OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/framebuffer_manager.h" | 5 #include "gpu/command_buffer/service/framebuffer_manager.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
9 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 9 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
10 #include "gpu/command_buffer/service/texture_manager.h" | 10 #include "gpu/command_buffer/service/texture_manager.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 } | 247 } |
248 | 248 |
249 Framebuffer::Framebuffer( | 249 Framebuffer::Framebuffer( |
250 FramebufferManager* manager, GLuint service_id) | 250 FramebufferManager* manager, GLuint service_id) |
251 : manager_(manager), | 251 : manager_(manager), |
252 deleted_(false), | 252 deleted_(false), |
253 service_id_(service_id), | 253 service_id_(service_id), |
254 has_been_bound_(false), | 254 has_been_bound_(false), |
255 framebuffer_complete_state_count_id_(0) { | 255 framebuffer_complete_state_count_id_(0) { |
256 manager->StartTracking(this); | 256 manager->StartTracking(this); |
257 draw_buffers_[0] = GL_COLOR_ATTACHMENT0; | |
258 for (GLsizei i = 1; i < kMaxDrawBuffers; ++i) | |
259 draw_buffers_[i] = GL_NONE; | |
257 } | 260 } |
258 | 261 |
259 Framebuffer::~Framebuffer() { | 262 Framebuffer::~Framebuffer() { |
260 if (manager_) { | 263 if (manager_) { |
261 if (manager_->have_context_) { | 264 if (manager_->have_context_) { |
262 GLuint id = service_id(); | 265 GLuint id = service_id(); |
263 glDeleteFramebuffersEXT(1, &id); | 266 glDeleteFramebuffersEXT(1, &id); |
264 } | 267 } |
265 manager_->StopTracking(this); | 268 manager_->StopTracking(this); |
266 manager_ = NULL; | 269 manager_ = NULL; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 for (AttachmentMap::const_iterator it = attachments_.begin(); | 398 for (AttachmentMap::const_iterator it = attachments_.begin(); |
396 it != attachments_.end(); ++it) { | 399 it != attachments_.end(); ++it) { |
397 Attachment* attachment = it->second; | 400 Attachment* attachment = it->second; |
398 if (!attachment->cleared()) { | 401 if (!attachment->cleared()) { |
399 return false; | 402 return false; |
400 } | 403 } |
401 } | 404 } |
402 return true; | 405 return true; |
403 } | 406 } |
404 | 407 |
408 GLenum Framebuffer::GetDrawBuffer(GLenum draw_buffer) const { | |
409 GLsizei index = static_cast<GLsizei>( | |
410 draw_buffer - GL_DRAW_BUFFER0_ARB); | |
411 CHECK(index >= 0 && index < kMaxDrawBuffers); | |
greggman
2013/03/08 21:48:28
Do these need to be CHECKs? We don't do CHECKS for
Zhenyao Mo
2013/03/13 01:22:02
Done.
| |
412 return draw_buffers_[index]; | |
413 } | |
414 | |
415 void Framebuffer::SetDrawBuffers(GLsizei n, const GLenum* bufs) { | |
416 CHECK(n <= kMaxDrawBuffers); | |
greggman
2013/03/08 21:48:28
Same as above
Zhenyao Mo
2013/03/13 01:22:02
Done.
| |
417 for (GLsizei i = 0; i < n; ++i) | |
418 draw_buffers_[i] = bufs[i]; | |
419 } | |
420 | |
405 void Framebuffer::UnbindRenderbuffer( | 421 void Framebuffer::UnbindRenderbuffer( |
406 GLenum target, Renderbuffer* renderbuffer) { | 422 GLenum target, Renderbuffer* renderbuffer) { |
407 bool done; | 423 bool done; |
408 do { | 424 do { |
409 done = true; | 425 done = true; |
410 for (AttachmentMap::const_iterator it = attachments_.begin(); | 426 for (AttachmentMap::const_iterator it = attachments_.begin(); |
411 it != attachments_.end(); ++it) { | 427 it != attachments_.end(); ++it) { |
412 Attachment* attachment = it->second; | 428 Attachment* attachment = it->second; |
413 if (attachment->IsRenderbuffer(renderbuffer)) { | 429 if (attachment->IsRenderbuffer(renderbuffer)) { |
414 // TODO(gman): manually detach renderbuffer. | 430 // TODO(gman): manually detach renderbuffer. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 void FramebufferManager::RemoveFramebuffer(GLuint client_id) { | 465 void FramebufferManager::RemoveFramebuffer(GLuint client_id) { |
450 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); | 466 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); |
451 if (it != framebuffer_infos_.end()) { | 467 if (it != framebuffer_infos_.end()) { |
452 it->second->MarkAsDeleted(); | 468 it->second->MarkAsDeleted(); |
453 framebuffer_infos_.erase(it); | 469 framebuffer_infos_.erase(it); |
454 } | 470 } |
455 } | 471 } |
456 | 472 |
457 void Framebuffer::AttachRenderbuffer( | 473 void Framebuffer::AttachRenderbuffer( |
458 GLenum attachment, Renderbuffer* renderbuffer) { | 474 GLenum attachment, Renderbuffer* renderbuffer) { |
459 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || | |
460 attachment == GL_DEPTH_ATTACHMENT || | |
461 attachment == GL_STENCIL_ATTACHMENT || | |
462 attachment == GL_DEPTH_STENCIL_ATTACHMENT); | |
463 const Attachment* a = GetAttachment(attachment); | 475 const Attachment* a = GetAttachment(attachment); |
464 if (a) | 476 if (a) |
465 a->DetachFromFramebuffer(); | 477 a->DetachFromFramebuffer(); |
466 if (renderbuffer) { | 478 if (renderbuffer) { |
467 attachments_[attachment] = scoped_refptr<Attachment>( | 479 attachments_[attachment] = scoped_refptr<Attachment>( |
468 new RenderbufferAttachment(renderbuffer)); | 480 new RenderbufferAttachment(renderbuffer)); |
469 } else { | 481 } else { |
470 attachments_.erase(attachment); | 482 attachments_.erase(attachment); |
471 } | 483 } |
472 framebuffer_complete_state_count_id_ = 0; | 484 framebuffer_complete_state_count_id_ = 0; |
473 } | 485 } |
474 | 486 |
475 void Framebuffer::AttachTexture( | 487 void Framebuffer::AttachTexture( |
476 GLenum attachment, Texture* texture, GLenum target, | 488 GLenum attachment, Texture* texture, GLenum target, |
477 GLint level) { | 489 GLint level) { |
478 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || | |
479 attachment == GL_DEPTH_ATTACHMENT || | |
480 attachment == GL_STENCIL_ATTACHMENT || | |
481 attachment == GL_DEPTH_STENCIL_ATTACHMENT); | |
482 const Attachment* a = GetAttachment(attachment); | 490 const Attachment* a = GetAttachment(attachment); |
483 if (a) | 491 if (a) |
484 a->DetachFromFramebuffer(); | 492 a->DetachFromFramebuffer(); |
485 if (texture) { | 493 if (texture) { |
486 attachments_[attachment] = scoped_refptr<Attachment>( | 494 attachments_[attachment] = scoped_refptr<Attachment>( |
487 new TextureAttachment(texture, target, level)); | 495 new TextureAttachment(texture, target, level)); |
488 texture->AttachToFramebuffer(); | 496 texture->AttachToFramebuffer(); |
489 } else { | 497 } else { |
490 attachments_.erase(attachment); | 498 attachments_.erase(attachment); |
491 } | 499 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 Framebuffer* framebuffer) { | 544 Framebuffer* framebuffer) { |
537 DCHECK(framebuffer); | 545 DCHECK(framebuffer); |
538 return framebuffer->framebuffer_complete_state_count_id() == | 546 return framebuffer->framebuffer_complete_state_count_id() == |
539 framebuffer_state_change_count_; | 547 framebuffer_state_change_count_; |
540 } | 548 } |
541 | 549 |
542 } // namespace gles2 | 550 } // namespace gles2 |
543 } // namespace gpu | 551 } // namespace gpu |
544 | 552 |
545 | 553 |
OLD | NEW |