VTK  9.5.20251208
vtkOpenGLShaderDeclaration.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
8
9#ifndef vtkOpenGLShaderDeclaration_h
10#define vtkOpenGLShaderDeclaration_h
11
12#include "vtkRenderingOpenGL2Module.h"
13#include "vtkStringToken.h"
14
15VTK_ABI_NAMESPACE_BEGIN
16class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLShaderDeclaration
17{
18public:
32
33 enum class GLSLDataType
34 {
38 };
39
47
49 {
53 };
62 : QualifierType(qual)
63 , PrecisionType(prec)
64 , DataType(dtype)
65 , AttributeType(attr)
66 , VariableName(varName)
67 {
68 }
69
70 friend std::ostream& operator<<(std::ostream& os, const vtkOpenGLShaderDeclaration& decl)
71 {
72 const std::string space = " ";
73 switch (decl.QualifierType)
74 {
76 os << "uniform";
77 break;
79 os << "in";
80 break;
82 default:
83 os << "out";
84 break;
85 }
86
87 switch (decl.PrecisionType)
88 {
90 os << space;
91 os << "lowp";
92 break;
94 os << space;
95 os << "mediump";
96 break;
98 os << space;
99 os << "highp";
100 break;
102 default:
103 break;
104 }
105
107 {
108 switch (decl.DataType)
109 {
111 os << space;
112 os << "u";
113 break;
115 os << space;
116 os << "i";
117 break;
119 default:
120 os << space;
121 break;
122 }
123 }
124
125 switch (decl.AttributeType)
126 {
128 os << "mat3";
129 break;
131 os << "mat4";
132 break;
134 os << "samplerBuffer";
135 break;
137 os << "samplerCube";
138 break;
140 os << "sampler2D";
141 break;
143 os << "sampler1D";
144 break;
146 switch (decl.DataType)
147 {
149 os << space;
150 os << "uint";
151 break;
153 os << space;
154 os << "int";
155 break;
157 default:
158 os << space;
159 os << "float";
160 break;
161 }
162 break;
164 os << "vec2";
165 break;
167 os << "vec3";
168 break;
170 default:
171 os << "vec4";
172 break;
173 }
174 os << space << decl.VariableName.Data() << ";";
175 return os;
176 }
177};
178
179VTK_ABI_NAMESPACE_END
180#endif // vtkOpenGLShaderDeclaration_h
vtkOpenGLShaderDeclaration()=default
friend std::ostream & operator<<(std::ostream &os, const vtkOpenGLShaderDeclaration &decl)
vtkOpenGLShaderDeclaration(GLSLQualifierType qual, GLSLPrecisionType prec, GLSLDataType dtype, GLSLAttributeType attr, vtkStringToken varName)
Represent a string by its integer hash.
const std::string & Data() const
Return the string corresponding to the token.