srp
software rendering pipeline
Loading...
Searching...
No Matches
Clipping

Functions related to primitive clipping. More...

Collaboration diagram for Clipping:

Files

file  clipping.c
 
file  clipping.h
 
enum  ClipPlane {
  PLANE_LEFT , PLANE_RIGHT , PLANE_BOTTOM , PLANE_TOP ,
  PLANE_NEAR , PLANE_FAR , PLANE_COUNT
}
 
static uint8_t computeClipCode (const SRPVertexShaderOut *v)
 
static size_t clipAgainstPlane (SRPVertexShaderOut *in, size_t inCount, ClipPlane plane, const SRPShaderProgram *sp, SRPVertexShaderOut *out)
 
static void interpolateVertex (const SRPVertexShaderOut *a, const SRPVertexShaderOut *b, float t, const SRPShaderProgram *sp, SRPVertexShaderOut *out)
 
static float planeDistance (const SRPVertexShaderOut *v, ClipPlane p)
 
bool clipLine (SRPLine *line, const SRPShaderProgram *sp)
 
bool clipPoint (SRPPoint *p)
 
size_t clipTriangle (const SRPTriangle *in, const SRPShaderProgram *sp, SRPTriangle *out)
 

Detailed Description

Functions related to primitive clipping.

Enumeration Type Documentation

◆ ClipPlane

enum ClipPlane

Represents all possible clip planes

Function Documentation

◆ clipAgainstPlane()

static size_t clipAgainstPlane ( SRPVertexShaderOut in,
size_t  inCount,
ClipPlane  plane,
const SRPShaderProgram sp,
SRPVertexShaderOut out 
)
static

Clip a polygon against specified plane (Sutherland-Hodgman)

Parameters
[in]inVertices of an input polygon
[in]inCountAmount of vertices the input polygon has
[in]planeThe plane to clip against
[in]spThe shader program being used
[out]outVertices of a clipped polygon
Returns
Amount of vertices the clipped polygon has

◆ clipLine()

bool clipLine ( SRPLine line,
const SRPShaderProgram sp 
)

Clip the line in-place using Liang-Barsky algorithm

Parameters
[in]lineThe line to clip
[in]spThe shader program being used
Returns
true if clipped fully (nothing left), false if clipped partially

◆ clipPoint()

bool clipPoint ( SRPPoint p)

Determine whether or not a point should be clipped

Parameters
[in]pPoint to test
Returns
true if point is clipped, false otherwise

◆ clipTriangle()

size_t clipTriangle ( const SRPTriangle in,
const SRPShaderProgram sp,
SRPTriangle out 
)

Clip the triangle using Sutherland-Hodgman algorithm

Parameters
[in]inThe triangle to clip
[in]spThe shader program being used
[out]outThe returned array of triangles
Returns
Amount of outputted triangles

◆ computeClipCode()

static uint8_t computeClipCode ( const SRPVertexShaderOut v)
inlinestatic

Compute the clip code for a vertex. 0 if inside all 6 clip planes, else 1 in a specific bit.

Parameters
[in]vVertex
Returns
Clip code

◆ interpolateVertex()

static void interpolateVertex ( const SRPVertexShaderOut a,
const SRPVertexShaderOut b,
float  t,
const SRPShaderProgram sp,
SRPVertexShaderOut out 
)
static

Create new vertex via interpolating between two existing ones

Parameters
[in]aFirst vertex
[in]bSecond vertex
[in]tInterpolation parameter: 0 -> first vertex, 1 -> second vertex
[in]spThe shader program being used
[in]outInterpolated vertex
Todo:
this is disgusting

◆ planeDistance()

static float planeDistance ( const SRPVertexShaderOut v,
ClipPlane  p 
)
inlinestatic

Calculate the distance from the vertex to the specified clip plane

Parameters
[in]vVertex
[in]pClip plane
Returns
The distance from the vertex to the specified clip plane