Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ set(SOURCES
WebGL/OpenGLContext.cpp
WebGL/WebGL2RenderingContext.cpp
WebGL/WebGL2RenderingContextImpl.cpp
WebGL/WebGL2RenderingContextOverloads.cpp
WebGL/WebGLActiveInfo.cpp
WebGL/WebGLBuffer.cpp
WebGL/WebGLContextAttributes.cpp
Expand All @@ -1052,6 +1053,7 @@ set(SOURCES
WebGL/WebGLRenderingContext.cpp
WebGL/WebGLRenderingContextBase.cpp
WebGL/WebGLRenderingContextImpl.cpp
WebGL/WebGLRenderingContextOverloads.cpp
WebGL/WebGLSampler.cpp
WebGL/WebGLShader.cpp
WebGL/WebGLShaderPrecisionFormat.cpp
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibWeb/WebGL/OpenGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class WEB_API OpenGLContext {
Vector<String> get_supported_extensions();
void request_extension(char const* extension_name);

WebGLVersion webgl_version() const { return m_webgl_version; }

private:
NonnullRefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
Gfx::IntSize m_size;
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibWeb/WebGL/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using GLuint = unsigned int;
using GLint = int;
using GLsizei = int;
using GLintptr = long long;
using GLchar = char;

// FIXME: This should really be "struct __GLsync*", but the linker doesn't recognise it.
// Since this conflicts with the original definition of GLsync, the suffix "Internal" has been added.
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/WebGL/WebGL2RenderingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ JS::ThrowCompletionOr<GC::Ptr<WebGL2RenderingContext>> WebGL2RenderingContext::c

WebGL2RenderingContext::WebGL2RenderingContext(JS::Realm& realm, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<OpenGLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
: PlatformObject(realm)
, WebGL2RenderingContextImpl(realm, move(context))
, WebGL2RenderingContextOverloads(realm, move(context))
, m_canvas_element(canvas_element)
, m_context_creation_parameters(context_creation_parameters)
, m_actual_context_parameters(actual_context_parameters)
Expand Down
4 changes: 2 additions & 2 deletions Libraries/LibWeb/WebGL/WebGL2RenderingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebGL/Types.h>
#include <LibWeb/WebGL/WebGL2RenderingContextImpl.h>
#include <LibWeb/WebGL/WebGL2RenderingContextOverloads.h>
#include <LibWeb/WebGL/WebGLContextAttributes.h>

namespace Web::WebGL {

class WebGL2RenderingContext final : public Bindings::PlatformObject
, public WebGL2RenderingContextImpl {
, public WebGL2RenderingContextOverloads {
WEB_PLATFORM_OBJECT(WebGL2RenderingContext, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(WebGL2RenderingContext);

Expand Down
2,490 changes: 1 addition & 2,489 deletions Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.cpp

Large diffs are not rendered by default.

174 changes: 3 additions & 171 deletions Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.h

Large diffs are not rendered by default.

366 changes: 366 additions & 0 deletions Libraries/LibWeb/WebGL/WebGL2RenderingContextOverloads.cpp

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions Libraries/LibWeb/WebGL/WebGL2RenderingContextOverloads.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2024, Aliaksandr Kalenik <[email protected]>
* Copyright (c) 2024-2025, Luke Wilde <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <AK/NonnullOwnPtr.h>
#include <LibGC/Ptr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebGL/WebGL2RenderingContextImpl.h>
#include <LibWeb/WebIDL/Types.h>

namespace Web::WebGL {

using namespace Web::HTML;

class WebGL2RenderingContextOverloads : public WebGL2RenderingContextImpl {
public:
WebGL2RenderingContextOverloads(JS::Realm&, NonnullOwnPtr<OpenGLContext>);

void buffer_data(WebIDL::UnsignedLong target, WebIDL::LongLong size, WebIDL::UnsignedLong usage);
void buffer_data(WebIDL::UnsignedLong target, GC::Root<WebIDL::BufferSource> src_data, WebIDL::UnsignedLong usage);
void buffer_sub_data(WebIDL::UnsignedLong target, WebIDL::LongLong dst_byte_offset, GC::Root<WebIDL::BufferSource> src_data);
void buffer_data(WebIDL::UnsignedLong target, GC::Root<WebIDL::ArrayBufferView> src_data, WebIDL::UnsignedLong usage, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong length);
void buffer_sub_data(WebIDL::UnsignedLong target, WebIDL::LongLong dst_byte_offset, GC::Root<WebIDL::ArrayBufferView> src_data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong length);
void tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels);
void tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source);
void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels);
void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source);
void tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source);
void tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> src_data, WebIDL::UnsignedLongLong src_offset);
void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source);
void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> src_data, WebIDL::UnsignedLongLong src_offset);
void compressed_tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::UnsignedLong internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, GC::Root<WebIDL::ArrayBufferView> src_data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length_override);
void compressed_tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, GC::Root<WebIDL::ArrayBufferView> src_data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length_override);
void uniform1fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform1iv(GC::Root<WebGLUniformLocation> location, Int32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform2iv(GC::Root<WebGLUniformLocation> location, Int32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform3iv(GC::Root<WebGLUniformLocation> location, Int32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform4iv(GC::Root<WebGLUniformLocation> location, Int32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void read_pixels(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels);
void read_pixels(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, WebIDL::LongLong offset);
};

}
2 changes: 1 addition & 1 deletion Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ JS::ThrowCompletionOr<GC::Ptr<WebGLRenderingContext>> WebGLRenderingContext::cre

WebGLRenderingContext::WebGLRenderingContext(JS::Realm& realm, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<OpenGLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
: PlatformObject(realm)
, WebGLRenderingContextImpl(realm, move(context))
, WebGLRenderingContextOverloads(realm, move(context))
, m_canvas_element(canvas_element)
, m_context_creation_parameters(context_creation_parameters)
, m_actual_context_parameters(actual_context_parameters)
Expand Down
4 changes: 2 additions & 2 deletions Libraries/LibWeb/WebGL/WebGLRenderingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#include <LibWeb/Forward.h>
#include <LibWeb/WebGL/Types.h>
#include <LibWeb/WebGL/WebGLContextAttributes.h>
#include <LibWeb/WebGL/WebGLRenderingContextImpl.h>
#include <LibWeb/WebGL/WebGLRenderingContextOverloads.h>

namespace Web::WebGL {

class WebGLRenderingContext final : public Bindings::PlatformObject
, public WebGLRenderingContextImpl {
, public WebGLRenderingContextOverloads {
WEB_PLATFORM_OBJECT(WebGLRenderingContext, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(WebGLRenderingContext);

Expand Down
21 changes: 21 additions & 0 deletions Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@
#include <LibJS/Runtime/DataView.h>
#include <LibJS/Runtime/TypedArray.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebGL/Types.h>
#include <LibWeb/WebIDL/Buffers.h>
#include <LibWeb/WebIDL/Types.h>

#define SET_ERROR_VALUE_IF_ERROR(expression, error_value) \
({ \
auto maybe_error = expression; \
if (maybe_error.is_error()) [[unlikely]] { \
set_error(error_value); \
return; \
} \
maybe_error.release_value(); \
})

namespace Web::WebGL {

static constexpr int COMPRESSED_TEXTURE_FORMATS = 0x86A3;
Expand Down Expand Up @@ -117,6 +128,16 @@ class WebGLRenderingContextBase {
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 {});

protected:
static Vector<GLchar> null_terminated_string(StringView string)
{
Vector<GLchar> result;
result.ensure_capacity(string.length() + 1);
for (auto c : string.bytes())
result.append(c);
result.append('\0');
return result;
}

// UNPACK_FLIP_Y_WEBGL of type boolean
// If set, then during any subsequent calls to texImage2D or texSubImage2D, the source data is flipped along
// the vertical axis, so that conceptually the last row is the first one transferred. The initial value is false.
Expand Down
Loading
Loading