Commit 1bc851f7 authored by Andreas Neu's avatar Andreas Neu

Usage of static GL Contexts in basic OpenGL Objects incorporated.

Until now only the class Texture used it. Now it has been added to ElementArrayBuffer, ArrayBuffer, FrameBuffer and ShaderProgram.
Static class members have to be initialized outside the header, so the file ElementArrayBuffer.cc had to be added.
Unbind calls e.g. glBindBuffer(GL_ARRAY_BUFFER, 0) outside of the specific class are not useful anymore, because it
would not reset the static context variable and thus lead to bugs/crashes.
parent e178f74a
......@@ -59,7 +59,7 @@ public:
{
elementArrayBuffer->bind();
elementArrayBuffer->setData(mpData, mElements);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
return elementArrayBuffer;
}
......
......@@ -20,6 +20,12 @@ namespace OpenGL{
class ArrayBuffer
{
// ======================================================================================================== \/
// ============================================================================================ GPU CONTEXT \/
// ======================================================================================================== \/
private:
static GLuint sArrayBufferContext;
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
// ==================================================================================================== \/
......@@ -123,7 +129,11 @@ public:
//! Bind this buffer
inline void bind(void) const
{
if(sArrayBufferContext == mContext)
return;
glBindBuffer(GL_ARRAY_BUFFER, mContext);
sArrayBufferContext = mContext;
}
inline void setPointer(AttributeVec::size_type _indexInArray, GLuint _indexInShader) const
......
......@@ -18,6 +18,11 @@ namespace OpenGL{
class ElementArrayBuffer
{
// ======================================================================================================== \/
// ============================================================================================ GPU CONTEXT \/
// ======================================================================================================== \/
private:
static GLuint sElementArrayBufferContext;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
......@@ -77,7 +82,11 @@ public:
//! Bind this buffer
inline void bind(void) const
{
if(sElementArrayBufferContext == mContext)
return;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mContext);
sElementArrayBufferContext = mContext;
}
void draw(void) const
......
......@@ -38,6 +38,12 @@ namespace OpenGL{
class FrameBuffer
{
// ======================================================================================================== \/
// ============================================================================================ GPU CONTEXT \/
// ======================================================================================================== \/
private:
static GLuint sFrameBufferContext;
// =================================================================================================== \/
// ============================================================================================ STATIC \/
// =================================================================================================== \/
......@@ -125,8 +131,12 @@ public:
*/
inline void bind( TargetType _type = READ_DRAW_FRAMEBUFFER ) const
{
if(sFrameBufferContext == mContext)
return;
glBindFramebuffer(_type, mContext);
openGLRareError(); // glBindFramebuffer can only fail if the contect is no valid FBO which shouldn't happen using this framework
sFrameBufferContext = mContext;
}
inline void setDrawBuffers(void) const
......
......@@ -22,6 +22,12 @@ namespace OpenGL{
class ShaderProgram
{
// ======================================================================================================== \/
// ============================================================================================ GPU CONTEXT \/
// ======================================================================================================== \/
private:
static GLuint sShaderProgramContext;
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
......@@ -87,7 +93,14 @@ public:
inline void setTexture (GLint _location, const SharedTexture& _texture, GLenum _unit = 0) const { glUniform1i(_location, _unit); _texture->bind(_unit); }
inline void use (void) const { glUseProgram(mContext); }
inline void use (void) const
{
if(sShaderProgramContext == mContext)
return;
glUseProgram(mContext);
sShaderProgramContext = mContext;
}
inline GLint getUniformLocation( const char *_name ) const { return glGetUniformLocation( mContext, _name ); }
......
......@@ -23,7 +23,7 @@ SharedArrayBuffer ArrayBufferControl::create(void)
{
arrayBuffer->bind();
arrayBuffer->setData(mpData, mElements);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//glBindBuffer(GL_ARRAY_BUFFER, 0);
}
return arrayBuffer;
}
......@@ -310,10 +310,10 @@ bool VertexBufferControlFileOBJ::loadOBJ(SharedVertexBuffer& _vertexBuffer)
elementArrayBuffer->setType(indexType);
elementArrayBuffer->bind();
elementArrayBuffer->setData(&indexVector[0], indexVector.size());
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
arrayBuffer->bind();
arrayBuffer->setData(&interleavedDataVector[0], index);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//glBindBuffer(GL_ARRAY_BUFFER, 0);
_vertexBuffer->setElements(indexVector.size());
return true;
......
......@@ -8,6 +8,8 @@
using namespace ACGL;
using namespace ACGL::OpenGL;
GLuint ArrayBuffer::sArrayBufferContext = 0;
int_t ArrayBuffer::getAttributeIndexByName(const std::string& _nameInArray) const
{
for(AttributeVec::size_type i = 0; i < mAttributes.size(); ++i)
......@@ -31,5 +33,5 @@ void ArrayBuffer::render(void) const
glDisableVertexAttribArray(i);
openGLRareError();
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
//glBindBuffer(GL_ARRAY_BUFFER, 0);
}
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Objects/ElementArrayBuffer.hh>
using namespace ACGL;
using namespace ACGL::OpenGL;
GLuint ElementArrayBuffer::sElementArrayBufferContext = 0;
......@@ -7,6 +7,8 @@
using namespace ACGL::OpenGL;
GLuint FrameBuffer::sFrameBufferContext = 0;
/*
* We can't use the constants GL_COLOR_ATTACHMENT1 to GL_COLOR_ATTACHMENT7 here
* because OpenGL ES does not know these yet.
......
......@@ -10,6 +10,8 @@ using namespace ACGL::OpenGL;
using namespace ACGL::Base;
using namespace ACGL::Utils;
GLuint ShaderProgram::sShaderProgramContext = 0;
void ShaderProgram::bindAttributeLocations() const
{
for (SharedShaderVec::size_type i = 0; i < mShaders.size(); ++i)
......
......@@ -48,7 +48,9 @@ void VertexBuffer::render(void) const
openGLRareError();
}
/*
if(mpElementArrayBuffer)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
*/
}
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