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

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

Issue 732423002: Update from chromium https://crrev.com/304586 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « gpu/command_buffer/service/query_manager.cc ('k') | gpu/command_buffer/tests/gl_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #ifndef GL_GLEXT_PROTOTYPES
6 #define GL_GLEXT_PROTOTYPES
7 #endif
8
9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h>
11 #include <GLES2/gl2extchromium.h>
12
13 #include <vector>
14
15 #include "base/command_line.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "gpu/command_buffer/service/gpu_switches.h"
18 #include "gpu/command_buffer/tests/gl_manager.h"
19 #include "gpu/command_buffer/tests/gl_test_utils.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 namespace gpu {
24
25 // A collection of tests that exercise the glClear workaround.
26 class GLClearFramebufferTest : public testing::TestWithParam<bool> {
27 public:
28 GLClearFramebufferTest() : color_handle_(0u), depth_handle_(0u) {}
29
30 protected:
31 void SetUp() override {
32 if (GetParam()) {
33 // Force the glClear() workaround so we can test it here.
34 CommandLine command_line(base::CommandLine::NO_PROGRAM);
35 command_line.AppendSwitchASCII(switches::kGpuDriverBugWorkarounds,
36 base::IntToString(gpu::GL_CLEAR_BROKEN));
37 gl_.InitializeWithCommandLine(GLManager::Options(), &command_line);
38 DCHECK(gl_.workarounds().gl_clear_broken);
39 } else {
40 gl_.Initialize(GLManager::Options());
41 DCHECK(!gl_.workarounds().gl_clear_broken);
42 }
43 }
44
45 void InitDraw();
46 void SetDrawColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
47 void SetDrawDepth(GLfloat depth);
48 void DrawQuad();
49
50 void TearDown() override {
51 GLTestHelper::CheckGLError("no errors", __LINE__);
52 gl_.Destroy();
53 }
54
55 private:
56 GLManager gl_;
57 GLuint color_handle_;
58 GLuint depth_handle_;
59 };
60
61 void GLClearFramebufferTest::InitDraw() {
62 static const char* v_shader_str =
63 "attribute vec4 a_Position;\n"
64 "uniform float u_depth;\n"
65 "void main()\n"
66 "{\n"
67 " gl_Position = a_Position;\n"
68 " gl_Position.z = u_depth;\n"
69 "}\n";
70 static const char* f_shader_str =
71 "precision mediump float;\n"
72 "uniform vec4 u_draw_color;\n"
73 "void main()\n"
74 "{\n"
75 " gl_FragColor = u_draw_color;\n"
76 "}\n";
77
78 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str);
79 DCHECK(program);
80 glUseProgram(program);
81 GLuint position_loc = glGetAttribLocation(program, "a_Position");
82
83 GLTestHelper::SetupUnitQuad(position_loc);
84 color_handle_ = glGetUniformLocation(program, "u_draw_color");
85 DCHECK(color_handle_ != static_cast<GLuint>(-1));
86 depth_handle_ = glGetUniformLocation(program, "u_depth");
87 DCHECK(depth_handle_ != static_cast<GLuint>(-1));
88 }
89
90 void GLClearFramebufferTest::SetDrawColor(GLfloat r,
91 GLfloat g,
92 GLfloat b,
93 GLfloat a) {
94 glUniform4f(color_handle_, r, g, b, a);
95 }
96
97 void GLClearFramebufferTest::SetDrawDepth(GLfloat depth) {
98 glUniform1f(depth_handle_, depth);
99 }
100
101 void GLClearFramebufferTest::DrawQuad() {
102 glDrawArrays(GL_TRIANGLES, 0, 6);
103 }
104
105 INSTANTIATE_TEST_CASE_P(GLClearFramebufferTestWithParam,
106 GLClearFramebufferTest,
107 ::testing::Values(true, false));
108
109 TEST_P(GLClearFramebufferTest, ClearColor) {
110 glClearColor(1.0f, 0.5f, 0.25f, 0.5f);
111 glClear(GL_COLOR_BUFFER_BIT);
112
113 // Verify.
114 const uint8 expected[] = {255, 128, 64, 128};
115 EXPECT_TRUE(
116 GLTestHelper::CheckPixels(0, 0, 1, 1, 1 /* tolerance */, expected));
117 }
118
119 TEST_P(GLClearFramebufferTest, ClearColorWithMask) {
120 glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
121 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
122 glClear(GL_COLOR_BUFFER_BIT);
123
124 // Verify.
125 const uint8 expected[] = {255, 0, 0, 0};
126 EXPECT_TRUE(
127 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, expected));
128 }
129
130 // crbug.com/434094
131 #if !defined(OS_MACOSX)
132 TEST_P(GLClearFramebufferTest, ClearColorWithScissor) {
133 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
134 glClear(GL_COLOR_BUFFER_BIT);
135
136 // Verify.
137 const uint8 expected[] = {255, 255, 255, 255};
138 EXPECT_TRUE(
139 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, expected));
140
141 glScissor(0, 0, 0, 0);
142 glEnable(GL_SCISSOR_TEST);
143 glClearColor(0, 0, 0, 0);
144 glClear(GL_COLOR_BUFFER_BIT);
145
146 // Verify - no changes.
147 EXPECT_TRUE(
148 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, expected));
149 }
150 #endif
151
152 TEST_P(GLClearFramebufferTest, ClearDepthStencil) {
153 const GLuint kStencilRef = 1 << 2;
154 InitDraw();
155 SetDrawColor(1.0f, 0.0f, 0.0f, 1.0f);
156 DrawQuad();
157 // Verify.
158 const uint8 kRed[] = {255, 0, 0, 255};
159 const uint8 kGreen[] = {0, 255, 0, 255};
160 EXPECT_TRUE(
161 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, kRed));
162
163 glClearStencil(kStencilRef);
164 glClear(GL_STENCIL_BUFFER_BIT);
165 glEnable(GL_STENCIL_TEST);
166 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
167 glStencilFunc(GL_NOTEQUAL, kStencilRef, 0xFFFFFFFF);
168
169 SetDrawColor(0.0f, 1.0f, 0.0f, 1.0f);
170 DrawQuad();
171 // Verify - stencil should have failed, so still red.
172 EXPECT_TRUE(
173 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, kRed));
174
175 glStencilFunc(GL_EQUAL, kStencilRef, 0xFFFFFFFF);
176 DrawQuad();
177 // Verify - stencil should have passed, so green.
178 EXPECT_TRUE(
179 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, kGreen));
180
181 glEnable(GL_DEPTH_TEST);
182 glClearDepthf(0.0f);
183 glClear(GL_DEPTH_BUFFER_BIT);
184
185 SetDrawDepth(0.5f);
186 SetDrawColor(1.0f, 0.0f, 0.0f, 1.0f);
187 DrawQuad();
188 // Verify - depth test should have failed, so still green.
189 EXPECT_TRUE(
190 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, kGreen));
191
192 glClearDepthf(0.9f);
193 glClear(GL_DEPTH_BUFFER_BIT);
194 DrawQuad();
195 // Verify - depth test should have passed, so red.
196 EXPECT_TRUE(
197 GLTestHelper::CheckPixels(0, 0, 1, 1, 0 /* tolerance */, kRed));
198 }
199
200 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/query_manager.cc ('k') | gpu/command_buffer/tests/gl_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698