1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 18:25:08 +00:00
serenity/Userland/Libraries/LibGPU/Device.h
Jelle Raaijmakers a20bf80b05 LibGL+LibGPU+LibSoftGPU: Implement point and line drawing
Implement (anti)aliased point drawing and anti-aliased line drawing.
Supported through LibGL's `GL_POINTS`, `GL_LINES`, `GL_LINE_LOOP` and
`GL_LINE_STRIP`.

In order to support this, `LibSoftGPU`s rasterization logic was
reworked. Now, any primitive can be drawn by invoking `rasterize()`
which takes care of the quad loop and fragment testing logic. Three
callbacks need to be passed:

* `set_coverage_mask`: the primitive needs to provide initial coverage
   mask information so fragments can be discarded early.
* `set_quad_depth`: fragments survived stencil testing, so depth values
  need to be set so depth testing can take place.
* `set_quad_attributes`: fragments survived depth testing, so fragment
  shading is going to take place. All attributes like color, tex coords
  and fog depth need to be set so alpha testing and eventually,
  fragment rasterization can take place.

As of this commit, there are four instantiations of this function:

* Triangle rasterization
* Points - aliased
* Points - anti-aliased
* Lines - anti-aliased

In order to standardize vertex processing for all primitive types,
things like vertex transformation, lighting and tex coord generation
are now taking place before clipping.
2022-05-09 21:49:48 +02:00

74 lines
2.9 KiB
C++

/*
* Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Array.h>
#include <AK/Error.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/Vector.h>
#include <LibGPU/DeviceInfo.h>
#include <LibGPU/Enums.h>
#include <LibGPU/Image.h>
#include <LibGPU/ImageFormat.h>
#include <LibGPU/Light.h>
#include <LibGPU/LightModelParameters.h>
#include <LibGPU/Material.h>
#include <LibGPU/RasterPosition.h>
#include <LibGPU/RasterizerOptions.h>
#include <LibGPU/SamplerConfig.h>
#include <LibGPU/StencilConfiguration.h>
#include <LibGPU/TexCoordGenerationConfig.h>
#include <LibGPU/Vertex.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Matrix3x3.h>
#include <LibGfx/Matrix4x4.h>
#include <LibGfx/Rect.h>
#include <LibGfx/Size.h>
#include <LibGfx/Vector4.h>
namespace GPU {
class Device {
public:
virtual ~Device() { }
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 resize(Gfx::IntSize const& min_size) = 0;
virtual void clear_color(FloatVector4 const&) = 0;
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 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 void set_sampler_config(unsigned, SamplerConfig const&) = 0;
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 RasterPosition raster_position() const = 0;
virtual void set_raster_position(RasterPosition const& raster_position) = 0;
virtual void set_raster_position(FloatVector4 const& position, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform) = 0;
};
}
typedef GPU::Device* (*serenity_gpu_create_device_t)(Gfx::IntSize const& size);
extern "C" GPU::Device* serenity_gpu_create_device(Gfx::IntSize const& size);