Chromium Code Reviews| Index: gpu/command_buffer/tests/gl_cube_map_texture_unittest.cc |
| diff --git a/gpu/command_buffer/tests/gl_cube_map_texture_unittest.cc b/gpu/command_buffer/tests/gl_cube_map_texture_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f2bf35025e5441c0954549c02ecf1327a723e294 |
| --- /dev/null |
| +++ b/gpu/command_buffer/tests/gl_cube_map_texture_unittest.cc |
| @@ -0,0 +1,124 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <GLES2/gl2.h> |
| + |
| +#include "gpu/command_buffer/tests/gl_manager.h" |
| +#include "gpu/command_buffer/tests/gl_test_utils.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace gpu { |
| + |
| +namespace { |
| +const GLenum kCubeMapTextureTargets[] = { |
| + GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
| + GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, |
| + GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, |
| +}; |
| +} // namespace |
| + |
| +// A collection of tests that exercise the cube map texture. |
| +class GLCubeMapTextureTest : public testing::TestWithParam<GLenum> { |
| + protected: |
| + void SetUp() override { |
| + gl_.Initialize(GLManager::Options()); |
| + for (int i = 0; i < 256; i++) { |
| + pixels_[i * 4] = 255u; |
| + pixels_[(i * 4) + 1] = 0; |
| + pixels_[(i * 4) + 2] = 0; |
| + pixels_[(i * 4) + 3] = 255u; |
| + } |
| + } |
| + |
| + void TearDown() override { gl_.Destroy(); } |
| + |
| + uint8 pixels_[256 * 4]; |
| + const int width_ = 16; |
| + GLManager gl_; |
| +}; |
| + |
| +INSTANTIATE_TEST_CASE_P(GLCubeMapTextureTests, |
| + GLCubeMapTextureTest, |
| + ::testing::ValuesIn(kCubeMapTextureTargets)); |
| + |
| +TEST_P(GLCubeMapTextureTest, FramebufferTexture2DToIncompleteCubeTexture) { |
| + GLenum cube_map_target = GetParam(); |
| + |
| + GLuint texture = 0; |
| + glGenTextures(1, &texture); |
| + |
| + glBindTexture(GL_TEXTURE_CUBE_MAP, texture); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| + |
| + glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA, |
| + GL_UNSIGNED_BYTE, pixels_); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| + |
| + GLuint framebuffer_id = 0; |
| + glGenFramebuffers(1, &framebuffer_id); |
| + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); |
| + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| + texture, 0); |
| + |
| + // force_gl_finish_after_compositing workaround prevents Nexus 5 crash. |
| + // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889 |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| +} |
| + |
| +TEST_P(GLCubeMapTextureTest, TexImage2DAfterFBOBinding) { |
| + GLenum cube_map_target = GetParam(); |
| + |
| + GLuint texture = 0; |
| + glGenTextures(1, &texture); |
| + |
| + glBindTexture(GL_TEXTURE_CUBE_MAP, texture); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| + |
| + GLuint framebuffer_id = 0; |
| + glGenFramebuffers(1, &framebuffer_id); |
| + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); |
| + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| + texture, 0); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| + |
| + // force_gl_finish_after_compositing workaround prevents Nexus 5 crash. |
| + // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889 |
| + glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA, |
| + GL_UNSIGNED_BYTE, pixels_); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| +} |
| + |
| +TEST_P(GLCubeMapTextureTest, ReadPixels) { |
| + GLenum cube_map_target = GetParam(); |
| + |
| + GLuint texture = 0; |
| + glGenTextures(1, &texture); |
| + |
| + glBindTexture(GL_TEXTURE_CUBE_MAP, texture); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| + |
| + // Make a cube texture complete |
| + for (unsigned i = 0; i < arraysize(kCubeMapTextureTargets); i++) { |
| + glTexImage2D(kCubeMapTextureTargets[i], 0, GL_RGBA, width_, width_, 0, |
| + GL_RGBA, GL_UNSIGNED_BYTE, pixels_); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| + } |
| + |
| + GLuint framebuffer_id = 0; |
| + glGenFramebuffers(1, &framebuffer_id); |
| + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id); |
| + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target, |
| + texture, 0); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| + |
| + // Check that FB is complete. |
| + EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
|
no sievers
2015/08/11 21:08:54
what about mipmaps? don't you have to set the filt
dshwang
2015/08/12 08:06:09
good point! I add filter setup in SetUp()
|
| + glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| + |
| + // ANGLE crashes on glReadPixels() except for CUBE_MAP_POSITIVE_X. |
| + GLTestHelper::CheckPixels(0, 0, width_, width_, 0, pixels_); |
| + EXPECT_TRUE(GL_NO_ERROR == glGetError()); |
| +} |
| + |
| +} // namespace gpu |