Add rayman2 source files
This commit is contained in:
553
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Acces.c
Normal file
553
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Acces.c
Normal file
@@ -0,0 +1,553 @@
|
||||
#include <d3d.h>
|
||||
#include <ddraw.h>
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Vertex Access Macros
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/* GET*/
|
||||
#define GetX(a) a.sx
|
||||
#define GetY(a) a.sy
|
||||
#define GetZ(a) a.rhw
|
||||
#define GetPackedColor(a) a.color
|
||||
#define GetPackedSpecular(a) a.specular
|
||||
#define GetU(a) a.tu
|
||||
#define GetV(a) a.tv
|
||||
/* SET*/
|
||||
#define SetX(a,b) a.sx = b
|
||||
#define SetY(a,b) a.sy = b
|
||||
#define SetZ(a,b) a.sz = a.rhw = b
|
||||
#define SetPackedColor(a,b) a.color = b
|
||||
#define SetPackedSpecular(a,b) a.specular = b
|
||||
#define SetU(a,b) a.tu = b
|
||||
#define SetV(a,b) a.tv = b
|
||||
#define SetU_Cpy(a,b) a.tu = b
|
||||
#define SetV_Cpy(a,b) a.tv = b
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Globals
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
double fNumberOfTexels = 0;
|
||||
double fNumberMinOfTexels = 1e30;
|
||||
double fNumberMaxOfTexels = 0;
|
||||
*/
|
||||
|
||||
/*
|
||||
* Draw primitive flag
|
||||
*/
|
||||
#define GLI_C_dwDPFlag_NoClip D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT
|
||||
#define GLI_C_dwDPFlag_Clip D3DDP_DONOTLIGHT
|
||||
|
||||
DWORD dwDrawPrimitiveFlag = GLI_C_dwDPFlag_NoClip;
|
||||
|
||||
|
||||
/*
|
||||
* D3D vertex buffer
|
||||
*/
|
||||
#define GLI_tdScreenVertx D3DTLVERTEX
|
||||
|
||||
GLI_tdScreenVertx ga_stVertexBuffer[ 3000 ];
|
||||
GLI_tdScreenVertx *CurrentDestXYZ = ga_stVertexBuffer;
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
External
|
||||
=======================================================================================
|
||||
*/
|
||||
extern LPDIRECT3DDEVICE3 g_pd3dDevice;
|
||||
|
||||
extern void GLI_DRV_xSendSpriteToClip_TRIANGLES( GLI_tdstAligned2DVector *a4_st2DVertex, GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT);
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Function & macros
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
#define GLI_M_RestoreCW()
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : called before a complex object is drawn
|
||||
complex object is several faces with same material
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_BeforeDraw()
|
||||
{
|
||||
CurrentDestXYZ = ga_stVertexBuffer;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : called after complex object is send
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_AfterDraw()
|
||||
{
|
||||
long lVertexNumber;
|
||||
|
||||
if ((lVertexNumber = CurrentDestXYZ - ga_stVertexBuffer) != 0)
|
||||
{
|
||||
/* if( FAILED( g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice) ) )
|
||||
return;
|
||||
*/
|
||||
|
||||
/* Draw the triangles*/
|
||||
g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, ga_stVertexBuffer, lVertexNumber, dwDrawPrimitiveFlag );
|
||||
|
||||
/* End the scene.*/
|
||||
/* g_pd3dDevice->lpVtbl->EndScene(g_pd3dDevice); */
|
||||
}
|
||||
|
||||
/* bench : count texels*/
|
||||
/*
|
||||
if ( GLI_BIG_GLOBALS->p_stCurrentTexture != NULL)
|
||||
{
|
||||
GLI_tdScreenVertx *p_stCurVertex = ga_stVertexBuffer;
|
||||
unsigned long ulSizeOfTexture = GLI_BIG_GLOBALS->p_stCurrentTexture->lHeight * GLI_BIG_GLOBALS->p_stCurrentTexture->lWidth / 2;
|
||||
float fLocalNumberOfTexels, fSizeInPixel;
|
||||
|
||||
while (p_stCurVertex != CurrentDestXYZ)
|
||||
{
|
||||
fLocalNumberOfTexels = fabs( ( p_stCurVertex[0].tu - p_stCurVertex[1].tu ) * fabs( p_stCurVertex[0].tv - p_stCurVertex[2].tv ) * ulSizeOfTexture);
|
||||
fSizeInPixel = fabs( ( p_stCurVertex[0].sx - p_stCurVertex[1].sx ) * fabs( p_stCurVertex[0].sy - p_stCurVertex[2].sy ) * 0.5f);
|
||||
|
||||
if (fSizeInPixel > fLocalNumberOfTexels)
|
||||
fLocalNumberOfTexels = fSizeInPixel;
|
||||
|
||||
fNumberOfTexels += fLocalNumberOfTexels;
|
||||
|
||||
p_stCurVertex += 3;
|
||||
}
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Draw single triangle stored in CurrentDestXYZ array
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
GLI_FuncNodeBegin(GLI_vDrawTriangle)
|
||||
{
|
||||
CurrentDestXYZ += 3;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Add a single triangle in Z sorted list
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
GLI_FuncNodeBegin(GLI_vZSortTriangle)
|
||||
{
|
||||
float ZMax;
|
||||
|
||||
if ((unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint > (unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_TableOfPoints + ((3L << GLI_MaxZListeTrianglesPO2)* sizeof (GLI_tdScreenVertx)) - 3L * sizeof(GLI_tdScreenVertx))
|
||||
return;
|
||||
|
||||
memcpy(GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint , CurrentDestXYZ , sizeof(GLI_tdScreenVertx) * 3L);
|
||||
if (*(unsigned long *)&GetZ(CurrentDestXYZ[0]) < *(unsigned long *)&GetZ(CurrentDestXYZ[1]))
|
||||
*(unsigned long *)&ZMax = *(unsigned long *)&GetZ(CurrentDestXYZ[0]);
|
||||
else
|
||||
*(unsigned long *)&ZMax = *(unsigned long *)&GetZ(CurrentDestXYZ[1]);
|
||||
if (*(unsigned long *)&ZMax > *(unsigned long *)&GetZ(CurrentDestXYZ[2]))
|
||||
*(unsigned long *)&ZMax = *(unsigned long *)&GetZ(CurrentDestXYZ[2]);
|
||||
GLI_v_AddNodeInZList(ZMax);
|
||||
|
||||
(unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint += sizeof(GLI_tdScreenVertx) * 3L;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Add a single triangle in Z sorted list
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
GLI_FuncNodeBegin(GLI_vDrawWiredTriangle)
|
||||
{
|
||||
/* if( FAILED( g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice) ) )
|
||||
return;
|
||||
*/
|
||||
|
||||
/* Draw the triangle using a DrawPrimitive() call. */
|
||||
CurrentDestXYZ[3] = CurrentDestXYZ[0];
|
||||
g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_LINESTRIP, D3DFVF_TLVERTEX, CurrentDestXYZ, 4, GLI_C_dwDPFlag_Clip );
|
||||
|
||||
/* End the scene.*/
|
||||
/* g_pd3dDevice->lpVtbl->EndScene(g_pd3dDevice); */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : draw a quad stored in CurrentDestXYZ array or add it in Z list
|
||||
|
||||
1-----0
|
||||
| /| Send two triangle : 0 1 2 and 3 2 0
|
||||
| / |
|
||||
|/ |
|
||||
2-----3
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DrawQuad(void)
|
||||
{
|
||||
/* draw 2 triangles */
|
||||
/*
|
||||
CurrentDestXYZ[0].color = 0xFFFFFFFF;
|
||||
CurrentDestXYZ[1].color = 0xFFFFFFFF;
|
||||
CurrentDestXYZ[2].color = 0xFFFFFFFF;
|
||||
CurrentDestXYZ[3].color = 0xFFFFFFFF;
|
||||
*/
|
||||
|
||||
if ( GLI_BIG_GLOBALS -> lClippingModeMask & GLI_C_TrianglesMustBeSorted )
|
||||
{
|
||||
GLI_BIG_GLOBALS -> lCurrentDrawMask &= ~GLI_C_lIsGouraud;
|
||||
if ((unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint > (unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_TableOfPoints + ((3L << GLI_MaxZListeTrianglesPO2)* sizeof (GLI_tdScreenVertx)) - 4L * sizeof(GLI_tdScreenVertx))
|
||||
return;
|
||||
memcpy(GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint , CurrentDestXYZ , sizeof(GLI_tdScreenVertx) * 4L);
|
||||
GLI_v_AddNodeInZList(GetZ(CurrentDestXYZ[0]));
|
||||
(unsigned long) GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint += sizeof(GLI_tdScreenVertx) * 4L;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentDestXYZ[4] = CurrentDestXYZ[2];
|
||||
CurrentDestXYZ[5] = CurrentDestXYZ[0];
|
||||
CurrentDestXYZ += 6;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Draw a line
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DrawLine(void)
|
||||
{
|
||||
/* if( FAILED( g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice) ) )
|
||||
return;
|
||||
*/
|
||||
|
||||
/* Draw the triangle using a DrawPrimitive() call. */
|
||||
|
||||
g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_LINELIST, D3DFVF_TLVERTEX, CurrentDestXYZ, 2, GLI_C_dwDPFlag_Clip );
|
||||
//g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_LINELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, CurrentDestXYZ, 2, GLI_C_dwDPFlag_Clip );
|
||||
/* End the scene.*/
|
||||
/* g_pd3dDevice->lpVtbl->EndScene(g_pd3dDevice); */
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : draw Zsorted triangle
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void GLI_vDrawZSortedTriangle(void *p_3Point)
|
||||
{
|
||||
memcpy( CurrentDestXYZ, p_3Point, 3 * sizeof(GLI_tdScreenVertx) );
|
||||
CurrentDestXYZ += 3;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : draw ZSorted quad
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_vDrawZSortedQuad(void *p_3Point)
|
||||
{
|
||||
memcpy( CurrentDestXYZ, p_3Point, 4 * sizeof(GLI_tdScreenVertx) );
|
||||
CurrentDestXYZ[4] = *((GLI_tdScreenVertx *) p_3Point + 2);
|
||||
CurrentDestXYZ[5] = *((GLI_tdScreenVertx *) p_3Point);
|
||||
CurrentDestXYZ += 6;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : choose good drawing function
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_vAddDrawFunc()
|
||||
{
|
||||
if (GLI_BIG_GLOBALS -> lClippingModeMask & GLI_C_TrianglesMustBeSorted)
|
||||
{
|
||||
GLI_M_AddFunc(GLI_vZSortTriangle);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else if ( (GLI_BIG_GLOBALS->lCurrentDrawMask & GLI_C_lIsNotWired) == 0 )
|
||||
{
|
||||
GLI_M_AddFunc(GLI_vDrawWiredTriangle);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
GLI_M_AddFunc(GLI_vDrawTriangle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : compute clipping mask
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_ReComputeClippingMask()
|
||||
{
|
||||
*(float *)&fX_CMP_Optimize = GLI_BIG_GLOBALS->fXMaxClipping;
|
||||
*(float *)&fY_CMP_Optimize = GLI_BIG_GLOBALS->fYMaxClipping;
|
||||
*(float *)&fXMin_CLIP_Optimize = GLI_BIG_GLOBALS->fXMinClipping;
|
||||
*(float *)&fYMin_CLIP_Optimize = GLI_BIG_GLOBALS->fYMinClipping;
|
||||
*(float *)&fXMax_CLIP_Optimize = GLI_BIG_GLOBALS->fXMaxClipping;
|
||||
*(float *)&fYMax_CLIP_Optimize = GLI_BIG_GLOBALS->fYMaxClipping;
|
||||
|
||||
GLI_BIG_GLOBALS->lClippingModeMask |= (GLI_BIG_GLOBALS->lClippingModeMask & GLI_C_lCLIP_ALL) << 4;
|
||||
/*
|
||||
if (GLI_BIG_GLOBALS->lClippingModeMask & GLI_C_lCLIP_ALL == 0)
|
||||
{
|
||||
dwDrawPrimitiveFlag = GLI_C_dwDPFlag_NoClip;
|
||||
}
|
||||
else
|
||||
{
|
||||
dwDrawPrimitiveFlag = GLI_C_dwDPFlag_Clip;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : clip a sprite
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DRV_vSendSpriteToClip
|
||||
(
|
||||
GLI_tdstAligned2DVector *a4_st2DVertex ,
|
||||
MTH_tdxReal xZ ,
|
||||
GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT
|
||||
)
|
||||
{
|
||||
float fClipYMax, fClipYMin, fClipXMax, fClipXMin;
|
||||
unsigned long ulColor;
|
||||
|
||||
GLI_BeforeDraw();
|
||||
|
||||
if (a4_st2DVertex[0].xY == a4_st2DVertex[1].xY) /* Aligned sprite */
|
||||
{
|
||||
GLI_ReComputeClippingMask();
|
||||
|
||||
if ( ( *(long *) &a4_st2DVertex[0].xY > fYMax_CLIP_Optimize) || (*(long *) &a4_st2DVertex[2].xY < fYMin_CLIP_Optimize) || (*(long *) &a4_st2DVertex[0].xX < fXMin_CLIP_Optimize) || (*(long *) &a4_st2DVertex[1].xX > fXMax_CLIP_Optimize) )
|
||||
return;
|
||||
|
||||
/*
|
||||
* clip xMax
|
||||
*/
|
||||
if ( *(long *) &a4_st2DVertex[0].xX > fXMax_CLIP_Optimize )
|
||||
{
|
||||
fClipXMax = (GLI_BIG_GLOBALS->fXMaxClipping - a4_st2DVertex[1].xX) / ( a4_st2DVertex[0].xX - a4_st2DVertex[1].xX );
|
||||
a4_st2DVertex[0].xX = a4_st2DVertex[3].xX = GLI_BIG_GLOBALS->fXMaxClipping;
|
||||
}
|
||||
else
|
||||
fClipXMax = 1.0f;
|
||||
|
||||
/*
|
||||
* clip xMin
|
||||
*/
|
||||
if ( *(long *) &a4_st2DVertex[1].xX < fXMin_CLIP_Optimize )
|
||||
{
|
||||
fClipXMin = (fClipXMax * ( GLI_BIG_GLOBALS->fXMinClipping - a4_st2DVertex[1].xX) ) / ( a4_st2DVertex[0].xX - a4_st2DVertex[1].xX );
|
||||
a4_st2DVertex[1].xX = a4_st2DVertex[2].xX = GLI_BIG_GLOBALS->fXMinClipping;
|
||||
}
|
||||
else
|
||||
fClipXMin = 0.0f;
|
||||
|
||||
/*
|
||||
* clip yMin
|
||||
*/
|
||||
if ( *(long *) &a4_st2DVertex[0].xY < fYMin_CLIP_Optimize )
|
||||
{
|
||||
fClipYMin = (GLI_BIG_GLOBALS->fYMinClipping - a4_st2DVertex[2].xY) / ( a4_st2DVertex[0].xY - a4_st2DVertex[2].xY );
|
||||
a4_st2DVertex[0].xY = a4_st2DVertex[1].xY = GLI_BIG_GLOBALS->fYMinClipping;
|
||||
}
|
||||
else
|
||||
fClipYMin = 1.0f;
|
||||
|
||||
/*
|
||||
* clip yMax
|
||||
*/
|
||||
if ( *(long *) &a4_st2DVertex[2].xY > fYMax_CLIP_Optimize )
|
||||
{
|
||||
fClipYMax = (fClipYMin * ( GLI_BIG_GLOBALS->fYMaxClipping - a4_st2DVertex[2].xY ) ) / ( a4_st2DVertex[0].xY - a4_st2DVertex[2].xY );
|
||||
a4_st2DVertex[2].xY = a4_st2DVertex[3].xY = GLI_BIG_GLOBALS->fYMaxClipping;
|
||||
}
|
||||
else
|
||||
fClipYMax = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( *(long *) &GLI_BIG_GLOBALS->xWaterPlaneDistance != 0 );
|
||||
{
|
||||
GLI_DRV_xSendSpriteToClip_TRIANGLES( a4_st2DVertex, p_stGlobaleMT);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( (a4_st2DVertex [0] . xY < 0.0f) || (a4_st2DVertex [1] . xY < 0.0f) || (a4_st2DVertex [2] . xY < 0.0f) || (a4_st2DVertex [3] . xY < 0.0f) ) return;
|
||||
if ( (a4_st2DVertex [0] . xX < 0.0f) || (a4_st2DVertex [1] . xX < 0.0f) || (a4_st2DVertex [2] . xX < 0.0f) || (a4_st2DVertex [3] . xX < 0.0f) ) return;
|
||||
if ( (a4_st2DVertex [0] . xY > 480.0f) || (a4_st2DVertex [1] . xY > 480.0f) || (a4_st2DVertex [2] . xY > 480.0f) || (a4_st2DVertex [3] . xY > 480.0f) ) return;
|
||||
if ( (a4_st2DVertex [0] . xX > 640.0f) || (a4_st2DVertex [1] . xX > 640.0f) || (a4_st2DVertex [2] . xX > 640.0f) || (a4_st2DVertex [3] . xX > 640.0f) ) return;
|
||||
fClipXMin = fClipYMax = 0.0f;
|
||||
fClipYMin = fClipXMax = 1.0f;
|
||||
}
|
||||
|
||||
GLI_M_InitSprite();
|
||||
|
||||
ulColor = (p_stGlobaleMT->xTextureDontAcceptFog) ? 0xFF000000 : p_stGlobaleMT->ulSpecularColorForSprite;
|
||||
SetPackedSpecular( CurrentDestXYZ[0], ulColor );
|
||||
SetPackedSpecular( CurrentDestXYZ[1], ulColor );
|
||||
SetPackedSpecular( CurrentDestXYZ[2], ulColor );
|
||||
SetPackedSpecular( CurrentDestXYZ[3], ulColor );
|
||||
|
||||
SetU(CurrentDestXYZ[0], fClipXMax );
|
||||
SetV(CurrentDestXYZ[0], fClipYMin );
|
||||
SetU(CurrentDestXYZ[1], fClipXMin );
|
||||
SetV(CurrentDestXYZ[1], fClipYMin );
|
||||
SetU(CurrentDestXYZ[2], fClipXMin );
|
||||
SetV(CurrentDestXYZ[2], fClipYMax );
|
||||
SetU(CurrentDestXYZ[3], fClipXMax );
|
||||
SetV(CurrentDestXYZ[3], fClipYMax );
|
||||
|
||||
GLI_DrawQuad();
|
||||
GLI_AfterDraw();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : clip a sprite that have UV coordinates (it seems to be unused)
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DRV_vSendSpriteToClipWithUV
|
||||
(
|
||||
GLI_tdstAligned2DVector *a4_st2DVertex ,
|
||||
MTH_tdxReal *a8_stUVVertex,
|
||||
MTH_tdxReal xZ ,
|
||||
GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT)
|
||||
{
|
||||
unsigned long ulColor;
|
||||
|
||||
GLI_BeforeDraw();
|
||||
GLI_M_InitSprite();
|
||||
|
||||
if (a4_st2DVertex [0] . xY < 0.0f) return;
|
||||
if (a4_st2DVertex [1] . xY < 0.0f) return;
|
||||
if (a4_st2DVertex [2] . xY < 0.0f) return;
|
||||
if (a4_st2DVertex [3] . xY < 0.0f) return;
|
||||
if (a4_st2DVertex [0] . xY > GLI_BIG_GLOBALS->fYMaxClipping) return;
|
||||
if (a4_st2DVertex [1] . xY > GLI_BIG_GLOBALS->fYMaxClipping) return;
|
||||
if (a4_st2DVertex [2] . xY > GLI_BIG_GLOBALS->fYMaxClipping) return;
|
||||
if (a4_st2DVertex [3] . xY > GLI_BIG_GLOBALS->fYMaxClipping) return;
|
||||
|
||||
ulColor = (p_stGlobaleMT->xTextureDontAcceptFog) ? 0xFF000000 : p_stGlobaleMT->ulSpecularColorForSprite;
|
||||
SetPackedSpecular( CurrentDestXYZ[0], ulColor );
|
||||
SetPackedSpecular( CurrentDestXYZ[1], ulColor );
|
||||
SetPackedSpecular( CurrentDestXYZ[2], ulColor );
|
||||
SetPackedSpecular( CurrentDestXYZ[3], ulColor );
|
||||
|
||||
if ( p_stGlobaleMT->p_stCurrentTexture->lIncrementIsEnable )
|
||||
{
|
||||
float fAddU, fAddV;
|
||||
fAddU = p_stGlobaleMT-> p_stCurrentTexture -> fAddU;
|
||||
fAddV = p_stGlobaleMT-> p_stCurrentTexture -> fAddV;
|
||||
SetU(CurrentDestXYZ[2], a8_stUVVertex[4] + fAddU );
|
||||
SetV(CurrentDestXYZ[2], a8_stUVVertex[4 + 1] + fAddV);
|
||||
SetU(CurrentDestXYZ[3], a8_stUVVertex[6] + fAddU);
|
||||
SetV(CurrentDestXYZ[3], a8_stUVVertex[6 + 1] + fAddV);
|
||||
SetU(CurrentDestXYZ[0], a8_stUVVertex[0] + fAddU);
|
||||
SetV(CurrentDestXYZ[0], a8_stUVVertex[0 + 1] + fAddV);
|
||||
SetU(CurrentDestXYZ[1], a8_stUVVertex[2] + fAddU);
|
||||
SetV(CurrentDestXYZ[1], a8_stUVVertex[2 + 1] + fAddV);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetU(CurrentDestXYZ[2], a8_stUVVertex[4]);
|
||||
SetV(CurrentDestXYZ[2], a8_stUVVertex[4 + 1]);
|
||||
SetU(CurrentDestXYZ[3], a8_stUVVertex[6]);
|
||||
SetV(CurrentDestXYZ[3], a8_stUVVertex[6 + 1]);
|
||||
SetU(CurrentDestXYZ[0], a8_stUVVertex[0]);
|
||||
SetV(CurrentDestXYZ[0], a8_stUVVertex[0 + 1]);
|
||||
SetU(CurrentDestXYZ[1], a8_stUVVertex[2]);
|
||||
SetV(CurrentDestXYZ[1], a8_stUVVertex[2 + 1]);
|
||||
}
|
||||
GLI_DrawQuad();
|
||||
GLI_AfterDraw();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : clip a line (not implemented)
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
#if 0
|
||||
void GLI_DRV_vSendSingleLineToClip
|
||||
(
|
||||
GLD_tdstViewportAttributes *p_stVpt ,
|
||||
GLI_tdstAligned3DVector *p_stVertex1 ,
|
||||
GLI_tdstAligned2DVector *p_st2DVertex1 ,
|
||||
GLI_tdstAligned3DVector *p_stVertex2 ,
|
||||
GLI_tdstAligned2DVector *p_st2DVertex2 ,
|
||||
GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT,
|
||||
long lDrawModeMask, GEO_tdstColor *p_stColor
|
||||
)
|
||||
{
|
||||
|
||||
p_st2DVertex1->ulPackedColor =0xFFFFFFFF;
|
||||
p_st2DVertex2->ulPackedColor =0xFFFFFFFF;
|
||||
|
||||
GLI_M_InitLine();
|
||||
GLI_DrawLine();
|
||||
}
|
||||
#else
|
||||
|
||||
void GLI_DRV_vSendSingleLineToClip
|
||||
(
|
||||
GLD_tdstViewportAttributes *p_stVpt ,
|
||||
GLI_tdstAligned3DVector *p_stVertex1 ,
|
||||
GLI_tdstAligned2DVector *p_st2DVertex1 ,
|
||||
GLI_tdstAligned3DVector *p_stVertex2 ,
|
||||
GLI_tdstAligned2DVector *p_st2DVertex2 ,
|
||||
GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT,
|
||||
long lDrawModeMask, GEO_tdstColor *p_stColor
|
||||
)
|
||||
{
|
||||
|
||||
|
||||
DWORD dwRenderState;
|
||||
|
||||
g_pd3dDevice->lpVtbl->GetRenderState(g_pd3dDevice, D3DRENDERSTATE_ZENABLE,&dwRenderState);
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice, D3DRENDERSTATE_ZENABLE, FALSE);
|
||||
g_pd3dDevice->lpVtbl->SetTexture(g_pd3dDevice,0, NULL );
|
||||
|
||||
SetX(CurrentDestXYZ[0],p_st2DVertex1->xX);
|
||||
SetY(CurrentDestXYZ[0],p_st2DVertex1->xY);
|
||||
SetX(CurrentDestXYZ[1],p_st2DVertex2->xX);
|
||||
SetY(CurrentDestXYZ[1],p_st2DVertex2->xY);
|
||||
SetZ(CurrentDestXYZ[0],p_st2DVertex1->xOoZ );
|
||||
SetZ(CurrentDestXYZ[1],p_st2DVertex2->xOoZ );
|
||||
SetPackedColor(CurrentDestXYZ[0],p_st2DVertex1->ulPackedColor );
|
||||
SetPackedColor(CurrentDestXYZ[1],p_st2DVertex2->ulPackedColor );
|
||||
|
||||
g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_LINELIST, D3DFVF_TLVERTEX, CurrentDestXYZ, 2, GLI_C_dwDPFlag_Clip );
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice, D3DRENDERSTATE_ZENABLE, (BOOL)dwRenderState);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
738
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Caps.c
Normal file
738
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Caps.c
Normal file
@@ -0,0 +1,738 @@
|
||||
/*
|
||||
=======================================================================================
|
||||
Name : DX6_Caps.c
|
||||
Author : vincent lhullier Date :30/10/98
|
||||
Description : capabilities of driver (depend on hardware)
|
||||
=======================================================================================
|
||||
*/
|
||||
#include "DLLCom.h"
|
||||
#include "DX6_Choose.h"
|
||||
#include "DX6_Caps.h"
|
||||
|
||||
extern LPDIRECTDRAW4 g_pDD4;
|
||||
extern LPDIRECT3DDEVICE3 g_pd3dDevice;
|
||||
extern LPDIRECTDRAWSURFACE4 g_pddsPrimary;
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Globals
|
||||
=======================================================================================
|
||||
*/
|
||||
static long gs_lNumberOfPixelFormats;
|
||||
static DDPIXELFORMAT gs_a_stD3DPixelFormat[20];
|
||||
static char gs_a_cPixelFormatIndex[ GLI_DX6_TexNbFormats ];
|
||||
|
||||
static long gs_a_lPrecalculatedTextureSize[GLI_DX6_TexNbFormats][2][9][9];
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
private Functions prototypes
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
unsigned char GLI_DX6_fn_ucGetPrimarySurfacePixelFormat( LPDDPIXELFORMAT _p_stDDPF );
|
||||
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
public Functions
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : compute video memory
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
HRESULT GLI_DX6_hGetVideoMemory( LPDIRECTDRAW4 _pDD4, long _lDDSCaps, unsigned long *_ulTotal, unsigned long *_ulLeft )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
DDSCAPS2 stLocalVideoCaps;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
memset(&stLocalVideoCaps,0,sizeof(stLocalVideoCaps));
|
||||
stLocalVideoCaps.dwCaps = _lDDSCaps;
|
||||
return _pDD4->lpVtbl->GetAvailableVidMem( _pDD4 ,&stLocalVideoCaps,_ulTotal, _ulLeft );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Get driver caps
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
HRESULT GLI_DX6_fn_hGetDriverCaps( tdstGliCaps *_pst_Caps, long _lFlags, LPDIRECTDRAW4 _pDD4 )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
DDCAPS stHDDCaps;
|
||||
DDCAPS stSDDCaps;
|
||||
DDCAPS *p_stCaps;
|
||||
HRESULT hr;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
memset( &stHDDCaps, 0, sizeof( DDCAPS ) );
|
||||
memset( &stSDDCaps, 0, sizeof( DDCAPS ) );
|
||||
stHDDCaps.dwSize = stSDDCaps.dwSize = sizeof( DDCAPS );
|
||||
|
||||
hr = _pDD4->lpVtbl->GetCaps( _pDD4, &stHDDCaps, &stSDDCaps );
|
||||
if (hr != DD_OK)
|
||||
{
|
||||
char szText[512];
|
||||
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0, szText, 512, NULL );
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
p_stCaps = (_lFlags & DX6_C_Dev_Hardware) ? &stHDDCaps : &stSDDCaps;
|
||||
|
||||
if( p_stCaps->dwCaps & DDCAPS_3D)
|
||||
_pst_Caps->ulDriverCaps |= GLICAPS_DRV_C_ulIsHardware;
|
||||
|
||||
if ( ( p_stCaps->dwCaps & DDCAPS_PALETTE ) && (p_stCaps->dwPalCaps & DDPCAPS_8BIT ) && (p_stCaps->dwPalCaps & DDPCAPS_ALLOW256 ) )
|
||||
_pst_Caps->ulTextureCaps |= GLICAPS_TEX_C_ulSupport8P;
|
||||
|
||||
if( p_stCaps->dwCaps2 & DDCAPS2_NONLOCALVIDMEM)
|
||||
_pst_Caps->ulDriverCaps |= GLICAPS_DRV_C_ulCanUseAGP;
|
||||
|
||||
if( p_stCaps->dwCaps2 & DDCAPS2_CANRENDERWINDOWED )
|
||||
_pst_Caps->ulDriverCaps |= GLICAPS_DRV_C_ulCanBeWindowed | GLICAPS_DRV_C_ulReadjustViewport;
|
||||
|
||||
/*if( (stHDDCaps.ddsCaps.dwCaps & (DDSCAPS_COMPLEX | DDSCAPS_MIPMAP)) == (DDSCAPS_COMPLEX | DDSCAPS_MIPMAP) )*/
|
||||
if( p_stCaps->ddsCaps.dwCaps & DDSCAPS_MIPMAP )
|
||||
_pst_Caps->ulTextureCaps |= GLICAPS_TEX_C_ulSupportMipmap;
|
||||
|
||||
/* Compute monitor's refresh rate */
|
||||
if( TMR_MDRV_vTimerGetCounter && TMR_MDRV_ulTimerTickPerSecond )
|
||||
{
|
||||
hr = _pDD4->lpVtbl->WaitForVerticalBlank( _pDD4, DDWAITVB_BLOCKBEGIN, NULL );
|
||||
if( FAILED( hr ) )
|
||||
_pst_Caps->fRefreshRate = 60.0f;
|
||||
else
|
||||
{
|
||||
stTimerCount stTimerBefore, stTimerAfter;
|
||||
int i;
|
||||
|
||||
TMR_MDRV_vTimerGetCounter( C_wTimerFrequencyMedium, &stTimerBefore );
|
||||
/* it's a 10 frame sample */
|
||||
for( i=0; i<10; i++ )
|
||||
{
|
||||
hr = _pDD4->lpVtbl->WaitForVerticalBlank( _pDD4, DDWAITVB_BLOCKBEGIN, NULL );
|
||||
if( FAILED( hr ) )
|
||||
break;
|
||||
}
|
||||
TMR_MDRV_vTimerGetCounter( C_wTimerFrequencyMedium, &stTimerAfter );
|
||||
|
||||
if( i<10 )
|
||||
/* If an error occured we set the refresh rate to 60Hz */
|
||||
_pst_Caps->fRefreshRate = 60.0f;
|
||||
else
|
||||
/* Else, we compute it normally. The result is rounded to the nearest integer value. */
|
||||
_pst_Caps->fRefreshRate =
|
||||
(float)floor(
|
||||
0.5f +
|
||||
((float) i * TMR_MDRV_ulTimerTickPerSecond(C_wTimerFrequencyMedium))
|
||||
/ ((float)abs( stTimerAfter.m_ulLowPart - stTimerBefore.m_ulLowPart) ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
_pst_Caps->fRefreshRate = 60.0f;
|
||||
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Get device caps
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
HRESULT GLI_DX6_fn_hGetDeviceCaps( tdstGliCaps *_pst_Caps, LPDIRECTDRAW4 _pDD4, D3DDEVICEDESC *_pst_DevDesc )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
HRESULT hr;
|
||||
unsigned long ulTotal, ulLeft;
|
||||
DDPIXELFORMAT stPixelFormat;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
/*
|
||||
* Alpha test
|
||||
*/
|
||||
if ( _pst_DevDesc->dpcTriCaps.dwAlphaCmpCaps & D3DPCMPCAPS_GREATEREQUAL )
|
||||
_pst_Caps->ulDriverCaps |= GLICAPS_DRV_C_ulSupportAlphaTest;
|
||||
|
||||
/*
|
||||
* non squared texture
|
||||
*/
|
||||
if (!(_pst_DevDesc->dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY))
|
||||
_pst_Caps->ulTextureCaps |= GLICAPS_TEX_C_ulSupportNonSquare;
|
||||
|
||||
/*
|
||||
* non local texture
|
||||
*/
|
||||
if ( _pst_DevDesc->dwDevCaps & D3DDEVCAPS_TEXTURENONLOCALVIDMEM )
|
||||
_pst_Caps->ulDriverCaps |= GLICAPS_DRV_C_ulCanUseAGP;
|
||||
else if (_pst_Caps->ulDriverCaps & GLICAPS_DRV_C_ulCanUseAGP )
|
||||
_pst_Caps->ulDriverCaps -= GLICAPS_DRV_C_ulCanUseAGP;
|
||||
|
||||
/*
|
||||
* max texture size
|
||||
*/
|
||||
_pst_Caps->ulTextureMaxSize = __min(_pst_DevDesc->dwMaxTextureWidth, _pst_DevDesc->dwMaxTextureHeight);
|
||||
if ( _pst_Caps->ulTextureMaxSize == 0)
|
||||
_pst_Caps->ulTextureMaxSize = 256;
|
||||
|
||||
/*
|
||||
* total video mem (local and non local)
|
||||
*/
|
||||
hr = GLI_DX6_hGetVideoMemory( _pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulLeft );
|
||||
if (hr == DD_OK)
|
||||
{
|
||||
_pst_Caps->ulTotalVideoMemory = ulTotal;
|
||||
_pst_Caps->ulTotalTextureMemory = ulLeft;
|
||||
}
|
||||
|
||||
if ( _pst_Caps->ulDriverCaps & GLICAPS_DRV_C_ulCanUseAGP)
|
||||
{
|
||||
hr = GLI_DX6_hGetVideoMemory( _pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulLeft );
|
||||
if (hr == DD_OK)
|
||||
{
|
||||
_pst_Caps->ulTotalAGPMemory = ulTotal;
|
||||
/*_pst_Caps->ulTotalTextureMemory += ulLeft;*/
|
||||
}
|
||||
else
|
||||
_pst_Caps->ulDriverCaps -= GLICAPS_DRV_C_ulCanUseAGP;
|
||||
}
|
||||
|
||||
/*
|
||||
* pixel format of primary surface
|
||||
*/
|
||||
if ( g_pddsPrimary )
|
||||
{
|
||||
memset( &stPixelFormat, 0, sizeof(DDPIXELFORMAT) );
|
||||
stPixelFormat.dwSize = sizeof( DDPIXELFORMAT );
|
||||
g_pddsPrimary->lpVtbl->GetPixelFormat(g_pddsPrimary, &stPixelFormat );
|
||||
_pst_Caps->ucPrimarySurfacePixelFormat = GLI_DX6_fn_ucGetPrimarySurfacePixelFormat(&stPixelFormat);
|
||||
}
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
=======================================================================================
|
||||
Private Function
|
||||
=======================================================================================
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
conversion D3D Pixel format to Defined Pixel Format
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
long GLI_DX6_fn_lConvertMaskToShift ( unsigned long _ulMask )
|
||||
{
|
||||
if ( _ulMask & 0x00000001 ) return 0;
|
||||
if ( _ulMask & 0x00000002 ) return 1;
|
||||
if ( _ulMask & 0x00000004 ) return 2;
|
||||
if ( _ulMask & 0x00000008 ) return 3;
|
||||
if ( _ulMask & 0x00000010 ) return 4;
|
||||
if ( _ulMask & 0x00000020 ) return 5;
|
||||
if ( _ulMask & 0x00000040 ) return 6;
|
||||
if ( _ulMask & 0x00000080 ) return 7;
|
||||
if ( _ulMask & 0x00000100 ) return 8;
|
||||
if ( _ulMask & 0x00000200 ) return 9;
|
||||
if ( _ulMask & 0x00000400 ) return 10;
|
||||
if ( _ulMask & 0x00000800 ) return 11;
|
||||
if ( _ulMask & 0x00001000 ) return 12;
|
||||
if ( _ulMask & 0x00002000 ) return 13;
|
||||
if ( _ulMask & 0x00004000 ) return 14;
|
||||
if ( _ulMask & 0x00008000 ) return 15;
|
||||
if ( _ulMask & 0x00010000 ) return 16;
|
||||
if ( _ulMask & 0x00020000 ) return 17;
|
||||
if ( _ulMask & 0x00040000 ) return 18;
|
||||
if ( _ulMask & 0x00080000 ) return 19;
|
||||
if ( _ulMask & 0x00100000 ) return 20;
|
||||
if ( _ulMask & 0x00200000 ) return 21;
|
||||
if ( _ulMask & 0x00400000 ) return 22;
|
||||
if ( _ulMask & 0x00800000 ) return 23;
|
||||
if ( _ulMask & 0x01000000 ) return 24;
|
||||
if ( _ulMask & 0x02000000 ) return 25;
|
||||
if ( _ulMask & 0x04000000 ) return 26;
|
||||
if ( _ulMask & 0x08000000 ) return 27;
|
||||
if ( _ulMask & 0x10000000 ) return 28;
|
||||
if ( _ulMask & 0x20000000 ) return 29;
|
||||
if ( _ulMask & 0x40000000 ) return 30;
|
||||
if ( _ulMask & 0x80000000 ) return 31;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long GLI_DX6_fn_ulConvertNbBitsToMask ( long _lNbBits )
|
||||
{
|
||||
if ( _lNbBits == 0 ) return 0x00000000;
|
||||
if ( _lNbBits == 1 ) return 0x00000001;
|
||||
if ( _lNbBits == 2 ) return 0x00000003;
|
||||
if ( _lNbBits == 3 ) return 0x00000007;
|
||||
if ( _lNbBits == 4 ) return 0x0000000F;
|
||||
if ( _lNbBits == 5 ) return 0x0000001F;
|
||||
if ( _lNbBits == 6 ) return 0x0000003F;
|
||||
if ( _lNbBits == 7 ) return 0x0000007F;
|
||||
if ( _lNbBits == 8 ) return 0x000000FF;
|
||||
if ( _lNbBits == 9 ) return 0x000001FF;
|
||||
if ( _lNbBits == 10 ) return 0x000003FF;
|
||||
if ( _lNbBits == 11 ) return 0x000007FF;
|
||||
if ( _lNbBits == 12 ) return 0x00000FFF;
|
||||
if ( _lNbBits == 13 ) return 0x00001FFF;
|
||||
if ( _lNbBits == 14 ) return 0x00003FFF;
|
||||
if ( _lNbBits == 15 ) return 0x00007FFF;
|
||||
if ( _lNbBits == 16 ) return 0x0000FFFF;
|
||||
if ( _lNbBits == 17 ) return 0x0001FFFF;
|
||||
if ( _lNbBits == 18 ) return 0x0003FFFF;
|
||||
if ( _lNbBits == 19 ) return 0x0007FFFF;
|
||||
if ( _lNbBits == 20 ) return 0x000FFFFF;
|
||||
if ( _lNbBits == 21 ) return 0x001FFFFF;
|
||||
if ( _lNbBits == 22 ) return 0x003FFFFF;
|
||||
if ( _lNbBits == 23 ) return 0x007FFFFF;
|
||||
if ( _lNbBits == 24 ) return 0x00FFFFFF;
|
||||
if ( _lNbBits == 25 ) return 0x01FFFFFF;
|
||||
if ( _lNbBits == 26 ) return 0x03FFFFFF;
|
||||
if ( _lNbBits == 27 ) return 0x07FFFFFF;
|
||||
if ( _lNbBits == 28 ) return 0x0FFFFFFF;
|
||||
if ( _lNbBits == 29 ) return 0x1FFFFFFF;
|
||||
if ( _lNbBits == 30 ) return 0x3FFFFFFF;
|
||||
if ( _lNbBits == 31 ) return 0x7FFFFFFF;
|
||||
if ( _lNbBits == 32 ) return 0xFFFFFFFF;
|
||||
return 0x00000000;
|
||||
}
|
||||
|
||||
long GLI_DX6_fn_lConvertMaskToNbBits( unsigned long _ulMask )
|
||||
{
|
||||
if ( _ulMask == 0x00000000 ) return 0;
|
||||
if ( _ulMask == 0x00000001 ) return 1;
|
||||
if ( _ulMask == 0x00000003 ) return 2;
|
||||
if ( _ulMask == 0x00000007 ) return 3;
|
||||
if ( _ulMask == 0x0000000F ) return 4;
|
||||
if ( _ulMask == 0x0000001F ) return 5;
|
||||
if ( _ulMask == 0x0000003F ) return 6;
|
||||
if ( _ulMask == 0x0000007F ) return 7;
|
||||
if ( _ulMask == 0x000000FF ) return 8;
|
||||
if ( _ulMask == 0x000001FF ) return 9;
|
||||
if ( _ulMask == 0x000003FF ) return 10;
|
||||
if ( _ulMask == 0x000007FF ) return 11;
|
||||
if ( _ulMask == 0x00000FFF ) return 12;
|
||||
if ( _ulMask == 0x00001FFF ) return 13;
|
||||
if ( _ulMask == 0x00003FFF ) return 14;
|
||||
if ( _ulMask == 0x00007FFF ) return 15;
|
||||
if ( _ulMask == 0x0000FFFF ) return 16;
|
||||
if ( _ulMask == 0x0001FFFF ) return 17;
|
||||
if ( _ulMask == 0x0003FFFF ) return 18;
|
||||
if ( _ulMask == 0x0007FFFF ) return 19;
|
||||
if ( _ulMask == 0x000FFFFF ) return 20;
|
||||
if ( _ulMask == 0x001FFFFF ) return 21;
|
||||
if ( _ulMask == 0x003FFFFF ) return 22;
|
||||
if ( _ulMask == 0x007FFFFF ) return 23;
|
||||
if ( _ulMask == 0x00FFFFFF ) return 24;
|
||||
if ( _ulMask == 0x01FFFFFF ) return 25;
|
||||
if ( _ulMask == 0x03FFFFFF ) return 26;
|
||||
if ( _ulMask == 0x07FFFFFF ) return 27;
|
||||
if ( _ulMask == 0x0FFFFFFF ) return 28;
|
||||
if ( _ulMask == 0x1FFFFFFF ) return 29;
|
||||
if ( _ulMask == 0x3FFFFFFF ) return 30;
|
||||
if ( _ulMask == 0x7FFFFFFF ) return 31;
|
||||
if ( _ulMask == 0xFFFFFFFF ) return 32;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ACP_tdxBool GLI_DX6_fn_bEqualRGBMask( GLD_tdpstPixelFormat _p_stPF, DDPIXELFORMAT *_p_stDDPF )
|
||||
{
|
||||
return ( _p_stPF->ulRedMask == _p_stDDPF->dwRBitMask ) && ( _p_stPF->ulGreenMask == _p_stDDPF->dwGBitMask ) && ( _p_stPF->ulBlueMask == _p_stDDPF->dwBBitMask );
|
||||
}
|
||||
|
||||
ACP_tdxBool GLI_DX6_fn_bEqualRGBAMask( GLD_tdpstPixelFormat _p_stPF, DDPIXELFORMAT *_p_stDDPF )
|
||||
{
|
||||
return ( _p_stPF->ulRedMask == _p_stDDPF->dwRBitMask ) && ( _p_stPF->ulGreenMask == _p_stDDPF->dwGBitMask ) && ( _p_stPF->ulBlueMask == _p_stDDPF->dwBBitMask ) && ( _p_stPF->ulAlphaMask == _p_stDDPF->dwRGBAlphaBitMask );
|
||||
}
|
||||
|
||||
void GLI_DX6_fn_vConvertDDPixelFormatToPixelFormat( GLD_tdpstPixelFormat _p_stPF, LPDDPIXELFORMAT _p_stDDPF )
|
||||
{
|
||||
_p_stPF->xFormatNumber = 0;
|
||||
_p_stPF->bAlpha = (unsigned char) (_p_stDDPF->dwFlags & DDPF_ALPHAPIXELS);
|
||||
|
||||
_p_stPF->lPixelNbBits = _p_stDDPF->dwRGBBitCount;
|
||||
_p_stPF->ulPixelMask = GLI_DX6_fn_ulConvertNbBitsToMask( _p_stPF->lPixelNbBits );
|
||||
_p_stPF->lPixelNbBytes = _p_stPF->lPixelNbBits/8;
|
||||
|
||||
_p_stPF->ulRedMask = _p_stDDPF->dwRBitMask;
|
||||
_p_stPF->lRedShift = GLI_DX6_fn_lConvertMaskToShift( _p_stPF->ulRedMask );
|
||||
_p_stPF->lRedNbBits = GLI_DX6_fn_lConvertMaskToNbBits( _p_stPF->ulRedMask >> _p_stPF->lRedShift );
|
||||
|
||||
_p_stPF->ulGreenMask = _p_stDDPF->dwGBitMask;
|
||||
_p_stPF->lGreenShift = GLI_DX6_fn_lConvertMaskToShift( _p_stPF->ulGreenMask );
|
||||
_p_stPF->lGreenNbBits = GLI_DX6_fn_lConvertMaskToNbBits( _p_stPF->ulGreenMask >> _p_stPF->lGreenShift );
|
||||
|
||||
_p_stPF->ulBlueMask = _p_stDDPF->dwBBitMask;
|
||||
_p_stPF->lBlueShift = GLI_DX6_fn_lConvertMaskToShift( _p_stPF->ulBlueMask );
|
||||
_p_stPF->lBlueNbBits = GLI_DX6_fn_lConvertMaskToNbBits( _p_stPF->ulBlueMask >> _p_stPF->lBlueShift );
|
||||
|
||||
if ( _p_stPF->bAlpha )
|
||||
{
|
||||
_p_stPF->ulAlphaMask = _p_stDDPF->dwRGBAlphaBitMask;
|
||||
_p_stPF->lAlphaShift = GLI_DX6_fn_lConvertMaskToShift( _p_stPF->ulAlphaMask );
|
||||
_p_stPF->lAlphaNbBits= GLI_DX6_fn_lConvertMaskToNbBits( _p_stPF->ulAlphaMask >> _p_stPF->lAlphaShift );
|
||||
}
|
||||
else
|
||||
{
|
||||
_p_stPF->ulAlphaMask = 0x00000000;
|
||||
_p_stPF->lAlphaShift = 0;
|
||||
_p_stPF->lAlphaNbBits= 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
long GLI_DX6_fn_lGetEquivalentPixelFormat( LPDDPIXELFORMAT _p_stDDPixelFormat )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
long lFormatIndex;
|
||||
GLD_tdstPixelFormat *_p_stDefinedPF;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
if ( !(_p_stDDPixelFormat->dwFlags & DDPF_RGB) )
|
||||
return -1;
|
||||
|
||||
lFormatIndex = 0;
|
||||
while(1)
|
||||
{
|
||||
_p_stDefinedPF = GLD_MDRV_fn_p_stGetDefinedPixelFormat( lFormatIndex );
|
||||
if (_p_stDefinedPF == NULL)
|
||||
return -1;
|
||||
|
||||
if ( _p_stDefinedPF->lPixelNbBits == (long) _p_stDDPixelFormat->dwRGBBitCount )
|
||||
{
|
||||
if ( _p_stDDPixelFormat->dwFlags & DDPF_ALPHAPIXELS )
|
||||
{
|
||||
if ( ( _p_stDefinedPF->bAlpha ) && ( GLI_DX6_fn_bEqualRGBAMask( _p_stDefinedPF, _p_stDDPixelFormat ) ) )
|
||||
return lFormatIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ( !_p_stDefinedPF->bAlpha ) && ( GLI_DX6_fn_bEqualRGBMask( _p_stDefinedPF, _p_stDDPixelFormat ) ) )
|
||||
return lFormatIndex;
|
||||
}
|
||||
|
||||
}
|
||||
lFormatIndex++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char GLI_DX6_fn_ucGetPrimarySurfacePixelFormat( LPDDPIXELFORMAT _p_stDDPF )
|
||||
{
|
||||
long lPixelFormat;
|
||||
GLD_tdstPixelFormat stPF;
|
||||
|
||||
lPixelFormat = GLI_DX6_fn_lGetEquivalentPixelFormat( _p_stDDPF );
|
||||
if (lPixelFormat != -1)
|
||||
return (unsigned char) lPixelFormat;
|
||||
|
||||
GLI_DX6_fn_vConvertDDPixelFormatToPixelFormat( &stPF, _p_stDDPF );
|
||||
lPixelFormat = GLD_MDRV_fn_lAddDefinedPixelFormat( &stPF );
|
||||
if (lPixelFormat != -1 )
|
||||
return (unsigned char ) lPixelFormat;
|
||||
|
||||
return (unsigned char) GLD_C_xUndefinedPixelFormat;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
D3D texture format
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : callback (use by D3DDevice3 method "EnumTextureFormats")
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
static HRESULT CALLBACK fn_D3DCallbackGetPixelFormats (LPDDPIXELFORMAT _pddPF,LPVOID lpContext)
|
||||
{
|
||||
/*
|
||||
* Record the DDSURFACEDESC of this texture format
|
||||
*/
|
||||
/* Skip any funky modes*/
|
||||
if( _pddPF->dwFlags & (DDPF_LUMINANCE|DDPF_BUMPLUMINANCE|DDPF_BUMPDUDV) )
|
||||
return DDENUMRET_OK;
|
||||
|
||||
memset(&gs_a_stD3DPixelFormat[ gs_lNumberOfPixelFormats ], 0,sizeof(DDPIXELFORMAT));
|
||||
memcpy(&gs_a_stD3DPixelFormat[ gs_lNumberOfPixelFormats ], _pddPF,sizeof(DDPIXELFORMAT));
|
||||
gs_lNumberOfPixelFormats++;
|
||||
return DDENUMRET_OK;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : This function update stD3DTextureFormat from the device
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
HRESULT GLI_DX6_fn_hGetPixelFormats( void )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
HRESULT hr;
|
||||
long lIndex;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
|
||||
/*
|
||||
* Set the default format to -1 to let the callback know it's being
|
||||
* called for the first time.
|
||||
*/
|
||||
gs_lNumberOfPixelFormats = 0;
|
||||
hr = g_pd3dDevice->lpVtbl->EnumTextureFormats( g_pd3dDevice, &fn_D3DCallbackGetPixelFormats,NULL);
|
||||
if (hr != DD_OK)
|
||||
return hr;
|
||||
|
||||
memset( gs_a_cPixelFormatIndex, -1, GLI_DX6_TexNbFormats );
|
||||
for ( lIndex = 0; lIndex < gs_lNumberOfPixelFormats; lIndex++)
|
||||
{
|
||||
if (gs_a_stD3DPixelFormat[lIndex].dwFlags & DDPF_RGB)
|
||||
{
|
||||
/*
|
||||
* 32 bits format
|
||||
*/
|
||||
if (gs_a_stD3DPixelFormat[lIndex].dwRGBBitCount == 32)
|
||||
{
|
||||
if (gs_a_stD3DPixelFormat[lIndex].dwFlags & DDPF_ALPHAPIXELS)
|
||||
{
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat8888 ] = (char) lIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat888 ] = (char) lIndex;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 16 bit format
|
||||
*/
|
||||
else if (gs_a_stD3DPixelFormat[lIndex].dwRGBBitCount == 16)
|
||||
{
|
||||
/* alpha format*/
|
||||
if (gs_a_stD3DPixelFormat[lIndex].dwFlags & DDPF_ALPHAPIXELS)
|
||||
{
|
||||
if( (gs_a_stD3DPixelFormat[lIndex].dwRGBAlphaBitMask == 0xF000) || (gs_a_stD3DPixelFormat[lIndex].dwRGBAlphaBitMask == 0xF) )
|
||||
{
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat4444 ] = (char) lIndex;
|
||||
}
|
||||
else if ( (gs_a_stD3DPixelFormat[lIndex].dwRGBAlphaBitMask != 0x1) && (gs_a_stD3DPixelFormat[lIndex].dwRGBAlphaBitMask != 0x8000) )
|
||||
{
|
||||
if ( gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat4444 ] == -1)
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat4444 ] = (char) lIndex;
|
||||
}
|
||||
else if ( (gs_a_stD3DPixelFormat[lIndex].dwRGBAlphaBitMask == 0x1) || (gs_a_stD3DPixelFormat[lIndex].dwRGBAlphaBitMask == 0x8000) )
|
||||
{
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat1555 ] = (char) lIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat4444 ] == -1)
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat4444 ] = (char) lIndex;
|
||||
if ( gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat1555 ] == -1)
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat1555 ] = (char) lIndex;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(gs_a_stD3DPixelFormat[lIndex].dwGBitMask == 0x07E0)
|
||||
{
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat565 ] = (char) lIndex;
|
||||
if ( gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat4444 ] == -1)
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat4444 ] = (char) lIndex;
|
||||
if ( gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat1555 ] == -1)
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat1555 ] = (char) lIndex;
|
||||
|
||||
}
|
||||
else if(gs_a_stD3DPixelFormat[lIndex].dwGBitMask == 0x03E0)
|
||||
{
|
||||
if ( gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat565 ] != -1 )
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat565 ] = (char) lIndex;
|
||||
if ( gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat4444 ] == -1)
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat4444 ] = (char) lIndex;
|
||||
if ( gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat1555 ] == -1)
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormat1555 ] = (char) lIndex;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 8 bit format
|
||||
*/
|
||||
else if (gs_a_stD3DPixelFormat[lIndex].dwRGBBitCount == 8)
|
||||
{
|
||||
if( gs_a_stD3DPixelFormat[lIndex].dwFlags & DDPF_PALETTEINDEXED8 )
|
||||
gs_a_cPixelFormatIndex[ GLI_DX6_TexFormatPalette8 ] = (char) lIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* some more check
|
||||
*/
|
||||
if ( ( gs_a_cPixelFormatIndex[ GLI_DX6_TexFormatPalette8 ] == -1) && (g_p_stGliCaps->ulTextureCaps & GLICAPS_TEX_C_ulSupport8P) )
|
||||
g_p_stGliCaps->ulTextureCaps -= GLICAPS_TEX_C_ulSupport8P;
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Get pixel format that correspond to a constant
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DX6_fn_vGetPixelFormat( char _ucFormatAsked, DDPIXELFORMAT *_p_stPixelFormat )
|
||||
{
|
||||
if ( (_ucFormatAsked >= GLI_DX6_TexNbFormats) || (gs_a_cPixelFormatIndex[ _ucFormatAsked ] == -1 ) )
|
||||
*_p_stPixelFormat = gs_a_stD3DPixelFormat[0];
|
||||
else
|
||||
*_p_stPixelFormat = gs_a_stD3DPixelFormat[ gs_a_cPixelFormatIndex[ _ucFormatAsked ] ];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Precalculate different texture size
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : precalculate texture size
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DX6_fn_vPrecalculateTextureSize( void )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
char cTexFormat;
|
||||
char cMipmap;
|
||||
char cWidth, cHeight;
|
||||
long lWidth, lHeight;
|
||||
DDSURFACEDESC2 ddsd;
|
||||
unsigned long ulMemoryBefore, ulMemoryAfter, ulTotal, ulLeft;
|
||||
HRESULT hr;
|
||||
LPDIRECTDRAWSURFACE4 p_stDDS4;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
memset(&ddsd, 0, sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
|
||||
for (cTexFormat = 0; cTexFormat < GLI_DX6_TexNbFormats; cTexFormat++)
|
||||
{
|
||||
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT ;
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD | DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
|
||||
GLI_DX6_fn_vGetPixelFormat( cTexFormat, &ddsd.ddpfPixelFormat );
|
||||
|
||||
for (cMipmap = 0; cMipmap < 2; cMipmap++)
|
||||
{
|
||||
if (cMipmap)
|
||||
{
|
||||
if ( !( g_p_stGliCaps->ulTextureCaps & GLICAPS_TEX_C_ulSupportMipmap ) )
|
||||
{
|
||||
for (cWidth = 0, lWidth = 1; cWidth < 9 ; cWidth++, lWidth <<= 1 )
|
||||
for (cHeight = 0, lHeight = 1; cHeight < 9; cHeight++, lHeight <<= 1)
|
||||
gs_a_lPrecalculatedTextureSize[ cTexFormat ][ 1 ][ cWidth ][ cHeight ] = gs_a_lPrecalculatedTextureSize[ cTexFormat ][ 0 ][ cWidth ][ cHeight ];
|
||||
continue;
|
||||
}
|
||||
|
||||
ddsd.ddsCaps.dwCaps |= DDSCAPS_MIPMAP | DDSCAPS_COMPLEX;
|
||||
ddsd.dwFlags |= DDSD_MIPMAPCOUNT;
|
||||
}
|
||||
|
||||
for (cWidth = 0, lWidth = 1; cWidth < 9 ; cWidth++, lWidth <<= 1 )
|
||||
{
|
||||
for (cHeight = 0, lHeight = 1; cHeight < 9; cHeight++, lHeight <<= 1)
|
||||
{
|
||||
ddsd.dwWidth = lWidth;
|
||||
ddsd.dwHeight = lHeight;
|
||||
|
||||
if (cMipmap)
|
||||
ddsd.dwMipMapCount = ((cWidth > cHeight) ? cHeight : cWidth) + 1;
|
||||
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulMemoryBefore );
|
||||
if (g_p_stGliCaps->ulDriverCaps & GLICAPS_DRV_C_ulCanUseAGP )
|
||||
{
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulLeft);
|
||||
ulMemoryBefore += ulLeft;
|
||||
}
|
||||
|
||||
/*
|
||||
* create texture surface
|
||||
*/
|
||||
hr = g_pDD4->lpVtbl->CreateSurface( g_pDD4, &ddsd, &p_stDDS4, NULL );
|
||||
if ( (hr != DD_OK) || !(p_stDDS4) )
|
||||
{
|
||||
gs_a_lPrecalculatedTextureSize[ cTexFormat ][ cMipmap ][ cWidth ][ cHeight ] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulMemoryAfter );
|
||||
if (g_p_stGliCaps->ulDriverCaps & GLICAPS_DRV_C_ulCanUseAGP )
|
||||
{
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulLeft);
|
||||
ulMemoryAfter += ulLeft;
|
||||
}
|
||||
|
||||
|
||||
gs_a_lPrecalculatedTextureSize[ cTexFormat ][ cMipmap ][ cWidth ][ cHeight ] = ulMemoryBefore - ulMemoryAfter;
|
||||
|
||||
do
|
||||
{
|
||||
hr = p_stDDS4->lpVtbl->Release( p_stDDS4 );
|
||||
} while( hr );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
FILE *hpFile;
|
||||
hpFile = fopen( "PreCalcTextureSize.log", "wt" );
|
||||
if (hpFile == NULL)
|
||||
return;
|
||||
|
||||
fprintf( hpFile, "Precalculated texture size\r\n\r\n[PixelFormat][mipmap count][Width][height][size]\r\n\r\n" );
|
||||
|
||||
for (cTexFormat = 0; cTexFormat < GLI_DX6_TexNbFormats; cTexFormat++)
|
||||
for (cMipmap = 0; cMipmap < 2; cMipmap++)
|
||||
for (cWidth = 0, lWidth = 1; cWidth < 9 ; cWidth++, lWidth <<= 1 )
|
||||
for (cHeight = 0, lHeight = 1; cHeight < 9; cHeight++, lHeight <<= 1)
|
||||
{
|
||||
if (cMipmap)
|
||||
ddsd.dwMipMapCount = ((cWidth > cHeight) ? cHeight : cWidth) + 1;
|
||||
else
|
||||
ddsd.dwMipMapCount = 0;
|
||||
|
||||
fprintf( hpFile, "%d %d %3d %3d %8d %8X\r\n", cTexFormat, ddsd.dwMipMapCount, lWidth, lHeight,
|
||||
gs_a_lPrecalculatedTextureSize[ cTexFormat ][ cMipmap ][ cWidth ][ cHeight ],
|
||||
gs_a_lPrecalculatedTextureSize[ cTexFormat ][ cMipmap ][ cWidth ][ cHeight ] );
|
||||
}
|
||||
fclose( hpFile );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Get precalculated size
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
long GLI_DX6_fn_lGetPrecalculatedTextureSize( char _cTexFormat, char _cMipmap, long _lWidth, long _lHeight )
|
||||
{
|
||||
char cWidth, cHeight;
|
||||
|
||||
cWidth = (char) GLI_DX6_fn_lConvertMaskToShift( _lWidth );
|
||||
cHeight = (char) GLI_DX6_fn_lConvertMaskToShift( _lHeight );
|
||||
|
||||
return gs_a_lPrecalculatedTextureSize[ _cTexFormat ][ _cMipmap ][ cWidth ][ cHeight ];
|
||||
}
|
319
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Choose.c
Normal file
319
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Choose.c
Normal file
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
=======================================================================================
|
||||
Name : DX6_Choose.c
|
||||
Author : vincent lhullier Date :21/08/98
|
||||
Description : choose DirectX modes
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
#include <stdio.h>
|
||||
|
||||
#define INITGUID
|
||||
#include "d3d.h"
|
||||
#include "ddraw.h"
|
||||
|
||||
#include "GLI_util.h"
|
||||
#include "DispMode.h"
|
||||
#include "DLLCom.h"
|
||||
#include "DX6_Caps.h"
|
||||
#include "DX6_Choose.h"
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Extern (globals and function prototypes)
|
||||
=======================================================================================
|
||||
*/
|
||||
extern GUID GLIDX6_gx_DDDriverGuid;
|
||||
extern GUID GLIDX6_gx_D3DDeviceGuid;
|
||||
|
||||
long GLIDX6_gl_DeviceFlags;
|
||||
D3DDEVICEDESC GLIDX6_gst_DeviceDesc;
|
||||
|
||||
static char GLIDX6_gc_Found;
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Direct draw Display mode
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : enumeration call back to get all display mode
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
HRESULT CALLBACK GLIDX6_fnh_GetAllDisplayModesCallback(LPDDSURFACEDESC2 pddsd, LPVOID lpContext)
|
||||
{
|
||||
//chbani if ( ( pddsd->ddpfPixelFormat.dwRGBBitCount == 16 ) /* || ( pddsd->ddpfPixelFormat.dwRGBBitCount == 32 )*/ )
|
||||
{
|
||||
GLI_MDRV_lAddDisplayMode( 0, pddsd->dwWidth, pddsd->dwHeight, pddsd->ddpfPixelFormat.dwRGBBitCount ); //chbani 1-->0
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : enumeration call back to get all drivers
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
BOOL WINAPI GLIDX6_fnb_GetDriverCallback( GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext )
|
||||
{
|
||||
if ( strcmp( (char*) lpContext, lpDriverName ) == 0 )
|
||||
{
|
||||
if (lpGUID != NULL)
|
||||
memcpy( &GLIDX6_gx_DDDriverGuid, lpGUID, sizeof( GUID ) );
|
||||
else
|
||||
memset( &GLIDX6_gx_DDDriverGuid, 0, sizeof( GUID ) );
|
||||
GLIDX6_gc_Found = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* continue enumeration*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : enumeration call back to get device
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
static HRESULT CALLBACK GLIDX6_fnh_GetDeviceCallback( GUID *_pGuid, LPSTR _szDesc, LPSTR _szName, LPD3DDEVICEDESC _lpHWDesc, LPD3DDEVICEDESC _lpHELDesc, LPVOID _lpContext )
|
||||
{
|
||||
if ( strcmp( _szName, (char*) _lpContext ) == 0 )
|
||||
{
|
||||
GLIDX6_gc_Found = 1;
|
||||
memcpy( &GLIDX6_gx_D3DDeviceGuid, _pGuid, sizeof( GUID ) );
|
||||
|
||||
if ( _lpHWDesc->dcmColorModel )
|
||||
{
|
||||
GLIDX6_gl_DeviceFlags = DX6_C_Dev_Hardware;
|
||||
memcpy( &GLIDX6_gst_DeviceDesc, _lpHWDesc, sizeof( D3DDEVICEDESC ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
GLIDX6_gl_DeviceFlags = 0;
|
||||
memcpy( &GLIDX6_gst_DeviceDesc, _lpHELDesc, sizeof( D3DDEVICEDESC ) );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return D3DENUMRET_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Main mode enumeration function called by engine initialization
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
long __declspec(dllexport) GLI_DRV_fnl_EnumModes( char *_sz_DriverName, char *_sz_DeviceName )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
LPDIRECT3D3 pD3D = NULL;
|
||||
LPDIRECTDRAW4 pDD4 = NULL;
|
||||
LPDIRECTDRAW pDD;
|
||||
|
||||
HRESULT hr;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
/*
|
||||
* get driver
|
||||
*/
|
||||
GLIDX6_gc_Found = 0;
|
||||
hr = DirectDrawEnumerate( GLIDX6_fnb_GetDriverCallback, (void *) _sz_DriverName );
|
||||
if ( (hr != DD_OK) || (GLIDX6_gc_Found == 0) )
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* get device
|
||||
*/
|
||||
hr = DirectDrawCreate( &GLIDX6_gx_DDDriverGuid, &pDD, NULL );
|
||||
if (hr != DD_OK)
|
||||
return 0;
|
||||
|
||||
/* Get a ptr to an IDirectDraw4 interface. This interface to DirectDraw represents the DX6 version of the API.*/
|
||||
hr = pDD->lpVtbl->QueryInterface( pDD, &IID_IDirectDraw4, (LPVOID *) &pDD4 );
|
||||
pDD->lpVtbl->Release(pDD);
|
||||
if (hr != DD_OK)
|
||||
return 0;
|
||||
|
||||
/* Query DirectDraw for access to Direct3D*/
|
||||
hr = pDD4->lpVtbl->QueryInterface( pDD4, &IID_IDirect3D3, (VOID**)&pD3D );
|
||||
if (hr == DD_OK)
|
||||
{
|
||||
GLIDX6_gc_Found = 0;
|
||||
hr = pD3D->lpVtbl->EnumDevices( pD3D, GLIDX6_fnh_GetDeviceCallback, (void *) _sz_DeviceName );
|
||||
if ( (hr == DD_OK) && (GLIDX6_gc_Found != 0) )
|
||||
{
|
||||
hr = pDD4->lpVtbl->EnumDisplayModes( pDD4, 0, NULL, 0, GLIDX6_fnh_GetAllDisplayModesCallback );
|
||||
}
|
||||
}
|
||||
|
||||
if (pD3D) pD3D->lpVtbl->Release(pD3D);
|
||||
if (pDD4) pDD4->lpVtbl->Release(pDD4);
|
||||
return ( (hr == DD_OK) && (GLIDX6_gc_Found != 0) ) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Access function
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
char GLIDX6_fnc_IsHardware( void )
|
||||
{
|
||||
return (GLIDX6_gl_DeviceFlags & DX6_C_Dev_Hardware) ? 1 : 0;
|
||||
}
|
||||
|
||||
long GLIDX6_fnl_GetDeviceFlag( void )
|
||||
{
|
||||
return GLIDX6_gl_DeviceFlags;
|
||||
}
|
||||
|
||||
|
||||
D3DDEVICEDESC *GLIDX6_fnpst_GetDeviceDesc( void )
|
||||
{
|
||||
return &GLIDX6_gst_DeviceDesc;
|
||||
}
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Function used only by GliDetect not in engine used.
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
long (*gpfnl_AddDisplayInfo) (long, long, long , char*, unsigned long );
|
||||
long gl_Driver, gl_Device;
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : enumeration call back to get all display mode
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
static HRESULT CALLBACK DX6_fnh_ModeCallback(LPDDSURFACEDESC2 pddsd, LPVOID lpContext)
|
||||
{
|
||||
long l_Mode;
|
||||
if ( ( pddsd->ddpfPixelFormat.dwRGBBitCount == 16 ) || ( pddsd->ddpfPixelFormat.dwRGBBitCount == 32 ) )
|
||||
{
|
||||
l_Mode = gpfnl_AddDisplayInfo( gl_Driver, 0, 0, "modeadd", 0);
|
||||
gpfnl_AddDisplayInfo( gl_Driver, 0, l_Mode, "modefs", 1 );
|
||||
gpfnl_AddDisplayInfo( gl_Driver, 0, l_Mode, "modebpp", pddsd->ddpfPixelFormat.dwRGBBitCount );
|
||||
gpfnl_AddDisplayInfo( gl_Driver, 0, l_Mode, "modew", pddsd->dwWidth );
|
||||
gpfnl_AddDisplayInfo( gl_Driver, 0, l_Mode, "modeh", pddsd->dwHeight );
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : enumeration call back to get all device
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
static HRESULT CALLBACK DX6_fnh_DevicesCallback( GUID *_pGuid, LPSTR _szDesc, LPSTR _szName, LPD3DDEVICEDESC _lpHWDesc, LPD3DDEVICEDESC _lpHELDesc, LPVOID _lpContext )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
tdstGliCaps st_Caps;
|
||||
D3DDEVICEDESC *_pst_DevDesc;
|
||||
long lFlags;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
gl_Device = gpfnl_AddDisplayInfo( gl_Driver, 0, 0, "dev_add", 0);
|
||||
gpfnl_AddDisplayInfo( gl_Driver, gl_Device, 0, "dev_name", (unsigned long) _szName );
|
||||
gpfnl_AddDisplayInfo( gl_Driver, gl_Device, 0, "dev_desc", (unsigned long) _szDesc );
|
||||
gpfnl_AddDisplayInfo( gl_Driver, gl_Device, 0, "dev_param", (unsigned long) _pGuid );
|
||||
|
||||
if ( _lpHWDesc->dcmColorModel )
|
||||
{
|
||||
_pst_DevDesc = _lpHWDesc;
|
||||
lFlags = DX6_C_Dev_Hardware;
|
||||
}
|
||||
else
|
||||
{
|
||||
_pst_DevDesc = _lpHELDesc;
|
||||
lFlags = 0;
|
||||
}
|
||||
|
||||
memset( &st_Caps, 0, sizeof( tdstGliCaps ) );
|
||||
GLI_DX6_fn_hGetDriverCaps( &st_Caps, lFlags, (LPDIRECTDRAW4) _lpContext );
|
||||
GLI_DX6_fn_hGetDeviceCaps( &st_Caps, (LPDIRECTDRAW4) _lpContext, _pst_DevDesc );
|
||||
//GLI_DX6_fn_hGetPixelFormats();
|
||||
//GLI_DX6_fn_vPrecalculateTextureSize();
|
||||
|
||||
gpfnl_AddDisplayInfo( gl_Driver, gl_Device, 0, "dev_caps", (unsigned long) &st_Caps );
|
||||
|
||||
return D3DENUMRET_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : enumeration call back to get all drivers
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
BOOL WINAPI DX6_fnb_DriverCallback( GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
LPDIRECT3D3 pD3D = NULL;
|
||||
LPDIRECTDRAW4 pDD4 = NULL;
|
||||
LPDIRECTDRAW pDD = NULL;
|
||||
HRESULT hr;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
gl_Driver = gpfnl_AddDisplayInfo( 0, 0, 0, "dispadd", 0);
|
||||
gpfnl_AddDisplayInfo( gl_Driver, 0, 0, "dispname", (unsigned long) lpDriverName );
|
||||
gpfnl_AddDisplayInfo( gl_Driver, 0, 0, "dispdesc", (unsigned long) lpDriverDescription );
|
||||
gpfnl_AddDisplayInfo( gl_Driver, 0, 0, "dispparam", (unsigned long) lpGUID );
|
||||
|
||||
hr = DirectDrawCreate( lpGUID, &pDD, NULL );
|
||||
if (hr == DD_OK)
|
||||
{
|
||||
/* Get a ptr to an IDirectDraw4 interface. This interface to DirectDraw represents the DX6 version of the API.*/
|
||||
hr = pDD->lpVtbl->QueryInterface( pDD, &IID_IDirectDraw4, (LPVOID *) &pDD4 );
|
||||
if (hr == DD_OK)
|
||||
{
|
||||
/* Query DirectDraw for access to Direct3D*/
|
||||
hr = pDD4->lpVtbl->QueryInterface( pDD4, &IID_IDirect3D3, (VOID**)&pD3D );
|
||||
if ( hr == DD_OK )
|
||||
{
|
||||
hr = pD3D->lpVtbl->EnumDevices( pD3D, DX6_fnh_DevicesCallback, pDD4 );
|
||||
pDD4->lpVtbl->EnumDisplayModes( pDD4, 0, NULL, 0, DX6_fnh_ModeCallback );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pDD) pDD->lpVtbl->Release(pDD);
|
||||
if (pD3D) pD3D->lpVtbl->Release(pD3D);
|
||||
if (pDD4) pDD4->lpVtbl->Release(pDD4);
|
||||
|
||||
/* continue enumeration*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Function to Get All display information
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
long __declspec(dllexport) GLI_DRV_fn_lGetAllDisplayConfig( FARPROC _x_Fct )
|
||||
{
|
||||
HRESULT hr;
|
||||
long lVersion;
|
||||
|
||||
gpfnl_AddDisplayInfo = (long (__cdecl *)( long, long, long, char *, unsigned long ) ) _x_Fct;
|
||||
|
||||
gpfnl_AddDisplayInfo( 0, 0, 0, "dll_bmp", 2);
|
||||
|
||||
lVersion = gpfnl_AddDisplayInfo(0,0,0,"miscdxversiondetect", 0);
|
||||
if (lVersion < 0x600)
|
||||
return 0;
|
||||
|
||||
hr = DirectDrawEnumerate( DX6_fnb_DriverCallback, NULL );
|
||||
if (hr != DD_OK )
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
26
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Dll.c
Normal file
26
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Dll.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
=======================================================================================
|
||||
Name : DX6_Dll.c
|
||||
Author : vincent lhullier Date :16/09/98
|
||||
Description : specific DLL fonction
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
#include "init_gli.h"
|
||||
#include "DLLCom.h"
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
tdstGliDriverIdentity stDirectX6Id =
|
||||
{
|
||||
"DirectX6",
|
||||
"Driver for DirectX6",
|
||||
"1.0.0",
|
||||
GLI_C_VersionD3DDP,
|
||||
};
|
||||
|
||||
void fn_vInitDllIdentity( void )
|
||||
{
|
||||
memcpy( &g_stGliDrvId, &stDirectX6Id, sizeof( tdstGliDriverIdentity ) );
|
||||
}
|
||||
|
879
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Domat.c
Normal file
879
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Domat.c
Normal file
@@ -0,0 +1,879 @@
|
||||
/******************************************************************************************
|
||||
FILE : DoMat DirectX6
|
||||
|
||||
Do render parameters settings for texture/material/fog
|
||||
Dispay black triangles for window smaller than screen
|
||||
|
||||
*******************************************************************************************/
|
||||
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
#include <d3d.h>
|
||||
|
||||
#include "Gli_st.h"
|
||||
#include "GLI_Defn.h"
|
||||
#include "polygon.h"
|
||||
#include "mater_st.h"
|
||||
#include "light_st.h"
|
||||
#include "PvObj_st.h"
|
||||
#include "Liste.h"
|
||||
#include "watrplan.h"
|
||||
#include "proj.h"
|
||||
#include "vpt3D.h"
|
||||
#include "camera.h"
|
||||
#include "material.h"
|
||||
#include "texture.h"
|
||||
#include "TEX.h"
|
||||
#include "light.h"
|
||||
#include "GliBench.h"
|
||||
|
||||
#include "TextuD3D.h"
|
||||
#include "MacroD3D.h"
|
||||
#include "DLLCom.h"
|
||||
|
||||
#include "PRF.h"
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#ifdef ZARMA
|
||||
}
|
||||
#endif
|
||||
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Globals, Externals
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
D3DCOLOR xFogColor, xFogColorStart, xFogColorEnd, xFogcolorInfinite;
|
||||
|
||||
void GLI_vSetFogParams( tdstFogParams *_p_stFogParams );
|
||||
HRESULT GLI_fn_hRestoreSurfaces( void );
|
||||
|
||||
extern LPDIRECT3DDEVICE3 g_pd3dDevice;
|
||||
extern LPDIRECTDRAWSURFACE4 g_pddsBackBuffer;
|
||||
|
||||
/*
|
||||
* for Black triangles
|
||||
*/
|
||||
D3DTLVERTEX g_stBlackTriangle[24];
|
||||
long g_lNumberOfBlackTriangles = 0;
|
||||
|
||||
/*
|
||||
* For fog
|
||||
*/
|
||||
static float xZDepthConstant;
|
||||
/* Begin G.CLEMENT 23/08/1999 : unused vars, now local to GLI_vSetFogParams */
|
||||
/*static float xFogIntensityEnd;*/
|
||||
/*static float xFogIntensityStart;*/
|
||||
/* End G.CLEMENT 23/08/1999 */
|
||||
static float xZDepthStart, xZDepthStart2;
|
||||
static float xZDepthEnd;
|
||||
D3DCOLOR xFogColor, xFogColorStart, xFogColorEnd, xFogcolorInfinite;
|
||||
|
||||
/*
|
||||
* For ZBuffer
|
||||
*/
|
||||
static long bIsWriteEnable = 1;
|
||||
|
||||
/*
|
||||
* for render
|
||||
*/
|
||||
static ACP_tdxIndex xSaveFogIsOn = 0;
|
||||
static unsigned char ucSaveCyclingMode = -1;
|
||||
static unsigned char ucSaveFunction = -1;
|
||||
static unsigned long gs_ulDepthBufferTestEnabled = 0;
|
||||
|
||||
/*
|
||||
* for 32 bit back buffer
|
||||
*/
|
||||
extern long g_lFullScreenBpp;
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Special function for displaying black polygon
|
||||
it's for cinematic scene to hide non black background color
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : reinit list of black triangles
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DRV_vNoBlackPolygon()
|
||||
{
|
||||
g_lNumberOfBlackTriangles = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Add a black triangles to list
|
||||
Assume that list is large enough (no test)
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DRV_vAddBlackPolygon( long _lLeft, long _lTop, long _lRight, long _lBottom )
|
||||
{
|
||||
D3DTLVERTEX *p_stVertex;
|
||||
static float fOoDepth = 0.8f/*4.0f*/;
|
||||
|
||||
if (g_lNumberOfBlackTriangles + 6 > 24 )
|
||||
return;
|
||||
|
||||
p_stVertex = g_stBlackTriangle + g_lNumberOfBlackTriangles;
|
||||
memset( p_stVertex, 0, 6 * sizeof( D3DTLVERTEX ) );
|
||||
g_lNumberOfBlackTriangles += 6;
|
||||
|
||||
p_stVertex->sx = (D3DVALUE) _lLeft;
|
||||
p_stVertex->sy = (D3DVALUE) _lBottom;
|
||||
p_stVertex->rhw = (D3DVALUE) fOoDepth;
|
||||
|
||||
p_stVertex++;
|
||||
p_stVertex->sx = (D3DVALUE) _lLeft;
|
||||
p_stVertex->sy = (D3DVALUE) _lTop;
|
||||
p_stVertex->rhw = (D3DVALUE) fOoDepth;
|
||||
|
||||
p_stVertex++;
|
||||
p_stVertex->sx = (D3DVALUE) _lRight;
|
||||
p_stVertex->sy = (D3DVALUE) _lTop;
|
||||
p_stVertex->rhw = (D3DVALUE) fOoDepth;
|
||||
|
||||
p_stVertex++;
|
||||
p_stVertex->sx = (D3DVALUE) _lRight;
|
||||
p_stVertex->sy = (D3DVALUE) _lTop;
|
||||
p_stVertex->rhw = (D3DVALUE) fOoDepth;
|
||||
|
||||
p_stVertex++;
|
||||
p_stVertex->sx = (D3DVALUE) _lRight;
|
||||
p_stVertex->sy = (D3DVALUE) _lBottom;
|
||||
p_stVertex->rhw = (D3DVALUE) fOoDepth;
|
||||
|
||||
p_stVertex++;
|
||||
p_stVertex->sx = (D3DVALUE) _lLeft;
|
||||
p_stVertex->sy = (D3DVALUE) _lBottom;
|
||||
p_stVertex->rhw = (D3DVALUE) fOoDepth;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Draw black triangles
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_vSendBlackPolygon()
|
||||
{
|
||||
if (g_lNumberOfBlackTriangles == 0)
|
||||
return;
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetTexture(g_pd3dDevice,0, NULL );
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_FOGENABLE,FALSE);
|
||||
xSaveFogIsOn = 0;
|
||||
/*
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
|
||||
if( FAILED( g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice) ) )
|
||||
return;
|
||||
*/
|
||||
|
||||
/* Draw the triangles*/
|
||||
g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, g_stBlackTriangle, g_lNumberOfBlackTriangles, D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT );
|
||||
|
||||
/*
|
||||
/* End the scene./
|
||||
g_pd3dDevice->lpVtbl->EndScene(g_pd3dDevice);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
FOG
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : set render for fog parameters
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
/* Begin G.CLEMENT 23/08/1999 : modified computation of xZDepthStart2,
|
||||
turned global vars xFogIntensityStart/End into local ones */
|
||||
void GLI_vSetFogParams( tdstFogParams *_p_stFogParams )
|
||||
{
|
||||
/*
|
||||
xZDepthStart = _p_stFogParams->xDepthStart;
|
||||
xZDepthEnd = _p_stFogParams->xDepthEnd;
|
||||
|
||||
xFogIntensityStart = _p_stFogParams->xBlendStart / 255.0f;
|
||||
xFogIntensityEnd = _p_stFogParams->xBlendEnd / 255.0f;
|
||||
|
||||
xZDepthConstant = _p_stFogParams->xDepthEnd - _p_stFogParams->xDepthStart;
|
||||
if ( xZDepthConstant )
|
||||
xZDepthConstant = ( xFogIntensityEnd - xFogIntensityStart) / xZDepthConstant;
|
||||
|
||||
xZDepthStart2 = 1.0f / (256.0f * xZDepthConstant) + xZDepthStart;
|
||||
|
||||
if (_p_stFogParams->stColor.xR < 0.0f)
|
||||
_p_stFogParams->stColor.xR = 0.0f;
|
||||
else if (_p_stFogParams->stColor.xR > 1.0f)
|
||||
_p_stFogParams->stColor.xR = 1.0f;
|
||||
|
||||
if (_p_stFogParams->stColor.xG < 0.0f)
|
||||
_p_stFogParams->stColor.xG = 0.0f;
|
||||
else if (_p_stFogParams->stColor.xG > 1.0f)
|
||||
_p_stFogParams->stColor.xG = 1.0f;
|
||||
|
||||
if (_p_stFogParams->stColor.xB < 0.0f)
|
||||
_p_stFogParams->stColor.xB = 0.0f;
|
||||
else if (_p_stFogParams->stColor.xB > 1.0f)
|
||||
_p_stFogParams->stColor.xB = 1.0f;
|
||||
|
||||
xFogColor = D3DRGBA( _p_stFogParams->stColor.xR, _p_stFogParams->stColor.xG, _p_stFogParams->stColor.xB, 0 );
|
||||
xFogColorStart = D3DRGBA( 0, 0, 0, 1.f - xFogIntensityStart );
|
||||
xFogColorEnd = D3DRGBA( 0, 0, 0, 1.f - xFogIntensityEnd );
|
||||
*/
|
||||
|
||||
float xFogIntensityStart = _p_stFogParams->xBlendStart / 255.0f;
|
||||
float xFogIntensityEnd = _p_stFogParams->xBlendEnd / 255.0f;
|
||||
|
||||
xZDepthStart = _p_stFogParams->xDepthStart;
|
||||
xZDepthEnd = _p_stFogParams->xDepthEnd;
|
||||
|
||||
xZDepthConstant = xZDepthEnd - xZDepthStart;
|
||||
if ( xZDepthConstant )
|
||||
{
|
||||
xZDepthConstant = ( xFogIntensityEnd - xFogIntensityStart) / xZDepthConstant;
|
||||
if (xFogIntensityStart == 0)
|
||||
xZDepthStart2 = xZDepthStart; /* More accurate than actual computation */
|
||||
else
|
||||
xZDepthStart2 = (xFogIntensityEnd * xZDepthStart - xFogIntensityStart * xZDepthEnd) / (xFogIntensityEnd - xFogIntensityStart);
|
||||
} else {
|
||||
xZDepthStart2 = xZDepthConstant = 0;
|
||||
}
|
||||
|
||||
/* xZDepthStart2 = 1.0f / (256.0f * xZDepthConstant) + xZDepthStart; /* was wrong */
|
||||
|
||||
if (_p_stFogParams->stColor.xR < 0.0f)
|
||||
_p_stFogParams->stColor.xR = 0.0f;
|
||||
else if (_p_stFogParams->stColor.xR > 1.0f)
|
||||
_p_stFogParams->stColor.xR = 1.0f;
|
||||
|
||||
if (_p_stFogParams->stColor.xG < 0.0f)
|
||||
_p_stFogParams->stColor.xG = 0.0f;
|
||||
else if (_p_stFogParams->stColor.xG > 1.0f)
|
||||
_p_stFogParams->stColor.xG = 1.0f;
|
||||
|
||||
if (_p_stFogParams->stColor.xB < 0.0f)
|
||||
_p_stFogParams->stColor.xB = 0.0f;
|
||||
else if (_p_stFogParams->stColor.xB > 1.0f)
|
||||
_p_stFogParams->stColor.xB = 1.0f;
|
||||
|
||||
xFogColor = D3DRGBA( _p_stFogParams->stColor.xR, _p_stFogParams->stColor.xG, _p_stFogParams->stColor.xB, 0 );
|
||||
xFogColorStart = D3DRGBA( 0, 0, 0, 1.0f - xFogIntensityStart);
|
||||
xFogColorEnd = D3DRGBA( 0, 0, 0, 1.0f - xFogIntensityEnd);
|
||||
/* End G.CLEMENT 23/08/1999 */
|
||||
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice, D3DRENDERSTATE_FOGCOLOR, xFogColor);
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : compute vertex color to render fog
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DRV_vComputeFogEffect(GLI_tdstInternalGlobalValuesFor3dEngine *p_stBG )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
GLI_tdstAligned3DVector *p_stVertex, *p_stLastVertex;
|
||||
D3DCOLOR *p_xColor;
|
||||
unsigned long ulAlpha;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
if ( !GLI_BIG_GLOBALS->xFogIsOn )
|
||||
return;
|
||||
|
||||
if ( GLI_BIG_GLOBALS->p_stLastComputedFog != GLI_BIG_GLOBALS->p_stActiveFog )
|
||||
{
|
||||
GLI_vSetFogParams( GLI_BIG_GLOBALS->p_stActiveFog );
|
||||
GLI_BIG_GLOBALS->p_stLastComputedFog = GLI_BIG_GLOBALS->p_stActiveFog;
|
||||
}
|
||||
|
||||
p_stVertex = p_stBG->GLI_TurnedScaledDisplecedPoint;
|
||||
p_stLastVertex = p_stVertex + p_stBG->p_stObj->xNbPoints;
|
||||
p_xColor = (D3DCOLOR *) p_stBG->GLI_aDEF_stColorsRLIS;
|
||||
|
||||
for ( ; p_stVertex < p_stLastVertex;p_stVertex++, p_xColor++)
|
||||
{
|
||||
if (p_stVertex->xZ >= xZDepthEnd)
|
||||
*p_xColor = xFogColorEnd;
|
||||
else if ( p_stVertex->xZ <= xZDepthStart2)
|
||||
*p_xColor = 0xff000000; /* and not xFogColorStart; /* G.CLEMENT 24/08/1999 */
|
||||
else
|
||||
{
|
||||
/* Begin G.CLEMENT 24/08/1999 : added post-computation test */
|
||||
*(float *) &ulAlpha = (1.f - (p_stVertex->xZ - xZDepthStart2) * xZDepthConstant) + 32768.0f + 16384.0f; /* G.CLEMENT 23/08/1999 : changed xZDepthStart to xZDepthStart2 */
|
||||
/* Blending factor as a float is between 0 and 1, so we don't have to test the negative case.
|
||||
We just test if it is too near 1, which would cause *p_xColor to be 0x00 */
|
||||
if (ulAlpha & 0x0000ff00)
|
||||
*p_xColor = 0xff000000;
|
||||
else
|
||||
*p_xColor = ulAlpha << 24;
|
||||
/* End G.CLEMENT 24/08/1999 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
ZBuffer function
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : To enable write to ZBuffer
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
static void GLI_fn_vEnableWriteToZBuffer()
|
||||
{
|
||||
if (bIsWriteEnable) return;
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ZWRITEENABLE, TRUE );
|
||||
bIsWriteEnable = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : To disable write to ZBuffer
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
static void GLI_fn_vDisableWriteToZBuffer()
|
||||
{
|
||||
if (!bIsWriteEnable) return;
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ZWRITEENABLE, FALSE );
|
||||
bIsWriteEnable = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : To manage use of ZBuffer
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void GLI_DRV_vEnableDepthTest()
|
||||
{
|
||||
if( gs_ulDepthBufferTestEnabled )
|
||||
return;
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ZFUNC, D3DCMP_GREATEREQUAL );
|
||||
gs_ulDepthBufferTestEnabled = 1;
|
||||
}
|
||||
|
||||
void GLI_DRV_vDisableDepthTest()
|
||||
{
|
||||
if( ! gs_ulDepthBufferTestEnabled )
|
||||
return;
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS );
|
||||
gs_ulDepthBufferTestEnabled = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Main render parameter setting functions
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* Write to ZBuffer
|
||||
*/
|
||||
#define M_vZBuffer()\
|
||||
if (p_stGlobaleMT -> lCurrentDrawMask & GLI_C_lIsWriteZBuffer) \
|
||||
GLI_fn_vEnableWriteToZBuffer(); \
|
||||
else \
|
||||
GLI_fn_vDisableWriteToZBuffer();
|
||||
|
||||
/*
|
||||
* fog
|
||||
*/
|
||||
#define M_vFog()\
|
||||
if (GLI_BIG_GLOBALS->xFogIsOn) \
|
||||
{ \
|
||||
if ( GLI_BIG_GLOBALS->p_stLastComputedFog != GLI_BIG_GLOBALS->p_stActiveFog ) \
|
||||
{ \
|
||||
GLI_vSetFogParams( GLI_BIG_GLOBALS->p_stActiveFog ); \
|
||||
GLI_BIG_GLOBALS->p_stLastComputedFog = GLI_BIG_GLOBALS->p_stActiveFog; \
|
||||
} \
|
||||
if (!xSaveFogIsOn) \
|
||||
{ \
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_FOGENABLE,TRUE); \
|
||||
xSaveFogIsOn = 1; \
|
||||
} \
|
||||
} \
|
||||
else if (xSaveFogIsOn) \
|
||||
{ \
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_FOGENABLE,FALSE); \
|
||||
xSaveFogIsOn = 0; \
|
||||
}
|
||||
|
||||
/*
|
||||
* back face testing
|
||||
*/
|
||||
/*
|
||||
#define M_vBackFace()\
|
||||
if (p_stGlobaleMT->lCurrentDrawMask & GLI_C_lIsTestingBackface) \
|
||||
if ((p_stGlobaleMT -> lHierachDrawMask & GLI_C_lIsNotDrawingInMirror) ? \
|
||||
(p_stGlobaleMT -> lCurrentDrawMask & GLI_C_lNotInvertBackfaces) : \
|
||||
!(p_stGlobaleMT -> lCurrentDrawMask & GLI_C_lNotInvertBackfaces) ) \
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_CULLMODE, D3DCULL_CW); \
|
||||
else \
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); \
|
||||
else \
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Chromakey
|
||||
*/
|
||||
#define M_vChromakey()\
|
||||
if (p_stGlobaleMT -> p_stCurrentTexture -> lTextureCaps & GLI_C_lNZTexture) \
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_COLORKEYENABLE,TRUE); \
|
||||
else \
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_COLORKEYENABLE,FALSE);
|
||||
|
||||
/*
|
||||
* uv cycling mode
|
||||
*/
|
||||
|
||||
/* Begin G.CLEMENT 20/07/1999 : replacing superseded SetRenderState's with SetTextureStageState */
|
||||
#define M_vUVCyclingMode()\
|
||||
if ( p_stGlobaleMT -> p_stCurrentTexture -> ucCylingMode != ucSaveCyclingMode ) \
|
||||
{ \
|
||||
switch ( ucSaveCyclingMode = p_stGlobaleMT -> p_stCurrentTexture -> ucCylingMode ) \
|
||||
{ \
|
||||
case 0: \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice ,D3DRENDERSTATE_TEXTUREADDRESS,D3DTADDRESS_CLAMP); */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESSU,D3DTADDRESS_CLAMP); */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESSV,D3DTADDRESS_CLAMP); */ \
|
||||
/*g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP); */ \
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); \
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); \
|
||||
break; \
|
||||
case GLI_C_lCylingU: /* Cycling V */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESS,D3DTADDRESS_WRAP); */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESSU,D3DTADDRESS_CLAMP); */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESSV,D3DTADDRESS_WRAP); */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP); */ \
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); \
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); \
|
||||
break; \
|
||||
case GLI_C_lCylingV: /* Cycling U */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESS,D3DTADDRESS_WRAP); */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESSU,D3DTADDRESS_WRAP); */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESSV,D3DTADDRESS_CLAMP); */ \
|
||||
/*g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP); */\
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); \
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); \
|
||||
break; \
|
||||
case GLI_C_lCylingUV: \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESS,D3DTADDRESS_WRAP); */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESSU,D3DTADDRESS_WRAP); */ \
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREADDRESSV,D3DTADDRESS_WRAP); */ \
|
||||
/*g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP); */ \
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); \
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
/* End G.CLEMENT 20/07/1999 */
|
||||
|
||||
/* Begin G.CLEMENT 20/07/1999 : some macros for Texture Stage Settings */
|
||||
#define GLI_M_SetTextureColorStage(dev, i, arg1, op, arg2) { \
|
||||
dev->lpVtbl->SetTextureStageState(dev, i, D3DTSS_COLOROP, op); \
|
||||
dev->lpVtbl->SetTextureStageState(dev, i, D3DTSS_COLORARG1, arg1); \
|
||||
dev->lpVtbl->SetTextureStageState(dev, i, D3DTSS_COLORARG2, arg2); \
|
||||
}
|
||||
|
||||
#define GLI_M_SetTextureAlphaStage(dev, i, arg1, op, arg2) {\
|
||||
dev->lpVtbl->SetTextureStageState(dev, i, D3DTSS_ALPHAOP, op); \
|
||||
dev->lpVtbl->SetTextureStageState(dev, i, D3DTSS_ALPHAARG1, arg1); \
|
||||
dev->lpVtbl->SetTextureStageState(dev, i, D3DTSS_ALPHAARG2, arg2); \
|
||||
}
|
||||
/* End G.CLEMENT 20/07/1999 */
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : set render parameters that will work for all Opaque faces
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_fn_vSetRenderParametersBeforeOpaqueFace( void )
|
||||
{
|
||||
GLI_fn_vEnableWriteToZBuffer();
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
|
||||
/* Begin G.CLEMENT 19/07/1999 */
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATEALPHA); replaced with */
|
||||
GLI_M_SetTextureColorStage(g_pd3dDevice, 0, D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
|
||||
GLI_M_SetTextureAlphaStage(g_pd3dDevice, 0, D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE); /* For NZ-textures */
|
||||
/* End G.CLEMENT 19/07/1999 */
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHATESTENABLE, FALSE );
|
||||
ucSaveFunction = 4;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : called before the rendering of any triangle
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
BOOL GLI_DRV_bBeginScene()
|
||||
{
|
||||
if( SUCCEEDED( g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice) ) )
|
||||
{
|
||||
GLI_fn_vSetRenderParametersBeforeOpaqueFace();
|
||||
GLI_vSendBlackPolygon();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : called after the rendering of all triangles
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
BOOL GLI_DRV_bEndScene()
|
||||
{
|
||||
return SUCCEEDED( g_pd3dDevice->lpVtbl->EndScene(g_pd3dDevice) );
|
||||
}
|
||||
/*
|
||||
=======================================================================================
|
||||
Special function for displaying black polygon
|
||||
it's for cinematic scene to hide non black background color
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Called for all object before drawn.
|
||||
Set some general parameters and set render parameter for opaque texture only
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DRV_vDoOpaqueTextureSelection(GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT)
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
BOOL bTexture;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
bTexture = (p_stGlobaleMT->p_stCurrentTexture != NULL) && (p_stGlobaleMT->p_stCurrentTexture->bIsAvailable);
|
||||
/*p_stGlobaleMT->xTextureDontAcceptFog = TRUE;*/
|
||||
p_stGlobaleMT->xTextureDontAcceptFog = FALSE;
|
||||
|
||||
|
||||
/*
|
||||
* test if triangle will be transparent if so do not set render parameters
|
||||
*/
|
||||
if (GLI_BIG_GLOBALS->lAMirrorIsDetected)
|
||||
GLI_BIG_GLOBALS->lAMirrorIsDetected = 3;
|
||||
|
||||
if (
|
||||
(!(GLI_BIG_GLOBALS->lAMirrorIsDetected) && bTexture && (p_stGlobaleMT -> p_stCurrentTexture -> lTextureCaps & (GLI_C_lAlphaTexture | GLI_C_lNZFilteredTexture | GLI_C_lAddTransparencyTexture) ) )
|
||||
|| (!(p_stGlobaleMT -> lCurrentDrawMask & GLI_C_lIsNotGrided) && (p_stGlobaleMT->xGlobalAlpha < 0.98f))
|
||||
)
|
||||
{
|
||||
p_stGlobaleMT -> lClippingModeMask |= GLI_C_TrianglesMustBeSorted;
|
||||
if (bTexture && !(p_stGlobaleMT -> p_stCurrentTexture -> lTextureCaps & GLI_C_lAlphaTexture ))
|
||||
p_stGlobaleMT->xTextureDontAcceptFog = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
p_stGlobaleMT->lClippingModeMask &= 0xffffffff - GLI_C_TrianglesMustBeSorted;
|
||||
|
||||
/*
|
||||
if ( p_stGlobaleMT->lCurrentDrawMask & GLI_C_lIsEnableZSorting )
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ZFUNC, D3DCMP_GREATEREQUAL );
|
||||
else
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS );
|
||||
*/
|
||||
if ( p_stGlobaleMT->lCurrentDrawMask & GLI_C_lIsEnableZSorting )
|
||||
GLI_DRV_vEnableDepthTest();
|
||||
else
|
||||
GLI_DRV_vDisableDepthTest();
|
||||
|
||||
M_vFog();
|
||||
|
||||
/* GuS : Backfaces are removed by the engine itself. */
|
||||
/*
|
||||
M_vBackFace();
|
||||
*/
|
||||
|
||||
M_vZBuffer();
|
||||
|
||||
/*
|
||||
* mirror
|
||||
*/
|
||||
if ( bTexture )
|
||||
{
|
||||
if (p_stGlobaleMT -> p_stCurrentTexture -> lTextureCaps & GLI_C_lAlphaTest)
|
||||
{
|
||||
if (ucSaveFunction != 5)
|
||||
{
|
||||
if ( ucSaveFunction == 2 )
|
||||
GLI_fn_vSetRenderParametersBeforeOpaqueFace() ;
|
||||
/* Begin Guidom */
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); /*
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHAFUNC, D3DCMP_GREATEREQUAL );
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHAREF, 0xC0 );
|
||||
/* End Guidom */
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHATESTENABLE, TRUE );
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_ALPHABLENDENABLE,FALSE);*/
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREMAPBLEND,D3DTBLEND_MODULATEALPHA);*/
|
||||
ucSaveFunction = 5;
|
||||
}
|
||||
}
|
||||
else if (GLI_BIG_GLOBALS->lAMirrorIsDetected & 2)
|
||||
{
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHATESTENABLE, FALSE );
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA);
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA);
|
||||
/* Begin G.CLEMENT 19/07/1999 */
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATEALPHA); replaced with */
|
||||
GLI_M_SetTextureColorStage(g_pd3dDevice, 0, D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
|
||||
GLI_M_SetTextureAlphaStage(g_pd3dDevice, 0, D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
|
||||
/* End G.CLEMENT 19/07/1999 */
|
||||
ucSaveFunction = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ucSaveFunction != 4)
|
||||
{
|
||||
if ( ucSaveFunction == 2 )
|
||||
GLI_fn_vSetRenderParametersBeforeOpaqueFace() ;
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHATESTENABLE, FALSE );
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_ALPHABLENDENABLE,FALSE);*/
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREMAPBLEND,D3DTBLEND_MODULATEALPHA);*/
|
||||
ucSaveFunction = 4;
|
||||
}
|
||||
}
|
||||
|
||||
M_vChromakey();
|
||||
M_vUVCyclingMode();
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetTexture(g_pd3dDevice,0, (LPDIRECT3DTEXTURE2) p_stGlobaleMT->p_stCurrentTexture->p_stSpecParam );
|
||||
}
|
||||
else /* gouraud */
|
||||
{
|
||||
if (ucSaveFunction != 4)
|
||||
{
|
||||
if ( ucSaveFunction == 2 )
|
||||
GLI_fn_vSetRenderParametersBeforeOpaqueFace() ;
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHATESTENABLE, FALSE );
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_ALPHABLENDENABLE,FALSE);*/
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREMAPBLEND,D3DTBLEND_MODULATEALPHA);*/
|
||||
ucSaveFunction = 4;
|
||||
}
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetTexture(g_pd3dDevice,0, NULL );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : set render parameters that will work for all transparency faces
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_fn_vSetRenderParametersBeforeTransparencyFace( void )
|
||||
{
|
||||
GLI_fn_vDisableWriteToZBuffer();
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ALPHATESTENABLE, FALSE );
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA);
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : set render parameters for transparent triangles
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_vDoTransparentTextureSelection(GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT)
|
||||
{
|
||||
/*
|
||||
if ( p_stGlobaleMT->lCurrentDrawMask & GLI_C_lIsEnableZSorting )
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ZFUNC, D3DCMP_GREATEREQUAL );
|
||||
else
|
||||
g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS );
|
||||
*/
|
||||
if ( p_stGlobaleMT->lCurrentDrawMask & GLI_C_lIsEnableZSorting )
|
||||
GLI_DRV_vEnableDepthTest();
|
||||
else
|
||||
GLI_DRV_vDisableDepthTest();
|
||||
|
||||
M_vFog();
|
||||
|
||||
/* GuS : Backfaces are removed by the engine itself. */
|
||||
/*
|
||||
M_vBackFace();
|
||||
*/
|
||||
|
||||
if ((p_stGlobaleMT -> p_stCurrentTexture != NULL) && (p_stGlobaleMT -> p_stCurrentTexture -> bIsAvailable))
|
||||
{
|
||||
if (p_stGlobaleMT -> p_stCurrentTexture -> lTextureCaps & GLI_C_lAddTransparencyTexture)
|
||||
{
|
||||
/* Begin G.CLEMENT 02/08/1999 : Take the fog-disabling outside the 'if' statement */
|
||||
/* Otherwise several addtransp. textures won't work well together */
|
||||
if (ucSaveFunction != 1)
|
||||
{
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);*/
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA);*/
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_DESTBLEND,D3DBLEND_ONE);
|
||||
/* Begin G.CLEMENT 19/07/1999 */
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_TEXTUREMAPBLEND,D3DTBLEND_COPY); replaced with */
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
|
||||
g_pd3dDevice->lpVtbl->SetTextureStageState(g_pd3dDevice, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
/* End G.CLEMENT 19/07/1999 */
|
||||
ucSaveFunction = 1;
|
||||
}
|
||||
if (xSaveFogIsOn)
|
||||
{
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_FOGENABLE,FALSE);
|
||||
xSaveFogIsOn = 0;
|
||||
}
|
||||
/* End G.CLEMENT 02/08/1999 */
|
||||
}
|
||||
else if (ucSaveFunction != 2)
|
||||
{
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);*/
|
||||
/*g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA);*/
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA);
|
||||
/* Begin G.CLEMENT 19/07/1999 */
|
||||
/* g_pd3dDevice->lpVtbl->SetRenderState( g_pd3dDevice, D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATEALPHA); replaced with */
|
||||
GLI_M_SetTextureColorStage(g_pd3dDevice, 0, D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
|
||||
GLI_M_SetTextureAlphaStage(g_pd3dDevice, 0, D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_DIFFUSE);
|
||||
/* End G.CLEMENT 19/07/1999 */
|
||||
ucSaveFunction = 2;
|
||||
}
|
||||
|
||||
|
||||
M_vChromakey();
|
||||
M_vUVCyclingMode();
|
||||
|
||||
g_pd3dDevice->lpVtbl->SetTexture(g_pd3dDevice,0, (LPDIRECT3DTEXTURE2) p_stGlobaleMT->p_stCurrentTexture->p_stSpecParam );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* GOURAUD*/
|
||||
/* Begin G.CLEMENT 02/08/1999 : Don't forget to reset destination alpha */
|
||||
if (ucSaveFunction == 1)
|
||||
g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice,D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA);
|
||||
/* End G.CLEMENT 02/08/1999 */
|
||||
g_pd3dDevice->lpVtbl->SetTexture(g_pd3dDevice, 0, NULL );
|
||||
ucSaveFunction = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
Write bitmap in backbuffer
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : write region of a bitmap into a region of the backbuffer
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_WriteRegionD3D(long X, long Y, long l, long h, unsigned char *p_ucSrc, long SrcPitch , LPDDSURFACEDESC2 p_ddsd )
|
||||
{
|
||||
long lXDst, lYDst;
|
||||
unsigned short *p_uwSrc, *p_uwTgt;
|
||||
long TgtPitch;
|
||||
|
||||
p_uwSrc = (unsigned short *) p_ucSrc;
|
||||
p_uwTgt = (unsigned short *) ( (unsigned char *) p_ddsd->lpSurface + Y * p_ddsd->lPitch + X * 2 );
|
||||
SrcPitch = (SrcPitch >> 1) - l;
|
||||
TgtPitch = (p_ddsd->lPitch >> 1) - l;
|
||||
|
||||
for ( lYDst = 0 ; lYDst < h ; lYDst ++ )
|
||||
{
|
||||
for ( lXDst = 0 ; lXDst < l; lXDst ++ )
|
||||
*p_uwTgt++ = *p_uwSrc++;
|
||||
|
||||
p_uwTgt += TgtPitch;
|
||||
p_uwSrc += SrcPitch;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Write a 16 bit bitmap in the back buffer
|
||||
_p_vSourceBuffer -> bitmap
|
||||
_lWidth, _lHeight -> dimension of bitmap
|
||||
_lDestX, _lDestY -> where the bitmap have to be copied in the backbuffer
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DRV_vWrite16bBitmapToBackBuffer( void *_p_vSourceBuffer, long _lWidth, long _lHeight, long _lDestLeft, long _lDestTop, long _lDestRight, long _lDestBottom )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
long lXDst, lYDst;
|
||||
DDSURFACEDESC2 ddsd;
|
||||
unsigned short *p_uwSrc, *p_uwTgt;
|
||||
HRESULT hr;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
memset(&ddsd,0,sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
hr = g_pddsBackBuffer->lpVtbl->Lock(g_pddsBackBuffer, NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK, NULL);
|
||||
|
||||
if ( hr != DD_OK )
|
||||
{
|
||||
GLI_fn_hRestoreSurfaces();
|
||||
memset(&ddsd,0,sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
hr = g_pddsBackBuffer->lpVtbl->Lock(g_pddsBackBuffer, NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK, NULL);
|
||||
|
||||
if ( hr != DD_OK )
|
||||
return;
|
||||
}
|
||||
|
||||
if ( g_lFullScreenBpp == 32 )
|
||||
{
|
||||
unsigned char *p_ucSrc, *p_ucTgt;
|
||||
|
||||
p_ucSrc = (unsigned char *) _p_vSourceBuffer;
|
||||
p_ucTgt = (unsigned char *) ddsd.lpSurface;
|
||||
ddsd.lPitch = ddsd.lPitch - (_lWidth * 4);
|
||||
|
||||
for ( lYDst = 0 ; lYDst < _lHeight ; lYDst ++ )
|
||||
{
|
||||
for ( lXDst = 0 ; lXDst < _lWidth; lXDst ++ )
|
||||
{
|
||||
*p_ucTgt++ = *p_ucSrc++;
|
||||
*p_ucTgt++ = *p_ucSrc++;
|
||||
*p_ucTgt++ = *p_ucSrc++;
|
||||
p_ucTgt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p_uwSrc = (unsigned short *) _p_vSourceBuffer;
|
||||
p_uwTgt = (unsigned short *) ddsd.lpSurface;
|
||||
p_uwTgt += (ddsd.lPitch >> 1) * _lDestTop + _lDestLeft;
|
||||
GLD_MDRV_vBlitStretched16b( _lDestRight - _lDestLeft + 1, _lDestBottom - _lDestTop + 1, p_uwTgt, ddsd.lPitch >> 1, _lWidth, _lHeight, p_uwSrc );
|
||||
}
|
||||
|
||||
hr = g_pddsBackBuffer->lpVtbl->Unlock(g_pddsBackBuffer, NULL);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
881
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_HdwTx.c
Normal file
881
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_HdwTx.c
Normal file
@@ -0,0 +1,881 @@
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
#include "GLD.h"
|
||||
#include "GEO.h"
|
||||
#include "TEX.h"
|
||||
#include "gli_st.h"
|
||||
#include "textu_st.h"
|
||||
#include "texture.h"
|
||||
#include "ErrGli.h"
|
||||
#include "DLLCaps.h"
|
||||
#include <string.h>
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
#include "d3d.h"
|
||||
#include "ddraw.h"
|
||||
#include "TextuD3D.h"
|
||||
#include "MacroD3D.h"
|
||||
#include "DLLCom.h"
|
||||
#include "DX6_Caps.h"
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
externals globals
|
||||
=======================================================================================
|
||||
*/
|
||||
extern LPDIRECT3DDEVICE3 g_pd3dDevice;
|
||||
extern LPDIRECTDRAW4 g_pDD4;
|
||||
extern LPDIRECTDRAWSURFACE4 g_pddsPrimary;
|
||||
|
||||
extern long g_lFullScreenBpp;
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
globals
|
||||
=======================================================================================
|
||||
*/
|
||||
static long gs_lRestore = 0;
|
||||
|
||||
static LPDIRECTDRAWSURFACE4 g_p_stDDS4Temp = NULL;
|
||||
static LPDIRECTDRAWSURFACE4 g_p_stDDS4New = NULL;
|
||||
static LPDIRECT3DTEXTURE2 g_p_stD3DT2Temp = NULL;
|
||||
static LPDIRECT3DTEXTURE2 g_p_stD3DT2New = NULL;
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
functions
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : get video memory size taken by a given texture
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
long GLI_DRV_lGetSizeOfTexture( GLI_tdstTexture *_p_stTexture )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
char cPixelFormat;
|
||||
char cMipmap;
|
||||
long lSize;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
if ( g_lFullScreenBpp == 32)
|
||||
{
|
||||
if ( _p_stTexture->lTextureCaps & GLI_C_lPaletteTexture )
|
||||
cPixelFormat = GLI_DX6_TexFormatPalette8;
|
||||
else if ( _p_stTexture->lTextureCaps & (GLI_C_lAlphaTexture | GLI_C_lAlphaTest | GLI_C_lNZFilteredTexture) )
|
||||
cPixelFormat = GLI_DX6_TexFormat8888;
|
||||
else
|
||||
cPixelFormat = GLI_DX6_TexFormat888;
|
||||
}
|
||||
else if ( g_lFullScreenBpp == 16)
|
||||
{
|
||||
if ( _p_stTexture->lTextureCaps & GLI_C_lPaletteTexture )
|
||||
cPixelFormat = GLI_DX6_TexFormatPalette8;
|
||||
else if ( _p_stTexture->lTextureCaps & GLI_C_lAlphaTexture)
|
||||
cPixelFormat = GLI_DX6_TexFormat4444;
|
||||
else if ( _p_stTexture->lTextureCaps & (GLI_C_lAlphaTest | GLI_C_lNZFilteredTexture) )
|
||||
cPixelFormat = GLI_DX6_TexFormat1555;
|
||||
else
|
||||
cPixelFormat = GLI_DX6_TexFormat565;
|
||||
}
|
||||
else
|
||||
cPixelFormat = GLI_DX6_TexFormat565;
|
||||
|
||||
|
||||
cMipmap = (char) ((_p_stTexture->lNumberOfLod) ? 1 : 0);
|
||||
|
||||
lSize = GLI_DX6_fn_lGetPrecalculatedTextureSize( cPixelFormat, cMipmap, _p_stTexture->lWidth, _p_stTexture->lHeight );
|
||||
|
||||
GLI_MDRV_TEXBENCH_vSetTextureSize( _p_stTexture, TEXBENCH_C_cComputedSize, lSize );
|
||||
|
||||
return lSize;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
General functions
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
typedef struct tdstD3DErrorDesc_
|
||||
{
|
||||
HRESULT hErrorValue;
|
||||
char *szText;
|
||||
} tdstD3DErrorDesc;
|
||||
|
||||
#define C_cNumberOfD3DErrorDesc 65
|
||||
|
||||
tdstD3DErrorDesc g_a_stD3DError[C_cNumberOfD3DErrorDesc] =
|
||||
{
|
||||
{ DDERR_SURFACELOST, "DDERR_SURFACELOST"}, { DDERR_SURFACEBUSY, "DDERR_SURFACEBUSY"},
|
||||
{ DDERR_INCOMPATIBLEPRIMARY, "DDERR_INCOMPATIBLEPRIMARY"}, { DDERR_INVALIDCAPS, "DDERR_INVALIDCAPS"},
|
||||
{ DDERR_INVALIDOBJECT, "DDERR_INVALIDOBJECT"}, { DDERR_INVALIDPARAMS, "DDERR_INVALIDPARAMS"},
|
||||
{ DDERR_INVALIDPIXELFORMAT, "DDERR_INVALIDPIXELFORMAT"}, { DDERR_NOALPHAHW, "DDERR_NOALPHAHW"},
|
||||
{ DDERR_NOCOOPERATIVELEVELSET, "DDERR_NOCOOPERATIVELEVELSET"}, { DDERR_NODIRECTDRAWHW, "DDERR_NODIRECTDRAWHW"},
|
||||
{ DDERR_NOEMULATION, "DDERR_NOEMULATION"}, { DDERR_NOEXCLUSIVEMODE, "DDERR_NOEXCLUSIVEMODE"},
|
||||
{ DDERR_NOFLIPHW, "DDERR_NOFLIPHW"}, { DDERR_NOMIPMAPHW, "DDERR_NOMIPMAPHW"},
|
||||
{ DDERR_NOOVERLAYHW, "DDERR_NOOVERLAYHW"}, { DDERR_NOZBUFFERHW, "DDERR_NOZBUFFERHW"},
|
||||
{ DDERR_OUTOFMEMORY, "DDERR_OUTOFMEMORY"}, { DDERR_OUTOFVIDEOMEMORY, "DDERR_OUTOFVIDEOMEMORY"},
|
||||
{ DDERR_PRIMARYSURFACEALREADYEXISTS,"DDERR_PRIMARYSURFACEALREADYEXISTS"}, { DDERR_UNSUPPORTEDMODE, "DDERR_UNSUPPORTEDMODE"},
|
||||
{ D3DERR_BADMAJORVERSION, "D3DERR_BADMAJORVERSION"}, { D3DERR_BADMINORVERSION, "D3DERR_BADMINORVERSION"},
|
||||
{ D3DERR_EXECUTE_CLIPPED_FAILED, "D3DERR_EXECUTE_CLIPPED_FAILED"}, { D3DERR_EXECUTE_CREATE_FAILED, "D3DERR_EXECUTE_CREATE_FAILED"},
|
||||
{ D3DERR_EXECUTE_DESTROY_FAILED, "D3DERR_EXECUTE_DESTROY_FAILED"}, { D3DERR_EXECUTE_FAILED, "D3DERR_EXECUTE_FAILED"},
|
||||
{ D3DERR_EXECUTE_LOCK_FAILED, "D3DERR_EXECUTE_LOCK_FAILED"}, { D3DERR_EXECUTE_LOCKED, "D3DERR_EXECUTE_LOCKED"},
|
||||
{ D3DERR_EXECUTE_NOT_LOCKED, "D3DERR_EXECUTE_NOT_LOCKED"}, { D3DERR_EXECUTE_UNLOCK_FAILED, "D3DERR_EXECUTE_UNLOCK_FAILED"},
|
||||
{ D3DERR_INBEGIN, "D3DERR_INBEGIN"}, { D3DERR_INVALID_DEVICE, "D3DERR_INVALID_DEVICE"},
|
||||
{ D3DERR_INVALIDCURRENTVIEWPORT, "D3DERR_INVALIDCURRENTVIEWPORT"}, { D3DERR_INVALIDPRIMITIVETYPE, "D3DERR_INVALIDPRIMITIVETYPE"},
|
||||
{ D3DERR_INVALIDVERTEXTYPE, "D3DERR_INVALIDVERTEXTYPE"}, { D3DERR_LIGHT_SET_FAILED, "D3DERR_LIGHT_SET_FAILED"},
|
||||
{ D3DERR_MATERIAL_CREATE_FAILED, "D3DERR_MATERIAL_CREATE_FAILED"}, { D3DERR_MATERIAL_DESTROY_FAILED, "D3DERR_MATERIAL_DESTROY_FAILED"},
|
||||
{ D3DERR_MATERIAL_GETDATA_FAILED, "D3DERR_MATERIAL_GETDATA_FAILED"}, { D3DERR_MATERIAL_SETDATA_FAILED, "D3DERR_MATERIAL_SETDATA_FAILED"},
|
||||
{ D3DERR_MATRIX_CREATE_FAILED, "D3DERR_MATRIX_CREATE_FAILED"}, { D3DERR_MATRIX_DESTROY_FAILED, "D3DERR_MATRIX_DESTROY_FAILED"},
|
||||
{ D3DERR_MATRIX_GETDATA_FAILED, "D3DERR_MATRIX_GETDATA_FAILED"}, { D3DERR_MATRIX_SETDATA_FAILED, "D3DERR_MATRIX_SETDATA_FAILED"},
|
||||
{ D3DERR_NOTINBEGIN, "D3DERR_NOTINBEGIN"}, { D3DERR_NOVIEWPORTS, "D3DERR_NOVIEWPORTS"},
|
||||
{ D3DERR_SCENE_BEGIN_FAILED, "D3DERR_SCENE_BEGIN_FAILED"}, { D3DERR_SCENE_END_FAILED, "D3DERR_SCENE_END_FAILED"},
|
||||
{ D3DERR_SCENE_IN_SCENE, "D3DERR_SCENE_IN_SCENE"}, { D3DERR_SCENE_NOT_IN_SCENE, "D3DERR_SCENE_NOT_IN_SCENE"},
|
||||
{ D3DERR_SETVIEWPORTDATA_FAILED, "D3DERR_SETVIEWPORTDATA_FAILED"}, { D3DERR_TEXTURE_BADSIZE , "D3DERR_TEXTURE_BADSIZE"},
|
||||
{ D3DERR_TEXTURE_CREATE_FAILED, "D3DERR_TEXTURE_CREATE_FAILED"}, { D3DERR_TEXTURE_DESTROY_FAILED, "D3DERR_TEXTURE_DESTROY_FAILED"},
|
||||
{ D3DERR_TEXTURE_GETSURF_FAILED, "D3DERR_TEXTURE_GETSURF_FAILED"}, { D3DERR_TEXTURE_LOAD_FAILED, "D3DERR_TEXTURE_LOAD_FAILED"},
|
||||
{ D3DERR_TEXTURE_LOCK_FAILED, "D3DERR_TEXTURE_LOCK_FAILED"}, { D3DERR_TEXTURE_LOCKED, "D3DERR_TEXTURE_LOCKED"},
|
||||
{ D3DERR_TEXTURE_NO_SUPPORT, "D3DERR_TEXTURE_NO_SUPPORT"}, { D3DERR_TEXTURE_NOT_LOCKED, "D3DERR_TEXTURE_NOT_LOCKED"},
|
||||
{ D3DERR_TEXTURE_SWAP_FAILED, "D3DERR_TEXTURE_SWAP_FAILED"}, { D3DERR_TEXTURE_UNLOCK_FAILED, "D3DERR_TEXTURE_UNLOCK_FAILED"},
|
||||
{ D3DERR_VIEWPORTDATANOTSET, "D3DERR_VIEWPORTDATANOTSET"}, { D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY, "D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY"},
|
||||
{ D3DERR_ZBUFF_NEEDS_VIDEOMEMORY, "D3DERR_ZBUFF_NEEDS_VIDEOMEMORY"},
|
||||
};
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : return text that correspond to D3D error
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void vGetD3DError(HRESULT ddres,char *result)
|
||||
{
|
||||
tdstD3DErrorDesc *p_stErrorDesc = g_a_stD3DError;
|
||||
tdstD3DErrorDesc *p_stLastErrorDesc = p_stErrorDesc + C_cNumberOfD3DErrorDesc;
|
||||
|
||||
for ( ; p_stErrorDesc < p_stLastErrorDesc; p_stErrorDesc++ )
|
||||
{
|
||||
if ( p_stErrorDesc->hErrorValue == ddres )
|
||||
{
|
||||
strcpy( result, p_stErrorDesc->szText );
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* not a registered error*/
|
||||
strcpy(result, "DDERR : default");
|
||||
}
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
compute functions
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description :
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
static void fn_vGetScaleAndShiftFromMask(unsigned long ulMask, long *p_lShift, long *p_lScale)
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
unsigned long ulTemp;
|
||||
long lNbBits;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
ulTemp = ulMask;
|
||||
*p_lShift = *p_lScale = lNbBits = 0;
|
||||
|
||||
while( (lNbBits != 32) && ((ulTemp&0x1) == 0) )
|
||||
{
|
||||
ulTemp >>= 1;
|
||||
(*p_lShift)++;
|
||||
lNbBits++;
|
||||
}
|
||||
|
||||
while( (lNbBits != 32) && ((ulTemp&0x1) == 1) )
|
||||
{
|
||||
ulTemp >>= 1;
|
||||
(*p_lScale)++;
|
||||
lNbBits++;
|
||||
}
|
||||
|
||||
*p_lScale = 8 - (*p_lScale);
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : copy a bitmap to a D3D surface
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
/* Begin G.CLEMENT 28/07/1999 : added 'GLI_tdstTexture *p_stTexture' parameter for NZ special cases */
|
||||
BOOL GLI_D3D_bCopyBitmapToSurface(char *hBitmap, LPDIRECTDRAWSURFACE4 p_stDDSurface, GLI_tdstTexture *p_stTexture)
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
long lShiftRed, lScaleRed, lShiftGreen, lScaleGreen, lShiftBlue, lScaleBlue, lShiftAlpha, lScaleAlpha ;
|
||||
unsigned long ulMaskRed, ulMaskGreen, ulMaskBlue, ulMaskAlpha;
|
||||
DDSURFACEDESC2 ddsd;
|
||||
HRESULT ddres;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
memset(&ddsd,0,sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
do
|
||||
{
|
||||
ddres = p_stDDSurface->lpVtbl->Lock( p_stDDSurface, NULL, &ddsd, 0, NULL);
|
||||
} while (ddres==DDERR_WASSTILLDRAWING);
|
||||
|
||||
/*get the pixel format*/
|
||||
if (ddsd.ddpfPixelFormat.dwRGBBitCount == 8)
|
||||
{
|
||||
memcpy( ddsd.lpSurface, hBitmap, ddsd.dwWidth * ddsd.dwHeight );
|
||||
}
|
||||
else
|
||||
{
|
||||
ulMaskRed = ddsd.ddpfPixelFormat.dwRBitMask;
|
||||
ulMaskGreen = ddsd.ddpfPixelFormat.dwGBitMask;
|
||||
ulMaskBlue = ddsd.ddpfPixelFormat.dwBBitMask;
|
||||
ulMaskAlpha = ddsd.ddpfPixelFormat.dwRGBAlphaBitMask;
|
||||
|
||||
fn_vGetScaleAndShiftFromMask(ulMaskRed, &lShiftRed, &lScaleRed);
|
||||
fn_vGetScaleAndShiftFromMask(ulMaskGreen, &lShiftGreen, &lScaleGreen);
|
||||
fn_vGetScaleAndShiftFromMask(ulMaskBlue, &lShiftBlue, &lScaleBlue);
|
||||
fn_vGetScaleAndShiftFromMask(ulMaskAlpha, &lShiftAlpha, &lScaleAlpha);
|
||||
|
||||
/*Translate load texture in the temporary texture*/
|
||||
switch (ddsd.ddpfPixelFormat.dwRGBBitCount)
|
||||
{
|
||||
case 16:
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
long lHCounter,lWCounter;
|
||||
char *p_cSource;
|
||||
unsigned short *p_uwDest, *p_uwDestLocal;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
p_cSource=(char*)hBitmap;
|
||||
p_uwDestLocal = p_uwDest=(unsigned short *)ddsd.lpSurface;
|
||||
|
||||
/* Here is the special NZ case */
|
||||
if ((p_stTexture!=NULL) && (p_stTexture->lTextureCaps & GLI_C_lNZTexture)) {
|
||||
/* It's mostly the same as non-NZ but we have to check that we don't add false chromakeyed pixels */
|
||||
/* For this we need : */
|
||||
char *p_cOriginalKey ; /* points to the original Chroma Key color, needed for comparison */
|
||||
unsigned short usConvertedKey; /* The corresponding 16-bit value, so as not to recalculate it endlessly */
|
||||
|
||||
p_cOriginalKey = (char *) &(p_stTexture->lChromakeyColorRGBA);
|
||||
/* Yes, we could get it with GetColorKey instead of recompute it...
|
||||
But that way we don't depend on wether SetColoKey was called before */
|
||||
usConvertedKey = (unsigned short)((((p_cOriginalKey[0]>>lScaleRed) <<lShiftRed) & ulMaskRed)
|
||||
|(((p_cOriginalKey[1]>>lScaleGreen)<<lShiftGreen) & ulMaskGreen)
|
||||
|(((p_cOriginalKey[2]>>lScaleBlue) <<lShiftBlue) & ulMaskBlue));
|
||||
/* Note : no need for the alpha field in the chromakey */
|
||||
|
||||
for (lHCounter=0;lHCounter<(long)ddsd.dwHeight;lHCounter++,(unsigned char *)p_uwDestLocal += ddsd.lPitch )
|
||||
for (lWCounter=0,p_uwDest = p_uwDestLocal;lWCounter<(long)ddsd.dwWidth;lWCounter++)
|
||||
{
|
||||
*p_uwDest = (unsigned short)((((p_cSource[0]>>lScaleRed) <<lShiftRed) &ulMaskRed)
|
||||
|(((p_cSource[1]>>lScaleGreen)<<lShiftGreen)&ulMaskGreen)
|
||||
|(((p_cSource[2]>>lScaleBlue) <<lShiftBlue) &ulMaskBlue)
|
||||
|(((p_cSource[3]>>lScaleAlpha)<<lShiftAlpha)&ulMaskAlpha));
|
||||
|
||||
if ( ((*p_uwDest & ~ulMaskAlpha) == usConvertedKey) /* converted RGB values match */ &&
|
||||
( (((*(unsigned long *)p_cSource) ^ (*(unsigned long *)p_cOriginalKey)) & 0x00ffffff) )) /* but original don't */ /* 0x00f8f8f8 */
|
||||
{
|
||||
/* We slightly change the converted value */
|
||||
/* by inverting the least significant green bit */
|
||||
*p_uwDest ^= ((unsigned short)1) << lShiftGreen;
|
||||
/* Why the green bit ? Because in 565 it shows the least, and otherwise, why not ! */
|
||||
} else if ((*p_uwDest & ~ulMaskAlpha) == usConvertedKey) {
|
||||
*p_uwDest &= ~ulMaskAlpha;
|
||||
}
|
||||
p_uwDest++;
|
||||
p_cSource+=4;
|
||||
}
|
||||
} else {
|
||||
for (lHCounter=0;lHCounter<(long)ddsd.dwHeight;lHCounter++,(unsigned char *)p_uwDestLocal += ddsd.lPitch )
|
||||
for (lWCounter=0,p_uwDest = p_uwDestLocal;lWCounter<(long)ddsd.dwWidth;lWCounter++)
|
||||
{
|
||||
*p_uwDest = (unsigned short)((((p_cSource[0]>>lScaleRed) <<lShiftRed) &ulMaskRed)
|
||||
|(((p_cSource[1]>>lScaleGreen)<<lShiftGreen)&ulMaskGreen)
|
||||
|(((p_cSource[2]>>lScaleBlue) <<lShiftBlue) &ulMaskBlue)
|
||||
|(((p_cSource[3]>>lScaleAlpha)<<lShiftAlpha)&ulMaskAlpha));
|
||||
|
||||
p_uwDest++;
|
||||
p_cSource+=4;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 24:
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
long lHCounter,lWCounter;
|
||||
char *p_cSource;
|
||||
unsigned long *p_ulDest , *p_ulDestLocal;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
p_cSource=(char*)hBitmap;
|
||||
p_ulDestLocal = p_ulDest=(unsigned long *)ddsd.lpSurface;
|
||||
|
||||
for (lHCounter=0;lHCounter<(long)ddsd.dwHeight;lHCounter++, (unsigned char *)p_ulDestLocal += ddsd.lPitch )
|
||||
for (lWCounter=0 , p_ulDest = p_ulDestLocal ;lWCounter<(long)ddsd.dwWidth;lWCounter++)
|
||||
{
|
||||
*p_ulDest = (unsigned long)((((p_cSource[0]>>lScaleRed) <<lShiftRed) &ulMaskRed)
|
||||
|(((p_cSource[1]>>lScaleGreen)<<lShiftGreen)&ulMaskGreen)
|
||||
|(((p_cSource[2]>>lScaleBlue) <<lShiftBlue) &ulMaskBlue));
|
||||
p_ulDest = (unsigned long*)((unsigned char*)p_ulDest + 3);
|
||||
p_cSource+=4;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 32:
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
long lHCounter,lWCounter;
|
||||
char *p_cSource;
|
||||
unsigned long *p_ulDest, *p_ulDestLocal ;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
p_cSource=(char*)hBitmap;
|
||||
p_ulDest = p_ulDestLocal =(unsigned long *)ddsd.lpSurface;
|
||||
|
||||
for (lHCounter=0;lHCounter<(long)ddsd.dwHeight;lHCounter++ , (unsigned char *)p_ulDestLocal += ddsd.lPitch )
|
||||
for (lWCounter=0 , p_ulDest = p_ulDestLocal ;lWCounter<(long)ddsd.dwWidth;lWCounter++)
|
||||
{
|
||||
*p_ulDest = (unsigned long)((((p_cSource[0]>>lScaleRed) <<lShiftRed) &ulMaskRed)
|
||||
|(((p_cSource[1]>>lScaleGreen)<<lShiftGreen)&ulMaskGreen)
|
||||
|(((p_cSource[2]>>lScaleBlue) <<lShiftBlue) &ulMaskBlue)
|
||||
|(((p_cSource[3]>>lScaleAlpha)<<lShiftAlpha)&ulMaskAlpha));
|
||||
|
||||
p_ulDest++;
|
||||
p_cSource+=4;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}/*end switch*/
|
||||
}
|
||||
|
||||
ddres = p_stDDSurface->lpVtbl->Unlock(p_stDDSurface, ddsd.lpSurface);
|
||||
return (ddres == DD_OK);
|
||||
}
|
||||
/* End G.CLEMENT 28/07/1999 */
|
||||
|
||||
|
||||
/*
|
||||
=======================================================================================
|
||||
D3D texture format
|
||||
=======================================================================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : get good pixel format for given texture caps
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_fn_vGetPixelFormat( long _lTexCaps, DDPIXELFORMAT *_p_stPixelFormat )
|
||||
{
|
||||
if ( g_lFullScreenBpp == 32)
|
||||
{
|
||||
if ( _lTexCaps & GLI_C_lPaletteTexture )
|
||||
GLI_DX6_fn_vGetPixelFormat( GLI_DX6_TexFormatPalette8, _p_stPixelFormat );
|
||||
else if ( _lTexCaps & (GLI_C_lAlphaTexture | GLI_C_lAlphaTest | GLI_C_lNZFilteredTexture) )
|
||||
GLI_DX6_fn_vGetPixelFormat( GLI_DX6_TexFormat8888, _p_stPixelFormat );
|
||||
else
|
||||
GLI_DX6_fn_vGetPixelFormat( GLI_DX6_TexFormat888, _p_stPixelFormat );
|
||||
}
|
||||
else if ( g_lFullScreenBpp == 16)
|
||||
{
|
||||
if (_lTexCaps & GLI_C_lPaletteTexture )
|
||||
GLI_DX6_fn_vGetPixelFormat( GLI_DX6_TexFormatPalette8, _p_stPixelFormat );
|
||||
else if(_lTexCaps & GLI_C_lAlphaTexture)
|
||||
GLI_DX6_fn_vGetPixelFormat( GLI_DX6_TexFormat4444, _p_stPixelFormat );
|
||||
else if (_lTexCaps & (GLI_C_lAlphaTest | GLI_C_lNZFilteredTexture) )
|
||||
GLI_DX6_fn_vGetPixelFormat( GLI_DX6_TexFormat1555, _p_stPixelFormat );
|
||||
else
|
||||
GLI_DX6_fn_vGetPixelFormat( GLI_DX6_TexFormat565, _p_stPixelFormat );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : get memory for creating a texture
|
||||
( depend on use of AGP, size of texture, memory left )
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
unsigned long GLI_fn_ulGetMemoryFlag( GLI_tdstTexture *_p_stTexture, long _lTextureMode, BOOL _bUseAgp )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
unsigned long ulLeftMem, ulTotalMem;
|
||||
unsigned long ulTextureSize;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
/*ulTextureSize = (unsigned long) GLI_D3D_lGetSizeOfTexture( _p_stTexture );*/
|
||||
ulTextureSize = GLI_DRV_lGetSizeOfTexture( _p_stTexture );
|
||||
|
||||
if ( ( _lTextureMode == TEX_C_VRAM ) || ( _lTextureMode == TEX_C_VRAMAGP ) || ( _lTextureMode == TEX_C_VRAM4 ) || ( _lTextureMode == TEX_C_VRAM8 ) )
|
||||
{
|
||||
/* memoire video*/
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotalMem, &ulLeftMem );
|
||||
if (ulLeftMem > ulTextureSize + 5 * 1024) /* 5*1024 cache texture*/
|
||||
return (DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY);
|
||||
/* memoire AGP*/
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotalMem, &ulLeftMem );
|
||||
if( _bUseAgp && (ulLeftMem > ulTextureSize ))
|
||||
return (DDSCAPS_NONLOCALVIDMEM | DDSCAPS_VIDEOMEMORY);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* memoire AGP*/
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotalMem, &ulLeftMem );
|
||||
if( _bUseAgp && (ulLeftMem > ulTextureSize ) )
|
||||
return (DDSCAPS_NONLOCALVIDMEM | DDSCAPS_VIDEOMEMORY);
|
||||
/* memoire video*/
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotalMem, &ulLeftMem );
|
||||
if (ulLeftMem > ulTextureSize + 5 * 1024) /* 5*1024 cache texture*/
|
||||
return (DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY);
|
||||
}
|
||||
/* memoire system*/
|
||||
return DDSCAPS_SYSTEMMEMORY;
|
||||
}
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : when an error occors while downloading texture
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DX6_fn_vErrorLoadingTexture( GLI_tdstTexture *_p_stTexture, HRESULT _hError, char *_szErrorText )
|
||||
{
|
||||
char szMessage[128];
|
||||
|
||||
sprintf(szMessage, "texture.c :%s : %X -> ", _szErrorText, _hError );
|
||||
GLI_MDRV_vErmPrintMsg(szMessage, _p_stTexture->a255_cFileName);
|
||||
|
||||
if (g_p_stD3DT2Temp)
|
||||
{
|
||||
do
|
||||
{
|
||||
_hError = g_p_stD3DT2Temp->lpVtbl->Release( g_p_stD3DT2Temp );
|
||||
} while (_hError > 0);
|
||||
}
|
||||
else if (g_p_stDDS4Temp)
|
||||
g_p_stDDS4Temp->lpVtbl->Release( g_p_stDDS4Temp );
|
||||
|
||||
if (g_p_stD3DT2New)
|
||||
{
|
||||
do
|
||||
{
|
||||
_hError = g_p_stD3DT2Temp->lpVtbl->Release( g_p_stD3DT2New );
|
||||
} while (_hError > 0);
|
||||
}
|
||||
else if (g_p_stDDS4New)
|
||||
g_p_stDDS4New->lpVtbl->Release( g_p_stDDS4New );
|
||||
}
|
||||
|
||||
/* Begin G.CLEMENT 29/07/1999 : new function to set the chromakey with the pixel format of the texture */
|
||||
/*
|
||||
-----------------------------------------------------------------------------------------
|
||||
Description : set the chromakey of the texture to the DDSurface4 with the right format
|
||||
-----------------------------------------------------------------------------------------
|
||||
*/
|
||||
BOOL GLI_DX6_ConvertAndSetChromakey(GLI_tdstTexture *p_stTexture, LPDIRECTDRAWSURFACE4 p_stDDSurface)
|
||||
{
|
||||
DDSURFACEDESC2 ddsd;
|
||||
DDCOLORKEY stColorKey;
|
||||
HRESULT ddres;
|
||||
|
||||
memset(&ddsd,0,sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
ddres = p_stDDSurface->lpVtbl->GetSurfaceDesc( p_stDDSurface, &ddsd);
|
||||
if (ddres != DD_OK)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*get the pixel format*/
|
||||
if (ddsd.ddpfPixelFormat.dwRGBBitCount == 8)
|
||||
{
|
||||
/* Dunno what to do ! */
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Neat ! Works the same with 16, 24, and 32 bits formats */
|
||||
long lShiftRed, lScaleRed, lShiftGreen, lScaleGreen, lShiftBlue, lScaleBlue ;
|
||||
unsigned long ulMaskRed, ulMaskGreen, ulMaskBlue;
|
||||
unsigned long ulConvertedKey;
|
||||
char *p_cOriginalKey = (char *)&(p_stTexture->lChromakeyColorRGBA);
|
||||
|
||||
ulMaskRed = ddsd.ddpfPixelFormat.dwRBitMask;
|
||||
ulMaskGreen = ddsd.ddpfPixelFormat.dwGBitMask;
|
||||
ulMaskBlue = ddsd.ddpfPixelFormat.dwBBitMask;
|
||||
|
||||
fn_vGetScaleAndShiftFromMask(ulMaskRed, &lShiftRed, &lScaleRed);
|
||||
fn_vGetScaleAndShiftFromMask(ulMaskGreen, &lShiftGreen, &lScaleGreen);
|
||||
fn_vGetScaleAndShiftFromMask(ulMaskBlue, &lShiftBlue, &lScaleBlue);
|
||||
|
||||
/* This is done for NZ textures, so we don't care about the alpha part */
|
||||
ulConvertedKey = (unsigned long)((((p_cOriginalKey[0]>>lScaleRed) <<lShiftRed) & ulMaskRed)
|
||||
|(((p_cOriginalKey[1]>>lScaleGreen)<<lShiftGreen) & ulMaskGreen)
|
||||
|(((p_cOriginalKey[2]>>lScaleBlue) <<lShiftBlue) & ulMaskBlue));
|
||||
stColorKey.dwColorSpaceLowValue = ulConvertedKey;
|
||||
stColorKey.dwColorSpaceHighValue = ulConvertedKey;
|
||||
ddres = p_stDDSurface->lpVtbl->SetColorKey( p_stDDSurface, DDCKEY_SRCBLT, &stColorKey);
|
||||
return (ddres == DD_OK);
|
||||
}
|
||||
}
|
||||
/* End G.CLEMENT 29/07/1999 */
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Download texture
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DRV_vDownLoadTextures(long bRestore, long _lTextureMode, BOOL bReloading )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
long lMipMappingLocalSwitch, lTextureCounter;
|
||||
GLI_tdstTexture *p_stTexture;
|
||||
DDSURFACEDESC2 ddsd;
|
||||
LPDIRECTDRAWSURFACE4 p_stDDSurfaceCurrentTemp;
|
||||
HRESULT ddres;
|
||||
DDSCAPS2 ddsCaps;
|
||||
BOOL bCanUseMipmap;
|
||||
BOOL bUseAGPMemory;
|
||||
LPPALETTEENTRY p_stPalette;
|
||||
|
||||
unsigned long ulMemoryBefore, ulMemoryAfter, ulTotal, ulLeft;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
/*GLI_vInitD3DTextureFormat();*/
|
||||
|
||||
bCanUseMipmap = g_p_stGliCaps->ulTextureCaps & GLICAPS_TEX_C_ulSupportMipmap;
|
||||
bUseAGPMemory = g_p_stGliCaps->ulDriverCaps & GLICAPS_DRV_C_ulCanUseAGP;
|
||||
|
||||
/* loop on textures*/
|
||||
for (lTextureCounter = 0; lTextureCounter < GLI_C_lNBMaxOfTextures ; lTextureCounter ++)
|
||||
{
|
||||
if ( ( gs_aDEFTableOfTextureMemoryChannels[lTextureCounter] == GLI_TEXIsUnallocated ) || ( (p_stTexture = gs_aDEFTableOfTextureAlreadyRead[lTextureCounter]) == NULL ) )
|
||||
continue;
|
||||
|
||||
g_p_stDDS4Temp = NULL;
|
||||
g_p_stDDS4New = NULL;
|
||||
g_p_stD3DT2Temp = NULL;
|
||||
g_p_stD3DT2New = NULL;
|
||||
|
||||
/* Load bitmap*/
|
||||
|
||||
|
||||
GLI_MDRV_xLoadTextureInTexelField(p_stTexture, GLI_gs_p_ConvertBufferMipMapping, bReloading);
|
||||
|
||||
/*
|
||||
* Bench : compute memory before texture creation
|
||||
*/
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulMemoryBefore );
|
||||
if (bUseAGPMemory)
|
||||
{
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulLeft);
|
||||
ulMemoryBefore += ulLeft;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* set surface parameters
|
||||
*/
|
||||
memset(&ddsd, 0, sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT ;
|
||||
GLI_fn_vGetPixelFormat( p_stTexture->lTextureCaps, &ddsd.ddpfPixelFormat );
|
||||
ddsd.dwWidth = p_stTexture->lWidth;
|
||||
ddsd.dwHeight = p_stTexture->lHeight;
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_ALLOCONLOAD;
|
||||
|
||||
/*
|
||||
* some more parameters in case of mipmap texture
|
||||
*/
|
||||
if( bCanUseMipmap && p_stTexture->lNumberOfLod)
|
||||
{
|
||||
ddsd.ddsCaps.dwCaps |= DDSCAPS_MIPMAP | DDSCAPS_COMPLEX;
|
||||
ddsd.dwFlags |= DDSD_MIPMAPCOUNT;
|
||||
ddsd.dwMipMapCount = p_stTexture->lNumberOfLod + 1;
|
||||
}
|
||||
else
|
||||
ddsd.dwMipMapCount = 0;
|
||||
|
||||
|
||||
ddsd.ddsCaps.dwCaps |= GLI_fn_ulGetMemoryFlag( p_stTexture, _lTextureMode, bUseAGPMemory );
|
||||
|
||||
|
||||
/*
|
||||
* create texture surface
|
||||
*/
|
||||
ddres = g_pDD4->lpVtbl->CreateSurface( g_pDD4, &ddsd, &g_p_stDDS4New, NULL );
|
||||
if ( (ddres != DD_OK) || !(g_p_stDDS4New) )
|
||||
{
|
||||
GLI_DX6_fn_vErrorLoadingTexture( p_stTexture, ddres, "Create surface failed" );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* create temporary surface*/
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE;
|
||||
if( bCanUseMipmap && p_stTexture->lNumberOfLod)
|
||||
ddsd.ddsCaps.dwCaps |= DDSCAPS_MIPMAP | DDSCAPS_COMPLEX;
|
||||
|
||||
ddres = g_pDD4->lpVtbl->CreateSurface( g_pDD4, &ddsd, &g_p_stDDS4Temp,NULL);
|
||||
if ( (ddres != DD_OK) || !(g_p_stDDS4Temp) )
|
||||
{
|
||||
GLI_DX6_fn_vErrorLoadingTexture( p_stTexture, ddres, "Create surface temp failed" );
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set palette
|
||||
*/
|
||||
if ( p_stTexture->lTextureCaps & GLI_C_lPaletteTexture )
|
||||
{
|
||||
LPDIRECTDRAWPALETTE p_stDDPalette;
|
||||
long lColor;
|
||||
unsigned char ucSave;
|
||||
|
||||
p_stPalette = (LPPALETTEENTRY) p_stTexture->p_vColorTable;
|
||||
for (lColor = 0; lColor < 256; lColor++)
|
||||
{
|
||||
ucSave = p_stPalette[lColor].peRed;
|
||||
p_stPalette[lColor].peRed = p_stPalette[lColor].peBlue;
|
||||
p_stPalette[lColor].peBlue = ucSave;
|
||||
}
|
||||
|
||||
ddres = g_pDD4->lpVtbl->CreatePalette( g_pDD4, DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, p_stPalette, &p_stDDPalette, NULL );
|
||||
ddres = g_p_stDDS4Temp->lpVtbl->SetPalette( g_p_stDDS4Temp, p_stDDPalette );
|
||||
ddres = g_p_stDDS4New->lpVtbl->SetPalette( g_p_stDDS4New, p_stDDPalette );
|
||||
ddres = p_stDDPalette->lpVtbl->Release( p_stDDPalette );
|
||||
}
|
||||
|
||||
/* Begin G.CLEMENT 28/07/1999 : reverted chromakey settings and bitmap copy (we need the former in the latter) */
|
||||
/* Set the color key (chroma key) ([G.CLEMENT] using my new function) */
|
||||
if(p_stTexture->lTextureCaps & GLI_C_lNZTexture)
|
||||
{
|
||||
if (!GLI_DX6_ConvertAndSetChromakey(p_stTexture, g_p_stDDS4New))
|
||||
{
|
||||
GLI_DX6_fn_vErrorLoadingTexture( p_stTexture, ddres, "SetColorKey failed" );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy bitmap in the temporary surface*/
|
||||
if(!GLI_D3D_bCopyBitmapToSurface(p_stTexture->p_vBitMap, g_p_stDDS4Temp,p_stTexture)) /* G.CLEMENT 28/07/1999 : added 'p_stTexture' as an argument */
|
||||
{
|
||||
GLI_DX6_fn_vErrorLoadingTexture( p_stTexture, ddres, "Copy bitmap failed" );
|
||||
continue;
|
||||
}
|
||||
/* End G.CLEMENT 28/07/1999 */
|
||||
|
||||
/* compute next mipmaping levels*/
|
||||
if( bCanUseMipmap )
|
||||
{
|
||||
unsigned short uwWidth, uwHeight;
|
||||
|
||||
uwWidth = p_stTexture->lWidth;
|
||||
uwHeight = p_stTexture->lHeight;
|
||||
lMipMappingLocalSwitch = p_stTexture->lNumberOfLod;
|
||||
p_stDDSurfaceCurrentTemp = g_p_stDDS4Temp;
|
||||
ddres = DD_OK;
|
||||
|
||||
while ( lMipMappingLocalSwitch-- )
|
||||
{
|
||||
/* Compute the bitmap from the prev level of mipmaping*/
|
||||
if ( p_stTexture->lTextureCaps & GLI_C_lPaletteTexture )
|
||||
GLI_MDRV_vDivideBitmapSurfaceBy2Palette( (unsigned long *)GLI_gs_p_ConvertBufferMipMapping , (unsigned long *) p_stPalette, uwHeight, uwWidth );
|
||||
else if (p_stTexture -> lTextureCaps & GLI_C_lNZTexture)
|
||||
GLI_MDRV_vDivideBitmapSurfaceBy2NonZero((unsigned long *)GLI_gs_p_ConvertBufferMipMapping , (unsigned long *)GLI_gs_p_ConvertBufferMipMapping, uwHeight, uwWidth, p_stTexture->lChromakeyColorRGBA); /* G.CLEMENT 29/07/1999 : added chromakey */
|
||||
else
|
||||
GLI_MDRV_vDivideBitmapSurfaceBy2((unsigned long *)GLI_gs_p_ConvertBufferMipMapping, (unsigned long *)GLI_gs_p_ConvertBufferMipMapping, uwHeight, uwWidth );
|
||||
|
||||
/* Get the temporary surface of the current mipmaping level*/
|
||||
ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
|
||||
ddres = p_stDDSurfaceCurrentTemp->lpVtbl->GetAttachedSurface( p_stDDSurfaceCurrentTemp, &ddsCaps ,&p_stDDSurfaceCurrentTemp);
|
||||
if(ddres != DD_OK)
|
||||
{
|
||||
GLI_DX6_fn_vErrorLoadingTexture( p_stTexture, ddres, "GetAttachedSurface failed" );
|
||||
break;
|
||||
}
|
||||
|
||||
/* Copy the bitmap in the current temporary surface*/
|
||||
if(!GLI_D3D_bCopyBitmapToSurface(GLI_gs_p_ConvertBufferMipMapping, p_stDDSurfaceCurrentTemp,p_stTexture)) /* G.CLEMENT 28/07/1999 : added 'p_stTexture' as an argument */
|
||||
{
|
||||
GLI_DX6_fn_vErrorLoadingTexture( p_stTexture, ddres, "Copy bitmap level failed" );
|
||||
break;
|
||||
}
|
||||
|
||||
uwWidth >>= 1;
|
||||
uwHeight >>= 1;
|
||||
}
|
||||
if (ddres != DD_OK)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Get the texture interface*/
|
||||
ddres = g_p_stDDS4New->lpVtbl->QueryInterface( g_p_stDDS4New, &IID_IDirect3DTexture2, (void**) &g_p_stD3DT2New );
|
||||
if (ddres != DD_OK)
|
||||
{
|
||||
GLI_DX6_fn_vErrorLoadingTexture( p_stTexture, ddres, "QueryInterface texture2 failed" );
|
||||
continue;
|
||||
}
|
||||
|
||||
ddres = g_p_stDDS4Temp->lpVtbl->QueryInterface( g_p_stDDS4Temp , &IID_IDirect3DTexture2, (void**) &g_p_stD3DT2Temp );
|
||||
if (ddres != DD_OK)
|
||||
{
|
||||
GLI_DX6_fn_vErrorLoadingTexture( p_stTexture, ddres, "QueryInterface TempTexture2 failed" );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Load temporary texture in the good texture*/
|
||||
ddres = g_p_stD3DT2New->lpVtbl->Load( g_p_stD3DT2New, g_p_stD3DT2Temp );
|
||||
if (ddres != DD_OK)
|
||||
{
|
||||
GLI_DX6_fn_vErrorLoadingTexture( p_stTexture, ddres, "load failed" );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Delete the texture interface*/
|
||||
do
|
||||
{
|
||||
ddres = g_p_stD3DT2Temp->lpVtbl->Release( g_p_stD3DT2Temp );
|
||||
} while (ddres > 0);
|
||||
|
||||
/* Delete the temporary surface*/
|
||||
p_stTexture->p_stSpecParam = (void *) g_p_stD3DT2New;
|
||||
p_stTexture->bIsAvailable = 1;
|
||||
|
||||
/*
|
||||
* Bench : compute memory after texture creation
|
||||
*/
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulMemoryAfter );
|
||||
if (bUseAGPMemory)
|
||||
{
|
||||
GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulLeft);
|
||||
ulMemoryAfter += ulLeft;
|
||||
}
|
||||
GLI_MDRV_TEXBENCH_vSetTextureSize( p_stTexture, 1, ulMemoryBefore - ulMemoryAfter );
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : Compute total memory size available for texture
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
#ifdef __old__
|
||||
long GLI_DRV_lGetHardwareTotalTextureMemorySize( long _lTextureMode )
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
unsigned long ulTotal, ulLeft;
|
||||
long lReturn;
|
||||
HRESULT ddres;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
switch( _lTextureMode )
|
||||
{
|
||||
case TEX_C_VRAM:
|
||||
ddres = GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulLeft );
|
||||
lReturn = (ddres != DD_OK) ? -1 : (long) ulLeft;
|
||||
break;
|
||||
|
||||
case TEX_C_VRAM4:
|
||||
case TEX_C_AGP4:
|
||||
lReturn = 0x400000; /* 4 Mo*/
|
||||
break;
|
||||
|
||||
case TEX_C_VRAM8:
|
||||
case TEX_C_AGP8:
|
||||
lReturn = 0x800000; /* 8 Mo */
|
||||
break;
|
||||
|
||||
case TEX_C_VRAMAGP:
|
||||
case TEX_C_AGP:
|
||||
|
||||
ddres = GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulLeft );
|
||||
lReturn = (ddres != DD_OK) ? -1 : (long) ulLeft;
|
||||
|
||||
ddres = GLI_DX6_hGetVideoMemory( g_pDD4, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_MIPMAP, &ulTotal, &ulLeft );
|
||||
if (ddres != DD_OK)
|
||||
lReturn = -1;
|
||||
else
|
||||
lReturn += (long) ulLeft;
|
||||
break;
|
||||
}
|
||||
|
||||
return lReturn;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : recursive callback function to release the mipmap texture surfaces
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
//HRESULT WINAPI ReleaseAttachedSurfaceCallback(LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 lpDDSurfaceDesc, LPVOID lpContext)
|
||||
//{
|
||||
// lpDDSurface->lpVtbl->EnumAttachedSurfaces(lpDDSurface, NULL, ReleaseAttachedSurfaceCallback);
|
||||
// lpDDSurface->lpVtbl->Release(lpDDSurface);
|
||||
// return DDENUMRET_OK;
|
||||
//}
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------------
|
||||
Description : unload textures
|
||||
----------------------------------------------------------------------------------------
|
||||
*/
|
||||
void GLI_DRV_vUnLoadTextures()
|
||||
{
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
HRESULT hr;
|
||||
long lTextureCounter;
|
||||
LPDIRECT3DTEXTURE2 lpD3DT2;
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
|
||||
GLI_tdstTexture *p_stTexture;
|
||||
|
||||
//chbani : add this line sinon ca plante dans UnLoadTex (changement de map et display WayPoint)
|
||||
if( g_pd3dDevice )
|
||||
g_pd3dDevice->lpVtbl->SetTexture(g_pd3dDevice,0, NULL );
|
||||
|
||||
for ( lTextureCounter = 0 ; lTextureCounter < C_lMaxNumberOfTexture ;lTextureCounter ++)
|
||||
{
|
||||
if (gs_aDEFTableOfTextureMemoryChannels[lTextureCounter] != GLI_TEXIsUnallocated )
|
||||
{
|
||||
p_stTexture = gs_aDEFTableOfTextureAlreadyRead[lTextureCounter];
|
||||
if (p_stTexture != NULL)
|
||||
{
|
||||
if ( (p_stTexture->bIsAvailable) && ( p_stTexture->p_stSpecParam ) )
|
||||
{
|
||||
/*lpD3DT2 = ((GLI_tdstTextureD3D *) p_stTexture->p_stSpecParam)->p_stD3DTexture; */
|
||||
lpD3DT2 = (LPDIRECT3DTEXTURE2) p_stTexture->p_stSpecParam;
|
||||
if (lpD3DT2 != NULL)
|
||||
/* Don't forget to release mipmap (attached) textures too */
|
||||
//lpD3DT2->lpVtbl->EnumAttachedSurfaces(lpD3DT2, NULL, ReleaseAttachedSurfaceCallback);
|
||||
do
|
||||
{
|
||||
hr =lpD3DT2->lpVtbl->Release( lpD3DT2 );
|
||||
} while (hr > 0);
|
||||
|
||||
/*GLI_MDRV_vTmpFree( p_stTexture->p_stSpecParam );*/
|
||||
p_stTexture->p_stSpecParam = NULL;
|
||||
p_stTexture->bIsAvailable = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
1103
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Init.c
Normal file
1103
Rayman_X/cpa/tempgrp/GliGlou/Drivers/DirectX6/Src/DX6_Init.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user