Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / service / framebuffer_manager_unittest.cc
blobc423764f45812eeb017a6603e9d97c326a3f9535
1 // Copyright (c) 2012 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/error_state_mock.h"
6 #include "gpu/command_buffer/service/framebuffer_manager.h"
7 #include "gpu/command_buffer/service/feature_info.h"
8 #include "gpu/command_buffer/service/gpu_service_test.h"
9 #include "gpu/command_buffer/service/renderbuffer_manager.h"
10 #include "gpu/command_buffer/service/test_helper.h"
11 #include "gpu/command_buffer/service/texture_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gl/gl_mock.h"
15 using ::testing::_;
16 using ::testing::Return;
18 namespace gpu {
19 namespace gles2 {
20 namespace {
22 const GLint kMaxTextureSize = 64;
23 const GLint kMaxCubemapSize = 64;
24 const GLint kMaxRectangleTextureSize = 64;
25 const GLint kMax3DTextureSize = 256;
26 const GLint kMaxRenderbufferSize = 64;
27 const GLint kMaxSamples = 4;
28 const uint32 kMaxDrawBuffers = 16;
29 const uint32 kMaxColorAttachments = 16;
30 const bool kUseDefaultTextures = false;
32 } // namespace
34 class FramebufferManagerTest : public GpuServiceTest {
35 public:
36 FramebufferManagerTest()
37 : manager_(1, 1, ContextGroup::CONTEXT_TYPE_UNDEFINED, NULL),
38 feature_info_(new FeatureInfo()) {
39 texture_manager_.reset(new TextureManager(NULL,
40 feature_info_.get(),
41 kMaxTextureSize,
42 kMaxCubemapSize,
43 kMaxRectangleTextureSize,
44 kMax3DTextureSize,
45 kUseDefaultTextures));
46 renderbuffer_manager_.reset(new RenderbufferManager(NULL,
47 kMaxRenderbufferSize,
48 kMaxSamples,
49 feature_info_.get()));
51 ~FramebufferManagerTest() override {
52 manager_.Destroy(false);
53 texture_manager_->Destroy(false);
54 renderbuffer_manager_->Destroy(false);
57 protected:
58 FramebufferManager manager_;
59 scoped_refptr<FeatureInfo> feature_info_;
60 scoped_ptr<TextureManager> texture_manager_;
61 scoped_ptr<RenderbufferManager> renderbuffer_manager_;
64 TEST_F(FramebufferManagerTest, Basic) {
65 const GLuint kClient1Id = 1;
66 const GLuint kService1Id = 11;
67 const GLuint kClient2Id = 2;
68 // Check we can create framebuffer.
69 manager_.CreateFramebuffer(kClient1Id, kService1Id);
70 // Check framebuffer got created.
71 Framebuffer* framebuffer1 = manager_.GetFramebuffer(kClient1Id);
72 ASSERT_TRUE(framebuffer1 != NULL);
73 EXPECT_FALSE(framebuffer1->IsDeleted());
74 EXPECT_EQ(kService1Id, framebuffer1->service_id());
75 GLuint client_id = 0;
76 EXPECT_TRUE(manager_.GetClientId(framebuffer1->service_id(), &client_id));
77 EXPECT_EQ(kClient1Id, client_id);
78 // Check we get nothing for a non-existent framebuffer.
79 EXPECT_TRUE(manager_.GetFramebuffer(kClient2Id) == NULL);
80 // Check trying to a remove non-existent framebuffers does not crash.
81 manager_.RemoveFramebuffer(kClient2Id);
82 // Check framebuffer gets deleted when last reference is released.
83 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, ::testing::Pointee(kService1Id)))
84 .Times(1)
85 .RetiresOnSaturation();
86 // Check we can't get the framebuffer after we remove it.
87 manager_.RemoveFramebuffer(kClient1Id);
88 EXPECT_TRUE(manager_.GetFramebuffer(kClient1Id) == NULL);
91 TEST_F(FramebufferManagerTest, Destroy) {
92 const GLuint kClient1Id = 1;
93 const GLuint kService1Id = 11;
94 // Check we can create framebuffer.
95 manager_.CreateFramebuffer(kClient1Id, kService1Id);
96 // Check framebuffer got created.
97 Framebuffer* framebuffer1 = manager_.GetFramebuffer(kClient1Id);
98 ASSERT_TRUE(framebuffer1 != NULL);
99 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, ::testing::Pointee(kService1Id)))
100 .Times(1)
101 .RetiresOnSaturation();
102 manager_.Destroy(true);
103 // Check the resources were released.
104 framebuffer1 = manager_.GetFramebuffer(kClient1Id);
105 ASSERT_TRUE(framebuffer1 == NULL);
108 class FramebufferInfoTestBase : public GpuServiceTest {
109 public:
110 static const GLuint kClient1Id = 1;
111 static const GLuint kService1Id = 11;
113 explicit FramebufferInfoTestBase(ContextGroup::ContextType context_type)
114 : manager_(kMaxDrawBuffers,
115 kMaxColorAttachments,
116 context_type,
117 new FramebufferCompletenessCache),
118 feature_info_(new FeatureInfo()) {
119 texture_manager_.reset(new TextureManager(NULL,
120 feature_info_.get(),
121 kMaxTextureSize,
122 kMaxCubemapSize,
123 kMaxRectangleTextureSize,
124 kMax3DTextureSize,
125 kUseDefaultTextures));
126 renderbuffer_manager_.reset(new RenderbufferManager(NULL,
127 kMaxRenderbufferSize,
128 kMaxSamples,
129 feature_info_.get()));
131 ~FramebufferInfoTestBase() override {
132 manager_.Destroy(false);
133 texture_manager_->Destroy(false);
134 renderbuffer_manager_->Destroy(false);
137 protected:
138 void SetUp() override {
139 InitializeContext("2.0", "GL_EXT_framebuffer_object");
142 void InitializeContext(const char* gl_version, const char* extensions) {
143 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions);
144 TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(gl_.get(),
145 extensions, "", gl_version);
146 feature_info_->Initialize();
147 manager_.CreateFramebuffer(kClient1Id, kService1Id);
148 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>());
149 framebuffer_ = manager_.GetFramebuffer(kClient1Id);
150 ASSERT_TRUE(framebuffer_ != NULL);
153 FramebufferManager manager_;
154 Framebuffer* framebuffer_;
155 scoped_refptr<FeatureInfo> feature_info_;
156 scoped_ptr<TextureManager> texture_manager_;
157 scoped_ptr<RenderbufferManager> renderbuffer_manager_;
158 scoped_ptr<MockErrorState> error_state_;
161 class FramebufferInfoTest : public FramebufferInfoTestBase {
162 public:
163 FramebufferInfoTest()
164 : FramebufferInfoTestBase(ContextGroup::CONTEXT_TYPE_UNDEFINED) {
168 // GCC requires these declarations, but MSVC requires they not be present
169 #ifndef COMPILER_MSVC
170 const GLuint FramebufferInfoTestBase::kClient1Id;
171 const GLuint FramebufferInfoTestBase::kService1Id;
172 #endif
174 TEST_F(FramebufferInfoTest, Basic) {
175 EXPECT_EQ(kService1Id, framebuffer_->service_id());
176 EXPECT_FALSE(framebuffer_->IsDeleted());
177 EXPECT_TRUE(NULL == framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0));
178 EXPECT_TRUE(NULL == framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT));
179 EXPECT_TRUE(NULL == framebuffer_->GetAttachment(GL_STENCIL_ATTACHMENT));
180 EXPECT_TRUE(
181 NULL == framebuffer_->GetAttachment(GL_DEPTH_STENCIL_ATTACHMENT));
182 EXPECT_FALSE(framebuffer_->HasDepthAttachment());
183 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
184 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
185 framebuffer_->IsPossiblyComplete());
186 EXPECT_TRUE(framebuffer_->IsCleared());
187 EXPECT_EQ(static_cast<GLenum>(0),
188 framebuffer_->GetReadBufferInternalFormat());
189 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
192 TEST_F(FramebufferInfoTest, AttachRenderbuffer) {
193 const GLuint kRenderbufferClient1Id = 33;
194 const GLuint kRenderbufferService1Id = 333;
195 const GLuint kRenderbufferClient2Id = 34;
196 const GLuint kRenderbufferService2Id = 334;
197 const GLuint kRenderbufferClient3Id = 35;
198 const GLuint kRenderbufferService3Id = 335;
199 const GLuint kRenderbufferClient4Id = 36;
200 const GLuint kRenderbufferService4Id = 336;
201 const GLsizei kWidth1 = 16;
202 const GLsizei kHeight1 = 32;
203 const GLenum kFormat1 = GL_RGBA4;
204 const GLenum kBadFormat1 = GL_DEPTH_COMPONENT16;
205 const GLsizei kSamples1 = 0;
206 const GLsizei kWidth2 = 16;
207 const GLsizei kHeight2 = 32;
208 const GLenum kFormat2 = GL_DEPTH_COMPONENT16;
209 const GLsizei kSamples2 = 0;
210 const GLsizei kWidth3 = 16;
211 const GLsizei kHeight3 = 32;
212 const GLenum kFormat3 = GL_STENCIL_INDEX8;
213 const GLsizei kSamples3 = 0;
214 const GLsizei kWidth4 = 16;
215 const GLsizei kHeight4 = 32;
216 const GLenum kFormat4 = GL_STENCIL_INDEX8;
217 const GLsizei kSamples4 = 0;
219 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
220 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
221 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
222 EXPECT_FALSE(
223 framebuffer_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT));
225 renderbuffer_manager_->CreateRenderbuffer(
226 kRenderbufferClient1Id, kRenderbufferService1Id);
227 Renderbuffer* renderbuffer1 =
228 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient1Id);
229 ASSERT_TRUE(renderbuffer1 != NULL);
231 // check adding one attachment
232 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, renderbuffer1);
233 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
234 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
235 EXPECT_EQ(static_cast<GLenum>(GL_RGBA4),
236 framebuffer_->GetReadBufferInternalFormat());
237 EXPECT_FALSE(framebuffer_->HasDepthAttachment());
238 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
239 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
240 framebuffer_->IsPossiblyComplete());
241 EXPECT_TRUE(framebuffer_->IsCleared());
243 // Try a format that's not good for COLOR_ATTACHMENT0.
244 renderbuffer_manager_->SetInfo(
245 renderbuffer1, kSamples1, kBadFormat1, kWidth1, kHeight1);
246 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
247 framebuffer_->IsPossiblyComplete());
249 // Try a good format.
250 renderbuffer_manager_->SetInfo(
251 renderbuffer1, kSamples1, kFormat1, kWidth1, kHeight1);
252 EXPECT_EQ(static_cast<GLenum>(kFormat1),
253 framebuffer_->GetReadBufferInternalFormat());
254 EXPECT_FALSE(framebuffer_->HasDepthAttachment());
255 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
256 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
257 framebuffer_->IsPossiblyComplete());
258 EXPECT_FALSE(framebuffer_->IsCleared());
260 // check adding another
261 renderbuffer_manager_->CreateRenderbuffer(
262 kRenderbufferClient2Id, kRenderbufferService2Id);
263 Renderbuffer* renderbuffer2 =
264 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient2Id);
265 ASSERT_TRUE(renderbuffer2 != NULL);
266 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, renderbuffer2);
267 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
268 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
269 EXPECT_EQ(static_cast<GLenum>(kFormat1),
270 framebuffer_->GetReadBufferInternalFormat());
271 EXPECT_TRUE(framebuffer_->HasDepthAttachment());
272 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
273 // The attachment has a size of 0,0 so depending on the order of the map
274 // of attachments it could either get INCOMPLETE_ATTACHMENT because it's 0,0
275 // or INCOMPLETE_DIMENSIONS because it's not the same size as the other
276 // attachment.
277 GLenum status = framebuffer_->IsPossiblyComplete();
278 EXPECT_TRUE(
279 status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ||
280 status == GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT);
281 EXPECT_FALSE(framebuffer_->IsCleared());
283 renderbuffer_manager_->SetInfo(
284 renderbuffer2, kSamples2, kFormat2, kWidth2, kHeight2);
285 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
286 framebuffer_->IsPossiblyComplete());
287 EXPECT_FALSE(framebuffer_->IsCleared());
288 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
290 // check marking them as cleared.
291 manager_.MarkAttachmentsAsCleared(
292 framebuffer_, renderbuffer_manager_.get(), texture_manager_.get());
293 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
294 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
295 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
296 framebuffer_->IsPossiblyComplete());
297 EXPECT_TRUE(framebuffer_->IsCleared());
299 // Check adding one that is already cleared.
300 renderbuffer_manager_->CreateRenderbuffer(
301 kRenderbufferClient3Id, kRenderbufferService3Id);
302 Renderbuffer* renderbuffer3 =
303 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient3Id);
304 ASSERT_TRUE(renderbuffer3 != NULL);
305 renderbuffer_manager_->SetInfo(
306 renderbuffer3, kSamples3, kFormat3, kWidth3, kHeight3);
307 renderbuffer_manager_->SetCleared(renderbuffer3, true);
309 framebuffer_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, renderbuffer3);
310 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
311 EXPECT_EQ(static_cast<GLenum>(kFormat1),
312 framebuffer_->GetReadBufferInternalFormat());
313 EXPECT_TRUE(framebuffer_->HasDepthAttachment());
314 EXPECT_TRUE(framebuffer_->HasStencilAttachment());
315 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
316 framebuffer_->IsPossiblyComplete());
317 EXPECT_TRUE(framebuffer_->IsCleared());
319 // Check marking the renderbuffer as unclared.
320 renderbuffer_manager_->SetInfo(
321 renderbuffer1, kSamples1, kFormat1, kWidth1, kHeight1);
322 EXPECT_EQ(static_cast<GLenum>(kFormat1),
323 framebuffer_->GetReadBufferInternalFormat());
324 EXPECT_TRUE(framebuffer_->HasDepthAttachment());
325 EXPECT_TRUE(framebuffer_->HasStencilAttachment());
326 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
327 framebuffer_->IsPossiblyComplete());
328 EXPECT_FALSE(framebuffer_->IsCleared());
330 const Framebuffer::Attachment* attachment =
331 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
332 ASSERT_TRUE(attachment != NULL);
333 EXPECT_EQ(kWidth1, attachment->width());
334 EXPECT_EQ(kHeight1, attachment->height());
335 EXPECT_EQ(kSamples1, attachment->samples());
336 EXPECT_EQ(kFormat1, attachment->internal_format());
337 EXPECT_FALSE(attachment->cleared());
339 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
341 // Clear it.
342 manager_.MarkAttachmentsAsCleared(
343 framebuffer_, renderbuffer_manager_.get(), texture_manager_.get());
344 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
345 EXPECT_TRUE(framebuffer_->IsCleared());
347 // Check replacing an attachment
348 renderbuffer_manager_->CreateRenderbuffer(
349 kRenderbufferClient4Id, kRenderbufferService4Id);
350 Renderbuffer* renderbuffer4 =
351 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient4Id);
352 ASSERT_TRUE(renderbuffer4 != NULL);
353 renderbuffer_manager_->SetInfo(
354 renderbuffer4, kSamples4, kFormat4, kWidth4, kHeight4);
356 framebuffer_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, renderbuffer4);
357 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
358 EXPECT_FALSE(framebuffer_->IsCleared());
360 attachment = framebuffer_->GetAttachment(GL_STENCIL_ATTACHMENT);
361 ASSERT_TRUE(attachment != NULL);
362 EXPECT_EQ(kWidth4, attachment->width());
363 EXPECT_EQ(kHeight4, attachment->height());
364 EXPECT_EQ(kSamples4, attachment->samples());
365 EXPECT_EQ(kFormat4, attachment->internal_format());
366 EXPECT_FALSE(attachment->cleared());
367 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
368 framebuffer_->IsPossiblyComplete());
370 // Check changing an attachment.
371 renderbuffer_manager_->SetInfo(
372 renderbuffer4, kSamples4, kFormat4, kWidth4 + 1, kHeight4);
374 attachment = framebuffer_->GetAttachment(GL_STENCIL_ATTACHMENT);
375 ASSERT_TRUE(attachment != NULL);
376 EXPECT_EQ(kWidth4 + 1, attachment->width());
377 EXPECT_EQ(kHeight4, attachment->height());
378 EXPECT_EQ(kSamples4, attachment->samples());
379 EXPECT_EQ(kFormat4, attachment->internal_format());
380 EXPECT_FALSE(attachment->cleared());
381 EXPECT_FALSE(framebuffer_->IsCleared());
382 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT),
383 framebuffer_->IsPossiblyComplete());
385 // Check removing it.
386 framebuffer_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, NULL);
387 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
388 EXPECT_EQ(static_cast<GLenum>(kFormat1),
389 framebuffer_->GetReadBufferInternalFormat());
390 EXPECT_TRUE(framebuffer_->HasDepthAttachment());
391 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
393 EXPECT_TRUE(framebuffer_->IsCleared());
394 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
395 framebuffer_->IsPossiblyComplete());
397 // Remove depth, Set color to 0 size.
398 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, NULL);
399 renderbuffer_manager_->SetInfo(renderbuffer1, kSamples1, kFormat1, 0, 0);
400 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
401 framebuffer_->IsPossiblyComplete());
403 // Remove color.
404 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, NULL);
405 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
406 framebuffer_->IsPossiblyComplete());
409 TEST_F(FramebufferInfoTest, AttachTexture) {
410 const GLuint kTextureClient1Id = 33;
411 const GLuint kTextureService1Id = 333;
412 const GLuint kTextureClient2Id = 34;
413 const GLuint kTextureService2Id = 334;
414 const GLint kDepth = 1;
415 const GLint kBorder = 0;
416 const GLenum kType = GL_UNSIGNED_BYTE;
417 const GLsizei kWidth1 = 16;
418 const GLsizei kHeight1 = 32;
419 const GLint kLevel1 = 0;
420 const GLenum kFormat1 = GL_RGBA;
421 const GLenum kBadFormat1 = GL_DEPTH_COMPONENT16;
422 const GLenum kTarget1 = GL_TEXTURE_2D;
423 const GLsizei kSamples1 = 0;
424 const GLsizei kWidth2 = 16;
425 const GLsizei kHeight2 = 32;
426 const GLint kLevel2 = 0;
427 const GLenum kFormat2 = GL_RGB;
428 const GLenum kTarget2 = GL_TEXTURE_2D;
429 const GLsizei kSamples2 = 0;
430 const GLsizei kWidth3 = 75;
431 const GLsizei kHeight3 = 123;
432 const GLint kLevel3 = 0;
433 const GLenum kFormat3 = GL_RGB565;
434 const GLsizei kSamples3 = 0;
435 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
436 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
437 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
438 EXPECT_FALSE(
439 framebuffer_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT));
440 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
441 framebuffer_->IsPossiblyComplete());
443 texture_manager_->CreateTexture(kTextureClient1Id, kTextureService1Id);
444 scoped_refptr<TextureRef> texture1(
445 texture_manager_->GetTexture(kTextureClient1Id));
446 ASSERT_TRUE(texture1.get() != NULL);
448 // check adding one attachment
449 framebuffer_->AttachTexture(
450 GL_COLOR_ATTACHMENT0, texture1.get(), kTarget1, kLevel1, kSamples1);
451 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
452 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
453 framebuffer_->IsPossiblyComplete());
454 EXPECT_TRUE(framebuffer_->IsCleared());
455 EXPECT_EQ(static_cast<GLenum>(0),
456 framebuffer_->GetReadBufferInternalFormat());
458 // Try format that doesn't work with COLOR_ATTACHMENT0
459 texture_manager_->SetTarget(texture1.get(), GL_TEXTURE_2D);
460 texture_manager_->SetLevelInfo(
461 texture1.get(), GL_TEXTURE_2D, kLevel1, kBadFormat1, kWidth1, kHeight1,
462 kDepth, kBorder, kBadFormat1, kType, gfx::Rect(kWidth1, kHeight1));
463 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
464 framebuffer_->IsPossiblyComplete());
466 // Try a good format.
467 texture_manager_->SetLevelInfo(texture1.get(), GL_TEXTURE_2D, kLevel1,
468 kFormat1, kWidth1, kHeight1, kDepth, kBorder,
469 kFormat1, kType, gfx::Rect());
470 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
471 framebuffer_->IsPossiblyComplete());
472 EXPECT_FALSE(framebuffer_->IsCleared());
473 texture_manager_->SetLevelInfo(texture1.get(), GL_TEXTURE_2D, kLevel1,
474 kFormat1, kWidth1, kHeight1, kDepth, kBorder,
475 kFormat1, kType, gfx::Rect(kWidth1, kHeight1));
476 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
477 framebuffer_->IsPossiblyComplete());
478 EXPECT_TRUE(framebuffer_->IsCleared());
479 EXPECT_EQ(static_cast<GLenum>(kFormat1),
480 framebuffer_->GetReadBufferInternalFormat());
482 const Framebuffer::Attachment* attachment =
483 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
484 ASSERT_TRUE(attachment != NULL);
485 EXPECT_EQ(kWidth1, attachment->width());
486 EXPECT_EQ(kHeight1, attachment->height());
487 EXPECT_EQ(kSamples1, attachment->samples());
488 EXPECT_EQ(kFormat1, attachment->internal_format());
489 EXPECT_TRUE(attachment->cleared());
491 // Check replacing an attachment
492 texture_manager_->CreateTexture(kTextureClient2Id, kTextureService2Id);
493 scoped_refptr<TextureRef> texture2(
494 texture_manager_->GetTexture(kTextureClient2Id));
495 ASSERT_TRUE(texture2.get() != NULL);
496 texture_manager_->SetTarget(texture2.get(), GL_TEXTURE_2D);
497 texture_manager_->SetLevelInfo(texture2.get(), GL_TEXTURE_2D, kLevel2,
498 kFormat2, kWidth2, kHeight2, kDepth, kBorder,
499 kFormat2, kType, gfx::Rect(kWidth2, kHeight2));
501 framebuffer_->AttachTexture(
502 GL_COLOR_ATTACHMENT0, texture2.get(), kTarget2, kLevel2, kSamples2);
503 EXPECT_EQ(static_cast<GLenum>(kFormat2),
504 framebuffer_->GetReadBufferInternalFormat());
505 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
506 framebuffer_->IsPossiblyComplete());
507 EXPECT_TRUE(framebuffer_->IsCleared());
509 attachment = framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
510 ASSERT_TRUE(attachment != NULL);
511 EXPECT_EQ(kWidth2, attachment->width());
512 EXPECT_EQ(kHeight2, attachment->height());
513 EXPECT_EQ(kSamples2, attachment->samples());
514 EXPECT_EQ(kFormat2, attachment->internal_format());
515 EXPECT_TRUE(attachment->cleared());
517 // Check changing attachment
518 texture_manager_->SetLevelInfo(texture2.get(), GL_TEXTURE_2D, kLevel3,
519 kFormat3, kWidth3, kHeight3, kDepth, kBorder,
520 kFormat3, kType, gfx::Rect());
521 attachment = framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
522 ASSERT_TRUE(attachment != NULL);
523 EXPECT_EQ(kWidth3, attachment->width());
524 EXPECT_EQ(kHeight3, attachment->height());
525 EXPECT_EQ(kSamples3, attachment->samples());
526 EXPECT_EQ(kFormat3, attachment->internal_format());
527 EXPECT_FALSE(attachment->cleared());
528 EXPECT_EQ(static_cast<GLenum>(kFormat3),
529 framebuffer_->GetReadBufferInternalFormat());
530 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
531 framebuffer_->IsPossiblyComplete());
532 EXPECT_FALSE(framebuffer_->IsCleared());
534 // Set to size 0
535 texture_manager_->SetLevelInfo(texture2.get(), GL_TEXTURE_2D, kLevel3,
536 kFormat3, 0, 0, kDepth, kBorder, kFormat3,
537 kType, gfx::Rect());
538 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
539 framebuffer_->IsPossiblyComplete());
541 // Check removing it.
542 framebuffer_->AttachTexture(GL_COLOR_ATTACHMENT0, NULL, 0, 0, 0);
543 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL);
544 EXPECT_EQ(static_cast<GLenum>(0),
545 framebuffer_->GetReadBufferInternalFormat());
547 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
548 framebuffer_->IsPossiblyComplete());
549 EXPECT_TRUE(framebuffer_->IsCleared());
552 TEST_F(FramebufferInfoTest, DrawBuffers) {
553 const GLuint kTextureClientId[] = { 33, 34 };
554 const GLuint kTextureServiceId[] = { 333, 334 };
556 for (GLenum i = GL_COLOR_ATTACHMENT0;
557 i < GL_COLOR_ATTACHMENT0 + kMaxColorAttachments; ++i) {
558 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(i));
560 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments());
562 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0),
563 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB));
564 for (GLenum i = GL_DRAW_BUFFER1_ARB;
565 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) {
566 EXPECT_EQ(static_cast<GLenum>(GL_NONE),
567 framebuffer_->GetDrawBuffer(i));
570 for (size_t ii = 0; ii < arraysize(kTextureClientId); ++ii) {
571 texture_manager_->CreateTexture(
572 kTextureClientId[ii], kTextureServiceId[ii]);
573 scoped_refptr<TextureRef> texture(
574 texture_manager_->GetTexture(kTextureClientId[ii]));
575 ASSERT_TRUE(texture.get() != NULL);
577 framebuffer_->AttachTexture(
578 GL_COLOR_ATTACHMENT0 + ii, texture.get(), GL_TEXTURE_2D, 0, 0);
579 EXPECT_FALSE(
580 framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0 + ii));
582 const Framebuffer::Attachment* attachment =
583 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0 + ii);
584 ASSERT_TRUE(attachment != NULL);
585 EXPECT_TRUE(attachment->cleared());
587 EXPECT_TRUE(framebuffer_->IsCleared());
588 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments());
590 // Set a texture as uncleared.
591 scoped_refptr<TextureRef> texture1(
592 texture_manager_->GetTexture(kTextureClientId[1]));
593 texture_manager_->SetTarget(texture1.get(), GL_TEXTURE_2D);
594 texture_manager_->SetLevelInfo(texture1.get(), GL_TEXTURE_2D, 0, GL_RGBA, 4,
595 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
596 gfx::Rect());
598 const Framebuffer::Attachment* attachment1 =
599 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT1);
600 ASSERT_TRUE(attachment1 != NULL);
601 EXPECT_FALSE(attachment1->cleared());
602 EXPECT_FALSE(framebuffer_->IsCleared());
603 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT1));
604 EXPECT_TRUE(framebuffer_->HasUnclearedColorAttachments());
606 GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
607 framebuffer_->SetDrawBuffers(2, buffers);
608 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0),
609 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB));
610 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT1),
611 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER1_ARB));
612 for (GLenum i = GL_DRAW_BUFFER2_ARB;
613 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) {
614 EXPECT_EQ(static_cast<GLenum>(GL_NONE),
615 framebuffer_->GetDrawBuffer(i));
618 // Nothing happens.
619 framebuffer_->PrepareDrawBuffersForClear();
620 framebuffer_->RestoreDrawBuffersAfterClear();
622 // Now we disable a draw buffer 1.
623 buffers[1] = GL_NONE;
624 framebuffer_->SetDrawBuffers(2, buffers);
625 // We will enable the disabled draw buffer for clear(), and disable it
626 // after the clear.
627 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
628 .Times(1)
629 .RetiresOnSaturation();
630 framebuffer_->PrepareDrawBuffersForClear();
631 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
632 .Times(1)
633 .RetiresOnSaturation();
634 framebuffer_->RestoreDrawBuffersAfterClear();
636 // Now remove draw buffer 1's attachment.
637 framebuffer_->AttachTexture(GL_COLOR_ATTACHMENT1, NULL, 0, 0, 0);
638 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT1) == NULL);
640 // Nothing happens.
641 framebuffer_->PrepareDrawBuffersForClear();
642 framebuffer_->RestoreDrawBuffersAfterClear();
645 class FramebufferInfoFloatTest : public FramebufferInfoTest {
646 public:
647 FramebufferInfoFloatTest()
648 : FramebufferInfoTest() {
650 ~FramebufferInfoFloatTest() override {}
652 protected:
653 void SetUp() override {
654 InitializeContext("OpenGL ES 3.0",
655 "GL_OES_texture_float GL_EXT_color_buffer_float");
659 TEST_F(FramebufferInfoFloatTest, AttachFloatTexture) {
660 const GLuint kTextureClientId = 33;
661 const GLuint kTextureServiceId = 333;
662 const GLint kDepth = 1;
663 const GLint kBorder = 0;
664 const GLenum kType = GL_FLOAT;
665 const GLsizei kWidth = 16;
666 const GLsizei kHeight = 32;
667 const GLint kLevel = 0;
668 const GLenum kFormat = GL_RGBA;
669 const GLenum kInternalFormat = GL_RGBA32F;
670 const GLenum kTarget = GL_TEXTURE_2D;
671 const GLsizei kSamples = 0;
672 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
673 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
674 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
676 texture_manager_->CreateTexture(kTextureClientId, kTextureServiceId);
677 scoped_refptr<TextureRef> texture(
678 texture_manager_->GetTexture(kTextureClientId));
679 ASSERT_TRUE(texture.get() != NULL);
681 framebuffer_->AttachTexture(
682 GL_COLOR_ATTACHMENT0, texture.get(), kTarget, kLevel, kSamples);
683 EXPECT_EQ(static_cast<GLenum>(0),
684 framebuffer_->GetReadBufferInternalFormat());
686 texture_manager_->SetTarget(texture.get(), GL_TEXTURE_2D);
687 texture_manager_->SetLevelInfo(texture.get(), GL_TEXTURE_2D, kLevel,
688 kInternalFormat, kWidth, kHeight, kDepth,
689 kBorder, kFormat, kType, gfx::Rect());
690 // Texture with a sized float internalformat is allowed as an attachment
691 // since float color attachment extension is present.
692 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
693 framebuffer_->IsPossiblyComplete());
696 TEST_F(FramebufferInfoTest, UnbindRenderbuffer) {
697 const GLuint kRenderbufferClient1Id = 33;
698 const GLuint kRenderbufferService1Id = 333;
699 const GLuint kRenderbufferClient2Id = 34;
700 const GLuint kRenderbufferService2Id = 334;
702 renderbuffer_manager_->CreateRenderbuffer(
703 kRenderbufferClient1Id, kRenderbufferService1Id);
704 Renderbuffer* renderbuffer1 =
705 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient1Id);
706 ASSERT_TRUE(renderbuffer1 != NULL);
707 renderbuffer_manager_->CreateRenderbuffer(
708 kRenderbufferClient2Id, kRenderbufferService2Id);
709 Renderbuffer* renderbuffer2 =
710 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient2Id);
711 ASSERT_TRUE(renderbuffer2 != NULL);
713 // Attach to 2 attachment points.
714 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, renderbuffer1);
715 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, renderbuffer1);
716 // Check they were attached.
717 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) != NULL);
718 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) != NULL);
719 // Unbind unattached renderbuffer.
720 framebuffer_->UnbindRenderbuffer(GL_RENDERBUFFER, renderbuffer2);
721 // Should be no-op.
722 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) != NULL);
723 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) != NULL);
724 // Unbind renderbuffer.
725 framebuffer_->UnbindRenderbuffer(GL_RENDERBUFFER, renderbuffer1);
726 // Check they were detached
727 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL);
728 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) == NULL);
731 TEST_F(FramebufferInfoTest, UnbindTexture) {
732 const GLuint kTextureClient1Id = 33;
733 const GLuint kTextureService1Id = 333;
734 const GLuint kTextureClient2Id = 34;
735 const GLuint kTextureService2Id = 334;
736 const GLenum kTarget1 = GL_TEXTURE_2D;
737 const GLint kLevel1 = 0;
738 const GLint kSamples1 = 0;
740 texture_manager_->CreateTexture(kTextureClient1Id, kTextureService1Id);
741 scoped_refptr<TextureRef> texture1(
742 texture_manager_->GetTexture(kTextureClient1Id));
743 ASSERT_TRUE(texture1.get() != NULL);
744 texture_manager_->CreateTexture(kTextureClient2Id, kTextureService2Id);
745 scoped_refptr<TextureRef> texture2(
746 texture_manager_->GetTexture(kTextureClient2Id));
747 ASSERT_TRUE(texture2.get() != NULL);
749 // Attach to 2 attachment points.
750 framebuffer_->AttachTexture(
751 GL_COLOR_ATTACHMENT0, texture1.get(), kTarget1, kLevel1, kSamples1);
752 framebuffer_->AttachTexture(
753 GL_DEPTH_ATTACHMENT, texture1.get(), kTarget1, kLevel1, kSamples1);
754 // Check they were attached.
755 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) != NULL);
756 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) != NULL);
757 // Unbind unattached texture.
758 framebuffer_->UnbindTexture(kTarget1, texture2.get());
759 // Should be no-op.
760 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) != NULL);
761 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) != NULL);
762 // Unbind texture.
763 framebuffer_->UnbindTexture(kTarget1, texture1.get());
764 // Check they were detached
765 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL);
766 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) == NULL);
769 TEST_F(FramebufferInfoTest, IsCompleteMarkAsComplete) {
770 const GLuint kRenderbufferClient1Id = 33;
771 const GLuint kRenderbufferService1Id = 333;
772 const GLuint kTextureClient2Id = 34;
773 const GLuint kTextureService2Id = 334;
774 const GLenum kTarget1 = GL_TEXTURE_2D;
775 const GLint kLevel1 = 0;
776 const GLint kSamples1 = 0;
778 renderbuffer_manager_->CreateRenderbuffer(
779 kRenderbufferClient1Id, kRenderbufferService1Id);
780 Renderbuffer* renderbuffer1 =
781 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient1Id);
782 ASSERT_TRUE(renderbuffer1 != NULL);
783 texture_manager_->CreateTexture(kTextureClient2Id, kTextureService2Id);
784 scoped_refptr<TextureRef> texture2(
785 texture_manager_->GetTexture(kTextureClient2Id));
786 ASSERT_TRUE(texture2.get() != NULL);
788 // Check MarkAsComlete marks as complete.
789 manager_.MarkAsComplete(framebuffer_);
790 EXPECT_TRUE(manager_.IsComplete(framebuffer_));
792 // Check at attaching marks as not complete.
793 framebuffer_->AttachTexture(
794 GL_COLOR_ATTACHMENT0, texture2.get(), kTarget1, kLevel1, kSamples1);
795 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
796 manager_.MarkAsComplete(framebuffer_);
797 EXPECT_TRUE(manager_.IsComplete(framebuffer_));
798 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, renderbuffer1);
799 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
801 // Check MarkAttachmentsAsCleared marks as complete.
802 manager_.MarkAttachmentsAsCleared(
803 framebuffer_, renderbuffer_manager_.get(), texture_manager_.get());
804 EXPECT_TRUE(manager_.IsComplete(framebuffer_));
806 // Check Unbind marks as not complete.
807 framebuffer_->UnbindRenderbuffer(GL_RENDERBUFFER, renderbuffer1);
808 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
809 manager_.MarkAsComplete(framebuffer_);
810 EXPECT_TRUE(manager_.IsComplete(framebuffer_));
811 framebuffer_->UnbindTexture(kTarget1, texture2.get());
812 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
815 TEST_F(FramebufferInfoTest, GetStatus) {
816 const GLuint kRenderbufferClient1Id = 33;
817 const GLuint kRenderbufferService1Id = 333;
818 const GLuint kTextureClient2Id = 34;
819 const GLuint kTextureService2Id = 334;
820 const GLenum kTarget1 = GL_TEXTURE_2D;
821 const GLint kLevel1 = 0;
822 const GLint kSamples1 = 0;
824 renderbuffer_manager_->CreateRenderbuffer(
825 kRenderbufferClient1Id, kRenderbufferService1Id);
826 Renderbuffer* renderbuffer1 =
827 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient1Id);
828 ASSERT_TRUE(renderbuffer1 != NULL);
829 texture_manager_->CreateTexture(kTextureClient2Id, kTextureService2Id);
830 scoped_refptr<TextureRef> texture2(
831 texture_manager_->GetTexture(kTextureClient2Id));
832 ASSERT_TRUE(texture2.get() != NULL);
833 texture_manager_->SetTarget(texture2.get(), GL_TEXTURE_2D);
835 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
836 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
837 .RetiresOnSaturation();
838 framebuffer_->GetStatus(texture_manager_.get(), GL_FRAMEBUFFER);
840 // Check a second call for the same type does not call anything
841 framebuffer_->GetStatus(texture_manager_.get(), GL_FRAMEBUFFER);
843 // Check changing the attachments calls CheckFramebufferStatus.
844 framebuffer_->AttachTexture(
845 GL_COLOR_ATTACHMENT0, texture2.get(), kTarget1, kLevel1, kSamples1);
846 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
847 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)).RetiresOnSaturation();
848 framebuffer_->GetStatus(texture_manager_.get(), GL_FRAMEBUFFER);
850 // Check a second call for the same type does not call anything.
851 framebuffer_->GetStatus(texture_manager_.get(), GL_FRAMEBUFFER);
853 // Check a second call with a different target calls CheckFramebufferStatus.
854 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
855 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
856 .RetiresOnSaturation();
857 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
859 // Check a second call for the same type does not call anything.
860 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
862 // Check adding another attachment calls CheckFramebufferStatus.
863 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, renderbuffer1);
864 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
865 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
866 .RetiresOnSaturation();
867 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
869 // Check a second call for the same type does not call anything.
870 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
872 // Check changing the format calls CheckFramebuffferStatus.
873 TestHelper::SetTexParameteriWithExpectations(gl_.get(),
874 error_state_.get(),
875 texture_manager_.get(),
876 texture2.get(),
877 GL_TEXTURE_WRAP_S,
878 GL_CLAMP_TO_EDGE,
879 GL_NO_ERROR);
881 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
882 .WillOnce(Return(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT))
883 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
884 .RetiresOnSaturation();
885 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
887 // Check since it did not return FRAMEBUFFER_COMPLETE that it calls
888 // CheckFramebufferStatus
889 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
891 // Check putting it back does not call CheckFramebufferStatus.
892 TestHelper::SetTexParameteriWithExpectations(gl_.get(),
893 error_state_.get(),
894 texture_manager_.get(),
895 texture2.get(),
896 GL_TEXTURE_WRAP_S,
897 GL_REPEAT,
898 GL_NO_ERROR);
899 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
901 // Check Unbinding does not call CheckFramebufferStatus
902 framebuffer_->UnbindRenderbuffer(GL_RENDERBUFFER, renderbuffer1);
903 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
906 class FramebufferInfoES3Test : public FramebufferInfoTestBase {
907 public:
908 FramebufferInfoES3Test()
909 : FramebufferInfoTestBase(ContextGroup::CONTEXT_TYPE_WEBGL2) {
913 TEST_F(FramebufferInfoES3Test, DifferentDimensions) {
914 const GLuint kRenderbufferClient1Id = 33;
915 const GLuint kRenderbufferService1Id = 333;
916 const GLuint kRenderbufferClient2Id = 34;
917 const GLuint kRenderbufferService2Id = 334;
918 const GLsizei kWidth1 = 16;
919 const GLsizei kHeight1 = 32;
920 const GLenum kFormat1 = GL_RGBA4;
921 const GLsizei kSamples1 = 0;
922 const GLsizei kWidth2 = 32; // Different from kWidth1
923 const GLsizei kHeight2 = 32;
924 const GLenum kFormat2 = GL_DEPTH_COMPONENT16;
925 const GLsizei kSamples2 = 0;
927 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
928 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
929 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
930 EXPECT_FALSE(
931 framebuffer_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT));
933 renderbuffer_manager_->CreateRenderbuffer(
934 kRenderbufferClient1Id, kRenderbufferService1Id);
935 Renderbuffer* renderbuffer1 =
936 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient1Id);
937 ASSERT_TRUE(renderbuffer1 != NULL);
938 renderbuffer_manager_->SetInfo(
939 renderbuffer1, kSamples1, kFormat1, kWidth1, kHeight1);
940 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, renderbuffer1);
942 renderbuffer_manager_->CreateRenderbuffer(
943 kRenderbufferClient2Id, kRenderbufferService2Id);
944 Renderbuffer* renderbuffer2 =
945 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient2Id);
946 ASSERT_TRUE(renderbuffer2 != NULL);
947 renderbuffer_manager_->SetInfo(
948 renderbuffer2, kSamples2, kFormat2, kWidth2, kHeight2);
949 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, renderbuffer2);
951 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
952 framebuffer_->IsPossiblyComplete());
955 TEST_F(FramebufferInfoES3Test, ReadBuffer) {
956 const GLuint kRenderbufferClientId = 33;
957 const GLuint kRenderbufferServiceId = 333;
959 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0),
960 framebuffer_->read_buffer());
961 framebuffer_->set_read_buffer(GL_NONE);
962 EXPECT_EQ(static_cast<GLenum>(GL_NONE), framebuffer_->read_buffer());
963 EXPECT_FALSE(framebuffer_->GetReadBufferAttachment());
965 framebuffer_->set_read_buffer(GL_COLOR_ATTACHMENT1);
966 EXPECT_FALSE(framebuffer_->GetReadBufferAttachment());
968 renderbuffer_manager_->CreateRenderbuffer(
969 kRenderbufferClientId, kRenderbufferServiceId);
970 Renderbuffer* renderbuffer =
971 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClientId);
972 ASSERT_TRUE(renderbuffer != NULL);
973 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT1, renderbuffer);
974 EXPECT_TRUE(framebuffer_->GetReadBufferAttachment());
977 } // namespace gles2
978 } // namespace gpu