- Minor cleanup and comments added

- Support for wireframe alpha mode
This commit is contained in:
shashclp 2007-05-19 15:45:16 +00:00
parent 0c7e0a4a6a
commit 1a68fcaad6
1 changed files with 338 additions and 372 deletions

View File

@ -36,7 +36,8 @@
#define fix10_2float(v) (((float)((s32)(v))) / (float)(1<<9))
static unsigned char GPU_screen3D[256*256*4]={0};
// Accelerationg tables
// Acceleration tables
static float* float16table = NULL;
static float* float10Table = NULL;
static float* float10RelTable = NULL;
@ -98,9 +99,6 @@ static unsigned int vtxFormat;
static unsigned int textureFormat=0, texturePalette=0;
static unsigned int lastTextureFormat=0, lastTexturePalette=0;
// This was used to disable/enable certain stuff, as some is partially broken
//extern char disableBlending, disableLighting, wireframeMode, disableTexturing;
extern u32 nbframe;
extern HWND hwnd;
char NDS_glInit(void)
@ -149,6 +147,7 @@ char NDS_glInit(void)
if (glGetError() != GL_NO_ERROR)
return 0;
// Precalculate some tables, to avoid pushing data to the FPU and back for conversion
float16table = (float*) malloc (sizeof(float)*65536);
for (i = 0; i < 65536; i++)
{
@ -275,7 +274,6 @@ void NDS_glLoadMatrix4x4(signed long v)
++ML4x4ind;
if(ML4x4ind<16) return;
//MATRIX_LOAD4x4[15]*=2; // petite triche pour faire fonctionner Meteos
if (mode == 2)
MatrixCopy (mtxCurrent[1], mtxCurrent[2]);
@ -344,7 +342,7 @@ void NDS_glTranslate(signed long v)
void NDS_glScale(signed long v)
{
scale[scaleind] = fix2float(v); //(((signed long)v>>16)) / (float)(1<<9);
scale[scaleind] = fix2float(v);
++scaleind;
@ -416,7 +414,7 @@ void NDS_glMultMatrix4x4(signed long v)
static __inline void SetupTexture (unsigned int format, unsigned int palette)
{
if(format == 0)// || disableTexturing)
if(format == 0)
return;
else
{
@ -431,6 +429,7 @@ static __inline void SetupTexture (unsigned int format, unsigned int palette)
unsigned int paletteSize = 0;
unsigned int palZeroTransparent = (1-((format>>29)&1))*255; // shash: CONVERT THIS TO A TABLE :)
unsigned int x=0, y=0;
unsigned char * dst = texMAP, *src = NULL;
if (mode == 0)
glDisable (GL_TEXTURE_2D);
@ -484,9 +483,6 @@ static __inline void SetupTexture (unsigned int format, unsigned int palette)
}
}
{
unsigned char * dst = texMAP, *src = NULL;
switch(mode)
{
case 1:
@ -819,10 +815,9 @@ static __inline void SetupTexture (unsigned int format, unsigned int palette)
break;
}
}
}
invTexWidth = 1.f/((float)sizeX*(1<<4));//+ 1;
invTexHeight = 1.f/((float)sizeY*(1<<4));//+ 1;
invTexWidth = 1.f/((float)sizeX*(1<<4));
invTexHeight = 1.f/((float)sizeY*(1<<4));
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
@ -839,9 +834,6 @@ static __inline void SetupTexture (unsigned int format, unsigned int palette)
else
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
//flipS = BIT18(format);
//flipT = BIT19(format);
texCoordinateTransform = (format>>30);
}
}
@ -854,7 +846,7 @@ void NDS_glBegin(unsigned long v)
}
// Light enable/disable
if (lightMask)// && !disableLighting)
if (lightMask)
{
if (lightMask&1) glEnable (GL_LIGHT0);
else glDisable(GL_LIGHT0);
@ -869,7 +861,6 @@ void NDS_glBegin(unsigned long v)
else glDisable(GL_LIGHT3);
glEnable (GL_LIGHTING);
//glEnable (GL_COLOR_MATERIAL);
}
else
{
@ -893,23 +884,24 @@ void NDS_glBegin(unsigned long v)
}
// Alpha value, actually not well handled, 0 should be wireframe
if (colorAlpha == 0.0f)
if (colorAlpha > 0.0f)
{
//glPolygonMode (GL_FRONT, GL_LINE);
//glPolygonMode (GL_BACK, GL_LINE);
}
else
{
//glPolygonMode (GL_FRONT, GL_FILL);
//glPolygonMode (GL_BACK, GL_FILL);
glPolygonMode (GL_FRONT, GL_FILL);
glPolygonMode (GL_BACK, GL_FILL);
/*
colorRGB[0] = 1.f;
colorRGB[1] = 1.f;
colorRGB[2] = 1.f;
*/
colorRGB[3] = colorAlpha;
glColor4iv (colorRGB);
}
else
{
glPolygonMode (GL_FRONT, GL_LINE);
glPolygonMode (GL_BACK, GL_LINE);
}
if (textureFormat != lastTextureFormat ||
texturePalette != lastTexturePalette)
@ -952,29 +944,26 @@ void NDS_glColor3b(unsigned long v)
glColor4iv (colorRGB);
}
#define SetTextureCoordinate(s,t) glTexCoord2i (s,t)
static __inline void SetVertex()
{
float coordTransformed[3] = { coord[0], coord[1], coord[2] };
if (texCoordinateTransform == 3)
{
float *textureMatrix = mtxCurrent[3];
int s2 = (int)(( coord[0]*textureMatrix[0] +
coord[1]*textureMatrix[4] +
coord[2]*textureMatrix[8]) + s);
int t2 = (int)(( coord[0]*textureMatrix[1] +
coord[1]*textureMatrix[5] +
coord[2]*textureMatrix[9]) + t);
int s2 = (int)(( coord[0]*mtxCurrent[3][0] +
coord[1]*mtxCurrent[3][4] +
coord[2]*mtxCurrent[3][8]) + s);
int t2 = (int)(( coord[0]*mtxCurrent[3][1] +
coord[1]*mtxCurrent[3][5] +
coord[2]*mtxCurrent[3][9]) + t);
SetTextureCoordinate (s2, t2);
glTexCoord2i (s2, t2);
}
MatrixMultVec4x4 (mtxCurrent[1], coordTransformed);
glVertex3fv (coordTransformed);
//glVertex3fv (coord);
numVertex++;
}
@ -983,16 +972,13 @@ void NDS_glVertex16b(unsigned int v)
if(coordind==0)
{
coord[0] = float16table[v&0xFFFF];
// coordFixed[0] = (signed short) (v&0xFFFF);
coord[1] = float16table[v>>16];
// coordFixed[1] = (signed short) (v>>16);
++coordind;
return;
}
coord[2] = float16table[v&0xFFFF];
// coordFixed[2] = (signed short) (v&0xFFFF);
coordind = 0;
SetVertex ();
@ -1001,11 +987,8 @@ void NDS_glVertex16b(unsigned int v)
void NDS_glVertex10b(unsigned long v)
{
coord[0] = float10Table[v&1023];
// coordFixed[0] = (signed short)(( v &1023)<<6);
coord[1] = float10Table[(v>>10)&1023];
// coordFixed[1] = (signed short)(((v>>10)&1023)<<6);
coord[2] = float10Table[(v>>20)&1023];
// coordFixed[2] = (signed short)(((v>>20)&1023)<<6);
SetVertex ();
}
@ -1013,9 +996,7 @@ void NDS_glVertex10b(unsigned long v)
void NDS_glVertex3_cord(unsigned int one, unsigned int two, unsigned int v)
{
coord[one] = float16table[v&0xffff];
// coordFixed[one] = (signed short) (v&0xFFFF);
coord[two] = float16table[v>>16];
// coordFixed[two] = (signed short) (v>>16);
SetVertex ();
}
@ -1023,11 +1004,8 @@ void NDS_glVertex3_cord(unsigned int one, unsigned int two, unsigned int v)
void NDS_glVertex_rel(unsigned long v)
{
coord[0] += float10RelTable[v&1023];
// coordFixed[0] += (signed short)((v&511) | ((v&512)<<6));
coord[1] += float10RelTable[(v>>10)&1023];
// coordFixed[1] += (signed short)((((v>>10)&511)) | (((v>>10)&512)<<6));
coord[2] += float10RelTable[(v>>20)&1023];
// coordFixed[2] += (signed short)(((v>>20)&511) | (((v>>20)&512)<<6));
SetVertex ();
}
@ -1083,24 +1061,14 @@ void NDS_glFlush(unsigned long v)
clCmd = 0;
clInd = 0;
// if (!disable3D)
{
glFlush();
glReadPixels(0,0,256,192,GL_BGRA,GL_UNSIGNED_BYTE,GPU_screen3D);
}
numVertex = 0;
/*if (wireframeMode)
{
glPolygonMode (GL_BACK, GL_LINE);
glPolygonMode (GL_FRONT, GL_LINE);
}
else*/
{
// Set back some secure render states
glPolygonMode (GL_BACK, GL_FILL);
glPolygonMode (GL_FRONT, GL_FILL);
}
glDepthMask (GL_TRUE);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -1216,17 +1184,16 @@ void NDS_glTexCoord(unsigned long val)
if (texCoordinateTransform == 1)
{
float *textureMatrix = mtxCurrent[3];
int s2 =(int)( s* textureMatrix[0] + t* textureMatrix[4] +
(1.f/16.f)* textureMatrix[8] + (1.f/16.f)* textureMatrix[12]);
int t2 =(int)( s* textureMatrix[1] + t* textureMatrix[5] +
(1.f/16.f)* textureMatrix[9] + (1.f/16.f)* textureMatrix[13]);
int s2 =(int)( s* mtxCurrent[3][0] + t* mtxCurrent[3][4] +
(1.f/16.f)* mtxCurrent[3][8] + (1.f/16.f)* mtxCurrent[3][12]);
int t2 =(int)( s* mtxCurrent[3][1] + t* mtxCurrent[3][5] +
(1.f/16.f)* mtxCurrent[3][9] + (1.f/16.f)* mtxCurrent[3][13]);
SetTextureCoordinate (s2, t2);
glTexCoord2i (s2, t2);
}
else
{
SetTextureCoordinate (s, t);
glTexCoord2i (s, t);
}
}
@ -1368,13 +1335,12 @@ void NDS_glNormal(unsigned long v)
if (texCoordinateTransform == 2)
{
float *textureMatrix = mtxCurrent[3];
int s2 =(int)( (normal[0] *textureMatrix[0] + normal[1] *textureMatrix[4] +
normal[2] *textureMatrix[8]) + s);
int t2 =(int)( (normal[0] *textureMatrix[1] + normal[1] *textureMatrix[5] +
normal[2] *textureMatrix[9]) + t);
int s2 =(int)( (normal[0] *mtxCurrent[3][0] + normal[1] *mtxCurrent[3][4] +
normal[2] *mtxCurrent[3][8]) + s);
int t2 =(int)( (normal[0] *mtxCurrent[3][1] + normal[1] *mtxCurrent[3][5] +
normal[2] *mtxCurrent[3][9]) + t);
SetTextureCoordinate (s2, t2);
glTexCoord2i (s2, t2);
}
MatrixMultVec3x3 (mtxCurrent[2], normal);