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 |
| 34 void TearDown() override { gl_.Destroy(); } |
| 35 |
| 36 uint8 pixels_[256 * 4]; |
| 37 const int width_ = 16; |
| 38 GLManager gl_; |
| 39 }; |
| 40 |
| 41 INSTANTIATE_TEST_CASE_P(GLCubeMapTextureTests, |
| 42 GLCubeMapTextureTest, |
| 43 ::testing::ValuesIn(kCubeMapTextureTargets)); |
| 44 |
| 45 TEST_P(GLCubeMapTextureTest, TexImage2DAfterFBOBinding) { |
| 46 GLenum cube_map_target = GetParam(); |
| 47 |
| 48 GLuint texture = 0; |
| 49 glGenTextures(1, &texture); |
| 50 |
| 51 glBindTexture(GL_TEXTURE_CUBE_MAP, texture); |
| 52 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 53 |
| 54 GLuint framebuffer_id = 0; |
| 55 glGenFramebuffers(1, &framebuffer_id); |
| 56 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); |
| 57 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| 58 texture, 0); |
| 59 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 60 |
| 61 // force_gl_finish_after_compositing workaround prevents Nexus 5 crash. |
| 62 // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889 |
| 63 glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA, |
| 64 GL_UNSIGNED_BYTE, pixels_); |
| 65 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 66 } |
| 67 |
| 68 #if defined(OS_WIN) |
| 69 // ANGLE crashes. crbug.com/518889 |
| 70 TEST_P(GLCubeMapTextureTest, DISABLED_ReadPixels) { |
| 71 #else |
| 72 TEST_P(GLCubeMapTextureTest, ReadPixels) { |
| 73 #endif |
| 74 GLenum cube_map_target = GetParam(); |
| 75 |
| 76 GLuint texture = 0; |
| 77 glGenTextures(1, &texture); |
| 78 |
| 79 glBindTexture(GL_TEXTURE_CUBE_MAP, texture); |
| 80 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 81 |
| 82 glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA, |
| 83 GL_UNSIGNED_BYTE, pixels_); |
| 84 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 85 |
| 86 GLuint framebuffer_id = 0; |
| 87 glGenFramebuffers(1, &framebuffer_id); |
| 88 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); |
| 89 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| 90 texture, 0); |
| 91 // force_gl_finish_after_compositing workaround prevents Nexus 5 crash. |
| 92 // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889 |
| 93 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 94 |
| 95 // Check that FB is complete. |
| 96 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 97 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 98 |
| 99 // ANGLE crashes on glReadPixels() except for CUBE_MAP_POSITIVE_X. |
| 100 GLTestHelper::CheckPixels(0, 0, width_, width_, 0, pixels_); |
| 101 EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| 102 } |
| 103 |
| 104 } // namespace gpu |
OLD | NEW |