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