mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00:00
LibWeb/WebGL: Implement WEBGL_compressed_texture_s3tc extension
This commit is contained in:
parent
484008d440
commit
958938655d
Notes:
github-actions[bot]
2025-02-09 00:01:44 +00:00
Author: https://github.com/Lubrsi Commit: https://github.com/LadybirdBrowser/ladybird/commit/958938655d5 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3385
11 changed files with 137 additions and 2 deletions
|
@ -834,6 +834,7 @@ set(SOURCES
|
|||
WebDriver/UserPrompt.cpp
|
||||
WebGL/Extensions/ANGLEInstancedArrays.cpp
|
||||
WebGL/Extensions/OESVertexArrayObject.cpp
|
||||
WebGL/Extensions/WebGLCompressedTextureS3tc.cpp
|
||||
WebGL/Extensions/WebGLDrawBuffers.cpp
|
||||
WebGL/Extensions/WebGLVertexArrayObjectOES.cpp
|
||||
WebGL/EventNames.cpp
|
||||
|
|
|
@ -883,6 +883,7 @@ class WebGLVertexArrayObject;
|
|||
namespace Web::WebGL::Extensions {
|
||||
class ANGLEInstancedArrays;
|
||||
class OESVertexArrayObject;
|
||||
class WebGLCompressedTextureS3tc;
|
||||
class WebGLDrawBuffers;
|
||||
class WebGLVertexArrayObjectOES;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/WebGLCompressedTextureS3tcPrototype.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tc.h>
|
||||
#include <LibWeb/WebGL/OpenGLContext.h>
|
||||
|
||||
namespace Web::WebGL::Extensions {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(WebGLCompressedTextureS3tc);
|
||||
|
||||
JS::ThrowCompletionOr<GC::Ptr<WebGLCompressedTextureS3tc>> WebGLCompressedTextureS3tc::create(JS::Realm& realm, WebGLRenderingContextBase* context)
|
||||
{
|
||||
return realm.create<WebGLCompressedTextureS3tc>(realm, context);
|
||||
}
|
||||
|
||||
WebGLCompressedTextureS3tc::WebGLCompressedTextureS3tc(JS::Realm& realm, WebGLRenderingContextBase* context)
|
||||
: PlatformObject(realm)
|
||||
, m_context(context)
|
||||
{
|
||||
m_context->context().request_extension("GL_EXT_texture_compression_dxt1");
|
||||
m_context->context().request_extension("GL_ANGLE_texture_compression_dxt3");
|
||||
m_context->context().request_extension("GL_ANGLE_texture_compression_dxt5");
|
||||
}
|
||||
|
||||
void WebGLCompressedTextureS3tc::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLCompressedTextureS3tc);
|
||||
}
|
||||
|
||||
void WebGLCompressedTextureS3tc::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_context->gc_cell());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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>
|
||||
#include <LibWeb/WebGL/WebGLRenderingContextBase.h>
|
||||
|
||||
namespace Web::WebGL::Extensions {
|
||||
|
||||
class WebGLCompressedTextureS3tc : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(WebGLCompressedTextureS3tc, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(WebGLCompressedTextureS3tc);
|
||||
|
||||
public:
|
||||
static JS::ThrowCompletionOr<GC::Ptr<WebGLCompressedTextureS3tc>> create(JS::Realm&, WebGLRenderingContextBase*);
|
||||
|
||||
protected:
|
||||
void initialize(JS::Realm&) override;
|
||||
void visit_edges(Visitor&) override;
|
||||
|
||||
private:
|
||||
WebGLCompressedTextureS3tc(JS::Realm&, WebGLRenderingContextBase*);
|
||||
|
||||
// FIXME: It should be GC::Ptr instead of raw pointer, but we need to make WebGLRenderingContextBase inherit from PlatformObject first.
|
||||
WebGLRenderingContextBase* m_context;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#import <WebGL/Types.idl>
|
||||
|
||||
// https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_s3tc/
|
||||
// NOTE: Original WEBGL_compressed_texture_s3tc 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 WebGLCompressedTextureS3tc {
|
||||
// Compressed Texture Formats
|
||||
const GLenum COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
|
||||
const GLenum COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1;
|
||||
const GLenum COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2;
|
||||
const GLenum COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
|
||||
};
|
|
@ -12,8 +12,10 @@
|
|||
#include <LibWeb/Bindings/WebGL2RenderingContextPrototype.h>
|
||||
#include <LibWeb/HTML/HTMLCanvasElement.h>
|
||||
#include <LibWeb/HTML/TraversableNavigable.h>
|
||||
#include <LibWeb/Infra/Strings.h>
|
||||
#include <LibWeb/Painting/Paintable.h>
|
||||
#include <LibWeb/WebGL/EventNames.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tc.h>
|
||||
#include <LibWeb/WebGL/OpenGLContext.h>
|
||||
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
|
||||
#include <LibWeb/WebGL/WebGLContextEvent.h>
|
||||
|
@ -71,6 +73,7 @@ void WebGL2RenderingContext::visit_edges(Cell::Visitor& visitor)
|
|||
Base::visit_edges(visitor);
|
||||
WebGL2RenderingContextImpl::visit_edges(visitor);
|
||||
visitor.visit(m_canvas_element);
|
||||
visitor.visit(m_webgl_compressed_texture_s3tc_extension);
|
||||
}
|
||||
|
||||
void WebGL2RenderingContext::present()
|
||||
|
@ -154,8 +157,29 @@ Optional<Vector<String>> WebGL2RenderingContext::get_supported_extensions()
|
|||
return context().get_supported_extensions();
|
||||
}
|
||||
|
||||
JS::Object* WebGL2RenderingContext::get_extension(String const&)
|
||||
JS::Object* WebGL2RenderingContext::get_extension(String const& name)
|
||||
{
|
||||
// Returns an object if, and only if, name is an ASCII case-insensitive match [HTML] for one of the names returned
|
||||
// from getSupportedExtensions; otherwise, returns null. The object returned from getExtension contains any constants
|
||||
// or functions provided by the extension. A returned object may have no constants or functions if the extension does
|
||||
// not define any, but a unique object must still be returned. That object is used to indicate that the extension has
|
||||
// been enabled.
|
||||
auto supported_extensions = get_supported_extensions();
|
||||
auto supported_extension_iterator = supported_extensions->find_if([&name](String const& supported_extension) {
|
||||
return Infra::is_ascii_case_insensitive_match(supported_extension, name);
|
||||
});
|
||||
if (supported_extension_iterator == supported_extensions->end())
|
||||
return nullptr;
|
||||
|
||||
if (Infra::is_ascii_case_insensitive_match(name, "WEBGL_compressed_texture_s3tc"sv)) {
|
||||
if (!m_webgl_compressed_texture_s3tc_extension) {
|
||||
m_webgl_compressed_texture_s3tc_extension = MUST(Extensions::WebGLCompressedTextureS3tc::create(realm(), this));
|
||||
}
|
||||
|
||||
VERIFY(m_webgl_compressed_texture_s3tc_extension);
|
||||
return m_webgl_compressed_texture_s3tc_extension;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,10 @@ private:
|
|||
|
||||
GLenum m_error { 0 };
|
||||
|
||||
// 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::WebGLCompressedTextureS3tc> m_webgl_compressed_texture_s3tc_extension;
|
||||
|
||||
virtual void set_error(GLenum error) override;
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibWeb/WebGL/EventNames.h>
|
||||
#include <LibWeb/WebGL/Extensions/ANGLEInstancedArrays.h>
|
||||
#include <LibWeb/WebGL/Extensions/OESVertexArrayObject.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tc.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLDrawBuffers.h>
|
||||
#include <LibWeb/WebGL/OpenGLContext.h>
|
||||
#include <LibWeb/WebGL/WebGLContextEvent.h>
|
||||
|
@ -93,6 +94,7 @@ void WebGLRenderingContext::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_canvas_element);
|
||||
visitor.visit(m_angle_instanced_arrays_extension);
|
||||
visitor.visit(m_oes_vertex_array_object_extension);
|
||||
visitor.visit(m_webgl_compressed_texture_s3tc_extension);
|
||||
visitor.visit(m_webgl_draw_buffers_extension);
|
||||
}
|
||||
|
||||
|
@ -209,6 +211,15 @@ JS::Object* WebGLRenderingContext::get_extension(String const& name)
|
|||
return m_oes_vertex_array_object_extension;
|
||||
}
|
||||
|
||||
if (Infra::is_ascii_case_insensitive_match(name, "WEBGL_compressed_texture_s3tc"sv)) {
|
||||
if (!m_webgl_compressed_texture_s3tc_extension) {
|
||||
m_webgl_compressed_texture_s3tc_extension = MUST(Extensions::WebGLCompressedTextureS3tc::create(realm(), this));
|
||||
}
|
||||
|
||||
VERIFY(m_webgl_compressed_texture_s3tc_extension);
|
||||
return m_webgl_compressed_texture_s3tc_extension;
|
||||
}
|
||||
|
||||
if (Infra::is_ascii_case_insensitive_match(name, "WEBGL_draw_buffers"sv)) {
|
||||
if (!m_webgl_draw_buffers_extension) {
|
||||
m_webgl_draw_buffers_extension = MUST(Extensions::WebGLDrawBuffers::create(realm(), *this));
|
||||
|
|
|
@ -83,6 +83,7 @@ private:
|
|||
// "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::ANGLEInstancedArrays> m_angle_instanced_arrays_extension;
|
||||
GC::Ptr<Extensions::OESVertexArrayObject> m_oes_vertex_array_object_extension;
|
||||
GC::Ptr<Extensions::WebGLCompressedTextureS3tc> m_webgl_compressed_texture_s3tc_extension;
|
||||
GC::Ptr<Extensions::WebGLDrawBuffers> m_webgl_draw_buffers_extension;
|
||||
|
||||
virtual void set_error(GLenum error) override;
|
||||
|
|
|
@ -388,6 +388,7 @@ libweb_js_bindings(WebAudio/PeriodicWave)
|
|||
libweb_js_bindings(WebAudio/StereoPannerNode)
|
||||
libweb_js_bindings(WebGL/Extensions/ANGLEInstancedArrays)
|
||||
libweb_js_bindings(WebGL/Extensions/OESVertexArrayObject)
|
||||
libweb_js_bindings(WebGL/Extensions/WebGLCompressedTextureS3tc)
|
||||
libweb_js_bindings(WebGL/Extensions/WebGLDrawBuffers)
|
||||
libweb_js_bindings(WebGL/Extensions/WebGLVertexArrayObjectOES)
|
||||
libweb_js_bindings(WebGL/WebGL2RenderingContext)
|
||||
|
|
|
@ -832,7 +832,7 @@ class @class_name@ : public WebGLRenderingContextBase {
|
|||
public:
|
||||
@class_name@(JS::Realm&, NonnullOwnPtr<OpenGLContext>);
|
||||
|
||||
OpenGLContext& context() { return *m_context; }
|
||||
virtual OpenGLContext& context() override { return *m_context; }
|
||||
|
||||
virtual void present() = 0;
|
||||
virtual void needs_to_present() = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue