| 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 |
| 60 GLManager gl_; | 65 GLManager gl_; |
| 61 GLuint textures_[2]; | 66 GLuint textures_[2]; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 148 |
| 144 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); | 149 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, pixels); |
| 145 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 150 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 146 } | 151 } |
| 147 } | 152 } |
| 148 | 153 |
| 149 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormat) { | 154 TEST_P(GLCopyTextureCHROMIUMTest, InternalFormat) { |
| 150 CopyType copy_type = GetParam(); | 155 CopyType copy_type = GetParam(); |
| 151 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, | 156 GLint src_formats[] = {GL_ALPHA, GL_RGB, GL_RGBA, |
| 152 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; | 157 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGRA_EXT}; |
| 153 GLint dest_formats[] = {GL_RGB, GL_RGBA}; | 158 GLint dest_formats[] = {GL_RGB, GL_RGBA, GL_BGRA_EXT}; |
| 154 | 159 |
| 155 for (size_t src_index = 0; src_index < arraysize(src_formats); src_index++) { | 160 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); | 161 for (size_t dest_index = 0; dest_index < arraysize(dest_formats); |
| 157 dest_index++) { | 162 dest_index++) { |
| 158 glBindTexture(GL_TEXTURE_2D, textures_[0]); | 163 glBindTexture(GL_TEXTURE_2D, textures_[0]); |
| 159 glTexImage2D(GL_TEXTURE_2D, 0, src_formats[src_index], 1, 1, 0, | 164 glTexImage2D(GL_TEXTURE_2D, 0, src_formats[src_index], 1, 1, 0, |
| 160 src_formats[src_index], GL_UNSIGNED_BYTE, nullptr); | 165 src_formats[src_index], GL_UNSIGNED_BYTE, nullptr); |
| 161 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 166 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 162 | 167 |
| 163 if (copy_type == TexImage) { | 168 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}; | 739 uint8_t red[1 * 4] = {255u, 0u, 0u, 255u}; |
| 735 uint8_t green[1 * 4] = {0u, 255u, 0u, 255u}; | 740 uint8_t green[1 * 4] = {0u, 255u, 0u, 255u}; |
| 736 uint8_t blue[1 * 4] = {0u, 0u, 255u, 255u}; | 741 uint8_t blue[1 * 4] = {0u, 0u, 255u, 255u}; |
| 737 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, transparent); | 742 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, transparent); |
| 738 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, red); | 743 GLTestHelper::CheckPixels(1, 1, 1, 1, 0, red); |
| 739 GLTestHelper::CheckPixels(1, 0, 1, 1, 0, green); | 744 GLTestHelper::CheckPixels(1, 0, 1, 1, 0, green); |
| 740 GLTestHelper::CheckPixels(0, 1, 1, 1, 0, blue); | 745 GLTestHelper::CheckPixels(0, 1, 1, 1, 0, blue); |
| 741 EXPECT_TRUE(GL_NO_ERROR == glGetError()); | 746 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 742 } | 747 } |
| 743 | 748 |
| 749 TEST_F(GLCopyTextureCHROMIUMTest, CopyTextureBetweenTexture2DAndRectangleArb) { |
| 750 if (!GLTestHelper::HasExtension("GL_ARB_texture_rectangle")) { |
| 751 LOG(INFO) << |
| 752 "GL_ARB_texture_rectangle not supported. Skipping test..."; |
| 753 return; |
| 754 } |
| 755 |
| 756 GLenum src_targets[] = {GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_2D}; |
| 757 GLenum dest_targets[] = {GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_2D}; |
| 758 GLsizei width = 30; |
| 759 GLsizei height = 14; |
| 760 GLsizei dest_width = 15; |
| 761 GLsizei dest_height = 13; |
| 762 GLsizei copy_region_x = 1; |
| 763 GLsizei copy_region_y = 1; |
| 764 GLsizei copy_region_width = 5; |
| 765 GLsizei copy_region_height = 3; |
| 766 uint8_t red[1 * 4] = {255u, 0u, 0u, 255u}; |
| 767 uint8_t blue[1 * 4] = {0u, 0u, 255u, 255u}; |
| 768 uint8_t green[1 * 4] = {0u, 255u, 0, 255u}; |
| 769 uint8_t white[1 * 4] = {255u, 255u, 255u, 255u}; |
| 770 uint8_t grey[1 * 4] = {199u, 199u, 199u, 255u}; |
| 771 |
| 772 for (size_t src_index = 0; src_index < arraysize(src_targets); src_index++) { |
| 773 GLenum src_target = src_targets[src_index]; |
| 774 for (size_t dest_index = 0; dest_index < arraysize(dest_targets); |
| 775 dest_index++) { |
| 776 GLenum dest_target = dest_targets[dest_index]; |
| 777 |
| 778 glDeleteTextures(2, textures_); |
| 779 glDeleteFramebuffers(1, &framebuffer_id_); |
| 780 CreateAndBindDestinationTextureAndFBO(dest_target); |
| 781 |
| 782 // Allocate source and destination textures. |
| 783 glBindTexture(src_target, textures_[0]); |
| 784 glTexImage2D(src_target, 0, GL_RGBA, width, height, 0, GL_RGBA, |
| 785 GL_UNSIGNED_BYTE, nullptr); |
| 786 glBindTexture(dest_target, textures_[1]); |
| 787 glTexImage2D(dest_target, 0, GL_RGBA, dest_width, dest_height, 0, GL_RGBA, |
| 788 GL_UNSIGNED_BYTE, nullptr); |
| 789 |
| 790 // The bottom left is red, bottom right is blue, top left is green, top |
| 791 // right is white. |
| 792 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, src_target, |
| 793 textures_[0], 0); |
| 794 glBindTexture(src_target, textures_[0]); |
| 795 for (GLint x = 0; x < width; ++x) { |
| 796 for (GLint y = 0; y < height; ++y) { |
| 797 uint8_t* data; |
| 798 if (x < width / 2) { |
| 799 data = y < height / 2 ? red : green; |
| 800 } else { |
| 801 data = y < height / 2 ? blue : white; |
| 802 } |
| 803 glTexSubImage2D(src_target, 0, x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 804 data); |
| 805 } |
| 806 } |
| 807 |
| 808 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dest_target, |
| 809 textures_[1], 0); |
| 810 glBindTexture(dest_target, textures_[1]); |
| 811 |
| 812 // Copy the subtexture x=[13,18) y=[6,9) to the destination. |
| 813 glClearColor(grey[0] / 255.f, grey[1] / 255.f, grey[2] / 255.f, 1.0); |
| 814 glClear(GL_COLOR_BUFFER_BIT); |
| 815 glCopySubTextureCHROMIUM(textures_[0], textures_[1], copy_region_x, |
| 816 copy_region_y, 13, 6, copy_region_width, |
| 817 copy_region_height, false, false, false); |
| 818 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 819 |
| 820 for (GLint x = 0; x < dest_width; ++x) { |
| 821 for (GLint y = 0; y < dest_height; ++y) { |
| 822 if (x < copy_region_x || x >= copy_region_x + copy_region_width || |
| 823 y < copy_region_y || y >= copy_region_y + copy_region_height) { |
| 824 GLTestHelper::CheckPixels(x, y, 1, 1, 0, grey); |
| 825 continue; |
| 826 } |
| 827 |
| 828 uint8_t* expected_color; |
| 829 if (x < copy_region_x + 2) { |
| 830 expected_color = y < copy_region_y + 1 ? red : green; |
| 831 } else { |
| 832 expected_color = y < copy_region_y + 1 ? blue : white; |
| 833 } |
| 834 GLTestHelper::CheckPixels(x, y, 1, 1, 0, expected_color); |
| 835 } |
| 836 } |
| 837 } |
| 838 } |
| 839 } |
| 840 |
| 744 } // namespace gpu | 841 } // namespace gpu |
| OLD | NEW |