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/common/id_allocator.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
14 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
15 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
16 #include "gpu/command_buffer/service/context_group.h"
17 #include "gpu/command_buffer/service/context_state.h"
18 #include "gpu/command_buffer/service/gl_surface_mock.h"
19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
21 #include "gpu/command_buffer/service/gpu_switches.h"
22 #include "gpu/command_buffer/service/image_manager.h"
23 #include "gpu/command_buffer/service/mailbox_manager.h"
24 #include "gpu/command_buffer/service/mocks.h"
25 #include "gpu/command_buffer/service/program_manager.h"
26 #include "gpu/command_buffer/service/test_helper.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gl/gl_implementation.h"
29 #include "ui/gl/gl_mock.h"
30 #include "ui/gl/gl_surface_stub.h"
32 #if !defined(GL_DEPTH24_STENCIL8)
33 #define GL_DEPTH24_STENCIL8 0x88F0
36 using ::gfx::MockGLInterface
;
38 using ::testing::DoAll
;
39 using ::testing::InSequence
;
40 using ::testing::Invoke
;
41 using ::testing::MatcherCast
;
42 using ::testing::Mock
;
43 using ::testing::Pointee
;
44 using ::testing::Return
;
45 using ::testing::SaveArg
;
46 using ::testing::SetArrayArgument
;
47 using ::testing::SetArgumentPointee
;
48 using ::testing::SetArgPointee
;
49 using ::testing::StrEq
;
50 using ::testing::StrictMock
;
57 class GLES2DecoderGeometryInstancingTest
: public GLES2DecoderWithShaderTest
{
59 GLES2DecoderGeometryInstancingTest() : GLES2DecoderWithShaderTest() {}
61 virtual void SetUp() {
63 init
.extensions
= "GL_ANGLE_instanced_arrays";
64 init
.gl_version
= "opengl es 2.0";
65 init
.has_alpha
= true;
66 init
.has_depth
= true;
67 init
.request_alpha
= true;
68 init
.request_depth
= true;
69 init
.bind_generates_resource
= true;
71 SetupDefaultProgram();
75 INSTANTIATE_TEST_CASE_P(Service
,
76 GLES2DecoderGeometryInstancingTest
,
79 void GLES2DecoderManualInitTest::DirtyStateMaskTest(GLuint color_bits
,
81 GLuint front_stencil_mask
,
82 GLuint back_stencil_mask
) {
83 ColorMask color_mask_cmd
;
84 color_mask_cmd
.Init((color_bits
& 0x1000) != 0,
85 (color_bits
& 0x0100) != 0,
86 (color_bits
& 0x0010) != 0,
87 (color_bits
& 0x0001) != 0);
88 EXPECT_EQ(error::kNoError
, ExecuteCmd(color_mask_cmd
));
89 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
91 DepthMask depth_mask_cmd
;
92 depth_mask_cmd
.Init(depth_mask
);
93 EXPECT_EQ(error::kNoError
, ExecuteCmd(depth_mask_cmd
));
94 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
96 StencilMaskSeparate front_stencil_mask_cmd
;
97 front_stencil_mask_cmd
.Init(GL_FRONT
, front_stencil_mask
);
98 EXPECT_EQ(error::kNoError
, ExecuteCmd(front_stencil_mask_cmd
));
99 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
101 StencilMaskSeparate back_stencil_mask_cmd
;
102 back_stencil_mask_cmd
.Init(GL_BACK
, back_stencil_mask
);
103 EXPECT_EQ(error::kNoError
, ExecuteCmd(back_stencil_mask_cmd
));
104 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
106 SetupExpectationsForApplyingDirtyState(
107 false, // Framebuffer is RGB
108 true, // Framebuffer has depth
109 true, // Framebuffer has stencil
110 color_bits
, // color bits
111 depth_mask
, // depth mask
112 false, // depth enabled
113 front_stencil_mask
, // front stencil mask
114 back_stencil_mask
, // back stencil mask
115 false); // stencil enabled
117 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
119 .RetiresOnSaturation();
121 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
122 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
123 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
126 // Test that with an RGB backbuffer if we set the color mask to 1,1,1,1 it is
127 // set to 1,1,1,0 at Draw time but is 1,1,1,1 at query time.
128 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferColorMask
) {
130 cmd
.Init(true, true, true, true);
131 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
132 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
135 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
136 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
137 false, // Framebuffer has depth
138 false, // Framebuffer has stencil
139 0x1110, // color bits
141 false, // depth enabled
142 0, // front stencil mask
143 0, // back stencil mask
144 false); // stencil enabled
146 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
148 .RetiresOnSaturation();
150 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
151 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
152 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
154 EXPECT_CALL(*gl_
, GetError())
155 .WillOnce(Return(GL_NO_ERROR
))
156 .WillOnce(Return(GL_NO_ERROR
))
157 .RetiresOnSaturation();
158 typedef GetIntegerv::Result Result
;
159 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
160 EXPECT_CALL(*gl_
, GetIntegerv(GL_COLOR_WRITEMASK
, result
->GetData()))
164 cmd2
.Init(GL_COLOR_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
165 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
167 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_COLOR_WRITEMASK
),
168 result
->GetNumResults());
169 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
170 EXPECT_EQ(1, result
->GetData()[0]);
171 EXPECT_EQ(1, result
->GetData()[1]);
172 EXPECT_EQ(1, result
->GetData()[2]);
173 EXPECT_EQ(1, result
->GetData()[3]);
176 // Test that with no depth if we set DepthMask true that it's set to false at
177 // draw time but querying it returns true.
178 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferDepthMask
) {
179 EXPECT_CALL(*gl_
, DepthMask(true)).Times(0).RetiresOnSaturation();
182 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
183 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
186 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
187 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
188 false, // Framebuffer has depth
189 false, // Framebuffer has stencil
190 0x1110, // color bits
192 false, // depth enabled
193 0, // front stencil mask
194 0, // back stencil mask
195 false); // stencil enabled
197 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
199 .RetiresOnSaturation();
201 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
202 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
203 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
205 EXPECT_CALL(*gl_
, GetError())
206 .WillOnce(Return(GL_NO_ERROR
))
207 .WillOnce(Return(GL_NO_ERROR
))
208 .RetiresOnSaturation();
209 typedef GetIntegerv::Result Result
;
210 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
211 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_WRITEMASK
, result
->GetData()))
215 cmd2
.Init(GL_DEPTH_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
216 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
218 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_WRITEMASK
),
219 result
->GetNumResults());
220 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
221 EXPECT_EQ(1, result
->GetData()[0]);
224 // Test that with no stencil if we set the stencil mask it's still set to 0 at
225 // draw time but gets our value if we query.
226 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferStencilMask
) {
227 const GLint kMask
= 123;
228 EXPECT_CALL(*gl_
, StencilMask(kMask
)).Times(0).RetiresOnSaturation();
231 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
232 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
235 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
236 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
237 false, // Framebuffer has depth
238 false, // Framebuffer has stencil
239 0x1110, // color bits
241 false, // depth enabled
242 0, // front stencil mask
243 0, // back stencil mask
244 false); // stencil enabled
246 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
248 .RetiresOnSaturation();
250 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
251 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
252 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
254 EXPECT_CALL(*gl_
, GetError())
255 .WillOnce(Return(GL_NO_ERROR
))
256 .WillOnce(Return(GL_NO_ERROR
))
257 .RetiresOnSaturation();
258 typedef GetIntegerv::Result Result
;
259 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
260 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_WRITEMASK
, result
->GetData()))
264 cmd2
.Init(GL_STENCIL_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
265 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
267 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_WRITEMASK
),
268 result
->GetNumResults());
269 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
270 EXPECT_EQ(kMask
, result
->GetData()[0]);
273 // Test that if an FBO is bound we get the correct masks.
274 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferColorMaskFBO
) {
276 cmd
.Init(true, true, true, true);
277 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
278 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
282 DoEnableVertexAttribArray(0);
283 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
284 DoEnableVertexAttribArray(1);
285 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
286 DoEnableVertexAttribArray(2);
287 DoVertexAttribPointer(2, 2, GL_FLOAT
, 0, 0);
288 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
289 false, // Framebuffer has depth
290 false, // Framebuffer has stencil
291 0x1110, // color bits
293 false, // depth enabled
294 0, // front stencil mask
295 0, // back stencil mask
296 false); // stencil enabled
298 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
300 .RetiresOnSaturation();
302 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
303 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
304 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
306 // Check that no extra calls are made on the next draw.
307 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
309 .RetiresOnSaturation();
310 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
311 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
313 // Setup Frame buffer.
314 // needs to be 1x1 or else it's not renderable.
315 const GLsizei kWidth
= 1;
316 const GLsizei kHeight
= 1;
317 const GLenum kFormat
= GL_RGB
;
318 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
319 // Pass some data so the texture will be marked as cleared.
320 DoTexImage2D(GL_TEXTURE_2D
,
329 kSharedMemoryOffset
);
331 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
332 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
333 GL_COLOR_ATTACHMENT0
,
339 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
340 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
341 .RetiresOnSaturation();
343 // This time state needs to be set.
344 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
345 false, // Framebuffer has depth
346 false, // Framebuffer has stencil
347 0x1110, // color bits
349 false, // depth enabled
350 0, // front stencil mask
351 0, // back stencil mask
352 false); // stencil enabled
354 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
356 .RetiresOnSaturation();
357 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
358 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
360 // Check that no extra calls are made on the next draw.
361 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
363 .RetiresOnSaturation();
364 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
365 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
368 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
370 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
371 false, // Framebuffer has depth
372 false, // Framebuffer has stencil
373 0x1110, // color bits
375 false, // depth enabled
376 0, // front stencil mask
377 0, // back stencil mask
378 false); // stencil enabled
380 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
382 .RetiresOnSaturation();
383 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
384 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
387 TEST_P(GLES2DecoderManualInitTest
, DepthEnableWithDepth
) {
389 init
.gl_version
= "3.0";
390 init
.has_depth
= true;
391 init
.request_depth
= true;
392 init
.bind_generates_resource
= true;
396 cmd
.Init(GL_DEPTH_TEST
);
397 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
398 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
400 SetupDefaultProgram();
402 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
403 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
404 true, // Framebuffer has depth
405 false, // Framebuffer has stencil
406 0x1110, // color bits
408 true, // depth enabled
409 0, // front stencil mask
410 0, // back stencil mask
411 false); // stencil enabled
413 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
415 .RetiresOnSaturation();
417 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
418 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
419 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
421 EXPECT_CALL(*gl_
, GetError())
422 .WillOnce(Return(GL_NO_ERROR
))
423 .WillOnce(Return(GL_NO_ERROR
))
424 .RetiresOnSaturation();
425 typedef GetIntegerv::Result Result
;
426 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
427 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_TEST
, _
))
429 .RetiresOnSaturation();
432 cmd2
.Init(GL_DEPTH_TEST
, shared_memory_id_
, shared_memory_offset_
);
433 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
434 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST
),
435 result
->GetNumResults());
436 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
437 EXPECT_EQ(1, result
->GetData()[0]);
440 TEST_P(GLES2DecoderManualInitTest
, DepthEnableWithoutRequestedDepth
) {
442 init
.gl_version
= "3.0";
443 init
.has_depth
= true;
444 init
.bind_generates_resource
= true;
448 cmd
.Init(GL_DEPTH_TEST
);
449 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
450 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
452 SetupDefaultProgram();
454 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
455 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
456 false, // Framebuffer has depth
457 false, // Framebuffer has stencil
458 0x1110, // color bits
460 false, // depth enabled
461 0, // front stencil mask
462 0, // back stencil mask
463 false); // stencil enabled
465 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
467 .RetiresOnSaturation();
469 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
470 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
471 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
473 EXPECT_CALL(*gl_
, GetError())
474 .WillOnce(Return(GL_NO_ERROR
))
475 .WillOnce(Return(GL_NO_ERROR
))
476 .RetiresOnSaturation();
477 typedef GetIntegerv::Result Result
;
478 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
479 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_TEST
, _
))
481 .RetiresOnSaturation();
484 cmd2
.Init(GL_DEPTH_TEST
, shared_memory_id_
, shared_memory_offset_
);
485 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
486 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST
),
487 result
->GetNumResults());
488 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
489 EXPECT_EQ(1, result
->GetData()[0]);
492 TEST_P(GLES2DecoderManualInitTest
, StencilEnableWithStencil
) {
494 init
.gl_version
= "3.0";
495 init
.has_stencil
= true;
496 init
.request_stencil
= true;
497 init
.bind_generates_resource
= true;
501 cmd
.Init(GL_STENCIL_TEST
);
502 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
503 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
505 SetupDefaultProgram();
507 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
508 SetupExpectationsForApplyingDirtyState(
509 true, // Framebuffer is RGB
510 false, // Framebuffer has depth
511 true, // Framebuffer has stencil
512 0x1110, // color bits
514 false, // depth enabled
515 GLES2Decoder::kDefaultStencilMask
, // front stencil mask
516 GLES2Decoder::kDefaultStencilMask
, // back stencil mask
517 true); // stencil enabled
519 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
521 .RetiresOnSaturation();
523 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
524 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
525 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
527 EXPECT_CALL(*gl_
, GetError())
528 .WillOnce(Return(GL_NO_ERROR
))
529 .WillOnce(Return(GL_NO_ERROR
))
530 .RetiresOnSaturation();
531 typedef GetIntegerv::Result Result
;
532 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
533 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_TEST
, _
))
535 .RetiresOnSaturation();
538 cmd2
.Init(GL_STENCIL_TEST
, shared_memory_id_
, shared_memory_offset_
);
539 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
540 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST
),
541 result
->GetNumResults());
542 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
543 EXPECT_EQ(1, result
->GetData()[0]);
546 TEST_P(GLES2DecoderManualInitTest
, StencilEnableWithoutRequestedStencil
) {
548 init
.gl_version
= "3.0";
549 init
.has_stencil
= true;
550 init
.bind_generates_resource
= true;
554 cmd
.Init(GL_STENCIL_TEST
);
555 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
556 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
558 SetupDefaultProgram();
560 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
561 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
562 false, // Framebuffer has depth
563 false, // Framebuffer has stencil
564 0x1110, // color bits
566 false, // depth enabled
567 0, // front stencil mask
568 0, // back stencil mask
569 false); // stencil enabled
571 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
573 .RetiresOnSaturation();
575 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
576 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
577 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
579 EXPECT_CALL(*gl_
, GetError())
580 .WillOnce(Return(GL_NO_ERROR
))
581 .WillOnce(Return(GL_NO_ERROR
))
582 .RetiresOnSaturation();
583 typedef GetIntegerv::Result Result
;
584 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
585 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_TEST
, _
))
587 .RetiresOnSaturation();
590 cmd2
.Init(GL_STENCIL_TEST
, shared_memory_id_
, shared_memory_offset_
);
591 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
592 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST
),
593 result
->GetNumResults());
594 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
595 EXPECT_EQ(1, result
->GetData()[0]);
598 TEST_P(GLES2DecoderManualInitTest
, CachedColorMask
) {
600 init
.gl_version
= "3.0";
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
.gl_version
= "3.0";
629 init
.has_alpha
= true;
630 init
.has_depth
= true;
631 init
.has_stencil
= true;
632 init
.request_alpha
= true;
633 init
.request_depth
= true;
634 init
.request_stencil
= true;
635 init
.bind_generates_resource
= true;
638 SetupDefaultProgram();
639 SetupAllNeededVertexBuffers();
642 // Test all depth_mask combinations twice.
643 for (int i
= 0; i
< 4; i
++) {
644 bool depth_mask
= (i
& 1) == 1;
646 // Toggle color masks to force ApplyDirtyState each time.
647 DirtyStateMaskTest(0x1010, depth_mask
, 0xffffffff, 0xffffffff);
648 DirtyStateMaskTest(0x0101, depth_mask
, 0xffffffff, 0xffffffff);
649 DirtyStateMaskTest(0x1010, depth_mask
, 0xffffffff, 0xffffffff);
653 TEST_P(GLES2DecoderManualInitTest
, CachedStencilMask
) {
655 init
.gl_version
= "3.0";
656 init
.has_alpha
= true;
657 init
.has_depth
= true;
658 init
.has_stencil
= true;
659 init
.request_alpha
= true;
660 init
.request_depth
= true;
661 init
.request_stencil
= true;
662 init
.bind_generates_resource
= true;
665 SetupDefaultProgram();
666 SetupAllNeededVertexBuffers();
669 // Test all stencil_mask combinations twice.
670 for (int i
= 0; i
< 4; i
++) {
671 GLuint stencil_mask
= (i
& 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
673 // Toggle color masks to force ApplyDirtyState each time.
674 DirtyStateMaskTest(0x1010, true, stencil_mask
, 0xffffffff);
675 DirtyStateMaskTest(0x0101, true, stencil_mask
, 0xffffffff);
676 DirtyStateMaskTest(0x1010, true, stencil_mask
, 0xffffffff);
679 for (int i
= 0; i
< 4; i
++) {
680 GLuint stencil_mask
= (i
& 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
682 // Toggle color masks to force ApplyDirtyState each time.
683 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask
);
684 DirtyStateMaskTest(0x0101, true, 0xffffffff, stencil_mask
);
685 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask
);
689 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysNoAttributesSucceeds
) {
691 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
692 SetupExpectationsForApplyingDefaultDirtyState();
694 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
696 .RetiresOnSaturation();
698 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
699 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
700 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
703 // Tests when the math overflows (0x40000000 * sizeof GLfloat)
704 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0OverflowFails
) {
705 const GLsizei kLargeCount
= 0x40000000;
707 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
709 cmd
.Init(GL_TRIANGLES
, 0, kLargeCount
);
710 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
711 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
712 EXPECT_FALSE(GetDecoder()->WasContextLost());
715 // Tests when the math overflows (0x7FFFFFFF + 1 = 0x8000000 verts)
716 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0PosToNegFails
) {
717 const GLsizei kLargeCount
= 0x7FFFFFFF;
719 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
721 cmd
.Init(GL_TRIANGLES
, 0, kLargeCount
);
722 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
723 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
724 EXPECT_FALSE(GetDecoder()->WasContextLost());
727 // Tests when the driver returns an error
728 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0OOMFails
) {
729 const GLsizei kFakeLargeCount
= 0x1234;
731 AddExpectationsForSimulatedAttrib0WithError(
732 kFakeLargeCount
, 0, GL_OUT_OF_MEMORY
);
733 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
735 cmd
.Init(GL_TRIANGLES
, 0, kFakeLargeCount
);
736 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
737 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
738 EXPECT_FALSE(GetDecoder()->WasContextLost());
741 // Test that we lose context.
742 TEST_P(GLES2DecoderManualInitTest
, LoseContextWhenOOM
) {
744 init
.gl_version
= "3.0";
745 init
.has_alpha
= true;
746 init
.has_depth
= true;
747 init
.request_alpha
= true;
748 init
.request_depth
= true;
749 init
.bind_generates_resource
= true;
750 init
.lose_context_when_out_of_memory
= true;
752 SetupDefaultProgram();
754 const GLsizei kFakeLargeCount
= 0x1234;
756 AddExpectationsForSimulatedAttrib0WithError(
757 kFakeLargeCount
, 0, GL_OUT_OF_MEMORY
);
758 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
759 // Other contexts in the group should be lost also.
760 EXPECT_CALL(*mock_decoder_
, LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB
))
762 .RetiresOnSaturation();
764 cmd
.Init(GL_TRIANGLES
, 0, kFakeLargeCount
);
765 // This context should be lost.
766 EXPECT_EQ(error::kLostContext
, ExecuteCmd(cmd
));
767 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
768 EXPECT_TRUE(decoder_
->WasContextLost());
771 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysBadTextureUsesBlack
) {
772 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
773 // This is an NPOT texture. As the default filtering requires mips
774 // this should trigger replacing with black textures before rendering.
775 DoTexImage2D(GL_TEXTURE_2D
,
784 kSharedMemoryOffset
);
785 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
788 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
790 .RetiresOnSaturation();
792 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceBlackTexture2dId
))
794 .RetiresOnSaturation();
795 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
797 .RetiresOnSaturation();
798 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
800 .RetiresOnSaturation();
801 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
803 .RetiresOnSaturation();
804 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
806 .RetiresOnSaturation();
808 SetupExpectationsForApplyingDefaultDirtyState();
810 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
811 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
812 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
815 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysMissingAttributesFails
) {
816 DoEnableVertexAttribArray(1);
818 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
820 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
821 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
822 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
825 TEST_P(GLES2DecoderWithShaderTest
,
826 DrawArraysMissingAttributesZeroCountSucceeds
) {
827 DoEnableVertexAttribArray(1);
829 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
831 cmd
.Init(GL_TRIANGLES
, 0, 0);
832 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
833 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
836 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysValidAttributesSucceeds
) {
839 DoEnableVertexAttribArray(1);
840 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
841 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
842 SetupExpectationsForApplyingDefaultDirtyState();
844 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
846 .RetiresOnSaturation();
848 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
849 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
850 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
853 // Same as DrawArraysValidAttributesSucceeds, but with workaround
854 // |init_vertex_attributes|.
855 TEST_P(GLES2DecoderManualInitTest
, InitVertexAttributes
) {
856 CommandLine
command_line(0, NULL
);
857 command_line
.AppendSwitchASCII(
858 switches::kGpuDriverBugWorkarounds
,
859 base::IntToString(gpu::INIT_VERTEX_ATTRIBUTES
));
861 init
.gl_version
= "3.0";
862 init
.has_alpha
= true;
863 init
.has_depth
= true;
864 init
.request_alpha
= true;
865 init
.request_depth
= true;
866 init
.bind_generates_resource
= true;
867 InitDecoderWithCommandLine(init
, &command_line
);
868 SetupDefaultProgram();
871 DoEnableVertexAttribArray(1);
872 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
873 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
874 SetupExpectationsForApplyingDefaultDirtyState();
876 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
878 .RetiresOnSaturation();
880 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
881 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
882 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
885 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysDeletedBufferFails
) {
887 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
888 DeleteVertexBuffer();
890 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
892 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
893 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
894 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
897 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysDeletedProgramSucceeds
) {
899 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
900 SetupExpectationsForApplyingDefaultDirtyState();
901 DoDeleteProgram(client_program_id_
, kServiceProgramId
);
903 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(1).RetiresOnSaturation();
904 EXPECT_CALL(*gl_
, DeleteProgram(kServiceProgramId
)).Times(1);
906 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
907 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
908 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
911 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysWithInvalidModeFails
) {
913 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
915 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
917 cmd
.Init(GL_QUADS
, 0, 1);
918 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
919 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
920 cmd
.Init(GL_POLYGON
, 0, 1);
921 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
922 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
925 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysInvalidCountFails
) {
927 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
930 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
932 cmd
.Init(GL_TRIANGLES
, 1, kNumVertices
);
933 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
934 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
935 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
937 // Try with count > size
938 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
+ 1);
939 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
940 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
941 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
943 // Try with attrib offset > 0
944 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
945 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 4);
946 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
947 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
948 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
950 // Try with size > 2 (ie, vec3 instead of vec2)
951 DoVertexAttribPointer(1, 3, GL_FLOAT
, 0, 0);
952 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
953 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
954 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
956 // Try with stride > 8 (vec2 + vec2 byte)
957 DoVertexAttribPointer(1, 2, GL_FLOAT
, sizeof(GLfloat
) * 3, 0);
958 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
959 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
960 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
963 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysInstancedANGLEFails
) {
966 DoEnableVertexAttribArray(1);
967 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
969 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
971 .RetiresOnSaturation();
972 DrawArraysInstancedANGLE cmd
;
973 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
974 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
975 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
978 TEST_P(GLES2DecoderWithShaderTest
, VertexAttribDivisorANGLEFails
) {
981 DoEnableVertexAttribArray(1);
982 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
984 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(_
, _
))
986 .RetiresOnSaturation();
988 VertexAttribDivisorANGLE cmd
;
990 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
991 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
994 TEST_P(GLES2DecoderGeometryInstancingTest
,
995 DrawArraysInstancedANGLENoAttributesFails
) {
998 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1000 .RetiresOnSaturation();
1001 DrawArraysInstancedANGLE cmd
;
1002 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1003 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1004 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1007 TEST_P(GLES2DecoderGeometryInstancingTest
,
1008 DrawArraysInstancedANGLESimulatedAttrib0
) {
1010 SetupVertexBuffer();
1011 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1013 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
1014 SetupExpectationsForApplyingDefaultDirtyState();
1016 DoVertexAttribDivisorANGLE(0, 1);
1017 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, 3))
1019 .RetiresOnSaturation();
1020 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
1022 .RetiresOnSaturation();
1023 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 1))
1025 .RetiresOnSaturation();
1026 DrawArraysInstancedANGLE cmd
;
1027 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 3);
1028 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1029 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1032 TEST_P(GLES2DecoderGeometryInstancingTest
,
1033 DrawArraysInstancedANGLEMissingAttributesFails
) {
1034 DoEnableVertexAttribArray(1);
1036 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1037 DrawArraysInstancedANGLE cmd
;
1038 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1039 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1040 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1043 TEST_P(GLES2DecoderGeometryInstancingTest
,
1044 DrawArraysInstancedANGLEMissingAttributesZeroCountSucceeds
) {
1045 DoEnableVertexAttribArray(1);
1047 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1048 DrawArraysInstancedANGLE cmd
;
1049 cmd
.Init(GL_TRIANGLES
, 0, 0, 1);
1050 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1051 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1054 TEST_P(GLES2DecoderGeometryInstancingTest
,
1055 DrawArraysInstancedANGLEValidAttributesSucceeds
) {
1057 SetupVertexBuffer();
1058 DoEnableVertexAttribArray(1);
1059 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1060 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
1061 SetupExpectationsForApplyingDefaultDirtyState();
1063 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, 1))
1065 .RetiresOnSaturation();
1066 DrawArraysInstancedANGLE cmd
;
1067 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1068 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1069 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1072 TEST_P(GLES2DecoderGeometryInstancingTest
,
1073 DrawArraysInstancedANGLEWithInvalidModeFails
) {
1074 SetupVertexBuffer();
1075 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1077 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1078 DrawArraysInstancedANGLE cmd
;
1079 cmd
.Init(GL_QUADS
, 0, 1, 1);
1080 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1081 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1082 cmd
.Init(GL_POLYGON
, 0, 1, 1);
1083 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1084 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1087 TEST_P(GLES2DecoderGeometryInstancingTest
,
1088 DrawArraysInstancedANGLEInvalidPrimcountFails
) {
1089 SetupVertexBuffer();
1090 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1092 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1093 DrawArraysInstancedANGLE cmd
;
1094 cmd
.Init(GL_TRIANGLES
, 0, 1, -1);
1095 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1096 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1099 // Per-instance data is twice as large, but number of instances is half
1100 TEST_P(GLES2DecoderGeometryInstancingTest
,
1101 DrawArraysInstancedANGLELargeInstanceSucceeds
) {
1103 SetupVertexBuffer();
1104 SetupExpectationsForApplyingDefaultDirtyState();
1105 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1107 DoEnableVertexAttribArray(0);
1108 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1109 DoVertexAttribDivisorANGLE(0, 1);
1112 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
/ 2))
1114 .RetiresOnSaturation();
1115 DrawArraysInstancedANGLE cmd
;
1116 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
/ 2);
1117 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1118 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1121 // Regular drawArrays takes the divisor into account
1122 TEST_P(GLES2DecoderGeometryInstancingTest
,
1123 DrawArraysWithDivisorSucceeds
) {
1125 SetupVertexBuffer();
1126 SetupExpectationsForApplyingDefaultDirtyState();
1127 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1129 DoEnableVertexAttribArray(0);
1130 // Access the data right at the end of the buffer.
1131 DoVertexAttribPointer(
1132 0, 2, GL_FLOAT
, 0, (kNumVertices
- 1) * 2 * sizeof(GLfloat
));
1133 DoVertexAttribDivisorANGLE(0, 1);
1136 DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1138 .RetiresOnSaturation();
1140 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1141 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1142 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1145 // Per-instance data is twice as large, but divisor is twice
1146 TEST_P(GLES2DecoderGeometryInstancingTest
,
1147 DrawArraysInstancedANGLELargeDivisorSucceeds
) {
1149 SetupVertexBuffer();
1150 SetupExpectationsForApplyingDefaultDirtyState();
1151 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1153 DoEnableVertexAttribArray(0);
1154 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1155 DoVertexAttribDivisorANGLE(0, 2);
1158 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
))
1160 .RetiresOnSaturation();
1161 DrawArraysInstancedANGLE cmd
;
1162 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
);
1163 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1164 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1167 TEST_P(GLES2DecoderGeometryInstancingTest
, DrawArraysInstancedANGLELargeFails
) {
1169 SetupVertexBuffer();
1170 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1172 DoEnableVertexAttribArray(0);
1173 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1174 DoVertexAttribDivisorANGLE(0, 1);
1175 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1177 .RetiresOnSaturation();
1178 DrawArraysInstancedANGLE cmd
;
1179 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
+ 1);
1180 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1181 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1182 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1184 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1186 .RetiresOnSaturation();
1187 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
+ 1, kNumVertices
);
1188 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1189 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1190 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1193 // Per-index data is twice as large, but number of indices is half
1194 TEST_P(GLES2DecoderGeometryInstancingTest
,
1195 DrawArraysInstancedANGLELargeIndexSucceeds
) {
1197 SetupVertexBuffer();
1198 SetupExpectationsForApplyingDefaultDirtyState();
1199 DoVertexAttribPointer(1, 4, GL_FLOAT
, 0, 0);
1201 DoEnableVertexAttribArray(0);
1202 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1203 DoVertexAttribDivisorANGLE(0, 1);
1206 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
/ 2, kNumVertices
))
1208 .RetiresOnSaturation();
1209 DrawArraysInstancedANGLE cmd
;
1210 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
/ 2, kNumVertices
);
1211 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1212 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1215 TEST_P(GLES2DecoderGeometryInstancingTest
,
1216 DrawArraysInstancedANGLENoDivisor0Fails
) {
1218 SetupVertexBuffer();
1219 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1221 DoEnableVertexAttribArray(0);
1222 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1223 DoVertexAttribDivisorANGLE(0, 1);
1224 DoVertexAttribDivisorANGLE(1, 1);
1225 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1227 .RetiresOnSaturation();
1228 DrawArraysInstancedANGLE cmd
;
1229 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1230 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1231 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1232 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1235 TEST_P(GLES2DecoderGeometryInstancingTest
,
1236 DrawArraysNoDivisor0Fails
) {
1238 SetupVertexBuffer();
1239 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1241 DoEnableVertexAttribArray(0);
1242 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1243 DoVertexAttribDivisorANGLE(0, 1);
1244 DoVertexAttribDivisorANGLE(1, 1);
1245 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
))
1247 .RetiresOnSaturation();
1249 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1250 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1251 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1252 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1255 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsNoAttributesSucceeds
) {
1258 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
1259 SetupExpectationsForApplyingDefaultDirtyState();
1261 DrawElements(GL_TRIANGLES
,
1262 kValidIndexRangeCount
,
1264 BufferOffset(kValidIndexRangeStart
* 2)))
1266 .RetiresOnSaturation();
1268 cmd
.Init(GL_TRIANGLES
,
1269 kValidIndexRangeCount
,
1271 kValidIndexRangeStart
* 2);
1272 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1273 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1276 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsMissingAttributesFails
) {
1278 DoEnableVertexAttribArray(1);
1280 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1282 cmd
.Init(GL_TRIANGLES
,
1283 kValidIndexRangeCount
,
1285 kValidIndexRangeStart
* 2);
1286 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1287 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1290 TEST_P(GLES2DecoderWithShaderTest
,
1291 DrawElementsMissingAttributesZeroCountSucceeds
) {
1293 DoEnableVertexAttribArray(1);
1295 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1297 cmd
.Init(GL_TRIANGLES
, 0, GL_UNSIGNED_SHORT
, kValidIndexRangeStart
* 2);
1298 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1299 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1302 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsExtraAttributesFails
) {
1304 DoEnableVertexAttribArray(6);
1306 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1308 cmd
.Init(GL_TRIANGLES
,
1309 kValidIndexRangeCount
,
1311 kValidIndexRangeStart
* 2);
1312 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1313 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1316 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsValidAttributesSucceeds
) {
1318 SetupVertexBuffer();
1320 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1321 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1322 SetupExpectationsForApplyingDefaultDirtyState();
1325 DrawElements(GL_TRIANGLES
,
1326 kValidIndexRangeCount
,
1328 BufferOffset(kValidIndexRangeStart
* 2)))
1330 .RetiresOnSaturation();
1332 cmd
.Init(GL_TRIANGLES
,
1333 kValidIndexRangeCount
,
1335 kValidIndexRangeStart
* 2);
1336 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1337 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1340 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedBufferFails
) {
1341 SetupVertexBuffer();
1343 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1344 DeleteIndexBuffer();
1346 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1348 cmd
.Init(GL_TRIANGLES
,
1349 kValidIndexRangeCount
,
1351 kValidIndexRangeStart
* 2);
1352 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1353 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1356 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedProgramSucceeds
) {
1359 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
1360 SetupExpectationsForApplyingDefaultDirtyState();
1361 DoDeleteProgram(client_program_id_
, kServiceProgramId
);
1363 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(1);
1364 EXPECT_CALL(*gl_
, DeleteProgram(kServiceProgramId
)).Times(1);
1366 cmd
.Init(GL_TRIANGLES
,
1367 kValidIndexRangeCount
,
1369 kValidIndexRangeStart
* 2);
1370 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1371 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1374 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsWithInvalidModeFails
) {
1375 SetupVertexBuffer();
1377 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1379 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1382 kValidIndexRangeCount
,
1384 kValidIndexRangeStart
* 2);
1385 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1386 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1387 cmd
.Init(GL_POLYGON
,
1388 kValidIndexRangeCount
,
1390 kValidIndexRangeStart
);
1391 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1392 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1395 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsInvalidCountFails
) {
1396 SetupVertexBuffer();
1398 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1401 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1403 cmd
.Init(GL_TRIANGLES
, kNumIndices
, GL_UNSIGNED_SHORT
, 2);
1404 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1405 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1406 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1408 // Try with count > size
1409 cmd
.Init(GL_TRIANGLES
, kNumIndices
+ 1, GL_UNSIGNED_SHORT
, 0);
1410 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1411 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1412 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1415 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsOutOfRangeIndicesFails
) {
1416 SetupVertexBuffer();
1418 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1420 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1422 cmd
.Init(GL_TRIANGLES
,
1423 kInvalidIndexRangeCount
,
1425 kInvalidIndexRangeStart
* 2);
1426 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1427 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1428 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1431 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsOddOffsetForUint16Fails
) {
1432 SetupVertexBuffer();
1434 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1436 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1438 cmd
.Init(GL_TRIANGLES
, kInvalidIndexRangeCount
, GL_UNSIGNED_SHORT
, 1);
1439 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1440 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1441 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1444 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsInstancedANGLEFails
) {
1446 SetupVertexBuffer();
1448 DoEnableVertexAttribArray(1);
1449 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1451 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1453 .RetiresOnSaturation();
1454 DrawElementsInstancedANGLE cmd
;
1455 cmd
.Init(GL_TRIANGLES
,
1456 kValidIndexRangeCount
,
1458 kValidIndexRangeStart
* 2,
1460 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1461 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1464 TEST_P(GLES2DecoderGeometryInstancingTest
,
1465 DrawElementsInstancedANGLENoAttributesFails
) {
1469 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1471 .RetiresOnSaturation();
1472 DrawElementsInstancedANGLE cmd
;
1473 cmd
.Init(GL_TRIANGLES
,
1474 kValidIndexRangeCount
,
1476 kValidIndexRangeStart
* 2,
1478 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1479 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1482 TEST_P(GLES2DecoderGeometryInstancingTest
,
1483 DrawElementsInstancedANGLESimulatedAttrib0
) {
1485 SetupVertexBuffer();
1487 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1489 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1490 SetupExpectationsForApplyingDefaultDirtyState();
1492 DoVertexAttribDivisorANGLE(0, 1);
1495 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1496 kValidIndexRangeCount
,
1498 BufferOffset(kValidIndexRangeStart
* 2),
1501 .RetiresOnSaturation();
1502 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
1504 .RetiresOnSaturation();
1505 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 1))
1507 .RetiresOnSaturation();
1508 DrawElementsInstancedANGLE cmd
;
1509 cmd
.Init(GL_TRIANGLES
,
1510 kValidIndexRangeCount
,
1512 kValidIndexRangeStart
* 2,
1514 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1515 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1518 TEST_P(GLES2DecoderGeometryInstancingTest
,
1519 DrawElementsInstancedANGLEMissingAttributesFails
) {
1521 DoEnableVertexAttribArray(1);
1523 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1524 DrawElementsInstancedANGLE cmd
;
1525 cmd
.Init(GL_TRIANGLES
,
1526 kValidIndexRangeCount
,
1528 kValidIndexRangeStart
* 2,
1530 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1531 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1534 TEST_P(GLES2DecoderGeometryInstancingTest
,
1535 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds
) {
1537 DoEnableVertexAttribArray(1);
1539 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1540 DrawElementsInstancedANGLE cmd
;
1541 cmd
.Init(GL_TRIANGLES
, 0, GL_UNSIGNED_SHORT
, kValidIndexRangeStart
* 2, 1);
1542 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1543 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1546 TEST_P(GLES2DecoderGeometryInstancingTest
,
1547 DrawElementsInstancedANGLEValidAttributesSucceeds
) {
1550 SetupVertexBuffer();
1551 DoEnableVertexAttribArray(1);
1552 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1553 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1554 SetupExpectationsForApplyingDefaultDirtyState();
1558 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1559 kValidIndexRangeCount
,
1561 BufferOffset(kValidIndexRangeStart
* 2),
1564 .RetiresOnSaturation();
1565 DrawElementsInstancedANGLE cmd
;
1566 cmd
.Init(GL_TRIANGLES
,
1567 kValidIndexRangeCount
,
1569 kValidIndexRangeStart
* 2,
1571 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1572 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1575 TEST_P(GLES2DecoderGeometryInstancingTest
,
1576 DrawElementsInstancedANGLEWithInvalidModeFails
) {
1578 SetupVertexBuffer();
1579 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1581 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1582 DrawElementsInstancedANGLE cmd
;
1584 kValidIndexRangeCount
,
1586 kValidIndexRangeStart
* 2,
1588 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1589 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1590 cmd
.Init(GL_INVALID_ENUM
,
1591 kValidIndexRangeCount
,
1593 kValidIndexRangeStart
* 2,
1595 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1596 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1599 // Per-instance data is twice as large, but number of instances is half
1600 TEST_P(GLES2DecoderGeometryInstancingTest
,
1601 DrawElementsInstancedANGLELargeInstanceSucceeds
) {
1604 SetupVertexBuffer();
1605 SetupExpectationsForApplyingDefaultDirtyState();
1606 // Add offset so we're sure we're accessing data near the end of the buffer.
1607 DoVertexAttribPointer(
1612 (kNumVertices
- kMaxValidIndex
- 1) * 2 * sizeof(GLfloat
));
1614 DoEnableVertexAttribArray(0);
1615 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1616 DoVertexAttribDivisorANGLE(0, 1);
1619 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1620 kValidIndexRangeCount
,
1622 BufferOffset(kValidIndexRangeStart
* 2),
1625 .RetiresOnSaturation();
1626 DrawElementsInstancedANGLE cmd
;
1627 cmd
.Init(GL_TRIANGLES
,
1628 kValidIndexRangeCount
,
1630 kValidIndexRangeStart
* 2,
1632 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1633 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1636 // Regular drawElements takes the divisor into account
1637 TEST_P(GLES2DecoderGeometryInstancingTest
,
1638 DrawElementsWithDivisorSucceeds
) {
1641 SetupVertexBuffer();
1642 SetupExpectationsForApplyingDefaultDirtyState();
1643 // Add offset so we're sure we're accessing data near the end of the buffer.
1644 DoVertexAttribPointer(
1649 (kNumVertices
- kMaxValidIndex
- 1) * 2 * sizeof(GLfloat
));
1651 DoEnableVertexAttribArray(0);
1652 // Access the data right at the end of the buffer.
1653 DoVertexAttribPointer(
1654 0, 2, GL_FLOAT
, 0, (kNumVertices
- 1) * 2 * sizeof(GLfloat
));
1655 DoVertexAttribDivisorANGLE(0, 1);
1658 DrawElements(GL_TRIANGLES
,
1659 kValidIndexRangeCount
,
1661 BufferOffset(kValidIndexRangeStart
* 2)))
1663 .RetiresOnSaturation();
1665 cmd
.Init(GL_TRIANGLES
,
1666 kValidIndexRangeCount
,
1668 kValidIndexRangeStart
* 2);
1669 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1670 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1673 // Per-instance data is twice as large, but divisor is twice
1674 TEST_P(GLES2DecoderGeometryInstancingTest
,
1675 DrawElementsInstancedANGLELargeDivisorSucceeds
) {
1678 SetupVertexBuffer();
1679 SetupExpectationsForApplyingDefaultDirtyState();
1680 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1682 DoEnableVertexAttribArray(0);
1683 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1684 DoVertexAttribDivisorANGLE(0, 2);
1687 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1688 kValidIndexRangeCount
,
1690 BufferOffset(kValidIndexRangeStart
* 2),
1693 .RetiresOnSaturation();
1694 DrawElementsInstancedANGLE cmd
;
1695 cmd
.Init(GL_TRIANGLES
,
1696 kValidIndexRangeCount
,
1698 kValidIndexRangeStart
* 2,
1700 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1701 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1704 TEST_P(GLES2DecoderGeometryInstancingTest
,
1705 DrawElementsInstancedANGLELargeFails
) {
1708 SetupVertexBuffer();
1709 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1711 DoEnableVertexAttribArray(0);
1712 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1713 DoVertexAttribDivisorANGLE(0, 1);
1714 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1716 .RetiresOnSaturation();
1717 DrawElementsInstancedANGLE cmd
;
1718 cmd
.Init(GL_TRIANGLES
,
1719 kValidIndexRangeCount
,
1721 kValidIndexRangeStart
* 2,
1723 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1724 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1725 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1727 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1729 .RetiresOnSaturation();
1730 cmd
.Init(GL_TRIANGLES
,
1731 kInvalidIndexRangeCount
,
1733 kInvalidIndexRangeStart
* 2,
1735 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1736 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1737 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1740 TEST_P(GLES2DecoderGeometryInstancingTest
,
1741 DrawElementsInstancedANGLEInvalidPrimcountFails
) {
1744 SetupVertexBuffer();
1745 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1747 DoEnableVertexAttribArray(0);
1748 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1749 DoVertexAttribDivisorANGLE(0, 1);
1750 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1752 .RetiresOnSaturation();
1753 DrawElementsInstancedANGLE cmd
;
1754 cmd
.Init(GL_TRIANGLES
,
1755 kValidIndexRangeCount
,
1757 kValidIndexRangeStart
* 2,
1759 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1760 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1761 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1764 // Per-index data is twice as large, but values of indices are smaller
1765 TEST_P(GLES2DecoderGeometryInstancingTest
,
1766 DrawElementsInstancedANGLELargeIndexSucceeds
) {
1769 SetupVertexBuffer();
1770 SetupExpectationsForApplyingDefaultDirtyState();
1771 DoVertexAttribPointer(1, 4, GL_FLOAT
, 0, 0);
1773 DoEnableVertexAttribArray(0);
1774 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1775 DoVertexAttribDivisorANGLE(0, 1);
1778 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1779 kValidIndexRangeCount
,
1781 BufferOffset(kValidIndexRangeStart
* 2),
1784 .RetiresOnSaturation();
1785 DrawElementsInstancedANGLE cmd
;
1786 cmd
.Init(GL_TRIANGLES
,
1787 kValidIndexRangeCount
,
1789 kValidIndexRangeStart
* 2,
1791 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1792 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1795 TEST_P(GLES2DecoderGeometryInstancingTest
,
1796 DrawElementsInstancedANGLENoDivisor0Fails
) {
1799 SetupVertexBuffer();
1800 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1802 DoEnableVertexAttribArray(0);
1803 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1804 DoVertexAttribDivisorANGLE(0, 1);
1805 DoVertexAttribDivisorANGLE(1, 1);
1806 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1808 .RetiresOnSaturation();
1809 DrawElementsInstancedANGLE cmd
;
1810 cmd
.Init(GL_TRIANGLES
,
1811 kValidIndexRangeCount
,
1813 kValidIndexRangeStart
* 2,
1815 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1816 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1817 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1820 TEST_P(GLES2DecoderGeometryInstancingTest
,
1821 DrawElementsNoDivisor0Fails
) {
1824 SetupVertexBuffer();
1825 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1827 DoEnableVertexAttribArray(0);
1828 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1829 DoVertexAttribDivisorANGLE(0, 1);
1830 DoVertexAttribDivisorANGLE(1, 1);
1831 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
))
1833 .RetiresOnSaturation();
1835 cmd
.Init(GL_TRIANGLES
,
1836 kValidIndexRangeCount
,
1838 kValidIndexRangeStart
* 2);
1839 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1840 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1841 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1844 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysClearsAfterTexImage2DNULL
) {
1845 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
,
1863 SetupClearTextureExpectations(kServiceTextureId
,
1873 SetupExpectationsForApplyingDefaultDirtyState();
1874 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1876 .RetiresOnSaturation();
1878 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1879 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1880 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1883 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1885 .RetiresOnSaturation();
1886 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1887 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1890 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsClearsAfterTexImage2DNULL
) {
1891 SetupAllNeededVertexBuffers();
1893 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1894 // Create an uncleared texture with 2 levels.
1896 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1898 GL_TEXTURE_2D
, 1, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1899 // Expect 2 levels will be cleared.
1900 SetupClearTextureExpectations(kServiceTextureId
,
1910 SetupClearTextureExpectations(kServiceTextureId
,
1920 SetupExpectationsForApplyingDefaultDirtyState();
1923 DrawElements(GL_TRIANGLES
,
1924 kValidIndexRangeCount
,
1926 BufferOffset(kValidIndexRangeStart
* 2)))
1928 .RetiresOnSaturation();
1930 cmd
.Init(GL_TRIANGLES
,
1931 kValidIndexRangeCount
,
1933 kValidIndexRangeStart
* 2);
1934 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1935 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1939 DrawElements(GL_TRIANGLES
,
1940 kValidIndexRangeCount
,
1942 BufferOffset(kValidIndexRangeStart
* 2)))
1944 .RetiresOnSaturation();
1945 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1946 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1949 TEST_P(GLES2DecoderWithShaderTest
, DrawClearsAfterTexImage2DNULLInFBO
) {
1950 const GLuint kFBOClientTextureId
= 4100;
1951 const GLuint kFBOServiceTextureId
= 4101;
1953 SetupAllNeededVertexBuffers();
1954 // Register a texture id.
1955 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1956 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1957 .RetiresOnSaturation();
1958 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1960 // Setup "render to" texture.
1961 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1963 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1965 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1966 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1967 GL_COLOR_ATTACHMENT0
,
1969 kFBOClientTextureId
,
1970 kFBOServiceTextureId
,
1974 // Setup "render from" texture.
1977 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
1978 GL_COLOR_BUFFER_BIT
, // clear bits
1985 false); // scissor test
1987 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1988 false, // Framebuffer has depth
1989 false, // Framebuffer has stencil
1990 0x1111, // color bits
1991 false, // depth mask
1992 false, // depth enabled
1993 0, // front stencil mask
1994 0, // back stencil mask
1995 false); // stencil enabled
1997 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1999 .RetiresOnSaturation();
2001 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2002 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2003 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2006 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2008 .RetiresOnSaturation();
2009 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2010 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2013 TEST_P(GLES2DecoderWithShaderTest
, DrawWitFBOThatCantClearDoesNotDraw
) {
2014 const GLuint kFBOClientTextureId
= 4100;
2015 const GLuint kFBOServiceTextureId
= 4101;
2017 // Register a texture id.
2018 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2019 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2020 .RetiresOnSaturation();
2021 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2023 // Setup "render to" texture.
2024 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2026 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2028 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2029 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2030 GL_COLOR_ATTACHMENT0
,
2032 kFBOClientTextureId
,
2033 kFBOServiceTextureId
,
2037 // Setup "render from" texture.
2040 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
2041 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED
))
2042 .RetiresOnSaturation();
2043 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
2045 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2046 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2047 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION
, GetGLError());
2050 TEST_P(GLES2DecoderWithShaderTest
, DrawClearsAfterRenderbufferStorageInFBO
) {
2053 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
2055 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2056 DoRenderbufferStorage(
2057 GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 100, 50, GL_NO_ERROR
);
2058 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2059 GL_COLOR_ATTACHMENT0
,
2061 client_renderbuffer_id_
,
2062 kServiceRenderbufferId
,
2065 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
2066 GL_COLOR_BUFFER_BIT
, // clear bits
2073 false); // scissor test
2075 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2076 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2077 false, // Framebuffer has depth
2078 false, // Framebuffer has stencil
2079 0x1111, // color bits
2080 false, // depth mask
2081 false, // depth enabled
2082 0, // front stencil mask
2083 0, // back stencil mask
2084 false); // stencil enabled
2086 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2088 .RetiresOnSaturation();
2090 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2091 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2092 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2095 TEST_P(GLES2DecoderManualInitTest
, DrawArraysClearsAfterTexImage2DNULLCubemap
) {
2097 init
.gl_version
= "opengl es 2.0";
2098 init
.has_alpha
= true;
2099 init
.has_depth
= true;
2100 init
.request_alpha
= true;
2101 init
.request_depth
= true;
2104 static const GLenum faces
[] = {
2105 GL_TEXTURE_CUBE_MAP_POSITIVE_X
, GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
2106 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2107 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
2109 SetupCubemapProgram();
2110 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2111 // Fill out all the faces for 2 levels, leave 2 uncleared.
2112 for (int ii
= 0; ii
< 6; ++ii
) {
2113 GLenum face
= faces
[ii
];
2115 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryId
;
2117 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryOffset
;
2139 // Expect 2 levels will be cleared.
2140 SetupClearTextureExpectations(kServiceTextureId
,
2142 GL_TEXTURE_CUBE_MAP
,
2143 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2150 SetupClearTextureExpectations(kServiceTextureId
,
2152 GL_TEXTURE_CUBE_MAP
,
2153 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2160 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2161 SetupExpectationsForApplyingDefaultDirtyState();
2162 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2164 .RetiresOnSaturation();
2166 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2167 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2170 TEST_P(GLES2DecoderWithShaderTest
,
2171 DrawClearsAfterRenderbuffersWithMultipleAttachments
) {
2172 const GLuint kFBOClientTextureId
= 4100;
2173 const GLuint kFBOServiceTextureId
= 4101;
2175 // Register a texture id.
2176 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2177 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2178 .RetiresOnSaturation();
2179 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2181 // Setup "render to" texture.
2182 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2184 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2186 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2187 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2188 GL_COLOR_ATTACHMENT0
,
2190 kFBOClientTextureId
,
2191 kFBOServiceTextureId
,
2196 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
2198 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2199 DoRenderbufferStorage(GL_RENDERBUFFER
,
2200 GL_DEPTH_COMPONENT16
,
2205 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2206 GL_DEPTH_ATTACHMENT
,
2208 client_renderbuffer_id_
,
2209 kServiceRenderbufferId
,
2213 SetupExpectationsForFramebufferClearing(
2214 GL_FRAMEBUFFER
, // target
2215 GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
, // clear bits
2222 false); // scissor test
2224 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2225 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2226 true, // Framebuffer has depth
2227 false, // Framebuffer has stencil
2228 0x1111, // color bits
2230 false, // depth enabled
2231 0, // front stencil mask
2232 0, // back stencil mask
2233 false); // stencil enabled
2235 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2237 .RetiresOnSaturation();
2239 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2240 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2241 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2244 TEST_P(GLES2DecoderWithShaderTest
,
2245 DrawingWithFBOTwiceChecksForFBOCompleteOnce
) {
2246 const GLuint kFBOClientTextureId
= 4100;
2247 const GLuint kFBOServiceTextureId
= 4101;
2249 SetupAllNeededVertexBuffers();
2251 // Register a texture id.
2252 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2253 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2254 .RetiresOnSaturation();
2255 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2257 // Setup "render to" texture that is cleared.
2258 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2259 DoTexImage2D(GL_TEXTURE_2D
,
2268 kSharedMemoryOffset
);
2270 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2271 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2272 GL_COLOR_ATTACHMENT0
,
2274 kFBOClientTextureId
,
2275 kFBOServiceTextureId
,
2279 // Setup "render from" texture.
2282 // Make sure we check for framebuffer complete.
2283 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
2284 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
2285 .RetiresOnSaturation();
2287 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2288 false, // Framebuffer has depth
2289 false, // Framebuffer has stencil
2290 0x1111, // color bits
2291 false, // depth mask
2292 false, // depth enabled
2293 0, // front stencil mask
2294 0, // back stencil mask
2295 false); // stencil enabled
2297 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2299 .RetiresOnSaturation();
2301 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2302 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2303 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2306 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2308 .RetiresOnSaturation();
2309 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2310 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2313 TEST_P(GLES2DecoderManualInitTest
, DrawClearsDepthTexture
) {
2315 init
.extensions
= "GL_ANGLE_depth_texture";
2316 init
.gl_version
= "opengl es 2.0";
2317 init
.has_alpha
= true;
2318 init
.has_depth
= true;
2319 init
.request_alpha
= true;
2320 init
.request_depth
= true;
2321 init
.bind_generates_resource
= true;
2324 SetupDefaultProgram();
2325 SetupAllNeededVertexBuffers();
2326 const GLenum attachment
= GL_DEPTH_ATTACHMENT
;
2327 const GLenum target
= GL_TEXTURE_2D
;
2328 const GLint level
= 0;
2329 DoBindTexture(target
, client_texture_id_
, kServiceTextureId
);
2331 // Create a depth texture.
2332 DoTexImage2D(target
,
2343 // Enable GL_SCISSOR_TEST to make sure we disable it in the clear,
2344 // then re-enable it.
2345 DoEnableDisable(GL_SCISSOR_TEST
, true);
2347 EXPECT_CALL(*gl_
, GenFramebuffersEXT(1, _
)).Times(1).RetiresOnSaturation();
2348 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, _
))
2350 .RetiresOnSaturation();
2353 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT
,
2359 .RetiresOnSaturation();
2360 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT
))
2361 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
2362 .RetiresOnSaturation();
2364 EXPECT_CALL(*gl_
, ClearStencil(0)).Times(1).RetiresOnSaturation();
2365 SetupExpectationsForStencilMask(GLES2Decoder::kDefaultStencilMask
,
2366 GLES2Decoder::kDefaultStencilMask
);
2367 EXPECT_CALL(*gl_
, ClearDepth(1.0f
)).Times(1).RetiresOnSaturation();
2368 SetupExpectationsForDepthMask(true);
2369 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, false);
2371 EXPECT_CALL(*gl_
, Clear(GL_DEPTH_BUFFER_BIT
)).Times(1).RetiresOnSaturation();
2373 SetupExpectationsForRestoreClearState(0.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 1.0f
, true);
2375 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, _
)).Times(1).RetiresOnSaturation();
2376 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0))
2378 .RetiresOnSaturation();
2380 SetupExpectationsForApplyingDefaultDirtyState();
2381 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2383 .RetiresOnSaturation();
2385 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2386 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2387 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2390 } // namespace gles2