ladybird/Libraries/LibWeb/WebGL/Extensions/WebGLDrawBuffers.cpp
Undefine c2aeb9ea73 LibWeb: Move WebGL extensions requests to WebGLRenderingContextBase
Instead of making the extension objects request the OpenGL extensions
themselves, we can do it here since we already store that information
to be able to compute the list of available extensions. As bonus points
this makes it impossible to forget to request an OpenGL extension when
implementing a new WebGL one.
2026-03-11 20:19:45 +01:00

51 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/WebGLDrawBuffersPrototype.h>
#include <LibWeb/WebGL/Extensions/WebGLDrawBuffers.h>
#include <LibWeb/WebGL/OpenGLContext.h>
#include <LibWeb/WebGL/WebGLRenderingContextBase.h>
#define GL_GLEXT_PROTOTYPES 1
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
namespace Web::WebGL::Extensions {
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();
glDrawBuffersEXT(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);
}
}