Commit bf15b688 authored by Robert Menzel's avatar Robert Menzel

added support to set uniform buffer locations via controller

parent 05305f7d
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_SHADERPROGRAMCONTROLFILES_HH
#define ACGL_OPENGL_CONTROLLER_SHADERPROGRAMCONTROLFILES_HH
/*
/**
* Used to create a ShaderProgram from a given set of file names:
* e.g.:
* SharedShaderProgram prog = ShaderProgramControlFiles("file.vsh").andFile("foobar.fsh").create();
......@@ -47,7 +47,8 @@ public:
: Resource::FileController<ShaderProgram>(_fileName),
mShaderType(),
mAttributeLocations(new LocationMappings),
mFragmentDataLocations(new LocationMappings)
mFragmentDataLocations(new LocationMappings),
mUniformBufferLocations(new LocationMappings)
{
if ( _type != GL_INVALID_VALUE ) {
andFile( _fileName, _type );
......@@ -70,7 +71,6 @@ public:
//
// Adding files:
//
//! adds a single file, the shader type will be guessed by the ending:
inline ShaderProgramControlFiles& andFile (const std::string &_fileName) { mFileName.push_back( _fileName ); mShaderType.push_back( GL_INVALID_VALUE ); return *this; }
......@@ -82,7 +82,7 @@ public:
ShaderProgramControlFiles& autoFiles (const std::string &_fileName);
//
// Adding locations:
// Adding attribute locations:
//
//! adds an attribute location to the next free location number:
inline ShaderProgramControlFiles& attributeLocation (const std::string &_attributeName) { mAttributeLocations->setLocation(_attributeName); return *this; }
......@@ -90,6 +90,12 @@ public:
//! adds an attribute location to the given location number:
inline ShaderProgramControlFiles& attributeLocation (const std::string &_attributeName, GLuint _location) { mAttributeLocations->setLocation(_attributeName,_location); return *this; }
//! adds a whole list of mappings
inline ShaderProgramControlFiles& attributeLocations (const SharedLocationMappings &_mapping) { mAttributeLocations->addLocations(_mapping); return *this; }
//
// Adding fragment output locations:
//
//! adds a fragment output location to the next free location number:
inline ShaderProgramControlFiles& fragmentDataLocation (const std::string &_fragmentDataName) { mFragmentDataLocations->setLocation(_fragmentDataName); return *this; }
......@@ -97,10 +103,20 @@ public:
inline ShaderProgramControlFiles& fragmentDataLocation (const std::string &_fragmentDataName, GLuint _location) { mFragmentDataLocations->setLocation(_fragmentDataName,_location); return *this; }
//! adds a whole list of mappings
inline ShaderProgramControlFiles& attributeLocations (const SharedLocationMappings &_mapping) { mAttributeLocations->addLocations(_mapping); return *this; }
inline ShaderProgramControlFiles& fragmentDataLocations(const SharedLocationMappings &_mapping) { mFragmentDataLocations->addLocations(_mapping); return *this; }
//
// Adding uniform buffer locations:
//
//! adds an attribute location to the next free location number:
inline ShaderProgramControlFiles& uniformBufferLocation(const std::string &_uniformBufferName) { mUniformBufferLocations->setLocation(_uniformBufferName); return *this; }
//! adds an attribute location to the given location number:
inline ShaderProgramControlFiles& uniformBufferLocation(const std::string &_uniformBufferName, GLuint _location){ mUniformBufferLocations->setLocation(_uniformBufferName,_location);return *this; }
//! adds a whole list of mappings
inline ShaderProgramControlFiles& fragmentDataLocations(const SharedLocationMappings &_mapping) { mFragmentDataLocations->addLocations(_mapping); return *this; }
inline ShaderProgramControlFiles& uniformBufferLocations(const SharedLocationMappings &_mapping) { mUniformBufferLocations->addLocations(_mapping);return *this; }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
......@@ -118,6 +134,7 @@ protected:
SharedLocationMappings mAttributeLocations;
SharedLocationMappings mFragmentDataLocations;
SharedLocationMappings mUniformBufferLocations;
private:
// set attribute & fragdata locations prior to shader program linking
......
......@@ -124,9 +124,17 @@ public:
//! 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 ); }
GLint getUniformBlockBinding( const std::string& _blockName ) { return getUniformBlockBinding( getUniformBlockIndex(_blockName)); }
GLint getUniformBlockBinding( GLuint _blockIndex ) {
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 );
......
......@@ -34,7 +34,7 @@ const ShaderProgramControlFiles::ShaderEndings ShaderProgramControlFiles::sShade
ShaderProgramControlFiles& ShaderProgramControlFiles::autoFiles(const std::string &_fileName)
{
Utils::debug() << "autoFiles: " << _fileName << std::endl;
//Utils::debug() << "autoFiles: " << _fileName << std::endl;
std::string baseFileName = Base::Settings::the()->getFullShaderPath() + _fileName + ".";
for (unsigned int ending = 0; ending < sShaderEndingsSize; ++ending)
{
......@@ -118,14 +118,27 @@ SharedShaderProgram ShaderProgramControlFiles::create(void)
void ShaderProgramControlFiles::setBindings(SharedShaderProgram &_shaderProgram)
{
#if (ACGL_OPENGL_VERSION >= 30)
_shaderProgram->setFragmentDataLocations( mFragmentDataLocations );
_shaderProgram->setAttributeLocations( mAttributeLocations );
#else
if ( (mAttributeLocations.getSize() > 0) && (mFragmentDataLocations.getSize() > 0) ) {
Utils::error() << "can't set explicit attribute/fragdata locations on OpenGL < 3.0 " << std::endl;
# if (ACGL_OPENGL_VERSION >= 30)
_shaderProgram->setFragmentDataLocations( mFragmentDataLocations ); // will relink on it's own
_shaderProgram->setAttributeLocations( mAttributeLocations ); // will relink on it's own
# else
if ( (mAttributeLocations->getSize() > 0) && (mFragmentDataLocations->getSize() > 0) ) {
Utils::error() << "can't set explicit attribute/fragdata locations on OpenGL < 3.0" << std::endl;
}
# endif
// uniform block binding have to be set after linking!
if ( mUniformBufferLocations->getSize() > 0) {
# if (ACGL_OPENGL_VERSION >= 31)
LocationMappings::LocationMap map = mUniformBufferLocations->getLocations();
LocationMappings::LocationMap::const_iterator end = map.end();
for (LocationMappings::LocationMap::const_iterator it = map.begin(); it != end; ++it) {
_shaderProgram->setUniformBlockBinding( it->first, it->second );
}
# else
Utils::error() << "can't set uniform buffer locations on OpenGL < 3.1" << std::endl;
# endif
}
#endif
}
bool ShaderProgramControlFiles::update(SharedShaderProgram &_shaderProgram)
......
......@@ -12,7 +12,7 @@ using namespace ACGL::Base::StringOperations;
int_t TextureDataControlFileFactory::registerType(const std::string& _type, factoryCreate _creator)
{
ACGL::Utils::debug() << "TextureDataControlFileFactory register type: " << _type << std::endl;
ACGL::Utils::debug() << "TextureDataControlFileFactory register type: " << _type << " with id " << mRegisteredTypes << std::endl;
mFactoryMap[_type] = _creator;
return mRegisteredTypes++;
}
......
......@@ -4,7 +4,7 @@
// not all functions are implemented right now, so ignore warnings about unused parameters
#ifdef _MSC_VER
# pragma warning( push )
# pragma warning( push )
# pragma warning ( disable : 4100 )
# pragma warning ( disable : 4101 )
#else
......@@ -63,9 +63,9 @@ void initDirectStateAccessFunctions()
//
# ifdef ACGL_USE_GLEW
if (GLEW_EXT_direct_state_access) {
ACGL::Utils::debug() << "native EXT_direct_state_access detected" << std::endl;
//ACGL::Utils::debug() << "native EXT_direct_state_access detected" << std::endl;
} else {
ACGL::Utils::message() << "EXT_direct_state_access has to be emulated - some of the functions could be missing..." << std::endl;
//ACGL::Utils::message() << "EXT_direct_state_access has to be emulated - some of the functions could be missing..." << std::endl;
mapDSAFromEMULATION();
}
# else
......
......@@ -12,7 +12,9 @@ using namespace ACGL::OpenGL;
void ACGL::OpenGL::initStaticFileTypes(void)
{
ACGL::Utils::debug() << "TextureDataControlFileJPG type ID: " << TextureDataControlFileJPG::registerType() << std::endl;
ACGL::Utils::debug() << "TextureDataControlFilePNG type ID: " << TextureDataControlFilePNG::registerType() << std::endl;
#ifdef ACGL_COMPILE_WITH_QT
TextureDataControlFileJPG::registerType();
TextureDataControlFilePNG::registerType();
#endif
}
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