Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfBatch.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef __glfBatch_hh__
26 #define __glfBatch_hh__
27 
28 #include "glfRenderTarget.hh"
29 #include "glfViewport.hh"
30 #include "glfTexture.hh"
31 #include "glfDepthBufferMode.hh"
32 #include "glfStencilBufferMode.hh"
33 #include "glfBlendMode.hh"
34 #include "glfShaderProgram.hh"
35 #include "glfVertexBuffer.hh"
36 #include "glfElementBuffer.hh"
37 #include "glfMatrix.hh"
38 
39 namespace BIAS {
40 
41  /**
42  * \brief A batch represents a single Draw call including all parameters (render states).
43  * \attention The pointers to all objects passed to the 'Set...' functions must still
44  * be valid when the batch is rendered. The objects are not copied!
45  * \ingroup g_openglframework
46  * \author jkollmann
47  */
48  class BIASOpenGLFramework_EXPORT glfBatch {
49  public:
50  glfBatch();
51  ~glfBatch();
52 
53  /**
54  * Sets the render target. Must be non-NULL. Default render target is 'glfScreen'.
55  */
56  void SetRenderTarget(const glfRenderTarget* renderTarget);
57 
58  /**
59  * Sets the viewport. Must be non-NULL. There is no default viewport, so
60  * you _must_ set one.
61  */
62  void SetViewport(const glfViewport* viewport);
63 
64  /**
65  * Sets the texture of a texture unit. NULL is allowed. Defaults are NULL.
66  * If a texture of a texture unit is NULL, it should not be used.
67  */
68  void SetTexture(const glfTexture* texture, int textureUnit);
69 
70  unsigned int GetMaxUsedTextureIndex();
71 
72  /**
73  * Releases texture including the matrix associated with
74  * the argument index.
75  */
76  void ReleaseTextures(unsigned int fromIndex);
77 
78  /**
79  * Sets the depth buffer mode.
80  * Defaults to GL Default.
81  * \Attention If passed NULL, the currently set GL state is used!
82  */
83  void SetDepthBufferMode(const glfDepthBufferMode* depthBufferMode);
84 
85  /**
86  * Sets the stencil buffer mode.
87  * Defaults to GL Default.
88  * \Attention If passed NULL, the currently set GL state is used!
89  */
90  void SetStencilBufferMode(const glfStencilBufferMode* stencilBufferMode);
91 
92 
93  /**
94  * Sets the blend mode.
95  * Defaults to GL Default.
96  * \Attention If passed NULL, the currently set GL state is used!
97  */
98  void SetBlendMode(const glfBlendMode* blendMode);
99 
100  /**
101  * Sets the shader program. NULL is allowed. If the shader program is NULL,
102  * the fixed-function pipeline is used.
103  */
104  void SetShaderProgram(const glfShaderProgram* shaderProgram);
105 
106  /**
107  * Sets the vertex buffer. Must be non-NULL.
108  */
109  void SetVertexBuffer(const glfVertexBuffer* vertexBuffer);
110 
111  /**
112  * Sets the element buffer. NULL is allowed. If no element buffer is used,
113  * you call Batch::SetPrimitiveType and vertices will be rendered
114  * straight from the vertex buffer.
115  */
116  void SetElementBuffer(const glfElementBuffer* elementBuffer);
117 
118  /**
119  * Sets the primitive type to rendering.
120  * This is used only if no element buffer is provided.
121  * Valid primitive types are be GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP,
122  * GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES,
123  * GL_QUAD_STRIP, GL_QUADS, and GL_POLYGON.
124  */
125  void SetPrimitiveType(GLenum primitiveType);
126 
127  /**
128  * Sets the range of vertices to be rendered if no element buffer is
129  * set, or the range of vertex indices if an element buffer is set.
130  * By default, all geometry will be rendered.
131  */
132  void SetRange(int first, int count);
133 
134  /**
135  * Sets the modelview matrix. Must be non-NULL. Default is the identity matrix.
136  */
137  void SetModelViewMatrix(const glfMatrix* matrix);
138 
139  /**
140  * Sets the projection matrix. Must be non-NULL. Default is the identity matrix.
141  */
142  void SetProjectionMatrix(const glfMatrix* matrix);
143 
144  /**
145  * Sets a texture matrix. NULL is allowed. If a texture matrix is NULL,
146  * it will not be set and is undefined. Make sure to not use a texture
147  * matrix that is not set.
148  */
149  void SetTextureMatrix(const glfMatrix* matrix, int index);
150 
151  unsigned int GetMaxUsedTextureMatrixIndex() const;
152 
153  /**
154  * Releases texture matrices including the matrix associated with
155  * the argument index.
156  */
157  void ReleaseTextureMatrices(unsigned int fromIndex);
158 
159  /**
160  * Draws the batch.
161  */
162  void Draw();
163 
164  /**
165  * Sets all render states possibly modified by Batch to the OpenGL defaults.
166  * Should be called before using an external library that uses OpenGL.
167  * \note: The viewport cannot be set to default, because the default is
168  * unknown to Batch.
169  */
170  static void SetDefaultRenderStates();
171 
172  static int GetMaxSupportedTextureUnits();
173  static int GetMaxSupportedTextureMatrices();
174 
175  void Init();
176 
177  private:
178  void BindRenderStates();
179 
185 
187  std::vector<const glfTexture*> textures_;
196  int first_, count_;
199  std::vector<const glfMatrix*> textureMatrix_;
200  };
201 
202 } // namespace BIAS
203 
204 #endif // __glfBatch_hh__
const glfShaderProgram * shaderProgram_
Definition: glfBatch.hh:191
An element buffer contains vertex indices that form primitives.
Defines the usage of the stencil buffer.
int maxUsedTextureIndex_
Definition: glfBatch.hh:183
Defines the usage of the depth buffer.
GLenum primitiveType_
Definition: glfBatch.hh:195
std::vector< const glfTexture * > textures_
Definition: glfBatch.hh:187
std::vector< const glfMatrix * > textureMatrix_
Definition: glfBatch.hh:199
const glfMatrix * modelViewMatrix_
Definition: glfBatch.hh:197
const glfVertexBuffer * vertexBuffer_
Definition: glfBatch.hh:193
const glfStencilBufferMode * stencilBufferMode_
Definition: glfBatch.hh:189
A vertex buffer contains an array of vertices that can be used for rendering.
A batch represents a single Draw call including all parameters (render states).
Definition: glfBatch.hh:48
const glfRenderTarget * renderTarget_
Definition: glfBatch.hh:192
A shader program composed of several shaders.
const glfElementBuffer * elementBuffer_
Definition: glfBatch.hh:194
bool initialized_
Definition: glfBatch.hh:182
Defines the function that blends rendered geometry with its background.
Definition: glfBlendMode.hh:37
GLint MAX_TEXTURE_UNITS_
Definition: glfBatch.hh:180
class for setting viewports
Definition: glfViewport.hh:37
const glfViewport * viewport_
Definition: glfBatch.hh:186
const glfMatrix * projectionMatrix_
Definition: glfBatch.hh:198
A 4x4 matrix in native OpenGL format.
Definition: glfMatrix.hh:41
Base class for textures.
Definition: glfTexture.hh:42
const glfDepthBufferMode * depthBufferMode_
Definition: glfBatch.hh:188
GLint MAX_TEXTURE_COORDS_
Definition: glfBatch.hh:181
const glfBlendMode * blendMode_
Definition: glfBatch.hh:190
Interface for render targets.
int maxUsedTextureMatrixIndex_
Definition: glfBatch.hh:184