VTK  9.3.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
10 #ifndef vtkOpenGLShaderCache_h
11 #define vtkOpenGLShaderCache_h
12 
13 #include "vtkObject.h"
14 #include "vtkRenderingOpenGL2Module.h" // For export macro
15 #include "vtkShader.h" // for vtkShader::Type
16 #include <map> // for methods
17 
18 VTK_ABI_NAMESPACE_BEGIN
20 class vtkShaderProgram;
21 class vtkWindow;
23 
24 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLShaderCache : public vtkObject
25 {
26 public:
27  static vtkOpenGLShaderCache* New();
29  void PrintSelf(ostream& os, vtkIndent indent) override;
30 
31  // make sure the specified shaders are compiled, linked, and bound
32  virtual vtkShaderProgram* ReadyShaderProgram(const char* vertexCode, const char* fragmentCode,
33  const char* geometryCode, vtkTransformFeedback* cap = nullptr);
34 
35  // make sure the specified shaders are compiled, linked, and bound
36  // will increment the reference count on the shaders if it
37  // needs to keep them around
38  virtual vtkShaderProgram* ReadyShaderProgram(
39  std::map<vtkShader::Type, vtkShader*> shaders, vtkTransformFeedback* cap = nullptr);
40 
41  // make sure the specified shaders are compiled, linked, and bound
42  virtual vtkShaderProgram* ReadyShaderProgram(
43  vtkShaderProgram* shader, vtkTransformFeedback* cap = nullptr);
44 
50  void ReleaseCurrentShader();
51 
55  virtual void ReleaseGraphicsResources(vtkWindow* win);
56 
61  virtual void ClearLastShaderBound() { this->LastShaderBound = nullptr; }
62  vtkGetObjectMacro(LastShaderBound, vtkShaderProgram);
63 
64  // Set the time in seconds elapsed since the first render
65  void SetElapsedTime(float val) { this->ElapsedTime = val; }
66 
67 protected:
69  ~vtkOpenGLShaderCache() override;
70 
71  // perform System and Output replacements in place. Returns
72  // the number of outputs
73  virtual unsigned int ReplaceShaderValues(
74  std::string& VSSource, std::string& FSSource, std::string& GSSource);
75 
76  virtual vtkShaderProgram* GetShaderProgram(
77  const char* vertexCode, const char* fragmentCode, const char* geometryCode);
78  virtual vtkShaderProgram* GetShaderProgram(std::map<vtkShader::Type, vtkShader*> shaders);
79  virtual int BindShader(vtkShaderProgram* shader);
80 
81  class Private;
82  Private* Internal;
84 
87 
88  float ElapsedTime;
89 
90 private:
92  void operator=(const vtkOpenGLShaderCache&) = delete;
93 };
94 
95 VTK_ABI_NAMESPACE_END
96 #endif
OpenGL rendering window.
abstract base class for most VTK objects
Definition: vtkObject.h:51
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:27
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.