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