VTK  9.3.0
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:
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
39  std::map<vtkShader::Type, vtkShader*> shaders, vtkTransformFeedback* cap = nullptr);
40 
41  // make sure the specified shaders are compiled, linked, and bound
43  vtkShaderProgram* shader, vtkTransformFeedback* cap = nullptr);
44 
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:
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 
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
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
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 unsigned int ReplaceShaderValues(std::string &VSSource, std::string &FSSource, std::string &GSSource)
virtual vtkShaderProgram * GetShaderProgram(const char *vertexCode, const char *fragmentCode, const char *geometryCode)
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:37
@ string
Definition: vtkX3D.h:490