VTK
vtkShaderProgram.h
Go to the documentation of this file.
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 =========================================================================*/
20 #ifndef vtkShaderProgram_h
21 #define vtkShaderProgram_h
22 
23 #include "vtkRenderingOpenGL2Module.h" // for export macro
24 #include "vtkObject.h"
25 
26 #include <string> // For member variables.
27 #include <map> // For member variables.
28 
29 class vtkMatrix3x3;
30 class vtkMatrix4x4;
31 class vtkShader;
32 class VertexArrayObject;
33 class vtkWindow;
34 
42 class VTKRENDERINGOPENGL2_EXPORT vtkShaderProgram : public vtkObject
43 {
44 public:
45  static vtkShaderProgram *New();
47  void PrintSelf(ostream& os, vtkIndent indent);
48 
50 
51  vtkGetObjectMacro(VertexShader, vtkShader);
53 
55 
56  vtkGetObjectMacro(FragmentShader, vtkShader);
58 
60 
61  vtkGetObjectMacro(GeometryShader, vtkShader);
63 
65 
66  vtkGetMacro(Compiled, bool);
67  vtkSetMacro(Compiled, bool);
68  vtkBooleanMacro(Compiled, bool);
70 
72 
73  std::string GetMD5Hash() const { return this->MD5Hash; }
74  void SetMD5Hash(const std::string &hash) { this->MD5Hash = hash; }
76 
77 
90  NoNormalize
91  };
92 
93 
98  bool isBound() const { return this->Bound; }
99 
101  void ReleaseGraphicsResources(vtkWindow *win);
102 
104  int GetHandle() const { return Handle; }
105 
107  std::string GetError() const { return Error; }
108 
113  bool EnableAttributeArray(const char *name);
114 
119  bool DisableAttributeArray(const char *name);
120 
136  bool UseAttributeArray(const char *name, int offset, size_t stride,
137  int elementType, int elementTupleSize,
138  NormalizeOption normalize);
139 
157  template <class T>
158  bool SetAttributeArray(const char *name, const T &array,
159  int tupleSize, NormalizeOption normalize);
160 
162  bool SetUniformi(const char *name, int v);
163  bool SetUniformf(const char *name, float v);
164  bool SetUniform2i(const char *name, const int v[2]);
165  bool SetUniform2f(const char *name, const float v[2]);
166  bool SetUniform3f(const char *name, const float v[3]);
167  bool SetUniform4f(const char *name, const float v[4]);
168  bool SetUniform3uc(const char *name, const unsigned char v[3]); // maybe remove
169  bool SetUniform4uc(const char *name, const unsigned char v[4]); // maybe remove
170  bool SetUniformMatrix(const char *name, vtkMatrix3x3 *v);
171  bool SetUniformMatrix(const char *name, vtkMatrix4x4 *v);
172  bool SetUniformMatrix3x3(const char *name, float *v);
173  bool SetUniformMatrix4x4(const char *name, float *v);
174 
176  bool SetUniform1iv(const char *name, const int count, const int *f);
177  bool SetUniform1fv(const char *name, const int count, const float *f);
178  bool SetUniform2fv(const char *name, const int count, const float (*f)[2]);
179  bool SetUniform3fv(const char *name, const int count, const float (*f)[3]);
180  bool SetUniform4fv(const char *name, const int count, const float (*f)[4]);
181 
182 protected:
184  ~vtkShaderProgram();
185 
186  /***************************************************************
187  * The following functions are only for use by the shader cache
188  * which is why they are protected and that class is a friend
189  * you need to use the shader cache to compile/link/bind your shader
190  * do not try to do it yourself as it will screw up the cache
191  ***************************************************************/
192  friend class vtkOpenGLShaderCache;
193 
200  bool AttachShader(const vtkShader *shader);
201 
207  bool DetachShader(const vtkShader *shader);
208 
210  virtual int CompileShader();
211 
217  bool Link();
218 
223  bool Bind();
224 
226  void Release();
227 
228  /************* end **************************************/
229 
233 
234  // hash of the shader program
236 
237  bool SetAttributeArrayInternal(const char *name, void *buffer,
238  int type, int tupleSize,
239  NormalizeOption normalize);
240  int Handle;
243 
244  bool Linked;
245  bool Bound;
246  bool Compiled;
247 
249 
250  std::map<std::string, int> Attributes;
251 
252  friend class VertexArrayObject;
253 
254 private:
255  int FindAttributeArray(const char *name);
256  int FindUniform(const char *name);
257 
258  vtkShaderProgram(const vtkShaderProgram&); // Not implemented.
259  void operator=(const vtkShaderProgram&); // Not implemented.
260 };
261 
262 
263 #endif
GLclampf f
Definition: vtkgl.h:14181
int GetHandle() const
Get the handle of the shader program.
GLuint GLuint GLsizei GLenum type
Definition: vtkgl.h:11315
VTKRENDERINGOPENGL_EXPORT PFNGLDETACHSHADERPROC DetachShader
abstract base class for most VTK objects
Definition: vtkObject.h:61
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:38
const GLdouble * v
Definition: vtkgl.h:11595
GLuint buffer
Definition: vtkgl.h:11839
GLintptr offset
Definition: vtkgl.h:11844
manage Shader Programs within a context
bool isBound() const
Check if the program is currently bound, or not.
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
vtkShader * VertexShader
The values range across the limits of the numeric type.
GLuint GLuint GLsizei count
Definition: vtkgl.h:11315
GLsizei stride
Definition: vtkgl.h:11728
std::map< std::string, int > Attributes
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:632
GLuint shader
Definition: vtkgl.h:11982
void SetMD5Hash(const std::string &hash)
window superclass for vtkRenderWindow
Definition: vtkWindow.h:33
GLuint const GLchar * name
Definition: vtkgl.h:11983
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkShader * GeometryShader
vtkShader * FragmentShader
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:222
VTKRENDERINGOPENGL_EXPORT PFNGLATTACHSHADERPROC AttachShader
NormalizeOption
Options for attribute normalization.
std::string GetMD5Hash() const
Vertex or Fragment shader, combined into a ShaderProgram.
Definition: vtkShader.h:35
std::string GetError() const
Get the error message (empty if none) for the shader program.
#define vtkBooleanMacro(name, type)
Definition: vtkSetGet.h:234
static vtkObject * New()
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:35
GLsizei const GLchar ** string
Definition: vtkgl.h:12011
VTKRENDERINGOPENGL_EXPORT PFNGLCOMPILESHADERPROC CompileShader
The ShaderProgram uses one or more Shader objects.
#define vtkSetMacro(name, type)
Definition: vtkSetGet.h:69