VTK  9.2.6
vtkOpenGLShaderCache.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenGLTexture.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 =========================================================================*/
22 #ifndef vtkOpenGLShaderCache_h
23 #define vtkOpenGLShaderCache_h
24 
25 #include "vtkObject.h"
26 #include "vtkRenderingOpenGL2Module.h" // For export macro
27 #include "vtkShader.h" // for vtkShader::Type
28 #include <map> // for methods
29 
31 class vtkShaderProgram;
32 class vtkWindow;
34 
35 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLShaderCache : public vtkObject
36 {
37 public:
38  static vtkOpenGLShaderCache* New();
40  void PrintSelf(ostream& os, vtkIndent indent) override;
41 
42  // make sure the specified shaders are compiled, linked, and bound
43  virtual vtkShaderProgram* ReadyShaderProgram(const char* vertexCode, const char* fragmentCode,
44  const char* geometryCode, vtkTransformFeedback* cap = nullptr);
45 
46  // make sure the specified shaders are compiled, linked, and bound
47  // will increment the reference count on the shaders if it
48  // needs to keep them around
49  virtual vtkShaderProgram* ReadyShaderProgram(
50  std::map<vtkShader::Type, vtkShader*> shaders, vtkTransformFeedback* cap = nullptr);
51 
52  // make sure the specified shaders are compiled, linked, and bound
53  virtual vtkShaderProgram* ReadyShaderProgram(
54  vtkShaderProgram* shader, vtkTransformFeedback* cap = nullptr);
55 
61  void ReleaseCurrentShader();
62 
66  virtual void ReleaseGraphicsResources(vtkWindow* win);
67 
72  virtual void ClearLastShaderBound() { this->LastShaderBound = nullptr; }
73  vtkGetObjectMacro(LastShaderBound, vtkShaderProgram);
74 
75  // Set the time in seconds elapsed since the first render
76  void SetElapsedTime(float val) { this->ElapsedTime = val; }
77 
78 protected:
80  ~vtkOpenGLShaderCache() override;
81 
82  // perform System and Output replacements in place. Returns
83  // the number of outputs
84  virtual unsigned int ReplaceShaderValues(
85  std::string& VSSource, std::string& FSSource, std::string& GSSource);
86 
87  virtual vtkShaderProgram* GetShaderProgram(
88  const char* vertexCode, const char* fragmentCode, const char* geometryCode);
89  virtual vtkShaderProgram* GetShaderProgram(std::map<vtkShader::Type, vtkShader*> shaders);
90  virtual int BindShader(vtkShaderProgram* shader);
91 
92  class Private;
93  Private* Internal;
95 
98 
99  float ElapsedTime;
100 
101 private:
103  void operator=(const vtkOpenGLShaderCache&) = delete;
104 };
105 
106 #endif
OpenGL rendering window.
abstract base class for most VTK objects
Definition: vtkObject.h:62
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:38
a simple class to control print indentation
Definition: vtkIndent.h:39
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.