segaGT+index buffers+etc

This commit is contained in:
Aaron Robinson 2004-03-21 22:49:20 +00:00
parent 6c8a21eaa2
commit fb2d865fe3
7 changed files with 590 additions and 365 deletions

BIN
Cxbx.opt

Binary file not shown.

View File

@ -55,18 +55,18 @@ typedef signed short sint16;
typedef signed long sint32;
// define this to track resources for debugging purposes
#define _DEBUG_TRACK_VB // Vertex Buffers
#define _DEBUG_TRACK_VS // Vertex Shaders
#define _DEBUG_TRACK_PB // Push Buffers
//#define _DEBUG_TRACK_VB // Vertex Buffers
//#define _DEBUG_TRACK_VS // Vertex Shaders
//#define _DEBUG_TRACK_PB // Push Buffers
// define this to track memory allocations
#define _DEBUG_ALLOC
//#define _DEBUG_ALLOC
// define this to trace intercepted function calls
#define _DEBUG_TRACE
//#define _DEBUG_TRACE
// define this to trace warnings
#define _DEBUG_WARNINGS
//#define _DEBUG_WARNINGS
// version information
#ifndef _DEBUG_TRACE

View File

@ -57,4 +57,25 @@ extern VOID EmuFixupVerticesB
XTL::IDirect3DVertexBuffer8 *&pHackVertexBuffer8
);
// inline vertex buffer emulation
extern DWORD *g_pIVBVertexBuffer;
extern X_D3DPRIMITIVETYPE g_IVBPrimitiveType;
extern struct _D3DIVB
{
XTL::D3DXVECTOR3 Position; // Position
XTL::DWORD dwSpecular; // Specular
XTL::DWORD dwDiffuse; // Diffuse
XTL::D3DXVECTOR3 Normal; // Normal
XTL::D3DXVECTOR2 TexCoord1; // TexCoord1
XTL::D3DXVECTOR2 TexCoord2; // TexCoord2
XTL::D3DXVECTOR2 TexCoord3; // TexCoord3
XTL::D3DXVECTOR2 TexCoord4; // TexCoord4
}
*g_IVBTable;
extern UINT g_IVBTblOffs;
extern VOID EmuFlushIVB();
#endif

View File

@ -339,6 +339,26 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit
}
}
// initialize FS segment selector emulation
{
EmuInitFS();
EmuGenerateFS(pTLS, pTLSData);
}
// we must duplicate this handle in order to retain Suspend/Resume thread rights from a remote thread
{
HANDLE hDupHandle = NULL;
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hDupHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
EmuRegisterThread(hDupHandle);
}
DbgPrintf("EmuMain (0x%X): Initializing Direct3D.\n", GetCurrentThreadId());
XTL::EmuD3DInit(pXbeHeader, dwXbeHeaderSize);
// initialize OpenXDK emulation (non-existant for now at least)
if(pLibraryVersion == 0)
DbgPrintf("EmuMain (0x%X): Detected OpenXDK application...\n", GetCurrentThreadId());
@ -535,26 +555,6 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit
DbgPrintf("EmuMain (0x%X): Resolved %d cross reference(s)\n", GetCurrentThreadId(), OrigUnResolvedXRefs - UnResolvedXRefs);
}
// initialize FS segment selector emulation
{
EmuInitFS();
EmuGenerateFS(pTLS, pTLSData);
}
// we must duplicate this handle in order to retain Suspend/Resume thread rights from a remote thread
{
HANDLE hDupHandle = NULL;
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hDupHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
EmuRegisterThread(hDupHandle);
}
DbgPrintf("EmuMain (0x%X): Initializing Direct3D.\n", GetCurrentThreadId());
XTL::EmuD3DInit(pXbeHeader, dwXbeHeaderSize);
DbgPrintf("EmuMain (0x%X): Initial thread starting.\n", GetCurrentThreadId());
// Xbe entry point
@ -665,10 +665,7 @@ extern "C" CXBXKRNL_API void NTAPI EmuCleanup(const char *szErrorMessage, ...)
if(g_hEmuParent != NULL)
SendMessage(g_hEmuParent, WM_PARENTNOTIFY, WM_DESTROY, 0);
exit(0);
// Much less friendly :]
// TerminateProcess(GetCurrentProcess(), 0);
TerminateProcess(GetCurrentProcess(), 0);
return;
}

View File

@ -98,25 +98,6 @@ static int g_iWireframe = 0;
// resource caching for _Register
static XTL::X_D3DResource pCache[16] = {0};
// direct3d inline vertex buffer (Begin()/End())
static DWORD *g_pD3DIVBData = NULL; // data cache
static DWORD g_dwD3DIVBInd = NULL; // index
static DWORD g_dwD3DIVBPrim; // primitive type (Xbox)
static DWORD g_dwD3DIVBFVF = 0; // FVF
static struct _D3DIVB
{
XTL::D3DXVECTOR3 Position; // Position
XTL::DWORD dwSpecular; // Specular
XTL::DWORD dwDiffuse; // Diffuse
XTL::D3DXVECTOR3 Normal; // Normal
XTL::D3DXVECTOR2 TexCoord1; // TexCoord1
XTL::D3DXVECTOR2 TexCoord2; // TexCoord2
XTL::D3DXVECTOR2 TexCoord3; // TexCoord3
XTL::D3DXVECTOR2 TexCoord4; // TexCoord4
}
*g_D3DIVB;
// current active index buffer
static XTL::X_D3DIndexBuffer *g_pIndexBuffer = NULL; // current active index buffer
static DWORD g_dwBaseVertexIndex = 0;// current active index buffer base index
@ -2978,194 +2959,6 @@ HRESULT WINAPI XTL::EmuIDirect3DDevice8_GetDisplayMode
return hRet;
}
static inline DWORD FtoDW(FLOAT f) { return *((DWORD*)&f); }
static inline FLOAT DWtoF(DWORD f) { return *((FLOAT*)&f); }
// ******************************************************************
// * func: EmuFlushD3DIVB
// ******************************************************************
static void EmuFlushD3DIVB()
{
if(g_dwD3DIVBPrim != 7)
EmuCleanup("Unsupported primitive type %d for D3DIVB", g_dwD3DIVBPrim);
if(g_dwD3DIVBInd < 3)
return;
// generate stream data
{
DWORD dwFVF = g_dwD3DIVBFVF;
BYTE *pStreamData = (BYTE*)CxbxMalloc(g_dwD3DIVBInd*sizeof(struct _D3DIVB));
ZeroMemory(pStreamData, g_dwD3DIVBInd*sizeof(struct _D3DIVB));
int i=0;
for(uint32 r=0;r<g_dwD3DIVBInd;r++)
{
// append position (x,y,z)
if(dwFVF & D3DFVF_XYZ)
{
memcpy(&pStreamData[i], &g_D3DIVB[r].Position.x, sizeof(XTL::D3DXVECTOR3));
i += sizeof(XTL::D3DXVECTOR3);
DbgPrintf("D3DIVB[%.02d]->Position := {%f,%f,%f}\n", r, g_D3DIVB[r].Position.x, g_D3DIVB[r].Position.y, g_D3DIVB[r].Position.z);
}
// append specular (D3DCOLOR)
if(dwFVF & D3DFVF_SPECULAR)
{
memcpy(&pStreamData[i], &g_D3DIVB[r].dwSpecular, sizeof(DWORD));
i += sizeof(DWORD);
DbgPrintf("D3DIVB[%.02d]->dwSpecular := 0x%.08X\n", r, g_D3DIVB[r].dwSpecular);
}
// append diffuse (D3DCOLOR)
if(dwFVF & D3DFVF_DIFFUSE)
{
memcpy(&pStreamData[i], &g_D3DIVB[r].dwDiffuse, sizeof(DWORD));
i += sizeof(DWORD);
DbgPrintf("D3DIVB[%.02d]->dwDiffuse := 0x%.08X\n", r, g_D3DIVB[r].dwDiffuse);
}
// append normal (nx,ny,nz)
if(dwFVF & D3DFVF_NORMAL)
{
memcpy(&pStreamData[i], &g_D3DIVB[r].Normal.x, sizeof(XTL::D3DXVECTOR3));
i += sizeof(XTL::D3DXVECTOR3);
DbgPrintf("D3DIVB[%.02d]->Normal := {%f,%f,%f}\n", r, g_D3DIVB[r].Normal.x, g_D3DIVB[r].Normal.y, g_D3DIVB[r].Normal.z);
}
// append texcoord
switch(dwFVF & D3DFVF_TEXCOUNT_MASK)
{
case D3DFVF_TEX1:
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord1.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
DbgPrintf("D3DIVB[%.02d]->Tex1 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord1.x, g_D3DIVB[r].TexCoord1.y);
break;
case D3DFVF_TEX2:
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord1.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord2.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
DbgPrintf("D3DIVB[%.02d]->Tex1 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord1.x, g_D3DIVB[r].TexCoord1.y);
DbgPrintf("D3DIVB[%.02d]->Tex2 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord2.x, g_D3DIVB[r].TexCoord2.y);
break;
case D3DFVF_TEX3:
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord1.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord2.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord3.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
DbgPrintf("D3DIVB[%.02d]->Tex1 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord1.x, g_D3DIVB[r].TexCoord1.y);
DbgPrintf("D3DIVB[%.02d]->Tex2 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord2.x, g_D3DIVB[r].TexCoord2.y);
DbgPrintf("D3DIVB[%.02d]->Tex3 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord3.x, g_D3DIVB[r].TexCoord3.y);
break;
case D3DFVF_TEX4:
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord1.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord2.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord3.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
memcpy(&pStreamData[i], &g_D3DIVB[r].TexCoord4.x, sizeof(XTL::D3DXVECTOR2));
i += sizeof(XTL::D3DXVECTOR2);
DbgPrintf("D3DIVB[%.02d]->Tex1 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord1.x, g_D3DIVB[r].TexCoord1.y);
DbgPrintf("D3DIVB[%.02d]->Tex2 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord2.x, g_D3DIVB[r].TexCoord2.y);
DbgPrintf("D3DIVB[%.02d]->Tex3 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord3.x, g_D3DIVB[r].TexCoord3.y);
DbgPrintf("D3DIVB[%.02d]->Tex4 := {%f,%f}\n", r, g_D3DIVB[r].TexCoord4.x, g_D3DIVB[r].TexCoord4.y);
break;
}
}
// close any outstanding locks
{
XTL::IDirect3DTexture8 *pTexture8 = NULL;
if(g_pD3DDevice8->GetTexture(0, (XTL::IDirect3DBaseTexture8**)&pTexture8) == D3D_OK && pTexture8 != NULL)
{
pTexture8->UnlockRect(0);
pTexture8->Release();
}
}
/*
{
static int dwDumpTex = 0;
char szBuffer[255];
sprintf(szBuffer, "C:\\Aaron\\Textures\\Flush%.03d.bmp", dwDumpTex++);
XTL::IDirect3DBaseTexture8 *pBaseTexture8 = NULL;
if(g_pD3DDevice8->GetTexture(0, &pBaseTexture8) == D3D_OK)
{
if(pBaseTexture8 != NULL)
{
XTL::IDirect3DTexture8 *pTexture8 = (XTL::IDirect3DTexture8*)pBaseTexture8;
pTexture8->UnlockRect(0);
XTL::D3DXSaveTextureToFile(szBuffer, XTL::D3DXIFF_BMP, pTexture8, NULL);
pBaseTexture8->Release();
}
}
}
//*/
XTL::EmuUpdateDeferredStates();
// XTL::EmuD3DDeferredRenderState
// HACK: TODO: Halo apparently has different values for D3DCULL_CW...i believe
g_pD3DDevice8->SetRenderState(XTL::D3DRS_CULLMODE, XTL::D3DCULL_CW );
g_pD3DDevice8->SetRenderState(XTL::D3DRS_FOGENABLE, FALSE );
//g_pD3DDevice8->SetRenderState(XTL::D3DRS_LIGHTING, FALSE );
//g_pD3DDevice8->SetRenderState(XTL::D3DRS_ZENABLE, TRUE );
g_pD3DDevice8->SetVertexShader(dwFVF);
HRESULT hRet = S_OK;
#ifdef _DEBUG_TRACK_VB
if(!g_bVBSkipStream)
{
#endif
hRet = g_pD3DDevice8->DrawPrimitiveUP(XTL::EmuPrimitiveType(g_dwD3DIVBPrim), XTL::EmuD3DVertex2PrimitiveCount(g_dwD3DIVBPrim, g_dwD3DIVBInd), pStreamData, i/g_dwD3DIVBInd);
#ifdef _DEBUG_TRACK_VB
}
#endif
// HACK: TODO: probably unnecessary!!!
//g_pD3DDevice8->Present(0,0,0,0);
CxbxFree(pStreamData);
if(FAILED(hRet))
EmuCleanup("Inline Vertex DrawPrimitiveUP Failed!");
}
g_dwD3DIVBInd = 0;
g_dwD3DIVBFVF = 0;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_Begin
// ******************************************************************
@ -3182,16 +2975,41 @@ HRESULT WINAPI XTL::EmuIDirect3DDevice8_Begin
");\n",
GetCurrentThreadId(), PrimitiveType);
if(PrimitiveType != 7)
if((PrimitiveType != 7) && (PrimitiveType != 9))
EmuCleanup("EmuIDirect3DDevice8_Begin does not support primitive : %d", PrimitiveType);
g_dwD3DIVBInd = 0;
g_dwD3DIVBPrim = PrimitiveType;
g_dwD3DIVBFVF = 0;
g_IVBPrimitiveType = PrimitiveType;
g_D3DIVB = (struct _D3DIVB*)CxbxMalloc(sizeof(*g_D3DIVB)*32);
// allocate a max of 32 entries
g_IVBTable = (struct XTL::_D3DIVB*)CxbxMalloc(sizeof(XTL::_D3DIVB)*32);
g_IVBTblOffs = 0;
ZeroMemory(g_D3DIVB, sizeof(*g_D3DIVB)*32);
// default values
for(int v=0;v<32;v++)
{
g_IVBTable[v].Position.x = 0;
g_IVBTable[v].Position.y = 0;
g_IVBTable[v].Position.z = 0;
g_IVBTable[v].dwSpecular = 0x00000000;
g_IVBTable[v].dwDiffuse = 0x00000000;
g_IVBTable[v].Normal.x = 0;
g_IVBTable[v].Normal.y = 0;
g_IVBTable[v].Normal.z = 0;
g_IVBTable[v].TexCoord1.x = 0;
g_IVBTable[v].TexCoord1.y = 0;
g_IVBTable[v].TexCoord2.x = 0;
g_IVBTable[v].TexCoord2.y = 0;
g_IVBTable[v].TexCoord3.x = 0;
g_IVBTable[v].TexCoord3.y = 0;
g_IVBTable[v].TexCoord4.x = 0;
g_IVBTable[v].TexCoord4.y = 0;
}
DWORD dwShader = -1;
g_pD3DDevice8->GetVertexShader(&dwShader);
g_pIVBVertexBuffer = (DWORD*)CxbxMalloc(sizeof(struct XTL::_D3DIVB)*32);
EmuSwapFS(); // XBox FS
@ -3254,134 +3072,39 @@ HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetVertexData4f
switch(Register)
{
case 0: // D3DVSDE_POSITION
case 9:
{
g_D3DIVB[g_dwD3DIVBInd].Position.x = (a/320.0f) - 1.0f;
g_D3DIVB[g_dwD3DIVBInd].Position.y = (b/240.0f) - 1.0f;
g_D3DIVB[g_dwD3DIVBInd].Position.z = c;
int o = g_IVBTblOffs;
g_dwD3DIVBFVF |= D3DFVF_XYZ;
// if(a > 640) a = 640;
// if(b > 480) b = 480;
g_dwD3DIVBInd++;
// if(a > 1.0f) a /= 640.0f;
// if(b > 1.0f) b /= 480.0f;
g_IVBTable[o].TexCoord1.x = a;
g_IVBTable[o].TexCoord1.y = b;
}
break;
case 9: // HALO HACK!
case 3: // D3DVSDE_DIFFUSE
case 0xFFFFFFFF:
{
DWORD ca = FtoDW(d) << 24;
DWORD cr = FtoDW(a) << 16;
DWORD cg = FtoDW(b) << 8;
DWORD cb = FtoDW(c) << 0;
int o = g_IVBTblOffs;
g_D3DIVB[g_dwD3DIVBInd].dwDiffuse = ca | cr | cg | cb;
// g_IVBTable[o].Position.x = (a/320.0f) - 1.0f;
// g_IVBTable[o].Position.y = (b/240.0f) - 1.0f;
g_IVBTable[o].Position.x = a;
g_IVBTable[o].Position.y = b;
g_IVBTable[o].Position.z = c;
g_dwD3DIVBFVF |= D3DFVF_DIFFUSE;
g_IVBTblOffs++;
EmuFlushIVB();
}
break;
case 4: // D3DVSDE_SPECULAR
{
// TODO: use size of texture in this calculation
a /= 640.0f;
b = 480.0f - b;
b /= 480.0f;
g_D3DIVB[g_dwD3DIVBInd].TexCoord1.x = a;
g_D3DIVB[g_dwD3DIVBInd].TexCoord1.y = b;
g_dwD3DIVBFVF &= ~D3DFVF_TEXCOUNT_MASK; // clear tex mask
g_dwD3DIVBFVF |= D3DFVF_TEX1;
/* HALO HACK!
DWORD ca = FtoDW(d) << 24;
DWORD cr = FtoDW(a) << 16;
DWORD cg = FtoDW(b) << 8;
DWORD cb = FtoDW(c) << 0;
g_D3DIVB[g_dwD3DIVBInd].dwSpecular = ca | cr | cg | cb;
g_dwD3DIVBFVF |= D3DFVF_SPECULAR;*/
}
break;
/*
case 9: // D3DVSDE_TEXCOORD0
{
if(a > 1.0f) a /= 640.0f;
if(b > 1.0f) b /= 480.0f;
g_D3DIVB[g_dwD3DIVBInd].fU1 = a;
g_D3DIVB[g_dwD3DIVBInd].fV1 = b;
g_dwD3DIVBFVF &= ~D3DFVF_TEXCOUNT_MASK; // clear tex mask
g_dwD3DIVBFVF |= D3DFVF_TEX1;
}
break;
*/
case 10: // D3DVSDE_TEXCOORD1
{
//if(a > 1.0f || a < -1.0f) a = 0.0f - ((a/320.0f) - 1.0f);
//if(b > 1.0f || b < -1.0f) b = 0.0f - ((b/240.0f) - 1.0f);
// TODO: use size of texture in this calculation
a /= 640.0f;
b = 480.0f - b;
b /= 480.0f;
g_D3DIVB[g_dwD3DIVBInd].TexCoord2.x = a;
g_D3DIVB[g_dwD3DIVBInd].TexCoord2.y = b;
g_dwD3DIVBFVF &= ~D3DFVF_TEXCOUNT_MASK; // clear tex mask
g_dwD3DIVBFVF |= D3DFVF_TEX2;
}
break;
case 11: // D3DVSDE_TEXCOORD2
{
// TODO: use size of texture in this calculation
a /= 640.0f;
b = 480.0f - b;
b /= 480.0f;
g_D3DIVB[g_dwD3DIVBInd].TexCoord3.x = a;
g_D3DIVB[g_dwD3DIVBInd].TexCoord3.y = b;
g_dwD3DIVBFVF &= ~D3DFVF_TEXCOUNT_MASK; // clear tex mask
g_dwD3DIVBFVF |= D3DFVF_TEX3;
}
break;
case 12: // D3DVSDE_TEXCOORD3
{
// TODO: use size of texture in this calculation
a /= 640.0f;
b = 480.0f - b;
b /= 480.0f;
g_D3DIVB[g_dwD3DIVBInd].TexCoord4.x = a;
g_D3DIVB[g_dwD3DIVBInd].TexCoord4.y = b;
g_dwD3DIVBFVF &= ~D3DFVF_TEXCOUNT_MASK; // clear tex mask
g_dwD3DIVBFVF |= D3DFVF_TEX4;
}
break;
case 0xFFFFFFFF: // D3DVSDE_VERTEX
{
g_D3DIVB[g_dwD3DIVBInd].Position.x = (a/320.0f) - 1.0f;
g_D3DIVB[g_dwD3DIVBInd].Position.y = (b/240.0f) - 1.0f;
g_D3DIVB[g_dwD3DIVBInd].Position.z = c;
g_dwD3DIVBFVF |= D3DFVF_XYZ;
g_dwD3DIVBInd++;
EmuFlushD3DIVB();
}
break;
default:
EmuCleanup("Unknown Register (4f) : %d", Register);
break;
EmuCleanup("Unknown IVB Register : %d", Register);
}
EmuSwapFS(); // XBox FS
@ -3389,6 +3112,9 @@ HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetVertexData4f
return hRet;
}
static inline DWORD FtoDW(FLOAT f) { return *((DWORD*)&f); }
static inline FLOAT DWtoF(DWORD f) { return *((FLOAT*)&f); }
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetVertexDataColor
// ******************************************************************
@ -3429,10 +3155,12 @@ HRESULT WINAPI XTL::EmuIDirect3DDevice8_End()
DbgPrintf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_End();\n", GetCurrentThreadId());
if(g_dwD3DIVBInd != 0)
EmuFlushD3DIVB();
if(g_IVBTblOffs != 0)
EmuFlushIVB();
CxbxFree(g_D3DIVB);
CxbxFree(g_pIVBVertexBuffer);
CxbxFree(g_IVBTable);
EmuSwapFS(); // XBox FS
@ -4203,13 +3931,33 @@ VOID WINAPI XTL::EmuGet2DSurfaceDesc
if(dwLevel == 0xFEFEFEFE)
{
hRet = pPixelContainer->EmuSurface8->GetDesc(&SurfaceDesc);
/*
static int dwDumpSurface = 0;
char szBuffer[255];
sprintf(szBuffer, "C:\\Aaron\\Textures\\Surface%.03d.bmp", dwDumpSurface++);
D3DXSaveSurfaceToFile(szBuffer, D3DXIFF_BMP, pPixelContainer->EmuSurface8, NULL, NULL);
*/
}
else
{
hRet = pPixelContainer->EmuTexture8->GetLevelDesc(dwLevel, &SurfaceDesc);
/*
static int dwDumpTexture = 0;
char szBuffer[255];
sprintf(szBuffer, "C:\\Aaron\\Textures\\Texture%.03d.bmp", dwDumpTexture++);
D3DXSaveTextureToFile(szBuffer, D3DXIFF_BMP, pPixelContainer->EmuTexture8, NULL);
*/
}
// rearrange into windows format (remove D3DPOOL)
// rearrange into xbox format (remove D3DPOOL)
{
// Convert Format (PC->Xbox)
pDesc->Format = EmuPC2XB_D3DFormat(SurfaceDesc.Format);
@ -6453,11 +6201,64 @@ VOID WINAPI XTL::EmuIDirect3DDevice8_DrawIndexedVertices
{
#endif
g_pD3DDevice8->DrawIndexedPrimitive
bool bActiveIB = false;
IDirect3DIndexBuffer8 *pIndexBuffer = 0;
// check if there is an active index buffer
{
UINT BaseIndex = 0;
g_pD3DDevice8->GetIndices(&pIndexBuffer, &BaseIndex);
if(pIndexBuffer != 0)
bActiveIB = true;
}
UINT uiNumVertices = 0;
UINT uiStartIndex = 0;
// TODO: Caching (if it becomes noticably slow to recreate the buffer each time)
if(!bActiveIB)
{
g_pD3DDevice8->CreateIndexBuffer(VertexCount*2, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &pIndexBuffer);
if(pIndexBuffer == 0)
EmuCleanup("Could not create index buffer! (%d bytes)", VertexCount*2);
BYTE *pbData = 0;
pIndexBuffer->Lock(0, 0, &pbData, 0);
if(pbData == 0)
EmuCleanup("Could not lock index buffer!");
memcpy(pbData, pIndexData, VertexCount*2);
pIndexBuffer->Unlock();
g_pD3DDevice8->SetIndices(pIndexBuffer, 0);
uiNumVertices = VertexCount;
uiStartIndex = 0;
}
else
{
uiNumVertices = ((DWORD)pIndexData)/2 + VertexCount;
uiStartIndex = ((DWORD)pIndexData)/2;
}
g_pD3DDevice8->DrawIndexedPrimitive
(
PCPrimitiveType, 0, ((DWORD)pIndexData)/2 + VertexCount, ((DWORD)pIndexData)/2, PrimitiveCount
PCPrimitiveType, 0, uiNumVertices, uiStartIndex, PrimitiveCount
);
if(!bActiveIB)
{
g_pD3DDevice8->SetIndices(0, 0);
pIndexBuffer->Release();
}
#ifdef _DEBUG_TRACK_VB
}
#endif

View File

@ -46,6 +46,12 @@ namespace XTL
extern XTL::LPDIRECT3DDEVICE8 g_pD3DDevice8; // Direct3D8 Device
// inline vertex buffer emulation
XTL::DWORD *XTL::g_pIVBVertexBuffer = 0;
XTL::X_D3DPRIMITIVETYPE XTL::g_IVBPrimitiveType = 0;
UINT XTL::g_IVBTblOffs = 0;
struct XTL::_D3DIVB *XTL::g_IVBTable = 0;
// fixup xbox extensions to be compatible with PC direct3d
UINT XTL::EmuFixupVerticesA
(
@ -233,3 +239,132 @@ VOID XTL::EmuFixupVerticesB
if(pHackVertexBuffer8 != 0)
pHackVertexBuffer8->Release();
}
VOID XTL::EmuFlushIVB()
{
if(g_IVBPrimitiveType == 9 && g_IVBTblOffs == 4)
{
DWORD dwShader = -1;
DWORD *pdwVB = g_pIVBVertexBuffer;
g_pD3DDevice8->GetVertexShader(&dwShader);
UINT uiStride = 0;
for(int v=0;v<4;v++)
{
DWORD dwPos = dwShader & D3DFVF_POSITION_MASK;
if(dwPos == D3DFVF_XYZRHW)
{
*(FLOAT*)pdwVB++ = g_IVBTable[v].Position.x;
*(FLOAT*)pdwVB++ = g_IVBTable[v].Position.y;
*(FLOAT*)pdwVB++ = g_IVBTable[v].Position.z;
uiStride += (sizeof(FLOAT)*3);
DbgPrintf("IVB Position := {%f, %f, %f}\n", g_IVBTable[v].Position.x, g_IVBTable[v].Position.y, g_IVBTable[v].Position.z);
}
else
{
EmuCleanup("Unsupported Position Mask (FVF := 0x%.08X)", dwShader);
}
if(dwShader & D3DFVF_SPECULAR)
{
*(DWORD*)pdwVB++ = g_IVBTable[v].dwSpecular;
uiStride += sizeof(DWORD);
DbgPrintf("IVB Specular := 0x%.08X\n", g_IVBTable[v].dwSpecular);
}
if(dwShader & D3DFVF_DIFFUSE)
{
*(DWORD*)pdwVB++ = g_IVBTable[v].dwDiffuse;
DbgPrintf("IVB Diffuse := 0x%.08X\n", g_IVBTable[v].dwDiffuse);
}
if(dwShader & D3DFVF_NORMAL)
{
*(FLOAT*)pdwVB++ = g_IVBTable[v].Normal.x;
*(FLOAT*)pdwVB++ = g_IVBTable[v].Normal.y;
*(FLOAT*)pdwVB++ = g_IVBTable[v].Normal.z;
uiStride += sizeof(FLOAT)*3;
DbgPrintf("IVB Normal := {%f, %f, %f}\n", g_IVBTable[v].Normal.x, g_IVBTable[v].Normal.y, g_IVBTable[v].Normal.z);
}
DWORD dwTexN = (dwShader & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
if(dwTexN >= 1)
{
*(FLOAT*)pdwVB++ = g_IVBTable[v].TexCoord1.x;
*(FLOAT*)pdwVB++ = g_IVBTable[v].TexCoord1.y;
uiStride += sizeof(FLOAT)*2;
DbgPrintf("IVB TexCoord1 := {%f, %f}\n", g_IVBTable[v].TexCoord1.x, g_IVBTable[v].TexCoord1.y);
}
if(dwTexN >= 2)
{
*(FLOAT*)pdwVB++ = g_IVBTable[v].TexCoord2.x;
*(FLOAT*)pdwVB++ = g_IVBTable[v].TexCoord2.y;
uiStride += sizeof(FLOAT)*2;
DbgPrintf("IVB TexCoord2 := {%f, %f}\n", g_IVBTable[v].TexCoord2.x, g_IVBTable[v].TexCoord2.y);
}
if(dwTexN >= 3)
{
*(FLOAT*)pdwVB++ = g_IVBTable[v].TexCoord3.x;
*(FLOAT*)pdwVB++ = g_IVBTable[v].TexCoord3.y;
uiStride += sizeof(FLOAT)*2;
DbgPrintf("IVB TexCoord3 := {%f, %f}\n", g_IVBTable[v].TexCoord3.x, g_IVBTable[v].TexCoord3.y);
}
if(dwTexN >= 4)
{
*(FLOAT*)pdwVB++ = g_IVBTable[v].TexCoord4.x;
*(FLOAT*)pdwVB++ = g_IVBTable[v].TexCoord4.y;
uiStride += sizeof(FLOAT)*2;
DbgPrintf("IVB TexCoord4 := {%f, %f}\n", g_IVBTable[v].TexCoord4.x, g_IVBTable[v].TexCoord4.y);
}
}
//*
IDirect3DBaseTexture8 *pTexture = 0;
g_pD3DDevice8->GetTexture(0, &pTexture);
if(pTexture != NULL)
{
static int dwDumpTexture = 0;
char szBuffer[255];
sprintf(szBuffer, "C:\\Aaron\\Textures\\Texture%.03d.bmp", dwDumpTexture++);
D3DXSaveTextureToFile(szBuffer, D3DXIFF_BMP, pTexture, NULL);
}
//*/
XTL::EmuUpdateDeferredStates();
g_pD3DDevice8->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_pIVBVertexBuffer, uiStride);
g_pD3DDevice8->Present(0,0,0,0);
g_IVBTblOffs = 0;
}
return;
}

View File

@ -1185,6 +1185,107 @@ SOOVPA<14> IDirect3DDevice8_Begin_1_0_4627 =
}
};
// ******************************************************************
// * IDirect3DDevice8_SetVertexData2f
// ******************************************************************
SOOVPA<14> IDirect3DDevice8_SetVertexData2f_1_0_4627 =
{
0, // Large == 0
14, // Count == 14
-1, // XRef Not Saved
0, // XRef Not Used
{
// IDirect3DDevice8_SetVertexData2f+0x20 : lea edx, ds:abs[ecx*8]
{ 0x20, 0x8D }, // (Offset,Value)-Pair #1
{ 0x21, 0x14 }, // (Offset,Value)-Pair #2
{ 0x22, 0xCD }, // (Offset,Value)-Pair #3
// IDirect3DDevice8_SetVertexData2f+0x2B : mov [eax], edx; mov edx, [esp+0x10]
{ 0x2B, 0x89 }, // (Offset,Value)-Pair #4
{ 0x2C, 0x10 }, // (Offset,Value)-Pair #5
{ 0x2D, 0x8B }, // (Offset,Value)-Pair #6
{ 0x2E, 0x54 }, // (Offset,Value)-Pair #7
{ 0x2F, 0x24 }, // (Offset,Value)-Pair #8
{ 0x30, 0x10 }, // (Offset,Value)-Pair #9
// IDirect3DDevice8_SetVertexData2f+0x37 : add eax, 0x0C
{ 0x37, 0x83 }, // (Offset,Value)-Pair #10
{ 0x38, 0xC0 }, // (Offset,Value)-Pair #11
{ 0x39, 0x0C }, // (Offset,Value)-Pair #12
// IDirect3DDevice8_SetVertexData2f+0x3D : retn 0x0C
{ 0x3D, 0xC2 }, // (Offset,Value)-Pair #13
{ 0x3E, 0x0C }, // (Offset,Value)-Pair #14
}
};
// ******************************************************************
// * IDirect3DDevice8_SetVertexData4f
// ******************************************************************
SOOVPA<11> IDirect3DDevice8_SetVertexData4f_1_0_4627 =
{
0, // Large == 0
11, // Count == 11
-1, // XRef Not Saved
0, // XRef Not Used
{
// IDirect3DDevice8_SetVertexData4f+0x20 : cmp ecx, -1; jnz +0x07
{ 0x20, 0x83 }, // (Offset,Value)-Pair #1
{ 0x21, 0xF9 }, // (Offset,Value)-Pair #2
{ 0x22, 0xFF }, // (Offset,Value)-Pair #3
{ 0x23, 0x75 }, // (Offset,Value)-Pair #4
{ 0x24, 0x07 }, // (Offset,Value)-Pair #5
// IDirect3DDevice8_SetVertexData4f+0x2C : add ecx, 0x01A0
{ 0x2C, 0x81 }, // (Offset,Value)-Pair #6
{ 0x2D, 0xC1 }, // (Offset,Value)-Pair #7
{ 0x2E, 0xA0 }, // (Offset,Value)-Pair #8
{ 0x2F, 0x01 }, // (Offset,Value)-Pair #9
// IDirect3DDevice8_SetVertexData4f+0x5F : retn 0x14
{ 0x5F, 0xC2 }, // (Offset,Value)-Pair #10
{ 0x60, 0x14 }, // (Offset,Value)-Pair #11
}
};
// ******************************************************************
// * IDirect3DDevice8_End
// ******************************************************************
SOOVPA<12> IDirect3DDevice8_End_1_0_4627 =
{
0, // Large == 0
12, // Count == 12
-1, // XRef Not Saved
0, // XRef Not Used
{
// IDirect3DDevice8_End+0x1C : mov dword ptr [eax], 0x417FC
{ 0x1C, 0xC7 }, // (Offset,Value)-Pair #1
{ 0x1D, 0x00 }, // (Offset,Value)-Pair #2
{ 0x1E, 0xFC }, // (Offset,Value)-Pair #3
{ 0x1F, 0x17 }, // (Offset,Value)-Pair #4
{ 0x20, 0x04 }, // (Offset,Value)-Pair #5
{ 0x21, 0x00 }, // (Offset,Value)-Pair #6
// IDirect3DDevice8_End+0x31 : test ah, 0x10
{ 0x31, 0xF6 }, // (Offset,Value)-Pair #7
{ 0x32, 0xC4 }, // (Offset,Value)-Pair #8
{ 0x33, 0x10 }, // (Offset,Value)-Pair #9
// IDirect3DDevice8_End+0x34 : jz +0x07
{ 0x34, 0x74 }, // (Offset,Value)-Pair #10
{ 0x35, 0x07 }, // (Offset,Value)-Pair #11
// IDirect3DDevice8_End+0x45 : retn
{ 0x45, 0xC3 }, // (Offset,Value)-Pair #12
}
};
// ******************************************************************
// * IDirect3DDevice8_Clear
// ******************************************************************
@ -1570,6 +1671,38 @@ SOOVPA<8> IDirect3DDevice8_SetRenderState_NormalizeNormalsB_1_0_4627 =
}
};
// ******************************************************************
// * IDirect3DDevice8_SetRenderState_EdgeAntiAliasB
// ******************************************************************
SOOVPA<10> IDirect3DDevice8_SetRenderState_EdgeAntiAliasB_1_0_4627 =
{
0, // Large == 0
10, // Count == 10
-1, // XRef Not Saved
0, // XRef Not Used
{
// IDirect3DDevice8_SetRenderState_EdgeAntiAliasB+0x07 : mov eax, [esi]
{ 0x07, 0x8B }, // (Offset,Value)-Pair #1
{ 0x08, 0x06 }, // (Offset,Value)-Pair #2
// IDirect3DDevice8_SetRenderState_EdgeAntiAliasB+0x0C : jb +0x0E
{ 0x0C, 0x72 }, // (Offset,Value)-Pair #3
{ 0x0D, 0x0E }, // (Offset,Value)-Pair #4
// IDirect3DDevice8_SetRenderState_EdgeAntiAliasB+0x1C : mov ecx, [esp+0x08]
{ 0x1C, 0x8B }, // (Offset,Value)-Pair #5
{ 0x1D, 0x4C }, // (Offset,Value)-Pair #6
{ 0x1E, 0x24 }, // (Offset,Value)-Pair #7
{ 0x1F, 0x08 }, // (Offset,Value)-Pair #8
// IDirect3DDevice8_SetRenderState_EdgeAntiAliasB+0x38 : retn 0x04
{ 0x38, 0xC2 }, // (Offset,Value)-Pair #9
{ 0x39, 0x04 }, // (Offset,Value)-Pair #10
}
};
// ******************************************************************
// * IDirect3DDevice8_SetRenderState_Dxt1NoiseEnable
// ******************************************************************
@ -1739,6 +1872,44 @@ SOOVPA<12> IDirect3DDevice8_SetRenderState_MultiSampleAntiAlias_1_0_4627 =
}
};
// ******************************************************************
// * IDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB
// ******************************************************************
SOOVPA<12> IDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB_1_0_4627 =
{
0, // Large == 0
12, // Count == 12
-1, // XRef Not Saved
0, // XRef Not Used
{
// IDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB+0x04 : push esi
{ 0x04, 0x56 }, // (Offset,Value)-Pair #1
// IDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB+0x11 : call [abs]
{ 0x11, 0xE8 }, // (Offset,Value)-Pair #2
// IDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB+0x25 : shl edi, 0x10
{ 0x25, 0xC1 }, // (Offset,Value)-Pair #3
{ 0x26, 0xE7 }, // (Offset,Value)-Pair #4
{ 0x27, 0x10 }, // (Offset,Value)-Pair #5
// IDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB+0x2C : jns +0x0C
{ 0x2C, 0x79 }, // (Offset,Value)-Pair #6
{ 0x2D, 0x0C }, // (Offset,Value)-Pair #7
// IDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB+0x37 : or edi, 0x01
{ 0x37, 0x83 }, // (Offset,Value)-Pair #8
{ 0x38, 0xCF }, // (Offset,Value)-Pair #9
{ 0x39, 0x01 }, // (Offset,Value)-Pair #10
// IDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB+0x7B : retn 0x04
{ 0x7B, 0xC2 }, // (Offset,Value)-Pair #11
{ 0x7C, 0x04 }, // (Offset,Value)-Pair #12
}
};
// ******************************************************************
// * IDirect3DDevice8_DrawVerticesUP
// ******************************************************************
@ -1769,6 +1940,36 @@ SOOVPA<10> IDirect3DDevice8_DrawVerticesUP_1_0_4627 =
}
};
// ******************************************************************
// * IDirect3DDevice8_DrawVerticesUPB
// ******************************************************************
SOOVPA<10> IDirect3DDevice8_DrawVerticesUPB_1_0_4627 =
{
0, // Large == 0
10, // Count == 10
-1, // XRef Not Saved
0, // XRef Not Used
{
// IDirect3DDevice8_DrawVerticesUPB+0x03 : sub esp, 0x14
{ 0x03, 0x83 }, // (Offset,Value)-Pair #1
{ 0x04, 0xEC }, // (Offset,Value)-Pair #2
{ 0x05, 0x14 }, // (Offset,Value)-Pair #3
// IDirect3DDevice8_DrawVerticesUPB+0x3C : mov edx, [esi+0x804]
{ 0x3C, 0x8B }, // (Offset,Value)-Pair #4
{ 0x3D, 0x96 }, // (Offset,Value)-Pair #5
{ 0x3E, 0x04 }, // (Offset,Value)-Pair #6
{ 0x3F, 0x08 }, // (Offset,Value)-Pair #7
// IDirect3DDevice8_DrawVerticesUPB+0xF9 : cmp edi, 0x80
{ 0xF9, 0x81 }, // (Offset,Value)-Pair #8
{ 0xFA, 0xFF }, // (Offset,Value)-Pair #9
{ 0xFB, 0x80 }, // (Offset,Value)-Pair #10
}
};
// ******************************************************************
// * IDirect3DDevice8_DrawIndexedVertices
// ******************************************************************
@ -3086,6 +3287,36 @@ OOVPATable D3D8_1_0_4627[] =
"EmuIDirect3DDevice8_Begin"
#endif
},
// IDirect3DDevice8::SetVertexData2f
{
(OOVPA*)&IDirect3DDevice8_SetVertexData2f_1_0_4627,
XTL::EmuIDirect3DDevice8_SetVertexData2f,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_SetVertexData2f"
#endif
},
// IDirect3DDevice8::SetVertexData4f
{
(OOVPA*)&IDirect3DDevice8_SetVertexData4f_1_0_4627,
XTL::EmuIDirect3DDevice8_SetVertexData4f,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_SetVertexData4f"
#endif
},
// IDirect3DDevice8::End
{
(OOVPA*)&IDirect3DDevice8_End_1_0_4627,
XTL::EmuIDirect3DDevice8_End,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_End"
#endif
},
// IDirect3DDevice8::Clear
{
(OOVPA*)&IDirect3DDevice8_Clear_1_0_4627,
@ -3286,6 +3517,16 @@ OOVPATable D3D8_1_0_4627[] =
"EmuIDirect3DDevice8_SetRenderState_EdgeAntiAlias"
#endif
},
// IDirect3DDevice8::SetRenderState_EdgeAntiAliasB
{
(OOVPA*)&IDirect3DDevice8_SetRenderState_EdgeAntiAliasB_1_0_4627,
XTL::EmuIDirect3DDevice8_SetRenderState_EdgeAntiAlias,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_SetRenderState_EdgeAntiAliasB"
#endif
},
// IDirect3DDevice8::SetRenderState_FillMode (* unchanged since 4361 *)
{
(OOVPA*)&IDirect3DDevice8_SetRenderState_FillMode_1_0_4361,
@ -3386,6 +3627,16 @@ OOVPATable D3D8_1_0_4627[] =
"EmuIDirect3DDevice8_SetRenderState_MultiSampleAntiAlias"
#endif
},
// IDirect3DDevice8::SetRenderState_MultiSampleAntiAliasB
{
(OOVPA*)&IDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB_1_0_4627,
XTL::EmuIDirect3DDevice8_SetRenderState_MultiSampleAntiAlias,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_SetRenderState_MultiSampleAntiAliasB"
#endif
},
// IDirect3DDevice8::SetRenderState_ShadowFunc (* unchanged since 4432 *)
{
(OOVPA*)&IDirect3DDevice8_SetRenderState_ShadowFunc_1_0_4432,
@ -3486,6 +3737,16 @@ OOVPATable D3D8_1_0_4627[] =
"EmuIDirect3DDevice8_DrawVerticesUP"
#endif
},
// IDirect3DDevice8::DrawVerticesUPB
{
(OOVPA*)&IDirect3DDevice8_DrawVerticesUPB_1_0_4627,
XTL::EmuIDirect3DDevice8_DrawVerticesUP,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_DrawVerticesUPB"
#endif
},
// IDirect3DDevice8::SetLight (* unchanged since 4361 *)
{
(OOVPA*)&IDirect3DDevice8_SetLight_1_0_4361,
@ -3586,6 +3847,16 @@ OOVPATable D3D8_1_0_4627[] =
"EmuIDirect3DResource8_ReleaseB"
#endif
},
// IDirect3DResource8::AddRef (* unchanged since 3925 *)
{
(OOVPA*)&IDirect3DResource8_AddRef_1_0_3925,
XTL::EmuIDirect3DResource8_AddRef,
#ifdef _DEBUG_TRACE
"EmuIDirect3DResource8_AddRef"
#endif
},
// IDirect3DResource8::IsBusy (* unchanged since 4361 *)
{
(OOVPA*)&IDirect3DResource8_IsBusy_1_0_4361,