mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb/WebGL: Move Float32List -> Span<float> conversion into helper
This allows to remove lots of duplicated code.
This commit is contained in:
parent
d54cab60a8
commit
655cd339a7
Notes:
github-actions[bot]
2025-09-30 14:48:27 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 655cd339a7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6346
Reviewed-by: https://github.com/gmta
4 changed files with 84 additions and 359 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||||
* Copyright (c) 2024-2025, Luke Wilde <luke@ladybird.org>
|
* Copyright (c) 2024-2025, Luke Wilde <luke@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
@ -424,30 +424,18 @@ void WebGL2RenderingContextImpl::clear_bufferfv(WebIDL::UnsignedLong buffer, Web
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
m_context->notify_content_will_change();
|
m_context->notify_content_will_change();
|
||||||
|
|
||||||
float const* data = nullptr;
|
auto span = span_from_float32_list(values);
|
||||||
size_t count = 0;
|
|
||||||
if (values.has<Vector<float>>()) {
|
|
||||||
auto& vector = values.get<Vector<float>>();
|
|
||||||
data = vector.data();
|
|
||||||
count = vector.size();
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (buffer) {
|
switch (buffer) {
|
||||||
case GL_COLOR:
|
case GL_COLOR:
|
||||||
if (src_offset + 4 > count) {
|
if (src_offset + 4 > span.size()) {
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GL_DEPTH:
|
case GL_DEPTH:
|
||||||
case GL_STENCIL:
|
case GL_STENCIL:
|
||||||
if (src_offset + 1 > count) {
|
if (src_offset + 1 > span.size()) {
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -458,8 +446,8 @@ void WebGL2RenderingContextImpl::clear_bufferfv(WebIDL::UnsignedLong buffer, Web
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data += src_offset;
|
span = span.slice(src_offset);
|
||||||
glClearBufferfv(buffer, drawbuffer, data);
|
glClearBufferfv(buffer, drawbuffer, span.data());
|
||||||
needs_to_present();
|
needs_to_present();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1202,40 +1190,28 @@ void WebGL2RenderingContextImpl::compressed_tex_sub_image2d(WebIDL::UnsignedLong
|
||||||
glCompressedTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, format, count, src_data->byte_length(), pixels_ptr);
|
glCompressedTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, format, count, src_data->byte_length(), pixels_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> location, Float32List v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
|
void WebGL2RenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> location, Float32List values, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
|
||||||
{
|
{
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
|
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float const* data = nullptr;
|
auto span = span_from_float32_list(values);
|
||||||
size_t count = 0;
|
auto count = span.size();
|
||||||
if (v.has<Vector<float>>()) {
|
|
||||||
auto& vector = v.get<Vector<float>>();
|
|
||||||
data = vector.data();
|
|
||||||
count = vector.size();
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src_offset + src_length > count) {
|
if (src_offset + src_length > count) {
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data += src_offset;
|
span = span.slice(src_offset);
|
||||||
if (src_length == 0) {
|
if (src_length == 0) {
|
||||||
count -= src_offset;
|
count -= src_offset;
|
||||||
} else {
|
} else {
|
||||||
count = src_length;
|
count = src_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform1fv(location->handle(), count / 1, data);
|
glUniform1fv(location->handle(), count, span.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List 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)
|
||||||
|
|
@ -1245,33 +1221,21 @@ void WebGL2RenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> locat
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float const* data = nullptr;
|
auto span = span_from_float32_list(v);
|
||||||
size_t count = 0;
|
auto count = span.size();
|
||||||
if (v.has<Vector<float>>()) {
|
if (src_offset + src_length > span.size()) {
|
||||||
auto& vector = v.get<Vector<float>>();
|
|
||||||
data = vector.data();
|
|
||||||
count = vector.size();
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src_offset + src_length > count) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data += src_offset;
|
span = span.slice(src_offset);
|
||||||
if (src_length == 0) {
|
if (src_length == 0) {
|
||||||
count -= src_offset;
|
count -= src_offset;
|
||||||
} else {
|
} else {
|
||||||
count = src_length;
|
count = src_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform2fv(location->handle(), count / 2, data);
|
glUniform2fv(location->handle(), count / 2, span.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List 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)
|
||||||
|
|
@ -1281,33 +1245,21 @@ void WebGL2RenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> locat
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float const* data = nullptr;
|
auto span = span_from_float32_list(v);
|
||||||
size_t count = 0;
|
auto count = span.size();
|
||||||
if (v.has<Vector<float>>()) {
|
|
||||||
auto& vector = v.get<Vector<float>>();
|
|
||||||
data = vector.data();
|
|
||||||
count = vector.size();
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src_offset + src_length > count) {
|
if (src_offset + src_length > count) {
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data += src_offset;
|
span = span.slice(src_offset);
|
||||||
if (src_length == 0) {
|
if (src_length == 0) {
|
||||||
count -= src_offset;
|
count -= src_offset;
|
||||||
} else {
|
} else {
|
||||||
count = src_length;
|
count = src_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform3fv(location->handle(), count / 3, data);
|
glUniform3fv(location->handle(), count / 3, span.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List 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)
|
||||||
|
|
@ -1317,33 +1269,21 @@ void WebGL2RenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> locat
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float const* data = nullptr;
|
auto span = span_from_float32_list(v);
|
||||||
size_t count = 0;
|
auto count = span.size();
|
||||||
if (v.has<Vector<float>>()) {
|
|
||||||
auto& vector = v.get<Vector<float>>();
|
|
||||||
data = vector.data();
|
|
||||||
count = vector.size();
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src_offset + src_length > count) {
|
if (src_offset + src_length > count) {
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data += src_offset;
|
span = span.slice(src_offset);
|
||||||
if (src_length == 0) {
|
if (src_length == 0) {
|
||||||
count -= src_offset;
|
count -= src_offset;
|
||||||
} else {
|
} else {
|
||||||
count = src_length;
|
count = src_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform4fv(location->handle(), count / 4, data);
|
glUniform4fv(location->handle(), count / 4, span.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::uniform1iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
|
void WebGL2RenderingContextImpl::uniform1iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v, WebIDL::UnsignedLongLong src_offset, WebIDL::UnsignedLong src_length)
|
||||||
|
|
@ -1502,31 +1442,22 @@ void WebGL2RenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto matrix_size = 2 * 2;
|
auto matrix_size = 2 * 2;
|
||||||
float const* raw_data = nullptr;
|
auto span = span_from_float32_list(data);
|
||||||
u64 count = 0;
|
auto count = span.size() / matrix_size;
|
||||||
if (data.has<Vector<float>>()) {
|
|
||||||
auto& vector_data = data.get<Vector<float>>();
|
|
||||||
raw_data = vector_data.data();
|
|
||||||
count = vector_data.size() / matrix_size;
|
|
||||||
} else {
|
|
||||||
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)) {
|
if (src_offset + src_length > (count * matrix_size)) {
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_data += src_offset;
|
span = span.slice(src_offset);
|
||||||
if (src_length == 0) {
|
if (src_length == 0) {
|
||||||
count -= src_offset;
|
count -= src_offset;
|
||||||
} else {
|
} else {
|
||||||
count = src_length;
|
count = src_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniformMatrix2fv(location->handle(), count, transpose, raw_data);
|
glUniformMatrix2fv(location->handle(), count, transpose, span.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List 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)
|
||||||
|
|
@ -1537,31 +1468,22 @@ void WebGL2RenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto matrix_size = 3 * 3;
|
auto matrix_size = 3 * 3;
|
||||||
float const* raw_data = nullptr;
|
auto span = span_from_float32_list(data);
|
||||||
u64 count = 0;
|
auto count = span.size() / matrix_size;
|
||||||
if (data.has<Vector<float>>()) {
|
|
||||||
auto& vector_data = data.get<Vector<float>>();
|
|
||||||
raw_data = vector_data.data();
|
|
||||||
count = vector_data.size() / matrix_size;
|
|
||||||
} else {
|
|
||||||
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)) {
|
if (src_offset + src_length > (count * matrix_size)) {
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_data += src_offset;
|
span = span.slice(src_offset);
|
||||||
if (src_length == 0) {
|
if (src_length == 0) {
|
||||||
count -= src_offset;
|
count -= src_offset;
|
||||||
} else {
|
} else {
|
||||||
count = src_length;
|
count = src_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniformMatrix3fv(location->handle(), count, transpose, raw_data);
|
glUniformMatrix3fv(location->handle(), count, transpose, span.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List 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)
|
||||||
|
|
@ -1572,31 +1494,22 @@ void WebGL2RenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto matrix_size = 4 * 4;
|
auto matrix_size = 4 * 4;
|
||||||
float const* raw_data = nullptr;
|
auto span = span_from_float32_list(data);
|
||||||
u64 count = 0;
|
auto count = span.size() / matrix_size;
|
||||||
if (data.has<Vector<float>>()) {
|
|
||||||
auto& vector_data = data.get<Vector<float>>();
|
|
||||||
raw_data = vector_data.data();
|
|
||||||
count = vector_data.size() / matrix_size;
|
|
||||||
} else {
|
|
||||||
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)) {
|
if (src_offset + src_length > (count * matrix_size)) {
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_data += src_offset;
|
span = span.slice(src_offset);
|
||||||
if (src_length == 0) {
|
if (src_length == 0) {
|
||||||
count -= src_offset;
|
count -= src_offset;
|
||||||
} else {
|
} else {
|
||||||
count = src_length;
|
count = src_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniformMatrix4fv(location->handle(), count, transpose, raw_data);
|
glUniformMatrix4fv(location->handle(), count, transpose, span.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::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 WebGL2RenderingContextImpl::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)
|
||||||
|
|
@ -3431,100 +3344,48 @@ void WebGL2RenderingContextImpl::vertex_attrib1fv(WebIDL::UnsignedLong index, Fl
|
||||||
{
|
{
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
|
|
||||||
if (values.has<Vector<float>>()) {
|
auto span = span_from_float32_list(values);
|
||||||
auto& data = values.get<Vector<float>>();
|
if (span.size() < 1) {
|
||||||
if (data.size() < 1) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertexAttrib1fv(index, data.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
|
|
||||||
if (float32_array.byte_length().length() < 1 * sizeof(float)) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
glVertexAttrib1fv(index, span.data());
|
||||||
float const* data = float32_array.data().data();
|
|
||||||
glVertexAttrib1fv(index, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Float32List values)
|
void WebGL2RenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Float32List values)
|
||||||
{
|
{
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
|
|
||||||
if (values.has<Vector<float>>()) {
|
auto span = span_from_float32_list(values);
|
||||||
auto& data = values.get<Vector<float>>();
|
if (span.size() < 2) {
|
||||||
if (data.size() < 2) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertexAttrib2fv(index, data.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
|
|
||||||
if (float32_array.byte_length().length() < 2 * sizeof(float)) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
glVertexAttrib2fv(index, span.data());
|
||||||
float const* data = float32_array.data().data();
|
|
||||||
glVertexAttrib2fv(index, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Float32List values)
|
void WebGL2RenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Float32List values)
|
||||||
{
|
{
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
|
|
||||||
if (values.has<Vector<float>>()) {
|
auto span = span_from_float32_list(values);
|
||||||
auto& data = values.get<Vector<float>>();
|
if (span.size() < 3) {
|
||||||
if (data.size() < 3) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertexAttrib3fv(index, data.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
|
|
||||||
if (float32_array.byte_length().length() < 3 * sizeof(float)) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
glVertexAttrib3fv(index, span.data());
|
||||||
float const* data = float32_array.data().data();
|
|
||||||
glVertexAttrib3fv(index, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Float32List values)
|
void WebGL2RenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Float32List values)
|
||||||
{
|
{
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
|
|
||||||
if (values.has<Vector<float>>()) {
|
auto span = span_from_float32_list(values);
|
||||||
auto& data = values.get<Vector<float>>();
|
if (span.size() < 4) {
|
||||||
if (data.size() < 4) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertexAttrib4fv(index, data.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
|
|
||||||
if (float32_array.byte_length().length() < 4 * sizeof(float)) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
glVertexAttrib4fv(index, span.data());
|
||||||
float const* data = float32_array.data().data();
|
|
||||||
glVertexAttrib4fv(index, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGL2RenderingContextImpl::vertex_attrib_pointer(WebIDL::UnsignedLong index, WebIDL::Long size, WebIDL::UnsignedLong type, bool normalized, WebIDL::Long stride, WebIDL::LongLong offset)
|
void WebGL2RenderingContextImpl::vertex_attrib_pointer(WebIDL::UnsignedLong index, WebIDL::Long size, WebIDL::UnsignedLong type, bool normalized, WebIDL::Long stride, WebIDL::LongLong offset)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibJS/Runtime/TypedArray.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
#include <LibWeb/WebIDL/Types.h>
|
#include <LibWeb/WebIDL/Types.h>
|
||||||
|
|
||||||
|
|
@ -23,6 +24,13 @@ public:
|
||||||
virtual GC::Cell const* gc_cell() const = 0;
|
virtual GC::Cell const* gc_cell() const = 0;
|
||||||
virtual void visit_edges(JS::Cell::Visitor&) = 0;
|
virtual void visit_edges(JS::Cell::Visitor&) = 0;
|
||||||
virtual OpenGLContext& context() = 0;
|
virtual OpenGLContext& context() = 0;
|
||||||
|
|
||||||
|
static Span<float> span_from_float32_list(Float32List& float32_list)
|
||||||
|
{
|
||||||
|
if (float32_list.has<Vector<float>>())
|
||||||
|
return float32_list.get<Vector<float>>();
|
||||||
|
return float32_list.get<GC::Root<JS::Float32Array>>()->data();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -368,22 +368,8 @@ void WebGLRenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> locati
|
||||||
|
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
auto span = span_from_float32_list(v);
|
||||||
float const* data = nullptr;
|
glUniform1fv(location->handle(), span.size(), span.data());
|
||||||
size_t count = 0;
|
|
||||||
if (v.has<Vector<float>>()) {
|
|
||||||
auto& vector = v.get<Vector<float>>();
|
|
||||||
data = vector.data();
|
|
||||||
count = vector.size();
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
glUniform1fv(location->handle(), count / 1, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List v)
|
void WebGLRenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List v)
|
||||||
|
|
@ -392,22 +378,8 @@ void WebGLRenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> locati
|
||||||
|
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
auto span = span_from_float32_list(v);
|
||||||
float const* data = nullptr;
|
glUniform2fv(location->handle(), span.size() / 2, span.data());
|
||||||
size_t count = 0;
|
|
||||||
if (v.has<Vector<float>>()) {
|
|
||||||
auto& vector = v.get<Vector<float>>();
|
|
||||||
data = vector.data();
|
|
||||||
count = vector.size();
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
glUniform2fv(location->handle(), count / 2, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List v)
|
void WebGLRenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List v)
|
||||||
|
|
@ -416,22 +388,8 @@ void WebGLRenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> locati
|
||||||
|
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
auto span = span_from_float32_list(v);
|
||||||
float const* data = nullptr;
|
glUniform3fv(location->handle(), span.size() / 3, span.data());
|
||||||
size_t count = 0;
|
|
||||||
if (v.has<Vector<float>>()) {
|
|
||||||
auto& vector = v.get<Vector<float>>();
|
|
||||||
data = vector.data();
|
|
||||||
count = vector.size();
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
glUniform3fv(location->handle(), count / 3, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List v)
|
void WebGLRenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List v)
|
||||||
|
|
@ -440,22 +398,8 @@ void WebGLRenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> locati
|
||||||
|
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
auto span = span_from_float32_list(v);
|
||||||
float const* data = nullptr;
|
glUniform4fv(location->handle(), span.size() / 4, span.data());
|
||||||
size_t count = 0;
|
|
||||||
if (v.has<Vector<float>>()) {
|
|
||||||
auto& vector = v.get<Vector<float>>();
|
|
||||||
data = vector.data();
|
|
||||||
count = vector.size();
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
glUniform4fv(location->handle(), count / 4, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::uniform1iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v)
|
void WebGLRenderingContextImpl::uniform1iv(GC::Root<WebGLUniformLocation> location, Variant<GC::Root<WebIDL::BufferSource>, Vector<WebIDL::Long>> v)
|
||||||
|
|
@ -564,21 +508,9 @@ void WebGLRenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation>
|
||||||
|
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto matrix_size = 2 * 2;
|
auto matrix_size = 2 * 2;
|
||||||
float const* raw_data = nullptr;
|
auto span = span_from_float32_list(value);
|
||||||
u64 count = 0;
|
glUniformMatrix2fv(location->handle(), span.size() / matrix_size, transpose, span.data());
|
||||||
if (value.has<Vector<float>>()) {
|
|
||||||
auto& vector_data = value.get<Vector<float>>();
|
|
||||||
raw_data = vector_data.data();
|
|
||||||
count = vector_data.size() / matrix_size;
|
|
||||||
} else {
|
|
||||||
auto& float32_array = *value.get<GC::Root<JS::Float32Array>>();
|
|
||||||
raw_data = float32_array.data().data();
|
|
||||||
count = float32_array.array_length().length() / matrix_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
glUniformMatrix2fv(location->handle(), count, transpose, raw_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
|
void WebGLRenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
|
||||||
|
|
@ -587,21 +519,9 @@ void WebGLRenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation>
|
||||||
|
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto matrix_size = 3 * 3;
|
auto matrix_size = 3 * 3;
|
||||||
float const* raw_data = nullptr;
|
auto span = span_from_float32_list(value);
|
||||||
u64 count = 0;
|
glUniformMatrix3fv(location->handle(), span.size() / matrix_size, transpose, span.data());
|
||||||
if (value.has<Vector<float>>()) {
|
|
||||||
auto& vector_data = value.get<Vector<float>>();
|
|
||||||
raw_data = vector_data.data();
|
|
||||||
count = vector_data.size() / matrix_size;
|
|
||||||
} else {
|
|
||||||
auto& float32_array = *value.get<GC::Root<JS::Float32Array>>();
|
|
||||||
raw_data = float32_array.data().data();
|
|
||||||
count = float32_array.array_length().length() / matrix_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
glUniformMatrix3fv(location->handle(), count, transpose, raw_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
|
void WebGLRenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
|
||||||
|
|
@ -610,21 +530,9 @@ void WebGLRenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation>
|
||||||
|
|
||||||
if (!location)
|
if (!location)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto matrix_size = 4 * 4;
|
auto matrix_size = 4 * 4;
|
||||||
float const* raw_data = nullptr;
|
auto span = span_from_float32_list(value);
|
||||||
u64 count = 0;
|
glUniformMatrix4fv(location->handle(), span.size() / matrix_size, transpose, span.data());
|
||||||
if (value.has<Vector<float>>()) {
|
|
||||||
auto& vector_data = value.get<Vector<float>>();
|
|
||||||
raw_data = vector_data.data();
|
|
||||||
count = vector_data.size() / matrix_size;
|
|
||||||
} else {
|
|
||||||
auto& float32_array = *value.get<GC::Root<JS::Float32Array>>();
|
|
||||||
raw_data = float32_array.data().data();
|
|
||||||
count = float32_array.array_length().length() / matrix_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
glUniformMatrix4fv(location->handle(), count, transpose, raw_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::active_texture(WebIDL::UnsignedLong texture)
|
void WebGLRenderingContextImpl::active_texture(WebIDL::UnsignedLong texture)
|
||||||
|
|
@ -2272,100 +2180,48 @@ void WebGLRenderingContextImpl::vertex_attrib1fv(WebIDL::UnsignedLong index, Flo
|
||||||
{
|
{
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
|
|
||||||
if (values.has<Vector<float>>()) {
|
auto span = span_from_float32_list(values);
|
||||||
auto& data = values.get<Vector<float>>();
|
if (span.size() < 1) {
|
||||||
if (data.size() < 1) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertexAttrib1fv(index, data.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
|
|
||||||
if (float32_array.byte_length().length() < 1 * sizeof(float)) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
glVertexAttrib1fv(index, span.data());
|
||||||
float const* data = float32_array.data().data();
|
|
||||||
glVertexAttrib1fv(index, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Float32List values)
|
void WebGLRenderingContextImpl::vertex_attrib2fv(WebIDL::UnsignedLong index, Float32List values)
|
||||||
{
|
{
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
|
|
||||||
if (values.has<Vector<float>>()) {
|
auto span = span_from_float32_list(values);
|
||||||
auto& data = values.get<Vector<float>>();
|
if (span.size() < 2) {
|
||||||
if (data.size() < 2) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertexAttrib2fv(index, data.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
|
|
||||||
if (float32_array.byte_length().length() < 2 * sizeof(float)) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
glVertexAttrib2fv(index, span.data());
|
||||||
float const* data = float32_array.data().data();
|
|
||||||
glVertexAttrib2fv(index, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Float32List values)
|
void WebGLRenderingContextImpl::vertex_attrib3fv(WebIDL::UnsignedLong index, Float32List values)
|
||||||
{
|
{
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
|
|
||||||
if (values.has<Vector<float>>()) {
|
auto span = span_from_float32_list(values);
|
||||||
auto& data = values.get<Vector<float>>();
|
if (span.size() < 3) {
|
||||||
if (data.size() < 3) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertexAttrib3fv(index, data.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
|
|
||||||
if (float32_array.byte_length().length() < 3 * sizeof(float)) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
glVertexAttrib3fv(index, span.data());
|
||||||
float const* data = float32_array.data().data();
|
|
||||||
glVertexAttrib3fv(index, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Float32List values)
|
void WebGLRenderingContextImpl::vertex_attrib4fv(WebIDL::UnsignedLong index, Float32List values)
|
||||||
{
|
{
|
||||||
m_context->make_current();
|
m_context->make_current();
|
||||||
|
|
||||||
if (values.has<Vector<float>>()) {
|
auto span = span_from_float32_list(values);
|
||||||
auto& data = values.get<Vector<float>>();
|
if (span.size() < 4) {
|
||||||
if (data.size() < 4) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glVertexAttrib4fv(index, data.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& float32_array = *values.get<GC::Root<JS::Float32Array>>();
|
|
||||||
if (float32_array.byte_length().length() < 4 * sizeof(float)) {
|
|
||||||
set_error(GL_INVALID_VALUE);
|
set_error(GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
glVertexAttrib4fv(index, span.data());
|
||||||
float const* data = float32_array.data().data();
|
|
||||||
glVertexAttrib4fv(index, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextImpl::vertex_attrib_pointer(WebIDL::UnsignedLong index, WebIDL::Long size, WebIDL::UnsignedLong type, bool normalized, WebIDL::Long stride, WebIDL::LongLong offset)
|
void WebGLRenderingContextImpl::vertex_attrib_pointer(WebIDL::UnsignedLong index, WebIDL::Long size, WebIDL::UnsignedLong type, bool normalized, WebIDL::Long stride, WebIDL::LongLong offset)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||||
* Copyright (c) 2024-2025, Luke Wilde <luke@ladybird.org>
|
* Copyright (c) 2024-2025, Luke Wilde <luke@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue