46 #include <QTextStream> 48 #include <ACG/GL/gl.hh> 50 #include <ACG/GL/IRenderer.hh> 52 #include <ACG/GL/VertexDeclaration.hh> 54 #include <ACG/GL/ShaderCache.hh> 69 programPointSize =
false;
71 colorWriteMask[0] = colorWriteMask[1] = colorWriteMask[2] = colorWriteMask[3] = 1;
103 for (
int i = 0; i < 3; ++i)
113 #ifdef GL_PROGRAM_POINT_SIZE 114 programPointSize = _glState->
isStateEnabled(GL_PROGRAM_POINT_SIZE);
132 _glState->
getTexGenMode(GL_S, GL_TEXTURE_GEN_MODE, &genMode);
148 switch (_props->lightStage()) {
170 if (_props->primitive() == SceneGraph::DrawModes::PRIMITIVE_WIREFRAME ||
171 _props->primitive() == SceneGraph::DrawModes::PRIMITIVE_HIDDENLINE ||
172 _props->primitive() == SceneGraph::DrawModes::PRIMITIVE_EDGE ||
173 _props->primitive() == SceneGraph::DrawModes::PRIMITIVE_HALFEDGE)
180 for (
int i = 0; i < 3; ++i)
207 culling(true), blending(false), alphaTest(false),
208 depthTest(true), depthWrite(true),
211 blendSrc(GL_SRC_ALPHA),
blendDest(GL_ONE_MINUS_SRC_ALPHA),
216 programPointSize(false),
219 patchDefaultInnerLevel(1.0f, 1.0f),
220 patchDefaultOuterLevel(1.0f, 1.0f, 1.0f, 1.0f),
222 diffuse(0.6f, 0.6f, 0.6f), ambient(0.1f, 0.1f, 0.1f),
223 specular(0.0f, 0.0f, 0.0f), emissive(0.05f, 0.05f, 0.05f),
224 alpha(1.0f), shininess(100.0f),
232 colorWriteMask[0] = colorWriteMask[1] = colorWriteMask[2] = colorWriteMask[3] = 1;
235 RenderObject::~RenderObject() {
236 uniformPool_.
clear();
243 const char* primitiveString[] =
255 "GL_LINES_ADJACENCY",
256 "GL_LINE_STRIP_ADJACENCY",
257 "GL_TRIANGLES_ADJACENCY",
258 "GL_TRIANGLE_STRIP_ADJACENCY",
262 const char* fillModeString[] =
269 const char* depthFunString[] =
282 QTextStream resultStrm(&result);
285 #if !defined(GL_VERSION_3_2) 286 const GLenum maxSupportedPrimitiveMode = GL_POLYGON;
287 #elif !defined(GL_ARB_tessellation_shader) 288 const GLenum maxSupportedPrimitiveMode = GL_TRIANGLE_STRIP_ADJACENCY;
290 const GLenum maxSupportedPrimitiveMode = GL_PATCHES;
293 resultStrm <<
"name: " << QString::fromStdString(debugName)
297 <<
"\nfillMode: " << fillModeString[fillMode - GL_POINT]
302 #ifdef GL_ARB_tessellation_shader 303 if (primitiveMode == GL_PATCHES)
317 resultStrm <<
"\nmodelview: " 323 resultStrm <<
"\nproj: " 324 <<
"{" <<
proj(0, 0) <<
", " <<
proj(0, 1) <<
", " <<
proj(0, 2) <<
", " <<
proj(0, 3) <<
"} " 325 <<
"{" <<
proj(1, 0) <<
", " <<
proj(1, 1) <<
", " <<
proj(1, 2) <<
", " <<
proj(1, 3) <<
"} " 326 <<
"{" <<
proj(2, 0) <<
", " <<
proj(2, 1) <<
", " <<
proj(2, 2) <<
", " <<
proj(2, 3) <<
"} " 327 <<
"{" <<
proj(3, 0) <<
", " <<
proj(3, 1) <<
", " <<
proj(3, 2) <<
", " <<
proj(3, 3) <<
"} ";
330 resultStrm <<
"\nculling: " << culling
331 <<
"\nblending: " << blending
332 <<
"\nalphaTest: " << alphaTest;
335 resultStrm <<
"\ndepthTest: " << depthTest
336 <<
"\ndepthWrite: " << depthWrite
337 <<
"\ndepthFunc: " << depthFunString[
depthFunc - GL_NEVER]
339 <<
"\ncolorWriteMask: " << colorWriteMask[0] <<
", " << colorWriteMask[1] <<
", "<< colorWriteMask[2] <<
", "<< colorWriteMask[2];
341 resultStrm <<
"\nalphaFunc: " << depthFunString[
alphaFunc - GL_NEVER]
342 <<
"\nalphaRef: " << alphaRef;
344 resultStrm <<
"\nclipDistanceMask: " << QString::number(clipDistanceMask, 2);
345 resultStrm <<
"\nprogramPointSize: " << programPointSize;
346 resultStrm <<
"\npointSize: " << pointSize;
349 resultStrm <<
"\nambient: [" << ambient[0] <<
", " << ambient[1] <<
", " << ambient[2] <<
"]";
350 resultStrm <<
"\nspecular: [" << specular[0] <<
", " << specular[1] <<
", " << specular[2] <<
"]";
351 resultStrm <<
"\nemissive: [" << emissive[0] <<
", " << emissive[1] <<
", " << emissive[2] <<
"]";
353 resultStrm <<
"\nshininess: " << shininess;
354 resultStrm <<
"\nalpha: " << alpha;
364 for (std::map<size_t, Texture>::const_iterator it =
textures_.begin(); it !=
textures_.end(); ++it)
366 resultStrm <<
"\ntexture unit " << it->first <<
": ";
368 switch (it->second.type)
370 case GL_TEXTURE_1D: resultStrm <<
"GL_TEXTURE_1D";
break;
371 case GL_TEXTURE_2D: resultStrm <<
"GL_TEXTURE_2D";
break;
372 case GL_TEXTURE_3D: resultStrm <<
"GL_TEXTURE_3D";
break;
373 #ifdef GL_TEXTURE_RECTANGLE 374 case GL_TEXTURE_RECTANGLE: resultStrm <<
"GL_TEXTURE_RECTANGLE";
break;
376 #ifdef GL_TEXTURE_CUBE_MAP 377 case GL_TEXTURE_CUBE_MAP: resultStrm <<
"GL_TEXTURE_CUBE_MAP";
break;
379 #ifdef GL_TEXTURE_1D_ARRAY 380 case GL_TEXTURE_1D_ARRAY: resultStrm <<
"GL_TEXTURE_1D_ARRAY";
break;
382 #ifdef GL_TEXTURE_2D_ARRAY 383 case GL_TEXTURE_2D_ARRAY: resultStrm <<
"GL_TEXTURE_2D_ARRAY";
break;
385 #ifdef GL_TEXTURE_CUBE_MAP_ARRAY 386 case GL_TEXTURE_CUBE_MAP_ARRAY: resultStrm <<
"GL_TEXTURE_CUBE_MAP_ARRAY";
break;
388 #ifdef GL_TEXTURE_BUFFER 389 case GL_TEXTURE_BUFFER: resultStrm <<
"GL_TEXTURE_BUFFER";
break;
391 #ifdef GL_TEXTURE_2D_MULTISAMPLE 392 case GL_TEXTURE_2D_MULTISAMPLE: resultStrm <<
"GL_TEXTURE_2D_MULTISAMPLE";
break;
394 #ifdef GL_TEXTURE_2D_MULTISAMPLE_ARRAY 395 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: resultStrm <<
"GL_TEXTURE_2D_MULTISAMPLE_ARRAY";
break;
397 default: resultStrm <<
"unknown_type";
break;
400 resultStrm <<
" - id " << it->second.id;
406 if (!uniformPool_.
empty())
407 resultStrm <<
"\n" << uniformPool_.
toString();
440 uniformPool_.
setUniform(_name, _value, _transposed);
443 void RenderObject::setUniformMat3(
const char *_name,
const ACG::GLMatrixf &_value,
bool _transposed )
445 uniformPool_.
setUniform(_name, _value, _transposed);
450 uniformPool_.
setUniform(_name, _values, _count);
455 uniformPool_.
setUniform(_name, _values, _count);
466 shaderDesc.geometryTemplateFile =
"Wireframe/geom_line2quad.tpl";
474 return shaderDesc.geometryTemplateFile ==
"Wireframe/geom_line2quad.tpl" ||
475 (
shaderDesc.geometryTemplateFile ==
"Wireframe/gl42/geometry.tpl" &&
476 shaderDesc.fragmentTemplateFile ==
"Wireframe/gl42/fragment.tpl");
486 shaderDesc.geometryTemplateFile =
"PointSize/geometry.tpl";
487 shaderDesc.fragmentTemplateFile =
"PointSize/fragment.tpl";
495 return shaderDesc.geometryTemplateFile ==
"PointSize/geometry.tpl" &&
496 shaderDesc.fragmentTemplateFile ==
"PointSize/fragment.tpl";
const Vec4f & specular_color() const
get specular color
bool textured() const
Is texturing enabled?
Namespace providing different geometric functions concerning angles.
void clearTextures()
disables texture support and removes all texture types
GLMatrixd proj
Projection transform.
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
void clear()
Clear the pool.
bool inZPrePass
Specify whether this object should be rendered in a z-prepass.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
void ambientColor(const Vec4f &_a)
set the ambient color.
GLenum primitiveMode
Primitive type.
float alphaValue() const
get current alpha value for alpha_test
const char * depthMapUniformName
Uniform name of the depth map in the used shader.
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
unsigned int patchVertices
patch size if primitiveMode is GL_PATCHES for rendering with tessellation shaders ...
static void getBlendFunc(GLenum *_sfactor, GLenum *_dfactor)
get blend function, null-ptr safe
const GLMatrixd & projection() const
get projection matrix
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
GLMatrixd modelview
Modelview transform.
float point_size() const
get point size
void specularColor(const Vec4f &_s)
set the specular color
bool empty() const
returns if the pool is empty
Scalar * data()
access to Scalar array
Vec2f depthRange
glDepthRange: (znear, zmax)
void diffuseColor(const Vec4f &_d)
set the diffuse color.
bool isDefaultLineObject() const
Test if the object is rendered with one of the default line thickness methods.
Vec3f diffuse
material definitions
void addUniformPool(const GLSL::UniformPool &_pool)
add all uniforms from a pool
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
bool flatShaded() const
Is flat shading used (Normals per face)?
bool lighting() const
Is lighting enabled?
VectorT< float, 2 > Vec2f
unsigned int indexOffset
Offset to first index in the index buffer or vertex buffer respectively.
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
unsigned int internalFlags_
may be used internally by the renderer
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) ) ...
bool colored() const
Are colors used?
const Vec4f & base_color() const
get base color (used when lighting is off)
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
void resetPointRendering()
Reset shader template names blocked by point rendering.
void setUniform(const char *_name, GLint _value)
set values for int uniforms
float shininess() const
get specular shininess (must be in [0, 128])
GLuint vertexArrayObject
Use vertex array object.
std::map< size_t, Texture > textures_
holds the textures (second) and the stage id (first)
void resetLineRendering()
Reset shader template names blocked by line rendering.
void addPool(const UniformPool &_src)
Add all uniforms of a pool to this pool.
bool overlay
Layer based rendering.
void addTextureType(GLenum _type, bool _shadow, size_t _stage)
adds a texture type to the shader and enables texturing.
GLenum alphaFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
unsigned int numIndices
Number indices to render.
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
bool alphaTest() const
Return state of Alpha test.
const GLMatrixd & modelview() const
get modelview matrix
ShaderGenDesc shaderDesc
Drawmode and other shader params.
static bool isStateEnabled(GLenum _cap)
returns true, if a cpa state is enabled
GLuint indexBuffer
Use vertex array object.
static void getTexGenMode(GLenum _coord, GLenum _name, GLint *_param)
replaces glVertexPointer, supports locking
GLenum indexType
Index element type.
QString toString() const
convert ShaderGenDesc to string format for debugging
int debugID
used internally for renderer debugging
QString toString() const
print to string for debugging
bool isDefaultPointObject() const
Test if the object is rendered with one of the default point extension methods.
QString vertexNormalInterpolator
interpolation qualifier for vertex shader normal outputs: "flat", "smooth", "noperspective" ...
const Vec4f & diffuse_color() const
get diffuse color
const void * sysmemIndexBuffer
Use system memory index buffer.
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
void shininess(float _s)
set shininess
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
const Vec4f & ambient_color() const
get ambient color
DrawModeProperties stores a set of properties that defines, how to render an object.
int priority
Priority to allow sorting of objects.