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 
43 {
44 public:
45  static vtkShaderProgram *New();
46  vtkTypeMacro(vtkShaderProgram, vtkObject);
47  void PrintSelf(ostream& os, vtkIndent indent);
48 
50 
51  vtkGetObjectMacro(VertexShader, vtkShader);
52  void SetVertexShader(vtkShader*);
54 
56 
57  vtkGetObjectMacro(FragmentShader, vtkShader);
58  void SetFragmentShader(vtkShader*);
60 
62 
63  vtkGetObjectMacro(GeometryShader, vtkShader);
64  void SetGeometryShader(vtkShader*);
66 
68 
69  vtkGetMacro(Compiled, bool);
70  vtkSetMacro(Compiled, bool);
71  vtkBooleanMacro(Compiled, bool);
73 
75 
76  std::string GetMD5Hash() const { return this->MD5Hash; }
77  void SetMD5Hash(const std::string &hash) { this->MD5Hash = hash; }
79 
80 
93  NoNormalize
94  };
95 
96 
101  bool isBound() const { return this->Bound; }
102 
104  void ReleaseGraphicsResources(vtkWindow *win);
105 
107  int GetHandle() const { return Handle; }
108 
110  std::string GetError() const { return Error; }
111 
116  bool EnableAttributeArray(const char *name);
117 
122  bool DisableAttributeArray(const char *name);
123 
139  bool UseAttributeArray(const char *name, int offset, size_t stride,
140  int elementType, int elementTupleSize,
141  NormalizeOption normalize);
142 
160  template <class T>
161  bool SetAttributeArray(const char *name, const T &array,
162  int tupleSize, NormalizeOption normalize);
163 
165  bool SetUniformi(const char *name, int v);
166  bool SetUniformf(const char *name, float v);
167  bool SetUniform2i(const char *name, const int v[2]);
168  bool SetUniform2f(const char *name, const float v[2]);
169  bool SetUniform3f(const char *name, const float v[3]);
170  bool SetUniform4f(const char *name, const float v[4]);
171  bool SetUniform3uc(const char *name, const unsigned char v[3]); // maybe remove
172  bool SetUniform4uc(const char *name, const unsigned char v[4]); // maybe remove
173  bool SetUniformMatrix(const char *name, vtkMatrix3x3 *v);
174  bool SetUniformMatrix(const char *name, vtkMatrix4x4 *v);
175  bool SetUniformMatrix3x3(const char *name, float *v);
176  bool SetUniformMatrix4x4(const char *name, float *v);
177 
179  bool SetUniform1iv(const char *name, const int count, const int *f);
180  bool SetUniform1fv(const char *name, const int count, const float *f);
181  bool SetUniform2fv(const char *name, const int count, const float (*f)[2]);
182  bool SetUniform3fv(const char *name, const int count, const float (*f)[3]);
183  bool SetUniform4fv(const char *name, const int count, const float (*f)[4]);
184  bool SetUniformMatrix4x4v(const char *name, const int count, float *v);
185 
186  // How many outputs does this program produce
187  // only valid for OpenGL 3.2 or later
188  vtkSetMacro(NumberOfOutputs,unsigned int);
189 
190 //BTX
192 
196  static bool Substitute(
198  const std::string &search,
199  const std::string replace,
200  bool all = true);
202 
206  bool IsUniformUsed(const char *);
207 
208 protected:
210  ~vtkShaderProgram();
211 
212  /***************************************************************
213  * The following functions are only for use by the shader cache
214  * which is why they are protected and that class is a friend
215  * you need to use the shader cache to compile/link/bind your shader
216  * do not try to do it yourself as it will screw up the cache
217  ***************************************************************/
218  friend class vtkOpenGLShaderCache;
219 
226  bool AttachShader(const vtkShader *shader);
227 
233  bool DetachShader(const vtkShader *shader);
234 
236  virtual int CompileShader();
237 
243  bool Link();
244 
249  bool Bind();
250 
252  void Release();
253 
254  /************* end **************************************/
255 
259 
260  // hash of the shader program
262 
263  bool SetAttributeArrayInternal(const char *name, void *buffer,
264  int type, int tupleSize,
265  NormalizeOption normalize);
266  int Handle;
270 
271  bool Linked;
272  bool Bound;
273  bool Compiled;
274 
275  // for glsl 1.5 or later, how many outputs
276  // does this shader create
277  // they will be bound in order to
278  // fragOutput0 fragOutput1 etc...
279  unsigned int NumberOfOutputs;
280 
282 
283  std::map<std::string, int> Attributes;
284 
285 
286  std::map<std::string, bool> UniformsUsed;
287 
288  friend class VertexArrayObject;
289 
290 private:
291  int FindAttributeArray(const char *name);
292  int FindUniform(const char *name);
293 
294  vtkShaderProgram(const vtkShaderProgram&); // Not implemented.
295  void operator=(const vtkShaderProgram&); // Not implemented.
296 //ETX
297 };
298 
299 
300 #endif
int GetHandle() const
Get the handle of the shader program.
abstract base class for most VTK objects
Definition: vtkObject.h:61
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:38
unsigned int NumberOfOutputs
manage Shader Programs within a context
bool isBound() const
Check if the program is currently bound, or not.
#define VTKRENDERINGOPENGL2_EXPORT
vtkShader * VertexShader
The values range across the limits of the numeric type.
std::map< std::string, bool > UniformsUsed
std::map< std::string, int > Attributes
void SetMD5Hash(const std::string &hash)
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkShader * GeometryShader
vtkShader * FragmentShader
NormalizeOption
Options for attribute normalization.
std::string GetMD5Hash() const
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Vertex or Fragment shader, combined into a ShaderProgram.
Definition: vtkShader.h:39
std::string GetError() const
Get the error message (empty if none) for the shader program.
std::string replace(std::string source, const std::string &search, const std::string replace, bool all)
static vtkObject * New()
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:35
The ShaderProgram uses one or more Shader objects.