LibWeb's WebGL implementation currently reaches ANGLE by calling glFoo() throughout the WebGL context and extension code. That ties the WebGL spec layer to the concrete GL executor. A future backend that records operations, sends them to another process, or executes them from the Compositor would otherwise need to duplicate the WebGL logic or edit every call site again. Introduce GLFunctions as an explicit boundary between WebGL semantics and GL execution. GLFunctions.json lists the GL entry points used by the implementation, and the generator emits one forwarding method per entry point. OpenGLContext implements those methods today, so the current in-process ANGLE path keeps the same behavior while all callers go through a single replaceable interface. That boundary is needed before canvas/WebGL rendering can move to the Compositor: the WebGL context code can keep doing validation, state tracking, and spec-visible error handling in LibWeb, while a later implementation can record the same GL calls and replay them where the canvas surface is produced. The JSON source also gives the recorder and replayer one shared description of argument shapes, avoiding two hand-written views of the GL API drifting apart.
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
/*
|
|
* 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/WebGLDrawBuffers.h>
|
|
#include <LibWeb/WebGL/Extensions/WebGLDrawBuffers.h>
|
|
#include <LibWeb/WebGL/OpenGLContext.h>
|
|
#include <LibWeb/WebGL/WebGLRenderingContextBase.h>
|
|
|
|
#include <GLES2/gl2.h>
|
|
#include <GLES2/gl2ext.h>
|
|
|
|
namespace Web::WebGL {
|
|
|
|
GC_DEFINE_ALLOCATOR(WebGLDrawBuffers);
|
|
|
|
JS::ThrowCompletionOr<GC::Ref<JS::Object>> WebGLDrawBuffers::create(JS::Realm& realm, GC::Ref<WebGLRenderingContextBase> context)
|
|
{
|
|
return realm.create<WebGLDrawBuffers>(realm, context);
|
|
}
|
|
|
|
WebGLDrawBuffers::WebGLDrawBuffers(JS::Realm& realm, GC::Ref<WebGLRenderingContextBase> context)
|
|
: PlatformObject(realm)
|
|
, m_context(context)
|
|
{
|
|
}
|
|
|
|
void WebGLDrawBuffers::draw_buffers_webgl(Vector<GLenum> buffers)
|
|
{
|
|
m_context->context().make_current();
|
|
m_context->context().draw_buffers_ext(buffers.size(), buffers.data());
|
|
}
|
|
|
|
void WebGLDrawBuffers::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLDrawBuffers);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
void WebGLDrawBuffers::visit_edges(Visitor& visitor)
|
|
{
|
|
Base::visit_edges(visitor);
|
|
visitor.visit(m_context);
|
|
}
|
|
|
|
}
|