/* * Copyright (c) 2025, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include namespace Web::WebGL { GC_DEFINE_ALLOCATOR(OESVertexArrayObject); JS::ThrowCompletionOr> OESVertexArrayObject::create(JS::Realm& realm, GC::Ref context) { return realm.create(realm, context); } OESVertexArrayObject::OESVertexArrayObject(JS::Realm& realm, GC::Ref context) : PlatformObject(realm) , m_context(context) { } GC::Ref OESVertexArrayObject::create_vertex_array_oes() { m_context->context().make_current(); GLuint handle = 0; m_context->context().gen_vertex_arrays_oes(1, &handle); return WebGLVertexArrayObjectOES::create(realm(), m_context, handle); } void OESVertexArrayObject::delete_vertex_array_oes(GC::Ptr array_object) { m_context->context().make_current(); if (!array_object) return; auto handle_or_error = array_object->handle_for_deletion(m_context.ptr()); if (handle_or_error.is_error()) { // FIXME: m_context->set_error(GL_INVALID_OPERATION); return; } auto vertex_array_handle = handle_or_error.release_value(); if (!vertex_array_handle.has_value()) return; auto handle = vertex_array_handle.value(); m_context->context().delete_vertex_arrays_oes(1, &handle); } bool OESVertexArrayObject::is_vertex_array_oes(GC::Ptr array_object) { m_context->context().make_current(); if (!array_object) return false; auto handle_or_error = array_object->handle_for_query(m_context.ptr()); if (handle_or_error.is_error()) { return false; } auto vertex_array_handle = handle_or_error.release_value(); if (!vertex_array_handle.has_value()) return false; return m_context->context().is_vertex_array_oes(vertex_array_handle.value()) == GL_TRUE; } void OESVertexArrayObject::bind_vertex_array_oes(GC::Ptr 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(); } m_context->context().bind_vertex_array_oes(vertex_array_handle); } void OESVertexArrayObject::initialize(JS::Realm& realm) { WEB_SET_PROTOTYPE_FOR_INTERFACE(OESVertexArrayObject); Base::initialize(realm); } void OESVertexArrayObject::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_context); } }