1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
|
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "third_party/blink/renderer/modules/webgl/webgl_framebuffer.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "third_party/blink/renderer/modules/webgl/webgl_context_object_support.h"
#include "third_party/blink/renderer/modules/webgl/webgl_renderbuffer.h"
#include "third_party/blink/renderer/modules/webgl/webgl_texture.h"
namespace blink {
namespace {
const char kIncompleteOpaque[] =
"Cannot render to a XRWebGLLayer framebuffer outside of an XRSession "
"animation frame callback.";
class WebGLRenderbufferAttachment final
: public WebGLFramebuffer::WebGLAttachment {
public:
explicit WebGLRenderbufferAttachment(WebGLRenderbuffer*);
void Trace(Visitor*) const override;
const char* NameInHeapSnapshot() const override { return "WebGLAttachment"; }
private:
WebGLObject* Object() const override;
bool IsObject(WebGLObject*) const override;
bool Valid() const override;
void OnDetached(gpu::gles2::GLES2Interface*) override;
void Attach(gpu::gles2::GLES2Interface*,
GLenum target,
GLenum attachment) override;
void Unattach(gpu::gles2::GLES2Interface*,
GLenum target,
GLenum attachment) override;
Member<WebGLRenderbuffer> renderbuffer_;
};
void WebGLRenderbufferAttachment::Trace(Visitor* visitor) const {
visitor->Trace(renderbuffer_);
WebGLFramebuffer::WebGLAttachment::Trace(visitor);
}
WebGLRenderbufferAttachment::WebGLRenderbufferAttachment(
WebGLRenderbuffer* renderbuffer)
: renderbuffer_(renderbuffer) {}
WebGLObject* WebGLRenderbufferAttachment::Object() const {
return renderbuffer_->Object() ? renderbuffer_.Get() : nullptr;
}
bool WebGLRenderbufferAttachment::IsObject(WebGLObject* object) const {
return object == renderbuffer_;
}
bool WebGLRenderbufferAttachment::Valid() const {
return renderbuffer_->Object();
}
void WebGLRenderbufferAttachment::OnDetached(gpu::gles2::GLES2Interface* gl) {
renderbuffer_->OnDetached(gl);
}
void WebGLRenderbufferAttachment::Attach(gpu::gles2::GLES2Interface* gl,
GLenum target,
GLenum attachment) {
GLuint object = ObjectOrZero(renderbuffer_.Get());
if (gl) {
gl->FramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, object);
}
}
void WebGLRenderbufferAttachment::Unattach(gpu::gles2::GLES2Interface* gl,
GLenum target,
GLenum attachment) {
if (gl) {
gl->FramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, 0);
}
}
class WebGLTextureAttachment final : public WebGLFramebuffer::WebGLAttachment {
public:
WebGLTextureAttachment(WebGLTexture*,
GLenum target,
GLint level,
GLint layer);
void Trace(Visitor*) const override;
const char* NameInHeapSnapshot() const override {
return "WebGLTextureAttachment";
}
private:
WebGLObject* Object() const override;
bool IsObject(WebGLObject*) const override;
bool Valid() const override;
void OnDetached(gpu::gles2::GLES2Interface*) override;
void Attach(gpu::gles2::GLES2Interface*,
GLenum target,
GLenum attachment) override;
void Unattach(gpu::gles2::GLES2Interface*,
GLenum target,
GLenum attachment) override;
Member<WebGLTexture> texture_;
GLenum target_;
GLint level_;
GLint layer_;
};
void WebGLTextureAttachment::Trace(Visitor* visitor) const {
visitor->Trace(texture_);
WebGLFramebuffer::WebGLAttachment::Trace(visitor);
}
WebGLTextureAttachment::WebGLTextureAttachment(WebGLTexture* texture,
GLenum target,
GLint level,
GLint layer)
: texture_(texture), target_(target), level_(level), layer_(layer) {}
WebGLObject* WebGLTextureAttachment::Object() const {
return texture_->Object() ? texture_.Get() : nullptr;
}
bool WebGLTextureAttachment::IsObject(WebGLObject* object) const {
return object == texture_;
}
bool WebGLTextureAttachment::Valid() const {
return texture_->Object();
}
void WebGLTextureAttachment::OnDetached(gpu::gles2::GLES2Interface* gl) {
texture_->OnDetached(gl);
}
void WebGLTextureAttachment::Attach(gpu::gles2::GLES2Interface* gl,
GLenum target,
GLenum attachment) {
if (!gl) {
// Context lost.
return;
}
GLuint object = ObjectOrZero(texture_.Get());
if (target_ == GL_TEXTURE_3D || target_ == GL_TEXTURE_2D_ARRAY) {
gl->FramebufferTextureLayer(target, attachment, object, level_, layer_);
} else {
gl->FramebufferTexture2D(target, attachment, target_, object, level_);
}
}
void WebGLTextureAttachment::Unattach(gpu::gles2::GLES2Interface* gl,
GLenum target,
GLenum attachment) {
if (!gl) {
// Context lost.
return;
}
// GL_DEPTH_STENCIL_ATTACHMENT attachment is valid in ES3.
if (target_ == GL_TEXTURE_3D || target_ == GL_TEXTURE_2D_ARRAY) {
gl->FramebufferTextureLayer(target, attachment, 0, level_, layer_);
} else {
gl->FramebufferTexture2D(target, attachment, target_, 0, level_);
}
}
} // anonymous namespace
WebGLFramebuffer::WebGLAttachment::WebGLAttachment() = default;
WebGLFramebuffer* WebGLFramebuffer::CreateOpaque(WebGLContextObjectSupport* ctx,
bool has_depth,
bool has_stencil) {
WebGLFramebuffer* const fb =
MakeGarbageCollected<WebGLFramebuffer>(ctx, true);
fb->SetOpaqueHasDepth(has_depth);
fb->SetOpaqueHasStencil(has_stencil);
return fb;
}
WebGLFramebuffer::WebGLFramebuffer(WebGLContextObjectSupport* ctx, bool opaque)
: WebGLObject(ctx),
has_ever_been_bound_(false),
web_gl1_depth_stencil_consistent_(true),
opaque_(opaque),
read_buffer_(GL_COLOR_ATTACHMENT0) {
if (!ctx->IsLost()) {
GLuint fbo;
ctx->ContextGL()->GenFramebuffers(1, &fbo);
SetObject(fbo);
}
}
WebGLFramebuffer::~WebGLFramebuffer() = default;
void WebGLFramebuffer::SetAttachmentForBoundFramebuffer(GLenum target,
GLenum attachment,
GLenum tex_target,
WebGLTexture* texture,
GLint level,
GLint layer,
GLsizei num_views) {
DCHECK(HasObject());
DCHECK(IsBound(target));
if (Context()->IsLost()) {
return;
}
if (Context()->IsWebGL2()) {
if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
SetAttachmentInternal(target, GL_DEPTH_ATTACHMENT, tex_target, texture,
level, layer);
SetAttachmentInternal(target, GL_STENCIL_ATTACHMENT, tex_target, texture,
level, layer);
} else {
SetAttachmentInternal(target, attachment, tex_target, texture, level,
layer);
}
GLuint texture_id = ObjectOrZero(texture);
// texTarget can be 0 if detaching using framebufferTextureLayer.
DCHECK(tex_target || !texture_id);
switch (tex_target) {
case 0:
case GL_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
if (num_views > 0) {
DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D_ARRAY), tex_target);
Context()->ContextGL()->FramebufferTextureMultiviewOVR(
target, attachment, texture_id, level, layer, num_views);
} else {
Context()->ContextGL()->FramebufferTextureLayer(
target, attachment, texture_id, level, layer);
}
break;
default:
DCHECK_EQ(layer, 0);
DCHECK_EQ(num_views, 0);
Context()->ContextGL()->FramebufferTexture2D(
target, attachment, tex_target, texture_id, level);
break;
}
} else {
DCHECK_EQ(layer, 0);
DCHECK_EQ(num_views, 0);
SetAttachmentInternal(target, attachment, tex_target, texture, level,
layer);
switch (attachment) {
case GL_DEPTH_ATTACHMENT:
case GL_STENCIL_ATTACHMENT:
case GL_DEPTH_STENCIL_ATTACHMENT:
CommitWebGL1DepthStencilIfConsistent(target);
break;
default:
Context()->ContextGL()->FramebufferTexture2D(
target, attachment, tex_target, ObjectOrZero(texture), level);
break;
}
}
}
void WebGLFramebuffer::SetAttachmentForBoundFramebuffer(
GLenum target,
GLenum attachment,
WebGLRenderbuffer* renderbuffer) {
DCHECK(HasObject());
DCHECK(IsBound(target));
if (Context()->IsLost()) {
return;
}
if (Context()->IsWebGL2()) {
if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
SetAttachmentInternal(target, GL_DEPTH_ATTACHMENT, renderbuffer);
SetAttachmentInternal(target, GL_STENCIL_ATTACHMENT, renderbuffer);
} else {
SetAttachmentInternal(target, attachment, renderbuffer);
}
Context()->ContextGL()->FramebufferRenderbuffer(
target, attachment, GL_RENDERBUFFER, ObjectOrZero(renderbuffer));
} else {
SetAttachmentInternal(target, attachment, renderbuffer);
switch (attachment) {
case GL_DEPTH_ATTACHMENT:
case GL_STENCIL_ATTACHMENT:
case GL_DEPTH_STENCIL_ATTACHMENT:
CommitWebGL1DepthStencilIfConsistent(target);
break;
default:
Context()->ContextGL()->FramebufferRenderbuffer(
target, attachment, GL_RENDERBUFFER, ObjectOrZero(renderbuffer));
break;
}
}
}
WebGLObject* WebGLFramebuffer::GetAttachmentObject(GLenum attachment) const {
if (!HasObject()) {
return nullptr;
}
WebGLAttachment* attachment_object = GetAttachment(attachment);
return attachment_object ? attachment_object->Object() : nullptr;
}
WebGLFramebuffer::WebGLAttachment* WebGLFramebuffer::GetAttachment(
GLenum attachment) const {
const AttachmentMap::const_iterator it = attachments_.find(attachment);
return (it != attachments_.end()) ? it->value.Get() : nullptr;
}
void WebGLFramebuffer::RemoveAttachmentFromBoundFramebuffer(
GLenum target,
WebGLObject* attachment) {
DCHECK(IsBound(target));
if (!HasObject()) {
return;
}
if (!attachment)
return;
bool check_more = true;
bool is_web_gl1 = !Context()->IsWebGL2();
bool check_web_gl1_depth_stencil = false;
while (check_more) {
check_more = false;
for (const auto& it : attachments_) {
WebGLAttachment* attachment_object = it.value.Get();
if (attachment_object->IsObject(attachment)) {
GLenum attachment_type = it.key;
switch (attachment_type) {
case GL_DEPTH_ATTACHMENT:
case GL_STENCIL_ATTACHMENT:
case GL_DEPTH_STENCIL_ATTACHMENT:
if (is_web_gl1) {
check_web_gl1_depth_stencil = true;
} else {
attachment_object->Unattach(Context()->ContextGL(), target,
attachment_type);
}
break;
default:
attachment_object->Unattach(Context()->ContextGL(), target,
attachment_type);
break;
}
RemoveAttachmentInternal(target, attachment_type);
check_more = true;
break;
}
}
}
if (check_web_gl1_depth_stencil)
CommitWebGL1DepthStencilIfConsistent(target);
}
GLenum WebGLFramebuffer::CheckDepthStencilStatus(const char** reason) const {
// This function is called any time framebuffer completeness is checked, which
// makes it the most convenient place to add this check.
if (opaque_) {
if (opaque_complete_)
return GL_FRAMEBUFFER_COMPLETE;
*reason = kIncompleteOpaque;
return GL_FRAMEBUFFER_UNSUPPORTED;
}
if (Context()->IsWebGL2() || web_gl1_depth_stencil_consistent_)
return GL_FRAMEBUFFER_COMPLETE;
*reason = "conflicting DEPTH/STENCIL/DEPTH_STENCIL attachments";
return GL_FRAMEBUFFER_UNSUPPORTED;
}
bool WebGLFramebuffer::HasDepthBuffer() const {
if (opaque_) {
return opaque_has_depth_;
} else {
WebGLAttachment* attachment = GetAttachment(GL_DEPTH_ATTACHMENT);
if (!attachment) {
attachment = GetAttachment(GL_DEPTH_STENCIL_ATTACHMENT);
}
return attachment && attachment->Valid();
}
}
bool WebGLFramebuffer::HasStencilBuffer() const {
if (opaque_) {
return opaque_has_stencil_;
} else {
WebGLAttachment* attachment = GetAttachment(GL_STENCIL_ATTACHMENT);
if (!attachment)
attachment = GetAttachment(GL_DEPTH_STENCIL_ATTACHMENT);
return attachment && attachment->Valid();
}
}
void WebGLFramebuffer::DeleteObjectImpl(gpu::gles2::GLES2Interface* gl) {
// Both the AttachmentMap and its WebGLAttachment objects are GCed
// objects and cannot be accessed after the destructor has been
// entered, as they may have been finalized already during the
// same GC sweep. These attachments' OpenGL objects will be fully
// destroyed once their JavaScript wrappers are collected.
if (!DestructionInProgress()) {
for (const auto& attachment : attachments_)
attachment.value->OnDetached(gl);
for (const auto& tex : pls_textures_) {
tex.value->OnDetached(gl);
}
}
// "gl" is null-checked at higher levels.
gl->DeleteFramebuffers(1, &Object());
}
bool WebGLFramebuffer::IsBound(GLenum target) const {
GLint bound_fbo = 0;
switch (target) {
case GL_FRAMEBUFFER:
case GL_DRAW_FRAMEBUFFER:
Context()->ContextGL()->GetIntegerv(GL_FRAMEBUFFER_BINDING, &bound_fbo);
break;
case GL_READ_FRAMEBUFFER:
Context()->ContextGL()->GetIntegerv(GL_READ_FRAMEBUFFER_BINDING,
&bound_fbo);
break;
default:
NOTREACHED();
}
return GLuint(bound_fbo) == Object();
}
void WebGLFramebuffer::DrawBuffers(const Vector<GLenum>& bufs) {
draw_buffers_ = bufs;
filtered_draw_buffers_.resize(draw_buffers_.size());
for (wtf_size_t i = 0; i < filtered_draw_buffers_.size(); ++i)
filtered_draw_buffers_[i] = GL_NONE;
DrawBuffersIfNecessary(true);
}
void WebGLFramebuffer::DrawBuffersIfNecessary(bool force) {
if (Context()->IsWebGL2() ||
Context()->ExtensionEnabled(kWebGLDrawBuffersName)) {
if (Context()->IsLost()) {
return;
}
bool reset = force;
// This filtering works around graphics driver bugs on Mac OS X.
for (wtf_size_t i = 0; i < draw_buffers_.size(); ++i) {
if (draw_buffers_[i] != GL_NONE && GetAttachment(draw_buffers_[i])) {
if (filtered_draw_buffers_[i] != draw_buffers_[i]) {
filtered_draw_buffers_[i] = draw_buffers_[i];
reset = true;
}
} else {
if (filtered_draw_buffers_[i] != GL_NONE) {
filtered_draw_buffers_[i] = GL_NONE;
reset = true;
}
}
}
if (reset) {
Context()->ContextGL()->DrawBuffersEXT(filtered_draw_buffers_.size(),
filtered_draw_buffers_.data());
}
}
}
void WebGLFramebuffer::SetAttachmentInternal(GLenum target,
GLenum attachment,
GLenum tex_target,
WebGLTexture* texture,
GLint level,
GLint layer) {
DCHECK(IsBound(target));
DCHECK(HasObject());
RemoveAttachmentInternal(target, attachment);
if (texture && texture->Object()) {
attachments_.insert(attachment,
MakeGarbageCollected<WebGLTextureAttachment>(
texture, tex_target, level, layer));
DrawBuffersIfNecessary(false);
texture->OnAttached();
}
}
void WebGLFramebuffer::SetAttachmentInternal(GLenum target,
GLenum attachment,
WebGLRenderbuffer* renderbuffer) {
DCHECK(IsBound(target));
DCHECK(HasObject());
RemoveAttachmentInternal(target, attachment);
if (renderbuffer && renderbuffer->Object()) {
attachments_.insert(
attachment,
MakeGarbageCollected<WebGLRenderbufferAttachment>(renderbuffer));
DrawBuffersIfNecessary(false);
renderbuffer->OnAttached();
}
}
void WebGLFramebuffer::RemoveAttachmentInternal(GLenum target,
GLenum attachment) {
DCHECK(IsBound(target));
DCHECK(HasObject());
WebGLAttachment* attachment_object = GetAttachment(attachment);
if (attachment_object) {
attachment_object->OnDetached(Context()->ContextGL());
attachments_.erase(attachment);
DrawBuffersIfNecessary(false);
}
}
void WebGLFramebuffer::CommitWebGL1DepthStencilIfConsistent(GLenum target) {
DCHECK(!Context()->IsWebGL2());
if (Context()->IsLost()) {
return;
}
WebGLAttachment* depth_attachment = nullptr;
WebGLAttachment* stencil_attachment = nullptr;
WebGLAttachment* depth_stencil_attachment = nullptr;
int count = 0;
for (const auto& it : attachments_) {
WebGLAttachment* attachment = it.value.Get();
DCHECK(attachment);
switch (it.key) {
case GL_DEPTH_ATTACHMENT:
depth_attachment = attachment;
++count;
break;
case GL_STENCIL_ATTACHMENT:
stencil_attachment = attachment;
++count;
break;
case GL_DEPTH_STENCIL_ATTACHMENT:
depth_stencil_attachment = attachment;
++count;
break;
default:
break;
}
}
web_gl1_depth_stencil_consistent_ = count <= 1;
if (!web_gl1_depth_stencil_consistent_)
return;
gpu::gles2::GLES2Interface* gl = Context()->ContextGL();
if (!gl) {
// Context has been lost.
return;
}
if (depth_attachment) {
gl->FramebufferRenderbuffer(target, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, 0);
depth_attachment->Attach(gl, target, GL_DEPTH_ATTACHMENT);
gl->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
0);
} else if (stencil_attachment) {
gl->FramebufferRenderbuffer(target, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, 0);
gl->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
0);
stencil_attachment->Attach(gl, target, GL_STENCIL_ATTACHMENT);
} else if (depth_stencil_attachment) {
gl->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
0);
gl->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
0);
depth_stencil_attachment->Attach(gl, target, GL_DEPTH_STENCIL_ATTACHMENT);
} else {
gl->FramebufferRenderbuffer(target, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, 0);
gl->FramebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
0);
gl->FramebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
0);
}
}
GLenum WebGLFramebuffer::GetDrawBuffer(GLenum draw_buffer) {
int index = static_cast<int>(draw_buffer - GL_DRAW_BUFFER0_EXT);
DCHECK_GE(index, 0);
if (index < static_cast<int>(draw_buffers_.size()))
return draw_buffers_[index];
if (draw_buffer == GL_DRAW_BUFFER0_EXT)
return GL_COLOR_ATTACHMENT0;
return GL_NONE;
}
// HeapHashMap does not allow keys with a value of 0.
constexpr static GLint PlaneKey(GLint plane) {
return plane + 1;
}
void WebGLFramebuffer::SetPLSTexture(GLint plane, WebGLTexture* texture) {
if (texture == nullptr) {
pls_textures_.erase(PlaneKey(plane));
} else {
pls_textures_.Set(PlaneKey(plane), texture);
}
}
WebGLTexture* WebGLFramebuffer::GetPLSTexture(GLint plane) const {
const auto it = pls_textures_.find(PlaneKey(plane));
return (it != pls_textures_.end()) ? it->value.Get() : nullptr;
}
void WebGLFramebuffer::Trace(Visitor* visitor) const {
visitor->Trace(attachments_);
visitor->Trace(pls_textures_);
WebGLObject::Trace(visitor);
}
} // namespace blink
|