LibWeb/WebGL2: Implement the EXT_render_snorm extension

This commit is contained in:
Luke Wilde 2025-10-18 18:36:20 +01:00 committed by Jelle Raaijmakers
parent 7ba496b798
commit 93d3ebfd59
8 changed files with 99 additions and 0 deletions

View File

@ -1023,6 +1023,7 @@ set(SOURCES
WebGL/Extensions/ANGLEInstancedArrays.cpp
WebGL/Extensions/EXTBlendMinMax.cpp
WebGL/Extensions/EXTColorBufferFloat.cpp
WebGL/Extensions/EXTRenderSnorm.cpp
WebGL/Extensions/OESVertexArrayObject.cpp
WebGL/Extensions/WebGLCompressedTextureS3tc.cpp
WebGL/Extensions/WebGLDrawBuffers.cpp

View File

@ -1224,6 +1224,7 @@ namespace Web::WebGL::Extensions {
class ANGLEInstancedArrays;
class EXTBlendMinMax;
class EXTColorBufferFloat;
class EXTRenderSnorm;
class OESVertexArrayObject;
class WebGLCompressedTextureS3tc;
class WebGLDrawBuffers;

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/EXTRenderSnormPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/WebGL/Extensions/EXTRenderSnorm.h>
#include <LibWeb/WebGL/OpenGLContext.h>
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
namespace Web::WebGL::Extensions {
GC_DEFINE_ALLOCATOR(EXTRenderSnorm);
JS::ThrowCompletionOr<GC::Ptr<EXTRenderSnorm>> EXTRenderSnorm::create(JS::Realm& realm, GC::Ref<WebGL2RenderingContext> context)
{
return realm.create<EXTRenderSnorm>(realm, context);
}
EXTRenderSnorm::EXTRenderSnorm(JS::Realm& realm, GC::Ref<WebGL2RenderingContext> context)
: PlatformObject(realm)
, m_context(context)
{
m_context->context().request_extension("GL_EXT_render_snorm");
}
void EXTRenderSnorm::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(EXTRenderSnorm);
Base::initialize(realm);
}
void EXTRenderSnorm::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_context);
}
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>
namespace Web::WebGL::Extensions {
class EXTRenderSnorm : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(EXTRenderSnorm, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(EXTRenderSnorm);
public:
static JS::ThrowCompletionOr<GC::Ptr<EXTRenderSnorm>> create(JS::Realm&, GC::Ref<WebGL2RenderingContext>);
protected:
void initialize(JS::Realm&) override;
void visit_edges(Visitor&) override;
private:
EXTRenderSnorm(JS::Realm&, GC::Ref<WebGL2RenderingContext>);
GC::Ref<WebGL2RenderingContext> m_context;
};
}

View File

@ -0,0 +1,11 @@
#import <WebGL/Types.idl>
// https://registry.khronos.org/webgl/extensions/EXT_render_snorm/
// NOTE: Original EXT_render_snorm name is changed to title case,
// so it matches corresponding C++ class name, and does not require
// IDL generator to handle snake_case to TitleCase conversion.
// Having a different name is totally fine, because LegacyNoInterfaceObject
// prevents the name from being exposed to JavaScript.
[Exposed=(Window,Worker), LegacyNoInterfaceObject]
interface EXTRenderSnorm {
};

View File

@ -16,6 +16,7 @@
#include <LibWeb/Painting/Paintable.h>
#include <LibWeb/WebGL/EventNames.h>
#include <LibWeb/WebGL/Extensions/EXTColorBufferFloat.h>
#include <LibWeb/WebGL/Extensions/EXTRenderSnorm.h>
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tc.h>
#include <LibWeb/WebGL/OpenGLContext.h>
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
@ -75,6 +76,7 @@ void WebGL2RenderingContext::visit_edges(Cell::Visitor& visitor)
WebGL2RenderingContextImpl::visit_edges(visitor);
visitor.visit(m_canvas_element);
visitor.visit(m_ext_color_buffer_float_extension);
visitor.visit(m_ext_render_snorm);
visitor.visit(m_webgl_compressed_texture_s3tc_extension);
}
@ -182,6 +184,15 @@ JS::Object* WebGL2RenderingContext::get_extension(String const& name)
return m_ext_color_buffer_float_extension;
}
if (name.equals_ignoring_ascii_case("EXT_render_snorm"sv)) {
if (!m_ext_render_snorm) {
m_ext_render_snorm = MUST(Extensions::EXTRenderSnorm::create(realm(), *this));
}
VERIFY(m_ext_render_snorm);
return m_ext_render_snorm;
}
return nullptr;
}

View File

@ -83,6 +83,7 @@ private:
// Extensions
// "Multiple calls to getExtension with the same extension string, taking into account case-insensitive comparison, must return the same object as long as the extension is enabled."
GC::Ptr<Extensions::EXTColorBufferFloat> m_ext_color_buffer_float_extension;
GC::Ptr<Extensions::EXTRenderSnorm> m_ext_render_snorm;
GC::Ptr<Extensions::WebGLCompressedTextureS3tc> m_webgl_compressed_texture_s3tc_extension;
virtual void set_error(GLenum error) override;

View File

@ -471,6 +471,7 @@ libweb_js_bindings(WebAudio/StereoPannerNode)
libweb_js_bindings(WebGL/Extensions/ANGLEInstancedArrays)
libweb_js_bindings(WebGL/Extensions/EXTBlendMinMax)
libweb_js_bindings(WebGL/Extensions/EXTColorBufferFloat)
libweb_js_bindings(WebGL/Extensions/EXTRenderSnorm)
libweb_js_bindings(WebGL/Extensions/OESVertexArrayObject)
libweb_js_bindings(WebGL/Extensions/WebGLCompressedTextureS3tc)
libweb_js_bindings(WebGL/Extensions/WebGLDrawBuffers)