Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: gpu/command_buffer/tests/gl_cube_map_texture_unittest.cc

Issue 1286193008: Reland of "gpu: workaround force_cube_map_positive_x_allocation fixes Android crash." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ANGLE to workaround Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 TEST_P(GLCubeMapTextureTest, ReadPixelsFromIncompleteCubeTexture) {
106 GLenum cube_map_target = GetParam();
107
108 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_);
109 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
110
111 glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA,
112 GL_UNSIGNED_BYTE, pixels_);
113 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
114
115 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_);
116 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target,
117 texture_, 0);
118
119 // force_gl_finish_after_compositing workaround prevents Nexus 5 crash.
120 // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889
121 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
122
123 // Check that FB is complete.
124 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
125 glCheckFramebufferStatus(GL_FRAMEBUFFER));
dshwang 2015/08/19 08:10:38 FBO should be complete even if texture isn't cube
126
127 GLTestHelper::CheckPixels(0, 0, width_, width_, 0, pixels_);
128 EXPECT_TRUE(GL_NO_ERROR == glGetError());
129 }
130
131 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698