OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
| 8 #include <stdint.h> |
8 | 9 |
9 #include "base/basictypes.h" | |
10 #include "gpu/command_buffer/tests/gl_manager.h" | 10 #include "gpu/command_buffer/tests/gl_manager.h" |
11 #include "gpu/command_buffer/tests/gl_test_utils.h" | 11 #include "gpu/command_buffer/tests/gl_test_utils.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 #define SHADER(src) #src | 14 #define SHADER(src) #src |
15 | 15 |
16 namespace gpu { | 16 namespace gpu { |
17 | 17 |
18 static const uint16 kRedMask = 0xF800; | 18 static const uint16_t kRedMask = 0xF800; |
19 static const uint16 kGreenMask = 0x07E0; | 19 static const uint16_t kGreenMask = 0x07E0; |
20 static const uint16 kBlueMask = 0x001F; | 20 static const uint16_t kBlueMask = 0x001F; |
21 | 21 |
22 // Color palette in 565 format. | 22 // Color palette in 565 format. |
23 static const uint16 kPalette[] = { | 23 static const uint16_t kPalette[] = { |
24 kGreenMask | kBlueMask, // Cyan. | 24 kGreenMask | kBlueMask, // Cyan. |
25 kBlueMask | kRedMask, // Magenta. | 25 kBlueMask | kRedMask, // Magenta. |
26 kRedMask | kGreenMask, // Yellow. | 26 kRedMask | kGreenMask, // Yellow. |
27 0x0000, // Black. | 27 0x0000, // Black. |
28 kRedMask, // Red. | 28 kRedMask, // Red. |
29 kGreenMask, // Green. | 29 kGreenMask, // Green. |
30 kBlueMask, // Blue. | 30 kBlueMask, // Blue. |
31 0xFFFF, // White. | 31 0xFFFF, // White. |
32 }; | 32 }; |
33 static const unsigned kBlockSize = 4; | 33 static const unsigned kBlockSize = 4; |
34 static const unsigned kPaletteSize = sizeof(kPalette) / sizeof(kPalette[0]); | 34 static const unsigned kPaletteSize = sizeof(kPalette) / sizeof(kPalette[0]); |
35 static const unsigned kTextureWidth = kBlockSize * kPaletteSize; | 35 static const unsigned kTextureWidth = kBlockSize * kPaletteSize; |
36 static const unsigned kTextureHeight = kBlockSize; | 36 static const unsigned kTextureHeight = kBlockSize; |
37 | 37 |
38 static const char* extension(GLenum format) { | 38 static const char* extension(GLenum format) { |
39 switch(format) { | 39 switch(format) { |
40 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: | 40 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
41 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: | 41 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
42 return "GL_EXT_texture_compression_dxt1"; | 42 return "GL_EXT_texture_compression_dxt1"; |
43 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: | 43 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
44 return "GL_CHROMIUM_texture_compression_dxt3"; | 44 return "GL_CHROMIUM_texture_compression_dxt3"; |
45 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: | 45 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
46 return "GL_CHROMIUM_texture_compression_dxt5"; | 46 return "GL_CHROMIUM_texture_compression_dxt5"; |
47 default: | 47 default: |
48 NOTREACHED(); | 48 NOTREACHED(); |
49 } | 49 } |
50 return NULL; | 50 return NULL; |
51 } | 51 } |
52 | 52 |
53 // Index that chooses the given colors (color_0 and color_1), | 53 // Index that chooses the given colors (color_0 and color_1), |
54 // not the interpolated colors (color_2 and color_3). | 54 // not the interpolated colors (color_2 and color_3). |
55 static const uint16 kColor0 = 0x0000; | 55 static const uint16_t kColor0 = 0x0000; |
56 static const uint16 kColor1 = 0x5555; | 56 static const uint16_t kColor1 = 0x5555; |
57 | 57 |
58 static GLuint LoadCompressedTexture(const void* data, | 58 static GLuint LoadCompressedTexture(const void* data, |
59 GLsizeiptr size, | 59 GLsizeiptr size, |
60 GLenum format, | 60 GLenum format, |
61 GLsizei width, | 61 GLsizei width, |
62 GLsizei height) { | 62 GLsizei height) { |
63 GLuint texture; | 63 GLuint texture; |
64 glGenTextures(1, &texture); | 64 glGenTextures(1, &texture); |
65 glBindTexture(GL_TEXTURE_2D, texture); | 65 glBindTexture(GL_TEXTURE_2D, texture); |
66 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 66 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
67 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 67 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
68 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 68 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
69 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 69 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
70 glCompressedTexImage2D( | 70 glCompressedTexImage2D( |
71 GL_TEXTURE_2D, 0, format, width, height, 0, size, data); | 71 GL_TEXTURE_2D, 0, format, width, height, 0, size, data); |
72 return texture; | 72 return texture; |
73 } | 73 } |
74 | 74 |
75 GLuint LoadTextureDXT1(bool alpha) { | 75 GLuint LoadTextureDXT1(bool alpha) { |
76 const unsigned kStride = 4; | 76 const unsigned kStride = 4; |
77 uint16 data[kStride * kPaletteSize]; | 77 uint16_t data[kStride * kPaletteSize]; |
78 for (unsigned i = 0; i < kPaletteSize; ++i) { | 78 for (unsigned i = 0; i < kPaletteSize; ++i) { |
79 // Each iteration defines a 4x4 block of texture. | 79 // Each iteration defines a 4x4 block of texture. |
80 unsigned j = kStride * i; | 80 unsigned j = kStride * i; |
81 data[j++] = kPalette[i]; // color_0. | 81 data[j++] = kPalette[i]; // color_0. |
82 data[j++] = kPalette[i]; // color_1. | 82 data[j++] = kPalette[i]; // color_1. |
83 data[j++] = kColor0; // color index. | 83 data[j++] = kColor0; // color index. |
84 data[j++] = kColor1; // color index. | 84 data[j++] = kColor1; // color index. |
85 } | 85 } |
86 GLenum format = alpha ? | 86 GLenum format = alpha ? |
87 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT : GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | 87 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT : GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
88 return LoadCompressedTexture( | 88 return LoadCompressedTexture( |
89 data, sizeof(data), format, kTextureWidth, kTextureHeight); | 89 data, sizeof(data), format, kTextureWidth, kTextureHeight); |
90 } | 90 } |
91 | 91 |
92 GLuint LoadTextureDXT3() { | 92 GLuint LoadTextureDXT3() { |
93 const unsigned kStride = 8; | 93 const unsigned kStride = 8; |
94 const uint16 kOpaque = 0xFFFF; | 94 const uint16_t kOpaque = 0xFFFF; |
95 uint16 data[kStride * kPaletteSize]; | 95 uint16_t data[kStride * kPaletteSize]; |
96 for (unsigned i = 0; i < kPaletteSize; ++i) { | 96 for (unsigned i = 0; i < kPaletteSize; ++i) { |
97 // Each iteration defines a 4x4 block of texture. | 97 // Each iteration defines a 4x4 block of texture. |
98 unsigned j = kStride * i; | 98 unsigned j = kStride * i; |
99 data[j++] = kOpaque; // alpha row 0. | 99 data[j++] = kOpaque; // alpha row 0. |
100 data[j++] = kOpaque; // alpha row 1. | 100 data[j++] = kOpaque; // alpha row 1. |
101 data[j++] = kOpaque; // alpha row 2. | 101 data[j++] = kOpaque; // alpha row 2. |
102 data[j++] = kOpaque; // alpha row 3. | 102 data[j++] = kOpaque; // alpha row 3. |
103 data[j++] = kPalette[i]; // color_0. | 103 data[j++] = kPalette[i]; // color_0. |
104 data[j++] = kPalette[i]; // color_1. | 104 data[j++] = kPalette[i]; // color_1. |
105 data[j++] = kColor0; // color index. | 105 data[j++] = kColor0; // color index. |
106 data[j++] = kColor1; // color index. | 106 data[j++] = kColor1; // color index. |
107 } | 107 } |
108 return LoadCompressedTexture(data, | 108 return LoadCompressedTexture(data, |
109 sizeof(data), | 109 sizeof(data), |
110 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, | 110 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, |
111 kTextureWidth, | 111 kTextureWidth, |
112 kTextureHeight); | 112 kTextureHeight); |
113 } | 113 } |
114 | 114 |
115 GLuint LoadTextureDXT5() { | 115 GLuint LoadTextureDXT5() { |
116 const unsigned kStride = 8; | 116 const unsigned kStride = 8; |
117 const uint16 kClear = 0x0000; | 117 const uint16_t kClear = 0x0000; |
118 const uint16 kAlpha7 = 0xFFFF; // Opaque alpha index. | 118 const uint16_t kAlpha7 = 0xFFFF; // Opaque alpha index. |
119 uint16 data[kStride * kPaletteSize]; | 119 uint16_t data[kStride * kPaletteSize]; |
120 for (unsigned i = 0; i < kPaletteSize; ++i) { | 120 for (unsigned i = 0; i < kPaletteSize; ++i) { |
121 // Each iteration defines a 4x4 block of texture. | 121 // Each iteration defines a 4x4 block of texture. |
122 unsigned j = kStride * i; | 122 unsigned j = kStride * i; |
123 data[j++] = kClear; // alpha_0 | alpha_1. | 123 data[j++] = kClear; // alpha_0 | alpha_1. |
124 data[j++] = kAlpha7; // alpha index. | 124 data[j++] = kAlpha7; // alpha index. |
125 data[j++] = kAlpha7; // alpha index. | 125 data[j++] = kAlpha7; // alpha index. |
126 data[j++] = kAlpha7; // alpha index. | 126 data[j++] = kAlpha7; // alpha index. |
127 data[j++] = kPalette[i]; // color_0. | 127 data[j++] = kPalette[i]; // color_0. |
128 data[j++] = kPalette[i]; // color_1. | 128 data[j++] = kPalette[i]; // color_1. |
129 data[j++] = kColor0; // color index. | 129 data[j++] = kColor0; // color index. |
130 data[j++] = kColor1; // color index. | 130 data[j++] = kColor1; // color index. |
131 } | 131 } |
132 return LoadCompressedTexture(data, | 132 return LoadCompressedTexture(data, |
133 sizeof(data), | 133 sizeof(data), |
134 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, | 134 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, |
135 kTextureWidth, | 135 kTextureWidth, |
136 kTextureHeight); | 136 kTextureHeight); |
137 } | 137 } |
138 | 138 |
139 static void ToRGB888(uint16 rgb565, uint8 rgb888[]) { | 139 static void ToRGB888(uint16_t rgb565, uint8_t rgb888[]) { |
140 uint8 r5 = (rgb565 & kRedMask) >> 11; | 140 uint8_t r5 = (rgb565 & kRedMask) >> 11; |
141 uint8 g6 = (rgb565 & kGreenMask) >> 5; | 141 uint8_t g6 = (rgb565 & kGreenMask) >> 5; |
142 uint8 b5 = (rgb565 & kBlueMask); | 142 uint8_t b5 = (rgb565 & kBlueMask); |
143 // Replicate upper bits to lower empty bits. | 143 // Replicate upper bits to lower empty bits. |
144 rgb888[0] = (r5 << 3) | (r5 >> 2); | 144 rgb888[0] = (r5 << 3) | (r5 >> 2); |
145 rgb888[1] = (g6 << 2) | (g6 >> 4); | 145 rgb888[1] = (g6 << 2) | (g6 >> 4); |
146 rgb888[2] = (b5 << 3) | (b5 >> 2); | 146 rgb888[2] = (b5 << 3) | (b5 >> 2); |
147 } | 147 } |
148 | 148 |
149 class CompressedTextureTest : public ::testing::TestWithParam<GLenum> { | 149 class CompressedTextureTest : public ::testing::TestWithParam<GLenum> { |
150 protected: | 150 protected: |
151 void SetUp() override { | 151 void SetUp() override { |
152 GLManager::Options options; | 152 GLManager::Options options; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 glActiveTexture(GL_TEXTURE0); | 222 glActiveTexture(GL_TEXTURE0); |
223 glBindTexture(GL_TEXTURE_2D, texture); | 223 glBindTexture(GL_TEXTURE_2D, texture); |
224 glUniform1i(texture_loc, 0); | 224 glUniform1i(texture_loc, 0); |
225 | 225 |
226 // Draw. | 226 // Draw. |
227 glDrawArrays(GL_TRIANGLES, 0, 6); | 227 glDrawArrays(GL_TRIANGLES, 0, 6); |
228 glFlush(); | 228 glFlush(); |
229 | 229 |
230 // Verify results. | 230 // Verify results. |
231 int origin[] = {0, 0}; | 231 int origin[] = {0, 0}; |
232 uint8 expected_rgba[] = {0, 0, 0, 255}; | 232 uint8_t expected_rgba[] = {0, 0, 0, 255}; |
233 for (unsigned i = 0; i < kPaletteSize; ++i) { | 233 for (unsigned i = 0; i < kPaletteSize; ++i) { |
234 origin[0] = kBlockSize * i; | 234 origin[0] = kBlockSize * i; |
235 ToRGB888(kPalette[i], expected_rgba); | 235 ToRGB888(kPalette[i], expected_rgba); |
236 EXPECT_TRUE(GLTestHelper::CheckPixels(origin[0], origin[1], | 236 EXPECT_TRUE(GLTestHelper::CheckPixels(origin[0], origin[1], |
237 kBlockSize, kBlockSize, | 237 kBlockSize, kBlockSize, |
238 0, expected_rgba)); | 238 0, expected_rgba)); |
239 } | 239 } |
240 GLTestHelper::CheckGLError("CompressedTextureTest.Draw", __LINE__); | 240 GLTestHelper::CheckGLError("CompressedTextureTest.Draw", __LINE__); |
241 } | 241 } |
242 | 242 |
243 static const GLenum kFormats[] = { | 243 static const GLenum kFormats[] = { |
244 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | 244 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
245 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, | 245 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, |
246 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, | 246 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, |
247 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT | 247 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT |
248 }; | 248 }; |
249 INSTANTIATE_TEST_CASE_P(Format, | 249 INSTANTIATE_TEST_CASE_P(Format, |
250 CompressedTextureTest, | 250 CompressedTextureTest, |
251 ::testing::ValuesIn(kFormats)); | 251 ::testing::ValuesIn(kFormats)); |
252 | 252 |
253 } // namespace gpu | 253 } // namespace gpu |
OLD | NEW |