Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 1 | #include "ANGLETest.h" |
Geoff Lang | d701ea1 | 2014-01-10 15:53:35 -0500 | [diff] [blame] | 2 | #include "media/pixel.inl" |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 3 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 4 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 5 | typedef ::testing::Types<TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes; |
| 6 | TYPED_TEST_CASE(CompressedTextureTest, TestFixtureTypes); |
| 7 | |
| 8 | template<typename T> |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 9 | class CompressedTextureTest : public ANGLETest |
| 10 | { |
| 11 | protected: |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 12 | CompressedTextureTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer()) |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 13 | { |
| 14 | setWindowWidth(512); |
| 15 | setWindowHeight(512); |
| 16 | setConfigRedBits(8); |
| 17 | setConfigGreenBits(8); |
| 18 | setConfigBlueBits(8); |
| 19 | setConfigAlphaBits(8); |
| 20 | } |
| 21 | |
| 22 | virtual void SetUp() |
| 23 | { |
| 24 | ANGLETest::SetUp(); |
| 25 | |
| 26 | const std::string vsSource = SHADER_SOURCE |
| 27 | ( |
| 28 | precision highp float; |
| 29 | attribute vec4 position; |
| 30 | varying vec2 texcoord; |
| 31 | |
| 32 | void main() |
| 33 | { |
| 34 | gl_Position = position; |
| 35 | texcoord = (position.xy * 0.5) + 0.5; |
| 36 | texcoord.y = 1.0 - texcoord.y; |
| 37 | } |
| 38 | ); |
| 39 | |
| 40 | const std::string textureFSSource = SHADER_SOURCE |
| 41 | ( |
| 42 | precision highp float; |
| 43 | uniform sampler2D tex; |
| 44 | varying vec2 texcoord; |
| 45 | |
| 46 | void main() |
| 47 | { |
| 48 | gl_FragColor = texture2D(tex, texcoord); |
| 49 | } |
| 50 | ); |
| 51 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 52 | mTextureProgram = CompileProgram(vsSource, textureFSSource); |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 53 | if (mTextureProgram == 0) |
| 54 | { |
| 55 | FAIL() << "shader compilation failed."; |
| 56 | } |
| 57 | |
| 58 | mTextureUniformLocation = glGetUniformLocation(mTextureProgram, "tex"); |
| 59 | |
| 60 | ASSERT_GL_NO_ERROR(); |
| 61 | } |
| 62 | |
| 63 | virtual void TearDown() |
| 64 | { |
| 65 | glDeleteProgram(mTextureProgram); |
| 66 | |
| 67 | ANGLETest::TearDown(); |
| 68 | } |
| 69 | |
| 70 | GLuint mTextureProgram; |
| 71 | GLint mTextureUniformLocation; |
| 72 | }; |
| 73 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 74 | TYPED_TEST(CompressedTextureTest, CompressedTexImage) |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 75 | { |
| 76 | if (getClientVersion() < 3 && !extensionEnabled("GL_EXT_texture_compression_dxt1")) |
| 77 | { |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | GLuint texture; |
| 82 | glGenTextures(1, &texture); |
| 83 | glBindTexture(GL_TEXTURE_2D, texture); |
| 84 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 85 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 86 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 87 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 88 | |
Geoff Lang | d701ea1 | 2014-01-10 15:53:35 -0500 | [diff] [blame] | 89 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_width, pixel_0_height, 0, pixel_0_size, pixel_0_data); |
| 90 | glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_1_width, pixel_1_height, 0, pixel_1_size, pixel_1_data); |
| 91 | glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_2_width, pixel_2_height, 0, pixel_2_size, pixel_2_data); |
| 92 | glCompressedTexImage2D(GL_TEXTURE_2D, 3, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_3_width, pixel_3_height, 0, pixel_3_size, pixel_3_data); |
| 93 | glCompressedTexImage2D(GL_TEXTURE_2D, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_4_width, pixel_4_height, 0, pixel_4_size, pixel_4_data); |
| 94 | glCompressedTexImage2D(GL_TEXTURE_2D, 5, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_5_width, pixel_5_height, 0, pixel_5_size, pixel_5_data); |
| 95 | glCompressedTexImage2D(GL_TEXTURE_2D, 6, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_6_width, pixel_6_height, 0, pixel_6_size, pixel_6_data); |
| 96 | glCompressedTexImage2D(GL_TEXTURE_2D, 7, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_7_width, pixel_7_height, 0, pixel_7_size, pixel_7_data); |
| 97 | glCompressedTexImage2D(GL_TEXTURE_2D, 8, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_8_width, pixel_8_height, 0, pixel_8_size, pixel_8_data); |
| 98 | glCompressedTexImage2D(GL_TEXTURE_2D, 9, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_9_width, pixel_9_height, 0, pixel_9_size, pixel_9_data); |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 99 | |
| 100 | EXPECT_GL_NO_ERROR(); |
| 101 | |
| 102 | glUseProgram(mTextureProgram); |
| 103 | glUniform1i(mTextureUniformLocation, 0); |
| 104 | |
| 105 | drawQuad(mTextureProgram, "position", 0.5f); |
| 106 | |
| 107 | EXPECT_GL_NO_ERROR(); |
| 108 | |
| 109 | glDeleteTextures(1, &texture); |
| 110 | |
| 111 | EXPECT_GL_NO_ERROR(); |
| 112 | } |
| 113 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 114 | TYPED_TEST(CompressedTextureTest, CompressedTexStorage) |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 115 | { |
| 116 | if (getClientVersion() < 3 && !extensionEnabled("GL_EXT_texture_compression_dxt1")) |
| 117 | { |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | if (getClientVersion() < 3 && (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8"))) |
| 122 | { |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | GLuint texture; |
| 127 | glGenTextures(1, &texture); |
| 128 | glBindTexture(GL_TEXTURE_2D, texture); |
| 129 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 130 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 131 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 132 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 133 | |
| 134 | if (getClientVersion() < 3) |
| 135 | { |
Geoff Lang | a836e48 | 2014-04-28 10:08:27 -0400 | [diff] [blame] | 136 | glTexStorage2DEXT(GL_TEXTURE_2D, pixel_levels, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_width, pixel_0_height); |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 137 | } |
| 138 | else |
| 139 | { |
Geoff Lang | a836e48 | 2014-04-28 10:08:27 -0400 | [diff] [blame] | 140 | glTexStorage2D(GL_TEXTURE_2D, pixel_levels, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_width, pixel_0_height); |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 141 | } |
| 142 | EXPECT_GL_NO_ERROR(); |
| 143 | |
Geoff Lang | d701ea1 | 2014-01-10 15:53:35 -0500 | [diff] [blame] | 144 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, pixel_0_width, pixel_0_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_0_size, pixel_0_data); |
Geoff Lang | a836e48 | 2014-04-28 10:08:27 -0400 | [diff] [blame] | 145 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, pixel_1_width, pixel_1_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_1_size, pixel_1_data); |
| 146 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, pixel_2_width, pixel_2_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_2_size, pixel_2_data); |
| 147 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 3, 0, 0, pixel_3_width, pixel_3_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_3_size, pixel_3_data); |
| 148 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 4, 0, 0, pixel_4_width, pixel_4_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_4_size, pixel_4_data); |
| 149 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 5, 0, 0, pixel_5_width, pixel_5_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_5_size, pixel_5_data); |
| 150 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 6, 0, 0, pixel_6_width, pixel_6_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_6_size, pixel_6_data); |
| 151 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 7, 0, 0, pixel_7_width, pixel_7_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_7_size, pixel_7_data); |
| 152 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 8, 0, 0, pixel_8_width, pixel_8_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_8_size, pixel_8_data); |
| 153 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 9, 0, 0, pixel_9_width, pixel_9_height, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixel_9_size, pixel_9_data); |
Geoff Lang | 066230a | 2013-10-30 12:59:30 -0400 | [diff] [blame] | 154 | |
| 155 | EXPECT_GL_NO_ERROR(); |
| 156 | |
| 157 | glUseProgram(mTextureProgram); |
| 158 | glUniform1i(mTextureUniformLocation, 0); |
| 159 | |
| 160 | drawQuad(mTextureProgram, "position", 0.5f); |
| 161 | |
| 162 | EXPECT_GL_NO_ERROR(); |
| 163 | |
| 164 | glDeleteTextures(1, &texture); |
| 165 | |
| 166 | EXPECT_GL_NO_ERROR(); |
| 167 | } |