Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_drawing.cc
blobbb0286d2a8366378c2fcb322199067c966ce15a7
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
14 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
15 #include "gpu/command_buffer/service/context_group.h"
16 #include "gpu/command_buffer/service/context_state.h"
17 #include "gpu/command_buffer/service/gl_surface_mock.h"
18 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
20 #include "gpu/command_buffer/service/image_manager.h"
21 #include "gpu/command_buffer/service/mailbox_manager.h"
22 #include "gpu/command_buffer/service/mocks.h"
23 #include "gpu/command_buffer/service/program_manager.h"
24 #include "gpu/command_buffer/service/test_helper.h"
25 #include "gpu/config/gpu_switches.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gl/gl_implementation.h"
28 #include "ui/gl/gl_mock.h"
29 #include "ui/gl/gl_surface_stub.h"
31 #if !defined(GL_DEPTH24_STENCIL8)
32 #define GL_DEPTH24_STENCIL8 0x88F0
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 // 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;
72 InitDecoder(init);
73 SetupDefaultProgram();
77 INSTANTIATE_TEST_CASE_P(Service,
78 GLES2DecoderGeometryInstancingTest,
79 ::testing::Bool());
81 void GLES2DecoderManualInitTest::DirtyStateMaskTest(GLuint color_bits,
82 bool depth_mask,
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))
120 .Times(1)
121 .RetiresOnSaturation();
122 DrawArrays draw_cmd;
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) {
131 ColorMask cmd;
132 cmd.Init(true, true, true, true);
133 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
134 EXPECT_EQ(GL_NO_ERROR, GetGLError());
136 SetupTexture();
137 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
138 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
139 false, // Framebuffer has depth
140 false, // Framebuffer has stencil
141 0x1110, // color bits
142 false, // depth mask
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))
149 .Times(1)
150 .RetiresOnSaturation();
151 DrawArrays draw_cmd;
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()))
163 .Times(0);
164 result->size = 0;
165 GetIntegerv cmd2;
166 cmd2.Init(GL_COLOR_WRITEMASK, shared_memory_id_, shared_memory_offset_);
167 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
168 EXPECT_EQ(
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();
182 DepthMask cmd;
183 cmd.Init(true);
184 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
185 EXPECT_EQ(GL_NO_ERROR, GetGLError());
187 SetupTexture();
188 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
189 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
190 false, // Framebuffer has depth
191 false, // Framebuffer has stencil
192 0x1110, // color bits
193 false, // depth mask
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))
200 .Times(1)
201 .RetiresOnSaturation();
202 DrawArrays draw_cmd;
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()))
214 .Times(0);
215 result->size = 0;
216 GetIntegerv cmd2;
217 cmd2.Init(GL_DEPTH_WRITEMASK, shared_memory_id_, shared_memory_offset_);
218 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
219 EXPECT_EQ(
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();
231 StencilMask cmd;
232 cmd.Init(kMask);
233 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
234 EXPECT_EQ(GL_NO_ERROR, GetGLError());
236 SetupTexture();
237 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
238 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
239 false, // Framebuffer has depth
240 false, // Framebuffer has stencil
241 0x1110, // color bits
242 false, // depth mask
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))
249 .Times(1)
250 .RetiresOnSaturation();
251 DrawArrays draw_cmd;
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()))
263 .Times(0);
264 result->size = 0;
265 GetIntegerv cmd2;
266 cmd2.Init(GL_STENCIL_WRITEMASK, shared_memory_id_, shared_memory_offset_);
267 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
268 EXPECT_EQ(
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) {
277 ColorMask cmd;
278 cmd.Init(true, true, true, true);
279 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
280 EXPECT_EQ(GL_NO_ERROR, GetGLError());
282 SetupTexture();
283 SetupVertexBuffer();
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
294 false, // depth mask
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))
301 .Times(1)
302 .RetiresOnSaturation();
303 DrawArrays draw_cmd;
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))
310 .Times(1)
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,
329 kFormat,
330 kWidth,
331 kHeight,
333 kFormat,
334 GL_UNSIGNED_BYTE,
335 kSharedMemoryId,
336 kSharedMemoryOffset);
337 DoBindFramebuffer(
338 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
339 DoFramebufferTexture2D(GL_FRAMEBUFFER,
340 GL_COLOR_ATTACHMENT0,
341 GL_TEXTURE_2D,
342 kNewClientId,
343 kNewServiceId,
345 GL_NO_ERROR);
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
356 false, // depth mask
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))
363 .Times(1)
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))
370 .Times(1)
371 .RetiresOnSaturation();
372 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
373 EXPECT_EQ(GL_NO_ERROR, GetGLError());
375 // Unbind
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
382 false, // depth mask
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))
389 .Times(1)
390 .RetiresOnSaturation();
391 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
392 EXPECT_EQ(GL_NO_ERROR, GetGLError());
395 TEST_P(GLES2DecoderManualInitTest, DepthEnableWithDepth) {
396 InitState init;
397 init.has_depth = true;
398 init.request_depth = true;
399 init.bind_generates_resource = true;
400 InitDecoder(init);
402 Enable cmd;
403 cmd.Init(GL_DEPTH_TEST);
404 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
405 EXPECT_EQ(GL_NO_ERROR, GetGLError());
407 SetupDefaultProgram();
408 SetupTexture();
409 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
410 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
411 true, // Framebuffer has depth
412 false, // Framebuffer has stencil
413 0x1110, // color bits
414 true, // depth mask
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))
421 .Times(1)
422 .RetiresOnSaturation();
423 DrawArrays draw_cmd;
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, _))
435 .Times(0)
436 .RetiresOnSaturation();
437 result->size = 0;
438 GetIntegerv cmd2;
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) {
448 InitState init;
449 init.has_depth = true;
450 init.bind_generates_resource = true;
451 InitDecoder(init);
453 Enable cmd;
454 cmd.Init(GL_DEPTH_TEST);
455 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
456 EXPECT_EQ(GL_NO_ERROR, GetGLError());
458 SetupDefaultProgram();
459 SetupTexture();
460 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
461 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
462 false, // Framebuffer has depth
463 false, // Framebuffer has stencil
464 0x1110, // color bits
465 false, // depth mask
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))
472 .Times(1)
473 .RetiresOnSaturation();
474 DrawArrays draw_cmd;
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, _))
486 .Times(0)
487 .RetiresOnSaturation();
488 result->size = 0;
489 GetIntegerv cmd2;
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) {
499 InitState init;
500 init.has_stencil = true;
501 init.request_stencil = true;
502 init.bind_generates_resource = true;
503 InitDecoder(init);
505 Enable cmd;
506 cmd.Init(GL_STENCIL_TEST);
507 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
508 EXPECT_EQ(GL_NO_ERROR, GetGLError());
510 SetupDefaultProgram();
511 SetupTexture();
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
518 false, // depth mask
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))
525 .Times(1)
526 .RetiresOnSaturation();
527 DrawArrays draw_cmd;
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, _))
539 .Times(0)
540 .RetiresOnSaturation();
541 result->size = 0;
542 GetIntegerv cmd2;
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) {
552 InitState init;
553 init.has_stencil = true;
554 init.bind_generates_resource = true;
555 InitDecoder(init);
557 Enable cmd;
558 cmd.Init(GL_STENCIL_TEST);
559 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
560 EXPECT_EQ(GL_NO_ERROR, GetGLError());
562 SetupDefaultProgram();
563 SetupTexture();
564 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
565 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
566 false, // Framebuffer has depth
567 false, // Framebuffer has stencil
568 0x1110, // color bits
569 false, // depth mask
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))
576 .Times(1)
577 .RetiresOnSaturation();
578 DrawArrays draw_cmd;
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, _))
590 .Times(0)
591 .RetiresOnSaturation();
592 result->size = 0;
593 GetIntegerv cmd2;
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) {
603 InitState init;
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;
611 InitDecoder(init);
613 SetupDefaultProgram();
614 SetupAllNeededVertexBuffers();
615 SetupTexture();
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) {
630 InitState init;
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;
638 InitDecoder(init);
640 SetupDefaultProgram();
641 SetupAllNeededVertexBuffers();
642 SetupTexture();
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) {
656 InitState init;
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;
664 InitDecoder(init);
666 SetupDefaultProgram();
667 SetupAllNeededVertexBuffers();
668 SetupTexture();
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) {
691 SetupTexture();
692 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
693 SetupExpectationsForApplyingDefaultDirtyState();
695 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
696 .Times(1)
697 .RetiresOnSaturation();
698 DrawArrays cmd;
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;
707 SetupTexture();
708 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
709 DrawArrays cmd;
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;
719 SetupTexture();
720 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
721 DrawArrays cmd;
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;
731 SetupTexture();
732 AddExpectationsForSimulatedAttrib0WithError(
733 kFakeLargeCount, 0, GL_OUT_OF_MEMORY);
734 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
735 DrawArrays cmd;
736 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount);
737 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
738 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
739 EXPECT_FALSE(GetDecoder()->WasContextLost());
742 TEST_P(GLES2DecoderWithShaderTest, DrawArraysBadTextureUsesBlack) {
743 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
744 // This is an NPOT texture. As the default filtering requires mips
745 // this should trigger replacing with black textures before rendering.
746 DoTexImage2D(GL_TEXTURE_2D,
748 GL_RGBA,
752 GL_RGBA,
753 GL_UNSIGNED_BYTE,
754 kSharedMemoryId,
755 kSharedMemoryOffset);
756 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
758 InSequence sequence;
759 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
760 .Times(1)
761 .RetiresOnSaturation();
762 EXPECT_CALL(
763 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceBlackTexture2dId))
764 .Times(1)
765 .RetiresOnSaturation();
766 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
767 .Times(1)
768 .RetiresOnSaturation();
769 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
770 .Times(1)
771 .RetiresOnSaturation();
772 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
773 .Times(1)
774 .RetiresOnSaturation();
775 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
776 .Times(1)
777 .RetiresOnSaturation();
779 SetupExpectationsForApplyingDefaultDirtyState();
780 DrawArrays cmd;
781 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
782 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
783 EXPECT_EQ(GL_NO_ERROR, GetGLError());
786 TEST_P(GLES2DecoderWithShaderTest, DrawArraysMissingAttributesFails) {
787 DoEnableVertexAttribArray(1);
789 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
790 DrawArrays cmd;
791 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
792 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
793 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
796 TEST_P(GLES2DecoderWithShaderTest,
797 DrawArraysMissingAttributesZeroCountSucceeds) {
798 DoEnableVertexAttribArray(1);
800 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
801 DrawArrays cmd;
802 cmd.Init(GL_TRIANGLES, 0, 0);
803 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
804 EXPECT_EQ(GL_NO_ERROR, GetGLError());
807 TEST_P(GLES2DecoderWithShaderTest, DrawArraysValidAttributesSucceeds) {
808 SetupTexture();
809 SetupVertexBuffer();
810 DoEnableVertexAttribArray(1);
811 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
812 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
813 SetupExpectationsForApplyingDefaultDirtyState();
815 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
816 .Times(1)
817 .RetiresOnSaturation();
818 DrawArrays cmd;
819 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
820 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
821 EXPECT_EQ(GL_NO_ERROR, GetGLError());
824 // Same as DrawArraysValidAttributesSucceeds, but with workaround
825 // |init_vertex_attributes|.
826 TEST_P(GLES2DecoderManualInitTest, InitVertexAttributes) {
827 base::CommandLine command_line(0, NULL);
828 command_line.AppendSwitchASCII(
829 switches::kGpuDriverBugWorkarounds,
830 base::IntToString(gpu::INIT_VERTEX_ATTRIBUTES));
831 InitState init;
832 init.has_alpha = true;
833 init.has_depth = true;
834 init.request_alpha = true;
835 init.request_depth = true;
836 init.bind_generates_resource = true;
837 InitDecoderWithCommandLine(init, &command_line);
838 SetupDefaultProgram();
839 SetupTexture();
840 SetupVertexBuffer();
841 DoEnableVertexAttribArray(1);
842 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
843 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
844 SetupExpectationsForApplyingDefaultDirtyState();
846 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
847 .Times(1)
848 .RetiresOnSaturation();
849 DrawArrays cmd;
850 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
851 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
852 EXPECT_EQ(GL_NO_ERROR, GetGLError());
855 TEST_P(GLES2DecoderWithShaderTest, DrawArraysDeletedBufferFails) {
856 SetupVertexBuffer();
857 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
858 DeleteVertexBuffer();
860 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
861 DrawArrays cmd;
862 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
863 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
864 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
867 TEST_P(GLES2DecoderWithShaderTest, DrawArraysDeletedProgramSucceeds) {
868 SetupTexture();
869 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
870 SetupExpectationsForApplyingDefaultDirtyState();
871 DoDeleteProgram(client_program_id_, kServiceProgramId);
873 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(1).RetiresOnSaturation();
874 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId)).Times(1);
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, DrawArraysWithInvalidModeFails) {
882 SetupVertexBuffer();
883 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
885 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
886 DrawArrays cmd;
887 cmd.Init(GL_QUADS, 0, 1);
888 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
889 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
890 cmd.Init(GL_POLYGON, 0, 1);
891 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
892 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
895 TEST_P(GLES2DecoderWithShaderTest, DrawArraysInvalidCountFails) {
896 SetupVertexBuffer();
897 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
899 // Try start > 0
900 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
901 DrawArrays cmd;
902 cmd.Init(GL_TRIANGLES, 1, kNumVertices);
903 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
904 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
905 EXPECT_EQ(GL_NO_ERROR, GetGLError());
907 // Try with count > size
908 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1);
909 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
910 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
911 EXPECT_EQ(GL_NO_ERROR, GetGLError());
913 // Try with attrib offset > 0
914 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
915 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 4);
916 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
917 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
918 EXPECT_EQ(GL_NO_ERROR, GetGLError());
920 // Try with size > 2 (ie, vec3 instead of vec2)
921 DoVertexAttribPointer(1, 3, GL_FLOAT, 0, 0);
922 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
923 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
924 EXPECT_EQ(GL_NO_ERROR, GetGLError());
926 // Try with stride > 8 (vec2 + vec2 byte)
927 DoVertexAttribPointer(1, 2, GL_FLOAT, sizeof(GLfloat) * 3, 0);
928 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
929 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
930 EXPECT_EQ(GL_NO_ERROR, GetGLError());
933 TEST_P(GLES2DecoderWithShaderTest, DrawArraysInstancedANGLEFails) {
934 SetupTexture();
935 SetupVertexBuffer();
936 DoEnableVertexAttribArray(1);
937 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
939 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
940 .Times(0)
941 .RetiresOnSaturation();
942 DrawArraysInstancedANGLE cmd;
943 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
944 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
945 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
948 TEST_P(GLES2DecoderWithShaderTest, VertexAttribDivisorANGLEFails) {
949 SetupTexture();
950 SetupVertexBuffer();
951 DoEnableVertexAttribArray(1);
952 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
954 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(_, _))
955 .Times(0)
956 .RetiresOnSaturation();
958 VertexAttribDivisorANGLE cmd;
959 cmd.Init(0, 1);
960 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
961 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
964 TEST_P(GLES2DecoderGeometryInstancingTest,
965 DrawArraysInstancedANGLENoAttributesFails) {
966 SetupTexture();
968 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
969 .Times(0)
970 .RetiresOnSaturation();
971 DrawArraysInstancedANGLE cmd;
972 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
973 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
974 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
977 TEST_P(GLES2DecoderGeometryInstancingTest,
978 DrawArraysInstancedANGLESimulatedAttrib0) {
979 SetupTexture();
980 SetupVertexBuffer();
981 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
983 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
984 SetupExpectationsForApplyingDefaultDirtyState();
986 DoVertexAttribDivisorANGLE(0, 1);
987 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 3))
988 .Times(1)
989 .RetiresOnSaturation();
990 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
991 .Times(1)
992 .RetiresOnSaturation();
993 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
994 .Times(1)
995 .RetiresOnSaturation();
996 DrawArraysInstancedANGLE cmd;
997 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 3);
998 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
999 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1002 TEST_P(GLES2DecoderGeometryInstancingTest,
1003 DrawArraysInstancedANGLEMissingAttributesFails) {
1004 DoEnableVertexAttribArray(1);
1006 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1007 DrawArraysInstancedANGLE cmd;
1008 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1009 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1010 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1013 TEST_P(GLES2DecoderGeometryInstancingTest,
1014 DrawArraysInstancedANGLEMissingAttributesZeroCountSucceeds) {
1015 DoEnableVertexAttribArray(1);
1017 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1018 DrawArraysInstancedANGLE cmd;
1019 cmd.Init(GL_TRIANGLES, 0, 0, 1);
1020 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1021 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1024 TEST_P(GLES2DecoderGeometryInstancingTest,
1025 DrawArraysInstancedANGLEValidAttributesSucceeds) {
1026 SetupTexture();
1027 SetupVertexBuffer();
1028 DoEnableVertexAttribArray(1);
1029 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1030 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
1031 SetupExpectationsForApplyingDefaultDirtyState();
1033 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 1))
1034 .Times(1)
1035 .RetiresOnSaturation();
1036 DrawArraysInstancedANGLE cmd;
1037 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1038 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1039 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1042 TEST_P(GLES2DecoderGeometryInstancingTest,
1043 DrawArraysInstancedANGLEWithInvalidModeFails) {
1044 SetupVertexBuffer();
1045 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1047 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1048 DrawArraysInstancedANGLE cmd;
1049 cmd.Init(GL_QUADS, 0, 1, 1);
1050 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1051 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1052 cmd.Init(GL_POLYGON, 0, 1, 1);
1053 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1054 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1057 TEST_P(GLES2DecoderGeometryInstancingTest,
1058 DrawArraysInstancedANGLEInvalidPrimcountFails) {
1059 SetupVertexBuffer();
1060 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1062 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1063 DrawArraysInstancedANGLE cmd;
1064 cmd.Init(GL_TRIANGLES, 0, 1, -1);
1065 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1066 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1069 // Per-instance data is twice as large, but number of instances is half
1070 TEST_P(GLES2DecoderGeometryInstancingTest,
1071 DrawArraysInstancedANGLELargeInstanceSucceeds) {
1072 SetupTexture();
1073 SetupVertexBuffer();
1074 SetupExpectationsForApplyingDefaultDirtyState();
1075 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1077 DoEnableVertexAttribArray(0);
1078 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1079 DoVertexAttribDivisorANGLE(0, 1);
1080 EXPECT_CALL(
1081 *gl_,
1082 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2))
1083 .Times(1)
1084 .RetiresOnSaturation();
1085 DrawArraysInstancedANGLE cmd;
1086 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2);
1087 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1088 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1091 // Regular drawArrays takes the divisor into account
1092 TEST_P(GLES2DecoderGeometryInstancingTest,
1093 DrawArraysWithDivisorSucceeds) {
1094 SetupTexture();
1095 SetupVertexBuffer();
1096 SetupExpectationsForApplyingDefaultDirtyState();
1097 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1099 DoEnableVertexAttribArray(0);
1100 // Access the data right at the end of the buffer.
1101 DoVertexAttribPointer(
1102 0, 2, GL_FLOAT, 0, (kNumVertices - 1) * 2 * sizeof(GLfloat));
1103 DoVertexAttribDivisorANGLE(0, 1);
1104 EXPECT_CALL(
1105 *gl_,
1106 DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1107 .Times(1)
1108 .RetiresOnSaturation();
1109 DrawArrays cmd;
1110 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1111 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1112 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1115 // Per-instance data is twice as large, but divisor is twice
1116 TEST_P(GLES2DecoderGeometryInstancingTest,
1117 DrawArraysInstancedANGLELargeDivisorSucceeds) {
1118 SetupTexture();
1119 SetupVertexBuffer();
1120 SetupExpectationsForApplyingDefaultDirtyState();
1121 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1123 DoEnableVertexAttribArray(0);
1124 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1125 DoVertexAttribDivisorANGLE(0, 2);
1126 EXPECT_CALL(
1127 *gl_,
1128 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices))
1129 .Times(1)
1130 .RetiresOnSaturation();
1131 DrawArraysInstancedANGLE cmd;
1132 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices);
1133 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1134 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1137 TEST_P(GLES2DecoderGeometryInstancingTest, DrawArraysInstancedANGLELargeFails) {
1138 SetupTexture();
1139 SetupVertexBuffer();
1140 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1142 DoEnableVertexAttribArray(0);
1143 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1144 DoVertexAttribDivisorANGLE(0, 1);
1145 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1146 .Times(0)
1147 .RetiresOnSaturation();
1148 DrawArraysInstancedANGLE cmd;
1149 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices + 1);
1150 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1151 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1152 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1154 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1155 .Times(0)
1156 .RetiresOnSaturation();
1157 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1, kNumVertices);
1158 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1159 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1160 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1163 // Per-index data is twice as large, but number of indices is half
1164 TEST_P(GLES2DecoderGeometryInstancingTest,
1165 DrawArraysInstancedANGLELargeIndexSucceeds) {
1166 SetupTexture();
1167 SetupVertexBuffer();
1168 SetupExpectationsForApplyingDefaultDirtyState();
1169 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
1171 DoEnableVertexAttribArray(0);
1172 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1173 DoVertexAttribDivisorANGLE(0, 1);
1174 EXPECT_CALL(
1175 *gl_,
1176 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices))
1177 .Times(1)
1178 .RetiresOnSaturation();
1179 DrawArraysInstancedANGLE cmd;
1180 cmd.Init(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices);
1181 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1182 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1185 TEST_P(GLES2DecoderGeometryInstancingTest,
1186 DrawArraysInstancedANGLENoDivisor0Fails) {
1187 SetupTexture();
1188 SetupVertexBuffer();
1189 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1191 DoEnableVertexAttribArray(0);
1192 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1193 DoVertexAttribDivisorANGLE(0, 1);
1194 DoVertexAttribDivisorANGLE(1, 1);
1195 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1196 .Times(0)
1197 .RetiresOnSaturation();
1198 DrawArraysInstancedANGLE cmd;
1199 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1200 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1201 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1202 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1205 TEST_P(GLES2DecoderGeometryInstancingTest,
1206 DrawArraysNoDivisor0Fails) {
1207 SetupTexture();
1208 SetupVertexBuffer();
1209 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1211 DoEnableVertexAttribArray(0);
1212 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1213 DoVertexAttribDivisorANGLE(0, 1);
1214 DoVertexAttribDivisorANGLE(1, 1);
1215 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
1216 .Times(0)
1217 .RetiresOnSaturation();
1218 DrawArrays cmd;
1219 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1220 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1221 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1222 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1225 TEST_P(GLES2DecoderWithShaderTest, DrawElementsNoAttributesSucceeds) {
1226 SetupTexture();
1227 SetupIndexBuffer();
1228 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
1229 SetupExpectationsForApplyingDefaultDirtyState();
1230 EXPECT_CALL(*gl_,
1231 DrawElements(GL_TRIANGLES,
1232 kValidIndexRangeCount,
1233 GL_UNSIGNED_SHORT,
1234 BufferOffset(kValidIndexRangeStart * 2)))
1235 .Times(1)
1236 .RetiresOnSaturation();
1237 DrawElements cmd;
1238 cmd.Init(GL_TRIANGLES,
1239 kValidIndexRangeCount,
1240 GL_UNSIGNED_SHORT,
1241 kValidIndexRangeStart * 2);
1242 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1243 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1246 TEST_P(GLES2DecoderWithShaderTest, DrawElementsMissingAttributesFails) {
1247 SetupIndexBuffer();
1248 DoEnableVertexAttribArray(1);
1250 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1251 DrawElements cmd;
1252 cmd.Init(GL_TRIANGLES,
1253 kValidIndexRangeCount,
1254 GL_UNSIGNED_SHORT,
1255 kValidIndexRangeStart * 2);
1256 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1257 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1260 TEST_P(GLES2DecoderWithShaderTest,
1261 DrawElementsMissingAttributesZeroCountSucceeds) {
1262 SetupIndexBuffer();
1263 DoEnableVertexAttribArray(1);
1265 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1266 DrawElements cmd;
1267 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2);
1268 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1269 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1272 TEST_P(GLES2DecoderWithShaderTest, DrawElementsExtraAttributesFails) {
1273 SetupIndexBuffer();
1274 DoEnableVertexAttribArray(6);
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, DrawElementsValidAttributesSucceeds) {
1287 SetupTexture();
1288 SetupVertexBuffer();
1289 SetupIndexBuffer();
1290 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1291 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1292 SetupExpectationsForApplyingDefaultDirtyState();
1294 EXPECT_CALL(*gl_,
1295 DrawElements(GL_TRIANGLES,
1296 kValidIndexRangeCount,
1297 GL_UNSIGNED_SHORT,
1298 BufferOffset(kValidIndexRangeStart * 2)))
1299 .Times(1)
1300 .RetiresOnSaturation();
1301 DrawElements cmd;
1302 cmd.Init(GL_TRIANGLES,
1303 kValidIndexRangeCount,
1304 GL_UNSIGNED_SHORT,
1305 kValidIndexRangeStart * 2);
1306 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1307 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1310 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedBufferFails) {
1311 SetupVertexBuffer();
1312 SetupIndexBuffer();
1313 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1314 DeleteIndexBuffer();
1316 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1317 DrawElements cmd;
1318 cmd.Init(GL_TRIANGLES,
1319 kValidIndexRangeCount,
1320 GL_UNSIGNED_SHORT,
1321 kValidIndexRangeStart * 2);
1322 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1323 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1326 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedProgramSucceeds) {
1327 SetupTexture();
1328 SetupIndexBuffer();
1329 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
1330 SetupExpectationsForApplyingDefaultDirtyState();
1331 DoDeleteProgram(client_program_id_, kServiceProgramId);
1333 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1);
1334 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId)).Times(1);
1335 DrawElements cmd;
1336 cmd.Init(GL_TRIANGLES,
1337 kValidIndexRangeCount,
1338 GL_UNSIGNED_SHORT,
1339 kValidIndexRangeStart * 2);
1340 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1341 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1344 TEST_P(GLES2DecoderWithShaderTest, DrawElementsWithInvalidModeFails) {
1345 SetupVertexBuffer();
1346 SetupIndexBuffer();
1347 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1349 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1350 DrawElements cmd;
1351 cmd.Init(GL_QUADS,
1352 kValidIndexRangeCount,
1353 GL_UNSIGNED_SHORT,
1354 kValidIndexRangeStart * 2);
1355 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1356 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1357 cmd.Init(GL_POLYGON,
1358 kValidIndexRangeCount,
1359 GL_UNSIGNED_SHORT,
1360 kValidIndexRangeStart);
1361 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1362 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1365 TEST_P(GLES2DecoderWithShaderTest, DrawElementsInvalidCountFails) {
1366 SetupVertexBuffer();
1367 SetupIndexBuffer();
1368 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1370 // Try start > 0
1371 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1372 DrawElements cmd;
1373 cmd.Init(GL_TRIANGLES, kNumIndices, GL_UNSIGNED_SHORT, 2);
1374 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1375 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1376 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1378 // Try with count > size
1379 cmd.Init(GL_TRIANGLES, kNumIndices + 1, GL_UNSIGNED_SHORT, 0);
1380 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1381 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1382 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1385 TEST_P(GLES2DecoderWithShaderTest, DrawElementsOutOfRangeIndicesFails) {
1386 SetupVertexBuffer();
1387 SetupIndexBuffer();
1388 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1390 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1391 DrawElements cmd;
1392 cmd.Init(GL_TRIANGLES,
1393 kInvalidIndexRangeCount,
1394 GL_UNSIGNED_SHORT,
1395 kInvalidIndexRangeStart * 2);
1396 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1397 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1398 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1401 TEST_P(GLES2DecoderWithShaderTest, DrawElementsOddOffsetForUint16Fails) {
1402 SetupVertexBuffer();
1403 SetupIndexBuffer();
1404 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1406 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1407 DrawElements cmd;
1408 cmd.Init(GL_TRIANGLES, kInvalidIndexRangeCount, GL_UNSIGNED_SHORT, 1);
1409 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1410 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1411 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1414 TEST_P(GLES2DecoderWithShaderTest, DrawElementsInstancedANGLEFails) {
1415 SetupTexture();
1416 SetupVertexBuffer();
1417 SetupIndexBuffer();
1418 DoEnableVertexAttribArray(1);
1419 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1421 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1422 .Times(0)
1423 .RetiresOnSaturation();
1424 DrawElementsInstancedANGLE cmd;
1425 cmd.Init(GL_TRIANGLES,
1426 kValidIndexRangeCount,
1427 GL_UNSIGNED_SHORT,
1428 kValidIndexRangeStart * 2,
1430 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1431 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1434 TEST_P(GLES2DecoderGeometryInstancingTest,
1435 DrawElementsInstancedANGLENoAttributesFails) {
1436 SetupTexture();
1437 SetupIndexBuffer();
1439 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1440 .Times(0)
1441 .RetiresOnSaturation();
1442 DrawElementsInstancedANGLE cmd;
1443 cmd.Init(GL_TRIANGLES,
1444 kValidIndexRangeCount,
1445 GL_UNSIGNED_SHORT,
1446 kValidIndexRangeStart * 2,
1448 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1449 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1452 TEST_P(GLES2DecoderGeometryInstancingTest,
1453 DrawElementsInstancedANGLESimulatedAttrib0) {
1454 SetupTexture();
1455 SetupVertexBuffer();
1456 SetupIndexBuffer();
1457 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1459 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1460 SetupExpectationsForApplyingDefaultDirtyState();
1462 DoVertexAttribDivisorANGLE(0, 1);
1463 EXPECT_CALL(
1464 *gl_,
1465 DrawElementsInstancedANGLE(GL_TRIANGLES,
1466 kValidIndexRangeCount,
1467 GL_UNSIGNED_SHORT,
1468 BufferOffset(kValidIndexRangeStart * 2),
1470 .Times(1)
1471 .RetiresOnSaturation();
1472 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
1473 .Times(1)
1474 .RetiresOnSaturation();
1475 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
1476 .Times(1)
1477 .RetiresOnSaturation();
1478 DrawElementsInstancedANGLE cmd;
1479 cmd.Init(GL_TRIANGLES,
1480 kValidIndexRangeCount,
1481 GL_UNSIGNED_SHORT,
1482 kValidIndexRangeStart * 2,
1484 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1485 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1488 TEST_P(GLES2DecoderGeometryInstancingTest,
1489 DrawElementsInstancedANGLEMissingAttributesFails) {
1490 SetupIndexBuffer();
1491 DoEnableVertexAttribArray(1);
1493 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1494 DrawElementsInstancedANGLE cmd;
1495 cmd.Init(GL_TRIANGLES,
1496 kValidIndexRangeCount,
1497 GL_UNSIGNED_SHORT,
1498 kValidIndexRangeStart * 2,
1500 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1501 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1504 TEST_P(GLES2DecoderGeometryInstancingTest,
1505 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds) {
1506 SetupIndexBuffer();
1507 DoEnableVertexAttribArray(1);
1509 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1510 DrawElementsInstancedANGLE cmd;
1511 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2, 1);
1512 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1513 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1516 TEST_P(GLES2DecoderGeometryInstancingTest,
1517 DrawElementsInstancedANGLEValidAttributesSucceeds) {
1518 SetupIndexBuffer();
1519 SetupTexture();
1520 SetupVertexBuffer();
1521 DoEnableVertexAttribArray(1);
1522 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1523 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1524 SetupExpectationsForApplyingDefaultDirtyState();
1526 EXPECT_CALL(
1527 *gl_,
1528 DrawElementsInstancedANGLE(GL_TRIANGLES,
1529 kValidIndexRangeCount,
1530 GL_UNSIGNED_SHORT,
1531 BufferOffset(kValidIndexRangeStart * 2),
1533 .Times(1)
1534 .RetiresOnSaturation();
1535 DrawElementsInstancedANGLE cmd;
1536 cmd.Init(GL_TRIANGLES,
1537 kValidIndexRangeCount,
1538 GL_UNSIGNED_SHORT,
1539 kValidIndexRangeStart * 2,
1541 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1542 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1545 TEST_P(GLES2DecoderGeometryInstancingTest,
1546 DrawElementsInstancedANGLEWithInvalidModeFails) {
1547 SetupIndexBuffer();
1548 SetupVertexBuffer();
1549 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1551 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1552 DrawElementsInstancedANGLE cmd;
1553 cmd.Init(GL_QUADS,
1554 kValidIndexRangeCount,
1555 GL_UNSIGNED_SHORT,
1556 kValidIndexRangeStart * 2,
1558 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1559 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1560 cmd.Init(GL_INVALID_ENUM,
1561 kValidIndexRangeCount,
1562 GL_UNSIGNED_SHORT,
1563 kValidIndexRangeStart * 2,
1565 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1566 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1569 // Per-instance data is twice as large, but number of instances is half
1570 TEST_P(GLES2DecoderGeometryInstancingTest,
1571 DrawElementsInstancedANGLELargeInstanceSucceeds) {
1572 SetupTexture();
1573 SetupIndexBuffer();
1574 SetupVertexBuffer();
1575 SetupExpectationsForApplyingDefaultDirtyState();
1576 // Add offset so we're sure we're accessing data near the end of the buffer.
1577 DoVertexAttribPointer(
1580 GL_FLOAT,
1582 (kNumVertices - kMaxValidIndex - 1) * 2 * sizeof(GLfloat));
1584 DoEnableVertexAttribArray(0);
1585 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1586 DoVertexAttribDivisorANGLE(0, 1);
1587 EXPECT_CALL(
1588 *gl_,
1589 DrawElementsInstancedANGLE(GL_TRIANGLES,
1590 kValidIndexRangeCount,
1591 GL_UNSIGNED_SHORT,
1592 BufferOffset(kValidIndexRangeStart * 2),
1593 kNumVertices / 2))
1594 .Times(1)
1595 .RetiresOnSaturation();
1596 DrawElementsInstancedANGLE cmd;
1597 cmd.Init(GL_TRIANGLES,
1598 kValidIndexRangeCount,
1599 GL_UNSIGNED_SHORT,
1600 kValidIndexRangeStart * 2,
1601 kNumVertices / 2);
1602 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1603 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1606 // Regular drawElements takes the divisor into account
1607 TEST_P(GLES2DecoderGeometryInstancingTest,
1608 DrawElementsWithDivisorSucceeds) {
1609 SetupTexture();
1610 SetupIndexBuffer();
1611 SetupVertexBuffer();
1612 SetupExpectationsForApplyingDefaultDirtyState();
1613 // Add offset so we're sure we're accessing data near the end of the buffer.
1614 DoVertexAttribPointer(
1617 GL_FLOAT,
1619 (kNumVertices - kMaxValidIndex - 1) * 2 * sizeof(GLfloat));
1621 DoEnableVertexAttribArray(0);
1622 // Access the data right at the end of the buffer.
1623 DoVertexAttribPointer(
1624 0, 2, GL_FLOAT, 0, (kNumVertices - 1) * 2 * sizeof(GLfloat));
1625 DoVertexAttribDivisorANGLE(0, 1);
1626 EXPECT_CALL(
1627 *gl_,
1628 DrawElements(GL_TRIANGLES,
1629 kValidIndexRangeCount,
1630 GL_UNSIGNED_SHORT,
1631 BufferOffset(kValidIndexRangeStart * 2)))
1632 .Times(1)
1633 .RetiresOnSaturation();
1634 DrawElements cmd;
1635 cmd.Init(GL_TRIANGLES,
1636 kValidIndexRangeCount,
1637 GL_UNSIGNED_SHORT,
1638 kValidIndexRangeStart * 2);
1639 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1640 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1643 // Per-instance data is twice as large, but divisor is twice
1644 TEST_P(GLES2DecoderGeometryInstancingTest,
1645 DrawElementsInstancedANGLELargeDivisorSucceeds) {
1646 SetupTexture();
1647 SetupIndexBuffer();
1648 SetupVertexBuffer();
1649 SetupExpectationsForApplyingDefaultDirtyState();
1650 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1652 DoEnableVertexAttribArray(0);
1653 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1654 DoVertexAttribDivisorANGLE(0, 2);
1655 EXPECT_CALL(
1656 *gl_,
1657 DrawElementsInstancedANGLE(GL_TRIANGLES,
1658 kValidIndexRangeCount,
1659 GL_UNSIGNED_SHORT,
1660 BufferOffset(kValidIndexRangeStart * 2),
1661 kNumVertices))
1662 .Times(1)
1663 .RetiresOnSaturation();
1664 DrawElementsInstancedANGLE cmd;
1665 cmd.Init(GL_TRIANGLES,
1666 kValidIndexRangeCount,
1667 GL_UNSIGNED_SHORT,
1668 kValidIndexRangeStart * 2,
1669 kNumVertices);
1670 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1671 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1674 TEST_P(GLES2DecoderGeometryInstancingTest,
1675 DrawElementsInstancedANGLELargeFails) {
1676 SetupTexture();
1677 SetupIndexBuffer();
1678 SetupVertexBuffer();
1679 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1681 DoEnableVertexAttribArray(0);
1682 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1683 DoVertexAttribDivisorANGLE(0, 1);
1684 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1685 .Times(0)
1686 .RetiresOnSaturation();
1687 DrawElementsInstancedANGLE cmd;
1688 cmd.Init(GL_TRIANGLES,
1689 kValidIndexRangeCount,
1690 GL_UNSIGNED_SHORT,
1691 kValidIndexRangeStart * 2,
1692 kNumVertices + 1);
1693 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1694 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1695 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1697 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1698 .Times(0)
1699 .RetiresOnSaturation();
1700 cmd.Init(GL_TRIANGLES,
1701 kInvalidIndexRangeCount,
1702 GL_UNSIGNED_SHORT,
1703 kInvalidIndexRangeStart * 2,
1704 kNumVertices);
1705 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1706 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1707 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1710 TEST_P(GLES2DecoderGeometryInstancingTest,
1711 DrawElementsInstancedANGLEInvalidPrimcountFails) {
1712 SetupTexture();
1713 SetupIndexBuffer();
1714 SetupVertexBuffer();
1715 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1717 DoEnableVertexAttribArray(0);
1718 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1719 DoVertexAttribDivisorANGLE(0, 1);
1720 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1721 .Times(0)
1722 .RetiresOnSaturation();
1723 DrawElementsInstancedANGLE cmd;
1724 cmd.Init(GL_TRIANGLES,
1725 kValidIndexRangeCount,
1726 GL_UNSIGNED_SHORT,
1727 kValidIndexRangeStart * 2,
1728 -1);
1729 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1730 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1731 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1734 // Per-index data is twice as large, but values of indices are smaller
1735 TEST_P(GLES2DecoderGeometryInstancingTest,
1736 DrawElementsInstancedANGLELargeIndexSucceeds) {
1737 SetupTexture();
1738 SetupIndexBuffer();
1739 SetupVertexBuffer();
1740 SetupExpectationsForApplyingDefaultDirtyState();
1741 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
1743 DoEnableVertexAttribArray(0);
1744 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1745 DoVertexAttribDivisorANGLE(0, 1);
1746 EXPECT_CALL(
1747 *gl_,
1748 DrawElementsInstancedANGLE(GL_TRIANGLES,
1749 kValidIndexRangeCount,
1750 GL_UNSIGNED_SHORT,
1751 BufferOffset(kValidIndexRangeStart * 2),
1752 kNumVertices))
1753 .Times(1)
1754 .RetiresOnSaturation();
1755 DrawElementsInstancedANGLE cmd;
1756 cmd.Init(GL_TRIANGLES,
1757 kValidIndexRangeCount,
1758 GL_UNSIGNED_SHORT,
1759 kValidIndexRangeStart * 2,
1760 kNumVertices);
1761 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1762 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1765 TEST_P(GLES2DecoderGeometryInstancingTest,
1766 DrawElementsInstancedANGLENoDivisor0Fails) {
1767 SetupTexture();
1768 SetupIndexBuffer();
1769 SetupVertexBuffer();
1770 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1772 DoEnableVertexAttribArray(0);
1773 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1774 DoVertexAttribDivisorANGLE(0, 1);
1775 DoVertexAttribDivisorANGLE(1, 1);
1776 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1777 .Times(0)
1778 .RetiresOnSaturation();
1779 DrawElementsInstancedANGLE cmd;
1780 cmd.Init(GL_TRIANGLES,
1781 kValidIndexRangeCount,
1782 GL_UNSIGNED_SHORT,
1783 kValidIndexRangeStart * 2,
1784 kNumVertices);
1785 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1786 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1787 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1790 TEST_P(GLES2DecoderGeometryInstancingTest,
1791 DrawElementsNoDivisor0Fails) {
1792 SetupTexture();
1793 SetupIndexBuffer();
1794 SetupVertexBuffer();
1795 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1797 DoEnableVertexAttribArray(0);
1798 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1799 DoVertexAttribDivisorANGLE(0, 1);
1800 DoVertexAttribDivisorANGLE(1, 1);
1801 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
1802 .Times(0)
1803 .RetiresOnSaturation();
1804 DrawElements cmd;
1805 cmd.Init(GL_TRIANGLES,
1806 kValidIndexRangeCount,
1807 GL_UNSIGNED_SHORT,
1808 kValidIndexRangeStart * 2);
1809 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1810 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1811 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1814 TEST_P(GLES2DecoderWithShaderTest, DrawArraysClearsAfterTexImage2DNULL) {
1815 SetupAllNeededVertexBuffers();
1816 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1817 // Create an uncleared texture with 2 levels.
1818 DoTexImage2D(
1819 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1820 DoTexImage2D(
1821 GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1822 // Expect 2 levels will be cleared.
1823 SetupClearTextureExpectations(kServiceTextureId,
1824 kServiceTextureId,
1825 GL_TEXTURE_2D,
1826 GL_TEXTURE_2D,
1828 GL_RGBA,
1829 GL_RGBA,
1830 GL_UNSIGNED_BYTE,
1833 SetupClearTextureExpectations(kServiceTextureId,
1834 kServiceTextureId,
1835 GL_TEXTURE_2D,
1836 GL_TEXTURE_2D,
1838 GL_RGBA,
1839 GL_RGBA,
1840 GL_UNSIGNED_BYTE,
1843 SetupExpectationsForApplyingDefaultDirtyState();
1844 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1845 .Times(1)
1846 .RetiresOnSaturation();
1847 DrawArrays cmd;
1848 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1849 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1850 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1852 // But not again
1853 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1854 .Times(1)
1855 .RetiresOnSaturation();
1856 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1857 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1860 TEST_P(GLES2DecoderWithShaderTest, DrawElementsClearsAfterTexImage2DNULL) {
1861 SetupAllNeededVertexBuffers();
1862 SetupIndexBuffer();
1863 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1864 // Create an uncleared texture with 2 levels.
1865 DoTexImage2D(
1866 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1867 DoTexImage2D(
1868 GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1869 // Expect 2 levels will be cleared.
1870 SetupClearTextureExpectations(kServiceTextureId,
1871 kServiceTextureId,
1872 GL_TEXTURE_2D,
1873 GL_TEXTURE_2D,
1875 GL_RGBA,
1876 GL_RGBA,
1877 GL_UNSIGNED_BYTE,
1880 SetupClearTextureExpectations(kServiceTextureId,
1881 kServiceTextureId,
1882 GL_TEXTURE_2D,
1883 GL_TEXTURE_2D,
1885 GL_RGBA,
1886 GL_RGBA,
1887 GL_UNSIGNED_BYTE,
1890 SetupExpectationsForApplyingDefaultDirtyState();
1892 EXPECT_CALL(*gl_,
1893 DrawElements(GL_TRIANGLES,
1894 kValidIndexRangeCount,
1895 GL_UNSIGNED_SHORT,
1896 BufferOffset(kValidIndexRangeStart * 2)))
1897 .Times(1)
1898 .RetiresOnSaturation();
1899 DrawElements cmd;
1900 cmd.Init(GL_TRIANGLES,
1901 kValidIndexRangeCount,
1902 GL_UNSIGNED_SHORT,
1903 kValidIndexRangeStart * 2);
1904 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1905 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1907 // But not again
1908 EXPECT_CALL(*gl_,
1909 DrawElements(GL_TRIANGLES,
1910 kValidIndexRangeCount,
1911 GL_UNSIGNED_SHORT,
1912 BufferOffset(kValidIndexRangeStart * 2)))
1913 .Times(1)
1914 .RetiresOnSaturation();
1915 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1916 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1919 TEST_P(GLES2DecoderWithShaderTest, DrawClearsAfterTexImage2DNULLInFBO) {
1920 const GLuint kFBOClientTextureId = 4100;
1921 const GLuint kFBOServiceTextureId = 4101;
1923 SetupAllNeededVertexBuffers();
1924 // Register a texture id.
1925 EXPECT_CALL(*gl_, GenTextures(_, _))
1926 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1927 .RetiresOnSaturation();
1928 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1930 // Setup "render to" texture.
1931 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1932 DoTexImage2D(
1933 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1934 DoBindFramebuffer(
1935 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1936 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1937 GL_COLOR_ATTACHMENT0,
1938 GL_TEXTURE_2D,
1939 kFBOClientTextureId,
1940 kFBOServiceTextureId,
1942 GL_NO_ERROR);
1944 // Setup "render from" texture.
1945 SetupTexture();
1947 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1948 GL_COLOR_BUFFER_BIT, // clear bits
1952 0, // color
1953 0, // stencil
1954 1.0f, // depth
1955 false); // scissor test
1957 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1958 false, // Framebuffer has depth
1959 false, // Framebuffer has stencil
1960 0x1111, // color bits
1961 false, // depth mask
1962 false, // depth enabled
1963 0, // front stencil mask
1964 0, // back stencil mask
1965 false); // stencil enabled
1967 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1968 .Times(1)
1969 .RetiresOnSaturation();
1970 DrawArrays cmd;
1971 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1972 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1973 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1975 // But not again.
1976 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1977 .Times(1)
1978 .RetiresOnSaturation();
1979 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1980 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1983 TEST_P(GLES2DecoderWithShaderTest, DrawWitFBOThatCantClearDoesNotDraw) {
1984 const GLuint kFBOClientTextureId = 4100;
1985 const GLuint kFBOServiceTextureId = 4101;
1987 // Register a texture id.
1988 EXPECT_CALL(*gl_, GenTextures(_, _))
1989 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1990 .RetiresOnSaturation();
1991 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1993 // Setup "render to" texture.
1994 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1995 DoTexImage2D(
1996 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1997 DoBindFramebuffer(
1998 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1999 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2000 GL_COLOR_ATTACHMENT0,
2001 GL_TEXTURE_2D,
2002 kFBOClientTextureId,
2003 kFBOServiceTextureId,
2005 GL_NO_ERROR);
2007 // Setup "render from" texture.
2008 SetupTexture();
2010 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
2011 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED))
2012 .RetiresOnSaturation();
2013 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
2014 DrawArrays cmd;
2015 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2016 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2017 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
2020 TEST_P(GLES2DecoderWithShaderTest, DrawClearsAfterRenderbufferStorageInFBO) {
2021 SetupTexture();
2022 DoBindRenderbuffer(
2023 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
2024 DoBindFramebuffer(
2025 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2026 DoRenderbufferStorage(
2027 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 100, 50, GL_NO_ERROR);
2028 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
2029 GL_COLOR_ATTACHMENT0,
2030 GL_RENDERBUFFER,
2031 client_renderbuffer_id_,
2032 kServiceRenderbufferId,
2033 GL_NO_ERROR);
2035 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
2036 GL_COLOR_BUFFER_BIT, // clear bits
2040 0, // color
2041 0, // stencil
2042 1.0f, // depth
2043 false); // scissor test
2045 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2046 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2047 false, // Framebuffer has depth
2048 false, // Framebuffer has stencil
2049 0x1111, // color bits
2050 false, // depth mask
2051 false, // depth enabled
2052 0, // front stencil mask
2053 0, // back stencil mask
2054 false); // stencil enabled
2056 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2057 .Times(1)
2058 .RetiresOnSaturation();
2059 DrawArrays cmd;
2060 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2061 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2062 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2065 TEST_P(GLES2DecoderManualInitTest, DrawArraysClearsAfterTexImage2DNULLCubemap) {
2066 InitState init;
2067 init.gl_version = "opengl es 2.0";
2068 init.has_alpha = true;
2069 init.has_depth = true;
2070 init.request_alpha = true;
2071 init.request_depth = true;
2072 InitDecoder(init);
2074 static const GLenum faces[] = {
2075 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
2076 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2077 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
2079 SetupCubemapProgram();
2080 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2081 // Fill out all the faces for 2 levels, leave 2 uncleared.
2082 for (int ii = 0; ii < 6; ++ii) {
2083 GLenum face = faces[ii];
2084 int32 shm_id =
2085 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryId;
2086 uint32 shm_offset =
2087 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryOffset;
2088 DoTexImage2D(face,
2090 GL_RGBA,
2094 GL_RGBA,
2095 GL_UNSIGNED_BYTE,
2096 shm_id,
2097 shm_offset);
2098 DoTexImage2D(face,
2100 GL_RGBA,
2104 GL_RGBA,
2105 GL_UNSIGNED_BYTE,
2106 shm_id,
2107 shm_offset);
2109 // Expect 2 levels will be cleared.
2110 SetupClearTextureExpectations(kServiceTextureId,
2111 kServiceTextureId,
2112 GL_TEXTURE_CUBE_MAP,
2113 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2115 GL_RGBA,
2116 GL_RGBA,
2117 GL_UNSIGNED_BYTE,
2120 SetupClearTextureExpectations(kServiceTextureId,
2121 kServiceTextureId,
2122 GL_TEXTURE_CUBE_MAP,
2123 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2125 GL_RGBA,
2126 GL_RGBA,
2127 GL_UNSIGNED_BYTE,
2130 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2131 SetupExpectationsForApplyingDefaultDirtyState();
2132 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2133 .Times(1)
2134 .RetiresOnSaturation();
2135 DrawArrays cmd;
2136 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2137 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2140 TEST_P(GLES2DecoderWithShaderTest,
2141 DrawClearsAfterRenderbuffersWithMultipleAttachments) {
2142 const GLuint kFBOClientTextureId = 4100;
2143 const GLuint kFBOServiceTextureId = 4101;
2145 // Register a texture id.
2146 EXPECT_CALL(*gl_, GenTextures(_, _))
2147 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2148 .RetiresOnSaturation();
2149 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2151 // Setup "render to" texture.
2152 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2153 DoTexImage2D(
2154 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2155 DoBindFramebuffer(
2156 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2157 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2158 GL_COLOR_ATTACHMENT0,
2159 GL_TEXTURE_2D,
2160 kFBOClientTextureId,
2161 kFBOServiceTextureId,
2163 GL_NO_ERROR);
2165 DoBindRenderbuffer(
2166 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
2167 DoBindFramebuffer(
2168 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2169 DoRenderbufferStorage(GL_RENDERBUFFER,
2170 GL_DEPTH_COMPONENT16,
2171 GL_DEPTH_COMPONENT,
2174 GL_NO_ERROR);
2175 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
2176 GL_DEPTH_ATTACHMENT,
2177 GL_RENDERBUFFER,
2178 client_renderbuffer_id_,
2179 kServiceRenderbufferId,
2180 GL_NO_ERROR);
2182 SetupTexture();
2183 SetupExpectationsForFramebufferClearing(
2184 GL_FRAMEBUFFER, // target
2185 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, // clear bits
2189 0, // color
2190 0, // stencil
2191 1.0f, // depth
2192 false); // scissor test
2194 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2195 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2196 true, // Framebuffer has depth
2197 false, // Framebuffer has stencil
2198 0x1111, // color bits
2199 true, // depth mask
2200 false, // depth enabled
2201 0, // front stencil mask
2202 0, // back stencil mask
2203 false); // stencil enabled
2205 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2206 .Times(1)
2207 .RetiresOnSaturation();
2208 DrawArrays cmd;
2209 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2210 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2211 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2214 TEST_P(GLES2DecoderWithShaderTest,
2215 DrawingWithFBOTwiceChecksForFBOCompleteOnce) {
2216 const GLuint kFBOClientTextureId = 4100;
2217 const GLuint kFBOServiceTextureId = 4101;
2219 SetupAllNeededVertexBuffers();
2221 // Register a texture id.
2222 EXPECT_CALL(*gl_, GenTextures(_, _))
2223 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2224 .RetiresOnSaturation();
2225 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2227 // Setup "render to" texture that is cleared.
2228 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2229 DoTexImage2D(GL_TEXTURE_2D,
2231 GL_RGBA,
2235 GL_RGBA,
2236 GL_UNSIGNED_BYTE,
2237 kSharedMemoryId,
2238 kSharedMemoryOffset);
2239 DoBindFramebuffer(
2240 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2241 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2242 GL_COLOR_ATTACHMENT0,
2243 GL_TEXTURE_2D,
2244 kFBOClientTextureId,
2245 kFBOServiceTextureId,
2247 GL_NO_ERROR);
2249 // Setup "render from" texture.
2250 SetupTexture();
2252 // Make sure we check for framebuffer complete.
2253 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
2254 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
2255 .RetiresOnSaturation();
2257 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2258 false, // Framebuffer has depth
2259 false, // Framebuffer has stencil
2260 0x1111, // color bits
2261 false, // depth mask
2262 false, // depth enabled
2263 0, // front stencil mask
2264 0, // back stencil mask
2265 false); // stencil enabled
2267 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2268 .Times(1)
2269 .RetiresOnSaturation();
2270 DrawArrays cmd;
2271 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2272 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2273 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2275 // But not again.
2276 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2277 .Times(1)
2278 .RetiresOnSaturation();
2279 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2280 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2283 TEST_P(GLES2DecoderManualInitTest, DrawClearsDepthTexture) {
2284 InitState init;
2285 init.extensions = "GL_ANGLE_depth_texture";
2286 init.gl_version = "opengl es 2.0";
2287 init.has_alpha = true;
2288 init.has_depth = true;
2289 init.request_alpha = true;
2290 init.request_depth = true;
2291 init.bind_generates_resource = true;
2292 InitDecoder(init);
2294 SetupDefaultProgram();
2295 SetupAllNeededVertexBuffers();
2296 const GLenum attachment = GL_DEPTH_ATTACHMENT;
2297 const GLenum target = GL_TEXTURE_2D;
2298 const GLint level = 0;
2299 DoBindTexture(target, client_texture_id_, kServiceTextureId);
2301 // Create a depth texture.
2302 DoTexImage2D(target,
2303 level,
2304 GL_DEPTH_COMPONENT,
2308 GL_DEPTH_COMPONENT,
2309 GL_UNSIGNED_INT,
2313 // Enable GL_SCISSOR_TEST to make sure we disable it in the clear,
2314 // then re-enable it.
2315 DoEnableDisable(GL_SCISSOR_TEST, true);
2317 EXPECT_CALL(*gl_, GenFramebuffersEXT(1, _)).Times(1).RetiresOnSaturation();
2318 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, _))
2319 .Times(1)
2320 .RetiresOnSaturation();
2322 EXPECT_CALL(*gl_,
2323 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT,
2324 attachment,
2325 target,
2326 kServiceTextureId,
2327 level))
2328 .Times(1)
2329 .RetiresOnSaturation();
2330 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT))
2331 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
2332 .RetiresOnSaturation();
2334 EXPECT_CALL(*gl_, ClearStencil(0)).Times(1).RetiresOnSaturation();
2335 SetupExpectationsForStencilMask(GLES2Decoder::kDefaultStencilMask,
2336 GLES2Decoder::kDefaultStencilMask);
2337 EXPECT_CALL(*gl_, ClearDepth(1.0f)).Times(1).RetiresOnSaturation();
2338 SetupExpectationsForDepthMask(true);
2339 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, false);
2341 EXPECT_CALL(*gl_, Clear(GL_DEPTH_BUFFER_BIT)).Times(1).RetiresOnSaturation();
2343 SetupExpectationsForRestoreClearState(0.0f, 0.0f, 0.0f, 0.0f, 0, 1.0f, true);
2345 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, _)).Times(1).RetiresOnSaturation();
2346 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0))
2347 .Times(1)
2348 .RetiresOnSaturation();
2350 SetupExpectationsForApplyingDefaultDirtyState();
2351 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2352 .Times(1)
2353 .RetiresOnSaturation();
2354 DrawArrays cmd;
2355 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2356 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2357 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2360 } // namespace gles2
2361 } // namespace gpu