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)
202 vertexArrayObject(0),
203 vertexBuffer(0), indexBuffer(0), sysmemIndexBuffer(0),
204 primitiveMode(GL_TRIANGLES), patchVertices(0), numIndices(0), indexOffset(0), indexType(GL_UNSIGNED_INT),
207 culling(true), blending(false), alphaTest(false),
208 depthTest(true), depthWrite(true),
209 fillMode(GL_FILL), depthFunc(GL_LESS),
210 alphaFunc(GL_ALWAYS), alphaRef(0.0f),
211 blendSrc(GL_SRC_ALPHA), blendDest(GL_ONE_MINUS_SRC_ALPHA),
212 depthRange(0.0f, 1.0f),
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),
227 depthMapUniformName(0),
232 colorWriteMask[0] = colorWriteMask[1] = colorWriteMask[2] = colorWriteMask[3] = 1;
235RenderObject::~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
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);
443void 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
const GLMatrixd & modelview() const
get modelview matrix
const Vec4f & base_color() const
get base color (used when lighting is off)
static void getBlendFunc(GLenum *_sfactor, GLenum *_dfactor)
get blend function, null-ptr safe
const GLMatrixd & projection() const
get projection matrix
const Vec4f & ambient_color() const
get ambient color
static void getTexGenMode(GLenum _coord, GLenum _name, GLint *_param)
replaces glVertexPointer, supports locking
static bool isStateEnabled(GLenum _cap)
returns true, if a cpa state is enabled
const Vec4f & diffuse_color() const
get diffuse color
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
float shininess() const
get specular shininess (must be in [0, 128])
float point_size() const
get point size
DrawModeProperties stores a set of properties that defines, how to render an object.
bool colored() const
Are colors used?
bool textured() const
Is texturing enabled?
bool flatShaded() const
Is flat shading used (Normals per face)?
bool lighting() const
Is lighting enabled?
void shininess(float _s)
set shininess
bool alphaTest() const
Return state of Alpha test.
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) )
void specularColor(const Vec4f &_s)
set the specular color
void ambientColor(const Vec4f &_a)
set the ambient color.
float alphaValue() const
get current alpha value for alpha_test
void diffuseColor(const Vec4f &_d)
set the diffuse color.
QString vertexNormalInterpolator
interpolation qualifier for vertex shader normal outputs: "flat", "smooth", "noperspective"
void addTextureType(GLenum _type, bool _shadow, size_t _stage)
adds a texture type to the shader and enables texturing.
QString toString() const
convert ShaderGenDesc to string format for debugging
void clearTextures()
disables texture support and removes all texture types
Scalar * data()
access to Scalar array
Namespace providing different geometric functions concerning angles.
VectorT< float, 2 > Vec2f
int debugID
used internally for renderer debugging
const char * depthMapUniformName
Uniform name of the depth map in the used shader.
Vec3f diffuse
material definitions
ShaderGenDesc shaderDesc
Drawmode and other shader params.
bool isDefaultLineObject() const
Test if the object is rendered with one of the default line thickness methods.
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
GLuint vertexArrayObject
Use vertex array object.
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
const void * sysmemIndexBuffer
Use system memory index buffer.
void resetLineRendering()
Reset shader template names blocked by line rendering.
void resetPointRendering()
Reset shader template names blocked by point rendering.
GLuint indexBuffer
Use vertex array object.
int priority
Priority to allow sorting of objects.
unsigned int numIndices
Number indices to render.
GLMatrixd modelview
Modelview transform.
GLMatrixd proj
Projection transform.
std::map< size_t, Texture > textures_
holds the textures (second) and the stage id (first)
bool inZPrePass
Specify whether this object should be rendered in a z-prepass.
unsigned int indexOffset
Offset to first index in the index buffer or vertex buffer respectively.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
bool isDefaultPointObject() const
Test if the object is rendered with one of the default point extension methods.
GLenum primitiveMode
Primitive type.
GLenum alphaFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
void setUniform(const char *_name, GLint _value)
set values for int uniforms
unsigned int patchVertices
patch size if primitiveMode is GL_PATCHES for rendering with tessellation shaders
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
unsigned int internalFlags_
may be used internally by the renderer
Vec2f depthRange
glDepthRange: (znear, zmax)
void addUniformPool(const GLSL::UniformPool &_pool)
add all uniforms from a pool
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
GLenum depthFunc
GL_LESS, GL_LEQUAL, GL_GREATER ..
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.