Path: blob/main_old/src/tests/gl_tests/DXTSRGBCompressedTextureTest.cpp
1693 views
//1// Copyright 2016 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// DXTSRGBCompressedTextureTest.cpp6// Tests for sRGB DXT textures (GL_EXT_texture_compression_s3tc_srgb)7//89#include "test_utils/ANGLETest.h"10#include "test_utils/gl_raii.h"1112#include "media/pixel.inc"1314#include "DXTSRGBCompressedTextureTestData.inl"1516using namespace angle;1718static constexpr int kWindowSize = 64;1920class DXTSRGBCompressedTextureTest : public ANGLETest21{22protected:23DXTSRGBCompressedTextureTest()24{25setWindowWidth(kWindowSize);26setWindowHeight(kWindowSize);27setConfigRedBits(8);28setConfigGreenBits(8);29setConfigBlueBits(8);30setConfigAlphaBits(8);31}3233void testSetUp() override34{35constexpr char kVS[] =36"precision highp float;\n"37"attribute vec4 position;\n"38"varying vec2 texcoord;\n"39"void main() {\n"40" gl_Position = position;\n"41" texcoord = (position.xy * 0.5) + 0.5;\n"42" texcoord.y = 1.0 - texcoord.y;\n"43"}";4445constexpr char kFS[] =46"precision highp float;\n"47"uniform sampler2D tex;\n"48"varying vec2 texcoord;\n"49"void main() {\n"50" gl_FragColor = texture2D(tex, texcoord);\n"51"}\n";5253mTextureProgram = CompileProgram(kVS, kFS);54ASSERT_NE(0u, mTextureProgram);5556mTextureUniformLocation = glGetUniformLocation(mTextureProgram, "tex");57ASSERT_NE(-1, mTextureUniformLocation);5859ASSERT_GL_NO_ERROR();60}6162void testTearDown() override { glDeleteProgram(mTextureProgram); }6364void runTestChecks(const TestCase &test)65{66GLColor actual[kWindowSize * kWindowSize] = {0};67drawQuad(mTextureProgram, "position", 0.5f);68ASSERT_GL_NO_ERROR();69glReadPixels(0, 0, kWindowSize, kWindowSize, GL_RGBA, GL_UNSIGNED_BYTE,70reinterpret_cast<void *>(actual));71ASSERT_GL_NO_ERROR();72for (GLsizei y = 0; y < test.height; ++y)73{74for (GLsizei x = 0; x < test.width; ++x)75{76GLColor exp = reinterpret_cast<const GLColor *>(test.expected)[y * test.width + x];77size_t x_actual = (x * kWindowSize + kWindowSize / 2) / test.width;78size_t y_actual =79((test.height - y - 1) * kWindowSize + kWindowSize / 2) / test.height;80GLColor act = actual[y_actual * kWindowSize + x_actual];81EXPECT_COLOR_NEAR(exp, act, 2.0);82}83}84}8586void runTest(GLenum format)87{88ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_compression_s3tc_srgb"));8990const TestCase &test = kTests.at(format);9192GLTexture texture;93glBindTexture(GL_TEXTURE_2D, texture.get());94glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);95glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);96glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);97glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);9899glUseProgram(mTextureProgram);100glUniform1i(mTextureUniformLocation, 0);101ASSERT_GL_NO_ERROR();102103glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, test.width, test.height, 0, test.dataSize,104test.data);105ASSERT_GL_NO_ERROR() << "glCompressedTexImage2D(format=" << format << ")";106runTestChecks(test);107108glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, test.width, test.height, 0, test.dataSize,109nullptr);110ASSERT_GL_NO_ERROR() << "glCompressedTexImage2D(format=" << format << ", data=null)";111glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, test.width, test.height, format,112test.dataSize, test.data);113ASSERT_GL_NO_ERROR() << "glCompressedTexSubImage2D(format=" << format << ")";114runTestChecks(test);115116ASSERT_GL_NO_ERROR();117}118119GLuint mTextureProgram = 0;120GLint mTextureUniformLocation = -1;121};122123// Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_S3TC_DXT1124TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBDXT1)125{126runTest(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT);127}128129// Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_ALPHA_S3TC_DXT1130TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBADXT1)131{132runTest(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT);133}134135// Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_ALPHA_S3TC_DXT3136TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBADXT3)137{138runTest(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT);139}140141// Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_ALPHA_S3TC_DXT5142TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBADXT5)143{144runTest(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT);145}146147// Use this to select which configurations (e.g. which renderer, which GLES major version) these148// tests should be run against.149ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(DXTSRGBCompressedTextureTest);150151152