diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-05-08 02:13:14 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-09 21:49:48 +0200 |
commit | a20bf80b050659466a1bd118d594103c20ec3e6d (patch) | |
tree | 3b62a66e28b3b62bdd61b504d498b1de5c23c53b /Tests | |
parent | 950ded7ab9768cb80117328a5d05dadee0b8b004 (diff) | |
download | serenity-a20bf80b050659466a1bd118d594103c20ec3e6d.zip |
LibGL+LibGPU+LibSoftGPU: Implement point and line drawing
Implement (anti)aliased point drawing and anti-aliased line drawing.
Supported through LibGL's `GL_POINTS`, `GL_LINES`, `GL_LINE_LOOP` and
`GL_LINE_STRIP`.
In order to support this, `LibSoftGPU`s rasterization logic was
reworked. Now, any primitive can be drawn by invoking `rasterize()`
which takes care of the quad loop and fragment testing logic. Three
callbacks need to be passed:
* `set_coverage_mask`: the primitive needs to provide initial coverage
mask information so fragments can be discarded early.
* `set_quad_depth`: fragments survived stencil testing, so depth values
need to be set so depth testing can take place.
* `set_quad_attributes`: fragments survived depth testing, so fragment
shading is going to take place. All attributes like color, tex coords
and fog depth need to be set so alpha testing and eventually,
fragment rasterization can take place.
As of this commit, there are four instantiations of this function:
* Triangle rasterization
* Points - aliased
* Points - anti-aliased
* Lines - anti-aliased
In order to standardize vertex processing for all primitive types,
things like vertex transformation, lighting and tex coord generation
are now taking place before clipping.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibGL/TestRender.cpp | 52 | ||||
-rw-r--r-- | Tests/LibGL/reference-images/0004_points.qoi | bin | 0 -> 170 bytes | |||
-rw-r--r-- | Tests/LibGL/reference-images/0005_lines.qoi | bin | 0 -> 2166 bytes |
3 files changed, 52 insertions, 0 deletions
diff --git a/Tests/LibGL/TestRender.cpp b/Tests/LibGL/TestRender.cpp index 640c54252f..85604fae6a 100644 --- a/Tests/LibGL/TestRender.cpp +++ b/Tests/LibGL/TestRender.cpp @@ -117,3 +117,55 @@ TEST_CASE(0003_rect_w_coordinate_regression) context->present(); expect_bitmap_equals_reference(context->frontbuffer(), "0003_rect_w_coordinate_regression"); } + +TEST_CASE(0004_points) +{ + auto context = create_testing_context(64, 64); + + // Aliased points + for (size_t i = 0; i < 3; ++i) { + glPointSize(1.f + i); + glBegin(GL_POINTS); + glVertex2f(-.5f + i * .5f, .5f); + glEnd(); + } + + // Anti-aliased points + glEnable(GL_POINT_SMOOTH); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + for (size_t i = 0; i < 3; ++i) { + glPointSize(3.f - i); + glBegin(GL_POINTS); + glVertex2f(-.5f + i * .5f, -.5f); + glEnd(); + } + + EXPECT_EQ(glGetError(), 0u); + + context->present(); + expect_bitmap_equals_reference(context->frontbuffer(), "0004_points"); +} + +TEST_CASE(0005_lines_antialiased) +{ + auto context = create_testing_context(64, 64); + + // Draw anti-aliased lines + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glBegin(GL_LINES); + for (size_t i = 0; i < 6; ++i) { + glVertex2f(-.9f, .25f - i * .1f); + glVertex2f(.9f, .9f - i * .36f); + } + glEnd(); + + EXPECT_EQ(glGetError(), 0u); + + context->present(); + expect_bitmap_equals_reference(context->frontbuffer(), "0005_lines"); +} diff --git a/Tests/LibGL/reference-images/0004_points.qoi b/Tests/LibGL/reference-images/0004_points.qoi Binary files differnew file mode 100644 index 0000000000..20695549e5 --- /dev/null +++ b/Tests/LibGL/reference-images/0004_points.qoi diff --git a/Tests/LibGL/reference-images/0005_lines.qoi b/Tests/LibGL/reference-images/0005_lines.qoi Binary files differnew file mode 100644 index 0000000000..c95b868352 --- /dev/null +++ b/Tests/LibGL/reference-images/0005_lines.qoi |