1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:57:35 +00:00

LibGL: Fix clipping and interpolate vertex attributes

The previous clipping implementation was problematic especially when
clipping against the near plane. Triangles are now correctly clipped
using homogenous coordinates against all frustum planes.

Texture coordinates and vertex colors are now correctly interpolated.
The earier implementation was just a placeholder.
This commit is contained in:
Stephan Unverwerth 2021-08-16 19:22:08 +02:00 committed by Andreas Kling
parent 39ff1459f8
commit 220ac5eb02
6 changed files with 111 additions and 205 deletions

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Vector.h>
#include <LibGL/GLStruct.h>
#include <LibGfx/Vector4.h>
namespace GL {
@ -34,26 +35,24 @@ class Clipper final {
};
static constexpr FloatVector4 clip_plane_normals[] = {
{ 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
{ 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<FloatVector4>& input_vecs);
const Vector<FloatVector4, MAX_CLIPPED_VERTS>& clipped_verts() const;
void clip_triangle_against_frustum(Vector<GLVertex>& input_vecs);
private:
bool point_within_clip_plane(const FloatVector4& vertex, ClipPlane plane);
FloatVector4 clip_intersection_point(const FloatVector4& vec, const FloatVector4& prev_vec, ClipPlane plane_index);
private:
Vector<FloatVector4, MAX_CLIPPED_VERTS> m_clipped_verts;
GLVertex clip_intersection_point(const GLVertex& vec, const GLVertex& prev_vec, ClipPlane plane_index);
Vector<GLVertex> list_a;
Vector<GLVertex> list_b;
};
}