1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4 
5   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6   All rights reserved.
7   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9      This software is distributed WITHOUT ANY WARRANTY; without even
10      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11      PURPOSE.  See the above copyright notice for more information.
12 
13 =========================================================================*/
14 /**
15  * @class   vtkOpenGLUniform
16  * @brief   helper class to set custom uniform variables in GLSL shaders.
17  *
18  * This class implements all SetUniform* functions supported by vtkShaderProgram but instead of
19  * directly calling the underlying OpenGL functions, it caches the name and value of the variable
20  * and provides a mechanism for client mappers to set all cached variables at once in a generic way.
21 */
22 
23 #ifndef vtkOpenGLUniforms_h
24 #define vtkOpenGLUniforms_h
25 
26 #include "vtkObject.h"
27 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
28 
29 #include <string> // For member functions
30 
31 class vtkUniformInternals;
32 class vtkMatrix3x3;
33 class vtkMatrix4x4;
34 class vtkShaderProgram;
35 
36 class VTKRENDERINGVOLUMEOPENGL2_EXPORT  vtkOpenGLUniforms : public vtkObject
37 {
38 public:
39     static vtkOpenGLUniforms *New();
40     vtkTypeMacro(vtkOpenGLUniforms, vtkObject);
41     void PrintSelf(ostream& os, vtkIndent indent) override;
42 
43     std::string GetDeclarations();
44     bool SetUniforms( vtkShaderProgram * p );
45     vtkMTimeType GetUniformListMTime();
46 
47     /** Add the @p name uniform variable with value @p defaultValue. */
48     void AddUniformi (const char *name, int defaultValue);
49     void AddUniformf(const char *name, float defaultValue);
50     void AddUniform2i(const char *name, const int defaultValue[2]);
51     void AddUniform2f(const char *name, const float defaultValue[2]);
52     void AddUniform3f(const char *name, const float defaultValue[3]);
53     void AddUniform3f(const char *name, const double defaultValue[3]);
54     void AddUniform4f(const char *name, const float defaultValue[4]);
55     void AddUniform3uc(const char *name, const unsigned char defaultValue[3]); // maybe remove
56     void AddUniform4uc(const char *name, const unsigned char defaultValue[4]); // maybe remove
57     void AddUniformMatrix(const char *name, vtkMatrix3x3 *defaultValue);
58     void AddUniformMatrix(const char *name, vtkMatrix4x4 *defaultValue);
59     void AddUniformMatrix3x3(const char *name, float *defaultValue);
60     void AddUniformMatrix4x4(const char *name, float *defaultValue);
61 
62     /** Add the @p name uniform array to @p f with @p count elements */
63     void AddUniform1iv(const char *name, const int count, const int *f);
64     void AddUniform1fv (const char *name, const int count, const float *f);
65     void AddUniform2fv (const char *name, const int count, const float(*f)[2]);
66     void AddUniform3fv (const char *name, const int count, const float(*f)[3]);
67     void AddUniform4fv (const char *name, const int count, const float(*f)[4]);
68     void AddUniformMatrix4x4v (const char *name, const int count, float *v);
69 
70     /** Remove uniform variable named @p name */
71     void RemoveUniform(const char *name);
72 
73     /** Remove all uniform variables */
74     void RemoveAllUniforms();
75 
76     /** Set the @p name uniform value to @p v. */
77     void SetUniformi(const char *name, int v);
78     void SetUniformf(const char *name, float v);
79     void SetUniform2i(const char *name, const int v[2]);
80     void SetUniform2f(const char *name, const float v[2]);
81     void SetUniform3f(const char *name, const float v[3]);
82     void SetUniform3f(const char *name, const double v[3]);
83     void SetUniform4f(const char *name, const float v[4]);
84     void SetUniform3uc(const char *name, const unsigned char v[3]); // maybe remove
85     void SetUniform4uc(const char *name, const unsigned char v[4]); // maybe remove
86     void SetUniformMatrix(const char *name, vtkMatrix3x3 *v);
87     void SetUniformMatrix(const char *name, vtkMatrix4x4 *v);
88     void SetUniformMatrix3x3(const char *name, float *v);
89     void SetUniformMatrix4x4(const char *name, float *v);
90 
91     /** Set the @p name uniform array to @p f with @p count elements */
92     void SetUniform1iv(const char *name, const int count, const int *f);
93     void SetUniform1fv(const char *name, const int count, const float *f);
94     void SetUniform2fv(const char *name, const int count, const float (*f)[2]);
95     void SetUniform3fv(const char *name, const int count, const float (*f)[3]);
96     void SetUniform4fv(const char *name, const int count, const float (*f)[4]);
97     void SetUniformMatrix4x4v(const char *name, const int count, float *v);
98 
99 protected:
100   vtkOpenGLUniforms();
101   ~vtkOpenGLUniforms() override;
102 
103 private:
104   vtkOpenGLUniforms(const vtkOpenGLUniforms&) = delete;
105   void operator=(const vtkOpenGLUniforms&) = delete;
106 
107   vtkUniformInternals * Internals;
108 };
109 
110 #endif
111