OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <GLES2/gl2.h> |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "gpu/command_buffer/tests/gl_manager.h" |
| 10 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 11 #include "gpu/config/gpu_switches.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace gpu { |
| 15 |
| 16 namespace { |
| 17 const GLenum kCubeMapTextureTargets[] = { |
| 18 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
| 19 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, |
| 20 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, |
| 21 }; |
| 22 } // namespace |
| 23 |
| 24 // A collection of tests that exercise the cube map texture. |
| 25 class GLCubeMapTextureTest : public testing::TestWithParam<GLenum> { |
| 26 protected: |
| 27 void SetUp() override { |
| 28 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 29 // ANGLE and NVidia fails ReadPixelsFromIncompleteCubeTexture without this |
| 30 // workaround. |
| 31 command_line.AppendSwitchASCII(switches::kGpuDriverBugWorkarounds, |
| 32 base::IntToString(gpu::FORCE_CUBE_COMPLETE)); |
| 33 gl_.InitializeWithCommandLine(GLManager::Options(), &command_line); |
| 34 DCHECK(gl_.workarounds().force_cube_complete); |
| 35 for (int i = 0; i < 256; i++) { |
| 36 pixels_[i * 4] = 255u; |
| 37 pixels_[(i * 4) + 1] = 0; |
| 38 pixels_[(i * 4) + 2] = 0; |
| 39 pixels_[(i * 4) + 3] = 255u; |
| 40 } |
| 41 |
| 42 glGenTextures(1, &texture_); |
| 43 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_); |
| 44 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 45 |
| 46 glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 47 glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 48 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 49 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 50 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 51 |
| 52 glGenFramebuffers(1, &framebuffer_id_); |
| 53 } |
| 54 |
| 55 void TearDown() override { |
| 56 glDeleteTextures(1, &texture_); |
| 57 glDeleteFramebuffers(1, &framebuffer_id_); |
| 58 gl_.Destroy(); |
| 59 } |
| 60 |
| 61 GLManager gl_; |
| 62 uint8 pixels_[256 * 4]; |
| 63 const int width_ = 16; |
| 64 GLuint texture_; |
| 65 GLuint framebuffer_id_; |
| 66 }; |
| 67 |
| 68 INSTANTIATE_TEST_CASE_P(GLCubeMapTextureTests, |
| 69 GLCubeMapTextureTest, |
| 70 ::testing::ValuesIn(kCubeMapTextureTargets)); |
| 71 |
| 72 TEST_P(GLCubeMapTextureTest, TexImage2DAfterFBOBinding) { |
| 73 GLenum cube_map_target = GetParam(); |
| 74 |
| 75 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); |
| 76 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| 77 texture_, 0); |
| 78 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 79 |
| 80 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_); |
| 81 // force_gl_finish_after_compositing workaround prevents Nexus 5 crash. |
| 82 // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889 |
| 83 glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA, |
| 84 GL_UNSIGNED_BYTE, pixels_); |
| 85 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 86 } |
| 87 |
| 88 TEST_P(GLCubeMapTextureTest, ReadPixels) { |
| 89 GLenum cube_map_target = GetParam(); |
| 90 |
| 91 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_); |
| 92 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 93 |
| 94 // Make a cube texture complete |
| 95 for (unsigned i = 0; i < arraysize(kCubeMapTextureTargets); i++) { |
| 96 glTexImage2D(kCubeMapTextureTargets[i], 0, GL_RGBA, width_, width_, 0, |
| 97 GL_RGBA, GL_UNSIGNED_BYTE, pixels_); |
| 98 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 99 } |
| 100 |
| 101 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); |
| 102 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| 103 texture_, 0); |
| 104 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 105 |
| 106 // Check that FB is complete. |
| 107 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 108 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 109 |
| 110 GLTestHelper::CheckPixels(0, 0, width_, width_, 0, pixels_); |
| 111 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 112 } |
| 113 |
| 114 |
| 115 TEST_P(GLCubeMapTextureTest, ReadPixelsFromIncompleteCubeTexture) { |
| 116 GLenum cube_map_target = GetParam(); |
| 117 |
| 118 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_); |
| 119 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 120 |
| 121 glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA, |
| 122 GL_UNSIGNED_BYTE, pixels_); |
| 123 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 124 |
| 125 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); |
| 126 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| 127 texture_, 0); |
| 128 |
| 129 // force_gl_finish_after_compositing workaround prevents Nexus 5 crash. |
| 130 // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889 |
| 131 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 132 |
| 133 // Check that FB is complete. |
| 134 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 135 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 136 #if defined(OS_ANDROID) |
| 137 // No way to workaround on Android NVIDIA drivers. Users have to texImage2D |
| 138 // by (POSITIVE_X, NEGATIVE_Z) order only once. If users call texImage2D again |
| 139 // after defining all faces, glReadPixels fails. |
| 140 GLsizei size = width_ * width_ * 4; |
| 141 scoped_ptr<uint8[]> pixels(new uint8[size]); |
| 142 glReadPixels(0, 0, width_, width_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
| 143 #else |
| 144 // Without force_cube_complete workaround, |
| 145 // 1. ANGLE crashes on glReadPixels() from incomplete cube texture. |
| 146 // 2. NVidia fails on glReadPixels() from incomplete cube texture. |
| 147 GLTestHelper::CheckPixels(0, 0, width_, width_, 0, pixels_); |
| 148 #endif |
| 149 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 150 } |
| 151 |
| 152 } // namespace gpu |
OLD | NEW |