2024-11-13 05:31:46 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
|
2024-11-30 12:53:52 -03:00
|
|
|
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2024-12-05 12:13:02 -03:00
|
|
|
* Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
|
2024-11-13 05:31:46 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2024-12-05 12:13:02 -03:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2026-04-18 05:54:06 -03:00
|
|
|
#include <LibWeb/Bindings/WebGLObject.h>
|
2024-11-13 05:31:46 -03:00
|
|
|
#include <LibWeb/WebGL/WebGLObject.h>
|
|
|
|
|
|
2024-12-17 12:17:37 -03:00
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
|
|
2024-11-13 05:31:46 -03:00
|
|
|
namespace Web::WebGL {
|
|
|
|
|
|
2025-12-01 18:01:17 -03:00
|
|
|
WebGLObject::WebGLObject(JS::Realm& realm, GC::Ref<WebGLRenderingContextBase> context, GLuint handle)
|
2024-11-13 05:31:46 -03:00
|
|
|
: Bindings::PlatformObject(realm)
|
2025-12-01 18:01:17 -03:00
|
|
|
, m_context(context)
|
2024-11-30 12:53:52 -03:00
|
|
|
, m_handle(handle)
|
2024-11-13 05:31:46 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebGLObject::~WebGLObject() = default;
|
|
|
|
|
|
2024-12-05 12:13:02 -03:00
|
|
|
void WebGLObject::initialize(JS::Realm& realm)
|
|
|
|
|
{
|
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLObject);
|
2025-04-20 11:22:57 -03:00
|
|
|
Base::initialize(realm);
|
2024-12-05 12:13:02 -03:00
|
|
|
}
|
|
|
|
|
|
2024-12-17 02:15:53 -03:00
|
|
|
void WebGLObject::visit_edges(Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
2025-12-01 18:01:17 -03:00
|
|
|
visitor.visit(m_context);
|
2024-12-17 02:15:53 -03:00
|
|
|
}
|
|
|
|
|
|
2024-12-17 12:17:37 -03:00
|
|
|
ErrorOr<GLuint> WebGLObject::handle(WebGLRenderingContextBase const* context) const
|
2026-06-15 14:37:51 -03:00
|
|
|
{
|
|
|
|
|
TRY(validate_context(context));
|
|
|
|
|
if (invalidated_for_context(context))
|
|
|
|
|
return Error::from_errno(GL_INVALID_OPERATION);
|
|
|
|
|
return m_handle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorOr<Optional<GLuint>> WebGLObject::handle_for_deletion(WebGLRenderingContextBase const* context)
|
|
|
|
|
{
|
|
|
|
|
TRY(validate_context(context));
|
|
|
|
|
if (invalidated_for_context(context))
|
|
|
|
|
return Optional<GLuint> {};
|
|
|
|
|
m_invalidated = true;
|
|
|
|
|
return Optional<GLuint> { m_handle };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorOr<Optional<GLuint>> WebGLObject::handle_for_query(WebGLRenderingContextBase const* context) const
|
|
|
|
|
{
|
|
|
|
|
TRY(validate_context(context));
|
|
|
|
|
if (invalidated_for_context(context))
|
|
|
|
|
return Optional<GLuint> {};
|
|
|
|
|
return Optional<GLuint> { m_handle };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebGLObject::invalidated_for_context(WebGLRenderingContextBase const* context) const
|
|
|
|
|
{
|
|
|
|
|
(void)context;
|
|
|
|
|
return m_invalidated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorOr<void> WebGLObject::validate_context(WebGLRenderingContextBase const* context) const
|
2024-12-17 12:17:37 -03:00
|
|
|
{
|
|
|
|
|
if (context == m_context)
|
2026-06-15 14:37:51 -03:00
|
|
|
return {};
|
2024-12-17 12:17:37 -03:00
|
|
|
return Error::from_errno(GL_INVALID_OPERATION);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 05:31:46 -03:00
|
|
|
}
|