From db0616c67a1a046b460e73b8e3b6861d982c5f46 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sun, 23 Jan 2022 22:15:28 +0100 Subject: LibSoftGPU: Generalize pixel buffers and standardize on BGRA8888 Between the OpenGL client and server, a lot of data type and color conversion needs to happen. We are performing these conversions both in `LibSoftGPU` and `LibGL`, which is not ideal. Additionally, some concepts like the color, depth and stencil buffers should share their logic but have separate implementations. This is the first step towards generalizing our `LibSoftGPU` frame buffer: a generalized `Typed3DBuffer` is introduced for arbitrary 3D value storage and retrieval, and `Typed2DBuffer` wraps around it to provide in an easy-to-use 2D pixel buffer. The color, depth and stencil buffers are replaced by `Typed2DBuffer` and are now managed by the new `FrameBuffer` class. The `Image` class now uses multiple `Typed3DBuffer`s for layers and mipmap levels. Additionally, the textures are now always stored as BGRA8888, only converting between formats when reading or writing pixels. Ideally this refactor should have no functional changes, but some graphical glitches in Grim Fandango seem to be fixed and most OpenGL ports get an FPS boost on my machine. :^) --- Userland/Libraries/LibSoftGPU/Device.h | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'Userland/Libraries/LibSoftGPU/Device.h') diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h index 6a4b2f6ebb..f2e74b510c 100644 --- a/Userland/Libraries/LibSoftGPU/Device.h +++ b/Userland/Libraries/LibSoftGPU/Device.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -17,9 +17,10 @@ #include #include #include +#include +#include #include #include -#include #include #include #include @@ -27,7 +28,6 @@ #include #include #include -#include #include #include @@ -100,13 +100,13 @@ struct RasterPosition { struct StencilConfiguration { StencilTestFunction test_function; - u8 reference_value; - u8 test_mask; + StencilType reference_value; + StencilType test_mask; StencilOperation on_stencil_test_fail; StencilOperation on_depth_test_fail; StencilOperation on_pass; - u8 write_mask; + StencilType write_mask; }; class Device final { @@ -116,21 +116,21 @@ public: DeviceInfo info() const; void draw_primitives(PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix3x3 const& normal_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector const& vertices, Vector const& enabled_texture_units); - void resize(const Gfx::IntSize& min_size); - void clear_color(const FloatVector4&); - void clear_depth(float); - void clear_stencil(u8); - void blit_to(Gfx::Bitmap&); + void resize(Gfx::IntSize const& min_size); + void clear_color(FloatVector4 const&); + void clear_depth(DepthType); + void clear_stencil(StencilType); + void blit_color_buffer_to(Gfx::Bitmap& target); void blit_to_color_buffer_at_raster_position(Gfx::Bitmap const&); - void blit_to_depth_buffer_at_raster_position(Vector const&, size_t, size_t); + void blit_to_depth_buffer_at_raster_position(Vector const&, int, int); void set_options(const RasterizerOptions&); void set_light_model_params(const LightModelParameters&); RasterizerOptions options() const { return m_options; } LightModelParameters light_model() const { return m_lighting_model; } - Gfx::RGBA32 get_backbuffer_pixel(int x, int y); - float get_depthbuffer_value(int x, int y); + ColorType get_color_buffer_pixel(int x, int y); + DepthType get_depthbuffer_value(int x, int y); - NonnullRefPtr create_image(ImageFormat, unsigned width, unsigned height, unsigned depth, unsigned levels, unsigned layers); + NonnullRefPtr create_image(ImageFormat format, unsigned width, unsigned height, unsigned depth, unsigned levels, unsigned layers); void set_sampler_config(unsigned, SamplerConfig const&); void set_light_state(unsigned, Light const&); @@ -151,9 +151,7 @@ private: void shade_fragments(PixelQuad&); bool test_alpha(PixelQuad&); - RefPtr m_render_target; - NonnullOwnPtr m_depth_buffer; - NonnullOwnPtr m_stencil_buffer; + RefPtr> m_frame_buffer {}; RasterizerOptions m_options; LightModelParameters m_lighting_model; Clipper m_clipper; -- cgit v1.2.3