Browse Source

LibWeb/WebGL: Implement vertexAttrib{1,2,3,4}fv

Aliaksandr Kalenik 7 months ago
parent
commit
ba19328b98

+ 3 - 0
Libraries/LibWeb/WebGL/Types.idl

@@ -13,3 +13,6 @@ typedef unrestricted float GLclampf;
 // WebGL 2.0
 typedef long long GLint64;
 typedef unsigned long long GLuint64;
+
+// FIXME: BufferSource should be a Float32Array
+typedef (BufferSource or sequence<GLfloat>) Float32List;

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

@@ -182,10 +182,10 @@ interface mixin WebGLRenderingContextBase {
     undefined vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z);
     undefined vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
 
-    [FIXME] undefined vertexAttrib1fv(GLuint index, Float32List values);
-    [FIXME] undefined vertexAttrib2fv(GLuint index, Float32List values);
-    [FIXME] undefined vertexAttrib3fv(GLuint index, Float32List values);
-    [FIXME] undefined vertexAttrib4fv(GLuint index, Float32List values);
+    undefined vertexAttrib1fv(GLuint index, Float32List values);
+    undefined vertexAttrib2fv(GLuint index, Float32List values);
+    undefined vertexAttrib3fv(GLuint index, Float32List values);
+    undefined vertexAttrib4fv(GLuint index, Float32List values);
 
     undefined vertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset);
 

+ 0 - 3
Libraries/LibWeb/WebGL/WebGLRenderingContextOverloads.idl

@@ -9,9 +9,6 @@ typedef (ImageBitmap or
          // FIXME: VideoFrame
          ) TexImageSource;
 
-// FIXME: BufferSource should be a Float32Array
-typedef (BufferSource or sequence<GLfloat>) Float32List;
-
 // FIXME: BufferSource should be a Int32Array
 typedef (BufferSource or sequence<GLint>) Int32List;
 

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

@@ -709,6 +709,24 @@ public:
             continue;
         }
 
+        if (function.name == "vertexAttrib1fv"sv || function.name == "vertexAttrib2fv"sv || function.name == "vertexAttrib3fv"sv || function.name == "vertexAttrib4fv"sv) {
+            auto number_of_vector_elements = function.name.substring_view(12, 1);
+            function_impl_generator.set("number_of_vector_elements", number_of_vector_elements);
+            function_impl_generator.append(R"~~~(
+    if (values.has<Vector<float>>()) {
+        auto& data = values.get<Vector<float>>();
+        glVertexAttrib@number_of_vector_elements@fv(index, data.data());
+        return;
+    }
+
+    auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*values.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
+    auto& float32_array = verify_cast<JS::Float32Array>(typed_array_base);
+    float const* data = float32_array.data().data();
+    glVertexAttrib@number_of_vector_elements@fv(index, data);
+)~~~");
+            continue;
+        }
+
         if (function.name == "getParameter"sv) {
             generate_get_parameter(function_impl_generator);
             continue;