/* * 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: Device(Gfx::IntSize const& min_size); GPU::DeviceInfo info() const; void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector const& vertices, Vector const& enabled_texture_units); void resize(Gfx::IntSize const& min_size); void clear_color(FloatVector4 const&); void clear_depth(GPU::DepthType); void clear_stencil(GPU::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&, int, int); void set_options(GPU::RasterizerOptions const&); void set_light_model_params(GPU::LightModelParameters const&); GPU::RasterizerOptions options() const { return m_options; } GPU::LightModelParameters light_model() const { return m_lighting_model; } GPU::ColorType get_color_buffer_pixel(int x, int y); GPU::DepthType get_depthbuffer_value(int x, int y); NonnullRefPtr create_image(GPU::ImageFormat format, unsigned width, unsigned height, unsigned depth, unsigned levels, unsigned layers); void set_sampler_config(unsigned, GPU::SamplerConfig const&); void set_light_state(unsigned, GPU::Light const&); void set_material_state(GPU::Face, GPU::Material const&); void set_stencil_configuration(GPU::Face, GPU::StencilConfiguration const&); GPU::RasterPosition raster_position() const { return m_raster_position; } void set_raster_position(GPU::RasterPosition const& raster_position); void set_raster_position(FloatVector4 const& position, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform); private: void draw_statistics_overlay(Gfx::Bitmap&); Gfx::IntRect get_rasterization_rect_of_size(Gfx::IntSize size); void rasterize_triangle(Triangle const& triangle); void setup_blend_factors(); void shade_fragments(PixelQuad&); bool 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; Array m_stencil_configuration; }; }