ladybird/Userland/Libraries/LibSoftGPU/Clipper.h
Lenny Maiorani 2e436129b0 LibSoftGPU: Dispatch based on ClipPlane enum at compile-time
The `ClipPlane` enum is being looped over at run-time performing
run-time dispatch to determine the comparison operation in
`point_within_clip_plane`.

Change this `for` loop to be linear code which dispatches using a
template parameter. This allows for the `point_within_clip_plane`
function to do compile-time dispatch.

Note: This linear code can become a compile-time loop when static
reflection lands in C++2[y|z] allowing looping over the reflected
`enum class`.
2022-02-10 10:33:31 +00:00

37 lines
603 B
C++

/*
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <LibGfx/Vector4.h>
#include <LibSoftGPU/Vertex.h>
namespace SoftGPU {
class Clipper final {
public:
enum class ClipPlane : u8 {
LEFT = 0,
RIGHT,
TOP,
BOTTOM,
NEAR,
FAR
};
Clipper() = default;
void clip_triangle_against_frustum(Vector<Vertex>& input_vecs);
private:
Vector<Vertex> list_a;
Vector<Vertex> list_b;
};
}