diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 10d76757361..86854011fdd 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -1031,6 +1031,7 @@ set(SOURCES WebGL/Extensions/EXTRenderSnorm.cpp WebGL/Extensions/EXTTextureFilterAnisotropic.cpp WebGL/Extensions/EXTTextureNorm16.cpp + WebGL/Extensions/OESStandardDerivatives.cpp WebGL/Extensions/OESVertexArrayObject.cpp WebGL/Extensions/WebGLCompressedTextureS3tc.cpp WebGL/Extensions/WebGLCompressedTextureS3tcSrgb.cpp diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index a59eaf7fc3b..a79a9291f64 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -1236,6 +1236,7 @@ class EXTColorBufferFloat; class EXTRenderSnorm; class EXTTextureFilterAnisotropic; class EXTTextureNorm16; +class OESStandardDerivatives; class OESVertexArrayObject; class WebGLCompressedTextureS3tc; class WebGLCompressedTextureS3tcSrgb; diff --git a/Libraries/LibWeb/WebGL/Extensions/OESStandardDerivatives.cpp b/Libraries/LibWeb/WebGL/Extensions/OESStandardDerivatives.cpp new file mode 100644 index 00000000000..5e265e8fb2f --- /dev/null +++ b/Libraries/LibWeb/WebGL/Extensions/OESStandardDerivatives.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025, Undefine + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include + +namespace Web::WebGL::Extensions { + +GC_DEFINE_ALLOCATOR(OESStandardDerivatives); + +JS::ThrowCompletionOr> OESStandardDerivatives::create(JS::Realm& realm, GC::Ref context) +{ + return realm.create(realm, context); +} + +OESStandardDerivatives::OESStandardDerivatives(JS::Realm& realm, GC::Ref context) + : PlatformObject(realm) + , m_context(context) +{ + m_context->context().request_extension("GL_OES_standard_derivatives"); +} + +void OESStandardDerivatives::initialize(JS::Realm& realm) +{ + WEB_SET_PROTOTYPE_FOR_INTERFACE(OESStandardDerivatives); + Base::initialize(realm); +} + +void OESStandardDerivatives::visit_edges(Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_context); +} + +} diff --git a/Libraries/LibWeb/WebGL/Extensions/OESStandardDerivatives.h b/Libraries/LibWeb/WebGL/Extensions/OESStandardDerivatives.h new file mode 100644 index 00000000000..b77c3c3c8c5 --- /dev/null +++ b/Libraries/LibWeb/WebGL/Extensions/OESStandardDerivatives.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025, Undefine + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::WebGL::Extensions { + +class OESStandardDerivatives : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(OESStandardDerivatives, Bindings::PlatformObject); + GC_DECLARE_ALLOCATOR(OESStandardDerivatives); + +public: + static JS::ThrowCompletionOr> create(JS::Realm&, GC::Ref); + +protected: + void initialize(JS::Realm&) override; + void visit_edges(Visitor&) override; + +private: + OESStandardDerivatives(JS::Realm&, GC::Ref); + + GC::Ref m_context; +}; + +} diff --git a/Libraries/LibWeb/WebGL/Extensions/OESStandardDerivatives.idl b/Libraries/LibWeb/WebGL/Extensions/OESStandardDerivatives.idl new file mode 100644 index 00000000000..12638b52e5e --- /dev/null +++ b/Libraries/LibWeb/WebGL/Extensions/OESStandardDerivatives.idl @@ -0,0 +1,12 @@ +#import + +// https://registry.khronos.org/webgl/extensions/OES_standard_derivatives/ +// NOTE: Original OES_standard_derivatives 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 OESStandardDerivatives { + const GLenum FRAGMENT_SHADER_DERIVATIVE_HINT_OES = 0x8B8B; +}; diff --git a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp index b24fd1f98f3..ceef7a6c640 100644 --- a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp +++ b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp @@ -252,6 +252,11 @@ bool WebGL2RenderingContext::angle_instanced_arrays_extension_enabled() const return false; } +bool WebGL2RenderingContext::oes_standard_derivatives_extension_enabled() const +{ + return false; +} + ReadonlySpan WebGL2RenderingContext::enabled_compressed_texture_formats() const { return m_enabled_compressed_texture_formats; diff --git a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h index 9d52ac5fec0..55c66b38c09 100644 --- a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h +++ b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h @@ -53,6 +53,7 @@ public: virtual bool ext_texture_filter_anisotropic_extension_enabled() const override; virtual bool angle_instanced_arrays_extension_enabled() const override; + virtual bool oes_standard_derivatives_extension_enabled() const override; virtual ReadonlySpan enabled_compressed_texture_formats() const override; private: diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp b/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp index 479e200c134..ab2d54b4dd6 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +99,7 @@ void WebGLRenderingContext::visit_edges(Cell::Visitor& visitor) visitor.visit(m_angle_instanced_arrays_extension); visitor.visit(m_ext_blend_min_max_extension); visitor.visit(m_ext_texture_filter_anisotropic); + visitor.visit(m_oes_standard_derivatives_object_extension); visitor.visit(m_oes_vertex_array_object_extension); visitor.visit(m_webgl_compressed_texture_s3tc_extension); visitor.visit(m_webgl_compressed_texture_s3tc_srgb_extension); @@ -208,6 +210,15 @@ JS::Object* WebGLRenderingContext::get_extension(String const& name) return m_ext_texture_filter_anisotropic; } + if (name.equals_ignoring_ascii_case("OES_standard_derivatives"sv)) { + if (!m_oes_standard_derivatives_object_extension) { + m_oes_standard_derivatives_object_extension = MUST(Extensions::OESStandardDerivatives::create(realm(), *this)); + } + + VERIFY(m_oes_standard_derivatives_object_extension); + return m_oes_standard_derivatives_object_extension; + } + if (name.equals_ignoring_ascii_case("OES_vertex_array_object"sv)) { if (!m_oes_vertex_array_object_extension) { m_oes_vertex_array_object_extension = MUST(Extensions::OESVertexArrayObject::create(realm(), *this)); @@ -279,6 +290,11 @@ bool WebGLRenderingContext::angle_instanced_arrays_extension_enabled() const return !!m_angle_instanced_arrays_extension; } +bool WebGLRenderingContext::oes_standard_derivatives_extension_enabled() const +{ + return !!m_oes_standard_derivatives_object_extension; +} + ReadonlySpan WebGLRenderingContext::enabled_compressed_texture_formats() const { return m_enabled_compressed_texture_formats; diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContext.h b/Libraries/LibWeb/WebGL/WebGLRenderingContext.h index e2f9025ed82..aaafc7d3cf9 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContext.h +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContext.h @@ -52,6 +52,7 @@ public: virtual bool ext_texture_filter_anisotropic_extension_enabled() const override; virtual bool angle_instanced_arrays_extension_enabled() const override; + virtual bool oes_standard_derivatives_extension_enabled() const override; virtual ReadonlySpan enabled_compressed_texture_formats() const override; private: @@ -88,6 +89,7 @@ private: GC::Ptr m_angle_instanced_arrays_extension; GC::Ptr m_ext_blend_min_max_extension; GC::Ptr m_ext_texture_filter_anisotropic; + GC::Ptr m_oes_standard_derivatives_object_extension; GC::Ptr m_oes_vertex_array_object_extension; GC::Ptr m_webgl_compressed_texture_s3tc_extension; GC::Ptr m_webgl_compressed_texture_s3tc_srgb_extension; diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h index d062690f8c6..054e12f8771 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h @@ -46,6 +46,7 @@ public: virtual OpenGLContext& context() = 0; virtual bool ext_texture_filter_anisotropic_extension_enabled() const = 0; virtual bool angle_instanced_arrays_extension_enabled() const = 0; + virtual bool oes_standard_derivatives_extension_enabled() const = 0; virtual ReadonlySpan enabled_compressed_texture_formats() const = 0; template diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.cpp b/Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.cpp index 9933420a1f8..8f8530812f7 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.cpp +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.cpp @@ -1236,8 +1236,8 @@ JS::Value WebGLRenderingContextImpl::get_parameter(WebIDL::UnsignedLong pname) return JS::Int32Array::create(m_realm, 4, array_buffer); } - case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: { - if (m_context->webgl_version() == OpenGLContext::WebGLVersion::WebGL2) { // FIXME: Allow this code path for GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES + case GL_FRAGMENT_SHADER_DERIVATIVE_HINT: { // NOTE: This has the same value as GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES + if (oes_standard_derivatives_extension_enabled() || m_context->webgl_version() == OpenGLContext::WebGLVersion::WebGL2) { GLint result { 0 }; glGetIntegervRobustANGLE(GL_FRAGMENT_SHADER_DERIVATIVE_HINT, 1, nullptr, &result); return JS::Value(result); diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake index 49e9f8861b7..868c1b672be 100644 --- a/Libraries/LibWeb/idl_files.cmake +++ b/Libraries/LibWeb/idl_files.cmake @@ -475,6 +475,7 @@ libweb_js_bindings(WebGL/Extensions/EXTColorBufferFloat) libweb_js_bindings(WebGL/Extensions/EXTRenderSnorm) libweb_js_bindings(WebGL/Extensions/EXTTextureFilterAnisotropic) libweb_js_bindings(WebGL/Extensions/EXTTextureNorm16) +libweb_js_bindings(WebGL/Extensions/OESStandardDerivatives) libweb_js_bindings(WebGL/Extensions/OESVertexArrayObject) libweb_js_bindings(WebGL/Extensions/WebGLCompressedTextureS3tc) libweb_js_bindings(WebGL/Extensions/WebGLCompressedTextureS3tcSrgb)