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

This commit is contained in:
Aliaksandr Kalenik 2024-12-10 05:18:17 +01:00 committed by Alexander Kalenik
parent 4e8ec1e793
commit ba19328b98
Notes: github-actions[bot] 2024-12-13 08:20:54 +00:00
4 changed files with 25 additions and 7 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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;