1 /***********************************************************************
2 created: Thu Jan 8 2009
3 authors: Paul D Turner <paul@cegui.org.uk>
4 Lukas E Meindl
5 *************************************************************************/
6 /***************************************************************************
7 * Copyright (C) 2004 - 2013 Paul D Turner & The CEGUI Development Team
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining
10 * a copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 ***************************************************************************/
28 #include "CEGUI/RendererModules/OpenGL/GL.h"
29 #include "CEGUI/RendererModules/OpenGL/GLGeometryBuffer.h"
30 #include "CEGUI/RendererModules/OpenGL/GLRenderer.h"
31 #include "CEGUI/RenderEffect.h"
32 #include "CEGUI/RendererModules/OpenGL/Texture.h"
33 #include "CEGUI/Vertex.h"
34 #include "CEGUI/RendererModules/OpenGL/GlmPimpl.h"
35 #include "glm/gtc/type_ptr.hpp"
36
37 // Start of CEGUI namespace section
38 namespace CEGUI
39 {
40 //----------------------------------------------------------------------------//
OpenGLGeometryBuffer(OpenGLRenderer & owner)41 OpenGLGeometryBuffer::OpenGLGeometryBuffer(OpenGLRenderer& owner) :
42 OpenGLGeometryBufferBase(owner)
43 {
44 }
45
46 //----------------------------------------------------------------------------//
draw() const47 void OpenGLGeometryBuffer::draw() const
48 {
49 CEGUI::Rectf viewPort = d_owner->getActiveViewPort();
50
51 // setup clip region
52 glScissor(static_cast<GLint>(d_clipRect.left()),
53 static_cast<GLint>(viewPort.getHeight() - d_clipRect.bottom()),
54 static_cast<GLint>(d_clipRect.getWidth()),
55 static_cast<GLint>(d_clipRect.getHeight()));
56
57 // apply the transformations we need to use.
58 if (!d_matrixValid)
59 updateMatrix();
60
61 glMatrixMode(GL_MODELVIEW);
62 glLoadMatrixf(glm::value_ptr(d_matrix->d_matrix));
63
64 // activate desired blending mode
65 d_owner->setupRenderingBlendMode(d_blendMode);
66
67 const int pass_count = d_effect ? d_effect->getPassCount() : 1;
68 for (int pass = 0; pass < pass_count; ++pass)
69 {
70 // set up RenderEffect
71 if (d_effect)
72 d_effect->performPreRenderFunctions(pass);
73
74 // draw the batches
75 size_t pos = 0;
76 BatchList::const_iterator i = d_batches.begin();
77 for ( ; i != d_batches.end(); ++i)
78 {
79 if (i->clip)
80 glEnable(GL_SCISSOR_TEST);
81 else
82 glDisable(GL_SCISSOR_TEST);
83
84 glBindTexture(GL_TEXTURE_2D, i->texture);
85 // set up pointers to the vertex element arrays
86 glTexCoordPointer(2, GL_FLOAT, sizeof(GLVertex),
87 &d_vertices[pos]);
88 glColorPointer(4, GL_FLOAT, sizeof(GLVertex),
89 &d_vertices[pos].colour[0]);
90 glVertexPointer(3, GL_FLOAT, sizeof(GLVertex),
91 &d_vertices[pos].position[0]);
92 // draw the geometry
93 glDrawArrays(GL_TRIANGLES, 0, i->vertexCount);
94 pos += i->vertexCount;
95 }
96 }
97
98 // clean up RenderEffect
99 if (d_effect)
100 d_effect->performPostRenderFunctions();
101 }
102
103 //----------------------------------------------------------------------------//
104
105 } // End of CEGUI namespace section
106
107