Skip to content

Commit

Permalink
WebGLFramebuffer uses renderbuffer and texture attachments via WebGLO…
Browse files Browse the repository at this point in the history
…bject

https://bugs.webkit.org/show_bug.cgi?id=260955
rdar://114750589

Reviewed by Dan Glastonbury.

Framebuffer attachments can be 2d textures, 3d texture layers or
renderbuffers. Use std::variant to encode this instead of
a virtual base class. This removes a lot of unneeded complexity in
the code. This also enables future bugfixes related to non-typesafe
handling of these variants.

When obtaining a pointer to the attached object, use std::variant
instead of WebGLObject*. This way future commits may break the
dependency to a common base class. The objects do not have intrinsic
polymorphic operations, rather their types are always known at the
invocation site, from JS through WebGLRenderingContextBase.

* Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::framebufferTextureLayer):
(WebCore::WebGL2RenderingContext::getFramebufferAttachmentParameter):
* Source/WebCore/html/canvas/WebGLFramebuffer.cpp:
(WebCore::entryAddMembersToOpaqueRoots):
(WebCore::entryDetachAndClear):
(WebCore::entryAttach):
(WebCore::entryContextSetAttachment):
(WebCore::entryObject):
(WebCore::entryHasObject):
(WebCore::WebGLFramebuffer::setAttachmentForBoundFramebuffer):
(WebCore::WebGLFramebuffer::getAttachmentObject const):
(WebCore::WebGLFramebuffer::removeAttachmentFromBoundFramebuffer):
(WebCore::WebGLFramebuffer::deleteObjectImpl):
(WebCore::WebGLFramebuffer::drawBuffersIfNecessary):
(WebCore::WebGLFramebuffer::addMembersToOpaqueRoots):
(WebCore::WebGLFramebuffer::setAttachmentInternal):
(WebCore::WebGLFramebuffer::TextureAttachment::operator== const):
(WebCore::WebGLFramebuffer::TextureLayerAttachment::operator== const):
(): Deleted.
(WebCore::WebGLFramebuffer::attach): Deleted.
(WebCore::WebGLFramebuffer::getAttachment const): Deleted.
(WebCore::WebGLFramebuffer::removeAttachmentInternal): Deleted.
* Source/WebCore/html/canvas/WebGLFramebuffer.h:
* Source/WebCore/html/canvas/WebGLObject.h:
(WebCore::WebGLObject::isRenderbuffer const): Deleted.
(WebCore::WebGLObject::isTexture const): Deleted.
* Source/WebCore/html/canvas/WebGLRenderbuffer.h:
* Source/WebCore/html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::getFramebufferAttachmentParameter):
* Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::framebufferRenderbuffer):
(WebCore::WebGLRenderingContextBase::framebufferTexture2D):
* Source/WebCore/html/canvas/WebGLTexture.h:

Canonical link: https://commits.webkit.org/267535@main
  • Loading branch information
kkinnunen-apple authored and djg committed Sep 1, 2023
1 parent e803ed3 commit 0dcc7a6
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 318 deletions.
17 changes: 9 additions & 8 deletions Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void WebGL2RenderingContext::framebufferTextureLayer(GCGLenum target, GCGLenum a
synthesizeGLError(GraphicsContextGL::INVALID_OPERATION, "framebufferTextureLayer", "no framebuffer bound");
return;
}
framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, texTarget, texture, level, layer);
framebufferBinding->setAttachmentForBoundFramebuffer(target, attachment, WebGLFramebuffer::TextureLayerAttachment { texture, level, layer });
}

WebGLAny WebGL2RenderingContext::getInternalformatParameter(GCGLenum target, GCGLenum internalformat, GCGLenum pname)
Expand Down Expand Up @@ -2723,10 +2723,10 @@ WebGLAny WebGL2RenderingContext::getFramebufferAttachmentParameter(GCGLenum targ
if (!validateNonDefaultFramebufferAttachment(functionName, attachment))
return nullptr;

RefPtr<WebGLObject> attachmentObject;
std::optional<WebGLFramebuffer::AttachmentObject> attachmentObject;
if (attachment == GraphicsContextGL::DEPTH_STENCIL_ATTACHMENT) {
attachmentObject = targetFramebuffer->getAttachmentObject(GraphicsContextGL::DEPTH_ATTACHMENT);
RefPtr stencilAttachment = targetFramebuffer->getAttachmentObject(GraphicsContextGL::STENCIL_ATTACHMENT);
auto stencilAttachment = targetFramebuffer->getAttachmentObject(GraphicsContextGL::STENCIL_ATTACHMENT);
if (attachmentObject != stencilAttachment) {
synthesizeGLError(GraphicsContextGL::INVALID_OPERATION, functionName, "different objects bound to DEPTH_ATTACHMENT and STENCIL_ATTACHMENT");
return nullptr;
Expand All @@ -2743,19 +2743,20 @@ WebGLAny WebGL2RenderingContext::getFramebufferAttachmentParameter(GCGLenum targ
return nullptr;
}

const bool isTexture = std::holds_alternative<RefPtr<WebGLTexture>>(*attachmentObject);
switch (pname) {
case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
if (attachmentObject->isTexture())
if (isTexture)
return static_cast<unsigned>(GraphicsContextGL::TEXTURE);
return static_cast<unsigned>(GraphicsContextGL::RENDERBUFFER);
case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
if (attachmentObject->isTexture())
return static_pointer_cast<WebGLTexture>(WTFMove(attachmentObject));
return static_pointer_cast<WebGLRenderbuffer>(WTFMove(attachmentObject));
if (isTexture)
return std::get<RefPtr<WebGLTexture>>(WTFMove(*attachmentObject));
return std::get<RefPtr<WebGLRenderbuffer>>(WTFMove(*attachmentObject));
case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
if (!attachmentObject->isTexture())
if (!isTexture)
break;
FALLTHROUGH;
case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_RED_SIZE:
Expand Down
Loading

0 comments on commit 0dcc7a6

Please sign in to comment.