diff --git a/Libraries/LibWeb/WebGL/WebGLBuffer.cpp b/Libraries/LibWeb/WebGL/WebGLBuffer.cpp index 472b402e67d..3f8ff3331ad 100644 --- a/Libraries/LibWeb/WebGL/WebGLBuffer.cpp +++ b/Libraries/LibWeb/WebGL/WebGLBuffer.cpp @@ -1,9 +1,11 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include @@ -11,8 +13,13 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLBuffer); -WebGLBuffer::WebGLBuffer(JS::Realm& realm) - : WebGLObject(realm) +GC::Ptr WebGLBuffer::create(JS::Realm& realm, GLuint handle) +{ + return realm.heap().allocate(realm, handle); +} + +WebGLBuffer::WebGLBuffer(JS::Realm& realm, GLuint handle) + : WebGLObject(realm, handle) { } diff --git a/Libraries/LibWeb/WebGL/WebGLBuffer.h b/Libraries/LibWeb/WebGL/WebGLBuffer.h index 0c6cc5e2b2d..2e9ca1166a2 100644 --- a/Libraries/LibWeb/WebGL/WebGLBuffer.h +++ b/Libraries/LibWeb/WebGL/WebGLBuffer.h @@ -1,11 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include #include namespace Web::WebGL { @@ -15,10 +17,12 @@ class WebGLBuffer final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLBuffer); public: + static GC::Ptr create(JS::Realm& realm, GLuint handle); + virtual ~WebGLBuffer(); protected: - explicit WebGLBuffer(JS::Realm&); + explicit WebGLBuffer(JS::Realm&, GLuint handle); }; } diff --git a/Libraries/LibWeb/WebGL/WebGLFramebuffer.cpp b/Libraries/LibWeb/WebGL/WebGLFramebuffer.cpp index 2fb5c681da0..42792e8a838 100644 --- a/Libraries/LibWeb/WebGL/WebGLFramebuffer.cpp +++ b/Libraries/LibWeb/WebGL/WebGLFramebuffer.cpp @@ -12,7 +12,7 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLFramebuffer); WebGLFramebuffer::WebGLFramebuffer(JS::Realm& realm) - : WebGLObject(realm) + : WebGLObject(realm, 0) { } diff --git a/Libraries/LibWeb/WebGL/WebGLObject.cpp b/Libraries/LibWeb/WebGL/WebGLObject.cpp index dff390dfe92..3b3345bf128 100644 --- a/Libraries/LibWeb/WebGL/WebGLObject.cpp +++ b/Libraries/LibWeb/WebGL/WebGLObject.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ @@ -8,8 +9,9 @@ namespace Web::WebGL { -WebGLObject::WebGLObject(JS::Realm& realm) +WebGLObject::WebGLObject(JS::Realm& realm, GLuint handle) : Bindings::PlatformObject(realm) + , m_handle(handle) { } diff --git a/Libraries/LibWeb/WebGL/WebGLObject.h b/Libraries/LibWeb/WebGL/WebGLObject.h index 6dd1558dd0b..cb9772865d1 100644 --- a/Libraries/LibWeb/WebGL/WebGLObject.h +++ b/Libraries/LibWeb/WebGL/WebGLObject.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,6 +8,9 @@ #pragma once #include +#include + +typedef unsigned int GLuint; namespace Web::WebGL { @@ -19,14 +23,17 @@ public: String label() const { return m_label; } void set_label(String const& label) { m_label = label; } + GLuint handle() const { return m_handle; } + protected: - explicit WebGLObject(JS::Realm&); + explicit WebGLObject(JS::Realm&, GLuint handle); bool invalidated() const { return m_invalidated; } private: bool m_invalidated { false }; String m_label; + GLuint m_handle { 0 }; }; } diff --git a/Libraries/LibWeb/WebGL/WebGLProgram.cpp b/Libraries/LibWeb/WebGL/WebGLProgram.cpp index cf784403daf..fc071de0969 100644 --- a/Libraries/LibWeb/WebGL/WebGLProgram.cpp +++ b/Libraries/LibWeb/WebGL/WebGLProgram.cpp @@ -1,9 +1,11 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include @@ -11,8 +13,13 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLProgram); -WebGLProgram::WebGLProgram(JS::Realm& realm) - : WebGLObject(realm) +GC::Ptr WebGLProgram::create(JS::Realm& realm, GLuint handle) +{ + return realm.heap().allocate(realm, handle); +} + +WebGLProgram::WebGLProgram(JS::Realm& realm, GLuint handle) + : WebGLObject(realm, handle) { } diff --git a/Libraries/LibWeb/WebGL/WebGLProgram.h b/Libraries/LibWeb/WebGL/WebGLProgram.h index 7e1de769c9f..e322028f9bd 100644 --- a/Libraries/LibWeb/WebGL/WebGLProgram.h +++ b/Libraries/LibWeb/WebGL/WebGLProgram.h @@ -1,11 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include #include namespace Web::WebGL { @@ -15,10 +17,12 @@ class WebGLProgram final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLProgram); public: + static GC::Ptr create(JS::Realm& realm, GLuint handle); + virtual ~WebGLProgram(); protected: - explicit WebGLProgram(JS::Realm&); + explicit WebGLProgram(JS::Realm&, GLuint handle); }; } diff --git a/Libraries/LibWeb/WebGL/WebGLRenderbuffer.cpp b/Libraries/LibWeb/WebGL/WebGLRenderbuffer.cpp index cfc0480fb18..d1d951842fd 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderbuffer.cpp +++ b/Libraries/LibWeb/WebGL/WebGLRenderbuffer.cpp @@ -12,7 +12,7 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLRenderbuffer); WebGLRenderbuffer::WebGLRenderbuffer(JS::Realm& realm) - : WebGLObject(realm) + : WebGLObject(realm, 0) { } diff --git a/Libraries/LibWeb/WebGL/WebGLShader.cpp b/Libraries/LibWeb/WebGL/WebGLShader.cpp index 9a6b121ae32..7293eafe923 100644 --- a/Libraries/LibWeb/WebGL/WebGLShader.cpp +++ b/Libraries/LibWeb/WebGL/WebGLShader.cpp @@ -1,9 +1,11 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include @@ -11,8 +13,13 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLShader); -WebGLShader::WebGLShader(JS::Realm& realm) - : WebGLObject(realm) +GC::Ptr WebGLShader::create(JS::Realm& realm, GLuint handle) +{ + return realm.heap().allocate(realm, handle); +} + +WebGLShader::WebGLShader(JS::Realm& realm, GLuint handle) + : WebGLObject(realm, handle) { } diff --git a/Libraries/LibWeb/WebGL/WebGLShader.h b/Libraries/LibWeb/WebGL/WebGLShader.h index 9207143427b..7af54e66e30 100644 --- a/Libraries/LibWeb/WebGL/WebGLShader.h +++ b/Libraries/LibWeb/WebGL/WebGLShader.h @@ -1,11 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include #include namespace Web::WebGL { @@ -15,10 +17,12 @@ class WebGLShader final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLShader); public: + static GC::Ptr create(JS::Realm& realm, GLuint handle); + virtual ~WebGLShader(); protected: - explicit WebGLShader(JS::Realm&); + explicit WebGLShader(JS::Realm&, GLuint handle); }; } diff --git a/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.cpp b/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.cpp index 0a7caa88cec..275c0cbf9d8 100644 --- a/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.cpp +++ b/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.cpp @@ -12,7 +12,7 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLShaderPrecisionFormat); WebGLShaderPrecisionFormat::WebGLShaderPrecisionFormat(JS::Realm& realm) - : WebGLObject(realm) + : WebGLObject(realm, 0) { } diff --git a/Libraries/LibWeb/WebGL/WebGLTexture.cpp b/Libraries/LibWeb/WebGL/WebGLTexture.cpp index be3b837f859..60a5c1cf1ec 100644 --- a/Libraries/LibWeb/WebGL/WebGLTexture.cpp +++ b/Libraries/LibWeb/WebGL/WebGLTexture.cpp @@ -1,9 +1,11 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include @@ -11,8 +13,13 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLTexture); -WebGLTexture::WebGLTexture(JS::Realm& realm) - : WebGLObject(realm) +GC::Ptr WebGLTexture::create(JS::Realm& realm, GLuint handle) +{ + return realm.heap().allocate(realm, handle); +} + +WebGLTexture::WebGLTexture(JS::Realm& realm, GLuint handle) + : WebGLObject(realm, handle) { } diff --git a/Libraries/LibWeb/WebGL/WebGLTexture.h b/Libraries/LibWeb/WebGL/WebGLTexture.h index 1b2cc675f59..7d82eca0cfa 100644 --- a/Libraries/LibWeb/WebGL/WebGLTexture.h +++ b/Libraries/LibWeb/WebGL/WebGLTexture.h @@ -1,11 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include #include namespace Web::WebGL { @@ -15,10 +17,12 @@ class WebGLTexture final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLTexture); public: + static GC::Ptr create(JS::Realm& realm, GLuint handle); + virtual ~WebGLTexture(); protected: - explicit WebGLTexture(JS::Realm&); + explicit WebGLTexture(JS::Realm&, GLuint handle); }; } diff --git a/Libraries/LibWeb/WebGL/WebGLUniformLocation.cpp b/Libraries/LibWeb/WebGL/WebGLUniformLocation.cpp index 11e3e414a88..437693026aa 100644 --- a/Libraries/LibWeb/WebGL/WebGLUniformLocation.cpp +++ b/Libraries/LibWeb/WebGL/WebGLUniformLocation.cpp @@ -1,9 +1,11 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include @@ -11,8 +13,13 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLUniformLocation); -WebGLUniformLocation::WebGLUniformLocation(JS::Realm& realm) - : WebGLObject(realm) +GC::Ptr WebGLUniformLocation::create(JS::Realm& realm, GLuint handle) +{ + return realm.heap().allocate(realm, handle); +} + +WebGLUniformLocation::WebGLUniformLocation(JS::Realm& realm, GLuint handle) + : WebGLObject(realm, handle) { } diff --git a/Libraries/LibWeb/WebGL/WebGLUniformLocation.h b/Libraries/LibWeb/WebGL/WebGLUniformLocation.h index 282cc646692..7cc28b16309 100644 --- a/Libraries/LibWeb/WebGL/WebGLUniformLocation.h +++ b/Libraries/LibWeb/WebGL/WebGLUniformLocation.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,10 +16,12 @@ class WebGLUniformLocation final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLUniformLocation); public: + static GC::Ptr create(JS::Realm& realm, GLuint handle); + virtual ~WebGLUniformLocation(); protected: - explicit WebGLUniformLocation(JS::Realm&); + explicit WebGLUniformLocation(JS::Realm&, GLuint handle); }; }