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;
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)
201 culling(true), blending(false), alphaTest(false),
202 depthTest(true), depthWrite(true),
205 blendSrc(GL_SRC_ALPHA),
blendDest(GL_ONE_MINUS_SRC_ALPHA),
210 patchDefaultInnerLevel(1.0f, 1.0f),
211 patchDefaultOuterLevel(1.0f, 1.0f, 1.0f, 1.0f),
213 diffuse(0.6f, 0.6f, 0.6f), ambient(0.1f, 0.1f, 0.1f),
214 specular(0.0f, 0.0f, 0.0f), emissive(0.05f, 0.05f, 0.05f),
215 alpha(1.0f), shininess(100.0f),
223 colorWriteMask[0] = colorWriteMask[1] = colorWriteMask[2] = colorWriteMask[3] = 1;
226 RenderObject::~RenderObject() {
227 uniformPool_.
clear();
234 const char* primitiveString[] =
246 "GL_LINES_ADJACENCY",
247 "GL_LINE_STRIP_ADJACENCY",
248 "GL_TRIANGLES_ADJACENCY",
249 "GL_TRIANGLE_STRIP_ADJACENCY",
253 const char* fillModeString[] =
260 const char* depthFunString[] =
273 QTextStream resultStrm(&result);
276 #if !defined(GL_VERSION_3_2) 277 const GLenum maxSupportedPrimitiveMode = GL_POLYGON;
278 #elif !defined(GL_ARB_tessellation_shader) 279 const GLenum maxSupportedPrimitiveMode = GL_TRIANGLE_STRIP_ADJACENCY;
281 const GLenum maxSupportedPrimitiveMode = GL_PATCHES;
284 resultStrm <<
"name: " << debugName
288 <<
"\nfillMode: " << fillModeString[fillMode - GL_POINT]
293 #ifdef GL_ARB_tessellation_shader 294 if (primitiveMode == GL_PATCHES)
308 resultStrm <<
"\nmodelview: " 314 resultStrm <<
"\nproj: " 315 <<
"{" <<
proj(0, 0) <<
", " <<
proj(0, 1) <<
", " <<
proj(0, 2) <<
", " <<
proj(0, 3) <<
"} " 316 <<
"{" <<
proj(1, 0) <<
", " <<
proj(1, 1) <<
", " <<
proj(1, 2) <<
", " <<
proj(1, 3) <<
"} " 317 <<
"{" <<
proj(2, 0) <<
", " <<
proj(2, 1) <<
", " <<
proj(2, 2) <<
", " <<
proj(2, 3) <<
"} " 318 <<
"{" <<
proj(3, 0) <<
", " <<
proj(3, 1) <<
", " <<
proj(3, 2) <<
", " <<
proj(3, 3) <<
"} ";
321 resultStrm <<
"\nculling: " << culling
322 <<
"\nblending: " << blending
323 <<
"\nalphaTest: " << alphaTest;
326 resultStrm <<
"\ndepthTest: " << depthTest
327 <<
"\ndepthWrite: " << depthWrite
328 <<
"\ndepthFunc: " << depthFunString[
depthFunc - GL_NEVER]
330 <<
"\ncolorWriteMask: " << colorWriteMask[0] <<
", " << colorWriteMask[1] <<
", "<< colorWriteMask[2] <<
", "<< colorWriteMask[2];
332 resultStrm <<
"\nalphaFunc: " << depthFunString[
alphaFunc - GL_NEVER]
333 <<
"\nalphaRef: " << alphaRef;
336 resultStrm <<
"\nambient: [" << ambient[0] <<
", " << ambient[1] <<
", " << ambient[2] <<
"]";
337 resultStrm <<
"\nspecular: [" << specular[0] <<
", " << specular[1] <<
", " << specular[2] <<
"]";
338 resultStrm <<
"\nemissive: [" << emissive[0] <<
", " << emissive[1] <<
", " << emissive[2] <<
"]";
340 resultStrm <<
"\nshininess: " << shininess;
341 resultStrm <<
"\nalpha: " << alpha;
351 for (std::map<size_t, Texture>::const_iterator it =
textures_.begin(); it !=
textures_.end(); ++it)
353 resultStrm <<
"\ntexture unit " << it->first <<
": ";
355 switch (it->second.type)
357 case GL_TEXTURE_1D: resultStrm <<
"GL_TEXTURE_1D";
break;
358 case GL_TEXTURE_2D: resultStrm <<
"GL_TEXTURE_2D";
break;
359 case GL_TEXTURE_3D: resultStrm <<
"GL_TEXTURE_3D";
break;
360 #ifdef GL_TEXTURE_RECTANGLE 361 case GL_TEXTURE_RECTANGLE: resultStrm <<
"GL_TEXTURE_RECTANGLE";
break;
363 #ifdef GL_TEXTURE_CUBE_MAP 364 case GL_TEXTURE_CUBE_MAP: resultStrm <<
"GL_TEXTURE_CUBE_MAP";
break;
366 #ifdef GL_TEXTURE_1D_ARRAY 367 case GL_TEXTURE_1D_ARRAY: resultStrm <<
"GL_TEXTURE_1D_ARRAY";
break;
369 #ifdef GL_TEXTURE_2D_ARRAY 370 case GL_TEXTURE_2D_ARRAY: resultStrm <<
"GL_TEXTURE_2D_ARRAY";
break;
372 #ifdef GL_TEXTURE_CUBE_MAP_ARRAY 373 case GL_TEXTURE_CUBE_MAP_ARRAY: resultStrm <<
"GL_TEXTURE_CUBE_MAP_ARRAY";
break;
375 #ifdef GL_TEXTURE_BUFFER 376 case GL_TEXTURE_BUFFER: resultStrm <<
"GL_TEXTURE_BUFFER";
break;
378 #ifdef GL_TEXTURE_2D_MULTISAMPLE 379 case GL_TEXTURE_2D_MULTISAMPLE: resultStrm <<
"GL_TEXTURE_2D_MULTISAMPLE";
break;
381 #ifdef GL_TEXTURE_2D_MULTISAMPLE_ARRAY 382 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: resultStrm <<
"GL_TEXTURE_2D_MULTISAMPLE_ARRAY";
break;
384 default: resultStrm <<
"unknown_type";
break;
387 resultStrm <<
" - id " << it->second.id;
425 uniformPool_.
setUniform(_name, _value, _transposed);
428 void RenderObject::setUniformMat3(
const char *_name,
const ACG::GLMatrixf &_value,
bool _transposed )
430 uniformPool_.
setUniform(_name, _value, _transposed);
435 uniformPool_.
setUniform(_name, _values, _count);
440 uniformPool_.
setUniform(_name, _values, _count);
451 shaderDesc.geometryTemplateFile =
"Wireframe/geom_line2quad.tpl";
459 return shaderDesc.geometryTemplateFile ==
"Wireframe/geom_line2quad.tpl" ||
460 (
shaderDesc.geometryTemplateFile ==
"Wireframe/gl42/geometry.tpl" &&
461 shaderDesc.fragmentTemplateFile ==
"Wireframe/gl42/fragment.tpl");
471 shaderDesc.geometryTemplateFile =
"PointSize/geometry.tpl";
472 shaderDesc.fragmentTemplateFile =
"PointSize/fragment.tpl";
480 return shaderDesc.geometryTemplateFile ==
"PointSize/geometry.tpl" &&
481 shaderDesc.fragmentTemplateFile ==
"PointSize/fragment.tpl";
VectorT< float, 2 > Vec2f
Vec3f diffuse
material definitions
void specularColor(const Vec4f &_s)
set the specular color
void clearTextures()
disables texture support and removes all texture types
int debugID
used internally for renderer debugging
QString toString() const
convert ShaderGenDesc to string format for debugging
DrawModeProperties stores a set of properties that defines, how to render an object.
void addPool(const UniformPool &_src)
Add all uniforms of a pool to this pool.
bool overlay
Layer based rendering.
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
GLenum primitiveMode
Primitive type.
void addTextureType(GLenum _type, bool _shadow, size_t _stage)
adds a texture type to the shader and enables texturing.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
bool isDefaultLineObject() const
Test if the object is rendered with one of the default line thickness methods.
bool flatShaded() const
Is flat shading used (Normals per face)?
int priority
Priority to allow sorting of objects.
bool textured() const
Is texturing enabled?
std::map< size_t, Texture > textures_
holds the textures (second) and the stage id (first)
unsigned int internalFlags_
may be used internally by the renderer
const Vec4f & ambient_color() const
get ambient color
GLuint indexBuffer
Use vertex array object.
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
bool colored() const
Are colors used?
const void * sysmemIndexBuffer
Use system memory index buffer.
void baseColor(const Vec4f &_c)
set the base color
GLuint vertexArrayObject
Use vertex array object.
static bool isStateEnabled(GLenum _cap)
returns true, if a cpa state is enabled
GLenum indexType
Index element type.
const Vec4f & specular_color() const
get specular color
float alphaValue() const
get current alpha value for alpha_test
unsigned int patchVertices
patch size if primitiveMode is GL_PATCHES for rendering with tessellation shaders ...
bool lighting() const
Is lighting enabled?
unsigned int numIndices
Number indices to render.
GLMatrixd modelview
Modelview transform.
void ambientColor(const Vec4f &_a)
set the ambient color.
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
const Vec4f & base_color() const
get base color (used when lighting is off)
unsigned int indexOffset
Offset to first index in the index buffer or vertex buffer respectively.
void resetPointRendering()
Reset shader template names blocked by point rendering.
void diffuseColor(const Vec4f &_d)
set the diffuse color.
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
void setUniform(const char *_name, GLint _value)
set values for int uniforms
void clear()
Clear the pool.
float shininess() const
get specular shininess (must be in [0, 128])
Namespace providing different geometric functions concerning angles.
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
const GLMatrixd & projection() const
get projection matrix
const char * depthMapUniformName
Uniform name of the depth map in the used shader.
void shininess(float _s)
set shininess
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
GLenum alphaFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
const Vec4f & diffuse_color() const
get diffuse color
const GLMatrixd & modelview() const
get modelview matrix
void addUniformPool(const GLSL::UniformPool &_pool)
add all uniforms from a pool
bool inZPrePass
Specify whether this object should be rendered in a z-prepass.
static void getBlendFunc(GLenum *_sfactor, GLenum *_dfactor)
get blend function, null-ptr safe
GLMatrixd proj
Projection transform.
void resetLineRendering()
Reset shader template names blocked by line rendering.
bool isDefaultPointObject() const
Test if the object is rendered with one of the default point extension methods.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
ShaderGenDesc shaderDesc
Drawmode and other shader params.
Scalar * data()
access to Scalar array
Vec2f depthRange
glDepthRange: (znear, zmax)