Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_drawing.cc
blob932e85116d531025bcb735178f67d760d46476b3
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.
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
12 #include "gpu/command_buffer/service/context_group.h"
13 #include "gpu/command_buffer/service/context_state.h"
14 #include "gpu/command_buffer/service/gl_surface_mock.h"
15 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
17 #include "gpu/command_buffer/service/image_manager.h"
18 #include "gpu/command_buffer/service/mailbox_manager.h"
19 #include "gpu/command_buffer/service/mocks.h"
20 #include "gpu/command_buffer/service/program_manager.h"
21 #include "gpu/command_buffer/service/test_helper.h"
22 #include "gpu/config/gpu_switches.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/gl/gl_implementation.h"
25 #include "ui/gl/gl_mock.h"
26 #include "ui/gl/gl_surface_stub.h"
28 #if !defined(GL_DEPTH24_STENCIL8)
29 #define GL_DEPTH24_STENCIL8 0x88F0
30 #endif
32 using ::gfx::MockGLInterface;
33 using ::testing::_;
34 using ::testing::DoAll;
35 using ::testing::InSequence;
36 using ::testing::Invoke;
37 using ::testing::MatcherCast;
38 using ::testing::Mock;
39 using ::testing::Pointee;
40 using ::testing::Return;
41 using ::testing::SaveArg;
42 using ::testing::SetArrayArgument;
43 using ::testing::SetArgumentPointee;
44 using ::testing::SetArgPointee;
45 using ::testing::StrEq;
46 using ::testing::StrictMock;
48 namespace gpu {
49 namespace gles2 {
51 using namespace cmds;
53 class GLES2DecoderGeometryInstancingTest : public GLES2DecoderWithShaderTest {
54 public:
55 GLES2DecoderGeometryInstancingTest() : GLES2DecoderWithShaderTest() {}
57 void SetUp() override {
58 InitState init;
59 init.extensions = "GL_ANGLE_instanced_arrays";
60 // Most of the tests in this file assume they're running on
61 // desktop OpenGL, and large portions of the tests will become
62 // no-ops if they aren't.
63 init.gl_version = "opengl 2.1";
64 init.has_alpha = true;
65 init.has_depth = true;
66 init.request_alpha = true;
67 init.request_depth = true;
68 init.bind_generates_resource = true;
69 InitDecoder(init);
70 SetupDefaultProgram();
74 INSTANTIATE_TEST_CASE_P(Service,
75 GLES2DecoderGeometryInstancingTest,
76 ::testing::Bool());
78 void GLES2DecoderManualInitTest::DirtyStateMaskTest(GLuint color_bits,
79 bool depth_mask,
80 GLuint front_stencil_mask,
81 GLuint back_stencil_mask) {
82 ColorMask color_mask_cmd;
83 color_mask_cmd.Init((color_bits & 0x1000) != 0,
84 (color_bits & 0x0100) != 0,
85 (color_bits & 0x0010) != 0,
86 (color_bits & 0x0001) != 0);
87 EXPECT_EQ(error::kNoError, ExecuteCmd(color_mask_cmd));
88 EXPECT_EQ(GL_NO_ERROR, GetGLError());
90 DepthMask depth_mask_cmd;
91 depth_mask_cmd.Init(depth_mask);
92 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_mask_cmd));
93 EXPECT_EQ(GL_NO_ERROR, GetGLError());
95 StencilMaskSeparate front_stencil_mask_cmd;
96 front_stencil_mask_cmd.Init(GL_FRONT, front_stencil_mask);
97 EXPECT_EQ(error::kNoError, ExecuteCmd(front_stencil_mask_cmd));
98 EXPECT_EQ(GL_NO_ERROR, GetGLError());
100 StencilMaskSeparate back_stencil_mask_cmd;
101 back_stencil_mask_cmd.Init(GL_BACK, back_stencil_mask);
102 EXPECT_EQ(error::kNoError, ExecuteCmd(back_stencil_mask_cmd));
103 EXPECT_EQ(GL_NO_ERROR, GetGLError());
105 SetupExpectationsForApplyingDirtyState(
106 false, // Framebuffer is RGB
107 true, // Framebuffer has depth
108 true, // Framebuffer has stencil
109 color_bits, // color bits
110 depth_mask, // depth mask
111 false, // depth enabled
112 front_stencil_mask, // front stencil mask
113 back_stencil_mask, // back stencil mask
114 false); // stencil enabled
116 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
117 .Times(1)
118 .RetiresOnSaturation();
119 DrawArrays draw_cmd;
120 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
121 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
122 EXPECT_EQ(GL_NO_ERROR, GetGLError());
125 // Test that with an RGB backbuffer if we set the color mask to 1,1,1,1 it is
126 // set to 1,1,1,0 at Draw time but is 1,1,1,1 at query time.
127 TEST_P(GLES2DecoderRGBBackbufferTest, RGBBackbufferColorMask) {
128 ColorMask cmd;
129 cmd.Init(true, true, true, true);
130 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
131 EXPECT_EQ(GL_NO_ERROR, GetGLError());
133 SetupTexture();
134 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
135 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
136 false, // Framebuffer has depth
137 false, // Framebuffer has stencil
138 0x1110, // color bits
139 false, // depth mask
140 false, // depth enabled
141 0, // front stencil mask
142 0, // back stencil mask
143 false); // stencil enabled
145 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
146 .Times(1)
147 .RetiresOnSaturation();
148 DrawArrays draw_cmd;
149 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
150 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
151 EXPECT_EQ(GL_NO_ERROR, GetGLError());
153 EXPECT_CALL(*gl_, GetError())
154 .WillOnce(Return(GL_NO_ERROR))
155 .WillOnce(Return(GL_NO_ERROR))
156 .RetiresOnSaturation();
157 typedef GetIntegerv::Result Result;
158 Result* result = static_cast<Result*>(shared_memory_address_);
159 EXPECT_CALL(*gl_, GetIntegerv(GL_COLOR_WRITEMASK, result->GetData()))
160 .Times(0);
161 result->size = 0;
162 GetIntegerv cmd2;
163 cmd2.Init(GL_COLOR_WRITEMASK, shared_memory_id_, shared_memory_offset_);
164 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
165 EXPECT_EQ(
166 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_COLOR_WRITEMASK),
167 result->GetNumResults());
168 EXPECT_EQ(GL_NO_ERROR, GetGLError());
169 EXPECT_EQ(1, result->GetData()[0]);
170 EXPECT_EQ(1, result->GetData()[1]);
171 EXPECT_EQ(1, result->GetData()[2]);
172 EXPECT_EQ(1, result->GetData()[3]);
175 // Test that with no depth if we set DepthMask true that it's set to false at
176 // draw time but querying it returns true.
177 TEST_P(GLES2DecoderRGBBackbufferTest, RGBBackbufferDepthMask) {
178 EXPECT_CALL(*gl_, DepthMask(true)).Times(0).RetiresOnSaturation();
179 DepthMask cmd;
180 cmd.Init(true);
181 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
182 EXPECT_EQ(GL_NO_ERROR, GetGLError());
184 SetupTexture();
185 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
186 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
187 false, // Framebuffer has depth
188 false, // Framebuffer has stencil
189 0x1110, // color bits
190 false, // depth mask
191 false, // depth enabled
192 0, // front stencil mask
193 0, // back stencil mask
194 false); // stencil enabled
196 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
197 .Times(1)
198 .RetiresOnSaturation();
199 DrawArrays draw_cmd;
200 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
201 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
202 EXPECT_EQ(GL_NO_ERROR, GetGLError());
204 EXPECT_CALL(*gl_, GetError())
205 .WillOnce(Return(GL_NO_ERROR))
206 .WillOnce(Return(GL_NO_ERROR))
207 .RetiresOnSaturation();
208 typedef GetIntegerv::Result Result;
209 Result* result = static_cast<Result*>(shared_memory_address_);
210 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_WRITEMASK, result->GetData()))
211 .Times(0);
212 result->size = 0;
213 GetIntegerv cmd2;
214 cmd2.Init(GL_DEPTH_WRITEMASK, shared_memory_id_, shared_memory_offset_);
215 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
216 EXPECT_EQ(
217 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_WRITEMASK),
218 result->GetNumResults());
219 EXPECT_EQ(GL_NO_ERROR, GetGLError());
220 EXPECT_EQ(1, result->GetData()[0]);
223 // Test that with no stencil if we set the stencil mask it's still set to 0 at
224 // draw time but gets our value if we query.
225 TEST_P(GLES2DecoderRGBBackbufferTest, RGBBackbufferStencilMask) {
226 const GLint kMask = 123;
227 EXPECT_CALL(*gl_, StencilMask(kMask)).Times(0).RetiresOnSaturation();
228 StencilMask cmd;
229 cmd.Init(kMask);
230 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
231 EXPECT_EQ(GL_NO_ERROR, GetGLError());
233 SetupTexture();
234 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
235 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
236 false, // Framebuffer has depth
237 false, // Framebuffer has stencil
238 0x1110, // color bits
239 false, // depth mask
240 false, // depth enabled
241 0, // front stencil mask
242 0, // back stencil mask
243 false); // stencil enabled
245 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
246 .Times(1)
247 .RetiresOnSaturation();
248 DrawArrays draw_cmd;
249 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
250 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
251 EXPECT_EQ(GL_NO_ERROR, GetGLError());
253 EXPECT_CALL(*gl_, GetError())
254 .WillOnce(Return(GL_NO_ERROR))
255 .WillOnce(Return(GL_NO_ERROR))
256 .RetiresOnSaturation();
257 typedef GetIntegerv::Result Result;
258 Result* result = static_cast<Result*>(shared_memory_address_);
259 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_WRITEMASK, result->GetData()))
260 .Times(0);
261 result->size = 0;
262 GetIntegerv cmd2;
263 cmd2.Init(GL_STENCIL_WRITEMASK, shared_memory_id_, shared_memory_offset_);
264 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
265 EXPECT_EQ(
266 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_WRITEMASK),
267 result->GetNumResults());
268 EXPECT_EQ(GL_NO_ERROR, GetGLError());
269 EXPECT_EQ(kMask, result->GetData()[0]);
272 // Test that if an FBO is bound we get the correct masks.
273 TEST_P(GLES2DecoderRGBBackbufferTest, RGBBackbufferColorMaskFBO) {
274 ColorMask cmd;
275 cmd.Init(true, true, true, true);
276 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
277 EXPECT_EQ(GL_NO_ERROR, GetGLError());
279 SetupTexture();
280 SetupVertexBuffer();
281 DoEnableVertexAttribArray(0);
282 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
283 DoEnableVertexAttribArray(1);
284 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
285 DoEnableVertexAttribArray(2);
286 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
287 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
288 false, // Framebuffer has depth
289 false, // Framebuffer has stencil
290 0x1110, // color bits
291 false, // depth mask
292 false, // depth enabled
293 0, // front stencil mask
294 0, // back stencil mask
295 false); // stencil enabled
297 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
298 .Times(1)
299 .RetiresOnSaturation();
300 DrawArrays draw_cmd;
301 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
302 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
303 EXPECT_EQ(GL_NO_ERROR, GetGLError());
305 // Check that no extra calls are made on the next draw.
306 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
307 .Times(1)
308 .RetiresOnSaturation();
309 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
310 EXPECT_EQ(GL_NO_ERROR, GetGLError());
312 // Setup Frame buffer.
313 // needs to be 1x1 or else it's not renderable.
314 const GLsizei kWidth = 1;
315 const GLsizei kHeight = 1;
316 const GLenum kFormat = GL_RGB;
317 // Use a different texture for framebuffer to avoid drawing feedback loops.
318 EXPECT_CALL(*gl_, GenTextures(_, _))
319 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
320 .RetiresOnSaturation();
321 GenHelper<cmds::GenTexturesImmediate>(kNewClientId);
322 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId);
323 // Pass some data so the texture will be marked as cleared.
324 DoTexImage2D(GL_TEXTURE_2D,
326 kFormat,
327 kWidth,
328 kHeight,
330 kFormat,
331 GL_UNSIGNED_BYTE,
332 kSharedMemoryId,
333 kSharedMemoryOffset);
334 DoBindFramebuffer(
335 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
336 DoFramebufferTexture2D(GL_FRAMEBUFFER,
337 GL_COLOR_ATTACHMENT0,
338 GL_TEXTURE_2D,
339 kNewClientId,
340 kNewServiceId,
342 GL_NO_ERROR);
343 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
344 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
345 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
346 .RetiresOnSaturation();
348 // This time state needs to be set.
349 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
350 false, // Framebuffer has depth
351 false, // Framebuffer has stencil
352 0x1110, // color bits
353 false, // depth mask
354 false, // depth enabled
355 0, // front stencil mask
356 0, // back stencil mask
357 false); // stencil enabled
359 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
360 .Times(1)
361 .RetiresOnSaturation();
362 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
363 EXPECT_EQ(GL_NO_ERROR, GetGLError());
365 // Check that no extra calls are made on the next draw.
366 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
367 .Times(1)
368 .RetiresOnSaturation();
369 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
370 EXPECT_EQ(GL_NO_ERROR, GetGLError());
372 // Unbind
373 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
375 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
376 false, // Framebuffer has depth
377 false, // Framebuffer has stencil
378 0x1110, // color bits
379 false, // depth mask
380 false, // depth enabled
381 0, // front stencil mask
382 0, // back stencil mask
383 false); // stencil enabled
385 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
386 .Times(1)
387 .RetiresOnSaturation();
388 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
389 EXPECT_EQ(GL_NO_ERROR, GetGLError());
392 TEST_P(GLES2DecoderManualInitTest, DepthEnableWithDepth) {
393 InitState init;
394 init.has_depth = true;
395 init.request_depth = true;
396 init.bind_generates_resource = true;
397 InitDecoder(init);
399 Enable cmd;
400 cmd.Init(GL_DEPTH_TEST);
401 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
402 EXPECT_EQ(GL_NO_ERROR, GetGLError());
404 SetupDefaultProgram();
405 SetupTexture();
406 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
407 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
408 true, // Framebuffer has depth
409 false, // Framebuffer has stencil
410 0x1110, // color bits
411 true, // depth mask
412 true, // depth enabled
413 0, // front stencil mask
414 0, // back stencil mask
415 false); // stencil enabled
417 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
418 .Times(1)
419 .RetiresOnSaturation();
420 DrawArrays draw_cmd;
421 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
422 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
423 EXPECT_EQ(GL_NO_ERROR, GetGLError());
425 EXPECT_CALL(*gl_, GetError())
426 .WillOnce(Return(GL_NO_ERROR))
427 .WillOnce(Return(GL_NO_ERROR))
428 .RetiresOnSaturation();
429 typedef GetIntegerv::Result Result;
430 Result* result = static_cast<Result*>(shared_memory_address_);
431 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_TEST, _))
432 .Times(0)
433 .RetiresOnSaturation();
434 result->size = 0;
435 GetIntegerv cmd2;
436 cmd2.Init(GL_DEPTH_TEST, shared_memory_id_, shared_memory_offset_);
437 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
438 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST),
439 result->GetNumResults());
440 EXPECT_EQ(GL_NO_ERROR, GetGLError());
441 EXPECT_EQ(1, result->GetData()[0]);
444 TEST_P(GLES2DecoderManualInitTest, DepthEnableWithoutRequestedDepth) {
445 InitState init;
446 init.has_depth = true;
447 init.bind_generates_resource = true;
448 InitDecoder(init);
450 Enable cmd;
451 cmd.Init(GL_DEPTH_TEST);
452 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
453 EXPECT_EQ(GL_NO_ERROR, GetGLError());
455 SetupDefaultProgram();
456 SetupTexture();
457 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
458 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
459 false, // Framebuffer has depth
460 false, // Framebuffer has stencil
461 0x1110, // color bits
462 false, // depth mask
463 false, // depth enabled
464 0, // front stencil mask
465 0, // back stencil mask
466 false); // stencil enabled
468 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
469 .Times(1)
470 .RetiresOnSaturation();
471 DrawArrays draw_cmd;
472 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
473 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
474 EXPECT_EQ(GL_NO_ERROR, GetGLError());
476 EXPECT_CALL(*gl_, GetError())
477 .WillOnce(Return(GL_NO_ERROR))
478 .WillOnce(Return(GL_NO_ERROR))
479 .RetiresOnSaturation();
480 typedef GetIntegerv::Result Result;
481 Result* result = static_cast<Result*>(shared_memory_address_);
482 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_TEST, _))
483 .Times(0)
484 .RetiresOnSaturation();
485 result->size = 0;
486 GetIntegerv cmd2;
487 cmd2.Init(GL_DEPTH_TEST, shared_memory_id_, shared_memory_offset_);
488 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
489 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST),
490 result->GetNumResults());
491 EXPECT_EQ(GL_NO_ERROR, GetGLError());
492 EXPECT_EQ(1, result->GetData()[0]);
495 TEST_P(GLES2DecoderManualInitTest, StencilEnableWithStencil) {
496 InitState init;
497 init.has_stencil = true;
498 init.request_stencil = true;
499 init.bind_generates_resource = true;
500 InitDecoder(init);
502 Enable cmd;
503 cmd.Init(GL_STENCIL_TEST);
504 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
505 EXPECT_EQ(GL_NO_ERROR, GetGLError());
507 SetupDefaultProgram();
508 SetupTexture();
509 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
510 SetupExpectationsForApplyingDirtyState(
511 true, // Framebuffer is RGB
512 false, // Framebuffer has depth
513 true, // Framebuffer has stencil
514 0x1110, // color bits
515 false, // depth mask
516 false, // depth enabled
517 GLES2Decoder::kDefaultStencilMask, // front stencil mask
518 GLES2Decoder::kDefaultStencilMask, // back stencil mask
519 true); // stencil enabled
521 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
522 .Times(1)
523 .RetiresOnSaturation();
524 DrawArrays draw_cmd;
525 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
526 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
527 EXPECT_EQ(GL_NO_ERROR, GetGLError());
529 EXPECT_CALL(*gl_, GetError())
530 .WillOnce(Return(GL_NO_ERROR))
531 .WillOnce(Return(GL_NO_ERROR))
532 .RetiresOnSaturation();
533 typedef GetIntegerv::Result Result;
534 Result* result = static_cast<Result*>(shared_memory_address_);
535 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_TEST, _))
536 .Times(0)
537 .RetiresOnSaturation();
538 result->size = 0;
539 GetIntegerv cmd2;
540 cmd2.Init(GL_STENCIL_TEST, shared_memory_id_, shared_memory_offset_);
541 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
542 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST),
543 result->GetNumResults());
544 EXPECT_EQ(GL_NO_ERROR, GetGLError());
545 EXPECT_EQ(1, result->GetData()[0]);
548 TEST_P(GLES2DecoderManualInitTest, StencilEnableWithoutRequestedStencil) {
549 InitState init;
550 init.has_stencil = true;
551 init.bind_generates_resource = true;
552 InitDecoder(init);
554 Enable cmd;
555 cmd.Init(GL_STENCIL_TEST);
556 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
557 EXPECT_EQ(GL_NO_ERROR, GetGLError());
559 SetupDefaultProgram();
560 SetupTexture();
561 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
562 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
563 false, // Framebuffer has depth
564 false, // Framebuffer has stencil
565 0x1110, // color bits
566 false, // depth mask
567 false, // depth enabled
568 0, // front stencil mask
569 0, // back stencil mask
570 false); // stencil enabled
572 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
573 .Times(1)
574 .RetiresOnSaturation();
575 DrawArrays draw_cmd;
576 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
577 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
578 EXPECT_EQ(GL_NO_ERROR, GetGLError());
580 EXPECT_CALL(*gl_, GetError())
581 .WillOnce(Return(GL_NO_ERROR))
582 .WillOnce(Return(GL_NO_ERROR))
583 .RetiresOnSaturation();
584 typedef GetIntegerv::Result Result;
585 Result* result = static_cast<Result*>(shared_memory_address_);
586 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_TEST, _))
587 .Times(0)
588 .RetiresOnSaturation();
589 result->size = 0;
590 GetIntegerv cmd2;
591 cmd2.Init(GL_STENCIL_TEST, shared_memory_id_, shared_memory_offset_);
592 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
593 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST),
594 result->GetNumResults());
595 EXPECT_EQ(GL_NO_ERROR, GetGLError());
596 EXPECT_EQ(1, result->GetData()[0]);
599 TEST_P(GLES2DecoderManualInitTest, CachedColorMask) {
600 InitState init;
601 init.has_alpha = true;
602 init.has_depth = true;
603 init.has_stencil = true;
604 init.request_alpha = true;
605 init.request_depth = true;
606 init.request_stencil = true;
607 init.bind_generates_resource = true;
608 InitDecoder(init);
610 SetupDefaultProgram();
611 SetupAllNeededVertexBuffers();
612 SetupTexture();
614 // Test all color_bits combinations twice.
615 for (int i = 0; i < 32; i++) {
616 GLuint color_bits = (i & 1 ? 0x0001 : 0x0000) | (i & 2 ? 0x0010 : 0x0000) |
617 (i & 4 ? 0x0100 : 0x0000) | (i & 8 ? 0x1000 : 0x0000);
619 // Toggle depth_test to force ApplyDirtyState each time.
620 DirtyStateMaskTest(color_bits, false, 0xffffffff, 0xffffffff);
621 DirtyStateMaskTest(color_bits, true, 0xffffffff, 0xffffffff);
622 DirtyStateMaskTest(color_bits, false, 0xffffffff, 0xffffffff);
626 TEST_P(GLES2DecoderManualInitTest, CachedDepthMask) {
627 InitState init;
628 init.has_alpha = true;
629 init.has_depth = true;
630 init.has_stencil = true;
631 init.request_alpha = true;
632 init.request_depth = true;
633 init.request_stencil = true;
634 init.bind_generates_resource = true;
635 InitDecoder(init);
637 SetupDefaultProgram();
638 SetupAllNeededVertexBuffers();
639 SetupTexture();
641 // Test all depth_mask combinations twice.
642 for (int i = 0; i < 4; i++) {
643 bool depth_mask = (i & 1) == 1;
645 // Toggle color masks to force ApplyDirtyState each time.
646 DirtyStateMaskTest(0x1010, depth_mask, 0xffffffff, 0xffffffff);
647 DirtyStateMaskTest(0x0101, depth_mask, 0xffffffff, 0xffffffff);
648 DirtyStateMaskTest(0x1010, depth_mask, 0xffffffff, 0xffffffff);
652 TEST_P(GLES2DecoderManualInitTest, CachedStencilMask) {
653 InitState init;
654 init.has_alpha = true;
655 init.has_depth = true;
656 init.has_stencil = true;
657 init.request_alpha = true;
658 init.request_depth = true;
659 init.request_stencil = true;
660 init.bind_generates_resource = true;
661 InitDecoder(init);
663 SetupDefaultProgram();
664 SetupAllNeededVertexBuffers();
665 SetupTexture();
667 // Test all stencil_mask combinations twice.
668 for (int i = 0; i < 4; i++) {
669 GLuint stencil_mask = (i & 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
671 // Toggle color masks to force ApplyDirtyState each time.
672 DirtyStateMaskTest(0x1010, true, stencil_mask, 0xffffffff);
673 DirtyStateMaskTest(0x0101, true, stencil_mask, 0xffffffff);
674 DirtyStateMaskTest(0x1010, true, stencil_mask, 0xffffffff);
677 for (int i = 0; i < 4; i++) {
678 GLuint stencil_mask = (i & 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
680 // Toggle color masks to force ApplyDirtyState each time.
681 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask);
682 DirtyStateMaskTest(0x0101, true, 0xffffffff, stencil_mask);
683 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask);
687 TEST_P(GLES2DecoderWithShaderTest, DrawArraysNoAttributesSucceeds) {
688 SetupTexture();
689 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
690 SetupExpectationsForApplyingDefaultDirtyState();
692 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
693 .Times(1)
694 .RetiresOnSaturation();
695 DrawArrays cmd;
696 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
697 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
698 EXPECT_EQ(GL_NO_ERROR, GetGLError());
701 // Tests when the math overflows (0x40000000 * sizeof GLfloat)
702 TEST_P(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OverflowFails) {
703 const GLsizei kLargeCount = 0x40000000;
704 SetupTexture();
705 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
706 DrawArrays cmd;
707 cmd.Init(GL_TRIANGLES, 0, kLargeCount);
708 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
709 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
710 EXPECT_FALSE(GetDecoder()->WasContextLost());
713 // Tests when the math overflows (0x7FFFFFFF + 1 = 0x8000000 verts)
714 TEST_P(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0PosToNegFails) {
715 const GLsizei kLargeCount = 0x7FFFFFFF;
716 SetupTexture();
717 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
718 DrawArrays cmd;
719 cmd.Init(GL_TRIANGLES, 0, kLargeCount);
720 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
721 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
722 EXPECT_FALSE(GetDecoder()->WasContextLost());
725 // Tests when the driver returns an error
726 TEST_P(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OOMFails) {
727 const GLsizei kFakeLargeCount = 0x1234;
728 SetupTexture();
729 AddExpectationsForSimulatedAttrib0WithError(
730 kFakeLargeCount, 0, GL_OUT_OF_MEMORY);
731 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
732 DrawArrays cmd;
733 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount);
734 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
735 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
736 EXPECT_FALSE(GetDecoder()->WasContextLost());
739 TEST_P(GLES2DecoderWithShaderTest, DrawArraysBadTextureUsesBlack) {
740 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
741 // This is an NPOT texture. As the default filtering requires mips
742 // this should trigger replacing with black textures before rendering.
743 DoTexImage2D(GL_TEXTURE_2D,
745 GL_RGBA,
749 GL_RGBA,
750 GL_UNSIGNED_BYTE,
751 kSharedMemoryId,
752 kSharedMemoryOffset);
753 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
755 InSequence sequence;
756 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
757 .Times(1)
758 .RetiresOnSaturation();
759 EXPECT_CALL(
760 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceBlackTexture2dId))
761 .Times(1)
762 .RetiresOnSaturation();
763 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
764 .Times(1)
765 .RetiresOnSaturation();
766 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
767 .Times(1)
768 .RetiresOnSaturation();
769 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
770 .Times(1)
771 .RetiresOnSaturation();
772 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
773 .Times(1)
774 .RetiresOnSaturation();
776 SetupExpectationsForApplyingDefaultDirtyState();
777 DrawArrays cmd;
778 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
779 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
780 EXPECT_EQ(GL_NO_ERROR, GetGLError());
783 TEST_P(GLES2DecoderWithShaderTest, DrawArraysMissingAttributesFails) {
784 DoEnableVertexAttribArray(1);
786 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
787 DrawArrays cmd;
788 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
789 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
790 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
793 TEST_P(GLES2DecoderWithShaderTest,
794 DrawArraysMissingAttributesZeroCountSucceeds) {
795 DoEnableVertexAttribArray(1);
797 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
798 DrawArrays cmd;
799 cmd.Init(GL_TRIANGLES, 0, 0);
800 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
801 EXPECT_EQ(GL_NO_ERROR, GetGLError());
804 TEST_P(GLES2DecoderWithShaderTest, DrawArraysValidAttributesSucceeds) {
805 SetupTexture();
806 SetupVertexBuffer();
807 DoEnableVertexAttribArray(1);
808 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
809 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
810 SetupExpectationsForApplyingDefaultDirtyState();
812 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
813 .Times(1)
814 .RetiresOnSaturation();
815 DrawArrays cmd;
816 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
817 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
818 EXPECT_EQ(GL_NO_ERROR, GetGLError());
821 // Same as DrawArraysValidAttributesSucceeds, but with workaround
822 // |init_vertex_attributes|.
823 TEST_P(GLES2DecoderManualInitTest, InitVertexAttributes) {
824 base::CommandLine command_line(0, NULL);
825 command_line.AppendSwitchASCII(
826 switches::kGpuDriverBugWorkarounds,
827 base::IntToString(gpu::INIT_VERTEX_ATTRIBUTES));
828 InitState init;
829 init.has_alpha = true;
830 init.has_depth = true;
831 init.request_alpha = true;
832 init.request_depth = true;
833 init.bind_generates_resource = true;
834 InitDecoderWithCommandLine(init, &command_line);
835 SetupDefaultProgram();
836 SetupTexture();
837 SetupVertexBuffer();
838 DoEnableVertexAttribArray(1);
839 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
840 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
841 SetupExpectationsForApplyingDefaultDirtyState();
843 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
844 .Times(1)
845 .RetiresOnSaturation();
846 DrawArrays cmd;
847 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
848 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
849 EXPECT_EQ(GL_NO_ERROR, GetGLError());
852 TEST_P(GLES2DecoderWithShaderTest, DrawArraysDeletedBufferFails) {
853 SetupVertexBuffer();
854 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
855 DeleteVertexBuffer();
857 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
858 DrawArrays cmd;
859 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
860 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
861 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
864 TEST_P(GLES2DecoderWithShaderTest, DrawArraysDeletedProgramSucceeds) {
865 SetupTexture();
866 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
867 SetupExpectationsForApplyingDefaultDirtyState();
868 DoDeleteProgram(client_program_id_, kServiceProgramId);
870 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(1).RetiresOnSaturation();
871 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId)).Times(1);
872 DrawArrays cmd;
873 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
874 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
875 EXPECT_EQ(GL_NO_ERROR, GetGLError());
878 TEST_P(GLES2DecoderWithShaderTest, DrawArraysWithInvalidModeFails) {
879 SetupVertexBuffer();
880 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
882 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
883 DrawArrays cmd;
884 cmd.Init(GL_QUADS, 0, 1);
885 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
886 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
887 cmd.Init(GL_POLYGON, 0, 1);
888 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
889 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
892 TEST_P(GLES2DecoderWithShaderTest, DrawArraysInvalidCountFails) {
893 SetupVertexBuffer();
894 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
896 // Try start > 0
897 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
898 DrawArrays cmd;
899 cmd.Init(GL_TRIANGLES, 1, kNumVertices);
900 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
901 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
902 EXPECT_EQ(GL_NO_ERROR, GetGLError());
904 // Try with count > size
905 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1);
906 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
907 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
908 EXPECT_EQ(GL_NO_ERROR, GetGLError());
910 // Try with attrib offset > 0
911 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
912 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 4);
913 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
914 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
915 EXPECT_EQ(GL_NO_ERROR, GetGLError());
917 // Try with size > 2 (ie, vec3 instead of vec2)
918 DoVertexAttribPointer(1, 3, GL_FLOAT, 0, 0);
919 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
920 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
921 EXPECT_EQ(GL_NO_ERROR, GetGLError());
923 // Try with stride > 8 (vec2 + vec2 byte)
924 DoVertexAttribPointer(1, 2, GL_FLOAT, sizeof(GLfloat) * 3, 0);
925 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
926 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
927 EXPECT_EQ(GL_NO_ERROR, GetGLError());
930 TEST_P(GLES2DecoderWithShaderTest, DrawArraysInstancedANGLEFails) {
931 SetupTexture();
932 SetupVertexBuffer();
933 DoEnableVertexAttribArray(1);
934 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
936 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
937 .Times(0)
938 .RetiresOnSaturation();
939 DrawArraysInstancedANGLE cmd;
940 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
941 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
942 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
945 TEST_P(GLES2DecoderWithShaderTest, VertexAttribDivisorANGLEFails) {
946 SetupTexture();
947 SetupVertexBuffer();
948 DoEnableVertexAttribArray(1);
949 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
951 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(_, _))
952 .Times(0)
953 .RetiresOnSaturation();
955 VertexAttribDivisorANGLE cmd;
956 cmd.Init(0, 1);
957 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
958 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
961 TEST_P(GLES2DecoderGeometryInstancingTest,
962 DrawArraysInstancedANGLENoAttributesFails) {
963 SetupTexture();
965 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
966 .Times(0)
967 .RetiresOnSaturation();
968 DrawArraysInstancedANGLE cmd;
969 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
970 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
971 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
974 TEST_P(GLES2DecoderGeometryInstancingTest,
975 DrawArraysInstancedANGLESimulatedAttrib0) {
976 SetupTexture();
977 SetupVertexBuffer();
978 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
980 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
981 SetupExpectationsForApplyingDefaultDirtyState();
983 DoVertexAttribDivisorANGLE(0, 1);
984 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 3))
985 .Times(1)
986 .RetiresOnSaturation();
987 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
988 .Times(1)
989 .RetiresOnSaturation();
990 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
991 .Times(1)
992 .RetiresOnSaturation();
993 DrawArraysInstancedANGLE cmd;
994 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 3);
995 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
996 EXPECT_EQ(GL_NO_ERROR, GetGLError());
999 TEST_P(GLES2DecoderGeometryInstancingTest,
1000 DrawArraysInstancedANGLEMissingAttributesFails) {
1001 DoEnableVertexAttribArray(1);
1003 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1004 DrawArraysInstancedANGLE cmd;
1005 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1006 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1007 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1010 TEST_P(GLES2DecoderGeometryInstancingTest,
1011 DrawArraysInstancedANGLEMissingAttributesZeroCountSucceeds) {
1012 DoEnableVertexAttribArray(1);
1014 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1015 DrawArraysInstancedANGLE cmd;
1016 cmd.Init(GL_TRIANGLES, 0, 0, 1);
1017 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1018 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1021 TEST_P(GLES2DecoderGeometryInstancingTest,
1022 DrawArraysInstancedANGLEValidAttributesSucceeds) {
1023 SetupTexture();
1024 SetupVertexBuffer();
1025 DoEnableVertexAttribArray(1);
1026 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1027 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
1028 SetupExpectationsForApplyingDefaultDirtyState();
1030 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 1))
1031 .Times(1)
1032 .RetiresOnSaturation();
1033 DrawArraysInstancedANGLE cmd;
1034 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1035 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1036 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1039 TEST_P(GLES2DecoderGeometryInstancingTest,
1040 DrawArraysInstancedANGLEWithInvalidModeFails) {
1041 SetupVertexBuffer();
1042 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1044 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1045 DrawArraysInstancedANGLE cmd;
1046 cmd.Init(GL_QUADS, 0, 1, 1);
1047 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1048 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1049 cmd.Init(GL_POLYGON, 0, 1, 1);
1050 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1051 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1054 TEST_P(GLES2DecoderGeometryInstancingTest,
1055 DrawArraysInstancedANGLEInvalidPrimcountFails) {
1056 SetupVertexBuffer();
1057 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1059 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1060 DrawArraysInstancedANGLE cmd;
1061 cmd.Init(GL_TRIANGLES, 0, 1, -1);
1062 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1063 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1066 // Per-instance data is twice as large, but number of instances is half
1067 TEST_P(GLES2DecoderGeometryInstancingTest,
1068 DrawArraysInstancedANGLELargeInstanceSucceeds) {
1069 SetupTexture();
1070 SetupVertexBuffer();
1071 SetupExpectationsForApplyingDefaultDirtyState();
1072 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1074 DoEnableVertexAttribArray(0);
1075 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1076 DoVertexAttribDivisorANGLE(0, 1);
1077 EXPECT_CALL(
1078 *gl_,
1079 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2))
1080 .Times(1)
1081 .RetiresOnSaturation();
1082 DrawArraysInstancedANGLE cmd;
1083 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2);
1084 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1085 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1088 // Regular drawArrays takes the divisor into account
1089 TEST_P(GLES2DecoderGeometryInstancingTest,
1090 DrawArraysWithDivisorSucceeds) {
1091 SetupTexture();
1092 SetupVertexBuffer();
1093 SetupExpectationsForApplyingDefaultDirtyState();
1094 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1096 DoEnableVertexAttribArray(0);
1097 // Access the data right at the end of the buffer.
1098 DoVertexAttribPointer(
1099 0, 2, GL_FLOAT, 0, (kNumVertices - 1) * 2 * sizeof(GLfloat));
1100 DoVertexAttribDivisorANGLE(0, 1);
1101 EXPECT_CALL(
1102 *gl_,
1103 DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1104 .Times(1)
1105 .RetiresOnSaturation();
1106 DrawArrays cmd;
1107 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1108 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1109 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1112 // Per-instance data is twice as large, but divisor is twice
1113 TEST_P(GLES2DecoderGeometryInstancingTest,
1114 DrawArraysInstancedANGLELargeDivisorSucceeds) {
1115 SetupTexture();
1116 SetupVertexBuffer();
1117 SetupExpectationsForApplyingDefaultDirtyState();
1118 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1120 DoEnableVertexAttribArray(0);
1121 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1122 DoVertexAttribDivisorANGLE(0, 2);
1123 EXPECT_CALL(
1124 *gl_,
1125 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices))
1126 .Times(1)
1127 .RetiresOnSaturation();
1128 DrawArraysInstancedANGLE cmd;
1129 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices);
1130 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1131 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1134 TEST_P(GLES2DecoderGeometryInstancingTest, DrawArraysInstancedANGLELargeFails) {
1135 SetupTexture();
1136 SetupVertexBuffer();
1137 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1139 DoEnableVertexAttribArray(0);
1140 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1141 DoVertexAttribDivisorANGLE(0, 1);
1142 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1143 .Times(0)
1144 .RetiresOnSaturation();
1145 DrawArraysInstancedANGLE cmd;
1146 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices + 1);
1147 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1148 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1149 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1151 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1152 .Times(0)
1153 .RetiresOnSaturation();
1154 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1, kNumVertices);
1155 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1156 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1157 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1160 // Per-index data is twice as large, but number of indices is half
1161 TEST_P(GLES2DecoderGeometryInstancingTest,
1162 DrawArraysInstancedANGLELargeIndexSucceeds) {
1163 SetupTexture();
1164 SetupVertexBuffer();
1165 SetupExpectationsForApplyingDefaultDirtyState();
1166 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
1168 DoEnableVertexAttribArray(0);
1169 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1170 DoVertexAttribDivisorANGLE(0, 1);
1171 EXPECT_CALL(
1172 *gl_,
1173 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices))
1174 .Times(1)
1175 .RetiresOnSaturation();
1176 DrawArraysInstancedANGLE cmd;
1177 cmd.Init(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices);
1178 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1179 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1182 TEST_P(GLES2DecoderGeometryInstancingTest,
1183 DrawArraysInstancedANGLENoDivisor0Fails) {
1184 SetupTexture();
1185 SetupVertexBuffer();
1186 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1188 DoEnableVertexAttribArray(0);
1189 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1190 DoVertexAttribDivisorANGLE(0, 1);
1191 DoVertexAttribDivisorANGLE(1, 1);
1192 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1193 .Times(0)
1194 .RetiresOnSaturation();
1195 DrawArraysInstancedANGLE cmd;
1196 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1197 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1198 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1199 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1202 TEST_P(GLES2DecoderGeometryInstancingTest,
1203 DrawArraysNoDivisor0Fails) {
1204 SetupTexture();
1205 SetupVertexBuffer();
1206 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1208 DoEnableVertexAttribArray(0);
1209 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1210 DoVertexAttribDivisorANGLE(0, 1);
1211 DoVertexAttribDivisorANGLE(1, 1);
1212 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
1213 .Times(0)
1214 .RetiresOnSaturation();
1215 DrawArrays cmd;
1216 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1217 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1218 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1219 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1222 TEST_P(GLES2DecoderWithShaderTest, DrawElementsNoAttributesSucceeds) {
1223 SetupTexture();
1224 SetupIndexBuffer();
1225 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
1226 SetupExpectationsForApplyingDefaultDirtyState();
1227 EXPECT_CALL(*gl_,
1228 DrawElements(GL_TRIANGLES,
1229 kValidIndexRangeCount,
1230 GL_UNSIGNED_SHORT,
1231 BufferOffset(kValidIndexRangeStart * 2)))
1232 .Times(1)
1233 .RetiresOnSaturation();
1234 DrawElements cmd;
1235 cmd.Init(GL_TRIANGLES,
1236 kValidIndexRangeCount,
1237 GL_UNSIGNED_SHORT,
1238 kValidIndexRangeStart * 2);
1239 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1240 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1243 TEST_P(GLES2DecoderWithShaderTest, DrawElementsMissingAttributesFails) {
1244 SetupIndexBuffer();
1245 DoEnableVertexAttribArray(1);
1247 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1248 DrawElements cmd;
1249 cmd.Init(GL_TRIANGLES,
1250 kValidIndexRangeCount,
1251 GL_UNSIGNED_SHORT,
1252 kValidIndexRangeStart * 2);
1253 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1254 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1257 TEST_P(GLES2DecoderWithShaderTest,
1258 DrawElementsMissingAttributesZeroCountSucceeds) {
1259 SetupIndexBuffer();
1260 DoEnableVertexAttribArray(1);
1262 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1263 DrawElements cmd;
1264 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2);
1265 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1266 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1269 TEST_P(GLES2DecoderWithShaderTest, DrawElementsExtraAttributesFails) {
1270 SetupIndexBuffer();
1271 DoEnableVertexAttribArray(6);
1273 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1274 DrawElements cmd;
1275 cmd.Init(GL_TRIANGLES,
1276 kValidIndexRangeCount,
1277 GL_UNSIGNED_SHORT,
1278 kValidIndexRangeStart * 2);
1279 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1280 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1283 TEST_P(GLES2DecoderWithShaderTest, DrawElementsValidAttributesSucceeds) {
1284 SetupTexture();
1285 SetupVertexBuffer();
1286 SetupIndexBuffer();
1287 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1288 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1289 SetupExpectationsForApplyingDefaultDirtyState();
1291 EXPECT_CALL(*gl_,
1292 DrawElements(GL_TRIANGLES,
1293 kValidIndexRangeCount,
1294 GL_UNSIGNED_SHORT,
1295 BufferOffset(kValidIndexRangeStart * 2)))
1296 .Times(1)
1297 .RetiresOnSaturation();
1298 DrawElements cmd;
1299 cmd.Init(GL_TRIANGLES,
1300 kValidIndexRangeCount,
1301 GL_UNSIGNED_SHORT,
1302 kValidIndexRangeStart * 2);
1303 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1304 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1307 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedBufferFails) {
1308 SetupVertexBuffer();
1309 SetupIndexBuffer();
1310 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1311 DeleteIndexBuffer();
1313 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1314 DrawElements cmd;
1315 cmd.Init(GL_TRIANGLES,
1316 kValidIndexRangeCount,
1317 GL_UNSIGNED_SHORT,
1318 kValidIndexRangeStart * 2);
1319 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1320 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1323 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedProgramSucceeds) {
1324 SetupTexture();
1325 SetupIndexBuffer();
1326 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
1327 SetupExpectationsForApplyingDefaultDirtyState();
1328 DoDeleteProgram(client_program_id_, kServiceProgramId);
1330 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1);
1331 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId)).Times(1);
1332 DrawElements cmd;
1333 cmd.Init(GL_TRIANGLES,
1334 kValidIndexRangeCount,
1335 GL_UNSIGNED_SHORT,
1336 kValidIndexRangeStart * 2);
1337 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1338 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1341 TEST_P(GLES2DecoderWithShaderTest, DrawElementsWithInvalidModeFails) {
1342 SetupVertexBuffer();
1343 SetupIndexBuffer();
1344 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1346 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1347 DrawElements cmd;
1348 cmd.Init(GL_QUADS,
1349 kValidIndexRangeCount,
1350 GL_UNSIGNED_SHORT,
1351 kValidIndexRangeStart * 2);
1352 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1353 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1354 cmd.Init(GL_POLYGON,
1355 kValidIndexRangeCount,
1356 GL_UNSIGNED_SHORT,
1357 kValidIndexRangeStart);
1358 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1359 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1362 TEST_P(GLES2DecoderWithShaderTest, DrawElementsInvalidCountFails) {
1363 SetupVertexBuffer();
1364 SetupIndexBuffer();
1365 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1367 // Try start > 0
1368 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1369 DrawElements cmd;
1370 cmd.Init(GL_TRIANGLES, kNumIndices, GL_UNSIGNED_SHORT, 2);
1371 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1372 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1373 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1375 // Try with count > size
1376 cmd.Init(GL_TRIANGLES, kNumIndices + 1, GL_UNSIGNED_SHORT, 0);
1377 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1378 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1379 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1382 TEST_P(GLES2DecoderWithShaderTest, DrawElementsOutOfRangeIndicesFails) {
1383 SetupVertexBuffer();
1384 SetupIndexBuffer();
1385 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1387 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1388 DrawElements cmd;
1389 cmd.Init(GL_TRIANGLES,
1390 kInvalidIndexRangeCount,
1391 GL_UNSIGNED_SHORT,
1392 kInvalidIndexRangeStart * 2);
1393 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1394 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1395 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1398 TEST_P(GLES2DecoderWithShaderTest, DrawElementsOddOffsetForUint16Fails) {
1399 SetupVertexBuffer();
1400 SetupIndexBuffer();
1401 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1403 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1404 DrawElements cmd;
1405 cmd.Init(GL_TRIANGLES, kInvalidIndexRangeCount, GL_UNSIGNED_SHORT, 1);
1406 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1407 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1408 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1411 TEST_P(GLES2DecoderWithShaderTest, DrawElementsInstancedANGLEFails) {
1412 SetupTexture();
1413 SetupVertexBuffer();
1414 SetupIndexBuffer();
1415 DoEnableVertexAttribArray(1);
1416 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1418 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1419 .Times(0)
1420 .RetiresOnSaturation();
1421 DrawElementsInstancedANGLE cmd;
1422 cmd.Init(GL_TRIANGLES,
1423 kValidIndexRangeCount,
1424 GL_UNSIGNED_SHORT,
1425 kValidIndexRangeStart * 2,
1427 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1428 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1431 TEST_P(GLES2DecoderGeometryInstancingTest,
1432 DrawElementsInstancedANGLENoAttributesFails) {
1433 SetupTexture();
1434 SetupIndexBuffer();
1436 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1437 .Times(0)
1438 .RetiresOnSaturation();
1439 DrawElementsInstancedANGLE cmd;
1440 cmd.Init(GL_TRIANGLES,
1441 kValidIndexRangeCount,
1442 GL_UNSIGNED_SHORT,
1443 kValidIndexRangeStart * 2,
1445 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1446 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1449 TEST_P(GLES2DecoderGeometryInstancingTest,
1450 DrawElementsInstancedANGLESimulatedAttrib0) {
1451 SetupTexture();
1452 SetupVertexBuffer();
1453 SetupIndexBuffer();
1454 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1456 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1457 SetupExpectationsForApplyingDefaultDirtyState();
1459 DoVertexAttribDivisorANGLE(0, 1);
1460 EXPECT_CALL(
1461 *gl_,
1462 DrawElementsInstancedANGLE(GL_TRIANGLES,
1463 kValidIndexRangeCount,
1464 GL_UNSIGNED_SHORT,
1465 BufferOffset(kValidIndexRangeStart * 2),
1467 .Times(1)
1468 .RetiresOnSaturation();
1469 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
1470 .Times(1)
1471 .RetiresOnSaturation();
1472 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
1473 .Times(1)
1474 .RetiresOnSaturation();
1475 DrawElementsInstancedANGLE cmd;
1476 cmd.Init(GL_TRIANGLES,
1477 kValidIndexRangeCount,
1478 GL_UNSIGNED_SHORT,
1479 kValidIndexRangeStart * 2,
1481 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1482 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1485 TEST_P(GLES2DecoderGeometryInstancingTest,
1486 DrawElementsInstancedANGLEMissingAttributesFails) {
1487 SetupIndexBuffer();
1488 DoEnableVertexAttribArray(1);
1490 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1491 DrawElementsInstancedANGLE cmd;
1492 cmd.Init(GL_TRIANGLES,
1493 kValidIndexRangeCount,
1494 GL_UNSIGNED_SHORT,
1495 kValidIndexRangeStart * 2,
1497 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1498 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1501 TEST_P(GLES2DecoderGeometryInstancingTest,
1502 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds) {
1503 SetupIndexBuffer();
1504 DoEnableVertexAttribArray(1);
1506 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1507 DrawElementsInstancedANGLE cmd;
1508 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2, 1);
1509 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1510 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1513 TEST_P(GLES2DecoderGeometryInstancingTest,
1514 DrawElementsInstancedANGLEValidAttributesSucceeds) {
1515 SetupIndexBuffer();
1516 SetupTexture();
1517 SetupVertexBuffer();
1518 DoEnableVertexAttribArray(1);
1519 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1520 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1521 SetupExpectationsForApplyingDefaultDirtyState();
1523 EXPECT_CALL(
1524 *gl_,
1525 DrawElementsInstancedANGLE(GL_TRIANGLES,
1526 kValidIndexRangeCount,
1527 GL_UNSIGNED_SHORT,
1528 BufferOffset(kValidIndexRangeStart * 2),
1530 .Times(1)
1531 .RetiresOnSaturation();
1532 DrawElementsInstancedANGLE cmd;
1533 cmd.Init(GL_TRIANGLES,
1534 kValidIndexRangeCount,
1535 GL_UNSIGNED_SHORT,
1536 kValidIndexRangeStart * 2,
1538 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1539 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1542 TEST_P(GLES2DecoderGeometryInstancingTest,
1543 DrawElementsInstancedANGLEWithInvalidModeFails) {
1544 SetupIndexBuffer();
1545 SetupVertexBuffer();
1546 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1548 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1549 DrawElementsInstancedANGLE cmd;
1550 cmd.Init(GL_QUADS,
1551 kValidIndexRangeCount,
1552 GL_UNSIGNED_SHORT,
1553 kValidIndexRangeStart * 2,
1555 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1556 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1557 cmd.Init(GL_INVALID_ENUM,
1558 kValidIndexRangeCount,
1559 GL_UNSIGNED_SHORT,
1560 kValidIndexRangeStart * 2,
1562 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1563 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1566 // Per-instance data is twice as large, but number of instances is half
1567 TEST_P(GLES2DecoderGeometryInstancingTest,
1568 DrawElementsInstancedANGLELargeInstanceSucceeds) {
1569 SetupTexture();
1570 SetupIndexBuffer();
1571 SetupVertexBuffer();
1572 SetupExpectationsForApplyingDefaultDirtyState();
1573 // Add offset so we're sure we're accessing data near the end of the buffer.
1574 DoVertexAttribPointer(
1577 GL_FLOAT,
1579 (kNumVertices - kMaxValidIndex - 1) * 2 * sizeof(GLfloat));
1581 DoEnableVertexAttribArray(0);
1582 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1583 DoVertexAttribDivisorANGLE(0, 1);
1584 EXPECT_CALL(
1585 *gl_,
1586 DrawElementsInstancedANGLE(GL_TRIANGLES,
1587 kValidIndexRangeCount,
1588 GL_UNSIGNED_SHORT,
1589 BufferOffset(kValidIndexRangeStart * 2),
1590 kNumVertices / 2))
1591 .Times(1)
1592 .RetiresOnSaturation();
1593 DrawElementsInstancedANGLE cmd;
1594 cmd.Init(GL_TRIANGLES,
1595 kValidIndexRangeCount,
1596 GL_UNSIGNED_SHORT,
1597 kValidIndexRangeStart * 2,
1598 kNumVertices / 2);
1599 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1600 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1603 // Regular drawElements takes the divisor into account
1604 TEST_P(GLES2DecoderGeometryInstancingTest,
1605 DrawElementsWithDivisorSucceeds) {
1606 SetupTexture();
1607 SetupIndexBuffer();
1608 SetupVertexBuffer();
1609 SetupExpectationsForApplyingDefaultDirtyState();
1610 // Add offset so we're sure we're accessing data near the end of the buffer.
1611 DoVertexAttribPointer(
1614 GL_FLOAT,
1616 (kNumVertices - kMaxValidIndex - 1) * 2 * sizeof(GLfloat));
1618 DoEnableVertexAttribArray(0);
1619 // Access the data right at the end of the buffer.
1620 DoVertexAttribPointer(
1621 0, 2, GL_FLOAT, 0, (kNumVertices - 1) * 2 * sizeof(GLfloat));
1622 DoVertexAttribDivisorANGLE(0, 1);
1623 EXPECT_CALL(
1624 *gl_,
1625 DrawElements(GL_TRIANGLES,
1626 kValidIndexRangeCount,
1627 GL_UNSIGNED_SHORT,
1628 BufferOffset(kValidIndexRangeStart * 2)))
1629 .Times(1)
1630 .RetiresOnSaturation();
1631 DrawElements cmd;
1632 cmd.Init(GL_TRIANGLES,
1633 kValidIndexRangeCount,
1634 GL_UNSIGNED_SHORT,
1635 kValidIndexRangeStart * 2);
1636 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1637 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1640 // Per-instance data is twice as large, but divisor is twice
1641 TEST_P(GLES2DecoderGeometryInstancingTest,
1642 DrawElementsInstancedANGLELargeDivisorSucceeds) {
1643 SetupTexture();
1644 SetupIndexBuffer();
1645 SetupVertexBuffer();
1646 SetupExpectationsForApplyingDefaultDirtyState();
1647 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1649 DoEnableVertexAttribArray(0);
1650 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1651 DoVertexAttribDivisorANGLE(0, 2);
1652 EXPECT_CALL(
1653 *gl_,
1654 DrawElementsInstancedANGLE(GL_TRIANGLES,
1655 kValidIndexRangeCount,
1656 GL_UNSIGNED_SHORT,
1657 BufferOffset(kValidIndexRangeStart * 2),
1658 kNumVertices))
1659 .Times(1)
1660 .RetiresOnSaturation();
1661 DrawElementsInstancedANGLE cmd;
1662 cmd.Init(GL_TRIANGLES,
1663 kValidIndexRangeCount,
1664 GL_UNSIGNED_SHORT,
1665 kValidIndexRangeStart * 2,
1666 kNumVertices);
1667 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1668 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1671 TEST_P(GLES2DecoderGeometryInstancingTest,
1672 DrawElementsInstancedANGLELargeFails) {
1673 SetupTexture();
1674 SetupIndexBuffer();
1675 SetupVertexBuffer();
1676 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1678 DoEnableVertexAttribArray(0);
1679 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1680 DoVertexAttribDivisorANGLE(0, 1);
1681 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1682 .Times(0)
1683 .RetiresOnSaturation();
1684 DrawElementsInstancedANGLE cmd;
1685 cmd.Init(GL_TRIANGLES,
1686 kValidIndexRangeCount,
1687 GL_UNSIGNED_SHORT,
1688 kValidIndexRangeStart * 2,
1689 kNumVertices + 1);
1690 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1691 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1692 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1694 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1695 .Times(0)
1696 .RetiresOnSaturation();
1697 cmd.Init(GL_TRIANGLES,
1698 kInvalidIndexRangeCount,
1699 GL_UNSIGNED_SHORT,
1700 kInvalidIndexRangeStart * 2,
1701 kNumVertices);
1702 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1703 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1704 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1707 TEST_P(GLES2DecoderGeometryInstancingTest,
1708 DrawElementsInstancedANGLEInvalidPrimcountFails) {
1709 SetupTexture();
1710 SetupIndexBuffer();
1711 SetupVertexBuffer();
1712 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1714 DoEnableVertexAttribArray(0);
1715 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1716 DoVertexAttribDivisorANGLE(0, 1);
1717 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1718 .Times(0)
1719 .RetiresOnSaturation();
1720 DrawElementsInstancedANGLE cmd;
1721 cmd.Init(GL_TRIANGLES,
1722 kValidIndexRangeCount,
1723 GL_UNSIGNED_SHORT,
1724 kValidIndexRangeStart * 2,
1725 -1);
1726 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1727 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1728 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1731 // Per-index data is twice as large, but values of indices are smaller
1732 TEST_P(GLES2DecoderGeometryInstancingTest,
1733 DrawElementsInstancedANGLELargeIndexSucceeds) {
1734 SetupTexture();
1735 SetupIndexBuffer();
1736 SetupVertexBuffer();
1737 SetupExpectationsForApplyingDefaultDirtyState();
1738 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
1740 DoEnableVertexAttribArray(0);
1741 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1742 DoVertexAttribDivisorANGLE(0, 1);
1743 EXPECT_CALL(
1744 *gl_,
1745 DrawElementsInstancedANGLE(GL_TRIANGLES,
1746 kValidIndexRangeCount,
1747 GL_UNSIGNED_SHORT,
1748 BufferOffset(kValidIndexRangeStart * 2),
1749 kNumVertices))
1750 .Times(1)
1751 .RetiresOnSaturation();
1752 DrawElementsInstancedANGLE cmd;
1753 cmd.Init(GL_TRIANGLES,
1754 kValidIndexRangeCount,
1755 GL_UNSIGNED_SHORT,
1756 kValidIndexRangeStart * 2,
1757 kNumVertices);
1758 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1759 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1762 TEST_P(GLES2DecoderGeometryInstancingTest,
1763 DrawElementsInstancedANGLENoDivisor0Fails) {
1764 SetupTexture();
1765 SetupIndexBuffer();
1766 SetupVertexBuffer();
1767 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1769 DoEnableVertexAttribArray(0);
1770 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1771 DoVertexAttribDivisorANGLE(0, 1);
1772 DoVertexAttribDivisorANGLE(1, 1);
1773 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1774 .Times(0)
1775 .RetiresOnSaturation();
1776 DrawElementsInstancedANGLE cmd;
1777 cmd.Init(GL_TRIANGLES,
1778 kValidIndexRangeCount,
1779 GL_UNSIGNED_SHORT,
1780 kValidIndexRangeStart * 2,
1781 kNumVertices);
1782 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1783 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1784 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1787 TEST_P(GLES2DecoderGeometryInstancingTest,
1788 DrawElementsNoDivisor0Fails) {
1789 SetupTexture();
1790 SetupIndexBuffer();
1791 SetupVertexBuffer();
1792 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1794 DoEnableVertexAttribArray(0);
1795 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1796 DoVertexAttribDivisorANGLE(0, 1);
1797 DoVertexAttribDivisorANGLE(1, 1);
1798 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
1799 .Times(0)
1800 .RetiresOnSaturation();
1801 DrawElements cmd;
1802 cmd.Init(GL_TRIANGLES,
1803 kValidIndexRangeCount,
1804 GL_UNSIGNED_SHORT,
1805 kValidIndexRangeStart * 2);
1806 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1807 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1808 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1811 TEST_P(GLES2DecoderWithShaderTest, DrawArraysClearsAfterTexImage2DNULL) {
1812 SetupAllNeededVertexBuffers();
1813 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1814 // Create an uncleared texture with 2 levels.
1815 DoTexImage2D(
1816 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1817 DoTexImage2D(
1818 GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1819 // Expect 2 levels will be cleared.
1820 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
1821 GL_TEXTURE_2D, GL_TEXTURE_2D, 0, GL_RGBA,
1822 GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 2, 2);
1823 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
1824 GL_TEXTURE_2D, GL_TEXTURE_2D, 1, GL_RGBA,
1825 GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 1, 1);
1826 SetupExpectationsForApplyingDefaultDirtyState();
1827 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1828 .Times(1)
1829 .RetiresOnSaturation();
1830 DrawArrays cmd;
1831 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1832 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1833 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1835 // But not again
1836 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1837 .Times(1)
1838 .RetiresOnSaturation();
1839 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1840 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1843 TEST_P(GLES2DecoderWithShaderTest, DrawElementsClearsAfterTexImage2DNULL) {
1844 SetupAllNeededVertexBuffers();
1845 SetupIndexBuffer();
1846 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1847 // Create an uncleared texture with 2 levels.
1848 DoTexImage2D(
1849 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1850 DoTexImage2D(
1851 GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1852 // Expect 2 levels will be cleared.
1853 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
1854 GL_TEXTURE_2D, GL_TEXTURE_2D, 0, GL_RGBA,
1855 GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 2, 2);
1856 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
1857 GL_TEXTURE_2D, GL_TEXTURE_2D, 1, GL_RGBA,
1858 GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 1, 1);
1859 SetupExpectationsForApplyingDefaultDirtyState();
1861 EXPECT_CALL(*gl_,
1862 DrawElements(GL_TRIANGLES,
1863 kValidIndexRangeCount,
1864 GL_UNSIGNED_SHORT,
1865 BufferOffset(kValidIndexRangeStart * 2)))
1866 .Times(1)
1867 .RetiresOnSaturation();
1868 DrawElements cmd;
1869 cmd.Init(GL_TRIANGLES,
1870 kValidIndexRangeCount,
1871 GL_UNSIGNED_SHORT,
1872 kValidIndexRangeStart * 2);
1873 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1874 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1876 // But not again
1877 EXPECT_CALL(*gl_,
1878 DrawElements(GL_TRIANGLES,
1879 kValidIndexRangeCount,
1880 GL_UNSIGNED_SHORT,
1881 BufferOffset(kValidIndexRangeStart * 2)))
1882 .Times(1)
1883 .RetiresOnSaturation();
1884 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1885 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1888 TEST_P(GLES2DecoderWithShaderTest, DrawClearsAfterTexImage2DNULLInFBO) {
1889 const GLuint kFBOClientTextureId = 4100;
1890 const GLuint kFBOServiceTextureId = 4101;
1892 SetupAllNeededVertexBuffers();
1893 // Register a texture id.
1894 EXPECT_CALL(*gl_, GenTextures(_, _))
1895 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1896 .RetiresOnSaturation();
1897 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1899 // Setup "render to" texture.
1900 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1901 DoTexImage2D(
1902 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1903 DoBindFramebuffer(
1904 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1905 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1906 GL_COLOR_ATTACHMENT0,
1907 GL_TEXTURE_2D,
1908 kFBOClientTextureId,
1909 kFBOServiceTextureId,
1911 GL_NO_ERROR);
1912 DoEnableDisable(GL_SCISSOR_TEST, false);
1913 DoScissor(0, 0, 1, 1);
1915 // Setup "render from" texture.
1916 SetupTexture();
1918 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1919 GL_COLOR_BUFFER_BIT, // clear bits
1920 0, 0, 0,
1921 0, // color
1922 0, // stencil
1923 1.0f, // depth
1924 false, // scissor test
1925 0, 0, 1, 1);
1927 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1928 false, // Framebuffer has depth
1929 false, // Framebuffer has stencil
1930 0x1111, // color bits
1931 false, // depth mask
1932 false, // depth enabled
1933 0, // front stencil mask
1934 0, // back stencil mask
1935 false); // stencil enabled
1937 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1938 .Times(1)
1939 .RetiresOnSaturation();
1940 DrawArrays cmd;
1941 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1942 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1943 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1945 // But not again.
1946 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1947 .Times(1)
1948 .RetiresOnSaturation();
1949 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1950 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1953 TEST_P(GLES2DecoderWithShaderTest, DrawWitFBOThatCantClearDoesNotDraw) {
1954 const GLuint kFBOClientTextureId = 4100;
1955 const GLuint kFBOServiceTextureId = 4101;
1957 // Register a texture id.
1958 EXPECT_CALL(*gl_, GenTextures(_, _))
1959 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1960 .RetiresOnSaturation();
1961 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1963 // Setup "render to" texture.
1964 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1965 DoTexImage2D(
1966 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1967 DoBindFramebuffer(
1968 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1969 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1970 GL_COLOR_ATTACHMENT0,
1971 GL_TEXTURE_2D,
1972 kFBOClientTextureId,
1973 kFBOServiceTextureId,
1975 GL_NO_ERROR);
1977 // Setup "render from" texture.
1978 SetupTexture();
1980 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
1981 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED))
1982 .RetiresOnSaturation();
1983 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
1984 DrawArrays cmd;
1985 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1986 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1987 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
1990 TEST_P(GLES2DecoderWithShaderTest, DrawClearsAfterRenderbufferStorageInFBO) {
1991 SetupTexture();
1992 DoBindRenderbuffer(
1993 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1994 DoBindFramebuffer(
1995 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1996 DoRenderbufferStorage(
1997 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 100, 50, GL_NO_ERROR);
1998 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1999 GL_COLOR_ATTACHMENT0,
2000 GL_RENDERBUFFER,
2001 client_renderbuffer_id_,
2002 kServiceRenderbufferId,
2003 GL_NO_ERROR);
2004 DoEnableDisable(GL_SCISSOR_TEST, false);
2005 DoScissor(0, 0, 1, 1);
2007 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
2008 GL_COLOR_BUFFER_BIT, // clear bits
2009 0, 0, 0,
2010 0, // color
2011 0, // stencil
2012 1.0f, // depth
2013 false, // scissor test
2014 0, 0, 1, 1);
2016 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2017 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2018 false, // Framebuffer has depth
2019 false, // Framebuffer has stencil
2020 0x1111, // color bits
2021 false, // depth mask
2022 false, // depth enabled
2023 0, // front stencil mask
2024 0, // back stencil mask
2025 false); // stencil enabled
2027 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2028 .Times(1)
2029 .RetiresOnSaturation();
2030 DrawArrays cmd;
2031 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2032 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2033 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2036 TEST_P(GLES2DecoderManualInitTest, DrawArraysClearsAfterTexImage2DNULLCubemap) {
2037 InitState init;
2038 init.gl_version = "opengl es 2.0";
2039 init.has_alpha = true;
2040 init.has_depth = true;
2041 init.request_alpha = true;
2042 init.request_depth = true;
2043 InitDecoder(init);
2045 static const GLenum faces[] = {
2046 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
2047 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2048 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
2050 SetupCubemapProgram();
2051 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2052 // Fill out all the faces for 2 levels, leave 2 uncleared.
2053 for (int ii = 0; ii < 6; ++ii) {
2054 GLenum face = faces[ii];
2055 int32 shm_id =
2056 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryId;
2057 uint32 shm_offset =
2058 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryOffset;
2059 DoTexImage2D(face,
2061 GL_RGBA,
2065 GL_RGBA,
2066 GL_UNSIGNED_BYTE,
2067 shm_id,
2068 shm_offset);
2069 DoTexImage2D(face,
2071 GL_RGBA,
2075 GL_RGBA,
2076 GL_UNSIGNED_BYTE,
2077 shm_id,
2078 shm_offset);
2080 // Expect 2 levels will be cleared.
2081 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
2082 GL_TEXTURE_CUBE_MAP,
2083 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA,
2084 GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 2, 2);
2085 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
2086 GL_TEXTURE_CUBE_MAP,
2087 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA,
2088 GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 1, 1);
2089 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2090 SetupExpectationsForApplyingDefaultDirtyState();
2091 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2092 .Times(1)
2093 .RetiresOnSaturation();
2094 DrawArrays cmd;
2095 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2096 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2099 TEST_P(GLES2DecoderWithShaderTest,
2100 DrawClearsAfterRenderbuffersWithMultipleAttachments) {
2101 const GLuint kFBOClientTextureId = 4100;
2102 const GLuint kFBOServiceTextureId = 4101;
2104 // Register a texture id.
2105 EXPECT_CALL(*gl_, GenTextures(_, _))
2106 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2107 .RetiresOnSaturation();
2108 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2110 // Setup "render to" texture.
2111 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2112 DoTexImage2D(
2113 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2114 DoBindFramebuffer(
2115 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2116 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2117 GL_COLOR_ATTACHMENT0,
2118 GL_TEXTURE_2D,
2119 kFBOClientTextureId,
2120 kFBOServiceTextureId,
2122 GL_NO_ERROR);
2124 DoBindRenderbuffer(
2125 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
2126 DoBindFramebuffer(
2127 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2128 DoRenderbufferStorage(GL_RENDERBUFFER,
2129 GL_DEPTH_COMPONENT16,
2130 GL_DEPTH_COMPONENT,
2133 GL_NO_ERROR);
2134 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
2135 GL_DEPTH_ATTACHMENT,
2136 GL_RENDERBUFFER,
2137 client_renderbuffer_id_,
2138 kServiceRenderbufferId,
2139 GL_NO_ERROR);
2140 DoEnableDisable(GL_SCISSOR_TEST, false);
2141 DoScissor(0, 0, 1, 1);
2142 SetupTexture();
2143 SetupExpectationsForFramebufferClearing(
2144 GL_FRAMEBUFFER, // target
2145 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, // clear bits
2146 0, 0, 0,
2147 0, // color
2148 0, // stencil
2149 1.0f, // depth
2150 false, // scissor test
2151 0, 0, 1, 1);
2153 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2154 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2155 true, // Framebuffer has depth
2156 false, // Framebuffer has stencil
2157 0x1111, // color bits
2158 true, // depth mask
2159 false, // depth enabled
2160 0, // front stencil mask
2161 0, // back stencil mask
2162 false); // stencil enabled
2164 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2165 .Times(1)
2166 .RetiresOnSaturation();
2167 DrawArrays cmd;
2168 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2169 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2170 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2173 TEST_P(GLES2DecoderWithShaderTest,
2174 DrawingWithFBOTwiceChecksForFBOCompleteOnce) {
2175 const GLuint kFBOClientTextureId = 4100;
2176 const GLuint kFBOServiceTextureId = 4101;
2178 SetupAllNeededVertexBuffers();
2180 // Register a texture id.
2181 EXPECT_CALL(*gl_, GenTextures(_, _))
2182 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2183 .RetiresOnSaturation();
2184 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2186 // Setup "render to" texture that is cleared.
2187 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2188 DoTexImage2D(GL_TEXTURE_2D,
2190 GL_RGBA,
2194 GL_RGBA,
2195 GL_UNSIGNED_BYTE,
2196 kSharedMemoryId,
2197 kSharedMemoryOffset);
2198 DoBindFramebuffer(
2199 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2200 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2201 GL_COLOR_ATTACHMENT0,
2202 GL_TEXTURE_2D,
2203 kFBOClientTextureId,
2204 kFBOServiceTextureId,
2206 GL_NO_ERROR);
2208 // Setup "render from" texture.
2209 SetupTexture();
2211 // Make sure we check for framebuffer complete.
2212 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
2213 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
2214 .RetiresOnSaturation();
2216 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2217 false, // Framebuffer has depth
2218 false, // Framebuffer has stencil
2219 0x1111, // color bits
2220 false, // depth mask
2221 false, // depth enabled
2222 0, // front stencil mask
2223 0, // back stencil mask
2224 false); // stencil enabled
2226 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2227 .Times(1)
2228 .RetiresOnSaturation();
2229 DrawArrays cmd;
2230 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2231 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2232 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2234 // But not again.
2235 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2236 .Times(1)
2237 .RetiresOnSaturation();
2238 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2239 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2242 TEST_P(GLES2DecoderManualInitTest, DrawClearsDepthTexture) {
2243 InitState init;
2244 init.extensions = "GL_ANGLE_depth_texture";
2245 init.gl_version = "opengl es 2.0";
2246 init.has_alpha = true;
2247 init.has_depth = true;
2248 init.request_alpha = true;
2249 init.request_depth = true;
2250 init.bind_generates_resource = true;
2251 InitDecoder(init);
2253 SetupDefaultProgram();
2254 SetupAllNeededVertexBuffers();
2255 const GLenum attachment = GL_DEPTH_ATTACHMENT;
2256 const GLenum target = GL_TEXTURE_2D;
2257 const GLint level = 0;
2258 DoBindTexture(target, client_texture_id_, kServiceTextureId);
2260 // Create a depth texture.
2261 DoTexImage2D(target,
2262 level,
2263 GL_DEPTH_COMPONENT,
2267 GL_DEPTH_COMPONENT,
2268 GL_UNSIGNED_INT,
2272 // Set scissor rect and disable GL_SCISSOR_TEST to make sure we enable it in
2273 // the clear, then disable it and restore the rect again.
2274 DoScissor(0, 0, 32, 32);
2275 DoEnableDisable(GL_SCISSOR_TEST, false);
2277 EXPECT_CALL(*gl_, GenFramebuffersEXT(1, _)).Times(1).RetiresOnSaturation();
2278 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, _))
2279 .Times(1)
2280 .RetiresOnSaturation();
2282 EXPECT_CALL(*gl_,
2283 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT,
2284 attachment,
2285 target,
2286 kServiceTextureId,
2287 level))
2288 .Times(1)
2289 .RetiresOnSaturation();
2290 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT))
2291 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
2292 .RetiresOnSaturation();
2294 EXPECT_CALL(*gl_, ClearStencil(0)).Times(1).RetiresOnSaturation();
2295 SetupExpectationsForStencilMask(GLES2Decoder::kDefaultStencilMask,
2296 GLES2Decoder::kDefaultStencilMask);
2297 EXPECT_CALL(*gl_, ClearDepth(1.0f)).Times(1).RetiresOnSaturation();
2298 SetupExpectationsForDepthMask(true);
2299 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, true);
2300 EXPECT_CALL(*gl_, Scissor(0, 0, 1, 1)).Times(1).RetiresOnSaturation();
2302 EXPECT_CALL(*gl_, Clear(GL_DEPTH_BUFFER_BIT)).Times(1).RetiresOnSaturation();
2304 SetupExpectationsForRestoreClearState(0.0f, 0.0f, 0.0f, 0.0f, 0, 1.0f, false,
2305 0, 0, 32, 32);
2307 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, _)).Times(1).RetiresOnSaturation();
2308 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0))
2309 .Times(1)
2310 .RetiresOnSaturation();
2312 SetupExpectationsForApplyingDefaultDirtyState();
2313 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2314 .Times(1)
2315 .RetiresOnSaturation();
2316 DrawArrays cmd;
2317 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2318 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2319 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2322 } // namespace gles2
2323 } // namespace gpu