Browse Source

LibGPU+LibSoftGPU: Move RasterizerOptions into LibGPU

Stephan Unverwerth 3 years ago
parent
commit
1f3642ed48

+ 61 - 0
Userland/Libraries/LibGPU/RasterizerOptions.h

@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
+ * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Array.h>
+#include <LibGPU/Config.h>
+#include <LibGPU/Enums.h>
+#include <LibGPU/TexCoordGenerationConfig.h>
+#include <LibGfx/Rect.h>
+#include <LibGfx/Vector4.h>
+
+namespace GPU {
+
+struct RasterizerOptions {
+    bool shade_smooth { true };
+    bool enable_stencil_test { false };
+    bool enable_depth_test { false };
+    bool enable_depth_write { true };
+    bool enable_alpha_test { false };
+    AlphaTestFunction alpha_test_func { AlphaTestFunction::Always };
+    float alpha_test_ref_value { 0 };
+    bool enable_blending { false };
+    BlendFactor blend_source_factor { BlendFactor::One };
+    BlendFactor blend_destination_factor { BlendFactor::One };
+    u32 color_mask { 0xffffffff };
+    float depth_min { 0.f };
+    float depth_max { 1.f };
+    DepthTestFunction depth_func { DepthTestFunction::Less };
+    PolygonMode polygon_mode { PolygonMode::Fill };
+    FloatVector4 fog_color { 0.0f, 0.0f, 0.0f, 0.0f };
+    float fog_density { 1.0f };
+    FogMode fog_mode { FogMode::Exp };
+    bool fog_enabled { false };
+    float fog_start { 0.0f };
+    float fog_end { 1.0f };
+    bool scissor_enabled { false };
+    bool normalization_enabled { false };
+    Gfx::IntRect scissor_box;
+    bool enable_color_write { true };
+    float depth_offset_factor { 0 };
+    float depth_offset_constant { 0 };
+    bool depth_offset_enabled { false };
+    bool enable_culling { false };
+    WindingOrder front_face { WindingOrder::CounterClockwise };
+    bool cull_back { true };
+    bool cull_front { false };
+    Array<u8, NUM_SAMPLERS> texcoord_generation_enabled_coordinates {};
+    Array<Array<TexCoordGenerationConfig, 4>, NUM_SAMPLERS> texcoord_generation_config {};
+    Gfx::IntRect viewport;
+    bool lighting_enabled { false };
+    bool color_material_enabled { false };
+    ColorMaterialFace color_material_face { ColorMaterialFace::FrontAndBack };
+    ColorMaterialMode color_material_mode { ColorMaterialMode::AmbientAndDiffuse };
+};
+
+}

+ 2 - 2
Userland/Libraries/LibSoftGPU/Device.cpp

@@ -589,7 +589,7 @@ GPU::DeviceInfo Device::info() const
     };
 }
 
-static void generate_texture_coordinates(GPU::Vertex& vertex, RasterizerOptions const& options)
+static void generate_texture_coordinates(GPU::Vertex& vertex, GPU::RasterizerOptions const& options)
 {
     auto generate_coordinate = [&](size_t texcoord_index, size_t config_index) -> float {
         auto mode = options.texcoord_generation_config[texcoord_index][config_index].mode;
@@ -1190,7 +1190,7 @@ void Device::draw_statistics_overlay(Gfx::Bitmap& target)
     painter.draw_text(target.rect().translated(2, 2), debug_string, font, Gfx::TextAlignment::TopLeft, Gfx::Color::White);
 }
 
-void Device::set_options(RasterizerOptions const& options)
+void Device::set_options(GPU::RasterizerOptions const& options)
 {
     m_options = options;
 

+ 4 - 45
Userland/Libraries/LibSoftGPU/Device.h

@@ -18,6 +18,7 @@
 #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>
@@ -38,48 +39,6 @@
 
 namespace SoftGPU {
 
-struct RasterizerOptions {
-    bool shade_smooth { true };
-    bool enable_stencil_test { false };
-    bool enable_depth_test { false };
-    bool enable_depth_write { true };
-    bool enable_alpha_test { false };
-    GPU::AlphaTestFunction alpha_test_func { GPU::AlphaTestFunction::Always };
-    float alpha_test_ref_value { 0 };
-    bool enable_blending { false };
-    GPU::BlendFactor blend_source_factor { GPU::BlendFactor::One };
-    GPU::BlendFactor blend_destination_factor { GPU::BlendFactor::One };
-    u32 color_mask { 0xffffffff };
-    float depth_min { 0.f };
-    float depth_max { 1.f };
-    GPU::DepthTestFunction depth_func { GPU::DepthTestFunction::Less };
-    GPU::PolygonMode polygon_mode { GPU::PolygonMode::Fill };
-    FloatVector4 fog_color { 0.0f, 0.0f, 0.0f, 0.0f };
-    float fog_density { 1.0f };
-    GPU::FogMode fog_mode { GPU::FogMode::Exp };
-    bool fog_enabled { false };
-    float fog_start { 0.0f };
-    float fog_end { 1.0f };
-    bool scissor_enabled { false };
-    bool normalization_enabled { false };
-    Gfx::IntRect scissor_box;
-    bool enable_color_write { true };
-    float depth_offset_factor { 0 };
-    float depth_offset_constant { 0 };
-    bool depth_offset_enabled { false };
-    bool enable_culling { false };
-    GPU::WindingOrder front_face { GPU::WindingOrder::CounterClockwise };
-    bool cull_back { true };
-    bool cull_front { false };
-    Array<u8, GPU::NUM_SAMPLERS> texcoord_generation_enabled_coordinates {};
-    Array<Array<GPU::TexCoordGenerationConfig, 4>, GPU::NUM_SAMPLERS> texcoord_generation_config {};
-    Gfx::IntRect viewport;
-    bool lighting_enabled { false };
-    bool color_material_enabled { false };
-    GPU::ColorMaterialFace color_material_face { GPU::ColorMaterialFace::FrontAndBack };
-    GPU::ColorMaterialMode color_material_mode { GPU::ColorMaterialMode::AmbientAndDiffuse };
-};
-
 struct PixelQuad;
 
 class Device final {
@@ -96,9 +55,9 @@ public:
     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<GPU::DepthType> const&, int, int);
-    void set_options(RasterizerOptions const&);
+    void set_options(GPU::RasterizerOptions const&);
     void set_light_model_params(GPU::LightModelParameters const&);
-    RasterizerOptions options() const { return m_options; }
+    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);
@@ -124,7 +83,7 @@ private:
     bool test_alpha(PixelQuad&);
 
     RefPtr<FrameBuffer<GPU::ColorType, GPU::DepthType, GPU::StencilType>> m_frame_buffer {};
-    RasterizerOptions m_options;
+    GPU::RasterizerOptions m_options;
     GPU::LightModelParameters m_lighting_model;
     Clipper m_clipper;
     Vector<Triangle> m_triangle_list;