mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
LibWeb/WebGL: Implement OES_vertex_array_object extension
This commit is contained in:
parent
58942e1137
commit
442f0b9a13
Notes:
github-actions[bot]
2025-01-21 20:37:57 +00:00
Author: https://github.com/Lubrsi Commit: https://github.com/LadybirdBrowser/ladybird/commit/442f0b9a13b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3239 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/kalenikaliaksandr
10 changed files with 244 additions and 0 deletions
|
@ -825,6 +825,7 @@ set(SOURCES
|
|||
WebDriver/TimeoutsConfiguration.cpp
|
||||
WebGL/ANGLEInstancedArrays.cpp
|
||||
WebGL/EventNames.cpp
|
||||
WebGL/OESVertexArrayObject.cpp
|
||||
WebGL/OpenGLContext.cpp
|
||||
WebGL/WebGL2RenderingContext.cpp
|
||||
WebGL/WebGLActiveInfo.cpp
|
||||
|
@ -845,6 +846,7 @@ set(SOURCES
|
|||
WebGL/WebGLTransformFeedback.cpp
|
||||
WebGL/WebGLUniformLocation.cpp
|
||||
WebGL/WebGLVertexArrayObject.cpp
|
||||
WebGL/WebGLVertexArrayObjectOES.cpp
|
||||
WebIDL/AbstractOperations.cpp
|
||||
WebIDL/Buffers.cpp
|
||||
WebIDL/CallbackType.cpp
|
||||
|
|
105
Libraries/LibWeb/WebGL/OESVertexArrayObject.cpp
Normal file
105
Libraries/LibWeb/WebGL/OESVertexArrayObject.cpp
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibWeb/Bindings/OESVertexArrayObjectPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/WebGL/OESVertexArrayObject.h>
|
||||
#include <LibWeb/WebGL/OpenGLContext.h>
|
||||
#include <LibWeb/WebGL/WebGLRenderingContext.h>
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
namespace Web::WebGL {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(OESVertexArrayObject);
|
||||
|
||||
JS::ThrowCompletionOr<GC::Ptr<OESVertexArrayObject>> OESVertexArrayObject::create(JS::Realm& realm, GC::Ref<WebGLRenderingContext> context)
|
||||
{
|
||||
return realm.create<OESVertexArrayObject>(realm, context);
|
||||
}
|
||||
|
||||
OESVertexArrayObject::OESVertexArrayObject(JS::Realm& realm, GC::Ref<WebGLRenderingContext> context)
|
||||
: PlatformObject(realm)
|
||||
, m_context(context)
|
||||
{
|
||||
m_context->context().request_extension("GL_OES_vertex_array_object");
|
||||
}
|
||||
|
||||
GC::Ref<WebGLVertexArrayObjectOES> OESVertexArrayObject::create_vertex_array_oes()
|
||||
{
|
||||
m_context->context().make_current();
|
||||
|
||||
GLuint handle = 0;
|
||||
glGenVertexArraysOES(1, &handle);
|
||||
return WebGLVertexArrayObjectOES::create(realm(), m_context, handle);
|
||||
}
|
||||
|
||||
void OESVertexArrayObject::delete_vertex_array_oes(GC::Root<WebGLVertexArrayObjectOES> array_object)
|
||||
{
|
||||
m_context->context().make_current();
|
||||
|
||||
GLuint vertex_array_handle = 0;
|
||||
if (array_object) {
|
||||
auto handle_or_error = array_object->handle(m_context.ptr());
|
||||
if (handle_or_error.is_error()) {
|
||||
// FIXME: m_context->set_error(GL_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
vertex_array_handle = handle_or_error.release_value();
|
||||
}
|
||||
|
||||
glDeleteVertexArraysOES(1, &vertex_array_handle);
|
||||
}
|
||||
|
||||
bool OESVertexArrayObject::is_vertex_array_oes(GC::Root<WebGLVertexArrayObjectOES> array_object)
|
||||
{
|
||||
m_context->context().make_current();
|
||||
|
||||
GLuint vertex_array_handle = 0;
|
||||
if (array_object) {
|
||||
auto handle_or_error = array_object->handle(m_context.ptr());
|
||||
if (handle_or_error.is_error()) {
|
||||
return false;
|
||||
}
|
||||
vertex_array_handle = handle_or_error.release_value();
|
||||
}
|
||||
|
||||
return glIsVertexArrayOES(vertex_array_handle) == GL_TRUE;
|
||||
}
|
||||
|
||||
void OESVertexArrayObject::bind_vertex_array_oes(GC::Root<WebGLVertexArrayObjectOES> array_object)
|
||||
{
|
||||
m_context->context().make_current();
|
||||
|
||||
GLuint vertex_array_handle = 0;
|
||||
if (array_object) {
|
||||
auto handle_or_error = array_object->handle(m_context.ptr());
|
||||
if (handle_or_error.is_error()) {
|
||||
// FIXME: m_context->set_error(GL_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
vertex_array_handle = handle_or_error.release_value();
|
||||
}
|
||||
|
||||
glBindVertexArrayOES(vertex_array_handle);
|
||||
}
|
||||
|
||||
void OESVertexArrayObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(OESVertexArrayObject);
|
||||
}
|
||||
|
||||
void OESVertexArrayObject::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_context);
|
||||
}
|
||||
|
||||
}
|
38
Libraries/LibWeb/WebGL/OESVertexArrayObject.h
Normal file
38
Libraries/LibWeb/WebGL/OESVertexArrayObject.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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/Types.h>
|
||||
#include <LibWeb/WebGL/WebGLVertexArrayObjectOES.h>
|
||||
|
||||
namespace Web::WebGL {
|
||||
|
||||
class OESVertexArrayObject : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(OESVertexArrayObject, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(OESVertexArrayObject);
|
||||
|
||||
public:
|
||||
static JS::ThrowCompletionOr<GC::Ptr<OESVertexArrayObject>> create(JS::Realm&, GC::Ref<WebGLRenderingContext>);
|
||||
|
||||
GC::Ref<WebGLVertexArrayObjectOES> create_vertex_array_oes();
|
||||
void delete_vertex_array_oes(GC::Root<WebGLVertexArrayObjectOES> array_object);
|
||||
bool is_vertex_array_oes(GC::Root<WebGLVertexArrayObjectOES> array_object);
|
||||
void bind_vertex_array_oes(GC::Root<WebGLVertexArrayObjectOES> array_object);
|
||||
|
||||
protected:
|
||||
void initialize(JS::Realm&) override;
|
||||
void visit_edges(Visitor&) override;
|
||||
|
||||
private:
|
||||
OESVertexArrayObject(JS::Realm&, GC::Ref<WebGLRenderingContext>);
|
||||
|
||||
GC::Ref<WebGLRenderingContext> m_context;
|
||||
};
|
||||
|
||||
}
|
21
Libraries/LibWeb/WebGL/OESVertexArrayObject.idl
Normal file
21
Libraries/LibWeb/WebGL/OESVertexArrayObject.idl
Normal file
|
@ -0,0 +1,21 @@
|
|||
#import <WebGL/Types.idl>
|
||||
#import <WebGL/WebGLVertexArrayObjectOES.idl>
|
||||
|
||||
// https://registry.khronos.org/webgl/extensions/OES_vertex_array_object/
|
||||
// NOTE: Original OES_vertex_array_object 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 OESVertexArrayObject {
|
||||
// Same note as WebGLRenderingContextBase:
|
||||
// Functions that have the [WebGLHandlesContextLoss] extended attribute in the spec do not have them here.
|
||||
|
||||
const GLenum VERTEX_ARRAY_BINDING_OES = 0x85B5;
|
||||
|
||||
WebGLVertexArrayObjectOES createVertexArrayOES();
|
||||
undefined deleteVertexArrayOES(WebGLVertexArrayObjectOES? arrayObject);
|
||||
GLboolean isVertexArrayOES(WebGLVertexArrayObjectOES? arrayObject);
|
||||
undefined bindVertexArrayOES(WebGLVertexArrayObjectOES? arrayObject);
|
||||
};
|
|
@ -14,6 +14,7 @@
|
|||
#include <LibWeb/Painting/Paintable.h>
|
||||
#include <LibWeb/WebGL/ANGLEInstancedArrays.h>
|
||||
#include <LibWeb/WebGL/EventNames.h>
|
||||
#include <LibWeb/WebGL/OESVertexArrayObject.h>
|
||||
#include <LibWeb/WebGL/OpenGLContext.h>
|
||||
#include <LibWeb/WebGL/WebGLContextEvent.h>
|
||||
#include <LibWeb/WebGL/WebGLRenderingContext.h>
|
||||
|
@ -176,6 +177,9 @@ JS::Object* WebGLRenderingContext::get_extension(String const& name)
|
|||
if (name == "ANGLE_instanced_arrays"sv) {
|
||||
return MUST(ANGLEInstancedArrays::create(realm()));
|
||||
}
|
||||
if (name == "OES_vertex_array_object"sv) {
|
||||
return MUST(OESVertexArrayObject::create(realm(), *this));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
35
Libraries/LibWeb/WebGL/WebGLVertexArrayObjectOES.cpp
Normal file
35
Libraries/LibWeb/WebGL/WebGLVertexArrayObjectOES.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
||||
* 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/WebGLVertexArrayObjectOESPrototype.h>
|
||||
#include <LibWeb/WebGL/WebGLVertexArrayObjectOES.h>
|
||||
|
||||
namespace Web::WebGL {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(WebGLVertexArrayObjectOES);
|
||||
|
||||
GC::Ref<WebGLVertexArrayObjectOES> WebGLVertexArrayObjectOES::create(JS::Realm& realm, WebGLRenderingContextBase& context, GLuint handle)
|
||||
{
|
||||
return realm.create<WebGLVertexArrayObjectOES>(realm, context, handle);
|
||||
}
|
||||
|
||||
WebGLVertexArrayObjectOES::WebGLVertexArrayObjectOES(JS::Realm& realm, WebGLRenderingContextBase& context, GLuint handle)
|
||||
: WebGLObject(realm, context, handle)
|
||||
{
|
||||
}
|
||||
|
||||
WebGLVertexArrayObjectOES::~WebGLVertexArrayObjectOES() = default;
|
||||
|
||||
void WebGLVertexArrayObjectOES::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLVertexArrayObjectOES);
|
||||
}
|
||||
|
||||
}
|
30
Libraries/LibWeb/WebGL/WebGLVertexArrayObjectOES.h
Normal file
30
Libraries/LibWeb/WebGL/WebGLVertexArrayObjectOES.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
||||
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/WebGL/Types.h>
|
||||
#include <LibWeb/WebGL/WebGLObject.h>
|
||||
|
||||
namespace Web::WebGL {
|
||||
|
||||
class WebGLVertexArrayObjectOES : public WebGLObject {
|
||||
WEB_PLATFORM_OBJECT(WebGLVertexArrayObjectOES, WebGLObject);
|
||||
GC_DECLARE_ALLOCATOR(WebGLVertexArrayObjectOES);
|
||||
|
||||
public:
|
||||
static GC::Ref<WebGLVertexArrayObjectOES> create(JS::Realm& realm, WebGLRenderingContextBase&, GLuint handle);
|
||||
|
||||
virtual ~WebGLVertexArrayObjectOES() override;
|
||||
|
||||
protected:
|
||||
explicit WebGLVertexArrayObjectOES(JS::Realm&, WebGLRenderingContextBase&, GLuint handle);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
}
|
6
Libraries/LibWeb/WebGL/WebGLVertexArrayObjectOES.idl
Normal file
6
Libraries/LibWeb/WebGL/WebGLVertexArrayObjectOES.idl
Normal file
|
@ -0,0 +1,6 @@
|
|||
#import <WebGL/WebGLObject.idl>
|
||||
|
||||
// https://registry.khronos.org/webgl/extensions/OES_vertex_array_object/
|
||||
[Exposed=(Window,Worker), LegacyNoInterfaceObject]
|
||||
interface WebGLVertexArrayObjectOES : WebGLObject {
|
||||
};
|
|
@ -381,6 +381,7 @@ libweb_js_bindings(WebAudio/PannerNode)
|
|||
libweb_js_bindings(WebAudio/PeriodicWave)
|
||||
libweb_js_bindings(WebAudio/StereoPannerNode)
|
||||
libweb_js_bindings(WebGL/ANGLEInstancedArrays)
|
||||
libweb_js_bindings(WebGL/OESVertexArrayObject)
|
||||
libweb_js_bindings(WebGL/WebGL2RenderingContext)
|
||||
libweb_js_bindings(WebGL/WebGLActiveInfo)
|
||||
libweb_js_bindings(WebGL/WebGLBuffer)
|
||||
|
@ -399,6 +400,7 @@ libweb_js_bindings(WebGL/WebGLTexture)
|
|||
libweb_js_bindings(WebGL/WebGLTransformFeedback)
|
||||
libweb_js_bindings(WebGL/WebGLUniformLocation)
|
||||
libweb_js_bindings(WebGL/WebGLVertexArrayObject)
|
||||
libweb_js_bindings(WebGL/WebGLVertexArrayObjectOES)
|
||||
libweb_js_bindings(WebIDL/DOMException)
|
||||
libweb_js_bindings(WebSockets/WebSocket)
|
||||
libweb_js_bindings(WebVTT/VTTCue)
|
||||
|
|
|
@ -123,6 +123,7 @@ static bool is_platform_object(Type const& type)
|
|||
"WebGLTexture"sv,
|
||||
"WebGLUniformLocation"sv,
|
||||
"WebGLVertexArrayObject"sv,
|
||||
"WebGLVertexArrayObjectOES"sv,
|
||||
"Window"sv,
|
||||
"WindowProxy"sv,
|
||||
"WritableStream"sv,
|
||||
|
|
Loading…
Reference in a new issue