Commit 257a0859 authored by Robert Menzel's avatar Robert Menzel
Browse files

Improved OpenGL core profile compatibility and added optional error checks

* GLEW is not core profile campatible, new ACGL::init() code tries to work around that
  NOTE: on core profile systems (like OSX 10.7 Lion) no extension will be detected by GLEW
* Added some optional error checks that helped finding compatibility errors
parent 77fb0374
......@@ -117,17 +117,20 @@ public:
void draw(void) const
{
glDrawArrays(mMode, 0, mElements);
openGLRareError();
}
void draw(GLint _first, GLsizei _count) const
{
glDrawArrays(mMode, _first, _count);
openGLRareError();
}
//! Bind this buffer
inline void bind(void) const
{
glBindBuffer(GL_ARRAY_BUFFER, mContext);
openGLRareError();
}
inline void setAttributePointer(AttributeVec::size_type _indexInArray, GLuint _indexInShader) const
......@@ -139,6 +142,7 @@ public:
mAttributes[_indexInArray].normalized,
mStride,
reinterpret_cast<GLvoid*>(mAttributes[_indexInArray].offset));
openGLRareError();
}
inline bool setAttributePointer(const std::string& _nameInArray, GLuint _indexInShader) const
......
......@@ -86,11 +86,13 @@ public:
void draw(GLint _first, GLsizei _count) const
{
glDrawElements(mMode, _count, mType, reinterpret_cast<GLvoid*>(_first));
openGLRareError();
}
void draw(void) const
{
glDrawElements(mMode, mElements, mType, (GLvoid*)0);
openGLRareError();
}
//! Set data for this buffer
......
......@@ -17,11 +17,27 @@ bool init(void)
// init GLEW
//
#ifdef ACGL_USE_GLEW
glewInit();
if (openGLCriticalErrorOccured()) {
Utils::error() << "could not init GLEW!" << std::endl;
return false;
}
# ifdef ACGL_OPENGL_PROFILE_CORE
glewExperimental = TRUE;
GLenum errorCode = glewInit();
glGetError(); // just to get silently rid of the invalid enum that's quite normal for glew on core context :-(
if (errorCode != GLEW_OK)
{
Utils::error() << "could not init GLEW!" << std::endl;
}
// create a vertex array object
// needed on core profile
GLuint vao;
glGenVertexArrays(1,&vao);
glBindVertexArray(vao);
# else
GLenum errorCode = glewInit();
if ((errorCode != GLEW_OK) || (openGLCriticalErrorOccured())) {
Utils::error() << "could not init GLEW!" << std::endl;
return false;
}
# endif
#endif
//
......
......@@ -47,10 +47,12 @@ void RenderObject::bindFrameBufferObject (void) const
{
mpFrameBufferObject->bind();
glDrawBuffers(mpFrameBufferObject->getColorAttachments().size(), mpDrawBuffers);
openGLRareError();
}
else
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
openGLRareError();
}
}
......@@ -75,6 +77,7 @@ void RenderObject::enableVertexBufferObject (void) const
}
mpVertexBufferObject->setAttributePointer(mpVertexBufferObject->getAttributes()[mAttributeMappings[i].attributeID].attributeID, mAttributeMappings[i].attributeLocation);
glEnableVertexAttribArray(mAttributeMappings[i].attributeLocation);
openGLRareError();
}
}
......@@ -89,5 +92,6 @@ void RenderObject::disableVertexBufferObject (void) const
currentArrayBufferID = mpVertexBufferObject->getAttributes()[mAttributeMappings[i].attributeID].bufferID;
}
glDisableVertexAttribArray(mAttributeMappings[i].attributeLocation);
openGLRareError();
}
}
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