Skip to content
Snippets Groups Projects
Commit 08ebdf6c authored by Robert Menzel's avatar Robert Menzel
Browse files

fixed FBO controller, more robust UniformBlock binding setting

parent 7d2def5a
No related branches found
No related tags found
No related merge requests found
......@@ -48,13 +48,13 @@ public:
inline FrameBufferObjectControl& colorTexture(const std::string& _name, const ConstSharedTexture& _texture)
{
FrameBufferObject::Attachment attachment = {_name, _texture, SharedRenderBuffer()};
FrameBufferObject::Attachment attachment = {_name, _texture, SharedRenderBuffer(), (GLuint) mColorAttachments.size()};
mColorAttachments.push_back(attachment);
return *this;
}
inline FrameBufferObjectControl& colorRenderBuffer(const std::string& _name, const ConstSharedRenderBuffer& _renderBuffer)
{
FrameBufferObject::Attachment attachment = {_name, SharedTexture(), _renderBuffer};
FrameBufferObject::Attachment attachment = {_name, SharedTexture(), _renderBuffer, (GLuint) mColorAttachments.size()};
mColorAttachments.push_back(attachment);
return *this;
}
......
......@@ -122,26 +122,30 @@ public:
#if (ACGL_OPENGL_VERSION >= 31)
//! if the block name does not exist, GL_INVALID_INDEX will get returned
inline GLuint getUniformBlockIndex (const std::string& _nameInShader) { return glGetUniformBlockIndex(mObjectName, _nameInShader.c_str()); }
//! binds a uniform block
inline void setUniformBlockBinding( GLuint _blockIndex, GLuint _bindingPoint ) { glUniformBlockBinding( mObjectName, _blockIndex, _bindingPoint ); }
inline void setUniformBlockBinding( const std::string& _blockName, GLuint _bindingPoint ) { glUniformBlockBinding( mObjectName, getUniformBlockIndex(_blockName), _bindingPoint ); }
inline GLuint getUniformBlockIndex (const std::string& _nameInShader) const { return glGetUniformBlockIndex(mObjectName, _nameInShader.c_str()); }
//! binds a uniform block, the string version will ignore a non-existent block
inline void setUniformBlockBinding( GLuint _blockIndex, GLuint _bindingPoint ) const { glUniformBlockBinding( mObjectName, _blockIndex, _bindingPoint ); openGLCommonErrorOccured(); }
inline void setUniformBlockBinding( const std::string& _blockName, GLuint _bindingPoint ) const {
GLuint blockIndex = getUniformBlockIndex(_blockName);
if (blockIndex != GL_INVALID_INDEX) glUniformBlockBinding( mObjectName, blockIndex, _bindingPoint );
openGLCommonErrorOccured();
}
GLint getUniformBlockBinding( const std::string& _blockName ) { return getUniformBlockBinding( getUniformBlockIndex(_blockName)); }
GLint getUniformBlockBinding( GLuint _blockIndex ) {
GLint getUniformBlockBinding( const std::string& _blockName ) const { return getUniformBlockBinding( getUniformBlockIndex(_blockName)); }
GLint getUniformBlockBinding( GLuint _blockIndex ) const {
GLint bindingPoint;
glGetActiveUniformBlockiv( mObjectName, _blockIndex, GL_UNIFORM_BLOCK_BINDING, &bindingPoint );
return bindingPoint;
}
//! returns a mapping from the uniforms in a given block to the offset within the block
SharedLocationMappings getUniformOffsetsOfBlock( const std::string &_blockName ) { return getUniformOffsetsOfBlock(getUniformBlockIndex(_blockName)); }
SharedLocationMappings getUniformOffsetsOfBlock( GLuint _blockIndex );
SharedLocationMappings getUniformOffsetsOfBlock( const std::string &_blockName ) const { return getUniformOffsetsOfBlock(getUniformBlockIndex(_blockName)); }
SharedLocationMappings getUniformOffsetsOfBlock( GLuint _blockIndex ) const;
//! returns the size in bytes of the uniform block, can be used to allocate the right amount of memory
GLsizeiptr getUniformBlockSize( const std::string &_blockName ) { return getUniformBlockSize(getUniformBlockIndex(_blockName)); }
GLsizeiptr getUniformBlockSize( GLuint _blockIndex );
GLsizeiptr getUniformBlockSize( const std::string &_blockName ) const { return getUniformBlockSize(getUniformBlockIndex(_blockName)); }
GLsizeiptr getUniformBlockSize( GLuint _blockIndex ) const ;
#endif // OpenGL >= 3.1
......
......@@ -117,6 +117,7 @@ SharedShaderProgram ShaderProgramControlFiles::create(void)
return SharedShaderProgram(); // linking failed
}
setBindings( shaderProgram ); // will relink, but needs a linked program :-(
openGLCommonErrorOccured();
updateFileModificationTimes();
return shaderProgram;
}
......@@ -124,12 +125,15 @@ SharedShaderProgram ShaderProgramControlFiles::create(void)
// program has to be linked before calling setBindings!
void ShaderProgramControlFiles::setBindings(SharedShaderProgram &_shaderProgram)
{
openGLRareErrorOccured();
# if (ACGL_OPENGL_VERSION >= 30)
_shaderProgram->setFragmentDataLocations( mFragmentDataLocations ); // will relink on it's own
openGLRareErrorOccured();
SharedLocationMappings oldMap = _shaderProgram->getAttributeLocations();
mAttributeLocations->addLocations( oldMap ); // add as many old locations as possible without destoying the location map
_shaderProgram->setAttributeLocations( mAttributeLocations ); // will relink on it's own
openGLRareErrorOccured();
# else
if ( (mAttributeLocations->getSize() > 0) && (mFragmentDataLocations->getSize() > 0) ) {
Utils::error() << "can't set explicit attribute/fragdata locations on OpenGL < 3.0" << std::endl;
......
......@@ -157,7 +157,7 @@ SharedLocationMappings ShaderProgram::getFragmentDataLocations()
return locationMap;
}
SharedLocationMappings ShaderProgram::getUniformOffsetsOfBlock( GLuint _blockIndex )
SharedLocationMappings ShaderProgram::getUniformOffsetsOfBlock( GLuint _blockIndex ) const
{
SharedLocationMappings locationMap = SharedLocationMappings( new LocationMappings() );
......@@ -198,7 +198,7 @@ SharedLocationMappings ShaderProgram::getUniformOffsetsOfBlock( GLuint _blockInd
return locationMap;
}
GLsizeiptr ShaderProgram::getUniformBlockSize( GLuint _blockIndex )
GLsizeiptr ShaderProgram::getUniformBlockSize( GLuint _blockIndex ) const
{
if (_blockIndex == GL_INVALID_INDEX) return 0; // block does not exist
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment