1e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 2e5c31af7Sopenharmony_ci * OpenGL Conformance Test Suite 3e5c31af7Sopenharmony_ci * ----------------------------- 4e5c31af7Sopenharmony_ci * 5e5c31af7Sopenharmony_ci * Copyright (c) 2014-2016 The Khronos Group Inc. 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 22e5c31af7Sopenharmony_ci */ /*-------------------------------------------------------------------*/ 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ci/*! 25e5c31af7Sopenharmony_ci * \file esextcGPUShader5SamplerArrayIndexing.cpp 26e5c31af7Sopenharmony_ci * \brief gpu_shader5 extension - Sampler Array Indexing (Test 1) 27e5c31af7Sopenharmony_ci */ /*-------------------------------------------------------------------*/ 28e5c31af7Sopenharmony_ci 29e5c31af7Sopenharmony_ci#include "esextcGPUShader5SamplerArrayIndexing.hpp" 30e5c31af7Sopenharmony_ci 31e5c31af7Sopenharmony_ci#include "gluDefs.hpp" 32e5c31af7Sopenharmony_ci#include "glwEnums.hpp" 33e5c31af7Sopenharmony_ci#include "glwFunctions.hpp" 34e5c31af7Sopenharmony_ci#include "tcuTestLog.hpp" 35e5c31af7Sopenharmony_ci#include <cstring> 36e5c31af7Sopenharmony_ci 37e5c31af7Sopenharmony_cinamespace glcts 38e5c31af7Sopenharmony_ci{ 39e5c31af7Sopenharmony_ci 40e5c31af7Sopenharmony_ciconst int GPUShader5SamplerArrayIndexing::m_n_small_textures = 4; 41e5c31af7Sopenharmony_ciconst int GPUShader5SamplerArrayIndexing::m_n_texture_components = 4; 42e5c31af7Sopenharmony_ciconst int GPUShader5SamplerArrayIndexing::m_big_texture_height = 3; 43e5c31af7Sopenharmony_ciconst int GPUShader5SamplerArrayIndexing::m_big_texture_width = 3; 44e5c31af7Sopenharmony_ciconst int GPUShader5SamplerArrayIndexing::m_n_texture_levels = 1; 45e5c31af7Sopenharmony_ciconst int GPUShader5SamplerArrayIndexing::m_small_texture_height = 1; 46e5c31af7Sopenharmony_ciconst int GPUShader5SamplerArrayIndexing::m_small_texture_width = 1; 47e5c31af7Sopenharmony_ci 48e5c31af7Sopenharmony_ci/** Constructor 49e5c31af7Sopenharmony_ci * 50e5c31af7Sopenharmony_ci * @param context Test context 51e5c31af7Sopenharmony_ci * @param name Test case's name 52e5c31af7Sopenharmony_ci * @param description Test case's description 53e5c31af7Sopenharmony_ci **/ 54e5c31af7Sopenharmony_ciGPUShader5SamplerArrayIndexing::GPUShader5SamplerArrayIndexing(Context& context, const ExtParameters& extParams, 55e5c31af7Sopenharmony_ci const char* name, const char* description) 56e5c31af7Sopenharmony_ci : TestCaseBase(context, extParams, name, description) 57e5c31af7Sopenharmony_ci , m_big_to_id(0) 58e5c31af7Sopenharmony_ci , m_fbo_id(0) 59e5c31af7Sopenharmony_ci , m_fs_id(0) 60e5c31af7Sopenharmony_ci , m_po_id(0) 61e5c31af7Sopenharmony_ci , m_small_to_ids(DE_NULL) 62e5c31af7Sopenharmony_ci , m_vao_id(0) 63e5c31af7Sopenharmony_ci , m_vbo_id(0) 64e5c31af7Sopenharmony_ci , m_vs_id(0) 65e5c31af7Sopenharmony_ci{ 66e5c31af7Sopenharmony_ci} 67e5c31af7Sopenharmony_ci 68e5c31af7Sopenharmony_ci/** Deinitializes GLES objects created during the test. 69e5c31af7Sopenharmony_ci * 70e5c31af7Sopenharmony_ci */ 71e5c31af7Sopenharmony_civoid GPUShader5SamplerArrayIndexing::deinit(void) 72e5c31af7Sopenharmony_ci{ 73e5c31af7Sopenharmony_ci const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 74e5c31af7Sopenharmony_ci 75e5c31af7Sopenharmony_ci /* Reset OpenGL ES state */ 76e5c31af7Sopenharmony_ci gl.useProgram(0); 77e5c31af7Sopenharmony_ci gl.bindBuffer(GL_ARRAY_BUFFER, 0); 78e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE0); 79e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, 0); 80e5c31af7Sopenharmony_ci gl.bindFramebuffer(GL_FRAMEBUFFER, 0); 81e5c31af7Sopenharmony_ci gl.bindVertexArray(0); 82e5c31af7Sopenharmony_ci 83e5c31af7Sopenharmony_ci if (m_po_id != 0) 84e5c31af7Sopenharmony_ci { 85e5c31af7Sopenharmony_ci gl.deleteProgram(m_po_id); 86e5c31af7Sopenharmony_ci m_po_id = 0; 87e5c31af7Sopenharmony_ci } 88e5c31af7Sopenharmony_ci 89e5c31af7Sopenharmony_ci if (m_fs_id != 0) 90e5c31af7Sopenharmony_ci { 91e5c31af7Sopenharmony_ci gl.deleteShader(m_fs_id); 92e5c31af7Sopenharmony_ci m_fs_id = 0; 93e5c31af7Sopenharmony_ci } 94e5c31af7Sopenharmony_ci 95e5c31af7Sopenharmony_ci if (m_vs_id != 0) 96e5c31af7Sopenharmony_ci { 97e5c31af7Sopenharmony_ci gl.deleteShader(m_vs_id); 98e5c31af7Sopenharmony_ci m_vs_id = 0; 99e5c31af7Sopenharmony_ci } 100e5c31af7Sopenharmony_ci 101e5c31af7Sopenharmony_ci if (m_vbo_id != 0) 102e5c31af7Sopenharmony_ci { 103e5c31af7Sopenharmony_ci gl.deleteBuffers(1, &m_vbo_id); 104e5c31af7Sopenharmony_ci m_vbo_id = 0; 105e5c31af7Sopenharmony_ci } 106e5c31af7Sopenharmony_ci 107e5c31af7Sopenharmony_ci if (m_fbo_id != 0) 108e5c31af7Sopenharmony_ci { 109e5c31af7Sopenharmony_ci gl.deleteFramebuffers(1, &m_fbo_id); 110e5c31af7Sopenharmony_ci m_fbo_id = 0; 111e5c31af7Sopenharmony_ci } 112e5c31af7Sopenharmony_ci 113e5c31af7Sopenharmony_ci if (m_vao_id != 0) 114e5c31af7Sopenharmony_ci { 115e5c31af7Sopenharmony_ci gl.deleteVertexArrays(1, &m_vao_id); 116e5c31af7Sopenharmony_ci m_vao_id = 0; 117e5c31af7Sopenharmony_ci } 118e5c31af7Sopenharmony_ci 119e5c31af7Sopenharmony_ci if (m_big_to_id != 0) 120e5c31af7Sopenharmony_ci { 121e5c31af7Sopenharmony_ci gl.deleteTextures(1, &m_big_to_id); 122e5c31af7Sopenharmony_ci m_big_to_id = 0; 123e5c31af7Sopenharmony_ci } 124e5c31af7Sopenharmony_ci 125e5c31af7Sopenharmony_ci if (m_small_to_ids != DE_NULL) 126e5c31af7Sopenharmony_ci { 127e5c31af7Sopenharmony_ci gl.deleteTextures(m_n_small_textures, m_small_to_ids); 128e5c31af7Sopenharmony_ci delete[] m_small_to_ids; 129e5c31af7Sopenharmony_ci m_small_to_ids = DE_NULL; 130e5c31af7Sopenharmony_ci } 131e5c31af7Sopenharmony_ci 132e5c31af7Sopenharmony_ci /* Release base class */ 133e5c31af7Sopenharmony_ci TestCaseBase::deinit(); 134e5c31af7Sopenharmony_ci} 135e5c31af7Sopenharmony_ci 136e5c31af7Sopenharmony_ci/** Initializes GLES objects used during the test. 137e5c31af7Sopenharmony_ci * 138e5c31af7Sopenharmony_ci */ 139e5c31af7Sopenharmony_civoid GPUShader5SamplerArrayIndexing::initTest(void) 140e5c31af7Sopenharmony_ci{ 141e5c31af7Sopenharmony_ci const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 142e5c31af7Sopenharmony_ci 143e5c31af7Sopenharmony_ci /* Check if gpu_shader5 extension is supported */ 144e5c31af7Sopenharmony_ci if (!m_is_gpu_shader5_supported) 145e5c31af7Sopenharmony_ci { 146e5c31af7Sopenharmony_ci throw tcu::NotSupportedError(GPU_SHADER5_EXTENSION_NOT_SUPPORTED, "", __FILE__, __LINE__); 147e5c31af7Sopenharmony_ci } 148e5c31af7Sopenharmony_ci 149e5c31af7Sopenharmony_ci /* Create shader objects */ 150e5c31af7Sopenharmony_ci m_fs_id = gl.createShader(GL_FRAGMENT_SHADER); 151e5c31af7Sopenharmony_ci m_vs_id = gl.createShader(GL_VERTEX_SHADER); 152e5c31af7Sopenharmony_ci 153e5c31af7Sopenharmony_ci /* Create progream object */ 154e5c31af7Sopenharmony_ci m_po_id = gl.createProgram(); 155e5c31af7Sopenharmony_ci 156e5c31af7Sopenharmony_ci const char* fsCode = getFragmentShaderCode(); 157e5c31af7Sopenharmony_ci const char* vsCode = getVertexShaderCode(); 158e5c31af7Sopenharmony_ci 159e5c31af7Sopenharmony_ci if (!buildProgram(m_po_id, m_fs_id, 1 /* part */, &fsCode, m_vs_id, 1 /* part */, &vsCode)) 160e5c31af7Sopenharmony_ci { 161e5c31af7Sopenharmony_ci TCU_FAIL("Could not create program object!"); 162e5c31af7Sopenharmony_ci } 163e5c31af7Sopenharmony_ci 164e5c31af7Sopenharmony_ci /* Create and bind vertex array object */ 165e5c31af7Sopenharmony_ci gl.genVertexArrays(1, &m_vao_id); 166e5c31af7Sopenharmony_ci gl.bindVertexArray(m_vao_id); 167e5c31af7Sopenharmony_ci 168e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error configuring vertex array object"); 169e5c31af7Sopenharmony_ci 170e5c31af7Sopenharmony_ci /* Configure vertex buffer */ 171e5c31af7Sopenharmony_ci const glw::GLfloat vertices[] = { -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 172e5c31af7Sopenharmony_ci -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f }; 173e5c31af7Sopenharmony_ci 174e5c31af7Sopenharmony_ci gl.genBuffers(1, &m_vbo_id); 175e5c31af7Sopenharmony_ci gl.bindBuffer(GL_ARRAY_BUFFER, m_vbo_id); 176e5c31af7Sopenharmony_ci gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 177e5c31af7Sopenharmony_ci 178e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error creating vertex buffer object!"); 179e5c31af7Sopenharmony_ci 180e5c31af7Sopenharmony_ci /* Create and configure texture object used as color attachment */ 181e5c31af7Sopenharmony_ci gl.genTextures(1, &m_big_to_id); 182e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, m_big_to_id); 183e5c31af7Sopenharmony_ci gl.texStorage2D(GL_TEXTURE_2D, m_n_texture_levels, GL_RGBA8, m_big_texture_width, m_big_texture_height); 184e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error configuring texture object!"); 185e5c31af7Sopenharmony_ci 186e5c31af7Sopenharmony_ci /* Create and configure the framebuffer object */ 187e5c31af7Sopenharmony_ci gl.genFramebuffers(1, &m_fbo_id); 188e5c31af7Sopenharmony_ci gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo_id); 189e5c31af7Sopenharmony_ci gl.framebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_big_to_id, 0 /* level */); 190e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error configuring framebuffer object!"); 191e5c31af7Sopenharmony_ci 192e5c31af7Sopenharmony_ci /* Configure textures used in fragment shader */ 193e5c31af7Sopenharmony_ci const glw::GLfloat alpha[] = { 0.0f, 0.0f, 0.0f, 1.0f }; 194e5c31af7Sopenharmony_ci const glw::GLfloat blue[] = { 0.0f, 0.0f, 1.0f, 0.0f }; 195e5c31af7Sopenharmony_ci const glw::GLfloat green[] = { 0.0f, 1.0f, 0.0f, 0.0f }; 196e5c31af7Sopenharmony_ci const glw::GLfloat red[] = { 1.0f, 0.0f, 0.0f, 0.0f }; 197e5c31af7Sopenharmony_ci 198e5c31af7Sopenharmony_ci m_small_to_ids = new glw::GLuint[m_n_small_textures]; 199e5c31af7Sopenharmony_ci memset(m_small_to_ids, 0, m_n_small_textures * sizeof(glw::GLuint)); 200e5c31af7Sopenharmony_ci 201e5c31af7Sopenharmony_ci gl.genTextures(m_n_small_textures, m_small_to_ids); 202e5c31af7Sopenharmony_ci 203e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE0); 204e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, m_small_to_ids[0]); 205e5c31af7Sopenharmony_ci gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_small_texture_width, m_small_texture_height, 0 /* border */, GL_RGBA, 206e5c31af7Sopenharmony_ci GL_FLOAT, red); 207e5c31af7Sopenharmony_ci gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 208e5c31af7Sopenharmony_ci gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 209e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error configuring texture object"); 210e5c31af7Sopenharmony_ci 211e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE1); 212e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, m_small_to_ids[1]); 213e5c31af7Sopenharmony_ci gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_small_texture_width, m_small_texture_height, 0 /* border */, GL_RGBA, 214e5c31af7Sopenharmony_ci GL_FLOAT, green); 215e5c31af7Sopenharmony_ci gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 216e5c31af7Sopenharmony_ci gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 217e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error configuring texture object"); 218e5c31af7Sopenharmony_ci 219e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE2); 220e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, m_small_to_ids[2]); 221e5c31af7Sopenharmony_ci gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_small_texture_width, m_small_texture_height, 0 /* border */, GL_RGBA, 222e5c31af7Sopenharmony_ci GL_FLOAT, blue); 223e5c31af7Sopenharmony_ci gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 224e5c31af7Sopenharmony_ci gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 225e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error configuring texture object"); 226e5c31af7Sopenharmony_ci 227e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE3); 228e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, m_small_to_ids[3]); 229e5c31af7Sopenharmony_ci gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_small_texture_width, m_small_texture_height, 0 /* border */, GL_RGBA, 230e5c31af7Sopenharmony_ci GL_FLOAT, alpha); 231e5c31af7Sopenharmony_ci gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 232e5c31af7Sopenharmony_ci gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 233e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error configuring texture object"); 234e5c31af7Sopenharmony_ci} 235e5c31af7Sopenharmony_ci 236e5c31af7Sopenharmony_ci/** Executes the test. 237e5c31af7Sopenharmony_ci * Sets the test result to QP_TEST_RESULT_FAIL if the test failed, QP_TEST_RESULT_PASS otherwise. 238e5c31af7Sopenharmony_ci * 239e5c31af7Sopenharmony_ci * @return STOP if the test has finished, CONTINUE to indicate iterate should be called once again. 240e5c31af7Sopenharmony_ci * 241e5c31af7Sopenharmony_ci * Note the function throws exception should an error occur! 242e5c31af7Sopenharmony_ci **/ 243e5c31af7Sopenharmony_citcu::TestNode::IterateResult GPUShader5SamplerArrayIndexing::iterate(void) 244e5c31af7Sopenharmony_ci{ 245e5c31af7Sopenharmony_ci initTest(); 246e5c31af7Sopenharmony_ci 247e5c31af7Sopenharmony_ci const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 248e5c31af7Sopenharmony_ci 249e5c31af7Sopenharmony_ci gl.viewport(0 /* x */, 0 /* y */, m_big_texture_width, m_big_texture_height); 250e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport() call failed"); 251e5c31af7Sopenharmony_ci 252e5c31af7Sopenharmony_ci gl.useProgram(m_po_id); 253e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram() call failed"); 254e5c31af7Sopenharmony_ci 255e5c31af7Sopenharmony_ci /* Configure position vertex array */ 256e5c31af7Sopenharmony_ci gl.bindBuffer(GL_ARRAY_BUFFER, m_vbo_id); 257e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer() call failed"); 258e5c31af7Sopenharmony_ci 259e5c31af7Sopenharmony_ci glw::GLint position_attribute_location = gl.getAttribLocation(m_po_id, "position"); 260e5c31af7Sopenharmony_ci 261e5c31af7Sopenharmony_ci gl.vertexAttribPointer(position_attribute_location, 4 /* size */, GL_FLOAT, GL_FALSE, 0 /* stride */, 262e5c31af7Sopenharmony_ci DE_NULL /* pointer */); 263e5c31af7Sopenharmony_ci gl.enableVertexAttribArray(position_attribute_location); 264e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error configuring position vertex attribute array!"); 265e5c31af7Sopenharmony_ci 266e5c31af7Sopenharmony_ci glw::GLint samplers_uniform_location = gl.getUniformLocation(m_po_id, "samplers"); 267e5c31af7Sopenharmony_ci 268e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE0); 269e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, m_small_to_ids[0]); 270e5c31af7Sopenharmony_ci gl.uniform1i(samplers_uniform_location + 0, 0); 271e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error assigning texture unit 0 to samplers[0] uniform location!"); 272e5c31af7Sopenharmony_ci 273e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE1); 274e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, m_small_to_ids[1]); 275e5c31af7Sopenharmony_ci gl.uniform1i(samplers_uniform_location + 1, 1); 276e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error assigning texture unit 1 to samplers[1] uniform location!"); 277e5c31af7Sopenharmony_ci 278e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE2); 279e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, m_small_to_ids[2]); 280e5c31af7Sopenharmony_ci gl.uniform1i(samplers_uniform_location + 2, 2); 281e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error assigning texture unit 2 to samplers[2] uniform location!"); 282e5c31af7Sopenharmony_ci 283e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE3); 284e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, m_small_to_ids[3]); 285e5c31af7Sopenharmony_ci gl.uniform1i(samplers_uniform_location + 3, 3); 286e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error assigning texture unit 3 to samplers[3] uniform location!"); 287e5c31af7Sopenharmony_ci 288e5c31af7Sopenharmony_ci /* Render */ 289e5c31af7Sopenharmony_ci gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f); 290e5c31af7Sopenharmony_ci gl.clear(GL_COLOR_BUFFER_BIT); 291e5c31af7Sopenharmony_ci 292e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error clearing color buffer!"); 293e5c31af7Sopenharmony_ci 294e5c31af7Sopenharmony_ci gl.drawArrays(GL_TRIANGLE_STRIP, 0 /* first */, 4 /* count */); 295e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Rendering error"); 296e5c31af7Sopenharmony_ci 297e5c31af7Sopenharmony_ci /* Verify results */ 298e5c31af7Sopenharmony_ci const glw::GLubyte referenceColor[] = { 255, 255, 255, 255 }; 299e5c31af7Sopenharmony_ci glw::GLubyte buffer[m_n_texture_components]; 300e5c31af7Sopenharmony_ci 301e5c31af7Sopenharmony_ci memset(buffer, 0, m_n_texture_components * sizeof(glw::GLubyte)); 302e5c31af7Sopenharmony_ci 303e5c31af7Sopenharmony_ci /* Reading data */ 304e5c31af7Sopenharmony_ci gl.bindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_id); 305e5c31af7Sopenharmony_ci gl.readPixels(1, /* x */ 306e5c31af7Sopenharmony_ci 1, /* y */ 307e5c31af7Sopenharmony_ci 1, /* width */ 308e5c31af7Sopenharmony_ci 1, /* height */ 309e5c31af7Sopenharmony_ci GL_RGBA, GL_UNSIGNED_BYTE, buffer); 310e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "Error reading pixel data!"); 311e5c31af7Sopenharmony_ci 312e5c31af7Sopenharmony_ci /* Fail if result color is different from reference color */ 313e5c31af7Sopenharmony_ci if (memcmp(referenceColor, buffer, sizeof(referenceColor))) 314e5c31af7Sopenharmony_ci { 315e5c31af7Sopenharmony_ci m_testCtx.getLog() << tcu::TestLog::Message << "Rendered color [" << (int)buffer[0] << ", " << (int)buffer[1] 316e5c31af7Sopenharmony_ci << ", " << (int)buffer[2] << ", " << (int)buffer[3] 317e5c31af7Sopenharmony_ci << "] is different from reference color [" << (int)referenceColor[0] << ", " 318e5c31af7Sopenharmony_ci << (int)referenceColor[1] << ", " << (int)referenceColor[2] << ", " << (int)referenceColor[3] 319e5c31af7Sopenharmony_ci << "] !" << tcu::TestLog::EndMessage; 320e5c31af7Sopenharmony_ci 321e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 322e5c31af7Sopenharmony_ci return STOP; 323e5c31af7Sopenharmony_ci } 324e5c31af7Sopenharmony_ci 325e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 326e5c31af7Sopenharmony_ci return STOP; 327e5c31af7Sopenharmony_ci} 328e5c31af7Sopenharmony_ci 329e5c31af7Sopenharmony_ci/** Returns code for Vertex Shader 330e5c31af7Sopenharmony_ci * 331e5c31af7Sopenharmony_ci * @return pointer to literal with Vertex Shader code 332e5c31af7Sopenharmony_ci **/ 333e5c31af7Sopenharmony_ciconst char* GPUShader5SamplerArrayIndexing::getVertexShaderCode() 334e5c31af7Sopenharmony_ci{ 335e5c31af7Sopenharmony_ci static const char* result = "${VERSION}\n" 336e5c31af7Sopenharmony_ci "\n" 337e5c31af7Sopenharmony_ci "${GPU_SHADER5_REQUIRE}\n" 338e5c31af7Sopenharmony_ci "\n" 339e5c31af7Sopenharmony_ci "precision highp float;\n" 340e5c31af7Sopenharmony_ci "\n" 341e5c31af7Sopenharmony_ci "in vec4 position;" 342e5c31af7Sopenharmony_ci "\n" 343e5c31af7Sopenharmony_ci "void main()\n" 344e5c31af7Sopenharmony_ci "{\n" 345e5c31af7Sopenharmony_ci " gl_Position = position;" 346e5c31af7Sopenharmony_ci "}\n"; 347e5c31af7Sopenharmony_ci 348e5c31af7Sopenharmony_ci return result; 349e5c31af7Sopenharmony_ci} 350e5c31af7Sopenharmony_ci 351e5c31af7Sopenharmony_ci/** Returns code for Fragment Shader 352e5c31af7Sopenharmony_ci * 353e5c31af7Sopenharmony_ci * @return pointer to literal with Fragment Shader code 354e5c31af7Sopenharmony_ci **/ 355e5c31af7Sopenharmony_ciconst char* GPUShader5SamplerArrayIndexing::getFragmentShaderCode() 356e5c31af7Sopenharmony_ci{ 357e5c31af7Sopenharmony_ci static const char* result = "${VERSION}\n" 358e5c31af7Sopenharmony_ci "\n" 359e5c31af7Sopenharmony_ci "${GPU_SHADER5_REQUIRE}\n" 360e5c31af7Sopenharmony_ci "\n" 361e5c31af7Sopenharmony_ci "precision highp float;\n" 362e5c31af7Sopenharmony_ci "\n" 363e5c31af7Sopenharmony_ci "uniform sampler2D samplers[4];\n" 364e5c31af7Sopenharmony_ci "\n" 365e5c31af7Sopenharmony_ci "layout(location = 0) out vec4 outColor;\n" 366e5c31af7Sopenharmony_ci "\n" 367e5c31af7Sopenharmony_ci "void main(void)\n" 368e5c31af7Sopenharmony_ci "{\n" 369e5c31af7Sopenharmony_ci " outColor = vec4(0, 0, 0, 0);\n" 370e5c31af7Sopenharmony_ci "\n" 371e5c31af7Sopenharmony_ci " for (int i = 0;i < 4; ++i)\n" 372e5c31af7Sopenharmony_ci " {\n" 373e5c31af7Sopenharmony_ci " outColor += texture(samplers[i],vec2(0,0));\n" 374e5c31af7Sopenharmony_ci " }\n" 375e5c31af7Sopenharmony_ci "}\n"; 376e5c31af7Sopenharmony_ci 377e5c31af7Sopenharmony_ci return result; 378e5c31af7Sopenharmony_ci} 379e5c31af7Sopenharmony_ci 380e5c31af7Sopenharmony_ci} // namespace glcts 381