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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 if (target == GL_TEXTURE_RECTANGLE_ARB) { | 66 if (target == GL_TEXTURE_RECTANGLE_ARB) { |
67 GLuint image_id = glCreateGpuMemoryBufferImageCHROMIUM( | 67 GLuint image_id = glCreateGpuMemoryBufferImageCHROMIUM( |
68 width, height, GL_RGBA, GL_READ_WRITE_CHROMIUM); | 68 width, height, GL_RGBA, GL_READ_WRITE_CHROMIUM); |
69 glBindTexImage2DCHROMIUM(target, image_id); | 69 glBindTexImage2DCHROMIUM(target, image_id); |
70 } else { | 70 } else { |
71 glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, | 71 glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, |
72 GL_UNSIGNED_BYTE, nullptr); | 72 GL_UNSIGNED_BYTE, nullptr); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
| 76 GLenum ExtractFormatFrom(GLenum internalformat) { |
| 77 switch (internalformat) { |
| 78 case GL_RGBA8_OES: |
| 79 return GL_RGBA; |
| 80 case GL_RGB8_OES: |
| 81 return GL_RGB; |
| 82 case GL_BGRA8_EXT: |
| 83 return GL_BGRA_EXT; |
| 84 default: |
| 85 NOTREACHED(); |
| 86 return GL_NONE; |
| 87 } |
| 88 } |
| 89 |
76 GLManager gl_; | 90 GLManager gl_; |
77 GLuint textures_[2]; | 91 GLuint textures_[2]; |
78 GLuint framebuffer_id_; | 92 GLuint framebuffer_id_; |
79 }; | 93 }; |
80 | 94 |
81 INSTANTIATE_TEST_CASE_P(CopyType, | 95 INSTANTIATE_TEST_CASE_P(CopyType, |
82 GLCopyTextureCHROMIUMTest, | 96 GLCopyTextureCHROMIUMTest, |
83 ::testing::ValuesIn(kCopyTypes)); | 97 ::testing::ValuesIn(kCopyTypes)); |
84 | 98 |
85 // Test to ensure that the basic functionality of the extension works. | 99 // Test to ensure that the basic functionality of the extension works. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | 131 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
118 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 132 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
119 } | 133 } |
120 | 134 |
121 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { | 135 TEST_P(GLCopyTextureCHROMIUMTest, ImmutableTexture) { |
122 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { | 136 if (!GLTestHelper::HasExtension("GL_EXT_texture_storage")) { |
123 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; | 137 LOG(INFO) << "GL_EXT_texture_storage not supported. Skipping test..."; |
124 return; | 138 return; |
125 } | 139 } |
126 CopyType copy_type = GetParam(); | 140 CopyType copy_type = GetParam(); |
| 141 GLenum src_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; |
| 142 GLenum dest_internal_formats[] = {GL_RGB8_OES, GL_RGBA8_OES, GL_BGRA8_EXT}; |
127 | 143 |
128 uint8_t pixels[1 * 4] = {255u, 0u, 0u, 255u}; | 144 uint8_t pixels[1 * 4] = {255u, 0u, 255u, 255u}; |
129 | 145 |
130 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 146 for (auto src_internal_format : src_internal_formats) { |
131 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); | 147 for (auto dest_internal_format : dest_internal_formats) { |
132 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, | 148 glDeleteTextures(2, textures_); |
133 pixels); | 149 glDeleteFramebuffers(1, &framebuffer_id_); |
| 150 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); |
134 | 151 |
135 glBindTexture(GL_TEXTURE_2D, textures_[1]); | 152 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
136 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); | 153 glTexStorage2DEXT(GL_TEXTURE_2D, 1, src_internal_format, 1, 1); |
137 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 154 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, |
138 textures_[1], 0); | 155 ExtractFormatFrom(src_internal_format), GL_UNSIGNED_BYTE, |
139 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | 156 pixels); |
140 | 157 |
141 if (copy_type == TexImage) { | 158 glBindTexture(GL_TEXTURE_2D, textures_[1]); |
142 glCopyTextureCHROMIUM(textures_[0], textures_[1], GL_RGBA, | 159 glTexStorage2DEXT(GL_TEXTURE_2D, 1, dest_internal_format, 1, 1); |
143 GL_UNSIGNED_BYTE, false, false, false); | 160 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
144 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION); | 161 GL_TEXTURE_2D, textures_[1], 0); |
145 } else { | 162 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
146 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, | |
147 0, 1, 1, false, false, false); | |
148 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
149 | 163 |
150 // Check the FB is still bound. | 164 if (copy_type == TexImage) { |
151 GLint value = 0; | 165 glCopyTextureCHROMIUM(textures_[0], textures_[1], |
152 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); | 166 ExtractFormatFrom(dest_internal_format), |
153 GLuint fb_id = value; | 167 GL_UNSIGNED_BYTE, false, false, false); |
154 EXPECT_EQ(framebuffer_id_, fb_id); | 168 EXPECT_TRUE(glGetError() == GL_INVALID_OPERATION); |
| 169 } else { |
| 170 glCopySubTextureCHROMIUM(textures_[0], textures_[1], 0, 0, 0, 0, 1, 1, |
| 171 false, false, false); |
| 172 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
155 | 173 |
156 // Check that FB is complete. | 174 // Check the FB is still bound. |
157 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 175 GLint value = 0; |
158 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 176 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &value); |
| 177 GLuint fb_id = value; |
| 178 EXPECT_EQ(framebuffer_id_, fb_id); |
159 | 179 |
160 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | 180 // Check that FB is complete. |
161 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 181 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 182 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 183 |
| 184 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
| 185 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 186 } |
| 187 } |
162 } | 188 } |
163 } | 189 } |
164 | 190 |
165 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormat) { | 191 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormat) { |
166 CopyType copy_type = GetParam(); | 192 CopyType copy_type = GetParam(); |
167 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, | 193 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, |
168 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; | 194 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; |
169 GLint dest_formats[] = {GL_RGB, GL_RGBA, GL_BGRA_EXT}; | 195 GLint dest_formats[] = {GL_RGB, GL_RGBA, GL_BGRA_EXT}; |
170 | 196 |
171 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) { | 197 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) { |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 expected_color = y < copy_region_y + 1 ? blue : white; | 894 expected_color = y < copy_region_y + 1 ? blue : white; |
869 } | 895 } |
870 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); | 896 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); |
871 } | 897 } |
872 } | 898 } |
873 } | 899 } |
874 } | 900 } |
875 } | 901 } |
876 | 902 |
877 } // namespace gpu | 903 } // namespace gpu |
OLD | NEW |