Skip to content

Commit ddf60eb

Browse files
Lubrsigmta
authored andcommitted
LibWeb/WebGL2: Implement the EXT_texture_norm16 extension
1 parent 93d3ebf commit ddf60eb

File tree

8 files changed

+107
-0
lines changed

8 files changed

+107
-0
lines changed

Libraries/LibWeb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ set(SOURCES
10241024
WebGL/Extensions/EXTBlendMinMax.cpp
10251025
WebGL/Extensions/EXTColorBufferFloat.cpp
10261026
WebGL/Extensions/EXTRenderSnorm.cpp
1027+
WebGL/Extensions/EXTTextureNorm16.cpp
10271028
WebGL/Extensions/OESVertexArrayObject.cpp
10281029
WebGL/Extensions/WebGLCompressedTextureS3tc.cpp
10291030
WebGL/Extensions/WebGLDrawBuffers.cpp

Libraries/LibWeb/Forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ class ANGLEInstancedArrays;
12251225
class EXTBlendMinMax;
12261226
class EXTColorBufferFloat;
12271227
class EXTRenderSnorm;
1228+
class EXTTextureNorm16;
12281229
class OESVertexArrayObject;
12291230
class WebGLCompressedTextureS3tc;
12301231
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/EXTTextureNorm16Prototype.h>
9+
#include <LibWeb/Bindings/Intrinsics.h>
10+
#include <LibWeb/WebGL/Extensions/EXTTextureNorm16.h>
11+
#include <LibWeb/WebGL/OpenGLContext.h>
12+
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
13+
14+
namespace Web::WebGL::Extensions {
15+
16+
GC_DEFINE_ALLOCATOR(EXTTextureNorm16);
17+
18+
JS::ThrowCompletionOr<GC::Ptr<EXTTextureNorm16>> EXTTextureNorm16::create(JS::Realm& realm, GC::Ref<WebGL2RenderingContext> context)
19+
{
20+
return realm.create<EXTTextureNorm16>(realm, context);
21+
}
22+
23+
EXTTextureNorm16::EXTTextureNorm16(JS::Realm& realm, GC::Ref<WebGL2RenderingContext> context)
24+
: PlatformObject(realm)
25+
, m_context(context)
26+
{
27+
m_context->context().request_extension("GL_EXT_texture_norm16");
28+
}
29+
30+
void EXTTextureNorm16::initialize(JS::Realm& realm)
31+
{
32+
WEB_SET_PROTOTYPE_FOR_INTERFACE(EXTTextureNorm16);
33+
Base::initialize(realm);
34+
}
35+
36+
void EXTTextureNorm16::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 EXTTextureNorm16 : public Bindings::PlatformObject {
15+
WEB_PLATFORM_OBJECT(EXTTextureNorm16, Bindings::PlatformObject);
16+
GC_DECLARE_ALLOCATOR(EXTTextureNorm16);
17+
18+
public:
19+
static JS::ThrowCompletionOr<GC::Ptr<EXTTextureNorm16>> 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+
EXTTextureNorm16(JS::Realm&, GC::Ref<WebGL2RenderingContext>);
27+
28+
GC::Ref<WebGL2RenderingContext> m_context;
29+
};
30+
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#import <WebGL/Types.idl>
2+
3+
// https://registry.khronos.org/webgl/extensions/EXT_texture_norm16/
4+
// NOTE: Original EXT_texture_norm16 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 EXTTextureNorm16 {
11+
const GLenum R16_EXT = 0x822A;
12+
const GLenum RG16_EXT = 0x822C;
13+
const GLenum RGB16_EXT = 0x8054;
14+
const GLenum RGBA16_EXT = 0x805B;
15+
const GLenum R16_SNORM_EXT = 0x8F98;
16+
const GLenum RG16_SNORM_EXT = 0x8F99;
17+
const GLenum RGB16_SNORM_EXT = 0x8F9A;
18+
const GLenum RGBA16_SNORM_EXT = 0x8F9B;
19+
};

Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <LibWeb/WebGL/EventNames.h>
1818
#include <LibWeb/WebGL/Extensions/EXTColorBufferFloat.h>
1919
#include <LibWeb/WebGL/Extensions/EXTRenderSnorm.h>
20+
#include <LibWeb/WebGL/Extensions/EXTTextureNorm16.h>
2021
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tc.h>
2122
#include <LibWeb/WebGL/OpenGLContext.h>
2223
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
@@ -77,6 +78,7 @@ void WebGL2RenderingContext::visit_edges(Cell::Visitor& visitor)
7778
visitor.visit(m_canvas_element);
7879
visitor.visit(m_ext_color_buffer_float_extension);
7980
visitor.visit(m_ext_render_snorm);
81+
visitor.visit(m_ext_texture_norm16);
8082
visitor.visit(m_webgl_compressed_texture_s3tc_extension);
8183
}
8284

@@ -193,6 +195,15 @@ JS::Object* WebGL2RenderingContext::get_extension(String const& name)
193195
return m_ext_render_snorm;
194196
}
195197

198+
if (name.equals_ignoring_ascii_case("EXT_texture_norm16"sv)) {
199+
if (!m_ext_texture_norm16) {
200+
m_ext_texture_norm16 = MUST(Extensions::EXTTextureNorm16::create(realm(), *this));
201+
}
202+
203+
VERIFY(m_ext_texture_norm16);
204+
return m_ext_texture_norm16;
205+
}
206+
196207
return nullptr;
197208
}
198209

Libraries/LibWeb/WebGL/WebGL2RenderingContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class WebGL2RenderingContext : public Bindings::PlatformObject
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;
8686
GC::Ptr<Extensions::EXTRenderSnorm> m_ext_render_snorm;
87+
GC::Ptr<Extensions::EXTTextureNorm16> m_ext_texture_norm16;
8788
GC::Ptr<Extensions::WebGLCompressedTextureS3tc> m_webgl_compressed_texture_s3tc_extension;
8889

8990
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
@@ -472,6 +472,7 @@ libweb_js_bindings(WebGL/Extensions/ANGLEInstancedArrays)
472472
libweb_js_bindings(WebGL/Extensions/EXTBlendMinMax)
473473
libweb_js_bindings(WebGL/Extensions/EXTColorBufferFloat)
474474
libweb_js_bindings(WebGL/Extensions/EXTRenderSnorm)
475+
libweb_js_bindings(WebGL/Extensions/EXTTextureNorm16)
475476
libweb_js_bindings(WebGL/Extensions/OESVertexArrayObject)
476477
libweb_js_bindings(WebGL/Extensions/WebGLCompressedTextureS3tc)
477478
libweb_js_bindings(WebGL/Extensions/WebGLDrawBuffers)

0 commit comments

Comments
 (0)