| 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 // SetUp() sets up textures with the wrong parameters for this test, and |
| 790 // TearDown() expects to successfully delete textures/framebuffers, so |
| 791 // this is the right place for the delete/create calls. |
| 792 glDeleteTextures(2, textures_); |
| 793 glDeleteFramebuffers(1, &framebuffer_id_); |
| 794 CreateAndBindDestinationTextureAndFBO(dest_target); |
| 795 |
| 796 // Allocate source and destination textures. |
| 797 glBindTexture(src_target, textures_[0]); |
| 798 CreateBackingForTexture(src_target, src_width, src_height); |
| 799 |
| 800 glBindTexture(dest_target, textures_[1]); |
| 801 CreateBackingForTexture(dest_target, dest_width, dest_height); |
| 802 |
| 803 // The bottom left is red, bottom right is blue, top left is green, top |
| 804 // right is white. |
| 805 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, src_target, |
| 806 textures_[0], 0); |
| 807 glBindTexture(src_target, textures_[0]); |
| 808 for (GLint x = 0; x < src_width; ++x) { |
| 809 for (GLint y = 0; y < src_height; ++y) { |
| 810 uint8_t* data; |
| 811 if (x < src_width / 2) { |
| 812 data = y < src_height / 2 ? red : green; |
| 813 } else { |
| 814 data = y < src_height / 2 ? blue : white; |
| 815 } |
| 816 glTexSubImage2D(src_target, 0, x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 817 data); |
| 818 } |
| 819 } |
| 820 |
| 821 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dest_target, |
| 822 textures_[1], 0); |
| 823 glBindTexture(dest_target, textures_[1]); |
| 824 |
| 825 // Copy the subtexture x=[13,18) y=[6,9) to the destination. |
| 826 glClearColor(grey[0] / 255.f, grey[1] / 255.f, grey[2] / 255.f, 1.0); |
| 827 glClear(GL_COLOR_BUFFER_BIT); |
| 828 glCopySubTextureCHROMIUM(textures_[0], textures_[1], copy_region_x, |
| 829 copy_region_y, 13, 6, copy_region_width, |
| 830 copy_region_height, false, false, false); |
| 831 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 832 |
| 833 for (GLint x = 0; x < dest_width; ++x) { |
| 834 for (GLint y = 0; y < dest_height; ++y) { |
| 835 if (x < copy_region_x || x >= copy_region_x + copy_region_width || |
| 836 y < copy_region_y || y >= copy_region_y + copy_region_height) { |
| 837 GLTestHelper::CheckPixels(x, y, 1, 1, 0, grey); |
| 838 continue; |
| 839 } |
| 840 |
| 841 uint8_t* expected_color; |
| 842 if (x < copy_region_x + 2) { |
| 843 expected_color = y < copy_region_y + 1 ? red : green; |
| 844 } else { |
| 845 expected_color = y < copy_region_y + 1 ? blue : white; |
| 846 } |
| 847 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); |
| 848 } |
| 849 } |
| 850 } |
| 851 } |
| 852 } |
| 853 |
| 744 } // namespace gpu | 854 } // namespace gpu |
| OLD | NEW |