VTK  9.3.20240424
vtkShader.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
102#ifndef vtkShader_h
103#define vtkShader_h
104
105#include "vtkObject.h"
106#include "vtkRenderingOpenGL2Module.h" // for export macro
107
108#include <string> // For member variables.
109#include <vector> // For member variables.
110
118VTK_ABI_NAMESPACE_BEGIN
119class VTKRENDERINGOPENGL2_EXPORT vtkShader : public vtkObject
120{
121public:
122 static vtkShader* New();
123 vtkTypeMacro(vtkShader, vtkObject);
124 void PrintSelf(ostream& os, vtkIndent indent) override;
125
127 enum Type
128 {
135 Unknown
136 };
137
139 void SetType(Type type);
140
142 Type GetType() const { return this->ShaderType; }
143
145 void SetSource(const std::string& source);
146
148 std::string GetSource() const { return this->Source; }
149
151 std::string GetError() const { return this->Error; }
152
154 int GetHandle() const { return this->Handle; }
155
159 bool Compile();
160
165 void Cleanup();
166
169
172
174 {
175 public:
176 std::string OriginalValue;
179 bool operator<(const ReplacementSpec& v1) const
180 {
181 if (this->OriginalValue != v1.OriginalValue)
182 {
183 return this->OriginalValue < v1.OriginalValue;
184 }
185 if (this->ShaderType != v1.ShaderType)
186 {
187 return this->ShaderType < v1.ShaderType;
188 }
189 return (this->ReplaceFirst < v1.ReplaceFirst);
190 }
191 bool operator>(const ReplacementSpec& v1) const
192 {
193 if (this->OriginalValue != v1.OriginalValue)
194 {
195 return this->OriginalValue > v1.OriginalValue;
196 }
197 if (this->ShaderType != v1.ShaderType)
198 {
199 return this->ShaderType > v1.ShaderType;
200 }
201 return (this->ReplaceFirst > v1.ReplaceFirst);
202 }
203 };
205 {
206 public:
207 std::string Replacement;
209 };
210
211protected:
213 ~vtkShader() override;
214
217 bool Dirty;
218
219 std::string Source;
220 std::string Error;
221
222private:
223 vtkShader(const vtkShader&) = delete;
224 void operator=(const vtkShader&) = delete;
225};
226
227VTK_ABI_NAMESPACE_END
228#endif
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
bool operator>(const ReplacementSpec &v1) const
Definition vtkShader.h:191
vtkShader::Type ShaderType
Definition vtkShader.h:177
bool operator<(const ReplacementSpec &v1) const
Definition vtkShader.h:179
Vertex or Fragment shader, combined into a ShaderProgram.
Definition vtkShader.h:120
void Cleanup()
Delete the shader.
Type ShaderType
Definition vtkShader.h:215
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
std::string Error
Definition vtkShader.h:220
Type GetType() const
Get the shader type, typically Vertex or Fragment.
Definition vtkShader.h:142
static vtkShader * New()
static bool IsComputeShaderSupported()
Check if compute shaders are supported.
std::string GetSource() const
Get the source for the shader.
Definition vtkShader.h:148
std::string GetError() const
Get the error message (empty if none) for the shader.
Definition vtkShader.h:151
bool Compile()
Compile the shader.
std::string Source
Definition vtkShader.h:219
~vtkShader() override
int GetHandle() const
Get the handle of the shader.
Definition vtkShader.h:154
Type
Available shader types.
Definition vtkShader.h:128
@ Vertex
Vertex shader.
Definition vtkShader.h:129
@ TessControl
Tessellation Control.
Definition vtkShader.h:133
@ Geometry
Geometry shader.
Definition vtkShader.h:131
@ Fragment
Fragment shader.
Definition vtkShader.h:130
@ Compute
Compute shader.
Definition vtkShader.h:132
@ TessEvaluation
Tessellation Evaluation.
Definition vtkShader.h:134
bool Dirty
Definition vtkShader.h:217
static bool IsTessellationShaderSupported()
Check if tessellation shaders are supported.
void SetSource(const std::string &source)
Set the shader source to the supplied string.
void SetType(Type type)
Set the shader type.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)