summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-07-13 15:18:19 +0000
committerrodri <rgl@antares-labs.eu>2024-07-13 15:18:19 +0000
commit82888bed1931e83ed1401485033cb9f7acdadc94 (patch)
treea481e076aa8ba6b28b30d1495061d4d7ff156512
parent04d50b8bbe324fdb7a8a1e724fbc59c4050862f0 (diff)
downloadlibgraphics-82888bed1931e83ed1401485033cb9f7acdadc94.tar.gz
libgraphics-82888bed1931e83ed1401485033cb9f7acdadc94.tar.bz2
libgraphics-82888bed1931e83ed1401485033cb9f7acdadc94.zip
enable culling and add a camera knob for it.
-rw-r--r--graphics.h25
-rw-r--r--render.c9
2 files changed, 19 insertions, 15 deletions
diff --git a/graphics.h b/graphics.h
index 47a41cd..132b57b 100644
--- a/graphics.h
+++ b/graphics.h
@@ -6,24 +6,27 @@ typedef enum {
} Projection;
enum {
- PPoint,
+ /* culling modes */
+ CullNone,
+ CullFront,
+ CullBack,
+
+ /* primitive types */
+ PPoint = 0,
PLine,
PTriangle,
-};
-enum {
- LIGHT_POINT,
+ /* light types */
+ LIGHT_POINT = 0,
LIGHT_DIRECTIONAL,
LIGHT_SPOT,
-};
-enum {
- RAWTexture, /* unmanaged */
+ /* texture formats */
+ RAWTexture = 0, /* unmanaged */
sRGBTexture,
-};
-enum {
- VAPoint,
+ /* vertex attribute types */
+ VAPoint = 0,
VANumber,
};
@@ -282,12 +285,12 @@ struct Camera
} clip;
Matrix3 proj; /* VCS to clip space xform */
Projection projtype;
+ int cullmode;
struct {
uvlong min, avg, max, acc, n, v;
uvlong nframes;
} stats;
-
struct {
Rendertime R[100], E[100], Tn[100], Rn[100];
int cur;
diff --git a/render.c b/render.c
index 3d980af..6937c92 100644
--- a/render.c
+++ b/render.c
@@ -377,7 +377,6 @@ tilerdurden(void *arg)
for(; np--; p++){
p->v[0].p = clip2ndc(p->v[0].p);
p->v[1].p = clip2ndc(p->v[1].p);
-
p->v[0].p = ndc2viewport(params->fb, p->v[0].p);
p->v[1].p = ndc2viewport(params->fb, p->v[1].p);
@@ -425,8 +424,10 @@ tilerdurden(void *arg)
p->v[2].p = clip2ndc(p->v[2].p);
/* culling */
-// if(isfacingback(*p))
-// goto skiptri;
+ switch(params->camera->cullmode){
+ case CullFront: if(!isfacingback(p)) goto skiptri; break;
+ case CullBack: if(isfacingback(p)) goto skiptri; break;
+ }
p->v[0].p = ndc2viewport(params->fb, p->v[0].p);
p->v[1].p = ndc2viewport(params->fb, p->v[1].p);
@@ -450,7 +451,7 @@ tilerdurden(void *arg)
task->p.v[2] = dupvertex(&p->v[2]);
sendp(taskchans[i], task);
}
-//skiptri:
+skiptri:
delvattrs(&p->v[0]);
delvattrs(&p->v[1]);
delvattrs(&p->v[2]);