1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:47:34 +00:00

LibGL+LibSoftGPU: Move rendering related code to LibSoftGPU library

This introduces a new library, LibSoftGPU, that incorporates all
rendering related features that formerly resided within LibGL itself.

Going forward we will make both libraries completely independent from
each other allowing LibGL to load different, possibly accelerated,
rendering backends.
This commit is contained in:
Stephan Unverwerth 2021-12-16 20:32:38 +01:00 committed by Brian Gianforcaro
parent 46b1c2d609
commit ad3d5d43bd
12 changed files with 58 additions and 45 deletions

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <LibGL/GLStruct.h>
#include <LibGfx/Vector4.h>
namespace SoftGPU {
class Clipper final {
enum ClipPlane : u8 {
LEFT = 0,
RIGHT,
TOP,
BOTTOM,
NEAR,
FAR
};
static constexpr u8 NUMBER_OF_CLIPPING_PLANES = 6;
static constexpr u8 MAX_CLIPPED_VERTS = 6;
static constexpr FloatVector4 clip_planes[] = {
{ -1, 0, 0, 1 }, // Left Plane
{ 1, 0, 0, 1 }, // Right Plane
{ 0, 1, 0, 1 }, // Top Plane
{ 0, -1, 0, 1 }, // Bottom plane
{ 0, 0, 1, 1 }, // Near Plane
{ 0, 0, -1, 1 } // Far Plane
};
static constexpr FloatVector4 clip_plane_normals[] = {
{ 1, 0, 0, 0 }, // Left Plane
{ -1, 0, 0, 0 }, // Right Plane
{ 0, -1, 0, 0 }, // Top Plane
{ 0, 1, 0, 0 }, // Bottom plane
{ 0, 0, 1, 0 }, // Near Plane
{ 0, 0, -1, 0 } // Far Plane
};
public:
Clipper() { }
void clip_triangle_against_frustum(Vector<GL::GLVertex>& input_vecs);
private:
bool point_within_clip_plane(const FloatVector4& vertex, ClipPlane plane);
GL::GLVertex clip_intersection_point(const GL::GLVertex& vec, const GL::GLVertex& prev_vec, ClipPlane plane_index);
Vector<GL::GLVertex> list_a;
Vector<GL::GLVertex> list_b;
};
}