Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ option(PLUSH_BUILD_EXAMPLES "Build Plush Examples" ON)
option(PLUSH_USE_ASAN "Use Address Sanitizer" OFF)
set(PLUSH_MAX_LIGHTS "32" CACHE STRING "Maximum number of lights in a single render pass")
set(PLUSH_MAX_TRIANGLES "16384" CACHE STRING "Maximum number of triangles in a single render pass")
set(PLUSH_MAX_VERTICES "49152" CACHE STRING "Maximum number of vertices in a single render pass")
set(PLUSH_RESOURCE_ALIGNMENT "8" CACHE STRING "Byte alignment of resource memory allocations")

# asan
Expand Down
3 changes: 3 additions & 0 deletions cmake/pl_conf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ approximately 8*PL_MAX_TRIANGLES bytes of memory. i.e. the default of

#define PL_MAX_TRIANGLES (@PLUSH_MAX_TRIANGLES@)

/* Maximum number of vertices per scene */
#define PL_MAX_VERTICES (@PLUSH_MAX_VERTICES@)

/* Byte alignment of resource memory allocations */
#define PL_RESOURCE_ALIGNMENT (@PLUSH_RESOURCE_ALIGNMENT@)

Expand Down
46 changes: 34 additions & 12 deletions include/plush/pl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct _pl_Texture {
** Material type. Create materials with plMatCreate().
*/
typedef struct _pl_Face pl_Face;
typedef struct _pl_PrepFace pl_PrepFace;
typedef struct _pl_Cam pl_Cam;
typedef struct _pl_Mat {
int32_t Ambient[3]; /* RGB of surface (0-255 is a good range) */
Expand All @@ -61,7 +62,7 @@ typedef struct _pl_Mat {
uint16_t *_AddTable; /* Shading/Translucent/etc table */
uint8_t *_ReMapTable; /* Table to remap colors to palette */
uint8_t *_RequestedColors; /* _ColorsUsed colors, desired colors */
void (*_PutFace)(pl_Cam *, pl_Face *);
void (*_PutFace)(pl_Cam *, pl_PrepFace *);
/* Function that renders the triangle with this
material */
} pl_Mat;
Expand All @@ -71,13 +72,7 @@ typedef struct _pl_Mat {
*/
typedef struct _pl_Vertex {
float x, y, z; /* Vertex coordinate (objectspace) */
float xformedx, xformedy, xformedz;
/* Transformed vertex
coordinate (cameraspace) */
float nx, ny, nz; /* Unit vertex normal (objectspace) */
float xformednx, xformedny, xformednz;
/* Transformed unit vertex normal
(cameraspace) */
} pl_Vertex;

/*
Expand All @@ -87,16 +82,11 @@ typedef struct _pl_Face {
pl_Vertex *Vertices[3]; /* Vertices of triangle */
float nx, ny, nz; /* Normal of triangle (object space) */
pl_Mat *Material; /* Material of triangle */
int32_t Scrx[3], Scry[3]; /* Projected screen coordinates
(12.20 fixed point) */
float Scrz[3]; /* Projected 1/Z coordinates */
int32_t MappingU[3], MappingV[3];
/* 16.16 Texture mapping coordinates */
int32_t eMappingU[3], eMappingV[3];
/* 16.16 Environment map coordinates */
float fShade; /* Flat intensity */
float sLighting; /* Face static lighting. Should usually be 0.0 */
float Shades[3]; /* Vertex intensity */
float vsLighting[3]; /* Vertex static lighting. Should be 0.0 */
} pl_Face;

Expand Down Expand Up @@ -183,6 +173,38 @@ typedef struct _pl_Cam {
float *zBuffer; /* Z Buffer (NULL if none) */
} pl_Cam;

/*
** Prepared Vertex
*/
typedef struct _pl_PrepVertex {
pl_Vertex *Vertex; /* Source vertex */
float xformedx, xformedy, xformedz; /* Transformed vertex coordinate (cameraspace) */
float xformednx, xformedny, xformednz; /* Transformed unit vertex normal (cameraspace) */
} pl_PrepVertex;

/*
** Prepared Face
*/
typedef struct _pl_PrepFace {
pl_PrepVertex *Vertices[3]; /* Prepared vertices */
pl_Face *Face; /* Source face */
int32_t Scrx[3], Scry[3]; /* Projected screen coordinates (12.20 fixed point) */
float Scrz[3]; /* Projected 1/Z coordinates */
int32_t MappingU[3], MappingV[3]; /* 16.16 Texture mapping coordinates */
int32_t eMappingU[3], eMappingV[3]; /* 16.16 Environment map coordinates */
float Shades[3]; /* Vertex intensity */
float zd; /* Z distance from camera (when using no zbuffer) */
float fShade; /* Flat intensity */
} pl_PrepFace;

/*
** Prepared Light
*/
typedef struct _pl_PrepLight {
pl_Light *light;
float l[3];
} pl_PrepLight;

#ifdef __cplusplus
}
#endif
Expand Down
58 changes: 9 additions & 49 deletions include/plush/plush.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,46 +392,6 @@ int plObjEnumerate(pl_Obj *obj, int (*func)(pl_Obj *obj, void *user), void *user
*/
pl_Obj *plObjFind(pl_Obj *obj, const char *name);

/******************************************************************************
** Frustum Clipping Functions (clip.c)
******************************************************************************/

/*
plClipSetFrustum() sets up the clipping frustum.
Parameters:
cam: a camera allocated with plCamCreate().
Returns:
nothing
Notes:
Sets up the internal structures.
DO NOT CALL THIS ROUTINE FROM WITHIN A plRender*() block.
*/
void plClipSetFrustum(pl_Cam *cam);

/*
plClipRenderFace() renders a face and clips it to the frustum initialized
with plClipSetFrustum().
Parameters:
face: the face to render
Returns:
nothing
Notes: this is used internally by plRender*(), so be careful. Kinda slow too.
*/
void plClipRenderFace(pl_Face *face);

/*
plClipNeeded() decides whether the face is in the frustum, intersecting
the frustum, or completely out of the frustum craeted with
plClipSetFrustum().
Parameters:
face: the face to check
Returns:
0: the face is out of the frustum, no drawing necessary
1: the face is intersecting the frustum, splitting and drawing necessary
Notes: this is used internally by plRender*(), so be careful. Kinda slow too.
*/
int32_t plClipNeeded(pl_Face *face);

/******************************************************************************
** Light Handling Routines (light.c)
******************************************************************************/
Expand Down Expand Up @@ -978,15 +938,15 @@ void plTextPrintf(pl_Cam *cam, int32_t x, int32_t y, float z,
** Built-in Rasterizers
******************************************************************************/

void plPF_SolidF(pl_Cam *, pl_Face *);
void plPF_SolidG(pl_Cam *, pl_Face *);
void plPF_TexF(pl_Cam *, pl_Face *);
void plPF_TexG(pl_Cam *, pl_Face *);
void plPF_TexEnv(pl_Cam *, pl_Face *);
void plPF_PTexF(pl_Cam *, pl_Face *);
void plPF_PTexG(pl_Cam *, pl_Face *);
void plPF_TransF(pl_Cam *, pl_Face *);
void plPF_TransG(pl_Cam *, pl_Face *);
void plPF_SolidF(pl_Cam *, pl_PrepFace *);
void plPF_SolidG(pl_Cam *, pl_PrepFace *);
void plPF_TexF(pl_Cam *, pl_PrepFace *);
void plPF_TexG(pl_Cam *, pl_PrepFace *);
void plPF_TexEnv(pl_Cam *, pl_PrepFace *);
void plPF_PTexF(pl_Cam *, pl_PrepFace *);
void plPF_PTexG(pl_Cam *, pl_PrepFace *);
void plPF_TransF(pl_Cam *, pl_PrepFace *);
void plPF_TransG(pl_Cam *, pl_PrepFace *);

#ifdef __cplusplus
}
Expand Down
12 changes: 6 additions & 6 deletions source/clip.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Copyright (C) 2024-2025, erysdren (it/its)

typedef struct
{
pl_Vertex newVertices[8];
pl_PrepVertex newVertices[8];
double Shades[8];
double MappingU[8];
double MappingV[8];
Expand Down Expand Up @@ -110,10 +110,10 @@ void plClipSetFrustum(pl_Cam *cam) {
}


void plClipRenderFace(pl_Face *face) {
void plClipRenderFace(pl_PrepFace *face) {
uint32_t k, a, w, numVerts;
double tmp, tmp2;
pl_Face newface;
pl_PrepFace newface;

for (a = 0; a < 3; a ++) {
m_cl[0].newVertices[a] = *(face->Vertices[a]);
Expand All @@ -133,7 +133,7 @@ void plClipRenderFace(pl_Face *face) {
a++;
}
if (numVerts > 2) {
plMemCpy(&newface,face,sizeof(pl_Face));
plMemCpy(&newface, face, sizeof(pl_PrepFace));
for (k = 2; k < numVerts; k ++) {
newface.fShade = plMax(0,plMin(face->fShade,1));
for (a = 0; a < 3; a ++) {
Expand All @@ -152,14 +152,14 @@ void plClipRenderFace(pl_Face *face) {
newface.Scrx[a] = m_cx + ((int32_t)((tmp*(float) (1<<20))));
newface.Scry[a] = m_cy - ((int32_t)((tmp2*m_adj_asp*(float) (1<<20))));
}
newface.Material->_PutFace(m_cam,&newface);
newface.Face->Material->_PutFace(m_cam,&newface);
plRender_TriStats[3] ++;
}
plRender_TriStats[2] ++;
}
}

int32_t plClipNeeded(pl_Face *face) {
int32_t plClipNeeded(pl_PrepFace *face) {
double dr,dl,db,dt;
double f;
dr = (m_cam->ClipRight-m_cam->CenterX);
Expand Down
Loading