LibWeb/WebGL: Define Float32List exactly like in the spec

Use `Float32Array or sequence<GLfloat>` instead of
`BufferSource or sequence<GLfloat>`. This meaningfully changes behavior
for `Float16Array` and `Float64Array`: they are now converted to
`sequence<GLfloat>` by iterating the typed array, rather than being
treated as a `BufferSource`. As a result, many WebGL calls now work
correctly where we previously crashed in `VERIFY_NOT_REACHED()` due to
the assumption that a `BufferSource` was always a `Float32Array`.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/5962
This commit is contained in:
Aliaksandr Kalenik 2025-09-30 03:03:05 +02:00 committed by Alexander Kalenik
commit d54cab60a8
Notes: github-actions[bot] 2025-09-30 14:48:33 +00:00
6 changed files with 113 additions and 143 deletions

View file

@ -14,5 +14,4 @@ typedef unrestricted float GLclampf;
typedef long long GLint64;
typedef unsigned long long GLuint64;
// FIXME: BufferSource should be a Float32Array
typedef (BufferSource or sequence<GLfloat>) Float32List;
typedef (Float32Array or sequence<GLfloat>) Float32List;

View file

@ -419,7 +419,7 @@ void WebGL2RenderingContextImpl::draw_buffers(Vector<WebIDL::UnsignedLong> buffe
glDrawBuffers(buffers.size(), buffers.data());
}
void WebGL2RenderingContextImpl::clear_bufferfv(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values, WebIDL::UnsignedLongLong src_offset)
void WebGL2RenderingContextImpl::clear_bufferfv(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, Float32List values, WebIDL::UnsignedLongLong src_offset)
{
m_context->make_current();
m_context->notify_content_will_change();
@ -430,11 +430,10 @@ void WebGL2RenderingContextImpl::clear_bufferfv(WebIDL::UnsignedLong buffer, Web
auto& vector = values.get<Vector<float>>();
data = vector.data();
count = vector.size();
} else if (values.has<GC::Root<WebIDL::BufferSource>>()) {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*values.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& typed_array = as<JS::Float32Array>(typed_array_base);
data = typed_array.data().data();
count = typed_array.array_length().length();
} else if (values.has<GC::Root<JS::Float32Array>>()) {
auto& float32_array = values.get<GC::Root<JS::Float32Array>>();
data = float32_array->data().data();
count = float32_array->array_length().length();
} else {
VERIFY_NOT_REACHED();
}
@ -1203,7 +1202,7 @@ void WebGL2RenderingContextImpl::compressed_tex_sub_image2d(WebIDL::UnsignedLong
glCompressedTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, format, count, src_data->byte_length(), pixels_ptr);
}
void WebGL2RenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
void WebGL2RenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
{
m_context->make_current();
@ -1216,11 +1215,10 @@ void WebGL2RenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> locat
auto& vector = v.get<Vector<float>>();
data = vector.data();
count = vector.size();
} else if (v.has<GC::Root<WebIDL::BufferSource>>()) {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& typed_array = as<JS::Float32Array>(typed_array_base);
data = typed_array.data().data();
count = typed_array.array_length().length();
} else if (v.has<GC::Root<JS::Float32Array>>()) {
auto& typed_array = v.get<GC::Root<JS::Float32Array>>();
data = typed_array->data().data();
count = typed_array->array_length().length();
} else {
VERIFY_NOT_REACHED();
}
@ -1240,7 +1238,7 @@ void WebGL2RenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> locat
glUniform1fv(location->handle(), count / 1, data);
}
void WebGL2RenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
void WebGL2RenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
{
m_context->make_current();
@ -1253,11 +1251,10 @@ void WebGL2RenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> locat
auto& vector = v.get<Vector<float>>();
data = vector.data();
count = vector.size();
} else if (v.has<GC::Root<WebIDL::BufferSource>>()) {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& typed_array = as<JS::Float32Array>(typed_array_base);
data = typed_array.data().data();
count = typed_array.array_length().length();
} else if (v.has<GC::Root<JS::Float32Array>>()) {
auto& typed_array = v.get<GC::Root<JS::Float32Array>>();
data = typed_array->data().data();
count = typed_array->array_length().length();
} else {
VERIFY_NOT_REACHED();
}
@ -1277,7 +1274,7 @@ void WebGL2RenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> locat
glUniform2fv(location->handle(), count / 2, data);
}
void WebGL2RenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
void WebGL2RenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
{
m_context->make_current();
@ -1290,11 +1287,10 @@ void WebGL2RenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> locat
auto& vector = v.get<Vector<float>>();
data = vector.data();
count = vector.size();
} else if (v.has<GC::Root<WebIDL::BufferSource>>()) {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& typed_array = as<JS::Float32Array>(typed_array_base);
data = typed_array.data().data();
count = typed_array.array_length().length();
} else if (v.has<GC::Root<JS::Float32Array>>()) {
auto& typed_array = v.get<GC::Root<JS::Float32Array>>();
data = typed_array->data().data();
count = typed_array->array_length().length();
} else {
VERIFY_NOT_REACHED();
}
@ -1314,7 +1310,7 @@ void WebGL2RenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> locat
glUniform3fv(location->handle(), count / 3, data);
}
void WebGL2RenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
void WebGL2RenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
{
m_context->make_current();
@ -1327,11 +1323,10 @@ void WebGL2RenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> locat
auto& vector = v.get<Vector<float>>();
data = vector.data();
count = vector.size();
} else if (v.has<GC::Root<WebIDL::BufferSource>>()) {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& typed_array = as<JS::Float32Array>(typed_array_base);
data = typed_array.data().data();
count = typed_array.array_length().length();
} else if (v.has<GC::Root<JS::Float32Array>>()) {
auto& typed_array = v.get<GC::Root<JS::Float32Array>>();
data = typed_array->data().data();
count = typed_array->array_length().length();
} else {
VERIFY_NOT_REACHED();
}
@ -1499,7 +1494,7 @@ void WebGL2RenderingContextImpl::uniform4iv(GC::Root<WebGLUniformLocation> locat
glUniform4iv(location->handle(), count / 4, data);
}
void WebGL2RenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
void WebGL2RenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
{
m_context->make_current();
@ -1514,10 +1509,9 @@ void WebGL2RenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation
raw_data = vector_data.data();
count = vector_data.size() / matrix_size;
} else {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*data.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
raw_data = float32_array.data().data();
count = float32_array.array_length().length() / matrix_size;
auto& float32_array = data.get<GC::Root<JS::Float32Array>>();
raw_data = float32_array->data().data();
count = float32_array->array_length().length() / matrix_size;
}
if (src_offset + src_length > (count * matrix_size)) {
@ -1535,7 +1529,7 @@ void WebGL2RenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation
glUniformMatrix2fv(location->handle(), count, transpose, raw_data);
}
void WebGL2RenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
void WebGL2RenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
{
m_context->make_current();
@ -1550,10 +1544,9 @@ void WebGL2RenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation
raw_data = vector_data.data();
count = vector_data.size() / matrix_size;
} else {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*data.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
raw_data = float32_array.data().data();
count = float32_array.array_length().length() / matrix_size;
auto& float32_array = data.get<GC::Root<JS::Float32Array>>();
raw_data = float32_array->data().data();
count = float32_array->array_length().length() / matrix_size;
}
if (src_offset + src_length > (count * matrix_size)) {
@ -1571,7 +1564,7 @@ void WebGL2RenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation
glUniformMatrix3fv(location->handle(), count, transpose, raw_data);
}
void WebGL2RenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
void WebGL2RenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
{
m_context->make_current();
@ -1586,10 +1579,9 @@ void WebGL2RenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation
raw_data = vector_data.data();
count = vector_data.size() / matrix_size;
} else {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*data.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
raw_data = float32_array.data().data();
count = float32_array.array_length().length() / matrix_size;
auto& float32_array = data.get<GC::Root<JS::Float32Array>>();
raw_data = float32_array->data().data();
count = float32_array->array_length().length() / matrix_size;
}
if (src_offset + src_length > (count * matrix_size)) {
@ -3435,7 +3427,7 @@ void WebGL2RenderingContextImpl::vertex_attrib4f(WebIDL::UnsignedLong index, flo
glVertexAttrib4f(index, x, y, z, w);
}
void WebGL2RenderingContextImpl::vertex_attrib1fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values)
void WebGL2RenderingContextImpl::vertex_attrib1fv(WebIDL::UnsignedLong index, Float32List values)
{
m_context->make_current();
@ -3450,19 +3442,17 @@ void WebGL2RenderingContextImpl::vertex_attrib1fv(WebIDL::UnsignedLong index, Va
return;
}
auto& buffer_source = values.get<GC::Root<WebIDL::BufferSource>>();
if (buffer_source->byte_length() < 1 * sizeof(float)) {
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
if (float32_array.byte_length().length() < 1 * sizeof(float)) {
set_error(GL_INVALID_VALUE);
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*buffer_source->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
float const* data = float32_array.data().data();
glVertexAttrib1fv(index, data);
}
void WebGL2RenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values)
void WebGL2RenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Float32List values)
{
m_context->make_current();
@ -3477,19 +3467,17 @@ void WebGL2RenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Va
return;
}
auto& buffer_source = values.get<GC::Root<WebIDL::BufferSource>>();
if (buffer_source->byte_length() < 2 * sizeof(float)) {
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
if (float32_array.byte_length().length() < 2 * sizeof(float)) {
set_error(GL_INVALID_VALUE);
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*buffer_source->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
float const* data = float32_array.data().data();
glVertexAttrib2fv(index, data);
}
void WebGL2RenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values)
void WebGL2RenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Float32List values)
{
m_context->make_current();
@ -3504,19 +3492,17 @@ void WebGL2RenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Va
return;
}
auto& buffer_source = values.get<GC::Root<WebIDL::BufferSource>>();
if (buffer_source->byte_length() < 3 * sizeof(float)) {
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
if (float32_array.byte_length().length() < 3 * sizeof(float)) {
set_error(GL_INVALID_VALUE);
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*buffer_source->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
float const* data = float32_array.data().data();
glVertexAttrib3fv(index, data);
}
void WebGL2RenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values)
void WebGL2RenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Float32List values)
{
m_context->make_current();
@ -3531,14 +3517,12 @@ void WebGL2RenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Va
return;
}
auto& buffer_source = values.get<GC::Root<WebIDL::BufferSource>>();
if (buffer_source->byte_length() < 4 * sizeof(float)) {
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
if (float32_array.byte_length().length() < 4 * sizeof(float)) {
set_error(GL_INVALID_VALUE);
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*buffer_source->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
float const* data = float32_array.data().data();
glVertexAttrib4fv(index, data);
}

View file

@ -48,7 +48,7 @@ public:
void draw_arrays_instanced(WebIDL::UnsignedLong mode, WebIDL::Long first, WebIDL::Long count, WebIDL::Long instance_count);
void draw_elements_instanced(WebIDL::UnsignedLong mode, WebIDL::Long count, WebIDL::UnsignedLong type, WebIDL::LongLong offset, WebIDL::Long instance_count);
void draw_buffers(Vector<WebIDL::UnsignedLong> buffers);
void clear_bufferfv(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values, WebIDL::UnsignedLongLong src_offset);
void clear_bufferfv(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, Float32List values, WebIDL::UnsignedLongLong src_offset);
void clear_bufferiv(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> values, WebIDL::UnsignedLongLong src_offset);
void clear_bufferuiv(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::UnsignedLong>> values, WebIDL::UnsignedLongLong src_offset);
void clear_bufferfi(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, float depth, WebIDL::Long stencil);
@ -87,17 +87,17 @@ public:
void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> src_data, WebIDL::UnsignedLongLong src_offset);
void compressed_tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::UnsignedLong internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, GC::Root<WebIDL::ArrayBufferView> src_data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length_override);
void compressed_tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, GC::Root<WebIDL::ArrayBufferView> src_data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length_override);
void uniform1fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform2fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform3fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform4fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform1fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform1iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform2iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform3iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform4iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List data, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length);
void read_pixels(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels);
void active_texture(WebIDL::UnsignedLong texture);
void attach_shader(GC::Root<WebGLProgram> program, GC::Root<WebGLShader> shader);
@ -200,10 +200,10 @@ public:
void vertex_attrib2f(WebIDL::UnsignedLong index, float x, float y);
void vertex_attrib3f(WebIDL::UnsignedLong index, float x, float y, float z);
void vertex_attrib4f(WebIDL::UnsignedLong index, float x, float y, float z, float w);
void vertex_attrib1fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values);
void vertex_attrib2fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values);
void vertex_attrib3fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values);
void vertex_attrib4fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values);
void vertex_attrib1fv(WebIDL::UnsignedLong index, Float32List values);
void vertex_attrib2fv(WebIDL::UnsignedLong index, Float32List values);
void vertex_attrib3fv(WebIDL::UnsignedLong index, Float32List values);
void vertex_attrib4fv(WebIDL::UnsignedLong index, Float32List values);
void vertex_attrib_pointer(WebIDL::UnsignedLong index, WebIDL::Long size, WebIDL::UnsignedLong type, bool normalized, WebIDL::Long stride, WebIDL::LongLong offset);
void viewport(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height);

View file

@ -18,6 +18,8 @@ using TexImageSource = Variant<GC::Root<HTML::ImageBitmap>, GC::Root<HTML::Image
// We should make WebGL code generator to produce implementation for this interface.
class WebGLRenderingContextBase {
public:
using Float32List = Variant<GC::Root<JS::Float32Array>, Vector<float>>;
virtual GC::Cell const* gc_cell() const = 0;
virtual void visit_edges(JS::Cell::Visitor&) = 0;
virtual OpenGLContext& context() = 0;

View file

@ -362,7 +362,7 @@ void WebGLRenderingContextImpl::tex_sub_image2d(WebIDL::UnsignedLong target, Web
glTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, converted_texture.width, converted_texture.height, format, type, converted_texture.buffer.size(), converted_texture.buffer.data());
}
void WebGLRenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v)
void WebGLRenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> location, Float32List v)
{
m_context->make_current();
@ -375,11 +375,10 @@ void WebGLRenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> locati
auto& vector = v.get<Vector<float>>();
data = vector.data();
count = vector.size();
} else if (v.has<GC::Root<WebIDL::BufferSource>>()) {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& typed_array = as<JS::Float32Array>(typed_array_base);
data = typed_array.data().data();
count = typed_array.array_length().length();
} else if (v.has<GC::Root<JS::Float32Array>>()) {
auto& float32_array = *v.get<GC::Root<JS::Float32Array>>();
data = float32_array.data().data();
count = float32_array.array_length().length();
} else {
VERIFY_NOT_REACHED();
}
@ -387,7 +386,7 @@ void WebGLRenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> locati
glUniform1fv(location->handle(), count / 1, data);
}
void WebGLRenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v)
void WebGLRenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List v)
{
m_context->make_current();
@ -400,11 +399,10 @@ void WebGLRenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> locati
auto& vector = v.get<Vector<float>>();
data = vector.data();
count = vector.size();
} else if (v.has<GC::Root<WebIDL::BufferSource>>()) {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& typed_array = as<JS::Float32Array>(typed_array_base);
data = typed_array.data().data();
count = typed_array.array_length().length();
} else if (v.has<GC::Root<JS::Float32Array>>()) {
auto& float32_array = *v.get<GC::Root<JS::Float32Array>>();
data = float32_array.data().data();
count = float32_array.array_length().length();
} else {
VERIFY_NOT_REACHED();
}
@ -412,7 +410,7 @@ void WebGLRenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> locati
glUniform2fv(location->handle(), count / 2, data);
}
void WebGLRenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v)
void WebGLRenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List v)
{
m_context->make_current();
@ -425,11 +423,10 @@ void WebGLRenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> locati
auto& vector = v.get<Vector<float>>();
data = vector.data();
count = vector.size();
} else if (v.has<GC::Root<WebIDL::BufferSource>>()) {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& typed_array = as<JS::Float32Array>(typed_array_base);
data = typed_array.data().data();
count = typed_array.array_length().length();
} else if (v.has<GC::Root<JS::Float32Array>>()) {
auto& float32_array = *v.get<GC::Root<JS::Float32Array>>();
data = float32_array.data().data();
count = float32_array.array_length().length();
} else {
VERIFY_NOT_REACHED();
}
@ -437,7 +434,7 @@ void WebGLRenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> locati
glUniform3fv(location->handle(), count / 3, data);
}
void WebGLRenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v)
void WebGLRenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List v)
{
m_context->make_current();
@ -450,11 +447,10 @@ void WebGLRenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> locati
auto& vector = v.get<Vector<float>>();
data = vector.data();
count = vector.size();
} else if (v.has<GC::Root<WebIDL::BufferSource>>()) {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& typed_array = as<JS::Float32Array>(typed_array_base);
data = typed_array.data().data();
count = typed_array.array_length().length();
} else if (v.has<GC::Root<JS::Float32Array>>()) {
auto& float32_array = *v.get<GC::Root<JS::Float32Array>>();
data = float32_array.data().data();
count = float32_array.array_length().length();
} else {
VERIFY_NOT_REACHED();
}
@ -562,7 +558,7 @@ void WebGLRenderingContextImpl::uniform4iv(GC::Root<WebGLUniformLocation> locati
glUniform4iv(location->handle(), count / 4, data);
}
void WebGLRenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> value)
void WebGLRenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
{
m_context->make_current();
@ -577,8 +573,7 @@ void WebGLRenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation>
raw_data = vector_data.data();
count = vector_data.size() / matrix_size;
} else {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*value.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
auto& float32_array = *value.get<GC::Root<JS::Float32Array>>();
raw_data = float32_array.data().data();
count = float32_array.array_length().length() / matrix_size;
}
@ -586,7 +581,7 @@ void WebGLRenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation>
glUniformMatrix2fv(location->handle(), count, transpose, raw_data);
}
void WebGLRenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> value)
void WebGLRenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
{
m_context->make_current();
@ -601,8 +596,7 @@ void WebGLRenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation>
raw_data = vector_data.data();
count = vector_data.size() / matrix_size;
} else {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*value.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
auto& float32_array = *value.get<GC::Root<JS::Float32Array>>();
raw_data = float32_array.data().data();
count = float32_array.array_length().length() / matrix_size;
}
@ -610,7 +604,7 @@ void WebGLRenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation>
glUniformMatrix3fv(location->handle(), count, transpose, raw_data);
}
void WebGLRenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> value)
void WebGLRenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
{
m_context->make_current();
@ -625,8 +619,7 @@ void WebGLRenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation>
raw_data = vector_data.data();
count = vector_data.size() / matrix_size;
} else {
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*value.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
auto& float32_array = *value.get<GC::Root<JS::Float32Array>>();
raw_data = float32_array.data().data();
count = float32_array.array_length().length() / matrix_size;
}
@ -2275,7 +2268,7 @@ void WebGLRenderingContextImpl::vertex_attrib4f(WebIDL::UnsignedLong index, floa
glVertexAttrib4f(index, x, y, z, w);
}
void WebGLRenderingContextImpl::vertex_attrib1fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values)
void WebGLRenderingContextImpl::vertex_attrib1fv(WebIDL::UnsignedLong index, Float32List values)
{
m_context->make_current();
@ -2290,19 +2283,17 @@ void WebGLRenderingContextImpl::vertex_attrib1fv(WebIDL::UnsignedLong index, Var
return;
}
auto& buffer_source = values.get<GC::Root<WebIDL::BufferSource>>();
if (buffer_source->byte_length() < 1 * sizeof(float)) {
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
if (float32_array.byte_length().length() < 1 * sizeof(float)) {
set_error(GL_INVALID_VALUE);
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*buffer_source->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
float const* data = float32_array.data().data();
glVertexAttrib1fv(index, data);
}
void WebGLRenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values)
void WebGLRenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Float32List values)
{
m_context->make_current();
@ -2317,19 +2308,17 @@ void WebGLRenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Var
return;
}
auto& buffer_source = values.get<GC::Root<WebIDL::BufferSource>>();
if (buffer_source->byte_length() < 2 * sizeof(float)) {
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
if (float32_array.byte_length().length() < 2 * sizeof(float)) {
set_error(GL_INVALID_VALUE);
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*buffer_source->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
float const* data = float32_array.data().data();
glVertexAttrib2fv(index, data);
}
void WebGLRenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values)
void WebGLRenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Float32List values)
{
m_context->make_current();
@ -2344,19 +2333,17 @@ void WebGLRenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Var
return;
}
auto& buffer_source = values.get<GC::Root<WebIDL::BufferSource>>();
if (buffer_source->byte_length() < 3 * sizeof(float)) {
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
if (float32_array.byte_length().length() < 3 * sizeof(float)) {
set_error(GL_INVALID_VALUE);
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*buffer_source->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
float const* data = float32_array.data().data();
glVertexAttrib3fv(index, data);
}
void WebGLRenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values)
void WebGLRenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Float32List values)
{
m_context->make_current();
@ -2371,14 +2358,12 @@ void WebGLRenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Var
return;
}
auto& buffer_source = values.get<GC::Root<WebIDL::BufferSource>>();
if (buffer_source->byte_length() < 4 * sizeof(float)) {
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
if (float32_array.byte_length().length() < 4 * sizeof(float)) {
set_error(GL_INVALID_VALUE);
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*buffer_source->raw_object());
auto& float32_array = as<JS::Float32Array>(typed_array_base);
float const* data = float32_array.data().data();
glVertexAttrib4fv(index, data);
}

View file

@ -38,17 +38,17 @@ public:
void tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, Variant<GC::Root<ImageBitmap>, GC::Root<ImageData>, GC::Root<HTMLImageElement>, GC::Root<HTMLCanvasElement>, GC::Root<HTMLVideoElement>, GC::Root<OffscreenCanvas>> source);
void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels);
void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, Variant<GC::Root<ImageBitmap>, GC::Root<ImageData>, GC::Root<HTMLImageElement>, GC::Root<HTMLCanvasElement>, GC::Root<HTMLVideoElement>, GC::Root<OffscreenCanvas>> source);
void uniform1fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v);
void uniform2fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v);
void uniform3fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v);
void uniform4fv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> v);
void uniform1fv(GC::Root<WebGLUniformLocation> location, Float32List v);
void uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List v);
void uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List v);
void uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List v);
void uniform1iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v);
void uniform2iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v);
void uniform3iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v);
void uniform4iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v);
void uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> value);
void uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> value);
void uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> value);
void uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value);
void uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value);
void uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value);
void active_texture(WebIDL::UnsignedLong texture);
void attach_shader(GC::Root<WebGLProgram> program, GC::Root<WebGLShader> shader);
void bind_attrib_location(GC::Root<WebGLProgram> program, WebIDL::UnsignedLong index, String name);
@ -150,10 +150,10 @@ public:
void vertex_attrib2f(WebIDL::UnsignedLong index, float x, float y);
void vertex_attrib3f(WebIDL::UnsignedLong index, float x, float y, float z);
void vertex_attrib4f(WebIDL::UnsignedLong index, float x, float y, float z, float w);
void vertex_attrib1fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values);
void vertex_attrib2fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values);
void vertex_attrib3fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values);
void vertex_attrib4fv(WebIDL::UnsignedLong index, Variant<GC::Root<WebIDL::BufferSource>, Vector<float>> values);
void vertex_attrib1fv(WebIDL::UnsignedLong index, Float32List values);
void vertex_attrib2fv(WebIDL::UnsignedLong index, Float32List values);
void vertex_attrib3fv(WebIDL::UnsignedLong index, Float32List values);
void vertex_attrib4fv(WebIDL::UnsignedLong index, Float32List values);
void vertex_attrib_pointer(WebIDL::UnsignedLong index, WebIDL::Long size, WebIDL::UnsignedLong type, bool normalized, WebIDL::Long stride, WebIDL::LongLong offset);
void viewport(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height);