ソースを参照

LibWeb/WebGL: Implement getShaderPrecisionFormat

Luke Wilde 7 ヶ月 前
コミット
bf2b8c5f2b

+ 1 - 0
Libraries/LibWeb/Forward.h

@@ -841,6 +841,7 @@ class WebGLProgram;
 class WebGLRenderbuffer;
 class WebGLRenderingContext;
 class WebGLShader;
+class WebGLShaderPrecisionFormat;
 class WebGLTexture;
 class WebGLUniformLocation;
 }

+ 1 - 0
Libraries/LibWeb/WebGL/Types.h

@@ -13,5 +13,6 @@ namespace Web::WebGL {
 
 using GLenum = unsigned int;
 using GLuint = unsigned int;
+using GLint = int;
 
 }

+ 2 - 1
Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl

@@ -5,6 +5,7 @@
 #import <WebGL/WebGLObject.idl>
 #import <WebGL/WebGLProgram.idl>
 #import <WebGL/WebGLShader.idl>
+#import <WebGL/WebGLShaderPrecisionFormat.idl>
 #import <WebGL/WebGLTexture.idl>
 #import <WebGL/WebGLUniformLocation.idl>
 #import <WebGL/WebGLRenderbuffer.idl>
@@ -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);

+ 19 - 2
Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.cpp

@@ -1,9 +1,12 @@
 /*
  * Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
+ * Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibJS/Runtime/Realm.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/Bindings/WebGLShaderPrecisionFormatPrototype.h>
 #include <LibWeb/WebGL/WebGLShaderPrecisionFormat.h>
 
@@ -11,11 +14,25 @@ namespace Web::WebGL {
 
 GC_DEFINE_ALLOCATOR(WebGLShaderPrecisionFormat);
 
-WebGLShaderPrecisionFormat::WebGLShaderPrecisionFormat(JS::Realm& realm)
-    : WebGLObject(realm, 0)
+GC::Ref<WebGLShaderPrecisionFormat> WebGLShaderPrecisionFormat::create(JS::Realm& realm, GLint range_min, GLint range_max, GLint precision)
+{
+    return realm.create<WebGLShaderPrecisionFormat>(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);
+}
+
 }

+ 20 - 5
Libraries/LibWeb/WebGL/WebGLShaderPrecisionFormat.h

@@ -1,24 +1,39 @@
 /*
  * Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
+ * Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
 #pragma once
 
-#include <LibWeb/WebGL/WebGLObject.h>
+#include <LibWeb/Bindings/PlatformObject.h>
+#include <LibWeb/WebGL/Types.h>
 
 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<WebGLShaderPrecisionFormat> 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 };
 };
 
 }

+ 3 - 3
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;
 };

+ 1 - 0
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,

+ 12 - 0
Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
+ * Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -327,6 +328,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 #include <LibWeb/WebGL/WebGLRenderbuffer.h>
 #include <LibWeb/WebGL/WebGLRenderingContextImpl.h>
 #include <LibWeb/WebGL/WebGLShader.h>
+#include <LibWeb/WebGL/WebGLShaderPrecisionFormat.h>
 #include <LibWeb/WebGL/WebGLTexture.h>
 #include <LibWeb/WebGL/WebGLUniformLocation.h>
 #include <LibWeb/WebIDL/Buffers.h>
@@ -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;