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
32 using ::gfx::MockGLInterface
;
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
;
53 class GLES2DecoderGeometryInstancingTest
: public GLES2DecoderWithShaderTest
{
55 GLES2DecoderGeometryInstancingTest() : GLES2DecoderWithShaderTest() {}
57 void SetUp() override
{
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;
70 SetupDefaultProgram();
74 INSTANTIATE_TEST_CASE_P(Service
,
75 GLES2DecoderGeometryInstancingTest
,
78 void GLES2DecoderManualInitTest::DirtyStateMaskTest(GLuint color_bits
,
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
))
118 .RetiresOnSaturation();
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
) {
129 cmd
.Init(true, true, true, true);
130 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
131 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
134 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
135 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
136 false, // Framebuffer has depth
137 false, // Framebuffer has stencil
138 0x1110, // color bits
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
))
147 .RetiresOnSaturation();
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()))
163 cmd2
.Init(GL_COLOR_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
164 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
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();
181 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
182 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
185 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
186 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
187 false, // Framebuffer has depth
188 false, // Framebuffer has stencil
189 0x1110, // color bits
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
))
198 .RetiresOnSaturation();
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()))
214 cmd2
.Init(GL_DEPTH_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
215 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
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();
230 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
231 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
234 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
235 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
236 false, // Framebuffer has depth
237 false, // Framebuffer has stencil
238 0x1110, // color bits
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
))
247 .RetiresOnSaturation();
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()))
263 cmd2
.Init(GL_STENCIL_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
264 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
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
) {
275 cmd
.Init(true, true, true, true);
276 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
277 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
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
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
))
299 .RetiresOnSaturation();
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
))
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
,
333 kSharedMemoryOffset
);
335 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
336 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
337 GL_COLOR_ATTACHMENT0
,
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
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
))
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
))
368 .RetiresOnSaturation();
369 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
370 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
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
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
))
387 .RetiresOnSaturation();
388 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
389 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
392 TEST_P(GLES2DecoderManualInitTest
, DepthEnableWithDepth
) {
394 init
.has_depth
= true;
395 init
.request_depth
= true;
396 init
.bind_generates_resource
= true;
400 cmd
.Init(GL_DEPTH_TEST
);
401 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
402 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
404 SetupDefaultProgram();
406 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
407 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
408 true, // Framebuffer has depth
409 false, // Framebuffer has stencil
410 0x1110, // color bits
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
))
419 .RetiresOnSaturation();
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
, _
))
433 .RetiresOnSaturation();
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
) {
446 init
.has_depth
= true;
447 init
.bind_generates_resource
= true;
451 cmd
.Init(GL_DEPTH_TEST
);
452 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
453 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
455 SetupDefaultProgram();
457 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
458 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
459 false, // Framebuffer has depth
460 false, // Framebuffer has stencil
461 0x1110, // color bits
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
))
470 .RetiresOnSaturation();
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
, _
))
484 .RetiresOnSaturation();
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
) {
497 init
.has_stencil
= true;
498 init
.request_stencil
= true;
499 init
.bind_generates_resource
= true;
503 cmd
.Init(GL_STENCIL_TEST
);
504 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
505 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
507 SetupDefaultProgram();
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
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
))
523 .RetiresOnSaturation();
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
, _
))
537 .RetiresOnSaturation();
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
) {
550 init
.has_stencil
= true;
551 init
.bind_generates_resource
= true;
555 cmd
.Init(GL_STENCIL_TEST
);
556 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
557 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
559 SetupDefaultProgram();
561 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
562 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
563 false, // Framebuffer has depth
564 false, // Framebuffer has stencil
565 0x1110, // color bits
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
))
574 .RetiresOnSaturation();
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
, _
))
588 .RetiresOnSaturation();
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
) {
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;
610 SetupDefaultProgram();
611 SetupAllNeededVertexBuffers();
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
) {
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;
637 SetupDefaultProgram();
638 SetupAllNeededVertexBuffers();
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
) {
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;
663 SetupDefaultProgram();
664 SetupAllNeededVertexBuffers();
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
) {
689 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
690 SetupExpectationsForApplyingDefaultDirtyState();
692 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
694 .RetiresOnSaturation();
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;
705 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
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;
717 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
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;
729 AddExpectationsForSimulatedAttrib0WithError(
730 kFakeLargeCount
, 0, GL_OUT_OF_MEMORY
);
731 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
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
,
752 kSharedMemoryOffset
);
753 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
756 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
758 .RetiresOnSaturation();
760 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceBlackTexture2dId
))
762 .RetiresOnSaturation();
763 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
765 .RetiresOnSaturation();
766 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
768 .RetiresOnSaturation();
769 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
771 .RetiresOnSaturation();
772 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
774 .RetiresOnSaturation();
776 SetupExpectationsForApplyingDefaultDirtyState();
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);
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);
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
) {
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
))
814 .RetiresOnSaturation();
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
));
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();
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
))
845 .RetiresOnSaturation();
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
) {
854 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
855 DeleteVertexBuffer();
857 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
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
) {
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);
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
) {
880 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
882 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
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
) {
894 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
897 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
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
) {
933 DoEnableVertexAttribArray(1);
934 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
936 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
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
) {
948 DoEnableVertexAttribArray(1);
949 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
951 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(_
, _
))
953 .RetiresOnSaturation();
955 VertexAttribDivisorANGLE cmd
;
957 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
958 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
961 TEST_P(GLES2DecoderGeometryInstancingTest
,
962 DrawArraysInstancedANGLENoAttributesFails
) {
965 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
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
) {
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))
986 .RetiresOnSaturation();
987 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
989 .RetiresOnSaturation();
990 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 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
) {
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))
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
) {
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);
1079 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
/ 2))
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
) {
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);
1103 DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1105 .RetiresOnSaturation();
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
) {
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);
1125 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
))
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
) {
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(_
, _
, _
, _
))
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(_
, _
, _
, _
))
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
) {
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);
1173 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
/ 2, kNumVertices
))
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
) {
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(_
, _
, _
, _
))
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
) {
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(_
, _
, _
))
1214 .RetiresOnSaturation();
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
) {
1225 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
1226 SetupExpectationsForApplyingDefaultDirtyState();
1228 DrawElements(GL_TRIANGLES
,
1229 kValidIndexRangeCount
,
1231 BufferOffset(kValidIndexRangeStart
* 2)))
1233 .RetiresOnSaturation();
1235 cmd
.Init(GL_TRIANGLES
,
1236 kValidIndexRangeCount
,
1238 kValidIndexRangeStart
* 2);
1239 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1240 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1243 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsMissingAttributesFails
) {
1245 DoEnableVertexAttribArray(1);
1247 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1249 cmd
.Init(GL_TRIANGLES
,
1250 kValidIndexRangeCount
,
1252 kValidIndexRangeStart
* 2);
1253 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1254 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1257 TEST_P(GLES2DecoderWithShaderTest
,
1258 DrawElementsMissingAttributesZeroCountSucceeds
) {
1260 DoEnableVertexAttribArray(1);
1262 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
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
) {
1271 DoEnableVertexAttribArray(6);
1273 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1275 cmd
.Init(GL_TRIANGLES
,
1276 kValidIndexRangeCount
,
1278 kValidIndexRangeStart
* 2);
1279 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1280 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1283 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsValidAttributesSucceeds
) {
1285 SetupVertexBuffer();
1287 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1288 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1289 SetupExpectationsForApplyingDefaultDirtyState();
1292 DrawElements(GL_TRIANGLES
,
1293 kValidIndexRangeCount
,
1295 BufferOffset(kValidIndexRangeStart
* 2)))
1297 .RetiresOnSaturation();
1299 cmd
.Init(GL_TRIANGLES
,
1300 kValidIndexRangeCount
,
1302 kValidIndexRangeStart
* 2);
1303 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1304 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1307 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedBufferFails
) {
1308 SetupVertexBuffer();
1310 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1311 DeleteIndexBuffer();
1313 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1315 cmd
.Init(GL_TRIANGLES
,
1316 kValidIndexRangeCount
,
1318 kValidIndexRangeStart
* 2);
1319 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1320 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1323 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedProgramSucceeds
) {
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);
1333 cmd
.Init(GL_TRIANGLES
,
1334 kValidIndexRangeCount
,
1336 kValidIndexRangeStart
* 2);
1337 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1338 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1341 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsWithInvalidModeFails
) {
1342 SetupVertexBuffer();
1344 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1346 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1349 kValidIndexRangeCount
,
1351 kValidIndexRangeStart
* 2);
1352 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1353 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1354 cmd
.Init(GL_POLYGON
,
1355 kValidIndexRangeCount
,
1357 kValidIndexRangeStart
);
1358 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1359 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1362 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsInvalidCountFails
) {
1363 SetupVertexBuffer();
1365 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1368 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
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();
1385 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1387 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1389 cmd
.Init(GL_TRIANGLES
,
1390 kInvalidIndexRangeCount
,
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();
1401 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1403 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
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
) {
1413 SetupVertexBuffer();
1415 DoEnableVertexAttribArray(1);
1416 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1418 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1420 .RetiresOnSaturation();
1421 DrawElementsInstancedANGLE cmd
;
1422 cmd
.Init(GL_TRIANGLES
,
1423 kValidIndexRangeCount
,
1425 kValidIndexRangeStart
* 2,
1427 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1428 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1431 TEST_P(GLES2DecoderGeometryInstancingTest
,
1432 DrawElementsInstancedANGLENoAttributesFails
) {
1436 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1438 .RetiresOnSaturation();
1439 DrawElementsInstancedANGLE cmd
;
1440 cmd
.Init(GL_TRIANGLES
,
1441 kValidIndexRangeCount
,
1443 kValidIndexRangeStart
* 2,
1445 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1446 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1449 TEST_P(GLES2DecoderGeometryInstancingTest
,
1450 DrawElementsInstancedANGLESimulatedAttrib0
) {
1452 SetupVertexBuffer();
1454 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1456 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1457 SetupExpectationsForApplyingDefaultDirtyState();
1459 DoVertexAttribDivisorANGLE(0, 1);
1462 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1463 kValidIndexRangeCount
,
1465 BufferOffset(kValidIndexRangeStart
* 2),
1468 .RetiresOnSaturation();
1469 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
1471 .RetiresOnSaturation();
1472 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 1))
1474 .RetiresOnSaturation();
1475 DrawElementsInstancedANGLE cmd
;
1476 cmd
.Init(GL_TRIANGLES
,
1477 kValidIndexRangeCount
,
1479 kValidIndexRangeStart
* 2,
1481 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1482 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1485 TEST_P(GLES2DecoderGeometryInstancingTest
,
1486 DrawElementsInstancedANGLEMissingAttributesFails
) {
1488 DoEnableVertexAttribArray(1);
1490 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1491 DrawElementsInstancedANGLE cmd
;
1492 cmd
.Init(GL_TRIANGLES
,
1493 kValidIndexRangeCount
,
1495 kValidIndexRangeStart
* 2,
1497 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1498 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1501 TEST_P(GLES2DecoderGeometryInstancingTest
,
1502 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds
) {
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
) {
1517 SetupVertexBuffer();
1518 DoEnableVertexAttribArray(1);
1519 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1520 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1521 SetupExpectationsForApplyingDefaultDirtyState();
1525 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1526 kValidIndexRangeCount
,
1528 BufferOffset(kValidIndexRangeStart
* 2),
1531 .RetiresOnSaturation();
1532 DrawElementsInstancedANGLE cmd
;
1533 cmd
.Init(GL_TRIANGLES
,
1534 kValidIndexRangeCount
,
1536 kValidIndexRangeStart
* 2,
1538 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1539 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1542 TEST_P(GLES2DecoderGeometryInstancingTest
,
1543 DrawElementsInstancedANGLEWithInvalidModeFails
) {
1545 SetupVertexBuffer();
1546 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1548 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1549 DrawElementsInstancedANGLE cmd
;
1551 kValidIndexRangeCount
,
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
,
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
) {
1571 SetupVertexBuffer();
1572 SetupExpectationsForApplyingDefaultDirtyState();
1573 // Add offset so we're sure we're accessing data near the end of the buffer.
1574 DoVertexAttribPointer(
1579 (kNumVertices
- kMaxValidIndex
- 1) * 2 * sizeof(GLfloat
));
1581 DoEnableVertexAttribArray(0);
1582 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1583 DoVertexAttribDivisorANGLE(0, 1);
1586 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1587 kValidIndexRangeCount
,
1589 BufferOffset(kValidIndexRangeStart
* 2),
1592 .RetiresOnSaturation();
1593 DrawElementsInstancedANGLE cmd
;
1594 cmd
.Init(GL_TRIANGLES
,
1595 kValidIndexRangeCount
,
1597 kValidIndexRangeStart
* 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
) {
1608 SetupVertexBuffer();
1609 SetupExpectationsForApplyingDefaultDirtyState();
1610 // Add offset so we're sure we're accessing data near the end of the buffer.
1611 DoVertexAttribPointer(
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);
1625 DrawElements(GL_TRIANGLES
,
1626 kValidIndexRangeCount
,
1628 BufferOffset(kValidIndexRangeStart
* 2)))
1630 .RetiresOnSaturation();
1632 cmd
.Init(GL_TRIANGLES
,
1633 kValidIndexRangeCount
,
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
) {
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);
1654 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1655 kValidIndexRangeCount
,
1657 BufferOffset(kValidIndexRangeStart
* 2),
1660 .RetiresOnSaturation();
1661 DrawElementsInstancedANGLE cmd
;
1662 cmd
.Init(GL_TRIANGLES
,
1663 kValidIndexRangeCount
,
1665 kValidIndexRangeStart
* 2,
1667 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1668 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1671 TEST_P(GLES2DecoderGeometryInstancingTest
,
1672 DrawElementsInstancedANGLELargeFails
) {
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(_
, _
, _
, _
, _
))
1683 .RetiresOnSaturation();
1684 DrawElementsInstancedANGLE cmd
;
1685 cmd
.Init(GL_TRIANGLES
,
1686 kValidIndexRangeCount
,
1688 kValidIndexRangeStart
* 2,
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(_
, _
, _
, _
, _
))
1696 .RetiresOnSaturation();
1697 cmd
.Init(GL_TRIANGLES
,
1698 kInvalidIndexRangeCount
,
1700 kInvalidIndexRangeStart
* 2,
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
) {
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(_
, _
, _
, _
, _
))
1719 .RetiresOnSaturation();
1720 DrawElementsInstancedANGLE cmd
;
1721 cmd
.Init(GL_TRIANGLES
,
1722 kValidIndexRangeCount
,
1724 kValidIndexRangeStart
* 2,
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
) {
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);
1745 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1746 kValidIndexRangeCount
,
1748 BufferOffset(kValidIndexRangeStart
* 2),
1751 .RetiresOnSaturation();
1752 DrawElementsInstancedANGLE cmd
;
1753 cmd
.Init(GL_TRIANGLES
,
1754 kValidIndexRangeCount
,
1756 kValidIndexRangeStart
* 2,
1758 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1759 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1762 TEST_P(GLES2DecoderGeometryInstancingTest
,
1763 DrawElementsInstancedANGLENoDivisor0Fails
) {
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(_
, _
, _
, _
, _
))
1775 .RetiresOnSaturation();
1776 DrawElementsInstancedANGLE cmd
;
1777 cmd
.Init(GL_TRIANGLES
,
1778 kValidIndexRangeCount
,
1780 kValidIndexRangeStart
* 2,
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
) {
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(_
, _
, _
, _
))
1800 .RetiresOnSaturation();
1802 cmd
.Init(GL_TRIANGLES
,
1803 kValidIndexRangeCount
,
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.
1816 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
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
))
1829 .RetiresOnSaturation();
1831 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1832 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1833 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1836 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1838 .RetiresOnSaturation();
1839 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1840 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1843 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsClearsAfterTexImage2DNULL
) {
1844 SetupAllNeededVertexBuffers();
1846 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1847 // Create an uncleared texture with 2 levels.
1849 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
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();
1862 DrawElements(GL_TRIANGLES
,
1863 kValidIndexRangeCount
,
1865 BufferOffset(kValidIndexRangeStart
* 2)))
1867 .RetiresOnSaturation();
1869 cmd
.Init(GL_TRIANGLES
,
1870 kValidIndexRangeCount
,
1872 kValidIndexRangeStart
* 2);
1873 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1874 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1878 DrawElements(GL_TRIANGLES
,
1879 kValidIndexRangeCount
,
1881 BufferOffset(kValidIndexRangeStart
* 2)))
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
);
1902 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1904 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1905 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1906 GL_COLOR_ATTACHMENT0
,
1908 kFBOClientTextureId
,
1909 kFBOServiceTextureId
,
1912 DoEnableDisable(GL_SCISSOR_TEST
, false);
1913 DoScissor(0, 0, 1, 1);
1915 // Setup "render from" texture.
1918 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
1919 GL_COLOR_BUFFER_BIT
, // clear bits
1924 false, // scissor test
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
))
1939 .RetiresOnSaturation();
1941 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1942 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1943 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1946 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
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
);
1966 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1968 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1969 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1970 GL_COLOR_ATTACHMENT0
,
1972 kFBOClientTextureId
,
1973 kFBOServiceTextureId
,
1977 // Setup "render from" texture.
1980 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
1981 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED
))
1982 .RetiresOnSaturation();
1983 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
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
) {
1993 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
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
,
2001 client_renderbuffer_id_
,
2002 kServiceRenderbufferId
,
2004 DoEnableDisable(GL_SCISSOR_TEST
, false);
2005 DoScissor(0, 0, 1, 1);
2007 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
2008 GL_COLOR_BUFFER_BIT
, // clear bits
2013 false, // scissor test
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
))
2029 .RetiresOnSaturation();
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
) {
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;
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
];
2056 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryId
;
2058 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryOffset
;
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
))
2093 .RetiresOnSaturation();
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
);
2113 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2115 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2116 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2117 GL_COLOR_ATTACHMENT0
,
2119 kFBOClientTextureId
,
2120 kFBOServiceTextureId
,
2125 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
2127 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2128 DoRenderbufferStorage(GL_RENDERBUFFER
,
2129 GL_DEPTH_COMPONENT16
,
2134 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2135 GL_DEPTH_ATTACHMENT
,
2137 client_renderbuffer_id_
,
2138 kServiceRenderbufferId
,
2140 DoEnableDisable(GL_SCISSOR_TEST
, false);
2141 DoScissor(0, 0, 1, 1);
2143 SetupExpectationsForFramebufferClearing(
2144 GL_FRAMEBUFFER
, // target
2145 GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
, // clear bits
2150 false, // scissor test
2153 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2154 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2155 true, // Framebuffer has depth
2156 false, // Framebuffer has stencil
2157 0x1111, // color bits
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
))
2166 .RetiresOnSaturation();
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
,
2197 kSharedMemoryOffset
);
2199 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2200 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2201 GL_COLOR_ATTACHMENT0
,
2203 kFBOClientTextureId
,
2204 kFBOServiceTextureId
,
2208 // Setup "render from" texture.
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
))
2228 .RetiresOnSaturation();
2230 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2231 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2232 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2235 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2237 .RetiresOnSaturation();
2238 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2239 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2242 TEST_P(GLES2DecoderManualInitTest
, DrawClearsDepthTexture
) {
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;
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
,
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
, _
))
2280 .RetiresOnSaturation();
2283 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT
,
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,
2307 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, _
)).Times(1).RetiresOnSaturation();
2308 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0))
2310 .RetiresOnSaturation();
2312 SetupExpectationsForApplyingDefaultDirtyState();
2313 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2315 .RetiresOnSaturation();
2317 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2318 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2319 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2322 } // namespace gles2