54 #include <QTextStream>
56 #include <ACG/GL/gl.hh>
58 #include <ACG/GL/IRenderer.hh>
60 #include <ACG/GL/VertexDeclaration.hh>
62 #include <ACG/GL/ShaderCache.hh>
77 colorWriteMask[0] = colorWriteMask[1] = colorWriteMask[2] = colorWriteMask[3] = 1;
101 glGetFloatv(GL_DEPTH_RANGE,
depthRange.data());
108 for (
int i = 0; i < 3; ++i)
120 if (glIsEnabled(GL_TEXTURE_GEN_Q))
122 else if (glIsEnabled(GL_TEXTURE_GEN_R))
124 else if (glIsEnabled(GL_TEXTURE_GEN_T))
126 else if (glIsEnabled(GL_TEXTURE_GEN_S))
132 glGetTexGeniv(GL_S, GL_TEXTURE_GEN_MODE, &genMode);
148 switch (_props->lightStage()) {
165 if (_props->primitive() == SceneGraph::DrawModes::PRIMITIVE_WIREFRAME ||
166 _props->primitive() == SceneGraph::DrawModes::PRIMITIVE_HIDDENLINE ||
167 _props->primitive() == SceneGraph::DrawModes::PRIMITIVE_EDGE ||
168 _props->primitive() == SceneGraph::DrawModes::PRIMITIVE_HALFEDGE)
175 for (
int i = 0; i < 3; ++i)
196 vertexArrayObject(0),
197 vertexBuffer(0), indexBuffer(0), sysmemIndexBuffer(0),
198 primitiveMode(GL_TRIANGLES), patchVertices(0), numIndices(0), indexOffset(0), indexType(GL_UNSIGNED_INT),
201 culling(true), blending(false), alphaTest(false),
202 depthTest(true), depthWrite(true),
203 fillMode(GL_FILL), depthFunc(GL_LESS),
204 alphaFunc(GL_ALWAYS), alphaRef(0.0f),
205 blendSrc(GL_SRC_ALPHA), blendDest(GL_ONE_MINUS_SRC_ALPHA),
206 depthRange(0.0f, 1.0f),
208 patchDefaultInnerLevel(1.0f, 1.0f),
209 patchDefaultOuterLevel(1.0f, 1.0f, 1.0f, 1.0f),
211 diffuse(0.6f, 0.6f, 0.6f), ambient(0.1f, 0.1f, 0.1f),
212 specular(0.0f, 0.0f, 0.0f), emissive(0.05f, 0.05f, 0.05f),
213 alpha(1.0f), shininess(100.0f),
216 depthMapUniformName(0),
218 debugID(0), debugName(0),
221 colorWriteMask[0] = colorWriteMask[1] = colorWriteMask[2] = colorWriteMask[3] = 1;
224 RenderObject::~RenderObject() {
225 uniformPool_.
clear();
232 const char* primitiveString[] =
244 "GL_LINES_ADJACENCY",
245 "GL_LINE_STRIP_ADJACENCY",
246 "GL_TRIANGLES_ADJACENCY",
247 "GL_TRIANGLE_STRIP_ADJACENCY",
251 const char* fillModeString[] =
258 const char* depthFunString[] =
271 QTextStream resultStrm(&result);
274 #if !defined(GL_VERSION_3_2)
275 const GLenum maxSupportedPrimitiveMode = GL_POLYGON;
276 #elif !defined(GL_ARB_tessellation_shader)
277 const GLenum maxSupportedPrimitiveMode = GL_TRIANGLE_STRIP_ADJACENCY;
279 const GLenum maxSupportedPrimitiveMode = GL_PATCHES;
282 resultStrm <<
"name: " << debugName
286 <<
"\nfillMode: " << fillModeString[fillMode - GL_POINT]
291 #ifdef GL_ARB_tessellation_shader
292 if (primitiveMode == GL_PATCHES)
306 resultStrm <<
"\nmodelview: "
312 resultStrm <<
"\nproj: "
313 <<
"{" <<
proj(0, 0) <<
", " <<
proj(0, 1) <<
", " <<
proj(0, 2) <<
", " <<
proj(0, 3) <<
"} "
314 <<
"{" <<
proj(1, 0) <<
", " <<
proj(1, 1) <<
", " <<
proj(1, 2) <<
", " <<
proj(1, 3) <<
"} "
315 <<
"{" <<
proj(2, 0) <<
", " <<
proj(2, 1) <<
", " <<
proj(2, 2) <<
", " <<
proj(2, 3) <<
"} "
316 <<
"{" <<
proj(3, 0) <<
", " <<
proj(3, 1) <<
", " <<
proj(3, 2) <<
", " <<
proj(3, 3) <<
"} ";
319 resultStrm <<
"\nculling: " << culling
320 <<
"\nblending: " << blending
321 <<
"\nalphaTest: " << alphaTest;
324 resultStrm <<
"\ndepthTest: " << depthTest
325 <<
"\ndepthWrite: " << depthWrite
326 <<
"\ndepthFunc: " << depthFunString[
depthFunc - GL_NEVER]
328 <<
"\ncolorWriteMask: " << colorWriteMask[0] <<
", " << colorWriteMask[1] <<
", "<< colorWriteMask[2] <<
", "<< colorWriteMask[2];
330 resultStrm <<
"\nalphaFunc: " << depthFunString[
alphaFunc - GL_NEVER]
331 <<
"\nalphaRef: " << alphaRef;
334 resultStrm <<
"\nambient: [" << ambient[0] <<
", " << ambient[1] <<
", " << ambient[2] <<
"]";
335 resultStrm <<
"\nspecular: [" << specular[0] <<
", " << specular[1] <<
", " << specular[2] <<
"]";
336 resultStrm <<
"\nemissive: [" << emissive[0] <<
", " << emissive[1] <<
", " << emissive[2] <<
"]";
338 resultStrm <<
"\nshininess: " << shininess;
339 resultStrm <<
"\nalpha: " << alpha;
349 for (std::map<size_t, Texture>::const_iterator it =
textures_.begin(); it !=
textures_.end(); ++it)
351 resultStrm <<
"\ntexture unit " << it->first <<
": ";
353 switch (it->second.type)
355 case GL_TEXTURE_1D: resultStrm <<
"GL_TEXTURE_1D";
break;
356 case GL_TEXTURE_2D: resultStrm <<
"GL_TEXTURE_2D";
break;
357 case GL_TEXTURE_3D: resultStrm <<
"GL_TEXTURE_3D";
break;
358 #ifdef GL_TEXTURE_RECTANGLE
359 case GL_TEXTURE_RECTANGLE: resultStrm <<
"GL_TEXTURE_RECTANGLE";
break;
361 #ifdef GL_TEXTURE_CUBE_MAP
362 case GL_TEXTURE_CUBE_MAP: resultStrm <<
"GL_TEXTURE_CUBE_MAP";
break;
364 #ifdef GL_TEXTURE_1D_ARRAY
365 case GL_TEXTURE_1D_ARRAY: resultStrm <<
"GL_TEXTURE_1D_ARRAY";
break;
367 #ifdef GL_TEXTURE_2D_ARRAY
368 case GL_TEXTURE_2D_ARRAY: resultStrm <<
"GL_TEXTURE_2D_ARRAY";
break;
370 #ifdef GL_TEXTURE_CUBE_MAP_ARRAY
371 case GL_TEXTURE_CUBE_MAP_ARRAY: resultStrm <<
"GL_TEXTURE_CUBE_MAP_ARRAY";
break;
373 #ifdef GL_TEXTURE_BUFFER
374 case GL_TEXTURE_BUFFER: resultStrm <<
"GL_TEXTURE_BUFFER";
break;
376 #ifdef GL_TEXTURE_2D_MULTISAMPLE
377 case GL_TEXTURE_2D_MULTISAMPLE: resultStrm <<
"GL_TEXTURE_2D_MULTISAMPLE";
break;
379 #ifdef GL_TEXTURE_2D_MULTISAMPLE_ARRAY
380 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: resultStrm <<
"GL_TEXTURE_2D_MULTISAMPLE_ARRAY";
break;
382 default: resultStrm <<
"unknown_type";
break;
385 resultStrm <<
" - id " << it->second.id;
423 uniformPool_.
setUniform(_name, _value, _transposed);
426 void RenderObject::setUniformMat3(
const char *_name,
const ACG::GLMatrixf &_value,
bool _transposed )
428 uniformPool_.
setUniform(_name, _value, _transposed);
433 uniformPool_.
setUniform(_name, _values, _count);
438 uniformPool_.
setUniform(_name, _values, _count);
449 shaderDesc.geometryTemplateFile =
"Wireframe/geom_line2quad.tpl";
457 return shaderDesc.geometryTemplateFile ==
"Wireframe/geom_line2quad.tpl" ||
458 (
shaderDesc.geometryTemplateFile ==
"Wireframe/gl42/geometry.tpl" &&
459 shaderDesc.fragmentTemplateFile ==
"Wireframe/gl42/fragment.tpl");
469 shaderDesc.geometryTemplateFile =
"PointSize/geometry.tpl";
470 shaderDesc.fragmentTemplateFile =
"PointSize/fragment.tpl";
478 return shaderDesc.geometryTemplateFile ==
"PointSize/geometry.tpl" &&
479 shaderDesc.fragmentTemplateFile ==
"PointSize/fragment.tpl";
void addPool(const UniformPool &_src)
Add all uniforms of a pool to this pool.
VectorT< float, 2 > Vec2f
GLuint indexBuffer
Use vertex array object.
ShaderGenDesc shaderDesc
Drawmode and other shader params.
float shininess() const
get specular shininess (must be in [0, 128])
Vec2f depthRange
glDepthRange: (znear, zmax)
Namespace providing different geometric functions concerning angles.
void specularColor(const Vec4f &_s)
set the specular color
std::map< size_t, Texture > textures_
holds the textures (second) and the stage id (first)
GLenum alphaFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
bool isDefaultLineObject() const
Test if the object is rendered with one of the default line thickness methods.
void resetPointRendering()
Reset shader template names blocked by point rendering.
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
void resetLineRendering()
Reset shader template names blocked by line rendering.
void addTextureType(GLenum _type, bool _shadow, size_t _stage)
adds a texture type to the shader and enables texturing.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
void setUniform(const char *_name, GLint _value)
set values for int uniforms
unsigned int internalFlags_
may be used internally by the renderer
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
GLuint vertexArrayObject
Use vertex array object.
const GLMatrixd & modelview() const
get modelview matrix
void clear()
Clear the pool.
const GLMatrixd & projection() const
get projection matrix
QString toString() const
convert ShaderGenDesc to string format for debugging
void diffuseColor(const Vec4f &_d)
set the diffuse color.
const void * sysmemIndexBuffer
Use system memory index buffer.
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
bool colored() const
Are colors used?
GLenum primitiveMode
Primitive type.
const Vec4f & specular_color() const
get specular color
unsigned int numIndices
Number indices to render.
void addUniformPool(const GLSL::UniformPool &_pool)
add all uniforms from a pool
DrawModeProperties stores a set of properties that defines, how to render an object.
Vec3f diffuse
material definitions
bool flatShaded() const
Is flat shading used (Normals per face)?
static bool isStateEnabled(GLenum _cap)
returns true, if a cpa state is enabled
void clearTextures()
disables texture support and removes all texture types
void ambientColor(const Vec4f &_a)
set the ambient color.
void baseColor(const Vec4f &_c)
set the base color
GLMatrixd modelview
Modelview transform.
const char * depthMapUniformName
Uniform name of the depth map in the used shader.
bool textured() const
Is texturing enabled?
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
const Vec4f & ambient_color() const
get ambient color
unsigned int indexOffset
Offset to first index in the index buffer or vertex buffer respectively.
bool lighting() const
Is lighting enabled?
int priority
Priority to allow sorting of objects.
bool isDefaultPointObject() const
Test if the object is rendered with one of the default point extension methods.
void shininess(float _s)
set shininess
const Vec4f & base_color() const
get base color (used when lighting is off)
int debugID
used internally for renderer debugging
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
static void getBlendFunc(GLenum *_sfactor, GLenum *_dfactor)
get blend function, null-ptr safe
bool inZPrePass
Specify whether this object should be rendered in a z-prepass.
unsigned int patchVertices
patch size if primitiveMode is GL_PATCHES for rendering with tessellation shaders ...
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
const Vec4f & diffuse_color() const
get diffuse color
float alphaValue() const
get current alpha value for alpha_test
GLMatrixd proj
Projection transform.