summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGPU
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2022-09-05 00:40:27 +0200
committerLinus Groh <mail@linusgroh.de>2022-09-11 22:37:07 +0100
commit00d46e5d77d7188d835627cd4c3d76152e4f7b3e (patch)
tree8402803e233cf896a714aa8fd1045d6256ba2cec /Userland/Libraries/LibGPU
parent1540c56e6c82bfbdb1fd9b29c34c7ac1a399a1d3 (diff)
downloadserenity-00d46e5d77d7188d835627cd4c3d76152e4f7b3e.zip
LibGL+LibGPU+LibSoftGPU: Implement matrix stack per texture unit
Each texture unit now has its own texture transformation matrix stack. Introduce a new texture unit configuration that is synced when changed. Because we're no longer passing a silly `Vector` when drawing each primitive, this results in a slightly improved frames per second :^)
Diffstat (limited to 'Userland/Libraries/LibGPU')
-rw-r--r--Userland/Libraries/LibGPU/Config.h2
-rw-r--r--Userland/Libraries/LibGPU/Device.h5
-rw-r--r--Userland/Libraries/LibGPU/Enums.h2
-rw-r--r--Userland/Libraries/LibGPU/RasterizerOptions.h3
-rw-r--r--Userland/Libraries/LibGPU/StencilConfiguration.h1
-rw-r--r--Userland/Libraries/LibGPU/TexCoordGenerationConfig.h19
-rw-r--r--Userland/Libraries/LibGPU/TextureUnitConfiguration.h30
-rw-r--r--Userland/Libraries/LibGPU/Vertex.h2
8 files changed, 36 insertions, 28 deletions
diff --git a/Userland/Libraries/LibGPU/Config.h b/Userland/Libraries/LibGPU/Config.h
index 4a61826025..f3ab5e5c3f 100644
--- a/Userland/Libraries/LibGPU/Config.h
+++ b/Userland/Libraries/LibGPU/Config.h
@@ -18,6 +18,6 @@ using StencilType = u8;
// FIXME: This constant was originally introduced in LibSoftGPU and is currently used in the Vertex struct.
// Once we refactor the interface this should move back into LibSoftGPU.
-static constexpr int NUM_SAMPLERS = 2;
+static constexpr int NUM_TEXTURE_UNITS = 2;
}
diff --git a/Userland/Libraries/LibGPU/Device.h b/Userland/Libraries/LibGPU/Device.h
index 279a1355ce..270d44dfc0 100644
--- a/Userland/Libraries/LibGPU/Device.h
+++ b/Userland/Libraries/LibGPU/Device.h
@@ -21,7 +21,7 @@
#include <LibGPU/RasterizerOptions.h>
#include <LibGPU/SamplerConfig.h>
#include <LibGPU/StencilConfiguration.h>
-#include <LibGPU/TexCoordGenerationConfig.h>
+#include <LibGPU/TextureUnitConfiguration.h>
#include <LibGPU/Vertex.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Matrix3x3.h>
@@ -38,7 +38,7 @@ public:
virtual DeviceInfo info() const = 0;
- virtual void draw_primitives(PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector<Vertex>& vertices, Vector<size_t> const& enabled_texture_units) = 0;
+ virtual void draw_primitives(PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, Vector<Vertex>& vertices) = 0;
virtual void resize(Gfx::IntSize const& min_size) = 0;
virtual void clear_color(FloatVector4 const&) = 0;
virtual void clear_depth(DepthType) = 0;
@@ -61,6 +61,7 @@ public:
virtual void set_light_state(unsigned, Light const&) = 0;
virtual void set_material_state(Face, Material const&) = 0;
virtual void set_stencil_configuration(Face, StencilConfiguration const&) = 0;
+ virtual void set_texture_unit_configuration(TextureUnitIndex, TextureUnitConfiguration const&) = 0;
virtual void set_clip_planes(Vector<FloatVector4> const&) = 0;
virtual RasterPosition raster_position() const = 0;
diff --git a/Userland/Libraries/LibGPU/Enums.h b/Userland/Libraries/LibGPU/Enums.h
index 3486fd03d4..5cf8922761 100644
--- a/Userland/Libraries/LibGPU/Enums.h
+++ b/Userland/Libraries/LibGPU/Enums.h
@@ -120,7 +120,7 @@ enum StencilTestFunction {
NotEqual,
};
-enum TexCoordGenerationCoordinate {
+enum TexCoordGenerationCoordinate : u8 {
None = 0x0,
S = 0x1,
T = 0x2,
diff --git a/Userland/Libraries/LibGPU/RasterizerOptions.h b/Userland/Libraries/LibGPU/RasterizerOptions.h
index a5ae66c6c1..82130292c4 100644
--- a/Userland/Libraries/LibGPU/RasterizerOptions.h
+++ b/Userland/Libraries/LibGPU/RasterizerOptions.h
@@ -10,7 +10,6 @@
#include <AK/Array.h>
#include <LibGPU/Config.h>
#include <LibGPU/Enums.h>
-#include <LibGPU/TexCoordGenerationConfig.h>
#include <LibGfx/Rect.h>
#include <LibGfx/Vector4.h>
@@ -53,8 +52,6 @@ struct RasterizerOptions {
WindingOrder front_face { WindingOrder::CounterClockwise };
bool cull_back { true };
bool cull_front { false };
- Array<u8, NUM_SAMPLERS> texcoord_generation_enabled_coordinates {};
- Array<Array<TexCoordGenerationConfig, 4>, NUM_SAMPLERS> texcoord_generation_config {};
Gfx::IntRect viewport;
bool lighting_enabled { false };
bool color_material_enabled { false };
diff --git a/Userland/Libraries/LibGPU/StencilConfiguration.h b/Userland/Libraries/LibGPU/StencilConfiguration.h
index b68b2d6ba1..1c0d9503f0 100644
--- a/Userland/Libraries/LibGPU/StencilConfiguration.h
+++ b/Userland/Libraries/LibGPU/StencilConfiguration.h
@@ -6,7 +6,6 @@
#pragma once
-#include <LibGPU/Config.h>
#include <LibGPU/Enums.h>
namespace GPU {
diff --git a/Userland/Libraries/LibGPU/TexCoordGenerationConfig.h b/Userland/Libraries/LibGPU/TexCoordGenerationConfig.h
deleted file mode 100644
index dbd8db63e6..0000000000
--- a/Userland/Libraries/LibGPU/TexCoordGenerationConfig.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibGPU/Enums.h>
-#include <LibGfx/Vector4.h>
-
-namespace GPU {
-
-struct TexCoordGenerationConfig {
- GPU::TexCoordGenerationMode mode { GPU::TexCoordGenerationMode::EyeLinear };
- FloatVector4 coefficients {};
-};
-
-}
diff --git a/Userland/Libraries/LibGPU/TextureUnitConfiguration.h b/Userland/Libraries/LibGPU/TextureUnitConfiguration.h
new file mode 100644
index 0000000000..686dba5e5d
--- /dev/null
+++ b/Userland/Libraries/LibGPU/TextureUnitConfiguration.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibGPU/Enums.h>
+#include <LibGfx/Matrix4x4.h>
+#include <LibGfx/Vector4.h>
+
+namespace GPU {
+
+typedef u8 TextureUnitIndex;
+
+struct TexCoordGeneration {
+ bool enabled;
+ TexCoordGenerationMode mode;
+ FloatVector4 coefficients;
+};
+
+struct TextureUnitConfiguration {
+ bool enabled { false };
+ FloatMatrix4x4 transformation_matrix { FloatMatrix4x4::identity() };
+ u8 tex_coord_generation_enabled;
+ TexCoordGeneration tex_coord_generation[4];
+};
+
+}
diff --git a/Userland/Libraries/LibGPU/Vertex.h b/Userland/Libraries/LibGPU/Vertex.h
index 5307dd083c..e11e1eebc6 100644
--- a/Userland/Libraries/LibGPU/Vertex.h
+++ b/Userland/Libraries/LibGPU/Vertex.h
@@ -20,7 +20,7 @@ struct Vertex {
FloatVector4 clip_coordinates;
FloatVector4 window_coordinates;
FloatVector4 color;
- Array<FloatVector4, GPU::NUM_SAMPLERS> tex_coords;
+ Array<FloatVector4, GPU::NUM_TEXTURE_UNITS> tex_coords;
FloatVector3 normal;
};