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 "gpu/command_buffer/tests/gl_manager.h" |
| 8 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace gpu { |
| 12 |
| 13 namespace { |
| 14 const GLenum kCubeMapTextureTargets[] = { |
| 15 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
| 16 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, |
| 17 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, |
| 18 }; |
| 19 } // namespace |
| 20 |
| 21 // A collection of tests that exercise the cube map texture. |
| 22 class GLCubeMapTextureTest : public testing::TestWithParam<GLenum> { |
| 23 protected: |
| 24 void SetUp() override { |
| 25 gl_.Initialize(GLManager::Options()); |
| 26 for (int i = 0; i < 256; i++) { |
| 27 pixels_[i * 4] = 255u; |
| 28 pixels_[(i * 4) + 1] = 0; |
| 29 pixels_[(i * 4) + 2] = 0; |
| 30 pixels_[(i * 4) + 3] = 255u; |
| 31 } |
| 32 |
| 33 glGenTextures(1, &texture_); |
| 34 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_); |
| 35 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 36 |
| 37 glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 38 glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 39 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 40 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 41 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 42 |
| 43 glGenFramebuffers(1, &framebuffer_id_); |
| 44 } |
| 45 |
| 46 void TearDown() override { |
| 47 glDeleteTextures(1, &texture_); |
| 48 glDeleteFramebuffers(1, &framebuffer_id_); |
| 49 gl_.Destroy(); |
| 50 } |
| 51 |
| 52 GLManager gl_; |
| 53 uint8 pixels_[256 * 4]; |
| 54 const int width_ = 16; |
| 55 GLuint texture_; |
| 56 GLuint framebuffer_id_; |
| 57 }; |
| 58 |
| 59 INSTANTIATE_TEST_CASE_P(GLCubeMapTextureTests, |
| 60 GLCubeMapTextureTest, |
| 61 ::testing::ValuesIn(kCubeMapTextureTargets)); |
| 62 |
| 63 TEST_P(GLCubeMapTextureTest, TexImage2DAfterFBOBinding) { |
| 64 GLenum cube_map_target = GetParam(); |
| 65 |
| 66 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); |
| 67 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| 68 texture_, 0); |
| 69 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 70 |
| 71 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_); |
| 72 // force_gl_finish_after_compositing workaround prevents Nexus 5 crash. |
| 73 // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889 |
| 74 glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA, |
| 75 GL_UNSIGNED_BYTE, pixels_); |
| 76 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 77 } |
| 78 |
| 79 TEST_P(GLCubeMapTextureTest, ReadPixels) { |
| 80 GLenum cube_map_target = GetParam(); |
| 81 |
| 82 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_); |
| 83 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 84 |
| 85 // Make a cube texture complete |
| 86 for (unsigned i = 0; i < arraysize(kCubeMapTextureTargets); i++) { |
| 87 glTexImage2D(kCubeMapTextureTargets[i], 0, GL_RGBA, width_, width_, 0, |
| 88 GL_RGBA, GL_UNSIGNED_BYTE, pixels_); |
| 89 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 90 } |
| 91 |
| 92 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); |
| 93 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| 94 texture_, 0); |
| 95 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 96 |
| 97 // Check that FB is complete. |
| 98 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 99 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 100 |
| 101 GLTestHelper::CheckPixels(0, 0, width_, width_, 0, pixels_); |
| 102 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 103 } |
| 104 |
| 105 #if defined(OS_WIN) |
| 106 // TODO(dshwang): ANGLE crashes. crbug.com/518889 |
| 107 TEST_P(GLCubeMapTextureTest, DISABLED_ReadPixelsFromIncompleteFBO) { |
| 108 #else |
| 109 TEST_P(GLCubeMapTextureTest, ReadPixelsFromIncompleteFBO) { |
| 110 #endif |
| 111 GLenum cube_map_target = GetParam(); |
| 112 |
| 113 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_); |
| 114 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 115 |
| 116 glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA, |
| 117 GL_UNSIGNED_BYTE, pixels_); |
| 118 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 119 |
| 120 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_); |
| 121 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| 122 texture_, 0); |
| 123 |
| 124 // force_gl_finish_after_compositing workaround prevents Nexus 5 crash. |
| 125 // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889 |
| 126 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 127 |
| 128 GLsizei size = width_ * width_ * 4; |
| 129 scoped_ptr<uint8[]> pixels(new uint8[size]); |
| 130 // ANGLE crashes on glReadPixels() from incomplete FBO. |
| 131 glReadPixels(0, 0, width_, width_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
| 132 // TODO(dshwang): According to spec, above glReadPixels() should fail and |
| 133 // glGetError() should report an error, but some drivers are fine to bind |
| 134 // incomplete cube map texture to FBO. crbug.com/517548 |
| 135 glGetError(); |
| 136 } |
| 137 |
| 138 } // namespace gpu |
OLD | NEW |