Kai Ninomiya | 02f075c | 2016-12-22 14:55:46 -0800 | [diff] [blame^] | 1 | // |
| 2 | // Copyright 2016 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // DXTSRGBCompressedTextureTest.cpp |
| 7 | // Tests for sRGB DXT textures (GL_EXT_texture_compression_s3tc_srgb) |
| 8 | // |
| 9 | |
| 10 | #include "test_utils/ANGLETest.h" |
| 11 | #include "test_utils/gl_raii.h" |
| 12 | |
| 13 | #include "media/pixel.inl" |
| 14 | |
| 15 | #include "DXTSRGBCompressedTextureTestData.inl" |
| 16 | |
| 17 | using namespace angle; |
| 18 | |
| 19 | static constexpr int kWindowSize = 64; |
| 20 | |
| 21 | class DXTSRGBCompressedTextureTest : public ANGLETest |
| 22 | { |
| 23 | protected: |
| 24 | DXTSRGBCompressedTextureTest() |
| 25 | { |
| 26 | setWindowWidth(kWindowSize); |
| 27 | setWindowHeight(kWindowSize); |
| 28 | setConfigRedBits(8); |
| 29 | setConfigGreenBits(8); |
| 30 | setConfigBlueBits(8); |
| 31 | setConfigAlphaBits(8); |
| 32 | } |
| 33 | |
| 34 | void SetUp() override |
| 35 | { |
| 36 | ANGLETest::SetUp(); |
| 37 | |
| 38 | const std::string vsSource = std::string( |
| 39 | "precision highp float;\n" |
| 40 | "attribute vec4 position;\n" |
| 41 | "varying vec2 texcoord;\n" |
| 42 | "void main() {\n" |
| 43 | " gl_Position = position;\n" |
| 44 | " texcoord = (position.xy * 0.5) + 0.5;\n" |
| 45 | " texcoord.y = 1.0 - texcoord.y;\n" |
| 46 | "}"); |
| 47 | |
| 48 | const std::string textureFSSource = std::string( |
| 49 | "precision highp float;\n" |
| 50 | "uniform sampler2D tex;\n" |
| 51 | "varying vec2 texcoord;\n" |
| 52 | "void main() {\n" |
| 53 | " gl_FragColor = texture2D(tex, texcoord);\n" |
| 54 | "}\n"); |
| 55 | |
| 56 | mTextureProgram = CompileProgram(vsSource, textureFSSource); |
| 57 | ASSERT_NE(0u, mTextureProgram); |
| 58 | |
| 59 | mTextureUniformLocation = glGetUniformLocation(mTextureProgram, "tex"); |
| 60 | ASSERT_NE(-1, mTextureUniformLocation); |
| 61 | |
| 62 | ASSERT_GL_NO_ERROR(); |
| 63 | } |
| 64 | |
| 65 | void TearDown() override |
| 66 | { |
| 67 | glDeleteProgram(mTextureProgram); |
| 68 | |
| 69 | ANGLETest::TearDown(); |
| 70 | } |
| 71 | |
| 72 | void runTestChecks(const TestCase &test) |
| 73 | { |
| 74 | GLColor actual[kWindowSize * kWindowSize] = {0}; |
| 75 | drawQuad(mTextureProgram, "position", 0.5f); |
| 76 | ASSERT_GL_NO_ERROR(); |
| 77 | glReadPixels(0, 0, kWindowSize, kWindowSize, GL_RGBA, GL_UNSIGNED_BYTE, |
| 78 | reinterpret_cast<void *>(actual)); |
| 79 | ASSERT_GL_NO_ERROR(); |
| 80 | for (GLsizei y = 0; y < test.height; ++y) |
| 81 | { |
| 82 | for (GLsizei x = 0; x < test.width; ++x) |
| 83 | { |
| 84 | GLColor exp = reinterpret_cast<const GLColor *>(test.expected)[y * test.width + x]; |
| 85 | size_t x_actual = (x * kWindowSize + kWindowSize / 2) / test.width; |
| 86 | size_t y_actual = |
| 87 | ((test.height - y - 1) * kWindowSize + kWindowSize / 2) / test.height; |
| 88 | GLColor act = actual[y_actual * kWindowSize + x_actual]; |
| 89 | EXPECT_COLOR_NEAR(exp, act, 2.0); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void runTest(GLenum format) |
| 95 | { |
| 96 | if (!extensionEnabled("GL_EXT_texture_compression_s3tc_srgb")) |
| 97 | { |
| 98 | std::cout |
| 99 | << "Test skipped because GL_EXT_texture_compression_s3tc_srgb is not available." |
| 100 | << std::endl; |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | const TestCase &test = kTests.at(format); |
| 105 | |
| 106 | GLTexture texture; |
| 107 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 108 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 109 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 110 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 111 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 112 | |
| 113 | glUseProgram(mTextureProgram); |
| 114 | glUniform1i(mTextureUniformLocation, 0); |
| 115 | ASSERT_GL_NO_ERROR(); |
| 116 | |
| 117 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, test.width, test.height, 0, test.dataSize, |
| 118 | test.data); |
| 119 | ASSERT_GL_NO_ERROR() << "glCompressedTexImage2D(format=" << format << ")"; |
| 120 | runTestChecks(test); |
| 121 | |
| 122 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, test.width, test.height, 0, test.dataSize, |
| 123 | nullptr); |
| 124 | ASSERT_GL_NO_ERROR() << "glCompressedTexImage2D(format=" << format << ", data=null)"; |
| 125 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, test.width, test.height, format, |
| 126 | test.dataSize, test.data); |
| 127 | ASSERT_GL_NO_ERROR() << "glCompressedTexSubImage2D(format=" << format << ")"; |
| 128 | runTestChecks(test); |
| 129 | |
| 130 | ASSERT_GL_NO_ERROR(); |
| 131 | } |
| 132 | |
| 133 | GLuint mTextureProgram = 0; |
| 134 | GLint mTextureUniformLocation = -1; |
| 135 | }; |
| 136 | |
| 137 | // Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_S3TC_DXT1 |
| 138 | TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBDXT1) |
| 139 | { |
| 140 | runTest(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT); |
| 141 | } |
| 142 | |
| 143 | // Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_ALPHA_S3TC_DXT1 |
| 144 | TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBADXT1) |
| 145 | { |
| 146 | runTest(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT); |
| 147 | } |
| 148 | |
| 149 | // Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_ALPHA_S3TC_DXT3 |
| 150 | TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBADXT3) |
| 151 | { |
| 152 | runTest(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT); |
| 153 | } |
| 154 | |
| 155 | // Test correct decompression of 8x8 textures (four 4x4 blocks) of SRGB_ALPHA_S3TC_DXT5 |
| 156 | TEST_P(DXTSRGBCompressedTextureTest, Decompression8x8RGBADXT5) |
| 157 | { |
| 158 | runTest(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT); |
| 159 | } |
| 160 | |
| 161 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 162 | // tests should be run against. |
| 163 | ANGLE_INSTANTIATE_TEST(DXTSRGBCompressedTextureTest, |
| 164 | ES2_D3D11(), |
| 165 | ES2_D3D11_FL9_3(), |
| 166 | ES3_D3D11(), |
| 167 | ES2_OPENGL(), |
| 168 | ES3_OPENGL(), |
| 169 | ES2_OPENGLES(), |
| 170 | ES3_OPENGLES()); |