1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

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.
This commit is contained in:
Jelle Raaijmakers 2022-05-08 02:13:14 +02:00 committed by Linus Groh
parent 950ded7ab9
commit a20bf80b05
Notes: sideshowbarker 2024-07-17 21:11:12 +09:00
13 changed files with 712 additions and 390 deletions

View file

@ -91,6 +91,46 @@ FLATTEN static constexpr void clip_plane(Vector<GPU::Vertex>& input_list, Vector
}
}
void Clipper::clip_points_against_frustum(Vector<GPU::Vertex>& vertices)
{
m_vertex_buffer.clear_with_capacity();
for (auto& vertex : vertices) {
auto const coords = vertex.clip_coordinates;
if (point_within_clip_plane<ClipPlane::LEFT>(coords) && point_within_clip_plane<ClipPlane::RIGHT>(coords)
&& point_within_clip_plane<ClipPlane::TOP>(coords) && point_within_clip_plane<ClipPlane::BOTTOM>(coords)
&& point_within_clip_plane<ClipPlane::NEAR>(coords) && point_within_clip_plane<ClipPlane::FAR>(coords))
m_vertex_buffer.append(vertex);
}
vertices.clear_with_capacity();
vertices.extend(m_vertex_buffer);
}
template<Clipper::ClipPlane plane>
static constexpr bool constrain_line_within_plane(GPU::Vertex& from, GPU::Vertex& to)
{
auto from_within_plane = point_within_clip_plane<plane>(from.clip_coordinates);
auto to_within_plane = point_within_clip_plane<plane>(to.clip_coordinates);
if (!from_within_plane && !to_within_plane)
return false;
if (!from_within_plane)
from = clip_intersection_point<plane>(from, to);
else if (!to_within_plane)
to = clip_intersection_point<plane>(from, to);
return true;
}
bool Clipper::clip_line_against_frustum(GPU::Vertex& from, GPU::Vertex& to)
{
return constrain_line_within_plane<ClipPlane::LEFT>(from, to)
&& constrain_line_within_plane<ClipPlane::RIGHT>(from, to)
&& constrain_line_within_plane<ClipPlane::TOP>(from, to)
&& constrain_line_within_plane<ClipPlane::BOTTOM>(from, to)
&& constrain_line_within_plane<ClipPlane::NEAR>(from, to)
&& constrain_line_within_plane<ClipPlane::FAR>(from, to);
}
void Clipper::clip_triangle_against_frustum(Vector<GPU::Vertex>& input_verts)
{
// FIXME C++23. Static reflection will provide looping over all enum values.