/*********************************************************************** * Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. * * All rights reserved. * * Distributed under the terms of the MIT License (see LICENSE.TXT). * **********************************************************************/ // See http://www.graphics.rwth-aachen.de/redmine/projects/acgl/wiki/ACGL_compile_time_settings // for a comment what unsupported means. #ifdef deprecated #ifndef ACGL_OPENGL_OBJECTS_UNIFORM_HH #define ACGL_OPENGL_OBJECTS_UNIFORM_HH /* * Uniforms do not map to OpenGL objects directly, to set a uniform value in a * ShaderProgram, use the setUniform() / setProgramUniform() methods there with * the raw values you want to ste. * * This class provides the ability to save uniform values on the client side and * wait with the uploading until the ShaderProgram gets used. It gets used in * combination with the ShaderProgramObject/RenderObject (see there). */ #include #include #include #include #include #include namespace ACGL{ namespace OpenGL{ // ================================================================================================== \/ // ================================================================================== BASIC INTERFACE \/ // ================================================================================================== \/ class Uniform { public: //! Apply the uniform to a specified location virtual void apply(GLint) const = 0; }; ACGL_SMARTPOINTER_TYPEDEFS(Uniform) // ================================================================================================= \/ // ===================================================================================== C-SIDE DATA \/ // ================================================================================================= \/ template class UniformData { // ===================================================================================================== \/ // ============================================================================================ TYPEDEFS \/ // ===================================================================================================== \/ public: typedef T DATA_TYPE; // ========================================================================================================= \/ // ============================================================================================ CONSTRUCTORS \/ // ========================================================================================================= \/ public: UniformData(void) : mValue() {} virtual ~UniformData(void) {} // ==================================================================================================== \/ // ============================================================================================ SETTERS \/ // ==================================================================================================== \/ public: inline void setValue (const T& _value) { mValue = _value; } // ==================================================================================================== \/ // ============================================================================================ GETTERS \/ // ==================================================================================================== \/ public: inline const T& getValue (void) const { return mValue; } // =================================================================================================== \/ // ============================================================================================ FIELDS \/ // =================================================================================================== \/ protected: T mValue; }; // ===================================================================================================== \/ // ===================================================================================== IMPLEMENTATIONS \/ // ===================================================================================================== \/ class Uniform1i : public UniformData, public Uniform { public: Uniform1i(void) : UniformData() {} virtual ~Uniform1i(void) {} void apply(GLint _location) const { glUniform1i(_location, mValue); } }; ACGL_SMARTPOINTER_TYPEDEFS(Uniform1i) //========================= #if (ACGL_OPENGL_VERSION >= 30) class Uniform1ui : public UniformData, public Uniform { public: Uniform1ui(void) : UniformData() {} virtual ~Uniform1ui(void) {} void apply(GLint _location) const { glUniform1ui(_location, mValue); } }; ACGL_SMARTPOINTER_TYPEDEFS(Uniform1ui) #endif //========================= class Uniform1f : public UniformData, public Uniform { public: Uniform1f(void) : UniformData() {} virtual ~Uniform1f(void) {} void apply(GLint _location) const { glUniform1f(_location, mValue); } }; ACGL_SMARTPOINTER_TYPEDEFS(Uniform1f) //========================= class Uniform1fv : public UniformData >, public Uniform { public: virtual ~Uniform1fv(void) {} void apply(GLint _location) const { if(!mValue.empty()) glUniform1fv(_location, (GLsizei)mValue.size(), (GLfloat*)&mValue[0]); } }; ACGL_SMARTPOINTER_TYPEDEFS(Uniform1fv) //========================= class Uniform2f : public UniformData, public Uniform { public: Uniform2f(void) : UniformData() {} virtual ~Uniform2f(void) {} void apply(GLint _location) const { glUniform2fv(_location, 1, glm::value_ptr(mValue)); } }; ACGL_SMARTPOINTER_TYPEDEFS(Uniform2f) //========================= class Uniform3f : public UniformData, public Uniform { public: Uniform3f(void) : UniformData() {} virtual ~Uniform3f(void) {} void apply(GLint _location) const { glUniform3fv(_location, 1, glm::value_ptr(mValue)); } }; ACGL_SMARTPOINTER_TYPEDEFS(Uniform3f) //========================= class Uniform4f : public UniformData, public Uniform { public: Uniform4f(void) : UniformData() {} virtual ~Uniform4f(void) {} void apply(GLint _location) const { glUniform4fv(_location, 1, glm::value_ptr(mValue)); } }; ACGL_SMARTPOINTER_TYPEDEFS(Uniform4f) //========================= class UniformMatrix2f : public UniformData, public Uniform { public: UniformMatrix2f(void) : UniformData() {} virtual ~UniformMatrix2f(void) {} void apply(GLint _location) const { glUniformMatrix2fv(_location, 1, GL_FALSE, glm::value_ptr(mValue)); } }; ACGL_SMARTPOINTER_TYPEDEFS(UniformMatrix2f) //========================= class UniformMatrix3f : public UniformData, public Uniform { public: UniformMatrix3f(void) : UniformData() {} virtual ~UniformMatrix3f(void) {} void apply(GLint _location) const { glUniformMatrix3fv(_location, 1, GL_FALSE, glm::value_ptr(mValue)); } }; ACGL_SMARTPOINTER_TYPEDEFS(UniformMatrix3f) //========================= class UniformMatrix4f : public UniformData, public Uniform { public: UniformMatrix4f(void) : UniformData() {} virtual ~UniformMatrix4f(void) {} void apply(GLint _location) const { glUniformMatrix4fv(_location, 1, GL_FALSE, glm::value_ptr(mValue)); } }; ACGL_SMARTPOINTER_TYPEDEFS(UniformMatrix4f) //========================= class UniformTexture : public UniformData { public: UniformTexture(void) : UniformData() {} virtual ~UniformTexture(void) {} void apply(GLint _location, GLenum _unit) const { glUniform1i(_location, _unit); mValue->bind(_unit); } }; ACGL_SMARTPOINTER_TYPEDEFS(UniformTexture) } // OpenGL } // ACGL #endif // ACGL_OPENGL_OBJECTS_UNIFORM_HH #endif