ref: a6c73d93d6c3c0b0d058d432caf8b053d73b988e
parent: e2e12c60ee18888709eaccaa8fc55b7c9fb3cf45
author: David <gek@katherine>
date: Mon Feb 15 16:11:25 EST 2021
MAJOR performance overhaul
--- a/README.md
+++ b/README.md
@@ -174,7 +174,7 @@
* Per vertex color is broken due to a faulty optimization in clip.c
-* The conventions for 32 bit color were RGBA for textured triangles and ABGR for non-textured. Now both render as ABGR.
+* The conventions for 32 bit color were RGBA for textured triangles and ABGR for non-textured. Now both render as ARGB.
* Little endian was assumed in a thousand places in the code
@@ -186,7 +186,7 @@
## FULLY COMPATIBLE WITH RGBA!
-The library is now able to be configured properly for RGBA rendering. Note that the output *is actually ABGR*
+The library is now able to be configured properly for RGBA rendering. Note that the output *is actually ARGB*
but adjusting it is easy, see the SDL examples under SDL_EXAMPLES (They require SDL 1.2 and Mixer to compile)
The library is sometimes by default configured for RGBA or 5R6G5B, check include/zfeatures.h and change the values in this table:
--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -274,6 +274,7 @@
int winSizeX=640;
int winSizeY=480;
unsigned int fps =0;
+ char needsRGBAFix = 0;
if(argc > 2){
char* larg = argv[1];
for(int i = 0; i < argc; i++){
@@ -302,12 +303,21 @@
printf("\nGMASK IS %u",screen->format->Gmask);
printf("\nBMASK IS %u",screen->format->Bmask);
printf("\nAMASK IS %u",screen->format->Amask);
-
-
+#if TGL_FEATURE_RENDER_BITS == 32
+ if(
+ screen->format->Rmask != 0x00FF0000 ||
+ screen->format->Gmask != 0x0000FF00 ||
+ screen->format->Bmask != 0x000000FF
+ ){
+ needsRGBAFix = 1;
+ printf("\nYour screen is using an RGBA output different than this library expects.");
+ printf("\nYou should consider using the 16 bit version for optimal performance");
+ }
+#endif
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);
+ printf("\nASHIFT IS %u\n",screen->format->Ashift);
fflush(stdout);
track* myTrack = NULL;
#ifdef PLAY_MUSIC
@@ -415,19 +425,15 @@
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
#if TGL_FEATURE_RENDER_BITS == 32
+//for testing!
+ if(needsRGBAFix)
for(int i = 0; i < frameBuffer->xsize* frameBuffer->ysize;i++){
#define DATONE (frameBuffer->pbuf[i])
- DATONE = ((DATONE & 0x000000FF) ) << screen->format->Rshift |
+ DATONE = ((DATONE & 0x00FF0000) ) << screen->format->Rshift |
((DATONE & 0x0000FF00) >> 8) << screen->format->Gshift |
- ((DATONE & 0x00FF0000) >>16) << screen->format->Bshift;
+ ((DATONE & 0x000000FF) >>16) << screen->format->Bshift;
}
#endif
ZB_copyFrameBuffer(frameBuffer, screen->pixels, screen->pitch);
--- a/SDL_Examples/helloworld.c
+++ b/SDL_Examples/helloworld.c
@@ -112,6 +112,7 @@
// initialize SDL video:
unsigned int fps =0;
+ char needsRGBAFix = 0;
if(argc > 2){
char* larg = argv[1];
for(int i = 0; i < argc; i++){
@@ -140,12 +141,22 @@
printf("\nGMASK IS %u",screen->format->Gmask);
printf("\nBMASK IS %u",screen->format->Bmask);
printf("\nAMASK IS %u",screen->format->Amask);
+#if TGL_FEATURE_RENDER_BITS == 32
+ if(
+ screen->format->Rmask != 0x00FF0000 ||
+ screen->format->Gmask != 0x0000FF00 ||
+ screen->format->Bmask != 0x000000FF
+ ){
+ needsRGBAFix = 1;
+ printf("\nYour screen is using an RGBA output different than this library expects.");
+ printf("\nYou should consider using the 16 bit version for optimal performance");
+ }
+#endif
-
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);
+ printf("\nASHIFT IS %u\n",screen->format->Ashift);
fflush(stdout);
track* myTrack = NULL;
#ifdef PLAY_MUSIC
@@ -244,7 +255,8 @@
printf("\nAMASK IS %u",screen->format->Amask);
*/
//Quickly convert all pixels to the correct format
-#if TGL_FEATURE_RENDER_BITS == 32
+#if TGL_FEATURE_RENDER_BITS == 32
+ if(needsRGBAFix)
for(int i = 0; i < frameBuffer->xsize* frameBuffer->ysize;i++){
#define DATONE (frameBuffer->pbuf[i])
DATONE = ((DATONE & 0x000000FF) ) << screen->format->Rshift |
--- a/SDL_Examples/model.c
+++ b/SDL_Examples/model.c
@@ -252,6 +252,7 @@
// initialize SDL video:
int winSizeX=640;
int winSizeY=480;
+ char needsRGBAFix = 0;
unsigned int count = 40;
GLuint modelDisplayList = 0; int dlExists = 0; int doTextures = 1;
char* modelName = "extrude.obj";
@@ -292,11 +293,21 @@
printf("\nBMASK IS %u",screen->format->Bmask);
printf("\nAMASK IS %u",screen->format->Amask);
-
+#if TGL_FEATURE_RENDER_BITS == 32
+ if(
+ screen->format->Rmask != 0x00FF0000 ||
+ screen->format->Gmask != 0x0000FF00 ||
+ screen->format->Bmask != 0x000000FF
+ ){
+ needsRGBAFix = 1;
+ printf("\nYour screen is using an RGBA output different than this library expects.");
+ printf("\nYou should consider using the 16 bit version for optimal performance");
+ }
+#endif
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);
+ printf("\nASHIFT IS %u\n",screen->format->Ashift);
fflush(stdout);
#ifdef PLAY_MUSIC
myTrack = lmus("WWGW.mp3");
@@ -520,7 +531,8 @@
printf("\nAMASK IS %u",screen->format->Amask);
*/
//Quickly convert all pixels to the correct format
-#if TGL_FEATURE_RENDER_BITS == 32
+#if TGL_FEATURE_RENDER_BITS == 32
+ if(needsRGBAFix)
for(int i = 0; i < frameBuffer->xsize* frameBuffer->ysize;i++){
#define DATONE (frameBuffer->pbuf[i])
DATONE = ((DATONE & 0x000000FF) ) << screen->format->Rshift |
--- a/SDL_Examples/texture.c
+++ b/SDL_Examples/texture.c
@@ -115,6 +115,7 @@
int winSizeX=640;
int winSizeY=480;
unsigned int fps =0;
+ char needsRGBAFix = 0;
if(argc > 2){
char* larg = argv[1];
for(int i = 0; i < argc; i++){
@@ -143,12 +144,22 @@
printf("\nGMASK IS %u",screen->format->Gmask);
printf("\nBMASK IS %u",screen->format->Bmask);
printf("\nAMASK IS %u",screen->format->Amask);
+#if TGL_FEATURE_RENDER_BITS == 32
+ if(
+ screen->format->Rmask != 0x00FF0000 ||
+ screen->format->Gmask != 0x0000FF00 ||
+ screen->format->Bmask != 0x000000FF
+ ){
+ needsRGBAFix = 1;
+ printf("\nYour screen is using an RGBA output different than this library expects.");
+ printf("\nYou should consider using the 16 bit version for optimal performance");
+ }
+#endif
-
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);
+ printf("\nASHIFT IS %u\n",screen->format->Ashift);
fflush(stdout);
track* myTrack = NULL;
#ifdef PLAY_MUSIC
@@ -162,10 +173,6 @@
int mode;
switch( screen->format->BitsPerPixel ) {
- case 8:
- fprintf(stderr,"ERROR: Palettes are currently not supported.\n");
- fprintf(stderr,"\nUnsupported by maintainer!!!");
- return 1;
case 16:
//fprintf(stderr,"\nUnsupported by maintainer!!!");
@@ -172,12 +179,6 @@
mode = ZB_MODE_5R6G5B;
//return 1;
break;
- case 24:
-
- fprintf(stderr,"\nUnsupported by maintainer!!!");
- mode = ZB_MODE_RGB24;
- return 1;
- break;
case 32:
mode = ZB_MODE_RGBA;
@@ -247,7 +248,8 @@
printf("\nAMASK IS %u",screen->format->Amask);
*/
//Quickly convert all pixels to the correct format
-#if TGL_FEATURE_RENDER_BITS == 32
+#if TGL_FEATURE_RENDER_BITS == 32
+if(needsRGBAFix)
for(int i = 0; i < frameBuffer->xsize* frameBuffer->ysize;i++){
#define DATONE (frameBuffer->pbuf[i])
DATONE = ((DATONE & 0x000000FF) ) << screen->format->Rshift |
--- a/include/zbuffer.h
+++ b/include/zbuffer.h
@@ -38,7 +38,9 @@
#if TGL_FEATURE_RENDER_BITS == 32
/* 32 bit mode */
-#define RGB_TO_PIXEL(r,g,b) ( ((b&65280)<<8) | ((g&65280)) | ((r&65280)>>8) )
+//#define RGB_TO_PIXEL(r,g,b) ( ((b&65280)<<8) | ((g&65280)) | ((r&65280)>>8) )
+#define RGB_TO_PIXEL(r,g,b) \
+ ((((r) << 8) & 0xff0000) | ((g) & 0xff00) | ((b) >> 8))
typedef unsigned int PIXEL;
#define PSZB 4
#define PSZSH 5
--- a/src/image_util.c
+++ b/src/image_util.c
@@ -29,9 +29,9 @@
p=rgb;
n=xsize*ysize;
for(i=0;i<n;i++) {
- pixmap[i]=(((GLuint)p[2])<<16) |
+ pixmap[i]=(((GLuint)p[0])<<16) |
(((GLuint)p[1])<<8) |
- (((GLuint)p[0]) );
+ (((GLuint)p[2]) );
p+=3;
}
}
--- a/src/ztriangle.h
+++ b/src/ztriangle.h
@@ -10,7 +10,7 @@
GLint part,update_left,update_right;
GLint nb_lines,dx1,dy1,tmp,dx2,dy2;
-#if TGL_FEATURE_POLYGON_STIPPLE
+#if TGL_FEATURE_POLYGON_STIPPLE == 1
GLushort the_y;
#endif
GLint error,derror;
@@ -135,9 +135,9 @@
/* screen coordinates */
pp1 = (PIXEL *) ((GLbyte *) zb->pbuf + zb->linesize * p0->y);
- #if TGL_FEATURE_POLYGON_STIPPLE
+#if TGL_FEATURE_POLYGON_STIPPLE == 1
the_y = p0->y;
- #endif
+#endif
pz1 = zb->zbuf + p0->y * zb->xsize;
DRAW_INIT();
@@ -355,7 +355,7 @@
/* screen coordinates */
pp1=(PIXEL *)((GLbyte *)pp1 + zb->linesize);
-#if TGL_FEATURE_POLYGON_STIPPLE
+#if TGL_FEATURE_POLYGON_STIPPLE == 1
the_y++;
#endif
pz1+=zb->xsize;