VTK
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 "vtkRenderingOpenGL2Module.h" // For export macro
26 #include "vtkObject.h"
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(
44  const char *vertexCode,
45  const char *fragmentCode,
46  const char *geometryCode,
47  vtkTransformFeedback *cap = nullptr);
48 
49  // make sure the specified shaders are compiled, linked, and bound
50  // will increment the reference count on the shaders if it
51  // needs to keep them around
52  virtual vtkShaderProgram *ReadyShaderProgram(
53  std::map<vtkShader::Type,vtkShader *> shaders,
54  vtkTransformFeedback *cap = nullptr);
55 
56  // make sure the specified shaders are compiled, linked, and bound
57  virtual vtkShaderProgram *ReadyShaderProgram(
58  vtkShaderProgram *shader, vtkTransformFeedback *cap = nullptr);
59 
65  void ReleaseCurrentShader();
66 
70  virtual void ReleaseGraphicsResources(vtkWindow *win);
71 
76  virtual void ClearLastShaderBound() { this->LastShaderBound = nullptr; }
77  vtkGetObjectMacro(LastShaderBound, vtkShaderProgram);
78 
79 protected:
81  ~vtkOpenGLShaderCache() override;
82 
83  // perform System and Output replacements in place. Returns
84  // the number of outputs
85  virtual unsigned int ReplaceShaderValues(
86  std::string &VSSource,
87  std::string &FSSource,
88  std::string &GSSource);
89 
90  virtual vtkShaderProgram* GetShaderProgram(const char *vertexCode,
91  const char *fragmentCode,
92  const char *geometryCode);
93  virtual vtkShaderProgram* GetShaderProgram(
94  std::map<vtkShader::Type,vtkShader *> shaders);
95  virtual int BindShader(vtkShaderProgram* shader);
96 
97  class Private;
98  Private *Internal;
100 
103 
104 private:
106  void operator=(const vtkOpenGLShaderCache&) = delete;
107 
108 };
109 
110 #endif
OpenGL rendering window.
abstract base class for most VTK objects
Definition: vtkObject.h:59
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
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:37
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.