Commit a5b5c5fa authored by Martin Schultz's avatar Martin Schultz
Browse files

adopted Coreprofile changes for ACG from QOpenGL branch

specifically:
 initialized glstate properly
 moved various compatibility calls to if branches
 use previous VAO properly in ACG
still to go for the nodes
parent 927827c3
......@@ -118,6 +118,10 @@ GLStateContext::GLStateContext() :
{
framebuffers_[0] = framebuffers_[1] = 0;
memset(drawBufferState_, GL_BACK, sizeof(drawBufferState_));
blendFuncState_[0] = GL_SRC_ALPHA;
blendFuncState_[1] = GL_ONE_MINUS_SRC_ALPHA;
blendFuncState_[2] = GL_SRC_ALPHA;
blendFuncState_[3] = GL_ONE_MINUS_SRC_ALPHA;
}
GLState::GLState(bool _updateGL, bool _compatibilityProfile)
......@@ -273,9 +277,10 @@ void GLState::clearBuffers ()
GLState::disable(GL_DEPTH_TEST);
GLState::disable(GL_DITHER);
glShadeModel( GL_FLAT );
if ( compatibilityProfile_ ) {
glShadeModel(GL_FLAT);
GLState::disable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
......
......@@ -82,8 +82,10 @@ curViewerID_(0),
prevFbo_(0),
prevDrawBuffer_(GL_BACK),
prevFboSaved_(false),
prevVAO_(0),
depthCopyShader_(0),
errorDetectionLevel_(1),
coreProfile_(false),
enableLineThicknessGL42_(false)
{
prevViewport_[0] = 0;
......@@ -537,6 +539,13 @@ void IRenderer::traverseRenderableNodes( ACG::GLState* _glState, ACG::SceneGraph
void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _scenegraphRoot)
{
// save default VAO
#ifdef GL_ARB_vertex_array_object
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &prevVAO_);
#endif
coreProfile_ = !_glState->compatibilityProfile();
// grab view transform from glstate
viewMatrix_ = _glState->modelview();
camPosWS_ = Vec3f( viewMatrix_(0,3), viewMatrix_(1,3), viewMatrix_(2,3) );
......@@ -622,12 +631,14 @@ void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph
// ---------------------------
// gl cleanup
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
if (_glState->compatibilityProfile())
{
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
}
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
......@@ -663,7 +674,7 @@ void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph
void IRenderer::finishRenderingPipeline(bool _drawOverlay)
{
#ifdef GL_ARB_vertex_array_object
glBindVertexArray(0);
glBindVertexArray(prevVAO_);
#endif
// draw thick lines
......@@ -719,7 +730,7 @@ void IRenderer::finishRenderingPipeline(bool _drawOverlay)
}
#ifdef GL_ARB_vertex_array_object
glBindVertexArray(0);
glBindVertexArray(prevVAO_);
#endif
for (int i = 0; i < maxClipDistances_; ++i)
......@@ -732,8 +743,8 @@ void IRenderer::finishRenderingPipeline(bool _drawOverlay)
glUseProgram(0);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// Renderer check:
// Print a warning if the currently active fbo / viewport is not the same as the saved fbo.
......@@ -876,7 +887,8 @@ void IRenderer::bindObjectVBO(ACG::RenderObject* _obj,
#ifdef GL_ARB_vertex_array_object
glBindVertexArray(_obj->vertexArrayObject);
if (_obj->vertexArrayObject)
glBindVertexArray(_obj->vertexArrayObject);
#endif
if (!_obj->vertexArrayObject)
......@@ -885,8 +897,8 @@ void IRenderer::bindObjectVBO(ACG::RenderObject* _obj,
// 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);
glBindBuffer(GL_ARRAY_BUFFER, _obj->vertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _obj->indexBuffer);
// activate vertex declaration
......@@ -1017,13 +1029,16 @@ void IRenderer::bindObjectRenderStates(ACG::RenderObject* _obj)
else
glDisable(GL_BLEND);
if (_obj->alphaTest)
if (!coreProfile_)
{
glEnable(GL_ALPHA_TEST);
glAlphaFunc(_obj->alphaFunc, _obj->alphaRef);
if (_obj->alphaTest)
{
glEnable(GL_ALPHA_TEST);
glAlphaFunc(_obj->alphaFunc, _obj->alphaRef);
}
else
glDisable(GL_ALPHA_TEST);
}
else
glDisable(GL_ALPHA_TEST);
if (_obj->depthTest)
glEnable(GL_DEPTH_TEST);
......@@ -1162,7 +1177,7 @@ void IRenderer::renderObject(ACG::RenderObject* _obj,
#ifdef GL_ARB_vertex_array_object
if (_obj->vertexArrayObject)
glBindVertexArray(0);
glBindVertexArray(prevVAO_);
#endif
}
......
......@@ -480,6 +480,14 @@ public:
*/
void setViewerID(int _viewerID);
/** \brief Tell renderer to use core or compatibility profile
*
* @param _enable renderer should use opengl in core profile mode
*/
void setCoreProfileMode(bool _enable) {coreProfile_ = _enable;}
/**
* During traversal of the scene graph this method returns the range of
* render objects that has been collected in the current subtree.
......@@ -560,12 +568,20 @@ protected:
/// flag indicating a that saveCurrentFbo() has been called prior restoreFbo()
bool prevFboSaved_;
/// previously bound VAO
GLint prevVAO_;
/// shader copies depth of the first front layer to the back buffer
GLSL::Program* depthCopyShader_;
/// error-detection level for checking render objects
int errorDetectionLevel_;
/// core profile mode
bool coreProfile_;
/// max number of clip distance outputs in a vertex shader
static int maxClipDistances_;
......
......@@ -1142,7 +1142,9 @@ void QtBaseViewer::initializeGL()
ACG::GLState::enable(GL_DEPTH_TEST);
ACG::GLState::enable(GL_LIGHTING);
ACG::GLState::disable(GL_DITHER);
ACG::GLState::shadeModel( GL_FLAT );
if (glstate_->compatibilityProfile())
ACG::GLState::shadeModel( GL_FLAT );
projectionMode( projectionMode_ );
......@@ -1291,7 +1293,9 @@ void QtBaseViewer::paintGL()
ACG::GLState::enable(GL_DEPTH_TEST);
ACG::GLState::enable(GL_LIGHTING);
ACG::GLState::disable(GL_DITHER);
ACG::GLState::shadeModel( GL_FLAT );
if (glstate_->compatibilityProfile())
ACG::GLState::shadeModel( GL_FLAT );
glMatrixMode(GL_PROJECTION);
glPushMatrix();
......
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