VTK  9.3.20240416
vtkOpenGLShaderCache.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
13 #ifndef vtkOpenGLShaderCache_h
14 #define vtkOpenGLShaderCache_h
15 
16 #include "vtkObject.h"
17 #include "vtkRenderingOpenGL2Module.h" // For export macro
18 #include "vtkShader.h" // for vtkShader::Type
19 #include <map> // for methods
20 
21 VTK_ABI_NAMESPACE_BEGIN
23 class vtkShaderProgram;
24 class vtkWindow;
26 
27 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLShaderCache : public vtkObject
28 {
29 public:
32  void PrintSelf(ostream& os, vtkIndent indent) override;
33 
35 
42  vtkSetMacro(SyncGLSLShaderVersion, bool);
43  vtkGetMacro(SyncGLSLShaderVersion, bool);
44  vtkBooleanMacro(SyncGLSLShaderVersion, bool);
46 
47  // make sure the specified shaders are compiled, linked, and bound
48  virtual vtkShaderProgram* ReadyShaderProgram(const char* vertexCode, const char* fragmentCode,
49  const char* geometryCode, vtkTransformFeedback* cap = nullptr);
50  virtual vtkShaderProgram* ReadyShaderProgram(const char* vertexCode, const char* fragmentCode,
51  const char* geometryCode, const char* tessControlCode, const char* tessEvalCode,
52  vtkTransformFeedback* cap = nullptr);
53 
54  // make sure the specified shaders are compiled, linked, and bound
55  // will increment the reference count on the shaders if it
56  // needs to keep them around
58  std::map<vtkShader::Type, vtkShader*> shaders, vtkTransformFeedback* cap = nullptr);
59 
60  // make sure the specified shaders are compiled, linked, and bound
62  vtkShaderProgram* shader, vtkTransformFeedback* cap = nullptr);
63 
70 
74  virtual void ReleaseGraphicsResources(vtkWindow* win);
75 
80  virtual void ClearLastShaderBound() { this->LastShaderBound = nullptr; }
81  vtkGetObjectMacro(LastShaderBound, vtkShaderProgram);
82 
83  // Set the time in seconds elapsed since the first render
84  void SetElapsedTime(float val) { this->ElapsedTime = val; }
85 
86 protected:
89 
90  // perform System and Output replacements in place. Returns
91  // the number of outputs
92  virtual unsigned int ReplaceShaderValues(std::string& VSSource, std::string& FSSource,
93  std::string& GSSource, std::string& TCSSource, std::string& TESSource);
94 
95  virtual vtkShaderProgram* GetShaderProgram(const char* vertexCode, const char* fragmentCode,
96  const char* geometryCode, const char* tessControlCode, const char* tessEvalCode);
97  virtual vtkShaderProgram* GetShaderProgram(std::map<vtkShader::Type, vtkShader*> shaders);
98  virtual int BindShader(vtkShaderProgram* shader);
99 
100  class Private;
101  Private* Internal;
103 
107 
108  float ElapsedTime;
109 
110 private:
112  void operator=(const vtkOpenGLShaderCache&) = delete;
113 };
114 
115 VTK_ABI_NAMESPACE_END
116 #endif
a simple class to control print indentation
Definition: vtkIndent.h:108
abstract base class for most VTK objects
Definition: vtkObject.h:162
OpenGL rendering window.
manage Shader Programs within a context
virtual int BindShader(vtkShaderProgram *shader)
~vtkOpenGLShaderCache() override
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetElapsedTime(float val)
virtual vtkShaderProgram * ReadyShaderProgram(vtkShaderProgram *shader, vtkTransformFeedback *cap=nullptr)
static vtkOpenGLShaderCache * New()
virtual vtkShaderProgram * ReadyShaderProgram(const char *vertexCode, const char *fragmentCode, const char *geometryCode, vtkTransformFeedback *cap=nullptr)
vtkShaderProgram * LastShaderBound
void ReleaseCurrentShader()
Release the current shader.
virtual vtkShaderProgram * GetShaderProgram(const char *vertexCode, const char *fragmentCode, const char *geometryCode, const char *tessControlCode, const char *tessEvalCode)
virtual vtkShaderProgram * ReadyShaderProgram(const char *vertexCode, const char *fragmentCode, const char *geometryCode, const char *tessControlCode, const char *tessEvalCode, vtkTransformFeedback *cap=nullptr)
virtual unsigned int ReplaceShaderValues(std::string &VSSource, std::string &FSSource, std::string &GSSource, std::string &TCSSource, std::string &TESSource)
virtual void ReleaseGraphicsResources(vtkWindow *win)
Free up any resources being used by the provided shader.
virtual vtkShaderProgram * GetShaderProgram(std::map< vtkShader::Type, vtkShader * > shaders)
virtual void ClearLastShaderBound()
Get/Clear the last Shader bound, called by shaders as they release their graphics resources.
virtual vtkShaderProgram * ReadyShaderProgram(std::map< vtkShader::Type, vtkShader * > shaders, vtkTransformFeedback *cap=nullptr)
The ShaderProgram uses one or more Shader objects.
Manages a TransformFeedback buffer.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:48
@ string
Definition: vtkX3D.h:490