summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@serenityos.org>2022-03-27 15:20:51 +0200
committerAndreas Kling <kling@serenityos.org>2022-04-06 11:32:24 +0200
commite416380826a680ca4f1de630f5407b1e997943bc (patch)
tree1f599f33f973ff32f1ebe1d21a8f11fec7ff8bfe /Userland
parentb652db1f543c7c32f94a8d5cd9865ca7e02f09fd (diff)
downloadserenity-e416380826a680ca4f1de630f5407b1e997943bc.zip
LibGL+LibGPU+LibSoftGPU: Move StencilConfiguration.h to LibGPU
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGL/GLContext.cpp2
-rw-r--r--Userland/Libraries/LibGPU/Config.h19
-rw-r--r--Userland/Libraries/LibGPU/StencilConfiguration.h25
-rw-r--r--Userland/Libraries/LibSoftGPU/Config.h6
-rw-r--r--Userland/Libraries/LibSoftGPU/Device.cpp28
-rw-r--r--Userland/Libraries/LibSoftGPU/Device.h28
-rw-r--r--Userland/Libraries/LibSoftGPU/Image.cpp4
-rw-r--r--Userland/Libraries/LibSoftGPU/Image.h2
8 files changed, 73 insertions, 41 deletions
diff --git a/Userland/Libraries/LibGL/GLContext.cpp b/Userland/Libraries/LibGL/GLContext.cpp
index 12d9e30530..a303e0d1d9 100644
--- a/Userland/Libraries/LibGL/GLContext.cpp
+++ b/Userland/Libraries/LibGL/GLContext.cpp
@@ -3144,7 +3144,7 @@ void GLContext::sync_stencil_configuration()
m_stencil_configuration_dirty = false;
auto set_device_stencil = [&](GPU::Face face, StencilFunctionOptions func, StencilOperationOptions op) {
- SoftGPU::StencilConfiguration device_configuration;
+ GPU::StencilConfiguration device_configuration;
// Stencil test function
auto map_func = [](GLenum func) -> GPU::StencilTestFunction {
diff --git a/Userland/Libraries/LibGPU/Config.h b/Userland/Libraries/LibGPU/Config.h
new file mode 100644
index 0000000000..e080a95e0b
--- /dev/null
+++ b/Userland/Libraries/LibGPU/Config.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/Types.h>
+
+#pragma once
+
+namespace GPU {
+
+// FIXME: These 3 types were originally introduced in LibSoftGPU and are currently needed by the device interface.
+// Once we refactor the interface these should move back into LibSoftGPU.
+using ColorType = u32; // BGRA:8888
+using DepthType = float;
+using StencilType = u8;
+
+}
diff --git a/Userland/Libraries/LibGPU/StencilConfiguration.h b/Userland/Libraries/LibGPU/StencilConfiguration.h
new file mode 100644
index 0000000000..b68b2d6ba1
--- /dev/null
+++ b/Userland/Libraries/LibGPU/StencilConfiguration.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibGPU/Config.h>
+#include <LibGPU/Enums.h>
+
+namespace GPU {
+
+struct StencilConfiguration {
+ StencilTestFunction test_function;
+ StencilType reference_value;
+ StencilType test_mask;
+
+ StencilOperation on_stencil_test_fail;
+ StencilOperation on_depth_test_fail;
+ StencilOperation on_pass;
+ StencilType write_mask;
+};
+
+}
diff --git a/Userland/Libraries/LibSoftGPU/Config.h b/Userland/Libraries/LibSoftGPU/Config.h
index 24b80e38e5..7bcda1446b 100644
--- a/Userland/Libraries/LibSoftGPU/Config.h
+++ b/Userland/Libraries/LibSoftGPU/Config.h
@@ -6,6 +6,8 @@
#pragma once
+#include <LibGPU/Config.h>
+
#define INCREASE_STATISTICS_COUNTER(stat, n) \
do { \
if constexpr (ENABLE_STATISTICS_OVERLAY) \
@@ -23,8 +25,4 @@ static constexpr int NUM_LIGHTS = 8;
// FIXME: make this dynamically configurable through ConfigServer
static constexpr bool CLAMP_DEPRECATED_BEHAVIOR = false;
-using ColorType = u32; // BGRA:8888
-using DepthType = float;
-using StencilType = u8;
-
}
diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp
index 63e64c64aa..8b68e74c80 100644
--- a/Userland/Libraries/LibSoftGPU/Device.cpp
+++ b/Userland/Libraries/LibSoftGPU/Device.cpp
@@ -60,7 +60,7 @@ constexpr static auto interpolate(const T& v0, const T& v1, const T& v2, Vector3
return v0 * barycentric_coords.x() + v1 * barycentric_coords.y() + v2 * barycentric_coords.z();
}
-static ColorType to_bgra32(FloatVector4 const& color)
+static GPU::ColorType to_bgra32(FloatVector4 const& color)
{
auto clamped = color.clamped(0.0f, 1.0f);
auto r = static_cast<u8>(clamped.x() * 255);
@@ -265,7 +265,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
auto const& stencil_configuration = m_stencil_configuration[GPU::Face::Front];
auto const stencil_reference_value = stencil_configuration.reference_value & stencil_configuration.test_mask;
- auto write_to_stencil = [](StencilType* stencil_ptrs[4], i32x4 stencil_value, GPU::StencilOperation op, StencilType reference_value, StencilType write_mask, i32x4 pixel_mask) {
+ auto write_to_stencil = [](GPU::StencilType* stencil_ptrs[4], i32x4 stencil_value, GPU::StencilOperation op, GPU::StencilType reference_value, GPU::StencilType write_mask, i32x4 pixel_mask) {
if (write_mask == 0 || op == GPU::StencilOperation::Keep)
return;
@@ -331,7 +331,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
int coverage_bits = maskbits(quad.mask);
// Stencil testing
- StencilType* stencil_ptrs[4];
+ GPU::StencilType* stencil_ptrs[4];
i32x4 stencil_value;
if (m_options.enable_stencil_test) {
stencil_ptrs[0] = coverage_bits & 1 ? &stencil_buffer->scanline(by)[bx] : nullptr;
@@ -391,7 +391,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
quad.barycentrics = edge_values * one_over_area;
// Depth testing
- DepthType* depth_ptrs[4] = {
+ GPU::DepthType* depth_ptrs[4] = {
coverage_bits & 1 ? &depth_buffer->scanline(by)[bx] : nullptr,
coverage_bits & 2 ? &depth_buffer->scanline(by)[bx + 1] : nullptr,
coverage_bits & 4 ? &depth_buffer->scanline(by + 1)[bx] : nullptr,
@@ -529,7 +529,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
if ((m_options.color_mask == 0) || !m_options.enable_color_write)
continue;
- ColorType* color_ptrs[4] = {
+ GPU::ColorType* color_ptrs[4] = {
coverage_bits & 1 ? &color_buffer->scanline(by)[bx] : nullptr,
coverage_bits & 2 ? &color_buffer->scanline(by)[bx + 1] : nullptr,
coverage_bits & 4 ? &color_buffer->scanline(by + 1)[bx] : nullptr,
@@ -571,7 +571,7 @@ void Device::rasterize_triangle(Triangle const& triangle)
}
Device::Device(Gfx::IntSize const& size)
- : m_frame_buffer(FrameBuffer<ColorType, DepthType, StencilType>::try_create(size).release_value_but_fixme_should_propagate_errors())
+ : m_frame_buffer(FrameBuffer<GPU::ColorType, GPU::DepthType, GPU::StencilType>::try_create(size).release_value_but_fixme_should_propagate_errors())
{
m_options.scissor_box = m_frame_buffer->rect();
m_options.viewport = m_frame_buffer->rect();
@@ -584,7 +584,7 @@ GPU::DeviceInfo Device::info() const
.device_name = "SoftGPU",
.num_texture_units = NUM_SAMPLERS,
.num_lights = NUM_LIGHTS,
- .stencil_bits = sizeof(StencilType) * 8,
+ .stencil_bits = sizeof(GPU::StencilType) * 8,
.supports_npot_textures = true,
};
}
@@ -1061,7 +1061,7 @@ ALWAYS_INLINE bool Device::test_alpha(PixelQuad& quad)
void Device::resize(Gfx::IntSize const& size)
{
- auto frame_buffer_or_error = FrameBuffer<ColorType, DepthType, StencilType>::try_create(size);
+ auto frame_buffer_or_error = FrameBuffer<GPU::ColorType, GPU::DepthType, GPU::StencilType>::try_create(size);
m_frame_buffer = MUST(frame_buffer_or_error);
}
@@ -1076,7 +1076,7 @@ void Device::clear_color(FloatVector4 const& color)
m_frame_buffer->color_buffer()->fill(fill_color, clear_rect);
}
-void Device::clear_depth(DepthType depth)
+void Device::clear_depth(GPU::DepthType depth)
{
auto clear_rect = m_frame_buffer->rect();
if (m_options.scissor_enabled)
@@ -1085,7 +1085,7 @@ void Device::clear_depth(DepthType depth)
m_frame_buffer->depth_buffer()->fill(depth, clear_rect);
}
-void Device::clear_stencil(StencilType value)
+void Device::clear_stencil(GPU::StencilType value)
{
auto clear_rect = m_frame_buffer->rect();
if (m_options.scissor_enabled)
@@ -1106,7 +1106,7 @@ void Device::blit_to_color_buffer_at_raster_position(Gfx::Bitmap const& source)
m_frame_buffer->color_buffer()->blit_from_bitmap(source, blit_rect);
}
-void Device::blit_to_depth_buffer_at_raster_position(Vector<DepthType> const& depth_values, int width, int height)
+void Device::blit_to_depth_buffer_at_raster_position(Vector<GPU::DepthType> const& depth_values, int width, int height)
{
if (!m_raster_position.valid)
return;
@@ -1203,7 +1203,7 @@ void Device::set_light_model_params(LightModelParameters const& lighting_model)
m_lighting_model = lighting_model;
}
-ColorType Device::get_color_buffer_pixel(int x, int y)
+GPU::ColorType Device::get_color_buffer_pixel(int x, int y)
{
// FIXME: Reading individual pixels is very slow, rewrite this to transfer whole blocks
if (!m_frame_buffer->rect().contains(x, y))
@@ -1211,7 +1211,7 @@ ColorType Device::get_color_buffer_pixel(int x, int y)
return m_frame_buffer->color_buffer()->scanline(y)[x];
}
-DepthType Device::get_depthbuffer_value(int x, int y)
+GPU::DepthType Device::get_depthbuffer_value(int x, int y)
{
// FIXME: Reading individual pixels is very slow, rewrite this to transfer whole blocks
if (!m_frame_buffer->rect().contains(x, y))
@@ -1246,7 +1246,7 @@ void Device::set_material_state(GPU::Face face, GPU::Material const& material)
m_materials[face] = material;
}
-void Device::set_stencil_configuration(GPU::Face face, StencilConfiguration const& stencil_configuration)
+void Device::set_stencil_configuration(GPU::Face face, GPU::StencilConfiguration const& stencil_configuration)
{
m_stencil_configuration[face] = stencil_configuration;
}
diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h
index 4edfb2c6ac..f0e0bf0e1a 100644
--- a/Userland/Libraries/LibSoftGPU/Device.h
+++ b/Userland/Libraries/LibSoftGPU/Device.h
@@ -17,6 +17,7 @@
#include <LibGPU/Light.h>
#include <LibGPU/Material.h>
#include <LibGPU/SamplerConfig.h>
+#include <LibGPU/StencilConfiguration.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Matrix3x3.h>
#include <LibGfx/Matrix4x4.h>
@@ -99,17 +100,6 @@ struct RasterPosition {
FloatVector4 texture_coordinates { 0.0f, 0.0f, 0.0f, 1.0f };
};
-struct StencilConfiguration {
- GPU::StencilTestFunction test_function;
- StencilType reference_value;
- StencilType test_mask;
-
- GPU::StencilOperation on_stencil_test_fail;
- GPU::StencilOperation on_depth_test_fail;
- GPU::StencilOperation on_pass;
- StencilType write_mask;
-};
-
class Device final {
public:
Device(Gfx::IntSize const& min_size);
@@ -119,24 +109,24 @@ public:
void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
void resize(Gfx::IntSize const& min_size);
void clear_color(FloatVector4 const&);
- void clear_depth(DepthType);
- void clear_stencil(StencilType);
+ 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<DepthType> const&, int, int);
+ void blit_to_depth_buffer_at_raster_position(Vector<GPU::DepthType> const&, int, int);
void set_options(RasterizerOptions const&);
void set_light_model_params(LightModelParameters const&);
RasterizerOptions options() const { return m_options; }
LightModelParameters light_model() const { return m_lighting_model; }
- ColorType get_color_buffer_pixel(int x, int y);
- DepthType get_depthbuffer_value(int x, int y);
+ GPU::ColorType get_color_buffer_pixel(int x, int y);
+ GPU::DepthType get_depthbuffer_value(int x, int y);
NonnullRefPtr<Image> 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, StencilConfiguration const&);
+ void set_stencil_configuration(GPU::Face, GPU::StencilConfiguration const&);
RasterPosition raster_position() const { return m_raster_position; }
void set_raster_position(RasterPosition const& raster_position);
@@ -151,7 +141,7 @@ private:
void shade_fragments(PixelQuad&);
bool test_alpha(PixelQuad&);
- RefPtr<FrameBuffer<ColorType, DepthType, StencilType>> m_frame_buffer {};
+ RefPtr<FrameBuffer<GPU::ColorType, GPU::DepthType, GPU::StencilType>> m_frame_buffer {};
RasterizerOptions m_options;
LightModelParameters m_lighting_model;
Clipper m_clipper;
@@ -164,7 +154,7 @@ private:
Array<GPU::Light, NUM_LIGHTS> m_lights;
Array<GPU::Material, 2u> m_materials;
RasterPosition m_raster_position;
- Array<StencilConfiguration, 2u> m_stencil_configuration;
+ Array<GPU::StencilConfiguration, 2u> m_stencil_configuration;
};
}
diff --git a/Userland/Libraries/LibSoftGPU/Image.cpp b/Userland/Libraries/LibSoftGPU/Image.cpp
index f60d9890b8..bd7f6217e5 100644
--- a/Userland/Libraries/LibSoftGPU/Image.cpp
+++ b/Userland/Libraries/LibSoftGPU/Image.cpp
@@ -11,7 +11,7 @@ namespace SoftGPU {
Image::Image(unsigned width, unsigned height, unsigned depth, unsigned max_levels, unsigned layers)
: m_num_layers(layers)
- , m_mipmap_buffers(FixedArray<RefPtr<Typed3DBuffer<ColorType>>>::must_create_but_fixme_should_propagate_errors(layers * max_levels))
+ , m_mipmap_buffers(FixedArray<RefPtr<Typed3DBuffer<GPU::ColorType>>>::must_create_but_fixme_should_propagate_errors(layers * max_levels))
{
VERIFY(width > 0);
VERIFY(height > 0);
@@ -26,7 +26,7 @@ Image::Image(unsigned width, unsigned height, unsigned depth, unsigned max_level
unsigned level;
for (level = 0; level < max_levels; ++level) {
for (unsigned layer = 0; layer < layers; ++layer)
- m_mipmap_buffers[layer * layers + level] = MUST(Typed3DBuffer<ColorType>::try_create(width, height, depth));
+ m_mipmap_buffers[layer * layers + level] = MUST(Typed3DBuffer<GPU::ColorType>::try_create(width, height, depth));
if (width <= 1 && height <= 1 && depth <= 1)
break;
diff --git a/Userland/Libraries/LibSoftGPU/Image.h b/Userland/Libraries/LibSoftGPU/Image.h
index 3d4a2a1564..bbfe154138 100644
--- a/Userland/Libraries/LibSoftGPU/Image.h
+++ b/Userland/Libraries/LibSoftGPU/Image.h
@@ -175,7 +175,7 @@ private:
unsigned m_num_levels { 0 };
unsigned m_num_layers { 0 };
- FixedArray<RefPtr<Typed3DBuffer<ColorType>>> m_mipmap_buffers;
+ FixedArray<RefPtr<Typed3DBuffer<GPU::ColorType>>> m_mipmap_buffers;
bool m_width_is_power_of_two { false };
bool m_height_is_power_of_two { false };