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 // Most of the tests in this file assume they're running on
64 // desktop OpenGL, and large portions of the tests will become
65 // no-ops if they aren't.
66 init
.gl_version
= "opengl 2.1";
67 init
.has_alpha
= true;
68 init
.has_depth
= true;
69 init
.request_alpha
= true;
70 init
.request_depth
= true;
71 init
.bind_generates_resource
= true;
73 SetupDefaultProgram();
77 INSTANTIATE_TEST_CASE_P(Service
,
78 GLES2DecoderGeometryInstancingTest
,
81 void GLES2DecoderManualInitTest::DirtyStateMaskTest(GLuint color_bits
,
83 GLuint front_stencil_mask
,
84 GLuint back_stencil_mask
) {
85 ColorMask color_mask_cmd
;
86 color_mask_cmd
.Init((color_bits
& 0x1000) != 0,
87 (color_bits
& 0x0100) != 0,
88 (color_bits
& 0x0010) != 0,
89 (color_bits
& 0x0001) != 0);
90 EXPECT_EQ(error::kNoError
, ExecuteCmd(color_mask_cmd
));
91 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
93 DepthMask depth_mask_cmd
;
94 depth_mask_cmd
.Init(depth_mask
);
95 EXPECT_EQ(error::kNoError
, ExecuteCmd(depth_mask_cmd
));
96 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
98 StencilMaskSeparate front_stencil_mask_cmd
;
99 front_stencil_mask_cmd
.Init(GL_FRONT
, front_stencil_mask
);
100 EXPECT_EQ(error::kNoError
, ExecuteCmd(front_stencil_mask_cmd
));
101 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
103 StencilMaskSeparate back_stencil_mask_cmd
;
104 back_stencil_mask_cmd
.Init(GL_BACK
, back_stencil_mask
);
105 EXPECT_EQ(error::kNoError
, ExecuteCmd(back_stencil_mask_cmd
));
106 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
108 SetupExpectationsForApplyingDirtyState(
109 false, // Framebuffer is RGB
110 true, // Framebuffer has depth
111 true, // Framebuffer has stencil
112 color_bits
, // color bits
113 depth_mask
, // depth mask
114 false, // depth enabled
115 front_stencil_mask
, // front stencil mask
116 back_stencil_mask
, // back stencil mask
117 false); // stencil enabled
119 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
121 .RetiresOnSaturation();
123 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
124 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
125 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
128 // Test that with an RGB backbuffer if we set the color mask to 1,1,1,1 it is
129 // set to 1,1,1,0 at Draw time but is 1,1,1,1 at query time.
130 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferColorMask
) {
132 cmd
.Init(true, true, true, true);
133 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
134 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
137 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
138 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
139 false, // Framebuffer has depth
140 false, // Framebuffer has stencil
141 0x1110, // color bits
143 false, // depth enabled
144 0, // front stencil mask
145 0, // back stencil mask
146 false); // stencil enabled
148 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
150 .RetiresOnSaturation();
152 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
153 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
154 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
156 EXPECT_CALL(*gl_
, GetError())
157 .WillOnce(Return(GL_NO_ERROR
))
158 .WillOnce(Return(GL_NO_ERROR
))
159 .RetiresOnSaturation();
160 typedef GetIntegerv::Result Result
;
161 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
162 EXPECT_CALL(*gl_
, GetIntegerv(GL_COLOR_WRITEMASK
, result
->GetData()))
166 cmd2
.Init(GL_COLOR_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
167 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
169 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_COLOR_WRITEMASK
),
170 result
->GetNumResults());
171 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
172 EXPECT_EQ(1, result
->GetData()[0]);
173 EXPECT_EQ(1, result
->GetData()[1]);
174 EXPECT_EQ(1, result
->GetData()[2]);
175 EXPECT_EQ(1, result
->GetData()[3]);
178 // Test that with no depth if we set DepthMask true that it's set to false at
179 // draw time but querying it returns true.
180 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferDepthMask
) {
181 EXPECT_CALL(*gl_
, DepthMask(true)).Times(0).RetiresOnSaturation();
184 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
185 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
188 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
189 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
190 false, // Framebuffer has depth
191 false, // Framebuffer has stencil
192 0x1110, // color bits
194 false, // depth enabled
195 0, // front stencil mask
196 0, // back stencil mask
197 false); // stencil enabled
199 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
201 .RetiresOnSaturation();
203 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
204 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
205 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
207 EXPECT_CALL(*gl_
, GetError())
208 .WillOnce(Return(GL_NO_ERROR
))
209 .WillOnce(Return(GL_NO_ERROR
))
210 .RetiresOnSaturation();
211 typedef GetIntegerv::Result Result
;
212 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
213 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_WRITEMASK
, result
->GetData()))
217 cmd2
.Init(GL_DEPTH_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
218 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
220 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_WRITEMASK
),
221 result
->GetNumResults());
222 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
223 EXPECT_EQ(1, result
->GetData()[0]);
226 // Test that with no stencil if we set the stencil mask it's still set to 0 at
227 // draw time but gets our value if we query.
228 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferStencilMask
) {
229 const GLint kMask
= 123;
230 EXPECT_CALL(*gl_
, StencilMask(kMask
)).Times(0).RetiresOnSaturation();
233 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
234 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
237 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
238 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
239 false, // Framebuffer has depth
240 false, // Framebuffer has stencil
241 0x1110, // color bits
243 false, // depth enabled
244 0, // front stencil mask
245 0, // back stencil mask
246 false); // stencil enabled
248 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
250 .RetiresOnSaturation();
252 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
253 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
254 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
256 EXPECT_CALL(*gl_
, GetError())
257 .WillOnce(Return(GL_NO_ERROR
))
258 .WillOnce(Return(GL_NO_ERROR
))
259 .RetiresOnSaturation();
260 typedef GetIntegerv::Result Result
;
261 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
262 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_WRITEMASK
, result
->GetData()))
266 cmd2
.Init(GL_STENCIL_WRITEMASK
, shared_memory_id_
, shared_memory_offset_
);
267 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
269 decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_WRITEMASK
),
270 result
->GetNumResults());
271 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
272 EXPECT_EQ(kMask
, result
->GetData()[0]);
275 // Test that if an FBO is bound we get the correct masks.
276 TEST_P(GLES2DecoderRGBBackbufferTest
, RGBBackbufferColorMaskFBO
) {
278 cmd
.Init(true, true, true, true);
279 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
280 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
284 DoEnableVertexAttribArray(0);
285 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
286 DoEnableVertexAttribArray(1);
287 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
288 DoEnableVertexAttribArray(2);
289 DoVertexAttribPointer(2, 2, GL_FLOAT
, 0, 0);
290 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
291 false, // Framebuffer has depth
292 false, // Framebuffer has stencil
293 0x1110, // color bits
295 false, // depth enabled
296 0, // front stencil mask
297 0, // back stencil mask
298 false); // stencil enabled
300 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
302 .RetiresOnSaturation();
304 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
305 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
306 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
308 // Check that no extra calls are made on the next draw.
309 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
311 .RetiresOnSaturation();
312 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
313 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
315 // Setup Frame buffer.
316 // needs to be 1x1 or else it's not renderable.
317 const GLsizei kWidth
= 1;
318 const GLsizei kHeight
= 1;
319 const GLenum kFormat
= GL_RGB
;
320 // Use a different texture for framebuffer to avoid drawing feedback loops.
321 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
322 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
323 .RetiresOnSaturation();
324 GenHelper
<cmds::GenTexturesImmediate
>(kNewClientId
);
325 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kNewServiceId
);
326 // Pass some data so the texture will be marked as cleared.
327 DoTexImage2D(GL_TEXTURE_2D
,
336 kSharedMemoryOffset
);
338 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
339 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
340 GL_COLOR_ATTACHMENT0
,
346 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
347 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
348 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
349 .RetiresOnSaturation();
351 // This time state needs to be set.
352 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
353 false, // Framebuffer has depth
354 false, // Framebuffer has stencil
355 0x1110, // color bits
357 false, // depth enabled
358 0, // front stencil mask
359 0, // back stencil mask
360 false); // stencil enabled
362 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
364 .RetiresOnSaturation();
365 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
366 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
368 // Check that no extra calls are made on the next draw.
369 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
371 .RetiresOnSaturation();
372 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
373 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
376 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
378 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
379 false, // Framebuffer has depth
380 false, // Framebuffer has stencil
381 0x1110, // color bits
383 false, // depth enabled
384 0, // front stencil mask
385 0, // back stencil mask
386 false); // stencil enabled
388 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
390 .RetiresOnSaturation();
391 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
392 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
395 TEST_P(GLES2DecoderManualInitTest
, DepthEnableWithDepth
) {
397 init
.has_depth
= true;
398 init
.request_depth
= true;
399 init
.bind_generates_resource
= true;
403 cmd
.Init(GL_DEPTH_TEST
);
404 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
405 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
407 SetupDefaultProgram();
409 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
410 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
411 true, // Framebuffer has depth
412 false, // Framebuffer has stencil
413 0x1110, // color bits
415 true, // depth enabled
416 0, // front stencil mask
417 0, // back stencil mask
418 false); // stencil enabled
420 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
422 .RetiresOnSaturation();
424 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
425 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
426 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
428 EXPECT_CALL(*gl_
, GetError())
429 .WillOnce(Return(GL_NO_ERROR
))
430 .WillOnce(Return(GL_NO_ERROR
))
431 .RetiresOnSaturation();
432 typedef GetIntegerv::Result Result
;
433 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
434 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_TEST
, _
))
436 .RetiresOnSaturation();
439 cmd2
.Init(GL_DEPTH_TEST
, shared_memory_id_
, shared_memory_offset_
);
440 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
441 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST
),
442 result
->GetNumResults());
443 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
444 EXPECT_EQ(1, result
->GetData()[0]);
447 TEST_P(GLES2DecoderManualInitTest
, DepthEnableWithoutRequestedDepth
) {
449 init
.has_depth
= true;
450 init
.bind_generates_resource
= true;
454 cmd
.Init(GL_DEPTH_TEST
);
455 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
456 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
458 SetupDefaultProgram();
460 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
461 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
462 false, // Framebuffer has depth
463 false, // Framebuffer has stencil
464 0x1110, // color bits
466 false, // depth enabled
467 0, // front stencil mask
468 0, // back stencil mask
469 false); // stencil enabled
471 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
473 .RetiresOnSaturation();
475 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
476 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
477 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
479 EXPECT_CALL(*gl_
, GetError())
480 .WillOnce(Return(GL_NO_ERROR
))
481 .WillOnce(Return(GL_NO_ERROR
))
482 .RetiresOnSaturation();
483 typedef GetIntegerv::Result Result
;
484 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
485 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_TEST
, _
))
487 .RetiresOnSaturation();
490 cmd2
.Init(GL_DEPTH_TEST
, shared_memory_id_
, shared_memory_offset_
);
491 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
492 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST
),
493 result
->GetNumResults());
494 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
495 EXPECT_EQ(1, result
->GetData()[0]);
498 TEST_P(GLES2DecoderManualInitTest
, StencilEnableWithStencil
) {
500 init
.has_stencil
= true;
501 init
.request_stencil
= true;
502 init
.bind_generates_resource
= true;
506 cmd
.Init(GL_STENCIL_TEST
);
507 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
508 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
510 SetupDefaultProgram();
512 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
513 SetupExpectationsForApplyingDirtyState(
514 true, // Framebuffer is RGB
515 false, // Framebuffer has depth
516 true, // Framebuffer has stencil
517 0x1110, // color bits
519 false, // depth enabled
520 GLES2Decoder::kDefaultStencilMask
, // front stencil mask
521 GLES2Decoder::kDefaultStencilMask
, // back stencil mask
522 true); // stencil enabled
524 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
526 .RetiresOnSaturation();
528 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
529 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
530 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
532 EXPECT_CALL(*gl_
, GetError())
533 .WillOnce(Return(GL_NO_ERROR
))
534 .WillOnce(Return(GL_NO_ERROR
))
535 .RetiresOnSaturation();
536 typedef GetIntegerv::Result Result
;
537 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
538 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_TEST
, _
))
540 .RetiresOnSaturation();
543 cmd2
.Init(GL_STENCIL_TEST
, shared_memory_id_
, shared_memory_offset_
);
544 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
545 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST
),
546 result
->GetNumResults());
547 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
548 EXPECT_EQ(1, result
->GetData()[0]);
551 TEST_P(GLES2DecoderManualInitTest
, StencilEnableWithoutRequestedStencil
) {
553 init
.has_stencil
= true;
554 init
.bind_generates_resource
= true;
558 cmd
.Init(GL_STENCIL_TEST
);
559 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
560 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
562 SetupDefaultProgram();
564 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
565 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
566 false, // Framebuffer has depth
567 false, // Framebuffer has stencil
568 0x1110, // color bits
570 false, // depth enabled
571 0, // front stencil mask
572 0, // back stencil mask
573 false); // stencil enabled
575 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
577 .RetiresOnSaturation();
579 draw_cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
580 EXPECT_EQ(error::kNoError
, ExecuteCmd(draw_cmd
));
581 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
583 EXPECT_CALL(*gl_
, GetError())
584 .WillOnce(Return(GL_NO_ERROR
))
585 .WillOnce(Return(GL_NO_ERROR
))
586 .RetiresOnSaturation();
587 typedef GetIntegerv::Result Result
;
588 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
589 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_TEST
, _
))
591 .RetiresOnSaturation();
594 cmd2
.Init(GL_STENCIL_TEST
, shared_memory_id_
, shared_memory_offset_
);
595 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
596 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST
),
597 result
->GetNumResults());
598 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
599 EXPECT_EQ(1, result
->GetData()[0]);
602 TEST_P(GLES2DecoderManualInitTest
, CachedColorMask
) {
604 init
.has_alpha
= true;
605 init
.has_depth
= true;
606 init
.has_stencil
= true;
607 init
.request_alpha
= true;
608 init
.request_depth
= true;
609 init
.request_stencil
= true;
610 init
.bind_generates_resource
= true;
613 SetupDefaultProgram();
614 SetupAllNeededVertexBuffers();
617 // Test all color_bits combinations twice.
618 for (int i
= 0; i
< 32; i
++) {
619 GLuint color_bits
= (i
& 1 ? 0x0001 : 0x0000) | (i
& 2 ? 0x0010 : 0x0000) |
620 (i
& 4 ? 0x0100 : 0x0000) | (i
& 8 ? 0x1000 : 0x0000);
622 // Toggle depth_test to force ApplyDirtyState each time.
623 DirtyStateMaskTest(color_bits
, false, 0xffffffff, 0xffffffff);
624 DirtyStateMaskTest(color_bits
, true, 0xffffffff, 0xffffffff);
625 DirtyStateMaskTest(color_bits
, false, 0xffffffff, 0xffffffff);
629 TEST_P(GLES2DecoderManualInitTest
, CachedDepthMask
) {
631 init
.has_alpha
= true;
632 init
.has_depth
= true;
633 init
.has_stencil
= true;
634 init
.request_alpha
= true;
635 init
.request_depth
= true;
636 init
.request_stencil
= true;
637 init
.bind_generates_resource
= true;
640 SetupDefaultProgram();
641 SetupAllNeededVertexBuffers();
644 // Test all depth_mask combinations twice.
645 for (int i
= 0; i
< 4; i
++) {
646 bool depth_mask
= (i
& 1) == 1;
648 // Toggle color masks to force ApplyDirtyState each time.
649 DirtyStateMaskTest(0x1010, depth_mask
, 0xffffffff, 0xffffffff);
650 DirtyStateMaskTest(0x0101, depth_mask
, 0xffffffff, 0xffffffff);
651 DirtyStateMaskTest(0x1010, depth_mask
, 0xffffffff, 0xffffffff);
655 TEST_P(GLES2DecoderManualInitTest
, CachedStencilMask
) {
657 init
.has_alpha
= true;
658 init
.has_depth
= true;
659 init
.has_stencil
= true;
660 init
.request_alpha
= true;
661 init
.request_depth
= true;
662 init
.request_stencil
= true;
663 init
.bind_generates_resource
= true;
666 SetupDefaultProgram();
667 SetupAllNeededVertexBuffers();
670 // Test all stencil_mask combinations twice.
671 for (int i
= 0; i
< 4; i
++) {
672 GLuint stencil_mask
= (i
& 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
674 // Toggle color masks to force ApplyDirtyState each time.
675 DirtyStateMaskTest(0x1010, true, stencil_mask
, 0xffffffff);
676 DirtyStateMaskTest(0x0101, true, stencil_mask
, 0xffffffff);
677 DirtyStateMaskTest(0x1010, true, stencil_mask
, 0xffffffff);
680 for (int i
= 0; i
< 4; i
++) {
681 GLuint stencil_mask
= (i
& 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
683 // Toggle color masks to force ApplyDirtyState each time.
684 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask
);
685 DirtyStateMaskTest(0x0101, true, 0xffffffff, stencil_mask
);
686 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask
);
690 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysNoAttributesSucceeds
) {
692 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
693 SetupExpectationsForApplyingDefaultDirtyState();
695 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
697 .RetiresOnSaturation();
699 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
700 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
701 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
704 // Tests when the math overflows (0x40000000 * sizeof GLfloat)
705 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0OverflowFails
) {
706 const GLsizei kLargeCount
= 0x40000000;
708 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
710 cmd
.Init(GL_TRIANGLES
, 0, kLargeCount
);
711 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
712 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
713 EXPECT_FALSE(GetDecoder()->WasContextLost());
716 // Tests when the math overflows (0x7FFFFFFF + 1 = 0x8000000 verts)
717 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0PosToNegFails
) {
718 const GLsizei kLargeCount
= 0x7FFFFFFF;
720 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
722 cmd
.Init(GL_TRIANGLES
, 0, kLargeCount
);
723 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
724 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
725 EXPECT_FALSE(GetDecoder()->WasContextLost());
728 // Tests when the driver returns an error
729 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysSimulatedAttrib0OOMFails
) {
730 const GLsizei kFakeLargeCount
= 0x1234;
732 AddExpectationsForSimulatedAttrib0WithError(
733 kFakeLargeCount
, 0, GL_OUT_OF_MEMORY
);
734 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
736 cmd
.Init(GL_TRIANGLES
, 0, kFakeLargeCount
);
737 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
738 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
739 EXPECT_FALSE(GetDecoder()->WasContextLost());
742 // Test that we lose context.
743 TEST_P(GLES2DecoderManualInitTest
, LoseContextWhenOOM
) {
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 base::CommandLine
command_line(0, NULL
);
857 command_line
.AppendSwitchASCII(
858 switches::kGpuDriverBugWorkarounds
,
859 base::IntToString(gpu::INIT_VERTEX_ATTRIBUTES
));
861 init
.has_alpha
= true;
862 init
.has_depth
= true;
863 init
.request_alpha
= true;
864 init
.request_depth
= true;
865 init
.bind_generates_resource
= true;
866 InitDecoderWithCommandLine(init
, &command_line
);
867 SetupDefaultProgram();
870 DoEnableVertexAttribArray(1);
871 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
872 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
873 SetupExpectationsForApplyingDefaultDirtyState();
875 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
877 .RetiresOnSaturation();
879 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
880 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
881 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
884 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysDeletedBufferFails
) {
886 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
887 DeleteVertexBuffer();
889 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
891 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
892 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
893 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
896 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysDeletedProgramSucceeds
) {
898 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
899 SetupExpectationsForApplyingDefaultDirtyState();
900 DoDeleteProgram(client_program_id_
, kServiceProgramId
);
902 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(1).RetiresOnSaturation();
903 EXPECT_CALL(*gl_
, DeleteProgram(kServiceProgramId
)).Times(1);
905 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
906 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
907 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
910 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysWithInvalidModeFails
) {
912 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
914 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
916 cmd
.Init(GL_QUADS
, 0, 1);
917 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
918 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
919 cmd
.Init(GL_POLYGON
, 0, 1);
920 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
921 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
924 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysInvalidCountFails
) {
926 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
929 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0);
931 cmd
.Init(GL_TRIANGLES
, 1, kNumVertices
);
932 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
933 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
934 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
936 // Try with count > size
937 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
+ 1);
938 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
939 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
940 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
942 // Try with attrib offset > 0
943 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
944 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 4);
945 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
946 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
947 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
949 // Try with size > 2 (ie, vec3 instead of vec2)
950 DoVertexAttribPointer(1, 3, GL_FLOAT
, 0, 0);
951 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
952 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
953 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
955 // Try with stride > 8 (vec2 + vec2 byte)
956 DoVertexAttribPointer(1, 2, GL_FLOAT
, sizeof(GLfloat
) * 3, 0);
957 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
958 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
959 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
962 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysInstancedANGLEFails
) {
965 DoEnableVertexAttribArray(1);
966 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
968 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
970 .RetiresOnSaturation();
971 DrawArraysInstancedANGLE cmd
;
972 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
973 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
974 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
977 TEST_P(GLES2DecoderWithShaderTest
, VertexAttribDivisorANGLEFails
) {
980 DoEnableVertexAttribArray(1);
981 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
983 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(_
, _
))
985 .RetiresOnSaturation();
987 VertexAttribDivisorANGLE cmd
;
989 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
990 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
993 TEST_P(GLES2DecoderGeometryInstancingTest
,
994 DrawArraysInstancedANGLENoAttributesFails
) {
997 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
999 .RetiresOnSaturation();
1000 DrawArraysInstancedANGLE cmd
;
1001 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1002 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1003 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1006 TEST_P(GLES2DecoderGeometryInstancingTest
,
1007 DrawArraysInstancedANGLESimulatedAttrib0
) {
1009 SetupVertexBuffer();
1010 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1012 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
1013 SetupExpectationsForApplyingDefaultDirtyState();
1015 DoVertexAttribDivisorANGLE(0, 1);
1016 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, 3))
1018 .RetiresOnSaturation();
1019 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
1021 .RetiresOnSaturation();
1022 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 1))
1024 .RetiresOnSaturation();
1025 DrawArraysInstancedANGLE cmd
;
1026 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 3);
1027 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1028 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1031 TEST_P(GLES2DecoderGeometryInstancingTest
,
1032 DrawArraysInstancedANGLEMissingAttributesFails
) {
1033 DoEnableVertexAttribArray(1);
1035 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1036 DrawArraysInstancedANGLE cmd
;
1037 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1038 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1039 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1042 TEST_P(GLES2DecoderGeometryInstancingTest
,
1043 DrawArraysInstancedANGLEMissingAttributesZeroCountSucceeds
) {
1044 DoEnableVertexAttribArray(1);
1046 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1047 DrawArraysInstancedANGLE cmd
;
1048 cmd
.Init(GL_TRIANGLES
, 0, 0, 1);
1049 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1050 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1053 TEST_P(GLES2DecoderGeometryInstancingTest
,
1054 DrawArraysInstancedANGLEValidAttributesSucceeds
) {
1056 SetupVertexBuffer();
1057 DoEnableVertexAttribArray(1);
1058 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1059 AddExpectationsForSimulatedAttrib0(kNumVertices
, kServiceBufferId
);
1060 SetupExpectationsForApplyingDefaultDirtyState();
1062 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, 1))
1064 .RetiresOnSaturation();
1065 DrawArraysInstancedANGLE cmd
;
1066 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1067 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1068 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1071 TEST_P(GLES2DecoderGeometryInstancingTest
,
1072 DrawArraysInstancedANGLEWithInvalidModeFails
) {
1073 SetupVertexBuffer();
1074 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1076 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1077 DrawArraysInstancedANGLE cmd
;
1078 cmd
.Init(GL_QUADS
, 0, 1, 1);
1079 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1080 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1081 cmd
.Init(GL_POLYGON
, 0, 1, 1);
1082 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1083 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1086 TEST_P(GLES2DecoderGeometryInstancingTest
,
1087 DrawArraysInstancedANGLEInvalidPrimcountFails
) {
1088 SetupVertexBuffer();
1089 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1091 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
)).Times(0);
1092 DrawArraysInstancedANGLE cmd
;
1093 cmd
.Init(GL_TRIANGLES
, 0, 1, -1);
1094 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1095 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1098 // Per-instance data is twice as large, but number of instances is half
1099 TEST_P(GLES2DecoderGeometryInstancingTest
,
1100 DrawArraysInstancedANGLELargeInstanceSucceeds
) {
1102 SetupVertexBuffer();
1103 SetupExpectationsForApplyingDefaultDirtyState();
1104 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1106 DoEnableVertexAttribArray(0);
1107 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1108 DoVertexAttribDivisorANGLE(0, 1);
1111 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
/ 2))
1113 .RetiresOnSaturation();
1114 DrawArraysInstancedANGLE cmd
;
1115 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
/ 2);
1116 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1117 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1120 // Regular drawArrays takes the divisor into account
1121 TEST_P(GLES2DecoderGeometryInstancingTest
,
1122 DrawArraysWithDivisorSucceeds
) {
1124 SetupVertexBuffer();
1125 SetupExpectationsForApplyingDefaultDirtyState();
1126 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1128 DoEnableVertexAttribArray(0);
1129 // Access the data right at the end of the buffer.
1130 DoVertexAttribPointer(
1131 0, 2, GL_FLOAT
, 0, (kNumVertices
- 1) * 2 * sizeof(GLfloat
));
1132 DoVertexAttribDivisorANGLE(0, 1);
1135 DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1137 .RetiresOnSaturation();
1139 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1140 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1141 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1144 // Per-instance data is twice as large, but divisor is twice
1145 TEST_P(GLES2DecoderGeometryInstancingTest
,
1146 DrawArraysInstancedANGLELargeDivisorSucceeds
) {
1148 SetupVertexBuffer();
1149 SetupExpectationsForApplyingDefaultDirtyState();
1150 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1152 DoEnableVertexAttribArray(0);
1153 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1154 DoVertexAttribDivisorANGLE(0, 2);
1157 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
))
1159 .RetiresOnSaturation();
1160 DrawArraysInstancedANGLE cmd
;
1161 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
);
1162 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1163 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1166 TEST_P(GLES2DecoderGeometryInstancingTest
, DrawArraysInstancedANGLELargeFails
) {
1168 SetupVertexBuffer();
1169 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1171 DoEnableVertexAttribArray(0);
1172 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1173 DoVertexAttribDivisorANGLE(0, 1);
1174 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1176 .RetiresOnSaturation();
1177 DrawArraysInstancedANGLE cmd
;
1178 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, kNumVertices
+ 1);
1179 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1180 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1181 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1183 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1185 .RetiresOnSaturation();
1186 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
+ 1, kNumVertices
);
1187 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1188 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1189 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1192 // Per-index data is twice as large, but number of indices is half
1193 TEST_P(GLES2DecoderGeometryInstancingTest
,
1194 DrawArraysInstancedANGLELargeIndexSucceeds
) {
1196 SetupVertexBuffer();
1197 SetupExpectationsForApplyingDefaultDirtyState();
1198 DoVertexAttribPointer(1, 4, GL_FLOAT
, 0, 0);
1200 DoEnableVertexAttribArray(0);
1201 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1202 DoVertexAttribDivisorANGLE(0, 1);
1205 DrawArraysInstancedANGLE(GL_TRIANGLES
, 0, kNumVertices
/ 2, kNumVertices
))
1207 .RetiresOnSaturation();
1208 DrawArraysInstancedANGLE cmd
;
1209 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
/ 2, kNumVertices
);
1210 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1211 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1214 TEST_P(GLES2DecoderGeometryInstancingTest
,
1215 DrawArraysInstancedANGLENoDivisor0Fails
) {
1217 SetupVertexBuffer();
1218 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1220 DoEnableVertexAttribArray(0);
1221 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1222 DoVertexAttribDivisorANGLE(0, 1);
1223 DoVertexAttribDivisorANGLE(1, 1);
1224 EXPECT_CALL(*gl_
, DrawArraysInstancedANGLE(_
, _
, _
, _
))
1226 .RetiresOnSaturation();
1227 DrawArraysInstancedANGLE cmd
;
1228 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
, 1);
1229 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1230 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1231 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1234 TEST_P(GLES2DecoderGeometryInstancingTest
,
1235 DrawArraysNoDivisor0Fails
) {
1237 SetupVertexBuffer();
1238 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1240 DoEnableVertexAttribArray(0);
1241 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1242 DoVertexAttribDivisorANGLE(0, 1);
1243 DoVertexAttribDivisorANGLE(1, 1);
1244 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
))
1246 .RetiresOnSaturation();
1248 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1249 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1250 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1251 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1254 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsNoAttributesSucceeds
) {
1257 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
1258 SetupExpectationsForApplyingDefaultDirtyState();
1260 DrawElements(GL_TRIANGLES
,
1261 kValidIndexRangeCount
,
1263 BufferOffset(kValidIndexRangeStart
* 2)))
1265 .RetiresOnSaturation();
1267 cmd
.Init(GL_TRIANGLES
,
1268 kValidIndexRangeCount
,
1270 kValidIndexRangeStart
* 2);
1271 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1272 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1275 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsMissingAttributesFails
) {
1277 DoEnableVertexAttribArray(1);
1279 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1281 cmd
.Init(GL_TRIANGLES
,
1282 kValidIndexRangeCount
,
1284 kValidIndexRangeStart
* 2);
1285 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1286 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1289 TEST_P(GLES2DecoderWithShaderTest
,
1290 DrawElementsMissingAttributesZeroCountSucceeds
) {
1292 DoEnableVertexAttribArray(1);
1294 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1296 cmd
.Init(GL_TRIANGLES
, 0, GL_UNSIGNED_SHORT
, kValidIndexRangeStart
* 2);
1297 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1298 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1301 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsExtraAttributesFails
) {
1303 DoEnableVertexAttribArray(6);
1305 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1307 cmd
.Init(GL_TRIANGLES
,
1308 kValidIndexRangeCount
,
1310 kValidIndexRangeStart
* 2);
1311 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1312 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1315 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsValidAttributesSucceeds
) {
1317 SetupVertexBuffer();
1319 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1320 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1321 SetupExpectationsForApplyingDefaultDirtyState();
1324 DrawElements(GL_TRIANGLES
,
1325 kValidIndexRangeCount
,
1327 BufferOffset(kValidIndexRangeStart
* 2)))
1329 .RetiresOnSaturation();
1331 cmd
.Init(GL_TRIANGLES
,
1332 kValidIndexRangeCount
,
1334 kValidIndexRangeStart
* 2);
1335 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1336 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1339 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedBufferFails
) {
1340 SetupVertexBuffer();
1342 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1343 DeleteIndexBuffer();
1345 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1347 cmd
.Init(GL_TRIANGLES
,
1348 kValidIndexRangeCount
,
1350 kValidIndexRangeStart
* 2);
1351 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1352 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1355 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsDeletedProgramSucceeds
) {
1358 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
1359 SetupExpectationsForApplyingDefaultDirtyState();
1360 DoDeleteProgram(client_program_id_
, kServiceProgramId
);
1362 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(1);
1363 EXPECT_CALL(*gl_
, DeleteProgram(kServiceProgramId
)).Times(1);
1365 cmd
.Init(GL_TRIANGLES
,
1366 kValidIndexRangeCount
,
1368 kValidIndexRangeStart
* 2);
1369 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1370 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1373 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsWithInvalidModeFails
) {
1374 SetupVertexBuffer();
1376 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1378 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1381 kValidIndexRangeCount
,
1383 kValidIndexRangeStart
* 2);
1384 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1385 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1386 cmd
.Init(GL_POLYGON
,
1387 kValidIndexRangeCount
,
1389 kValidIndexRangeStart
);
1390 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1391 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1394 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsInvalidCountFails
) {
1395 SetupVertexBuffer();
1397 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1400 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1402 cmd
.Init(GL_TRIANGLES
, kNumIndices
, GL_UNSIGNED_SHORT
, 2);
1403 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1404 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1405 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1407 // Try with count > size
1408 cmd
.Init(GL_TRIANGLES
, kNumIndices
+ 1, GL_UNSIGNED_SHORT
, 0);
1409 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1410 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1411 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1414 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsOutOfRangeIndicesFails
) {
1415 SetupVertexBuffer();
1417 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1419 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1421 cmd
.Init(GL_TRIANGLES
,
1422 kInvalidIndexRangeCount
,
1424 kInvalidIndexRangeStart
* 2);
1425 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1426 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1427 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1430 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsOddOffsetForUint16Fails
) {
1431 SetupVertexBuffer();
1433 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1435 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(0);
1437 cmd
.Init(GL_TRIANGLES
, kInvalidIndexRangeCount
, GL_UNSIGNED_SHORT
, 1);
1438 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1439 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1440 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1443 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsInstancedANGLEFails
) {
1445 SetupVertexBuffer();
1447 DoEnableVertexAttribArray(1);
1448 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1450 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1452 .RetiresOnSaturation();
1453 DrawElementsInstancedANGLE cmd
;
1454 cmd
.Init(GL_TRIANGLES
,
1455 kValidIndexRangeCount
,
1457 kValidIndexRangeStart
* 2,
1459 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1460 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1463 TEST_P(GLES2DecoderGeometryInstancingTest
,
1464 DrawElementsInstancedANGLENoAttributesFails
) {
1468 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1470 .RetiresOnSaturation();
1471 DrawElementsInstancedANGLE cmd
;
1472 cmd
.Init(GL_TRIANGLES
,
1473 kValidIndexRangeCount
,
1475 kValidIndexRangeStart
* 2,
1477 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1478 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1481 TEST_P(GLES2DecoderGeometryInstancingTest
,
1482 DrawElementsInstancedANGLESimulatedAttrib0
) {
1484 SetupVertexBuffer();
1486 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1488 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1489 SetupExpectationsForApplyingDefaultDirtyState();
1491 DoVertexAttribDivisorANGLE(0, 1);
1494 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1495 kValidIndexRangeCount
,
1497 BufferOffset(kValidIndexRangeStart
* 2),
1500 .RetiresOnSaturation();
1501 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 0))
1503 .RetiresOnSaturation();
1504 EXPECT_CALL(*gl_
, VertexAttribDivisorANGLE(0, 1))
1506 .RetiresOnSaturation();
1507 DrawElementsInstancedANGLE cmd
;
1508 cmd
.Init(GL_TRIANGLES
,
1509 kValidIndexRangeCount
,
1511 kValidIndexRangeStart
* 2,
1513 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1514 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1517 TEST_P(GLES2DecoderGeometryInstancingTest
,
1518 DrawElementsInstancedANGLEMissingAttributesFails
) {
1520 DoEnableVertexAttribArray(1);
1522 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1523 DrawElementsInstancedANGLE cmd
;
1524 cmd
.Init(GL_TRIANGLES
,
1525 kValidIndexRangeCount
,
1527 kValidIndexRangeStart
* 2,
1529 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1530 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1533 TEST_P(GLES2DecoderGeometryInstancingTest
,
1534 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds
) {
1536 DoEnableVertexAttribArray(1);
1538 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1539 DrawElementsInstancedANGLE cmd
;
1540 cmd
.Init(GL_TRIANGLES
, 0, GL_UNSIGNED_SHORT
, kValidIndexRangeStart
* 2, 1);
1541 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1542 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1545 TEST_P(GLES2DecoderGeometryInstancingTest
,
1546 DrawElementsInstancedANGLEValidAttributesSucceeds
) {
1549 SetupVertexBuffer();
1550 DoEnableVertexAttribArray(1);
1551 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1552 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, kServiceBufferId
);
1553 SetupExpectationsForApplyingDefaultDirtyState();
1557 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1558 kValidIndexRangeCount
,
1560 BufferOffset(kValidIndexRangeStart
* 2),
1563 .RetiresOnSaturation();
1564 DrawElementsInstancedANGLE cmd
;
1565 cmd
.Init(GL_TRIANGLES
,
1566 kValidIndexRangeCount
,
1568 kValidIndexRangeStart
* 2,
1570 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1571 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1574 TEST_P(GLES2DecoderGeometryInstancingTest
,
1575 DrawElementsInstancedANGLEWithInvalidModeFails
) {
1577 SetupVertexBuffer();
1578 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1580 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
)).Times(0);
1581 DrawElementsInstancedANGLE cmd
;
1583 kValidIndexRangeCount
,
1585 kValidIndexRangeStart
* 2,
1587 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1588 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1589 cmd
.Init(GL_INVALID_ENUM
,
1590 kValidIndexRangeCount
,
1592 kValidIndexRangeStart
* 2,
1594 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1595 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1598 // Per-instance data is twice as large, but number of instances is half
1599 TEST_P(GLES2DecoderGeometryInstancingTest
,
1600 DrawElementsInstancedANGLELargeInstanceSucceeds
) {
1603 SetupVertexBuffer();
1604 SetupExpectationsForApplyingDefaultDirtyState();
1605 // Add offset so we're sure we're accessing data near the end of the buffer.
1606 DoVertexAttribPointer(
1611 (kNumVertices
- kMaxValidIndex
- 1) * 2 * sizeof(GLfloat
));
1613 DoEnableVertexAttribArray(0);
1614 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1615 DoVertexAttribDivisorANGLE(0, 1);
1618 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1619 kValidIndexRangeCount
,
1621 BufferOffset(kValidIndexRangeStart
* 2),
1624 .RetiresOnSaturation();
1625 DrawElementsInstancedANGLE cmd
;
1626 cmd
.Init(GL_TRIANGLES
,
1627 kValidIndexRangeCount
,
1629 kValidIndexRangeStart
* 2,
1631 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1632 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1635 // Regular drawElements takes the divisor into account
1636 TEST_P(GLES2DecoderGeometryInstancingTest
,
1637 DrawElementsWithDivisorSucceeds
) {
1640 SetupVertexBuffer();
1641 SetupExpectationsForApplyingDefaultDirtyState();
1642 // Add offset so we're sure we're accessing data near the end of the buffer.
1643 DoVertexAttribPointer(
1648 (kNumVertices
- kMaxValidIndex
- 1) * 2 * sizeof(GLfloat
));
1650 DoEnableVertexAttribArray(0);
1651 // Access the data right at the end of the buffer.
1652 DoVertexAttribPointer(
1653 0, 2, GL_FLOAT
, 0, (kNumVertices
- 1) * 2 * sizeof(GLfloat
));
1654 DoVertexAttribDivisorANGLE(0, 1);
1657 DrawElements(GL_TRIANGLES
,
1658 kValidIndexRangeCount
,
1660 BufferOffset(kValidIndexRangeStart
* 2)))
1662 .RetiresOnSaturation();
1664 cmd
.Init(GL_TRIANGLES
,
1665 kValidIndexRangeCount
,
1667 kValidIndexRangeStart
* 2);
1668 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1669 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1672 // Per-instance data is twice as large, but divisor is twice
1673 TEST_P(GLES2DecoderGeometryInstancingTest
,
1674 DrawElementsInstancedANGLELargeDivisorSucceeds
) {
1677 SetupVertexBuffer();
1678 SetupExpectationsForApplyingDefaultDirtyState();
1679 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1681 DoEnableVertexAttribArray(0);
1682 DoVertexAttribPointer(0, 4, GL_FLOAT
, 0, 0);
1683 DoVertexAttribDivisorANGLE(0, 2);
1686 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1687 kValidIndexRangeCount
,
1689 BufferOffset(kValidIndexRangeStart
* 2),
1692 .RetiresOnSaturation();
1693 DrawElementsInstancedANGLE cmd
;
1694 cmd
.Init(GL_TRIANGLES
,
1695 kValidIndexRangeCount
,
1697 kValidIndexRangeStart
* 2,
1699 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1700 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1703 TEST_P(GLES2DecoderGeometryInstancingTest
,
1704 DrawElementsInstancedANGLELargeFails
) {
1707 SetupVertexBuffer();
1708 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1710 DoEnableVertexAttribArray(0);
1711 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1712 DoVertexAttribDivisorANGLE(0, 1);
1713 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1715 .RetiresOnSaturation();
1716 DrawElementsInstancedANGLE cmd
;
1717 cmd
.Init(GL_TRIANGLES
,
1718 kValidIndexRangeCount
,
1720 kValidIndexRangeStart
* 2,
1722 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1723 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1724 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1726 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1728 .RetiresOnSaturation();
1729 cmd
.Init(GL_TRIANGLES
,
1730 kInvalidIndexRangeCount
,
1732 kInvalidIndexRangeStart
* 2,
1734 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1735 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1736 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1739 TEST_P(GLES2DecoderGeometryInstancingTest
,
1740 DrawElementsInstancedANGLEInvalidPrimcountFails
) {
1743 SetupVertexBuffer();
1744 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1746 DoEnableVertexAttribArray(0);
1747 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1748 DoVertexAttribDivisorANGLE(0, 1);
1749 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1751 .RetiresOnSaturation();
1752 DrawElementsInstancedANGLE cmd
;
1753 cmd
.Init(GL_TRIANGLES
,
1754 kValidIndexRangeCount
,
1756 kValidIndexRangeStart
* 2,
1758 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1759 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1760 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1763 // Per-index data is twice as large, but values of indices are smaller
1764 TEST_P(GLES2DecoderGeometryInstancingTest
,
1765 DrawElementsInstancedANGLELargeIndexSucceeds
) {
1768 SetupVertexBuffer();
1769 SetupExpectationsForApplyingDefaultDirtyState();
1770 DoVertexAttribPointer(1, 4, GL_FLOAT
, 0, 0);
1772 DoEnableVertexAttribArray(0);
1773 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1774 DoVertexAttribDivisorANGLE(0, 1);
1777 DrawElementsInstancedANGLE(GL_TRIANGLES
,
1778 kValidIndexRangeCount
,
1780 BufferOffset(kValidIndexRangeStart
* 2),
1783 .RetiresOnSaturation();
1784 DrawElementsInstancedANGLE cmd
;
1785 cmd
.Init(GL_TRIANGLES
,
1786 kValidIndexRangeCount
,
1788 kValidIndexRangeStart
* 2,
1790 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1791 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1794 TEST_P(GLES2DecoderGeometryInstancingTest
,
1795 DrawElementsInstancedANGLENoDivisor0Fails
) {
1798 SetupVertexBuffer();
1799 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1801 DoEnableVertexAttribArray(0);
1802 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1803 DoVertexAttribDivisorANGLE(0, 1);
1804 DoVertexAttribDivisorANGLE(1, 1);
1805 EXPECT_CALL(*gl_
, DrawElementsInstancedANGLE(_
, _
, _
, _
, _
))
1807 .RetiresOnSaturation();
1808 DrawElementsInstancedANGLE cmd
;
1809 cmd
.Init(GL_TRIANGLES
,
1810 kValidIndexRangeCount
,
1812 kValidIndexRangeStart
* 2,
1814 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1815 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1816 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1819 TEST_P(GLES2DecoderGeometryInstancingTest
,
1820 DrawElementsNoDivisor0Fails
) {
1823 SetupVertexBuffer();
1824 DoVertexAttribPointer(1, 2, GL_FLOAT
, 0, 0);
1826 DoEnableVertexAttribArray(0);
1827 DoVertexAttribPointer(0, 2, GL_FLOAT
, 0, 0);
1828 DoVertexAttribDivisorANGLE(0, 1);
1829 DoVertexAttribDivisorANGLE(1, 1);
1830 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
))
1832 .RetiresOnSaturation();
1834 cmd
.Init(GL_TRIANGLES
,
1835 kValidIndexRangeCount
,
1837 kValidIndexRangeStart
* 2);
1838 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1839 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1840 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1843 TEST_P(GLES2DecoderWithShaderTest
, DrawArraysClearsAfterTexImage2DNULL
) {
1844 SetupAllNeededVertexBuffers();
1845 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1846 // Create an uncleared texture with 2 levels.
1848 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1850 GL_TEXTURE_2D
, 1, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1851 // Expect 2 levels will be cleared.
1852 SetupClearTextureExpectations(kServiceTextureId
,
1862 SetupClearTextureExpectations(kServiceTextureId
,
1872 SetupExpectationsForApplyingDefaultDirtyState();
1873 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1875 .RetiresOnSaturation();
1877 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
1878 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1879 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1882 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1884 .RetiresOnSaturation();
1885 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1886 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1889 TEST_P(GLES2DecoderWithShaderTest
, DrawElementsClearsAfterTexImage2DNULL
) {
1890 SetupAllNeededVertexBuffers();
1892 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1893 // Create an uncleared texture with 2 levels.
1895 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1897 GL_TEXTURE_2D
, 1, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1898 // Expect 2 levels will be cleared.
1899 SetupClearTextureExpectations(kServiceTextureId
,
1909 SetupClearTextureExpectations(kServiceTextureId
,
1919 SetupExpectationsForApplyingDefaultDirtyState();
1922 DrawElements(GL_TRIANGLES
,
1923 kValidIndexRangeCount
,
1925 BufferOffset(kValidIndexRangeStart
* 2)))
1927 .RetiresOnSaturation();
1929 cmd
.Init(GL_TRIANGLES
,
1930 kValidIndexRangeCount
,
1932 kValidIndexRangeStart
* 2);
1933 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1934 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1938 DrawElements(GL_TRIANGLES
,
1939 kValidIndexRangeCount
,
1941 BufferOffset(kValidIndexRangeStart
* 2)))
1943 .RetiresOnSaturation();
1944 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1945 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1948 TEST_P(GLES2DecoderWithShaderTest
, DrawClearsAfterTexImage2DNULLInFBO
) {
1949 const GLuint kFBOClientTextureId
= 4100;
1950 const GLuint kFBOServiceTextureId
= 4101;
1952 SetupAllNeededVertexBuffers();
1953 // Register a texture id.
1954 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1955 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1956 .RetiresOnSaturation();
1957 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1959 // Setup "render to" texture.
1960 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1962 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1964 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1965 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1966 GL_COLOR_ATTACHMENT0
,
1968 kFBOClientTextureId
,
1969 kFBOServiceTextureId
,
1973 // Setup "render from" texture.
1976 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
1977 GL_COLOR_BUFFER_BIT
, // clear bits
1984 false); // scissor test
1986 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1987 false, // Framebuffer has depth
1988 false, // Framebuffer has stencil
1989 0x1111, // color bits
1990 false, // depth mask
1991 false, // depth enabled
1992 0, // front stencil mask
1993 0, // back stencil mask
1994 false); // stencil enabled
1996 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
1998 .RetiresOnSaturation();
2000 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2001 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2002 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2005 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2007 .RetiresOnSaturation();
2008 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2009 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2012 TEST_P(GLES2DecoderWithShaderTest
, DrawWitFBOThatCantClearDoesNotDraw
) {
2013 const GLuint kFBOClientTextureId
= 4100;
2014 const GLuint kFBOServiceTextureId
= 4101;
2016 // Register a texture id.
2017 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2018 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2019 .RetiresOnSaturation();
2020 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2022 // Setup "render to" texture.
2023 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2025 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2027 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2028 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2029 GL_COLOR_ATTACHMENT0
,
2031 kFBOClientTextureId
,
2032 kFBOServiceTextureId
,
2036 // Setup "render from" texture.
2039 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
2040 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED
))
2041 .RetiresOnSaturation();
2042 EXPECT_CALL(*gl_
, DrawArrays(_
, _
, _
)).Times(0).RetiresOnSaturation();
2044 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2045 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2046 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION
, GetGLError());
2049 TEST_P(GLES2DecoderWithShaderTest
, DrawClearsAfterRenderbufferStorageInFBO
) {
2052 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
2054 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2055 DoRenderbufferStorage(
2056 GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 100, 50, GL_NO_ERROR
);
2057 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2058 GL_COLOR_ATTACHMENT0
,
2060 client_renderbuffer_id_
,
2061 kServiceRenderbufferId
,
2064 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
2065 GL_COLOR_BUFFER_BIT
, // clear bits
2072 false); // scissor test
2074 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2075 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2076 false, // Framebuffer has depth
2077 false, // Framebuffer has stencil
2078 0x1111, // color bits
2079 false, // depth mask
2080 false, // depth enabled
2081 0, // front stencil mask
2082 0, // back stencil mask
2083 false); // stencil enabled
2085 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2087 .RetiresOnSaturation();
2089 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2090 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2091 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2094 TEST_P(GLES2DecoderManualInitTest
, DrawArraysClearsAfterTexImage2DNULLCubemap
) {
2096 init
.gl_version
= "opengl es 2.0";
2097 init
.has_alpha
= true;
2098 init
.has_depth
= true;
2099 init
.request_alpha
= true;
2100 init
.request_depth
= true;
2103 static const GLenum faces
[] = {
2104 GL_TEXTURE_CUBE_MAP_POSITIVE_X
, GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
2105 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2106 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
2108 SetupCubemapProgram();
2109 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2110 // Fill out all the faces for 2 levels, leave 2 uncleared.
2111 for (int ii
= 0; ii
< 6; ++ii
) {
2112 GLenum face
= faces
[ii
];
2114 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryId
;
2116 (face
== GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
) ? 0 : kSharedMemoryOffset
;
2138 // Expect 2 levels will be cleared.
2139 SetupClearTextureExpectations(kServiceTextureId
,
2141 GL_TEXTURE_CUBE_MAP
,
2142 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2149 SetupClearTextureExpectations(kServiceTextureId
,
2151 GL_TEXTURE_CUBE_MAP
,
2152 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
2159 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2160 SetupExpectationsForApplyingDefaultDirtyState();
2161 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2163 .RetiresOnSaturation();
2165 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2166 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2169 TEST_P(GLES2DecoderWithShaderTest
,
2170 DrawClearsAfterRenderbuffersWithMultipleAttachments
) {
2171 const GLuint kFBOClientTextureId
= 4100;
2172 const GLuint kFBOServiceTextureId
= 4101;
2174 // Register a texture id.
2175 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2176 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2177 .RetiresOnSaturation();
2178 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2180 // Setup "render to" texture.
2181 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2183 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2185 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2186 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2187 GL_COLOR_ATTACHMENT0
,
2189 kFBOClientTextureId
,
2190 kFBOServiceTextureId
,
2195 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
2197 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2198 DoRenderbufferStorage(GL_RENDERBUFFER
,
2199 GL_DEPTH_COMPONENT16
,
2204 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2205 GL_DEPTH_ATTACHMENT
,
2207 client_renderbuffer_id_
,
2208 kServiceRenderbufferId
,
2212 SetupExpectationsForFramebufferClearing(
2213 GL_FRAMEBUFFER
, // target
2214 GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
, // clear bits
2221 false); // scissor test
2223 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2224 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2225 true, // Framebuffer has depth
2226 false, // Framebuffer has stencil
2227 0x1111, // color bits
2229 false, // depth enabled
2230 0, // front stencil mask
2231 0, // back stencil mask
2232 false); // stencil enabled
2234 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2236 .RetiresOnSaturation();
2238 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2239 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2240 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2243 TEST_P(GLES2DecoderWithShaderTest
,
2244 DrawingWithFBOTwiceChecksForFBOCompleteOnce
) {
2245 const GLuint kFBOClientTextureId
= 4100;
2246 const GLuint kFBOServiceTextureId
= 4101;
2248 SetupAllNeededVertexBuffers();
2250 // Register a texture id.
2251 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2252 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2253 .RetiresOnSaturation();
2254 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2256 // Setup "render to" texture that is cleared.
2257 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2258 DoTexImage2D(GL_TEXTURE_2D
,
2267 kSharedMemoryOffset
);
2269 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2270 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2271 GL_COLOR_ATTACHMENT0
,
2273 kFBOClientTextureId
,
2274 kFBOServiceTextureId
,
2278 // Setup "render from" texture.
2281 // Make sure we check for framebuffer complete.
2282 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
2283 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
2284 .RetiresOnSaturation();
2286 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2287 false, // Framebuffer has depth
2288 false, // Framebuffer has stencil
2289 0x1111, // color bits
2290 false, // depth mask
2291 false, // depth enabled
2292 0, // front stencil mask
2293 0, // back stencil mask
2294 false); // stencil enabled
2296 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2298 .RetiresOnSaturation();
2300 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2301 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2302 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2305 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2307 .RetiresOnSaturation();
2308 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2309 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2312 TEST_P(GLES2DecoderManualInitTest
, DrawClearsDepthTexture
) {
2314 init
.extensions
= "GL_ANGLE_depth_texture";
2315 init
.gl_version
= "opengl es 2.0";
2316 init
.has_alpha
= true;
2317 init
.has_depth
= true;
2318 init
.request_alpha
= true;
2319 init
.request_depth
= true;
2320 init
.bind_generates_resource
= true;
2323 SetupDefaultProgram();
2324 SetupAllNeededVertexBuffers();
2325 const GLenum attachment
= GL_DEPTH_ATTACHMENT
;
2326 const GLenum target
= GL_TEXTURE_2D
;
2327 const GLint level
= 0;
2328 DoBindTexture(target
, client_texture_id_
, kServiceTextureId
);
2330 // Create a depth texture.
2331 DoTexImage2D(target
,
2342 // Enable GL_SCISSOR_TEST to make sure we disable it in the clear,
2343 // then re-enable it.
2344 DoEnableDisable(GL_SCISSOR_TEST
, true);
2346 EXPECT_CALL(*gl_
, GenFramebuffersEXT(1, _
)).Times(1).RetiresOnSaturation();
2347 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, _
))
2349 .RetiresOnSaturation();
2352 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT
,
2358 .RetiresOnSaturation();
2359 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT
))
2360 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
2361 .RetiresOnSaturation();
2363 EXPECT_CALL(*gl_
, ClearStencil(0)).Times(1).RetiresOnSaturation();
2364 SetupExpectationsForStencilMask(GLES2Decoder::kDefaultStencilMask
,
2365 GLES2Decoder::kDefaultStencilMask
);
2366 EXPECT_CALL(*gl_
, ClearDepth(1.0f
)).Times(1).RetiresOnSaturation();
2367 SetupExpectationsForDepthMask(true);
2368 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, false);
2370 EXPECT_CALL(*gl_
, Clear(GL_DEPTH_BUFFER_BIT
)).Times(1).RetiresOnSaturation();
2372 SetupExpectationsForRestoreClearState(0.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 1.0f
, true);
2374 EXPECT_CALL(*gl_
, DeleteFramebuffersEXT(1, _
)).Times(1).RetiresOnSaturation();
2375 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT
, 0))
2377 .RetiresOnSaturation();
2379 SetupExpectationsForApplyingDefaultDirtyState();
2380 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2382 .RetiresOnSaturation();
2384 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2385 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2386 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2389 } // namespace gles2