Commit d3706471 authored by Robert Menzel's avatar Robert Menzel

Added support for direct state access

* Added support for direct state access based uniform setting in the ShaderProgram
* functions from the EXT_direct_state_access extension can get emulated if the extension is not present
  in this case ACGL will map the simulated versions automatically to the *EXT function pointers
  so a programmer can just call the *EXT versions and doesn't have to care if the machine the code
  will get run on does support this extension (as long a simulated version already exists)
* not all functions have emulated version right now, so check if an alternative exists before relying on
  functions from this extension in ACGL lib or implement the missing simulation function to support
  machines without this extension
* all glProgramUniform functions can be emulated (plus some others that were quick to implement)
* dummy functions for all other simulation functions exist
parent 0a74bba2
This diff is collapsed.
......@@ -141,4 +141,9 @@
# include <QtOpenGL/qgl.h>
#endif // USE_QT
//
// our own "extension":
//
#include <ACGL/OpenGL/EXT_direct_state_access.hh>
#endif // ACGL_OPENGL_GL_HH
......@@ -88,22 +88,53 @@ public:
inline void setTexture (GLint _location, const ConstSharedTexture& _texture, GLenum _unit = 0) const { glUniform1i(_location, _unit); _texture->bind(_unit); }
//DSA versions:
inline void setProgramUniform (GLint _location, GLint _v) const { glProgramUniform1iEXT (mContext, _location, _v); }
inline void setProgramUniform (GLint _location, GLfloat _v) const { glProgramUniform1fEXT (mContext, _location, _v); }
inline void setProgramUniform (GLint _location, const glm::vec2& _v) const { glProgramUniform2fvEXT(mContext, _location, 1, glm::value_ptr(_v)); }
inline void setProgramUniform (GLint _location, const glm::vec3& _v) const { glProgramUniform3fvEXT(mContext, _location, 1, glm::value_ptr(_v)); }
inline void setProgramUniform (GLint _location, const glm::vec4& _v) const { glProgramUniform4fvEXT(mContext, _location, 1, glm::value_ptr(_v)); }
inline void setProgramUniform (GLint _location, const glm::mat2& _v, GLboolean _transpose = GL_FALSE) const { glProgramUniformMatrix2fvEXT(mContext, _location, 1, _transpose, glm::value_ptr(_v)); }
inline void setProgramUniform (GLint _location, const glm::mat3& _v, GLboolean _transpose = GL_FALSE) const { glProgramUniformMatrix3fvEXT(mContext, _location, 1, _transpose, glm::value_ptr(_v)); }
inline void setProgramUniform (GLint _location, const glm::mat4& _v, GLboolean _transpose = GL_FALSE) const { glProgramUniformMatrix4fvEXT(mContext, _location, 1, _transpose, glm::value_ptr(_v)); }
inline void setTextureDSA (GLint _location, const ConstSharedTexture& _texture, GLenum _unit = 0) const { glProgramUniform1iEXT(mContext, _location, _unit); _texture->bind(_unit); }
// =================================================================================================== \/
// ============================================================================== HIGH LEVEL FUNCTIONS \/
// =================================================================================================== \/
inline void setUniform (const std::string& _nameInShader, GLint _v) const { glUniform1i (getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, GLfloat _v) const { glUniform1f (getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, GLint _v) const { setUniform( getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, GLfloat _v) const { setUniform( getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, const glm::vec2& _v) const { setUniform( getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, const glm::vec3& _v) const { setUniform( getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, const glm::vec4& _v) const { setUniform( getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, const glm::mat2& _v, GLboolean _transpose = GL_FALSE) const { setUniform( getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, const glm::mat3& _v, GLboolean _transpose = GL_FALSE) const { setUniform( getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, const glm::mat4& _v, GLboolean _transpose = GL_FALSE) const { setUniform( getUniformLocation(_nameInShader), _v); }
inline void setTexture (const std::string& _nameInShader, const ConstSharedTexture& _texture, GLenum _unit = 0) const { setUniform( getUniformLocation(_nameInShader), (GLint) _unit); _texture->bind(_unit); }
//DSA versions:
inline void setProgramUniform (const std::string& _nameInShader, GLint _v) const { setProgramUniform( getUniformLocation(_nameInShader), _v); }
inline void setProgramUniform (const std::string& _nameInShader, GLfloat _v) const { setProgramUniform( getUniformLocation(_nameInShader), _v); }
inline void setProgramUniform (const std::string& _nameInShader, const glm::vec2& _v) const { setProgramUniform( getUniformLocation(_nameInShader), _v); }
inline void setProgramUniform (const std::string& _nameInShader, const glm::vec3& _v) const { setProgramUniform( getUniformLocation(_nameInShader), _v); }
inline void setProgramUniform (const std::string& _nameInShader, const glm::vec4& _v) const { setProgramUniform( getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, const glm::vec2& _v) const { glUniform2fv(getUniformLocation(_nameInShader), 1, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::vec3& _v) const { glUniform3fv(getUniformLocation(_nameInShader), 1, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::vec4& _v) const { glUniform4fv(getUniformLocation(_nameInShader), 1, glm::value_ptr(_v)); }
inline void setProgramUniform (const std::string& _nameInShader, const glm::mat2& _v, GLboolean _transpose = GL_FALSE) const { setProgramUniform( getUniformLocation(_nameInShader), _v); }
inline void setProgramUniform (const std::string& _nameInShader, const glm::mat3& _v, GLboolean _transpose = GL_FALSE) const { setProgramUniform( getUniformLocation(_nameInShader), _v); }
inline void setProgramUniform (const std::string& _nameInShader, const glm::mat4& _v, GLboolean _transpose = GL_FALSE) const { setProgramUniform( getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, const glm::mat2& _v, GLboolean _transpose = GL_FALSE) const { glUniformMatrix2fv(getUniformLocation(_nameInShader), 1, _transpose, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::mat3& _v, GLboolean _transpose = GL_FALSE) const { glUniformMatrix3fv(getUniformLocation(_nameInShader), 1, _transpose, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::mat4& _v, GLboolean _transpose = GL_FALSE) const { glUniformMatrix4fv(getUniformLocation(_nameInShader), 1, _transpose, glm::value_ptr(_v)); }
inline void setTextureDSA (const std::string& _nameInShader, const ConstSharedTexture& _texture, GLenum _unit = 0) const { setProgramUniform( getUniformLocation(_nameInShader), (GLint) _unit); _texture->bind(_unit); }
inline void setTexture (const std::string& _nameInShader, const ConstSharedTexture& _texture, GLenum _unit = 0) const { glUniform1i(getUniformLocation(_nameInShader), _unit); _texture->bind(_unit); }
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
......
......@@ -57,8 +57,16 @@ bool init(void)
if (openGLVersion < ACGL_OPENGL_VERSION) {
ACGL::Utils::error() << "At compile time an OpenGL context of version " << ACGL_OPENGL_VERSION
<< " was requested, but the current context only supports " << openGLVersion << std::endl;
return false;
//return false;
}
//
// Init DirectStateAccess functions:
// (using the extension versions or our own (slower) emulation)
//
initDirectStateAccessFunctions();
return true;
}
};
......
This diff is collapsed.
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