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=========================================================================*/
28#ifndef vtkShaderProgram2_h
29#define vtkShaderProgram2_h
30
31#include <cassert> // for templated functions
32#include "vtkRenderingOpenGLModule.h" // for export macro
33#include "vtkWeakPointer.h" // for weak ptr to rendering context
34#include "vtkObject.h"
35
36class vtkRenderWindow;
40
41// Values for GetLastBuildStatus()
43{
44 // one of the shaders failed to compile
46 // all the shaders compiled successfully but the link failed
48 // all the shaders compiled successfully and the link succeeded
50};
51
53{
59};
60
62{
66};
67
68class VTKRENDERINGOPENGL_EXPORT vtkShaderProgram2 : public vtkObject
69{
70public:
73 void PrintSelf(ostream& os, vtkIndent indent);
74
79 static bool IsSupported(vtkRenderWindow *context);
80
82
90 vtkGetMacro(PrintErrors,bool);
91 vtkSetMacro(PrintErrors,bool);
93
95
104
106
110 vtkGetObjectMacro(Shaders,vtkShader2Collection);
112
119
124
129
134
142
149 bool IsValid();
150
158 void Build();
159
167
175 vtkIndent indent);
176
184
190 bool IsUsed();
191
200 void Use();
201
207 void Restore();
208
217
219
226
237
243 const char *GetLastLinkLog();
244
250 const char *GetLastValidateLog();
251
256
265 int GetAttributeLocation(const char *name);
266
268
272 vtkGetObjectMacro(UniformVariables,vtkUniformVariables);
273 virtual void SetUniformVariables(vtkUniformVariables *variables);
275
286
288
301 vtkSetMacro(GeometryTypeIn,int);
302 vtkGetMacro(GeometryTypeIn,int);
304
306
318 vtkSetMacro(GeometryVerticesOut,int);
319 vtkGetMacro(GeometryVerticesOut,int);
321
323
334 vtkSetMacro(GeometryTypeOut,int);
335 vtkGetMacro(GeometryTypeOut,int);
337
338 /*
339 Low level api --
340 this is provided as a way to avoid some of the overhead in this
341 class's implementation of SendUniforms. One should use the
342 following API if performance is a concern (eg. uniforms are
343 set per primative), or if the uniform management is not needed
344 (eg. variables are already managed in other vtkObjects)
345 */
346
351 int GetUniformLocation(const char *name);
352
360 void SetUniformf(const char *name, float val)
361 { this->SetUniform1f(name, &val); }
362 void SetUniform1f(const char *name, float *val)
363 { this->SetUniform1f(this->GetUniformLocation(name), val); }
364 void SetUniform2f(const char *name, float *val)
365 { this->SetUniform2f(this->GetUniformLocation(name), val); }
366 void SetUniform3f(const char *name, float *val)
367 { this->SetUniform3f(this->GetUniformLocation(name), val); }
368 void SetUniform4f(const char *name, float *val)
369 { this->SetUniform4f(this->GetUniformLocation(name), val); }
370
371 void SetUniformi(const char *name, int val)
372 { this->SetUniform1i(name, &val); }
373 void SetUniform1i(const char *name, int *val)
374 { this->SetUniform1i(this->GetUniformLocation(name), val); }
375 void SetUniform2i(const char *name, int *val)
376 { this->SetUniform2i(this->GetUniformLocation(name), val); }
377 void SetUniform3i(const char *name, int *val)
378 { this->SetUniform3i(this->GetUniformLocation(name), val); }
379 void SetUniform4i(const char *name, int *val)
380 { this->SetUniform4i(this->GetUniformLocation(name), val); }
381
382 void SetUniformf(int loc, float val)
383 { this->SetUniform1f(loc, &val); }
384 void SetUniform1f(int loc, float *val);
385 void SetUniform2f(int loc, float *val);
386 void SetUniform3f(int loc, float *val);
387 void SetUniform4f(int loc, float *val);
388
389 void SetUniformi(int loc, int val)
390 { this->SetUniform1i(loc, &val); }
391 void SetUniform1i(int loc, int *val);
392 void SetUniform2i(int loc, int *val);
393 void SetUniform3i(int loc, int *val);
394 void SetUniform4i(int loc, int *val);
395
397
402 template<typename T> void SetUniform1it(const char *name, T *value);
403 template<typename T> void SetUniform2it(const char *name, T *value);
404 template<typename T> void SetUniform3it(const char *name, T *value);
405 template<typename T> void SetUniform4it(const char *name, T *value);
407
408 template<typename T> void SetUniform1ft(const char *name, T *value);
409 template<typename T> void SetUniform2ft(const char *name, T *value);
410 template<typename T> void SetUniform3ft(const char *name, T *value);
411 template<typename T> void SetUniform4ft(const char *name, T *value);
412
413 template<typename T> void SetUniform1it(int loc, T *value);
414 template<typename T> void SetUniform2it(int loc, T *value);
415 template<typename T> void SetUniform3it(int loc, T *value);
416 template<typename T> void SetUniform4it(int loc, T *value);
417
418 template<typename T> void SetUniform1ft(int loc, T *value);
419 template<typename T> void SetUniform2ft(int loc, T *value);
420 template<typename T> void SetUniform3ft(int loc, T *value);
421 template<typename T> void SetUniform4ft(int loc, T *value);
422
423protected:
426
431
442
443 unsigned int Id; // actually GLuint. Initial value is 0.
444 unsigned int SavedId;
445
448
451
452 int LastBuildStatus; // Initial value is VTK_SHADER_PROGRAM2_COMPILE_FAILED
453
454 char *LastLinkLog; // Initial value is the empty string ""='\0'
455 size_t LastLinkLogCapacity; // Initial value is 8.
456
457 char *LastValidateLog; // Initial value is the empty string ""='\0'
458 size_t LastValidateLogCapacity; // Initial value is 8.
459
460
462
465
469
470private:
471 vtkShaderProgram2(const vtkShaderProgram2&) VTK_DELETE_FUNCTION;
472 void operator=(const vtkShaderProgram2&) VTK_DELETE_FUNCTION;
473};
474
475// ----------------------------------------------------------------------------
476
477#define vtkShaderProgram2SetUniformCopyCastMacro(toLetter, toType, num) \
478template<typename fromType> \
479void vtkShaderProgram2::SetUniform##num##toLetter##t(const char *name, fromType *fvalues) \
480{ \
481 toType tvalues[num]; \
482 for (int i=0; i<num; ++i) \
483 { \
484 tvalues[i] = static_cast<toType>(fvalues[i]); \
485 } \
486 this->SetUniform##num##toLetter(name, tvalues); \
487} \
488template<typename fromType> \
489void vtkShaderProgram2::SetUniform##num##toLetter##t(int location, fromType *fvalues) \
490{ \
491 assert(location!=-1); \
492 toType tvalues[num]; \
493 for (int i=0; i<num; ++i) \
494 { \
495 tvalues[i] = static_cast<toType>(fvalues[i]); \
496 } \
497 this->SetUniform##num##toLetter(location, tvalues); \
498}
507
508#endif
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
Interface class for querying and using OpenGL extensions.
create a window for renderers to draw into
a list of Shader2 objects.
void SetUniform1f(const char *name, float *val)
void SetUniform2ft(int loc, T *value)
void Build()
If not done yet, compile all the shaders and link the program.
const char * GetLastLinkLog()
Return the log of the last link as a string.
void SetUniform4f(int loc, float *val)
void SetUniform2it(const char *name, T *value)
int GetUniformLocation(const char *name)
Get a uniform's location.
void SetUniform4i(const char *name, int *val)
bool HasGeometryShaders()
Tells if at least one of the shaders is a geometry shader.
bool HasTessellationControlShaders()
Tells if at least one of the shaders is a tessellation control shader.
bool HasFragmentShaders()
Tells if at least one of the shaders is a fragment shader.
void SetUniform2f(int loc, float *val)
vtkTimeStamp LastLinkTime
int GetLastBuildStatus()
Tells if the last build: failed during compilation of one of the shader, fails during link of the pro...
const char * GetLastValidateLog()
Return the log of the last call to IsValid as a string.
vtkUniformVariables * UniformVariables
void SetUniform3i(int loc, int *val)
void SetUniform1ft(int loc, T *value)
void SetUniform1i(const char *name, int *val)
void SetUniform4i(int loc, int *val)
bool IsValid()
Tell if the shader program is valid with the current OpenGL state.
int GetUniformLocationInternal(const char *name)
Get the location of a uniform, without caring if it really exists.
virtual void ReleaseGraphicsResources()
Release OpenGL resource (program id and sub-resources).
bool LoadRequiredExtensions(vtkRenderWindow *context)
Load the required OpenGL extentions.
void RestoreFixedPipeline()
Force the current shader program to be the fixed-pipeline.
void SetUniformf(int loc, float val)
static vtkShaderProgram2 * New()
void SetUniform4it(int loc, T *value)
void Restore()
Restore the previous shader program (or fixed-pipeline).
void PrintActiveUniformVariables(ostream &os, vtkIndent indent)
Introspection.
vtkRenderWindow * GetContext()
bool HasTessellationEvaluationShaders()
Tells if at least one of the shaders is a tessellation evaluation shader.
void SetUniform2ft(const char *name, T *value)
void SetUniformi(int loc, int val)
void SetUniformf(const char *name, float val)
Set a uniform value directly.
void SetUniform4ft(int loc, T *value)
void SetUniform3ft(int loc, T *value)
void SetUniform2it(int loc, T *value)
bool HasVertexShaders()
Tells if at least one of the shaders is a vertex shader.
void SendUniforms()
Send the uniform variables values to the program.
static bool IsSupported(vtkRenderWindow *context)
Returns if the context supports the required extensions.
void SetUniform2i(int loc, int *val)
void SetUniform1it(const char *name, T *value)
Convenience methods for copy/convert to supported type.
void SetUniform1f(int loc, float *val)
void SetUniform2f(const char *name, float *val)
virtual void SetUniformVariables(vtkUniformVariables *variables)
void SetUniform1it(int loc, T *value)
int GetAttributeLocation(const char *name)
Returns the generic attribute location.
void SetUniform1ft(const char *name, T *value)
void Use()
Use the shader program.
void SetUniform4f(const char *name, float *val)
virtual ~vtkShaderProgram2()
void SetUniform3f(int loc, float *val)
void PrintActiveUniformVariablesOnCout()
Call PrintActiveUniformVariables on cout.
void SetUniform3it(const char *name, T *value)
bool IsUsed()
Tell if the program is the one currently used by OpenGL.
void SetUniform4ft(const char *name, T *value)
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
void SetUniform3f(const char *name, float *val)
void SetUniform4it(const char *name, T *value)
void SetContext(vtkRenderWindow *context)
Get/Set the context.
void SetUniform3ft(const char *name, T *value)
void UseProgram()
Simple direct use of the program without side affects and with error check.
vtkWeakPointer< vtkRenderWindow > Context
void SetUniform3it(int loc, T *value)
vtkShader2Collection * Shaders
void SetUniform3i(const char *name, int *val)
void SetUniform1i(int loc, int *val)
bool DisplayListUnderCreationInCompileMode()
Tells if a display list is under construction with GL_COMPILE mode.
void SetUniform2i(const char *name, int *val)
vtkTimeStamp LastSendUniformsTime
void SetUniformi(const char *name, int val)
record modification and/or execution time
Definition: vtkTimeStamp.h:36
GLSL uniform variables.
@ value
Definition: vtkX3D.h:220
@ name
Definition: vtkX3D.h:219
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkShaderProgram2BuildStatus
@ VTK_SHADER_PROGRAM2_LINK_SUCCEEDED
@ VTK_SHADER_PROGRAM2_COMPILE_FAILED
@ VTK_SHADER_PROGRAM2_LINK_FAILED
vtkShaderProgram2GeometryInType
@ VTK_GEOMETRY_SHADER_IN_TYPE_LINES_ADJACENCY
@ VTK_GEOMETRY_SHADER_IN_TYPE_TRIANGLES_ADJACENCY
@ VTK_GEOMETRY_SHADER_IN_TYPE_POINTS
@ VTK_GEOMETRY_SHADER_IN_TYPE_LINES
@ VTK_GEOMETRY_SHADER_IN_TYPE_TRIANGLES
#define vtkShaderProgram2SetUniformCopyCastMacro(toLetter, toType, num)
vtkShaderProgram2GeometryOutType
@ VTK_GEOMETRY_SHADER_OUT_TYPE_LINE_STRIP
@ VTK_GEOMETRY_SHADER_OUT_TYPE_TRIANGLE_STRIP
@ VTK_GEOMETRY_SHADER_OUT_TYPE_POINTS