OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef GL_GLEXT_PROTOTYPES | 5 #ifndef GL_GLEXT_PROTOTYPES |
6 #define GL_GLEXT_PROTOTYPES | 6 #define GL_GLEXT_PROTOTYPES |
7 #endif | 7 #endif |
8 | 8 |
9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 EXPECT_EQ(framebuffer_id_, fb_id); | 69 EXPECT_EQ(framebuffer_id_, fb_id); |
70 | 70 |
71 // Check that FB is complete. | 71 // Check that FB is complete. |
72 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 72 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
73 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 73 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
74 | 74 |
75 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | 75 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
76 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 76 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
77 } | 77 } |
78 | 78 |
| 79 TEST_F(GLCopyTextureCHROMIUMTest, InternalFormat) { |
| 80 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, |
| 81 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; |
| 82 GLint dest_formats[] = {GL_RGB, GL_RGBA}; |
| 83 |
| 84 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) { |
| 85 for (size_t dest_index = 0; dest_index < arraysize(dest_formats); |
| 86 dest_index++) { |
| 87 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 88 glTexImage2D(GL_TEXTURE_2D, |
| 89 0, |
| 90 src_formats[src_index], |
| 91 1, |
| 92 1, |
| 93 0, |
| 94 src_formats[src_index], |
| 95 GL_UNSIGNED_BYTE, |
| 96 NULL); |
| 97 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 98 |
| 99 glCopyTextureCHROMIUM(GL_TEXTURE_2D, |
| 100 textures_[0], |
| 101 textures_[1], |
| 102 0, |
| 103 dest_formats[dest_index], |
| 104 GL_UNSIGNED_BYTE); |
| 105 EXPECT_TRUE(GL_NO_ERROR == glGetError()) << "src_index:" << src_index |
| 106 << " dest_index:" << dest_index; |
| 107 } |
| 108 } |
| 109 } |
| 110 |
| 111 TEST_F(GLCopyTextureCHROMIUMTest, InternalFormatNotSupported) { |
| 112 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 113 glTexImage2D( |
| 114 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 115 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 116 |
| 117 // Check unsupported format reports error. |
| 118 GLint unsupported_dest_formats[] = {GL_ALPHA, GL_LUMINANCE, |
| 119 GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; |
| 120 for (size_t dest_index = 0; dest_index < arraysize(unsupported_dest_formats); |
| 121 dest_index++) { |
| 122 glCopyTextureCHROMIUM(GL_TEXTURE_2D, |
| 123 textures_[0], |
| 124 textures_[1], |
| 125 0, |
| 126 unsupported_dest_formats[dest_index], |
| 127 GL_UNSIGNED_BYTE); |
| 128 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()) |
| 129 << "dest_index:" << dest_index; |
| 130 } |
| 131 } |
| 132 |
| 133 // Test to ensure that the destination texture is redefined if the properties |
| 134 // are different. |
| 135 TEST_F(GLCopyTextureCHROMIUMTest, RedefineDestinationTexture) { |
| 136 uint8 pixels[4 * 4] = {255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u, |
| 137 255u, 0u, 0u, 255u, 255u, 0u, 0u, 255u}; |
| 138 |
| 139 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 140 glTexImage2D( |
| 141 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 142 |
| 143 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 144 glTexImage2D(GL_TEXTURE_2D, |
| 145 0, |
| 146 GL_BGRA_EXT, |
| 147 1, |
| 148 1, |
| 149 0, |
| 150 GL_BGRA_EXT, |
| 151 GL_UNSIGNED_BYTE, |
| 152 pixels); |
| 153 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 154 |
| 155 // GL_INVALID_OPERATION due to "intrinsic format" != "internal format". |
| 156 glTexSubImage2D( |
| 157 GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 158 EXPECT_TRUE(GL_INVALID_OPERATION == glGetError()); |
| 159 // GL_INVALID_VALUE due to bad dimensions. |
| 160 glTexSubImage2D( |
| 161 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); |
| 162 EXPECT_TRUE(GL_INVALID_VALUE == glGetError()); |
| 163 |
| 164 // If the dest texture has different properties, glCopyTextureCHROMIUM() |
| 165 // redefines them. |
| 166 glCopyTextureCHROMIUM( |
| 167 GL_TEXTURE_2D, textures_[0], textures_[1], 0, GL_RGBA, GL_UNSIGNED_BYTE); |
| 168 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 169 |
| 170 // glTexSubImage2D() succeeds because textures_[1] is redefined into 2x2 |
| 171 // dimension and GL_RGBA format. |
| 172 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
| 173 glTexSubImage2D( |
| 174 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 175 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 176 |
| 177 // Check the FB is still bound. |
| 178 GLint value = 0; |
| 179 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); |
| 180 GLuint fb_id = value; |
| 181 EXPECT_EQ(framebuffer_id_, fb_id); |
| 182 |
| 183 // Check that FB is complete. |
| 184 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 185 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 186 |
| 187 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, &pixels[12]); |
| 188 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 189 } |
| 190 |
79 // Test that the extension respects the flip-y pixel storage setting. | 191 // Test that the extension respects the flip-y pixel storage setting. |
80 TEST_F(GLCopyTextureCHROMIUMTest, FlipY) { | 192 TEST_F(GLCopyTextureCHROMIUMTest, FlipY) { |
81 uint8 pixels[2][2][4]; | 193 uint8 pixels[2][2][4]; |
82 for (int x = 0; x < 2; ++x) { | 194 for (int x = 0; x < 2; ++x) { |
83 for (int y = 0; y < 2; ++y) { | 195 for (int y = 0; y < 2; ++y) { |
84 pixels[y][x][0] = x + y; | 196 pixels[y][x][0] = x + y; |
85 pixels[y][x][1] = x + y; | 197 pixels[y][x][1] = x + y; |
86 pixels[y][x][2] = x + y; | 198 pixels[y][x][2] = x + y; |
87 pixels[y][x][3] = 255u; | 199 pixels[y][x][3] = 255u; |
88 } | 200 } |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 EXPECT_EQ(0, pixels[y][x][1]); | 623 EXPECT_EQ(0, pixels[y][x][1]); |
512 EXPECT_EQ(0, pixels[y][x][2]); | 624 EXPECT_EQ(0, pixels[y][x][2]); |
513 EXPECT_EQ(0, pixels[y][x][3]); | 625 EXPECT_EQ(0, pixels[y][x][3]); |
514 } | 626 } |
515 } | 627 } |
516 | 628 |
517 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 629 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
518 } | 630 } |
519 | 631 |
520 } // namespace gpu | 632 } // namespace gpu |
OLD | NEW |