1 #ifndef _GLUPROGRAMINTERFACEQUERY_HPP
2 #define _GLUPROGRAMINTERFACEQUERY_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL Utilities
5 * ---------------------------------------------
6 *
7 * Copyright 2014 The Android Open Source Project
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Program interface query utilities
24 *//*--------------------------------------------------------------------*/
25
26 #include "gluDefs.hpp"
27
28 #include <vector>
29 #include <string>
30
31 namespace glw
32 {
33 class Functions;
34 }
35
36 namespace glu
37 {
38
39 //! Interface block info.
40 struct InterfaceBlockInfo
41 {
42 std::string name;
43 uint32_t index;
44 uint32_t bufferBinding; //!< GL_BUFFER_BINDING
45 uint32_t dataSize; //!< GL_BUFFER_DATA_SIZE
46 std::vector<int> activeVariables; //!< GL_ACTIVE_VARIABLES
47
InterfaceBlockInfoglu::InterfaceBlockInfo48 InterfaceBlockInfo(void) : index(~0u /* GL_INVALID_INDEX */), bufferBinding(0), dataSize(0)
49 {
50 }
51 };
52
53 //! Interface variable (uniform in uniform block, buffer variable) info.
54 struct InterfaceVariableInfo
55 {
56 std::string name;
57 uint32_t index;
58 uint32_t blockIndex; //!< GL_BLOCK_INDEX
59 uint32_t atomicCounterBufferIndex; //!< GL_ATOMIC_COUNTER_BUFFER_INDEX
60 uint32_t type; //!< GL_TYPE
61 uint32_t arraySize; //!< GL_ARRAY_SIZE
62 uint32_t offset; //!< GL_OFFSET
63 int32_t arrayStride; //!< GL_ARRAY_STRIDE
64 int32_t matrixStride; //!< GL_MATRIX_STRIDE
65 uint32_t topLevelArraySize; //!< GL_TOP_LEVEL_ARRAY_SIZE - set only for GL_BUFFER_VARIABLEs
66 int32_t topLevelArrayStride; //!< GL_TOP_LEVEL_ARRAY_STRIDE - set only for GL_BUFFER_VARIABLEs
67 bool isRowMajor; //!< GL_IS_ROW_MAJOR
68
InterfaceVariableInfoglu::InterfaceVariableInfo69 InterfaceVariableInfo(void)
70 : index(~0u /* GL_INVALID_INDEX */)
71 , blockIndex(~0u /* GL_INVALID_INDEX */)
72 , atomicCounterBufferIndex(~0u /* GL_INVALID_INDEX */)
73 , type(0)
74 , arraySize(0)
75 , offset(0)
76 , arrayStride(0)
77 , matrixStride(0)
78 , topLevelArraySize(0)
79 , topLevelArrayStride(0)
80 , isRowMajor(0)
81 {
82 }
83 };
84
85 int getProgramResourceInt(const glw::Functions &gl, uint32_t program, uint32_t programInterface, uint32_t index,
86 uint32_t queryParam);
87 uint32_t getProgramResourceUint(const glw::Functions &gl, uint32_t program, uint32_t programInterface, uint32_t index,
88 uint32_t queryParam);
89
90 void getProgramResourceName(const glw::Functions &gl, uint32_t program, uint32_t programInterface, uint32_t index,
91 std::string &dst);
92 std::string getProgramResourceName(const glw::Functions &gl, uint32_t program, uint32_t programInterface,
93 uint32_t index);
94
95 void getProgramInterfaceBlockInfo(const glw::Functions &gl, uint32_t program, uint32_t programInterface, uint32_t index,
96 InterfaceBlockInfo &info);
97 InterfaceBlockInfo getProgramInterfaceBlockInfo(const glw::Functions &gl, uint32_t program, uint32_t programInterface,
98 uint32_t index);
99
100 void getProgramInterfaceVariableInfo(const glw::Functions &gl, uint32_t program, uint32_t programInterface,
101 uint32_t index, InterfaceVariableInfo &info);
102 InterfaceVariableInfo getProgramInterfaceVariableInfo(const glw::Functions &gl, uint32_t program,
103 uint32_t programInterface, uint32_t index);
104
105 // Inline implementations for optimization (RVO in most cases).
106
getProgramResourceInt(const glw::Functions & gl,uint32_t program,uint32_t programInterface,uint32_t index,uint32_t queryParam)107 inline int getProgramResourceInt(const glw::Functions &gl, uint32_t program, uint32_t programInterface, uint32_t index,
108 uint32_t queryParam)
109 {
110 return (int)getProgramResourceUint(gl, program, programInterface, index, queryParam);
111 }
112
getProgramResourceName(const glw::Functions & gl,uint32_t program,uint32_t programInterface,uint32_t index)113 inline std::string getProgramResourceName(const glw::Functions &gl, uint32_t program, uint32_t programInterface,
114 uint32_t index)
115 {
116 std::string name;
117 getProgramResourceName(gl, program, programInterface, index, name);
118 return name;
119 }
120
getProgramInterfaceBlockInfo(const glw::Functions & gl,uint32_t program,uint32_t programInterface,uint32_t index)121 inline InterfaceBlockInfo getProgramInterfaceBlockInfo(const glw::Functions &gl, uint32_t program,
122 uint32_t programInterface, uint32_t index)
123 {
124 InterfaceBlockInfo info;
125 getProgramInterfaceBlockInfo(gl, program, programInterface, index, info);
126 return info;
127 }
128
getProgramInterfaceVariableInfo(const glw::Functions & gl,uint32_t program,uint32_t programInterface,uint32_t index)129 inline InterfaceVariableInfo getProgramInterfaceVariableInfo(const glw::Functions &gl, uint32_t program,
130 uint32_t programInterface, uint32_t index)
131 {
132 InterfaceVariableInfo info;
133 getProgramInterfaceVariableInfo(gl, program, programInterface, index, info);
134 return info;
135 }
136
137 } // namespace glu
138
139 #endif // _GLUPROGRAMINTERFACEQUERY_HPP
140