Commit 297099e8 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

add support for opengl vertex array objects

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@19788 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3ab3e8c5
......@@ -103,7 +103,7 @@ IRenderer::~IRenderer()
void IRenderer::addRenderObject(ACG::RenderObject* _renderObject)
{
// do some more checks for error detection
if (!_renderObject->vertexDecl)
if (!_renderObject->vertexDecl && !_renderObject->vertexArrayObject)
std::cout << "error: missing vertex declaration in renderobject: " << _renderObject->debugName << std::endl;
else
{
......@@ -208,27 +208,29 @@ void IRenderer::addRenderObject(ACG::RenderObject* _renderObject)
}
}
// Why are there gl errors and/or nothing gets drawn?
if (_renderObject->shaderDesc.shadeMode != SG_SHADE_UNLIT)
if (!_renderObject->vertexArrayObject)
{
// check for normals
if (!_renderObject->vertexDecl->findElementByUsage(VERTEX_USAGE_NORMAL))
std::cout << "warning: missing normals for lighting in renderobject: " << _renderObject->debugName << std::endl;
}
// Why are there gl errors and/or nothing gets drawn?
if (_renderObject->shaderDesc.shadeMode != SG_SHADE_UNLIT)
{
// check for normals
if (!_renderObject->vertexDecl->findElementByUsage(VERTEX_USAGE_NORMAL))
std::cout << "warning: missing normals for lighting in renderobject: " << _renderObject->debugName << std::endl;
}
if (_renderObject->shaderDesc.textured())
{
// check for texcoords
if (!_renderObject->vertexDecl->findElementByUsage(VERTEX_USAGE_TEXCOORD))
std::cout << "warning: missing texcoords for textured mode in renderobject: " << _renderObject->debugName << std::endl;
}
if (_renderObject->shaderDesc.textured())
{
// check for texcoords
if (!_renderObject->vertexDecl->findElementByUsage(VERTEX_USAGE_TEXCOORD))
std::cout << "warning: missing texcoords for textured mode in renderobject: " << _renderObject->debugName << std::endl;
}
if (_renderObject->shaderDesc.vertexColors)
{
// check for vertex colors
if (!_renderObject->vertexDecl->findElementByUsage(VERTEX_USAGE_COLOR))
std::cout << "warning: missing colors for vertexcolor mode in renderobject: " << _renderObject->debugName << std::endl;
if (_renderObject->shaderDesc.vertexColors)
{
// check for vertex colors
if (!_renderObject->vertexDecl->findElementByUsage(VERTEX_USAGE_COLOR))
std::cout << "warning: missing colors for vertexcolor mode in renderobject: " << _renderObject->debugName << std::endl;
}
}
......@@ -524,6 +526,10 @@ void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph
void IRenderer::finishRenderingPipeline(bool _drawOverlay)
{
#ifdef GL_ARB_vertex_array_object
glBindVertexArray(0);
#endif
// draw thick lines
if (enableLineThicknessGL42_)
renderLineThicknessGL42();
......@@ -576,6 +582,10 @@ void IRenderer::finishRenderingPipeline(bool _drawOverlay)
}
#ifdef GL_ARB_vertex_array_object
glBindVertexArray(0);
#endif
glDepthMask(1);
glColorMask(1,1,1,1);
......@@ -684,16 +694,25 @@ void IRenderer::bindObjectVBO(ACG::RenderObject* _obj,
{
_prog->use();
//////////////////////////////////////////////////////////////////////////
// NOTE:
// always bind buffers before glVertexAttribPointer calls!!
// freeze in glDrawElements guaranteed (with no error message whatsoever)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _obj->vertexBuffer);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _obj->indexBuffer);
#ifdef GL_ARB_vertex_array_object
glBindVertexArray(_obj->vertexArrayObject);
#endif
if (!_obj->vertexArrayObject)
{
//////////////////////////////////////////////////////////////////////////
// NOTE:
// always bind buffers before glVertexAttribPointer calls!!
// freeze in glDrawElements guaranteed (with no error message whatsoever)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, _obj->vertexBuffer);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _obj->indexBuffer);
// activate vertex declaration
_obj->vertexDecl->activateShaderPipeline(_prog);
// activate vertex declaration
_obj->vertexDecl->activateShaderPipeline(_prog);
}
}
......@@ -907,8 +926,17 @@ void IRenderer::renderObject(ACG::RenderObject* _obj,
ACG::glCheckErrors();
// deactivate vertex declaration to avoid errors
_obj->vertexDecl->deactivateShaderPipeline(prog);
if (_obj->vertexDecl)
{
// deactivate vertex declaration to avoid errors
_obj->vertexDecl->deactivateShaderPipeline(prog);
}
#ifdef GL_ARB_vertex_array_object
if (_obj->vertexArrayObject)
glBindVertexArray(0);
#endif
}
......
......@@ -174,6 +174,7 @@ RenderObject::RenderObject()
overlay(false),
modelview(GLMatrixf(ACG::Vec3f(1.0,0.0,0.0),ACG::Vec3f(0.0,1.0,0.0),ACG::Vec3f(0.0,0.0,1.0))),
proj(modelview),
vertexArrayObject(0),
vertexBuffer(0), indexBuffer(0), sysmemIndexBuffer(0),
primitiveMode(GL_TRIANGLES), numIndices(0), indexOffset(0), indexType(GL_UNSIGNED_INT),
vertexDecl(0),
......@@ -260,7 +261,8 @@ QString RenderObject::toString() const
<< "\nindexOffset: " << indexOffset;
resultStrm << "\nvbo-id: " << vertexBuffer
resultStrm << "\nvao-id: " << vertexArrayObject
<< "\nvbo-id: " << vertexBuffer
<< "\nibo-id: " << indexBuffer
<< "\nsysmemIndexBuffer: " << sysmemIndexBuffer;
......
......@@ -143,7 +143,18 @@ struct ACGDLLEXPORT RenderObject
* @{ */
//===========================================================================
/// VBO, IBO ids
/** \brief Use vertex array object
*
* Optionally, a VAO can be used to setup rendering buffers and attribute locations.
* If this is 0 (default), vertex-buffer, index-buffer, vertex-declarition etc. have to be provided individually.
* Otherwise, the VAO is used instead of vertexBuffer, indexBuffer etc.
* In this case, it is not neccessary to specify a vertex-declaration and provide vertex- and indexbuffer.
* This is also the only way to setup a renderobject that makes use of multiple vertexbuffers!
*/
GLuint vertexArrayObject;
/// VBO, IBO ids, ignored if VAO is provided
GLuint vertexBuffer,
indexBuffer;
......@@ -179,7 +190,7 @@ struct ACGDLLEXPORT RenderObject
GLenum indexType;
/// Defines the vertex buffer layout
/// Defines the vertex buffer layout, ignored if VAO is provided
const VertexDeclaration* vertexDecl;
/** @} */
......
Markdown is supported
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