1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL Utilities
3 * ---------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Program interface query utilities
22 *//*--------------------------------------------------------------------*/
23
24 #include "gluProgramInterfaceQuery.hpp"
25 #include "glwFunctions.hpp"
26 #include "glwEnums.hpp"
27
28 #include <sstream>
29
30 namespace glu
31 {
32
getProgramResourceUint(const glw::Functions & gl,uint32_t program,uint32_t programInterface,uint32_t index,uint32_t queryParam)33 uint32_t getProgramResourceUint(const glw::Functions &gl, uint32_t program, uint32_t programInterface, uint32_t index,
34 uint32_t queryParam)
35 {
36 uint32_t value = 0;
37 gl.getProgramResourceiv(program, programInterface, index, 1, &queryParam, 1, DE_NULL, (int *)&value);
38 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramResourceiv()");
39 return value;
40 }
41
getProgramResourceName(const glw::Functions & gl,uint32_t program,uint32_t programInterface,uint32_t index,std::string & dst)42 void getProgramResourceName(const glw::Functions &gl, uint32_t program, uint32_t programInterface, uint32_t index,
43 std::string &dst)
44 {
45 const int length = getProgramResourceInt(gl, program, programInterface, index, GL_NAME_LENGTH);
46
47 if (length > 0)
48 {
49 std::vector<char> buf(length + 1);
50 gl.getProgramResourceName(program, programInterface, index, (int)buf.size(), DE_NULL, &buf[0]);
51 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramResourceName()");
52
53 dst = (const char *)&buf[0];
54 }
55 else
56 {
57 std::ostringstream msg;
58 msg << "Empty name returned for " << programInterface << " at index " << index;
59 throw tcu::TestError(msg.str());
60 }
61 }
62
getProgramInterfaceActiveVariables(const glw::Functions & gl,uint32_t program,uint32_t programInterface,uint32_t index,std::vector<int> & activeVariables)63 static void getProgramInterfaceActiveVariables(const glw::Functions &gl, uint32_t program, uint32_t programInterface,
64 uint32_t index, std::vector<int> &activeVariables)
65 {
66 const int numActiveVariables = getProgramResourceInt(gl, program, programInterface, index, GL_NUM_ACTIVE_VARIABLES);
67
68 activeVariables.resize(numActiveVariables);
69 if (numActiveVariables > 0)
70 {
71 const uint32_t queryParam = GL_ACTIVE_VARIABLES;
72 gl.getProgramResourceiv(program, programInterface, index, 1, &queryParam, (int)activeVariables.size(), DE_NULL,
73 &activeVariables[0]);
74 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramResourceiv(GL_PROGRAM_ACTIVE_VARIABLES)");
75 }
76 }
77
getProgramInterfaceBlockInfo(const glw::Functions & gl,uint32_t program,uint32_t programInterface,uint32_t index,InterfaceBlockInfo & info)78 void getProgramInterfaceBlockInfo(const glw::Functions &gl, uint32_t program, uint32_t programInterface, uint32_t index,
79 InterfaceBlockInfo &info)
80 {
81 info.index = index;
82 info.bufferBinding = getProgramResourceUint(gl, program, programInterface, index, GL_BUFFER_BINDING);
83 info.dataSize = getProgramResourceUint(gl, program, programInterface, index, GL_BUFFER_DATA_SIZE);
84
85 getProgramInterfaceActiveVariables(gl, program, programInterface, index, info.activeVariables);
86
87 if (programInterface != GL_ATOMIC_COUNTER_BUFFER)
88 getProgramResourceName(gl, program, programInterface, index, info.name);
89 }
90
getProgramInterfaceVariableInfo(const glw::Functions & gl,uint32_t program,uint32_t programInterface,uint32_t index,InterfaceVariableInfo & info)91 void getProgramInterfaceVariableInfo(const glw::Functions &gl, uint32_t program, uint32_t programInterface,
92 uint32_t index, InterfaceVariableInfo &info)
93 {
94 // \todo [2013-08-27 pyry] Batch queries!
95 info.index = index;
96 info.blockIndex = getProgramResourceUint(gl, program, programInterface, index, GL_BLOCK_INDEX);
97 info.type = getProgramResourceUint(gl, program, programInterface, index, GL_TYPE);
98 info.arraySize = getProgramResourceUint(gl, program, programInterface, index, GL_ARRAY_SIZE);
99 info.offset = getProgramResourceUint(gl, program, programInterface, index, GL_OFFSET);
100 info.arrayStride = getProgramResourceUint(gl, program, programInterface, index, GL_ARRAY_STRIDE);
101 info.matrixStride = getProgramResourceUint(gl, program, programInterface, index, GL_MATRIX_STRIDE);
102 info.isRowMajor = getProgramResourceUint(gl, program, programInterface, index, GL_IS_ROW_MAJOR) != GL_FALSE;
103
104 if (programInterface == GL_UNIFORM)
105 info.atomicCounterBufferIndex =
106 getProgramResourceUint(gl, program, programInterface, index, GL_ATOMIC_COUNTER_BUFFER_INDEX);
107
108 if (programInterface == GL_BUFFER_VARIABLE)
109 {
110 info.topLevelArraySize = getProgramResourceUint(gl, program, programInterface, index, GL_TOP_LEVEL_ARRAY_SIZE);
111 info.topLevelArrayStride =
112 getProgramResourceUint(gl, program, programInterface, index, GL_TOP_LEVEL_ARRAY_STRIDE);
113 }
114
115 getProgramResourceName(gl, program, programInterface, index, info.name);
116 }
117
118 } // namespace glu
119