Skip to content

Commit d4ac9fc

Browse files
cqundefineawesomekling
authored andcommitted
LibWeb: Implement WebGL extension OES_standard_derivatives
1 parent 2bf3588 commit d4ac9fc

12 files changed

+115
-2
lines changed

Libraries/LibWeb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ set(SOURCES
10311031
WebGL/Extensions/EXTRenderSnorm.cpp
10321032
WebGL/Extensions/EXTTextureFilterAnisotropic.cpp
10331033
WebGL/Extensions/EXTTextureNorm16.cpp
1034+
WebGL/Extensions/OESStandardDerivatives.cpp
10341035
WebGL/Extensions/OESVertexArrayObject.cpp
10351036
WebGL/Extensions/WebGLCompressedTextureS3tc.cpp
10361037
WebGL/Extensions/WebGLCompressedTextureS3tcSrgb.cpp

Libraries/LibWeb/Forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ class EXTColorBufferFloat;
12361236
class EXTRenderSnorm;
12371237
class EXTTextureFilterAnisotropic;
12381238
class EXTTextureNorm16;
1239+
class OESStandardDerivatives;
12391240
class OESVertexArrayObject;
12401241
class WebGLCompressedTextureS3tc;
12411242
class WebGLCompressedTextureS3tcSrgb;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2025, Undefine <undefine@undefine.pl>
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#include <LibJS/Runtime/Realm.h>
8+
#include <LibWeb/Bindings/Intrinsics.h>
9+
#include <LibWeb/Bindings/OESStandardDerivativesPrototype.h>
10+
#include <LibWeb/WebGL/Extensions/OESStandardDerivatives.h>
11+
#include <LibWeb/WebGL/OpenGLContext.h>
12+
#include <LibWeb/WebGL/WebGLRenderingContext.h>
13+
14+
namespace Web::WebGL::Extensions {
15+
16+
GC_DEFINE_ALLOCATOR(OESStandardDerivatives);
17+
18+
JS::ThrowCompletionOr<GC::Ptr<OESStandardDerivatives>> OESStandardDerivatives::create(JS::Realm& realm, GC::Ref<WebGLRenderingContext> context)
19+
{
20+
return realm.create<OESStandardDerivatives>(realm, context);
21+
}
22+
23+
OESStandardDerivatives::OESStandardDerivatives(JS::Realm& realm, GC::Ref<WebGLRenderingContext> context)
24+
: PlatformObject(realm)
25+
, m_context(context)
26+
{
27+
m_context->context().request_extension("GL_OES_standard_derivatives");
28+
}
29+
30+
void OESStandardDerivatives::initialize(JS::Realm& realm)
31+
{
32+
WEB_SET_PROTOTYPE_FOR_INTERFACE(OESStandardDerivatives);
33+
Base::initialize(realm);
34+
}
35+
36+
void OESStandardDerivatives::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, Undefine <undefine@undefine.pl>
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 OESStandardDerivatives : public Bindings::PlatformObject {
15+
WEB_PLATFORM_OBJECT(OESStandardDerivatives, Bindings::PlatformObject);
16+
GC_DECLARE_ALLOCATOR(OESStandardDerivatives);
17+
18+
public:
19+
static JS::ThrowCompletionOr<GC::Ptr<OESStandardDerivatives>> create(JS::Realm&, GC::Ref<WebGLRenderingContext>);
20+
21+
protected:
22+
void initialize(JS::Realm&) override;
23+
void visit_edges(Visitor&) override;
24+
25+
private:
26+
OESStandardDerivatives(JS::Realm&, GC::Ref<WebGLRenderingContext>);
27+
28+
GC::Ref<WebGLRenderingContext> m_context;
29+
};
30+
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import <WebGL/Types.idl>
2+
3+
// https://registry.khronos.org/webgl/extensions/OES_standard_derivatives/
4+
// NOTE: Original OES_standard_derivatives 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 OESStandardDerivatives {
11+
const GLenum FRAGMENT_SHADER_DERIVATIVE_HINT_OES = 0x8B8B;
12+
};

Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ bool WebGL2RenderingContext::angle_instanced_arrays_extension_enabled() const
252252
return false;
253253
}
254254

255+
bool WebGL2RenderingContext::oes_standard_derivatives_extension_enabled() const
256+
{
257+
return false;
258+
}
259+
255260
ReadonlySpan<WebIDL::UnsignedLong> WebGL2RenderingContext::enabled_compressed_texture_formats() const
256261
{
257262
return m_enabled_compressed_texture_formats;

Libraries/LibWeb/WebGL/WebGL2RenderingContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class WebGL2RenderingContext final : public Bindings::PlatformObject
5353

5454
virtual bool ext_texture_filter_anisotropic_extension_enabled() const override;
5555
virtual bool angle_instanced_arrays_extension_enabled() const override;
56+
virtual bool oes_standard_derivatives_extension_enabled() const override;
5657
virtual ReadonlySpan<WebIDL::UnsignedLong> enabled_compressed_texture_formats() const override;
5758

5859
private:

Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <LibWeb/WebGL/Extensions/ANGLEInstancedArrays.h>
1818
#include <LibWeb/WebGL/Extensions/EXTBlendMinMax.h>
1919
#include <LibWeb/WebGL/Extensions/EXTTextureFilterAnisotropic.h>
20+
#include <LibWeb/WebGL/Extensions/OESStandardDerivatives.h>
2021
#include <LibWeb/WebGL/Extensions/OESVertexArrayObject.h>
2122
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tc.h>
2223
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tcSrgb.h>
@@ -98,6 +99,7 @@ void WebGLRenderingContext::visit_edges(Cell::Visitor& visitor)
9899
visitor.visit(m_angle_instanced_arrays_extension);
99100
visitor.visit(m_ext_blend_min_max_extension);
100101
visitor.visit(m_ext_texture_filter_anisotropic);
102+
visitor.visit(m_oes_standard_derivatives_object_extension);
101103
visitor.visit(m_oes_vertex_array_object_extension);
102104
visitor.visit(m_webgl_compressed_texture_s3tc_extension);
103105
visitor.visit(m_webgl_compressed_texture_s3tc_srgb_extension);
@@ -208,6 +210,15 @@ JS::Object* WebGLRenderingContext::get_extension(String const& name)
208210
return m_ext_texture_filter_anisotropic;
209211
}
210212

213+
if (name.equals_ignoring_ascii_case("OES_standard_derivatives"sv)) {
214+
if (!m_oes_standard_derivatives_object_extension) {
215+
m_oes_standard_derivatives_object_extension = MUST(Extensions::OESStandardDerivatives::create(realm(), *this));
216+
}
217+
218+
VERIFY(m_oes_standard_derivatives_object_extension);
219+
return m_oes_standard_derivatives_object_extension;
220+
}
221+
211222
if (name.equals_ignoring_ascii_case("OES_vertex_array_object"sv)) {
212223
if (!m_oes_vertex_array_object_extension) {
213224
m_oes_vertex_array_object_extension = MUST(Extensions::OESVertexArrayObject::create(realm(), *this));
@@ -279,6 +290,11 @@ bool WebGLRenderingContext::angle_instanced_arrays_extension_enabled() const
279290
return !!m_angle_instanced_arrays_extension;
280291
}
281292

293+
bool WebGLRenderingContext::oes_standard_derivatives_extension_enabled() const
294+
{
295+
return !!m_oes_standard_derivatives_object_extension;
296+
}
297+
282298
ReadonlySpan<WebIDL::UnsignedLong> WebGLRenderingContext::enabled_compressed_texture_formats() const
283299
{
284300
return m_enabled_compressed_texture_formats;

Libraries/LibWeb/WebGL/WebGLRenderingContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class WebGLRenderingContext final : public Bindings::PlatformObject
5252

5353
virtual bool ext_texture_filter_anisotropic_extension_enabled() const override;
5454
virtual bool angle_instanced_arrays_extension_enabled() const override;
55+
virtual bool oes_standard_derivatives_extension_enabled() const override;
5556
virtual ReadonlySpan<WebIDL::UnsignedLong> enabled_compressed_texture_formats() const override;
5657

5758
private:
@@ -88,6 +89,7 @@ class WebGLRenderingContext final : public Bindings::PlatformObject
8889
GC::Ptr<Extensions::ANGLEInstancedArrays> m_angle_instanced_arrays_extension;
8990
GC::Ptr<Extensions::EXTBlendMinMax> m_ext_blend_min_max_extension;
9091
GC::Ptr<Extensions::EXTTextureFilterAnisotropic> m_ext_texture_filter_anisotropic;
92+
GC::Ptr<Extensions::OESStandardDerivatives> m_oes_standard_derivatives_object_extension;
9193
GC::Ptr<Extensions::OESVertexArrayObject> m_oes_vertex_array_object_extension;
9294
GC::Ptr<Extensions::WebGLCompressedTextureS3tc> m_webgl_compressed_texture_s3tc_extension;
9395
GC::Ptr<Extensions::WebGLCompressedTextureS3tcSrgb> m_webgl_compressed_texture_s3tc_srgb_extension;

Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class WebGLRenderingContextBase {
4646
virtual OpenGLContext& context() = 0;
4747
virtual bool ext_texture_filter_anisotropic_extension_enabled() const = 0;
4848
virtual bool angle_instanced_arrays_extension_enabled() const = 0;
49+
virtual bool oes_standard_derivatives_extension_enabled() const = 0;
4950
virtual ReadonlySpan<WebIDL::UnsignedLong> enabled_compressed_texture_formats() const = 0;
5051

5152
template<typename T>

0 commit comments

Comments
 (0)