Vertex Rendering!

This commit is contained in:
Aaron Robinson 2003-05-02 02:42:29 +00:00
parent 6a8217e93b
commit 3b4e67d367
9 changed files with 565 additions and 4 deletions

View File

@ -1,5 +1,5 @@
# Microsoft Developer Studio Project File - Name="Cxbx" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# Microsoft Developer Studio Generated Build File, Format Version 60000
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101

View File

@ -7,7 +7,7 @@ version: 0.7.0 (??/??/??)
- Added Recent Xbe/Exe file menus
- Support __declspec(thread) style TLS ouch!! :)
- Support __declspec(thread) style TLS ( buggy :( )
- Fixed GUI color issues

View File

@ -66,7 +66,7 @@ typedef signed long sint32;
// ******************************************************************
// * Define this to trace intercepted function calls
// ******************************************************************
#define _DEBUG_TRACE
//#define _DEBUG_TRACE
// ******************************************************************
// * Round up dwValue to nearest multiple of dwMult

View File

@ -40,6 +40,7 @@
#include <windows.h>
#define DIRECT3D_VERSION 0x0800
#include <d3d8.h>
#include <d3d8types.h>
// ******************************************************************
// * global exports

View File

@ -36,6 +36,65 @@
#include "d3d8.h"
// ******************************************************************
// * D3DResource
// ******************************************************************
struct D3DResource
{
DWORD Common;
DWORD Data;
DWORD Lock;
};
// ******************************************************************
// * D3DVertexBuffer
// ******************************************************************
struct D3DVertexBuffer : public D3DResource
{
};
// ******************************************************************
// * D3DVertexToPrimitive
// ******************************************************************
extern UINT D3DVertexToPrimitive[11][2];
// ******************************************************************
// * D3DVertexToPrimitiveCount
// ******************************************************************
#define D3DVertex2PrimitiveCount(PrimitiveType, VertexCount) \
(((VertexCount)-D3DVertexToPrimitive[PrimitiveType][1])/D3DVertexToPrimitive[PrimitiveType][0])
// ******************************************************************
// * EmuPrimitiveType
// ******************************************************************
static D3DPRIMITIVETYPE EmuPrimitiveTypeLookup[] =
{
/* NULL = 0 */ (D3DPRIMITIVETYPE)0,
/* D3DPT_POINTLIST = 1, */ D3DPT_POINTLIST,
/* D3DPT_LINELIST = 2, */ D3DPT_LINELIST,
/* D3DPT_LINELOOP = 3, Xbox */ D3DPT_LINELIST,
/* D3DPT_LINESTRIP = 4, */ D3DPT_LINESTRIP,
/* D3DPT_TRIANGLELIST = 5, */ D3DPT_TRIANGLELIST,
/* D3DPT_TRIANGLESTRIP = 6, */ D3DPT_TRIANGLESTRIP,
/* D3DPT_TRIANGLEFAN = 7, */ D3DPT_TRIANGLEFAN,
/* D3DPT_QUADLIST = 8, Xbox */ D3DPT_TRIANGLEFAN,
/* D3DPT_QUADSTRIP = 9, Xbox */ D3DPT_TRIANGLEFAN,
/* D3DPT_POLYGON = 10, Xbox */ D3DPT_TRIANGLEFAN,
/* D3DPT_MAX = 11, */ (D3DPRIMITIVETYPE)11
};
// ******************************************************************
// * EmuPrimitiveType
// ******************************************************************
static inline D3DPRIMITIVETYPE EmuPrimitiveType(int PrimitiveType)
{
if(PrimitiveType == 0x7FFFFFFF)
return D3DPT_FORCE_DWORD;
return EmuPrimitiveTypeLookup[PrimitiveType];
}
// ******************************************************************
// * func: EmuIDirect3D8_CreateDevice
// ******************************************************************
@ -70,4 +129,49 @@ HRESULT WINAPI EmuIDirect3DDevice8_Swap
DWORD Flags
);
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateVertexBuffer
// ******************************************************************
D3DVertexBuffer* WINAPI EmuIDirect3DDevice8_CreateVertexBuffer2
(
UINT Length
);
// ******************************************************************
// * func: EmuIDirect3DVertexBuffer8_Lock
// ******************************************************************
BYTE* WINAPI EmuIDirect3DVertexBuffer8_Lock
(
D3DVertexBuffer *ppVertexBuffer,
DWORD Flags
);
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetStreamSource
// ******************************************************************
void WINAPI EmuIDirect3DDevice8_SetStreamSource
(
UINT StreamNumber,
D3DVertexBuffer *pStreamData,
UINT Stride
);
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetVertexShader
// ******************************************************************
void WINAPI EmuIDirect3DDevice8_SetVertexShader
(
DWORD Handle
);
// ******************************************************************
// * func: EmuIDirect3DDevice8_DrawVertices
// ******************************************************************
void WINAPI EmuIDirect3DDevice8_DrawVertices
(
D3DPRIMITIVETYPE PrimitiveType,
UINT StartVertex,
UINT VertexCount
);
#endif

View File

@ -115,6 +115,41 @@ SOOVPA<11> IDirect3DDevice8_Swap_1_0_4361 =
}
};
// ******************************************************************
// * IDirect3DDevice8_CreateVertexBuffer
// ******************************************************************
// NOTE: This is set up differently than other XDK version!
// ******************************************************************
// * IDirect3DVertexBuffer8_Lock
// ******************************************************************
SOOVPA<11> IDirect3DVertexBuffer8_Lock_1_0_4361 =
{
0, // Large == 0
11, // Count == 11
{
// IDirect3DVertexBuffer8_Lock+0x01 : mov bl, [esp+0x18]
{ 0x01, 0x8A }, // (Offset,Value)-Pair #1
{ 0x02, 0x5C }, // (Offset,Value)-Pair #2
{ 0x03, 0x24 }, // (Offset,Value)-Pair #3
{ 0x04, 0x18 }, // (Offset,Value)-Pair #4
// IDirect3DVertexBuffer8_Lock+0x09 : jnz +0x24
{ 0x09, 0x75 }, // (Offset,Value)-Pair #5
{ 0x0A, 0x24 }, // (Offset,Value)-Pair #6
// IDirect3DVertexBuffer8_Lock+0x2F : test bl, 0xA0
{ 0x2F, 0xF6 }, // (Offset,Value)-Pair #7
{ 0x30, 0xC3 }, // (Offset,Value)-Pair #8
{ 0x31, 0xA0 }, // (Offset,Value)-Pair #9
// IDirect3DVertexBuffer8_Lock+0x50 : retn 0x14
{ 0x50, 0xC2 }, // (Offset,Value)-Pair #10
{ 0x51, 0x14 }, // (Offset,Value)-Pair #11
}
};
// ******************************************************************
// * D3D8_1_0_4361
// ******************************************************************

View File

@ -115,6 +115,167 @@ SOOVPA<11> IDirect3DDevice8_Swap_1_0_4627 =
}
};
// ******************************************************************
// * IDirect3DDevice8_CreateVertexBuffer
// ******************************************************************
SOOVPA<13> IDirect3DDevice8_CreateVertexBuffer2_1_0_4627 =
{
0, // Large == 0
13, // Count == 13
{
// IDirect3DDevice8_CreateVertexBuffer2+0x03 : push 0x40
{ 0x03, 0x6A }, // (Offset,Value)-Pair #1
{ 0x04, 0x40 }, // (Offset,Value)-Pair #2
// IDirect3DDevice8_CreateVertexBuffer2+0x10 : mov eax, [esp+8]
{ 0x10, 0x8B }, // (Offset,Value)-Pair #3
{ 0x11, 0x44 }, // (Offset,Value)-Pair #4
{ 0x12, 0x24 }, // (Offset,Value)-Pair #5
{ 0x13, 0x08 }, // (Offset,Value)-Pair #6
// IDirect3DDevice8_CreateVertexBuffer2+0x41 : mov dword ptr [esi], 0x01000001
{ 0x41, 0xC7 }, // (Offset,Value)-Pair #7
{ 0x42, 0x06 }, // (Offset,Value)-Pair #8
{ 0x43, 0x01 }, // (Offset,Value)-Pair #9
{ 0x44, 0x00 }, // (Offset,Value)-Pair #10
{ 0x46, 0x01 }, // (Offset,Value)-Pair #11
// IDirect3DDevice8_CreateVertexBuffer2+0x4A : retn 0x04
{ 0x4A, 0xC2 }, // (Offset,Value)-Pair #12
{ 0x4B, 0x04 }, // (Offset,Value)-Pair #13
}
};
// ******************************************************************
// * IDirect3DVertexBuffer8_Lock
// ******************************************************************
SOOVPA<11> IDirect3DVertexBuffer8_Lock_1_0_4627 =
{
0, // Large == 0
11, // Count == 11
{
// IDirect3DVertexBuffer8_Lock+0x01 : mov bl, [esp+0x0C]
{ 0x01, 0x8A }, // (Offset,Value)-Pair #1
{ 0x02, 0x5C }, // (Offset,Value)-Pair #2
{ 0x03, 0x24 }, // (Offset,Value)-Pair #3
{ 0x04, 0x0C }, // (Offset,Value)-Pair #4
// IDirect3DVertexBuffer8_Lock+0x09 : jnz +0x24
{ 0x09, 0x75 }, // (Offset,Value)-Pair #5
{ 0x0A, 0x24 }, // (Offset,Value)-Pair #6
// IDirect3DVertexBuffer8_Lock+0x2F : test bl, 0xA0
{ 0x2F, 0xF6 }, // (Offset,Value)-Pair #7
{ 0x30, 0xC3 }, // (Offset,Value)-Pair #8
{ 0x31, 0xA0 }, // (Offset,Value)-Pair #9
// IDirect3DVertexBuffer8_Lock+0x48 : retn 0x08
{ 0x48, 0xC2 }, // (Offset,Value)-Pair #10
{ 0x49, 0x08 }, // (Offset,Value)-Pair #11
}
};
// ******************************************************************
// * IDirect3DDevice8_SetStreamSource
// ******************************************************************
SOOVPA<14> IDirect3DDevice8_SetStreamSource_1_0_4627 =
{
0, // Large == 0
14, // Count == 14
{
// IDirect3DDevice8_SetStreamSource+0x08 : mov edi, [esp+8+0x04]
{ 0x08, 0x8B }, // (Offset,Value)-Pair #1
{ 0x09, 0x7C }, // (Offset,Value)-Pair #2
{ 0x0A, 0x24 }, // (Offset,Value)-Pair #3
{ 0x0B, 0x10 }, // (Offset,Value)-Pair #4
// IDirect3DDevice8_SetStreamSource+0x28 : jz +0x26
{ 0x28, 0x74 }, // (Offset,Value)-Pair #5
{ 0x29, 0x26 }, // (Offset,Value)-Pair #6
// IDirect3DDevice8_SetStreamSource+0x70 : or ecx, 0x40
{ 0x70, 0x83 }, // (Offset,Value)-Pair #7
{ 0x71, 0xC9 }, // (Offset,Value)-Pair #8
{ 0x72, 0x40 }, // (Offset,Value)-Pair #9
// IDirect3DDevice8_SetStreamSource+0x7E : or ecx, 0x70
{ 0x7E, 0x83 }, // (Offset,Value)-Pair #10
{ 0x7F, 0xC9 }, // (Offset,Value)-Pair #11
{ 0x80, 0x70 }, // (Offset,Value)-Pair #12
// IDirect3DDevice8_SetStreamSource+0x89 : retn 0x0C
{ 0x89, 0xC2 }, // (Offset,Value)-Pair #13
{ 0x8A, 0x0C }, // (Offset,Value)-Pair #14
}
};
// ******************************************************************
// * IDirect3DDevice8_SetVertexShader
// ******************************************************************
SOOVPA<14> IDirect3DDevice8_SetVertexShader_1_0_4627 =
{
0, // Large == 0
14, // Count == 14
{
// IDirect3DDevice8_SetVertexShader+0x06 : test bl, 1
{ 0x06, 0xF6 }, // (Offset,Value)-Pair #1
{ 0x07, 0xC3 }, // (Offset,Value)-Pair #2
{ 0x08, 0x01 }, // (Offset,Value)-Pair #3
// IDirect3DDevice8_SetVertexShader+0x11 : mov eax, [esi+0x0380]
{ 0x11, 0x8B }, // (Offset,Value)-Pair #4
{ 0x12, 0x86 }, // (Offset,Value)-Pair #5
{ 0x13, 0x80 }, // (Offset,Value)-Pair #6
{ 0x14, 0x03 }, // (Offset,Value)-Pair #7
// IDirect3DDevice8_SetVertexShader+0x90 : retn 0x04
{ 0x90, 0xC2 }, // (Offset,Value)-Pair #8
{ 0x91, 0x04 }, // (Offset,Value)-Pair #9
// IDirect3DDevice8_SetVertexShader+0xB0 : mov dword ptr [eaax], 0x4194C
{ 0xB0, 0xC7 }, // (Offset,Value)-Pair #10
{ 0xB1, 0x00 }, // (Offset,Value)-Pair #11
{ 0xB2, 0x4C }, // (Offset,Value)-Pair #12
{ 0xB3, 0x19 }, // (Offset,Value)-Pair #13
{ 0xB4, 0x04 }, // (Offset,Value)-Pair #14
}
};
// ******************************************************************
// * IDirect3DDevice8_DrawVertices
// ******************************************************************
SOOVPA<12> IDirect3DDevice8_DrawVertices_1_0_4627 =
{
0, // Large == 0
12, // Count == 12
{
// IDirect3DDevice8_DrawVertices+0x12 : mov edi, [esp+0x0C+0x0C]
{ 0x12, 0x8B }, // (Offset,Value)-Pair #1
{ 0x13, 0x7C }, // (Offset,Value)-Pair #2
{ 0x14, 0x24 }, // (Offset,Value)-Pair #3
{ 0x15, 0x18 }, // (Offset,Value)-Pair #4
// IDirect3DDevice8_DrawVertices+0x16 : lea esi, [edi-1]
{ 0x16, 0x8D }, // (Offset,Value)-Pair #5
{ 0x17, 0x77 }, // (Offset,Value)-Pair #6
{ 0x18, 0xFF }, // (Offset,Value)-Pair #7
// IDirect3DDevice8_DrawVertices+0x7E : shl edi, 0x18
{ 0x7E, 0xC1 }, // (Offset,Value)-Pair #8
{ 0x7F, 0xE7 }, // (Offset,Value)-Pair #9
{ 0x80, 0x18 }, // (Offset,Value)-Pair #10
// IDirect3DDevice8_DrawVertices+0x9C : retn 0x0C
{ 0x9C, 0xC2 }, // (Offset,Value)-Pair #11
{ 0x9D, 0x0C }, // (Offset,Value)-Pair #12
}
};
// ******************************************************************
// * D3D8_1_0_4627
// ******************************************************************
@ -150,6 +311,56 @@ OOVPATable D3D8_1_0_4627[] =
"EmuIDirect3DDevice8_Swap"
#endif
},
// IDirect3DDevice8::CreateVertexBuffer2
{
(OOVPA*)&IDirect3DDevice8_CreateVertexBuffer2_1_0_4627,
xd3d8::EmuIDirect3DDevice8_CreateVertexBuffer2,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_CreateVertexBuffer2"
#endif
},
// IDirect3DVertexBuffer8::Lock
{
(OOVPA*)&IDirect3DVertexBuffer8_Lock_1_0_4627,
xd3d8::EmuIDirect3DVertexBuffer8_Lock,
#ifdef _DEBUG_TRACE
"EmuIDirect3DVertexBuffer8_Lock"
#endif
},
// IDirect3DDevice8::SetStreamSource
{
(OOVPA*)&IDirect3DDevice8_SetStreamSource_1_0_4627,
xd3d8::EmuIDirect3DDevice8_SetStreamSource,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_SetStreamSource"
#endif
},
// IDirect3DDevice8::SetVertexShader
{
(OOVPA*)&IDirect3DDevice8_SetVertexShader_1_0_4627,
xd3d8::EmuIDirect3DDevice8_SetVertexShader,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_SetVertexShader"
#endif
},
// IDirect3DDevice8::DrawVertices
{
(OOVPA*)&IDirect3DDevice8_DrawVertices_1_0_4627,
xd3d8::EmuIDirect3DDevice8_DrawVertices,
#ifdef _DEBUG_TRACE
"EmuIDirect3DDevice8_DrawVertices"
#endif
},
};
// ******************************************************************

View File

@ -300,6 +300,15 @@ extern "C" CXBXKRNL_API void NTAPI EmuCleanup(const char *szErrorMessage)
MessageBox(NULL, buffer, "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION);
}
// ******************************************************************
// * Cleanup debug output
// ******************************************************************
{
FreeConsole();
freopen("CONOUT$", "wt", stdout);
}
// ******************************************************************
// * Suspend and Redirect all Threads
// ******************************************************************

View File

@ -79,6 +79,24 @@ HBRUSH g_hBgBrush = NULL; // Background Brush
static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static void EmuRenderWindow(PVOID);
// ******************************************************************
// * D3DVertexToPrimitive
// ******************************************************************
UINT xd3d8::D3DVertexToPrimitive[11][2] =
{
{0, 0},
{1, 0},
{2, 0},
{1, 1},
{1, 1},
{3, 0},
{1, 2},
{1, 2},
{4, 0},
{2, 2},
{0, 0},
};
// ******************************************************************
// * func: EmuD3DInit
// ******************************************************************
@ -467,4 +485,187 @@ HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_Swap
EmuSwapFS(); // XBox FS
return ret;
}
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateVertexBuffer
// ******************************************************************
xd3d8::D3DVertexBuffer* WINAPI xd3d8::EmuIDirect3DDevice8_CreateVertexBuffer2
(
UINT Length
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%.08X): EmuIDirect3DDevice8_CreateVertexBuffer2\n"
"(\n"
" Length : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Length);
}
#endif
IDirect3DVertexBuffer8 *ppVertexBuffer=NULL;
HRESULT hRet = g_pD3D8Device->CreateVertexBuffer
(
Length,
D3DUSAGE_WRITEONLY,
0,
D3DPOOL_DEFAULT,
&ppVertexBuffer
);
EmuSwapFS(); // XBox FS
return (xd3d8::D3DVertexBuffer*)ppVertexBuffer;
}
// ******************************************************************
// * func: EmuIDirect3DVertexBuffer8_Lock
// ******************************************************************
BYTE* WINAPI xd3d8::EmuIDirect3DVertexBuffer8_Lock
(
D3DVertexBuffer *ppVertexBuffer,
DWORD Flags
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%.08X): EmuIDirect3DVertexBuffer8_Lock\n"
"(\n"
" ppVertexBuffer : 0x%.08X\n"
" Flags : 0x%.08X\n"
");\n",
GetCurrentThreadId(), ppVertexBuffer, Flags);
}
#endif
BYTE *pbData = NULL;
HRESULT hRet = ((IDirect3DVertexBuffer8*)ppVertexBuffer)->Lock(0, 0, &pbData, Flags);
EmuSwapFS(); // XBox FS
return pbData;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetStreamSource
// ******************************************************************
void WINAPI xd3d8::EmuIDirect3DDevice8_SetStreamSource
(
UINT StreamNumber,
D3DVertexBuffer *pStreamData,
UINT Stride
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%.08X): EmuIDirect3DDevice8_SetStreamSource\n"
"(\n"
" StreamNumber : 0x%.08X\n"
" pStreamData : 0x%.08X\n"
" Stride : 0x%.08X\n"
");\n",
GetCurrentThreadId(), StreamNumber, pStreamData, Stride);
}
#endif
((IDirect3DVertexBuffer8*)pStreamData)->Unlock();
HRESULT ret = g_pD3D8Device->SetStreamSource(StreamNumber, (IDirect3DVertexBuffer8*)pStreamData, Stride);
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetVertexShader
// ******************************************************************
void WINAPI xd3d8::EmuIDirect3DDevice8_SetVertexShader
(
DWORD Handle
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%.08X): EmuIDirect3DDevice8_SetVertexShader\n"
"(\n"
" Handle : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Handle);
}
#endif
HRESULT ret = g_pD3D8Device->SetVertexShader(Handle);
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_DrawVertices
// ******************************************************************
void WINAPI xd3d8::EmuIDirect3DDevice8_DrawVertices
(
D3DPRIMITIVETYPE PrimitiveType,
UINT StartVertex,
UINT VertexCount
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%.08X): EmuIDirect3DDevice8_DrawVertices\n"
"(\n"
" PrimitiveType : 0x%.08X\n"
" StartVertex : 0x%.08X\n"
" VertexCount : 0x%.08X\n"
");\n",
GetCurrentThreadId(), PrimitiveType, StartVertex, VertexCount);
}
#endif
UINT PrimitiveCount = D3DVertex2PrimitiveCount(PrimitiveType, VertexCount);
// Convert from Xbox to PC enumeration
PrimitiveType = EmuPrimitiveType(PrimitiveType);
HRESULT hRet = g_pD3D8Device->DrawPrimitive
(
PrimitiveType,
StartVertex,
PrimitiveCount
);
EmuSwapFS(); // XBox FS
return;
}