GteGLSLReflection.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <GTEngineDEF.h>
11 #include <Graphics/GL4/GteOpenGL.h>
12 #include <map>
13 #include <set>
14 #include <string>
15 #include <vector>
16 
17 // Query a program object for all information relevant to manipulating the
18 // program at run time.
19 
20 namespace gte
21 {
22 
24 {
25 public:
26  // Construction. The input is the handle to a program that was
27  // successfully created for the active context.
28  GLSLReflection(GLuint handle);
29 
30  enum // Named indices for the 'referencedBy' arrays.
31  {
37  ST_TESSEVALUATION
38  };
39 
40  struct Input
41  {
46  GLint referencedBy[6];
49  };
50 
51  struct Output
52  {
57  GLint referencedBy[6];
61  };
62 
63  struct Uniform
64  {
76  GLint referencedBy[6];
77  };
78 
79  struct DataBlock
80  {
84  GLint referencedBy[6];
85  std::vector<GLint> activeVariables;
86  };
87 
89  {
92  GLint referencedBy[6];
93  std::vector<GLint> activeVariables;
94  };
95 
97  {
101  std::vector<GLint> compatibleSubroutines;
102  };
103 
105  {
117  GLint referencedBy[6];
118  };
119 
121  {
127  };
128 
130  {
133  std::vector<GLint> activeVariables;
134  };
135 
136  // Member access.
137  inline GLuint GetProgramHandle() const;
138  inline std::vector<Input> const& GetInputs() const;
139  inline std::vector<Output> const& GetOutputs() const;
140  inline std::vector<Uniform> const& GetUniforms() const;
141  inline std::vector<DataBlock> const& GetUniformBlocks() const;
142  inline std::vector<BufferVariable> const& GetBufferVariables() const;
143  inline std::vector<DataBlock> const& GetBufferBlocks() const;
144  inline std::vector<AtomicCounterBuffer> const& GetAtomicCounterBuffers() const;
145 
146  // This will not work on an instance based on a visual program.
147  // This instance must correspond to a compute shader only program.
148  void GetComputeShaderWorkGroupSize(GLint &numXThreads, GLint& numYThreads, GLint& numZThreads) const;
149 
150  // Print to a text file for human readability.
151  void Print(std::ofstream& output) const;
152 
153 private:
154  void ReflectProgramInputs();
155  void ReflectProgramOutputs();
156  void ReflectUniforms();
157  void ReflectDataBlocks(GLenum programInterface,
158  std::vector<DataBlock>& blocks);
159  void ReflectAtomicCounterBuffers();
160  void ReflectSubroutines(GLenum programInterface,
161  std::vector<std::string>& subroutines);
162  void ReflectSubroutineUniforms(GLenum programInterface,
163  std::vector<SubroutineUniform>& subUniforms);
164  void ReflectBufferVariables();
165  void ReflectTransformFeedbackVaryings();
166  void ReflectTransformFeedbackBuffers();
167 
169  std::vector<Input> mInputs;
170  std::vector<Output> mOutputs;
171  std::vector<Uniform> mUniforms;
172  std::vector<DataBlock> mUniformBlocks;
173  std::vector<DataBlock> mShaderStorageBlocks;
174  std::vector<AtomicCounterBuffer> mAtomicCounterBuffers;
175  std::vector<std::string> mVertexSubroutines;
176  std::vector<std::string> mGeometrySubroutines;
177  std::vector<std::string> mPixelSubroutines;
178  std::vector<std::string> mComputeSubroutines;
179  std::vector<std::string> mTessControlSubroutines;
180  std::vector<std::string> mTessEvaluationSubroutines;
181  std::vector<SubroutineUniform> mVertexSubroutineUniforms;
182  std::vector<SubroutineUniform> mGeometrySubroutineUniforms;
183  std::vector<SubroutineUniform> mPixelSubroutineUniforms;
184  std::vector<SubroutineUniform> mComputeSubroutineUniforms;
185  std::vector<SubroutineUniform> mTessControlSubroutineUniforms;
186  std::vector<SubroutineUniform> mTessEvaluationSubroutineUniforms;
187  std::vector<BufferVariable> mBufferVariables;
188  std::vector<TransformFeedbackVarying> mTransformFeedbackVaryings;
189  std::vector<TransformFeedbackBuffer> mTransformFeedbackBuffers;
190 
191  // Used by Print() method to mape enums to strings.
192  struct EnumMap
193  {
197  unsigned rows; // use actual dim for straight vectors
198  unsigned cols; // only use for cols in matrices
199  unsigned size; // use 0 for opaques
200  };
201  static const EnumMap msEnumMap[];
202  static unsigned GetEnumSize(GLenum value, GLint arraySize, GLint arrayStride, GLint matrixStride, GLint isRowMajor);
203  static std::string GetEnumName(GLenum value);
204  static std::string GetEnumShaderName(GLenum value);
205  static std::string GetReferencedByShaderList(GLint const referencedBy[6]);
206 
207 private:
208  // TODO: This is a workaround for an apparent bug in the Intel
209  // HD 4600 OpenGL 4.3.0 (build 10.18.15.4281 and previous).
210  // Sometimes a buffer object in a compute shader is reported as
211  // unreferenced when in fact it is referenced. Remove this once
212  // the bug is fixed.
213  void IntelWorkaround(std::string const& name, GLint results[]);
215  std::map<GLenum, int> mShaderTypeMap;
216 };
217 
219 {
220  return mHandle;
221 }
222 
223 inline std::vector<GLSLReflection::Input> const&
225 {
226  return mInputs;
227 }
228 
229 inline std::vector<GLSLReflection::Output> const&
231 {
232  return mOutputs;
233 }
234 
235 inline std::vector<GLSLReflection::Uniform> const&
237 {
238  return mUniforms;
239 }
240 
241 inline std::vector<GLSLReflection::DataBlock> const&
243 {
244  return mUniformBlocks;
245 }
246 
247 inline std::vector<GLSLReflection::BufferVariable> const&
249 {
250  return mBufferVariables;
251 }
252 
253 inline std::vector<GLSLReflection::DataBlock> const&
255 {
256  return mShaderStorageBlocks;
257 }
258 
259 inline std::vector<GLSLReflection::AtomicCounterBuffer> const&
261 {
262  return mAtomicCounterBuffers;
263 }
264 
265 }
int GLint
Definition: glcorearb.h:85
unsigned int GLuint
Definition: glcorearb.h:89
std::vector< std::string > mTessEvaluationSubroutines
std::vector< BufferVariable > const & GetBufferVariables() const
std::vector< AtomicCounterBuffer > const & GetAtomicCounterBuffers() const
std::vector< Output > mOutputs
std::vector< SubroutineUniform > mTessControlSubroutineUniforms
std::vector< TransformFeedbackBuffer > mTransformFeedbackBuffers
std::vector< GLint > activeVariables
std::vector< DataBlock > const & GetBufferBlocks() const
GLsizei const GLfloat * value
Definition: glcorearb.h:819
GLuint const GLchar * name
Definition: glcorearb.h:781
std::vector< Input > const & GetInputs() const
std::vector< SubroutineUniform > mVertexSubroutineUniforms
std::vector< TransformFeedbackVarying > mTransformFeedbackVaryings
std::vector< SubroutineUniform > mPixelSubroutineUniforms
std::vector< std::string > mGeometrySubroutines
std::vector< SubroutineUniform > mComputeSubroutineUniforms
std::vector< Uniform > mUniforms
unsigned int GLenum
Definition: glcorearb.h:83
std::vector< std::string > mTessControlSubroutines
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
std::vector< DataBlock > mShaderStorageBlocks
std::vector< DataBlock > mUniformBlocks
std::vector< SubroutineUniform > mGeometrySubroutineUniforms
std::vector< BufferVariable > mBufferVariables
GLuint GetProgramHandle() const
std::vector< std::string > mPixelSubroutines
std::vector< std::string > mVertexSubroutines
GLenum programInterface
Definition: glcorearb.h:2517
std::vector< Output > const & GetOutputs() const
std::map< GLenum, int > mShaderTypeMap
std::vector< DataBlock > const & GetUniformBlocks() const
std::vector< AtomicCounterBuffer > mAtomicCounterBuffers
std::vector< std::string > mComputeSubroutines
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
std::vector< Input > mInputs
std::vector< SubroutineUniform > mTessEvaluationSubroutineUniforms
std::vector< Uniform > const & GetUniforms() const


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00