VTK
vtkShaderProgram2.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkShaderProgram2.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
27 #ifndef vtkShaderProgram2_h
28 #define vtkShaderProgram2_h
29 
30 #include <cassert> // for templated functions
31 #include "vtkRenderingOpenGLModule.h" // for export macro
32 #include "vtkWeakPointer.h" // for weak ptr to rendering context
33 #include "vtkObject.h"
34 
35 class vtkRenderWindow;
39 
40 // Values for GetLastBuildStatus()
42 {
43  // one of the shaders failed to compile
45  // all the shaders compiled successfully but the link failed
47  // all the shaders compiled successfully and the link succeeded
49 };
50 
52 {
58 };
59 
61 {
65 };
66 
68 {
69 public:
70  static vtkShaderProgram2* New();
71  vtkTypeMacro(vtkShaderProgram2, vtkObject);
72  void PrintSelf(ostream& os, vtkIndent indent);
73 
76  static bool IsSupported(vtkRenderWindow *context);
77 
79 
84  vtkGetMacro(PrintErrors,bool);
85  vtkSetMacro(PrintErrors,bool);
87 
89 
93  void SetContext(vtkRenderWindow *context);
94  vtkRenderWindow *GetContext();
96 
98 
100  vtkGetObjectMacro(Shaders,vtkShader2Collection);
102 
106  bool HasVertexShaders();
107 
110  bool HasTessellationControlShaders();
111 
114  bool HasTessellationEvaluationShaders();
115 
117  bool HasGeometryShaders();
118 
122  bool HasFragmentShaders();
123 
128  bool IsValid();
129 
134  void Build();
135 
140  void SendUniforms();
141 
143 
147  void PrintActiveUniformVariables(ostream &os,
148  vtkIndent indent);
150 
155  void PrintActiveUniformVariablesOnCout();
156 
160  bool IsUsed();
161 
167  void Use();
168 
172  void Restore();
173 
178  void RestoreFixedPipeline();
179 
181 
183  void UseProgram();
184  void UnuseProgram();
186 
193  int GetLastBuildStatus();
194 
197  const char *GetLastLinkLog();
198 
201  const char *GetLastValidateLog();
202 
204  virtual void ReleaseGraphicsResources();
205 
211  int GetAttributeLocation(const char *name);
212 
214 
216  vtkGetObjectMacro(UniformVariables,vtkUniformVariables);
217  virtual void SetUniformVariables(vtkUniformVariables *variables);
219 
226  bool DisplayListUnderCreationInCompileMode();
227 
229 
239  vtkSetMacro(GeometryTypeIn,int);
240  vtkGetMacro(GeometryTypeIn,int);
242 
244 
251  vtkSetMacro(GeometryVerticesOut,int);
252  vtkGetMacro(GeometryVerticesOut,int);
254 
256 
264  vtkSetMacro(GeometryTypeOut,int);
265  vtkGetMacro(GeometryTypeOut,int);
267 
268  /*
269  Low level api --
270  this is provided as a way to avoid some of the overhead in this
271  class's implementation of SendUniforms. One should use the
272  following API if performance is a concern (eg. uniforms are
273  set per primative), or if the uniform management is not needed
274  (eg. variables are already managed in other vtkObjects)
275  */
276 
278  int GetUniformLocation(const char *name);
279 
281 
285  void SetUniformf(const char *name, float val)
286  { this->SetUniform1f(name, &val); }
287  void SetUniform1f(const char *name, float *val)
288  { this->SetUniform1f(this->GetUniformLocation(name), val); }
289  void SetUniform2f(const char *name, float *val)
290  { this->SetUniform2f(this->GetUniformLocation(name), val); }
291  void SetUniform3f(const char *name, float *val)
292  { this->SetUniform3f(this->GetUniformLocation(name), val); }
293  void SetUniform4f(const char *name, float *val)
294  { this->SetUniform4f(this->GetUniformLocation(name), val); }
296 
297  void SetUniformi(const char *name, int val)
298  { this->SetUniform1i(name, &val); }
299  void SetUniform1i(const char *name, int *val)
300  { this->SetUniform1i(this->GetUniformLocation(name), val); }
301  void SetUniform2i(const char *name, int *val)
302  { this->SetUniform2i(this->GetUniformLocation(name), val); }
303  void SetUniform3i(const char *name, int *val)
304  { this->SetUniform3i(this->GetUniformLocation(name), val); }
305  void SetUniform4i(const char *name, int *val)
306  { this->SetUniform4i(this->GetUniformLocation(name), val); }
307 
308  void SetUniformf(int loc, float val)
309  { this->SetUniform1f(loc, &val); }
310  void SetUniform1f(int loc, float *val);
311  void SetUniform2f(int loc, float *val);
312  void SetUniform3f(int loc, float *val);
313  void SetUniform4f(int loc, float *val);
314 
315  void SetUniformi(int loc, int val)
316  { this->SetUniform1i(loc, &val); }
317  void SetUniform1i(int loc, int *val);
318  void SetUniform2i(int loc, int *val);
319  void SetUniform3i(int loc, int *val);
320  void SetUniform4i(int loc, int *val);
321 
323 
326  template<typename T> void SetUniform1it(const char *name, T *value);
327  template<typename T> void SetUniform2it(const char *name, T *value);
328  template<typename T> void SetUniform3it(const char *name, T *value);
329  template<typename T> void SetUniform4it(const char *name, T *value);
331 
332  template<typename T> void SetUniform1ft(const char *name, T *value);
333  template<typename T> void SetUniform2ft(const char *name, T *value);
334  template<typename T> void SetUniform3ft(const char *name, T *value);
335  template<typename T> void SetUniform4ft(const char *name, T *value);
336 
337  template<typename T> void SetUniform1it(int loc, T *value);
338  template<typename T> void SetUniform2it(int loc, T *value);
339  template<typename T> void SetUniform3it(int loc, T *value);
340  template<typename T> void SetUniform4it(int loc, T *value);
341 
342  template<typename T> void SetUniform1ft(int loc, T *value);
343  template<typename T> void SetUniform2ft(int loc, T *value);
344  template<typename T> void SetUniform3ft(int loc, T *value);
345  template<typename T> void SetUniform4ft(int loc, T *value);
346 
347 protected:
349  virtual ~vtkShaderProgram2();
350 
352  bool LoadRequiredExtensions(vtkRenderWindow *context);
353 
359  int GetUniformLocationInternal(const char *name);
360 
361  unsigned int Id; // actually GLuint. Initial value is 0.
362  unsigned int SavedId;
363 
366 
369 
370  int LastBuildStatus; // Initial value is VTK_SHADER_PROGRAM2_COMPILE_FAILED
371 
372  char *LastLinkLog; // Initial value is the empty string ""='\0'
373  size_t LastLinkLogCapacity; // Initial value is 8.
374 
375  char *LastValidateLog; // Initial value is the empty string ""='\0'
376  size_t LastValidateLogCapacity; // Initial value is 8.
377 
378 
380 
383 
387 
388 private:
389  vtkShaderProgram2(const vtkShaderProgram2&); // Not implemented.
390  void operator=(const vtkShaderProgram2&); // Not implemented.
391 };
392 
393 // ----------------------------------------------------------------------------
394 //BTX
395 #define vtkShaderProgram2SetUniformCopyCastMacro(toLetter, toType, num) \
396 template<typename fromType> \
397 void vtkShaderProgram2::SetUniform##num##toLetter##t(const char *name, fromType *fvalues) \
398 { \
399  toType tvalues[num]; \
400  for (int i=0; i<num; ++i) \
401  { \
402  tvalues[i] = static_cast<toType>(fvalues[i]); \
403  } \
404  this->SetUniform##num##toLetter(name, tvalues); \
405 } \
406 template<typename fromType> \
407 void vtkShaderProgram2::SetUniform##num##toLetter##t(int location, fromType *fvalues) \
408 { \
409  assert(location!=-1); \
410  toType tvalues[num]; \
411  for (int i=0; i<num; ++i) \
412  { \
413  tvalues[i] = static_cast<toType>(fvalues[i]); \
414  } \
415  this->SetUniform##num##toLetter(location, tvalues); \
416 }
425 //ETX
426 
427 
428 #endif
void SetUniform2f(const char *name, float *val)
void SetUniform3f(const char *name, float *val)
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkTimeStamp LastLinkTime
void SetUniform1f(const char *name, float *val)
vtkWeakPointer< vtkRenderWindow > Context
GLSL uniform variables.
record modification and/or execution time
Definition: vtkTimeStamp.h:34
void SetUniformi(const char *name, int val)
vtkUniformVariables * UniformVariables
a list of Shader2 objects.
GLSL Program.
void SetUniform3i(const char *name, int *val)
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkShaderProgram2GeometryInType
#define vtkShaderProgram2SetUniformCopyCastMacro(toLetter, toType, num)
#define VTKRENDERINGOPENGL_EXPORT
void SetUniformf(const char *name, float val)
void SetUniformf(int loc, float val)
void SetUniform4f(const char *name, float *val)
void SetUniform4i(const char *name, int *val)
vtkShaderProgram2GeometryOutType
Interface class for querying and using OpenGL extensions.
void SetUniform2i(const char *name, int *val)
void SetUniformi(int loc, int val)
create a window for renderers to draw into
static vtkObject * New()
void SetUniform1i(const char *name, int *val)
vtkShaderProgram2BuildStatus
vtkTimeStamp LastSendUniformsTime
vtkShader2Collection * Shaders