Sfoglia il codice sorgente

LibWeb/WebGL: Implement getActiveAttrib() and getActiveUniform()

Aliaksandr Kalenik 7 mesi fa
parent
commit
3c2ac309ca

+ 18 - 1
Libraries/LibWeb/WebGL/WebGLActiveInfo.cpp

@@ -4,17 +4,34 @@
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
 
 
+#include <LibJS/Runtime/Realm.h>
+#include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/Bindings/WebGLActiveInfoPrototype.h>
 #include <LibWeb/WebGL/WebGLActiveInfo.h>
 #include <LibWeb/WebGL/WebGLActiveInfo.h>
 
 
 namespace Web::WebGL {
 namespace Web::WebGL {
 
 
 GC_DEFINE_ALLOCATOR(WebGLActiveInfo);
 GC_DEFINE_ALLOCATOR(WebGLActiveInfo);
 
 
-WebGLActiveInfo::WebGLActiveInfo(JS::Realm& realm)
+GC::Ptr<WebGLActiveInfo> WebGLActiveInfo::create(JS::Realm& realm, String name, GLenum type, GLsizei size)
+{
+    return realm.create<WebGLActiveInfo>(realm, move(name), type, size);
+}
+
+WebGLActiveInfo::WebGLActiveInfo(JS::Realm& realm, String name, GLenum type, GLsizei size)
     : Bindings::PlatformObject(realm)
     : Bindings::PlatformObject(realm)
+    , m_name(move(name))
+    , m_type(type)
+    , m_size(size)
 {
 {
 }
 }
 
 
 WebGLActiveInfo::~WebGLActiveInfo() = default;
 WebGLActiveInfo::~WebGLActiveInfo() = default;
 
 
+void WebGLActiveInfo::initialize(JS::Realm& realm)
+{
+    Base::initialize(realm);
+    WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLActiveInfo);
+}
+
 }
 }

+ 16 - 1
Libraries/LibWeb/WebGL/WebGLActiveInfo.h

@@ -8,6 +8,9 @@
 
 
 #include <LibWeb/Bindings/PlatformObject.h>
 #include <LibWeb/Bindings/PlatformObject.h>
 
 
+typedef unsigned int GLenum;
+typedef int GLsizei;
+
 namespace Web::WebGL {
 namespace Web::WebGL {
 
 
 class WebGLActiveInfo : public Bindings::PlatformObject {
 class WebGLActiveInfo : public Bindings::PlatformObject {
@@ -15,10 +18,22 @@ class WebGLActiveInfo : public Bindings::PlatformObject {
     GC_DECLARE_ALLOCATOR(WebGLActiveInfo);
     GC_DECLARE_ALLOCATOR(WebGLActiveInfo);
 
 
 public:
 public:
+    static GC::Ptr<WebGLActiveInfo> create(JS::Realm&, String name, GLenum type, GLsizei size);
     virtual ~WebGLActiveInfo();
     virtual ~WebGLActiveInfo();
 
 
+    GLsizei size() const { return m_size; }
+    GLenum type() const { return m_type; }
+    String const& name() const { return m_name; }
+
 protected:
 protected:
-    explicit WebGLActiveInfo(JS::Realm&);
+    explicit WebGLActiveInfo(JS::Realm&, String name, GLenum type, GLsizei size);
+
+private:
+    virtual void initialize(JS::Realm&) override;
+
+    String m_name;
+    GLenum m_type { 0 };
+    GLsizei m_size { 0 };
 };
 };
 
 
 }
 }

+ 3 - 3
Libraries/LibWeb/WebGL/WebGLActiveInfo.idl

@@ -3,7 +3,7 @@
 // https://registry.khronos.org/webgl/specs/latest/1.0/#5.11
 // https://registry.khronos.org/webgl/specs/latest/1.0/#5.11
 [Exposed=(Window,Worker)]
 [Exposed=(Window,Worker)]
 interface WebGLActiveInfo {
 interface WebGLActiveInfo {
-    [FIXME] readonly attribute GLint size;
-    [FIXME] readonly attribute GLenum type;
-    [FIXME] readonly attribute DOMString name;
+    readonly attribute GLint size;
+    readonly attribute GLenum type;
+    readonly attribute DOMString name;
 };
 };

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

@@ -103,8 +103,8 @@ interface mixin WebGLRenderingContextBase {
 
 
     undefined generateMipmap(GLenum target);
     undefined generateMipmap(GLenum target);
 
 
-    [FIXME] WebGLActiveInfo? getActiveAttrib(WebGLProgram program, GLuint index);
-    [FIXME] WebGLActiveInfo? getActiveUniform(WebGLProgram program, GLuint index);
+    WebGLActiveInfo? getActiveAttrib(WebGLProgram program, GLuint index);
+    WebGLActiveInfo? getActiveUniform(WebGLProgram program, GLuint index);
     [FIXME] sequence<WebGLShader>? getAttachedShaders(WebGLProgram program);
     [FIXME] sequence<WebGLShader>? getAttachedShaders(WebGLProgram program);
 
 
     GLint getAttribLocation(WebGLProgram program, DOMString name);
     GLint getAttribLocation(WebGLProgram program, DOMString name);

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

@@ -352,6 +352,34 @@ public:
             continue;
             continue;
         }
         }
 
 
+        if (function.name == "getActiveUniform"sv) {
+            function_impl_generator.append(R"~~~(
+    GLint size = 0;
+    GLenum type = 0;
+    GLsizei buf_size = 256;
+    GLsizei length = 0;
+    GLchar name[256];
+    glGetActiveUniform(program->handle(), index, buf_size, &length, &size, &type, name);
+    auto readonly_bytes = ReadonlyBytes { name, static_cast<size_t>(length) };
+    return WebGLActiveInfo::create(m_realm, String::from_utf8_without_validation(readonly_bytes), type, size);
+)~~~");
+            continue;
+        }
+
+        if (function.name == "getActiveAttrib"sv) {
+            function_impl_generator.append(R"~~~(
+    GLint size = 0;
+    GLenum type = 0;
+    GLsizei buf_size = 256;
+    GLsizei length = 0;
+    GLchar name[256];
+    glGetActiveAttrib(program->handle(), index, buf_size, &length, &size, &type, name);
+    auto readonly_bytes = ReadonlyBytes { name, static_cast<size_t>(length) };
+    return WebGLActiveInfo::create(m_realm, String::from_utf8_without_validation(readonly_bytes), type, size);
+)~~~");
+            continue;
+        }
+
         Vector<ByteString> gl_call_arguments;
         Vector<ByteString> gl_call_arguments;
         for (size_t i = 0; i < function.parameters.size(); ++i) {
         for (size_t i = 0; i < function.parameters.size(); ++i) {
             auto const& parameter = function.parameters[i];
             auto const& parameter = function.parameters[i];