diff options
author | Stephan Unverwerth <s.unverwerth@gmx.de> | 2021-04-24 01:57:01 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-08 10:13:22 +0200 |
commit | 5ff248649bc171fe360e7c188aaab62c21f89639 (patch) | |
tree | ce16d9729a065e484cfb718cb943510dfbd4b6ea /Userland/Libraries/LibGL/SoftwareRasterizer.h | |
parent | e6c060049945ca34b7a46917a6674486deebf56e (diff) | |
download | serenity-5ff248649bc171fe360e7c188aaab62c21f89639.zip |
LibGL: Add software rasterizer
This is based mostly on Fabian "ryg" Giesen's 2011 blog series
"A trip through the Graphics Pipeline" and Scratchapixel's
"Rasterization: a Practical Implementation".
The rasterizer processes triangles in grid aligned 16x16 pixel blocks,
calculates barycentric coordinates and edge derivatives and interpolates
bilinearly across each block.
This will theoretically allow for better utilization of modern processor
features such as SMT and SIMD, as opposed to a classic scanline based
triangle rasterizer.
This serves as a starting point to get something on the screen.
In the future we might look into properly pipelining the main loop to
make the rasterizer more flexible, enabling us to enable/disable
certain features at the block rather than the pixel level.
Diffstat (limited to 'Userland/Libraries/LibGL/SoftwareRasterizer.h')
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareRasterizer.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.h b/Userland/Libraries/LibGL/SoftwareRasterizer.h new file mode 100644 index 0000000000..356bafe4c5 --- /dev/null +++ b/Userland/Libraries/LibGL/SoftwareRasterizer.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@gmx.de> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "GLStruct.h" +#include <LibGfx/Bitmap.h> +#include <LibGfx/Vector4.h> + +namespace GL { + +struct RasterizerOptions { + bool shade_smooth { false }; +}; + +class SoftwareRasterizer final { +public: + SoftwareRasterizer(const Gfx::IntSize& min_size); + + void submit_triangle(const GLTriangle& triangle); + void resize(const Gfx::IntSize& min_size); + void clear_color(const FloatVector4&); + void clear_depth(float); + void blit_to(Gfx::Bitmap&); + void wait_for_all_threads() const; + void set_options(const RasterizerOptions&); + RasterizerOptions options() const { return m_options; } + +private: + RefPtr<Gfx::Bitmap> m_render_target; + RasterizerOptions m_options; +}; + +} |