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

LibGL+LibGPU+LibSoftGPU: Implement flexible pixel format conversion

A GPU (driver) is now responsible for reading and writing pixels from
and to user data. The client (LibGL) is responsible for specifying how
the user data must be interpreted or written to.

This allows us to centralize all pixel format conversion in one class,
`LibSoftGPU::PixelConverter`. For both the input and output image, it
takes a specification containing the image dimensions, the pixel type
and the selection (basically a clipping rect), and converts the pixels
from the input image to the output image.

Effectively this means we now support almost all OpenGL 1.5 formats,
and all custom logic has disappeared from:
  - `glDrawPixels`
  - `glReadPixels`
  - `glTexImage2D`
  - `glTexSubImage2D`

The new logic is still unoptimized, but on my machine I experienced no
noticeable slowdown. :^)
This commit is contained in:
Jelle Raaijmakers 2022-08-24 23:47:49 +02:00 committed by Andreas Kling
parent d7cfdfe633
commit eb7c3d16fb
24 changed files with 1350 additions and 705 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org>
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -15,7 +16,7 @@
#include <LibGPU/DeviceInfo.h>
#include <LibGPU/Enums.h>
#include <LibGPU/Image.h>
#include <LibGPU/ImageFormat.h>
#include <LibGPU/ImageDataLayout.h>
#include <LibGPU/Light.h>
#include <LibGPU/LightModelParameters.h>
#include <LibGPU/Material.h>
@ -30,13 +31,14 @@
#include <LibGfx/Matrix4x4.h>
#include <LibGfx/Rect.h>
#include <LibGfx/Size.h>
#include <LibGfx/Vector2.h>
#include <LibGfx/Vector4.h>
namespace GPU {
class Device {
public:
virtual ~Device() { }
virtual ~Device() = default;
virtual DeviceInfo info() const = 0;
@ -46,16 +48,16 @@ public:
virtual void clear_depth(DepthType) = 0;
virtual void clear_stencil(StencilType) = 0;
virtual void blit_color_buffer_to(Gfx::Bitmap& target) = 0;
virtual void blit_to_color_buffer_at_raster_position(Gfx::Bitmap const&) = 0;
virtual void blit_to_depth_buffer_at_raster_position(Vector<DepthType> const&, int, int) = 0;
virtual void blit_from_color_buffer(void*, Vector2<i32> offset, GPU::ImageDataLayout const&) = 0;
virtual void blit_from_depth_buffer(void*, Vector2<i32> offset, GPU::ImageDataLayout const&) = 0;
virtual void blit_to_color_buffer_at_raster_position(void const*, GPU::ImageDataLayout const&) = 0;
virtual void blit_to_depth_buffer_at_raster_position(void const*, GPU::ImageDataLayout const&) = 0;
virtual void set_options(RasterizerOptions const&) = 0;
virtual void set_light_model_params(LightModelParameters const&) = 0;
virtual RasterizerOptions options() const = 0;
virtual LightModelParameters light_model() const = 0;
virtual ColorType get_color_buffer_pixel(int x, int y) = 0;
virtual DepthType get_depthbuffer_value(int x, int y) = 0;
virtual NonnullRefPtr<Image> create_image(ImageFormat format, unsigned width, unsigned height, unsigned depth, unsigned levels, unsigned layers) = 0;
virtual NonnullRefPtr<Image> create_image(PixelType const&, u32 width, u32 height, u32 depth, u32 levels, u32 layers) = 0;
virtual void set_sampler_config(unsigned, SamplerConfig const&) = 0;
virtual void set_light_state(unsigned, Light const&) = 0;