Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TemplateSpecializedBatch.cpp
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 #include <OpenGLFramework/SpecializedBatches/TemplateSpecializedBatch.hh>
26 #include <OpenGLFramework/Utils/Primitives.hh>
27 
28 using namespace BIAS;
29 using namespace std;
30 
33 processingScheme_(myProcessingScheme),
34 initialized_(false),
35 callPreExecuteFlag_(true)
36 {}
37 
38 
41 {
42  if(initialized_) {
43  BIASWARN("[TemplateSpecializedBatch] : Aready initilized!");
44  return;
45  }
46  processingScheme_ = ps;
47 
48  /** Remove unneccesary lines **/
53  InitShaders_();
55 
56 
57  InitBatch_();
58  initialized_ = true;
59 }
60 
63 {
64  //as an example a simple quad is appended
66 }
67 
70 {
73 }
74 
77 {
78  //in this example nothing is done here
79 }
80 
83 {
84  //If the projection and modelview matrix are identity matrices,
85  //the geometry specified in Primitives::PlainQuad2DWithTexture2D
86  // (see InitPrimitiveData_())
87  //will be mapped in a way, that it completely fills the viewport
88  //(see OpenGL Specs. for more info).
89  //This is what we typically want when processing an
90  //complete image. So we are fine with the identities matrices!
91 
94 
95  //we leave the viewport out here because its
96  //manipulated by SetViewport method.
97 
98 }
99 
102 {
104 
105  string fragmentProgram =
106  "uniform sampler2D image;" //input image
107  ""
108  "void main() {"
109  " vec4 color = texture2D(image, gl_TexCoord[0]);"
110  //permutate colors of texture and output to the framebuffer
111  " gl_FragColor.r = color.g;"
112  " gl_FragColor.g = color.b;"
113  " gl_FragColor.b = color.r;"
114  " gl_FragColor.a = color.a;"
115  "}";
116  fragmentShader_.Create(GL_FRAGMENT_SHADER, fragmentProgram);
117  //fragmentShader_.Create(GL_FRAGMENT_SHADER);
118  // is an alternative, which can be used to get an object id
119  // without specifying the code.
120 
123  //this associates texture unit 0 to be connected with the name
124  // "image" in the shader program.
125  // The texture bound to this unit is required to be a 2D texture.
126  // (see shader program above).
127  // SetUniform is the method to set uniforms, which are also
128  // ints, floats, vectors and matrices!
129  shaderProgram_.SetUniform("image", 0);
130 }
131 
132 
134 SetViewport(unsigned int viewportWidth,
135  unsigned int viewportHeight,
136  unsigned int viewportOx,
137  unsigned int viewportOy)
138 {
139  viewport_.SetOrigin(viewportOx, viewportOy);
140  viewport_.SetSize(viewportWidth, viewportHeight);
141 }
142 
145 {
147 }
148 
151 {
152  //don't need this in this example
153  depthTest_.SetDepthTest(true);
154 }
155 
158 {
166 
168 }
169 
172 
173  BIASASSERT(initialized_);
174 
175  if(callPreExecuteFlag_) {
176  PreExecute_();
177  }
178 
179  batch_.Draw();
180 
181 }
182 
185  //update some GL state based internal state
186  // our simple example doesn't use this ... could as well be
187  //removed
188  BIASWARN("this implementation still contains example-code!");
189 }
190 
193  //use this method to rearange state information which
194  // will stay fixed over several executions or to
195  //synchronsize changes that need multiple communication calls.
196 }
197 
200 {
202 }
203 
void SetVertexBuffer(const glfVertexBuffer *vertexBuffer)
Sets the vertex buffer.
Definition: glfBatch.cpp:129
void InitPerFragmentOperations_()
Create and setup the per fragment operations.
void SetModelViewMatrix(const glfMatrix *matrix)
Sets the modelview matrix.
Definition: glfBatch.cpp:150
void PreExecute_()
Is the first call performed by the Execute method called.
void Create()
Creates the shader program.
void SetUniform(const std::string &varName, float value)
void MakeIdentity()
Definition: glfMatrix.cpp:72
void InitVertexTransformation_()
Create and setup the render matrices and the viewport.
void Link()
Links the attached shaders.
void AttachShader(const glfShader &shader)
Attaches a shader to the program.
void Create()
Creates the texture but does not upload any data yet.
Definition: glfTexture.cpp:80
void SetDepthBufferMode(const glfDepthBufferMode *depthBufferMode)
Sets the depth buffer mode.
Definition: glfBatch.cpp:106
void Create(GLenum type)
Creates the shader without the GLSL source code, use other Create() methods to upload source afterwar...
Definition: glfShader.cpp:55
void Draw()
Draws the batch.
Definition: glfBatch.cpp:218
void InitBatch_()
Connects all data used in GL processing to the batch.
BIAS::glfElementBuffer elements_
Element buffers can be suitable are however not mandatory.
void UploadImage(const BIAS::ImageBase &image, GLenum internalFormat=0, int mipmap=0)
Uploads a BIAS::Image to a mipmap of the texture.
void SetViewport(unsigned int viewportWidth, unsigned int viewportHeight, unsigned int viewportOx=0, unsigned int viewportOy=0)
Method determines the viewport size, which is used in the render target.
void UploadTextureImage(BIAS::ImageBase &img)
Some textures will certainly be created internally.
void SetViewport(const glfViewport *viewport)
Sets the viewport.
Definition: glfBatch.cpp:65
void Execute()
Configures GL and issues a &quot;rendering&quot; on the GPU.
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...
void SetTexture(const glfTexture *texture, int textureUnit)
Sets the texture of a texture unit.
Definition: glfBatch.cpp:71
void InitTextureData_()
Creates and initializes the necessary textures.
void InitShaders_()
Creates and issues initialization of shader execution.
void SetRenderTarget(const glfRenderTarget *renderTarget)
Sets the render target.
Definition: glfBatch.cpp:59
static void PlainQuad2DWithTexture2D(BIAS::glfVertexBuffer &vb, BIAS::glfElementBuffer &eb, bool flip=false)
Vertex Order: 3–2 | | 0–1 .
Definition: Primitives.cpp:263
void SetShaderProgram(const glfShaderProgram *shaderProgram)
Sets the shader program.
Definition: glfBatch.cpp:124
void Init(TemplateSpecializedBatch::ProcessingScheme ps)
This method initializes all necessary GL structures.
void SetRenderTarget(BIAS::glfRenderTarget *rt)
Method determines where the results are delivered.
void SetDepthTest(bool enable)
Sets whether to use depth buffer tests.
void SetSize(int width, int height)
Sets the size of the viewport in pixel coordinates.
Definition: glfViewport.cpp:51
void Update()
It will certainly be necessary to pass non GL specific data to influence the processing.
void SetProjectionMatrix(const glfMatrix *matrix)
Sets the projection matrix.
Definition: glfBatch.cpp:156
void Set(GLenum minFilter=GL_NEAREST, GLenum magFilter=GL_NEAREST, GLenum wrapS=GL_CLAMP, GLenum wrapT=GL_CLAMP, GLint textureNr=GL_TEXTURE0)
Convenience wrapper.
void SetOrigin(int x, int y)
Sets the position of the upper-left corner of the viewport in pixel coordinates.
Definition: glfViewport.cpp:45
void SetElementBuffer(const glfElementBuffer *elementBuffer)
Sets the element buffer.
Definition: glfBatch.cpp:134
void InitTextureMatrixData_()
Creates and initializes the necessary texture matrices.
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...
void InitPrimitiveData_()
Creates the associated GL objects and the content of vertices_ and elements_.