1e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 2e5c31af7Sopenharmony_ci * drawElements Quality Program OpenGL ES 3.0 Module 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 Sampler object testcases. 22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ci#include "glsSamplerObjectTest.hpp" 25e5c31af7Sopenharmony_ci 26e5c31af7Sopenharmony_ci#include "tcuTexture.hpp" 27e5c31af7Sopenharmony_ci#include "tcuSurface.hpp" 28e5c31af7Sopenharmony_ci#include "tcuTextureUtil.hpp" 29e5c31af7Sopenharmony_ci#include "tcuImageCompare.hpp" 30e5c31af7Sopenharmony_ci#include "tcuTestLog.hpp" 31e5c31af7Sopenharmony_ci#include "tcuRGBA.hpp" 32e5c31af7Sopenharmony_ci#include "tcuRenderTarget.hpp" 33e5c31af7Sopenharmony_ci#include "tcuStringTemplate.hpp" 34e5c31af7Sopenharmony_ci 35e5c31af7Sopenharmony_ci#include "gluShaderProgram.hpp" 36e5c31af7Sopenharmony_ci#include "gluPixelTransfer.hpp" 37e5c31af7Sopenharmony_ci#include "gluDrawUtil.hpp" 38e5c31af7Sopenharmony_ci#include "gluRenderContext.hpp" 39e5c31af7Sopenharmony_ci#include "gluTextureUtil.hpp" 40e5c31af7Sopenharmony_ci 41e5c31af7Sopenharmony_ci#include "glwFunctions.hpp" 42e5c31af7Sopenharmony_ci 43e5c31af7Sopenharmony_ci#include "deRandom.hpp" 44e5c31af7Sopenharmony_ci#include "deString.h" 45e5c31af7Sopenharmony_ci 46e5c31af7Sopenharmony_ci#include "deString.h" 47e5c31af7Sopenharmony_ci 48e5c31af7Sopenharmony_ci#include <map> 49e5c31af7Sopenharmony_ci 50e5c31af7Sopenharmony_cinamespace deqp 51e5c31af7Sopenharmony_ci{ 52e5c31af7Sopenharmony_cinamespace gls 53e5c31af7Sopenharmony_ci{ 54e5c31af7Sopenharmony_ci 55e5c31af7Sopenharmony_cinamespace 56e5c31af7Sopenharmony_ci{ 57e5c31af7Sopenharmony_ciconst int VIEWPORT_WIDTH = 128; 58e5c31af7Sopenharmony_ciconst int VIEWPORT_HEIGHT = 128; 59e5c31af7Sopenharmony_ci 60e5c31af7Sopenharmony_ciconst int TEXTURE2D_WIDTH = 32; 61e5c31af7Sopenharmony_ciconst int TEXTURE2D_HEIGHT = 32; 62e5c31af7Sopenharmony_ci 63e5c31af7Sopenharmony_ciconst int TEXTURE3D_WIDTH = 32; 64e5c31af7Sopenharmony_ciconst int TEXTURE3D_HEIGHT = 32; 65e5c31af7Sopenharmony_ciconst int TEXTURE3D_DEPTH = 32; 66e5c31af7Sopenharmony_ci 67e5c31af7Sopenharmony_ciconst int CUBEMAP_SIZE = 32; 68e5c31af7Sopenharmony_ci 69e5c31af7Sopenharmony_ci} // anonymous 70e5c31af7Sopenharmony_ci 71e5c31af7Sopenharmony_ci 72e5c31af7Sopenharmony_ciTextureSamplerTest::TextureSamplerTest (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const TestSpec& spec) 73e5c31af7Sopenharmony_ci : tcu::TestCase (testCtx, spec.name, spec.desc) 74e5c31af7Sopenharmony_ci , m_renderCtx (renderCtx) 75e5c31af7Sopenharmony_ci , m_program (NULL) 76e5c31af7Sopenharmony_ci , m_target (spec.target) 77e5c31af7Sopenharmony_ci , m_textureState (spec.textureState) 78e5c31af7Sopenharmony_ci , m_samplerState (spec.samplerState) 79e5c31af7Sopenharmony_ci , m_random (deStringHash(spec.name)) 80e5c31af7Sopenharmony_ci{ 81e5c31af7Sopenharmony_ci} 82e5c31af7Sopenharmony_ci 83e5c31af7Sopenharmony_civoid TextureSamplerTest::setTextureState (const glw::Functions& gl, GLenum target, SamplingState state) 84e5c31af7Sopenharmony_ci{ 85e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_MIN_FILTER, state.minFilter); 86e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_MIN_FILTER, state.minFilter)"); 87e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_MAG_FILTER, state.magFilter); 88e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_MAG_FILTER, state.magFilter)"); 89e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_WRAP_S, state.wrapS); 90e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_WRAP_S, state.wrapS)"); 91e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_WRAP_T, state.wrapT); 92e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_WRAP_T, state.wrapT)"); 93e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_WRAP_R, state.wrapR); 94e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_WRAP_R, state.wrapR)"); 95e5c31af7Sopenharmony_ci gl.texParameterf(target, GL_TEXTURE_MAX_LOD, state.maxLod); 96e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameterf(target, GL_TEXTURE_MAX_LOD, state.maxLod)"); 97e5c31af7Sopenharmony_ci gl.texParameterf(target, GL_TEXTURE_MIN_LOD, state.minLod); 98e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameterf(target, GL_TEXTURE_MIN_LOD, state.minLod)"); 99e5c31af7Sopenharmony_ci} 100e5c31af7Sopenharmony_ci 101e5c31af7Sopenharmony_civoid TextureSamplerTest::setSamplerState (const glw::Functions& gl, SamplingState state, GLuint sampler) 102e5c31af7Sopenharmony_ci{ 103e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, state.minFilter); 104e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, state.minFilter)"); 105e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, state.magFilter); 106e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, state.magFilter)"); 107e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_WRAP_S, state.wrapS); 108e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, state.wrapS)"); 109e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_WRAP_T, state.wrapT); 110e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, state.wrapT)"); 111e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_WRAP_R, state.wrapR); 112e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_WRAP_R, state.wrapR)"); 113e5c31af7Sopenharmony_ci gl.samplerParameterf(sampler, GL_TEXTURE_MAX_LOD, state.maxLod); 114e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameterf(sampler, GL_TEXTURE_MAX_LOD, state.maxLod)"); 115e5c31af7Sopenharmony_ci gl.samplerParameterf(sampler, GL_TEXTURE_MIN_LOD, state.minLod); 116e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameterf(sampler, GL_TEXTURE_MIN_LOD, state.minLod)"); 117e5c31af7Sopenharmony_ci} 118e5c31af7Sopenharmony_ci 119e5c31af7Sopenharmony_ciconst char* TextureSamplerTest::selectVertexShader (GLenum target) 120e5c31af7Sopenharmony_ci{ 121e5c31af7Sopenharmony_ci switch (target) 122e5c31af7Sopenharmony_ci { 123e5c31af7Sopenharmony_ci case GL_TEXTURE_2D: 124e5c31af7Sopenharmony_ci return 125e5c31af7Sopenharmony_ci "${VTX_HDR}" 126e5c31af7Sopenharmony_ci "${VTX_IN} ${HIGHP} vec2 a_position;\n" 127e5c31af7Sopenharmony_ci "uniform ${HIGHP} float u_posScale;\n" 128e5c31af7Sopenharmony_ci "${VTX_OUT} ${MEDIUMP} vec2 v_texCoord;\n" 129e5c31af7Sopenharmony_ci "void main (void)\n" 130e5c31af7Sopenharmony_ci "{\n" 131e5c31af7Sopenharmony_ci "\tv_texCoord = a_position;\n" 132e5c31af7Sopenharmony_ci "\tgl_Position = vec4(u_posScale * a_position, 0.0, 1.0);\n" 133e5c31af7Sopenharmony_ci "}"; 134e5c31af7Sopenharmony_ci 135e5c31af7Sopenharmony_ci case GL_TEXTURE_3D: 136e5c31af7Sopenharmony_ci return 137e5c31af7Sopenharmony_ci "${VTX_HDR}" 138e5c31af7Sopenharmony_ci "${VTX_IN} ${HIGHP} vec3 a_position;\n" 139e5c31af7Sopenharmony_ci "uniform ${HIGHP} float u_posScale;\n" 140e5c31af7Sopenharmony_ci "${VTX_OUT} ${MEDIUMP} vec3 v_texCoord;\n" 141e5c31af7Sopenharmony_ci "void main (void)\n" 142e5c31af7Sopenharmony_ci "{\n" 143e5c31af7Sopenharmony_ci "\tv_texCoord = a_position;\n" 144e5c31af7Sopenharmony_ci "\tgl_Position = vec4(u_posScale * a_position.xy, 0.0, 1.0);\n" 145e5c31af7Sopenharmony_ci "}"; 146e5c31af7Sopenharmony_ci 147e5c31af7Sopenharmony_ci case GL_TEXTURE_CUBE_MAP: 148e5c31af7Sopenharmony_ci return 149e5c31af7Sopenharmony_ci "${VTX_HDR}" 150e5c31af7Sopenharmony_ci "${VTX_IN} ${HIGHP} vec4 a_position;\n" 151e5c31af7Sopenharmony_ci "uniform ${HIGHP} float u_posScale;\n" 152e5c31af7Sopenharmony_ci "${VTX_OUT} ${MEDIUMP} vec2 v_texCoord;\n" 153e5c31af7Sopenharmony_ci "void main (void)\n" 154e5c31af7Sopenharmony_ci "{\n" 155e5c31af7Sopenharmony_ci "\tv_texCoord = a_position.zw;\n" 156e5c31af7Sopenharmony_ci "\tgl_Position = vec4(u_posScale * a_position.xy, 0.0, 1.0);\n" 157e5c31af7Sopenharmony_ci "}"; 158e5c31af7Sopenharmony_ci 159e5c31af7Sopenharmony_ci default: 160e5c31af7Sopenharmony_ci DE_ASSERT(false); 161e5c31af7Sopenharmony_ci return NULL; 162e5c31af7Sopenharmony_ci } 163e5c31af7Sopenharmony_ci} 164e5c31af7Sopenharmony_ci 165e5c31af7Sopenharmony_ciconst char* TextureSamplerTest::selectFragmentShader (GLenum target) 166e5c31af7Sopenharmony_ci{ 167e5c31af7Sopenharmony_ci switch (target) 168e5c31af7Sopenharmony_ci { 169e5c31af7Sopenharmony_ci case GL_TEXTURE_2D: 170e5c31af7Sopenharmony_ci return 171e5c31af7Sopenharmony_ci "${FRAG_HDR}" 172e5c31af7Sopenharmony_ci "uniform ${LOWP} sampler2D u_sampler;\n" 173e5c31af7Sopenharmony_ci "${FRAG_IN} ${MEDIUMP} vec2 v_texCoord;\n" 174e5c31af7Sopenharmony_ci "void main (void)\n" 175e5c31af7Sopenharmony_ci "{\n" 176e5c31af7Sopenharmony_ci "\t${FRAG_COLOR} = texture(u_sampler, v_texCoord);\n" 177e5c31af7Sopenharmony_ci "}"; 178e5c31af7Sopenharmony_ci 179e5c31af7Sopenharmony_ci case GL_TEXTURE_3D: 180e5c31af7Sopenharmony_ci return 181e5c31af7Sopenharmony_ci "${FRAG_HDR}" 182e5c31af7Sopenharmony_ci "uniform ${LOWP} sampler3D u_sampler;\n" 183e5c31af7Sopenharmony_ci "${FRAG_IN} ${MEDIUMP} vec3 v_texCoord;\n" 184e5c31af7Sopenharmony_ci "void main (void)\n" 185e5c31af7Sopenharmony_ci "{\n" 186e5c31af7Sopenharmony_ci "\t${FRAG_COLOR} = texture(u_sampler, v_texCoord);\n" 187e5c31af7Sopenharmony_ci "}"; 188e5c31af7Sopenharmony_ci 189e5c31af7Sopenharmony_ci case GL_TEXTURE_CUBE_MAP: 190e5c31af7Sopenharmony_ci return 191e5c31af7Sopenharmony_ci "${FRAG_HDR}" 192e5c31af7Sopenharmony_ci "uniform ${LOWP} samplerCube u_sampler;\n" 193e5c31af7Sopenharmony_ci "${FRAG_IN} ${MEDIUMP} vec2 v_texCoord;\n" 194e5c31af7Sopenharmony_ci "void main (void)\n" 195e5c31af7Sopenharmony_ci "{\n" 196e5c31af7Sopenharmony_ci "\t${FRAG_COLOR} = texture(u_sampler, vec3(cos(3.14 * v_texCoord.y) * sin(3.14 * v_texCoord.x), sin(3.14 * v_texCoord.y), cos(3.14 * v_texCoord.y) * cos(3.14 * v_texCoord.x)));\n" 197e5c31af7Sopenharmony_ci "}"; 198e5c31af7Sopenharmony_ci 199e5c31af7Sopenharmony_ci default: 200e5c31af7Sopenharmony_ci DE_ASSERT(false); 201e5c31af7Sopenharmony_ci return NULL; 202e5c31af7Sopenharmony_ci } 203e5c31af7Sopenharmony_ci} 204e5c31af7Sopenharmony_ci 205e5c31af7Sopenharmony_civoid TextureSamplerTest::init (void) 206e5c31af7Sopenharmony_ci{ 207e5c31af7Sopenharmony_ci const char* vertexShaderTemplate = selectVertexShader(m_target); 208e5c31af7Sopenharmony_ci const char* fragmentShaderTemplate = selectFragmentShader(m_target); 209e5c31af7Sopenharmony_ci 210e5c31af7Sopenharmony_ci std::map<std::string, std::string> params; 211e5c31af7Sopenharmony_ci 212e5c31af7Sopenharmony_ci if (glu::isGLSLVersionSupported(m_renderCtx.getType(), glu::GLSL_VERSION_300_ES)) 213e5c31af7Sopenharmony_ci { 214e5c31af7Sopenharmony_ci params["VTX_HDR"] = "#version 300 es\n"; 215e5c31af7Sopenharmony_ci params["FRAG_HDR"] = "#version 300 es\nlayout(location = 0) out mediump vec4 o_color;\n"; 216e5c31af7Sopenharmony_ci params["VTX_IN"] = "in"; 217e5c31af7Sopenharmony_ci params["VTX_OUT"] = "out"; 218e5c31af7Sopenharmony_ci params["FRAG_IN"] = "in"; 219e5c31af7Sopenharmony_ci params["FRAG_COLOR"] = "o_color"; 220e5c31af7Sopenharmony_ci params["HIGHP"] = "highp"; 221e5c31af7Sopenharmony_ci params["LOWP"] = "lowp"; 222e5c31af7Sopenharmony_ci params["MEDIUMP"] = "mediump"; 223e5c31af7Sopenharmony_ci } 224e5c31af7Sopenharmony_ci else if (glu::isGLSLVersionSupported(m_renderCtx.getType(), glu::GLSL_VERSION_330)) 225e5c31af7Sopenharmony_ci { 226e5c31af7Sopenharmony_ci params["VTX_HDR"] = "#version 330\n"; 227e5c31af7Sopenharmony_ci params["FRAG_HDR"] = "#version 330\nlayout(location = 0) out mediump vec4 o_color;\n"; 228e5c31af7Sopenharmony_ci params["VTX_IN"] = "in"; 229e5c31af7Sopenharmony_ci params["VTX_OUT"] = "out"; 230e5c31af7Sopenharmony_ci params["FRAG_IN"] = "in"; 231e5c31af7Sopenharmony_ci params["FRAG_COLOR"] = "o_color"; 232e5c31af7Sopenharmony_ci params["HIGHP"] = "highp"; 233e5c31af7Sopenharmony_ci params["LOWP"] = "lowp"; 234e5c31af7Sopenharmony_ci params["MEDIUMP"] = "mediump"; 235e5c31af7Sopenharmony_ci } 236e5c31af7Sopenharmony_ci else 237e5c31af7Sopenharmony_ci DE_ASSERT(false); 238e5c31af7Sopenharmony_ci 239e5c31af7Sopenharmony_ci DE_ASSERT(!m_program); 240e5c31af7Sopenharmony_ci m_program = new glu::ShaderProgram(m_renderCtx, 241e5c31af7Sopenharmony_ci glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderTemplate).specialize(params), 242e5c31af7Sopenharmony_ci tcu::StringTemplate(fragmentShaderTemplate).specialize(params))); 243e5c31af7Sopenharmony_ci 244e5c31af7Sopenharmony_ci if (!m_program->isOk()) 245e5c31af7Sopenharmony_ci { 246e5c31af7Sopenharmony_ci tcu::TestLog& log = m_testCtx.getLog(); 247e5c31af7Sopenharmony_ci log << *m_program; 248e5c31af7Sopenharmony_ci TCU_FAIL("Failed to compile shaders"); 249e5c31af7Sopenharmony_ci } 250e5c31af7Sopenharmony_ci} 251e5c31af7Sopenharmony_ci 252e5c31af7Sopenharmony_civoid TextureSamplerTest::deinit (void) 253e5c31af7Sopenharmony_ci{ 254e5c31af7Sopenharmony_ci delete m_program; 255e5c31af7Sopenharmony_ci m_program = NULL; 256e5c31af7Sopenharmony_ci} 257e5c31af7Sopenharmony_ci 258e5c31af7Sopenharmony_ciTextureSamplerTest::~TextureSamplerTest (void) 259e5c31af7Sopenharmony_ci{ 260e5c31af7Sopenharmony_ci deinit(); 261e5c31af7Sopenharmony_ci} 262e5c31af7Sopenharmony_ci 263e5c31af7Sopenharmony_ciconst float s_positions[] = { 264e5c31af7Sopenharmony_ci -1.0, -1.0, 265e5c31af7Sopenharmony_ci 1.0, -1.0, 266e5c31af7Sopenharmony_ci 1.0, 1.0, 267e5c31af7Sopenharmony_ci 268e5c31af7Sopenharmony_ci 1.0, 1.0, 269e5c31af7Sopenharmony_ci -1.0, 1.0, 270e5c31af7Sopenharmony_ci -1.0, -1.0 271e5c31af7Sopenharmony_ci}; 272e5c31af7Sopenharmony_ci 273e5c31af7Sopenharmony_ciconst float s_positions3D[] = { 274e5c31af7Sopenharmony_ci -1.0f, -1.0f, -1.0f, 275e5c31af7Sopenharmony_ci 1.0f, -1.0f, 1.0f, 276e5c31af7Sopenharmony_ci 1.0f, 1.0f, -1.0f, 277e5c31af7Sopenharmony_ci 278e5c31af7Sopenharmony_ci 1.0f, 1.0f, -1.0f, 279e5c31af7Sopenharmony_ci -1.0f, 1.0f, 1.0f, 280e5c31af7Sopenharmony_ci -1.0f, -1.0f, -1.0f 281e5c31af7Sopenharmony_ci}; 282e5c31af7Sopenharmony_ci 283e5c31af7Sopenharmony_ciconst float s_positionsCube[] = { 284e5c31af7Sopenharmony_ci -1.0f, -1.0f, -1.0f, -0.5f, 285e5c31af7Sopenharmony_ci 1.0f, -1.0f, 1.0f, -0.5f, 286e5c31af7Sopenharmony_ci 1.0f, 1.0f, 1.0f, 0.5f, 287e5c31af7Sopenharmony_ci 288e5c31af7Sopenharmony_ci 1.0f, 1.0f, 1.0f, 0.5f, 289e5c31af7Sopenharmony_ci -1.0f, 1.0f, -1.0f, 0.5f, 290e5c31af7Sopenharmony_ci -1.0f, -1.0f, -1.0f, -0.5f 291e5c31af7Sopenharmony_ci}; 292e5c31af7Sopenharmony_ci 293e5c31af7Sopenharmony_civoid TextureSamplerTest::render (void) 294e5c31af7Sopenharmony_ci{ 295e5c31af7Sopenharmony_ci const glw::Functions& gl = m_renderCtx.getFunctions(); 296e5c31af7Sopenharmony_ci 297e5c31af7Sopenharmony_ci GLuint samplerLoc = (GLuint)-1; 298e5c31af7Sopenharmony_ci GLuint scaleLoc = (GLuint)-1; 299e5c31af7Sopenharmony_ci 300e5c31af7Sopenharmony_ci gl.useProgram(m_program->getProgram()); 301e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram(m_program->getProgram())"); 302e5c31af7Sopenharmony_ci 303e5c31af7Sopenharmony_ci samplerLoc = gl.getUniformLocation(m_program->getProgram(), "u_sampler"); 304e5c31af7Sopenharmony_ci TCU_CHECK(samplerLoc != (GLuint)-1); 305e5c31af7Sopenharmony_ci 306e5c31af7Sopenharmony_ci scaleLoc = gl.getUniformLocation(m_program->getProgram(), "u_posScale"); 307e5c31af7Sopenharmony_ci TCU_CHECK(scaleLoc != (GLuint)-1); 308e5c31af7Sopenharmony_ci 309e5c31af7Sopenharmony_ci gl.clearColor(0.5f, 0.5f, 0.5f, 1.0f); 310e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor(0.5f, 0.5f, 0.5f, 1.0f)"); 311e5c31af7Sopenharmony_ci 312e5c31af7Sopenharmony_ci gl.clear(GL_COLOR_BUFFER_BIT); 313e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glClear(GL_COLOR_BUFFER_BIT)"); 314e5c31af7Sopenharmony_ci 315e5c31af7Sopenharmony_ci gl.uniform1i(samplerLoc, 0); 316e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i(samplerLoc, 0)"); 317e5c31af7Sopenharmony_ci 318e5c31af7Sopenharmony_ci gl.uniform1f(scaleLoc, 1.0f); 319e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f(scaleLoc, 1.0f)"); 320e5c31af7Sopenharmony_ci 321e5c31af7Sopenharmony_ci switch (m_target) 322e5c31af7Sopenharmony_ci { 323e5c31af7Sopenharmony_ci case GL_TEXTURE_2D: 324e5c31af7Sopenharmony_ci { 325e5c31af7Sopenharmony_ci glu::VertexArrayBinding vertexArrays[] = 326e5c31af7Sopenharmony_ci { 327e5c31af7Sopenharmony_ci glu::VertexArrayBinding(glu::BindingPoint("a_position"), glu::VertexArrayPointer(glu::VTX_COMP_FLOAT, glu::VTX_COMP_CONVERT_NONE, 2, 6, 0, s_positions)) 328e5c31af7Sopenharmony_ci }; 329e5c31af7Sopenharmony_ci 330e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 331e5c31af7Sopenharmony_ci 332e5c31af7Sopenharmony_ci gl.uniform1f(scaleLoc, 0.25f); 333e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f(scaleLoc, 0.25f)"); 334e5c31af7Sopenharmony_ci 335e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 336e5c31af7Sopenharmony_ci 337e5c31af7Sopenharmony_ci break; 338e5c31af7Sopenharmony_ci } 339e5c31af7Sopenharmony_ci 340e5c31af7Sopenharmony_ci case GL_TEXTURE_3D: 341e5c31af7Sopenharmony_ci { 342e5c31af7Sopenharmony_ci glu::VertexArrayBinding vertexArrays[] = 343e5c31af7Sopenharmony_ci { 344e5c31af7Sopenharmony_ci glu::VertexArrayBinding(glu::BindingPoint("a_position"), glu::VertexArrayPointer(glu::VTX_COMP_FLOAT, glu::VTX_COMP_CONVERT_NONE, 3, 6, 0, s_positions3D)) 345e5c31af7Sopenharmony_ci }; 346e5c31af7Sopenharmony_ci 347e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 348e5c31af7Sopenharmony_ci 349e5c31af7Sopenharmony_ci gl.uniform1f(scaleLoc, 0.25f); 350e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f(scaleLoc, 0.25f)"); 351e5c31af7Sopenharmony_ci 352e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 353e5c31af7Sopenharmony_ci 354e5c31af7Sopenharmony_ci break; 355e5c31af7Sopenharmony_ci } 356e5c31af7Sopenharmony_ci 357e5c31af7Sopenharmony_ci case GL_TEXTURE_CUBE_MAP: 358e5c31af7Sopenharmony_ci { 359e5c31af7Sopenharmony_ci glu::VertexArrayBinding vertexArrays[] = 360e5c31af7Sopenharmony_ci { 361e5c31af7Sopenharmony_ci glu::VertexArrayBinding(glu::BindingPoint("a_position"), glu::VertexArrayPointer(glu::VTX_COMP_FLOAT, glu::VTX_COMP_CONVERT_NONE, 4, 6, 0, s_positionsCube)) 362e5c31af7Sopenharmony_ci }; 363e5c31af7Sopenharmony_ci 364e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 365e5c31af7Sopenharmony_ci 366e5c31af7Sopenharmony_ci gl.uniform1f(scaleLoc, 0.25f); 367e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f(scaleLoc, 0.25f)"); 368e5c31af7Sopenharmony_ci 369e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 370e5c31af7Sopenharmony_ci 371e5c31af7Sopenharmony_ci break; 372e5c31af7Sopenharmony_ci } 373e5c31af7Sopenharmony_ci 374e5c31af7Sopenharmony_ci default: 375e5c31af7Sopenharmony_ci DE_ASSERT(false); 376e5c31af7Sopenharmony_ci } 377e5c31af7Sopenharmony_ci} 378e5c31af7Sopenharmony_ci 379e5c31af7Sopenharmony_ciGLuint TextureSamplerTest::createTexture2D (const glw::Functions& gl) 380e5c31af7Sopenharmony_ci{ 381e5c31af7Sopenharmony_ci GLuint texture = (GLuint)-1; 382e5c31af7Sopenharmony_ci tcu::Texture2D refTexture (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), TEXTURE2D_WIDTH, TEXTURE2D_HEIGHT); 383e5c31af7Sopenharmony_ci 384e5c31af7Sopenharmony_ci refTexture.allocLevel(0); 385e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 386e5c31af7Sopenharmony_ci 387e5c31af7Sopenharmony_ci gl.genTextures(1, &texture); 388e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures(1, &texture)"); 389e5c31af7Sopenharmony_ci 390e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, texture); 391e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_2D, texture)"); 392e5c31af7Sopenharmony_ci 393e5c31af7Sopenharmony_ci gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, refTexture.getWidth(), refTexture.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevel(0).getDataPtr()); 394e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, refTexture.getWidth(), refTexture.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevel(0).getDataPtr())"); 395e5c31af7Sopenharmony_ci 396e5c31af7Sopenharmony_ci gl.generateMipmap(GL_TEXTURE_2D); 397e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenerateMipmap(GL_TEXTURE_2D)"); 398e5c31af7Sopenharmony_ci 399e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, 0); 400e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_2D, texture)"); 401e5c31af7Sopenharmony_ci 402e5c31af7Sopenharmony_ci return texture; 403e5c31af7Sopenharmony_ci} 404e5c31af7Sopenharmony_ci 405e5c31af7Sopenharmony_ciGLuint TextureSamplerTest::createTexture3D (const glw::Functions& gl) 406e5c31af7Sopenharmony_ci{ 407e5c31af7Sopenharmony_ci GLuint texture = (GLuint)-1; 408e5c31af7Sopenharmony_ci tcu::Texture3D refTexture (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), TEXTURE3D_WIDTH, TEXTURE3D_HEIGHT, TEXTURE3D_DEPTH); 409e5c31af7Sopenharmony_ci 410e5c31af7Sopenharmony_ci refTexture.allocLevel(0); 411e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 412e5c31af7Sopenharmony_ci 413e5c31af7Sopenharmony_ci gl.genTextures(1, &texture); 414e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures(1, &texture)"); 415e5c31af7Sopenharmony_ci 416e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_3D, texture); 417e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_3D, texture)"); 418e5c31af7Sopenharmony_ci 419e5c31af7Sopenharmony_ci gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, refTexture.getWidth(), refTexture.getHeight(), refTexture.getDepth(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevel(0).getDataPtr()); 420e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, refTexture.getWidth(), refTexture.getHeight(), refTexture.getDepth(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevel(0).getDataPtr())"); 421e5c31af7Sopenharmony_ci 422e5c31af7Sopenharmony_ci gl.generateMipmap(GL_TEXTURE_3D); 423e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenerateMipmap(GL_TEXTURE_3D)"); 424e5c31af7Sopenharmony_ci 425e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_3D, 0); 426e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_3D, 0)"); 427e5c31af7Sopenharmony_ci 428e5c31af7Sopenharmony_ci return texture; 429e5c31af7Sopenharmony_ci} 430e5c31af7Sopenharmony_ci 431e5c31af7Sopenharmony_ciGLuint TextureSamplerTest::createTextureCube (const glw::Functions& gl) 432e5c31af7Sopenharmony_ci{ 433e5c31af7Sopenharmony_ci GLuint texture = (GLuint)-1; 434e5c31af7Sopenharmony_ci tcu::TextureCube refTexture (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), CUBEMAP_SIZE); 435e5c31af7Sopenharmony_ci 436e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_POSITIVE_X, 0); 437e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_POSITIVE_Y, 0); 438e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_POSITIVE_Z, 0); 439e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_NEGATIVE_X, 0); 440e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_NEGATIVE_Y, 0); 441e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_NEGATIVE_Z, 0); 442e5c31af7Sopenharmony_ci 443e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_X), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 444e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_Y), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 445e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_Z), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 446e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_NEGATIVE_X), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 447e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_NEGATIVE_Y), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 448e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_NEGATIVE_Z), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 449e5c31af7Sopenharmony_ci 450e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture); 451e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_CUBE_MAP, texture)"); 452e5c31af7Sopenharmony_ci 453e5c31af7Sopenharmony_ci for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 454e5c31af7Sopenharmony_ci { 455e5c31af7Sopenharmony_ci const deUint32 target = glu::getGLCubeFace((tcu::CubeFace)face); 456e5c31af7Sopenharmony_ci gl.texImage2D(target, 0, GL_RGBA8, refTexture.getSize(), refTexture.getSize(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevelFace(0, (tcu::CubeFace)face).getDataPtr()); 457e5c31af7Sopenharmony_ci } 458e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D(GL_TEXTURE_CUBE_MAP_...) failed"); 459e5c31af7Sopenharmony_ci 460e5c31af7Sopenharmony_ci gl.generateMipmap(GL_TEXTURE_CUBE_MAP); 461e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenerateMipmap(GL_TEXTURE_CUBE_MAP)"); 462e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_CUBE_MAP, 0); 463e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_CUBE_MAP, texture)"); 464e5c31af7Sopenharmony_ci 465e5c31af7Sopenharmony_ci return texture; 466e5c31af7Sopenharmony_ci} 467e5c31af7Sopenharmony_ci 468e5c31af7Sopenharmony_ciGLuint TextureSamplerTest::createTexture (const glw::Functions& gl, GLenum target) 469e5c31af7Sopenharmony_ci{ 470e5c31af7Sopenharmony_ci switch (target) 471e5c31af7Sopenharmony_ci { 472e5c31af7Sopenharmony_ci case GL_TEXTURE_2D: 473e5c31af7Sopenharmony_ci return createTexture2D(gl); 474e5c31af7Sopenharmony_ci 475e5c31af7Sopenharmony_ci case GL_TEXTURE_3D: 476e5c31af7Sopenharmony_ci return createTexture3D(gl); 477e5c31af7Sopenharmony_ci 478e5c31af7Sopenharmony_ci case GL_TEXTURE_CUBE_MAP: 479e5c31af7Sopenharmony_ci return createTextureCube(gl); 480e5c31af7Sopenharmony_ci 481e5c31af7Sopenharmony_ci default: 482e5c31af7Sopenharmony_ci DE_ASSERT(false); 483e5c31af7Sopenharmony_ci return (GLuint)-1; 484e5c31af7Sopenharmony_ci } 485e5c31af7Sopenharmony_ci} 486e5c31af7Sopenharmony_ci 487e5c31af7Sopenharmony_civoid TextureSamplerTest::renderReferences (tcu::Surface& textureRef, tcu::Surface& samplerRef, int x, int y) 488e5c31af7Sopenharmony_ci{ 489e5c31af7Sopenharmony_ci const glw::Functions& gl = m_renderCtx.getFunctions(); 490e5c31af7Sopenharmony_ci GLuint texture = createTexture(gl, m_target); 491e5c31af7Sopenharmony_ci 492e5c31af7Sopenharmony_ci gl.viewport(x, y, VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 493e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport(x, y, VIEWPORT_WIDTH, VIEWPORT_HEIGHT)"); 494e5c31af7Sopenharmony_ci 495e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture); 496e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture)"); 497e5c31af7Sopenharmony_ci 498e5c31af7Sopenharmony_ci setTextureState(gl, m_target, m_textureState); 499e5c31af7Sopenharmony_ci render(); 500e5c31af7Sopenharmony_ci glu::readPixels(m_renderCtx, x, y, textureRef.getAccess()); 501e5c31af7Sopenharmony_ci 502e5c31af7Sopenharmony_ci setTextureState(gl, m_target, m_samplerState); 503e5c31af7Sopenharmony_ci render(); 504e5c31af7Sopenharmony_ci glu::readPixels(m_renderCtx, x, y, samplerRef.getAccess()); 505e5c31af7Sopenharmony_ci 506e5c31af7Sopenharmony_ci gl.deleteTextures(1, &texture); 507e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteTextures(1, &texture)"); 508e5c31af7Sopenharmony_ci} 509e5c31af7Sopenharmony_ci 510e5c31af7Sopenharmony_civoid TextureSamplerTest::renderResults (tcu::Surface& textureResult, tcu::Surface& samplerResult, int x, int y) 511e5c31af7Sopenharmony_ci{ 512e5c31af7Sopenharmony_ci const glw::Functions& gl = m_renderCtx.getFunctions(); 513e5c31af7Sopenharmony_ci GLuint texture = createTexture(gl, m_target); 514e5c31af7Sopenharmony_ci GLuint sampler = -1; 515e5c31af7Sopenharmony_ci 516e5c31af7Sopenharmony_ci gl.viewport(x, y, VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 517e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport(x, y, VIEWPORT_WIDTH, VIEWPORT_HEIGHT)"); 518e5c31af7Sopenharmony_ci 519e5c31af7Sopenharmony_ci gl.genSamplers(1, &sampler); 520e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenSamplers(1, &sampler)"); 521e5c31af7Sopenharmony_ci TCU_CHECK(sampler != (GLuint)-1); 522e5c31af7Sopenharmony_ci 523e5c31af7Sopenharmony_ci gl.bindSampler(0, sampler); 524e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindSampler(0, sampler)"); 525e5c31af7Sopenharmony_ci 526e5c31af7Sopenharmony_ci // First set sampler state 527e5c31af7Sopenharmony_ci setSamplerState(gl, m_samplerState, sampler); 528e5c31af7Sopenharmony_ci 529e5c31af7Sopenharmony_ci // Set texture state 530e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture); 531e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture)"); 532e5c31af7Sopenharmony_ci 533e5c31af7Sopenharmony_ci setTextureState(gl, m_target, m_textureState); 534e5c31af7Sopenharmony_ci 535e5c31af7Sopenharmony_ci // Render using sampler 536e5c31af7Sopenharmony_ci render(); 537e5c31af7Sopenharmony_ci glu::readPixels(m_renderCtx, x, y, samplerResult.getAccess()); 538e5c31af7Sopenharmony_ci 539e5c31af7Sopenharmony_ci // Render without sampler 540e5c31af7Sopenharmony_ci gl.bindSampler(0, 0); 541e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindSampler(0, 0)"); 542e5c31af7Sopenharmony_ci 543e5c31af7Sopenharmony_ci render(); 544e5c31af7Sopenharmony_ci glu::readPixels(m_renderCtx, x, y, textureResult.getAccess()); 545e5c31af7Sopenharmony_ci 546e5c31af7Sopenharmony_ci gl.deleteSamplers(1, &sampler); 547e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteSamplers(1, &sampler)"); 548e5c31af7Sopenharmony_ci gl.deleteTextures(1, &texture); 549e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteTextures(1, &texture)"); 550e5c31af7Sopenharmony_ci} 551e5c31af7Sopenharmony_ci 552e5c31af7Sopenharmony_citcu::TestCase::IterateResult TextureSamplerTest::iterate (void) 553e5c31af7Sopenharmony_ci{ 554e5c31af7Sopenharmony_ci tcu::TestLog& log = m_testCtx.getLog(); 555e5c31af7Sopenharmony_ci 556e5c31af7Sopenharmony_ci tcu::Surface textureRef(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 557e5c31af7Sopenharmony_ci tcu::Surface samplerRef(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 558e5c31af7Sopenharmony_ci 559e5c31af7Sopenharmony_ci tcu::Surface textureResult(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 560e5c31af7Sopenharmony_ci tcu::Surface samplerResult(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 561e5c31af7Sopenharmony_ci 562e5c31af7Sopenharmony_ci int x = m_random.getInt(0, m_renderCtx.getRenderTarget().getWidth() - VIEWPORT_WIDTH); 563e5c31af7Sopenharmony_ci int y = m_random.getInt(0, m_renderCtx.getRenderTarget().getHeight() - VIEWPORT_HEIGHT); 564e5c31af7Sopenharmony_ci 565e5c31af7Sopenharmony_ci renderReferences(textureRef, samplerRef, x, y); 566e5c31af7Sopenharmony_ci renderResults(textureResult, samplerResult, x, y); 567e5c31af7Sopenharmony_ci 568e5c31af7Sopenharmony_ci bool isOk = pixelThresholdCompare (log, "Sampler render result", "Result from rendering with sampler", samplerRef, samplerResult, tcu::RGBA(0, 0, 0, 0), tcu::COMPARE_LOG_RESULT); 569e5c31af7Sopenharmony_ci 570e5c31af7Sopenharmony_ci if (!pixelThresholdCompare (log, "Texture render result", "Result from rendering with texture state", textureRef, textureResult, tcu::RGBA(0, 0, 0, 0), tcu::COMPARE_LOG_RESULT)) 571e5c31af7Sopenharmony_ci isOk = false; 572e5c31af7Sopenharmony_ci 573e5c31af7Sopenharmony_ci if (!isOk) 574e5c31af7Sopenharmony_ci { 575e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 576e5c31af7Sopenharmony_ci return STOP; 577e5c31af7Sopenharmony_ci } 578e5c31af7Sopenharmony_ci 579e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 580e5c31af7Sopenharmony_ci return STOP; 581e5c31af7Sopenharmony_ci} 582e5c31af7Sopenharmony_ci 583e5c31af7Sopenharmony_ciMultiTextureSamplerTest::MultiTextureSamplerTest (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const TestSpec& spec) 584e5c31af7Sopenharmony_ci : TestCase (testCtx, spec.name, spec.desc) 585e5c31af7Sopenharmony_ci , m_renderCtx (renderCtx) 586e5c31af7Sopenharmony_ci , m_program (NULL) 587e5c31af7Sopenharmony_ci , m_target (spec.target) 588e5c31af7Sopenharmony_ci , m_textureState1 (spec.textureState1) 589e5c31af7Sopenharmony_ci , m_textureState2 (spec.textureState2) 590e5c31af7Sopenharmony_ci , m_samplerState (spec.samplerState) 591e5c31af7Sopenharmony_ci , m_random (deStringHash(spec.name)) 592e5c31af7Sopenharmony_ci{ 593e5c31af7Sopenharmony_ci} 594e5c31af7Sopenharmony_ci 595e5c31af7Sopenharmony_civoid MultiTextureSamplerTest::setTextureState (const glw::Functions& gl, GLenum target, SamplingState state) 596e5c31af7Sopenharmony_ci{ 597e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_MIN_FILTER, state.minFilter); 598e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_MIN_FILTER, state.minFilter)"); 599e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_MAG_FILTER, state.magFilter); 600e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_MAG_FILTER, state.magFilter)"); 601e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_WRAP_S, state.wrapS); 602e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_WRAP_S, state.wrapS)"); 603e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_WRAP_T, state.wrapT); 604e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_WRAP_T, state.wrapT)"); 605e5c31af7Sopenharmony_ci gl.texParameteri(target, GL_TEXTURE_WRAP_R, state.wrapR); 606e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameteri(target, GL_TEXTURE_WRAP_R, state.wrapR)"); 607e5c31af7Sopenharmony_ci gl.texParameterf(target, GL_TEXTURE_MAX_LOD, state.maxLod); 608e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameterf(target, GL_TEXTURE_MAX_LOD, state.maxLod)"); 609e5c31af7Sopenharmony_ci gl.texParameterf(target, GL_TEXTURE_MIN_LOD, state.minLod); 610e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexParameterf(target, GL_TEXTURE_MIN_LOD, state.minLod)"); 611e5c31af7Sopenharmony_ci} 612e5c31af7Sopenharmony_ci 613e5c31af7Sopenharmony_civoid MultiTextureSamplerTest::setSamplerState (const glw::Functions& gl, SamplingState state, GLuint sampler) 614e5c31af7Sopenharmony_ci{ 615e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, state.minFilter); 616e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, state.minFilter)"); 617e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, state.magFilter); 618e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, state.magFilter)"); 619e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_WRAP_S, state.wrapS); 620e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, state.wrapS)"); 621e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_WRAP_T, state.wrapT); 622e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, state.wrapT)"); 623e5c31af7Sopenharmony_ci gl.samplerParameteri(sampler, GL_TEXTURE_WRAP_R, state.wrapR); 624e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameteri(sampler, GL_TEXTURE_WRAP_R, state.wrapR)"); 625e5c31af7Sopenharmony_ci gl.samplerParameterf(sampler, GL_TEXTURE_MAX_LOD, state.maxLod); 626e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameterf(sampler, GL_TEXTURE_MAX_LOD, state.maxLod)"); 627e5c31af7Sopenharmony_ci gl.samplerParameterf(sampler, GL_TEXTURE_MIN_LOD, state.minLod); 628e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glSamplerParameterf(sampler, GL_TEXTURE_MIN_LOD, state.minLod)"); 629e5c31af7Sopenharmony_ci} 630e5c31af7Sopenharmony_ci 631e5c31af7Sopenharmony_ciconst char* MultiTextureSamplerTest::selectVertexShader (GLenum target) 632e5c31af7Sopenharmony_ci{ 633e5c31af7Sopenharmony_ci switch (target) 634e5c31af7Sopenharmony_ci { 635e5c31af7Sopenharmony_ci case GL_TEXTURE_2D: 636e5c31af7Sopenharmony_ci return 637e5c31af7Sopenharmony_ci "${VTX_HDR}" 638e5c31af7Sopenharmony_ci "${VTX_IN} ${HIGHP} vec2 a_position;\n" 639e5c31af7Sopenharmony_ci "uniform ${HIGHP} float u_posScale;\n" 640e5c31af7Sopenharmony_ci "${VTX_OUT} ${MEDIUMP} vec2 v_texCoord;\n" 641e5c31af7Sopenharmony_ci "void main (void)\n" 642e5c31af7Sopenharmony_ci "{\n" 643e5c31af7Sopenharmony_ci "\tv_texCoord = a_position;\n" 644e5c31af7Sopenharmony_ci "\tgl_Position = vec4(u_posScale * a_position, 0.0, 1.0);\n" 645e5c31af7Sopenharmony_ci "}"; 646e5c31af7Sopenharmony_ci 647e5c31af7Sopenharmony_ci case GL_TEXTURE_3D: 648e5c31af7Sopenharmony_ci return 649e5c31af7Sopenharmony_ci "${VTX_HDR}" 650e5c31af7Sopenharmony_ci "${VTX_IN} ${HIGHP} vec3 a_position;\n" 651e5c31af7Sopenharmony_ci "uniform ${HIGHP} float u_posScale;\n" 652e5c31af7Sopenharmony_ci "${VTX_OUT} ${MEDIUMP} vec3 v_texCoord;\n" 653e5c31af7Sopenharmony_ci "void main (void)\n" 654e5c31af7Sopenharmony_ci "{\n" 655e5c31af7Sopenharmony_ci "\tv_texCoord = a_position;\n" 656e5c31af7Sopenharmony_ci "\tgl_Position = vec4(u_posScale * a_position.xy, 0.0, 1.0);\n" 657e5c31af7Sopenharmony_ci "}"; 658e5c31af7Sopenharmony_ci 659e5c31af7Sopenharmony_ci case GL_TEXTURE_CUBE_MAP: 660e5c31af7Sopenharmony_ci return 661e5c31af7Sopenharmony_ci "${VTX_HDR}" 662e5c31af7Sopenharmony_ci "${VTX_IN} ${HIGHP} vec4 a_position;\n" 663e5c31af7Sopenharmony_ci "uniform ${HIGHP} float u_posScale;\n" 664e5c31af7Sopenharmony_ci "${VTX_OUT} ${MEDIUMP} vec2 v_texCoord;\n" 665e5c31af7Sopenharmony_ci "void main (void)\n" 666e5c31af7Sopenharmony_ci "{\n" 667e5c31af7Sopenharmony_ci "\tv_texCoord = a_position.zw;\n" 668e5c31af7Sopenharmony_ci "\tgl_Position = vec4(u_posScale * a_position.xy, 0.0, 1.0);\n" 669e5c31af7Sopenharmony_ci "}"; 670e5c31af7Sopenharmony_ci 671e5c31af7Sopenharmony_ci default: 672e5c31af7Sopenharmony_ci DE_ASSERT(false); 673e5c31af7Sopenharmony_ci return NULL; 674e5c31af7Sopenharmony_ci } 675e5c31af7Sopenharmony_ci 676e5c31af7Sopenharmony_ci} 677e5c31af7Sopenharmony_ci 678e5c31af7Sopenharmony_ciconst char* MultiTextureSamplerTest::selectFragmentShader (GLenum target) 679e5c31af7Sopenharmony_ci{ 680e5c31af7Sopenharmony_ci switch (target) 681e5c31af7Sopenharmony_ci { 682e5c31af7Sopenharmony_ci case GL_TEXTURE_2D: 683e5c31af7Sopenharmony_ci return 684e5c31af7Sopenharmony_ci "${FRAG_HDR}" 685e5c31af7Sopenharmony_ci "uniform ${LOWP} sampler2D u_sampler1;\n" 686e5c31af7Sopenharmony_ci "uniform ${LOWP} sampler2D u_sampler2;\n" 687e5c31af7Sopenharmony_ci "${FRAG_IN} ${MEDIUMP} vec2 v_texCoord;\n" 688e5c31af7Sopenharmony_ci "void main (void)\n" 689e5c31af7Sopenharmony_ci "{\n" 690e5c31af7Sopenharmony_ci "\t${FRAG_COLOR} = vec4(0.75, 0.75, 0.75, 1.0) * (texture(u_sampler1, v_texCoord) + texture(u_sampler2, v_texCoord));\n" 691e5c31af7Sopenharmony_ci "}"; 692e5c31af7Sopenharmony_ci 693e5c31af7Sopenharmony_ci case GL_TEXTURE_3D: 694e5c31af7Sopenharmony_ci return 695e5c31af7Sopenharmony_ci "${FRAG_HDR}" 696e5c31af7Sopenharmony_ci "uniform ${LOWP} sampler3D u_sampler1;\n" 697e5c31af7Sopenharmony_ci "uniform ${LOWP} sampler3D u_sampler2;\n" 698e5c31af7Sopenharmony_ci "${FRAG_IN} ${MEDIUMP} vec3 v_texCoord;\n" 699e5c31af7Sopenharmony_ci "void main (void)\n" 700e5c31af7Sopenharmony_ci "{\n" 701e5c31af7Sopenharmony_ci "\t${FRAG_COLOR} = vec4(0.75, 0.75, 0.75, 1.0) * (texture(u_sampler1, v_texCoord) + texture(u_sampler2, v_texCoord));\n" 702e5c31af7Sopenharmony_ci "}"; 703e5c31af7Sopenharmony_ci 704e5c31af7Sopenharmony_ci case GL_TEXTURE_CUBE_MAP: 705e5c31af7Sopenharmony_ci return 706e5c31af7Sopenharmony_ci "${FRAG_HDR}" 707e5c31af7Sopenharmony_ci "uniform ${LOWP} samplerCube u_sampler1;\n" 708e5c31af7Sopenharmony_ci "uniform ${LOWP} samplerCube u_sampler2;\n" 709e5c31af7Sopenharmony_ci "${FRAG_IN} ${MEDIUMP} vec2 v_texCoord;\n" 710e5c31af7Sopenharmony_ci "void main (void)\n" 711e5c31af7Sopenharmony_ci "{\n" 712e5c31af7Sopenharmony_ci "\t${FRAG_COLOR} = vec4(0.5, 0.5, 0.5, 1.0) * (texture(u_sampler1, vec3(cos(3.14 * v_texCoord.y) * sin(3.14 * v_texCoord.x), sin(3.14 * v_texCoord.y), cos(3.14 * v_texCoord.y) * cos(3.14 * v_texCoord.x)))" 713e5c31af7Sopenharmony_ci "+ texture(u_sampler2, vec3(cos(3.14 * v_texCoord.y) * sin(3.14 * v_texCoord.x), sin(3.14 * v_texCoord.y), cos(3.14 * v_texCoord.y) * cos(3.14 * v_texCoord.x))));\n" 714e5c31af7Sopenharmony_ci "}"; 715e5c31af7Sopenharmony_ci 716e5c31af7Sopenharmony_ci default: 717e5c31af7Sopenharmony_ci DE_ASSERT(false); 718e5c31af7Sopenharmony_ci return NULL; 719e5c31af7Sopenharmony_ci } 720e5c31af7Sopenharmony_ci 721e5c31af7Sopenharmony_ci} 722e5c31af7Sopenharmony_ci 723e5c31af7Sopenharmony_civoid MultiTextureSamplerTest::init (void) 724e5c31af7Sopenharmony_ci{ 725e5c31af7Sopenharmony_ci const char* vertexShaderTemplate = selectVertexShader(m_target); 726e5c31af7Sopenharmony_ci const char* fragmentShaderTemplate = selectFragmentShader(m_target); 727e5c31af7Sopenharmony_ci 728e5c31af7Sopenharmony_ci std::map<std::string, std::string> params; 729e5c31af7Sopenharmony_ci 730e5c31af7Sopenharmony_ci if (glu::isGLSLVersionSupported(m_renderCtx.getType(), glu::GLSL_VERSION_300_ES)) 731e5c31af7Sopenharmony_ci { 732e5c31af7Sopenharmony_ci params["VTX_HDR"] = "#version 300 es\n"; 733e5c31af7Sopenharmony_ci params["FRAG_HDR"] = "#version 300 es\nlayout(location = 0) out mediump vec4 o_color;\n"; 734e5c31af7Sopenharmony_ci params["VTX_IN"] = "in"; 735e5c31af7Sopenharmony_ci params["VTX_OUT"] = "out"; 736e5c31af7Sopenharmony_ci params["FRAG_IN"] = "in"; 737e5c31af7Sopenharmony_ci params["FRAG_COLOR"] = "o_color"; 738e5c31af7Sopenharmony_ci params["HIGHP"] = "highp"; 739e5c31af7Sopenharmony_ci params["LOWP"] = "lowp"; 740e5c31af7Sopenharmony_ci params["MEDIUMP"] = "mediump"; 741e5c31af7Sopenharmony_ci } 742e5c31af7Sopenharmony_ci else if (glu::isGLSLVersionSupported(m_renderCtx.getType(), glu::GLSL_VERSION_330)) 743e5c31af7Sopenharmony_ci { 744e5c31af7Sopenharmony_ci params["VTX_HDR"] = "#version 330\n"; 745e5c31af7Sopenharmony_ci params["FRAG_HDR"] = "#version 330\nlayout(location = 0) out mediump vec4 o_color;\n"; 746e5c31af7Sopenharmony_ci params["VTX_IN"] = "in"; 747e5c31af7Sopenharmony_ci params["VTX_OUT"] = "out"; 748e5c31af7Sopenharmony_ci params["FRAG_IN"] = "in"; 749e5c31af7Sopenharmony_ci params["FRAG_COLOR"] = "o_color"; 750e5c31af7Sopenharmony_ci params["HIGHP"] = "highp"; 751e5c31af7Sopenharmony_ci params["LOWP"] = "lowp"; 752e5c31af7Sopenharmony_ci params["MEDIUMP"] = "mediump"; 753e5c31af7Sopenharmony_ci } 754e5c31af7Sopenharmony_ci else 755e5c31af7Sopenharmony_ci DE_ASSERT(false); 756e5c31af7Sopenharmony_ci 757e5c31af7Sopenharmony_ci DE_ASSERT(!m_program); 758e5c31af7Sopenharmony_ci m_program = new glu::ShaderProgram(m_renderCtx, 759e5c31af7Sopenharmony_ci glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderTemplate).specialize(params), 760e5c31af7Sopenharmony_ci tcu::StringTemplate(fragmentShaderTemplate).specialize(params))); 761e5c31af7Sopenharmony_ci if (!m_program->isOk()) 762e5c31af7Sopenharmony_ci { 763e5c31af7Sopenharmony_ci tcu::TestLog& log = m_testCtx.getLog(); 764e5c31af7Sopenharmony_ci 765e5c31af7Sopenharmony_ci log << *m_program; 766e5c31af7Sopenharmony_ci TCU_FAIL("Failed to compile shaders"); 767e5c31af7Sopenharmony_ci } 768e5c31af7Sopenharmony_ci} 769e5c31af7Sopenharmony_ci 770e5c31af7Sopenharmony_civoid MultiTextureSamplerTest::deinit (void) 771e5c31af7Sopenharmony_ci{ 772e5c31af7Sopenharmony_ci delete m_program; 773e5c31af7Sopenharmony_ci m_program = NULL; 774e5c31af7Sopenharmony_ci} 775e5c31af7Sopenharmony_ci 776e5c31af7Sopenharmony_ciMultiTextureSamplerTest::~MultiTextureSamplerTest (void) 777e5c31af7Sopenharmony_ci{ 778e5c31af7Sopenharmony_ci deinit(); 779e5c31af7Sopenharmony_ci} 780e5c31af7Sopenharmony_ci 781e5c31af7Sopenharmony_civoid MultiTextureSamplerTest::render (void) 782e5c31af7Sopenharmony_ci{ 783e5c31af7Sopenharmony_ci const glw::Functions& gl = m_renderCtx.getFunctions(); 784e5c31af7Sopenharmony_ci 785e5c31af7Sopenharmony_ci GLuint samplerLoc1 = (GLuint)-1; 786e5c31af7Sopenharmony_ci GLuint samplerLoc2 = (GLuint)-1; 787e5c31af7Sopenharmony_ci GLuint scaleLoc = (GLuint)-1; 788e5c31af7Sopenharmony_ci 789e5c31af7Sopenharmony_ci gl.useProgram(m_program->getProgram()); 790e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram(m_program->getProgram())"); 791e5c31af7Sopenharmony_ci 792e5c31af7Sopenharmony_ci samplerLoc1 = glGetUniformLocation(m_program->getProgram(), "u_sampler1"); 793e5c31af7Sopenharmony_ci TCU_CHECK(samplerLoc1 != (GLuint)-1); 794e5c31af7Sopenharmony_ci 795e5c31af7Sopenharmony_ci samplerLoc2 = glGetUniformLocation(m_program->getProgram(), "u_sampler2"); 796e5c31af7Sopenharmony_ci TCU_CHECK(samplerLoc2 != (GLuint)-1); 797e5c31af7Sopenharmony_ci 798e5c31af7Sopenharmony_ci scaleLoc = glGetUniformLocation(m_program->getProgram(), "u_posScale"); 799e5c31af7Sopenharmony_ci TCU_CHECK(scaleLoc != (GLuint)-1); 800e5c31af7Sopenharmony_ci 801e5c31af7Sopenharmony_ci gl.clearColor(0.5f, 0.5f, 0.5f, 1.0f); 802e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor(0.5f, 0.5f, 0.5f, 1.0f)"); 803e5c31af7Sopenharmony_ci 804e5c31af7Sopenharmony_ci gl.clear(GL_COLOR_BUFFER_BIT); 805e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glClear(GL_COLOR_BUFFER_BIT)"); 806e5c31af7Sopenharmony_ci 807e5c31af7Sopenharmony_ci gl.uniform1i(samplerLoc1, 0); 808e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i(samplerLoc1, 0)"); 809e5c31af7Sopenharmony_ci 810e5c31af7Sopenharmony_ci gl.uniform1i(samplerLoc2, 1); 811e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1i(samplerLoc2, 1)"); 812e5c31af7Sopenharmony_ci 813e5c31af7Sopenharmony_ci gl.uniform1f(scaleLoc, 1.0f); 814e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f(scaleLoc, 1.0f)"); 815e5c31af7Sopenharmony_ci 816e5c31af7Sopenharmony_ci switch (m_target) 817e5c31af7Sopenharmony_ci { 818e5c31af7Sopenharmony_ci case GL_TEXTURE_2D: 819e5c31af7Sopenharmony_ci { 820e5c31af7Sopenharmony_ci glu::VertexArrayBinding vertexArrays[] = 821e5c31af7Sopenharmony_ci { 822e5c31af7Sopenharmony_ci glu::VertexArrayBinding(glu::BindingPoint("a_position"), glu::VertexArrayPointer(glu::VTX_COMP_FLOAT, glu::VTX_COMP_CONVERT_NONE, 2, 6, 0, s_positions)) 823e5c31af7Sopenharmony_ci }; 824e5c31af7Sopenharmony_ci 825e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 826e5c31af7Sopenharmony_ci 827e5c31af7Sopenharmony_ci gl.uniform1f(scaleLoc, 0.25f); 828e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f(scaleLoc, 0.25f)"); 829e5c31af7Sopenharmony_ci 830e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 831e5c31af7Sopenharmony_ci 832e5c31af7Sopenharmony_ci break; 833e5c31af7Sopenharmony_ci } 834e5c31af7Sopenharmony_ci 835e5c31af7Sopenharmony_ci case GL_TEXTURE_3D: 836e5c31af7Sopenharmony_ci { 837e5c31af7Sopenharmony_ci glu::VertexArrayBinding vertexArrays[] = 838e5c31af7Sopenharmony_ci { 839e5c31af7Sopenharmony_ci glu::VertexArrayBinding(glu::BindingPoint("a_position"), glu::VertexArrayPointer(glu::VTX_COMP_FLOAT, glu::VTX_COMP_CONVERT_NONE, 3, 6, 0, s_positions3D)) 840e5c31af7Sopenharmony_ci }; 841e5c31af7Sopenharmony_ci 842e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 843e5c31af7Sopenharmony_ci 844e5c31af7Sopenharmony_ci gl.uniform1f(scaleLoc, 0.25f); 845e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f(scaleLoc, 0.25f)"); 846e5c31af7Sopenharmony_ci 847e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 848e5c31af7Sopenharmony_ci 849e5c31af7Sopenharmony_ci break; 850e5c31af7Sopenharmony_ci } 851e5c31af7Sopenharmony_ci 852e5c31af7Sopenharmony_ci case GL_TEXTURE_CUBE_MAP: 853e5c31af7Sopenharmony_ci { 854e5c31af7Sopenharmony_ci glu::VertexArrayBinding vertexArrays[] = 855e5c31af7Sopenharmony_ci { 856e5c31af7Sopenharmony_ci glu::VertexArrayBinding(glu::BindingPoint("a_position"), glu::VertexArrayPointer(glu::VTX_COMP_FLOAT, glu::VTX_COMP_CONVERT_NONE, 4, 6, 0, s_positionsCube)) 857e5c31af7Sopenharmony_ci }; 858e5c31af7Sopenharmony_ci 859e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 860e5c31af7Sopenharmony_ci 861e5c31af7Sopenharmony_ci gl.uniform1f(scaleLoc, 0.25f); 862e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glUniform1f(scaleLoc, 0.25f)"); 863e5c31af7Sopenharmony_ci 864e5c31af7Sopenharmony_ci glu::draw(m_renderCtx, m_program->getProgram(), DE_LENGTH_OF_ARRAY(vertexArrays), vertexArrays, glu::PrimitiveList(glu::PRIMITIVETYPE_TRIANGLES, 6)); 865e5c31af7Sopenharmony_ci 866e5c31af7Sopenharmony_ci break; 867e5c31af7Sopenharmony_ci } 868e5c31af7Sopenharmony_ci 869e5c31af7Sopenharmony_ci default: 870e5c31af7Sopenharmony_ci DE_ASSERT(false); 871e5c31af7Sopenharmony_ci } 872e5c31af7Sopenharmony_ci} 873e5c31af7Sopenharmony_ci 874e5c31af7Sopenharmony_ciGLuint MultiTextureSamplerTest::createTexture2D (const glw::Functions& gl, int id) 875e5c31af7Sopenharmony_ci{ 876e5c31af7Sopenharmony_ci GLuint texture = (GLuint)-1; 877e5c31af7Sopenharmony_ci tcu::Texture2D refTexture (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), TEXTURE2D_WIDTH, TEXTURE2D_HEIGHT); 878e5c31af7Sopenharmony_ci 879e5c31af7Sopenharmony_ci refTexture.allocLevel(0); 880e5c31af7Sopenharmony_ci 881e5c31af7Sopenharmony_ci gl.genTextures(1, &texture); 882e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures(1, &texture)"); 883e5c31af7Sopenharmony_ci 884e5c31af7Sopenharmony_ci switch (id) 885e5c31af7Sopenharmony_ci { 886e5c31af7Sopenharmony_ci case 0: 887e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.5f, 0.5f)); 888e5c31af7Sopenharmony_ci break; 889e5c31af7Sopenharmony_ci 890e5c31af7Sopenharmony_ci case 1: 891e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 1.0f, 1.0f)); 892e5c31af7Sopenharmony_ci break; 893e5c31af7Sopenharmony_ci 894e5c31af7Sopenharmony_ci default: 895e5c31af7Sopenharmony_ci DE_ASSERT(false); 896e5c31af7Sopenharmony_ci } 897e5c31af7Sopenharmony_ci 898e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, texture); 899e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_2D, texture)"); 900e5c31af7Sopenharmony_ci 901e5c31af7Sopenharmony_ci gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, refTexture.getWidth(), refTexture.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevel(0).getDataPtr()); 902e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, refTexture.getWidth(), refTexture.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevel(0).getDataPtr())"); 903e5c31af7Sopenharmony_ci 904e5c31af7Sopenharmony_ci gl.generateMipmap(GL_TEXTURE_2D); 905e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenerateMipmap(GL_TEXTURE_2D)"); 906e5c31af7Sopenharmony_ci 907e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_2D, 0); 908e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_2D, 0)"); 909e5c31af7Sopenharmony_ci 910e5c31af7Sopenharmony_ci return texture; 911e5c31af7Sopenharmony_ci} 912e5c31af7Sopenharmony_ci 913e5c31af7Sopenharmony_ciGLuint MultiTextureSamplerTest::createTexture3D (const glw::Functions& gl, int id) 914e5c31af7Sopenharmony_ci{ 915e5c31af7Sopenharmony_ci GLuint texture = (GLuint)-1; 916e5c31af7Sopenharmony_ci tcu::Texture3D refTexture (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), TEXTURE3D_WIDTH, TEXTURE3D_HEIGHT, TEXTURE3D_DEPTH); 917e5c31af7Sopenharmony_ci 918e5c31af7Sopenharmony_ci refTexture.allocLevel(0); 919e5c31af7Sopenharmony_ci 920e5c31af7Sopenharmony_ci gl.genTextures(1, &texture); 921e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures(1, &texture)"); 922e5c31af7Sopenharmony_ci 923e5c31af7Sopenharmony_ci switch (id) 924e5c31af7Sopenharmony_ci { 925e5c31af7Sopenharmony_ci case 0: 926e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 0.5f, 0.5f)); 927e5c31af7Sopenharmony_ci break; 928e5c31af7Sopenharmony_ci 929e5c31af7Sopenharmony_ci case 1: 930e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 1.0f, 1.0f)); 931e5c31af7Sopenharmony_ci break; 932e5c31af7Sopenharmony_ci 933e5c31af7Sopenharmony_ci default: 934e5c31af7Sopenharmony_ci DE_ASSERT(false); 935e5c31af7Sopenharmony_ci } 936e5c31af7Sopenharmony_ci 937e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_3D, texture); 938e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_3D, texture)"); 939e5c31af7Sopenharmony_ci 940e5c31af7Sopenharmony_ci gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, refTexture.getWidth(), refTexture.getHeight(), refTexture.getDepth(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevel(0).getDataPtr()); 941e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, refTexture.getWidth(), refTexture.getHeight(), refTexture.getDepth(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevel(0).getDataPtr())"); 942e5c31af7Sopenharmony_ci 943e5c31af7Sopenharmony_ci gl.generateMipmap(GL_TEXTURE_3D); 944e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenerateMipmap(GL_TEXTURE_3D)"); 945e5c31af7Sopenharmony_ci 946e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_3D, 0); 947e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_3D, 0)"); 948e5c31af7Sopenharmony_ci 949e5c31af7Sopenharmony_ci return texture; 950e5c31af7Sopenharmony_ci} 951e5c31af7Sopenharmony_ci 952e5c31af7Sopenharmony_ciGLuint MultiTextureSamplerTest::createTextureCube (const glw::Functions& gl, int id) 953e5c31af7Sopenharmony_ci{ 954e5c31af7Sopenharmony_ci GLuint texture = (GLuint)-1; 955e5c31af7Sopenharmony_ci tcu::TextureCube refTexture (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), CUBEMAP_SIZE); 956e5c31af7Sopenharmony_ci 957e5c31af7Sopenharmony_ci gl.genTextures(1, &texture); 958e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures(1, &texture)"); 959e5c31af7Sopenharmony_ci 960e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_POSITIVE_X, 0); 961e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_POSITIVE_Y, 0); 962e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_POSITIVE_Z, 0); 963e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_NEGATIVE_X, 0); 964e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_NEGATIVE_Y, 0); 965e5c31af7Sopenharmony_ci refTexture.allocLevel(tcu::CUBEFACE_NEGATIVE_Z, 0); 966e5c31af7Sopenharmony_ci 967e5c31af7Sopenharmony_ci switch (id) 968e5c31af7Sopenharmony_ci { 969e5c31af7Sopenharmony_ci case 0: 970e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_X), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f)); 971e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_Y), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f)); 972e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_Z), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f)); 973e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_NEGATIVE_X), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f)); 974e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_NEGATIVE_Y), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f)); 975e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_NEGATIVE_Z), tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f)); 976e5c31af7Sopenharmony_ci break; 977e5c31af7Sopenharmony_ci 978e5c31af7Sopenharmony_ci case 1: 979e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_X), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 980e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_Y), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 981e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_Z), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 982e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_NEGATIVE_X), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 983e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_NEGATIVE_Y), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 984e5c31af7Sopenharmony_ci tcu::fillWithComponentGradients(refTexture.getLevelFace(0, tcu::CUBEFACE_NEGATIVE_Z), tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); 985e5c31af7Sopenharmony_ci break; 986e5c31af7Sopenharmony_ci 987e5c31af7Sopenharmony_ci default: 988e5c31af7Sopenharmony_ci DE_ASSERT(false); 989e5c31af7Sopenharmony_ci } 990e5c31af7Sopenharmony_ci 991e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_CUBE_MAP, texture); 992e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_CUBE_MAP, texture)"); 993e5c31af7Sopenharmony_ci 994e5c31af7Sopenharmony_ci for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 995e5c31af7Sopenharmony_ci { 996e5c31af7Sopenharmony_ci const deUint32 target = glu::getGLCubeFace((tcu::CubeFace)face); 997e5c31af7Sopenharmony_ci gl.texImage2D(target, 0, GL_RGBA8, refTexture.getSize(), refTexture.getSize(), 0, GL_RGBA, GL_UNSIGNED_BYTE, refTexture.getLevelFace(0, (tcu::CubeFace)face).getDataPtr()); 998e5c31af7Sopenharmony_ci } 999e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D(GL_TEXTURE_CUBE_MAP_...) failed"); 1000e5c31af7Sopenharmony_ci 1001e5c31af7Sopenharmony_ci gl.generateMipmap(GL_TEXTURE_CUBE_MAP); 1002e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenerateMipmap(GL_TEXTURE_CUBE_MAP)"); 1003e5c31af7Sopenharmony_ci gl.bindTexture(GL_TEXTURE_CUBE_MAP, 0); 1004e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(GL_TEXTURE_CUBE_MAP, 0)"); 1005e5c31af7Sopenharmony_ci 1006e5c31af7Sopenharmony_ci return texture; 1007e5c31af7Sopenharmony_ci} 1008e5c31af7Sopenharmony_ci 1009e5c31af7Sopenharmony_ciGLuint MultiTextureSamplerTest::createTexture (const glw::Functions& gl, GLenum target, int id) 1010e5c31af7Sopenharmony_ci{ 1011e5c31af7Sopenharmony_ci switch (target) 1012e5c31af7Sopenharmony_ci { 1013e5c31af7Sopenharmony_ci case GL_TEXTURE_2D: 1014e5c31af7Sopenharmony_ci return createTexture2D(gl, id); 1015e5c31af7Sopenharmony_ci 1016e5c31af7Sopenharmony_ci case GL_TEXTURE_3D: 1017e5c31af7Sopenharmony_ci return createTexture3D(gl, id); 1018e5c31af7Sopenharmony_ci 1019e5c31af7Sopenharmony_ci case GL_TEXTURE_CUBE_MAP: 1020e5c31af7Sopenharmony_ci return createTextureCube(gl, id); 1021e5c31af7Sopenharmony_ci 1022e5c31af7Sopenharmony_ci default: 1023e5c31af7Sopenharmony_ci DE_ASSERT(false); 1024e5c31af7Sopenharmony_ci return (GLuint)-1; 1025e5c31af7Sopenharmony_ci } 1026e5c31af7Sopenharmony_ci} 1027e5c31af7Sopenharmony_ci 1028e5c31af7Sopenharmony_civoid MultiTextureSamplerTest::renderReferences (tcu::Surface& textureRef, tcu::Surface& samplerRef, int x, int y) 1029e5c31af7Sopenharmony_ci{ 1030e5c31af7Sopenharmony_ci const glw::Functions& gl = m_renderCtx.getFunctions(); 1031e5c31af7Sopenharmony_ci GLuint texture1 = createTexture(gl, m_target, 0); 1032e5c31af7Sopenharmony_ci GLuint texture2 = createTexture(gl, m_target, 1); 1033e5c31af7Sopenharmony_ci 1034e5c31af7Sopenharmony_ci gl.viewport(x, y, VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 1035e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport(x, y, VIEWPORT_WIDTH, VIEWPORT_HEIGHT)"); 1036e5c31af7Sopenharmony_ci 1037e5c31af7Sopenharmony_ci // Generate texture rendering reference 1038e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE0); 1039e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture(GL_TEXTURE0)"); 1040e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture1); 1041e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture1)"); 1042e5c31af7Sopenharmony_ci setTextureState(gl, m_target, m_textureState1); 1043e5c31af7Sopenharmony_ci 1044e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE1); 1045e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture(GL_TEXTURE1)"); 1046e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture2); 1047e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture2)"); 1048e5c31af7Sopenharmony_ci setTextureState(gl, m_target, m_textureState2); 1049e5c31af7Sopenharmony_ci 1050e5c31af7Sopenharmony_ci render(); 1051e5c31af7Sopenharmony_ci glu::readPixels(m_renderCtx, x, y, textureRef.getAccess()); 1052e5c31af7Sopenharmony_ci 1053e5c31af7Sopenharmony_ci // Generate sampler rendering reference 1054e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE0); 1055e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture(GL_TEXTURE0)"); 1056e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture1); 1057e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture1)"); 1058e5c31af7Sopenharmony_ci setTextureState(gl, m_target, m_samplerState); 1059e5c31af7Sopenharmony_ci 1060e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE1); 1061e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture(GL_TEXTURE1)"); 1062e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture2); 1063e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture2)"); 1064e5c31af7Sopenharmony_ci setTextureState(gl, m_target, m_samplerState); 1065e5c31af7Sopenharmony_ci 1066e5c31af7Sopenharmony_ci render(); 1067e5c31af7Sopenharmony_ci glu::readPixels(m_renderCtx, x, y, samplerRef.getAccess()); 1068e5c31af7Sopenharmony_ci} 1069e5c31af7Sopenharmony_ci 1070e5c31af7Sopenharmony_civoid MultiTextureSamplerTest::renderResults (tcu::Surface& textureResult, tcu::Surface& samplerResult, int x, int y) 1071e5c31af7Sopenharmony_ci{ 1072e5c31af7Sopenharmony_ci const glw::Functions& gl = m_renderCtx.getFunctions(); 1073e5c31af7Sopenharmony_ci GLuint texture1 = createTexture(gl, m_target, 0); 1074e5c31af7Sopenharmony_ci GLuint texture2 = createTexture(gl, m_target, 1); 1075e5c31af7Sopenharmony_ci GLuint sampler = -1; 1076e5c31af7Sopenharmony_ci 1077e5c31af7Sopenharmony_ci gl.viewport(x, y, VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 1078e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport(x, y, VIEWPORT_WIDTH, VIEWPORT_HEIGHT)"); 1079e5c31af7Sopenharmony_ci 1080e5c31af7Sopenharmony_ci gl.genSamplers(1, &sampler); 1081e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glGenSamplers(1, &sampler)"); 1082e5c31af7Sopenharmony_ci TCU_CHECK(sampler != (GLuint)-1); 1083e5c31af7Sopenharmony_ci 1084e5c31af7Sopenharmony_ci gl.bindSampler(0, sampler); 1085e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindSampler(0, sampler)"); 1086e5c31af7Sopenharmony_ci gl.bindSampler(1, sampler); 1087e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindSampler(1, sampler)"); 1088e5c31af7Sopenharmony_ci 1089e5c31af7Sopenharmony_ci // First set sampler state 1090e5c31af7Sopenharmony_ci setSamplerState(gl, m_samplerState, sampler); 1091e5c31af7Sopenharmony_ci 1092e5c31af7Sopenharmony_ci // Set texture state 1093e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture1); 1094e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture1)"); 1095e5c31af7Sopenharmony_ci setTextureState(gl, m_target, m_textureState1); 1096e5c31af7Sopenharmony_ci 1097e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture2); 1098e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture2)"); 1099e5c31af7Sopenharmony_ci setTextureState(gl, m_target, m_textureState2); 1100e5c31af7Sopenharmony_ci 1101e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE0); 1102e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture(GL_TEXTURE0)"); 1103e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture1); 1104e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture1)"); 1105e5c31af7Sopenharmony_ci 1106e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE1); 1107e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture(GL_TEXTURE1)"); 1108e5c31af7Sopenharmony_ci gl.bindTexture(m_target, texture2); 1109e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, texture2)"); 1110e5c31af7Sopenharmony_ci 1111e5c31af7Sopenharmony_ci // Render using sampler 1112e5c31af7Sopenharmony_ci render(); 1113e5c31af7Sopenharmony_ci glu::readPixels(m_renderCtx, x, y, samplerResult.getAccess()); 1114e5c31af7Sopenharmony_ci 1115e5c31af7Sopenharmony_ci gl.bindSampler(0, 0); 1116e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindSampler(0, 0)"); 1117e5c31af7Sopenharmony_ci gl.bindSampler(1, 0); 1118e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindSampler(1, 0)"); 1119e5c31af7Sopenharmony_ci 1120e5c31af7Sopenharmony_ci render(); 1121e5c31af7Sopenharmony_ci glu::readPixels(m_renderCtx, x, y, textureResult.getAccess()); 1122e5c31af7Sopenharmony_ci 1123e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE0); 1124e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture(GL_TEXTURE0)"); 1125e5c31af7Sopenharmony_ci gl.bindTexture(m_target, 0); 1126e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, 0)"); 1127e5c31af7Sopenharmony_ci 1128e5c31af7Sopenharmony_ci gl.activeTexture(GL_TEXTURE1); 1129e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glActiveTexture(GL_TEXTURE1)"); 1130e5c31af7Sopenharmony_ci gl.bindTexture(m_target, 0); 1131e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture(m_target, 0)"); 1132e5c31af7Sopenharmony_ci 1133e5c31af7Sopenharmony_ci gl.deleteSamplers(1, &sampler); 1134e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteSamplers(1, &sampler)"); 1135e5c31af7Sopenharmony_ci gl.deleteTextures(1, &texture1); 1136e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteTextures(1, &texture1)"); 1137e5c31af7Sopenharmony_ci gl.deleteTextures(1, &texture2); 1138e5c31af7Sopenharmony_ci GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteTextures(1, &texture2)"); 1139e5c31af7Sopenharmony_ci} 1140e5c31af7Sopenharmony_ci 1141e5c31af7Sopenharmony_citcu::TestCase::IterateResult MultiTextureSamplerTest::iterate (void) 1142e5c31af7Sopenharmony_ci{ 1143e5c31af7Sopenharmony_ci tcu::TestLog& log = m_testCtx.getLog(); 1144e5c31af7Sopenharmony_ci 1145e5c31af7Sopenharmony_ci tcu::Surface textureRef(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 1146e5c31af7Sopenharmony_ci tcu::Surface samplerRef(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 1147e5c31af7Sopenharmony_ci 1148e5c31af7Sopenharmony_ci tcu::Surface textureResult(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 1149e5c31af7Sopenharmony_ci tcu::Surface samplerResult(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); 1150e5c31af7Sopenharmony_ci 1151e5c31af7Sopenharmony_ci int x = m_random.getInt(0, m_renderCtx.getRenderTarget().getWidth() - VIEWPORT_WIDTH); 1152e5c31af7Sopenharmony_ci int y = m_random.getInt(0, m_renderCtx.getRenderTarget().getHeight() - VIEWPORT_HEIGHT); 1153e5c31af7Sopenharmony_ci 1154e5c31af7Sopenharmony_ci renderReferences(textureRef, samplerRef, x, y); 1155e5c31af7Sopenharmony_ci renderResults(textureResult, samplerResult, x, y); 1156e5c31af7Sopenharmony_ci 1157e5c31af7Sopenharmony_ci bool isOk = pixelThresholdCompare (log, "Sampler render result", "Result from rendering with sampler", samplerRef, samplerResult, tcu::RGBA(0, 0, 0, 0), tcu::COMPARE_LOG_RESULT); 1158e5c31af7Sopenharmony_ci 1159e5c31af7Sopenharmony_ci if (!pixelThresholdCompare (log, "Texture render result", "Result from rendering with texture state", textureRef, textureResult, tcu::RGBA(0, 0, 0, 0), tcu::COMPARE_LOG_RESULT)) 1160e5c31af7Sopenharmony_ci isOk = false; 1161e5c31af7Sopenharmony_ci 1162e5c31af7Sopenharmony_ci if (!isOk) 1163e5c31af7Sopenharmony_ci { 1164e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 1165e5c31af7Sopenharmony_ci return STOP; 1166e5c31af7Sopenharmony_ci } 1167e5c31af7Sopenharmony_ci 1168e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 1169e5c31af7Sopenharmony_ci return STOP; 1170e5c31af7Sopenharmony_ci} 1171e5c31af7Sopenharmony_ci 1172e5c31af7Sopenharmony_ci 1173e5c31af7Sopenharmony_ci} // gls 1174e5c31af7Sopenharmony_ci} // deqp 1175