Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UniformHandler.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2016 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OMNI_VISUAL_UNIFORMHANDLER_H_
20 #define OMNI_VISUAL_UNIFORMHANDLER_H_
21 
22 #include <set>
23 #include <functional>
24 #include <QOpenGLShaderProgram>
25 
26 class QOpenGLFunctions;
27 
28 namespace omni {
29  namespace visual {
30  /**@brief Uniform handler for a shader program
31  @detail Cares about bind and releasing shaders and texture uniforms.
32  Should only be used with the visual::useShader function.
33  **/
34  struct UniformHandler {
35  UniformHandler(QOpenGLFunctions& _gl,
36  QOpenGLShaderProgram& _shader);
37 
38  /// Destructor. Unbind all active texture units
40 
41  /// Set uniform value
42  template<typename ... ARGS>
43  void uniform(const char *_name, ARGS&& ... _args) {
44  shader_.setUniformValue(_name, _args ...);
45  }
46 
47  /// Set uniform value for texture with id and optional target
48  void texUniform(const char *_name,
49  GLuint _texId,
50  GLuint _target = GL_TEXTURE_2D);
51 
52  /**@brief Set uniform value for texture object
53  @detail Texture object can be either QOpenGLTexture or Texture32F
54  **/
55  template<typename TEXTURE>
56  void texUniform(const char *_name, TEXTURE& _tex) {
57  texUniform(_name, _tex.textureId(), _tex.target());
58  }
59 
60  void texRectUniform(const char* _name, GLuint _texId, QSize _size);
61 
62  private:
63  QOpenGLFunctions & gl_;
64  QOpenGLShaderProgram& shader_;
66  std::set<GLuint> usedTextureTargets_;
67  };
68  }
69 }
70 
71 #endif /* OMNI_VISUAL_UNIFORMHANDLER_H_ */
std::set< GLuint > usedTextureTargets_
Definition: UniformHandler.h:66
void texUniform(const char *_name, GLuint _texId, GLuint _target=GL_TEXTURE_2D)
Set uniform value for texture with id and optional target.
Definition: UniformHandler.cpp:49
UniformHandler(QOpenGLFunctions &_gl, QOpenGLShaderProgram &_shader)
Definition: UniformHandler.cpp:29
Uniform handler for a shader program Cares about bind and releasing shaders and texture uniforms...
Definition: UniformHandler.h:34
void uniform(const char *_name, ARGS &&..._args)
Set uniform value.
Definition: UniformHandler.h:43
GLint currentTextureUnit_
Definition: UniformHandler.h:65
~UniformHandler()
Destructor. Unbind all active texture units.
Definition: UniformHandler.cpp:34
void texUniform(const char *_name, TEXTURE &_tex)
Set uniform value for texture object Texture object can be either QOpenGLTexture or Texture32F...
Definition: UniformHandler.h:56
void texRectUniform(const char *_name, GLuint _texId, QSize _size)
Definition: UniformHandler.cpp:42
QOpenGLFunctions & gl_
Definition: UniformHandler.h:63
QOpenGLShaderProgram & shader_
Definition: UniformHandler.h:64