Commit 4a911c05 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

add patch-size property to renderobjects for the tessellation stage

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20622 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c8d9aa88
......@@ -250,6 +250,53 @@ void IRenderer::addRenderObject(ACG::RenderObject* _renderObject)
// Why is alpha blending not work?
if (fabsf(_renderObject->alpha - 1.0f) > 1e-3f && !(_renderObject->alphaTest || _renderObject->blending))
std::cout << "warning: alpha value != 1 but no alpha blending or testing enabled in renderobject: " << _renderObject->debugName << std::endl;
#ifdef GL_ARB_tessellation_shader
// Trying to render with tessellation shaders?
const bool tessellationActive = !_renderObject->shaderDesc.tessControlTemplateFile.isEmpty() || !_renderObject->shaderDesc.tessEvaluationTemplateFile.isEmpty();
bool tryToFixPatchInfo = false;
if (tessellationActive && _renderObject->primitiveMode != GL_PATCHES)
{
std::cout << "error: tessellation shaders are not used with GL_PATCHES primitiveType in renderobject: " << _renderObject->debugName << std::endl;
tryToFixPatchInfo = true;
}
if (tessellationActive && !_renderObject->patchVertices)
{
std::cout << "error: undefined patch size for tessellation in renderobject: " << _renderObject->debugName << std::endl;
tryToFixPatchInfo = true;
}
if (tryToFixPatchInfo)
{
if (_renderObject->primitiveMode == GL_POINTS)
{
_renderObject->primitiveMode = GL_PATCHES;
_renderObject->patchVertices = 1;
std::cout << "warning: attempting to draw with patchVertices = 1 for tessellation in renderobject: " << _renderObject->debugName << std::endl;
}
else if (_renderObject->primitiveMode == GL_LINES)
{
_renderObject->primitiveMode = GL_PATCHES;
_renderObject->patchVertices = 2;
std::cout << "warning: attempting to draw with patchVertices = 2 for tessellation in renderobject: " << _renderObject->debugName << std::endl;
}
else if (_renderObject->primitiveMode == GL_TRIANGLES)
{
_renderObject->primitiveMode = GL_PATCHES;
_renderObject->patchVertices = 3;
std::cout << "warning: attempting to draw with patchVertices = 3 for tessellation in renderobject: " << _renderObject->debugName << std::endl;
}
else if (_renderObject->primitiveMode == GL_QUADS)
{
_renderObject->primitiveMode = GL_PATCHES;
_renderObject->patchVertices = 4;
std::cout << "warning: attempting to draw with patchVertices = 4 for tessellation in renderobject: " << _renderObject->debugName << std::endl;
}
}
#endif
}
......@@ -889,6 +936,24 @@ void IRenderer::drawObject(ACG::RenderObject* _obj)
glPolygonMode(GL_FRONT_AND_BACK, _obj->fillMode);
// tessellation info
bool tessellationActive = !(_obj->shaderDesc.tessControlTemplateFile.isEmpty() && _obj->shaderDesc.tessEvaluationTemplateFile.isEmpty());
#ifdef GL_ARB_tessellation_shader
if (tessellationActive)
{
glPatchParameteri(GL_PATCH_VERTICES, _obj->patchVertices);
if (_obj->shaderDesc.tessControlTemplateFile.isEmpty())
{
glPatchParameterfv(GL_PATCH_DEFAULT_INNER_LEVEL, _obj->patchDefaultInnerLevel.data());
glPatchParameterfv(GL_PATCH_DEFAULT_OUTER_LEVEL, _obj->patchDefaultOuterLevel.data());
}
}
#else
if (tessellationActive)
std::cout << "error: tessellation shaders cannot be used with the outdated glew version" << std::endl;
#endif
if (noIndices) {
if (_obj->numInstances <= 0)
glDrawArrays(_obj->primitiveMode, _obj->indexOffset, _obj->numIndices);
......
......@@ -176,7 +176,7 @@ RenderObject::RenderObject()
proj(modelview),
vertexArrayObject(0),
vertexBuffer(0), indexBuffer(0), sysmemIndexBuffer(0),
primitiveMode(GL_TRIANGLES), numIndices(0), indexOffset(0), indexType(GL_UNSIGNED_INT),
primitiveMode(GL_TRIANGLES), patchVertices(0), numIndices(0), indexOffset(0), indexType(GL_UNSIGNED_INT),
numInstances(0),
vertexDecl(0),
culling(true), blending(false), alphaTest(false),
......@@ -186,6 +186,9 @@ RenderObject::RenderObject()
blendSrc(GL_SRC_ALPHA), blendDest(GL_ONE_MINUS_SRC_ALPHA),
depthRange(0.0f, 1.0f),
patchDefaultInnerLevel(1.0f, 1.0f),
patchDefaultOuterLevel(1.0f, 1.0f, 1.0f, 1.0f),
diffuse(0.6f, 0.6f, 0.6f), ambient(0.1f, 0.1f, 0.1f),
specular(0.0f, 0.0f, 0.0f), emissive(0.05f, 0.05f, 0.05f),
alpha(1.0f), shininess(100.0f),
......@@ -222,7 +225,8 @@ QString RenderObject::toString() const
"GL_LINES_ADJACENCY",
"GL_LINE_STRIP_ADJACENCY",
"GL_TRIANGLES_ADJACENCY",
"GL_TRIANGLE_STRIP_ADJACENCY"
"GL_TRIANGLE_STRIP_ADJACENCY",
"GL_PATCHES"
};
const char* fillModeString[] =
......@@ -247,21 +251,29 @@ QString RenderObject::toString() const
QString result;
QTextStream resultStrm(&result);
resultStrm << "name: " << debugName
<< "\ndebugID: " << debugID
<< "\npriority: " << priority
#ifdef ARCH_DARWIN
<< "\nprimitiveMode: " << (primitiveMode <= GL_POLYGON ? primitiveString[primitiveMode] : "undefined")
#if !defined(GL_VERSION_3_2)
const GLenum maxSupportedPrimitiveMode = GL_POLYGON;
#elif !defined(GL_ARB_tessellation_shader)
const GLenum maxSupportedPrimitiveMode = GL_TRIANGLE_STRIP_ADJACENCY;
#else
<< "\nprimitiveMode: " << (primitiveMode <= GL_TRIANGLE_STRIP_ADJACENCY ? primitiveString[primitiveMode] : "undefined")
const GLenum maxSupportedPrimitiveMode = GL_PATCHES;
#endif
resultStrm << "name: " << debugName
<< "\ndebugID: " << debugID
<< "\npriority: " << priority
<< "\nprimitiveMode: " << (primitiveMode <= maxSupportedPrimitiveMode ? primitiveString[primitiveMode] : "undefined")
<< "\nfillMode: " << fillModeString[fillMode - GL_POINT]
<< "\nnumIndices: " << numIndices
<< "\nindexOffset: " << indexOffset;
#ifdef GL_ARB_tessellation_shader
if (primitiveMode == GL_PATCHES)
resultStrm << "\npatchVertices: " << patchVertices;
#endif
resultStrm << "\nvao-id: " << vertexArrayObject
<< "\nvbo-id: " << vertexBuffer
<< "\nibo-id: " << indexBuffer
......@@ -388,6 +400,11 @@ bool RenderObject::isDefaultLineObject() const
shaderDesc.fragmentTemplateFile == "Wireframe/gl42/fragment.tpl");
}
void RenderObject::resetLineRendering()
{
shaderDesc.geometryTemplateFile.clear();
}
void RenderObject::setupPointRendering( float _pointSize, const Vec2f& _screenSize )
{
shaderDesc.geometryTemplateFile = "PointSize/geometry.tpl";
......@@ -403,6 +420,11 @@ bool RenderObject::isDefaultPointObject() const
shaderDesc.fragmentTemplateFile == "PointSize/fragment.tpl";
}
void RenderObject::resetPointRendering()
{
shaderDesc.geometryTemplateFile.clear();
shaderDesc.fragmentTemplateFile.clear();
}
......
......@@ -177,10 +177,13 @@ struct ACGDLLEXPORT RenderObject
* PrimitiveType must be one of the following:
* GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP,
* GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS, GL_POLYGON,
* GL_TRIANGLES_ADJACENCY, GL_LINES_ADJACENCY
* GL_TRIANGLES_ADJACENCY, GL_LINES_ADJACENCY, GL_PATCHES
*/
GLenum primitiveMode;
/// patch size if primitiveMode is GL_PATCHES for rendering with tessellation shaders
unsigned int patchVertices; // GL_PATCH_VERTICES
/// Number indices to render
unsigned int numIndices;
......@@ -245,6 +248,13 @@ struct ACGDLLEXPORT RenderObject
Vec2f depthRange; //!< glDepthRange: (znear, zmax)
// ---------------------------
// default tessellation lod, if only a tess-eval, but no tess-control shader is specified
// this is ignored otherwise
Vec2f patchDefaultInnerLevel; // GL_PATCH_DEFAULT_INNER_LEVEL
Vec4f patchDefaultOuterLevel; // GL_PATCH_DEFAULT_OUTER_LEVEL
// ---------------------------
/// material definitions
Vec3f diffuse,
......@@ -423,6 +433,9 @@ public:
/// Test if the object is rendered with one of the default line thickness methods
bool isDefaultLineObject() const;
/// Reset shader template names blocked by line rendering
void resetLineRendering();
/** \brief Setup rendering of circle points
*
* Use default quad extrusion shader.
......@@ -434,6 +447,9 @@ public:
/// Test if the object is rendered with one of the default point extension methods
bool isDefaultPointObject() const;
/// Reset shader template names blocked by point rendering
void resetPointRendering();
/** Returns a text representation of the RenderObject for debugging purposes.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment