Skip to content

Commit 93d3ebf

Browse files
Lubrsigmta
authored andcommitted
LibWeb/WebGL2: Implement the EXT_render_snorm extension
1 parent 7ba496b commit 93d3ebf

File tree

8 files changed

+99
-0
lines changed

8 files changed

+99
-0
lines changed

Libraries/LibWeb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ set(SOURCES
10231023
WebGL/Extensions/ANGLEInstancedArrays.cpp
10241024
WebGL/Extensions/EXTBlendMinMax.cpp
10251025
WebGL/Extensions/EXTColorBufferFloat.cpp
1026+
WebGL/Extensions/EXTRenderSnorm.cpp
10261027
WebGL/Extensions/OESVertexArrayObject.cpp
10271028
WebGL/Extensions/WebGLCompressedTextureS3tc.cpp
10281029
WebGL/Extensions/WebGLDrawBuffers.cpp

Libraries/LibWeb/Forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,7 @@ namespace Web::WebGL::Extensions {
12241224
class ANGLEInstancedArrays;
12251225
class EXTBlendMinMax;
12261226
class EXTColorBufferFloat;
1227+
class EXTRenderSnorm;
12271228
class OESVertexArrayObject;
12281229
class WebGLCompressedTextureS3tc;
12291230
class WebGLDrawBuffers;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#include <LibJS/Runtime/Realm.h>
8+
#include <LibWeb/Bindings/EXTRenderSnormPrototype.h>
9+
#include <LibWeb/Bindings/Intrinsics.h>
10+
#include <LibWeb/WebGL/Extensions/EXTRenderSnorm.h>
11+
#include <LibWeb/WebGL/OpenGLContext.h>
12+
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
13+
14+
namespace Web::WebGL::Extensions {
15+
16+
GC_DEFINE_ALLOCATOR(EXTRenderSnorm);
17+
18+
JS::ThrowCompletionOr<GC::Ptr<EXTRenderSnorm>> EXTRenderSnorm::create(JS::Realm& realm, GC::Ref<WebGL2RenderingContext> context)
19+
{
20+
return realm.create<EXTRenderSnorm>(realm, context);
21+
}
22+
23+
EXTRenderSnorm::EXTRenderSnorm(JS::Realm& realm, GC::Ref<WebGL2RenderingContext> context)
24+
: PlatformObject(realm)
25+
, m_context(context)
26+
{
27+
m_context->context().request_extension("GL_EXT_render_snorm");
28+
}
29+
30+
void EXTRenderSnorm::initialize(JS::Realm& realm)
31+
{
32+
WEB_SET_PROTOTYPE_FOR_INTERFACE(EXTRenderSnorm);
33+
Base::initialize(realm);
34+
}
35+
36+
void EXTRenderSnorm::visit_edges(Visitor& visitor)
37+
{
38+
Base::visit_edges(visitor);
39+
visitor.visit(m_context);
40+
}
41+
42+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
#include <LibWeb/Bindings/PlatformObject.h>
10+
#include <LibWeb/Forward.h>
11+
12+
namespace Web::WebGL::Extensions {
13+
14+
class EXTRenderSnorm : public Bindings::PlatformObject {
15+
WEB_PLATFORM_OBJECT(EXTRenderSnorm, Bindings::PlatformObject);
16+
GC_DECLARE_ALLOCATOR(EXTRenderSnorm);
17+
18+
public:
19+
static JS::ThrowCompletionOr<GC::Ptr<EXTRenderSnorm>> create(JS::Realm&, GC::Ref<WebGL2RenderingContext>);
20+
21+
protected:
22+
void initialize(JS::Realm&) override;
23+
void visit_edges(Visitor&) override;
24+
25+
private:
26+
EXTRenderSnorm(JS::Realm&, GC::Ref<WebGL2RenderingContext>);
27+
28+
GC::Ref<WebGL2RenderingContext> m_context;
29+
};
30+
31+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import <WebGL/Types.idl>
2+
3+
// https://registry.khronos.org/webgl/extensions/EXT_render_snorm/
4+
// NOTE: Original EXT_render_snorm name is changed to title case,
5+
// so it matches corresponding C++ class name, and does not require
6+
// IDL generator to handle snake_case to TitleCase conversion.
7+
// Having a different name is totally fine, because LegacyNoInterfaceObject
8+
// prevents the name from being exposed to JavaScript.
9+
[Exposed=(Window,Worker), LegacyNoInterfaceObject]
10+
interface EXTRenderSnorm {
11+
};

Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <LibWeb/Painting/Paintable.h>
1717
#include <LibWeb/WebGL/EventNames.h>
1818
#include <LibWeb/WebGL/Extensions/EXTColorBufferFloat.h>
19+
#include <LibWeb/WebGL/Extensions/EXTRenderSnorm.h>
1920
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tc.h>
2021
#include <LibWeb/WebGL/OpenGLContext.h>
2122
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
@@ -75,6 +76,7 @@ void WebGL2RenderingContext::visit_edges(Cell::Visitor& visitor)
7576
WebGL2RenderingContextImpl::visit_edges(visitor);
7677
visitor.visit(m_canvas_element);
7778
visitor.visit(m_ext_color_buffer_float_extension);
79+
visitor.visit(m_ext_render_snorm);
7880
visitor.visit(m_webgl_compressed_texture_s3tc_extension);
7981
}
8082

@@ -182,6 +184,15 @@ JS::Object* WebGL2RenderingContext::get_extension(String const& name)
182184
return m_ext_color_buffer_float_extension;
183185
}
184186

187+
if (name.equals_ignoring_ascii_case("EXT_render_snorm"sv)) {
188+
if (!m_ext_render_snorm) {
189+
m_ext_render_snorm = MUST(Extensions::EXTRenderSnorm::create(realm(), *this));
190+
}
191+
192+
VERIFY(m_ext_render_snorm);
193+
return m_ext_render_snorm;
194+
}
195+
185196
return nullptr;
186197
}
187198

Libraries/LibWeb/WebGL/WebGL2RenderingContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class WebGL2RenderingContext : public Bindings::PlatformObject
8383
// Extensions
8484
// "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."
8585
GC::Ptr<Extensions::EXTColorBufferFloat> m_ext_color_buffer_float_extension;
86+
GC::Ptr<Extensions::EXTRenderSnorm> m_ext_render_snorm;
8687
GC::Ptr<Extensions::WebGLCompressedTextureS3tc> m_webgl_compressed_texture_s3tc_extension;
8788

8889
virtual void set_error(GLenum error) override;

Libraries/LibWeb/idl_files.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ libweb_js_bindings(WebAudio/StereoPannerNode)
471471
libweb_js_bindings(WebGL/Extensions/ANGLEInstancedArrays)
472472
libweb_js_bindings(WebGL/Extensions/EXTBlendMinMax)
473473
libweb_js_bindings(WebGL/Extensions/EXTColorBufferFloat)
474+
libweb_js_bindings(WebGL/Extensions/EXTRenderSnorm)
474475
libweb_js_bindings(WebGL/Extensions/OESVertexArrayObject)
475476
libweb_js_bindings(WebGL/Extensions/WebGLCompressedTextureS3tc)
476477
libweb_js_bindings(WebGL/Extensions/WebGLDrawBuffers)

0 commit comments

Comments
 (0)