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/gpu_switches.h"
21 #include "gpu/command_buffer/service/image_manager.h"
22 #include "gpu/command_buffer/service/mailbox_manager.h"
23 #include "gpu/command_buffer/service/mocks.h"
24 #include "gpu/command_buffer/service/program_manager.h"
25 #include "gpu/command_buffer/service/test_helper.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 init
.gl_version
= "opengl es 2.0";
64 init
.has_alpha
= true;
65 init
.has_depth
= true;
66 init
.request_alpha
= true;
67 init
.request_depth
= true;
68 init
.bind_generates_resource
= true;
70 SetupDefaultProgram();
74 INSTANTIATE_TEST_CASE_P(Service
,
75 GLES2DecoderGeometryInstancingTest
,
78 void GLES2DecoderManualInitTest::DirtyStateMaskTest(GLuint color_bits
,
80 GLuint front_stencil_mask
,
81 GLuint back_stencil_mask
) {
82 ColorMask color_mask_cmd
;
83 color_mask_cmd
.Init((color_bits
& 0x1000) != 0,
84 (color_bits
& 0x0100) != 0,
85 (color_bits
& 0x0010) != 0,
86 (color_bits
& 0x0001) != 0);
87 EXPECT_EQ(error::kNoError
, ExecuteCmd(color_mask_cmd
));
88 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
90 DepthMask depth_mask_cmd
;
91 depth_mask_cmd
.Init(depth_mask
);
92 EXPECT_EQ(error::kNoError
, ExecuteCmd(depth_mask_cmd
));
93 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
95 StencilMaskSeparate front_stencil_mask_cmd
;
96 front_stencil_mask_cmd
.Init(GL_FRONT
, front_stencil_mask
);
97 EXPECT_EQ(error::kNoError
, ExecuteCmd(front_stencil_mask_cmd
));
98 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
100 StencilMaskSeparate back_stencil_mask_cmd
;
101 back_stencil_mask_cmd
.Init(GL_BACK
, back_stencil_mask
);
102 EXPECT_EQ(error::kNoError
, ExecuteCmd(back_stencil_mask_cmd
));
103 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
105 SetupExpectationsForApplyingDirtyState(
106 false, // Framebuffer is RGB
107 true, // Framebuffer has depth
108 true, // Framebuffer has stencil
109 color_bits
, // color bits
110 depth_mask
, // depth mask
111 false, // depth enabled
112 front_stencil_mask
, // front stencil mask
113 back_stencil_mask
, // back stencil mask
114 false); // stencil enabled
116 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
118 .RetiresOnSaturation();
120 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
121 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
122 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
125 // Test that with an RGB backbuffer if we set the color mask to 1,1,1,1 it is
126 // set to 1,1,1,0 at Draw time but is 1,1,1,1 at query time.
127 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferColorMask
) {
129 cmd
.Init(true, true, true, true);
130 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
131 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
134 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
135 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
136 false, // Framebuffer has depth
137 false, // Framebuffer has stencil
138 0x1110, // color bits
140 false, // depth enabled
141 0, // front stencil mask
142 0, // back stencil mask
143 false); // stencil enabled
145 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
147 .RetiresOnSaturation();
149 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
150 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
151 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
153 EXPECT_CALL(*gl_
, GetError())
154 .WillOnce(Return(GL_NO_ERROR
))
155 .WillOnce(Return(GL_NO_ERROR
))
156 .RetiresOnSaturation();
157 typedef GetIntegerv::Result Result
;
158 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
159 EXPECT_CALL(*gl_
, GetIntegerv(GL_COLOR_WRITEMASK
, result
->GetData()))
163 cmd2
.Init(GL_COLOR_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
164 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
166 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_COLOR_WRITEMASK
),
167 result
->GetNumResults());
168 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
169 EXPECT_EQ(1, result
->GetData()[0]);
170 EXPECT_EQ(1, result
->GetData()[1]);
171 EXPECT_EQ(1, result
->GetData()[2]);
172 EXPECT_EQ(1, result
->GetData()[3]);
175 // Test that with no depth if we set DepthMask true that it's set to false at
176 // draw time but querying it returns true.
177 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferDepthMask
) {
178 EXPECT_CALL(*gl_
, DepthMask(true)).Times(0).RetiresOnSaturation();
181 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
182 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
185 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
186 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
187 false, // Framebuffer has depth
188 false, // Framebuffer has stencil
189 0x1110, // color bits
191 false, // depth enabled
192 0, // front stencil mask
193 0, // back stencil mask
194 false); // stencil enabled
196 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
198 .RetiresOnSaturation();
200 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
201 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
202 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
204 EXPECT_CALL(*gl_
, GetError())
205 .WillOnce(Return(GL_NO_ERROR
))
206 .WillOnce(Return(GL_NO_ERROR
))
207 .RetiresOnSaturation();
208 typedef GetIntegerv::Result Result
;
209 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
210 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_WRITEMASK
, result
->GetData()))
214 cmd2
.Init(GL_DEPTH_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
215 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
217 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_WRITEMASK
),
218 result
->GetNumResults());
219 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
220 EXPECT_EQ(1, result
->GetData()[0]);
223 // Test that with no stencil if we set the stencil mask it's still set to 0 at
224 // draw time but gets our value if we query.
225 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferStencilMask
) {
226 const GLint kMask
= 123;
227 EXPECT_CALL(*gl_
, StencilMask(kMask
)).Times(0).RetiresOnSaturation();
230 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
231 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
234 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
235 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
236 false, // Framebuffer has depth
237 false, // Framebuffer has stencil
238 0x1110, // color bits
240 false, // depth enabled
241 0, // front stencil mask
242 0, // back stencil mask
243 false); // stencil enabled
245 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
247 .RetiresOnSaturation();
249 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
250 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
251 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
253 EXPECT_CALL(*gl_
, GetError())
254 .WillOnce(Return(GL_NO_ERROR
))
255 .WillOnce(Return(GL_NO_ERROR
))
256 .RetiresOnSaturation();
257 typedef GetIntegerv::Result Result
;
258 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
259 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_WRITEMASK
, result
->GetData()))
263 cmd2
.Init(GL_STENCIL_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
264 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
266 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_WRITEMASK
),
267 result
->GetNumResults());
268 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
269 EXPECT_EQ(kMask
, result
->GetData()[0]);
272 // Test that if an FBO is bound we get the correct masks.
273 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferColorMaskFBO
) {
275 cmd
.Init(true, true, true, true);
276 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
277 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
281 DoEnableVertexAttribArray(0);
282 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
283 DoEnableVertexAttribArray(1);
284 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
285 DoEnableVertexAttribArray(2);
286 DoVertexAttribPointer(2, 2, GL_FLOAT
, 0, 0);
287 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
288 false, // Framebuffer has depth
289 false, // Framebuffer has stencil
290 0x1110, // color bits
292 false, // depth enabled
293 0, // front stencil mask
294 0, // back stencil mask
295 false); // stencil enabled
297 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
299 .RetiresOnSaturation();
301 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
302 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
303 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
305 // Check that no extra calls are made on the next draw.
306 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
308 .RetiresOnSaturation();
309 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
310 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
312 // Setup Frame buffer.
313 // needs to be 1x1 or else it's not renderable.
314 const GLsizei kWidth
= 1;
315 const GLsizei kHeight
= 1;
316 const GLenum kFormat
= GL_RGB
;
317 // Use a different texture for framebuffer to avoid drawing feedback loops.
318 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
319 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
320 .RetiresOnSaturation();
321 GenHelper
<cmds::GenTexturesImmediate
>(kNewClientId
);
322 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kNewServiceId
);
323 // Pass some data so the texture will be marked as cleared.
324 DoTexImage2D(GL_TEXTURE_2D
,
333 kSharedMemoryOffset
);
335 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
336 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
337 GL_COLOR_ATTACHMENT0
,
343 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
344 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
345 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
346 .RetiresOnSaturation();
348 // This time state needs to be set.
349 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
350 false, // Framebuffer has depth
351 false, // Framebuffer has stencil
352 0x1110, // color bits
354 false, // depth enabled
355 0, // front stencil mask
356 0, // back stencil mask
357 false); // stencil enabled
359 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
361 .RetiresOnSaturation();
362 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
363 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
365 // Check that no extra calls are made on the next draw.
366 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
368 .RetiresOnSaturation();
369 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
370 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
373 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
375 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
376 false, // Framebuffer has depth
377 false, // Framebuffer has stencil
378 0x1110, // color bits
380 false, // depth enabled
381 0, // front stencil mask
382 0, // back stencil mask
383 false); // stencil enabled
385 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
387 .RetiresOnSaturation();
388 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
389 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
392 TEST_P(GLES2DecoderManualInitTest
, DepthEnableWithDepth
) {
394 init
.has_depth
= true;
395 init
.request_depth
= true;
396 init
.bind_generates_resource
= true;
400 cmd
.Init(GL_DEPTH_TEST
);
401 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
402 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
404 SetupDefaultProgram();
406 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
407 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
408 true, // Framebuffer has depth
409 false, // Framebuffer has stencil
410 0x1110, // color bits
412 true, // depth enabled
413 0, // front stencil mask
414 0, // back stencil mask
415 false); // stencil enabled
417 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
419 .RetiresOnSaturation();
421 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
422 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
423 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
425 EXPECT_CALL(*gl_
, GetError())
426 .WillOnce(Return(GL_NO_ERROR
))
427 .WillOnce(Return(GL_NO_ERROR
))
428 .RetiresOnSaturation();
429 typedef GetIntegerv::Result Result
;
430 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
431 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_TEST
, _
))
433 .RetiresOnSaturation();
436 cmd2
.Init(GL_DEPTH_TEST
, shared_memory_id_
, shared_memory_offset_
);
437 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
438 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST
),
439 result
->GetNumResults());
440 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
441 EXPECT_EQ(1, result
->GetData()[0]);
444 TEST_P(GLES2DecoderManualInitTest
, DepthEnableWithoutRequestedDepth
) {
446 init
.has_depth
= true;
447 init
.bind_generates_resource
= true;
451 cmd
.Init(GL_DEPTH_TEST
);
452 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
453 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
455 SetupDefaultProgram();
457 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
458 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
459 false, // Framebuffer has depth
460 false, // Framebuffer has stencil
461 0x1110, // color bits
463 false, // depth enabled
464 0, // front stencil mask
465 0, // back stencil mask
466 false); // stencil enabled
468 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
470 .RetiresOnSaturation();
472 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
473 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
474 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
476 EXPECT_CALL(*gl_
, GetError())
477 .WillOnce(Return(GL_NO_ERROR
))
478 .WillOnce(Return(GL_NO_ERROR
))
479 .RetiresOnSaturation();
480 typedef GetIntegerv::Result Result
;
481 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
482 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_TEST
, _
))
484 .RetiresOnSaturation();
487 cmd2
.Init(GL_DEPTH_TEST
, shared_memory_id_
, shared_memory_offset_
);
488 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
489 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST
),
490 result
->GetNumResults());
491 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
492 EXPECT_EQ(1, result
->GetData()[0]);
495 TEST_P(GLES2DecoderManualInitTest
, StencilEnableWithStencil
) {
497 init
.has_stencil
= true;
498 init
.request_stencil
= true;
499 init
.bind_generates_resource
= true;
503 cmd
.Init(GL_STENCIL_TEST
);
504 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
505 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
507 SetupDefaultProgram();
509 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
510 SetupExpectationsForApplyingDirtyState(
511 true, // Framebuffer is RGB
512 false, // Framebuffer has depth
513 true, // Framebuffer has stencil
514 0x1110, // color bits
516 false, // depth enabled
517 GLES2Decoder::kDefaultStencilMask
, // front stencil mask
518 GLES2Decoder::kDefaultStencilMask
, // back stencil mask
519 true); // stencil enabled
521 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
523 .RetiresOnSaturation();
525 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
526 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
527 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
529 EXPECT_CALL(*gl_
, GetError())
530 .WillOnce(Return(GL_NO_ERROR
))
531 .WillOnce(Return(GL_NO_ERROR
))
532 .RetiresOnSaturation();
533 typedef GetIntegerv::Result Result
;
534 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
535 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_TEST
, _
))
537 .RetiresOnSaturation();
540 cmd2
.Init(GL_STENCIL_TEST
, shared_memory_id_
, shared_memory_offset_
);
541 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
542 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST
),
543 result
->GetNumResults());
544 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
545 EXPECT_EQ(1, result
->GetData()[0]);
548 TEST_P(GLES2DecoderManualInitTest
, StencilEnableWithoutRequestedStencil
) {
550 init
.has_stencil
= true;
551 init
.bind_generates_resource
= true;
555 cmd
.Init(GL_STENCIL_TEST
);
556 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
557 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
559 SetupDefaultProgram();
561 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
562 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
563 false, // Framebuffer has depth
564 false, // Framebuffer has stencil
565 0x1110, // color bits
567 false, // depth enabled
568 0, // front stencil mask
569 0, // back stencil mask
570 false); // stencil enabled
572 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
574 .RetiresOnSaturation();
576 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
577 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
578 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
580 EXPECT_CALL(*gl_
, GetError())
581 .WillOnce(Return(GL_NO_ERROR
))
582 .WillOnce(Return(GL_NO_ERROR
))
583 .RetiresOnSaturation();
584 typedef GetIntegerv::Result Result
;
585 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
586 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_TEST
, _
))
588 .RetiresOnSaturation();
591 cmd2
.Init(GL_STENCIL_TEST
, shared_memory_id_
, shared_memory_offset_
);
592 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
593 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST
),
594 result
->GetNumResults());
595 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
596 EXPECT_EQ(1, result
->GetData()[0]);
599 TEST_P(GLES2DecoderManualInitTest
, CachedColorMask
) {
601 init
.has_alpha
= true;
602 init
.has_depth
= true;
603 init
.has_stencil
= true;
604 init
.request_alpha
= true;
605 init
.request_depth
= true;
606 init
.request_stencil
= true;
607 init
.bind_generates_resource
= true;
610 SetupDefaultProgram();
611 SetupAllNeededVertexBuffers();
614 // Test all color_bits combinations twice.
615 for (int i
= 0; i
< 32; i
++) {
616 GLuint color_bits
= (i
& 1 ? 0x0001 : 0x0000) | (i
& 2 ? 0x0010 : 0x0000) |
617 (i
& 4 ? 0x0100 : 0x0000) | (i
& 8 ? 0x1000 : 0x0000);
619 // Toggle depth_test to force ApplyDirtyState each time.
620 DirtyStateMaskTest(color_bits
, false, 0xffffffff, 0xffffffff);
621 DirtyStateMaskTest(color_bits
, true, 0xffffffff, 0xffffffff);
622 DirtyStateMaskTest(color_bits
, false, 0xffffffff, 0xffffffff);
626 TEST_P(GLES2DecoderManualInitTest
, CachedDepthMask
) {
628 init
.has_alpha
= true;
629 init
.has_depth
= true;
630 init
.has_stencil
= true;
631 init
.request_alpha
= true;
632 init
.request_depth
= true;
633 init
.request_stencil
= true;
634 init
.bind_generates_resource
= true;
637 SetupDefaultProgram();
638 SetupAllNeededVertexBuffers();
641 // Test all depth_mask combinations twice.
642 for (int i
= 0; i
< 4; i
++) {
643 bool depth_mask
= (i
& 1) == 1;
645 // Toggle color masks to force ApplyDirtyState each time.
646 DirtyStateMaskTest(0x1010, depth_mask
, 0xffffffff, 0xffffffff);
647 DirtyStateMaskTest(0x0101, depth_mask
, 0xffffffff, 0xffffffff);
648 DirtyStateMaskTest(0x1010, depth_mask
, 0xffffffff, 0xffffffff);
652 TEST_P(GLES2DecoderManualInitTest
, CachedStencilMask
) {
654 init
.has_alpha
= true;
655 init
.has_depth
= true;
656 init
.has_stencil
= true;
657 init
.request_alpha
= true;
658 init
.request_depth
= true;
659 init
.request_stencil
= true;
660 init
.bind_generates_resource
= true;
663 SetupDefaultProgram();
664 SetupAllNeededVertexBuffers();
667 // Test all stencil_mask combinations twice.
668 for (int i
= 0; i
< 4; i
++) {
669 GLuint stencil_mask
= (i
& 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
671 // Toggle color masks to force ApplyDirtyState each time.
672 DirtyStateMaskTest(0x1010, true, stencil_mask
, 0xffffffff);
673 DirtyStateMaskTest(0x0101, true, stencil_mask
, 0xffffffff);
674 DirtyStateMaskTest(0x1010, true, stencil_mask
, 0xffffffff);
677 for (int i
= 0; i
< 4; i
++) {
678 GLuint stencil_mask
= (i
& 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
680 // Toggle color masks to force ApplyDirtyState each time.
681 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask
);
682 DirtyStateMaskTest(0x0101, true, 0xffffffff, stencil_mask
);
683 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask
);
687 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysNoAttributesSucceeds
) {
689 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
690 SetupExpectationsForApplyingDefaultDirtyState();
692 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
694 .RetiresOnSaturation();
696 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
697 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
698 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
701 // Tests when the math overflows (0x40000000 * sizeof GLfloat)
702 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0OverflowFails
) {
703 const GLsizei kLargeCount
= 0x40000000;
705 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
707 cmd
.Init(GL_TRIANGLES
, 0, kLargeCount
);
708 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
709 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
710 EXPECT_FALSE(GetDecoder()->WasContextLost());
713 // Tests when the math overflows (0x7FFFFFFF + 1 = 0x8000000 verts)
714 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0PosToNegFails
) {
715 const GLsizei kLargeCount
= 0x7FFFFFFF;
717 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
719 cmd
.Init(GL_TRIANGLES
, 0, kLargeCount
);
720 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
721 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
722 EXPECT_FALSE(GetDecoder()->WasContextLost());
725 // Tests when the driver returns an error
726 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0OOMFails
) {
727 const GLsizei kFakeLargeCount
= 0x1234;
729 AddExpectationsForSimulatedAttrib0WithError(
730 kFakeLargeCount
, 0, GL_OUT_OF_MEMORY
);
731 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
733 cmd
.Init(GL_TRIANGLES
, 0, kFakeLargeCount
);
734 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
735 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
736 EXPECT_FALSE(GetDecoder()->WasContextLost());
739 // Test that we lose context.
740 TEST_P(GLES2DecoderManualInitTest
, LoseContextWhenOOM
) {
742 init
.has_alpha
= true;
743 init
.has_depth
= true;
744 init
.request_alpha
= true;
745 init
.request_depth
= true;
746 init
.bind_generates_resource
= true;
747 init
.lose_context_when_out_of_memory
= true;
749 SetupDefaultProgram();
751 const GLsizei kFakeLargeCount
= 0x1234;
753 AddExpectationsForSimulatedAttrib0WithError(
754 kFakeLargeCount
, 0, GL_OUT_OF_MEMORY
);
755 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
756 // Other contexts in the group should be lost also.
757 EXPECT_CALL(*mock_decoder_
, LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB
))
759 .RetiresOnSaturation();
761 cmd
.Init(GL_TRIANGLES
, 0, kFakeLargeCount
);
762 // This context should be lost.
763 EXPECT_EQ(error::kLostContext
, ExecuteCmd(cmd
));
764 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
765 EXPECT_TRUE(decoder_
->WasContextLost());
768 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysBadTextureUsesBlack
) {
769 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
770 // This is an NPOT texture. As the default filtering requires mips
771 // this should trigger replacing with black textures before rendering.
772 DoTexImage2D(GL_TEXTURE_2D
,
781 kSharedMemoryOffset
);
782 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
785 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
787 .RetiresOnSaturation();
789 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceBlackTexture2dId
))
791 .RetiresOnSaturation();
792 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
794 .RetiresOnSaturation();
795 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
797 .RetiresOnSaturation();
798 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
800 .RetiresOnSaturation();
801 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
803 .RetiresOnSaturation();
805 SetupExpectationsForApplyingDefaultDirtyState();
807 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
808 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
809 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
812 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysMissingAttributesFails
) {
813 DoEnableVertexAttribArray(1);
815 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
817 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
818 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
819 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
822 TEST_P(GLES2DecoderWithShaderTest
,
823 DrawArraysMissingAttributesZeroCountSucceeds
) {
824 DoEnableVertexAttribArray(1);
826 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
828 cmd
.Init(GL_TRIANGLES
, 0, 0);
829 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
830 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
833 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysValidAttributesSucceeds
) {
836 DoEnableVertexAttribArray(1);
837 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
838 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
839 SetupExpectationsForApplyingDefaultDirtyState();
841 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
843 .RetiresOnSaturation();
845 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
846 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
847 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
850 // Same as DrawArraysValidAttributesSucceeds, but with workaround
851 // |init_vertex_attributes|.
852 TEST_P(GLES2DecoderManualInitTest
, InitVertexAttributes
) {
853 base::CommandLine
command_line(0, NULL
);
854 command_line
.AppendSwitchASCII(
855 switches::kGpuDriverBugWorkarounds
,
856 base::IntToString(gpu::INIT_VERTEX_ATTRIBUTES
));
858 init
.has_alpha
= true;
859 init
.has_depth
= true;
860 init
.request_alpha
= true;
861 init
.request_depth
= true;
862 init
.bind_generates_resource
= true;
863 InitDecoderWithCommandLine(init
, &command_line
);
864 SetupDefaultProgram();
867 DoEnableVertexAttribArray(1);
868 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
869 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
870 SetupExpectationsForApplyingDefaultDirtyState();
872 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
874 .RetiresOnSaturation();
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
, DrawArraysDeletedBufferFails
) {
883 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
884 DeleteVertexBuffer();
886 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
888 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
889 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
890 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
893 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysDeletedProgramSucceeds
) {
895 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
896 SetupExpectationsForApplyingDefaultDirtyState();
897 DoDeleteProgram(client_program_id_
, kServiceProgramId
);
899 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(1).RetiresOnSaturation();
900 EXPECT_CALL(*gl_
, DeleteProgram(kServiceProgramId
)).Times(1);
902 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
903 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
904 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
907 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysWithInvalidModeFails
) {
909 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
911 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
913 cmd
.Init(GL_QUADS
, 0, 1);
914 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
915 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
916 cmd
.Init(GL_POLYGON
, 0, 1);
917 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
918 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
921 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysInvalidCountFails
) {
923 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
926 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
928 cmd
.Init(GL_TRIANGLES
, 1, kNumVertices
);
929 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
930 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
931 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
933 // Try with count > size
934 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
+ 1);
935 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
936 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
937 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
939 // Try with attrib offset > 0
940 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
941 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 4);
942 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
943 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
944 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
946 // Try with size > 2 (ie, vec3 instead of vec2)
947 DoVertexAttribPointer(1, 3, GL_FLOAT
, 0, 0);
948 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
949 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
950 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
952 // Try with stride > 8 (vec2 + vec2 byte)
953 DoVertexAttribPointer(1, 2, GL_FLOAT
, sizeof(GLfloat
) * 3, 0);
954 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
955 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
956 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
959 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysInstancedANGLEFails
) {
962 DoEnableVertexAttribArray(1);
963 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
965 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
967 .RetiresOnSaturation();
968 DrawArraysInstancedANGLE cmd
;
969 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
970 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
971 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
974 TEST_P(GLES2DecoderWithShaderTest
, VertexAttribDivisorANGLEFails
) {
977 DoEnableVertexAttribArray(1);
978 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
980 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(_
, _
))
982 .RetiresOnSaturation();
984 VertexAttribDivisorANGLE cmd
;
986 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
987 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
990 TEST_P(GLES2DecoderGeometryInstancingTest
,
991 DrawArraysInstancedANGLENoAttributesFails
) {
994 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
996 .RetiresOnSaturation();
997 DrawArraysInstancedANGLE cmd
;
998 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
999 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1000 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1003 TEST_P(GLES2DecoderGeometryInstancingTest
,
1004 DrawArraysInstancedANGLESimulatedAttrib0
) {
1006 SetupVertexBuffer();
1007 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1009 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
1010 SetupExpectationsForApplyingDefaultDirtyState();
1012 DoVertexAttribDivisorANGLE(0, 1);
1013 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, 3))
1015 .RetiresOnSaturation();
1016 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
1018 .RetiresOnSaturation();
1019 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 1))
1021 .RetiresOnSaturation();
1022 DrawArraysInstancedANGLE cmd
;
1023 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 3);
1024 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1025 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1028 TEST_P(GLES2DecoderGeometryInstancingTest
,
1029 DrawArraysInstancedANGLEMissingAttributesFails
) {
1030 DoEnableVertexAttribArray(1);
1032 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1033 DrawArraysInstancedANGLE cmd
;
1034 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1035 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1036 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1039 TEST_P(GLES2DecoderGeometryInstancingTest
,
1040 DrawArraysInstancedANGLEMissingAttributesZeroCountSucceeds
) {
1041 DoEnableVertexAttribArray(1);
1043 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1044 DrawArraysInstancedANGLE cmd
;
1045 cmd
.Init(GL_TRIANGLES
, 0, 0, 1);
1046 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1047 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1050 TEST_P(GLES2DecoderGeometryInstancingTest
,
1051 DrawArraysInstancedANGLEValidAttributesSucceeds
) {
1053 SetupVertexBuffer();
1054 DoEnableVertexAttribArray(1);
1055 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1056 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
1057 SetupExpectationsForApplyingDefaultDirtyState();
1059 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, 1))
1061 .RetiresOnSaturation();
1062 DrawArraysInstancedANGLE cmd
;
1063 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1064 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1065 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1068 TEST_P(GLES2DecoderGeometryInstancingTest
,
1069 DrawArraysInstancedANGLEWithInvalidModeFails
) {
1070 SetupVertexBuffer();
1071 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1073 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1074 DrawArraysInstancedANGLE cmd
;
1075 cmd
.Init(GL_QUADS
, 0, 1, 1);
1076 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1077 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1078 cmd
.Init(GL_POLYGON
, 0, 1, 1);
1079 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1080 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1083 TEST_P(GLES2DecoderGeometryInstancingTest
,
1084 DrawArraysInstancedANGLEInvalidPrimcountFails
) {
1085 SetupVertexBuffer();
1086 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1088 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1089 DrawArraysInstancedANGLE cmd
;
1090 cmd
.Init(GL_TRIANGLES
, 0, 1, -1);
1091 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1092 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1095 // Per-instance data is twice as large, but number of instances is half
1096 TEST_P(GLES2DecoderGeometryInstancingTest
,
1097 DrawArraysInstancedANGLELargeInstanceSucceeds
) {
1099 SetupVertexBuffer();
1100 SetupExpectationsForApplyingDefaultDirtyState();
1101 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1103 DoEnableVertexAttribArray(0);
1104 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1105 DoVertexAttribDivisorANGLE(0, 1);
1108 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
/ 2))
1110 .RetiresOnSaturation();
1111 DrawArraysInstancedANGLE cmd
;
1112 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
/ 2);
1113 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1114 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1117 // Regular drawArrays takes the divisor into account
1118 TEST_P(GLES2DecoderGeometryInstancingTest
,
1119 DrawArraysWithDivisorSucceeds
) {
1121 SetupVertexBuffer();
1122 SetupExpectationsForApplyingDefaultDirtyState();
1123 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1125 DoEnableVertexAttribArray(0);
1126 // Access the data right at the end of the buffer.
1127 DoVertexAttribPointer(
1128 0, 2, GL_FLOAT
, 0, (kNumVertices
- 1) * 2 * sizeof(GLfloat
));
1129 DoVertexAttribDivisorANGLE(0, 1);
1132 DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1134 .RetiresOnSaturation();
1136 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1137 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1138 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1141 // Per-instance data is twice as large, but divisor is twice
1142 TEST_P(GLES2DecoderGeometryInstancingTest
,
1143 DrawArraysInstancedANGLELargeDivisorSucceeds
) {
1145 SetupVertexBuffer();
1146 SetupExpectationsForApplyingDefaultDirtyState();
1147 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1149 DoEnableVertexAttribArray(0);
1150 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1151 DoVertexAttribDivisorANGLE(0, 2);
1154 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
))
1156 .RetiresOnSaturation();
1157 DrawArraysInstancedANGLE cmd
;
1158 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
);
1159 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1160 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1163 TEST_P(GLES2DecoderGeometryInstancingTest
, DrawArraysInstancedANGLELargeFails
) {
1165 SetupVertexBuffer();
1166 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1168 DoEnableVertexAttribArray(0);
1169 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1170 DoVertexAttribDivisorANGLE(0, 1);
1171 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1173 .RetiresOnSaturation();
1174 DrawArraysInstancedANGLE cmd
;
1175 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
+ 1);
1176 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1177 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1178 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1180 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1182 .RetiresOnSaturation();
1183 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
+ 1, kNumVertices
);
1184 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1185 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1186 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1189 // Per-index data is twice as large, but number of indices is half
1190 TEST_P(GLES2DecoderGeometryInstancingTest
,
1191 DrawArraysInstancedANGLELargeIndexSucceeds
) {
1193 SetupVertexBuffer();
1194 SetupExpectationsForApplyingDefaultDirtyState();
1195 DoVertexAttribPointer(1, 4, GL_FLOAT
, 0, 0);
1197 DoEnableVertexAttribArray(0);
1198 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1199 DoVertexAttribDivisorANGLE(0, 1);
1202 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
/ 2, kNumVertices
))
1204 .RetiresOnSaturation();
1205 DrawArraysInstancedANGLE cmd
;
1206 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
/ 2, kNumVertices
);
1207 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1208 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1211 TEST_P(GLES2DecoderGeometryInstancingTest
,
1212 DrawArraysInstancedANGLENoDivisor0Fails
) {
1214 SetupVertexBuffer();
1215 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1217 DoEnableVertexAttribArray(0);
1218 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1219 DoVertexAttribDivisorANGLE(0, 1);
1220 DoVertexAttribDivisorANGLE(1, 1);
1221 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1223 .RetiresOnSaturation();
1224 DrawArraysInstancedANGLE cmd
;
1225 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1226 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1227 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1228 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1231 TEST_P(GLES2DecoderGeometryInstancingTest
,
1232 DrawArraysNoDivisor0Fails
) {
1234 SetupVertexBuffer();
1235 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1237 DoEnableVertexAttribArray(0);
1238 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1239 DoVertexAttribDivisorANGLE(0, 1);
1240 DoVertexAttribDivisorANGLE(1, 1);
1241 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
))
1243 .RetiresOnSaturation();
1245 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1246 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1247 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1248 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1251 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsNoAttributesSucceeds
) {
1254 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
1255 SetupExpectationsForApplyingDefaultDirtyState();
1257 DrawElements(GL_TRIANGLES
,
1258 kValidIndexRangeCount
,
1260 BufferOffset(kValidIndexRangeStart
* 2)))
1262 .RetiresOnSaturation();
1264 cmd
.Init(GL_TRIANGLES
,
1265 kValidIndexRangeCount
,
1267 kValidIndexRangeStart
* 2);
1268 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1269 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1272 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsMissingAttributesFails
) {
1274 DoEnableVertexAttribArray(1);
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
,
1287 DrawElementsMissingAttributesZeroCountSucceeds
) {
1289 DoEnableVertexAttribArray(1);
1291 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1293 cmd
.Init(GL_TRIANGLES
, 0, GL_UNSIGNED_SHORT
, kValidIndexRangeStart
* 2);
1294 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1295 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1298 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsExtraAttributesFails
) {
1300 DoEnableVertexAttribArray(6);
1302 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1304 cmd
.Init(GL_TRIANGLES
,
1305 kValidIndexRangeCount
,
1307 kValidIndexRangeStart
* 2);
1308 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1309 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1312 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsValidAttributesSucceeds
) {
1314 SetupVertexBuffer();
1316 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1317 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1318 SetupExpectationsForApplyingDefaultDirtyState();
1321 DrawElements(GL_TRIANGLES
,
1322 kValidIndexRangeCount
,
1324 BufferOffset(kValidIndexRangeStart
* 2)))
1326 .RetiresOnSaturation();
1328 cmd
.Init(GL_TRIANGLES
,
1329 kValidIndexRangeCount
,
1331 kValidIndexRangeStart
* 2);
1332 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1333 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1336 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedBufferFails
) {
1337 SetupVertexBuffer();
1339 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1340 DeleteIndexBuffer();
1342 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1344 cmd
.Init(GL_TRIANGLES
,
1345 kValidIndexRangeCount
,
1347 kValidIndexRangeStart
* 2);
1348 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1349 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1352 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedProgramSucceeds
) {
1355 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
1356 SetupExpectationsForApplyingDefaultDirtyState();
1357 DoDeleteProgram(client_program_id_
, kServiceProgramId
);
1359 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(1);
1360 EXPECT_CALL(*gl_
, DeleteProgram(kServiceProgramId
)).Times(1);
1362 cmd
.Init(GL_TRIANGLES
,
1363 kValidIndexRangeCount
,
1365 kValidIndexRangeStart
* 2);
1366 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1367 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1370 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsWithInvalidModeFails
) {
1371 SetupVertexBuffer();
1373 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1375 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1378 kValidIndexRangeCount
,
1380 kValidIndexRangeStart
* 2);
1381 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1382 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1383 cmd
.Init(GL_POLYGON
,
1384 kValidIndexRangeCount
,
1386 kValidIndexRangeStart
);
1387 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1388 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1391 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsInvalidCountFails
) {
1392 SetupVertexBuffer();
1394 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1397 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1399 cmd
.Init(GL_TRIANGLES
, kNumIndices
, GL_UNSIGNED_SHORT
, 2);
1400 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1401 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1402 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1404 // Try with count > size
1405 cmd
.Init(GL_TRIANGLES
, kNumIndices
+ 1, GL_UNSIGNED_SHORT
, 0);
1406 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1407 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1408 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1411 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsOutOfRangeIndicesFails
) {
1412 SetupVertexBuffer();
1414 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1416 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1418 cmd
.Init(GL_TRIANGLES
,
1419 kInvalidIndexRangeCount
,
1421 kInvalidIndexRangeStart
* 2);
1422 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1423 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1424 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1427 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsOddOffsetForUint16Fails
) {
1428 SetupVertexBuffer();
1430 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1432 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1434 cmd
.Init(GL_TRIANGLES
, kInvalidIndexRangeCount
, GL_UNSIGNED_SHORT
, 1);
1435 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1436 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1437 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1440 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsInstancedANGLEFails
) {
1442 SetupVertexBuffer();
1444 DoEnableVertexAttribArray(1);
1445 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1447 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1449 .RetiresOnSaturation();
1450 DrawElementsInstancedANGLE cmd
;
1451 cmd
.Init(GL_TRIANGLES
,
1452 kValidIndexRangeCount
,
1454 kValidIndexRangeStart
* 2,
1456 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1457 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1460 TEST_P(GLES2DecoderGeometryInstancingTest
,
1461 DrawElementsInstancedANGLENoAttributesFails
) {
1465 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1467 .RetiresOnSaturation();
1468 DrawElementsInstancedANGLE cmd
;
1469 cmd
.Init(GL_TRIANGLES
,
1470 kValidIndexRangeCount
,
1472 kValidIndexRangeStart
* 2,
1474 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1475 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1478 TEST_P(GLES2DecoderGeometryInstancingTest
,
1479 DrawElementsInstancedANGLESimulatedAttrib0
) {
1481 SetupVertexBuffer();
1483 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1485 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1486 SetupExpectationsForApplyingDefaultDirtyState();
1488 DoVertexAttribDivisorANGLE(0, 1);
1491 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1492 kValidIndexRangeCount
,
1494 BufferOffset(kValidIndexRangeStart
* 2),
1497 .RetiresOnSaturation();
1498 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
1500 .RetiresOnSaturation();
1501 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 1))
1503 .RetiresOnSaturation();
1504 DrawElementsInstancedANGLE cmd
;
1505 cmd
.Init(GL_TRIANGLES
,
1506 kValidIndexRangeCount
,
1508 kValidIndexRangeStart
* 2,
1510 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1511 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1514 TEST_P(GLES2DecoderGeometryInstancingTest
,
1515 DrawElementsInstancedANGLEMissingAttributesFails
) {
1517 DoEnableVertexAttribArray(1);
1519 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1520 DrawElementsInstancedANGLE cmd
;
1521 cmd
.Init(GL_TRIANGLES
,
1522 kValidIndexRangeCount
,
1524 kValidIndexRangeStart
* 2,
1526 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1527 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1530 TEST_P(GLES2DecoderGeometryInstancingTest
,
1531 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds
) {
1533 DoEnableVertexAttribArray(1);
1535 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1536 DrawElementsInstancedANGLE cmd
;
1537 cmd
.Init(GL_TRIANGLES
, 0, GL_UNSIGNED_SHORT
, kValidIndexRangeStart
* 2, 1);
1538 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1539 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1542 TEST_P(GLES2DecoderGeometryInstancingTest
,
1543 DrawElementsInstancedANGLEValidAttributesSucceeds
) {
1546 SetupVertexBuffer();
1547 DoEnableVertexAttribArray(1);
1548 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1549 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1550 SetupExpectationsForApplyingDefaultDirtyState();
1554 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1555 kValidIndexRangeCount
,
1557 BufferOffset(kValidIndexRangeStart
* 2),
1560 .RetiresOnSaturation();
1561 DrawElementsInstancedANGLE cmd
;
1562 cmd
.Init(GL_TRIANGLES
,
1563 kValidIndexRangeCount
,
1565 kValidIndexRangeStart
* 2,
1567 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1568 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1571 TEST_P(GLES2DecoderGeometryInstancingTest
,
1572 DrawElementsInstancedANGLEWithInvalidModeFails
) {
1574 SetupVertexBuffer();
1575 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1577 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1578 DrawElementsInstancedANGLE cmd
;
1580 kValidIndexRangeCount
,
1582 kValidIndexRangeStart
* 2,
1584 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1585 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1586 cmd
.Init(GL_INVALID_ENUM
,
1587 kValidIndexRangeCount
,
1589 kValidIndexRangeStart
* 2,
1591 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1592 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1595 // Per-instance data is twice as large, but number of instances is half
1596 TEST_P(GLES2DecoderGeometryInstancingTest
,
1597 DrawElementsInstancedANGLELargeInstanceSucceeds
) {
1600 SetupVertexBuffer();
1601 SetupExpectationsForApplyingDefaultDirtyState();
1602 // Add offset so we're sure we're accessing data near the end of the buffer.
1603 DoVertexAttribPointer(
1608 (kNumVertices
- kMaxValidIndex
- 1) * 2 * sizeof(GLfloat
));
1610 DoEnableVertexAttribArray(0);
1611 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1612 DoVertexAttribDivisorANGLE(0, 1);
1615 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1616 kValidIndexRangeCount
,
1618 BufferOffset(kValidIndexRangeStart
* 2),
1621 .RetiresOnSaturation();
1622 DrawElementsInstancedANGLE cmd
;
1623 cmd
.Init(GL_TRIANGLES
,
1624 kValidIndexRangeCount
,
1626 kValidIndexRangeStart
* 2,
1628 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1629 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1632 // Regular drawElements takes the divisor into account
1633 TEST_P(GLES2DecoderGeometryInstancingTest
,
1634 DrawElementsWithDivisorSucceeds
) {
1637 SetupVertexBuffer();
1638 SetupExpectationsForApplyingDefaultDirtyState();
1639 // Add offset so we're sure we're accessing data near the end of the buffer.
1640 DoVertexAttribPointer(
1645 (kNumVertices
- kMaxValidIndex
- 1) * 2 * sizeof(GLfloat
));
1647 DoEnableVertexAttribArray(0);
1648 // Access the data right at the end of the buffer.
1649 DoVertexAttribPointer(
1650 0, 2, GL_FLOAT
, 0, (kNumVertices
- 1) * 2 * sizeof(GLfloat
));
1651 DoVertexAttribDivisorANGLE(0, 1);
1654 DrawElements(GL_TRIANGLES
,
1655 kValidIndexRangeCount
,
1657 BufferOffset(kValidIndexRangeStart
* 2)))
1659 .RetiresOnSaturation();
1661 cmd
.Init(GL_TRIANGLES
,
1662 kValidIndexRangeCount
,
1664 kValidIndexRangeStart
* 2);
1665 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1666 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1669 // Per-instance data is twice as large, but divisor is twice
1670 TEST_P(GLES2DecoderGeometryInstancingTest
,
1671 DrawElementsInstancedANGLELargeDivisorSucceeds
) {
1674 SetupVertexBuffer();
1675 SetupExpectationsForApplyingDefaultDirtyState();
1676 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1678 DoEnableVertexAttribArray(0);
1679 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1680 DoVertexAttribDivisorANGLE(0, 2);
1683 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1684 kValidIndexRangeCount
,
1686 BufferOffset(kValidIndexRangeStart
* 2),
1689 .RetiresOnSaturation();
1690 DrawElementsInstancedANGLE cmd
;
1691 cmd
.Init(GL_TRIANGLES
,
1692 kValidIndexRangeCount
,
1694 kValidIndexRangeStart
* 2,
1696 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1697 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1700 TEST_P(GLES2DecoderGeometryInstancingTest
,
1701 DrawElementsInstancedANGLELargeFails
) {
1704 SetupVertexBuffer();
1705 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1707 DoEnableVertexAttribArray(0);
1708 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1709 DoVertexAttribDivisorANGLE(0, 1);
1710 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1712 .RetiresOnSaturation();
1713 DrawElementsInstancedANGLE cmd
;
1714 cmd
.Init(GL_TRIANGLES
,
1715 kValidIndexRangeCount
,
1717 kValidIndexRangeStart
* 2,
1719 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1720 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1721 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1723 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1725 .RetiresOnSaturation();
1726 cmd
.Init(GL_TRIANGLES
,
1727 kInvalidIndexRangeCount
,
1729 kInvalidIndexRangeStart
* 2,
1731 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1732 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1733 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1736 TEST_P(GLES2DecoderGeometryInstancingTest
,
1737 DrawElementsInstancedANGLEInvalidPrimcountFails
) {
1740 SetupVertexBuffer();
1741 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1743 DoEnableVertexAttribArray(0);
1744 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1745 DoVertexAttribDivisorANGLE(0, 1);
1746 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1748 .RetiresOnSaturation();
1749 DrawElementsInstancedANGLE cmd
;
1750 cmd
.Init(GL_TRIANGLES
,
1751 kValidIndexRangeCount
,
1753 kValidIndexRangeStart
* 2,
1755 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1756 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1757 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1760 // Per-index data is twice as large, but values of indices are smaller
1761 TEST_P(GLES2DecoderGeometryInstancingTest
,
1762 DrawElementsInstancedANGLELargeIndexSucceeds
) {
1765 SetupVertexBuffer();
1766 SetupExpectationsForApplyingDefaultDirtyState();
1767 DoVertexAttribPointer(1, 4, GL_FLOAT
, 0, 0);
1769 DoEnableVertexAttribArray(0);
1770 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1771 DoVertexAttribDivisorANGLE(0, 1);
1774 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1775 kValidIndexRangeCount
,
1777 BufferOffset(kValidIndexRangeStart
* 2),
1780 .RetiresOnSaturation();
1781 DrawElementsInstancedANGLE cmd
;
1782 cmd
.Init(GL_TRIANGLES
,
1783 kValidIndexRangeCount
,
1785 kValidIndexRangeStart
* 2,
1787 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1788 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1791 TEST_P(GLES2DecoderGeometryInstancingTest
,
1792 DrawElementsInstancedANGLENoDivisor0Fails
) {
1795 SetupVertexBuffer();
1796 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1798 DoEnableVertexAttribArray(0);
1799 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1800 DoVertexAttribDivisorANGLE(0, 1);
1801 DoVertexAttribDivisorANGLE(1, 1);
1802 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1804 .RetiresOnSaturation();
1805 DrawElementsInstancedANGLE cmd
;
1806 cmd
.Init(GL_TRIANGLES
,
1807 kValidIndexRangeCount
,
1809 kValidIndexRangeStart
* 2,
1811 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1812 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1813 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1816 TEST_P(GLES2DecoderGeometryInstancingTest
,
1817 DrawElementsNoDivisor0Fails
) {
1820 SetupVertexBuffer();
1821 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1823 DoEnableVertexAttribArray(0);
1824 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1825 DoVertexAttribDivisorANGLE(0, 1);
1826 DoVertexAttribDivisorANGLE(1, 1);
1827 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
))
1829 .RetiresOnSaturation();
1831 cmd
.Init(GL_TRIANGLES
,
1832 kValidIndexRangeCount
,
1834 kValidIndexRangeStart
* 2);
1835 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1836 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1837 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1840 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysClearsAfterTexImage2DNULL
) {
1841 SetupAllNeededVertexBuffers();
1842 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1843 // Create an uncleared texture with 2 levels.
1845 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1847 GL_TEXTURE_2D
, 1, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1848 // Expect 2 levels will be cleared.
1849 SetupClearTextureExpectations(kServiceTextureId
,
1859 SetupClearTextureExpectations(kServiceTextureId
,
1869 SetupExpectationsForApplyingDefaultDirtyState();
1870 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1872 .RetiresOnSaturation();
1874 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1875 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1876 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1879 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1881 .RetiresOnSaturation();
1882 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1883 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1886 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsClearsAfterTexImage2DNULL
) {
1887 SetupAllNeededVertexBuffers();
1889 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1890 // Create an uncleared texture with 2 levels.
1892 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1894 GL_TEXTURE_2D
, 1, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1895 // Expect 2 levels will be cleared.
1896 SetupClearTextureExpectations(kServiceTextureId
,
1906 SetupClearTextureExpectations(kServiceTextureId
,
1916 SetupExpectationsForApplyingDefaultDirtyState();
1919 DrawElements(GL_TRIANGLES
,
1920 kValidIndexRangeCount
,
1922 BufferOffset(kValidIndexRangeStart
* 2)))
1924 .RetiresOnSaturation();
1926 cmd
.Init(GL_TRIANGLES
,
1927 kValidIndexRangeCount
,
1929 kValidIndexRangeStart
* 2);
1930 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1931 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1935 DrawElements(GL_TRIANGLES
,
1936 kValidIndexRangeCount
,
1938 BufferOffset(kValidIndexRangeStart
* 2)))
1940 .RetiresOnSaturation();
1941 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1942 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1945 TEST_P(GLES2DecoderWithShaderTest
, DrawClearsAfterTexImage2DNULLInFBO
) {
1946 const GLuint kFBOClientTextureId
= 4100;
1947 const GLuint kFBOServiceTextureId
= 4101;
1949 SetupAllNeededVertexBuffers();
1950 // Register a texture id.
1951 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1952 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1953 .RetiresOnSaturation();
1954 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1956 // Setup "render to" texture.
1957 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1959 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1961 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1962 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1963 GL_COLOR_ATTACHMENT0
,
1965 kFBOClientTextureId
,
1966 kFBOServiceTextureId
,
1970 // Setup "render from" texture.
1973 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
1974 GL_COLOR_BUFFER_BIT
, // clear bits
1981 false); // scissor test
1983 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1984 false, // Framebuffer has depth
1985 false, // Framebuffer has stencil
1986 0x1111, // color bits
1987 false, // depth mask
1988 false, // depth enabled
1989 0, // front stencil mask
1990 0, // back stencil mask
1991 false); // stencil enabled
1993 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1995 .RetiresOnSaturation();
1997 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1998 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1999 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2002 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2004 .RetiresOnSaturation();
2005 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2006 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2009 TEST_P(GLES2DecoderWithShaderTest
, DrawWitFBOThatCantClearDoesNotDraw
) {
2010 const GLuint kFBOClientTextureId
= 4100;
2011 const GLuint kFBOServiceTextureId
= 4101;
2013 // Register a texture id.
2014 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2015 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2016 .RetiresOnSaturation();
2017 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2019 // Setup "render to" texture.
2020 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2022 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2024 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2025 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2026 GL_COLOR_ATTACHMENT0
,
2028 kFBOClientTextureId
,
2029 kFBOServiceTextureId
,
2033 // Setup "render from" texture.
2036 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
2037 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED
))
2038 .RetiresOnSaturation();
2039 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
2041 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2042 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2043 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION
, GetGLError());
2046 TEST_P(GLES2DecoderWithShaderTest
, DrawClearsAfterRenderbufferStorageInFBO
) {
2049 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
2051 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2052 DoRenderbufferStorage(
2053 GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 100, 50, GL_NO_ERROR
);
2054 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2055 GL_COLOR_ATTACHMENT0
,
2057 client_renderbuffer_id_
,
2058 kServiceRenderbufferId
,
2061 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
2062 GL_COLOR_BUFFER_BIT
, // clear bits
2069 false); // scissor test
2071 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2072 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2073 false, // Framebuffer has depth
2074 false, // Framebuffer has stencil
2075 0x1111, // color bits
2076 false, // depth mask
2077 false, // depth enabled
2078 0, // front stencil mask
2079 0, // back stencil mask
2080 false); // stencil enabled
2082 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2084 .RetiresOnSaturation();
2086 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2087 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2088 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2091 TEST_P(GLES2DecoderManualInitTest
, DrawArraysClearsAfterTexImage2DNULLCubemap
) {
2093 init
.gl_version
= "opengl es 2.0";
2094 init
.has_alpha
= true;
2095 init
.has_depth
= true;
2096 init
.request_alpha
= true;
2097 init
.request_depth
= true;
2100 static const GLenum faces
[] = {
2101 GL_TEXTURE_CUBE_MAP_POSITIVE_X
, GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
2102 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2103 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
2105 SetupCubemapProgram();
2106 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2107 // Fill out all the faces for 2 levels, leave 2 uncleared.
2108 for (int ii
= 0; ii
< 6; ++ii
) {
2109 GLenum face
= faces
[ii
];
2111 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryId
;
2113 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryOffset
;
2135 // Expect 2 levels will be cleared.
2136 SetupClearTextureExpectations(kServiceTextureId
,
2138 GL_TEXTURE_CUBE_MAP
,
2139 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2146 SetupClearTextureExpectations(kServiceTextureId
,
2148 GL_TEXTURE_CUBE_MAP
,
2149 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2156 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2157 SetupExpectationsForApplyingDefaultDirtyState();
2158 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2160 .RetiresOnSaturation();
2162 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2163 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2166 TEST_P(GLES2DecoderWithShaderTest
,
2167 DrawClearsAfterRenderbuffersWithMultipleAttachments
) {
2168 const GLuint kFBOClientTextureId
= 4100;
2169 const GLuint kFBOServiceTextureId
= 4101;
2171 // Register a texture id.
2172 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2173 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2174 .RetiresOnSaturation();
2175 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2177 // Setup "render to" texture.
2178 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2180 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2182 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2183 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2184 GL_COLOR_ATTACHMENT0
,
2186 kFBOClientTextureId
,
2187 kFBOServiceTextureId
,
2192 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
2194 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2195 DoRenderbufferStorage(GL_RENDERBUFFER
,
2196 GL_DEPTH_COMPONENT16
,
2201 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2202 GL_DEPTH_ATTACHMENT
,
2204 client_renderbuffer_id_
,
2205 kServiceRenderbufferId
,
2209 SetupExpectationsForFramebufferClearing(
2210 GL_FRAMEBUFFER
, // target
2211 GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
, // clear bits
2218 false); // scissor test
2220 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2221 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2222 true, // Framebuffer has depth
2223 false, // Framebuffer has stencil
2224 0x1111, // color bits
2226 false, // depth enabled
2227 0, // front stencil mask
2228 0, // back stencil mask
2229 false); // stencil enabled
2231 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2233 .RetiresOnSaturation();
2235 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2236 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2237 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2240 TEST_P(GLES2DecoderWithShaderTest
,
2241 DrawingWithFBOTwiceChecksForFBOCompleteOnce
) {
2242 const GLuint kFBOClientTextureId
= 4100;
2243 const GLuint kFBOServiceTextureId
= 4101;
2245 SetupAllNeededVertexBuffers();
2247 // Register a texture id.
2248 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2249 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2250 .RetiresOnSaturation();
2251 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2253 // Setup "render to" texture that is cleared.
2254 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2255 DoTexImage2D(GL_TEXTURE_2D
,
2264 kSharedMemoryOffset
);
2266 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2267 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2268 GL_COLOR_ATTACHMENT0
,
2270 kFBOClientTextureId
,
2271 kFBOServiceTextureId
,
2275 // Setup "render from" texture.
2278 // Make sure we check for framebuffer complete.
2279 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
2280 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
2281 .RetiresOnSaturation();
2283 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2284 false, // Framebuffer has depth
2285 false, // Framebuffer has stencil
2286 0x1111, // color bits
2287 false, // depth mask
2288 false, // depth enabled
2289 0, // front stencil mask
2290 0, // back stencil mask
2291 false); // stencil enabled
2293 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2295 .RetiresOnSaturation();
2297 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2298 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2299 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2302 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2304 .RetiresOnSaturation();
2305 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2306 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2309 TEST_P(GLES2DecoderManualInitTest
, DrawClearsDepthTexture
) {
2311 init
.extensions
= "GL_ANGLE_depth_texture";
2312 init
.gl_version
= "opengl es 2.0";
2313 init
.has_alpha
= true;
2314 init
.has_depth
= true;
2315 init
.request_alpha
= true;
2316 init
.request_depth
= true;
2317 init
.bind_generates_resource
= true;
2320 SetupDefaultProgram();
2321 SetupAllNeededVertexBuffers();
2322 const GLenum attachment
= GL_DEPTH_ATTACHMENT
;
2323 const GLenum target
= GL_TEXTURE_2D
;
2324 const GLint level
= 0;
2325 DoBindTexture(target
, client_texture_id_
, kServiceTextureId
);
2327 // Create a depth texture.
2328 DoTexImage2D(target
,
2339 // Enable GL_SCISSOR_TEST to make sure we disable it in the clear,
2340 // then re-enable it.
2341 DoEnableDisable(GL_SCISSOR_TEST
, true);
2343 EXPECT_CALL(*gl_
, GenFramebuffersEXT(1, _
)).Times(1).RetiresOnSaturation();
2344 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, _
))
2346 .RetiresOnSaturation();
2349 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT
,
2355 .RetiresOnSaturation();
2356 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT
))
2357 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
2358 .RetiresOnSaturation();
2360 EXPECT_CALL(*gl_
, ClearStencil(0)).Times(1).RetiresOnSaturation();
2361 SetupExpectationsForStencilMask(GLES2Decoder::kDefaultStencilMask
,
2362 GLES2Decoder::kDefaultStencilMask
);
2363 EXPECT_CALL(*gl_
, ClearDepth(1.0f
)).Times(1).RetiresOnSaturation();
2364 SetupExpectationsForDepthMask(true);
2365 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, false);
2367 EXPECT_CALL(*gl_
, Clear(GL_DEPTH_BUFFER_BIT
)).Times(1).RetiresOnSaturation();
2369 SetupExpectationsForRestoreClearState(0.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 1.0f
, true);
2371 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, _
)).Times(1).RetiresOnSaturation();
2372 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0))
2374 .RetiresOnSaturation();
2376 SetupExpectationsForApplyingDefaultDirtyState();
2377 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2379 .RetiresOnSaturation();
2381 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2382 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2383 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2386 } // namespace gles2