Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TemplateSpecializedBatch.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 __TemplateSpecializedBatch_hh__
26 #define __TemplateSpecializedBatch_hh__
27 
28 #include <OpenGLFramework/Base/glfBatch.hh>
29 #include <OpenGLFramework/Base/glfRenderTarget.hh>
30 #include <OpenGLFramework/Base/glfDepthBufferMode.hh>
31 #include <OpenGLFramework/Base/glfViewport.hh>
32 #include <OpenGLFramework/Base/glfMatrix.hh>
33 #include <OpenGLFramework/Base/glfTexture2D.hh>
34 #include <bias_config.h>
35 
36 
37 namespace BIAS {
38 
39  /** This file contains the header for a class template.
40  * This template shall aid in the usage of the OpenGLFramework,
41  * by proposing an implementation scheme to encapsulate OpenGL processings.
42  * The whole proposal is based on the Batch concept proposed in the OpenGLFramework.
43  * As such the implementation can be emphesised as mantic gathering and
44  * maintenance of the necessary stateinformation to execute one or multiple
45  * rendering passes.
46  *
47  * \author bartczak 04/2008
48  **/
49  class BIASOpenGLFramework_EXPORT TemplateSpecializedBatch {
50  public:
51  enum ProcessingScheme {myProcessingScheme=0, myOtherProcessingScheme};
52  protected:
53  /** This enum is used to tell the class how it shall behave and setup
54  * GL states, it is specified using Init().
55  **/
57  public:
58 
60 
61  /** \name Pre Init Calls.
62  * In this section methods are found that must be issued to the obejcts BEFORE
63  * Init() is called.
64  */
65  /** @{ */
66  //void SomeUsefullStateSetter();
67  /** @} */
68 
69  /** \name Calls when appropriate Context is available.
70  */
71  /** @{ */
72  /** This method initializes all necessary GL structures.
73  * \attention must not be called before appropriate GLContext is available!
74  **/
76 
77  /** \name Communication with other GPU work steps*/
78  /** @{ */
79 
80  /** Method determines where the results are delivered.
81  * The default is the Screen, which is the same to passing NULL.
82  *
83  **/
84  void SetRenderTarget(BIAS::glfRenderTarget* rt);
85 
86  /** Method determines the viewport size, which is used in
87  * the render target.
88  **/
89  void SetViewport(unsigned int viewportWidth,
90  unsigned int viewportHeight, unsigned int viewportOx = 0,
91  unsigned int viewportOy = 0 );
92 
93  /** Textures are a pretty way to exchange information between GPU worksteps.
94  * Although some kind of polymorphism is
95  * available not all texture object implement the same amount of functionality.
96  * I therefore propose to implement the appropriate, specialized interface.
97  **/
98  // void SetTexture(some texture pointer);
99  // void GetTexture(some texture pointer reference);
100  /** @} */
101 
102  /** \name General I/O */
103  /** @{ */
104  /** Some textures will certainly be created internally.
105  * The UploadTextureContent routines, take care to fill them with content.
106  * Currently not all texture targets are fully implemented, therefore
107  * I also propose to implement the appropriate interface.
108  **/
109  void UploadTextureImage(BIAS::ImageBase& img);
110 
111  /** It will certainly be necessary to pass non GL specific data
112  * to influence the processing.
113  * If changes are made that make a reinitilaization necessary
114  * you should work with flags that are evaluated before drawing
115  * and are processed when all state changes have been gathered.
116  * Use the Update() and the PreExecute_() methods for that.
117  **/
118  //void SetParameter<MoreInfo>(some object/primitive type);
119 
120  /** Method evaluates set parameters and adapts the GL state. **/
121  void Update();
122 
123  /** @} */
124 
125  /**
126  * Configures GL and issues a "rendering" on the GPU.
127  **/
128  void Execute();
129  /** @} */
130 
131  protected:
132  /** Guard for multiple calls to Init().
133  * This way one can prohibit conflicts with already setup
134  * shader programms, which would start throwing exceptions.
135  **/
137 
138  /** This flag deteremines whether the PreExecute method has to be called or not. **/
140 
141  /** Is the first call performed by the Execute method called.
142  * This method can be used to update shader parameters etc.
143  **/
144  void PreExecute_();
145 
146 
147  //*************************
148  // Batch Assembly
149  //*************************
150  /** \name Batch Assembly */
151  /** @{ */
152  /** This is the core implementation that determines how
153  * updates to the GL state are handled. In this all GL state updates are
154  * gathered and the update stratgy is implemented here.
155  **/
157  /** Connects all data used in GL processing to the batch.
158  **/
159  void InitBatch_();
160  /** @} */
161 
162 
163  //*************************
164  // Geometry Specification
165  //*************************
166  /** \name Geometry Specification */
167  /** @{ */
168  /** If you want to process something, you will need vertex data!
169  * Of course its possible to have it defined and managed outside this
170  * class, but here is the general idea.
171  **/
173 
174  /** Element buffers can be suitable are however not mandatory. **/
176 
177  /** Creates the associated GL objects and the content of vertices_ and elements_.
178  * Connection to batch_ is performed in InitBatch_().
179  **/
180  void InitPrimitiveData_();
181  /** @} */
182 
183 
184  //*************************
185  // Textures
186  //*************************
187  /** \name Textures.
188  * Various textures exist in opengl however we did not implement them all yet.
189  * Whats pretty heavily used is the Texture2D class, which therefore is well implemented...
190  * Number of texture matrices and textures, which be handled in a single pass might differ!
191  **/
192  /** @{ */
194  //Texture2D textureInTextureUnit1;
195  //Texture2D textureInTextureUnit...;
196  //Texture2D textureInTextureUnitM;
197 
198 
199  /** Creates and initializes the necessary textures.
200  * Connection to batch_ is performed in InitBatch_().
201  **/
202  void InitTextureData_();
203 
204  //RenderMatrix textureMatrixInTextureUnit0;
205  //RenderMatrix textureMatrixInTextureUnit1;
206  //RenderMatrix textureMatrixInTextureUnit...;
207  //RenderMatrix textureMatrixInTextureUnitN;
208 
209  /** Creates and initializes the necessary texture matrices.
210  * Connection to batch_ is performed in InitBatch_().
211  **/
212  void InitTextureMatrixData_();
213  /** @} */
214 
215 
216  //*************************
217  // Vertex Transformation
218  //*************************
219  /** \name Vertex Transformation.
220  * GL contains a default vertex processing chain, which requires the specification
221  * of an affine transformation matrix, the ModelView matrix, and a Projection Matrix.
222  * In the end projected vertices are mapped to a viewport.
223  **/
224  /** @{ */
227 
228  /** Create and setup the render matrices and the viewport.
229  * Connection to batch_ is performed in InitBatch_().
230  * The viewport is not changed here! It is changed by
231  * SetViewport method.
232  **/
233  void InitVertexTransformation_();
234 
236  /** @} */
237 
238 
239  //*************************
240  // Shaders
241  //*************************
242  /** \name Shaders.
243  * The GL processing pipeline is made more flexible by the useage of Shaders.
244  * You do not have to use shaders. Yet I guess the shaders are the reason for using
245  * the OpenGLFramework in the first place...
246  * (remove these lines and their usage should you not need them?!)
247  **/
248  /** @{ */
250  /* Vertex shaders do not have to be used!*/
251  //Shader vertexShader_;
253 
254  /** Creates and issues initialization of shader execution.
255  * Connection to batch_ is performed in InitBatch_().
256  **/
257  void InitShaders_();
258  /** @} */
259 
260 
261  //*************************
262  // Per Fragment Operations
263  //*************************
264  /** \name Per Fragment Operations.
265  * In the Gl process ing pipeline after shader application per pixel
266  * operations are performed. This are depth test, stencil test, blending ... .
267  * Still not all tests are wraped in the OpenGLFramework, but when needed they will.
268  **/
269  /** @{ */
271 
272  //BlendMode blending_;
273 
274  /** Create and setup the per fragment operations.
275  * Connection to batch_ is performed in InitBatch_().
276  **/
277  void InitPerFragmentOperations_();
278  /** @} */
279 
280  };
281 
282 }//end of namespace
283 
284 #endif
An element buffer contains vertex indices that form primitives.
Defines the usage of the depth buffer.
This file contains the header for a class template.
A 2D texture.
Definition: glfTexture2D.hh:40
BIAS::glfElementBuffer elements_
Element buffers can be suitable are however not mandatory.
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
A shader program composed of several shaders.
A GLSL vertex shader or fragment shader, which must be linked in a shader program.
Definition: glfShader.hh:39
bool initialized_
Guard for multiple calls to Init().
bool callPreExecuteFlag_
This flag deteremines whether the PreExecute method has to be called or not.
BIAS::glfBatch batch_
This is the core implementation that determines how updates to the GL state are handled.
BIAS::glfVertexBuffer vertices_
If you want to process something, you will need vertex data! Of course its possible to have it define...
class for setting viewports
Definition: glfViewport.hh:37
A 4x4 matrix in native OpenGL format.
Definition: glfMatrix.hh:41
Interface for render targets.
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
ProcessingScheme processingScheme_
This enum is used to tell the class how it shall behave and setup GL states, it is specified using In...