Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_drawing.cc
blob3c5b72af9aa6c86e2c13aee48e4aef3e5597185b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/common/id_allocator.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
14 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
15 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
16 #include "gpu/command_buffer/service/context_group.h"
17 #include "gpu/command_buffer/service/context_state.h"
18 #include "gpu/command_buffer/service/gl_surface_mock.h"
19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
21 #include "gpu/command_buffer/service/gpu_switches.h"
22 #include "gpu/command_buffer/service/image_manager.h"
23 #include "gpu/command_buffer/service/mailbox_manager.h"
24 #include "gpu/command_buffer/service/mocks.h"
25 #include "gpu/command_buffer/service/program_manager.h"
26 #include "gpu/command_buffer/service/test_helper.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gl/gl_implementation.h"
29 #include "ui/gl/gl_mock.h"
30 #include "ui/gl/gl_surface_stub.h"
32 #if !defined(GL_DEPTH24_STENCIL8)
33 #define GL_DEPTH24_STENCIL8 0x88F0
34 #endif
36 using ::gfx::MockGLInterface;
37 using ::testing::_;
38 using ::testing::DoAll;
39 using ::testing::InSequence;
40 using ::testing::Invoke;
41 using ::testing::MatcherCast;
42 using ::testing::Mock;
43 using ::testing::Pointee;
44 using ::testing::Return;
45 using ::testing::SaveArg;
46 using ::testing::SetArrayArgument;
47 using ::testing::SetArgumentPointee;
48 using ::testing::SetArgPointee;
49 using ::testing::StrEq;
50 using ::testing::StrictMock;
52 namespace gpu {
53 namespace gles2 {
55 using namespace cmds;
57 class GLES2DecoderGeometryInstancingTest : public GLES2DecoderWithShaderTest {
58 public:
59 GLES2DecoderGeometryInstancingTest() : GLES2DecoderWithShaderTest() {}
61 virtual void SetUp() {
62 InitState init;
63 init.extensions = "GL_ANGLE_instanced_arrays";
64 init.gl_version = "opengl es 2.0";
65 init.has_alpha = true;
66 init.has_depth = true;
67 init.request_alpha = true;
68 init.request_depth = true;
69 init.bind_generates_resource = true;
70 InitDecoder(init);
71 SetupDefaultProgram();
75 INSTANTIATE_TEST_CASE_P(Service,
76 GLES2DecoderGeometryInstancingTest,
77 ::testing::Bool());
79 void GLES2DecoderManualInitTest::DirtyStateMaskTest(GLuint color_bits,
80 bool depth_mask,
81 GLuint front_stencil_mask,
82 GLuint back_stencil_mask) {
83 ColorMask color_mask_cmd;
84 color_mask_cmd.Init((color_bits & 0x1000) != 0,
85 (color_bits & 0x0100) != 0,
86 (color_bits & 0x0010) != 0,
87 (color_bits & 0x0001) != 0);
88 EXPECT_EQ(error::kNoError, ExecuteCmd(color_mask_cmd));
89 EXPECT_EQ(GL_NO_ERROR, GetGLError());
91 DepthMask depth_mask_cmd;
92 depth_mask_cmd.Init(depth_mask);
93 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_mask_cmd));
94 EXPECT_EQ(GL_NO_ERROR, GetGLError());
96 StencilMaskSeparate front_stencil_mask_cmd;
97 front_stencil_mask_cmd.Init(GL_FRONT, front_stencil_mask);
98 EXPECT_EQ(error::kNoError, ExecuteCmd(front_stencil_mask_cmd));
99 EXPECT_EQ(GL_NO_ERROR, GetGLError());
101 StencilMaskSeparate back_stencil_mask_cmd;
102 back_stencil_mask_cmd.Init(GL_BACK, back_stencil_mask);
103 EXPECT_EQ(error::kNoError, ExecuteCmd(back_stencil_mask_cmd));
104 EXPECT_EQ(GL_NO_ERROR, GetGLError());
106 SetupExpectationsForApplyingDirtyState(
107 false, // Framebuffer is RGB
108 true, // Framebuffer has depth
109 true, // Framebuffer has stencil
110 color_bits, // color bits
111 depth_mask, // depth mask
112 false, // depth enabled
113 front_stencil_mask, // front stencil mask
114 back_stencil_mask, // back stencil mask
115 false); // stencil enabled
117 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
118 .Times(1)
119 .RetiresOnSaturation();
120 DrawArrays draw_cmd;
121 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
122 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
123 EXPECT_EQ(GL_NO_ERROR, GetGLError());
126 // Test that with an RGB backbuffer if we set the color mask to 1,1,1,1 it is
127 // set to 1,1,1,0 at Draw time but is 1,1,1,1 at query time.
128 TEST_P(GLES2DecoderRGBBackbufferTest, RGBBackbufferColorMask) {
129 ColorMask cmd;
130 cmd.Init(true, true, true, true);
131 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
132 EXPECT_EQ(GL_NO_ERROR, GetGLError());
134 SetupTexture();
135 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
136 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
137 false, // Framebuffer has depth
138 false, // Framebuffer has stencil
139 0x1110, // color bits
140 false, // depth mask
141 false, // depth enabled
142 0, // front stencil mask
143 0, // back stencil mask
144 false); // stencil enabled
146 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
147 .Times(1)
148 .RetiresOnSaturation();
149 DrawArrays draw_cmd;
150 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
151 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
152 EXPECT_EQ(GL_NO_ERROR, GetGLError());
154 EXPECT_CALL(*gl_, GetError())
155 .WillOnce(Return(GL_NO_ERROR))
156 .WillOnce(Return(GL_NO_ERROR))
157 .RetiresOnSaturation();
158 typedef GetIntegerv::Result Result;
159 Result* result = static_cast<Result*>(shared_memory_address_);
160 EXPECT_CALL(*gl_, GetIntegerv(GL_COLOR_WRITEMASK, result->GetData()))
161 .Times(0);
162 result->size = 0;
163 GetIntegerv cmd2;
164 cmd2.Init(GL_COLOR_WRITEMASK, shared_memory_id_, shared_memory_offset_);
165 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
166 EXPECT_EQ(
167 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_COLOR_WRITEMASK),
168 result->GetNumResults());
169 EXPECT_EQ(GL_NO_ERROR, GetGLError());
170 EXPECT_EQ(1, result->GetData()[0]);
171 EXPECT_EQ(1, result->GetData()[1]);
172 EXPECT_EQ(1, result->GetData()[2]);
173 EXPECT_EQ(1, result->GetData()[3]);
176 // Test that with no depth if we set DepthMask true that it's set to false at
177 // draw time but querying it returns true.
178 TEST_P(GLES2DecoderRGBBackbufferTest, RGBBackbufferDepthMask) {
179 EXPECT_CALL(*gl_, DepthMask(true)).Times(0).RetiresOnSaturation();
180 DepthMask cmd;
181 cmd.Init(true);
182 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
183 EXPECT_EQ(GL_NO_ERROR, GetGLError());
185 SetupTexture();
186 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
187 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
188 false, // Framebuffer has depth
189 false, // Framebuffer has stencil
190 0x1110, // color bits
191 false, // depth mask
192 false, // depth enabled
193 0, // front stencil mask
194 0, // back stencil mask
195 false); // stencil enabled
197 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
198 .Times(1)
199 .RetiresOnSaturation();
200 DrawArrays draw_cmd;
201 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
202 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
203 EXPECT_EQ(GL_NO_ERROR, GetGLError());
205 EXPECT_CALL(*gl_, GetError())
206 .WillOnce(Return(GL_NO_ERROR))
207 .WillOnce(Return(GL_NO_ERROR))
208 .RetiresOnSaturation();
209 typedef GetIntegerv::Result Result;
210 Result* result = static_cast<Result*>(shared_memory_address_);
211 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_WRITEMASK, result->GetData()))
212 .Times(0);
213 result->size = 0;
214 GetIntegerv cmd2;
215 cmd2.Init(GL_DEPTH_WRITEMASK, shared_memory_id_, shared_memory_offset_);
216 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
217 EXPECT_EQ(
218 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_WRITEMASK),
219 result->GetNumResults());
220 EXPECT_EQ(GL_NO_ERROR, GetGLError());
221 EXPECT_EQ(1, result->GetData()[0]);
224 // Test that with no stencil if we set the stencil mask it's still set to 0 at
225 // draw time but gets our value if we query.
226 TEST_P(GLES2DecoderRGBBackbufferTest, RGBBackbufferStencilMask) {
227 const GLint kMask = 123;
228 EXPECT_CALL(*gl_, StencilMask(kMask)).Times(0).RetiresOnSaturation();
229 StencilMask cmd;
230 cmd.Init(kMask);
231 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
232 EXPECT_EQ(GL_NO_ERROR, GetGLError());
234 SetupTexture();
235 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
236 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
237 false, // Framebuffer has depth
238 false, // Framebuffer has stencil
239 0x1110, // color bits
240 false, // depth mask
241 false, // depth enabled
242 0, // front stencil mask
243 0, // back stencil mask
244 false); // stencil enabled
246 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
247 .Times(1)
248 .RetiresOnSaturation();
249 DrawArrays draw_cmd;
250 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
251 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
252 EXPECT_EQ(GL_NO_ERROR, GetGLError());
254 EXPECT_CALL(*gl_, GetError())
255 .WillOnce(Return(GL_NO_ERROR))
256 .WillOnce(Return(GL_NO_ERROR))
257 .RetiresOnSaturation();
258 typedef GetIntegerv::Result Result;
259 Result* result = static_cast<Result*>(shared_memory_address_);
260 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_WRITEMASK, result->GetData()))
261 .Times(0);
262 result->size = 0;
263 GetIntegerv cmd2;
264 cmd2.Init(GL_STENCIL_WRITEMASK, shared_memory_id_, shared_memory_offset_);
265 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
266 EXPECT_EQ(
267 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_WRITEMASK),
268 result->GetNumResults());
269 EXPECT_EQ(GL_NO_ERROR, GetGLError());
270 EXPECT_EQ(kMask, result->GetData()[0]);
273 // Test that if an FBO is bound we get the correct masks.
274 TEST_P(GLES2DecoderRGBBackbufferTest, RGBBackbufferColorMaskFBO) {
275 ColorMask cmd;
276 cmd.Init(true, true, true, true);
277 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
278 EXPECT_EQ(GL_NO_ERROR, GetGLError());
280 SetupTexture();
281 SetupVertexBuffer();
282 DoEnableVertexAttribArray(0);
283 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
284 DoEnableVertexAttribArray(1);
285 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
286 DoEnableVertexAttribArray(2);
287 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
288 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
289 false, // Framebuffer has depth
290 false, // Framebuffer has stencil
291 0x1110, // color bits
292 false, // depth mask
293 false, // depth enabled
294 0, // front stencil mask
295 0, // back stencil mask
296 false); // stencil enabled
298 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
299 .Times(1)
300 .RetiresOnSaturation();
301 DrawArrays draw_cmd;
302 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
303 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
304 EXPECT_EQ(GL_NO_ERROR, GetGLError());
306 // Check that no extra calls are made on the next draw.
307 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
308 .Times(1)
309 .RetiresOnSaturation();
310 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
311 EXPECT_EQ(GL_NO_ERROR, GetGLError());
313 // Setup Frame buffer.
314 // needs to be 1x1 or else it's not renderable.
315 const GLsizei kWidth = 1;
316 const GLsizei kHeight = 1;
317 const GLenum kFormat = GL_RGB;
318 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
319 // Pass some data so the texture will be marked as cleared.
320 DoTexImage2D(GL_TEXTURE_2D,
322 kFormat,
323 kWidth,
324 kHeight,
326 kFormat,
327 GL_UNSIGNED_BYTE,
328 kSharedMemoryId,
329 kSharedMemoryOffset);
330 DoBindFramebuffer(
331 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
332 DoFramebufferTexture2D(GL_FRAMEBUFFER,
333 GL_COLOR_ATTACHMENT0,
334 GL_TEXTURE_2D,
335 client_texture_id_,
336 kServiceTextureId,
338 GL_NO_ERROR);
339 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
340 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
341 .RetiresOnSaturation();
343 // This time state needs to be set.
344 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
345 false, // Framebuffer has depth
346 false, // Framebuffer has stencil
347 0x1110, // color bits
348 false, // depth mask
349 false, // depth enabled
350 0, // front stencil mask
351 0, // back stencil mask
352 false); // stencil enabled
354 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
355 .Times(1)
356 .RetiresOnSaturation();
357 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
358 EXPECT_EQ(GL_NO_ERROR, GetGLError());
360 // Check that no extra calls are made on the next draw.
361 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
362 .Times(1)
363 .RetiresOnSaturation();
364 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
365 EXPECT_EQ(GL_NO_ERROR, GetGLError());
367 // Unbind
368 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
370 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
371 false, // Framebuffer has depth
372 false, // Framebuffer has stencil
373 0x1110, // color bits
374 false, // depth mask
375 false, // depth enabled
376 0, // front stencil mask
377 0, // back stencil mask
378 false); // stencil enabled
380 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
381 .Times(1)
382 .RetiresOnSaturation();
383 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
384 EXPECT_EQ(GL_NO_ERROR, GetGLError());
387 TEST_P(GLES2DecoderManualInitTest, DepthEnableWithDepth) {
388 InitState init;
389 init.gl_version = "3.0";
390 init.has_depth = true;
391 init.request_depth = true;
392 init.bind_generates_resource = true;
393 InitDecoder(init);
395 Enable cmd;
396 cmd.Init(GL_DEPTH_TEST);
397 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
398 EXPECT_EQ(GL_NO_ERROR, GetGLError());
400 SetupDefaultProgram();
401 SetupTexture();
402 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
403 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
404 true, // Framebuffer has depth
405 false, // Framebuffer has stencil
406 0x1110, // color bits
407 true, // depth mask
408 true, // depth enabled
409 0, // front stencil mask
410 0, // back stencil mask
411 false); // stencil enabled
413 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
414 .Times(1)
415 .RetiresOnSaturation();
416 DrawArrays draw_cmd;
417 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
418 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
419 EXPECT_EQ(GL_NO_ERROR, GetGLError());
421 EXPECT_CALL(*gl_, GetError())
422 .WillOnce(Return(GL_NO_ERROR))
423 .WillOnce(Return(GL_NO_ERROR))
424 .RetiresOnSaturation();
425 typedef GetIntegerv::Result Result;
426 Result* result = static_cast<Result*>(shared_memory_address_);
427 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_TEST, _))
428 .Times(0)
429 .RetiresOnSaturation();
430 result->size = 0;
431 GetIntegerv cmd2;
432 cmd2.Init(GL_DEPTH_TEST, shared_memory_id_, shared_memory_offset_);
433 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
434 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST),
435 result->GetNumResults());
436 EXPECT_EQ(GL_NO_ERROR, GetGLError());
437 EXPECT_EQ(1, result->GetData()[0]);
440 TEST_P(GLES2DecoderManualInitTest, DepthEnableWithoutRequestedDepth) {
441 InitState init;
442 init.gl_version = "3.0";
443 init.has_depth = true;
444 init.bind_generates_resource = true;
445 InitDecoder(init);
447 Enable cmd;
448 cmd.Init(GL_DEPTH_TEST);
449 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
450 EXPECT_EQ(GL_NO_ERROR, GetGLError());
452 SetupDefaultProgram();
453 SetupTexture();
454 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
455 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
456 false, // Framebuffer has depth
457 false, // Framebuffer has stencil
458 0x1110, // color bits
459 false, // depth mask
460 false, // depth enabled
461 0, // front stencil mask
462 0, // back stencil mask
463 false); // stencil enabled
465 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
466 .Times(1)
467 .RetiresOnSaturation();
468 DrawArrays draw_cmd;
469 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
470 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
471 EXPECT_EQ(GL_NO_ERROR, GetGLError());
473 EXPECT_CALL(*gl_, GetError())
474 .WillOnce(Return(GL_NO_ERROR))
475 .WillOnce(Return(GL_NO_ERROR))
476 .RetiresOnSaturation();
477 typedef GetIntegerv::Result Result;
478 Result* result = static_cast<Result*>(shared_memory_address_);
479 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_TEST, _))
480 .Times(0)
481 .RetiresOnSaturation();
482 result->size = 0;
483 GetIntegerv cmd2;
484 cmd2.Init(GL_DEPTH_TEST, shared_memory_id_, shared_memory_offset_);
485 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
486 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST),
487 result->GetNumResults());
488 EXPECT_EQ(GL_NO_ERROR, GetGLError());
489 EXPECT_EQ(1, result->GetData()[0]);
492 TEST_P(GLES2DecoderManualInitTest, StencilEnableWithStencil) {
493 InitState init;
494 init.gl_version = "3.0";
495 init.has_stencil = true;
496 init.request_stencil = true;
497 init.bind_generates_resource = true;
498 InitDecoder(init);
500 Enable cmd;
501 cmd.Init(GL_STENCIL_TEST);
502 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
503 EXPECT_EQ(GL_NO_ERROR, GetGLError());
505 SetupDefaultProgram();
506 SetupTexture();
507 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
508 SetupExpectationsForApplyingDirtyState(
509 true, // Framebuffer is RGB
510 false, // Framebuffer has depth
511 true, // Framebuffer has stencil
512 0x1110, // color bits
513 false, // depth mask
514 false, // depth enabled
515 GLES2Decoder::kDefaultStencilMask, // front stencil mask
516 GLES2Decoder::kDefaultStencilMask, // back stencil mask
517 true); // stencil enabled
519 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
520 .Times(1)
521 .RetiresOnSaturation();
522 DrawArrays draw_cmd;
523 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
524 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
525 EXPECT_EQ(GL_NO_ERROR, GetGLError());
527 EXPECT_CALL(*gl_, GetError())
528 .WillOnce(Return(GL_NO_ERROR))
529 .WillOnce(Return(GL_NO_ERROR))
530 .RetiresOnSaturation();
531 typedef GetIntegerv::Result Result;
532 Result* result = static_cast<Result*>(shared_memory_address_);
533 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_TEST, _))
534 .Times(0)
535 .RetiresOnSaturation();
536 result->size = 0;
537 GetIntegerv cmd2;
538 cmd2.Init(GL_STENCIL_TEST, shared_memory_id_, shared_memory_offset_);
539 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
540 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST),
541 result->GetNumResults());
542 EXPECT_EQ(GL_NO_ERROR, GetGLError());
543 EXPECT_EQ(1, result->GetData()[0]);
546 TEST_P(GLES2DecoderManualInitTest, StencilEnableWithoutRequestedStencil) {
547 InitState init;
548 init.gl_version = "3.0";
549 init.has_stencil = true;
550 init.bind_generates_resource = true;
551 InitDecoder(init);
553 Enable cmd;
554 cmd.Init(GL_STENCIL_TEST);
555 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
556 EXPECT_EQ(GL_NO_ERROR, GetGLError());
558 SetupDefaultProgram();
559 SetupTexture();
560 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
561 SetupExpectationsForApplyingDirtyState(true, // Framebuffer is RGB
562 false, // Framebuffer has depth
563 false, // Framebuffer has stencil
564 0x1110, // color bits
565 false, // depth mask
566 false, // depth enabled
567 0, // front stencil mask
568 0, // back stencil mask
569 false); // stencil enabled
571 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
572 .Times(1)
573 .RetiresOnSaturation();
574 DrawArrays draw_cmd;
575 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
576 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
577 EXPECT_EQ(GL_NO_ERROR, GetGLError());
579 EXPECT_CALL(*gl_, GetError())
580 .WillOnce(Return(GL_NO_ERROR))
581 .WillOnce(Return(GL_NO_ERROR))
582 .RetiresOnSaturation();
583 typedef GetIntegerv::Result Result;
584 Result* result = static_cast<Result*>(shared_memory_address_);
585 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_TEST, _))
586 .Times(0)
587 .RetiresOnSaturation();
588 result->size = 0;
589 GetIntegerv cmd2;
590 cmd2.Init(GL_STENCIL_TEST, shared_memory_id_, shared_memory_offset_);
591 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
592 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST),
593 result->GetNumResults());
594 EXPECT_EQ(GL_NO_ERROR, GetGLError());
595 EXPECT_EQ(1, result->GetData()[0]);
598 TEST_P(GLES2DecoderManualInitTest, CachedColorMask) {
599 InitState init;
600 init.gl_version = "3.0";
601 init.has_alpha = true;
602 init.has_depth = true;
603 init.has_stencil = true;
604 init.request_alpha = true;
605 init.request_depth = true;
606 init.request_stencil = true;
607 init.bind_generates_resource = true;
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.gl_version = "3.0";
629 init.has_alpha = true;
630 init.has_depth = true;
631 init.has_stencil = true;
632 init.request_alpha = true;
633 init.request_depth = true;
634 init.request_stencil = true;
635 init.bind_generates_resource = true;
636 InitDecoder(init);
638 SetupDefaultProgram();
639 SetupAllNeededVertexBuffers();
640 SetupTexture();
642 // Test all depth_mask combinations twice.
643 for (int i = 0; i < 4; i++) {
644 bool depth_mask = (i & 1) == 1;
646 // Toggle color masks to force ApplyDirtyState each time.
647 DirtyStateMaskTest(0x1010, depth_mask, 0xffffffff, 0xffffffff);
648 DirtyStateMaskTest(0x0101, depth_mask, 0xffffffff, 0xffffffff);
649 DirtyStateMaskTest(0x1010, depth_mask, 0xffffffff, 0xffffffff);
653 TEST_P(GLES2DecoderManualInitTest, CachedStencilMask) {
654 InitState init;
655 init.gl_version = "3.0";
656 init.has_alpha = true;
657 init.has_depth = true;
658 init.has_stencil = true;
659 init.request_alpha = true;
660 init.request_depth = true;
661 init.request_stencil = true;
662 init.bind_generates_resource = true;
663 InitDecoder(init);
665 SetupDefaultProgram();
666 SetupAllNeededVertexBuffers();
667 SetupTexture();
669 // Test all stencil_mask combinations twice.
670 for (int i = 0; i < 4; i++) {
671 GLuint stencil_mask = (i & 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
673 // Toggle color masks to force ApplyDirtyState each time.
674 DirtyStateMaskTest(0x1010, true, stencil_mask, 0xffffffff);
675 DirtyStateMaskTest(0x0101, true, stencil_mask, 0xffffffff);
676 DirtyStateMaskTest(0x1010, true, stencil_mask, 0xffffffff);
679 for (int i = 0; i < 4; i++) {
680 GLuint stencil_mask = (i & 1) ? 0xf0f0f0f0 : 0x0f0f0f0f;
682 // Toggle color masks to force ApplyDirtyState each time.
683 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask);
684 DirtyStateMaskTest(0x0101, true, 0xffffffff, stencil_mask);
685 DirtyStateMaskTest(0x1010, true, 0xffffffff, stencil_mask);
689 TEST_P(GLES2DecoderWithShaderTest, DrawArraysNoAttributesSucceeds) {
690 SetupTexture();
691 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
692 SetupExpectationsForApplyingDefaultDirtyState();
694 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
695 .Times(1)
696 .RetiresOnSaturation();
697 DrawArrays cmd;
698 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
699 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
700 EXPECT_EQ(GL_NO_ERROR, GetGLError());
703 // Tests when the math overflows (0x40000000 * sizeof GLfloat)
704 TEST_P(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OverflowFails) {
705 const GLsizei kLargeCount = 0x40000000;
706 SetupTexture();
707 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
708 DrawArrays cmd;
709 cmd.Init(GL_TRIANGLES, 0, kLargeCount);
710 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
711 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
712 EXPECT_FALSE(GetDecoder()->WasContextLost());
715 // Tests when the math overflows (0x7FFFFFFF + 1 = 0x8000000 verts)
716 TEST_P(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0PosToNegFails) {
717 const GLsizei kLargeCount = 0x7FFFFFFF;
718 SetupTexture();
719 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
720 DrawArrays cmd;
721 cmd.Init(GL_TRIANGLES, 0, kLargeCount);
722 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
723 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
724 EXPECT_FALSE(GetDecoder()->WasContextLost());
727 // Tests when the driver returns an error
728 TEST_P(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OOMFails) {
729 const GLsizei kFakeLargeCount = 0x1234;
730 SetupTexture();
731 AddExpectationsForSimulatedAttrib0WithError(
732 kFakeLargeCount, 0, GL_OUT_OF_MEMORY);
733 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
734 DrawArrays cmd;
735 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount);
736 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
737 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
738 EXPECT_FALSE(GetDecoder()->WasContextLost());
741 // Test that we lose context.
742 TEST_P(GLES2DecoderManualInitTest, LoseContextWhenOOM) {
743 InitState init;
744 init.gl_version = "3.0";
745 init.has_alpha = true;
746 init.has_depth = true;
747 init.request_alpha = true;
748 init.request_depth = true;
749 init.bind_generates_resource = true;
750 init.lose_context_when_out_of_memory = true;
751 InitDecoder(init);
752 SetupDefaultProgram();
754 const GLsizei kFakeLargeCount = 0x1234;
755 SetupTexture();
756 AddExpectationsForSimulatedAttrib0WithError(
757 kFakeLargeCount, 0, GL_OUT_OF_MEMORY);
758 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
759 // Other contexts in the group should be lost also.
760 EXPECT_CALL(*mock_decoder_, LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB))
761 .Times(1)
762 .RetiresOnSaturation();
763 DrawArrays cmd;
764 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount);
765 // This context should be lost.
766 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd));
767 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
768 EXPECT_TRUE(decoder_->WasContextLost());
771 TEST_P(GLES2DecoderWithShaderTest, DrawArraysBadTextureUsesBlack) {
772 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
773 // This is an NPOT texture. As the default filtering requires mips
774 // this should trigger replacing with black textures before rendering.
775 DoTexImage2D(GL_TEXTURE_2D,
777 GL_RGBA,
781 GL_RGBA,
782 GL_UNSIGNED_BYTE,
783 kSharedMemoryId,
784 kSharedMemoryOffset);
785 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
787 InSequence sequence;
788 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
789 .Times(1)
790 .RetiresOnSaturation();
791 EXPECT_CALL(
792 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceBlackTexture2dId))
793 .Times(1)
794 .RetiresOnSaturation();
795 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
796 .Times(1)
797 .RetiresOnSaturation();
798 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
799 .Times(1)
800 .RetiresOnSaturation();
801 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
802 .Times(1)
803 .RetiresOnSaturation();
804 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
805 .Times(1)
806 .RetiresOnSaturation();
808 SetupExpectationsForApplyingDefaultDirtyState();
809 DrawArrays cmd;
810 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
811 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
812 EXPECT_EQ(GL_NO_ERROR, GetGLError());
815 TEST_P(GLES2DecoderWithShaderTest, DrawArraysMissingAttributesFails) {
816 DoEnableVertexAttribArray(1);
818 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
819 DrawArrays cmd;
820 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
821 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
822 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
825 TEST_P(GLES2DecoderWithShaderTest,
826 DrawArraysMissingAttributesZeroCountSucceeds) {
827 DoEnableVertexAttribArray(1);
829 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
830 DrawArrays cmd;
831 cmd.Init(GL_TRIANGLES, 0, 0);
832 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
833 EXPECT_EQ(GL_NO_ERROR, GetGLError());
836 TEST_P(GLES2DecoderWithShaderTest, DrawArraysValidAttributesSucceeds) {
837 SetupTexture();
838 SetupVertexBuffer();
839 DoEnableVertexAttribArray(1);
840 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
841 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
842 SetupExpectationsForApplyingDefaultDirtyState();
844 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
845 .Times(1)
846 .RetiresOnSaturation();
847 DrawArrays cmd;
848 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
849 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
850 EXPECT_EQ(GL_NO_ERROR, GetGLError());
853 // Same as DrawArraysValidAttributesSucceeds, but with workaround
854 // |init_vertex_attributes|.
855 TEST_P(GLES2DecoderManualInitTest, InitVertexAttributes) {
856 CommandLine command_line(0, NULL);
857 command_line.AppendSwitchASCII(
858 switches::kGpuDriverBugWorkarounds,
859 base::IntToString(gpu::INIT_VERTEX_ATTRIBUTES));
860 InitState init;
861 init.gl_version = "3.0";
862 init.has_alpha = true;
863 init.has_depth = true;
864 init.request_alpha = true;
865 init.request_depth = true;
866 init.bind_generates_resource = true;
867 InitDecoderWithCommandLine(init, &command_line);
868 SetupDefaultProgram();
869 SetupTexture();
870 SetupVertexBuffer();
871 DoEnableVertexAttribArray(1);
872 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
873 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
874 SetupExpectationsForApplyingDefaultDirtyState();
876 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
877 .Times(1)
878 .RetiresOnSaturation();
879 DrawArrays cmd;
880 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
881 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
882 EXPECT_EQ(GL_NO_ERROR, GetGLError());
885 TEST_P(GLES2DecoderWithShaderTest, DrawArraysDeletedBufferFails) {
886 SetupVertexBuffer();
887 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
888 DeleteVertexBuffer();
890 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
891 DrawArrays cmd;
892 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
893 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
894 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
897 TEST_P(GLES2DecoderWithShaderTest, DrawArraysDeletedProgramSucceeds) {
898 SetupTexture();
899 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
900 SetupExpectationsForApplyingDefaultDirtyState();
901 DoDeleteProgram(client_program_id_, kServiceProgramId);
903 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(1).RetiresOnSaturation();
904 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId)).Times(1);
905 DrawArrays cmd;
906 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
907 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
908 EXPECT_EQ(GL_NO_ERROR, GetGLError());
911 TEST_P(GLES2DecoderWithShaderTest, DrawArraysWithInvalidModeFails) {
912 SetupVertexBuffer();
913 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
915 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
916 DrawArrays cmd;
917 cmd.Init(GL_QUADS, 0, 1);
918 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
919 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
920 cmd.Init(GL_POLYGON, 0, 1);
921 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
922 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
925 TEST_P(GLES2DecoderWithShaderTest, DrawArraysInvalidCountFails) {
926 SetupVertexBuffer();
927 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
929 // Try start > 0
930 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
931 DrawArrays cmd;
932 cmd.Init(GL_TRIANGLES, 1, kNumVertices);
933 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
934 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
935 EXPECT_EQ(GL_NO_ERROR, GetGLError());
937 // Try with count > size
938 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1);
939 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
940 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
941 EXPECT_EQ(GL_NO_ERROR, GetGLError());
943 // Try with attrib offset > 0
944 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
945 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 4);
946 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
947 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
948 EXPECT_EQ(GL_NO_ERROR, GetGLError());
950 // Try with size > 2 (ie, vec3 instead of vec2)
951 DoVertexAttribPointer(1, 3, GL_FLOAT, 0, 0);
952 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
953 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
954 EXPECT_EQ(GL_NO_ERROR, GetGLError());
956 // Try with stride > 8 (vec2 + vec2 byte)
957 DoVertexAttribPointer(1, 2, GL_FLOAT, sizeof(GLfloat) * 3, 0);
958 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
959 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
960 EXPECT_EQ(GL_NO_ERROR, GetGLError());
963 TEST_P(GLES2DecoderWithShaderTest, DrawArraysInstancedANGLEFails) {
964 SetupTexture();
965 SetupVertexBuffer();
966 DoEnableVertexAttribArray(1);
967 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
969 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
970 .Times(0)
971 .RetiresOnSaturation();
972 DrawArraysInstancedANGLE cmd;
973 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
974 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
975 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
978 TEST_P(GLES2DecoderWithShaderTest, VertexAttribDivisorANGLEFails) {
979 SetupTexture();
980 SetupVertexBuffer();
981 DoEnableVertexAttribArray(1);
982 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
984 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(_, _))
985 .Times(0)
986 .RetiresOnSaturation();
988 VertexAttribDivisorANGLE cmd;
989 cmd.Init(0, 1);
990 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
991 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
994 TEST_P(GLES2DecoderGeometryInstancingTest,
995 DrawArraysInstancedANGLENoAttributesFails) {
996 SetupTexture();
998 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
999 .Times(0)
1000 .RetiresOnSaturation();
1001 DrawArraysInstancedANGLE cmd;
1002 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1003 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1004 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1007 TEST_P(GLES2DecoderGeometryInstancingTest,
1008 DrawArraysInstancedANGLESimulatedAttrib0) {
1009 SetupTexture();
1010 SetupVertexBuffer();
1011 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1013 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
1014 SetupExpectationsForApplyingDefaultDirtyState();
1016 DoVertexAttribDivisorANGLE(0, 1);
1017 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 3))
1018 .Times(1)
1019 .RetiresOnSaturation();
1020 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
1021 .Times(1)
1022 .RetiresOnSaturation();
1023 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
1024 .Times(1)
1025 .RetiresOnSaturation();
1026 DrawArraysInstancedANGLE cmd;
1027 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 3);
1028 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1029 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1032 TEST_P(GLES2DecoderGeometryInstancingTest,
1033 DrawArraysInstancedANGLEMissingAttributesFails) {
1034 DoEnableVertexAttribArray(1);
1036 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1037 DrawArraysInstancedANGLE cmd;
1038 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1039 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1040 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1043 TEST_P(GLES2DecoderGeometryInstancingTest,
1044 DrawArraysInstancedANGLEMissingAttributesZeroCountSucceeds) {
1045 DoEnableVertexAttribArray(1);
1047 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1048 DrawArraysInstancedANGLE cmd;
1049 cmd.Init(GL_TRIANGLES, 0, 0, 1);
1050 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1051 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1054 TEST_P(GLES2DecoderGeometryInstancingTest,
1055 DrawArraysInstancedANGLEValidAttributesSucceeds) {
1056 SetupTexture();
1057 SetupVertexBuffer();
1058 DoEnableVertexAttribArray(1);
1059 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1060 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
1061 SetupExpectationsForApplyingDefaultDirtyState();
1063 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 1))
1064 .Times(1)
1065 .RetiresOnSaturation();
1066 DrawArraysInstancedANGLE cmd;
1067 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1068 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1069 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1072 TEST_P(GLES2DecoderGeometryInstancingTest,
1073 DrawArraysInstancedANGLEWithInvalidModeFails) {
1074 SetupVertexBuffer();
1075 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1077 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1078 DrawArraysInstancedANGLE cmd;
1079 cmd.Init(GL_QUADS, 0, 1, 1);
1080 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1081 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1082 cmd.Init(GL_POLYGON, 0, 1, 1);
1083 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1084 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1087 TEST_P(GLES2DecoderGeometryInstancingTest,
1088 DrawArraysInstancedANGLEInvalidPrimcountFails) {
1089 SetupVertexBuffer();
1090 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1092 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1093 DrawArraysInstancedANGLE cmd;
1094 cmd.Init(GL_TRIANGLES, 0, 1, -1);
1095 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1096 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1099 // Per-instance data is twice as large, but number of instances is half
1100 TEST_P(GLES2DecoderGeometryInstancingTest,
1101 DrawArraysInstancedANGLELargeInstanceSucceeds) {
1102 SetupTexture();
1103 SetupVertexBuffer();
1104 SetupExpectationsForApplyingDefaultDirtyState();
1105 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1107 DoEnableVertexAttribArray(0);
1108 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1109 DoVertexAttribDivisorANGLE(0, 1);
1110 EXPECT_CALL(
1111 *gl_,
1112 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2))
1113 .Times(1)
1114 .RetiresOnSaturation();
1115 DrawArraysInstancedANGLE cmd;
1116 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2);
1117 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1118 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1121 // Regular drawArrays takes the divisor into account
1122 TEST_P(GLES2DecoderGeometryInstancingTest,
1123 DrawArraysWithDivisorSucceeds) {
1124 SetupTexture();
1125 SetupVertexBuffer();
1126 SetupExpectationsForApplyingDefaultDirtyState();
1127 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1129 DoEnableVertexAttribArray(0);
1130 // Access the data right at the end of the buffer.
1131 DoVertexAttribPointer(
1132 0, 2, GL_FLOAT, 0, (kNumVertices - 1) * 2 * sizeof(GLfloat));
1133 DoVertexAttribDivisorANGLE(0, 1);
1134 EXPECT_CALL(
1135 *gl_,
1136 DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1137 .Times(1)
1138 .RetiresOnSaturation();
1139 DrawArrays cmd;
1140 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1141 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1142 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1145 // Per-instance data is twice as large, but divisor is twice
1146 TEST_P(GLES2DecoderGeometryInstancingTest,
1147 DrawArraysInstancedANGLELargeDivisorSucceeds) {
1148 SetupTexture();
1149 SetupVertexBuffer();
1150 SetupExpectationsForApplyingDefaultDirtyState();
1151 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1153 DoEnableVertexAttribArray(0);
1154 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1155 DoVertexAttribDivisorANGLE(0, 2);
1156 EXPECT_CALL(
1157 *gl_,
1158 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices))
1159 .Times(1)
1160 .RetiresOnSaturation();
1161 DrawArraysInstancedANGLE cmd;
1162 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices);
1163 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1164 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1167 TEST_P(GLES2DecoderGeometryInstancingTest, DrawArraysInstancedANGLELargeFails) {
1168 SetupTexture();
1169 SetupVertexBuffer();
1170 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1172 DoEnableVertexAttribArray(0);
1173 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1174 DoVertexAttribDivisorANGLE(0, 1);
1175 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1176 .Times(0)
1177 .RetiresOnSaturation();
1178 DrawArraysInstancedANGLE cmd;
1179 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices + 1);
1180 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1181 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1182 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1184 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1185 .Times(0)
1186 .RetiresOnSaturation();
1187 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1, kNumVertices);
1188 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1189 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1190 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1193 // Per-index data is twice as large, but number of indices is half
1194 TEST_P(GLES2DecoderGeometryInstancingTest,
1195 DrawArraysInstancedANGLELargeIndexSucceeds) {
1196 SetupTexture();
1197 SetupVertexBuffer();
1198 SetupExpectationsForApplyingDefaultDirtyState();
1199 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
1201 DoEnableVertexAttribArray(0);
1202 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1203 DoVertexAttribDivisorANGLE(0, 1);
1204 EXPECT_CALL(
1205 *gl_,
1206 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices))
1207 .Times(1)
1208 .RetiresOnSaturation();
1209 DrawArraysInstancedANGLE cmd;
1210 cmd.Init(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices);
1211 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1212 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1215 TEST_P(GLES2DecoderGeometryInstancingTest,
1216 DrawArraysInstancedANGLENoDivisor0Fails) {
1217 SetupTexture();
1218 SetupVertexBuffer();
1219 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1221 DoEnableVertexAttribArray(0);
1222 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1223 DoVertexAttribDivisorANGLE(0, 1);
1224 DoVertexAttribDivisorANGLE(1, 1);
1225 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1226 .Times(0)
1227 .RetiresOnSaturation();
1228 DrawArraysInstancedANGLE cmd;
1229 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1230 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1231 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1232 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1235 TEST_P(GLES2DecoderGeometryInstancingTest,
1236 DrawArraysNoDivisor0Fails) {
1237 SetupTexture();
1238 SetupVertexBuffer();
1239 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1241 DoEnableVertexAttribArray(0);
1242 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1243 DoVertexAttribDivisorANGLE(0, 1);
1244 DoVertexAttribDivisorANGLE(1, 1);
1245 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
1246 .Times(0)
1247 .RetiresOnSaturation();
1248 DrawArrays cmd;
1249 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1250 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1251 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1252 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1255 TEST_P(GLES2DecoderWithShaderTest, DrawElementsNoAttributesSucceeds) {
1256 SetupTexture();
1257 SetupIndexBuffer();
1258 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
1259 SetupExpectationsForApplyingDefaultDirtyState();
1260 EXPECT_CALL(*gl_,
1261 DrawElements(GL_TRIANGLES,
1262 kValidIndexRangeCount,
1263 GL_UNSIGNED_SHORT,
1264 BufferOffset(kValidIndexRangeStart * 2)))
1265 .Times(1)
1266 .RetiresOnSaturation();
1267 DrawElements cmd;
1268 cmd.Init(GL_TRIANGLES,
1269 kValidIndexRangeCount,
1270 GL_UNSIGNED_SHORT,
1271 kValidIndexRangeStart * 2);
1272 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1273 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1276 TEST_P(GLES2DecoderWithShaderTest, DrawElementsMissingAttributesFails) {
1277 SetupIndexBuffer();
1278 DoEnableVertexAttribArray(1);
1280 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1281 DrawElements cmd;
1282 cmd.Init(GL_TRIANGLES,
1283 kValidIndexRangeCount,
1284 GL_UNSIGNED_SHORT,
1285 kValidIndexRangeStart * 2);
1286 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1287 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1290 TEST_P(GLES2DecoderWithShaderTest,
1291 DrawElementsMissingAttributesZeroCountSucceeds) {
1292 SetupIndexBuffer();
1293 DoEnableVertexAttribArray(1);
1295 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1296 DrawElements cmd;
1297 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2);
1298 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1299 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1302 TEST_P(GLES2DecoderWithShaderTest, DrawElementsExtraAttributesFails) {
1303 SetupIndexBuffer();
1304 DoEnableVertexAttribArray(6);
1306 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1307 DrawElements cmd;
1308 cmd.Init(GL_TRIANGLES,
1309 kValidIndexRangeCount,
1310 GL_UNSIGNED_SHORT,
1311 kValidIndexRangeStart * 2);
1312 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1313 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1316 TEST_P(GLES2DecoderWithShaderTest, DrawElementsValidAttributesSucceeds) {
1317 SetupTexture();
1318 SetupVertexBuffer();
1319 SetupIndexBuffer();
1320 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1321 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1322 SetupExpectationsForApplyingDefaultDirtyState();
1324 EXPECT_CALL(*gl_,
1325 DrawElements(GL_TRIANGLES,
1326 kValidIndexRangeCount,
1327 GL_UNSIGNED_SHORT,
1328 BufferOffset(kValidIndexRangeStart * 2)))
1329 .Times(1)
1330 .RetiresOnSaturation();
1331 DrawElements cmd;
1332 cmd.Init(GL_TRIANGLES,
1333 kValidIndexRangeCount,
1334 GL_UNSIGNED_SHORT,
1335 kValidIndexRangeStart * 2);
1336 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1337 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1340 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedBufferFails) {
1341 SetupVertexBuffer();
1342 SetupIndexBuffer();
1343 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1344 DeleteIndexBuffer();
1346 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1347 DrawElements cmd;
1348 cmd.Init(GL_TRIANGLES,
1349 kValidIndexRangeCount,
1350 GL_UNSIGNED_SHORT,
1351 kValidIndexRangeStart * 2);
1352 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1353 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1356 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedProgramSucceeds) {
1357 SetupTexture();
1358 SetupIndexBuffer();
1359 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
1360 SetupExpectationsForApplyingDefaultDirtyState();
1361 DoDeleteProgram(client_program_id_, kServiceProgramId);
1363 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1);
1364 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId)).Times(1);
1365 DrawElements cmd;
1366 cmd.Init(GL_TRIANGLES,
1367 kValidIndexRangeCount,
1368 GL_UNSIGNED_SHORT,
1369 kValidIndexRangeStart * 2);
1370 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1371 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1374 TEST_P(GLES2DecoderWithShaderTest, DrawElementsWithInvalidModeFails) {
1375 SetupVertexBuffer();
1376 SetupIndexBuffer();
1377 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1379 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1380 DrawElements cmd;
1381 cmd.Init(GL_QUADS,
1382 kValidIndexRangeCount,
1383 GL_UNSIGNED_SHORT,
1384 kValidIndexRangeStart * 2);
1385 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1386 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1387 cmd.Init(GL_POLYGON,
1388 kValidIndexRangeCount,
1389 GL_UNSIGNED_SHORT,
1390 kValidIndexRangeStart);
1391 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1392 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1395 TEST_P(GLES2DecoderWithShaderTest, DrawElementsInvalidCountFails) {
1396 SetupVertexBuffer();
1397 SetupIndexBuffer();
1398 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1400 // Try start > 0
1401 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1402 DrawElements cmd;
1403 cmd.Init(GL_TRIANGLES, kNumIndices, GL_UNSIGNED_SHORT, 2);
1404 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1405 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1406 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1408 // Try with count > size
1409 cmd.Init(GL_TRIANGLES, kNumIndices + 1, GL_UNSIGNED_SHORT, 0);
1410 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1411 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1412 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1415 TEST_P(GLES2DecoderWithShaderTest, DrawElementsOutOfRangeIndicesFails) {
1416 SetupVertexBuffer();
1417 SetupIndexBuffer();
1418 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1420 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1421 DrawElements cmd;
1422 cmd.Init(GL_TRIANGLES,
1423 kInvalidIndexRangeCount,
1424 GL_UNSIGNED_SHORT,
1425 kInvalidIndexRangeStart * 2);
1426 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1427 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1428 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1431 TEST_P(GLES2DecoderWithShaderTest, DrawElementsOddOffsetForUint16Fails) {
1432 SetupVertexBuffer();
1433 SetupIndexBuffer();
1434 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1436 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1437 DrawElements cmd;
1438 cmd.Init(GL_TRIANGLES, kInvalidIndexRangeCount, GL_UNSIGNED_SHORT, 1);
1439 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1440 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1441 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1444 TEST_P(GLES2DecoderWithShaderTest, DrawElementsInstancedANGLEFails) {
1445 SetupTexture();
1446 SetupVertexBuffer();
1447 SetupIndexBuffer();
1448 DoEnableVertexAttribArray(1);
1449 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1451 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1452 .Times(0)
1453 .RetiresOnSaturation();
1454 DrawElementsInstancedANGLE cmd;
1455 cmd.Init(GL_TRIANGLES,
1456 kValidIndexRangeCount,
1457 GL_UNSIGNED_SHORT,
1458 kValidIndexRangeStart * 2,
1460 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1461 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1464 TEST_P(GLES2DecoderGeometryInstancingTest,
1465 DrawElementsInstancedANGLENoAttributesFails) {
1466 SetupTexture();
1467 SetupIndexBuffer();
1469 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1470 .Times(0)
1471 .RetiresOnSaturation();
1472 DrawElementsInstancedANGLE cmd;
1473 cmd.Init(GL_TRIANGLES,
1474 kValidIndexRangeCount,
1475 GL_UNSIGNED_SHORT,
1476 kValidIndexRangeStart * 2,
1478 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1479 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1482 TEST_P(GLES2DecoderGeometryInstancingTest,
1483 DrawElementsInstancedANGLESimulatedAttrib0) {
1484 SetupTexture();
1485 SetupVertexBuffer();
1486 SetupIndexBuffer();
1487 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1489 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1490 SetupExpectationsForApplyingDefaultDirtyState();
1492 DoVertexAttribDivisorANGLE(0, 1);
1493 EXPECT_CALL(
1494 *gl_,
1495 DrawElementsInstancedANGLE(GL_TRIANGLES,
1496 kValidIndexRangeCount,
1497 GL_UNSIGNED_SHORT,
1498 BufferOffset(kValidIndexRangeStart * 2),
1500 .Times(1)
1501 .RetiresOnSaturation();
1502 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
1503 .Times(1)
1504 .RetiresOnSaturation();
1505 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
1506 .Times(1)
1507 .RetiresOnSaturation();
1508 DrawElementsInstancedANGLE cmd;
1509 cmd.Init(GL_TRIANGLES,
1510 kValidIndexRangeCount,
1511 GL_UNSIGNED_SHORT,
1512 kValidIndexRangeStart * 2,
1514 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1515 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1518 TEST_P(GLES2DecoderGeometryInstancingTest,
1519 DrawElementsInstancedANGLEMissingAttributesFails) {
1520 SetupIndexBuffer();
1521 DoEnableVertexAttribArray(1);
1523 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1524 DrawElementsInstancedANGLE cmd;
1525 cmd.Init(GL_TRIANGLES,
1526 kValidIndexRangeCount,
1527 GL_UNSIGNED_SHORT,
1528 kValidIndexRangeStart * 2,
1530 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1531 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1534 TEST_P(GLES2DecoderGeometryInstancingTest,
1535 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds) {
1536 SetupIndexBuffer();
1537 DoEnableVertexAttribArray(1);
1539 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1540 DrawElementsInstancedANGLE cmd;
1541 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2, 1);
1542 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1543 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1546 TEST_P(GLES2DecoderGeometryInstancingTest,
1547 DrawElementsInstancedANGLEValidAttributesSucceeds) {
1548 SetupIndexBuffer();
1549 SetupTexture();
1550 SetupVertexBuffer();
1551 DoEnableVertexAttribArray(1);
1552 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1553 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1554 SetupExpectationsForApplyingDefaultDirtyState();
1556 EXPECT_CALL(
1557 *gl_,
1558 DrawElementsInstancedANGLE(GL_TRIANGLES,
1559 kValidIndexRangeCount,
1560 GL_UNSIGNED_SHORT,
1561 BufferOffset(kValidIndexRangeStart * 2),
1563 .Times(1)
1564 .RetiresOnSaturation();
1565 DrawElementsInstancedANGLE cmd;
1566 cmd.Init(GL_TRIANGLES,
1567 kValidIndexRangeCount,
1568 GL_UNSIGNED_SHORT,
1569 kValidIndexRangeStart * 2,
1571 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1572 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1575 TEST_P(GLES2DecoderGeometryInstancingTest,
1576 DrawElementsInstancedANGLEWithInvalidModeFails) {
1577 SetupIndexBuffer();
1578 SetupVertexBuffer();
1579 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1581 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1582 DrawElementsInstancedANGLE cmd;
1583 cmd.Init(GL_QUADS,
1584 kValidIndexRangeCount,
1585 GL_UNSIGNED_SHORT,
1586 kValidIndexRangeStart * 2,
1588 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1589 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1590 cmd.Init(GL_INVALID_ENUM,
1591 kValidIndexRangeCount,
1592 GL_UNSIGNED_SHORT,
1593 kValidIndexRangeStart * 2,
1595 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1596 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1599 // Per-instance data is twice as large, but number of instances is half
1600 TEST_P(GLES2DecoderGeometryInstancingTest,
1601 DrawElementsInstancedANGLELargeInstanceSucceeds) {
1602 SetupTexture();
1603 SetupIndexBuffer();
1604 SetupVertexBuffer();
1605 SetupExpectationsForApplyingDefaultDirtyState();
1606 // Add offset so we're sure we're accessing data near the end of the buffer.
1607 DoVertexAttribPointer(
1610 GL_FLOAT,
1612 (kNumVertices - kMaxValidIndex - 1) * 2 * sizeof(GLfloat));
1614 DoEnableVertexAttribArray(0);
1615 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1616 DoVertexAttribDivisorANGLE(0, 1);
1617 EXPECT_CALL(
1618 *gl_,
1619 DrawElementsInstancedANGLE(GL_TRIANGLES,
1620 kValidIndexRangeCount,
1621 GL_UNSIGNED_SHORT,
1622 BufferOffset(kValidIndexRangeStart * 2),
1623 kNumVertices / 2))
1624 .Times(1)
1625 .RetiresOnSaturation();
1626 DrawElementsInstancedANGLE cmd;
1627 cmd.Init(GL_TRIANGLES,
1628 kValidIndexRangeCount,
1629 GL_UNSIGNED_SHORT,
1630 kValidIndexRangeStart * 2,
1631 kNumVertices / 2);
1632 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1633 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1636 // Regular drawElements takes the divisor into account
1637 TEST_P(GLES2DecoderGeometryInstancingTest,
1638 DrawElementsWithDivisorSucceeds) {
1639 SetupTexture();
1640 SetupIndexBuffer();
1641 SetupVertexBuffer();
1642 SetupExpectationsForApplyingDefaultDirtyState();
1643 // Add offset so we're sure we're accessing data near the end of the buffer.
1644 DoVertexAttribPointer(
1647 GL_FLOAT,
1649 (kNumVertices - kMaxValidIndex - 1) * 2 * sizeof(GLfloat));
1651 DoEnableVertexAttribArray(0);
1652 // Access the data right at the end of the buffer.
1653 DoVertexAttribPointer(
1654 0, 2, GL_FLOAT, 0, (kNumVertices - 1) * 2 * sizeof(GLfloat));
1655 DoVertexAttribDivisorANGLE(0, 1);
1656 EXPECT_CALL(
1657 *gl_,
1658 DrawElements(GL_TRIANGLES,
1659 kValidIndexRangeCount,
1660 GL_UNSIGNED_SHORT,
1661 BufferOffset(kValidIndexRangeStart * 2)))
1662 .Times(1)
1663 .RetiresOnSaturation();
1664 DrawElements cmd;
1665 cmd.Init(GL_TRIANGLES,
1666 kValidIndexRangeCount,
1667 GL_UNSIGNED_SHORT,
1668 kValidIndexRangeStart * 2);
1669 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1670 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1673 // Per-instance data is twice as large, but divisor is twice
1674 TEST_P(GLES2DecoderGeometryInstancingTest,
1675 DrawElementsInstancedANGLELargeDivisorSucceeds) {
1676 SetupTexture();
1677 SetupIndexBuffer();
1678 SetupVertexBuffer();
1679 SetupExpectationsForApplyingDefaultDirtyState();
1680 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1682 DoEnableVertexAttribArray(0);
1683 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1684 DoVertexAttribDivisorANGLE(0, 2);
1685 EXPECT_CALL(
1686 *gl_,
1687 DrawElementsInstancedANGLE(GL_TRIANGLES,
1688 kValidIndexRangeCount,
1689 GL_UNSIGNED_SHORT,
1690 BufferOffset(kValidIndexRangeStart * 2),
1691 kNumVertices))
1692 .Times(1)
1693 .RetiresOnSaturation();
1694 DrawElementsInstancedANGLE cmd;
1695 cmd.Init(GL_TRIANGLES,
1696 kValidIndexRangeCount,
1697 GL_UNSIGNED_SHORT,
1698 kValidIndexRangeStart * 2,
1699 kNumVertices);
1700 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1701 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1704 TEST_P(GLES2DecoderGeometryInstancingTest,
1705 DrawElementsInstancedANGLELargeFails) {
1706 SetupTexture();
1707 SetupIndexBuffer();
1708 SetupVertexBuffer();
1709 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1711 DoEnableVertexAttribArray(0);
1712 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1713 DoVertexAttribDivisorANGLE(0, 1);
1714 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1715 .Times(0)
1716 .RetiresOnSaturation();
1717 DrawElementsInstancedANGLE cmd;
1718 cmd.Init(GL_TRIANGLES,
1719 kValidIndexRangeCount,
1720 GL_UNSIGNED_SHORT,
1721 kValidIndexRangeStart * 2,
1722 kNumVertices + 1);
1723 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1724 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1725 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1727 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1728 .Times(0)
1729 .RetiresOnSaturation();
1730 cmd.Init(GL_TRIANGLES,
1731 kInvalidIndexRangeCount,
1732 GL_UNSIGNED_SHORT,
1733 kInvalidIndexRangeStart * 2,
1734 kNumVertices);
1735 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1736 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1737 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1740 TEST_P(GLES2DecoderGeometryInstancingTest,
1741 DrawElementsInstancedANGLEInvalidPrimcountFails) {
1742 SetupTexture();
1743 SetupIndexBuffer();
1744 SetupVertexBuffer();
1745 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1747 DoEnableVertexAttribArray(0);
1748 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1749 DoVertexAttribDivisorANGLE(0, 1);
1750 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1751 .Times(0)
1752 .RetiresOnSaturation();
1753 DrawElementsInstancedANGLE cmd;
1754 cmd.Init(GL_TRIANGLES,
1755 kValidIndexRangeCount,
1756 GL_UNSIGNED_SHORT,
1757 kValidIndexRangeStart * 2,
1758 -1);
1759 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1760 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1761 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1764 // Per-index data is twice as large, but values of indices are smaller
1765 TEST_P(GLES2DecoderGeometryInstancingTest,
1766 DrawElementsInstancedANGLELargeIndexSucceeds) {
1767 SetupTexture();
1768 SetupIndexBuffer();
1769 SetupVertexBuffer();
1770 SetupExpectationsForApplyingDefaultDirtyState();
1771 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
1773 DoEnableVertexAttribArray(0);
1774 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1775 DoVertexAttribDivisorANGLE(0, 1);
1776 EXPECT_CALL(
1777 *gl_,
1778 DrawElementsInstancedANGLE(GL_TRIANGLES,
1779 kValidIndexRangeCount,
1780 GL_UNSIGNED_SHORT,
1781 BufferOffset(kValidIndexRangeStart * 2),
1782 kNumVertices))
1783 .Times(1)
1784 .RetiresOnSaturation();
1785 DrawElementsInstancedANGLE cmd;
1786 cmd.Init(GL_TRIANGLES,
1787 kValidIndexRangeCount,
1788 GL_UNSIGNED_SHORT,
1789 kValidIndexRangeStart * 2,
1790 kNumVertices);
1791 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1792 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1795 TEST_P(GLES2DecoderGeometryInstancingTest,
1796 DrawElementsInstancedANGLENoDivisor0Fails) {
1797 SetupTexture();
1798 SetupIndexBuffer();
1799 SetupVertexBuffer();
1800 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1802 DoEnableVertexAttribArray(0);
1803 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1804 DoVertexAttribDivisorANGLE(0, 1);
1805 DoVertexAttribDivisorANGLE(1, 1);
1806 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1807 .Times(0)
1808 .RetiresOnSaturation();
1809 DrawElementsInstancedANGLE cmd;
1810 cmd.Init(GL_TRIANGLES,
1811 kValidIndexRangeCount,
1812 GL_UNSIGNED_SHORT,
1813 kValidIndexRangeStart * 2,
1814 kNumVertices);
1815 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1816 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1817 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1820 TEST_P(GLES2DecoderGeometryInstancingTest,
1821 DrawElementsNoDivisor0Fails) {
1822 SetupTexture();
1823 SetupIndexBuffer();
1824 SetupVertexBuffer();
1825 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1827 DoEnableVertexAttribArray(0);
1828 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1829 DoVertexAttribDivisorANGLE(0, 1);
1830 DoVertexAttribDivisorANGLE(1, 1);
1831 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
1832 .Times(0)
1833 .RetiresOnSaturation();
1834 DrawElements cmd;
1835 cmd.Init(GL_TRIANGLES,
1836 kValidIndexRangeCount,
1837 GL_UNSIGNED_SHORT,
1838 kValidIndexRangeStart * 2);
1839 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1840 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1841 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1844 TEST_P(GLES2DecoderWithShaderTest, DrawArraysClearsAfterTexImage2DNULL) {
1845 SetupAllNeededVertexBuffers();
1846 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1847 // Create an uncleared texture with 2 levels.
1848 DoTexImage2D(
1849 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1850 DoTexImage2D(
1851 GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1852 // Expect 2 levels will be cleared.
1853 SetupClearTextureExpectations(kServiceTextureId,
1854 kServiceTextureId,
1855 GL_TEXTURE_2D,
1856 GL_TEXTURE_2D,
1858 GL_RGBA,
1859 GL_RGBA,
1860 GL_UNSIGNED_BYTE,
1863 SetupClearTextureExpectations(kServiceTextureId,
1864 kServiceTextureId,
1865 GL_TEXTURE_2D,
1866 GL_TEXTURE_2D,
1868 GL_RGBA,
1869 GL_RGBA,
1870 GL_UNSIGNED_BYTE,
1873 SetupExpectationsForApplyingDefaultDirtyState();
1874 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1875 .Times(1)
1876 .RetiresOnSaturation();
1877 DrawArrays cmd;
1878 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1879 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1880 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1882 // But not again
1883 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1884 .Times(1)
1885 .RetiresOnSaturation();
1886 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1887 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1890 TEST_P(GLES2DecoderWithShaderTest, DrawElementsClearsAfterTexImage2DNULL) {
1891 SetupAllNeededVertexBuffers();
1892 SetupIndexBuffer();
1893 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1894 // Create an uncleared texture with 2 levels.
1895 DoTexImage2D(
1896 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1897 DoTexImage2D(
1898 GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1899 // Expect 2 levels will be cleared.
1900 SetupClearTextureExpectations(kServiceTextureId,
1901 kServiceTextureId,
1902 GL_TEXTURE_2D,
1903 GL_TEXTURE_2D,
1905 GL_RGBA,
1906 GL_RGBA,
1907 GL_UNSIGNED_BYTE,
1910 SetupClearTextureExpectations(kServiceTextureId,
1911 kServiceTextureId,
1912 GL_TEXTURE_2D,
1913 GL_TEXTURE_2D,
1915 GL_RGBA,
1916 GL_RGBA,
1917 GL_UNSIGNED_BYTE,
1920 SetupExpectationsForApplyingDefaultDirtyState();
1922 EXPECT_CALL(*gl_,
1923 DrawElements(GL_TRIANGLES,
1924 kValidIndexRangeCount,
1925 GL_UNSIGNED_SHORT,
1926 BufferOffset(kValidIndexRangeStart * 2)))
1927 .Times(1)
1928 .RetiresOnSaturation();
1929 DrawElements cmd;
1930 cmd.Init(GL_TRIANGLES,
1931 kValidIndexRangeCount,
1932 GL_UNSIGNED_SHORT,
1933 kValidIndexRangeStart * 2);
1934 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1935 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1937 // But not again
1938 EXPECT_CALL(*gl_,
1939 DrawElements(GL_TRIANGLES,
1940 kValidIndexRangeCount,
1941 GL_UNSIGNED_SHORT,
1942 BufferOffset(kValidIndexRangeStart * 2)))
1943 .Times(1)
1944 .RetiresOnSaturation();
1945 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1946 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1949 TEST_P(GLES2DecoderWithShaderTest, DrawClearsAfterTexImage2DNULLInFBO) {
1950 const GLuint kFBOClientTextureId = 4100;
1951 const GLuint kFBOServiceTextureId = 4101;
1953 SetupAllNeededVertexBuffers();
1954 // Register a texture id.
1955 EXPECT_CALL(*gl_, GenTextures(_, _))
1956 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1957 .RetiresOnSaturation();
1958 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1960 // Setup "render to" texture.
1961 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1962 DoTexImage2D(
1963 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1964 DoBindFramebuffer(
1965 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1966 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1967 GL_COLOR_ATTACHMENT0,
1968 GL_TEXTURE_2D,
1969 kFBOClientTextureId,
1970 kFBOServiceTextureId,
1972 GL_NO_ERROR);
1974 // Setup "render from" texture.
1975 SetupTexture();
1977 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1978 GL_COLOR_BUFFER_BIT, // clear bits
1982 0, // color
1983 0, // stencil
1984 1.0f, // depth
1985 false); // scissor test
1987 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1988 false, // Framebuffer has depth
1989 false, // Framebuffer has stencil
1990 0x1111, // color bits
1991 false, // depth mask
1992 false, // depth enabled
1993 0, // front stencil mask
1994 0, // back stencil mask
1995 false); // stencil enabled
1997 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1998 .Times(1)
1999 .RetiresOnSaturation();
2000 DrawArrays cmd;
2001 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2002 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2003 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2005 // But not again.
2006 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2007 .Times(1)
2008 .RetiresOnSaturation();
2009 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2010 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2013 TEST_P(GLES2DecoderWithShaderTest, DrawWitFBOThatCantClearDoesNotDraw) {
2014 const GLuint kFBOClientTextureId = 4100;
2015 const GLuint kFBOServiceTextureId = 4101;
2017 // Register a texture id.
2018 EXPECT_CALL(*gl_, GenTextures(_, _))
2019 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2020 .RetiresOnSaturation();
2021 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2023 // Setup "render to" texture.
2024 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2025 DoTexImage2D(
2026 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2027 DoBindFramebuffer(
2028 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2029 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2030 GL_COLOR_ATTACHMENT0,
2031 GL_TEXTURE_2D,
2032 kFBOClientTextureId,
2033 kFBOServiceTextureId,
2035 GL_NO_ERROR);
2037 // Setup "render from" texture.
2038 SetupTexture();
2040 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
2041 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED))
2042 .RetiresOnSaturation();
2043 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
2044 DrawArrays cmd;
2045 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2046 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2047 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
2050 TEST_P(GLES2DecoderWithShaderTest, DrawClearsAfterRenderbufferStorageInFBO) {
2051 SetupTexture();
2052 DoBindRenderbuffer(
2053 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
2054 DoBindFramebuffer(
2055 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2056 DoRenderbufferStorage(
2057 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 100, 50, GL_NO_ERROR);
2058 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
2059 GL_COLOR_ATTACHMENT0,
2060 GL_RENDERBUFFER,
2061 client_renderbuffer_id_,
2062 kServiceRenderbufferId,
2063 GL_NO_ERROR);
2065 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
2066 GL_COLOR_BUFFER_BIT, // clear bits
2070 0, // color
2071 0, // stencil
2072 1.0f, // depth
2073 false); // scissor test
2075 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2076 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2077 false, // Framebuffer has depth
2078 false, // Framebuffer has stencil
2079 0x1111, // color bits
2080 false, // depth mask
2081 false, // depth enabled
2082 0, // front stencil mask
2083 0, // back stencil mask
2084 false); // stencil enabled
2086 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2087 .Times(1)
2088 .RetiresOnSaturation();
2089 DrawArrays cmd;
2090 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2091 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2092 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2095 TEST_P(GLES2DecoderManualInitTest, DrawArraysClearsAfterTexImage2DNULLCubemap) {
2096 InitState init;
2097 init.gl_version = "opengl es 2.0";
2098 init.has_alpha = true;
2099 init.has_depth = true;
2100 init.request_alpha = true;
2101 init.request_depth = true;
2102 InitDecoder(init);
2104 static const GLenum faces[] = {
2105 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
2106 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2107 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
2109 SetupCubemapProgram();
2110 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2111 // Fill out all the faces for 2 levels, leave 2 uncleared.
2112 for (int ii = 0; ii < 6; ++ii) {
2113 GLenum face = faces[ii];
2114 int32 shm_id =
2115 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryId;
2116 uint32 shm_offset =
2117 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryOffset;
2118 DoTexImage2D(face,
2120 GL_RGBA,
2124 GL_RGBA,
2125 GL_UNSIGNED_BYTE,
2126 shm_id,
2127 shm_offset);
2128 DoTexImage2D(face,
2130 GL_RGBA,
2134 GL_RGBA,
2135 GL_UNSIGNED_BYTE,
2136 shm_id,
2137 shm_offset);
2139 // Expect 2 levels will be cleared.
2140 SetupClearTextureExpectations(kServiceTextureId,
2141 kServiceTextureId,
2142 GL_TEXTURE_CUBE_MAP,
2143 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2145 GL_RGBA,
2146 GL_RGBA,
2147 GL_UNSIGNED_BYTE,
2150 SetupClearTextureExpectations(kServiceTextureId,
2151 kServiceTextureId,
2152 GL_TEXTURE_CUBE_MAP,
2153 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2155 GL_RGBA,
2156 GL_RGBA,
2157 GL_UNSIGNED_BYTE,
2160 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2161 SetupExpectationsForApplyingDefaultDirtyState();
2162 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2163 .Times(1)
2164 .RetiresOnSaturation();
2165 DrawArrays cmd;
2166 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2167 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2170 TEST_P(GLES2DecoderWithShaderTest,
2171 DrawClearsAfterRenderbuffersWithMultipleAttachments) {
2172 const GLuint kFBOClientTextureId = 4100;
2173 const GLuint kFBOServiceTextureId = 4101;
2175 // Register a texture id.
2176 EXPECT_CALL(*gl_, GenTextures(_, _))
2177 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2178 .RetiresOnSaturation();
2179 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2181 // Setup "render to" texture.
2182 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2183 DoTexImage2D(
2184 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2185 DoBindFramebuffer(
2186 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2187 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2188 GL_COLOR_ATTACHMENT0,
2189 GL_TEXTURE_2D,
2190 kFBOClientTextureId,
2191 kFBOServiceTextureId,
2193 GL_NO_ERROR);
2195 DoBindRenderbuffer(
2196 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
2197 DoBindFramebuffer(
2198 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2199 DoRenderbufferStorage(GL_RENDERBUFFER,
2200 GL_DEPTH_COMPONENT16,
2201 GL_DEPTH_COMPONENT,
2204 GL_NO_ERROR);
2205 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
2206 GL_DEPTH_ATTACHMENT,
2207 GL_RENDERBUFFER,
2208 client_renderbuffer_id_,
2209 kServiceRenderbufferId,
2210 GL_NO_ERROR);
2212 SetupTexture();
2213 SetupExpectationsForFramebufferClearing(
2214 GL_FRAMEBUFFER, // target
2215 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, // clear bits
2219 0, // color
2220 0, // stencil
2221 1.0f, // depth
2222 false); // scissor test
2224 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2225 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2226 true, // Framebuffer has depth
2227 false, // Framebuffer has stencil
2228 0x1111, // color bits
2229 true, // depth mask
2230 false, // depth enabled
2231 0, // front stencil mask
2232 0, // back stencil mask
2233 false); // stencil enabled
2235 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2236 .Times(1)
2237 .RetiresOnSaturation();
2238 DrawArrays cmd;
2239 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2240 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2241 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2244 TEST_P(GLES2DecoderWithShaderTest,
2245 DrawingWithFBOTwiceChecksForFBOCompleteOnce) {
2246 const GLuint kFBOClientTextureId = 4100;
2247 const GLuint kFBOServiceTextureId = 4101;
2249 SetupAllNeededVertexBuffers();
2251 // Register a texture id.
2252 EXPECT_CALL(*gl_, GenTextures(_, _))
2253 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2254 .RetiresOnSaturation();
2255 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2257 // Setup "render to" texture that is cleared.
2258 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2259 DoTexImage2D(GL_TEXTURE_2D,
2261 GL_RGBA,
2265 GL_RGBA,
2266 GL_UNSIGNED_BYTE,
2267 kSharedMemoryId,
2268 kSharedMemoryOffset);
2269 DoBindFramebuffer(
2270 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2271 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2272 GL_COLOR_ATTACHMENT0,
2273 GL_TEXTURE_2D,
2274 kFBOClientTextureId,
2275 kFBOServiceTextureId,
2277 GL_NO_ERROR);
2279 // Setup "render from" texture.
2280 SetupTexture();
2282 // Make sure we check for framebuffer complete.
2283 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
2284 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
2285 .RetiresOnSaturation();
2287 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2288 false, // Framebuffer has depth
2289 false, // Framebuffer has stencil
2290 0x1111, // color bits
2291 false, // depth mask
2292 false, // depth enabled
2293 0, // front stencil mask
2294 0, // back stencil mask
2295 false); // stencil enabled
2297 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2298 .Times(1)
2299 .RetiresOnSaturation();
2300 DrawArrays cmd;
2301 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2302 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2303 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2305 // But not again.
2306 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2307 .Times(1)
2308 .RetiresOnSaturation();
2309 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2310 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2313 TEST_P(GLES2DecoderManualInitTest, DrawClearsDepthTexture) {
2314 InitState init;
2315 init.extensions = "GL_ANGLE_depth_texture";
2316 init.gl_version = "opengl es 2.0";
2317 init.has_alpha = true;
2318 init.has_depth = true;
2319 init.request_alpha = true;
2320 init.request_depth = true;
2321 init.bind_generates_resource = true;
2322 InitDecoder(init);
2324 SetupDefaultProgram();
2325 SetupAllNeededVertexBuffers();
2326 const GLenum attachment = GL_DEPTH_ATTACHMENT;
2327 const GLenum target = GL_TEXTURE_2D;
2328 const GLint level = 0;
2329 DoBindTexture(target, client_texture_id_, kServiceTextureId);
2331 // Create a depth texture.
2332 DoTexImage2D(target,
2333 level,
2334 GL_DEPTH_COMPONENT,
2338 GL_DEPTH_COMPONENT,
2339 GL_UNSIGNED_INT,
2343 // Enable GL_SCISSOR_TEST to make sure we disable it in the clear,
2344 // then re-enable it.
2345 DoEnableDisable(GL_SCISSOR_TEST, true);
2347 EXPECT_CALL(*gl_, GenFramebuffersEXT(1, _)).Times(1).RetiresOnSaturation();
2348 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, _))
2349 .Times(1)
2350 .RetiresOnSaturation();
2352 EXPECT_CALL(*gl_,
2353 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT,
2354 attachment,
2355 target,
2356 kServiceTextureId,
2357 level))
2358 .Times(1)
2359 .RetiresOnSaturation();
2360 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT))
2361 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
2362 .RetiresOnSaturation();
2364 EXPECT_CALL(*gl_, ClearStencil(0)).Times(1).RetiresOnSaturation();
2365 SetupExpectationsForStencilMask(GLES2Decoder::kDefaultStencilMask,
2366 GLES2Decoder::kDefaultStencilMask);
2367 EXPECT_CALL(*gl_, ClearDepth(1.0f)).Times(1).RetiresOnSaturation();
2368 SetupExpectationsForDepthMask(true);
2369 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, false);
2371 EXPECT_CALL(*gl_, Clear(GL_DEPTH_BUFFER_BIT)).Times(1).RetiresOnSaturation();
2373 SetupExpectationsForRestoreClearState(0.0f, 0.0f, 0.0f, 0.0f, 0, 1.0f, true);
2375 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, _)).Times(1).RetiresOnSaturation();
2376 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0))
2377 .Times(1)
2378 .RetiresOnSaturation();
2380 SetupExpectationsForApplyingDefaultDirtyState();
2381 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2382 .Times(1)
2383 .RetiresOnSaturation();
2384 DrawArrays cmd;
2385 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2386 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2387 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2390 } // namespace gles2
2391 } // namespace gpu