shithub: 3dee

Download patch

ref: 1aacac5b602d1f09b9b8ae74ca02a8060b75c406
parent: 80f3da5897e610dce9238d5b899a2b87e335e9da
author: rodri <rgl@antares-labs.eu>
date: Fri Feb 2 11:05:59 EST 2024

add profiling option. get rid of unnecessary vertex ops.

--- a/main.c
+++ b/main.c
@@ -45,15 +45,10 @@
 OBJ *model;
 Memimage *modeltex;
 Shader *shader;
-double θ, ω;
+double θ, ω = 2*DEG;
 
 Camera cams[4], *maincam;
 Camcfg camcfgs[4] = {
-//	2,0,-4,1,
-//	0,0,0,1,
-//	0,1,0,0,
-//	90*DEG, 0.1, 100, PERSPECTIVE,
-
 	2,0,-4,1,
 	0,0,0,1,
 	0,1,0,0,
@@ -64,11 +59,6 @@
 	0,1,0,0,
 	120*DEG, 0.1, 100, PERSPECTIVE,
 
-//	-2,0,4,1,
-//	0,0,0,1,
-//	0,1,0,0,
-//	90*DEG, 0.1, 100, PERSPECTIVE,
-
 	-2,0,4,1,
 	0,0,0,1,
 	0,1,0,0,
@@ -82,6 +72,8 @@
 Point3 center = {0,0,0,1};
 Point3 light = {0,1,1,1};	/* global point light */
 
+static int doprof;
+
 static int
 min(int a, int b)
 {
@@ -115,10 +107,8 @@
 {
 	sp->v->n = qrotate(sp->v->n, Vec3(0,1,0), θ+fmod(ω*sp->su->uni_time/1e9, 2*PI));
 	sp->su->var_intensity[sp->idx] = fmax(0, dotvec3(sp->v->n, light));
-	sp->v->n = world2vcs(maincam, sp->v->n);
 	sp->v->p = qrotate(sp->v->p, Vec3(0,1,0), θ+fmod(ω*sp->su->uni_time/1e9, 2*PI));
-	sp->v->p = world2clip(maincam, sp->v->p);
-	return sp->v->p;
+	return world2clip(maincam, sp->v->p);
 }
 
 Memimage *
@@ -455,6 +445,25 @@
 	nbsend(drawc, nil);
 }
 
+static void
+confproc(void)
+{
+	char buf[64];
+	int fd;
+
+	snprint(buf, sizeof buf, "/proc/%d/ctl", getpid());
+	fd = open(buf, OWRITE);
+	if(fd < 0)
+		sysfatal("open: %r");
+
+	if(doprof)
+		fprint(fd, "profile\n");
+//	fprint(fd, "pri 15\n");
+//	fprint(fd, "wired 0\n");
+
+	close(fd);
+}
+
 void
 usage(void)
 {
@@ -476,6 +485,7 @@
 	ARGBEGIN{
 	case 't': texpath = EARGF(usage()); break;
 	case 's': sname = EARGF(usage()); break;
+	case 'p': doprof++; break;
 	default: usage();
 	}ARGEND;
 	if(argc != 1)
@@ -482,6 +492,8 @@
 		usage();
 
 	mdlpath = argv[0];
+
+	confproc();
 
 	if((shader = getshader(sname)) == nil)
 		sysfatal("couldn't find %s shader", sname);