Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 25 TexImage, | 25 TexImage, |
| 26 TexSubImage, | 26 TexSubImage, |
| 27 }; | 27 }; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. | 30 // A collection of tests that exercise the GL_CHROMIUM_copy_texture extension. |
| 31 class GLCopyTextureCHROMIUMTest | 31 class GLCopyTextureCHROMIUMTest |
| 32 : public testing::Test, | 32 : public testing::Test, |
| 33 public ::testing::WithParamInterface<CopyType> { | 33 public ::testing::WithParamInterface<CopyType> { |
| 34 protected: | 34 protected: |
| 35 | |
| 36 void CreateAndBindDestinationTextureAndFBO(GLenum target) { | |
| 37 glGenTextures(2, textures_); | |
| 38 glBindTexture(target, textures_[1]); | |
| 39 | |
| 40 // Some drivers (NVidia/SGX) require texture settings to be a certain way or | |
| 41 // they won't report FRAMEBUFFER_COMPLETE. | |
| 42 glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| 43 glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 44 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 45 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 46 | |
| 47 glGenFramebuffers(1, &framebuffer_id_); | |
| 48 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); | |
| 49 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, | |
| 50 textures_[1], 0); | |
| 51 } | |
| 52 | |
| 35 void SetUp() override { | 53 void SetUp() override { |
| 36 gl_.Initialize(GLManager::Options()); | 54 gl_.Initialize(GLManager::Options()); |
| 37 | 55 |
| 38 glGenTextures(2, textures_); | 56 CreateAndBindDestinationTextureAndFBO(GL_TEXTURE_2D); |
| 39 glBindTexture(GL_TEXTURE_2D, textures_[1]); | |
| 40 | |
| 41 // Some drivers (NVidia/SGX) require texture settings to be a certain way or | |
| 42 // they won't report FRAMEBUFFER_COMPLETE. | |
| 43 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| 44 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 45 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 46 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 47 | |
| 48 glGenFramebuffers(1, &framebuffer_id_); | |
| 49 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); | |
| 50 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | |
| 51 textures_[1], 0); | |
| 52 } | 57 } |
| 53 | 58 |
| 54 void TearDown() override { | 59 void TearDown() override { |
| 55 glDeleteTextures(2, textures_); | 60 glDeleteTextures(2, textures_); |
| 56 glDeleteFramebuffers(1, &framebuffer_id_); | 61 glDeleteFramebuffers(1, &framebuffer_id_); |
| 57 gl_.Destroy(); | 62 gl_.Destroy(); |
| 58 } | 63 } |
| 59 | 64 |
| 65 void CreateBackingForTexture(GLenum target, GLsizei width, GLsizei height) { | |
| 66 if (target == GL_TEXTURE_RECTANGLE_ARB) { | |
| 67 GLuint image_id = glCreateGpuMemoryBufferImageCHROMIUM( | |
| 68 width, height, GL_RGBA, GL_READ_WRITE_CHROMIUM); | |
| 69 glBindTexImage2DCHROMIUM(target, image_id); | |
| 70 } else { | |
| 71 glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, | |
| 72 GL_UNSIGNED_BYTE, nullptr); | |
| 73 } | |
| 74 } | |
| 75 | |
| 60 GLManager gl_; | 76 GLManager gl_; |
| 61 GLuint textures_[2]; | 77 GLuint textures_[2]; |
| 62 GLuint framebuffer_id_; | 78 GLuint framebuffer_id_; |
| 63 }; | 79 }; |
| 64 | 80 |
| 65 INSTANTIATE_TEST_CASE_P(CopyType, | 81 INSTANTIATE_TEST_CASE_P(CopyType, |
| 66 GLCopyTextureCHROMIUMTest, | 82 GLCopyTextureCHROMIUMTest, |
| 67 ::testing::ValuesIn(kCopyTypes)); | 83 ::testing::ValuesIn(kCopyTypes)); |
| 68 | 84 |
| 69 // Test to ensure that the basic functionality of the extension works. | 85 // Test to ensure that the basic functionality of the extension works. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 159 |
| 144 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | 160 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
| 145 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 161 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 146 } | 162 } |
| 147 } | 163 } |
| 148 | 164 |
| 149 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormat) { | 165 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormat) { |
| 150 CopyType copy_type = GetParam(); | 166 CopyType copy_type = GetParam(); |
| 151 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, | 167 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, |
| 152 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; | 168 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; |
| 153 GLint dest_formats[] = {GL_RGB, GL_RGBA}; | 169 GLint dest_formats[] = {GL_RGB, GL_RGBA, GL_BGRA_EXT}; |
| 154 | 170 |
| 155 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) { | 171 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) { |
| 156 for (size_t dest_index = 0; dest_index < arraysize(dest_formats); | 172 for (size_t dest_index = 0; dest_index < arraysize(dest_formats); |
| 157 dest_index++) { | 173 dest_index++) { |
| 158 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 174 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 159 glTexImage2D(GL_TEXTURE_2D, 0, src_formats[src_index], 1, 1, 0, | 175 glTexImage2D(GL_TEXTURE_2D, 0, src_formats[src_index], 1, 1, 0, |
| 160 src_formats[src_index], GL_UNSIGNED_BYTE, nullptr); | 176 src_formats[src_index], GL_UNSIGNED_BYTE, nullptr); |
| 161 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 177 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 162 | 178 |
| 163 if (copy_type == TexImage) { | 179 if (copy_type == TexImage) { |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 uint8_t red[1 * 4] = {255u, 0u, 0u, 255u}; | 750 uint8_t red[1 * 4] = {255u, 0u, 0u, 255u}; |
| 735 uint8_t green[1 * 4] = {0u, 255u, 0u, 255u}; | 751 uint8_t green[1 * 4] = {0u, 255u, 0u, 255u}; |
| 736 uint8_t blue[1 * 4] = {0u, 0u, 255u, 255u}; | 752 uint8_t blue[1 * 4] = {0u, 0u, 255u, 255u}; |
| 737 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, transparent); | 753 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, transparent); |
| 738 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, red); | 754 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, red); |
| 739 GLTestHelper::CheckPixels(1, 0, 1, 1, 0, green); | 755 GLTestHelper::CheckPixels(1, 0, 1, 1, 0, green); |
| 740 GLTestHelper::CheckPixels(0, 1, 1, 1, 0, blue); | 756 GLTestHelper::CheckPixels(0, 1, 1, 1, 0, blue); |
| 741 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 757 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 742 } | 758 } |
| 743 | 759 |
| 760 TEST_F(GLCopyTextureCHROMIUMTest, CopyTextureBetweenTexture2DAndRectangleArb) { | |
| 761 if (!GLTestHelper::HasExtension("GL_ARB_texture_rectangle")) { | |
| 762 LOG(INFO) << | |
| 763 "GL_ARB_texture_rectangle not supported. Skipping test..."; | |
| 764 return; | |
| 765 } | |
| 766 | |
| 767 GLenum src_targets[] = {GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_2D}; | |
| 768 GLenum dest_targets[] = {GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_2D}; | |
| 769 GLsizei src_width = 30; | |
| 770 GLsizei src_height = 14; | |
| 771 GLsizei dest_width = 15; | |
| 772 GLsizei dest_height = 13; | |
| 773 GLsizei copy_region_x = 1; | |
| 774 GLsizei copy_region_y = 1; | |
| 775 GLsizei copy_region_width = 5; | |
| 776 GLsizei copy_region_height = 3; | |
| 777 uint8_t red[1 * 4] = {255u, 0u, 0u, 255u}; | |
| 778 uint8_t blue[1 * 4] = {0u, 0u, 255u, 255u}; | |
| 779 uint8_t green[1 * 4] = {0u, 255u, 0, 255u}; | |
| 780 uint8_t white[1 * 4] = {255u, 255u, 255u, 255u}; | |
| 781 uint8_t grey[1 * 4] = {199u, 199u, 199u, 255u}; | |
| 782 | |
| 783 for (size_t src_index = 0; src_index < arraysize(src_targets); src_index++) { | |
| 784 GLenum src_target = src_targets[src_index]; | |
| 785 for (size_t dest_index = 0; dest_index < arraysize(dest_targets); | |
| 786 dest_index++) { | |
| 787 GLenum dest_target = dest_targets[dest_index]; | |
| 788 | |
| 789 glDeleteTextures(2, textures_); | |
| 790 glDeleteFramebuffers(1, &framebuffer_id_); | |
|
Ken Russell (switch to Gerrit)
2016/01/06 02:14:28
Please move the Delete calls to the end of the loo
erikchen
2016/01/06 02:23:37
SetUp() sets up textures with the wrong parameters
Ken Russell (switch to Gerrit)
2016/01/06 03:46:28
That's fine - could you please add your first para
erikchen
2016/01/06 18:08:36
Done.
| |
| 791 CreateAndBindDestinationTextureAndFBO(dest_target); | |
| 792 | |
| 793 // Allocate source and destination textures. | |
| 794 glBindTexture(src_target, textures_[0]); | |
| 795 CreateBackingForTexture(src_target, src_width, src_height); | |
| 796 | |
| 797 glBindTexture(dest_target, textures_[1]); | |
| 798 CreateBackingForTexture(dest_target, dest_width, dest_height); | |
| 799 | |
| 800 // The bottom left is red, bottom right is blue, top left is green, top | |
| 801 // right is white. | |
| 802 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, src_target, | |
| 803 textures_[0], 0); | |
| 804 glBindTexture(src_target, textures_[0]); | |
| 805 for (GLint x = 0; x < src_width; ++x) { | |
| 806 for (GLint y = 0; y < src_height; ++y) { | |
| 807 uint8_t* data; | |
| 808 if (x < src_width / 2) { | |
| 809 data = y < src_height / 2 ? red : green; | |
| 810 } else { | |
| 811 data = y < src_height / 2 ? blue : white; | |
| 812 } | |
| 813 glTexSubImage2D(src_target, 0, x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, | |
| 814 data); | |
| 815 } | |
| 816 } | |
| 817 | |
| 818 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dest_target, | |
| 819 textures_[1], 0); | |
| 820 glBindTexture(dest_target, textures_[1]); | |
| 821 | |
| 822 // Copy the subtexture x=[13,18) y=[6,9) to the destination. | |
| 823 glClearColor(grey[0] / 255.f, grey[1] / 255.f, grey[2] / 255.f, 1.0); | |
| 824 glClear(GL_COLOR_BUFFER_BIT); | |
| 825 glCopySubTextureCHROMIUM(textures_[0], textures_[1], copy_region_x, | |
| 826 copy_region_y, 13, 6, copy_region_width, | |
| 827 copy_region_height, false, false, false); | |
| 828 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | |
| 829 | |
| 830 for (GLint x = 0; x < dest_width; ++x) { | |
| 831 for (GLint y = 0; y < dest_height; ++y) { | |
| 832 if (x < copy_region_x || x >= copy_region_x + copy_region_width || | |
| 833 y < copy_region_y || y >= copy_region_y + copy_region_height) { | |
| 834 GLTestHelper::CheckPixels(x, y, 1, 1, 0, grey); | |
| 835 continue; | |
| 836 } | |
| 837 | |
| 838 uint8_t* expected_color; | |
| 839 if (x < copy_region_x + 2) { | |
| 840 expected_color = y < copy_region_y + 1 ? red : green; | |
| 841 } else { | |
| 842 expected_color = y < copy_region_y + 1 ? blue : white; | |
| 843 } | |
| 844 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); | |
| 845 } | |
| 846 } | |
| 847 } | |
| 848 } | |
| 849 } | |
| 850 | |
| 744 } // namespace gpu | 851 } // namespace gpu |
| OLD | NEW |