diff options
author | Stephan Unverwerth <s.unverwerth@gmx.de> | 2021-05-16 17:09:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-16 19:27:23 +0200 |
commit | 2dcafde33094441da40a6d992dceadc030472284 (patch) | |
tree | 7220127184b24bcd8d73834536a3e013f4ef91e1 /Userland/Libraries/LibGL | |
parent | 1bd754882ddea4d6785879118dc032098e83e679 (diff) | |
download | serenity-2dcafde33094441da40a6d992dceadc030472284.zip |
LibGL: Implement alpha testing in SoftwareRasterizer
Diffstat (limited to 'Userland/Libraries/LibGL')
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareRasterizer.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp index 5f5c7ffa2f..4a35cf981d 100644 --- a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp +++ b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp @@ -316,6 +316,48 @@ static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& re } } + if (options.enable_alpha_test && options.alpha_test_func != GL_ALWAYS) { + // FIXME: I'm not sure if this is the right place to test this. + // If we tested this right at the beginning of our rasterizer routine + // we could skip a lot of work but the GL spec might disagree. + if (options.alpha_test_func == GL_NEVER) + continue; + + for (int y = 0; y < RASTERIZER_BLOCK_SIZE; y++) { + auto src = pixel_buffer[y]; + for (int x = 0; x < RASTERIZER_BLOCK_SIZE; x++, src++) { + if (~pixel_mask[y] & (1 << x)) + continue; + + bool passed = true; + + switch (options.alpha_test_func) { + case GL_LESS: + passed = src->w() < options.alpha_test_ref_value; + break; + case GL_EQUAL: + passed = src->w() == options.alpha_test_ref_value; + break; + case GL_LEQUAL: + passed = src->w() <= options.alpha_test_ref_value; + break; + case GL_GREATER: + passed = src->w() > options.alpha_test_ref_value; + break; + case GL_NOTEQUAL: + passed = src->w() != options.alpha_test_ref_value; + break; + case GL_GEQUAL: + passed = src->w() >= options.alpha_test_ref_value; + break; + } + + if (!passed) + pixel_mask[y] ^= (1 << x); + } + } + } + if (options.enable_blending) { // Blend color values from pixel_buffer into render_target for (int y = 0; y < RASTERIZER_BLOCK_SIZE; y++) { |