Hash :
b3ab67d3
        
        Author :
  
        
        Date :
2024-03-14T15:06:02
        
      
tests: Remove unnecessary .get() from RAII objects Bug: chromium:40942995 Change-Id: I82509869bce3ad8f51811188fe04267f2de04786 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5370904 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DXTSRGBCompressedTextureTest.cpp
//   Tests for sRGB DXT textures (GL_EXT_texture_compression_s3tc_srgb)
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "media/pixel.inc"
#include "DXTSRGBCompressedTextureTestData.inl"
using namespace angle;
static constexpr int kWindowSize = 64;
class DXTSRGBCompressedTextureTest : public ANGLETest<>
{
  protected:
    DXTSRGBCompressedTextureTest()
    {
        setWindowWidth(kWindowSize);
        setWindowHeight(kWindowSize);
        setConfigRedBits(8);
        setConfigGreenBits(8);
        setConfigBlueBits(8);
        setConfigAlphaBits(8);
    }
    void testSetUp() override
    {
        constexpr char kVS[] =
            "precision highp float;\n"
            "attribute vec4 position;\n"
            "varying vec2 texcoord;\n"
            "void main() {\n"
            "    gl_Position = position;\n"
            "    texcoord = (position.xy * 0.5) + 0.5;\n"
            "    texcoord.y = 1.0 - texcoord.y;\n"
            "}";
        constexpr char kFS[] =
            "precision highp float;\n"
            "uniform sampler2D tex;\n"
            "varying vec2 texcoord;\n"
            "void main() {\n"
            "    gl_FragColor = texture2D(tex, texcoord);\n"
            "}\n";
        mTextureProgram = CompileProgram(kVS, kFS);
        ASSERT_NE(0u, mTextureProgram);
        mTextureUniformLocation = glGetUniformLocation(mTextureProgram, "tex");
        ASSERT_NE(-1, mTextureUniformLocation);
        ASSERT_GL_NO_ERROR();
    }
    void testTearDown() override { glDeleteProgram(mTextureProgram); }
    void runTestChecks(const TestCase &test)
    {
        GLColor actual[kWindowSize * kWindowSize] = {0};
        drawQuad(mTextureProgram, "position", 0.5f);
        ASSERT_GL_NO_ERROR();
        glReadPixels(0, 0, kWindowSize, kWindowSize, GL_RGBA, GL_UNSIGNED_BYTE,
                     reinterpret_cast<void *>(actual));
        ASSERT_GL_NO_ERROR();
        for (GLsizei y = 0; y < test.height; ++y)
        {
            for (GLsizei x = 0; x < test.width; ++x)
            {
                GLColor exp = reinterpret_cast<const GLColor *>(test.expected)[y * test.width + x];
                size_t x_actual = (x * kWindowSize + kWindowSize / 2) / test.width;
                size_t y_actual =
                    ((test.height - y - 1) * kWindowSize + kWindowSize / 2) / test.height;
                GLColor act = actual[y_actual * kWindowSize + x_actual];
                EXPECT_COLOR_NEAR(exp, act, 2.0);
            }
        }
    }
    void runTest(GLenum format)
    {
        ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_compression_s3tc_srgb"));
        const TestCase &test = kTests.at(format);
        GLTexture texture;
        glBindTexture(GL_TEXTURE_2D, texture);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glUseProgram(mTextureProgram);
        glUniform1i(mTextureUniformLocation, 0);
        ASSERT_GL_NO_ERROR();
        glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, test.width, test.height, 0, test.dataSize,
                               test.data);
        ASSERT_GL_NO_ERROR() << "glCompressedTexImage2D(format=" << format << ")";
        runTestChecks(test);
        glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, test.width, test.height, 0, test.dataSize,
                               nullptr);
        ASSERT_GL_NO_ERROR() << "glCompressedTexImage2D(format=" << format << ", data=null)";
        glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, test.width, test.height, format,
                                  test.dataSize, test.data);
        ASSERT_GL_NO_ERROR() << "glCompressedTexSubImage2D(format=" << format << ")";
        runTestChecks(test);
        ASSERT_GL_NO_ERROR();
    }
    GLuint mTextureProgram        = 0;
    GLint mTextureUniformLocation = -1;
};
// Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_S3TC_DXT1
TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBDXT1)
{
    runTest(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT);
}
// Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_ALPHA_S3TC_DXT1
TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBADXT1)
{
    runTest(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT);
}
// Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_ALPHA_S3TC_DXT3
TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBADXT3)
{
    runTest(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT);
}
// Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_ALPHA_S3TC_DXT5
TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBADXT5)
{
    runTest(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(DXTSRGBCompressedTextureTest);