mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-25 19:51:59 +00: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: 442f0b9a13
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
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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue