Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_drawing.cc
blob957b53bf2e52afb22aefe60f735b439396b0191e
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
33 #endif
35 using ::gfx::MockGLInterface;
36 using ::testing::_;
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;
51 namespace gpu {
52 namespace gles2 {
54 using namespace cmds;
56 class GLES2DecoderGeometryInstancingTest : public GLES2DecoderWithShaderTest {
57 public:
58 GLES2DecoderGeometryInstancingTest() : GLES2DecoderWithShaderTest() {}
60 void SetUp() override {
61 InitState init;
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;
69 InitDecoder(init);
70 SetupDefaultProgram();
74 INSTANTIATE_TEST_CASE_P(Service,
75 GLES2DecoderGeometryInstancingTest,
76 ::testing::Bool());
78 void GLES2DecoderManualInitTest::DirtyStateMaskTest(GLuint color_bits,
79 bool depth_mask,
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))
117 .Times(1)
118 .RetiresOnSaturation();
119 DrawArrays draw_cmd;
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) {
128 ColorMask cmd;
129 cmd.Init(true, true, true, true);
130 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
131 EXPECT_EQ(GL_NO_ERROR, GetGLError());
133 SetupTexture();
134 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
135 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
136 false, // Framebuffer has depth
137 false, // Framebuffer has stencil
138 0x1110, // color bits
139 false, // depth mask
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))
146 .Times(1)
147 .RetiresOnSaturation();
148 DrawArrays draw_cmd;
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()))
160 .Times(0);
161 result->size = 0;
162 GetIntegerv cmd2;
163 cmd2.Init(GL_COLOR_WRITEMASK, shared_memory_id_, shared_memory_offset_);
164 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
165 EXPECT_EQ(
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();
179 DepthMask cmd;
180 cmd.Init(true);
181 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
182 EXPECT_EQ(GL_NO_ERROR, GetGLError());
184 SetupTexture();
185 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
186 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
187 false, // Framebuffer has depth
188 false, // Framebuffer has stencil
189 0x1110, // color bits
190 false, // depth mask
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))
197 .Times(1)
198 .RetiresOnSaturation();
199 DrawArrays draw_cmd;
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()))
211 .Times(0);
212 result->size = 0;
213 GetIntegerv cmd2;
214 cmd2.Init(GL_DEPTH_WRITEMASK, shared_memory_id_, shared_memory_offset_);
215 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
216 EXPECT_EQ(
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();
228 StencilMask cmd;
229 cmd.Init(kMask);
230 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
231 EXPECT_EQ(GL_NO_ERROR, GetGLError());
233 SetupTexture();
234 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
235 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
236 false, // Framebuffer has depth
237 false, // Framebuffer has stencil
238 0x1110, // color bits
239 false, // depth mask
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))
246 .Times(1)
247 .RetiresOnSaturation();
248 DrawArrays draw_cmd;
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()))
260 .Times(0);
261 result->size = 0;
262 GetIntegerv cmd2;
263 cmd2.Init(GL_STENCIL_WRITEMASK, shared_memory_id_, shared_memory_offset_);
264 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
265 EXPECT_EQ(
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) {
274 ColorMask cmd;
275 cmd.Init(true, true, true, true);
276 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
277 EXPECT_EQ(GL_NO_ERROR, GetGLError());
279 SetupTexture();
280 SetupVertexBuffer();
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
291 false, // depth mask
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))
298 .Times(1)
299 .RetiresOnSaturation();
300 DrawArrays draw_cmd;
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))
307 .Times(1)
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,
326 kFormat,
327 kWidth,
328 kHeight,
330 kFormat,
331 GL_UNSIGNED_BYTE,
332 kSharedMemoryId,
333 kSharedMemoryOffset);
334 DoBindFramebuffer(
335 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
336 DoFramebufferTexture2D(GL_FRAMEBUFFER,
337 GL_COLOR_ATTACHMENT0,
338 GL_TEXTURE_2D,
339 kNewClientId,
340 kNewServiceId,
342 GL_NO_ERROR);
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
353 false, // depth mask
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))
360 .Times(1)
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))
367 .Times(1)
368 .RetiresOnSaturation();
369 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
370 EXPECT_EQ(GL_NO_ERROR, GetGLError());
372 // Unbind
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
379 false, // depth mask
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))
386 .Times(1)
387 .RetiresOnSaturation();
388 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
389 EXPECT_EQ(GL_NO_ERROR, GetGLError());
392 TEST_P(GLES2DecoderManualInitTest, DepthEnableWithDepth) {
393 InitState init;
394 init.has_depth = true;
395 init.request_depth = true;
396 init.bind_generates_resource = true;
397 InitDecoder(init);
399 Enable cmd;
400 cmd.Init(GL_DEPTH_TEST);
401 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
402 EXPECT_EQ(GL_NO_ERROR, GetGLError());
404 SetupDefaultProgram();
405 SetupTexture();
406 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
407 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
408 true, // Framebuffer has depth
409 false, // Framebuffer has stencil
410 0x1110, // color bits
411 true, // depth mask
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))
418 .Times(1)
419 .RetiresOnSaturation();
420 DrawArrays draw_cmd;
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, _))
432 .Times(0)
433 .RetiresOnSaturation();
434 result->size = 0;
435 GetIntegerv cmd2;
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) {
445 InitState init;
446 init.has_depth = true;
447 init.bind_generates_resource = true;
448 InitDecoder(init);
450 Enable cmd;
451 cmd.Init(GL_DEPTH_TEST);
452 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
453 EXPECT_EQ(GL_NO_ERROR, GetGLError());
455 SetupDefaultProgram();
456 SetupTexture();
457 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
458 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
459 false, // Framebuffer has depth
460 false, // Framebuffer has stencil
461 0x1110, // color bits
462 false, // depth mask
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))
469 .Times(1)
470 .RetiresOnSaturation();
471 DrawArrays draw_cmd;
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, _))
483 .Times(0)
484 .RetiresOnSaturation();
485 result->size = 0;
486 GetIntegerv cmd2;
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) {
496 InitState init;
497 init.has_stencil = true;
498 init.request_stencil = true;
499 init.bind_generates_resource = true;
500 InitDecoder(init);
502 Enable cmd;
503 cmd.Init(GL_STENCIL_TEST);
504 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
505 EXPECT_EQ(GL_NO_ERROR, GetGLError());
507 SetupDefaultProgram();
508 SetupTexture();
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
515 false, // depth mask
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))
522 .Times(1)
523 .RetiresOnSaturation();
524 DrawArrays draw_cmd;
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, _))
536 .Times(0)
537 .RetiresOnSaturation();
538 result->size = 0;
539 GetIntegerv cmd2;
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) {
549 InitState init;
550 init.has_stencil = true;
551 init.bind_generates_resource = true;
552 InitDecoder(init);
554 Enable cmd;
555 cmd.Init(GL_STENCIL_TEST);
556 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
557 EXPECT_EQ(GL_NO_ERROR, GetGLError());
559 SetupDefaultProgram();
560 SetupTexture();
561 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
562 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
563 false, // Framebuffer has depth
564 false, // Framebuffer has stencil
565 0x1110, // color bits
566 false, // depth mask
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))
573 .Times(1)
574 .RetiresOnSaturation();
575 DrawArrays draw_cmd;
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, _))
587 .Times(0)
588 .RetiresOnSaturation();
589 result->size = 0;
590 GetIntegerv cmd2;
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) {
600 InitState init;
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;
608 InitDecoder(init);
610 SetupDefaultProgram();
611 SetupAllNeededVertexBuffers();
612 SetupTexture();
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) {
627 InitState init;
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;
635 InitDecoder(init);
637 SetupDefaultProgram();
638 SetupAllNeededVertexBuffers();
639 SetupTexture();
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) {
653 InitState init;
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;
661 InitDecoder(init);
663 SetupDefaultProgram();
664 SetupAllNeededVertexBuffers();
665 SetupTexture();
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) {
688 SetupTexture();
689 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
690 SetupExpectationsForApplyingDefaultDirtyState();
692 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
693 .Times(1)
694 .RetiresOnSaturation();
695 DrawArrays cmd;
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;
704 SetupTexture();
705 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
706 DrawArrays cmd;
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;
716 SetupTexture();
717 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
718 DrawArrays cmd;
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;
728 SetupTexture();
729 AddExpectationsForSimulatedAttrib0WithError(
730 kFakeLargeCount, 0, GL_OUT_OF_MEMORY);
731 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
732 DrawArrays cmd;
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) {
741 InitState init;
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;
748 InitDecoder(init);
749 SetupDefaultProgram();
751 const GLsizei kFakeLargeCount = 0x1234;
752 SetupTexture();
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))
758 .Times(1)
759 .RetiresOnSaturation();
760 DrawArrays cmd;
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,
774 GL_RGBA,
778 GL_RGBA,
779 GL_UNSIGNED_BYTE,
780 kSharedMemoryId,
781 kSharedMemoryOffset);
782 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
784 InSequence sequence;
785 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
786 .Times(1)
787 .RetiresOnSaturation();
788 EXPECT_CALL(
789 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceBlackTexture2dId))
790 .Times(1)
791 .RetiresOnSaturation();
792 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
793 .Times(1)
794 .RetiresOnSaturation();
795 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
796 .Times(1)
797 .RetiresOnSaturation();
798 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
799 .Times(1)
800 .RetiresOnSaturation();
801 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
802 .Times(1)
803 .RetiresOnSaturation();
805 SetupExpectationsForApplyingDefaultDirtyState();
806 DrawArrays cmd;
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);
816 DrawArrays cmd;
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);
827 DrawArrays cmd;
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) {
834 SetupTexture();
835 SetupVertexBuffer();
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))
842 .Times(1)
843 .RetiresOnSaturation();
844 DrawArrays cmd;
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));
857 InitState init;
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();
865 SetupTexture();
866 SetupVertexBuffer();
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))
873 .Times(1)
874 .RetiresOnSaturation();
875 DrawArrays cmd;
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) {
882 SetupVertexBuffer();
883 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
884 DeleteVertexBuffer();
886 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
887 DrawArrays cmd;
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) {
894 SetupTexture();
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);
901 DrawArrays cmd;
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) {
908 SetupVertexBuffer();
909 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
911 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
912 DrawArrays cmd;
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) {
922 SetupVertexBuffer();
923 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
925 // Try start > 0
926 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
927 DrawArrays cmd;
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) {
960 SetupTexture();
961 SetupVertexBuffer();
962 DoEnableVertexAttribArray(1);
963 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
965 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
966 .Times(0)
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) {
975 SetupTexture();
976 SetupVertexBuffer();
977 DoEnableVertexAttribArray(1);
978 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
980 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(_, _))
981 .Times(0)
982 .RetiresOnSaturation();
984 VertexAttribDivisorANGLE cmd;
985 cmd.Init(0, 1);
986 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
987 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
990 TEST_P(GLES2DecoderGeometryInstancingTest,
991 DrawArraysInstancedANGLENoAttributesFails) {
992 SetupTexture();
994 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
995 .Times(0)
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) {
1005 SetupTexture();
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))
1014 .Times(1)
1015 .RetiresOnSaturation();
1016 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
1017 .Times(1)
1018 .RetiresOnSaturation();
1019 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
1020 .Times(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) {
1052 SetupTexture();
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))
1060 .Times(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) {
1098 SetupTexture();
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);
1106 EXPECT_CALL(
1107 *gl_,
1108 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2))
1109 .Times(1)
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) {
1120 SetupTexture();
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);
1130 EXPECT_CALL(
1131 *gl_,
1132 DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1133 .Times(1)
1134 .RetiresOnSaturation();
1135 DrawArrays cmd;
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) {
1144 SetupTexture();
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);
1152 EXPECT_CALL(
1153 *gl_,
1154 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices))
1155 .Times(1)
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) {
1164 SetupTexture();
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(_, _, _, _))
1172 .Times(0)
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(_, _, _, _))
1181 .Times(0)
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) {
1192 SetupTexture();
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);
1200 EXPECT_CALL(
1201 *gl_,
1202 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices))
1203 .Times(1)
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) {
1213 SetupTexture();
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(_, _, _, _))
1222 .Times(0)
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) {
1233 SetupTexture();
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(_, _, _))
1242 .Times(0)
1243 .RetiresOnSaturation();
1244 DrawArrays cmd;
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) {
1252 SetupTexture();
1253 SetupIndexBuffer();
1254 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
1255 SetupExpectationsForApplyingDefaultDirtyState();
1256 EXPECT_CALL(*gl_,
1257 DrawElements(GL_TRIANGLES,
1258 kValidIndexRangeCount,
1259 GL_UNSIGNED_SHORT,
1260 BufferOffset(kValidIndexRangeStart * 2)))
1261 .Times(1)
1262 .RetiresOnSaturation();
1263 DrawElements cmd;
1264 cmd.Init(GL_TRIANGLES,
1265 kValidIndexRangeCount,
1266 GL_UNSIGNED_SHORT,
1267 kValidIndexRangeStart * 2);
1268 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1269 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1272 TEST_P(GLES2DecoderWithShaderTest, DrawElementsMissingAttributesFails) {
1273 SetupIndexBuffer();
1274 DoEnableVertexAttribArray(1);
1276 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1277 DrawElements cmd;
1278 cmd.Init(GL_TRIANGLES,
1279 kValidIndexRangeCount,
1280 GL_UNSIGNED_SHORT,
1281 kValidIndexRangeStart * 2);
1282 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1283 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1286 TEST_P(GLES2DecoderWithShaderTest,
1287 DrawElementsMissingAttributesZeroCountSucceeds) {
1288 SetupIndexBuffer();
1289 DoEnableVertexAttribArray(1);
1291 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1292 DrawElements cmd;
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) {
1299 SetupIndexBuffer();
1300 DoEnableVertexAttribArray(6);
1302 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1303 DrawElements cmd;
1304 cmd.Init(GL_TRIANGLES,
1305 kValidIndexRangeCount,
1306 GL_UNSIGNED_SHORT,
1307 kValidIndexRangeStart * 2);
1308 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1309 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1312 TEST_P(GLES2DecoderWithShaderTest, DrawElementsValidAttributesSucceeds) {
1313 SetupTexture();
1314 SetupVertexBuffer();
1315 SetupIndexBuffer();
1316 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1317 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1318 SetupExpectationsForApplyingDefaultDirtyState();
1320 EXPECT_CALL(*gl_,
1321 DrawElements(GL_TRIANGLES,
1322 kValidIndexRangeCount,
1323 GL_UNSIGNED_SHORT,
1324 BufferOffset(kValidIndexRangeStart * 2)))
1325 .Times(1)
1326 .RetiresOnSaturation();
1327 DrawElements cmd;
1328 cmd.Init(GL_TRIANGLES,
1329 kValidIndexRangeCount,
1330 GL_UNSIGNED_SHORT,
1331 kValidIndexRangeStart * 2);
1332 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1333 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1336 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedBufferFails) {
1337 SetupVertexBuffer();
1338 SetupIndexBuffer();
1339 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1340 DeleteIndexBuffer();
1342 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1343 DrawElements cmd;
1344 cmd.Init(GL_TRIANGLES,
1345 kValidIndexRangeCount,
1346 GL_UNSIGNED_SHORT,
1347 kValidIndexRangeStart * 2);
1348 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1349 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1352 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedProgramSucceeds) {
1353 SetupTexture();
1354 SetupIndexBuffer();
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);
1361 DrawElements cmd;
1362 cmd.Init(GL_TRIANGLES,
1363 kValidIndexRangeCount,
1364 GL_UNSIGNED_SHORT,
1365 kValidIndexRangeStart * 2);
1366 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1367 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1370 TEST_P(GLES2DecoderWithShaderTest, DrawElementsWithInvalidModeFails) {
1371 SetupVertexBuffer();
1372 SetupIndexBuffer();
1373 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1375 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1376 DrawElements cmd;
1377 cmd.Init(GL_QUADS,
1378 kValidIndexRangeCount,
1379 GL_UNSIGNED_SHORT,
1380 kValidIndexRangeStart * 2);
1381 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1382 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1383 cmd.Init(GL_POLYGON,
1384 kValidIndexRangeCount,
1385 GL_UNSIGNED_SHORT,
1386 kValidIndexRangeStart);
1387 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1388 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1391 TEST_P(GLES2DecoderWithShaderTest, DrawElementsInvalidCountFails) {
1392 SetupVertexBuffer();
1393 SetupIndexBuffer();
1394 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1396 // Try start > 0
1397 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1398 DrawElements cmd;
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();
1413 SetupIndexBuffer();
1414 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1416 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1417 DrawElements cmd;
1418 cmd.Init(GL_TRIANGLES,
1419 kInvalidIndexRangeCount,
1420 GL_UNSIGNED_SHORT,
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();
1429 SetupIndexBuffer();
1430 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1432 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1433 DrawElements cmd;
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) {
1441 SetupTexture();
1442 SetupVertexBuffer();
1443 SetupIndexBuffer();
1444 DoEnableVertexAttribArray(1);
1445 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1447 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1448 .Times(0)
1449 .RetiresOnSaturation();
1450 DrawElementsInstancedANGLE cmd;
1451 cmd.Init(GL_TRIANGLES,
1452 kValidIndexRangeCount,
1453 GL_UNSIGNED_SHORT,
1454 kValidIndexRangeStart * 2,
1456 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1457 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1460 TEST_P(GLES2DecoderGeometryInstancingTest,
1461 DrawElementsInstancedANGLENoAttributesFails) {
1462 SetupTexture();
1463 SetupIndexBuffer();
1465 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1466 .Times(0)
1467 .RetiresOnSaturation();
1468 DrawElementsInstancedANGLE cmd;
1469 cmd.Init(GL_TRIANGLES,
1470 kValidIndexRangeCount,
1471 GL_UNSIGNED_SHORT,
1472 kValidIndexRangeStart * 2,
1474 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1475 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1478 TEST_P(GLES2DecoderGeometryInstancingTest,
1479 DrawElementsInstancedANGLESimulatedAttrib0) {
1480 SetupTexture();
1481 SetupVertexBuffer();
1482 SetupIndexBuffer();
1483 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1485 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1486 SetupExpectationsForApplyingDefaultDirtyState();
1488 DoVertexAttribDivisorANGLE(0, 1);
1489 EXPECT_CALL(
1490 *gl_,
1491 DrawElementsInstancedANGLE(GL_TRIANGLES,
1492 kValidIndexRangeCount,
1493 GL_UNSIGNED_SHORT,
1494 BufferOffset(kValidIndexRangeStart * 2),
1496 .Times(1)
1497 .RetiresOnSaturation();
1498 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
1499 .Times(1)
1500 .RetiresOnSaturation();
1501 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
1502 .Times(1)
1503 .RetiresOnSaturation();
1504 DrawElementsInstancedANGLE cmd;
1505 cmd.Init(GL_TRIANGLES,
1506 kValidIndexRangeCount,
1507 GL_UNSIGNED_SHORT,
1508 kValidIndexRangeStart * 2,
1510 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1511 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1514 TEST_P(GLES2DecoderGeometryInstancingTest,
1515 DrawElementsInstancedANGLEMissingAttributesFails) {
1516 SetupIndexBuffer();
1517 DoEnableVertexAttribArray(1);
1519 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1520 DrawElementsInstancedANGLE cmd;
1521 cmd.Init(GL_TRIANGLES,
1522 kValidIndexRangeCount,
1523 GL_UNSIGNED_SHORT,
1524 kValidIndexRangeStart * 2,
1526 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1527 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1530 TEST_P(GLES2DecoderGeometryInstancingTest,
1531 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds) {
1532 SetupIndexBuffer();
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) {
1544 SetupIndexBuffer();
1545 SetupTexture();
1546 SetupVertexBuffer();
1547 DoEnableVertexAttribArray(1);
1548 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1549 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1550 SetupExpectationsForApplyingDefaultDirtyState();
1552 EXPECT_CALL(
1553 *gl_,
1554 DrawElementsInstancedANGLE(GL_TRIANGLES,
1555 kValidIndexRangeCount,
1556 GL_UNSIGNED_SHORT,
1557 BufferOffset(kValidIndexRangeStart * 2),
1559 .Times(1)
1560 .RetiresOnSaturation();
1561 DrawElementsInstancedANGLE cmd;
1562 cmd.Init(GL_TRIANGLES,
1563 kValidIndexRangeCount,
1564 GL_UNSIGNED_SHORT,
1565 kValidIndexRangeStart * 2,
1567 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1568 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1571 TEST_P(GLES2DecoderGeometryInstancingTest,
1572 DrawElementsInstancedANGLEWithInvalidModeFails) {
1573 SetupIndexBuffer();
1574 SetupVertexBuffer();
1575 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1577 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1578 DrawElementsInstancedANGLE cmd;
1579 cmd.Init(GL_QUADS,
1580 kValidIndexRangeCount,
1581 GL_UNSIGNED_SHORT,
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,
1588 GL_UNSIGNED_SHORT,
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) {
1598 SetupTexture();
1599 SetupIndexBuffer();
1600 SetupVertexBuffer();
1601 SetupExpectationsForApplyingDefaultDirtyState();
1602 // Add offset so we're sure we're accessing data near the end of the buffer.
1603 DoVertexAttribPointer(
1606 GL_FLOAT,
1608 (kNumVertices - kMaxValidIndex - 1) * 2 * sizeof(GLfloat));
1610 DoEnableVertexAttribArray(0);
1611 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1612 DoVertexAttribDivisorANGLE(0, 1);
1613 EXPECT_CALL(
1614 *gl_,
1615 DrawElementsInstancedANGLE(GL_TRIANGLES,
1616 kValidIndexRangeCount,
1617 GL_UNSIGNED_SHORT,
1618 BufferOffset(kValidIndexRangeStart * 2),
1619 kNumVertices / 2))
1620 .Times(1)
1621 .RetiresOnSaturation();
1622 DrawElementsInstancedANGLE cmd;
1623 cmd.Init(GL_TRIANGLES,
1624 kValidIndexRangeCount,
1625 GL_UNSIGNED_SHORT,
1626 kValidIndexRangeStart * 2,
1627 kNumVertices / 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) {
1635 SetupTexture();
1636 SetupIndexBuffer();
1637 SetupVertexBuffer();
1638 SetupExpectationsForApplyingDefaultDirtyState();
1639 // Add offset so we're sure we're accessing data near the end of the buffer.
1640 DoVertexAttribPointer(
1643 GL_FLOAT,
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);
1652 EXPECT_CALL(
1653 *gl_,
1654 DrawElements(GL_TRIANGLES,
1655 kValidIndexRangeCount,
1656 GL_UNSIGNED_SHORT,
1657 BufferOffset(kValidIndexRangeStart * 2)))
1658 .Times(1)
1659 .RetiresOnSaturation();
1660 DrawElements cmd;
1661 cmd.Init(GL_TRIANGLES,
1662 kValidIndexRangeCount,
1663 GL_UNSIGNED_SHORT,
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) {
1672 SetupTexture();
1673 SetupIndexBuffer();
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);
1681 EXPECT_CALL(
1682 *gl_,
1683 DrawElementsInstancedANGLE(GL_TRIANGLES,
1684 kValidIndexRangeCount,
1685 GL_UNSIGNED_SHORT,
1686 BufferOffset(kValidIndexRangeStart * 2),
1687 kNumVertices))
1688 .Times(1)
1689 .RetiresOnSaturation();
1690 DrawElementsInstancedANGLE cmd;
1691 cmd.Init(GL_TRIANGLES,
1692 kValidIndexRangeCount,
1693 GL_UNSIGNED_SHORT,
1694 kValidIndexRangeStart * 2,
1695 kNumVertices);
1696 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1697 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1700 TEST_P(GLES2DecoderGeometryInstancingTest,
1701 DrawElementsInstancedANGLELargeFails) {
1702 SetupTexture();
1703 SetupIndexBuffer();
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(_, _, _, _, _))
1711 .Times(0)
1712 .RetiresOnSaturation();
1713 DrawElementsInstancedANGLE cmd;
1714 cmd.Init(GL_TRIANGLES,
1715 kValidIndexRangeCount,
1716 GL_UNSIGNED_SHORT,
1717 kValidIndexRangeStart * 2,
1718 kNumVertices + 1);
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(_, _, _, _, _))
1724 .Times(0)
1725 .RetiresOnSaturation();
1726 cmd.Init(GL_TRIANGLES,
1727 kInvalidIndexRangeCount,
1728 GL_UNSIGNED_SHORT,
1729 kInvalidIndexRangeStart * 2,
1730 kNumVertices);
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) {
1738 SetupTexture();
1739 SetupIndexBuffer();
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(_, _, _, _, _))
1747 .Times(0)
1748 .RetiresOnSaturation();
1749 DrawElementsInstancedANGLE cmd;
1750 cmd.Init(GL_TRIANGLES,
1751 kValidIndexRangeCount,
1752 GL_UNSIGNED_SHORT,
1753 kValidIndexRangeStart * 2,
1754 -1);
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) {
1763 SetupTexture();
1764 SetupIndexBuffer();
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);
1772 EXPECT_CALL(
1773 *gl_,
1774 DrawElementsInstancedANGLE(GL_TRIANGLES,
1775 kValidIndexRangeCount,
1776 GL_UNSIGNED_SHORT,
1777 BufferOffset(kValidIndexRangeStart * 2),
1778 kNumVertices))
1779 .Times(1)
1780 .RetiresOnSaturation();
1781 DrawElementsInstancedANGLE cmd;
1782 cmd.Init(GL_TRIANGLES,
1783 kValidIndexRangeCount,
1784 GL_UNSIGNED_SHORT,
1785 kValidIndexRangeStart * 2,
1786 kNumVertices);
1787 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1788 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1791 TEST_P(GLES2DecoderGeometryInstancingTest,
1792 DrawElementsInstancedANGLENoDivisor0Fails) {
1793 SetupTexture();
1794 SetupIndexBuffer();
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(_, _, _, _, _))
1803 .Times(0)
1804 .RetiresOnSaturation();
1805 DrawElementsInstancedANGLE cmd;
1806 cmd.Init(GL_TRIANGLES,
1807 kValidIndexRangeCount,
1808 GL_UNSIGNED_SHORT,
1809 kValidIndexRangeStart * 2,
1810 kNumVertices);
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) {
1818 SetupTexture();
1819 SetupIndexBuffer();
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(_, _, _, _))
1828 .Times(0)
1829 .RetiresOnSaturation();
1830 DrawElements cmd;
1831 cmd.Init(GL_TRIANGLES,
1832 kValidIndexRangeCount,
1833 GL_UNSIGNED_SHORT,
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.
1844 DoTexImage2D(
1845 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1846 DoTexImage2D(
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,
1850 kServiceTextureId,
1851 GL_TEXTURE_2D,
1852 GL_TEXTURE_2D,
1854 GL_RGBA,
1855 GL_RGBA,
1856 GL_UNSIGNED_BYTE,
1859 SetupClearTextureExpectations(kServiceTextureId,
1860 kServiceTextureId,
1861 GL_TEXTURE_2D,
1862 GL_TEXTURE_2D,
1864 GL_RGBA,
1865 GL_RGBA,
1866 GL_UNSIGNED_BYTE,
1869 SetupExpectationsForApplyingDefaultDirtyState();
1870 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1871 .Times(1)
1872 .RetiresOnSaturation();
1873 DrawArrays cmd;
1874 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1875 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1876 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1878 // But not again
1879 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1880 .Times(1)
1881 .RetiresOnSaturation();
1882 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1883 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1886 TEST_P(GLES2DecoderWithShaderTest, DrawElementsClearsAfterTexImage2DNULL) {
1887 SetupAllNeededVertexBuffers();
1888 SetupIndexBuffer();
1889 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1890 // Create an uncleared texture with 2 levels.
1891 DoTexImage2D(
1892 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1893 DoTexImage2D(
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,
1897 kServiceTextureId,
1898 GL_TEXTURE_2D,
1899 GL_TEXTURE_2D,
1901 GL_RGBA,
1902 GL_RGBA,
1903 GL_UNSIGNED_BYTE,
1906 SetupClearTextureExpectations(kServiceTextureId,
1907 kServiceTextureId,
1908 GL_TEXTURE_2D,
1909 GL_TEXTURE_2D,
1911 GL_RGBA,
1912 GL_RGBA,
1913 GL_UNSIGNED_BYTE,
1916 SetupExpectationsForApplyingDefaultDirtyState();
1918 EXPECT_CALL(*gl_,
1919 DrawElements(GL_TRIANGLES,
1920 kValidIndexRangeCount,
1921 GL_UNSIGNED_SHORT,
1922 BufferOffset(kValidIndexRangeStart * 2)))
1923 .Times(1)
1924 .RetiresOnSaturation();
1925 DrawElements cmd;
1926 cmd.Init(GL_TRIANGLES,
1927 kValidIndexRangeCount,
1928 GL_UNSIGNED_SHORT,
1929 kValidIndexRangeStart * 2);
1930 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1931 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1933 // But not again
1934 EXPECT_CALL(*gl_,
1935 DrawElements(GL_TRIANGLES,
1936 kValidIndexRangeCount,
1937 GL_UNSIGNED_SHORT,
1938 BufferOffset(kValidIndexRangeStart * 2)))
1939 .Times(1)
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);
1958 DoTexImage2D(
1959 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1960 DoBindFramebuffer(
1961 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1962 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1963 GL_COLOR_ATTACHMENT0,
1964 GL_TEXTURE_2D,
1965 kFBOClientTextureId,
1966 kFBOServiceTextureId,
1968 GL_NO_ERROR);
1970 // Setup "render from" texture.
1971 SetupTexture();
1973 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1974 GL_COLOR_BUFFER_BIT, // clear bits
1978 0, // color
1979 0, // stencil
1980 1.0f, // depth
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))
1994 .Times(1)
1995 .RetiresOnSaturation();
1996 DrawArrays cmd;
1997 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1998 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1999 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2001 // But not again.
2002 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2003 .Times(1)
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);
2021 DoTexImage2D(
2022 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2023 DoBindFramebuffer(
2024 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2025 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2026 GL_COLOR_ATTACHMENT0,
2027 GL_TEXTURE_2D,
2028 kFBOClientTextureId,
2029 kFBOServiceTextureId,
2031 GL_NO_ERROR);
2033 // Setup "render from" texture.
2034 SetupTexture();
2036 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
2037 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED))
2038 .RetiresOnSaturation();
2039 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
2040 DrawArrays cmd;
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) {
2047 SetupTexture();
2048 DoBindRenderbuffer(
2049 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
2050 DoBindFramebuffer(
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,
2056 GL_RENDERBUFFER,
2057 client_renderbuffer_id_,
2058 kServiceRenderbufferId,
2059 GL_NO_ERROR);
2061 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
2062 GL_COLOR_BUFFER_BIT, // clear bits
2066 0, // color
2067 0, // stencil
2068 1.0f, // depth
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))
2083 .Times(1)
2084 .RetiresOnSaturation();
2085 DrawArrays cmd;
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) {
2092 InitState init;
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;
2098 InitDecoder(init);
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];
2110 int32 shm_id =
2111 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryId;
2112 uint32 shm_offset =
2113 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryOffset;
2114 DoTexImage2D(face,
2116 GL_RGBA,
2120 GL_RGBA,
2121 GL_UNSIGNED_BYTE,
2122 shm_id,
2123 shm_offset);
2124 DoTexImage2D(face,
2126 GL_RGBA,
2130 GL_RGBA,
2131 GL_UNSIGNED_BYTE,
2132 shm_id,
2133 shm_offset);
2135 // Expect 2 levels will be cleared.
2136 SetupClearTextureExpectations(kServiceTextureId,
2137 kServiceTextureId,
2138 GL_TEXTURE_CUBE_MAP,
2139 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2141 GL_RGBA,
2142 GL_RGBA,
2143 GL_UNSIGNED_BYTE,
2146 SetupClearTextureExpectations(kServiceTextureId,
2147 kServiceTextureId,
2148 GL_TEXTURE_CUBE_MAP,
2149 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2151 GL_RGBA,
2152 GL_RGBA,
2153 GL_UNSIGNED_BYTE,
2156 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2157 SetupExpectationsForApplyingDefaultDirtyState();
2158 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2159 .Times(1)
2160 .RetiresOnSaturation();
2161 DrawArrays cmd;
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);
2179 DoTexImage2D(
2180 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2181 DoBindFramebuffer(
2182 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2183 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2184 GL_COLOR_ATTACHMENT0,
2185 GL_TEXTURE_2D,
2186 kFBOClientTextureId,
2187 kFBOServiceTextureId,
2189 GL_NO_ERROR);
2191 DoBindRenderbuffer(
2192 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
2193 DoBindFramebuffer(
2194 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2195 DoRenderbufferStorage(GL_RENDERBUFFER,
2196 GL_DEPTH_COMPONENT16,
2197 GL_DEPTH_COMPONENT,
2200 GL_NO_ERROR);
2201 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
2202 GL_DEPTH_ATTACHMENT,
2203 GL_RENDERBUFFER,
2204 client_renderbuffer_id_,
2205 kServiceRenderbufferId,
2206 GL_NO_ERROR);
2208 SetupTexture();
2209 SetupExpectationsForFramebufferClearing(
2210 GL_FRAMEBUFFER, // target
2211 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, // clear bits
2215 0, // color
2216 0, // stencil
2217 1.0f, // depth
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
2225 true, // depth mask
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))
2232 .Times(1)
2233 .RetiresOnSaturation();
2234 DrawArrays cmd;
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,
2257 GL_RGBA,
2261 GL_RGBA,
2262 GL_UNSIGNED_BYTE,
2263 kSharedMemoryId,
2264 kSharedMemoryOffset);
2265 DoBindFramebuffer(
2266 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2267 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2268 GL_COLOR_ATTACHMENT0,
2269 GL_TEXTURE_2D,
2270 kFBOClientTextureId,
2271 kFBOServiceTextureId,
2273 GL_NO_ERROR);
2275 // Setup "render from" texture.
2276 SetupTexture();
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))
2294 .Times(1)
2295 .RetiresOnSaturation();
2296 DrawArrays cmd;
2297 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2298 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2299 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2301 // But not again.
2302 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2303 .Times(1)
2304 .RetiresOnSaturation();
2305 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2306 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2309 TEST_P(GLES2DecoderManualInitTest, DrawClearsDepthTexture) {
2310 InitState init;
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;
2318 InitDecoder(init);
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,
2329 level,
2330 GL_DEPTH_COMPONENT,
2334 GL_DEPTH_COMPONENT,
2335 GL_UNSIGNED_INT,
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, _))
2345 .Times(1)
2346 .RetiresOnSaturation();
2348 EXPECT_CALL(*gl_,
2349 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT,
2350 attachment,
2351 target,
2352 kServiceTextureId,
2353 level))
2354 .Times(1)
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))
2373 .Times(1)
2374 .RetiresOnSaturation();
2376 SetupExpectationsForApplyingDefaultDirtyState();
2377 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2378 .Times(1)
2379 .RetiresOnSaturation();
2380 DrawArrays cmd;
2381 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2382 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2383 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2386 } // namespace gles2
2387 } // namespace gpu