1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:17:35 +00:00

LibGL+LibSoftGPU: Implement the stencil buffer

This implements an 8-bit front stencil buffer. Stencil operations are
SIMD optimized. LibGL changes include:

* New `glStencilMask` and `glStencilMaskSeparate` functions
* New context parameter `GL_STENCIL_CLEAR_VALUE`
This commit is contained in:
Jelle Raaijmakers 2022-01-16 22:48:46 +01:00 committed by Andreas Kling
parent 6386671944
commit 11c807ebd1
13 changed files with 430 additions and 77 deletions

View file

@ -10,6 +10,7 @@
#include <AK/Array.h>
#include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h>
#include <AK/Vector.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Matrix3x3.h>
#include <LibGfx/Matrix4x4.h>
@ -26,6 +27,7 @@
#include <LibSoftGPU/Light/Light.h>
#include <LibSoftGPU/Light/Material.h>
#include <LibSoftGPU/Sampler.h>
#include <LibSoftGPU/StencilBuffer.h>
#include <LibSoftGPU/Triangle.h>
#include <LibSoftGPU/Vertex.h>
@ -38,6 +40,7 @@ struct TexCoordGenerationConfig {
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 };
@ -94,6 +97,17 @@ struct RasterPosition {
FloatVector4 texture_coordinates { 0.0f, 0.0f, 0.0f, 1.0f };
};
struct StencilConfiguration {
StencilTestFunction test_function;
u8 reference_value;
u8 test_mask;
StencilOperation on_stencil_test_fail;
StencilOperation on_depth_test_fail;
StencilOperation on_pass;
u8 write_mask;
};
class Device final {
public:
Device(const Gfx::IntSize& min_size);
@ -104,6 +118,7 @@ public:
void resize(const Gfx::IntSize& min_size);
void clear_color(const FloatVector4&);
void clear_depth(float);
void clear_stencil(u8);
void blit_to(Gfx::Bitmap&);
void blit_to_color_buffer_at_raster_position(Gfx::Bitmap const&);
void blit_to_depth_buffer_at_raster_position(Vector<float> const&, size_t, size_t);
@ -120,6 +135,7 @@ public:
void set_sampler_config(unsigned, SamplerConfig const&);
void set_light_state(unsigned, Light const&);
void set_material_state(Face, Material const&);
void set_stencil_configuration(Face, StencilConfiguration const&);
RasterPosition raster_position() const { return m_raster_position; }
void set_raster_position(RasterPosition const& raster_position);
@ -128,15 +144,16 @@ public:
private:
void draw_statistics_overlay(Gfx::Bitmap&);
Gfx::IntRect raster_rect_in_target_coordinates(Gfx::IntSize size);
Gfx::IntRect window_coordinates_to_target_coordinates(Gfx::IntRect const&);
void rasterize_triangle(const Triangle& triangle);
void setup_blend_factors();
void shade_fragments(PixelQuad&);
bool test_alpha(PixelQuad&);
private:
RefPtr<Gfx::Bitmap> m_render_target;
OwnPtr<DepthBuffer> m_depth_buffer;
NonnullOwnPtr<DepthBuffer> m_depth_buffer;
NonnullOwnPtr<StencilBuffer> m_stencil_buffer;
RasterizerOptions m_options;
LightModelParameters m_lighting_model;
Clipper m_clipper;
@ -149,6 +166,7 @@ private:
Array<Light, NUM_LIGHTS> m_lights;
Array<Material, 2u> m_materials;
RasterPosition m_raster_position;
Array<StencilConfiguration, 2u> m_stencil_configuration;
};
}