diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index 37425ee3212..91174df843e 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -841,6 +841,7 @@ class WebGLProgram; class WebGLRenderbuffer; class WebGLRenderingContext; class WebGLShader; +class WebGLShaderPrecisionFormat; class WebGLTexture; class WebGLUniformLocation; } diff --git a/Libraries/LibWeb/WebGL/Types.h b/Libraries/LibWeb/WebGL/Types.h index 19f80c93e92..bf8d35a25df 100644 --- a/Libraries/LibWeb/WebGL/Types.h +++ b/Libraries/LibWeb/WebGL/Types.h @@ -13,5 +13,6 @@ namespace Web::WebGL { using GLenum = unsigned int; using GLuint = unsigned int; +using GLint = int; } diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl index fd814a442dd..f59c42a4f65 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl @@ -5,6 +5,7 @@ #import #import #import +#import #import #import #import @@ -119,7 +120,7 @@ interface mixin WebGLRenderingContextBase { DOMString? getProgramInfoLog(WebGLProgram program); [FIXME] any getRenderbufferParameter(GLenum target, GLenum pname); any getShaderParameter(WebGLShader shader, GLenum pname); - [FIXME] WebGLShaderPrecisionFormat? getShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype); + WebGLShaderPrecisionFormat? getShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype); DOMString? getShaderInfoLog(WebGLShader shader); [FIXME] DOMString? getShaderSource(WebGLShader shader); diff --git a/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.cpp b/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.cpp index 275c0cbf9d8..7c6740a75d7 100644 --- a/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.cpp +++ b/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.cpp @@ -1,9 +1,12 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include @@ -11,11 +14,25 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLShaderPrecisionFormat); -WebGLShaderPrecisionFormat::WebGLShaderPrecisionFormat(JS::Realm& realm) - : WebGLObject(realm, 0) +GC::Ref WebGLShaderPrecisionFormat::create(JS::Realm& realm, GLint range_min, GLint range_max, GLint precision) +{ + return realm.create(realm, range_min, range_max, precision); +} + +WebGLShaderPrecisionFormat::WebGLShaderPrecisionFormat(JS::Realm& realm, GLint range_min, GLint range_max, GLint precision) + : Bindings::PlatformObject(realm) + , m_range_min(range_min) + , m_range_max(range_max) + , m_precision(precision) { } WebGLShaderPrecisionFormat::~WebGLShaderPrecisionFormat() = default; +void WebGLShaderPrecisionFormat::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLShaderPrecisionFormat); +} + } diff --git a/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.h b/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.h index 74668602ebf..2d321f61dc6 100644 --- a/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.h +++ b/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.h @@ -1,24 +1,39 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include +#include +#include namespace Web::WebGL { -class WebGLShaderPrecisionFormat final : public WebGLObject { - WEB_PLATFORM_OBJECT(WebGLShaderPrecisionFormat, WebGLObject); +class WebGLShaderPrecisionFormat final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(WebGLShaderPrecisionFormat, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(WebGLShaderPrecisionFormat); public: - virtual ~WebGLShaderPrecisionFormat(); + static GC::Ref create(JS::Realm& realm, GLint range_min, GLint range_max, GLint precision); + + virtual ~WebGLShaderPrecisionFormat() override; + + GLint range_min() const { return m_range_min; } + GLint range_max() const { return m_range_max; } + GLint precision() const { return m_precision; } protected: - explicit WebGLShaderPrecisionFormat(JS::Realm&); + explicit WebGLShaderPrecisionFormat(JS::Realm&, GLint range_min, GLint range_max, GLint precision); + + virtual void initialize(JS::Realm&) override; + +private: + GLint m_range_min { 0 }; + GLint m_range_max { 0 }; + GLint m_precision { 0 }; }; } diff --git a/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.idl b/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.idl index df92fe77e7f..25cbb44217f 100644 --- a/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.idl +++ b/Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.idl @@ -3,7 +3,7 @@ // https://registry.khronos.org/webgl/specs/latest/1.0/#5.12 [Exposed=(Window,Worker)] interface WebGLShaderPrecisionFormat { - [FIXME] readonly attribute GLint rangeMin; - [FIXME] readonly attribute GLint rangeMax; - [FIXME] readonly attribute GLint precision; + readonly attribute GLint rangeMin; + readonly attribute GLint rangeMax; + readonly attribute GLint precision; }; diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index c58b6529681..7cf528ad8b3 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -113,6 +113,7 @@ static bool is_platform_object(Type const& type) "WebGLRenderbuffer"sv, "WebGLRenderingContext"sv, "WebGLShader"sv, + "WebGLShaderPrecisionFormat"sv, "WebGLTexture"sv, "WebGLUniformLocation"sv, "Window"sv, diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp index cd97afe91bf..948308d883f 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ @@ -327,6 +328,7 @@ ErrorOr serenity_main(Main::Arguments arguments) #include #include #include +#include #include #include #include @@ -718,6 +720,16 @@ public: continue; } + if (function.name == "getShaderPrecisionFormat"sv) { + function_impl_generator.append(R"~~~( + GLint range[2]; + GLint precision; + glGetShaderPrecisionFormat(shadertype, precisiontype, range, &precision); + return WebGLShaderPrecisionFormat::create(m_realm, range[0], range[1], precision); +)~~~"); + continue; + } + if (function.name == "deleteBuffer"sv) { function_impl_generator.append(R"~~~( auto handle = buffer ? buffer->handle() : 0;