shithub: tinygl

Download patch

ref: 81619731cbb51492b2b3b75812af6c893ec924fe
parent: db3e69fcd0fbb4939f7d9dd1c43e070f7982cae2
author: David <gek@katherine>
date: Fri Feb 12 11:55:07 EST 2021

TinyGL Per-Vertex Color now working properly in the Gears demo.

--- a/src/SDL_Examples/gears.c
+++ b/src/SDL_Examples/gears.c
@@ -181,32 +181,42 @@
 
 void initScene() {
     static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0 };
-    static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 };
-    static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 };
-    static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0 };
+    
+    static GLfloat red[4] = {1.0, 0.0, 0.0, 0.0 };
+    static GLfloat green[4] = {0.0, 1.0, 0.0, 0.0 };
+    static GLfloat blue[4] = {0.0, 0.0, 1.0, 0.0 };
+    static GLfloat white[4] = {10.0, 10.0, 10.0, 0.0 };
 
     glLightfv( GL_LIGHT0, GL_POSITION, pos );
+    glLightfv( GL_LIGHT0, GL_DIFFUSE, white);
+    //glLightfv( GL_LIGHT0, GL_AMBIENT, white);
+    glLightfv( GL_LIGHT0, GL_SPECULAR, white);
     glEnable( GL_CULL_FACE );
     glEnable( GL_LIGHTING );
+    //glDisable( GL_LIGHTING );
     glEnable( GL_LIGHT0 );
     glEnable( GL_DEPTH_TEST );
+    glShadeModel( GL_SMOOTH );
 	glTextSize(GL_TEXT_SIZE24x24);
     /* make the gears */
     gear1 = glGenLists(1);
     glNewList(gear1, GL_COMPILE);
-    glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red );
+    glMaterialfv( GL_FRONT, GL_DIFFUSE, blue );
+    //glColor3fv(red);
     gear( 1.0, 4.0, 1.0, 20, 0.7 );
     glEndList();
 
     gear2 = glGenLists(1);
     glNewList(gear2, GL_COMPILE);
-    glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );
+    glMaterialfv( GL_FRONT, GL_DIFFUSE, red );
+    //glColor3fv(green);
     gear( 0.5, 2.0, 2.0, 10, 0.7 );
     glEndList();
 
     gear3 = glGenLists(1);
     glNewList(gear3, GL_COMPILE);
-    glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue );
+    glMaterialfv( GL_FRONT, GL_DIFFUSE, green );
+    //glColor3fv(blue);
     gear( 1.3, 2.0, 0.5, 10, 0.7 );
     glEndList();
     glEnable( GL_NORMALIZE );
@@ -216,7 +226,7 @@
     // initialize SDL video:
     int winSizeX=640;
     int winSizeY=480;
-
+	unsigned int fps =0;
     if(argc > 2){
     	char* larg = argv[1];
     	for(int i = 0; i < argc; i++){
@@ -224,6 +234,8 @@
 				winSizeX = atoi(argv[i]);
     		if(!strcmp(larg,"-h"))
 				winSizeY = atoi(argv[i]);
+			if(!strcmp(larg,"-fps"))
+				fps = strtoull(argv[i],0,10);
 			larg = argv[i];
     	}
     }
@@ -233,10 +245,21 @@
     }
     ainit(0);
     SDL_Surface* screen = NULL;
-    if((screen=SDL_SetVideoMode( winSizeX, winSizeY, 32, SDL_SWSURFACE)) == 0 ) {
+    if((screen=SDL_SetVideoMode( winSizeX, winSizeY, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) == 0 ) {
         fprintf(stderr,"ERROR: Video mode set failed.\n");
         return 1;
     }
+    printf("\nRMASK IS %u",screen->format->Rmask);
+    printf("\nGMASK IS %u",screen->format->Gmask);
+    printf("\nBMASK IS %u",screen->format->Bmask);
+    printf("\nAMASK IS %u",screen->format->Amask);
+
+
+    printf("\nRSHIFT IS %u",screen->format->Rshift);
+    printf("\nGSHIFT IS %u",screen->format->Gshift);
+    printf("\nBSHIFT IS %u",screen->format->Bshift);
+    printf("\nASHIFT IS %u",screen->format->Ashift);
+    fflush(stdout);
     track* myTrack = NULL;
     myTrack = lmus("WWGW.mp3");
     mplay(myTrack, -1, 1000);
@@ -255,11 +278,13 @@
         pitch = screen->pitch;
         fprintf(stderr,"\nUnsupported by maintainer!!!");
         mode = ZB_MODE_5R6G5B;
+        return 1;
         break;
     case 24:
         pitch = ( screen->pitch * 2 ) / 3;
         fprintf(stderr,"\nUnsupported by maintainer!!!");
         mode = ZB_MODE_RGB24;
+        return 1;
         break;
     case 32:
         pitch = screen->pitch / 2;
@@ -328,16 +353,33 @@
         // draw scene:
         glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
         draw();
-		glDrawText((unsigned char*)"\nBlitting text\nto the screen!", 0, 0, 0x00FFffFF);
+		glDrawText((unsigned char*)"\nBlitting text\nto the screen!", 0, 0, 0x000000FF);
         // swap buffers:
         if ( SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen)<0) ) {
             fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
             return 1;
         }
+        /*
+		printf("\nRMASK IS %u",screen->format->Rmask);
+		printf("\nGMASK IS %u",screen->format->Gmask);
+		printf("\nBMASK IS %u",screen->format->Bmask);
+		printf("\nAMASK IS %u",screen->format->Amask);
+        */
+        //Quickly convert all pixels to the correct format
+        for(int i = 0; i < frameBuffer->xsize* frameBuffer->ysize;i++){
+#define DATONE (frameBuffer->pbuf[i])
+			DATONE = ((DATONE & 0x000000FF)     ) << screen->format->Rshift | 
+					 ((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
+					 ((DATONE & 0x00FF0000) >>16) << screen->format->Bshift;
+        }
         ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
         if ( SDL_MUSTLOCK(screen) ) SDL_UnlockSurface(screen);
         SDL_Flip(screen);
-
+        if(fps>0)
+			if((1000/fps)>(SDL_GetTicks()-tNow))
+			{
+				SDL_Delay((1000/fps)-(SDL_GetTicks()-tNow)); //Yay stable framerate!
+			}
         // check for error conditions:
         char* sdl_error = SDL_GetError( );
         if( sdl_error[0] != '\0' ) {
--- a/src/api.c
+++ b/src/api.c
@@ -61,6 +61,7 @@
   p[3].f=b;
   p[4].f=a;
   /* direct convertion to integer to go faster if no shading */
+  /*
   p[5].ui = (unsigned int) (r * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) + 
                             ZB_POINT_RED_MIN);
   p[6].ui = (unsigned int) (g * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) + 
@@ -67,6 +68,10 @@
                             ZB_POINT_GREEN_MIN);
   p[7].ui = (unsigned int) (b * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) + 
                             ZB_POINT_BLUE_MIN);
+  */
+  p[5].ui = (((unsigned int)(r * 65535)) & 65535);
+  p[6].ui = (((unsigned int)(g * 65535)) & 65535);
+  p[7].ui = (((unsigned int)(b * 65535)) & 65535);
   gl_add_op(p);
 }
 
@@ -80,6 +85,7 @@
   p[3].f=v[2];
   p[4].f=v[3];
   /* direct convertion to integer to go faster if no shading */
+  /*
   p[5].ui = (unsigned int) (v[0] * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) + 
                             ZB_POINT_RED_MIN);
   p[6].ui = (unsigned int) (v[1] * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) + 
@@ -86,6 +92,11 @@
                             ZB_POINT_GREEN_MIN);
   p[7].ui = (unsigned int) (v[2] * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) + 
                             ZB_POINT_BLUE_MIN);
+  */
+  p[5].ui = (((unsigned int)(v[0] * 65535)) & 65535);
+  p[6].ui = (((unsigned int)(v[1] * 65535)) & 65535);
+  p[7].ui = (((unsigned int)(v[2] * 65535)) & 65535);
+  
   gl_add_op(p);
 }
 
--- a/src/clip.c
+++ b/src/clip.c
@@ -24,25 +24,31 @@
                    + c->viewport.trans.Z );
   /* color */
   if (c->lighting_enabled) {
-      v->zp.r=(int)(v->color.v[0] * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) 
-                    + ZB_POINT_RED_MIN);
-      v->zp.g=(int)(v->color.v[1] * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) 
-                    + ZB_POINT_GREEN_MIN);
-      v->zp.b=(int)(v->color.v[2] * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) 
-                    + ZB_POINT_BLUE_MIN);
+  	
+      v->zp.r=(unsigned int)(v->color.v[0] * 65535) & 65535;
+      v->zp.g=(unsigned int)(v->color.v[1] * 65535) & 65535;
+      v->zp.b=(unsigned int)(v->color.v[2] * 65535) & 65535;
   } else {
       /* no need to convert to integer if no lighting : take current color */
       /* OLD CODE
-      v->zp.r = c->longcurrent_color[0];
-      v->zp.g = c->longcurrent_color[1];
-      v->zp.b = c->longcurrent_color[2]; */
-      //NEW CODE
-      v->zp.r=(int)(v->color.v[0] * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) 
+      v->zp_r = c->longcurrent_color[0]; //MARKED, NOT USED
+      v->zp.g = c->longcurrent_color[1]; //MARKED, NOT USED
+      v->zp.b = c->longcurrent_color[2]; //MARKED, NOT USED
+
+      */
+      /*
+      v->zp_r=(int)(v->color.v[0] * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) 
                           + ZB_POINT_RED_MIN);
       v->zp.g=(int)(v->color.v[1] * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) 
                     + ZB_POINT_GREEN_MIN);
       v->zp.b=(int)(v->color.v[2] * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) 
                     + ZB_POINT_BLUE_MIN);
+      */
+      //printf("\nRECEIVED COLOR %f, %f, %f, %f", v->color.v[0], v->color.v[1], v->color.v[2], v->color.v[3]);
+      v->zp.r=(unsigned int)(v->color.v[0] * 65535) & 65535;
+      v->zp.g=(unsigned int)(v->color.v[1] * 65535) & 65535;
+      v->zp.b=(unsigned int)(v->color.v[2] * 65535) & 65535;
+      //printf("\nCOLORS ARE %d, %d, %d", v->zp.r,v->zp.g,v->zp.b);
   }
   
   /* texture */
--- a/src/image_util.c
+++ b/src/image_util.c
@@ -18,6 +18,8 @@
   }
 }
 
+//This actually converts to ABGR!!!
+//This is the format of the entire engine!!!
 void gl_convertRGB_to_8A8R8G8B(unsigned int *pixmap, unsigned char *rgb,
                                int xsize, int ysize)
 {
@@ -29,7 +31,7 @@
     for(i=0;i<n;i++) {
         pixmap[i]=(((unsigned int)p[2])<<16) | 
             (((unsigned int)p[1])<<8) | 
-            (((unsigned int)p[0])); 
+            (((unsigned int)p[0]) ); 
         p+=3;
     }
 }
--- a/src/init.c
+++ b/src/init.c
@@ -105,10 +105,11 @@
   c->current_color.X=1.0;
   c->current_color.Y=1.0;
   c->current_color.Z=1.0;
-  c->current_color.W=1.0;
-  c->longcurrent_color[0] = 65535;
-  c->longcurrent_color[1] = 65535;
-  c->longcurrent_color[2] = 65535;
+  c->current_color.W=0.0;
+  //Shouldn't ever be used.
+  c->longcurrent_color[0] = 65280;
+  c->longcurrent_color[1] = 65280;
+  c->longcurrent_color[2] = 65280;
 
   c->current_normal.X=1.0;
   c->current_normal.Y=0.0;
--- a/src/light.c
+++ b/src/light.c
@@ -5,7 +5,11 @@
 {
   int mode=p[1].i;
   int type=p[2].i;
-  float *v=&p[3].f;
+  float v[4]; 
+  v[0]= p[3].f;
+  v[1]= p[4].f;
+  v[2]= p[5].f;
+  v[3]= p[6].f;
   int i;
   GLMaterial *m;
 
@@ -25,10 +29,19 @@
   case GL_AMBIENT:
     for(i=0;i<4;i++)
       m->ambient.v[i]=v[i];
+    //c->current_color.X=v[0];
+    //c->current_color.Y=v[1];
+    //c->current_color.Z=v[2];
+    //c->current_color.W=v[3];
     break;
   case GL_DIFFUSE:
     for(i=0;i<4;i++)
       m->diffuse.v[i]=v[i];
+
+    //c->current_color.X=v[0];
+    //c->current_color.Y=v[1];
+    //c->current_color.Z=v[2];
+    //c->current_color.W=v[3];
     break;
   case GL_SPECULAR:
     for(i=0;i<4;i++)
@@ -39,12 +52,22 @@
     m->shininess_i = (v[0]/128.0f)*SPECULAR_BUFFER_RESOLUTION;
     break;
   case GL_AMBIENT_AND_DIFFUSE:
+  printf("\nRECEIVED AMBIENT AND DIFFUSE COLOR %f, %f, %f, %f", v[0], v[1], v[2], v[3]);
     for(i=0;i<4;i++)
       m->diffuse.v[i]=v[i];
+    //c->current_color.X=v[0];
+    //c->current_color.Y=v[1];
+    //c->current_color.Z=v[2];
+    //c->current_color.W=v[3];
+    
     for(i=0;i<4;i++)
       m->ambient.v[i]=v[i];
     break;
   default:
+    c->current_color.X=v[0];
+    c->current_color.Y=v[1];
+    c->current_color.Z=v[2];
+    c->current_color.W=v[3];
     assert(0);
   }
 }
@@ -307,6 +330,6 @@
   v->color.v[0]=clampf(R,0,1);
   v->color.v[1]=clampf(G,0,1);
   v->color.v[2]=clampf(B,0,1);
-  v->color.v[3]=A;
+  v->color.v[3]=clampf(A,0,1);
 }
 
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -34,9 +34,9 @@
     c->current_color.Y = p[2].f;
     c->current_color.Z = p[3].f;
     c->current_color.W = p[4].f;
-    c->longcurrent_color[0] = p[5].ui;
-    c->longcurrent_color[1] = p[6].ui;
-    c->longcurrent_color[2] = p[7].ui;
+    c->longcurrent_color[0] = p[5].ui; //MARKED
+    c->longcurrent_color[1] = p[6].ui; //MARKED
+    c->longcurrent_color[2] = p[7].ui; //MARKED
 
     if (c->color_material_enabled) {
 	GLParam q[7];
@@ -241,11 +241,14 @@
     /* color */
 
     if (c->lighting_enabled) {
-	gl_shade_vertex(c, v);
+		gl_shade_vertex(c, v);
     } else {
-	v->color = c->current_color;
+		v->color = c->current_color;
     }
-
+	/* Added by Gek to fix bug with rendering*/
+		v->zp.r=(unsigned int)(v->color.v[0] * 65535) & 65535;
+		v->zp.g=(unsigned int)(v->color.v[1] * 65535) & 65535;
+		v->zp.b=(unsigned int)(v->color.v[2] * 65535) & 65535;
     /* tex coords */
 
     if (c->texture_2d_enabled) {
--- a/src/zbuffer.c
+++ b/src/zbuffer.c
@@ -114,6 +114,37 @@
     }
 }
 
+
+inline PIXEL pxReverse(PIXEL x)
+{
+
+    return
+    // Source is in format: 0xAARRGGBB
+        ((x & 0xFF000000) >> 24) | //______AA
+        ((x & 0x00FF0000) >>  8) | //____RR__
+        ((x & 0x0000FF00) <<  8) | //__GG____
+        ((x & 0x000000FF) << 24);  //BB______
+    // Return value is in format:  0xBBGGRRAA
+}
+
+inline PIXEL pxARGB(PIXEL x)
+{
+
+    return
+    // Source is in format: 0xAABBGGRR
+        ((x & 0xFF000000) >>  0) | //______BB
+        ((x & 0x00FF0000) >> 16) | //____RR__
+        ((x & 0x0000FF00) <<  0) | //__GG____
+        ((x & 0x000000FF) << 16);  //AA______
+    // Return value is in format:  0xAARRGGBB
+}
+/*
+static void ZB_ARGB(Zbuffer* zb){
+	for(int i = 0; i < zb->xsize * zb->ysize; i++){
+		zb->pbuf[i] = pxARGB()
+	}
+}
+*/
 static void ZB_copyBuffer(ZBuffer * zb,
                           void *buf,
                           int linesize)
--- a/src/zbuffer.h
+++ b/src/zbuffer.h
@@ -15,7 +15,7 @@
 #define ZB_POINT_S_MAX ( (1<<22)-(1<<13) )
 #define ZB_POINT_T_MIN ( (1<<21) )
 #define ZB_POINT_T_MAX ( (1<<30)-(1<<21) )
-
+/*
 #define ZB_POINT_RED_MIN ( (1<<10) )
 #define ZB_POINT_RED_MAX ( (1<<16)-(1<<10) )
 #define ZB_POINT_GREEN_MIN ( (1<<9) )
@@ -22,45 +22,21 @@
 #define ZB_POINT_GREEN_MAX ( (1<<16)-(1<<9) )
 #define ZB_POINT_BLUE_MIN ( (1<<10) )
 #define ZB_POINT_BLUE_MAX ( (1<<16)-(1<<10) )
-
+*/
 /* display modes */
 #define ZB_MODE_5R6G5B  1  /* true color 16 bits */
 #define ZB_MODE_INDEX   2  /* color index 8 bits */
-#define ZB_MODE_RGBA    3  /* 32 bit rgba mode */
+#define ZB_MODE_RGBA    3  /* 32 bit ABGR mode */
 #define ZB_MODE_RGB24   4  /* 24 bit rgb mode */
 #define ZB_NB_COLORS    225 /* number of colors for 8 bit display */
 
-#if TGL_FEATURE_RENDER_BITS == 15
 
-#define RGB_TO_PIXEL(r,g,b) \
-  ((((b) >> 1) & 0x7c00) | (((g) >> 6) & 0x03e0) | ((r) >> 11))
-typedef unsigned short PIXEL;
-/* bytes per pixel */
-#define PSZB 2 
-/* bits per pixel = (1 << PSZH) */
-#define PSZSH 4 
 
-#elif TGL_FEATURE_RENDER_BITS == 16
 
-/* 16 bit mode */
-#define RGB_TO_PIXEL(r,g,b) \
-  (((r) & 0xF800) | (((g) >> 5) & 0x07E0) | ((b) >> 11))
-typedef unsigned short PIXEL;
-#define PSZB 2 
-#define PSZSH 4 
 
-#elif TGL_FEATURE_RENDER_BITS == 24
+#if TGL_FEATURE_RENDER_BITS == 32
 
-#define RGB_TO_PIXEL(r,g,b) \
-  ((((b) << 8) & 0xff0000) | ((g) & 0xff00) | ((r) >> 8))
-typedef unsigned char PIXEL;
-#define PSZB 3
-#define PSZSH 5
-
-#elif TGL_FEATURE_RENDER_BITS == 32
-
-#define RGB_TO_PIXEL(r,g,b) \
-  ((((b) << 8) & 0xff0000) | ((g) & 0xff00) | ((r) >> 8))
+#define RGB_TO_PIXEL(r,g,b) ( ((b&65280)<<8) | ((g&65280)) | ((r&65280)>>8) )
 typedef unsigned int PIXEL;
 #define PSZB 4
 #define PSZSH 5
--- a/src/zfeatures.h
+++ b/src/zfeatures.h
@@ -13,7 +13,7 @@
 #define TGL_NO_COPY_COLOR 0xff00ff
 //NOTE: fc02fc is what you'll get if you set glColor3f to 1,0,1. 
 //^ solid debug pink.
-#define TGL_COLOR_MASK 0xffffff
+#define TGL_COLOR_MASK 0xffffffff
 //^ mask to check for copybuffer. This is configured for the default mode.
 
 /*
--- a/src/ztriangle.c
+++ b/src/ztriangle.c
@@ -1,14 +1,21 @@
 #include <stdlib.h>
 #include "zbuffer.h"
+
+
+
+
 #if TGL_FEATURE_RENDER_BITS == 32
+
+
 #define THE_X (((unsigned short)(pp-pp1)))
-#elif TGL_FEATURE_RENDER_BITS == 16
-#define THE_X (((unsigned short)(pp-pp1)))
-#elif TGL_FEATURE_RENDER_BITS == 8
-#define THE_X (((unsigned short)pp)-(unsigned short)pp1)
+
 #else
-#error "24 bit mode is not supported in this port. Use 16 or 32 bit modes."
+
+#error "USE 32 BIT MODE!!!"
+
 #endif
+
+
 #define XSTIP(_a) ((THE_X+_a)& 31)
 #define YSTIP (the_y & 31)
 #define STIPBIT(_a) (zb->stipplepattern[(XSTIP(_a) + (YSTIP<<5))>>3] & (1<<(XSTIP(_a) & 7)))
@@ -21,37 +28,16 @@
 void ZB_fillTriangleFlat(ZBuffer *zb,
 			 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
 {
-#if TGL_FEATURE_RENDER_BITS == 24
-    unsigned char colorR, colorG, colorB;
-#else
-    int color;
-#endif
 
-#define INTERP_Z
 
-#if TGL_FEATURE_RENDER_BITS == 24 
 
-#define DRAW_INIT()				\
-{						\
-  colorR=p2->r>>8; \
-  colorG=p2->g>>8; \
-  colorB=p2->b>>8; \
-}
 
-#define PUT_PIXEL(_a)		\
-{						\
-    zz=z >> ZB_POINT_Z_FRAC_BITS;		\
-    if (ZCMP(zz,pz[_a])) {				\
-      pp[3 * _a]=colorR;\
-      pp[3 * _a + 1]=colorG;\
-      pp[3 * _a + 2]=colorB;\
-      pz[_a]=zz;				\
-    }\
-    z+=dzdx;					\
-}
+    unsigned int color;
 
-#else
 
+#define INTERP_Z
+
+
 #define DRAW_INIT()				\
 {						\
   color=RGB_TO_PIXEL(p2->r,p2->g,p2->b);	\
@@ -66,8 +52,8 @@
     }						\
     z+=dzdx;					\
 }
-#endif /* TGL_FEATURE_RENDER_BITS == 24 */
 
+
 #include "ztriangle.h"
 }
 
@@ -79,99 +65,24 @@
 void ZB_fillTriangleSmooth(ZBuffer *zb,
 			   ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
 {
-#if TGL_FEATURE_RENDER_BITS == 16
-        int _drgbdx;
-#endif
 
+//unsigned int color;
 #define INTERP_Z
 #define INTERP_RGB
 
 #define SAR_RND_TO_ZERO(v,n) (v / (1<<n))
 
-#if TGL_FEATURE_RENDER_BITS == 24
 
-#define DRAW_INIT() 				\
-{						\
-}
 
-#define PUT_PIXEL(_a)				\
+#define DRAW_INIT()				\
 {						\
-    zz=z >> ZB_POINT_Z_FRAC_BITS;		\
-    if (ZCMP(zz,pz[_a],_a)) {				\
-      pp[3 * _a]=or1 >> 8;\
-      pp[3 * _a + 1]=og1 >> 8;\
-      pp[3 * _a + 2]=ob1 >> 8;\
-      pz[_a]=zz;				\
-    }\
-    z+=dzdx;					\
-    og1+=dgdx;					\
-    or1+=drdx;					\
-    ob1+=dbdx;					\
+  	\
 }
 
-#elif TGL_FEATURE_RENDER_BITS == 16
-
-#define DRAW_INIT() 				\
-{						\
-  _drgbdx=(SAR_RND_TO_ZERO(drdx,6) << 22) & 0xFFC00000;		\
-  _drgbdx|=SAR_RND_TO_ZERO(dgdx,5) & 0x000007FF;		\
-  _drgbdx|=(SAR_RND_TO_ZERO(dbdx,7) << 12) & 0x001FF000; 	\
-}
-
-
 #define PUT_PIXEL(_a)				\
 {						\
     zz=z >> ZB_POINT_Z_FRAC_BITS;		\
     if (ZCMP(zz,pz[_a],_a)) {				\
-      tmp=rgb & 0xF81F07E0;			\
-      pp[_a]=tmp | (tmp >> 16);			\
-      pz[_a]=zz;				\
-    }						\
-    z+=dzdx;					\
-    rgb=(rgb+drgbdx) & ( ~ 0x00200800);		\
-}
-
-#define DRAW_LINE()							   \
-{									   \
-  register unsigned short *pz;					   \
-  register PIXEL *pp;					   \
-  register unsigned int tmp,z,zz,rgb,drgbdx;				   \
-  register int n;							   \
-  n=(x2 >> 16) - x1;							   \
-  pp=pp1+x1;								   \
-  pz=pz1+x1;								   \
-  z=z1;									   \
-  rgb=(r1 << 16) & 0xFFC00000;						   \
-  rgb|=(g1 >> 5) & 0x000007FF;						   \
-  rgb|=(b1 << 5) & 0x001FF000;						   \
-  drgbdx=_drgbdx;							   \
-  while (n>=3) {							   \
-    PUT_PIXEL(0);/*the_x++;*/							   \
-    PUT_PIXEL(1);/*the_x++;*/							   \
-    PUT_PIXEL(2);/*the_x++;*/							   \
-    PUT_PIXEL(3);/*the_x++;*/							   \
-    pz+=4;								   \
-    pp+=4;								   \
-    n-=4;								   \
-  }									   \
-  while (n>=0) {							   \
-    PUT_PIXEL(0);/*the_x++;*/						   \
-    pz+=1;								   \
-    pp+=1;								   \
-    n-=1;								   \
-  }									   \
-}
-
-#else
-
-#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;				\
     }\
@@ -181,8 +92,6 @@
     ob1+=dbdx;					\
 }
 
-#endif /* TGL_FEATURE_RENDER_BITS */
-
 #include "ztriangle.h"
 } //EOF smooth fill triangle
 
@@ -204,26 +113,8 @@
   texture=zb->current_texture;			\
 }
 
-#if TGL_FEATURE_RENDER_BITS == 24
 
-#define PUT_PIXEL(_a)				\
-{						\
-   unsigned char *ptr;\
-   zz=z >> ZB_POINT_Z_FRAC_BITS;		\
-     if (ZCMP(zz,pz[_a],_a)) {				\
-       ptr = texture + (((t & 0x3FC00000) | s) >> 14) * 3; \
-       pp[3 * _a]= ptr[0];\
-       pp[3 * _a + 1]= ptr[1];\
-       pp[3 * _a + 2]= ptr[2];\
-       pz[_a]=zz;				\
-    }						\
-    z+=dzdx;					\
-    s+=dsdx;					\
-    t+=dtdx;					\
-}
 
-#else
-
 #define PUT_PIXEL(_a)				\
 {						\
    zz=z >> ZB_POINT_Z_FRAC_BITS;		\
@@ -236,8 +127,6 @@
     t+=dtdx;					\
 }
 
-#endif
-
 #include "ztriangle.h"
 }
 
@@ -246,8 +135,10 @@
  * We use the gradient method to make less divisions.
  * TODO: pipeline the division
  */
-#if 1
 
+
+#if 1 //IF 1
+
 void ZB_fillTriangleMappingPerspective(ZBuffer *zb,
                             ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
 {
@@ -269,30 +160,10 @@
 }
 
 
-#if TGL_FEATURE_RENDER_BITS == 24
-
 #define PUT_PIXEL(_a)				\
 {						\
-   unsigned char *ptr;\
    zz=z >> ZB_POINT_Z_FRAC_BITS;		\
      if (ZCMP(zz,pz[_a],_a)) {				\
-       ptr = texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> 14) * 3;\
-       pp[3 * _a]= ptr[0];\
-       pp[3 * _a + 1]= ptr[1];\
-       pp[3 * _a + 2]= ptr[2];\
-       pz[_a]=zz;				\
-    }						\
-    z+=dzdx;					\
-    s+=dsdx;					\
-    t+=dtdx;					\
-}
-
-#else
-
-#define PUT_PIXEL(_a)				\
-{						\
-   zz=z >> ZB_POINT_Z_FRAC_BITS;		\
-     if (ZCMP(zz,pz[_a],_a)) {				\
        pp[_a]=*(PIXEL *)((char *)texture+ \
                (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));\
        pz[_a]=zz;				\
@@ -302,8 +173,8 @@
     t+=dtdx;					\
 }
 
-#endif
 
+
 #define DRAW_LINE()				\
 {						\
   register unsigned short *pz;		\
@@ -365,7 +236,21 @@
 #include "ztriangle.h"
 }
 
-#endif
+#endif //if 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
 #if 0