13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 3.0 Module 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Texture swizzle tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fTextureSwizzleTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsTextureTestUtil.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace deqp::gls; 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace deqp::gls::TextureTestUtil; 47c4eb6f3271a0bcd54835e666e836e3e72beebbd2Peter Siketusing namespace glu::TextureTestUtil; 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic int swizzle (const tcu::RGBA& c, deUint32 swz) 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (swz) 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_RED: return c.getRed(); 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_GREEN: return c.getGreen(); 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_BLUE: return c.getBlue(); 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_ALPHA: return c.getAlpha(); 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_ZERO: return 0; 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_ONE: return (1<<8)-1; 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 0; 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void swizzle (tcu::Surface& surface, deUint32 swzR, deUint32 swzG, deUint32 swzB, deUint32 swzA) 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < surface.getHeight(); y++) 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < surface.getWidth(); x++) 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA p = surface.getPixel(x, y); 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry surface.setPixel(x, y, tcu::RGBA(swizzle(p, swzR), swizzle(p, swzG), swizzle(p, swzB), swizzle(p, swzA))); 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Texture2DSwizzleCase : public TestCase 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DSwizzleCase (Context& context, const char* name, const char* description, deUint32 internalFormat, deUint32 format, deUint32 dataType, deUint32 swizzleR, deUint32 swizzleG, deUint32 swizzleB, deUint32 swizzleA); 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Texture2DSwizzleCase (void); 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DSwizzleCase (const Texture2DSwizzleCase& other); 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DSwizzleCase& operator= (const Texture2DSwizzleCase& other); 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_internalFormat; 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_format; 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_dataType; 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_swizzleR; 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_swizzleG; 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_swizzleB; 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_swizzleA; 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::Texture2D* m_texture; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureRenderer m_renderer; 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DSwizzleCase::Texture2DSwizzleCase (Context& context, const char* name, const char* description, deUint32 internalFormat, deUint32 format, deUint32 dataType, deUint32 swizzleR, deUint32 swizzleG, deUint32 swizzleB, deUint32 swizzleA) 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, description) 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_internalFormat (internalFormat) 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_dataType (dataType) 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_swizzleR (swizzleR) 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_swizzleG (swizzleG) 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_swizzleB (swizzleB) 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_swizzleA (swizzleA) 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_texture (DE_NULL) 113469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry , m_renderer (context.getRenderContext(), context.getTestContext().getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP) 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DSwizzleCase::~Texture2DSwizzleCase (void) 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DSwizzleCase::init (void) 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = de::min(128, m_context.getRenderContext().getRenderTarget().getWidth()); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = de::min(128, m_context.getRenderContext().getRenderTarget().getHeight()); 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture = (m_internalFormat == m_format) ? new glu::Texture2D(m_context.getRenderContext(), m_format, m_dataType, width, height) 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : new glu::Texture2D(m_context.getRenderContext(), m_internalFormat, width, height); 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureFormatInfo spec = tcu::getTextureFormatInfo(m_texture->getRefTexture().getFormat()); 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill level 0. 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture->getRefTexture().allocLevel(0); 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithComponentGradients(m_texture->getRefTexture().getLevel(0), spec.valueMin, spec.valueMax); 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DSwizzleCase::deinit (void) 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_texture; 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture = DE_NULL; 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.clear(); 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DSwizzleCase::IterateResult Texture2DSwizzleCase::iterate (void) 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RandomViewport viewport (m_context.getRenderContext().getRenderTarget(), m_texture->getRefTexture().getWidth(), m_texture->getRefTexture().getHeight(), deStringHash(getName())); 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface renderedFrame (viewport.width, viewport.height); 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface referenceFrame (viewport.width, viewport.height); 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA threshold = m_context.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1); 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<float> texCoord; 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ReferenceParams renderParams (TEXTURETYPE_2D); 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureFormatInfo spec = tcu::getTextureFormatInfo(m_texture->getRefTexture().getFormat()); 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderParams.samplerType = getSamplerType(m_texture->getRefTexture().getFormat()); 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderParams.sampler = tcu::Sampler(tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::NEAREST, tcu::Sampler::NEAREST); 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderParams.colorScale = spec.lookupScale; 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderParams.colorBias = spec.lookupBias; 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeQuadTexCoord2D(texCoord, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f)); 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup base viewport. 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height); 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload texture data to GL. 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture->upload(); 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Bind to unit 0. 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture()); 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup nearest neighbor filtering and clamp-to-edge. 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup texture swizzle. 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, m_swizzleR); 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, m_swizzleG); 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, m_swizzleB); 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, m_swizzleA); 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state"); 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Draw. 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.renderQuad(0, &texCoord[0], renderParams); 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_context.getRenderContext(), viewport.x, viewport.y, renderedFrame.getAccess()); 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute reference 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::PixelFormat pixelFormat = m_context.getRenderTarget().getPixelFormat(); 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Do initial rendering to RGBA8 in order to keep alpha 197c4eb6f3271a0bcd54835e666e836e3e72beebbd2Peter Siket sampleTexture(tcu::SurfaceAccess(referenceFrame, tcu::PixelFormat(8,8,8,8)), m_texture->getRefTexture(), &texCoord[0], renderParams); 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Swizzle channels 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry swizzle(referenceFrame, m_swizzleR, m_swizzleG, m_swizzleB, m_swizzleA); 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Convert to destination format 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (pixelFormat != tcu::PixelFormat(8,8,8,8)) 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < referenceFrame.getHeight(); y++) 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < referenceFrame.getWidth(); x++) 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA p = referenceFrame.getPixel(x, y); 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry referenceFrame.setPixel(x, y, pixelFormat.convertColor(p)); 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compare and log. 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold); 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk ? "Pass" : "Image comparison failed"); 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2253c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureSwizzleTests::TextureSwizzleTests (Context& context) 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "swizzle", "Texture Swizzle Tests") 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2303c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureSwizzleTests::~TextureSwizzleTests (void) 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureSwizzleTests::init (void) 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 internalFormat; 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format; 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 dataType; 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } formats[] = 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "alpha", GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE }, 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "luminance", GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE }, 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "luminance_alpha", GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE }, 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "red", GL_R8, GL_RED, GL_UNSIGNED_BYTE }, 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "rg", GL_RG8, GL_RG, GL_UNSIGNED_BYTE }, 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "rgb", GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE }, 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "rgba", GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE } 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 channel; 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } channels[] = 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "r", GL_TEXTURE_SWIZZLE_R }, 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "g", GL_TEXTURE_SWIZZLE_G }, 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "b", GL_TEXTURE_SWIZZLE_B }, 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "a", GL_TEXTURE_SWIZZLE_A } 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swizzle; 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } swizzles[] = 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "red", GL_RED }, 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "green", GL_GREEN }, 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "blue", GL_BLUE }, 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "alpha", GL_ALPHA }, 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "zero", GL_ZERO }, 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "one", GL_ONE } 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzR; 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzG; 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzB; 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzA; 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } swizzleCases[] = 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "all_red", GL_RED, GL_RED, GL_RED, GL_RED }, 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "all_green", GL_GREEN, GL_GREEN, GL_GREEN, GL_GREEN }, 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "all_blue", GL_BLUE, GL_BLUE, GL_BLUE, GL_BLUE }, 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "all_alpha", GL_ALPHA, GL_ALPHA, GL_ALPHA, GL_ALPHA }, 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "all_zero", GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO }, 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "all_one", GL_ONE, GL_ONE, GL_ONE, GL_ONE }, 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "bgra", GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA }, 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "abgr", GL_ALPHA, GL_BLUE, GL_GREEN, GL_RED }, 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "one_one_red_green", GL_ONE, GL_ONE, GL_RED, GL_GREEN } 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const deUint32 defaultSwizzles[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // All swizzles applied to each channel. 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* singleChannelGroup = new tcu::TestCaseGroup(m_testCtx, "single_channel", "Single-channel swizzle"); 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(singleChannelGroup); 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int chanNdx = 0; chanNdx < DE_LENGTH_OF_ARRAY(channels); chanNdx++) 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int swzNdx = 0; swzNdx < DE_LENGTH_OF_ARRAY(swizzles); swzNdx++) 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (swizzles[swzNdx].swizzle == defaultSwizzles[chanNdx]) 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; // No need to test default case. 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry string name = string(channels[chanNdx].name) + "_" + swizzles[swzNdx].name; 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swz = swizzles[swzNdx].swizzle; 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzR = (chanNdx == 0) ? swz : defaultSwizzles[0]; 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzG = (chanNdx == 1) ? swz : defaultSwizzles[1]; 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzB = (chanNdx == 2) ? swz : defaultSwizzles[2]; 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzA = (chanNdx == 3) ? swz : defaultSwizzles[3]; 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry singleChannelGroup->addChild(new Texture2DSwizzleCase(m_context, name.c_str(), "Single-channel swizzle", GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, swzR, swzG, swzB, swzA)); 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Swizzles for all formats. 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* multiChannelGroup = new tcu::TestCaseGroup(m_testCtx, "multi_channel", "Multi-channel swizzle"); 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(multiChannelGroup); 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int fmtNdx = 0; fmtNdx < DE_LENGTH_OF_ARRAY(formats); fmtNdx++) 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(swizzleCases); caseNdx++) 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry string name = string(formats[fmtNdx].name) + "_" + swizzleCases[caseNdx].name; 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzR = swizzleCases[caseNdx].swzR; 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzG = swizzleCases[caseNdx].swzG; 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzB = swizzleCases[caseNdx].swzB; 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 swzA = swizzleCases[caseNdx].swzA; 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 intFormat = formats[fmtNdx].internalFormat; 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format = formats[fmtNdx].format; 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 dataType = formats[fmtNdx].dataType; 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry multiChannelGroup->addChild(new Texture2DSwizzleCase(m_context, name.c_str(), "Multi-channel swizzle", intFormat, format, dataType, swzR, swzG, swzB, swzA)); 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 346