VTK  9.7.1
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:
30  static vtkOpenGLShaderCache* New();
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
57  virtual vtkShaderProgram* ReadyShaderProgram(
58  std::map<vtkShader::Type, vtkShader*> shaders, vtkTransformFeedback* cap = nullptr);
59 
60  // make sure the specified shaders are compiled, linked, and bound
61  virtual vtkShaderProgram* ReadyShaderProgram(
62  vtkShaderProgram* shader, vtkTransformFeedback* cap = nullptr);
63 
69  void ReleaseCurrentShader();
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:
88  ~vtkOpenGLShaderCache() override;
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
OpenGL rendering window.
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
manage Shader Programs within a context
void SetElapsedTime(float val)
virtual void ClearLastShaderBound()
Get/Clear the last Shader bound, called by shaders as they release their graphics resources...
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
a simple class to control print indentation
Definition: vtkIndent.h:28
Manages a TransformFeedback buffer.
vtkShaderProgram * LastShaderBound
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
The ShaderProgram uses one or more Shader objects.