Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_drawing.cc
blobfc5e2de2210635fd13febb3e0473920495c68be0
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
14 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
15 #include "gpu/command_buffer/service/context_group.h"
16 #include "gpu/command_buffer/service/context_state.h"
17 #include "gpu/command_buffer/service/gl_surface_mock.h"
18 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
20 #include "gpu/command_buffer/service/gpu_switches.h"
21 #include "gpu/command_buffer/service/image_manager.h"
22 #include "gpu/command_buffer/service/mailbox_manager.h"
23 #include "gpu/command_buffer/service/mocks.h"
24 #include "gpu/command_buffer/service/program_manager.h"
25 #include "gpu/command_buffer/service/test_helper.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gl/gl_implementation.h"
28 #include "ui/gl/gl_mock.h"
29 #include "ui/gl/gl_surface_stub.h"
31 #if !defined(GL_DEPTH24_STENCIL8)
32 #define GL_DEPTH24_STENCIL8 0x88F0
33 #endif
35 using ::gfx::MockGLInterface;
36 using ::testing::_;
37 using ::testing::DoAll;
38 using ::testing::InSequence;
39 using ::testing::Invoke;
40 using ::testing::MatcherCast;
41 using ::testing::Mock;
42 using ::testing::Pointee;
43 using ::testing::Return;
44 using ::testing::SaveArg;
45 using ::testing::SetArrayArgument;
46 using ::testing::SetArgumentPointee;
47 using ::testing::SetArgPointee;
48 using ::testing::StrEq;
49 using ::testing::StrictMock;
51 namespace gpu {
52 namespace gles2 {
54 using namespace cmds;
56 class GLES2DecoderGeometryInstancingTest : public GLES2DecoderWithShaderTest {
57 public:
58 GLES2DecoderGeometryInstancingTest() : GLES2DecoderWithShaderTest() {}
60 void SetUp() override {
61 InitState init;
62 init.extensions = "GL_ANGLE_instanced_arrays";
63 // 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 that we lose context.
743 TEST_P(GLES2DecoderManualInitTest, LoseContextWhenOOM) {
744 InitState init;
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 base::CommandLine command_line(0, NULL);
857 command_line.AppendSwitchASCII(
858 switches::kGpuDriverBugWorkarounds,
859 base::IntToString(gpu::INIT_VERTEX_ATTRIBUTES));
860 InitState init;
861 init.has_alpha = true;
862 init.has_depth = true;
863 init.request_alpha = true;
864 init.request_depth = true;
865 init.bind_generates_resource = true;
866 InitDecoderWithCommandLine(init, &command_line);
867 SetupDefaultProgram();
868 SetupTexture();
869 SetupVertexBuffer();
870 DoEnableVertexAttribArray(1);
871 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
872 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
873 SetupExpectationsForApplyingDefaultDirtyState();
875 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
876 .Times(1)
877 .RetiresOnSaturation();
878 DrawArrays cmd;
879 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
880 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
881 EXPECT_EQ(GL_NO_ERROR, GetGLError());
884 TEST_P(GLES2DecoderWithShaderTest, DrawArraysDeletedBufferFails) {
885 SetupVertexBuffer();
886 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
887 DeleteVertexBuffer();
889 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
890 DrawArrays cmd;
891 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
892 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
893 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
896 TEST_P(GLES2DecoderWithShaderTest, DrawArraysDeletedProgramSucceeds) {
897 SetupTexture();
898 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
899 SetupExpectationsForApplyingDefaultDirtyState();
900 DoDeleteProgram(client_program_id_, kServiceProgramId);
902 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(1).RetiresOnSaturation();
903 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId)).Times(1);
904 DrawArrays cmd;
905 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
906 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
907 EXPECT_EQ(GL_NO_ERROR, GetGLError());
910 TEST_P(GLES2DecoderWithShaderTest, DrawArraysWithInvalidModeFails) {
911 SetupVertexBuffer();
912 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
914 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
915 DrawArrays cmd;
916 cmd.Init(GL_QUADS, 0, 1);
917 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
918 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
919 cmd.Init(GL_POLYGON, 0, 1);
920 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
921 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
924 TEST_P(GLES2DecoderWithShaderTest, DrawArraysInvalidCountFails) {
925 SetupVertexBuffer();
926 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
928 // Try start > 0
929 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
930 DrawArrays cmd;
931 cmd.Init(GL_TRIANGLES, 1, kNumVertices);
932 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
933 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
934 EXPECT_EQ(GL_NO_ERROR, GetGLError());
936 // Try with count > size
937 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1);
938 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
939 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
940 EXPECT_EQ(GL_NO_ERROR, GetGLError());
942 // Try with attrib offset > 0
943 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
944 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 4);
945 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
946 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
947 EXPECT_EQ(GL_NO_ERROR, GetGLError());
949 // Try with size > 2 (ie, vec3 instead of vec2)
950 DoVertexAttribPointer(1, 3, GL_FLOAT, 0, 0);
951 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
952 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
953 EXPECT_EQ(GL_NO_ERROR, GetGLError());
955 // Try with stride > 8 (vec2 + vec2 byte)
956 DoVertexAttribPointer(1, 2, GL_FLOAT, sizeof(GLfloat) * 3, 0);
957 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
958 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
959 EXPECT_EQ(GL_NO_ERROR, GetGLError());
962 TEST_P(GLES2DecoderWithShaderTest, DrawArraysInstancedANGLEFails) {
963 SetupTexture();
964 SetupVertexBuffer();
965 DoEnableVertexAttribArray(1);
966 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
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(GLES2DecoderWithShaderTest, VertexAttribDivisorANGLEFails) {
978 SetupTexture();
979 SetupVertexBuffer();
980 DoEnableVertexAttribArray(1);
981 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
983 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(_, _))
984 .Times(0)
985 .RetiresOnSaturation();
987 VertexAttribDivisorANGLE cmd;
988 cmd.Init(0, 1);
989 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
990 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
993 TEST_P(GLES2DecoderGeometryInstancingTest,
994 DrawArraysInstancedANGLENoAttributesFails) {
995 SetupTexture();
997 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
998 .Times(0)
999 .RetiresOnSaturation();
1000 DrawArraysInstancedANGLE cmd;
1001 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1002 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1003 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1006 TEST_P(GLES2DecoderGeometryInstancingTest,
1007 DrawArraysInstancedANGLESimulatedAttrib0) {
1008 SetupTexture();
1009 SetupVertexBuffer();
1010 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1012 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
1013 SetupExpectationsForApplyingDefaultDirtyState();
1015 DoVertexAttribDivisorANGLE(0, 1);
1016 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 3))
1017 .Times(1)
1018 .RetiresOnSaturation();
1019 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
1020 .Times(1)
1021 .RetiresOnSaturation();
1022 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
1023 .Times(1)
1024 .RetiresOnSaturation();
1025 DrawArraysInstancedANGLE cmd;
1026 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 3);
1027 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1028 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1031 TEST_P(GLES2DecoderGeometryInstancingTest,
1032 DrawArraysInstancedANGLEMissingAttributesFails) {
1033 DoEnableVertexAttribArray(1);
1035 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1036 DrawArraysInstancedANGLE cmd;
1037 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1038 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1039 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1042 TEST_P(GLES2DecoderGeometryInstancingTest,
1043 DrawArraysInstancedANGLEMissingAttributesZeroCountSucceeds) {
1044 DoEnableVertexAttribArray(1);
1046 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1047 DrawArraysInstancedANGLE cmd;
1048 cmd.Init(GL_TRIANGLES, 0, 0, 1);
1049 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1050 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1053 TEST_P(GLES2DecoderGeometryInstancingTest,
1054 DrawArraysInstancedANGLEValidAttributesSucceeds) {
1055 SetupTexture();
1056 SetupVertexBuffer();
1057 DoEnableVertexAttribArray(1);
1058 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1059 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
1060 SetupExpectationsForApplyingDefaultDirtyState();
1062 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 1))
1063 .Times(1)
1064 .RetiresOnSaturation();
1065 DrawArraysInstancedANGLE cmd;
1066 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1067 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1068 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1071 TEST_P(GLES2DecoderGeometryInstancingTest,
1072 DrawArraysInstancedANGLEWithInvalidModeFails) {
1073 SetupVertexBuffer();
1074 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1076 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1077 DrawArraysInstancedANGLE cmd;
1078 cmd.Init(GL_QUADS, 0, 1, 1);
1079 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1080 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1081 cmd.Init(GL_POLYGON, 0, 1, 1);
1082 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1083 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1086 TEST_P(GLES2DecoderGeometryInstancingTest,
1087 DrawArraysInstancedANGLEInvalidPrimcountFails) {
1088 SetupVertexBuffer();
1089 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1091 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _)).Times(0);
1092 DrawArraysInstancedANGLE cmd;
1093 cmd.Init(GL_TRIANGLES, 0, 1, -1);
1094 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1095 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1098 // Per-instance data is twice as large, but number of instances is half
1099 TEST_P(GLES2DecoderGeometryInstancingTest,
1100 DrawArraysInstancedANGLELargeInstanceSucceeds) {
1101 SetupTexture();
1102 SetupVertexBuffer();
1103 SetupExpectationsForApplyingDefaultDirtyState();
1104 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1106 DoEnableVertexAttribArray(0);
1107 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1108 DoVertexAttribDivisorANGLE(0, 1);
1109 EXPECT_CALL(
1110 *gl_,
1111 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2))
1112 .Times(1)
1113 .RetiresOnSaturation();
1114 DrawArraysInstancedANGLE cmd;
1115 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2);
1116 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1117 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1120 // Regular drawArrays takes the divisor into account
1121 TEST_P(GLES2DecoderGeometryInstancingTest,
1122 DrawArraysWithDivisorSucceeds) {
1123 SetupTexture();
1124 SetupVertexBuffer();
1125 SetupExpectationsForApplyingDefaultDirtyState();
1126 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1128 DoEnableVertexAttribArray(0);
1129 // Access the data right at the end of the buffer.
1130 DoVertexAttribPointer(
1131 0, 2, GL_FLOAT, 0, (kNumVertices - 1) * 2 * sizeof(GLfloat));
1132 DoVertexAttribDivisorANGLE(0, 1);
1133 EXPECT_CALL(
1134 *gl_,
1135 DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1136 .Times(1)
1137 .RetiresOnSaturation();
1138 DrawArrays cmd;
1139 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1140 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1141 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1144 // Per-instance data is twice as large, but divisor is twice
1145 TEST_P(GLES2DecoderGeometryInstancingTest,
1146 DrawArraysInstancedANGLELargeDivisorSucceeds) {
1147 SetupTexture();
1148 SetupVertexBuffer();
1149 SetupExpectationsForApplyingDefaultDirtyState();
1150 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1152 DoEnableVertexAttribArray(0);
1153 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1154 DoVertexAttribDivisorANGLE(0, 2);
1155 EXPECT_CALL(
1156 *gl_,
1157 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, kNumVertices))
1158 .Times(1)
1159 .RetiresOnSaturation();
1160 DrawArraysInstancedANGLE cmd;
1161 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices);
1162 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1163 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1166 TEST_P(GLES2DecoderGeometryInstancingTest, DrawArraysInstancedANGLELargeFails) {
1167 SetupTexture();
1168 SetupVertexBuffer();
1169 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1171 DoEnableVertexAttribArray(0);
1172 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1173 DoVertexAttribDivisorANGLE(0, 1);
1174 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1175 .Times(0)
1176 .RetiresOnSaturation();
1177 DrawArraysInstancedANGLE cmd;
1178 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices + 1);
1179 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1180 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1181 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1183 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1184 .Times(0)
1185 .RetiresOnSaturation();
1186 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1, kNumVertices);
1187 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1188 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1189 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1192 // Per-index data is twice as large, but number of indices is half
1193 TEST_P(GLES2DecoderGeometryInstancingTest,
1194 DrawArraysInstancedANGLELargeIndexSucceeds) {
1195 SetupTexture();
1196 SetupVertexBuffer();
1197 SetupExpectationsForApplyingDefaultDirtyState();
1198 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
1200 DoEnableVertexAttribArray(0);
1201 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1202 DoVertexAttribDivisorANGLE(0, 1);
1203 EXPECT_CALL(
1204 *gl_,
1205 DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices))
1206 .Times(1)
1207 .RetiresOnSaturation();
1208 DrawArraysInstancedANGLE cmd;
1209 cmd.Init(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices);
1210 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1211 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1214 TEST_P(GLES2DecoderGeometryInstancingTest,
1215 DrawArraysInstancedANGLENoDivisor0Fails) {
1216 SetupTexture();
1217 SetupVertexBuffer();
1218 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1220 DoEnableVertexAttribArray(0);
1221 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1222 DoVertexAttribDivisorANGLE(0, 1);
1223 DoVertexAttribDivisorANGLE(1, 1);
1224 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
1225 .Times(0)
1226 .RetiresOnSaturation();
1227 DrawArraysInstancedANGLE cmd;
1228 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
1229 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1230 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1231 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1234 TEST_P(GLES2DecoderGeometryInstancingTest,
1235 DrawArraysNoDivisor0Fails) {
1236 SetupTexture();
1237 SetupVertexBuffer();
1238 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1240 DoEnableVertexAttribArray(0);
1241 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1242 DoVertexAttribDivisorANGLE(0, 1);
1243 DoVertexAttribDivisorANGLE(1, 1);
1244 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
1245 .Times(0)
1246 .RetiresOnSaturation();
1247 DrawArrays cmd;
1248 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1249 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1250 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1251 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1254 TEST_P(GLES2DecoderWithShaderTest, DrawElementsNoAttributesSucceeds) {
1255 SetupTexture();
1256 SetupIndexBuffer();
1257 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
1258 SetupExpectationsForApplyingDefaultDirtyState();
1259 EXPECT_CALL(*gl_,
1260 DrawElements(GL_TRIANGLES,
1261 kValidIndexRangeCount,
1262 GL_UNSIGNED_SHORT,
1263 BufferOffset(kValidIndexRangeStart * 2)))
1264 .Times(1)
1265 .RetiresOnSaturation();
1266 DrawElements cmd;
1267 cmd.Init(GL_TRIANGLES,
1268 kValidIndexRangeCount,
1269 GL_UNSIGNED_SHORT,
1270 kValidIndexRangeStart * 2);
1271 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1272 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1275 TEST_P(GLES2DecoderWithShaderTest, DrawElementsMissingAttributesFails) {
1276 SetupIndexBuffer();
1277 DoEnableVertexAttribArray(1);
1279 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1280 DrawElements cmd;
1281 cmd.Init(GL_TRIANGLES,
1282 kValidIndexRangeCount,
1283 GL_UNSIGNED_SHORT,
1284 kValidIndexRangeStart * 2);
1285 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1286 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1289 TEST_P(GLES2DecoderWithShaderTest,
1290 DrawElementsMissingAttributesZeroCountSucceeds) {
1291 SetupIndexBuffer();
1292 DoEnableVertexAttribArray(1);
1294 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1295 DrawElements cmd;
1296 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2);
1297 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1298 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1301 TEST_P(GLES2DecoderWithShaderTest, DrawElementsExtraAttributesFails) {
1302 SetupIndexBuffer();
1303 DoEnableVertexAttribArray(6);
1305 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1306 DrawElements cmd;
1307 cmd.Init(GL_TRIANGLES,
1308 kValidIndexRangeCount,
1309 GL_UNSIGNED_SHORT,
1310 kValidIndexRangeStart * 2);
1311 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1312 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1315 TEST_P(GLES2DecoderWithShaderTest, DrawElementsValidAttributesSucceeds) {
1316 SetupTexture();
1317 SetupVertexBuffer();
1318 SetupIndexBuffer();
1319 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1320 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1321 SetupExpectationsForApplyingDefaultDirtyState();
1323 EXPECT_CALL(*gl_,
1324 DrawElements(GL_TRIANGLES,
1325 kValidIndexRangeCount,
1326 GL_UNSIGNED_SHORT,
1327 BufferOffset(kValidIndexRangeStart * 2)))
1328 .Times(1)
1329 .RetiresOnSaturation();
1330 DrawElements cmd;
1331 cmd.Init(GL_TRIANGLES,
1332 kValidIndexRangeCount,
1333 GL_UNSIGNED_SHORT,
1334 kValidIndexRangeStart * 2);
1335 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1336 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1339 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedBufferFails) {
1340 SetupVertexBuffer();
1341 SetupIndexBuffer();
1342 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1343 DeleteIndexBuffer();
1345 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1346 DrawElements cmd;
1347 cmd.Init(GL_TRIANGLES,
1348 kValidIndexRangeCount,
1349 GL_UNSIGNED_SHORT,
1350 kValidIndexRangeStart * 2);
1351 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1352 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1355 TEST_P(GLES2DecoderWithShaderTest, DrawElementsDeletedProgramSucceeds) {
1356 SetupTexture();
1357 SetupIndexBuffer();
1358 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
1359 SetupExpectationsForApplyingDefaultDirtyState();
1360 DoDeleteProgram(client_program_id_, kServiceProgramId);
1362 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1);
1363 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId)).Times(1);
1364 DrawElements cmd;
1365 cmd.Init(GL_TRIANGLES,
1366 kValidIndexRangeCount,
1367 GL_UNSIGNED_SHORT,
1368 kValidIndexRangeStart * 2);
1369 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1370 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1373 TEST_P(GLES2DecoderWithShaderTest, DrawElementsWithInvalidModeFails) {
1374 SetupVertexBuffer();
1375 SetupIndexBuffer();
1376 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1378 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1379 DrawElements cmd;
1380 cmd.Init(GL_QUADS,
1381 kValidIndexRangeCount,
1382 GL_UNSIGNED_SHORT,
1383 kValidIndexRangeStart * 2);
1384 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1385 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1386 cmd.Init(GL_POLYGON,
1387 kValidIndexRangeCount,
1388 GL_UNSIGNED_SHORT,
1389 kValidIndexRangeStart);
1390 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1391 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1394 TEST_P(GLES2DecoderWithShaderTest, DrawElementsInvalidCountFails) {
1395 SetupVertexBuffer();
1396 SetupIndexBuffer();
1397 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1399 // Try start > 0
1400 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1401 DrawElements cmd;
1402 cmd.Init(GL_TRIANGLES, kNumIndices, GL_UNSIGNED_SHORT, 2);
1403 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1404 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1405 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1407 // Try with count > size
1408 cmd.Init(GL_TRIANGLES, kNumIndices + 1, GL_UNSIGNED_SHORT, 0);
1409 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1410 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1411 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1414 TEST_P(GLES2DecoderWithShaderTest, DrawElementsOutOfRangeIndicesFails) {
1415 SetupVertexBuffer();
1416 SetupIndexBuffer();
1417 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1419 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1420 DrawElements cmd;
1421 cmd.Init(GL_TRIANGLES,
1422 kInvalidIndexRangeCount,
1423 GL_UNSIGNED_SHORT,
1424 kInvalidIndexRangeStart * 2);
1425 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1426 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1427 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1430 TEST_P(GLES2DecoderWithShaderTest, DrawElementsOddOffsetForUint16Fails) {
1431 SetupVertexBuffer();
1432 SetupIndexBuffer();
1433 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1435 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
1436 DrawElements cmd;
1437 cmd.Init(GL_TRIANGLES, kInvalidIndexRangeCount, GL_UNSIGNED_SHORT, 1);
1438 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1439 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1440 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1443 TEST_P(GLES2DecoderWithShaderTest, DrawElementsInstancedANGLEFails) {
1444 SetupTexture();
1445 SetupVertexBuffer();
1446 SetupIndexBuffer();
1447 DoEnableVertexAttribArray(1);
1448 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1450 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1451 .Times(0)
1452 .RetiresOnSaturation();
1453 DrawElementsInstancedANGLE cmd;
1454 cmd.Init(GL_TRIANGLES,
1455 kValidIndexRangeCount,
1456 GL_UNSIGNED_SHORT,
1457 kValidIndexRangeStart * 2,
1459 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1460 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1463 TEST_P(GLES2DecoderGeometryInstancingTest,
1464 DrawElementsInstancedANGLENoAttributesFails) {
1465 SetupTexture();
1466 SetupIndexBuffer();
1468 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1469 .Times(0)
1470 .RetiresOnSaturation();
1471 DrawElementsInstancedANGLE cmd;
1472 cmd.Init(GL_TRIANGLES,
1473 kValidIndexRangeCount,
1474 GL_UNSIGNED_SHORT,
1475 kValidIndexRangeStart * 2,
1477 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1478 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1481 TEST_P(GLES2DecoderGeometryInstancingTest,
1482 DrawElementsInstancedANGLESimulatedAttrib0) {
1483 SetupTexture();
1484 SetupVertexBuffer();
1485 SetupIndexBuffer();
1486 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1488 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1489 SetupExpectationsForApplyingDefaultDirtyState();
1491 DoVertexAttribDivisorANGLE(0, 1);
1492 EXPECT_CALL(
1493 *gl_,
1494 DrawElementsInstancedANGLE(GL_TRIANGLES,
1495 kValidIndexRangeCount,
1496 GL_UNSIGNED_SHORT,
1497 BufferOffset(kValidIndexRangeStart * 2),
1499 .Times(1)
1500 .RetiresOnSaturation();
1501 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
1502 .Times(1)
1503 .RetiresOnSaturation();
1504 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
1505 .Times(1)
1506 .RetiresOnSaturation();
1507 DrawElementsInstancedANGLE cmd;
1508 cmd.Init(GL_TRIANGLES,
1509 kValidIndexRangeCount,
1510 GL_UNSIGNED_SHORT,
1511 kValidIndexRangeStart * 2,
1513 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1514 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1517 TEST_P(GLES2DecoderGeometryInstancingTest,
1518 DrawElementsInstancedANGLEMissingAttributesFails) {
1519 SetupIndexBuffer();
1520 DoEnableVertexAttribArray(1);
1522 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1523 DrawElementsInstancedANGLE cmd;
1524 cmd.Init(GL_TRIANGLES,
1525 kValidIndexRangeCount,
1526 GL_UNSIGNED_SHORT,
1527 kValidIndexRangeStart * 2,
1529 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1530 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1533 TEST_P(GLES2DecoderGeometryInstancingTest,
1534 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds) {
1535 SetupIndexBuffer();
1536 DoEnableVertexAttribArray(1);
1538 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1539 DrawElementsInstancedANGLE cmd;
1540 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, kValidIndexRangeStart * 2, 1);
1541 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1542 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1545 TEST_P(GLES2DecoderGeometryInstancingTest,
1546 DrawElementsInstancedANGLEValidAttributesSucceeds) {
1547 SetupIndexBuffer();
1548 SetupTexture();
1549 SetupVertexBuffer();
1550 DoEnableVertexAttribArray(1);
1551 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1552 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
1553 SetupExpectationsForApplyingDefaultDirtyState();
1555 EXPECT_CALL(
1556 *gl_,
1557 DrawElementsInstancedANGLE(GL_TRIANGLES,
1558 kValidIndexRangeCount,
1559 GL_UNSIGNED_SHORT,
1560 BufferOffset(kValidIndexRangeStart * 2),
1562 .Times(1)
1563 .RetiresOnSaturation();
1564 DrawElementsInstancedANGLE cmd;
1565 cmd.Init(GL_TRIANGLES,
1566 kValidIndexRangeCount,
1567 GL_UNSIGNED_SHORT,
1568 kValidIndexRangeStart * 2,
1570 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1571 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1574 TEST_P(GLES2DecoderGeometryInstancingTest,
1575 DrawElementsInstancedANGLEWithInvalidModeFails) {
1576 SetupIndexBuffer();
1577 SetupVertexBuffer();
1578 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1580 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _)).Times(0);
1581 DrawElementsInstancedANGLE cmd;
1582 cmd.Init(GL_QUADS,
1583 kValidIndexRangeCount,
1584 GL_UNSIGNED_SHORT,
1585 kValidIndexRangeStart * 2,
1587 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1588 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1589 cmd.Init(GL_INVALID_ENUM,
1590 kValidIndexRangeCount,
1591 GL_UNSIGNED_SHORT,
1592 kValidIndexRangeStart * 2,
1594 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1595 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1598 // Per-instance data is twice as large, but number of instances is half
1599 TEST_P(GLES2DecoderGeometryInstancingTest,
1600 DrawElementsInstancedANGLELargeInstanceSucceeds) {
1601 SetupTexture();
1602 SetupIndexBuffer();
1603 SetupVertexBuffer();
1604 SetupExpectationsForApplyingDefaultDirtyState();
1605 // Add offset so we're sure we're accessing data near the end of the buffer.
1606 DoVertexAttribPointer(
1609 GL_FLOAT,
1611 (kNumVertices - kMaxValidIndex - 1) * 2 * sizeof(GLfloat));
1613 DoEnableVertexAttribArray(0);
1614 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1615 DoVertexAttribDivisorANGLE(0, 1);
1616 EXPECT_CALL(
1617 *gl_,
1618 DrawElementsInstancedANGLE(GL_TRIANGLES,
1619 kValidIndexRangeCount,
1620 GL_UNSIGNED_SHORT,
1621 BufferOffset(kValidIndexRangeStart * 2),
1622 kNumVertices / 2))
1623 .Times(1)
1624 .RetiresOnSaturation();
1625 DrawElementsInstancedANGLE cmd;
1626 cmd.Init(GL_TRIANGLES,
1627 kValidIndexRangeCount,
1628 GL_UNSIGNED_SHORT,
1629 kValidIndexRangeStart * 2,
1630 kNumVertices / 2);
1631 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1632 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1635 // Regular drawElements takes the divisor into account
1636 TEST_P(GLES2DecoderGeometryInstancingTest,
1637 DrawElementsWithDivisorSucceeds) {
1638 SetupTexture();
1639 SetupIndexBuffer();
1640 SetupVertexBuffer();
1641 SetupExpectationsForApplyingDefaultDirtyState();
1642 // Add offset so we're sure we're accessing data near the end of the buffer.
1643 DoVertexAttribPointer(
1646 GL_FLOAT,
1648 (kNumVertices - kMaxValidIndex - 1) * 2 * sizeof(GLfloat));
1650 DoEnableVertexAttribArray(0);
1651 // Access the data right at the end of the buffer.
1652 DoVertexAttribPointer(
1653 0, 2, GL_FLOAT, 0, (kNumVertices - 1) * 2 * sizeof(GLfloat));
1654 DoVertexAttribDivisorANGLE(0, 1);
1655 EXPECT_CALL(
1656 *gl_,
1657 DrawElements(GL_TRIANGLES,
1658 kValidIndexRangeCount,
1659 GL_UNSIGNED_SHORT,
1660 BufferOffset(kValidIndexRangeStart * 2)))
1661 .Times(1)
1662 .RetiresOnSaturation();
1663 DrawElements cmd;
1664 cmd.Init(GL_TRIANGLES,
1665 kValidIndexRangeCount,
1666 GL_UNSIGNED_SHORT,
1667 kValidIndexRangeStart * 2);
1668 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1669 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1672 // Per-instance data is twice as large, but divisor is twice
1673 TEST_P(GLES2DecoderGeometryInstancingTest,
1674 DrawElementsInstancedANGLELargeDivisorSucceeds) {
1675 SetupTexture();
1676 SetupIndexBuffer();
1677 SetupVertexBuffer();
1678 SetupExpectationsForApplyingDefaultDirtyState();
1679 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1681 DoEnableVertexAttribArray(0);
1682 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
1683 DoVertexAttribDivisorANGLE(0, 2);
1684 EXPECT_CALL(
1685 *gl_,
1686 DrawElementsInstancedANGLE(GL_TRIANGLES,
1687 kValidIndexRangeCount,
1688 GL_UNSIGNED_SHORT,
1689 BufferOffset(kValidIndexRangeStart * 2),
1690 kNumVertices))
1691 .Times(1)
1692 .RetiresOnSaturation();
1693 DrawElementsInstancedANGLE cmd;
1694 cmd.Init(GL_TRIANGLES,
1695 kValidIndexRangeCount,
1696 GL_UNSIGNED_SHORT,
1697 kValidIndexRangeStart * 2,
1698 kNumVertices);
1699 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1700 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1703 TEST_P(GLES2DecoderGeometryInstancingTest,
1704 DrawElementsInstancedANGLELargeFails) {
1705 SetupTexture();
1706 SetupIndexBuffer();
1707 SetupVertexBuffer();
1708 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1710 DoEnableVertexAttribArray(0);
1711 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1712 DoVertexAttribDivisorANGLE(0, 1);
1713 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1714 .Times(0)
1715 .RetiresOnSaturation();
1716 DrawElementsInstancedANGLE cmd;
1717 cmd.Init(GL_TRIANGLES,
1718 kValidIndexRangeCount,
1719 GL_UNSIGNED_SHORT,
1720 kValidIndexRangeStart * 2,
1721 kNumVertices + 1);
1722 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1723 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1724 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1726 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1727 .Times(0)
1728 .RetiresOnSaturation();
1729 cmd.Init(GL_TRIANGLES,
1730 kInvalidIndexRangeCount,
1731 GL_UNSIGNED_SHORT,
1732 kInvalidIndexRangeStart * 2,
1733 kNumVertices);
1734 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1735 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1736 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1739 TEST_P(GLES2DecoderGeometryInstancingTest,
1740 DrawElementsInstancedANGLEInvalidPrimcountFails) {
1741 SetupTexture();
1742 SetupIndexBuffer();
1743 SetupVertexBuffer();
1744 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1746 DoEnableVertexAttribArray(0);
1747 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1748 DoVertexAttribDivisorANGLE(0, 1);
1749 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1750 .Times(0)
1751 .RetiresOnSaturation();
1752 DrawElementsInstancedANGLE cmd;
1753 cmd.Init(GL_TRIANGLES,
1754 kValidIndexRangeCount,
1755 GL_UNSIGNED_SHORT,
1756 kValidIndexRangeStart * 2,
1757 -1);
1758 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1759 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1760 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1763 // Per-index data is twice as large, but values of indices are smaller
1764 TEST_P(GLES2DecoderGeometryInstancingTest,
1765 DrawElementsInstancedANGLELargeIndexSucceeds) {
1766 SetupTexture();
1767 SetupIndexBuffer();
1768 SetupVertexBuffer();
1769 SetupExpectationsForApplyingDefaultDirtyState();
1770 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
1772 DoEnableVertexAttribArray(0);
1773 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1774 DoVertexAttribDivisorANGLE(0, 1);
1775 EXPECT_CALL(
1776 *gl_,
1777 DrawElementsInstancedANGLE(GL_TRIANGLES,
1778 kValidIndexRangeCount,
1779 GL_UNSIGNED_SHORT,
1780 BufferOffset(kValidIndexRangeStart * 2),
1781 kNumVertices))
1782 .Times(1)
1783 .RetiresOnSaturation();
1784 DrawElementsInstancedANGLE cmd;
1785 cmd.Init(GL_TRIANGLES,
1786 kValidIndexRangeCount,
1787 GL_UNSIGNED_SHORT,
1788 kValidIndexRangeStart * 2,
1789 kNumVertices);
1790 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1791 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1794 TEST_P(GLES2DecoderGeometryInstancingTest,
1795 DrawElementsInstancedANGLENoDivisor0Fails) {
1796 SetupTexture();
1797 SetupIndexBuffer();
1798 SetupVertexBuffer();
1799 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1801 DoEnableVertexAttribArray(0);
1802 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1803 DoVertexAttribDivisorANGLE(0, 1);
1804 DoVertexAttribDivisorANGLE(1, 1);
1805 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1806 .Times(0)
1807 .RetiresOnSaturation();
1808 DrawElementsInstancedANGLE cmd;
1809 cmd.Init(GL_TRIANGLES,
1810 kValidIndexRangeCount,
1811 GL_UNSIGNED_SHORT,
1812 kValidIndexRangeStart * 2,
1813 kNumVertices);
1814 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1815 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1816 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1819 TEST_P(GLES2DecoderGeometryInstancingTest,
1820 DrawElementsNoDivisor0Fails) {
1821 SetupTexture();
1822 SetupIndexBuffer();
1823 SetupVertexBuffer();
1824 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1826 DoEnableVertexAttribArray(0);
1827 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1828 DoVertexAttribDivisorANGLE(0, 1);
1829 DoVertexAttribDivisorANGLE(1, 1);
1830 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
1831 .Times(0)
1832 .RetiresOnSaturation();
1833 DrawElements cmd;
1834 cmd.Init(GL_TRIANGLES,
1835 kValidIndexRangeCount,
1836 GL_UNSIGNED_SHORT,
1837 kValidIndexRangeStart * 2);
1838 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1839 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1840 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1843 TEST_P(GLES2DecoderWithShaderTest, DrawArraysClearsAfterTexImage2DNULL) {
1844 SetupAllNeededVertexBuffers();
1845 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1846 // Create an uncleared texture with 2 levels.
1847 DoTexImage2D(
1848 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1849 DoTexImage2D(
1850 GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1851 // Expect 2 levels will be cleared.
1852 SetupClearTextureExpectations(kServiceTextureId,
1853 kServiceTextureId,
1854 GL_TEXTURE_2D,
1855 GL_TEXTURE_2D,
1857 GL_RGBA,
1858 GL_RGBA,
1859 GL_UNSIGNED_BYTE,
1862 SetupClearTextureExpectations(kServiceTextureId,
1863 kServiceTextureId,
1864 GL_TEXTURE_2D,
1865 GL_TEXTURE_2D,
1867 GL_RGBA,
1868 GL_RGBA,
1869 GL_UNSIGNED_BYTE,
1872 SetupExpectationsForApplyingDefaultDirtyState();
1873 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1874 .Times(1)
1875 .RetiresOnSaturation();
1876 DrawArrays cmd;
1877 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
1878 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1879 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1881 // But not again
1882 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1883 .Times(1)
1884 .RetiresOnSaturation();
1885 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1886 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1889 TEST_P(GLES2DecoderWithShaderTest, DrawElementsClearsAfterTexImage2DNULL) {
1890 SetupAllNeededVertexBuffers();
1891 SetupIndexBuffer();
1892 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1893 // Create an uncleared texture with 2 levels.
1894 DoTexImage2D(
1895 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1896 DoTexImage2D(
1897 GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1898 // Expect 2 levels will be cleared.
1899 SetupClearTextureExpectations(kServiceTextureId,
1900 kServiceTextureId,
1901 GL_TEXTURE_2D,
1902 GL_TEXTURE_2D,
1904 GL_RGBA,
1905 GL_RGBA,
1906 GL_UNSIGNED_BYTE,
1909 SetupClearTextureExpectations(kServiceTextureId,
1910 kServiceTextureId,
1911 GL_TEXTURE_2D,
1912 GL_TEXTURE_2D,
1914 GL_RGBA,
1915 GL_RGBA,
1916 GL_UNSIGNED_BYTE,
1919 SetupExpectationsForApplyingDefaultDirtyState();
1921 EXPECT_CALL(*gl_,
1922 DrawElements(GL_TRIANGLES,
1923 kValidIndexRangeCount,
1924 GL_UNSIGNED_SHORT,
1925 BufferOffset(kValidIndexRangeStart * 2)))
1926 .Times(1)
1927 .RetiresOnSaturation();
1928 DrawElements cmd;
1929 cmd.Init(GL_TRIANGLES,
1930 kValidIndexRangeCount,
1931 GL_UNSIGNED_SHORT,
1932 kValidIndexRangeStart * 2);
1933 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1934 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1936 // But not again
1937 EXPECT_CALL(*gl_,
1938 DrawElements(GL_TRIANGLES,
1939 kValidIndexRangeCount,
1940 GL_UNSIGNED_SHORT,
1941 BufferOffset(kValidIndexRangeStart * 2)))
1942 .Times(1)
1943 .RetiresOnSaturation();
1944 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1945 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1948 TEST_P(GLES2DecoderWithShaderTest, DrawClearsAfterTexImage2DNULLInFBO) {
1949 const GLuint kFBOClientTextureId = 4100;
1950 const GLuint kFBOServiceTextureId = 4101;
1952 SetupAllNeededVertexBuffers();
1953 // Register a texture id.
1954 EXPECT_CALL(*gl_, GenTextures(_, _))
1955 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1956 .RetiresOnSaturation();
1957 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1959 // Setup "render to" texture.
1960 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1961 DoTexImage2D(
1962 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1963 DoBindFramebuffer(
1964 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1965 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1966 GL_COLOR_ATTACHMENT0,
1967 GL_TEXTURE_2D,
1968 kFBOClientTextureId,
1969 kFBOServiceTextureId,
1971 GL_NO_ERROR);
1973 // Setup "render from" texture.
1974 SetupTexture();
1976 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1977 GL_COLOR_BUFFER_BIT, // clear bits
1981 0, // color
1982 0, // stencil
1983 1.0f, // depth
1984 false); // scissor test
1986 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1987 false, // Framebuffer has depth
1988 false, // Framebuffer has stencil
1989 0x1111, // color bits
1990 false, // depth mask
1991 false, // depth enabled
1992 0, // front stencil mask
1993 0, // back stencil mask
1994 false); // stencil enabled
1996 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1997 .Times(1)
1998 .RetiresOnSaturation();
1999 DrawArrays cmd;
2000 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2001 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2002 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2004 // But not again.
2005 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2006 .Times(1)
2007 .RetiresOnSaturation();
2008 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2009 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2012 TEST_P(GLES2DecoderWithShaderTest, DrawWitFBOThatCantClearDoesNotDraw) {
2013 const GLuint kFBOClientTextureId = 4100;
2014 const GLuint kFBOServiceTextureId = 4101;
2016 // Register a texture id.
2017 EXPECT_CALL(*gl_, GenTextures(_, _))
2018 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2019 .RetiresOnSaturation();
2020 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2022 // Setup "render to" texture.
2023 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2024 DoTexImage2D(
2025 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2026 DoBindFramebuffer(
2027 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2028 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2029 GL_COLOR_ATTACHMENT0,
2030 GL_TEXTURE_2D,
2031 kFBOClientTextureId,
2032 kFBOServiceTextureId,
2034 GL_NO_ERROR);
2036 // Setup "render from" texture.
2037 SetupTexture();
2039 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
2040 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED))
2041 .RetiresOnSaturation();
2042 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
2043 DrawArrays cmd;
2044 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2045 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2046 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
2049 TEST_P(GLES2DecoderWithShaderTest, DrawClearsAfterRenderbufferStorageInFBO) {
2050 SetupTexture();
2051 DoBindRenderbuffer(
2052 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
2053 DoBindFramebuffer(
2054 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2055 DoRenderbufferStorage(
2056 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 100, 50, GL_NO_ERROR);
2057 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
2058 GL_COLOR_ATTACHMENT0,
2059 GL_RENDERBUFFER,
2060 client_renderbuffer_id_,
2061 kServiceRenderbufferId,
2062 GL_NO_ERROR);
2064 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
2065 GL_COLOR_BUFFER_BIT, // clear bits
2069 0, // color
2070 0, // stencil
2071 1.0f, // depth
2072 false); // scissor test
2074 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2075 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2076 false, // Framebuffer has depth
2077 false, // Framebuffer has stencil
2078 0x1111, // color bits
2079 false, // depth mask
2080 false, // depth enabled
2081 0, // front stencil mask
2082 0, // back stencil mask
2083 false); // stencil enabled
2085 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2086 .Times(1)
2087 .RetiresOnSaturation();
2088 DrawArrays cmd;
2089 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2090 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2091 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2094 TEST_P(GLES2DecoderManualInitTest, DrawArraysClearsAfterTexImage2DNULLCubemap) {
2095 InitState init;
2096 init.gl_version = "opengl es 2.0";
2097 init.has_alpha = true;
2098 init.has_depth = true;
2099 init.request_alpha = true;
2100 init.request_depth = true;
2101 InitDecoder(init);
2103 static const GLenum faces[] = {
2104 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
2105 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2106 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
2108 SetupCubemapProgram();
2109 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2110 // Fill out all the faces for 2 levels, leave 2 uncleared.
2111 for (int ii = 0; ii < 6; ++ii) {
2112 GLenum face = faces[ii];
2113 int32 shm_id =
2114 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryId;
2115 uint32 shm_offset =
2116 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryOffset;
2117 DoTexImage2D(face,
2119 GL_RGBA,
2123 GL_RGBA,
2124 GL_UNSIGNED_BYTE,
2125 shm_id,
2126 shm_offset);
2127 DoTexImage2D(face,
2129 GL_RGBA,
2133 GL_RGBA,
2134 GL_UNSIGNED_BYTE,
2135 shm_id,
2136 shm_offset);
2138 // Expect 2 levels will be cleared.
2139 SetupClearTextureExpectations(kServiceTextureId,
2140 kServiceTextureId,
2141 GL_TEXTURE_CUBE_MAP,
2142 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2144 GL_RGBA,
2145 GL_RGBA,
2146 GL_UNSIGNED_BYTE,
2149 SetupClearTextureExpectations(kServiceTextureId,
2150 kServiceTextureId,
2151 GL_TEXTURE_CUBE_MAP,
2152 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
2154 GL_RGBA,
2155 GL_RGBA,
2156 GL_UNSIGNED_BYTE,
2159 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2160 SetupExpectationsForApplyingDefaultDirtyState();
2161 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2162 .Times(1)
2163 .RetiresOnSaturation();
2164 DrawArrays cmd;
2165 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2166 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2169 TEST_P(GLES2DecoderWithShaderTest,
2170 DrawClearsAfterRenderbuffersWithMultipleAttachments) {
2171 const GLuint kFBOClientTextureId = 4100;
2172 const GLuint kFBOServiceTextureId = 4101;
2174 // Register a texture id.
2175 EXPECT_CALL(*gl_, GenTextures(_, _))
2176 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2177 .RetiresOnSaturation();
2178 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2180 // Setup "render to" texture.
2181 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2182 DoTexImage2D(
2183 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2184 DoBindFramebuffer(
2185 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2186 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2187 GL_COLOR_ATTACHMENT0,
2188 GL_TEXTURE_2D,
2189 kFBOClientTextureId,
2190 kFBOServiceTextureId,
2192 GL_NO_ERROR);
2194 DoBindRenderbuffer(
2195 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
2196 DoBindFramebuffer(
2197 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2198 DoRenderbufferStorage(GL_RENDERBUFFER,
2199 GL_DEPTH_COMPONENT16,
2200 GL_DEPTH_COMPONENT,
2203 GL_NO_ERROR);
2204 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
2205 GL_DEPTH_ATTACHMENT,
2206 GL_RENDERBUFFER,
2207 client_renderbuffer_id_,
2208 kServiceRenderbufferId,
2209 GL_NO_ERROR);
2211 SetupTexture();
2212 SetupExpectationsForFramebufferClearing(
2213 GL_FRAMEBUFFER, // target
2214 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, // clear bits
2218 0, // color
2219 0, // stencil
2220 1.0f, // depth
2221 false); // scissor test
2223 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2224 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2225 true, // Framebuffer has depth
2226 false, // Framebuffer has stencil
2227 0x1111, // color bits
2228 true, // depth mask
2229 false, // depth enabled
2230 0, // front stencil mask
2231 0, // back stencil mask
2232 false); // stencil enabled
2234 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2235 .Times(1)
2236 .RetiresOnSaturation();
2237 DrawArrays cmd;
2238 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2239 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2240 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2243 TEST_P(GLES2DecoderWithShaderTest,
2244 DrawingWithFBOTwiceChecksForFBOCompleteOnce) {
2245 const GLuint kFBOClientTextureId = 4100;
2246 const GLuint kFBOServiceTextureId = 4101;
2248 SetupAllNeededVertexBuffers();
2250 // Register a texture id.
2251 EXPECT_CALL(*gl_, GenTextures(_, _))
2252 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2253 .RetiresOnSaturation();
2254 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2256 // Setup "render to" texture that is cleared.
2257 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2258 DoTexImage2D(GL_TEXTURE_2D,
2260 GL_RGBA,
2264 GL_RGBA,
2265 GL_UNSIGNED_BYTE,
2266 kSharedMemoryId,
2267 kSharedMemoryOffset);
2268 DoBindFramebuffer(
2269 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2270 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2271 GL_COLOR_ATTACHMENT0,
2272 GL_TEXTURE_2D,
2273 kFBOClientTextureId,
2274 kFBOServiceTextureId,
2276 GL_NO_ERROR);
2278 // Setup "render from" texture.
2279 SetupTexture();
2281 // Make sure we check for framebuffer complete.
2282 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
2283 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
2284 .RetiresOnSaturation();
2286 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2287 false, // Framebuffer has depth
2288 false, // Framebuffer has stencil
2289 0x1111, // color bits
2290 false, // depth mask
2291 false, // depth enabled
2292 0, // front stencil mask
2293 0, // back stencil mask
2294 false); // stencil enabled
2296 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2297 .Times(1)
2298 .RetiresOnSaturation();
2299 DrawArrays cmd;
2300 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2301 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2302 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2304 // But not again.
2305 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2306 .Times(1)
2307 .RetiresOnSaturation();
2308 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2309 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2312 TEST_P(GLES2DecoderManualInitTest, DrawClearsDepthTexture) {
2313 InitState init;
2314 init.extensions = "GL_ANGLE_depth_texture";
2315 init.gl_version = "opengl es 2.0";
2316 init.has_alpha = true;
2317 init.has_depth = true;
2318 init.request_alpha = true;
2319 init.request_depth = true;
2320 init.bind_generates_resource = true;
2321 InitDecoder(init);
2323 SetupDefaultProgram();
2324 SetupAllNeededVertexBuffers();
2325 const GLenum attachment = GL_DEPTH_ATTACHMENT;
2326 const GLenum target = GL_TEXTURE_2D;
2327 const GLint level = 0;
2328 DoBindTexture(target, client_texture_id_, kServiceTextureId);
2330 // Create a depth texture.
2331 DoTexImage2D(target,
2332 level,
2333 GL_DEPTH_COMPONENT,
2337 GL_DEPTH_COMPONENT,
2338 GL_UNSIGNED_INT,
2342 // Enable GL_SCISSOR_TEST to make sure we disable it in the clear,
2343 // then re-enable it.
2344 DoEnableDisable(GL_SCISSOR_TEST, true);
2346 EXPECT_CALL(*gl_, GenFramebuffersEXT(1, _)).Times(1).RetiresOnSaturation();
2347 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, _))
2348 .Times(1)
2349 .RetiresOnSaturation();
2351 EXPECT_CALL(*gl_,
2352 FramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT,
2353 attachment,
2354 target,
2355 kServiceTextureId,
2356 level))
2357 .Times(1)
2358 .RetiresOnSaturation();
2359 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT))
2360 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
2361 .RetiresOnSaturation();
2363 EXPECT_CALL(*gl_, ClearStencil(0)).Times(1).RetiresOnSaturation();
2364 SetupExpectationsForStencilMask(GLES2Decoder::kDefaultStencilMask,
2365 GLES2Decoder::kDefaultStencilMask);
2366 EXPECT_CALL(*gl_, ClearDepth(1.0f)).Times(1).RetiresOnSaturation();
2367 SetupExpectationsForDepthMask(true);
2368 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, false);
2370 EXPECT_CALL(*gl_, Clear(GL_DEPTH_BUFFER_BIT)).Times(1).RetiresOnSaturation();
2372 SetupExpectationsForRestoreClearState(0.0f, 0.0f, 0.0f, 0.0f, 0, 1.0f, true);
2374 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, _)).Times(1).RetiresOnSaturation();
2375 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0))
2376 .Times(1)
2377 .RetiresOnSaturation();
2379 SetupExpectationsForApplyingDefaultDirtyState();
2380 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2381 .Times(1)
2382 .RetiresOnSaturation();
2383 DrawArrays cmd;
2384 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2385 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2386 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2389 } // namespace gles2
2390 } // namespace gpu