CodeGenerators: Unify generation of uniform{1,2,3,4}{i,f}v [WebGL]

This commit is contained in:
Aliaksandr Kalenik 2024-12-10 07:44:27 +01:00 committed by Alexander Kalenik
parent 544a0216cf
commit 194edbfd89
Notes: github-actions[bot] 2024-12-13 08:20:21 +00:00

View file

@ -697,40 +697,33 @@ public:
continue;
}
if (function.name == "uniform1fv"sv || function.name == "uniform2fv"sv || function.name == "uniform3fv"sv || function.name == "uniform4fv"sv) {
if (function.name == "uniform1fv"sv || function.name == "uniform2fv"sv || function.name == "uniform3fv"sv || function.name == "uniform4fv"sv || function.name == "uniform1iv"sv || function.name == "uniform2iv"sv || function.name == "uniform3iv"sv || function.name == "uniform4iv"sv) {
auto number_of_vector_elements = function.name.substring_view(7, 1);
auto element_type = function.name.substring_view(8, 1);
if (element_type == "f"sv) {
function_impl_generator.set("cpp_element_type", "float"sv);
function_impl_generator.set("typed_array_type", "Float32Array"sv);
function_impl_generator.set("gl_postfix", "f"sv);
} else if (element_type == "i"sv) {
function_impl_generator.set("cpp_element_type", "int"sv);
function_impl_generator.set("typed_array_type", "Int32Array"sv);
function_impl_generator.set("gl_postfix", "i"sv);
} else {
VERIFY_NOT_REACHED();
}
function_impl_generator.set("number_of_vector_elements", number_of_vector_elements);
function_impl_generator.append(R"~~~(
if (v.has<Vector<float>>()) {
auto& data = v.get<Vector<float>>();
glUniform@number_of_vector_elements@fv(location->handle(), data.size() / @number_of_vector_elements@, data.data());
if (v.has<Vector<@cpp_element_type@>>()) {
auto& data = v.get<Vector<@cpp_element_type@>>();
glUniform@number_of_vector_elements@@gl_postfix@v(location->handle(), data.size() / @number_of_vector_elements@, data.data());
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& float32_array = verify_cast<JS::Float32Array>(typed_array_base);
float const* data = float32_array.data().data();
auto count = float32_array.array_length().length() / @number_of_vector_elements@;
glUniform@number_of_vector_elements@fv(location->handle(), count, data);
)~~~");
continue;
}
if (function.name == "uniform1iv"sv || function.name == "uniform2iv"sv || function.name == "uniform3iv"sv || function.name == "uniform4iv"sv) {
auto number_of_vector_elements = function.name.substring_view(7, 1);
function_impl_generator.set("number_of_vector_elements", number_of_vector_elements);
function_impl_generator.append(R"~~~(
if (v.has<Vector<int>>()) {
auto& data = v.get<Vector<int>>();
glUniform@number_of_vector_elements@iv(location->handle(), data.size() / @number_of_vector_elements@, data.data());
return;
}
auto& typed_array_base = static_cast<JS::TypedArrayBase&>(*v.get<GC::Root<WebIDL::BufferSource>>()->raw_object());
auto& int32_array = verify_cast<JS::Int32Array>(typed_array_base);
int const* data = int32_array.data().data();
auto count = int32_array.array_length().length() / @number_of_vector_elements@;
glUniform@number_of_vector_elements@iv(location->handle(), count, data);
auto& typed_array = verify_cast<JS::@typed_array_type@>(typed_array_base);
@cpp_element_type@ const* data = typed_array.data().data();
auto count = typed_array.array_length().length() / @number_of_vector_elements@;
glUniform@number_of_vector_elements@@gl_postfix@v(location->handle(), count, data);
)~~~");
continue;
}