1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL Utilities
3 * ---------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Program interface query utilities
22 *//*--------------------------------------------------------------------*/
24 #include "gluProgramInterfaceQuery.hpp"
25 #include "glwFunctions.hpp"
26 #include "glwEnums.hpp"
33 deUint32 getProgramResourceUint (const glw::Functions& gl, deUint32 program, deUint32 programInterface, deUint32 index, deUint32 queryParam)
36 gl.getProgramResourceiv(program, programInterface, index, 1, &queryParam, 1, DE_NULL, (int*)&value);
37 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramResourceiv()");
41 void getProgramResourceName (const glw::Functions& gl, deUint32 program, deUint32 programInterface, deUint32 index, std::string& dst)
43 const int length = getProgramResourceInt(gl, program, programInterface, index, GL_NAME_LENGTH);
47 std::vector<char> buf(length+1);
48 gl.getProgramResourceName(program, programInterface, index, (int)buf.size(), DE_NULL, &buf[0]);
49 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramResourceName()");
51 dst = (const char*)&buf[0];
55 std::ostringstream msg;
56 msg << "Empty name returned for " << programInterface << " at index " << index;
57 throw tcu::TestError(msg.str());
61 static void getProgramInterfaceActiveVariables (const glw::Functions& gl, deUint32 program, deUint32 programInterface, deUint32 index, std::vector<int>& activeVariables)
63 const int numActiveVariables = getProgramResourceInt(gl, program, programInterface, index, GL_NUM_ACTIVE_VARIABLES);
65 activeVariables.resize(numActiveVariables);
66 if (numActiveVariables > 0)
68 const deUint32 queryParam = GL_ACTIVE_VARIABLES;
69 gl.getProgramResourceiv(program, programInterface, index, 1, &queryParam, (int)activeVariables.size(), DE_NULL, &activeVariables[0]);
70 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramResourceiv(GL_PROGRAM_ACTIVE_VARIABLES)");
74 void getProgramInterfaceBlockInfo (const glw::Functions& gl, deUint32 program, deUint32 programInterface, deUint32 index, InterfaceBlockInfo& info)
77 info.bufferBinding = getProgramResourceUint(gl, program, programInterface, index, GL_BUFFER_BINDING);
78 info.dataSize = getProgramResourceUint(gl, program, programInterface, index, GL_BUFFER_DATA_SIZE);
80 getProgramInterfaceActiveVariables(gl, program, programInterface, index, info.activeVariables);
82 if (programInterface != GL_ATOMIC_COUNTER_BUFFER)
83 getProgramResourceName(gl, program, programInterface, index, info.name);
86 void getProgramInterfaceVariableInfo (const glw::Functions& gl, deUint32 program, deUint32 programInterface, deUint32 index, InterfaceVariableInfo& info)
88 // \todo [2013-08-27 pyry] Batch queries!
90 info.blockIndex = getProgramResourceUint(gl, program, programInterface, index, GL_BLOCK_INDEX);
91 info.type = getProgramResourceUint(gl, program, programInterface, index, GL_TYPE);
92 info.arraySize = getProgramResourceUint(gl, program, programInterface, index, GL_ARRAY_SIZE);
93 info.offset = getProgramResourceUint(gl, program, programInterface, index, GL_OFFSET);
94 info.arrayStride = getProgramResourceUint(gl, program, programInterface, index, GL_ARRAY_STRIDE);
95 info.matrixStride = getProgramResourceUint(gl, program, programInterface, index, GL_MATRIX_STRIDE);
96 info.isRowMajor = getProgramResourceUint(gl, program, programInterface, index, GL_IS_ROW_MAJOR) != GL_FALSE;
98 if (programInterface == GL_UNIFORM)
99 info.atomicCounterBufferIndex = getProgramResourceUint(gl, program, programInterface, index, GL_ATOMIC_COUNTER_BUFFER_INDEX);
101 if (programInterface == GL_BUFFER_VARIABLE)
103 info.topLevelArraySize = getProgramResourceUint(gl, program, programInterface, index, GL_TOP_LEVEL_ARRAY_SIZE);
104 info.topLevelArrayStride = getProgramResourceUint(gl, program, programInterface, index, GL_TOP_LEVEL_ARRAY_STRIDE);
107 getProgramResourceName(gl, program, programInterface, index, info.name);