/* * Copyright (c) 2021, Stephan Unverwerth * Copyright (c) 2022, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace SoftGPU { struct PixelQuad; class Device final : public GPU::Device { public: Device(Gfx::IntSize const& min_size); virtual GPU::DeviceInfo info() const override; virtual void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector& vertices, Vector const& enabled_texture_units) override; virtual void resize(Gfx::IntSize const& min_size) override; virtual void clear_color(FloatVector4 const&) override; virtual void clear_depth(GPU::DepthType) override; virtual void clear_stencil(GPU::StencilType) override; virtual void blit_color_buffer_to(Gfx::Bitmap& target) override; virtual void blit_to_color_buffer_at_raster_position(Gfx::Bitmap const&) override; virtual void blit_to_depth_buffer_at_raster_position(Vector const&, int, int) override; virtual void set_options(GPU::RasterizerOptions const&) override; virtual void set_light_model_params(GPU::LightModelParameters const&) override; virtual GPU::RasterizerOptions options() const override { return m_options; } virtual GPU::LightModelParameters light_model() const override { return m_lighting_model; } virtual GPU::ColorType get_color_buffer_pixel(int x, int y) override; virtual GPU::DepthType get_depthbuffer_value(int x, int y) override; virtual NonnullRefPtr create_image(GPU::ImageFormat format, unsigned width, unsigned height, unsigned depth, unsigned levels, unsigned layers) override; virtual void set_sampler_config(unsigned, GPU::SamplerConfig const&) override; virtual void set_light_state(unsigned, GPU::Light const&) override; virtual void set_material_state(GPU::Face, GPU::Material const&) override; virtual void set_stencil_configuration(GPU::Face, GPU::StencilConfiguration const&) override; virtual void set_clip_planes(Vector const&) override; virtual GPU::RasterPosition raster_position() const override { return m_raster_position; } virtual void set_raster_position(GPU::RasterPosition const& raster_position) override; virtual void set_raster_position(FloatVector4 const& position, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform) override; private: void calculate_vertex_lighting(GPU::Vertex& vertex) const; void draw_statistics_overlay(Gfx::Bitmap&); Gfx::IntRect get_rasterization_rect_of_size(Gfx::IntSize size) const; template void rasterize(Gfx::IntRect& render_bounds, CB1 set_coverage_mask, CB2 set_quad_depth, CB3 set_quad_attributes); void rasterize_line_aliased(GPU::Vertex&, GPU::Vertex&); void rasterize_line_antialiased(GPU::Vertex&, GPU::Vertex&); void rasterize_line(GPU::Vertex&, GPU::Vertex&); void rasterize_point_aliased(GPU::Vertex&); void rasterize_point_antialiased(GPU::Vertex&); void rasterize_point(GPU::Vertex&); void rasterize_triangle(Triangle&); void setup_blend_factors(); void shade_fragments(PixelQuad&); void test_alpha(PixelQuad&); RefPtr> m_frame_buffer {}; GPU::RasterizerOptions m_options; GPU::LightModelParameters m_lighting_model; Clipper m_clipper; Vector m_triangle_list; Vector m_processed_triangles; Vector m_clipped_vertices; Array m_samplers; Vector m_enabled_texture_units; AlphaBlendFactors m_alpha_blend_factors; Array m_lights; Array m_materials; GPU::RasterPosition m_raster_position; Vector m_clip_planes; Array m_stencil_configuration; }; }