ladybird/Userland/Libraries/LibSoftGPU/Clipper.h
Jelle Raaijmakers 4c1d8a7785 LibSoftGPU: Optimize clipping code
Three optimizations are applied:

1. If the list of vertices to clip is empty, return immediately after
   clearing the output list.

2. Remember the previous vertex instead of recalculating whether it is
   within the clip plane.

3. Instead of copying and swapping lists around, operate on the input
   and output lists directly. This prevents a lot of `malloc`/`free`
   traffic as a result of vector assignments.

This takes the clipping code CPU load from 3.9% down to 1.8% for
Quake 3 on my machine.
2022-04-11 19:31:23 -07:00

35 lines
591 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 <LibGPU/Vertex.h>
#include <LibGfx/Vector4.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<GPU::Vertex>& input_vecs);
private:
Vector<GPU::Vertex> m_vertex_buffer;
};
}