summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSoftGPU/Device.cpp
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@serenityos.org>2022-01-15 21:08:57 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-19 19:57:49 +0100
commit12f63df329148148f32dc50c4f6cadf6af73a6ac (patch)
tree78b29917f19329ef60c7a41dd1c524340753ca0b /Userland/Libraries/LibSoftGPU/Device.cpp
parentbc17a87450e3c282f026184ef90c61caec78dfb3 (diff)
downloadserenity-12f63df329148148f32dc50c4f6cadf6af73a6ac.zip
LibGL+LibSoftGPU: Support generation of multiple texture coordinates
Diffstat (limited to 'Userland/Libraries/LibSoftGPU/Device.cpp')
-rw-r--r--Userland/Libraries/LibSoftGPU/Device.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp
index 944cbfd226..1268342006 100644
--- a/Userland/Libraries/LibSoftGPU/Device.cpp
+++ b/Userland/Libraries/LibSoftGPU/Device.cpp
@@ -612,16 +612,16 @@ DeviceInfo Device::info() const
static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const& options)
{
- auto generate_coordinate = [&](size_t config_index) -> float {
- auto mode = options.texcoord_generation_config[config_index].mode;
+ auto generate_coordinate = [&](size_t texcoord_index, size_t config_index) -> float {
+ auto mode = options.texcoord_generation_config[texcoord_index][config_index].mode;
switch (mode) {
case TexCoordGenerationMode::ObjectLinear: {
- auto coefficients = options.texcoord_generation_config[config_index].coefficients;
+ auto coefficients = options.texcoord_generation_config[texcoord_index][config_index].coefficients;
return coefficients.dot(vertex.position);
}
case TexCoordGenerationMode::EyeLinear: {
- auto coefficients = options.texcoord_generation_config[config_index].coefficients;
+ auto coefficients = options.texcoord_generation_config[texcoord_index][config_index].coefficients;
return coefficients.dot(vertex.eye_coordinates);
}
case TexCoordGenerationMode::SphereMap: {
@@ -667,13 +667,16 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
}
};
- auto const enabled_coords = options.texcoord_generation_enabled_coordinates;
- vertex.tex_coords[0] = {
- ((enabled_coords & TexCoordGenerationCoordinate::S) > 0) ? generate_coordinate(0) : vertex.tex_coords[0].x(),
- ((enabled_coords & TexCoordGenerationCoordinate::T) > 0) ? generate_coordinate(1) : vertex.tex_coords[0].y(),
- ((enabled_coords & TexCoordGenerationCoordinate::R) > 0) ? generate_coordinate(2) : vertex.tex_coords[0].z(),
- ((enabled_coords & TexCoordGenerationCoordinate::Q) > 0) ? generate_coordinate(3) : vertex.tex_coords[0].w(),
- };
+ for (size_t i = 0; i < vertex.tex_coords.size(); ++i) {
+ auto& tex_coord = vertex.tex_coords[i];
+ auto const enabled_coords = options.texcoord_generation_enabled_coordinates[i];
+ tex_coord = {
+ ((enabled_coords & TexCoordGenerationCoordinate::S) > 0) ? generate_coordinate(i, 0) : tex_coord.x(),
+ ((enabled_coords & TexCoordGenerationCoordinate::T) > 0) ? generate_coordinate(i, 1) : tex_coord.y(),
+ ((enabled_coords & TexCoordGenerationCoordinate::R) > 0) ? generate_coordinate(i, 2) : tex_coord.z(),
+ ((enabled_coords & TexCoordGenerationCoordinate::Q) > 0) ? generate_coordinate(i, 3) : tex_coord.w(),
+ };
+ }
}
void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& model_view_transform, FloatMatrix3x3 const& normal_transform,
@@ -952,6 +955,15 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
}
}
+ // Generate texture coordinates if at least one coordinate is enabled
+ bool texture_coordinate_generation_enabled = false;
+ for (auto const coordinates_enabled : m_options.texcoord_generation_enabled_coordinates) {
+ if (coordinates_enabled != TexCoordGenerationCoordinate::None) {
+ texture_coordinate_generation_enabled = true;
+ break;
+ }
+ }
+
for (auto& triangle : m_processed_triangles) {
// Let's calculate the (signed) area of the triangle
// https://cp-algorithms.com/geometry/oriented-triangle-area.html
@@ -987,8 +999,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
triangle.vertices[2].normal.normalize();
}
- // Generate texture coordinates if at least one coordinate is enabled
- if (m_options.texcoord_generation_enabled_coordinates != TexCoordGenerationCoordinate::None) {
+ if (texture_coordinate_generation_enabled) {
generate_texture_coordinates(triangle.vertices[0], m_options);
generate_texture_coordinates(triangle.vertices[1], m_options);
generate_texture_coordinates(triangle.vertices[2], m_options);