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