Cxbx-Reloaded/Source/Win32/CxbxKrnl/EmuD3D8.cpp

4029 lines
129 KiB
C++
Raw Normal View History

// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
2003-05-02 06:51:35 +00:00
// * Cxbx->Win32->CxbxKrnl->EmuD3D8.cpp
// *
// * This file is part of the Cxbx project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
// *
// * All rights reserved
// *
2003-03-07 22:01:44 +00:00
// ******************************************************************
#define _CXBXKRNL_INTERNAL
2003-04-02 02:23:30 +00:00
#define _XBOXKRNL_LOCAL_
// ******************************************************************
// * prevent name collisions
// ******************************************************************
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h>
};
2003-03-27 06:23:58 +00:00
#include "Emu.h"
2003-04-02 02:23:30 +00:00
#include "EmuFS.h"
2003-05-31 01:17:12 +00:00
#include "EmuShared.h"
2003-03-07 22:01:44 +00:00
// ******************************************************************
// * prevent name collisions
// ******************************************************************
2003-07-02 20:14:15 +00:00
namespace XTL
2003-02-21 00:07:28 +00:00
{
2003-07-02 20:14:15 +00:00
#include "EmuXTL.h"
2003-04-02 02:23:30 +00:00
};
2003-02-21 00:07:28 +00:00
2003-03-04 07:05:25 +00:00
#include "ResCxbxDll.h"
2003-04-02 02:23:30 +00:00
#include <process.h>
#include <locale.h>
// ******************************************************************
2003-05-31 01:17:12 +00:00
// * Global(s)
// ******************************************************************
2003-07-02 20:14:15 +00:00
HWND XTL::g_hEmuWindow = NULL; // Rendering Window
2003-05-02 06:51:35 +00:00
// ******************************************************************
2003-05-31 01:17:12 +00:00
// * Static Function(s)
// ******************************************************************
2003-05-05 06:35:37 +00:00
static DWORD WINAPI EmuRenderWindow(LPVOID);
static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
2003-05-05 06:35:37 +00:00
static DWORD WINAPI EmuUpdateTickCount(LPVOID);
2003-06-18 05:15:02 +00:00
static DWORD EmuCheckAllocationSize(LPVOID);
2003-07-02 20:14:15 +00:00
static inline void EmuVerifyResourceIsRegistered(XTL::X_D3DResource *pResource);
2003-05-31 01:17:12 +00:00
// ******************************************************************
// * Static Variable(s)
// ******************************************************************
2003-07-02 20:14:15 +00:00
static XTL::LPDIRECT3D8 g_pD3D8 = NULL; // Direct3D8
static XTL::LPDIRECT3DDEVICE8 g_pD3DDevice8 = NULL; // Direct3D8 Device
static Xbe::Header *g_XbeHeader = NULL; // XbeHeader
static uint32 g_XbeHeaderSize = 0; // XbeHeaderSize
static XTL::D3DCAPS8 g_D3DCaps; // Direct3D8 Caps
static HBRUSH g_hBgBrush = NULL; // Background Brush
static volatile bool g_bThreadInitialized = false;
static XBVideo g_XBVideo;
2003-05-31 01:17:12 +00:00
2003-06-12 02:05:10 +00:00
// ******************************************************************
// * Cached Direct3D State Variable(s)
// ******************************************************************
2003-07-02 20:14:15 +00:00
static XTL::X_D3DSurface *g_pCachedRenderTarget = NULL;
static XTL::X_D3DSurface *g_pCachedZStencilSurface = NULL;
static DWORD g_dwVertexShaderUsage = 0;
2003-06-12 02:05:10 +00:00
2003-06-18 05:15:02 +00:00
// ******************************************************************
// * EmuD3DTiles (8 Tiles Max)
// ******************************************************************
2003-07-02 20:14:15 +00:00
XTL::X_D3DTILE XTL::EmuD3DTileCache[0x08] = {0};
2003-06-18 05:15:02 +00:00
2003-05-23 02:55:39 +00:00
// ******************************************************************
2003-06-13 00:37:41 +00:00
// * EmuD3DDeferredRenderState
2003-05-23 02:55:39 +00:00
// ******************************************************************
2003-07-02 20:14:15 +00:00
DWORD *XTL::EmuD3DDeferredRenderState;
2003-06-13 00:37:41 +00:00
// ******************************************************************
// * EmuD3DDeferredTextureState
// ******************************************************************
2003-07-02 20:14:15 +00:00
DWORD *XTL::EmuD3DDeferredTextureState;
2003-05-23 02:55:39 +00:00
// ******************************************************************
2003-07-02 20:14:15 +00:00
// * func: XTL::EmuD3DInit
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID XTL::EmuD3DInit(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
2003-02-21 00:07:28 +00:00
{
2003-05-31 01:17:12 +00:00
g_EmuShared->GetXBVideo(&g_XBVideo);
2003-03-21 03:30:00 +00:00
// ******************************************************************
// * store XbeHeader and XbeHeaderSize for further use
// ******************************************************************
2003-05-30 02:08:25 +00:00
g_XbeHeader = XbeHeader;
g_XbeHeaderSize = XbeHeaderSize;
2003-03-21 03:30:00 +00:00
2003-06-12 02:05:10 +00:00
g_bThreadInitialized = false;
2003-04-16 19:06:20 +00:00
2003-02-21 00:07:28 +00:00
// ******************************************************************
2003-05-30 02:08:25 +00:00
// * Create a thread dedicated to timing
2003-02-21 00:07:28 +00:00
// ******************************************************************
{
2003-05-03 08:29:37 +00:00
DWORD dwThreadId;
2003-05-05 06:35:37 +00:00
CreateThread(NULL, NULL, EmuUpdateTickCount, NULL, NULL, &dwThreadId);
2003-05-30 02:08:25 +00:00
}
// ******************************************************************
// * spark up a new thread to handle window message processing
// ******************************************************************
{
DWORD dwThreadId;
2003-05-03 08:29:37 +00:00
CreateThread(NULL, NULL, EmuRenderWindow, NULL, NULL, &dwThreadId);
2003-02-21 00:07:28 +00:00
2003-06-12 02:05:10 +00:00
while(!g_bThreadInitialized)
2003-03-07 07:38:26 +00:00
Sleep(10);
2003-04-26 23:10:35 +00:00
Sleep(50);
2003-02-21 00:07:28 +00:00
}
// ******************************************************************
2003-04-01 02:47:38 +00:00
// * create Direct3D8 and retrieve caps
2003-02-21 00:07:28 +00:00
// ******************************************************************
{
2003-07-02 20:14:15 +00:00
using namespace XTL;
2003-04-08 03:34:05 +00:00
2003-02-21 00:07:28 +00:00
// xbox Direct3DCreate8 returns "1" always, so we need our own ptr
g_pD3D8 = Direct3DCreate8(D3D_SDK_VERSION);
2003-04-01 02:47:38 +00:00
2003-04-26 04:32:46 +00:00
if(g_pD3D8 == NULL)
2003-06-09 03:44:07 +00:00
EmuCleanup("Could not initialize Direct3D8!");
2003-04-26 04:32:46 +00:00
2003-06-06 00:56:10 +00:00
D3DDEVTYPE DevType = (g_XBVideo.GetDirect3DDevice() == 0) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF;
g_pD3D8->GetDeviceCaps(g_XBVideo.GetDisplayAdapter(), DevType, &g_D3DCaps);
2003-02-21 00:07:28 +00:00
}
// ******************************************************************
// * create default device
// ******************************************************************
{
2003-07-02 20:14:15 +00:00
XTL::X_D3DPRESENT_PARAMETERS PresParam;
ZeroMemory(&PresParam, sizeof(PresParam));
PresParam.BackBufferWidth = 640;
PresParam.BackBufferHeight = 480;
PresParam.BackBufferFormat = 6; /* X_D3DFMT_A8R8G8B8 */
PresParam.BackBufferCount = 1;
PresParam.EnableAutoDepthStencil = TRUE;
PresParam.AutoDepthStencilFormat = 0x2A; /* X_D3DFMT_D24S8 */
2003-07-02 20:14:15 +00:00
PresParam.SwapEffect = XTL::D3DSWAPEFFECT_DISCARD;
EmuSwapFS(); // XBox FS
2003-07-02 20:14:15 +00:00
XTL::EmuIDirect3D8_CreateDevice(0, XTL::D3DDEVTYPE_HAL, 0, 0x00000040, &PresParam, &g_pD3DDevice8);
EmuSwapFS(); // Win2k/XP FS
}
2003-02-21 00:07:28 +00:00
}
2003-04-16 19:06:20 +00:00
// ******************************************************************
2003-07-02 20:14:15 +00:00
// * func: XTL::EmuD3DCleanup
2003-04-16 19:06:20 +00:00
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID XTL::EmuD3DCleanup()
2003-04-16 19:06:20 +00:00
{
2003-07-02 20:14:15 +00:00
XTL::EmuDInputCleanup();
2003-04-16 19:06:20 +00:00
return;
}
2003-02-21 00:07:28 +00:00
// ******************************************************************
2003-03-27 06:23:58 +00:00
// * func: EmuRenderWindow
2003-02-21 00:07:28 +00:00
// ******************************************************************
static DWORD WINAPI EmuRenderWindow(LPVOID)
{
// ******************************************************************
// * register window class
// ******************************************************************
{
#ifdef _DEBUG
2003-04-06 20:07:36 +00:00
HMODULE hCxbxDll = GetModuleHandle("CxbxKrnl.dll");
#else
2003-03-04 07:05:25 +00:00
HMODULE hCxbxDll = GetModuleHandle("Cxbx.dll");
#endif
2003-03-04 07:05:25 +00:00
2003-04-26 04:32:46 +00:00
LOGBRUSH logBrush = {BS_SOLID, RGB(0,0,0)};
g_hBgBrush = CreateBrushIndirect(&logBrush);
WNDCLASSEX wc =
{
sizeof(WNDCLASSEX),
CS_CLASSDC,
2003-03-27 06:23:58 +00:00
EmuMsgProc,
0, 0, GetModuleHandle(NULL),
2003-04-17 01:32:51 +00:00
LoadIcon(hCxbxDll, MAKEINTRESOURCE(IDI_CXBX)),
LoadCursor(NULL, IDC_ARROW),
2003-04-26 04:32:46 +00:00
(HBRUSH)(g_hBgBrush), NULL,
"CxbxRender",
NULL
};
RegisterClassEx(&wc);
}
// ******************************************************************
// * create the window
// ******************************************************************
{
2003-03-21 03:30:00 +00:00
char AsciiTitle[50];
// ******************************************************************
// * retrieve xbe title (if possible)
// ******************************************************************
{
char tAsciiTitle[40] = "Unknown";
uint32 CertAddr = g_XbeHeader->dwCertificateAddr - g_XbeHeader->dwBaseAddr;
if(CertAddr + 0x0C + 40 < g_XbeHeaderSize)
{
Xbe::Certificate *XbeCert = (Xbe::Certificate*)((uint32)g_XbeHeader + CertAddr);
setlocale( LC_ALL, "English" );
wcstombs(tAsciiTitle, XbeCert->wszTitleName, 40);
}
2003-04-08 03:34:05 +00:00
sprintf(AsciiTitle, "Cxbx : Emulating %s", tAsciiTitle);
2003-03-21 03:30:00 +00:00
}
2003-05-31 01:17:12 +00:00
// ******************************************************************
// * Create Window
// ******************************************************************
{
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
2003-06-01 03:19:15 +00:00
2003-05-31 01:17:12 +00:00
int x = 100, y = 100, nWidth = 640, nHeight = 480;
2003-06-01 03:19:15 +00:00
sscanf(g_XBVideo.GetVideoResolution(), "%d x %d", &nWidth, &nHeight);
2003-05-31 01:17:12 +00:00
if(g_XBVideo.GetFullscreen())
{
x = y = nWidth = nHeight = 0;
dwStyle = WS_POPUP;
}
2003-07-02 20:14:15 +00:00
XTL::g_hEmuWindow = CreateWindow
2003-05-31 01:17:12 +00:00
(
"CxbxRender", AsciiTitle,
dwStyle, x, y, nWidth, nHeight,
GetDesktopWindow(), NULL, GetModuleHandle(NULL), NULL
);
}
}
2003-07-02 20:14:15 +00:00
ShowWindow(XTL::g_hEmuWindow, SW_SHOWDEFAULT);
UpdateWindow(XTL::g_hEmuWindow);
2003-02-19 20:53:33 +00:00
2003-03-23 22:24:41 +00:00
// ******************************************************************
// * initialize direct input
// ******************************************************************
2003-07-02 20:14:15 +00:00
if(!XTL::EmuDInputInit())
2003-04-26 04:32:46 +00:00
EmuCleanup("Could not initialize DirectInput!");
2003-03-23 22:24:41 +00:00
2003-02-22 07:49:02 +00:00
// ******************************************************************
// * message processing loop
// ******************************************************************
{
MSG msg;
2003-02-22 07:49:02 +00:00
ZeroMemory(&msg, sizeof(msg));
2003-02-21 00:07:28 +00:00
2003-02-22 07:49:02 +00:00
while(msg.message != WM_QUIT)
2003-02-21 00:07:28 +00:00
{
2003-04-26 23:10:35 +00:00
if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
2003-02-22 07:49:02 +00:00
{
2003-06-12 02:05:10 +00:00
g_bThreadInitialized = true;
2003-04-18 23:44:36 +00:00
2003-02-22 07:49:02 +00:00
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
Sleep(10);
2003-02-21 00:07:28 +00:00
}
2003-04-26 04:32:46 +00:00
EmuCleanup(NULL);
2003-02-22 07:49:02 +00:00
}
2003-05-03 08:29:37 +00:00
return 0;
}
2003-02-21 04:51:03 +00:00
// ******************************************************************
2003-03-27 06:23:58 +00:00
// * func: EmuMsgProc
2003-02-21 04:51:03 +00:00
// ******************************************************************
static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2003-02-21 04:51:03 +00:00
{
2003-07-08 18:58:04 +00:00
static DWORD dwRestoreSleepRate = EmuAutoSleepRate;
2003-02-21 04:51:03 +00:00
switch(msg)
{
case WM_DESTROY:
2003-04-26 04:32:46 +00:00
DeleteObject(g_hBgBrush);
2003-02-21 04:51:03 +00:00
PostQuitMessage(0);
return 0;
2003-03-04 07:48:23 +00:00
2003-05-23 02:55:39 +00:00
case WM_KEYDOWN:
2003-04-16 19:06:20 +00:00
if(wParam == VK_ESCAPE)
2003-05-23 02:55:39 +00:00
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
2003-03-09 09:17:07 +00:00
2003-07-08 18:58:04 +00:00
case WM_SETFOCUS:
EmuAutoSleepRate = dwRestoreSleepRate;
break;
case WM_KILLFOCUS:
dwRestoreSleepRate = EmuAutoSleepRate;
EmuAutoSleepRate = 1;
break;
2003-03-04 07:48:23 +00:00
case WM_CLOSE:
DestroyWindow(hWnd);
break;
2003-07-08 18:58:04 +00:00
2003-03-23 22:24:41 +00:00
case WM_SETCURSOR:
2003-05-31 01:17:12 +00:00
if(g_XBVideo.GetFullscreen())
{
SetCursor(NULL);
return 0;
}
2003-06-01 03:19:15 +00:00
return DefWindowProc(hWnd, msg, wParam, lParam);
2003-07-08 18:58:04 +00:00
2003-04-16 19:06:20 +00:00
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
2003-02-21 04:51:03 +00:00
}
2003-04-16 19:06:20 +00:00
return 0;
2003-02-21 04:51:03 +00:00
}
// ******************************************************************
// * func: EmuUpdateTickCount
// ******************************************************************
static DWORD WINAPI EmuUpdateTickCount(LPVOID)
{
timeBeginPeriod(0);
while(true)
{
xboxkrnl::KeTickCount = timeGetTime();
Sleep(1);
}
timeEndPeriod(0);
}
// ******************************************************************
// * func: EmuCheckAllocationSize
// ******************************************************************
static DWORD EmuCheckAllocationSize(PVOID pBase)
{
MEMORY_BASIC_INFORMATION MemoryBasicInfo;
DWORD dwRet = VirtualQuery(pBase, &MemoryBasicInfo, sizeof(MemoryBasicInfo));
if(dwRet == 0)
return 0;
if(MemoryBasicInfo.State != MEM_COMMIT)
return 0;
return MemoryBasicInfo.RegionSize - ((DWORD)pBase - (DWORD)MemoryBasicInfo.BaseAddress);
}
// ******************************************************************
// * func: EmuVerifyResourceIsRegistered
// ******************************************************************
2003-07-02 20:14:15 +00:00
static inline void EmuVerifyResourceIsRegistered(XTL::X_D3DResource *pResource)
{
if(pResource->Lock == 0)
{
EmuSwapFS(); // XBox FS;
2003-07-02 20:14:15 +00:00
XTL::EmuIDirect3DResource8_Register(pResource, (PVOID)pResource->Data);
EmuSwapFS(); // Win2k/XP FS
}
}
// ******************************************************************
2003-03-27 06:23:58 +00:00
// * func: EmuIDirect3D8_CreateDevice
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3D8_CreateDevice
(
2003-06-07 03:06:59 +00:00
UINT Adapter,
D3DDEVTYPE DeviceType,
HWND hFocusWindow,
DWORD BehaviorFlags,
X_D3DPRESENT_PARAMETERS *pPresentationParameters,
IDirect3DDevice8 **ppReturnedDeviceInterface
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-19 20:53:33 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3D8_CreateDevice\n"
2003-02-19 20:53:33 +00:00
"(\n"
" Adapter : 0x%.08X\n"
" DeviceType : 0x%.08X\n"
" hFocusWindow : 0x%.08X\n"
" BehaviorFlags : 0x%.08X\n"
" pPresentationParameters : 0x%.08X\n"
" ppReturnedDeviceInterface : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Adapter, DeviceType, hFocusWindow,
BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
}
#endif
2003-06-28 08:16:08 +00:00
// only one device should be created at once
// TODO: ensure all surfaces are somehow cleaned up?
if(g_pD3DDevice8 != 0)
{
g_pD3DDevice8->Release();
g_pD3DDevice8 = 0;
}
2003-06-07 03:06:59 +00:00
// ******************************************************************
// * verify no ugly circumstances
// ******************************************************************
if(pPresentationParameters->BufferSurfaces[0] != NULL || pPresentationParameters->DepthStencilSurface != NULL)
printf("*Warning* DepthStencilSurface != NULL and/or BufferSurfaces[0] != NULL\n");
2003-06-07 03:06:59 +00:00
2003-02-19 20:53:33 +00:00
// ******************************************************************
// * make adjustments to parameters to make sense with windows d3d
// ******************************************************************
{
2003-05-31 01:17:12 +00:00
DeviceType =(g_XBVideo.GetDirect3DDevice() == 0) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF;
Adapter = g_XBVideo.GetDisplayAdapter();
2003-02-19 20:53:33 +00:00
2003-05-31 01:17:12 +00:00
pPresentationParameters->Windowed = !g_XBVideo.GetFullscreen();
2003-05-30 02:08:25 +00:00
2003-05-31 01:17:12 +00:00
if(g_XBVideo.GetVSync())
pPresentationParameters->SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
2003-02-23 08:01:01 +00:00
2003-04-26 08:57:51 +00:00
hFocusWindow = g_hEmuWindow;
2003-02-19 20:53:33 +00:00
2003-06-05 03:09:52 +00:00
pPresentationParameters->BackBufferFormat = EmuXB2PC_D3DFormat(pPresentationParameters->BackBufferFormat);
pPresentationParameters->AutoDepthStencilFormat = EmuXB2PC_D3DFormat(pPresentationParameters->AutoDepthStencilFormat);
2003-05-25 07:31:07 +00:00
2003-06-09 03:44:07 +00:00
// TODO: This should be detected from D3DCAPS8 ? (FrameSkip?)
pPresentationParameters->FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
2003-06-12 02:05:10 +00:00
// TODO: Support Xbox extensions if possible
if(pPresentationParameters->MultiSampleType != 0)
{
2003-06-17 02:23:53 +00:00
printf("*Warning* MultiSampleType (0x%.08X) Not Supported!\n", pPresentationParameters->MultiSampleType);
2003-06-12 02:05:10 +00:00
pPresentationParameters->MultiSampleType = D3DMULTISAMPLE_NONE;
// TODO: Check card for multisampling abilities
// if(pPresentationParameters->MultiSampleType == 0x00001121)
// pPresentationParameters->MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
// else
// EmuCleanup("Unknown MultiSampleType (0x%.08X)", pPresentationParameters->MultiSampleType);
}
pPresentationParameters->Flags &= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
2003-05-25 07:31:07 +00:00
// ******************************************************************
2003-06-01 03:19:15 +00:00
// * Retrieve Resolution from Configuration
2003-05-25 07:31:07 +00:00
// ******************************************************************
if(pPresentationParameters->Windowed)
{
D3DDISPLAYMODE D3DDisplayMode;
2003-06-05 03:09:52 +00:00
sscanf(g_XBVideo.GetVideoResolution(), "%d x %d", &pPresentationParameters->BackBufferWidth, &pPresentationParameters->BackBufferHeight);
2003-05-31 01:17:12 +00:00
g_pD3D8->GetAdapterDisplayMode(g_XBVideo.GetDisplayAdapter(), &D3DDisplayMode);
2003-05-25 07:31:07 +00:00
pPresentationParameters->BackBufferFormat = D3DDisplayMode.Format;
2003-06-01 03:19:15 +00:00
pPresentationParameters->FullScreen_RefreshRateInHz = 0;
}
else
{
char szBackBufferFormat[16];
sscanf(g_XBVideo.GetVideoResolution(), "%d x %d %*dbit %s (%d hz)",
&pPresentationParameters->BackBufferWidth,
&pPresentationParameters->BackBufferHeight,
szBackBufferFormat,
&pPresentationParameters->FullScreen_RefreshRateInHz);
if(strcmp(szBackBufferFormat, "x1r5g5b5") == 0)
pPresentationParameters->BackBufferFormat = D3DFMT_X1R5G5B5;
2003-06-07 03:06:59 +00:00
else if(strcmp(szBackBufferFormat, "r5g6r5") == 0)
2003-06-01 03:19:15 +00:00
pPresentationParameters->BackBufferFormat = D3DFMT_R5G6B5;
2003-06-07 03:06:59 +00:00
else if(strcmp(szBackBufferFormat, "x8r8g8b8") == 0)
2003-06-01 03:19:15 +00:00
pPresentationParameters->BackBufferFormat = D3DFMT_X8R8G8B8;
2003-06-07 03:06:59 +00:00
else if(strcmp(szBackBufferFormat, "a8r8g8b8") == 0)
2003-06-01 03:19:15 +00:00
pPresentationParameters->BackBufferFormat = D3DFMT_A8R8G8B8;
2003-05-25 07:31:07 +00:00
}
2003-02-19 20:53:33 +00:00
}
2003-02-20 08:07:52 +00:00
// ******************************************************************
2003-05-25 07:31:07 +00:00
// * Detect vertex processing capabilities
2003-02-20 08:07:52 +00:00
// ******************************************************************
2003-06-07 03:06:59 +00:00
if((g_D3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && DeviceType == D3DDEVTYPE_HAL)
2003-05-25 07:31:07 +00:00
{
#ifdef _DEBUG_TRACE
printf("EmuD3D8 (0x%X): Using hardware vertex processing\n", GetCurrentThreadId());
#endif
BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
2003-06-12 02:05:10 +00:00
g_dwVertexShaderUsage = 0;
2003-05-25 07:31:07 +00:00
}
else
{
#ifdef _DEBUG_TRACE
printf("EmuD3D8 (0x%X): Using software vertex processing\n", GetCurrentThreadId());
#endif
BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
2003-06-12 02:05:10 +00:00
g_dwVertexShaderUsage = D3DUSAGE_SOFTWAREPROCESSING;
2003-05-25 07:31:07 +00:00
}
2003-02-20 08:07:52 +00:00
2003-02-19 20:53:33 +00:00
// ******************************************************************
// * redirect to windows d3d
// ******************************************************************
2003-05-03 08:29:37 +00:00
HRESULT hRet = g_pD3D8->CreateDevice
2003-02-19 20:53:33 +00:00
(
Adapter,
DeviceType,
hFocusWindow,
2003-02-22 07:49:02 +00:00
BehaviorFlags,
2003-07-02 20:14:15 +00:00
(XTL::D3DPRESENT_PARAMETERS*)pPresentationParameters,
2003-02-19 20:53:33 +00:00
ppReturnedDeviceInterface
);
2003-06-26 23:55:09 +00:00
if(FAILED(hRet))
EmuCleanup("IDirect3D8::CreateDevice failed (Invalid Display Settings?)");
2003-02-20 08:07:52 +00:00
// ******************************************************************
// * it is necessary to store this pointer globally for emulation
// ******************************************************************
2003-06-10 22:32:31 +00:00
g_pD3DDevice8 = *ppReturnedDeviceInterface;
2003-06-07 03:06:59 +00:00
2003-06-12 02:05:10 +00:00
// ******************************************************************
// * Update Caches
// ******************************************************************
{
g_pCachedRenderTarget = new X_D3DSurface();
g_pD3DDevice8->GetRenderTarget(&g_pCachedRenderTarget->EmuSurface8);
g_pCachedZStencilSurface = new X_D3DSurface();
g_pD3DDevice8->GetDepthStencilSurface(&g_pCachedZStencilSurface->EmuSurface8);
}
2003-06-11 02:07:41 +00:00
// ******************************************************************
2003-06-15 00:37:03 +00:00
// * Begin Scene
2003-06-11 02:07:41 +00:00
// ******************************************************************
2003-06-15 00:37:03 +00:00
g_pD3DDevice8->BeginScene();
2003-06-11 02:07:41 +00:00
2003-06-04 02:18:40 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3D8_GetAdapterModeCount
// ******************************************************************
2003-07-02 20:14:15 +00:00
UINT WINAPI XTL::EmuIDirect3D8_GetAdapterModeCount
(
UINT Adapter
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3D8_GetAdapterModeCount\n"
"(\n"
" Adapter : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Adapter);
}
#endif
// NOTE: WARNING: We should return only modes that should exist on a real
// Xbox. This could even be configurable, if desirable.
// ******************************************************************
// * redirect to windows d3d
// ******************************************************************
UINT ret = g_pD3D8->GetAdapterModeCount(g_XBVideo.GetDisplayAdapter());
EmuSwapFS(); // XBox FS
return ret;
}
2003-06-09 03:44:07 +00:00
// ******************************************************************
// * func: EmuIDirect3D8_GetAdapterDisplayMode
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3D8_GetAdapterDisplayMode
2003-06-09 03:44:07 +00:00
(
UINT Adapter,
X_D3DDISPLAYMODE *pMode
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3D8_GetAdapterDisplayMode\n"
"(\n"
" Adapter : 0x%.08X\n"
" pMode : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Adapter, pMode);
}
#endif
// NOTE: WARNING: We should cache the "Emulated" display mode and return
// This value. We can initialize the cache with the default Xbox mode data.
2003-06-09 03:44:07 +00:00
// ******************************************************************
// * redirect to windows d3d
// ******************************************************************
HRESULT hRet = g_pD3D8->GetAdapterDisplayMode
(
g_XBVideo.GetDisplayAdapter(),
(D3DDISPLAYMODE*)pMode
);
// ******************************************************************
// * make adjustments to parameters to make sense with windows d3d
// ******************************************************************
{
D3DDISPLAYMODE *pPCMode = (D3DDISPLAYMODE*)pMode;
// Convert Format (PC->Xbox)
pMode->Format = EmuPC2XB_D3DFormat(pPCMode->Format);
// TODO: Make this configurable in the future?
// D3DPRESENTFLAG_FIELD | D3DPRESENTFLAG_INTERLACED | D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
pMode->Flags = 0x000000A1;
2003-06-09 03:44:07 +00:00
}
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3D8_EnumAdapterModes
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3D8_EnumAdapterModes
(
UINT Adapter,
UINT Mode,
X_D3DDISPLAYMODE *pMode
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3D8_EnumAdapterModes\n"
"(\n"
" Adapter : 0x%.08X\n"
" Mode : 0x%.08X\n"
" pMode : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Adapter, Mode, pMode);
}
#endif
// NOTE: WARNING: We should probably only return valid xbox display modes,
// this should be coordinated with GetAdapterModeCount, etc.
// ******************************************************************
// * redirect to windows d3d
// ******************************************************************
HRESULT hRet = g_pD3D8->EnumAdapterModes(g_XBVideo.GetDisplayAdapter(), Mode, (D3DDISPLAYMODE*)pMode);
// ******************************************************************
// * make adjustments to parameters to make sense with windows d3d
// ******************************************************************
{
D3DDISPLAYMODE *pPCMode = (D3DDISPLAYMODE*)pMode;
// Convert Format (PC->Xbox)
pMode->Format = EmuPC2XB_D3DFormat(pPCMode->Format);
// TODO: Make this configurable in the future?
// D3DPRESENTFLAG_FIELD | D3DPRESENTFLAG_INTERLACED | D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
pMode->Flags = 0x000000A1;
}
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-18 01:27:33 +00:00
// ******************************************************************
// * func: EmuIDirect3D8_KickOffAndWaitForIdle
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3D8_KickOffAndWaitForIdle()
2003-06-18 01:27:33 +00:00
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3D8_KickOffAndWaitForIdle()\n", GetCurrentThreadId());
}
#endif
// TODO: Actually do something here?
2003-06-18 01:27:33 +00:00
EmuSwapFS(); // XBox FS
return;
}
2003-07-03 05:09:28 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_AddRef
// ******************************************************************
ULONG WINAPI XTL::EmuIDirect3DDevice8_AddRef()
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_AddRef()\n", GetCurrentThreadId());
}
#endif
ULONG ret = g_pD3DDevice8->AddRef();
EmuSwapFS(); // XBox FS
return ret;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_BeginStateBlock
// ******************************************************************
HRESULT WINAPI XTL::EmuIDirect3DDevice8_BeginStateBlock()
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_BeginStateBlock()\n", GetCurrentThreadId());
}
#endif
ULONG ret = g_pD3DDevice8->BeginStateBlock();
EmuSwapFS(); // XBox FS
return ret;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_CaptureStateBlock
// ******************************************************************
HRESULT WINAPI XTL::EmuIDirect3DDevice8_CaptureStateBlock(DWORD Token)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_CaptureStateBlock\n"
"(\n"
" Token : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Token);
}
#endif
ULONG ret = g_pD3DDevice8->CaptureStateBlock(Token);
EmuSwapFS(); // XBox FS
return ret;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_ApplyStateBlock
// ******************************************************************
HRESULT WINAPI XTL::EmuIDirect3DDevice8_ApplyStateBlock(DWORD Token)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_ApplyStateBlock\n"
"(\n"
" Token : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Token);
}
#endif
ULONG ret = g_pD3DDevice8->ApplyStateBlock(Token);
EmuSwapFS(); // XBox FS
return ret;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_EndStateBlock
// ******************************************************************
HRESULT WINAPI XTL::EmuIDirect3DDevice8_EndStateBlock(DWORD *pToken)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_EndStateBlock\n"
"(\n"
" pToken : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pToken);
}
#endif
ULONG ret = g_pD3DDevice8->EndStateBlock(pToken);
EmuSwapFS(); // XBox FS
return ret;
}
2003-06-13 00:37:41 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_CopyRects
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_CopyRects
2003-06-13 00:37:41 +00:00
(
X_D3DSurface *pSourceSurface,
CONST RECT *pSourceRectsArray,
UINT cRects,
X_D3DSurface *pDestinationSurface,
CONST POINT *pDestPointsArray
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_CopyRects\n"
"(\n"
" pSourceSurface : 0x%.08X\n"
" pSourceRectsArray : 0x%.08X\n"
" cRects : 0x%.08X\n"
" pDestinationSurface : 0x%.08X\n"
" pDestPointsArray : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pSourceSurface, pSourceRectsArray, cRects,
pDestinationSurface, pDestPointsArray);
}
#endif
// ******************************************************************
// * Redirect to PC D3D
// ******************************************************************
HRESULT hRet = g_pD3DDevice8->CopyRects
(
pSourceSurface->EmuSurface8,
pSourceRectsArray,
cRects,
pDestinationSurface->EmuSurface8,
pDestPointsArray
);
EmuSwapFS(); // Xbox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateImageSurface
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_CreateImageSurface
2003-06-13 00:37:41 +00:00
(
UINT Width,
UINT Height,
X_D3DFORMAT Format,
X_D3DSurface **ppBackBuffer
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_CreateImageSurface\n"
"(\n"
" Width : 0x%.08X\n"
" Height : 0x%.08X\n"
" Format : 0x%.08X\n"
" ppBackBuffer : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Width, Height, Format, ppBackBuffer);
}
#endif
*ppBackBuffer = new X_D3DSurface();
2003-06-20 16:42:31 +00:00
D3DFORMAT PCFormat = EmuXB2PC_D3DFormat(Format);
2003-06-13 00:37:41 +00:00
2003-06-20 16:42:31 +00:00
HRESULT hRet = g_pD3DDevice8->CreateImageSurface(Width, Height, PCFormat, &((*ppBackBuffer)->EmuSurface8));
2003-06-13 00:37:41 +00:00
EmuSwapFS(); // Xbox FS
return hRet;
}
2003-06-12 17:36:30 +00:00
// ******************************************************************
2003-06-27 06:56:04 +00:00
// * func: EmuIDirect3DDevice8_GetBackBuffer2
2003-06-12 17:36:30 +00:00
// ******************************************************************
2003-07-02 20:14:15 +00:00
XTL::X_D3DSurface* WINAPI XTL::EmuIDirect3DDevice8_GetBackBuffer2
2003-06-12 17:36:30 +00:00
(
2003-06-27 06:56:04 +00:00
INT BackBuffer
2003-06-12 17:36:30 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-06-27 06:56:04 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetBackBuffer2\n"
2003-06-12 17:36:30 +00:00
"(\n"
" BackBuffer : 0x%.08X\n"
");\n",
2003-06-27 06:56:04 +00:00
GetCurrentThreadId(), BackBuffer);
2003-06-12 17:36:30 +00:00
}
#endif
/* Temporarily? removed
X_D3DSurface *pBackBuffer = new X_D3DSurface();
2003-06-12 17:36:30 +00:00
2003-06-26 23:55:09 +00:00
if(BackBuffer == -1)
{
static IDirect3DSurface8 *pCachedPrimarySurface = 0;
if(pCachedPrimarySurface == 0)
{
// create a buffer to return
// TODO: Verify the surface is always 640x480
g_pD3DDevice8->CreateImageSurface(640, 480, D3DFMT_A8R8G8B8, &pBackBuffer->EmuSurface8);
}
else
pBackBuffer->EmuSurface8 = pCachedPrimarySurface;
HRESULT hRet = g_pD3DDevice8->GetFrontBuffer(pBackBuffer->EmuSurface8);
if(FAILED(hRet))
{
printf("*Warning* Could not retrieve primary surface, using backbuffer\n");
pBackBuffer->EmuSurface8->Release();
pBackBuffer->EmuSurface8 = 0;
BackBuffer = 0;
}
2003-06-26 23:55:09 +00:00
// Debug: Save this image temporarily
//D3DXSaveSurfaceToFile("C:\\Aaron\\Textures\\FrontBuffer.bmp", D3DXIFF_BMP, pBackBuffer->EmuSurface8, NULL, NULL);
2003-06-26 23:55:09 +00:00
}
if(BackBuffer != -1)
g_pD3DDevice8->GetBackBuffer(BackBuffer, D3DBACKBUFFER_TYPE_MONO, &(pBackBuffer->EmuSurface8));
*/
X_D3DSurface *pBackBuffer = new X_D3DSurface();
if(BackBuffer == -1)
BackBuffer = 0;
g_pD3DDevice8->GetBackBuffer(BackBuffer, D3DBACKBUFFER_TYPE_MONO, &(pBackBuffer->EmuSurface8));
2003-06-12 17:36:30 +00:00
EmuSwapFS(); // Xbox FS
return pBackBuffer;
2003-06-27 06:56:04 +00:00
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_GetBackBuffer
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_GetBackBuffer
2003-06-27 06:56:04 +00:00
(
INT BackBuffer,
D3DBACKBUFFER_TYPE Type,
X_D3DSurface **ppBackBuffer
)
{
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
EmuSwapFS(); // Win2k/XP FS
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetBackBuffer\n"
"(\n"
" BackBuffer : 0x%.08X\n"
" Type : 0x%.08X\n"
" ppBackBuffer : 0x%.08X\n"
");\n",
GetCurrentThreadId(), BackBuffer, Type, ppBackBuffer);
EmuSwapFS(); // Xbox FS
}
#endif
*ppBackBuffer = EmuIDirect3DDevice8_GetBackBuffer2(BackBuffer);
2003-06-12 17:36:30 +00:00
return;
}
2003-07-06 01:16:03 +00:00
// ******************************************************************
// * func: EmuIDirect3D8_SetViewport
// ******************************************************************
HRESULT WINAPI XTL::EmuIDirect3D8_SetViewport
(
CONST D3DVIEWPORT8 *pViewport
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3D8_SetViewport\n"
"(\n"
" pViewport : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pViewport);
}
#endif
HRESULT hRet = g_pD3DDevice8->SetViewport(pViewport);
EmuSwapFS(); // Xbox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetShaderConstantMode
// ******************************************************************
HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetShaderConstantMode
(
DWORD dwMode // TODO: Fill out enumeration
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetShaderConstantMode\n"
"(\n"
" dwMode : 0x%.08X\n"
");\n",
GetCurrentThreadId(), dwMode);
}
#endif
// TODO: Actually implement this
EmuSwapFS(); // Xbox FS
return S_OK;
}
2003-06-12 02:05:10 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_GetRenderTarget
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_GetRenderTarget
2003-06-12 02:05:10 +00:00
(
X_D3DSurface **ppRenderTarget
)
{
2003-06-12 17:36:30 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-06-12 02:05:10 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetRenderTarget\n"
"(\n"
" ppRenderTarget : 0x%.08X\n"
");\n",
GetCurrentThreadId(), ppRenderTarget);
}
#endif
IDirect3DSurface8 *pSurface8 = g_pCachedRenderTarget->EmuSurface8;
pSurface8->AddRef();
*ppRenderTarget = g_pCachedRenderTarget;
2003-06-12 17:36:30 +00:00
EmuSwapFS(); // Xbox FS
2003-06-12 02:05:10 +00:00
return D3D_OK;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_GetRenderTarget2
// ******************************************************************
2003-07-02 20:14:15 +00:00
XTL::X_D3DSurface * WINAPI XTL::EmuIDirect3DDevice8_GetRenderTarget2()
2003-06-12 02:05:10 +00:00
{
2003-06-12 17:36:30 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-06-12 02:05:10 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetRenderTarget2()\n",
GetCurrentThreadId());
}
#endif
IDirect3DSurface8 *pSurface8 = g_pCachedRenderTarget->EmuSurface8;
pSurface8->AddRef();
2003-06-12 17:36:30 +00:00
EmuSwapFS(); // Xbox FS
2003-06-12 02:05:10 +00:00
return g_pCachedRenderTarget;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_GetDepthStencilSurface
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_GetDepthStencilSurface
2003-06-12 02:05:10 +00:00
(
X_D3DSurface **ppZStencilSurface
)
{
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
EmuSwapFS(); // Win2k/XP FS
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetDepthStencilSurface\n"
"(\n"
" ppZStencilSurface : 0x%.08X\n"
");\n",
GetCurrentThreadId(), ppZStencilSurface);
EmuSwapFS(); // Xbox FS
}
#endif
IDirect3DSurface8 *pSurface8 = g_pCachedZStencilSurface->EmuSurface8;
2003-06-30 16:39:04 +00:00
if(pSurface8 != 0)
pSurface8->AddRef();
2003-06-12 02:05:10 +00:00
*ppZStencilSurface = g_pCachedZStencilSurface;
return D3D_OK;
}
// ******************************************************************
2003-06-17 19:22:09 +00:00
// * func: EmuIDirect3DDevice8_GetDepthStencilSurface2
2003-06-12 02:05:10 +00:00
// ******************************************************************
2003-07-02 20:14:15 +00:00
XTL::X_D3DSurface * WINAPI XTL::EmuIDirect3DDevice8_GetDepthStencilSurface2()
2003-06-12 02:05:10 +00:00
{
2003-06-17 19:22:09 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-06-12 02:05:10 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetDepthStencilSurface2()\n",
GetCurrentThreadId());
}
#endif
IDirect3DSurface8 *pSurface8 = g_pCachedZStencilSurface->EmuSurface8;
2003-06-30 16:39:04 +00:00
if(pSurface8 != 0)
pSurface8->AddRef();
2003-06-12 02:05:10 +00:00
2003-06-17 19:22:09 +00:00
EmuSwapFS(); // Xbox FS
2003-06-12 02:05:10 +00:00
return g_pCachedZStencilSurface;
}
2003-06-17 19:22:09 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_GetTile
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_GetTile
2003-06-17 19:22:09 +00:00
(
DWORD Index,
X_D3DTILE *pTile
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetTile\n"
"(\n"
" Index : 0x%.08X\n"
" pTile : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Index, pTile);
}
#endif
2003-06-18 05:15:02 +00:00
if(pTile != NULL)
memcpy(pTile, &EmuD3DTileCache[Index], sizeof(X_D3DTILE));
2003-06-17 19:22:09 +00:00
EmuSwapFS(); // XBox FS
return D3D_OK;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetTileNoWait
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetTileNoWait
2003-06-17 19:22:09 +00:00
(
DWORD Index,
CONST X_D3DTILE *pTile
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetTileNoWait\n"
"(\n"
" Index : 0x%.08X\n"
" pTile : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Index, pTile);
}
#endif
2003-06-18 05:15:02 +00:00
if(pTile != NULL)
memcpy(&EmuD3DTileCache[Index], pTile, sizeof(X_D3DTILE));
2003-06-17 19:22:09 +00:00
EmuSwapFS(); // XBox FS
return D3D_OK;
}
2003-06-09 03:44:07 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateVertexShader
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_CreateVertexShader
2003-06-09 03:44:07 +00:00
(
CONST DWORD *pDeclaration,
CONST DWORD *pFunction,
DWORD *pHandle,
DWORD Usage
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_CreateVertexShader\n"
"(\n"
" pDeclaration : 0x%.08X\n"
" pFunction : 0x%.08X\n"
" pHandle : 0x%.08X\n"
" Usage : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pDeclaration, pFunction, pHandle, Usage);
}
#endif
2003-06-24 00:06:09 +00:00
// ******************************************************************
// * create emulated shader struct
// ******************************************************************
X_D3DVertexShader *pD3DVertexShader = new X_D3DVertexShader();
// Todo: Intelligently fill out these fields as necessary
ZeroMemory(pD3DVertexShader, sizeof(X_D3DVertexShader));
2003-06-09 03:44:07 +00:00
// ******************************************************************
// * redirect to windows d3d
// ******************************************************************
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->CreateVertexShader
2003-06-09 03:44:07 +00:00
(
pDeclaration,
pFunction,
2003-06-24 00:06:09 +00:00
&pD3DVertexShader->Handle,
g_dwVertexShaderUsage // TODO: HACK: Xbox has extensions!
2003-06-09 03:44:07 +00:00
);
2003-06-24 00:06:09 +00:00
*pHandle = (DWORD)pD3DVertexShader;
2003-06-17 19:22:09 +00:00
if(FAILED(hRet))
{
printf("*Warning* we're lying about the creation of a vertex shader!\n");
2003-06-17 19:22:09 +00:00
hRet = D3D_OK;
}
2003-06-09 03:44:07 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetVertexShaderConstant
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetVertexShaderConstant
2003-06-09 03:44:07 +00:00
(
INT Register,
CONST PVOID pConstantData,
DWORD ConstantCount
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetVertexShaderConstant\n"
"(\n"
" Register : 0x%.08X\n"
" pConstantData : 0x%.08X\n"
" ConstantCount : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Register, pConstantData, ConstantCount);
}
#endif
// ******************************************************************
// * redirect to windows d3d
// ******************************************************************
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->SetVertexShaderConstant
2003-06-09 03:44:07 +00:00
(
Register,
pConstantData,
ConstantCount
);
if(FAILED(hRet))
{
printf("*Warning* we're lying about setting a vertex shader constant!\n");
hRet = D3D_OK;
}
2003-06-09 03:44:07 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreatePixelShader
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_CreatePixelShader
2003-06-09 03:44:07 +00:00
(
CONST DWORD *pFunction,
DWORD *pHandle
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_CreatePixelShader\n"
"(\n"
" pFunction : 0x%.08X\n"
" pHandle : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pFunction, pHandle);
}
#endif
// ******************************************************************
// * redirect to windows d3d
// ******************************************************************
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->CreatePixelShader
2003-06-09 03:44:07 +00:00
(
pFunction,
pHandle
);
if(FAILED(hRet))
{
printf("*Warning* we're lying about the creation of a pixel shader!\n");
hRet = D3D_OK;
}
2003-06-09 03:44:07 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetPixelShader
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetPixelShader
(
DWORD Handle
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetPixelShader\n"
"(\n"
" Handle : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Handle);
}
#endif
// ******************************************************************
// * redirect to windows d3d
// ******************************************************************
HRESULT hRet = g_pD3DDevice8->SetPixelShader
(
Handle
);
if(FAILED(hRet))
{
printf("*Warning* we're lying about setting a pixel shader!\n");
hRet = D3D_OK;
}
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-10 03:00:19 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateTexture2
// ******************************************************************
2003-07-02 20:14:15 +00:00
XTL::X_D3DResource * WINAPI XTL::EmuIDirect3DDevice8_CreateTexture2
2003-06-10 03:00:19 +00:00
(
UINT Width,
UINT Height,
UINT Depth,
UINT Levels,
DWORD Usage,
D3DFORMAT Format,
D3DRESOURCETYPE D3DResource
)
{
2003-06-10 22:32:31 +00:00
X_D3DResource *pTexture;
2003-06-10 03:00:19 +00:00
EmuIDirect3DDevice8_CreateTexture(Width, Height, Levels, Usage, Format, D3DPOOL_MANAGED, &pTexture);
return pTexture;
}
2003-06-05 00:03:28 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateTexture
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_CreateTexture
2003-06-05 00:03:28 +00:00
(
2003-06-10 22:32:31 +00:00
UINT Width,
UINT Height,
UINT Levels,
DWORD Usage,
D3DFORMAT Format,
D3DPOOL Pool,
X_D3DResource **ppTexture
2003-06-05 00:03:28 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_CreateTexture\n"
"(\n"
" Width : 0x%.08X\n"
" Height : 0x%.08X\n"
" Levels : 0x%.08X\n"
" Usage : 0x%.08X\n"
" Format : 0x%.08X\n"
" Pool : 0x%.08X\n"
" ppTexture : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Width, Height, Levels, Usage, Format, Pool, ppTexture);
}
#endif
2003-06-05 03:09:52 +00:00
// Convert Format (Xbox->PC)
D3DFORMAT PCFormat = EmuXB2PC_D3DFormat(Format);
2003-06-05 00:03:28 +00:00
2003-06-24 00:06:09 +00:00
// TODO: HACK: Devices that don't support this should somehow emulate it!
if(PCFormat == D3DFMT_D16)
{
2003-06-24 01:07:48 +00:00
printf("*Warning* D3DFMT_16 is an unsupported texture format!\n");
2003-06-24 00:06:09 +00:00
PCFormat = D3DFMT_X8R8G8B8;
}
else if(PCFormat == D3DFMT_P8)
{
printf("*Warning* D3DFMT_P8 is an unsupported texture format!\n");
PCFormat = D3DFMT_X8R8G8B8;
}
2003-07-06 01:16:03 +00:00
else if(PCFormat == D3DFMT_D24S8)
{
printf("*Warning* D3DFMT_D24S8 is an unsupported texture format!\n");
PCFormat = D3DFMT_X8R8G8B8;
}
2003-06-24 00:06:09 +00:00
2003-06-10 22:32:31 +00:00
*ppTexture = new X_D3DResource();
2003-06-05 00:03:28 +00:00
// ******************************************************************
// * redirect to windows d3d
// ******************************************************************
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->CreateTexture
2003-06-05 00:03:28 +00:00
(
Width, Height, Levels,
2003-06-24 01:07:48 +00:00
0, // TODO: Xbox Allows a border to be drawn (maybe hack this in software ;[)
PCFormat, D3DPOOL_MANAGED, &((*ppTexture)->EmuTexture8)
2003-06-05 00:03:28 +00:00
);
2003-06-24 00:06:09 +00:00
if(FAILED(hRet))
2003-06-24 01:07:48 +00:00
printf("*Warning* CreateTexture FAILED\n");
2003-06-28 08:16:08 +00:00
2003-06-05 00:03:28 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-18 08:00:50 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetIndices
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetIndices
2003-06-18 08:00:50 +00:00
(
X_D3DIndexBuffer *pIndexData,
UINT BaseVertexIndex
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetIndices\n"
"(\n"
" pIndexData : 0x%.08X\n"
" BaseVertexIndex : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pIndexData, BaseVertexIndex);
}
#endif
EmuVerifyResourceIsRegistered(pIndexData);
2003-06-18 08:00:50 +00:00
IDirect3DIndexBuffer8 *pIndexBuffer = pIndexData->EmuIndexBuffer8;
2003-06-18 08:00:50 +00:00
g_pD3DDevice8->SetIndices(pIndexBuffer, BaseVertexIndex);
EmuSwapFS(); // XBox FS
return;
}
2003-06-05 06:53:14 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetTexture
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetTexture
2003-06-05 06:53:14 +00:00
(
2003-06-10 22:32:31 +00:00
DWORD Stage,
X_D3DResource *pTexture
2003-06-05 06:53:14 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetTexture\n"
"(\n"
" Stage : 0x%.08X\n"
" pTexture : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Stage, pTexture);
}
#endif
IDirect3DBaseTexture8 *pBaseTexture8 = NULL;
2003-06-18 05:15:02 +00:00
if(pTexture != NULL)
{
EmuVerifyResourceIsRegistered(pTexture);
pBaseTexture8 = pTexture->EmuBaseTexture8;
}
2003-06-05 06:53:14 +00:00
HRESULT hRet = g_pD3DDevice8->SetTexture(Stage, pBaseTexture8);
2003-06-05 06:53:14 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-13 19:21:10 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SwitchTexture
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID __fastcall XTL::EmuIDirect3DDevice8_SwitchTexture
2003-06-13 19:21:10 +00:00
(
DWORD Method,
DWORD Data,
DWORD Format
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SwitchTexture\n"
"(\n"
" Method : 0x%.08X\n"
" Data : 0x%.08X\n"
" Format : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Method, Data, Format);
}
#endif
EmuCleanup("EmuIDirect3DDevice8_SwitchTexture is not implemented!");
/***
IDirect3DBaseTexture8 *pBaseTexture8 = pTexture->EmuBaseTexture8;
IDirect3DBaseTexture8 *pPrevTexture8 = NULL;
// Xbox SwitchTexture does not decrement the reference count on the
// old texture, but SetTexture does, so we need to pre-increment
g_pD3DDevice8->GetTexture(Stage, &pPrevTexture8);
HRESULT hRet = g_pD3DDevice8->SetTexture(Stage, pBaseTexture8);
// Xbox SwitchTexture does not increment reference count, but the
// above SetTexture does, so we need to remove it.
pBaseTexture8->Release();
***/
EmuSwapFS(); // XBox FS
return;
}
2003-06-04 02:18:40 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_GetDisplayMode
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_GetDisplayMode
2003-06-04 02:18:40 +00:00
(
X_D3DDISPLAYMODE *pMode
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetDisplayMode\n"
"(\n"
" pMode : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pMode);
}
#endif
HRESULT hRet;
// ******************************************************************
// * make adjustments to parameters to make sense with windows d3d
// ******************************************************************
{
D3DDISPLAYMODE *pPCMode = (D3DDISPLAYMODE*)pMode;
2003-06-10 22:32:31 +00:00
hRet = g_pD3DDevice8->GetDisplayMode(pPCMode);
2003-06-04 02:18:40 +00:00
2003-06-05 03:09:52 +00:00
// Convert Format (PC->Xbox)
pMode->Format = EmuPC2XB_D3DFormat(pPCMode->Format);
2003-06-04 02:18:40 +00:00
// TODO: Make this configurable in the future?
2003-06-05 03:09:52 +00:00
pMode->Flags = 0x000000A1; // D3DPRESENTFLAG_FIELD | D3DPRESENTFLAG_INTERLACED | D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
2003-06-04 02:18:40 +00:00
}
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // XBox FS
2003-02-19 20:53:33 +00:00
2003-05-03 08:29:37 +00:00
return hRet;
2003-02-19 20:53:33 +00:00
}
// ******************************************************************
2003-03-27 06:23:58 +00:00
// * func: EmuIDirect3DDevice8_Clear
2003-02-19 20:53:33 +00:00
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_Clear
2003-02-19 20:53:33 +00:00
(
DWORD Count,
CONST D3DRECT *pRects,
DWORD Flags,
D3DCOLOR Color,
float Z,
DWORD Stencil
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-19 20:53:33 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_Clear\n"
2003-02-19 20:53:33 +00:00
"(\n"
" Count : 0x%.08X\n"
" pRects : 0x%.08X\n"
" Flags : 0x%.08X\n"
" Color : 0x%.08X\n"
2003-07-06 01:16:03 +00:00
" Z : %f\n"
2003-02-19 20:53:33 +00:00
" Stencil : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Count, pRects, Flags,
Color, Z, Stencil);
}
#endif
2003-05-28 07:21:41 +00:00
2003-02-19 20:53:33 +00:00
// ******************************************************************
// * make adjustments to parameters to make sense with windows d3d
// ******************************************************************
{
2003-02-21 20:33:21 +00:00
// TODO: D3DCLEAR_TARGET_A, *R, *G, *B don't exist on windows
2003-02-22 07:49:02 +00:00
DWORD newFlags = 0;
2003-02-20 08:07:52 +00:00
2003-07-08 18:58:04 +00:00
if(Flags & 0x000000f0)
2003-02-22 07:49:02 +00:00
newFlags |= D3DCLEAR_TARGET;
2003-02-20 08:07:52 +00:00
2003-07-08 18:58:04 +00:00
if(Flags & 0x00000001)
2003-02-22 07:49:02 +00:00
newFlags |= D3DCLEAR_ZBUFFER;
2003-02-20 08:07:52 +00:00
2003-07-08 18:58:04 +00:00
if(Flags & 0x00000002)
2003-02-22 07:49:02 +00:00
newFlags |= D3DCLEAR_STENCIL;
2003-02-20 08:07:52 +00:00
2003-02-22 07:49:02 +00:00
Flags = newFlags;
2003-02-19 20:53:33 +00:00
}
2003-06-10 22:32:31 +00:00
HRESULT ret = g_pD3DDevice8->Clear(Count, pRects, Flags, Color, Z, Stencil);
2003-02-19 20:53:33 +00:00
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // XBox FS
2003-02-19 20:53:33 +00:00
return ret;
}
2003-02-21 00:07:28 +00:00
2003-05-05 06:35:37 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_Present
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_Present
2003-05-05 06:35:37 +00:00
(
CONST RECT* pSourceRect,
CONST RECT* pDestRect,
PVOID pDummy1,
PVOID pDummy2
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_Present\n"
2003-05-05 06:35:37 +00:00
"(\n"
" pSourceRect : 0x%.08X\n"
" pDestRect : 0x%.08X\n"
" pDummy1 : 0x%.08X\n"
" pDummy2 : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pSourceRect, pDestRect, pDummy1, pDummy2);
}
#endif
HRESULT hRet = g_pD3DDevice8->Present(pSourceRect, pDestRect, (HWND)pDummy1, (CONST RGNDATA*)pDummy2);
2003-05-05 06:35:37 +00:00
EmuSwapFS(); // XBox FS
return hRet;
2003-05-05 06:35:37 +00:00
}
2003-02-21 00:07:28 +00:00
// ******************************************************************
2003-03-27 06:23:58 +00:00
// * func: EmuIDirect3DDevice8_Swap
2003-02-21 00:07:28 +00:00
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_Swap
2003-02-21 00:07:28 +00:00
(
DWORD Flags
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-21 00:07:28 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_Swap\n"
2003-02-21 00:07:28 +00:00
"(\n"
" Flags : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Flags);
}
#endif
// TODO: Ensure this flag is always the same across library versions
if(Flags != 0)
2003-07-02 20:14:15 +00:00
EmuCleanup("XTL::EmuIDirect3DDevice8_Swap: Flags != 0");
2003-02-21 00:07:28 +00:00
HRESULT hRet = g_pD3DDevice8->Present(0, 0, 0, 0);
2003-02-21 00:07:28 +00:00
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // XBox FS
2003-02-21 00:07:28 +00:00
return hRet;
2003-06-18 05:15:02 +00:00
}
2003-06-10 22:32:31 +00:00
// ******************************************************************
// * func: EmuIDirect3DResource8_Register
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DResource8_Register
2003-06-10 22:32:31 +00:00
(
X_D3DResource *pThis,
PVOID pBase
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DResource8_Register\n"
"(\n"
" pThis : 0x%.08X\n"
" pBase : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pThis, pBase);
}
#endif
HRESULT hRet;
X_D3DResource *pResource = (X_D3DResource*)pThis;
2003-06-24 00:06:09 +00:00
DWORD dwCommonType = pResource->Common & X_D3DCOMMON_TYPE_MASK;
2003-06-10 22:32:31 +00:00
// ******************************************************************
// * Determine the resource type, and initialize
// ******************************************************************
2003-06-24 00:06:09 +00:00
switch(dwCommonType)
2003-06-10 22:32:31 +00:00
{
2003-06-16 22:06:01 +00:00
case X_D3DCOMMON_TYPE_VERTEXBUFFER:
{
2003-06-19 05:37:16 +00:00
#ifdef _DEBUG_TRACE
printf("EmuIDirect3DResource8_Register :-> VertexBuffer...\n");
2003-06-19 05:37:16 +00:00
#endif
2003-06-18 05:15:02 +00:00
X_D3DVertexBuffer *pVertexBuffer = (X_D3DVertexBuffer*)pResource;
// ******************************************************************
// * Create the vertex buffer
// ******************************************************************
{
DWORD dwSize = EmuCheckAllocationSize(pBase);
hRet = g_pD3DDevice8->CreateVertexBuffer
2003-06-18 05:15:02 +00:00
(
dwSize, 0, 0, D3DPOOL_MANAGED,
&pResource->EmuVertexBuffer8
);
BYTE *pData = 0;
hRet = pResource->EmuVertexBuffer8->Lock(0, 0, &pData, 0);
if(FAILED(hRet))
EmuCleanup("VertexBuffer Lock failed");
memcpy(pData, (void*)pBase, dwSize);
pResource->EmuVertexBuffer8->Unlock();
pResource->Data = (ULONG)pData;
}
2003-06-16 22:06:01 +00:00
}
break;
2003-06-18 08:00:50 +00:00
case X_D3DCOMMON_TYPE_INDEXBUFFER:
{
2003-06-19 05:37:16 +00:00
#ifdef _DEBUG_TRACE
printf("EmuIDirect3DResource8_Register :-> IndexBuffer...\n");
2003-06-19 05:37:16 +00:00
#endif
2003-06-18 08:00:50 +00:00
X_D3DIndexBuffer *pIndexBuffer = (X_D3DIndexBuffer*)pResource;
// ******************************************************************
// * Create the index buffer
// ******************************************************************
{
DWORD dwSize = EmuCheckAllocationSize(pBase);
HRESULT hRet = g_pD3DDevice8->CreateIndexBuffer
(
dwSize, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED,
&pIndexBuffer->EmuIndexBuffer8
);
BYTE *pData = 0;
hRet = pResource->EmuIndexBuffer8->Lock(0, 0, &pData, 0);
if(FAILED(hRet))
EmuCleanup("IndexBuffer Lock failed");
memcpy(pData, (void*)pBase, dwSize);
pResource->EmuIndexBuffer8->Unlock();
pResource->Data = (ULONG)pData;
}
}
break;
2003-07-06 01:16:03 +00:00
case X_D3DCOMMON_TYPE_PUSHBUFFER:
{
printf("*Warning: X_D3DCOMMON_TYPE_PUSHBUFFER is not yet implemented");
X_D3DPushBuffer *pPushBuffer = (X_D3DPushBuffer*)pResource;
}
break;
2003-06-24 00:06:09 +00:00
case X_D3DCOMMON_TYPE_SURFACE:
2003-06-10 22:32:31 +00:00
case X_D3DCOMMON_TYPE_TEXTURE:
{
2003-06-26 00:43:21 +00:00
// TODO: Find out why this only seems to be safe with textures (for now)
pBase = (PVOID)((DWORD)pBase + (DWORD)pThis->Data);
2003-06-19 05:37:16 +00:00
#ifdef _DEBUG_TRACE
if(dwCommonType == X_D3DCOMMON_TYPE_SURFACE)
printf("EmuIDirect3DResource8_Register :-> Surface...\n");
else
printf("EmuIDirect3DResource8_Register :-> Texture...\n");
2003-06-19 05:37:16 +00:00
#endif
2003-06-10 22:32:31 +00:00
X_D3DPixelContainer *pPixelContainer = (X_D3DPixelContainer*)pResource;
2003-06-19 05:37:16 +00:00
X_D3DFORMAT X_Format = (X_D3DFORMAT)((pPixelContainer->Format & X_D3DFORMAT_FORMAT_MASK) >> X_D3DFORMAT_FORMAT_SHIFT);
D3DFORMAT Format = EmuXB2PC_D3DFormat(X_Format);
// TODO: HACK: Temporary?
if(X_Format == 0x2E)
{
X_Format = 0x12;
Format = D3DFMT_A8R8G8B8;
}
DWORD dwWidth, dwHeight, dwBPP, dwDepth = 1, dwPitch = 0, dwMipMapLevels = 1;
BOOL bSwizzled = FALSE, bCompressed = FALSE, dwCompressedSize = 0;
2003-06-26 23:55:09 +00:00
BOOL bCubemap = pPixelContainer->Format & X_D3DFORMAT_CUBEMAP;
if(bCubemap)
EmuCleanup("Cubemaps are temporarily unsupported");
2003-06-10 22:32:31 +00:00
// ******************************************************************
2003-06-19 05:37:16 +00:00
// * Interpret Width/Height/BPP
2003-06-10 22:32:31 +00:00
// ******************************************************************
2003-06-19 05:37:16 +00:00
if(X_Format == 0x07 /* X_D3DFMT_X8R8G8B8 */ || X_Format == 0x06 /* X_D3DFMT_A8R8G8B8 */)
2003-06-10 22:32:31 +00:00
{
2003-06-19 05:37:16 +00:00
bSwizzled = TRUE;
2003-06-10 22:32:31 +00:00
2003-06-19 05:37:16 +00:00
// Swizzled 32 Bit
dwWidth = 1 << ((pPixelContainer->Format & X_D3DFORMAT_USIZE_MASK) >> X_D3DFORMAT_USIZE_SHIFT);
dwHeight = 1 << ((pPixelContainer->Format & X_D3DFORMAT_VSIZE_MASK) >> X_D3DFORMAT_VSIZE_SHIFT);
2003-06-25 23:55:50 +00:00
dwDepth = 1 << ((pPixelContainer->Format & X_D3DFORMAT_PSIZE_MASK) >> X_D3DFORMAT_PSIZE_SHIFT);
dwPitch = dwWidth*4;
2003-06-19 05:37:16 +00:00
dwBPP = 4;
2003-06-10 22:32:31 +00:00
}
else if(X_Format == 0x05 /* X_D3DFMT_R5G6B5 */ || X_Format == 0x04 /* X_D3DFMT_A4R4G4B4 */)
2003-06-19 05:37:16 +00:00
{
bSwizzled = TRUE;
2003-06-10 22:32:31 +00:00
2003-06-19 05:37:16 +00:00
// Swizzled 16 Bit
dwWidth = 1 << ((pPixelContainer->Format & X_D3DFORMAT_USIZE_MASK) >> X_D3DFORMAT_USIZE_SHIFT);
dwHeight = 1 << ((pPixelContainer->Format & X_D3DFORMAT_VSIZE_MASK) >> X_D3DFORMAT_VSIZE_SHIFT);
2003-06-25 23:55:50 +00:00
dwDepth = 1 << ((pPixelContainer->Format & X_D3DFORMAT_PSIZE_MASK) >> X_D3DFORMAT_PSIZE_SHIFT);
dwPitch = dwWidth*2;
2003-06-19 05:37:16 +00:00
dwBPP = 2;
}
else if(X_Format == 0x12 /* X_D3DFORMAT_A8R8G8B8 */ || X_Format == 0x2E /* D3DFMT_LIN_D24S8 */)
2003-06-19 05:37:16 +00:00
{
// Linear 32 Bit
2003-06-25 23:55:50 +00:00
dwWidth = (pPixelContainer->Size & X_D3DSIZE_WIDTH_MASK) + 1;
dwHeight = ((pPixelContainer->Size & X_D3DSIZE_HEIGHT_MASK) >> X_D3DSIZE_HEIGHT_SHIFT) + 1;
2003-06-26 23:55:09 +00:00
dwPitch = (((pPixelContainer->Size & X_D3DSIZE_PITCH_MASK) >> X_D3DSIZE_PITCH_SHIFT)+1)*64;
2003-06-19 05:37:16 +00:00
dwBPP = 4;
}
2003-06-25 23:55:50 +00:00
else if(X_Format == 0x11 /* D3DFMT_LIN_R5G6B5 */)
{
// Linear 16 Bit
dwWidth = (pPixelContainer->Size & X_D3DSIZE_WIDTH_MASK) + 1;
dwHeight = ((pPixelContainer->Size & X_D3DSIZE_HEIGHT_MASK) >> X_D3DSIZE_HEIGHT_SHIFT) + 1;
2003-06-26 23:55:09 +00:00
dwPitch = (((pPixelContainer->Size & X_D3DSIZE_PITCH_MASK) >> X_D3DSIZE_PITCH_SHIFT)+1)*64;
2003-06-25 23:55:50 +00:00
dwBPP = 2;
}
else if(X_Format == 0x0C /* D3DFMT_DXT1 */ || X_Format == 0x0E /* D3DFMT_DXT2 */ || X_Format == 0x0F /* D3DFMT_DXT3 */)
{
bCompressed = TRUE;
// Compressed
dwWidth = 1 << ((pPixelContainer->Format & X_D3DFORMAT_USIZE_MASK) >> X_D3DFORMAT_USIZE_SHIFT);
dwHeight = 1 << ((pPixelContainer->Format & X_D3DFORMAT_VSIZE_MASK) >> X_D3DFORMAT_VSIZE_SHIFT);
dwDepth = 1 << ((pPixelContainer->Format & X_D3DFORMAT_PSIZE_MASK) >> X_D3DFORMAT_PSIZE_SHIFT);
// D3DFMT_DXT2->D3DFMT_DXT5 : 128bits per block/per 16 texels
dwCompressedSize = dwWidth*dwHeight;
if(X_Format == 0x0C) // D3DFMT_DXT1 : 64bits per block/per 16 texels
dwCompressedSize /= 2;
2003-06-25 23:55:50 +00:00
dwMipMapLevels = (pPixelContainer->Format & X_D3DFORMAT_MIPMAP_MASK) >> X_D3DFORMAT_MIPMAP_SHIFT;
}
2003-06-10 22:32:31 +00:00
else
{
2003-06-25 23:55:50 +00:00
EmuCleanup("0x%.08X is not a supported format!\n", X_Format);
2003-06-10 22:32:31 +00:00
}
// ******************************************************************
// * Create the happy little texture
// ******************************************************************
2003-06-24 00:06:09 +00:00
if(dwCommonType == X_D3DCOMMON_TYPE_SURFACE)
{
hRet = g_pD3DDevice8->CreateImageSurface(dwWidth, dwHeight, Format, &pResource->EmuSurface8);
2003-06-24 00:06:09 +00:00
}
else
{
hRet = g_pD3DDevice8->CreateTexture
(
2003-06-25 23:55:50 +00:00
dwWidth, dwHeight, dwMipMapLevels, 0, Format,
2003-06-24 00:06:09 +00:00
D3DPOOL_MANAGED, &pResource->EmuTexture8
);
}
2003-06-10 22:32:31 +00:00
D3DLOCKED_RECT LockedRect;
2003-06-10 22:32:31 +00:00
// ******************************************************************
2003-06-19 05:37:16 +00:00
// * Copy over data (deswizzle if necessary)
2003-06-10 22:32:31 +00:00
// ******************************************************************
2003-06-24 00:06:09 +00:00
if(dwCommonType == X_D3DCOMMON_TYPE_SURFACE)
hRet = pResource->EmuSurface8->LockRect(&LockedRect, NULL, 0);
2003-06-24 00:06:09 +00:00
else
2003-06-26 23:55:09 +00:00
hRet = pResource->EmuTexture8->LockRect(0, &LockedRect, NULL, 0);
2003-06-10 22:32:31 +00:00
RECT iRect = {0,0,0,0};
POINT iPoint = {0,0};
2003-06-10 22:32:31 +00:00
if(bSwizzled)
{
2003-07-02 20:14:15 +00:00
XTL::EmuXGUnswizzleRect
(
pBase, dwWidth, dwHeight, dwDepth, LockedRect.pBits,
LockedRect.Pitch, iRect, iPoint, dwBPP
);
}
else if(bCompressed)
{
memcpy(LockedRect.pBits, pBase, dwCompressedSize);
}
else
{
BYTE *pDest = (BYTE*)LockedRect.pBits;
BYTE *pSrc = (BYTE*)pBase;
if((DWORD)LockedRect.Pitch == dwPitch && dwPitch == dwWidth*dwBPP)
memcpy(pDest, pSrc, dwWidth*dwHeight*dwBPP);
2003-06-19 05:37:16 +00:00
else
{
// TODO: Faster copy (maybe unnecessary)
for(DWORD v=0;v<dwHeight;v++)
2003-06-19 05:37:16 +00:00
{
memcpy(pDest, pSrc, dwWidth*dwBPP);
pDest += LockedRect.Pitch;
pSrc += dwPitch;
2003-06-19 05:37:16 +00:00
}
}
}
2003-06-10 22:32:31 +00:00
if(dwCommonType == X_D3DCOMMON_TYPE_SURFACE)
pResource->EmuSurface8->UnlockRect();
else
2003-06-10 22:32:31 +00:00
pResource->EmuTexture8->UnlockRect(0);
2003-06-26 23:55:09 +00:00
// Debug Texture Dumping
/*
if(dwCommonType == X_D3DCOMMON_TYPE_SURFACE)
{
static int dwDumpSurface = 0;
char szBuffer[255];
sprintf(szBuffer, "C:\\Aaron\\Textures\\Surface%.03d.bmp", dwDumpSurface++);
D3DXSaveSurfaceToFile(szBuffer, D3DXIFF_BMP, pResource->EmuSurface8, NULL, NULL);
}
else
2003-06-26 23:55:09 +00:00
{
static int dwDumpTex = 0;
char szBuffer[255];
sprintf(szBuffer, "C:\\Aaron\\Textures\\Texture%.03d.bmp", dwDumpTex++);
D3DXSaveTextureToFile(szBuffer, D3DXIFF_BMP, pResource->EmuTexture8, NULL);
}
2003-07-06 01:16:03 +00:00
//*/
2003-06-10 22:32:31 +00:00
}
break;
default:
2003-06-24 00:06:09 +00:00
EmuCleanup("IDirect3DResource8::Register -> Common Type 0x%.08X not yet supported", dwCommonType);
2003-06-10 22:32:31 +00:00
}
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-05 06:53:14 +00:00
// ******************************************************************
// * func: EmuIDirect3DResource8_Release
// ******************************************************************
2003-07-02 20:14:15 +00:00
ULONG WINAPI XTL::EmuIDirect3DResource8_Release
2003-06-05 06:53:14 +00:00
(
2003-06-10 22:32:31 +00:00
X_D3DResource *pThis
2003-06-05 06:53:14 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DResource8_Release\n"
"(\n"
" pThis : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pThis);
}
#endif
2003-06-10 22:32:31 +00:00
IDirect3DResource8 *pResource8 = pThis->EmuResource8;
ULONG uRet = pResource8->Release();
if(uRet == 0)
{
2003-06-11 02:07:41 +00:00
#ifdef _DEBUG_TRACE
printf("EmuIDirect3DResource8_Release (0x%X): Cleaned up a Resource!\n", GetCurrentThreadId());
#endif
2003-06-10 22:32:31 +00:00
delete pThis;
}
2003-06-05 06:53:14 +00:00
EmuSwapFS(); // XBox FS
2003-06-10 22:32:31 +00:00
return uRet;
2003-06-05 06:53:14 +00:00
}
// ******************************************************************
// * func: EmuIDirect3DResource8_IsBusy
// ******************************************************************
2003-07-02 20:14:15 +00:00
BOOL WINAPI XTL::EmuIDirect3DResource8_IsBusy
(
X_D3DResource *pThis
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DResource8_IsBusy\n"
"(\n"
" pThis : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pThis);
}
#endif
IDirect3DResource8 *pResource8 = pThis->EmuResource8;
// I guess we arent doing anything, just return false..
EmuSwapFS(); // XBox FS
return FALSE;
}
2003-06-24 00:06:09 +00:00
// ******************************************************************
// * func: EmuGet2DSurfaceDesc
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuGet2DSurfaceDesc
2003-06-24 00:06:09 +00:00
(
X_D3DPixelContainer *pPixelContainer,
DWORD dwLevel,
X_D3DSURFACE_DESC *pDesc
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuGet2DSurfaceDesc\n"
"(\n"
" pPixelContainer : 0x%.08X\n"
" dwLevel : 0x%.08X\n"
" pDesc : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pPixelContainer, dwLevel, pDesc);
}
#endif
EmuVerifyResourceIsRegistered(pPixelContainer);
// TODO: HACK: notice that this is only safe to wrap a Texture Get2DSurfaceDesc,
// as it makes an assumption here. If there is some way to determine if this pointer
// is a texture or a surface, it'd be alot better!
IDirect3DTexture8 *pTexture8 = pPixelContainer->EmuTexture8;
D3DSURFACE_DESC SurfaceDesc;
HRESULT hRet = pTexture8->GetLevelDesc(dwLevel, &SurfaceDesc);
// ******************************************************************
// * Rearrange into windows format (remove D3DPool)
// ******************************************************************
{
// Convert Format (PC->Xbox)
pDesc->Format = EmuPC2XB_D3DFormat(SurfaceDesc.Format);
pDesc->Type = SurfaceDesc.Type;
if(pDesc->Type > 7)
EmuCleanup("EmuIDirect3DSurface8_GetDesc: pDesc->Type > 7");
pDesc->Usage = SurfaceDesc.Usage;
pDesc->Size = SurfaceDesc.Size;
// TODO: Convert from Xbox to PC!!
if(SurfaceDesc.MultiSampleType == D3DMULTISAMPLE_NONE)
2003-07-02 20:14:15 +00:00
pDesc->MultiSampleType = (XTL::D3DMULTISAMPLE_TYPE)0x0011;
2003-06-24 00:06:09 +00:00
else
EmuCleanup("EmuGet2DSurfaceDesc Unknown Multisample format! (%d)", SurfaceDesc.MultiSampleType);
pDesc->Width = SurfaceDesc.Width;
pDesc->Height = SurfaceDesc.Height;
}
EmuSwapFS(); // XBox FS
return;
}
2003-06-05 00:03:28 +00:00
// ******************************************************************
// * func: EmuIDirect3DSurface8_GetDesc
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DSurface8_GetDesc
2003-06-05 00:03:28 +00:00
(
2003-06-10 22:32:31 +00:00
X_D3DResource *pThis,
2003-06-05 00:03:28 +00:00
X_D3DSURFACE_DESC *pDesc
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DSurface8_GetDesc\n"
"(\n"
" pThis : 0x%.08X\n"
" pDesc : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pThis, pDesc);
}
#endif
EmuVerifyResourceIsRegistered(pThis);
2003-06-05 06:53:14 +00:00
2003-06-10 22:32:31 +00:00
IDirect3DSurface8 *pSurface8 = pThis->EmuSurface8;
D3DSURFACE_DESC SurfaceDesc;
2003-06-10 22:32:31 +00:00
HRESULT hRet = pSurface8->GetDesc(&SurfaceDesc);
2003-06-05 00:03:28 +00:00
// ******************************************************************
// * Rearrange into windows format (remove D3DPool)
// ******************************************************************
{
2003-06-05 03:09:52 +00:00
// Convert Format (PC->Xbox)
2003-06-05 06:53:14 +00:00
pDesc->Format = EmuPC2XB_D3DFormat(SurfaceDesc.Format);
pDesc->Type = SurfaceDesc.Type;
2003-06-05 00:03:28 +00:00
2003-06-05 03:09:52 +00:00
if(pDesc->Type > 7)
EmuCleanup("EmuIDirect3DSurface8_GetDesc: pDesc->Type > 7");
2003-06-05 06:53:14 +00:00
pDesc->Usage = SurfaceDesc.Usage;
pDesc->Size = SurfaceDesc.Size;
2003-06-05 00:03:28 +00:00
// TODO: Convert from Xbox to PC!!
2003-06-05 06:53:14 +00:00
if(SurfaceDesc.MultiSampleType == D3DMULTISAMPLE_NONE)
2003-07-02 20:14:15 +00:00
pDesc->MultiSampleType = (XTL::D3DMULTISAMPLE_TYPE)0x0011;
2003-06-05 00:03:28 +00:00
else
2003-06-10 08:18:43 +00:00
EmuCleanup("EmuIDirect3DSurface8_GetDesc Unknown Multisample format! (%d)", SurfaceDesc.MultiSampleType);
2003-06-05 00:03:28 +00:00
2003-06-05 06:53:14 +00:00
pDesc->Width = SurfaceDesc.Width;
pDesc->Height = SurfaceDesc.Height;
2003-06-05 00:03:28 +00:00
}
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-05 03:09:52 +00:00
// ******************************************************************
// * func: EmuIDirect3DSurface8_LockRect
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DSurface8_LockRect
2003-06-05 03:09:52 +00:00
(
2003-06-10 22:32:31 +00:00
X_D3DResource *pThis,
2003-06-05 03:09:52 +00:00
D3DLOCKED_RECT *pLockedRect,
CONST RECT *pRect,
DWORD Flags
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DSurface8_LockRect\n"
"(\n"
" pThis : 0x%.08X\n"
" pLockedRect : 0x%.08X\n"
" pRect : 0x%.08X\n"
" Flags : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pThis, pLockedRect, pRect, Flags);
2003-07-08 01:37:46 +00:00
}
2003-06-05 03:09:52 +00:00
#endif
2003-07-08 01:37:46 +00:00
if(Flags & 0x40)
printf("*Warning* D3DLOCK_TILED ignored!\n");
EmuVerifyResourceIsRegistered(pThis);
2003-06-10 22:32:31 +00:00
IDirect3DSurface8 *pSurface8 = pThis->EmuSurface8;
2003-06-05 06:53:14 +00:00
DWORD NewFlags = 0;
if(Flags & 0x80)
NewFlags |= D3DLOCK_READONLY;
if(Flags & !(0x80 | 0x40))
2003-06-10 08:18:43 +00:00
EmuCleanup("EmuIDirect3DSurface8_LockRect: Unknown Flags! (0x%.08X)", Flags);
2003-06-05 06:53:14 +00:00
// Remove old lock(s)
2003-06-10 22:32:31 +00:00
pSurface8->UnlockRect();
2003-06-05 23:42:45 +00:00
2003-06-10 22:32:31 +00:00
HRESULT hRet = pSurface8->LockRect(pLockedRect, pRect, NewFlags);
2003-06-05 06:53:14 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DBaseTexture8_GetLevelCount
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DBaseTexture8_GetLevelCount
2003-06-05 06:53:14 +00:00
(
2003-06-10 22:32:31 +00:00
X_D3DBaseTexture *pThis
2003-06-05 06:53:14 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
2003-06-05 03:09:52 +00:00
{
2003-06-05 06:53:14 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DBaseTexture8_GetLevelCount\n"
"(\n"
" pThis : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pThis);
2003-06-05 03:09:52 +00:00
}
2003-06-05 06:53:14 +00:00
#endif
2003-06-05 03:09:52 +00:00
EmuVerifyResourceIsRegistered(pThis);
2003-06-10 22:32:31 +00:00
IDirect3DBaseTexture8 *pBaseTexture8 = pThis->EmuBaseTexture8;
HRESULT hRet = pBaseTexture8->GetLevelCount();
2003-06-05 03:09:52 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-10 03:00:19 +00:00
// ******************************************************************
2003-06-10 22:32:31 +00:00
// * func: EmuIDirect3DTexture8_GetSurfaceLevel2
2003-06-10 03:00:19 +00:00
// ******************************************************************
2003-07-02 20:14:15 +00:00
XTL::X_D3DResource * WINAPI XTL::EmuIDirect3DTexture8_GetSurfaceLevel2
2003-06-10 03:00:19 +00:00
(
2003-06-10 22:32:31 +00:00
X_D3DTexture *pThis,
UINT Level
2003-06-10 03:00:19 +00:00
)
{
2003-06-10 22:32:31 +00:00
X_D3DSurface *pSurfaceLevel;
2003-06-10 03:00:19 +00:00
EmuIDirect3DTexture8_GetSurfaceLevel(pThis, Level, &pSurfaceLevel);
return pSurfaceLevel;
}
2003-06-24 00:06:09 +00:00
// ******************************************************************
// * func: EmuIDirect3DTexture8_LockRect
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DTexture8_LockRect
2003-06-24 00:06:09 +00:00
(
X_D3DTexture *pThis,
UINT Level,
D3DLOCKED_RECT *pLockedRect,
CONST RECT *pRect,
DWORD Flags
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DTexture8_LockRect\n"
"(\n"
" pThis : 0x%.08X\n"
" Level : 0x%.08X\n"
" pLockedRect : 0x%.08X\n"
" pRect : 0x%.08X\n"
" Flags : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pThis, Level, pLockedRect, pRect, Flags);
}
#endif
EmuVerifyResourceIsRegistered(pThis);
IDirect3DTexture8 *pTexture8 = pThis->EmuTexture8;
DWORD NewFlags = 0;
if(Flags & 0x80)
NewFlags |= D3DLOCK_READONLY;
if(Flags & !(0x80 | 0x40))
EmuCleanup("EmuIDirect3DTexture8_LockRect: Unknown Flags! (0x%.08X)", Flags);
// Remove old lock(s)
pTexture8->UnlockRect(Level);
HRESULT hRet = pTexture8->LockRect(Level, pLockedRect, pRect, NewFlags);
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-05 00:03:28 +00:00
// ******************************************************************
// * func: EmuIDirect3DTexture8_GetSurfaceLevel
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DTexture8_GetSurfaceLevel
2003-06-05 00:03:28 +00:00
(
2003-06-10 22:32:31 +00:00
X_D3DTexture *pThis,
2003-06-05 00:03:28 +00:00
UINT Level,
2003-06-10 22:32:31 +00:00
X_D3DSurface **ppSurfaceLevel
2003-06-05 00:03:28 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DTexture8_GetSurfaceLevel\n"
"(\n"
" pThis : 0x%.08X\n"
" Level : 0x%.08X\n"
" ppSurfaceLevel : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pThis, Level, ppSurfaceLevel);
}
#endif
EmuVerifyResourceIsRegistered(pThis);
2003-06-10 22:32:31 +00:00
IDirect3DTexture8 *pTexture8 = pThis->EmuTexture8;
*ppSurfaceLevel = new X_D3DSurface();
HRESULT hRet = pTexture8->GetSurfaceLevel(Level, &((*ppSurfaceLevel)->EmuSurface8));
2003-06-05 00:03:28 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
2003-05-02 02:42:29 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateVertexBuffer
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_CreateVertexBuffer
2003-05-06 06:40:09 +00:00
(
2003-06-10 22:32:31 +00:00
UINT Length,
DWORD Usage,
DWORD FVF,
D3DPOOL Pool,
X_D3DVertexBuffer **ppVertexBuffer
2003-05-06 06:40:09 +00:00
)
{
*ppVertexBuffer = EmuIDirect3DDevice8_CreateVertexBuffer2(Length);
return D3D_OK;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateVertexBuffer2
// ******************************************************************
2003-07-02 20:14:15 +00:00
XTL::X_D3DVertexBuffer* WINAPI XTL::EmuIDirect3DDevice8_CreateVertexBuffer2
2003-05-02 02:42:29 +00:00
(
UINT Length
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_CreateVertexBuffer2\n"
2003-05-02 02:42:29 +00:00
"(\n"
" Length : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Length);
}
#endif
2003-06-10 22:32:31 +00:00
X_D3DVertexBuffer *pD3DVertexBuffer = new X_D3DVertexBuffer();
2003-05-02 02:42:29 +00:00
IDirect3DVertexBuffer8 *ppVertexBuffer=NULL;
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->CreateVertexBuffer
2003-05-02 02:42:29 +00:00
(
2003-05-23 02:55:39 +00:00
Length,
0,
2003-06-18 05:15:02 +00:00
0,
D3DPOOL_MANAGED,
2003-06-10 22:32:31 +00:00
&pD3DVertexBuffer->EmuVertexBuffer8
2003-05-02 02:42:29 +00:00
);
EmuSwapFS(); // XBox FS
2003-06-10 22:32:31 +00:00
return pD3DVertexBuffer;
2003-05-02 02:42:29 +00:00
}
2003-06-13 00:37:41 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetTextureState_TexCoordIndex
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetTextureState_TexCoordIndex
2003-06-13 00:37:41 +00:00
(
DWORD Stage,
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetTextureState_TexCoordIndex\n"
"(\n"
" Stage : 0x%.08X\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Stage, Value);
}
#endif
if(Value > 0x00030000)
EmuCleanup("EmuIDirect3DDevice8_SetTextureState_TexCoordIndex: Unknown TexCoordIndex Value (0x%.08X)", Value);
g_pD3DDevice8->SetTextureStageState(Stage, D3DTSS_TEXCOORDINDEX, Value);
EmuSwapFS(); // XBox FS
return;
}
2003-05-05 06:35:37 +00:00
// ******************************************************************
2003-06-17 02:23:53 +00:00
// * func: EmuIDirect3DDevice8_SetRenderState_NormalizeNormals
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_NormalizeNormals
2003-06-17 02:23:53 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_NormalizeNormals\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
g_pD3DDevice8->SetRenderState(D3DRS_NORMALIZENORMALS, Value);
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_TextureFactor
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_TextureFactor
2003-06-17 02:23:53 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_TextureFactor\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
g_pD3DDevice8->SetRenderState(D3DRS_TEXTUREFACTOR, Value);
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_ZBias
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_ZBias
2003-06-17 02:23:53 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_ZBias\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
g_pD3DDevice8->SetRenderState(D3DRS_ZBIAS, Value);
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_EdgeAntiAlias
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_EdgeAntiAlias
2003-06-17 02:23:53 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_EdgeAntiAlias\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
// TODO: Analyze performance and compatibility (undefined behavior on PC with triangles or points)
// g_pD3DDevice8->SetRenderState(D3DRS_EDGEANTIALIAS, Value);
2003-06-25 23:55:50 +00:00
// printf("*Warning* SetRenderState_EdgeAntiAlias not implemented!\n");
2003-06-17 02:23:53 +00:00
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_FillMode
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_FillMode
2003-06-17 02:23:53 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_FillMode\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
2003-06-20 18:03:21 +00:00
g_pD3DDevice8->SetRenderState(D3DRS_FILLMODE, EmuXB2PC_D3DFILLMODE(Value));
2003-06-17 02:23:53 +00:00
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_FogColor
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_FogColor
2003-06-17 02:23:53 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_FogColor\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
2003-06-28 08:16:08 +00:00
g_pD3DDevice8->SetRenderState(D3DRS_FOGCOLOR, Value);
2003-06-17 02:23:53 +00:00
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_Dxt1NoiseEnable
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_Dxt1NoiseEnable
2003-06-17 02:23:53 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_Dxt1NoiseEnable\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
printf("*Warning* SetRenderState_Dxt1NoiseEnable not implemented!\n");
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_Simple
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID __fastcall XTL::EmuIDirect3DDevice8_SetRenderState_Simple
2003-06-17 02:23:53 +00:00
(
DWORD Method,
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_Simple\n"
"(\n"
" Method : 0x%.08X\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Method, Value);
}
#endif
2003-06-20 16:42:31 +00:00
int State = -1;
// Todo: make this faster and more elegant
2003-06-28 08:16:08 +00:00
for(int v=0;v<174;v++)
2003-06-20 16:42:31 +00:00
{
if(EmuD3DRenderStateSimpleEncoded[v] == Method)
{
State = v;
break;
}
}
if(State == -1)
printf("*Warning* RenderState_Simple(0x%.08X, 0x%.08X) is unsupported\n", Method, Value);
2003-06-20 16:42:31 +00:00
else
{
2003-06-20 18:03:21 +00:00
switch(State)
{
2003-06-28 08:16:08 +00:00
case D3DRS_COLORWRITEENABLE:
{
DWORD OrigValue = Value;
Value = 0;
if(OrigValue & (1L<<16))
Value |= D3DCOLORWRITEENABLE_RED;
if(OrigValue & (1L<<8))
Value |= D3DCOLORWRITEENABLE_GREEN;
if(OrigValue & (1L<<0))
Value |= D3DCOLORWRITEENABLE_BLUE;
if(OrigValue & (1L<<24))
Value |= D3DCOLORWRITEENABLE_ALPHA;
}
break;
case D3DRS_SHADEMODE:
Value = Value & 0x03;
break;
case D3DRS_BLENDOP:
Value = EmuXB2PC_D3DBLENDOP(Value);
break;
2003-06-20 18:03:21 +00:00
case D3DRS_SRCBLEND:
case D3DRS_DESTBLEND:
Value = EmuXB2PC_D3DBLEND(Value);
break;
2003-06-28 08:16:08 +00:00
case D3DRS_ZFUNC:
2003-06-20 18:03:21 +00:00
case D3DRS_ALPHAFUNC:
Value = EmuXB2PC_D3DCMPFUNC(Value);
break;
};
2003-06-20 16:42:31 +00:00
// Todo: Verify these params as you add support for them!
g_pD3DDevice8->SetRenderState((D3DRENDERSTATETYPE)State, Value);
}
2003-06-17 02:23:53 +00:00
EmuSwapFS(); // XBox FS
return;
}
2003-07-03 05:09:28 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_VertexBlend
// ******************************************************************
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_VertexBlend
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_VertexBlend\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
// ******************************************************************
// * Convert from Xbox D3D to PC D3D enumeration
// ******************************************************************
if(Value <= 1)
Value = Value;
else if(Value == 3)
Value = 2;
else if(Value == 5)
Value = 3;
else
EmuCleanup("Unsupported D3DVERTEXBLENDFLAGS (%d)", Value);
g_pD3DDevice8->SetRenderState(D3DRS_VERTEXBLEND, Value);
EmuSwapFS(); // XBox FS
return;
}
2003-06-17 02:23:53 +00:00
// ******************************************************************
2003-05-05 06:35:37 +00:00
// * func: EmuIDirect3DDevice8_SetRenderState_CullMode
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_CullMode
2003-05-05 06:35:37 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_CullMode\n"
2003-05-05 06:35:37 +00:00
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
// ******************************************************************
// * Convert from Xbox D3D to PC D3D enumeration
// ******************************************************************
// TODO: XDK-Specific Tables? So far they are the same
switch(Value)
{
case 0:
Value = D3DCULL_NONE;
break;
case 0x900:
Value = D3DCULL_CW;
break;
case 0x901:
Value = D3DCULL_CCW;
break;
2003-06-05 03:09:52 +00:00
default:
2003-06-10 08:18:43 +00:00
EmuCleanup("EmuIDirect3DDevice8_SetRenderState_CullMode: Unknown Cullmode (%d)", Value);
2003-05-05 06:35:37 +00:00
}
2003-06-10 22:32:31 +00:00
g_pD3DDevice8->SetRenderState(D3DRS_CULLMODE, Value);
2003-05-05 06:35:37 +00:00
EmuSwapFS(); // XBox FS
return;
}
2003-05-23 02:55:39 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_ZEnable
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_ZEnable
2003-05-23 02:55:39 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_ZEnable\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
2003-06-10 22:32:31 +00:00
g_pD3DDevice8->SetRenderState(D3DRS_ZENABLE, Value);
2003-05-23 02:55:39 +00:00
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_StencilEnable
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_StencilEnable
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_StencilEnable\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
g_pD3DDevice8->SetRenderState(D3DRS_STENCILENABLE, Value);
EmuSwapFS(); // XBox FS
return;
}
2003-06-09 03:44:07 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_MultiSampleAntiAlias
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetRenderState_MultiSampleAntiAlias
2003-06-09 03:44:07 +00:00
(
DWORD Value
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetRenderState_MultiSampleAntiAlias\n"
"(\n"
" Value : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Value);
}
#endif
2003-06-10 22:32:31 +00:00
g_pD3DDevice8->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, Value);
2003-06-09 03:44:07 +00:00
EmuSwapFS(); // XBox FS
return;
}
2003-05-23 02:55:39 +00:00
2003-05-05 06:35:37 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetTransform
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_SetTransform
2003-05-05 06:35:37 +00:00
(
D3DTRANSFORMSTATETYPE State,
CONST D3DMATRIX *pMatrix
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetTransform\n"
2003-05-05 06:35:37 +00:00
"(\n"
" State : 0x%.08X\n"
" pMatrix : 0x%.08X\n"
");\n",
GetCurrentThreadId(), State, pMatrix);
}
#endif
2003-06-18 05:15:02 +00:00
State = EmuXB2PC_D3DTS(State);
g_pD3DDevice8->SetTransform(State, pMatrix);
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_GetTransform
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_GetTransform
2003-06-18 05:15:02 +00:00
(
D3DTRANSFORMSTATETYPE State,
D3DMATRIX *pMatrix
)
{
EmuSwapFS(); // Win2k/XP FS
2003-05-05 06:35:37 +00:00
// ******************************************************************
2003-06-18 05:15:02 +00:00
// * debug trace
2003-05-05 06:35:37 +00:00
// ******************************************************************
2003-06-18 05:15:02 +00:00
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetTransform\n"
"(\n"
" State : 0x%.08X\n"
" pMatrix : 0x%.08X\n"
");\n",
GetCurrentThreadId(), State, pMatrix);
}
#endif
2003-05-05 06:35:37 +00:00
2003-06-18 05:15:02 +00:00
State = EmuXB2PC_D3DTS(State);
g_pD3DDevice8->GetTransform(State, pMatrix);
2003-05-05 06:35:37 +00:00
EmuSwapFS(); // XBox FS
return;
}
2003-05-02 02:42:29 +00:00
// ******************************************************************
// * func: EmuIDirect3DVertexBuffer8_Lock
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DVertexBuffer8_Lock
2003-05-02 02:42:29 +00:00
(
2003-06-10 22:32:31 +00:00
X_D3DVertexBuffer *ppVertexBuffer,
UINT OffsetToLock,
UINT SizeToLock,
BYTE **ppbData,
DWORD Flags
2003-05-02 02:42:29 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DVertexBuffer8_Lock\n"
2003-05-06 06:40:09 +00:00
"(\n"
" ppVertexBuffer : 0x%.08X\n"
" OffsetToLock : 0x%.08X\n"
" SizeToLock : 0x%.08X\n"
" ppbData : 0x%.08X\n"
" Flags : 0x%.08X\n"
");\n",
GetCurrentThreadId(), ppVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
}
#endif
2003-06-10 22:32:31 +00:00
IDirect3DVertexBuffer8 *pVertexBuffer8 = ppVertexBuffer->EmuVertexBuffer8;
HRESULT hRet = pVertexBuffer8->Lock(OffsetToLock, SizeToLock, ppbData, Flags);
2003-05-06 06:40:09 +00:00
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DVertexBuffer8_Lock2
// ******************************************************************
2003-07-02 20:14:15 +00:00
BYTE* WINAPI XTL::EmuIDirect3DVertexBuffer8_Lock2
2003-05-06 06:40:09 +00:00
(
2003-06-10 22:32:31 +00:00
X_D3DVertexBuffer *ppVertexBuffer,
DWORD Flags
2003-05-06 06:40:09 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DVertexBuffer8_Lock2\n"
2003-05-02 02:42:29 +00:00
"(\n"
" ppVertexBuffer : 0x%.08X\n"
" Flags : 0x%.08X\n"
");\n",
GetCurrentThreadId(), ppVertexBuffer, Flags);
}
#endif
2003-06-10 22:32:31 +00:00
IDirect3DVertexBuffer8 *pVertexBuffer8 = ppVertexBuffer->EmuVertexBuffer8;
2003-05-02 02:42:29 +00:00
BYTE *pbData = NULL;
2003-06-10 22:32:31 +00:00
HRESULT hRet = pVertexBuffer8->Lock(0, 0, &pbData, Flags);
2003-05-02 02:42:29 +00:00
EmuSwapFS(); // XBox FS
return pbData;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetStreamSource
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetStreamSource
2003-05-02 02:42:29 +00:00
(
2003-06-10 22:32:31 +00:00
UINT StreamNumber,
X_D3DVertexBuffer *pStreamData,
UINT Stride
2003-05-02 02:42:29 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetStreamSource\n"
2003-05-02 02:42:29 +00:00
"(\n"
" StreamNumber : 0x%.08X\n"
" pStreamData : 0x%.08X\n"
" Stride : 0x%.08X\n"
");\n",
GetCurrentThreadId(), StreamNumber, pStreamData, Stride);
}
#endif
2003-07-03 05:09:28 +00:00
IDirect3DVertexBuffer8 *pVertexBuffer8 = NULL;
if(pStreamData != NULL)
{
EmuVerifyResourceIsRegistered(pStreamData);
2003-06-10 22:32:31 +00:00
2003-07-03 05:09:28 +00:00
pVertexBuffer8 = pStreamData->EmuVertexBuffer8;
pVertexBuffer8->Unlock();
}
2003-05-02 02:42:29 +00:00
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->SetStreamSource(StreamNumber, pVertexBuffer8, Stride);
2003-05-02 02:42:29 +00:00
EmuSwapFS(); // XBox FS
2003-05-06 06:40:09 +00:00
return hRet;
2003-05-02 02:42:29 +00:00
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetVertexShader
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetVertexShader
2003-05-02 02:42:29 +00:00
(
DWORD Handle
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetVertexShader\n"
2003-05-02 02:42:29 +00:00
"(\n"
" Handle : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Handle);
}
#endif
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->SetVertexShader(Handle);
2003-05-02 02:42:29 +00:00
EmuSwapFS(); // XBox FS
2003-05-06 06:40:09 +00:00
return hRet;
2003-05-02 02:42:29 +00:00
}
// ******************************************************************
2003-06-13 19:21:10 +00:00
// * func: EmuUpdateDeferredStates
2003-05-02 02:42:29 +00:00
// ******************************************************************
2003-06-13 19:21:10 +00:00
static void EmuUpdateDeferredStates()
2003-05-02 02:42:29 +00:00
{
2003-07-02 20:14:15 +00:00
using namespace XTL;
2003-05-02 02:42:29 +00:00
2003-05-25 07:31:07 +00:00
// Certain D3DRS values need to be checked on each Draw[Indexed]Vertices
2003-07-07 18:38:27 +00:00
if(EmuD3DDeferredRenderState != 0)
2003-06-13 00:37:41 +00:00
{
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[0] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_FOGENABLE, XTL::EmuD3DDeferredRenderState[0]);
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[1] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_FOGTABLEMODE, XTL::EmuD3DDeferredRenderState[1]);
2003-07-08 01:37:46 +00:00
if(XTL::EmuD3DDeferredRenderState[6] != X_D3DRS_UNK)
{
::DWORD dwConv = 0;
dwConv |= (XTL::EmuD3DDeferredRenderState[6] & 0x00000010) ? D3DWRAP_U : 0;
dwConv |= (XTL::EmuD3DDeferredRenderState[6] & 0x00001000) ? D3DWRAP_V : 0;
dwConv |= (XTL::EmuD3DDeferredRenderState[6] & 0x00100000) ? D3DWRAP_W : 0;
g_pD3DDevice8->SetRenderState(D3DRS_WRAP0, dwConv);
}
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[10] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_LIGHTING, XTL::EmuD3DDeferredRenderState[10]);
2003-06-20 16:42:31 +00:00
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[11] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_SPECULARENABLE, XTL::EmuD3DDeferredRenderState[11]);
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[20] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, XTL::EmuD3DDeferredRenderState[20]);
2003-06-20 16:42:31 +00:00
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[23] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_AMBIENT, XTL::EmuD3DDeferredRenderState[23]);
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[24] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_POINTSIZE, XTL::EmuD3DDeferredRenderState[24]);
2003-06-21 01:14:25 +00:00
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[25] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_POINTSIZE_MIN, XTL::EmuD3DDeferredRenderState[25]);
2003-06-21 01:14:25 +00:00
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[26] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_POINTSPRITEENABLE, XTL::EmuD3DDeferredRenderState[26]);
2003-06-21 01:14:25 +00:00
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[27] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_POINTSCALEENABLE, XTL::EmuD3DDeferredRenderState[27]);
2003-06-21 01:14:25 +00:00
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[28] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_POINTSCALE_A, XTL::EmuD3DDeferredRenderState[28]);
2003-06-21 01:14:25 +00:00
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[29] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_POINTSCALE_B, XTL::EmuD3DDeferredRenderState[29]);
2003-06-21 01:14:25 +00:00
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[30] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_POINTSCALE_C, XTL::EmuD3DDeferredRenderState[30]);
2003-06-21 01:14:25 +00:00
2003-07-08 01:37:46 +00:00
if(XTL::EmuD3DDeferredRenderState[33] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_PATCHSEGMENTS, XTL::EmuD3DDeferredRenderState[33]);
2003-06-21 01:14:25 +00:00
/** To check for unhandled RenderStates
for(int v=0;v<117-82;v++)
{
2003-07-02 20:14:15 +00:00
if(XTL::EmuD3DDeferredRenderState[v] != X_D3DRS_UNK)
{
2003-07-08 01:37:46 +00:00
if(v != 0 && v != 1 && v != 6 && v != 10 && v != 11 && v != 20 && v != 23
&& v != 24 && v != 25 && v != 26 && v != 27 && v != 28 && v != 29 && v != 30
&& v != 33)
printf("*Warning* Unhandled RenderState Change @ %d (%d)\n", v, v + 82);
}
}
2003-06-21 00:27:30 +00:00
//**/
2003-06-13 00:37:41 +00:00
}
// Certain D3DTS values need to be checked on each Draw[Indexed]Vertices
2003-07-02 20:14:15 +00:00
if(EmuD3DDeferredTextureState != 0)
2003-06-13 00:37:41 +00:00
{
2003-06-18 08:00:50 +00:00
for(int v=0;v<4;v++)
2003-06-13 00:37:41 +00:00
{
2003-07-02 20:14:15 +00:00
::DWORD *pCur = &EmuD3DDeferredTextureState[v*32];
2003-06-13 00:37:41 +00:00
if(pCur[0] != X_D3DTSS_UNK)
{
if(pCur[0] == 5)
EmuCleanup("ClampToEdge is unsupported (temporarily)");
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_ADDRESSU, pCur[0]);
}
if(pCur[1] != X_D3DTSS_UNK)
{
if(pCur[1] == 5)
EmuCleanup("ClampToEdge is unsupported (temporarily)");
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_ADDRESSV, pCur[1]);
}
if(pCur[2] != X_D3DTSS_UNK)
{
if(pCur[2] == 5)
EmuCleanup("ClampToEdge is unsupported (temporarily)");
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_ADDRESSW, pCur[2]);
}
if(pCur[3] != X_D3DTSS_UNK)
{
if(pCur[3] == 4)
EmuCleanup("QuinCunx is unsupported (temporarily)");
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_MAGFILTER, pCur[3]);
}
if(pCur[4] != X_D3DTSS_UNK)
{
if(pCur[4] == 4)
EmuCleanup("QuinCunx is unsupported (temporarily)");
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_MINFILTER, pCur[4]);
}
if(pCur[5] != X_D3DTSS_UNK)
{
if(pCur[5] == 4)
EmuCleanup("QuinCunx is unsupported (temporarily)");
2003-06-26 00:43:21 +00:00
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_MIPFILTER, pCur[5]);
}
2003-06-13 00:37:41 +00:00
2003-06-26 23:55:09 +00:00
if(pCur[6] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_MIPMAPLODBIAS, pCur[6]);
if(pCur[7] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_MAXMIPLEVEL, pCur[7]);
if(pCur[8] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_MAXANISOTROPY, pCur[8]);
2003-06-13 00:37:41 +00:00
// TODO: Use a lookup table, this is not always a 1:1 map
2003-06-20 16:42:31 +00:00
if(pCur[12] != X_D3DTSS_UNK)
{
if(pCur[12] > 12)
EmuCleanup("(Temporarily) Unsupported D3DTSS_ALPHAOP Value (%d)", pCur[12]);
2003-06-18 08:00:50 +00:00
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_COLOROP, pCur[12]);
}
if(pCur[13] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_COLORARG0, pCur[13]);
2003-06-13 00:37:41 +00:00
2003-06-20 16:42:31 +00:00
if(pCur[14] != X_D3DTSS_UNK)
2003-06-18 08:00:50 +00:00
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_COLORARG1, pCur[14]);
2003-06-20 16:42:31 +00:00
if(pCur[15] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_COLORARG2, pCur[15]);
2003-06-13 00:37:41 +00:00
// TODO: Use a lookup table, this is not always a 1:1 map (same as D3DTSS_COLOROP)
2003-06-20 16:42:31 +00:00
if(pCur[16] != X_D3DTSS_UNK)
{
if(pCur[16] > 12)
EmuCleanup("(Temporarily) Unsupported D3DTSS_ALPHAOP Value (%d)", pCur[16]);
2003-06-20 16:42:31 +00:00
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_ALPHAOP, pCur[16]);
}
if(pCur[17] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_ALPHAARG0, pCur[17]);
if(pCur[18] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_ALPHAARG1, pCur[18]);
if(pCur[19] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_ALPHAARG2, pCur[19]);
if(pCur[20] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_RESULTARG, pCur[20]);
if(pCur[21] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_TEXTURETRANSFORMFLAGS, pCur[21]);
if(pCur[29] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_BORDERCOLOR, pCur[29]);
/** To check for unhandled texture stage state changes
for(int r=0;r<32;r++)
{
static const int unchecked[] =
{
2003-06-26 23:55:09 +00:00
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 29, 30, 31
};
if(pCur[r] != X_D3DTSS_UNK)
{
bool pass = true;
for(int q=0;q<sizeof(unchecked)/sizeof(int);q++)
{
if(r == unchecked[q])
{
pass = false;
break;
}
}
if(pass)
printf("*Warning* Unhandled TextureState Change @ %d->%d\n", v, r);
}
}
2003-06-21 01:14:25 +00:00
//**/
2003-06-13 00:37:41 +00:00
}
2003-07-07 18:38:27 +00:00
// if point sprites are enabled, copy stage 3 over to 0
if(EmuD3DDeferredRenderState[26] == TRUE)
{
// pCur = Texture Stage 3 States
::DWORD *pCur = &EmuD3DDeferredTextureState[2*32];
IDirect3DBaseTexture8 *pTexture;
// set the point sprites texture
g_pD3DDevice8->GetTexture(3, &pTexture);
g_pD3DDevice8->SetTexture(0, pTexture);
// disable all other stages
g_pD3DDevice8->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
g_pD3DDevice8->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
// in that case we have to copy over the stage by hand
for(int v=0;v<30;v++)
{
if(pCur[v] != X_D3DTSS_UNK)
{
::DWORD dwValue;
g_pD3DDevice8->GetTextureStageState(3, (D3DTEXTURESTAGESTATETYPE)v, &dwValue);
g_pD3DDevice8->SetTextureStageState(0, (D3DTEXTURESTAGESTATETYPE)v, dwValue);
}
}
}
2003-06-13 00:37:41 +00:00
}
2003-06-13 19:21:10 +00:00
}
2003-06-21 07:46:13 +00:00
// ******************************************************************
// * func: EmuQuadHackA
// ******************************************************************
2003-07-02 20:14:15 +00:00
uint32 EmuQuadHackA(uint32 PrimitiveCount, XTL::IDirect3DVertexBuffer8 *&pOrigVertexBuffer8, XTL::IDirect3DVertexBuffer8 *&pHackVertexBuffer8)
{
2003-06-21 07:46:13 +00:00
UINT nStride = 0;
g_pD3DDevice8->GetStreamSource(0, &pOrigVertexBuffer8, &nStride);
2003-07-02 20:14:15 +00:00
g_pD3DDevice8->CreateVertexBuffer(PrimitiveCount*nStride*6, 0, 0, XTL::D3DPOOL_DEFAULT, &pHackVertexBuffer8);
2003-06-21 07:46:13 +00:00
BOOL bPatch = FALSE;
// Determine if we need to patch the buffer (?)
{
DWORD dwVertexShader = NULL;
g_pD3DDevice8->GetVertexShader(&dwVertexShader);
if(dwVertexShader & D3DFVF_XYZRHW)
bPatch=TRUE;
}
BYTE *pOrigVertexData = 0;
BYTE *pHackVertexData = 0;
2003-06-26 00:43:21 +00:00
if(pOrigVertexBuffer8 != 0 && pHackVertexBuffer8 != 0)
2003-06-21 07:46:13 +00:00
{
2003-06-26 00:43:21 +00:00
pOrigVertexBuffer8->Lock(0, 0, &pOrigVertexData, 0);
pHackVertexBuffer8->Lock(0, 0, &pHackVertexData, 0);
2003-06-21 07:46:13 +00:00
2003-06-26 00:43:21 +00:00
for(DWORD i=0;i<PrimitiveCount;i++)
2003-06-21 07:46:13 +00:00
{
2003-06-26 00:43:21 +00:00
memcpy(&pHackVertexData[i*nStride*6+0*nStride], &pOrigVertexData[i*nStride*4+2*nStride], nStride);
memcpy(&pHackVertexData[i*nStride*6+1*nStride], &pOrigVertexData[i*nStride*4+0*nStride], nStride);
memcpy(&pHackVertexData[i*nStride*6+2*nStride], &pOrigVertexData[i*nStride*4+1*nStride], nStride);
memcpy(&pHackVertexData[i*nStride*6+3*nStride], &pOrigVertexData[i*nStride*4+2*nStride], nStride);
memcpy(&pHackVertexData[i*nStride*6+4*nStride], &pOrigVertexData[i*nStride*4+3*nStride], nStride);
memcpy(&pHackVertexData[i*nStride*6+5*nStride], &pOrigVertexData[i*nStride*4+0*nStride], nStride);
if(bPatch)
2003-06-21 07:46:13 +00:00
{
2003-06-26 00:43:21 +00:00
for(int z=0; z<6; z++)
{
if(((FLOAT*)&pHackVertexData[i*nStride*6+z*nStride])[2] == 0.0f)
((FLOAT*)&pHackVertexData[i*nStride*6+z*nStride])[2] = 1.0f;
if(((FLOAT*)&pHackVertexData[i*nStride*6+z*nStride])[3] == 0.0f)
((FLOAT*)&pHackVertexData[i*nStride*6+z*nStride])[3] = 1.0f;
}
}
}
2003-06-21 07:46:13 +00:00
2003-06-26 00:43:21 +00:00
pOrigVertexBuffer8->Unlock();
pHackVertexBuffer8->Unlock();
2003-06-21 07:46:13 +00:00
2003-06-26 00:43:21 +00:00
g_pD3DDevice8->SetStreamSource(0, pHackVertexBuffer8, nStride);
}
2003-06-21 07:46:13 +00:00
return nStride;
}
// ******************************************************************
// * func: EmuQuadHackB
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID EmuQuadHackB(uint32 nStride, XTL::IDirect3DVertexBuffer8 *&pOrigVertexBuffer8, XTL::IDirect3DVertexBuffer8 *&pHackVertexBuffer8)
2003-06-21 07:46:13 +00:00
{
2003-06-26 00:43:21 +00:00
if(pOrigVertexBuffer8 != 0 && pHackVertexBuffer8 != 0)
g_pD3DDevice8->SetStreamSource(0, pOrigVertexBuffer8, nStride);
2003-06-21 07:46:13 +00:00
2003-06-26 00:43:21 +00:00
if(pOrigVertexBuffer8 != 0)
pOrigVertexBuffer8->Release();
if(pHackVertexBuffer8 != 0)
pHackVertexBuffer8->Release();
}
2003-06-13 19:21:10 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_DrawVertices
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_DrawVertices
2003-06-13 19:21:10 +00:00
(
X_D3DPRIMITIVETYPE PrimitiveType,
UINT StartVertex,
UINT VertexCount
2003-06-13 19:21:10 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_DrawVertices\n"
"(\n"
" PrimitiveType : 0x%.08X\n"
" StartVertex : 0x%.08X\n"
" VertexCount : 0x%.08X\n"
");\n",
GetCurrentThreadId(), PrimitiveType, StartVertex, VertexCount);
}
#endif
EmuUpdateDeferredStates();
2003-05-23 02:55:39 +00:00
2003-06-24 00:06:09 +00:00
if((DWORD)PrimitiveType == 0x03 || (DWORD)PrimitiveType == 0x09 || (DWORD)PrimitiveType == 0x10)
printf("*Warning* unsupported PrimitiveType! (%d)\n", (DWORD)PrimitiveType);
2003-06-20 16:42:31 +00:00
UINT PrimitiveCount = EmuD3DVertex2PrimitiveCount(PrimitiveType, VertexCount);
2003-05-02 02:42:29 +00:00
// Convert from Xbox to PC enumeration
D3DPRIMITIVETYPE PCPrimitiveType = EmuPrimitiveType(PrimitiveType);
2003-06-21 07:46:13 +00:00
IDirect3DVertexBuffer8 *pOrigVertexBuffer8 = 0;
IDirect3DVertexBuffer8 *pHackVertexBuffer8 = 0;
2003-06-21 07:46:13 +00:00
uint32 nStride = 0;
2003-06-21 07:46:13 +00:00
if(PrimitiveType == 8) // Quad List
{
PrimitiveCount *= 2;
2003-06-21 07:46:13 +00:00
nStride = EmuQuadHackA(PrimitiveCount, pOrigVertexBuffer8, pHackVertexBuffer8);
}
2003-05-02 02:42:29 +00:00
2003-06-18 08:00:50 +00:00
g_pD3DDevice8->DrawPrimitive
2003-05-02 02:42:29 +00:00
(
PCPrimitiveType,
StartVertex,
2003-05-23 02:55:39 +00:00
PrimitiveCount
2003-05-02 02:42:29 +00:00
);
2003-06-21 07:46:13 +00:00
if(PrimitiveType == 8) // Quad List
EmuQuadHackB(nStride, pOrigVertexBuffer8, pHackVertexBuffer8);
2003-05-02 02:42:29 +00:00
EmuSwapFS(); // XBox FS
2003-06-18 08:00:50 +00:00
return;
2003-05-02 02:42:29 +00:00
}
2003-05-28 07:21:41 +00:00
2003-06-13 19:21:10 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_DrawVerticesUP
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_DrawVerticesUP
2003-06-13 19:21:10 +00:00
(
X_D3DPRIMITIVETYPE PrimitiveType,
UINT VertexCount,
CONST PVOID pVertexStreamZeroData,
UINT VertexStreamZeroStride
2003-06-13 19:21:10 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_DrawVerticesUP\n"
"(\n"
" PrimitiveType : 0x%.08X\n"
" VertexCount : 0x%.08X\n"
" pVertexStreamZeroData : 0x%.08X\n"
" VertexStreamZeroStride : 0x%.08X\n"
");\n",
GetCurrentThreadId(), PrimitiveType, VertexCount, pVertexStreamZeroData,
VertexStreamZeroStride);
}
#endif
EmuUpdateDeferredStates();
2003-06-24 00:06:09 +00:00
if((DWORD)PrimitiveType == 0x03 || (DWORD)PrimitiveType == 0x09 || (DWORD)PrimitiveType == 0x10)
printf("Unsupported PrimitiveType! (%d)\n", (DWORD)PrimitiveType);
2003-06-20 16:42:31 +00:00
UINT PrimitiveCount = EmuD3DVertex2PrimitiveCount(PrimitiveType, VertexCount);
2003-06-13 19:21:10 +00:00
// Convert from Xbox to PC enumeration
D3DPRIMITIVETYPE PCPrimitiveType = EmuPrimitiveType(PrimitiveType);
2003-06-13 19:21:10 +00:00
2003-06-21 07:46:13 +00:00
IDirect3DVertexBuffer8 *pOrigVertexBuffer8 = 0;
IDirect3DVertexBuffer8 *pHackVertexBuffer8 = 0;
uint32 nStride = 0;
if(PrimitiveType == 8) // Quad List
{
PrimitiveCount *= 2;
nStride = EmuQuadHackA(PrimitiveCount, pOrigVertexBuffer8, pHackVertexBuffer8);
}
2003-06-18 08:00:50 +00:00
g_pD3DDevice8->DrawPrimitiveUP
2003-06-13 19:21:10 +00:00
(
PCPrimitiveType,
2003-06-13 19:21:10 +00:00
PrimitiveCount,
pVertexStreamZeroData,
VertexStreamZeroStride
);
2003-06-21 07:46:13 +00:00
if(PrimitiveType == 8) // Quad List
EmuQuadHackB(nStride, pOrigVertexBuffer8, pHackVertexBuffer8);
2003-06-13 19:21:10 +00:00
EmuSwapFS(); // XBox FS
2003-06-18 08:00:50 +00:00
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_DrawIndexedVertices
// ******************************************************************
2003-07-02 20:14:15 +00:00
VOID WINAPI XTL::EmuIDirect3DDevice8_DrawIndexedVertices
2003-06-18 08:00:50 +00:00
(
X_D3DPRIMITIVETYPE PrimitiveType,
UINT VertexCount,
CONST PWORD pIndexData
2003-06-18 08:00:50 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_DrawIndexedVertices\n"
"(\n"
" PrimitiveType : 0x%.08X\n"
" VertexCount : 0x%.08X\n"
" pIndexData : 0x%.08X\n"
");\n",
GetCurrentThreadId(), PrimitiveType, VertexCount, pIndexData);
}
#endif
EmuUpdateDeferredStates();
if((DWORD)PrimitiveType == 0x03 || (DWORD)PrimitiveType == 0x08 || (DWORD)PrimitiveType == 0x09 || (DWORD)PrimitiveType == 0x10)
printf("*Warning* unsupported PrimitiveType! (%d)\n", (DWORD)PrimitiveType);
2003-06-20 16:42:31 +00:00
UINT PrimitiveCount = EmuD3DVertex2PrimitiveCount(PrimitiveType, VertexCount);
2003-06-18 08:00:50 +00:00
// Convert from Xbox to PC enumeration
D3DPRIMITIVETYPE PCPrimitiveType = EmuPrimitiveType(PrimitiveType);
2003-06-18 08:00:50 +00:00
2003-06-24 00:06:09 +00:00
IDirect3DVertexBuffer8 *pOrigVertexBuffer8 = 0;
IDirect3DVertexBuffer8 *pHackVertexBuffer8 = 0;
uint32 nStride = 0;
if(PrimitiveType == 8) // Quad List
{
PrimitiveCount *= 2;
nStride = EmuQuadHackA(PrimitiveCount, pOrigVertexBuffer8, pHackVertexBuffer8);
}
2003-06-18 08:00:50 +00:00
g_pD3DDevice8->DrawIndexedPrimitive
(
PCPrimitiveType, 0, VertexCount, (DWORD)pIndexData/sizeof(WORD), PrimitiveCount
2003-06-18 08:00:50 +00:00
);
2003-06-24 00:06:09 +00:00
if(PrimitiveType == 8) // Quad List
EmuQuadHackB(nStride, pOrigVertexBuffer8, pHackVertexBuffer8);
2003-06-18 08:00:50 +00:00
EmuSwapFS(); // XBox FS
return;
2003-06-13 19:21:10 +00:00
}
2003-05-28 07:21:41 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetLight
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetLight
2003-05-28 07:21:41 +00:00
(
DWORD Index,
CONST D3DLIGHT8 *pLight
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetLight\n"
"(\n"
" Index : 0x%.08X\n"
" pLight : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Index, pLight);
}
#endif
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->SetLight(Index, pLight);
2003-05-28 07:21:41 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetMaterial
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_SetMaterial
2003-05-28 07:21:41 +00:00
(
CONST D3DMATERIAL8 *pMaterial
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_SetMaterial\n"
"(\n"
" pMaterial : 0x%.08X\n"
");\n",
GetCurrentThreadId(), pMaterial);
}
#endif
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->SetMaterial(pMaterial);
2003-05-28 07:21:41 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_LightEnable
// ******************************************************************
2003-07-02 20:14:15 +00:00
HRESULT WINAPI XTL::EmuIDirect3DDevice8_LightEnable
2003-05-28 07:21:41 +00:00
(
DWORD Index,
BOOL bEnable
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_LightEnable\n"
"(\n"
" Index : 0x%.08X\n"
" bEnable : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Index, bEnable);
}
#endif
2003-06-10 22:32:31 +00:00
HRESULT hRet = g_pD3DDevice8->LightEnable(Index, bEnable);
2003-05-28 07:21:41 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}