2024-12-17 06:15:53 +01:00
|
|
|
/*
|
2025-09-30 15:40:59 +02:00
|
|
|
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2024-12-17 06:15:53 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2025-09-30 15:40:59 +02:00
|
|
|
#include <LibJS/Runtime/TypedArray.h>
|
2025-03-06 23:41:31 +01:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
#include <LibWeb/WebIDL/Types.h>
|
|
|
|
|
2024-12-17 06:15:53 +01:00
|
|
|
namespace Web::WebGL {
|
|
|
|
|
2025-03-06 23:41:31 +01:00
|
|
|
// NOTE: This is the Variant created by the IDL wrapper generator, and needs to be updated accordingly.
|
|
|
|
using TexImageSource = Variant<GC::Root<HTML::ImageBitmap>, GC::Root<HTML::ImageData>, GC::Root<HTML::HTMLImageElement>, GC::Root<HTML::HTMLCanvasElement>, GC::Root<HTML::OffscreenCanvas>, GC::Root<HTML::HTMLVideoElement>>;
|
|
|
|
|
2024-12-17 06:15:53 +01:00
|
|
|
// FIXME: This object should inherit from Bindings::PlatformObject and implement the WebGLRenderingContextBase IDL interface.
|
|
|
|
// We should make WebGL code generator to produce implementation for this interface.
|
|
|
|
class WebGLRenderingContextBase {
|
|
|
|
public:
|
2025-09-30 03:03:05 +02:00
|
|
|
using Float32List = Variant<GC::Root<JS::Float32Array>, Vector<float>>;
|
2025-09-30 16:55:21 +02:00
|
|
|
using Int32List = Variant<GC::Root<JS::Int32Array>, Vector<WebIDL::Long>>;
|
2025-09-30 17:52:15 +02:00
|
|
|
using Uint32List = Variant<GC::Root<JS::Uint32Array>, Vector<WebIDL::UnsignedLong>>;
|
2025-09-30 03:03:05 +02:00
|
|
|
|
2024-12-17 06:15:53 +01:00
|
|
|
virtual GC::Cell const* gc_cell() const = 0;
|
2024-12-24 18:16:29 +00:00
|
|
|
virtual void visit_edges(JS::Cell::Visitor&) = 0;
|
2025-01-28 17:26:23 +00:00
|
|
|
virtual OpenGLContext& context() = 0;
|
2025-09-30 15:40:59 +02:00
|
|
|
|
|
|
|
static Span<float> span_from_float32_list(Float32List& float32_list)
|
|
|
|
{
|
|
|
|
if (float32_list.has<Vector<float>>())
|
|
|
|
return float32_list.get<Vector<float>>();
|
|
|
|
return float32_list.get<GC::Root<JS::Float32Array>>()->data();
|
|
|
|
}
|
2025-09-30 16:55:21 +02:00
|
|
|
|
|
|
|
static Span<int> span_from_int32_list(Int32List& int32_list)
|
|
|
|
{
|
|
|
|
if (int32_list.has<Vector<int>>())
|
|
|
|
return int32_list.get<Vector<int>>();
|
|
|
|
return int32_list.get<GC::Root<JS::Int32Array>>()->data();
|
|
|
|
}
|
2025-09-30 17:52:15 +02:00
|
|
|
|
|
|
|
static Span<u32> span_from_uint32_list(Uint32List& int32_list)
|
|
|
|
{
|
|
|
|
if (int32_list.has<Vector<u32>>())
|
|
|
|
return int32_list.get<Vector<u32>>();
|
|
|
|
return int32_list.get<GC::Root<JS::Uint32Array>>()->data();
|
|
|
|
}
|
2025-10-02 17:26:53 +02:00
|
|
|
|
|
|
|
struct ConvertedTexture {
|
|
|
|
ByteBuffer buffer;
|
|
|
|
int width { 0 };
|
|
|
|
int height { 0 };
|
|
|
|
};
|
|
|
|
static Optional<ConvertedTexture> read_and_pixel_convert_texture_image_source(TexImageSource const& source, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, Optional<int> destination_width = OptionalNone {}, Optional<int> destination_height = OptionalNone {});
|
2024-12-17 06:15:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|