From 49139d5f4ebc72faf416090fa4ee898b2a09878f Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Fri, 16 Sep 2022 18:50:07 +0200 Subject: [PATCH] LibSoftGPU: Allow binding a fragment shader --- Userland/Libraries/LibGPU/Device.h | 2 ++ Userland/Libraries/LibSoftGPU/Device.cpp | 13 +++++++++++++ Userland/Libraries/LibSoftGPU/Device.h | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/Userland/Libraries/LibGPU/Device.h b/Userland/Libraries/LibGPU/Device.h index d2a7a112d9..59d5ea993a 100644 --- a/Userland/Libraries/LibGPU/Device.h +++ b/Userland/Libraries/LibGPU/Device.h @@ -70,6 +70,8 @@ public: 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; + + virtual void bind_fragment_shader(RefPtr) = 0; }; } diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index 318617d7e6..87108c05a7 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -1700,6 +1700,19 @@ void Device::set_raster_position(FloatVector4 const& position, FloatMatrix4x4 co m_raster_position.eye_coordinate_distance = eye_coordinates.length(); } +void Device::bind_fragment_shader(RefPtr shader) +{ + VERIFY(shader.is_null() || shader->ownership_token() == this); + + if (shader.is_null()) { + m_current_fragment_shader = nullptr; + return; + } + + auto softgpu_shader = static_ptr_cast(shader); + m_current_fragment_shader = softgpu_shader; +} + Gfx::IntRect Device::get_rasterization_rect_of_size(Gfx::IntSize size) const { // Round the X and Y floating point coordinates to the nearest integer; OpenGL 1.5 spec: diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h index 027a81d081..a7660b0154 100644 --- a/Userland/Libraries/LibSoftGPU/Device.h +++ b/Userland/Libraries/LibSoftGPU/Device.h @@ -35,6 +35,7 @@ #include #include #include +#include #include namespace SoftGPU { @@ -78,6 +79,8 @@ public: 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; + virtual void bind_fragment_shader(RefPtr) override; + private: void calculate_vertex_lighting(GPU::Vertex& vertex) const; void draw_statistics_overlay(Gfx::Bitmap&); @@ -116,6 +119,7 @@ private: Vector m_clip_planes; Array m_stencil_configuration; Array m_texture_unit_configuration; + RefPtr m_current_fragment_shader; }; }