1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

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 :^)
This commit is contained in:
Jelle Raaijmakers 2022-09-05 00:40:27 +02:00 committed by Linus Groh
parent 1540c56e6c
commit 00d46e5d77
22 changed files with 208 additions and 152 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -120,7 +120,7 @@ enum StencilTestFunction {
NotEqual,
};
enum TexCoordGenerationCoordinate {
enum TexCoordGenerationCoordinate : u8 {
None = 0x0,
S = 0x1,
T = 0x2,

View file

@ -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 };

View file

@ -6,7 +6,6 @@
#pragma once
#include <LibGPU/Config.h>
#include <LibGPU/Enums.h>
namespace GPU {

View file

@ -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 {};
};
}

View file

@ -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];
};
}

View file

@ -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;
};