shithub: tinygl

Download patch

ref: 6a85da7f3569faa9c0048c2d44b03172f49b020b
parent: 968148ad548285cf8e63e97a4ee13d3054e7e407
author: David <gek@katherine>
date: Wed Feb 17 07:26:45 EST 2021

Perf boost when not using blending while blending is enabled in zfeatures

--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -63,7 +63,8 @@
 
 	da = 2.0 * M_PI / teeth / 4.0;
 
-	glShadeModel(GL_SMOOTH);
+	//glShadeModel(GL_SMOOTH);
+	//glShadeModel(GL_FLAT);
 
 	glNormal3f(0.0, 0.0, 1.0);
 
@@ -210,7 +211,7 @@
 	
 	glEnable(GL_LIGHT0);
 	//glEnable(GL_DEPTH_TEST);
-	// glShadeModel( GL_SMOOTH );
+	//glShadeModel( GL_SMOOTH );
 
 	glEnable(GL_POLYGON_STIPPLE);
 	glPolygonStipple(stipplepattern);
@@ -333,6 +334,7 @@
 	// initialize GL:
 	glClearColor(0.0, 0.0, 0.0, 0.0);
 	glViewport(0, 0, winSizeX, winSizeY);
+	glShadeModel(GL_SMOOTH);
 //TESTING BLENDING...
 	//glDisable(GL_DEPTH_TEST);
 	glEnable(GL_DEPTH_TEST);
@@ -340,12 +342,12 @@
 	//glEnable(GL_BLEND);
 	glDisable(GL_BLEND);
 	
-	//glDepthMask(GL_FALSE);
 	glDepthMask(GL_TRUE);
+	//glDepthMask(GL_FALSE);
 
 	//glDisable( GL_LIGHTING );
 	glEnable(GL_LIGHTING);
-	glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_ONE_MINUS_DST_COLOR);
+	glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_ZERO);
 	glBlendEquation(GL_FUNC_ADD);
 	GLfloat h = (GLfloat)winSizeY / (GLfloat)winSizeX;
 	glMatrixMode(GL_PROJECTION);
--- a/include/zbuffer.h
+++ b/include/zbuffer.h
@@ -91,17 +91,14 @@
 
 
 #if TGL_FEATURE_BLEND == 1
+#define TGL_BLEND_VARS GLuint zbblendeq = zb->blendeq; GLuint sfactor = zb->sfactor; GLuint dfactor = zb->dfactor;
 #define TGL_NO_BLEND_FUNC(source, dest){dest = source;}
 #define TGL_NO_BLEND_FUNC_RGB(rr, gg, bb, dest){dest = RGB_TO_PIXEL(rr,gg,bb);}
 //SORCERY to achieve 32 bit signed integer clamping
-//#define TGL_IGTZ(imp) ((imp>>31) == 0)
-//#define TGL_ILT(imp) ((imp & 0x10000) != 0x10000)
-//#define TGL_INLT(imp) ((imp & 0x10000) == 0x10000)
-//#define TGL_CLAMPI(imp) ( TGL_IGTZ(imp)*( TGL_ILT(imp) * imp + !TGL_INLT(imp) * 65535)  )
-#define TGL_CLAMPI(imp) ( (imp<0)?0:((imp>65535)?65535:imp) )
+#define TGL_CLAMPI(imp) ( (imp>0) * (65535 * (imp>65535) + imp * (!(imp>65535)) )      )
 
 #define TGL_BLEND_SWITCH_CASE(sr,sg,sb,dr,dg,db,dest) 									\
-		switch(zb->blendeq){															\
+		switch(zbblendeq){															\
 			case GL_FUNC_ADD:															\
 			default:																	\
 				sr+=dr;sg+=dg;sb+=db;													\
@@ -131,9 +128,7 @@
 
 
 #define TGL_BLEND_FUNC(source, dest){													\
-	if(zb->enable_blend != 1){															\
-		TGL_NO_BLEND_FUNC(source,dest)													\
-	} else {																			\
+	{																					\
 	GLuint sr, sg, sb, dr, dg, db;														\
 	{	GLuint t = source;																\
 	sr = GET_REDDER(t); sg = GET_GREENER(t); sb = GET_BLUEER(t);						\
@@ -140,7 +135,7 @@
 	t = dest;																			\
 	dr = GET_REDDER(t); dg = GET_GREENER(t); db = GET_BLUEER(t);}						\
 		/*printf("\nShould never reach this point!");*/									\
-		switch(zb->sfactor){															\
+		switch(sfactor){															\
 			case GL_ONE:																\
 			default:																	\
 			break;																		\
@@ -153,7 +148,7 @@
 			sr=0;sg=0;sb=0;break;														\
 			break;																		\
 		}																				\
-		switch(zb->dfactor){															\
+		switch(dfactor){															\
 				case GL_ONE:															\
 				default:																\
 				break;																	\
@@ -171,14 +166,12 @@
 } ///////////////////////////////////////////////////////////////////////////////////////
 
 #define TGL_BLEND_FUNC_RGB(rr, gg, bb, dest){											\
-	if(zb->enable_blend != 1){															\
-		TGL_NO_BLEND_FUNC_RGB(rr,gg,bb,dest)											\
-	} else {																			\
+	{																					\
 		GLint sr = rr & 0xFFFF, sg = gg & 0xFFFF, sb = bb & 0xFFFF, dr, dg, db;			\
 		{GLuint t = dest;																\
 		dr = GET_REDDER(t); dg = GET_GREENER(t); db = GET_BLUEER(t);}					\
 	/*printf("\nShould never reach this point!");*/										\
-		switch(zb->sfactor){															\
+		switch(sfactor){																\
 			case GL_ONE:																\
 			default:																	\
 			break;																		\
@@ -191,7 +184,7 @@
 			sr=0;sg=0;sb=0;break;														\
 			break;																		\
 		}																				\
-		switch(zb->dfactor){															\
+		switch(dfactor){															\
 				case GL_ONE:															\
 				default:																\
 				break;																	\
@@ -209,6 +202,7 @@
 } ///////////////////////////////////////////////////////////////////////////////////////
 
 #else
+#define TGL_BLEND_VARS /* a comment */
 #define TGL_BLEND_FUNC(source, dest){dest = source;}
 #define TGL_BLEND_FUNC_RGB(rr, gg, bb, dest){dest = RGB_TO_PIXEL(rr,gg,bb);}
 #endif
@@ -288,9 +282,15 @@
 void ZB_fillTriangleFlat(ZBuffer *zb,
 		 ZBufferPoint *p1,ZBufferPoint *p2,ZBufferPoint *p3);
 
+void ZB_fillTriangleFlatNOBLEND(ZBuffer *zb,
+		 ZBufferPoint *p1,ZBufferPoint *p2,ZBufferPoint *p3);
+
+
 void ZB_fillTriangleSmooth(ZBuffer *zb,
 		   ZBufferPoint *p1,ZBufferPoint *p2,ZBufferPoint *p3);
 
+void ZB_fillTriangleSmoothNOBLEND(ZBuffer *zb,
+		   ZBufferPoint *p1,ZBufferPoint *p2,ZBufferPoint *p3);
 /*
 This function goes unused and is removed by Gek.
 void ZB_fillTriangleMapping(ZBuffer *zb,
@@ -299,6 +299,9 @@
 void ZB_fillTriangleMappingPerspective(ZBuffer *zb,
                     ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2);
 
+
+void ZB_fillTriangleMappingPerspectiveNOBLEND(ZBuffer *zb,
+                    ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2);
 
 typedef void (*ZB_fillTriangleFunc)(ZBuffer  *,
 	    ZBufferPoint *,ZBufferPoint *,ZBufferPoint *);
--- a/src/clip.c
+++ b/src/clip.c
@@ -403,11 +403,34 @@
 		count_triangles_textured++;
 #endif
 		ZB_setTexture(c->zb, c->current_texture->images[0].pixmap);
-		ZB_fillTriangleMappingPerspective(c->zb, &p0->zp, &p1->zp, &p2->zp);
+#if TGL_FEATURE_BLEND == 1
+		if(c->zb->enable_blend) 
+			ZB_fillTriangleMappingPerspective(c->zb, &p0->zp, &p1->zp, &p2->zp);
+		else 
+			ZB_fillTriangleMappingPerspectiveNOBLEND(c->zb, &p0->zp, &p1->zp, &p2->zp);
+#else
+		ZB_fillTriangleMappingPerspectiveNOBLEND(c->zb, &p0->zp, &p1->zp, &p2->zp);
+#endif
 	} else if (c->current_shade_model == GL_SMOOTH) {
-		ZB_fillTriangleSmooth(c->zb, &p0->zp, &p1->zp, &p2->zp);
+		//ZB_fillTriangleSmooth(c->zb, &p0->zp, &p1->zp, &p2->zp);
+		#if TGL_FEATURE_BLEND == 1
+				if(c->zb->enable_blend) 
+					ZB_fillTriangleSmooth(c->zb, &p0->zp, &p1->zp, &p2->zp);
+				else 
+					ZB_fillTriangleSmoothNOBLEND(c->zb, &p0->zp, &p1->zp, &p2->zp);
+		#else
+				ZB_fillTriangleSmoothNOBLEND(c->zb, &p0->zp, &p1->zp, &p2->zp);
+		#endif
 	} else {
 		ZB_fillTriangleFlat(c->zb, &p0->zp, &p1->zp, &p2->zp);
+		#if TGL_FEATURE_BLEND == 1
+				if(c->zb->enable_blend) 
+					ZB_fillTriangleFlat(c->zb, &p0->zp, &p1->zp, &p2->zp);
+				else 
+					ZB_fillTriangleFlatNOBLEND(c->zb, &p0->zp, &p1->zp, &p2->zp);
+		#else
+				ZB_fillTriangleFlatNOBLEND(c->zb, &p0->zp, &p1->zp, &p2->zp);
+		#endif
 	}
 }
 
--- a/src/zline.c
+++ b/src/zline.c
@@ -1,7 +1,7 @@
 #include "../include/zbuffer.h"
 #include <stdlib.h>
 
-#define ZCMP(z, zpix) (!(zb->depth_test) || z >= (zpix))
+#define ZCMP(z, zpix) (!(zbdt) || z >= (zpix))
 
 /* TODO: Implement blending for lines.*/
 
@@ -9,6 +9,9 @@
 	GLushort* pz;
 	PIXEL* pp;
 	GLint zz;
+	GLubyte zbdw = zb->depth_write; 
+	GLubyte zbdt = zb->depth_test;
+	TGL_BLEND_VARS
 	//	PIXEL col;
 	pz = zb->zbuf + (p->y * zb->xsize + p->x);
 	pp = (PIXEL*)((GLbyte*)zb->pbuf + zb->linesize * p->y + p->x * PSZB);
@@ -16,7 +19,7 @@
 	if (ZCMP(zz, *pz)) {
 		//*pp =
 		TGL_BLEND_FUNC_RGB(p->r, p->g, p->b, (*pp))
-		if(zb->depth_write)
+		if(zbdw)
 			*pz = zz;
 	}
 }
@@ -23,6 +26,8 @@
 
 #define INTERP_Z
 static void ZB_line_flat_z(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2, GLint color) {
+	//GLubyte zbdw = zb->depth_write; 
+	GLubyte zbdt = zb->depth_test;
 #include "zline.h"
 }
 
@@ -30,6 +35,8 @@
 #define INTERP_Z
 #define INTERP_RGB
 static void ZB_line_interp_z(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2) {
+	//GLubyte zbdw = zb->depth_write;
+	GLubyte zbdt = zb->depth_test;
 #include "zline.h"
 }
 
@@ -36,17 +43,20 @@
 /* no Z GLinterpolation */
 
 static void ZB_line_flat(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2, GLint color) {
+	//GLubyte zbdw = zb->depth_write; 
+	//GLubyte zbdt = zb->depth_test;
 #include "zline.h"
 }
 
 #define INTERP_RGB
 static void ZB_line_interp(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2) {
+//	GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
 #include "zline.h"
 }
 
 void ZB_line_z(ZBuffer* zb, ZBufferPoint* p1, ZBufferPoint* p2) {
 	GLint color1, color2;
-
+//	GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
 	color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
 	color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
 
--- a/src/ztriangle.c
+++ b/src/ztriangle.c
@@ -10,15 +10,17 @@
 
 #if TGL_FEATURE_POLYGON_STIPPLE
 
+#define TGL_STIPPLEVARS GLubyte* zbstipplepattern = zb->stipplepattern; GLubyte zbdostipple = zbdostipple;
 #define THE_X (((GLushort)(pp - pp1)))
 #define XSTIP(_a) ((THE_X + _a) & TGL_POLYGON_STIPPLE_MASK_X)
 #define YSTIP (the_y & TGL_POLYGON_STIPPLE_MASK_Y)
 // NOTES                                                           Divide by 8 to get the byte        Get the actual bit
-#define STIPBIT(_a) (zb->stipplepattern[(XSTIP(_a) | (YSTIP << TGL_POLYGON_STIPPLE_POW2_WIDTH)) >> 3] & (1 << (XSTIP(_a) & 7)))
-#define STIPTEST(_a) !(zb->dostipple && !STIPBIT(_a))
+#define STIPBIT(_a) (zbstipplepattern[(XSTIP(_a) | (YSTIP << TGL_POLYGON_STIPPLE_POW2_WIDTH)) >> 3] & (1 << (XSTIP(_a) & 7)))
+#define STIPTEST(_a) !(zbdostipple && !STIPBIT(_a))
 
 #else
 
+#define TGL_STIPPLEVARS /* a comment */
 #define STIPTEST(_a) (1)
 //#define ZCMP(z,zpix,_a) ((z) >= (zpix))
 
@@ -30,13 +32,14 @@
 #define NODRAWTEST(c) (1)
 #endif
 
-#define ZCMP(z, zpix, _a, c) ( ((!zb->depth_test) || (z) >= (zpix)) && STIPTEST(_a) && NODRAWTEST(c))
-#define ZCMPSIMP(z, zpix, _a, c) ( ((!zb->depth_test) || (z) >= (zpix)) && STIPTEST(_a))
+#define ZCMP(z, zpix, _a, c) ( ((!zbdt) || (z) >= (zpix)) && STIPTEST(_a) && NODRAWTEST(c))
+#define ZCMPSIMP(z, zpix, _a, c) ( ((!zbdt) || (z) >= (zpix)) && STIPTEST(_a))
 
 void ZB_fillTriangleFlat(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
 
-	PIXEL color;
-
+	PIXEL color; GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
+	TGL_BLEND_VARS
+	TGL_STIPPLEVARS
 #define INTERP_Z
 
 #define DRAW_INIT()                                                                                                                                            \
@@ -47,7 +50,7 @@
 		zz = z >> ZB_POINT_Z_FRAC_BITS;                                                                                                                        \
 		if (ZCMPSIMP(zz, pz[_a], _a, color)) {                                                                                                                 \
 			TGL_BLEND_FUNC(color, (pp[_a])) /*pp[_a] = color;*/                                                                                                \
-			if(zb->depth_write)pz[_a] = zz;                                                                                                                                       \
+			if(zbdw)pz[_a] = zz;                                                                                                                                       \
 		}                                                                                                                                                      \
 		z += dzdx;                                                                                                                                             \
 	}
@@ -55,6 +58,28 @@
 #include "ztriangle.h"
 }
 
+void ZB_fillTriangleFlatNOBLEND(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
+
+	PIXEL color; GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
+	TGL_STIPPLEVARS
+#define INTERP_Z
+
+#define DRAW_INIT()                                                                                                                                            \
+	{ color = RGB_TO_PIXEL(p2->r, p2->g, p2->b); }
+
+#define PUT_PIXEL(_a)                                                                                                                                          \
+	{                                                                                                                                                          \
+		zz = z >> ZB_POINT_Z_FRAC_BITS;                                                                                                                        \
+		if (ZCMPSIMP(zz, pz[_a], _a, 0)) {                                                                                                                 		\
+			pp[_a] = color;                                                                                                										\
+			if(zbdw)pz[_a] = zz;                                                                                            									\
+		}                                                                                                                                                      \
+		z += dzdx;                                                                                                                                             \
+	}
+
+#include "ztriangle.h"
+}
+
 /*
  * Smooth filled triangle.
  * The code below is very tricky :)
@@ -64,6 +89,9 @@
 #if TGL_FEATURE_NO_DRAW_COLOR == 1
 	PIXEL c;
 #endif
+	GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
+	TGL_BLEND_VARS
+	TGL_STIPPLEVARS
 // GLuint color;
 #define INTERP_Z
 #define INTERP_RGB
@@ -81,7 +109,7 @@
 		if (ZCMPSIMP(zz, pz[_a], _a, 0)) {                                                                                                                     \
 			/*pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);*/                                                                                                          \
 			TGL_BLEND_FUNC_RGB(or1, og1, ob1, (pp[_a]));                                                                                                       \
-			if(zb->depth_write)pz[_a] = zz;                                                                                                                                       \
+			if(zbdw)pz[_a] = zz;                                                                                                                               \
 		}                                                                                                                                                      \
 		z += dzdx;                                                                                                                                             \
 		og1 += dgdx;                                                                                                                                           \
@@ -96,7 +124,7 @@
 		if (ZCMPSIMP(zz, pz[_a], _a, 0)) {                                                                                                                     \
 			/*pp[_a] = c;*/                                                                                                                                    \
 			TGL_BLEND_FUNC_RGB(or1, og1, ob1, (pp[_a]));                                                                                                       \
-			if(zb->depth_write)pz[_a] = zz;                                                                                                                                       \
+			if(zbdw)pz[_a] = zz;                                                                                                                                       \
 		}                                                                                                                                                      \
 		z += dzdx;                                                                                                                                             \
 		og1 += dgdx;                                                                                                                                           \
@@ -132,8 +160,8 @@
 		if (ZCMPSIMP(zz, pz[_a], _a, 0)) {                                                                                                                     \
 			/*pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);*/                                                                                                          \
 			TGL_BLEND_FUNC_RGB(or1, og1, ob1, (pp[_a]));                                                                                                       \
-			                                                                                                                                                  \
-			if(zb->depth_write)pz[_a] = zz;                                                                                                                   \
+			                                                                                                                                                   \
+			if(zbdw)pz[_a] = zz;                                                                                                                   				\
 		}                                                                                                                                                      \
 		z += dzdx;                                                                                                                                             \
 		og1 += dgdx;                                                                                                                                           \
@@ -148,7 +176,7 @@
 		if (ZCMPSIMP(zz, pz[_a], _a, c)) {                                                                                                                     \
 			/*pp[_a] = c;*/                                                                                                                                    \
 			TGL_BLEND_FUNC_RGB(or1, og1, ob1, (pp[_a]));                                                                                                       \
-			if(zb->depth_write) pz[_a] = zz;                                                                                                                   \
+			if(zbdw) pz[_a] = zz;                                                                                                                   \
 		}                                                                                                                                                      \
 		z += dzdx;                                                                                                                                             \
 		og1 += dgdx;                                                                                                                                           \
@@ -162,6 +190,119 @@
 #include "ztriangle.h"
 } // EOF smooth fill triangle
 
+
+
+
+
+void ZB_fillTriangleSmoothNOBLEND(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
+#if TGL_FEATURE_NO_DRAW_COLOR == 1
+	PIXEL c;
+#endif
+	GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
+	TGL_STIPPLEVARS
+// GLuint color;
+#define INTERP_Z
+#define INTERP_RGB
+
+#define SAR_RND_TO_ZERO(v, n) (v / (1 << n))
+
+#if TGL_FEATURE_RENDER_BITS == 32
+#define DRAW_INIT()                                                                                                                                            \
+	{}
+
+#if TGL_FEATURE_NO_DRAW_COLOR != 1
+#define PUT_PIXEL(_a)                                                                                                                                          \
+	{                                                                                                                                                          \
+		zz = z >> ZB_POINT_Z_FRAC_BITS;                                                                                                                        \
+		if (ZCMPSIMP(zz, pz[_a], _a, 0)) {                                                                                                                     \
+			pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);                                                                                                          		\
+			if(zbdw)pz[_a] = zz;                                                                                                                               \
+		}                                                                                                                                                      \
+		z += dzdx;                                                                                                                                             \
+		og1 += dgdx;                                                                                                                                           \
+		or1 += drdx;                                                                                                                                           \
+		ob1 += dbdx;                                                                                                                                           \
+	}
+#else
+#define PUT_PIXEL(_a)                                                                                                                                          \
+	{                                                                                                                                                          \
+		zz = z >> ZB_POINT_Z_FRAC_BITS;                                                                                                                        \
+		/*c = RGB_TO_PIXEL(or1, og1, ob1);*/                                                                                                                   \
+		if (ZCMPSIMP(zz, pz[_a], _a, 0)) {                                                                                                                     \
+			pp[_a] = RGB_TO_PIXEL(or1,og1,ob1);                                                                                                            		\
+			if(zbdw)pz[_a] = zz;                                                                                                                               \
+		}                                                                                                                                                      \
+		z += dzdx;                                                                                                                                             \
+		og1 += dgdx;                                                                                                                                           \
+		or1 += drdx;                                                                                                                                           \
+		ob1 += dbdx;                                                                                                                                           \
+	}
+#endif
+// END OF 32 bit mode
+#elif TGL_FEATURE_RENDER_BITS == 16
+
+#define DRAW_INIT()                                                                                                                                            \
+	{}
+
+	/*
+	#define PUT_PIXEL(_a)				\
+	{						\
+		zz=z >> ZB_POINT_Z_FRAC_BITS;		\
+		if (ZCMP(zz,pz[_a],_a)) {				\
+		  pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);\
+		  pz[_a]=zz;				\
+		}\
+		z+=dzdx;					\
+		og1+=dgdx;					\
+		or1+=drdx;					\
+		ob1+=dbdx;					\
+	}
+	*/
+
+#if TGL_FEATURE_NO_DRAW_COLOR != 1
+#define PUT_PIXEL(_a)                                                                                                                                          \
+	{                                                                                                                                                          \
+		zz = z >> ZB_POINT_Z_FRAC_BITS;                                                                                                                        \
+		if (ZCMPSIMP(zz, pz[_a], _a, 0)) {                                                                                                                     \
+			pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);                                                                                                          \
+			                                                                                                                                                   \
+			if(zbdw)pz[_a] = zz;                                                                                                                   				\
+		}                                                                                                                                                      \
+		z += dzdx;                                                                                                                                             \
+		og1 += dgdx;                                                                                                                                           \
+		or1 += drdx;                                                                                                                                           \
+		ob1 += dbdx;                                                                                                                                           \
+	}
+#else
+#define PUT_PIXEL(_a)                                                                                                                                          \
+	{                                                                                                                                                          \
+		zz = z >> ZB_POINT_Z_FRAC_BITS;                                                                                                                        \
+		/*c = RGB_TO_PIXEL(or1, og1, ob1);*/                                                                                                                   \
+		if (ZCMPSIMP(zz, pz[_a], _a, c)) {                                                                                                                     \
+			/*pp[_a] = c;*/                                                                                                                                    \
+			pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);                                                                                                       \
+			if(zbdw) pz[_a] = zz;                                                                                                                   \
+		}                                                                                                                                                      \
+		z += dzdx;                                                                                                                                             \
+		og1 += dgdx;                                                                                                                                           \
+		or1 += drdx;                                                                                                                                           \
+		ob1 += dbdx;                                                                                                                                           \
+	}
+#endif
+
+#endif
+//^ End of 16 bit mode stuff
+#include "ztriangle.h"
+} // EOF smooth fill triangle
+
+
+
+
+
+
+
+
+
 //
 //
 //			TEXTURE MAPPED TRIANGLES
@@ -225,6 +366,9 @@
 void ZB_fillTriangleMappingPerspective(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
 	PIXEL* texture;
 	GLfloat fdzdx, fndzdx, ndszdx, ndtzdx;
+	GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
+	TGL_BLEND_VARS
+	TGL_STIPPLEVARS
 #if TGL_FEATURE_NO_DRAW_COLOR == 1
 	PIXEL c;
 #endif
@@ -266,7 +410,7 @@
 		if (ZCMP(zz, pz[_a], _a, 0)) {                                                                                                                         \
 			/*pp[_a] = RGB_MIX_FUNC(or1, og1, ob1, *(PIXEL*)((GLbyte*)texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH))));*/                   \
 			TGL_BLEND_FUNC(RGB_MIX_FUNC(or1, og1, ob1, *(PIXEL*)((GLbyte*)texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)))), pp[_a])         \
-			if(zb->depth_write) pz[_a] = zz;                                                                                                                   \
+			if(zbdw) pz[_a] = zz;                                                                                                                   \
 		}                                                                                                                                                      \
 		z += dzdx;                                                                                                                                             \
 		s += dsdx;                                                                                                                                             \
@@ -281,7 +425,7 @@
 		if (ZCMP(zz, pz[_a], _a, c)) {                                                                                                                         \
 			/*pp[_a] = RGB_MIX_FUNC(or1, og1, ob1, c);*/                                                                                                       \
 			TGL_BLEND_FUNC(RGB_MIX_FUNC(or1, og1, ob1, c), (pp[_a]));                                                                                          \
-			if(zb->depth_write) pz[_a] = zz;                                                                                                                   \
+			if(zbdw) pz[_a] = zz;                                                                                                                   			\
 		}                                                                                                                                                      \
 		z += dzdx;                                                                                                                                             \
 		s += dsdx;                                                                                                                                             \
@@ -351,6 +495,147 @@
 
 #include "ztriangle.h"
 }
+
+
+
+
+
+
+
+void ZB_fillTriangleMappingPerspectiveNOBLEND(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
+	PIXEL* texture;
+	GLfloat fdzdx, fndzdx, ndszdx, ndtzdx;
+	GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
+	TGL_STIPPLEVARS
+#if TGL_FEATURE_NO_DRAW_COLOR == 1
+	PIXEL c;
+#endif
+#define INTERP_Z
+#define INTERP_STZ
+#define INTERP_RGB
+
+#define NB_INTERP 8
+
+#define DRAW_INIT()                                                                                                                                            \
+	{                                                                                                                                                          \
+		texture = zb->current_texture;                                                                                                                         \
+		fdzdx = (GLfloat)dzdx;                                                                                                                                 \
+		fndzdx = NB_INTERP * fdzdx;                                                                                                                            \
+		ndszdx = NB_INTERP * dszdx;                                                                                                                            \
+		ndtzdx = NB_INTERP * dtzdx;                                                                                                                            \
+	}
+#if TGL_FEATURE_LIT_TEXTURES == 1
+#define OR1OG1OB1DECL                                                                                                                                          \
+	register GLuint or1, og1, ob1;                                                                                                                             \
+	or1 = r1;                                                                                                                                                  \
+	og1 = g1;                                                                                                                                                  \
+	ob1 = b1;
+#define OR1G1B1INCR                                                                                                                                            \
+	og1 += dgdx;                                                                                                                                               \
+	or1 += drdx;                                                                                                                                               \
+	ob1 += dbdx;
+#else
+#define OR1OG1OB1DECL /*A comment*/
+#define OR1G1B1INCR   /*Another comment*/
+#define or1 0xffff
+#define og1 0xffff
+#define ob1 0xffff
+#endif
+#if TGL_FEATURE_NO_DRAW_COLOR != 1
+#define PUT_PIXEL(_a)                                                                                                                                          \
+	{                                                                                                                                                          \
+		zz = z >> ZB_POINT_Z_FRAC_BITS;                                                                                                                        \
+		if (ZCMP(zz, pz[_a], _a, 0)) {                                                                                                                         \
+			pp[_a] = RGB_MIX_FUNC(or1, og1, ob1, *(PIXEL*)((GLbyte*)texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH))));                   		\
+			if(zbdw) pz[_a] = zz;                                                                                                                   			\
+		}                                                                                                                                                      \
+		z += dzdx;                                                                                                                                             \
+		s += dsdx;                                                                                                                                             \
+		t += dtdx;                                                                                                                                             \
+		OR1G1B1INCR                                                                                                                                            \
+	}
+#else
+#define PUT_PIXEL(_a)                                                                                                                                          \
+	{                                                                                                                                                          \
+		zz = z >> ZB_POINT_Z_FRAC_BITS;                                                                                                                        \
+		c = *(PIXEL*)((GLbyte*)texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));                                                             \
+		if (ZCMP(zz, pz[_a], _a, c)) {                                                                                                                         \
+			pp[_a] = RGB_MIX_FUNC(or1, og1, ob1, c);                                                                                                       		\
+			/*TGL_BLEND_FUNC(RGB_MIX_FUNC(or1, og1, ob1, c), (pp[_a]));*/                                                                                          \
+			if(zbdw) pz[_a] = zz;                                                                                                                   			\
+		}                                                                                                                                                      \
+		z += dzdx;                                                                                                                                             \
+		s += dsdx;                                                                                                                                             \
+		t += dtdx;                                                                                                                                             \
+		OR1G1B1INCR                                                                                                                                            \
+	}
+#endif
+
+#define DRAW_LINE()                                                                                                                                            \
+	{                                                                                                                                                          \
+		register GLushort* pz;                                                                                                                                 \
+		register PIXEL* pp;                                                                                                                                    \
+		register GLuint s, t, z, zz;                                                                                                                           \
+		register GLint n, dsdx, dtdx;                                                                                                                          \
+		OR1OG1OB1DECL                                                                                                                                          \
+		GLfloat sz, tz, fz, zinv;                                                                                                                              \
+		n = (x2 >> 16) - x1;                                                                                                                                   \
+		fz = (GLfloat)z1;                                                                                                                                      \
+		zinv = 1.0 / fz;                                                                                                                                       \
+		pp = (PIXEL*)((GLbyte*)pp1 + x1 * PSZB);                                                                                                               \
+		pz = pz1 + x1;                                                                                                                                         \
+		z = z1;                                                                                                                                                \
+		sz = sz1;                                                                                                                                              \
+		tz = tz1;                                                                                                                                              \
+		while (n >= (NB_INTERP - 1)) {                                                                                                                         \
+			{                                                                                                                                                  \
+				GLfloat ss, tt;                                                                                                                                \
+				ss = (sz * zinv);                                                                                                                              \
+				tt = (tz * zinv);                                                                                                                              \
+				s = (GLint)ss;                                                                                                                                 \
+				t = (GLint)tt;                                                                                                                                 \
+				dsdx = (GLint)((dszdx - ss * fdzdx) * zinv);                                                                                                   \
+				dtdx = (GLint)((dtzdx - tt * fdzdx) * zinv);                                                                                                   \
+				fz += fndzdx;                                                                                                                                  \
+				zinv = 1.0 / fz;                                                                                                                               \
+			}                                                                                                                                                  \
+			PUT_PIXEL(0); /*the_x++;*/                                                                                                                         \
+			PUT_PIXEL(1); /*the_x++;*/                                                                                                                         \
+			PUT_PIXEL(2); /*the_x++;*/                                                                                                                         \
+			PUT_PIXEL(3); /*the_x++;*/                                                                                                                         \
+			PUT_PIXEL(4); /*the_x++;*/                                                                                                                         \
+			PUT_PIXEL(5); /*the_x++;*/                                                                                                                         \
+			PUT_PIXEL(6); /*the_x++;*/                                                                                                                         \
+			PUT_PIXEL(7); /*the_x-=7;*/                                                                                                                        \
+			pz += NB_INTERP;                                                                                                                                   \
+			pp = (PIXEL*)((GLbyte*)pp + NB_INTERP * PSZB); /*the_x+=NB_INTERP * PSZB;*/                                                                        \
+			n -= NB_INTERP;                                                                                                                                    \
+			sz += ndszdx;                                                                                                                                      \
+			tz += ndtzdx;                                                                                                                                      \
+		}                                                                                                                                                      \
+		{                                                                                                                                                      \
+			GLfloat ss, tt;                                                                                                                                    \
+			ss = (sz * zinv);                                                                                                                                  \
+			tt = (tz * zinv);                                                                                                                                  \
+			s = (GLint)ss;                                                                                                                                     \
+			t = (GLint)tt;                                                                                                                                     \
+			dsdx = (GLint)((dszdx - ss * fdzdx) * zinv);                                                                                                       \
+			dtdx = (GLint)((dtzdx - tt * fdzdx) * zinv);                                                                                                       \
+		}                                                                                                                                                      \
+		while (n >= 0) {                                                                                                                                       \
+			PUT_PIXEL(0); /*the_x += PSZB;*/                                                                                                                   \
+			pz += 1;                                                                                                                                           \
+			pp = (PIXEL*)((GLbyte*)pp + PSZB);                                                                                                                 \
+			n -= 1;                                                                                                                                            \
+		}                                                                                                                                                      \
+	}
+
+#include "ztriangle.h"
+}
+
+
+
+
 
 #endif // if 1