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