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/async_pixel_transfer_delegate_mock.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
14 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
15 #include "gpu/command_buffer/service/context_group.h"
16 #include "gpu/command_buffer/service/context_state.h"
17 #include "gpu/command_buffer/service/gl_surface_mock.h"
18 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
20 #include "gpu/command_buffer/service/image_manager.h"
21 #include "gpu/command_buffer/service/mailbox_manager.h"
22 #include "gpu/command_buffer/service/mocks.h"
23 #include "gpu/command_buffer/service/program_manager.h"
24 #include "gpu/command_buffer/service/test_helper.h"
25 #include "gpu/config/gpu_switches.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gl/gl_implementation.h"
28 #include "ui/gl/gl_mock.h"
29 #include "ui/gl/gl_surface_stub.h"
31 #if !defined(GL_DEPTH24_STENCIL8)
32 #define GL_DEPTH24_STENCIL8 0x88F0
35 using ::gfx::MockGLInterface
;
37 using ::testing::DoAll
;
38 using ::testing::InSequence
;
39 using ::testing::Invoke
;
40 using ::testing::MatcherCast
;
41 using ::testing::Mock
;
42 using ::testing::Pointee
;
43 using ::testing::Return
;
44 using ::testing::SaveArg
;
45 using ::testing::SetArrayArgument
;
46 using ::testing::SetArgumentPointee
;
47 using ::testing::SetArgPointee
;
48 using ::testing::StrEq
;
49 using ::testing::StrictMock
;
56 class GLES2DecoderGeometryInstancingTest
: public GLES2DecoderWithShaderTest
{
58 GLES2DecoderGeometryInstancingTest() : GLES2DecoderWithShaderTest() {}
60 void SetUp() override
{
62 init
.extensions
= "GL_ANGLE_instanced_arrays";
63 // Most of the tests in this file assume they're running on
64 // desktop OpenGL, and large portions of the tests will become
65 // no-ops if they aren't.
66 init
.gl_version
= "opengl 2.1";
67 init
.has_alpha
= true;
68 init
.has_depth
= true;
69 init
.request_alpha
= true;
70 init
.request_depth
= true;
71 init
.bind_generates_resource
= true;
73 SetupDefaultProgram();
77 INSTANTIATE_TEST_CASE_P(Service
,
78 GLES2DecoderGeometryInstancingTest
,
81 void GLES2DecoderManualInitTest::DirtyStateMaskTest(GLuint color_bits
,
83 GLuint front_stencil_mask
,
84 GLuint back_stencil_mask
) {
85 ColorMask color_mask_cmd
;
86 color_mask_cmd
.Init((color_bits
& 0x1000) != 0,
87 (color_bits
& 0x0100) != 0,
88 (color_bits
& 0x0010) != 0,
89 (color_bits
& 0x0001) != 0);
90 EXPECT_EQ(error::kNoError
, ExecuteCmd(color_mask_cmd
));
91 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
93 DepthMask depth_mask_cmd
;
94 depth_mask_cmd
.Init(depth_mask
);
95 EXPECT_EQ(error::kNoError
, ExecuteCmd(depth_mask_cmd
));
96 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
98 StencilMaskSeparate front_stencil_mask_cmd
;
99 front_stencil_mask_cmd
.Init(GL_FRONT
, front_stencil_mask
);
100 EXPECT_EQ(error::kNoError
, ExecuteCmd(front_stencil_mask_cmd
));
101 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
103 StencilMaskSeparate back_stencil_mask_cmd
;
104 back_stencil_mask_cmd
.Init(GL_BACK
, back_stencil_mask
);
105 EXPECT_EQ(error::kNoError
, ExecuteCmd(back_stencil_mask_cmd
));
106 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
108 SetupExpectationsForApplyingDirtyState(
109 false, // Framebuffer is RGB
110 true, // Framebuffer has depth
111 true, // Framebuffer has stencil
112 color_bits
, // color bits
113 depth_mask
, // depth mask
114 false, // depth enabled
115 front_stencil_mask
, // front stencil mask
116 back_stencil_mask
, // back stencil mask
117 false); // stencil enabled
119 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
121 .RetiresOnSaturation();
123 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
124 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
125 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
128 // Test that with an RGB backbuffer if we set the color mask to 1,1,1,1 it is
129 // set to 1,1,1,0 at Draw time but is 1,1,1,1 at query time.
130 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferColorMask
) {
132 cmd
.Init(true, true, true, true);
133 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
134 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
137 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
138 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
139 false, // Framebuffer has depth
140 false, // Framebuffer has stencil
141 0x1110, // color bits
143 false, // depth enabled
144 0, // front stencil mask
145 0, // back stencil mask
146 false); // stencil enabled
148 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
150 .RetiresOnSaturation();
152 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
153 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
154 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
156 EXPECT_CALL(*gl_
, GetError())
157 .WillOnce(Return(GL_NO_ERROR
))
158 .WillOnce(Return(GL_NO_ERROR
))
159 .RetiresOnSaturation();
160 typedef GetIntegerv::Result Result
;
161 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
162 EXPECT_CALL(*gl_
, GetIntegerv(GL_COLOR_WRITEMASK
, result
->GetData()))
166 cmd2
.Init(GL_COLOR_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
167 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
169 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_COLOR_WRITEMASK
),
170 result
->GetNumResults());
171 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
172 EXPECT_EQ(1, result
->GetData()[0]);
173 EXPECT_EQ(1, result
->GetData()[1]);
174 EXPECT_EQ(1, result
->GetData()[2]);
175 EXPECT_EQ(1, result
->GetData()[3]);
178 // Test that with no depth if we set DepthMask true that it's set to false at
179 // draw time but querying it returns true.
180 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferDepthMask
) {
181 EXPECT_CALL(*gl_
, DepthMask(true)).Times(0).RetiresOnSaturation();
184 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
185 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
188 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
189 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
190 false, // Framebuffer has depth
191 false, // Framebuffer has stencil
192 0x1110, // color bits
194 false, // depth enabled
195 0, // front stencil mask
196 0, // back stencil mask
197 false); // stencil enabled
199 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
201 .RetiresOnSaturation();
203 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
204 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
205 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
207 EXPECT_CALL(*gl_
, GetError())
208 .WillOnce(Return(GL_NO_ERROR
))
209 .WillOnce(Return(GL_NO_ERROR
))
210 .RetiresOnSaturation();
211 typedef GetIntegerv::Result Result
;
212 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
213 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_WRITEMASK
, result
->GetData()))
217 cmd2
.Init(GL_DEPTH_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
218 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
220 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_WRITEMASK
),
221 result
->GetNumResults());
222 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
223 EXPECT_EQ(1, result
->GetData()[0]);
226 // Test that with no stencil if we set the stencil mask it's still set to 0 at
227 // draw time but gets our value if we query.
228 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferStencilMask
) {
229 const GLint kMask
= 123;
230 EXPECT_CALL(*gl_
, StencilMask(kMask
)).Times(0).RetiresOnSaturation();
233 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
234 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
237 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
238 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
239 false, // Framebuffer has depth
240 false, // Framebuffer has stencil
241 0x1110, // color bits
243 false, // depth enabled
244 0, // front stencil mask
245 0, // back stencil mask
246 false); // stencil enabled
248 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
250 .RetiresOnSaturation();
252 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
253 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
254 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
256 EXPECT_CALL(*gl_
, GetError())
257 .WillOnce(Return(GL_NO_ERROR
))
258 .WillOnce(Return(GL_NO_ERROR
))
259 .RetiresOnSaturation();
260 typedef GetIntegerv::Result Result
;
261 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
262 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_WRITEMASK
, result
->GetData()))
266 cmd2
.Init(GL_STENCIL_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
267 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
269 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_WRITEMASK
),
270 result
->GetNumResults());
271 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
272 EXPECT_EQ(kMask
, result
->GetData()[0]);
275 // Test that if an FBO is bound we get the correct masks.
276 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferColorMaskFBO
) {
278 cmd
.Init(true, true, true, true);
279 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
280 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
284 DoEnableVertexAttribArray(0);
285 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
286 DoEnableVertexAttribArray(1);
287 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
288 DoEnableVertexAttribArray(2);
289 DoVertexAttribPointer(2, 2, GL_FLOAT
, 0, 0);
290 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
291 false, // Framebuffer has depth
292 false, // Framebuffer has stencil
293 0x1110, // color bits
295 false, // depth enabled
296 0, // front stencil mask
297 0, // back stencil mask
298 false); // stencil enabled
300 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
302 .RetiresOnSaturation();
304 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
305 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
306 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
308 // Check that no extra calls are made on the next draw.
309 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
311 .RetiresOnSaturation();
312 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
313 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
315 // Setup Frame buffer.
316 // needs to be 1x1 or else it's not renderable.
317 const GLsizei kWidth
= 1;
318 const GLsizei kHeight
= 1;
319 const GLenum kFormat
= GL_RGB
;
320 // Use a different texture for framebuffer to avoid drawing feedback loops.
321 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
322 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
323 .RetiresOnSaturation();
324 GenHelper
<cmds::GenTexturesImmediate
>(kNewClientId
);
325 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kNewServiceId
);
326 // Pass some data so the texture will be marked as cleared.
327 DoTexImage2D(GL_TEXTURE_2D
,
336 kSharedMemoryOffset
);
338 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
339 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
340 GL_COLOR_ATTACHMENT0
,
346 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
347 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
348 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
349 .RetiresOnSaturation();
351 // This time state needs to be set.
352 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
353 false, // Framebuffer has depth
354 false, // Framebuffer has stencil
355 0x1110, // color bits
357 false, // depth enabled
358 0, // front stencil mask
359 0, // back stencil mask
360 false); // stencil enabled
362 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
364 .RetiresOnSaturation();
365 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
366 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
368 // Check that no extra calls are made on the next draw.
369 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
371 .RetiresOnSaturation();
372 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
373 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
376 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
378 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
379 false, // Framebuffer has depth
380 false, // Framebuffer has stencil
381 0x1110, // color bits
383 false, // depth enabled
384 0, // front stencil mask
385 0, // back stencil mask
386 false); // stencil enabled
388 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
390 .RetiresOnSaturation();
391 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
392 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
395 TEST_P(GLES2DecoderManualInitTest
, DepthEnableWithDepth
) {
397 init
.has_depth
= true;
398 init
.request_depth
= true;
399 init
.bind_generates_resource
= true;
403 cmd
.Init(GL_DEPTH_TEST
);
404 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
405 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
407 SetupDefaultProgram();
409 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
410 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
411 true, // Framebuffer has depth
412 false, // Framebuffer has stencil
413 0x1110, // color bits
415 true, // depth enabled
416 0, // front stencil mask
417 0, // back stencil mask
418 false); // stencil enabled
420 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
422 .RetiresOnSaturation();
424 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
425 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
426 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
428 EXPECT_CALL(*gl_
, GetError())
429 .WillOnce(Return(GL_NO_ERROR
))
430 .WillOnce(Return(GL_NO_ERROR
))
431 .RetiresOnSaturation();
432 typedef GetIntegerv::Result Result
;
433 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
434 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_TEST
, _
))
436 .RetiresOnSaturation();
439 cmd2
.Init(GL_DEPTH_TEST
, shared_memory_id_
, shared_memory_offset_
);
440 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
441 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST
),
442 result
->GetNumResults());
443 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
444 EXPECT_EQ(1, result
->GetData()[0]);
447 TEST_P(GLES2DecoderManualInitTest
, DepthEnableWithoutRequestedDepth
) {
449 init
.has_depth
= true;
450 init
.bind_generates_resource
= true;
454 cmd
.Init(GL_DEPTH_TEST
);
455 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
456 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
458 SetupDefaultProgram();
460 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
461 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
462 false, // Framebuffer has depth
463 false, // Framebuffer has stencil
464 0x1110, // color bits
466 false, // depth enabled
467 0, // front stencil mask
468 0, // back stencil mask
469 false); // stencil enabled
471 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
473 .RetiresOnSaturation();
475 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
476 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
477 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
479 EXPECT_CALL(*gl_
, GetError())
480 .WillOnce(Return(GL_NO_ERROR
))
481 .WillOnce(Return(GL_NO_ERROR
))
482 .RetiresOnSaturation();
483 typedef GetIntegerv::Result Result
;
484 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
485 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_TEST
, _
))
487 .RetiresOnSaturation();
490 cmd2
.Init(GL_DEPTH_TEST
, shared_memory_id_
, shared_memory_offset_
);
491 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
492 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST
),
493 result
->GetNumResults());
494 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
495 EXPECT_EQ(1, result
->GetData()[0]);
498 TEST_P(GLES2DecoderManualInitTest
, StencilEnableWithStencil
) {
500 init
.has_stencil
= true;
501 init
.request_stencil
= true;
502 init
.bind_generates_resource
= true;
506 cmd
.Init(GL_STENCIL_TEST
);
507 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
508 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
510 SetupDefaultProgram();
512 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
513 SetupExpectationsForApplyingDirtyState(
514 true, // Framebuffer is RGB
515 false, // Framebuffer has depth
516 true, // Framebuffer has stencil
517 0x1110, // color bits
519 false, // depth enabled
520 GLES2Decoder::kDefaultStencilMask
, // front stencil mask
521 GLES2Decoder::kDefaultStencilMask
, // back stencil mask
522 true); // stencil enabled
524 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
526 .RetiresOnSaturation();
528 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
529 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
530 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
532 EXPECT_CALL(*gl_
, GetError())
533 .WillOnce(Return(GL_NO_ERROR
))
534 .WillOnce(Return(GL_NO_ERROR
))
535 .RetiresOnSaturation();
536 typedef GetIntegerv::Result Result
;
537 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
538 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_TEST
, _
))
540 .RetiresOnSaturation();
543 cmd2
.Init(GL_STENCIL_TEST
, shared_memory_id_
, shared_memory_offset_
);
544 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
545 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST
),
546 result
->GetNumResults());
547 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
548 EXPECT_EQ(1, result
->GetData()[0]);
551 TEST_P(GLES2DecoderManualInitTest
, StencilEnableWithoutRequestedStencil
) {
553 init
.has_stencil
= true;
554 init
.bind_generates_resource
= true;
558 cmd
.Init(GL_STENCIL_TEST
);
559 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
560 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
562 SetupDefaultProgram();
564 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
565 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
566 false, // Framebuffer has depth
567 false, // Framebuffer has stencil
568 0x1110, // color bits
570 false, // depth enabled
571 0, // front stencil mask
572 0, // back stencil mask
573 false); // stencil enabled
575 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
577 .RetiresOnSaturation();
579 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
580 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
581 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
583 EXPECT_CALL(*gl_
, GetError())
584 .WillOnce(Return(GL_NO_ERROR
))
585 .WillOnce(Return(GL_NO_ERROR
))
586 .RetiresOnSaturation();
587 typedef GetIntegerv::Result Result
;
588 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
589 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_TEST
, _
))
591 .RetiresOnSaturation();
594 cmd2
.Init(GL_STENCIL_TEST
, shared_memory_id_
, shared_memory_offset_
);
595 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
596 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST
),
597 result
->GetNumResults());
598 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
599 EXPECT_EQ(1, result
->GetData()[0]);
602 TEST_P(GLES2DecoderManualInitTest
, CachedColorMask
) {
604 init
.has_alpha
= true;
605 init
.has_depth
= true;
606 init
.has_stencil
= true;
607 init
.request_alpha
= true;
608 init
.request_depth
= true;
609 init
.request_stencil
= true;
610 init
.bind_generates_resource
= true;
613 SetupDefaultProgram();
614 SetupAllNeededVertexBuffers();
617 // Test all color_bits combinations twice.
618 for (int i
= 0; i
< 32; i
++) {
619 GLuint color_bits
= (i
& 1 ? 0x0001 : 0x0000) | (i
& 2 ? 0x0010 : 0x0000) |
620 (i
& 4 ? 0x0100 : 0x0000) | (i
& 8 ? 0x1000 : 0x0000);
622 // Toggle depth_test to force ApplyDirtyState each time.
623 DirtyStateMaskTest(color_bits
, false, 0xffffffff, 0xffffffff);
624 DirtyStateMaskTest(color_bits
, true, 0xffffffff, 0xffffffff);
625 DirtyStateMaskTest(color_bits
, false, 0xffffffff, 0xffffffff);
629 TEST_P(GLES2DecoderManualInitTest
, CachedDepthMask
) {
631 init
.has_alpha
= true;
632 init
.has_depth
= true;
633 init
.has_stencil
= true;
634 init
.request_alpha
= true;
635 init
.request_depth
= true;
636 init
.request_stencil
= true;
637 init
.bind_generates_resource
= true;
640 SetupDefaultProgram();
641 SetupAllNeededVertexBuffers();
644 // Test all depth_mask combinations twice.
645 for (int i
= 0; i
< 4; i
++) {
646 bool depth_mask
= (i
& 1) == 1;
648 // Toggle color masks to force ApplyDirtyState each time.
649 DirtyStateMaskTest(0x1010, depth_mask
, 0xffffffff, 0xffffffff);
650 DirtyStateMaskTest(0x0101, depth_mask
, 0xffffffff, 0xffffffff);
651 DirtyStateMaskTest(0x1010, depth_mask
, 0xffffffff, 0xffffffff);
655 TEST_P(GLES2DecoderManualInitTest
, CachedStencilMask
) {
657 init
.has_alpha
= true;
658 init
.has_depth
= true;
659 init
.has_stencil
= true;
660 init
.request_alpha
= true;
661 init
.request_depth
= true;
662 init
.request_stencil
= true;
663 init
.bind_generates_resource
= true;
666 SetupDefaultProgram();
667 SetupAllNeededVertexBuffers();
670 // Test all stencil_mask combinations twice.
671 for (int i
= 0; i
< 4; i
++) {
672 GLuint stencil_mask
= (i
& 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
674 // Toggle color masks to force ApplyDirtyState each time.
675 DirtyStateMaskTest(0x1010, true, stencil_mask
, 0xffffffff);
676 DirtyStateMaskTest(0x0101, true, stencil_mask
, 0xffffffff);
677 DirtyStateMaskTest(0x1010, true, stencil_mask
, 0xffffffff);
680 for (int i
= 0; i
< 4; i
++) {
681 GLuint stencil_mask
= (i
& 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
683 // Toggle color masks to force ApplyDirtyState each time.
684 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask
);
685 DirtyStateMaskTest(0x0101, true, 0xffffffff, stencil_mask
);
686 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask
);
690 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysNoAttributesSucceeds
) {
692 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
693 SetupExpectationsForApplyingDefaultDirtyState();
695 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
697 .RetiresOnSaturation();
699 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
700 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
701 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
704 // Tests when the math overflows (0x40000000 * sizeof GLfloat)
705 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0OverflowFails
) {
706 const GLsizei kLargeCount
= 0x40000000;
708 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
710 cmd
.Init(GL_TRIANGLES
, 0, kLargeCount
);
711 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
712 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
713 EXPECT_FALSE(GetDecoder()->WasContextLost());
716 // Tests when the math overflows (0x7FFFFFFF + 1 = 0x8000000 verts)
717 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0PosToNegFails
) {
718 const GLsizei kLargeCount
= 0x7FFFFFFF;
720 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
722 cmd
.Init(GL_TRIANGLES
, 0, kLargeCount
);
723 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
724 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
725 EXPECT_FALSE(GetDecoder()->WasContextLost());
728 // Tests when the driver returns an error
729 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0OOMFails
) {
730 const GLsizei kFakeLargeCount
= 0x1234;
732 AddExpectationsForSimulatedAttrib0WithError(
733 kFakeLargeCount
, 0, GL_OUT_OF_MEMORY
);
734 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
736 cmd
.Init(GL_TRIANGLES
, 0, kFakeLargeCount
);
737 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
738 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
739 EXPECT_FALSE(GetDecoder()->WasContextLost());
742 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysBadTextureUsesBlack
) {
743 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
744 // This is an NPOT texture. As the default filtering requires mips
745 // this should trigger replacing with black textures before rendering.
746 DoTexImage2D(GL_TEXTURE_2D
,
755 kSharedMemoryOffset
);
756 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
759 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
761 .RetiresOnSaturation();
763 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceBlackTexture2dId
))
765 .RetiresOnSaturation();
766 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
768 .RetiresOnSaturation();
769 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
771 .RetiresOnSaturation();
772 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
774 .RetiresOnSaturation();
775 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
777 .RetiresOnSaturation();
779 SetupExpectationsForApplyingDefaultDirtyState();
781 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
782 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
783 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
786 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysMissingAttributesFails
) {
787 DoEnableVertexAttribArray(1);
789 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
791 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
792 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
793 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
796 TEST_P(GLES2DecoderWithShaderTest
,
797 DrawArraysMissingAttributesZeroCountSucceeds
) {
798 DoEnableVertexAttribArray(1);
800 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
802 cmd
.Init(GL_TRIANGLES
, 0, 0);
803 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
804 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
807 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysValidAttributesSucceeds
) {
810 DoEnableVertexAttribArray(1);
811 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
812 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
813 SetupExpectationsForApplyingDefaultDirtyState();
815 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
817 .RetiresOnSaturation();
819 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
820 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
821 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
824 // Same as DrawArraysValidAttributesSucceeds, but with workaround
825 // |init_vertex_attributes|.
826 TEST_P(GLES2DecoderManualInitTest
, InitVertexAttributes
) {
827 base::CommandLine
command_line(0, NULL
);
828 command_line
.AppendSwitchASCII(
829 switches::kGpuDriverBugWorkarounds
,
830 base::IntToString(gpu::INIT_VERTEX_ATTRIBUTES
));
832 init
.has_alpha
= true;
833 init
.has_depth
= true;
834 init
.request_alpha
= true;
835 init
.request_depth
= true;
836 init
.bind_generates_resource
= true;
837 InitDecoderWithCommandLine(init
, &command_line
);
838 SetupDefaultProgram();
841 DoEnableVertexAttribArray(1);
842 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
843 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
844 SetupExpectationsForApplyingDefaultDirtyState();
846 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
848 .RetiresOnSaturation();
850 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
851 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
852 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
855 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysDeletedBufferFails
) {
857 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
858 DeleteVertexBuffer();
860 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
862 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
863 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
864 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
867 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysDeletedProgramSucceeds
) {
869 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
870 SetupExpectationsForApplyingDefaultDirtyState();
871 DoDeleteProgram(client_program_id_
, kServiceProgramId
);
873 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(1).RetiresOnSaturation();
874 EXPECT_CALL(*gl_
, DeleteProgram(kServiceProgramId
)).Times(1);
876 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
877 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
878 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
881 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysWithInvalidModeFails
) {
883 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
885 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
887 cmd
.Init(GL_QUADS
, 0, 1);
888 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
889 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
890 cmd
.Init(GL_POLYGON
, 0, 1);
891 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
892 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
895 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysInvalidCountFails
) {
897 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
900 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
902 cmd
.Init(GL_TRIANGLES
, 1, kNumVertices
);
903 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
904 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
905 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
907 // Try with count > size
908 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
+ 1);
909 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
910 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
911 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
913 // Try with attrib offset > 0
914 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
915 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 4);
916 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
917 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
918 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
920 // Try with size > 2 (ie, vec3 instead of vec2)
921 DoVertexAttribPointer(1, 3, GL_FLOAT
, 0, 0);
922 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
923 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
924 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
926 // Try with stride > 8 (vec2 + vec2 byte)
927 DoVertexAttribPointer(1, 2, GL_FLOAT
, sizeof(GLfloat
) * 3, 0);
928 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
929 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
930 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
933 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysInstancedANGLEFails
) {
936 DoEnableVertexAttribArray(1);
937 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
939 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
941 .RetiresOnSaturation();
942 DrawArraysInstancedANGLE cmd
;
943 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
944 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
945 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
948 TEST_P(GLES2DecoderWithShaderTest
, VertexAttribDivisorANGLEFails
) {
951 DoEnableVertexAttribArray(1);
952 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
954 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(_
, _
))
956 .RetiresOnSaturation();
958 VertexAttribDivisorANGLE cmd
;
960 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
961 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
964 TEST_P(GLES2DecoderGeometryInstancingTest
,
965 DrawArraysInstancedANGLENoAttributesFails
) {
968 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
970 .RetiresOnSaturation();
971 DrawArraysInstancedANGLE cmd
;
972 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
973 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
974 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
977 TEST_P(GLES2DecoderGeometryInstancingTest
,
978 DrawArraysInstancedANGLESimulatedAttrib0
) {
981 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
983 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
984 SetupExpectationsForApplyingDefaultDirtyState();
986 DoVertexAttribDivisorANGLE(0, 1);
987 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, 3))
989 .RetiresOnSaturation();
990 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
992 .RetiresOnSaturation();
993 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 1))
995 .RetiresOnSaturation();
996 DrawArraysInstancedANGLE cmd
;
997 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 3);
998 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
999 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1002 TEST_P(GLES2DecoderGeometryInstancingTest
,
1003 DrawArraysInstancedANGLEMissingAttributesFails
) {
1004 DoEnableVertexAttribArray(1);
1006 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1007 DrawArraysInstancedANGLE cmd
;
1008 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1009 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1010 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1013 TEST_P(GLES2DecoderGeometryInstancingTest
,
1014 DrawArraysInstancedANGLEMissingAttributesZeroCountSucceeds
) {
1015 DoEnableVertexAttribArray(1);
1017 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1018 DrawArraysInstancedANGLE cmd
;
1019 cmd
.Init(GL_TRIANGLES
, 0, 0, 1);
1020 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1021 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1024 TEST_P(GLES2DecoderGeometryInstancingTest
,
1025 DrawArraysInstancedANGLEValidAttributesSucceeds
) {
1027 SetupVertexBuffer();
1028 DoEnableVertexAttribArray(1);
1029 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1030 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
1031 SetupExpectationsForApplyingDefaultDirtyState();
1033 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, 1))
1035 .RetiresOnSaturation();
1036 DrawArraysInstancedANGLE cmd
;
1037 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1038 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1039 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1042 TEST_P(GLES2DecoderGeometryInstancingTest
,
1043 DrawArraysInstancedANGLEWithInvalidModeFails
) {
1044 SetupVertexBuffer();
1045 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1047 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1048 DrawArraysInstancedANGLE cmd
;
1049 cmd
.Init(GL_QUADS
, 0, 1, 1);
1050 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1051 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1052 cmd
.Init(GL_POLYGON
, 0, 1, 1);
1053 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1054 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1057 TEST_P(GLES2DecoderGeometryInstancingTest
,
1058 DrawArraysInstancedANGLEInvalidPrimcountFails
) {
1059 SetupVertexBuffer();
1060 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1062 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1063 DrawArraysInstancedANGLE cmd
;
1064 cmd
.Init(GL_TRIANGLES
, 0, 1, -1);
1065 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1066 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1069 // Per-instance data is twice as large, but number of instances is half
1070 TEST_P(GLES2DecoderGeometryInstancingTest
,
1071 DrawArraysInstancedANGLELargeInstanceSucceeds
) {
1073 SetupVertexBuffer();
1074 SetupExpectationsForApplyingDefaultDirtyState();
1075 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1077 DoEnableVertexAttribArray(0);
1078 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1079 DoVertexAttribDivisorANGLE(0, 1);
1082 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
/ 2))
1084 .RetiresOnSaturation();
1085 DrawArraysInstancedANGLE cmd
;
1086 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
/ 2);
1087 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1088 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1091 // Regular drawArrays takes the divisor into account
1092 TEST_P(GLES2DecoderGeometryInstancingTest
,
1093 DrawArraysWithDivisorSucceeds
) {
1095 SetupVertexBuffer();
1096 SetupExpectationsForApplyingDefaultDirtyState();
1097 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1099 DoEnableVertexAttribArray(0);
1100 // Access the data right at the end of the buffer.
1101 DoVertexAttribPointer(
1102 0, 2, GL_FLOAT
, 0, (kNumVertices
- 1) * 2 * sizeof(GLfloat
));
1103 DoVertexAttribDivisorANGLE(0, 1);
1106 DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1108 .RetiresOnSaturation();
1110 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1111 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1112 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1115 // Per-instance data is twice as large, but divisor is twice
1116 TEST_P(GLES2DecoderGeometryInstancingTest
,
1117 DrawArraysInstancedANGLELargeDivisorSucceeds
) {
1119 SetupVertexBuffer();
1120 SetupExpectationsForApplyingDefaultDirtyState();
1121 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1123 DoEnableVertexAttribArray(0);
1124 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1125 DoVertexAttribDivisorANGLE(0, 2);
1128 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
))
1130 .RetiresOnSaturation();
1131 DrawArraysInstancedANGLE cmd
;
1132 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
);
1133 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1134 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1137 TEST_P(GLES2DecoderGeometryInstancingTest
, DrawArraysInstancedANGLELargeFails
) {
1139 SetupVertexBuffer();
1140 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1142 DoEnableVertexAttribArray(0);
1143 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1144 DoVertexAttribDivisorANGLE(0, 1);
1145 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1147 .RetiresOnSaturation();
1148 DrawArraysInstancedANGLE cmd
;
1149 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
+ 1);
1150 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1151 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1152 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1154 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1156 .RetiresOnSaturation();
1157 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
+ 1, kNumVertices
);
1158 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1159 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1160 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1163 // Per-index data is twice as large, but number of indices is half
1164 TEST_P(GLES2DecoderGeometryInstancingTest
,
1165 DrawArraysInstancedANGLELargeIndexSucceeds
) {
1167 SetupVertexBuffer();
1168 SetupExpectationsForApplyingDefaultDirtyState();
1169 DoVertexAttribPointer(1, 4, GL_FLOAT
, 0, 0);
1171 DoEnableVertexAttribArray(0);
1172 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1173 DoVertexAttribDivisorANGLE(0, 1);
1176 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
/ 2, kNumVertices
))
1178 .RetiresOnSaturation();
1179 DrawArraysInstancedANGLE cmd
;
1180 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
/ 2, kNumVertices
);
1181 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1182 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1185 TEST_P(GLES2DecoderGeometryInstancingTest
,
1186 DrawArraysInstancedANGLENoDivisor0Fails
) {
1188 SetupVertexBuffer();
1189 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1191 DoEnableVertexAttribArray(0);
1192 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1193 DoVertexAttribDivisorANGLE(0, 1);
1194 DoVertexAttribDivisorANGLE(1, 1);
1195 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1197 .RetiresOnSaturation();
1198 DrawArraysInstancedANGLE cmd
;
1199 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1200 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1201 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1202 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1205 TEST_P(GLES2DecoderGeometryInstancingTest
,
1206 DrawArraysNoDivisor0Fails
) {
1208 SetupVertexBuffer();
1209 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1211 DoEnableVertexAttribArray(0);
1212 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1213 DoVertexAttribDivisorANGLE(0, 1);
1214 DoVertexAttribDivisorANGLE(1, 1);
1215 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
))
1217 .RetiresOnSaturation();
1219 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1220 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1221 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1222 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1225 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsNoAttributesSucceeds
) {
1228 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
1229 SetupExpectationsForApplyingDefaultDirtyState();
1231 DrawElements(GL_TRIANGLES
,
1232 kValidIndexRangeCount
,
1234 BufferOffset(kValidIndexRangeStart
* 2)))
1236 .RetiresOnSaturation();
1238 cmd
.Init(GL_TRIANGLES
,
1239 kValidIndexRangeCount
,
1241 kValidIndexRangeStart
* 2);
1242 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1243 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1246 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsMissingAttributesFails
) {
1248 DoEnableVertexAttribArray(1);
1250 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1252 cmd
.Init(GL_TRIANGLES
,
1253 kValidIndexRangeCount
,
1255 kValidIndexRangeStart
* 2);
1256 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1257 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1260 TEST_P(GLES2DecoderWithShaderTest
,
1261 DrawElementsMissingAttributesZeroCountSucceeds
) {
1263 DoEnableVertexAttribArray(1);
1265 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1267 cmd
.Init(GL_TRIANGLES
, 0, GL_UNSIGNED_SHORT
, kValidIndexRangeStart
* 2);
1268 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1269 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1272 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsExtraAttributesFails
) {
1274 DoEnableVertexAttribArray(6);
1276 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1278 cmd
.Init(GL_TRIANGLES
,
1279 kValidIndexRangeCount
,
1281 kValidIndexRangeStart
* 2);
1282 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1283 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1286 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsValidAttributesSucceeds
) {
1288 SetupVertexBuffer();
1290 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1291 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1292 SetupExpectationsForApplyingDefaultDirtyState();
1295 DrawElements(GL_TRIANGLES
,
1296 kValidIndexRangeCount
,
1298 BufferOffset(kValidIndexRangeStart
* 2)))
1300 .RetiresOnSaturation();
1302 cmd
.Init(GL_TRIANGLES
,
1303 kValidIndexRangeCount
,
1305 kValidIndexRangeStart
* 2);
1306 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1307 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1310 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedBufferFails
) {
1311 SetupVertexBuffer();
1313 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1314 DeleteIndexBuffer();
1316 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1318 cmd
.Init(GL_TRIANGLES
,
1319 kValidIndexRangeCount
,
1321 kValidIndexRangeStart
* 2);
1322 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1323 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1326 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedProgramSucceeds
) {
1329 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
1330 SetupExpectationsForApplyingDefaultDirtyState();
1331 DoDeleteProgram(client_program_id_
, kServiceProgramId
);
1333 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(1);
1334 EXPECT_CALL(*gl_
, DeleteProgram(kServiceProgramId
)).Times(1);
1336 cmd
.Init(GL_TRIANGLES
,
1337 kValidIndexRangeCount
,
1339 kValidIndexRangeStart
* 2);
1340 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1341 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1344 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsWithInvalidModeFails
) {
1345 SetupVertexBuffer();
1347 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1349 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1352 kValidIndexRangeCount
,
1354 kValidIndexRangeStart
* 2);
1355 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1356 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1357 cmd
.Init(GL_POLYGON
,
1358 kValidIndexRangeCount
,
1360 kValidIndexRangeStart
);
1361 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1362 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1365 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsInvalidCountFails
) {
1366 SetupVertexBuffer();
1368 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1371 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1373 cmd
.Init(GL_TRIANGLES
, kNumIndices
, GL_UNSIGNED_SHORT
, 2);
1374 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1375 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1376 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1378 // Try with count > size
1379 cmd
.Init(GL_TRIANGLES
, kNumIndices
+ 1, GL_UNSIGNED_SHORT
, 0);
1380 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1381 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1382 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1385 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsOutOfRangeIndicesFails
) {
1386 SetupVertexBuffer();
1388 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1390 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1392 cmd
.Init(GL_TRIANGLES
,
1393 kInvalidIndexRangeCount
,
1395 kInvalidIndexRangeStart
* 2);
1396 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1397 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1398 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1401 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsOddOffsetForUint16Fails
) {
1402 SetupVertexBuffer();
1404 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1406 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1408 cmd
.Init(GL_TRIANGLES
, kInvalidIndexRangeCount
, GL_UNSIGNED_SHORT
, 1);
1409 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1410 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1411 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1414 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsInstancedANGLEFails
) {
1416 SetupVertexBuffer();
1418 DoEnableVertexAttribArray(1);
1419 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1421 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1423 .RetiresOnSaturation();
1424 DrawElementsInstancedANGLE cmd
;
1425 cmd
.Init(GL_TRIANGLES
,
1426 kValidIndexRangeCount
,
1428 kValidIndexRangeStart
* 2,
1430 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1431 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1434 TEST_P(GLES2DecoderGeometryInstancingTest
,
1435 DrawElementsInstancedANGLENoAttributesFails
) {
1439 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1441 .RetiresOnSaturation();
1442 DrawElementsInstancedANGLE cmd
;
1443 cmd
.Init(GL_TRIANGLES
,
1444 kValidIndexRangeCount
,
1446 kValidIndexRangeStart
* 2,
1448 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1449 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1452 TEST_P(GLES2DecoderGeometryInstancingTest
,
1453 DrawElementsInstancedANGLESimulatedAttrib0
) {
1455 SetupVertexBuffer();
1457 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1459 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1460 SetupExpectationsForApplyingDefaultDirtyState();
1462 DoVertexAttribDivisorANGLE(0, 1);
1465 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1466 kValidIndexRangeCount
,
1468 BufferOffset(kValidIndexRangeStart
* 2),
1471 .RetiresOnSaturation();
1472 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
1474 .RetiresOnSaturation();
1475 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 1))
1477 .RetiresOnSaturation();
1478 DrawElementsInstancedANGLE cmd
;
1479 cmd
.Init(GL_TRIANGLES
,
1480 kValidIndexRangeCount
,
1482 kValidIndexRangeStart
* 2,
1484 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1485 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1488 TEST_P(GLES2DecoderGeometryInstancingTest
,
1489 DrawElementsInstancedANGLEMissingAttributesFails
) {
1491 DoEnableVertexAttribArray(1);
1493 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1494 DrawElementsInstancedANGLE cmd
;
1495 cmd
.Init(GL_TRIANGLES
,
1496 kValidIndexRangeCount
,
1498 kValidIndexRangeStart
* 2,
1500 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1501 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1504 TEST_P(GLES2DecoderGeometryInstancingTest
,
1505 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds
) {
1507 DoEnableVertexAttribArray(1);
1509 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1510 DrawElementsInstancedANGLE cmd
;
1511 cmd
.Init(GL_TRIANGLES
, 0, GL_UNSIGNED_SHORT
, kValidIndexRangeStart
* 2, 1);
1512 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1513 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1516 TEST_P(GLES2DecoderGeometryInstancingTest
,
1517 DrawElementsInstancedANGLEValidAttributesSucceeds
) {
1520 SetupVertexBuffer();
1521 DoEnableVertexAttribArray(1);
1522 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1523 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1524 SetupExpectationsForApplyingDefaultDirtyState();
1528 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1529 kValidIndexRangeCount
,
1531 BufferOffset(kValidIndexRangeStart
* 2),
1534 .RetiresOnSaturation();
1535 DrawElementsInstancedANGLE cmd
;
1536 cmd
.Init(GL_TRIANGLES
,
1537 kValidIndexRangeCount
,
1539 kValidIndexRangeStart
* 2,
1541 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1542 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1545 TEST_P(GLES2DecoderGeometryInstancingTest
,
1546 DrawElementsInstancedANGLEWithInvalidModeFails
) {
1548 SetupVertexBuffer();
1549 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1551 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1552 DrawElementsInstancedANGLE cmd
;
1554 kValidIndexRangeCount
,
1556 kValidIndexRangeStart
* 2,
1558 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1559 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1560 cmd
.Init(GL_INVALID_ENUM
,
1561 kValidIndexRangeCount
,
1563 kValidIndexRangeStart
* 2,
1565 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1566 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1569 // Per-instance data is twice as large, but number of instances is half
1570 TEST_P(GLES2DecoderGeometryInstancingTest
,
1571 DrawElementsInstancedANGLELargeInstanceSucceeds
) {
1574 SetupVertexBuffer();
1575 SetupExpectationsForApplyingDefaultDirtyState();
1576 // Add offset so we're sure we're accessing data near the end of the buffer.
1577 DoVertexAttribPointer(
1582 (kNumVertices
- kMaxValidIndex
- 1) * 2 * sizeof(GLfloat
));
1584 DoEnableVertexAttribArray(0);
1585 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1586 DoVertexAttribDivisorANGLE(0, 1);
1589 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1590 kValidIndexRangeCount
,
1592 BufferOffset(kValidIndexRangeStart
* 2),
1595 .RetiresOnSaturation();
1596 DrawElementsInstancedANGLE cmd
;
1597 cmd
.Init(GL_TRIANGLES
,
1598 kValidIndexRangeCount
,
1600 kValidIndexRangeStart
* 2,
1602 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1603 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1606 // Regular drawElements takes the divisor into account
1607 TEST_P(GLES2DecoderGeometryInstancingTest
,
1608 DrawElementsWithDivisorSucceeds
) {
1611 SetupVertexBuffer();
1612 SetupExpectationsForApplyingDefaultDirtyState();
1613 // Add offset so we're sure we're accessing data near the end of the buffer.
1614 DoVertexAttribPointer(
1619 (kNumVertices
- kMaxValidIndex
- 1) * 2 * sizeof(GLfloat
));
1621 DoEnableVertexAttribArray(0);
1622 // Access the data right at the end of the buffer.
1623 DoVertexAttribPointer(
1624 0, 2, GL_FLOAT
, 0, (kNumVertices
- 1) * 2 * sizeof(GLfloat
));
1625 DoVertexAttribDivisorANGLE(0, 1);
1628 DrawElements(GL_TRIANGLES
,
1629 kValidIndexRangeCount
,
1631 BufferOffset(kValidIndexRangeStart
* 2)))
1633 .RetiresOnSaturation();
1635 cmd
.Init(GL_TRIANGLES
,
1636 kValidIndexRangeCount
,
1638 kValidIndexRangeStart
* 2);
1639 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1640 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1643 // Per-instance data is twice as large, but divisor is twice
1644 TEST_P(GLES2DecoderGeometryInstancingTest
,
1645 DrawElementsInstancedANGLELargeDivisorSucceeds
) {
1648 SetupVertexBuffer();
1649 SetupExpectationsForApplyingDefaultDirtyState();
1650 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1652 DoEnableVertexAttribArray(0);
1653 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1654 DoVertexAttribDivisorANGLE(0, 2);
1657 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1658 kValidIndexRangeCount
,
1660 BufferOffset(kValidIndexRangeStart
* 2),
1663 .RetiresOnSaturation();
1664 DrawElementsInstancedANGLE cmd
;
1665 cmd
.Init(GL_TRIANGLES
,
1666 kValidIndexRangeCount
,
1668 kValidIndexRangeStart
* 2,
1670 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1671 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1674 TEST_P(GLES2DecoderGeometryInstancingTest
,
1675 DrawElementsInstancedANGLELargeFails
) {
1678 SetupVertexBuffer();
1679 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1681 DoEnableVertexAttribArray(0);
1682 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1683 DoVertexAttribDivisorANGLE(0, 1);
1684 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1686 .RetiresOnSaturation();
1687 DrawElementsInstancedANGLE cmd
;
1688 cmd
.Init(GL_TRIANGLES
,
1689 kValidIndexRangeCount
,
1691 kValidIndexRangeStart
* 2,
1693 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1694 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1695 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1697 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1699 .RetiresOnSaturation();
1700 cmd
.Init(GL_TRIANGLES
,
1701 kInvalidIndexRangeCount
,
1703 kInvalidIndexRangeStart
* 2,
1705 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1706 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1707 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1710 TEST_P(GLES2DecoderGeometryInstancingTest
,
1711 DrawElementsInstancedANGLEInvalidPrimcountFails
) {
1714 SetupVertexBuffer();
1715 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1717 DoEnableVertexAttribArray(0);
1718 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1719 DoVertexAttribDivisorANGLE(0, 1);
1720 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1722 .RetiresOnSaturation();
1723 DrawElementsInstancedANGLE cmd
;
1724 cmd
.Init(GL_TRIANGLES
,
1725 kValidIndexRangeCount
,
1727 kValidIndexRangeStart
* 2,
1729 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1730 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1731 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1734 // Per-index data is twice as large, but values of indices are smaller
1735 TEST_P(GLES2DecoderGeometryInstancingTest
,
1736 DrawElementsInstancedANGLELargeIndexSucceeds
) {
1739 SetupVertexBuffer();
1740 SetupExpectationsForApplyingDefaultDirtyState();
1741 DoVertexAttribPointer(1, 4, GL_FLOAT
, 0, 0);
1743 DoEnableVertexAttribArray(0);
1744 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1745 DoVertexAttribDivisorANGLE(0, 1);
1748 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1749 kValidIndexRangeCount
,
1751 BufferOffset(kValidIndexRangeStart
* 2),
1754 .RetiresOnSaturation();
1755 DrawElementsInstancedANGLE cmd
;
1756 cmd
.Init(GL_TRIANGLES
,
1757 kValidIndexRangeCount
,
1759 kValidIndexRangeStart
* 2,
1761 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1762 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1765 TEST_P(GLES2DecoderGeometryInstancingTest
,
1766 DrawElementsInstancedANGLENoDivisor0Fails
) {
1769 SetupVertexBuffer();
1770 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1772 DoEnableVertexAttribArray(0);
1773 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1774 DoVertexAttribDivisorANGLE(0, 1);
1775 DoVertexAttribDivisorANGLE(1, 1);
1776 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1778 .RetiresOnSaturation();
1779 DrawElementsInstancedANGLE cmd
;
1780 cmd
.Init(GL_TRIANGLES
,
1781 kValidIndexRangeCount
,
1783 kValidIndexRangeStart
* 2,
1785 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1786 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1787 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1790 TEST_P(GLES2DecoderGeometryInstancingTest
,
1791 DrawElementsNoDivisor0Fails
) {
1794 SetupVertexBuffer();
1795 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1797 DoEnableVertexAttribArray(0);
1798 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1799 DoVertexAttribDivisorANGLE(0, 1);
1800 DoVertexAttribDivisorANGLE(1, 1);
1801 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
))
1803 .RetiresOnSaturation();
1805 cmd
.Init(GL_TRIANGLES
,
1806 kValidIndexRangeCount
,
1808 kValidIndexRangeStart
* 2);
1809 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1810 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1811 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1814 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysClearsAfterTexImage2DNULL
) {
1815 SetupAllNeededVertexBuffers();
1816 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1817 // Create an uncleared texture with 2 levels.
1819 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1821 GL_TEXTURE_2D
, 1, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1822 // Expect 2 levels will be cleared.
1823 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
1824 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
1825 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 2, 2);
1826 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
1827 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 1, GL_RGBA
,
1828 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 1, 1);
1829 SetupExpectationsForApplyingDefaultDirtyState();
1830 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1832 .RetiresOnSaturation();
1834 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1835 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1836 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1839 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1841 .RetiresOnSaturation();
1842 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1843 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1846 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsClearsAfterTexImage2DNULL
) {
1847 SetupAllNeededVertexBuffers();
1849 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1850 // Create an uncleared texture with 2 levels.
1852 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1854 GL_TEXTURE_2D
, 1, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1855 // Expect 2 levels will be cleared.
1856 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
1857 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
1858 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 2, 2);
1859 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
1860 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 1, GL_RGBA
,
1861 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 1, 1);
1862 SetupExpectationsForApplyingDefaultDirtyState();
1865 DrawElements(GL_TRIANGLES
,
1866 kValidIndexRangeCount
,
1868 BufferOffset(kValidIndexRangeStart
* 2)))
1870 .RetiresOnSaturation();
1872 cmd
.Init(GL_TRIANGLES
,
1873 kValidIndexRangeCount
,
1875 kValidIndexRangeStart
* 2);
1876 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1877 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1881 DrawElements(GL_TRIANGLES
,
1882 kValidIndexRangeCount
,
1884 BufferOffset(kValidIndexRangeStart
* 2)))
1886 .RetiresOnSaturation();
1887 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1888 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1891 TEST_P(GLES2DecoderWithShaderTest
, DrawClearsAfterTexImage2DNULLInFBO
) {
1892 const GLuint kFBOClientTextureId
= 4100;
1893 const GLuint kFBOServiceTextureId
= 4101;
1895 SetupAllNeededVertexBuffers();
1896 // Register a texture id.
1897 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1898 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1899 .RetiresOnSaturation();
1900 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1902 // Setup "render to" texture.
1903 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1905 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1907 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1908 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1909 GL_COLOR_ATTACHMENT0
,
1911 kFBOClientTextureId
,
1912 kFBOServiceTextureId
,
1915 DoEnableDisable(GL_SCISSOR_TEST
, false);
1916 DoScissor(0, 0, 1, 1);
1918 // Setup "render from" texture.
1921 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
1922 GL_COLOR_BUFFER_BIT
, // clear bits
1927 false, // scissor test
1930 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1931 false, // Framebuffer has depth
1932 false, // Framebuffer has stencil
1933 0x1111, // color bits
1934 false, // depth mask
1935 false, // depth enabled
1936 0, // front stencil mask
1937 0, // back stencil mask
1938 false); // stencil enabled
1940 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1942 .RetiresOnSaturation();
1944 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1945 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1946 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1949 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1951 .RetiresOnSaturation();
1952 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1953 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1956 TEST_P(GLES2DecoderWithShaderTest
, DrawWitFBOThatCantClearDoesNotDraw
) {
1957 const GLuint kFBOClientTextureId
= 4100;
1958 const GLuint kFBOServiceTextureId
= 4101;
1960 // Register a texture id.
1961 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1962 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1963 .RetiresOnSaturation();
1964 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1966 // Setup "render to" texture.
1967 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1969 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1971 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1972 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1973 GL_COLOR_ATTACHMENT0
,
1975 kFBOClientTextureId
,
1976 kFBOServiceTextureId
,
1980 // Setup "render from" texture.
1983 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
1984 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED
))
1985 .RetiresOnSaturation();
1986 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
1988 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1989 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1990 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION
, GetGLError());
1993 TEST_P(GLES2DecoderWithShaderTest
, DrawClearsAfterRenderbufferStorageInFBO
) {
1996 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1998 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1999 DoRenderbufferStorage(
2000 GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 100, 50, GL_NO_ERROR
);
2001 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2002 GL_COLOR_ATTACHMENT0
,
2004 client_renderbuffer_id_
,
2005 kServiceRenderbufferId
,
2007 DoEnableDisable(GL_SCISSOR_TEST
, false);
2008 DoScissor(0, 0, 1, 1);
2010 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
2011 GL_COLOR_BUFFER_BIT
, // clear bits
2016 false, // scissor test
2019 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2020 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2021 false, // Framebuffer has depth
2022 false, // Framebuffer has stencil
2023 0x1111, // color bits
2024 false, // depth mask
2025 false, // depth enabled
2026 0, // front stencil mask
2027 0, // back stencil mask
2028 false); // stencil enabled
2030 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2032 .RetiresOnSaturation();
2034 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2035 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2036 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2039 TEST_P(GLES2DecoderManualInitTest
, DrawArraysClearsAfterTexImage2DNULLCubemap
) {
2041 init
.gl_version
= "opengl es 2.0";
2042 init
.has_alpha
= true;
2043 init
.has_depth
= true;
2044 init
.request_alpha
= true;
2045 init
.request_depth
= true;
2048 static const GLenum faces
[] = {
2049 GL_TEXTURE_CUBE_MAP_POSITIVE_X
, GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
2050 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2051 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
2053 SetupCubemapProgram();
2054 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2055 // Fill out all the faces for 2 levels, leave 2 uncleared.
2056 for (int ii
= 0; ii
< 6; ++ii
) {
2057 GLenum face
= faces
[ii
];
2059 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryId
;
2061 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryOffset
;
2083 // Expect 2 levels will be cleared.
2084 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
2085 GL_TEXTURE_CUBE_MAP
,
2086 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
, 0, GL_RGBA
,
2087 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 2, 2);
2088 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
2089 GL_TEXTURE_CUBE_MAP
,
2090 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
, 1, GL_RGBA
,
2091 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 1, 1);
2092 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2093 SetupExpectationsForApplyingDefaultDirtyState();
2094 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2096 .RetiresOnSaturation();
2098 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2099 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2102 TEST_P(GLES2DecoderWithShaderTest
,
2103 DrawClearsAfterRenderbuffersWithMultipleAttachments
) {
2104 const GLuint kFBOClientTextureId
= 4100;
2105 const GLuint kFBOServiceTextureId
= 4101;
2107 // Register a texture id.
2108 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2109 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2110 .RetiresOnSaturation();
2111 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2113 // Setup "render to" texture.
2114 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2116 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2118 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2119 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2120 GL_COLOR_ATTACHMENT0
,
2122 kFBOClientTextureId
,
2123 kFBOServiceTextureId
,
2128 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
2130 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2131 DoRenderbufferStorage(GL_RENDERBUFFER
,
2132 GL_DEPTH_COMPONENT16
,
2137 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2138 GL_DEPTH_ATTACHMENT
,
2140 client_renderbuffer_id_
,
2141 kServiceRenderbufferId
,
2143 DoEnableDisable(GL_SCISSOR_TEST
, false);
2144 DoScissor(0, 0, 1, 1);
2146 SetupExpectationsForFramebufferClearing(
2147 GL_FRAMEBUFFER
, // target
2148 GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
, // clear bits
2153 false, // scissor test
2156 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2157 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2158 true, // Framebuffer has depth
2159 false, // Framebuffer has stencil
2160 0x1111, // color bits
2162 false, // depth enabled
2163 0, // front stencil mask
2164 0, // back stencil mask
2165 false); // stencil enabled
2167 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2169 .RetiresOnSaturation();
2171 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2172 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2173 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2176 TEST_P(GLES2DecoderWithShaderTest
,
2177 DrawingWithFBOTwiceChecksForFBOCompleteOnce
) {
2178 const GLuint kFBOClientTextureId
= 4100;
2179 const GLuint kFBOServiceTextureId
= 4101;
2181 SetupAllNeededVertexBuffers();
2183 // Register a texture id.
2184 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2185 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2186 .RetiresOnSaturation();
2187 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2189 // Setup "render to" texture that is cleared.
2190 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2191 DoTexImage2D(GL_TEXTURE_2D
,
2200 kSharedMemoryOffset
);
2202 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2203 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2204 GL_COLOR_ATTACHMENT0
,
2206 kFBOClientTextureId
,
2207 kFBOServiceTextureId
,
2211 // Setup "render from" texture.
2214 // Make sure we check for framebuffer complete.
2215 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
2216 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
2217 .RetiresOnSaturation();
2219 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2220 false, // Framebuffer has depth
2221 false, // Framebuffer has stencil
2222 0x1111, // color bits
2223 false, // depth mask
2224 false, // depth enabled
2225 0, // front stencil mask
2226 0, // back stencil mask
2227 false); // stencil enabled
2229 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2231 .RetiresOnSaturation();
2233 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2234 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2235 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2238 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2240 .RetiresOnSaturation();
2241 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2242 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2245 TEST_P(GLES2DecoderManualInitTest
, DrawClearsDepthTexture
) {
2247 init
.extensions
= "GL_ANGLE_depth_texture";
2248 init
.gl_version
= "opengl es 2.0";
2249 init
.has_alpha
= true;
2250 init
.has_depth
= true;
2251 init
.request_alpha
= true;
2252 init
.request_depth
= true;
2253 init
.bind_generates_resource
= true;
2256 SetupDefaultProgram();
2257 SetupAllNeededVertexBuffers();
2258 const GLenum attachment
= GL_DEPTH_ATTACHMENT
;
2259 const GLenum target
= GL_TEXTURE_2D
;
2260 const GLint level
= 0;
2261 DoBindTexture(target
, client_texture_id_
, kServiceTextureId
);
2263 // Create a depth texture.
2264 DoTexImage2D(target
,
2275 // Set scissor rect and disable GL_SCISSOR_TEST to make sure we enable it in
2276 // the clear, then disable it and restore the rect again.
2277 DoScissor(0, 0, 32, 32);
2278 DoEnableDisable(GL_SCISSOR_TEST
, false);
2280 EXPECT_CALL(*gl_
, GenFramebuffersEXT(1, _
)).Times(1).RetiresOnSaturation();
2281 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, _
))
2283 .RetiresOnSaturation();
2286 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT
,
2292 .RetiresOnSaturation();
2293 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT
))
2294 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
2295 .RetiresOnSaturation();
2297 EXPECT_CALL(*gl_
, ClearStencil(0)).Times(1).RetiresOnSaturation();
2298 SetupExpectationsForStencilMask(GLES2Decoder::kDefaultStencilMask
,
2299 GLES2Decoder::kDefaultStencilMask
);
2300 EXPECT_CALL(*gl_
, ClearDepth(1.0f
)).Times(1).RetiresOnSaturation();
2301 SetupExpectationsForDepthMask(true);
2302 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, true);
2303 EXPECT_CALL(*gl_
, Scissor(0, 0, 1, 1)).Times(1).RetiresOnSaturation();
2305 EXPECT_CALL(*gl_
, Clear(GL_DEPTH_BUFFER_BIT
)).Times(1).RetiresOnSaturation();
2307 SetupExpectationsForRestoreClearState(0.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 1.0f
, false,
2310 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, _
)).Times(1).RetiresOnSaturation();
2311 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0))
2313 .RetiresOnSaturation();
2315 SetupExpectationsForApplyingDefaultDirtyState();
2316 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2318 .RetiresOnSaturation();
2320 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2321 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2322 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2325 } // namespace gles2