shithub: tinygl

Download patch

ref: a3cc2043c7aa88b779ff556d74d936aa06a36972
parent: 6a85da7f3569faa9c0048c2d44b03172f49b020b
author: David <gek@katherine>
date: Wed Feb 17 07:50:30 EST 2021

Perf improvement update

--- a/README.md
+++ b/README.md
@@ -192,6 +192,7 @@
 //NOTE: Polygon Offset does nothing at the moment.
 #define TGL_FEATURE_POLYGON_OFFSET 0
 #define TGL_FEATURE_POLYGON_STIPPLE 0
+#define TGL_FEATURE_BLEND 			1
 ```
 
 Change the dimensions of a polygon stipple pattern, and how it's interpreted.
--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -63,9 +63,6 @@
 
 	da = 2.0 * M_PI / teeth / 4.0;
 
-	//glShadeModel(GL_SMOOTH);
-	//glShadeModel(GL_FLAT);
-
 	glNormal3f(0.0, 0.0, 1.0);
 
 	/* draw front face */
@@ -149,7 +146,6 @@
 
 	glEnd();
 
-	// glShadeModel( GL_SMOOTH );
 
 	/* draw inside radius cylinder */
 	glBegin(GL_QUAD_STRIP);
@@ -211,7 +207,7 @@
 	
 	glEnable(GL_LIGHT0);
 	//glEnable(GL_DEPTH_TEST);
-	//glShadeModel( GL_SMOOTH );
+	
 
 	glEnable(GL_POLYGON_STIPPLE);
 	glPolygonStipple(stipplepattern);
@@ -246,10 +242,11 @@
 	int winSizeX = 640;
 	int winSizeY = 480;
 	unsigned int fps = 0;
+	unsigned int flat = 0;
 	char needsRGBAFix = 0;
-	if (argc > 2) {
-		char* larg = argv[1];
-		for (int i = 0; i < argc; i++) {
+	if (argc > 1) {
+		char* larg = "";
+		for (int i = 1; i < argc; i++) {
 			if (!strcmp(larg, "-w"))
 				winSizeX = atoi(argv[i]);
 			if (!strcmp(larg, "-h"))
@@ -256,6 +253,10 @@
 				winSizeY = atoi(argv[i]);
 			if (!strcmp(larg, "-fps"))
 				fps = strtoull(argv[i], 0, 10);
+			if (!strcmp(argv[i],"-flat"))
+				flat = 1;
+			if (!strcmp(argv[i],"-smooth"))
+				flat = 0;
 			larg = argv[i];
 		}
 	}
@@ -334,7 +335,7 @@
 	// initialize GL:
 	glClearColor(0.0, 0.0, 0.0, 0.0);
 	glViewport(0, 0, winSizeX, winSizeY);
-	glShadeModel(GL_SMOOTH);
+if(flat)	glShadeModel(GL_FLAT); else glShadeModel(GL_SMOOTH);
 //TESTING BLENDING...
 	//glDisable(GL_DEPTH_TEST);
 	glEnable(GL_DEPTH_TEST);
--- a/src/clip.c
+++ b/src/clip.c
@@ -190,7 +190,7 @@
 						GLfloat (*clip_proc[6])(V4*, V4*, V4*) = {clip_xmin, clip_xmax, clip_ymin, clip_ymax, clip_zmin, clip_zmax};
 
 static inline void updateTmp(GLContext* c, GLVertex* q, GLVertex* p0, GLVertex* p1, GLfloat t) {
-	if (c->current_shade_model == GL_SMOOTH) {
+	{
 		q->color.v[0] = p0->color.v[0] + (p1->color.v[0] - p0->color.v[0]) * t;
 		q->color.v[1] = p0->color.v[1] + (p1->color.v[1] - p0->color.v[1]) * t;
 		q->color.v[2] = p0->color.v[2] + (p1->color.v[2] - p0->color.v[2]) * t;
@@ -203,13 +203,6 @@
 		// tgl_warning("\n~\nNew Components are %f, %f, %f", q->color.v[0], q->color.v[1], q->color.v[2]);
 		// tgl_warning("\nZbuffer point r,g,b for new point are: %d %d %d",q->zp.r, q->zp.g,q->zp.b);
 		/// *
-	} else {
-		q->color.v[0] = p0->color.v[0];
-		q->color.v[1] = p0->color.v[1];
-		q->color.v[2] = p0->color.v[2];
-		q->zp.r = p0->zp.r;
-		q->zp.g = p0->zp.g;
-		q->zp.b = p0->zp.b;
 	}
 	//	*/
 	if (c->texture_2d_enabled) {
--- a/src/ztriangle.c
+++ b/src/ztriangle.c
@@ -37,13 +37,19 @@
 
 void ZB_fillTriangleFlat(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
 
-	PIXEL color; GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
+	PIXEL color = RGB_TO_PIXEL(p2->r, p2->g, p2->b); GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
 	TGL_BLEND_VARS
 	TGL_STIPPLEVARS
+
+#undef INTERP_Z
+#undef INTERP_RGB
+#undef INTERP_ST
+#undef INTERP_STZ
+
 #define INTERP_Z
 
 #define DRAW_INIT()                                                                                                                                            \
-	{ color = RGB_TO_PIXEL(p2->r, p2->g, p2->b); }
+	{  }
 
 #define PUT_PIXEL(_a)                                                                                                                                          \
 	{                                                                                                                                                          \
@@ -60,12 +66,16 @@
 
 void ZB_fillTriangleFlatNOBLEND(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
 
-	PIXEL color; GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
+	PIXEL color = RGB_TO_PIXEL(p2->r, p2->g, p2->b); GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
 	TGL_STIPPLEVARS
+#undef INTERP_Z
+#undef INTERP_RGB
+#undef INTERP_ST
+#undef INTERP_STZ
 #define INTERP_Z
 
 #define DRAW_INIT()                                                                                                                                            \
-	{ color = RGB_TO_PIXEL(p2->r, p2->g, p2->b); }
+	{  }
 
 #define PUT_PIXEL(_a)                                                                                                                                          \
 	{                                                                                                                                                          \
--- a/src/ztriangle.h
+++ b/src/ztriangle.h
@@ -3,7 +3,7 @@
  */
 
 {
-	ZBufferPoint *t, *pr1, *pr2, *l1, *l2;
+	ZBufferPoint *pr1, *pr2, *l1, *l2;
 	GLfloat fdx1, fdx2, fdy1, fdy2, fz, d1, d2;
 	GLushort* pz1;
 	PIXEL* pp1;
@@ -36,6 +36,8 @@
 #endif
 
 	/* we sort the vertex with increasing y */
+	{
+	ZBufferPoint *t;
 	if (p1->y < p0->y) {
 		t = p0;
 		p0 = p1;
@@ -51,6 +53,7 @@
 		p1 = p2;
 		p2 = t;
 	}
+	}
 
 	/* we compute dXdx and dXdy for all GLinterpolated values */
 
@@ -265,7 +268,6 @@
 #endif
 
 				n = (x2 >> 16) - x1;
-				/*the_x = x1; //Gek added this to make determining the X coordinate easier!*/
 				pp = (PIXEL*)((GLbyte*)pp1 + x1 * PSZB);
 #ifdef INTERP_Z
 				pz = pz1 + x1;