mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb/WebGL: Implement the WEBGL_compressed_texture_s3tc_srgb extension
This commit is contained in:
parent
ddf60ebe9e
commit
d08915a0cd
Notes:
github-actions[bot]
2025-10-20 13:34:45 +00:00
Author: https://github.com/Lubrsi
Commit: d08915a0cd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6521
Reviewed-by: https://github.com/gmta ✅
10 changed files with 117 additions and 0 deletions
|
|
@ -1027,6 +1027,7 @@ set(SOURCES
|
|||
WebGL/Extensions/EXTTextureNorm16.cpp
|
||||
WebGL/Extensions/OESVertexArrayObject.cpp
|
||||
WebGL/Extensions/WebGLCompressedTextureS3tc.cpp
|
||||
WebGL/Extensions/WebGLCompressedTextureS3tcSrgb.cpp
|
||||
WebGL/Extensions/WebGLDrawBuffers.cpp
|
||||
WebGL/Extensions/WebGLVertexArrayObjectOES.cpp
|
||||
WebGL/OpenGLContext.cpp
|
||||
|
|
|
|||
|
|
@ -1228,6 +1228,7 @@ class EXTRenderSnorm;
|
|||
class EXTTextureNorm16;
|
||||
class OESVertexArrayObject;
|
||||
class WebGLCompressedTextureS3tc;
|
||||
class WebGLCompressedTextureS3tcSrgb;
|
||||
class WebGLDrawBuffers;
|
||||
class WebGLVertexArrayObjectOES;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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/WebGLCompressedTextureS3tcSrgbPrototype.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tcSrgb.h>
|
||||
#include <LibWeb/WebGL/OpenGLContext.h>
|
||||
|
||||
namespace Web::WebGL::Extensions {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(WebGLCompressedTextureS3tcSrgb);
|
||||
|
||||
JS::ThrowCompletionOr<GC::Ptr<WebGLCompressedTextureS3tcSrgb>> WebGLCompressedTextureS3tcSrgb::create(JS::Realm& realm, WebGLRenderingContextBase* context)
|
||||
{
|
||||
return realm.create<WebGLCompressedTextureS3tcSrgb>(realm, context);
|
||||
}
|
||||
|
||||
WebGLCompressedTextureS3tcSrgb::WebGLCompressedTextureS3tcSrgb(JS::Realm& realm, WebGLRenderingContextBase* context)
|
||||
: PlatformObject(realm)
|
||||
, m_context(context)
|
||||
{
|
||||
m_context->context().request_extension("GL_EXT_texture_compression_s3tc_srgb");
|
||||
}
|
||||
|
||||
void WebGLCompressedTextureS3tcSrgb::initialize(JS::Realm& realm)
|
||||
{
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLCompressedTextureS3tcSrgb);
|
||||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
void WebGLCompressedTextureS3tcSrgb::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 WebGLCompressedTextureS3tcSrgb : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(WebGLCompressedTextureS3tcSrgb, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(WebGLCompressedTextureS3tcSrgb);
|
||||
|
||||
public:
|
||||
static JS::ThrowCompletionOr<GC::Ptr<WebGLCompressedTextureS3tcSrgb>> create(JS::Realm&, WebGLRenderingContextBase*);
|
||||
|
||||
protected:
|
||||
void initialize(JS::Realm&) override;
|
||||
void visit_edges(Visitor&) override;
|
||||
|
||||
private:
|
||||
WebGLCompressedTextureS3tcSrgb(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_srgb/
|
||||
// NOTE: Original WEBGL_compressed_texture_s3tc_srgb 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 WebGLCompressedTextureS3tcSrgb {
|
||||
// Compressed Texture Formats
|
||||
const GLenum COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C;
|
||||
const GLenum COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D;
|
||||
const GLenum COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E;
|
||||
const GLenum COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F;
|
||||
};
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
#include <LibWeb/WebGL/Extensions/EXTRenderSnorm.h>
|
||||
#include <LibWeb/WebGL/Extensions/EXTTextureNorm16.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tc.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tcSrgb.h>
|
||||
#include <LibWeb/WebGL/OpenGLContext.h>
|
||||
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
|
||||
#include <LibWeb/WebGL/WebGLContextEvent.h>
|
||||
|
|
@ -80,6 +81,7 @@ void WebGL2RenderingContext::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_ext_render_snorm);
|
||||
visitor.visit(m_ext_texture_norm16);
|
||||
visitor.visit(m_webgl_compressed_texture_s3tc_extension);
|
||||
visitor.visit(m_webgl_compressed_texture_s3tc_srgb_extension);
|
||||
}
|
||||
|
||||
void WebGL2RenderingContext::present()
|
||||
|
|
@ -177,6 +179,15 @@ JS::Object* WebGL2RenderingContext::get_extension(String const& name)
|
|||
return m_webgl_compressed_texture_s3tc_extension;
|
||||
}
|
||||
|
||||
if (name.equals_ignoring_ascii_case("WEBGL_compressed_texture_s3tc_srgb"sv)) {
|
||||
if (!m_webgl_compressed_texture_s3tc_srgb_extension) {
|
||||
m_webgl_compressed_texture_s3tc_srgb_extension = MUST(Extensions::WebGLCompressedTextureS3tcSrgb::create(realm(), this));
|
||||
}
|
||||
|
||||
VERIFY(m_webgl_compressed_texture_s3tc_srgb_extension);
|
||||
return m_webgl_compressed_texture_s3tc_srgb_extension;
|
||||
}
|
||||
|
||||
if (name.equals_ignoring_ascii_case("EXT_color_buffer_float"sv)) {
|
||||
if (!m_ext_color_buffer_float_extension) {
|
||||
m_ext_color_buffer_float_extension = MUST(Extensions::EXTColorBufferFloat::create(realm(), *this));
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ private:
|
|||
GC::Ptr<Extensions::EXTRenderSnorm> m_ext_render_snorm;
|
||||
GC::Ptr<Extensions::EXTTextureNorm16> m_ext_texture_norm16;
|
||||
GC::Ptr<Extensions::WebGLCompressedTextureS3tc> m_webgl_compressed_texture_s3tc_extension;
|
||||
GC::Ptr<Extensions::WebGLCompressedTextureS3tcSrgb> m_webgl_compressed_texture_s3tc_srgb_extension;
|
||||
|
||||
virtual void set_error(GLenum error) override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
#include <LibWeb/WebGL/Extensions/EXTBlendMinMax.h>
|
||||
#include <LibWeb/WebGL/Extensions/OESVertexArrayObject.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tc.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLCompressedTextureS3tcSrgb.h>
|
||||
#include <LibWeb/WebGL/Extensions/WebGLDrawBuffers.h>
|
||||
#include <LibWeb/WebGL/OpenGLContext.h>
|
||||
#include <LibWeb/WebGL/WebGLContextEvent.h>
|
||||
|
|
@ -97,6 +98,7 @@ void WebGLRenderingContext::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_ext_blend_min_max_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);
|
||||
visitor.visit(m_webgl_draw_buffers_extension);
|
||||
}
|
||||
|
||||
|
|
@ -222,6 +224,15 @@ JS::Object* WebGLRenderingContext::get_extension(String const& name)
|
|||
return m_webgl_compressed_texture_s3tc_extension;
|
||||
}
|
||||
|
||||
if (name.equals_ignoring_ascii_case("WEBGL_compressed_texture_s3tc_srgb"sv)) {
|
||||
if (!m_webgl_compressed_texture_s3tc_srgb_extension) {
|
||||
m_webgl_compressed_texture_s3tc_srgb_extension = MUST(Extensions::WebGLCompressedTextureS3tcSrgb::create(realm(), this));
|
||||
}
|
||||
|
||||
VERIFY(m_webgl_compressed_texture_s3tc_srgb_extension);
|
||||
return m_webgl_compressed_texture_s3tc_srgb_extension;
|
||||
}
|
||||
|
||||
if (name.equals_ignoring_ascii_case("WEBGL_draw_buffers"sv)) {
|
||||
if (!m_webgl_draw_buffers_extension) {
|
||||
m_webgl_draw_buffers_extension = MUST(Extensions::WebGLDrawBuffers::create(realm(), *this));
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ private:
|
|||
GC::Ptr<Extensions::EXTBlendMinMax> m_ext_blend_min_max_extension;
|
||||
GC::Ptr<Extensions::OESVertexArrayObject> m_oes_vertex_array_object_extension;
|
||||
GC::Ptr<Extensions::WebGLCompressedTextureS3tc> m_webgl_compressed_texture_s3tc_extension;
|
||||
GC::Ptr<Extensions::WebGLCompressedTextureS3tcSrgb> m_webgl_compressed_texture_s3tc_srgb_extension;
|
||||
GC::Ptr<Extensions::WebGLDrawBuffers> m_webgl_draw_buffers_extension;
|
||||
|
||||
virtual void set_error(GLenum error) override;
|
||||
|
|
|
|||
|
|
@ -475,6 +475,7 @@ libweb_js_bindings(WebGL/Extensions/EXTRenderSnorm)
|
|||
libweb_js_bindings(WebGL/Extensions/EXTTextureNorm16)
|
||||
libweb_js_bindings(WebGL/Extensions/OESVertexArrayObject)
|
||||
libweb_js_bindings(WebGL/Extensions/WebGLCompressedTextureS3tc)
|
||||
libweb_js_bindings(WebGL/Extensions/WebGLCompressedTextureS3tcSrgb)
|
||||
libweb_js_bindings(WebGL/Extensions/WebGLDrawBuffers)
|
||||
libweb_js_bindings(WebGL/Extensions/WebGLVertexArrayObjectOES)
|
||||
libweb_js_bindings(WebGL/WebGL2RenderingContext)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue