Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RenderObject.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 /*===========================================================================*\
43 * *
44 * $Revision: 15868 $ *
45 * $Author: tenter $ *
46 * $Date: 2012-11-26 12:37:58 +0100 (Mo, 26 Nov 2012) $ *
47 * *
48 \*===========================================================================*/
49
50 #pragma once
51
52
53 #include <ACG/GL/gl.hh>
54 #include <ACG/Math/GLMatrixT.hh>
55 #include <ACG/GL/ShaderGenerator.hh>
56 #include <ACG/ShaderUtils/UniformPool.hh>
57
58 #include <map>
59
60
61 namespace GLSL{
62 class Program;
63 }
64
65 namespace ACG
66 {
67
68 // forward declaration
69 class VertexDeclaration;
70 class GLState;
71
72 namespace SceneGraph {
73 namespace DrawModes {
74 class DrawModeProperties;
75 }
76 class Material;
77 }
78
79
105 struct ACGDLLEXPORT RenderObject
106 {
107 friend class IRenderer;
108
112 RenderObject();
113
114 ~RenderObject();
115
116
123 int priority;
124
128 std::string name;
129
142 bool overlay;
143
145 GLMatrixd modelview;
146
148 GLMatrixd proj;
149
150
151 //===========================================================================
155 //===========================================================================
156
165 GLuint vertexArrayObject;
166
167
169 GLuint vertexBuffer,
170 indexBuffer;
171
180 const void* sysmemIndexBuffer;
181
189 GLenum primitiveMode;
190
192 unsigned int patchVertices; // GL_PATCH_VERTICES
193
195 unsigned int numIndices;
196
198 unsigned int indexOffset;
199
204 GLenum indexType;
205
211 GLsizei numInstances;
212
213
215 const VertexDeclaration* vertexDecl;
216
232 ShaderGenDesc shaderDesc;
233
234 // opengl states
235 // queried from glState in initFromState()
236 bool culling;
237 bool blending;
238 bool alphaTest;
239 bool depthTest;
240 bool depthWrite;
241
242 GLenum fillMode; // GL_POINT, GL_LINE, GL_FILL, default: GL_FILL
243
244 GLboolean colorWriteMask[4]; // {r,g,b,a}, default: all true
245
246 // GLenum shadeModel; // GL_FACE, GL_SMOOTH obsolete in shader pipeline
247 GLenum depthFunc;
248
249 // alpha testing function
250 GLenum alphaFunc;
251 float alphaRef; // reference value for alpha function
252
253 // alpha blending
254 GLenum blendSrc, blendDest;
255
256 Vec2f depthRange;
257
258 // ---------------------------
259 // default tessellation lod, if only a tess-eval, but no tess-control shader is specified
260 // this is ignored otherwise
261
262 Vec2f patchDefaultInnerLevel; // GL_PATCH_DEFAULT_INNER_LEVEL
263 Vec4f patchDefaultOuterLevel; // GL_PATCH_DEFAULT_OUTER_LEVEL
264
265 // ---------------------------
267 Vec3f diffuse,
268 ambient,
269 specular,
270 emissive;
271
272 float alpha,
273 shininess;
274
275
284 bool inZPrePass;
285
295 const char* depthMapUniformName;
296
297
306 struct Texture
307 {
308 GLuint id;
309 GLenum type;
310 bool shadow;
311 Texture(GLuint _id = 0, GLenum _type = GL_TEXTURE_2D, bool _shadow = false):
312 id(_id),
313 type(_type),
314 shadow(_shadow){}
315 };
316
317
319 void addTexture(const Texture& _t)
320 {
321 addTexture(_t,numTextures());
322 }
323
327 void addTexture(const Texture& _t,const size_t _stage, bool _addToShaderGen = true)
328 {
329 if (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS < numTextures())
330 {
331 std::cerr << "Texturestage " << _stage << " is too big. Allowed stages: "<< GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS << std::endl;
332 return;
333 }
334 textures_[_stage] = _t;
335 if (_addToShaderGen)
336 shaderDesc.addTextureType(_t.type,_t.shadow,_stage);
337 }
338
340 void clearTextures() {textures_.clear(); shaderDesc.clearTextures();}
341
342 const std::map<size_t,Texture>& textures(){return textures_;}
343
344 size_t numTextures() {return textures_.size();}
345
346 private:
348 std::map<size_t,Texture> textures_;
349 public:
350
351
353 int debugID;
354 const char* debugName;
355
357 unsigned int internalFlags_;
358
359
360 // opengl style helper function interface:
361 // provided for easier setup of RenderObjects,
362 // usage is not necessary
363 inline void glBindBuffer(GLenum target, GLuint buffer)
364 {
365 switch (target)
366 {
367 case GL_ARRAY_BUFFER: vertexBuffer = buffer; break;
368 case GL_ELEMENT_ARRAY_BUFFER: indexBuffer = buffer; break;
369 }
370 }
371
372 inline void glDrawArrays(GLenum mode, GLint first, GLsizei count)
373 {
374 this->glDrawInstancedArrays(mode, first, count, 0);
375 }
376
377 inline void glDrawInstancedArrays(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
378 {
379 indexBuffer = 0;
380 sysmemIndexBuffer = 0;
381
382 primitiveMode = mode;
383 indexOffset = first;
384 numIndices = count;
385 numInstances = primcount;
386 }
387
388 inline void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
389 {
390 this->glDrawElementsInstanced(mode, count, type, indices, 0);
391 }
392
393 inline void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
394 {
395 primitiveMode = mode;
396 numIndices = count;
397 indexType = type;
398
399 sysmemIndexBuffer = indices;
400
401 numInstances = primcount;
402 }
403
404 inline void glColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
405 {
406 colorWriteMask[0] = r; colorWriteMask[1] = g; colorWriteMask[2] = b; colorWriteMask[3] = a;
407 }
408
409 inline void glAlphaFunc(GLenum func, float ref)
410 {
411 alphaFunc = func;
412 alphaRef = ref;
413 }
414
419 void initFromState(GLState* _glState);
420
421 void setMaterial(const SceneGraph::Material* _mat);
422
425 void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties* _props);
426
427
438 void setupLineRendering(float _lineWidth, const Vec2f& _screenSize);
439
441 bool isDefaultLineObject() const;
442
444 void resetLineRendering();
445
452 void setupPointRendering(float _pointSize, const Vec2f& _screenSize);
453
455 bool isDefaultPointObject() const;
456
458 void resetPointRendering();
459
460
461
464 QString toString() const;
465
472 void setUniform(const char *_name, GLint _value);
473
480 void setUniform(const char *_name, GLfloat _value);
481
488 void setUniform(const char *_name, const ACG::Vec2f &_value);
489
496 void setUniform(const char *_name, const ACG::Vec3f &_value);
497
504 void setUniform(const char *_name, const ACG::Vec4f &_value);
505
506 void setUniform(const char *_name, const ACG::GLMatrixf &_value, bool _transposed = false);
507 void setUniformMat3(const char *_name, const ACG::GLMatrixf &_value, bool _transposed = false);
508
509
510 void setUniform(const char *_name, GLint *_values, int _count);
511 void setUniform(const char *_name, GLfloat *_values, int _count);
512
513
519 void addUniformPool(const GLSL::UniformPool& _pool);
520
521 private:
522 GLSL::UniformPool uniformPool_;
523 };
524
525
533 class ACGDLLEXPORT RenderObjectModifier
534 {
535 public:
536 RenderObjectModifier() {}
537 virtual ~RenderObjectModifier() {}
538
544 virtual void apply(RenderObject* _obj) = 0;
545
546 };
547
548
549
550 //=============================================================================
551 } // namespace ACG
552 //=============================================================================
ACG::RenderObject::shaderDesc
ShaderGenDesc shaderDesc
Drawmode and other shader params.
Definition: RenderObject.hh:232
ACG::RenderObject::depthRange
Vec2f depthRange
glDepthRange: (znear, zmax)
Definition: RenderObject.hh:256
ACG
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::RenderObject::textures_
std::map< size_t, Texture > textures_
holds the textures (second) and the stage id (first)
Definition: RenderObject.hh:348
ACG::RenderObject::alphaFunc
GLenum alphaFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
Definition: RenderObject.hh:250
ACG::RenderObject
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:105
ACG::RenderObject::blendDest
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
Definition: RenderObject.hh:254
ACG::ShaderGenDesc::addTextureType
void addTextureType(GLenum _type, bool _shadow, size_t _stage)
adds a texture type to the shader and enables texturing.
Definition: ShaderGenerator.hh:191
ACG::RenderObject::vertexBuffer
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
Definition: RenderObject.hh:169
ACG::RenderObject::internalFlags_
unsigned int internalFlags_
may be used internally by the renderer
Definition: RenderObject.hh:357
ACG::RenderObject::depthFunc
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
Definition: RenderObject.hh:247
ACG::RenderObject::addTexture
void addTexture(const Texture &_t, const size_t _stage, bool _addToShaderGen=true)
Definition: RenderObject.hh:327
ACG::RenderObject::vertexArrayObject
GLuint vertexArrayObject
Use vertex array object.
Definition: RenderObject.hh:165
ACG::RenderObject::sysmemIndexBuffer
const void * sysmemIndexBuffer
Use system memory index buffer.
Definition: RenderObject.hh:180
GLSL::UniformPool
GLSL uniform pool.
Definition: UniformPool.hh:71
ACG::RenderObject::vertexDecl
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
Definition: RenderObject.hh:215
ACG::IRenderer
Definition: IRenderer.hh:84
ACG::GLMatrixT< double >
ACG::RenderObject::primitiveMode
GLenum primitiveMode
Primitive type.
Definition: RenderObject.hh:189
ACG::RenderObject::numIndices
unsigned int numIndices
Number indices to render.
Definition: RenderObject.hh:195
ACG::RenderObject::diffuse
Vec3f diffuse
material definitions
Definition: RenderObject.hh:267
ACG::RenderObject::name
std::string name
Name for logging.
Definition: RenderObject.hh:128
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::ShaderGenDesc::clearTextures
void clearTextures()
disables texture support and removes all texture types
Definition: ShaderGenerator.hh:200
GLSL
This namespace contains all the classes and functions for handling GLSL shader and program objects...
Definition: AntiAliasing.hh:75
ACG::RenderObject::clearTextures
void clearTextures()
clear all textures. Also affected on shaderDesc
Definition: RenderObject.hh:340
ACG::RenderObject::Texture
Texture to be used.
Definition: RenderObject.hh:306
ACG::ShaderGenDesc
Definition: ShaderGenerator.hh:89
ACG::VertexDeclaration
Class to define the vertex input layout.
Definition: VertexDeclaration.hh:266
ACG::RenderObject::addTexture
void addTexture(const Texture &_t)
adds a texture to stage RenderObjects::numTextures()
Definition: RenderObject.hh:319
ACG::RenderObject::numInstances
GLsizei numInstances
Definition: RenderObject.hh:211
ACG::RenderObject::modelview
GLMatrixd modelview
Modelview transform.
Definition: RenderObject.hh:145
ACG::RenderObject::overlay
bool overlay
Layer based rendering.
Definition: RenderObject.hh:142
ACG::RenderObject::depthMapUniformName
const char * depthMapUniformName
Uniform name of the depth map in the used shader.
Definition: RenderObject.hh:295
ACG::RenderObject::indexType
GLenum indexType
Index element type.
Definition: RenderObject.hh:204
ACG::RenderObjectModifier
Interface for modifying render objects.
Definition: RenderObject.hh:533
ACG::RenderObject::indexOffset
unsigned int indexOffset
Offset to first index in the index buffer or vertex buffer respectively.
Definition: RenderObject.hh:198
ACG::RenderObject::priority
int priority
Priority to allow sorting of objects.
Definition: RenderObject.hh:123
ACG::RenderObject::debugID
int debugID
used internally for renderer debugging
Definition: RenderObject.hh:353
ACG::RenderObject::inZPrePass
bool inZPrePass
Specify whether this object should be rendered in a z-prepass.
Definition: RenderObject.hh:284
ACG::RenderObject::patchVertices
unsigned int patchVertices
patch size if primitiveMode is GL_PATCHES for rendering with tessellation shaders ...
Definition: RenderObject.hh:192
ACG::RenderObject::proj
GLMatrixd proj
Projection transform.
Definition: RenderObject.hh:148