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

3007 lines
94 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-04-27 04:56:09 +00:00
#include "EmuKrnl.h"
2003-04-02 02:23:30 +00:00
#include "EmuDInput.h"
2003-05-31 01:17:12 +00:00
#include "EmuShared.h"
2003-03-07 22:01:44 +00:00
// ******************************************************************
// * prevent name collisions
// ******************************************************************
2003-04-02 02:23:30 +00:00
namespace xd3d8
2003-02-21 00:07:28 +00:00
{
2003-04-02 02:23:30 +00:00
#include "xd3d8.h"
};
2003-02-21 00:07:28 +00:00
2003-06-10 22:32:31 +00:00
// ******************************************************************
// * prevent name collisions
// ******************************************************************
namespace xg
{
#include "EmuXG.h"
};
2003-04-02 02:23:30 +00:00
#include "EmuD3D8.h"
2003-06-05 03:09:52 +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-06-05 03:09:52 +00:00
HWND 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-03-27 06:23:58 +00:00
static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
2003-05-05 06:35:37 +00:00
static DWORD WINAPI EmuRenderWindow(LPVOID);
static DWORD WINAPI EmuUpdateTickCount(LPVOID);
2003-06-18 05:15:02 +00:00
static DWORD EmuCheckAllocationSize(LPVOID);
2003-05-31 01:17:12 +00:00
// ******************************************************************
// * Static Variable(s)
// ******************************************************************
static xd3d8::LPDIRECT3D8 g_pD3D8 = NULL; // Direct3D8
2003-06-10 22:32:31 +00:00
static xd3d8::LPDIRECT3DDEVICE8 g_pD3DDevice8 = NULL; // Direct3D8 Device
2003-05-31 01:17:12 +00:00
static Xbe::Header *g_XbeHeader = NULL; // XbeHeader
static uint32 g_XbeHeaderSize = 0; // XbeHeaderSize
static xd3d8::D3DCAPS8 g_D3DCaps; // Direct3D8 Caps
static HBRUSH g_hBgBrush = NULL; // Background Brush
2003-06-12 02:05:10 +00:00
static volatile bool g_bThreadInitialized = false;
2003-05-31 01:17:12 +00:00
static XBVideo g_XBVideo;
2003-06-12 02:05:10 +00:00
// ******************************************************************
// * Cached Direct3D State Variable(s)
// ******************************************************************
static xd3d8::X_D3DSurface *g_pCachedRenderTarget = NULL;
static xd3d8::X_D3DSurface *g_pCachedZStencilSurface = NULL;
static DWORD g_dwVertexShaderUsage = 0;
2003-06-18 05:15:02 +00:00
// ******************************************************************
// * EmuD3DTiles (8 Tiles Max)
// ******************************************************************
xd3d8::X_D3DTILE xd3d8::EmuD3DTileCache[0x08] = {0};
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-06-13 00:37:41 +00:00
DWORD *xd3d8::EmuD3DDeferredRenderState;
// ******************************************************************
// * EmuD3DDeferredTextureState
// ******************************************************************
DWORD *xd3d8::EmuD3DDeferredTextureState;
2003-05-23 02:55:39 +00:00
// ******************************************************************
2003-04-16 19:06:20 +00:00
// * func: EmuD3DInit
// ******************************************************************
2003-04-16 19:06:20 +00:00
VOID 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-04-02 02:23:30 +00:00
using namespace xd3d8;
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
}
}
2003-04-16 19:06:20 +00:00
// ******************************************************************
// * func: EmuD3DCleanup
// ******************************************************************
VOID EmuD3DCleanup()
{
EmuDInputCleanup();
return;
}
2003-05-05 06:35:37 +00:00
// ******************************************************************
// * func: EmuUpdateTickCount
// ******************************************************************
DWORD WINAPI EmuUpdateTickCount(LPVOID)
{
2003-05-30 02:08:25 +00:00
timeBeginPeriod(0);
2003-05-05 06:35:37 +00:00
while(true)
{
2003-05-30 02:08:25 +00:00
xboxkrnl::KeTickCount = timeGetTime();
2003-05-20 21:39:25 +00:00
Sleep(1);
2003-05-05 06:35:37 +00:00
}
2003-05-30 02:08:25 +00:00
timeEndPeriod(0);
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: EmuRenderWindow
2003-02-21 00:07:28 +00:00
// ******************************************************************
2003-05-03 08:29:37 +00:00
DWORD WINAPI EmuRenderWindow(LPVOID)
{
// ******************************************************************
// * register window class
// ******************************************************************
{
2003-04-06 20:07:36 +00:00
#ifdef _DEBUG
HMODULE hCxbxDll = GetModuleHandle("CxbxKrnl.dll");
#else
2003-03-04 07:05:25 +00:00
HMODULE hCxbxDll = GetModuleHandle("Cxbx.dll");
2003-04-06 20:07:36 +00:00
#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;
}
g_hEmuWindow = CreateWindow
(
"CxbxRender", AsciiTitle,
dwStyle, x, y, nWidth, nHeight,
GetDesktopWindow(), NULL, GetModuleHandle(NULL), NULL
);
}
}
2003-06-06 00:56:10 +00:00
ShowWindow(g_hEmuWindow, SW_SHOWDEFAULT);
UpdateWindow(g_hEmuWindow);
2003-02-19 20:53:33 +00:00
2003-03-23 22:24:41 +00:00
// ******************************************************************
// * initialize direct input
// ******************************************************************
2003-04-26 04:32:46 +00:00
if(!EmuDInputInit())
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
// ******************************************************************
2003-03-27 06:23:58 +00:00
LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
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-03-04 07:48:23 +00:00
case WM_CLOSE:
DestroyWindow(hWnd);
break;
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-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
}
// ******************************************************************
2003-03-27 06:23:58 +00:00
// * func: EmuIDirect3D8_CreateDevice
// ******************************************************************
2003-04-02 02:23:30 +00:00
HRESULT WINAPI xd3d8::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-07 03:06:59 +00:00
// ******************************************************************
// * verify no ugly circumstances
// ******************************************************************
if(pPresentationParameters->BufferSurfaces[0] != NULL || pPresentationParameters->DepthStencilSurface != NULL)
EmuCleanup("EmuIDirect3D8_CreateDevice: BufferSurfaces or DepthStencilSurface != NULL");
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);
}
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-06-07 03:06:59 +00:00
(xd3d8::D3DPRESENT_PARAMETERS*)pPresentationParameters,
2003-02-19 20:53:33 +00:00
ppReturnedDeviceInterface
);
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;
}
2003-06-09 03:44:07 +00:00
// ******************************************************************
// * func: EmuIDirect3D8_GetAdapterDisplayMode
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3D8_GetAdapterDisplayMode
(
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
// ******************************************************************
// * 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?
pMode->Flags = 0x000000A1; // D3DPRESENTFLAG_FIELD | D3DPRESENTFLAG_INTERLACED | D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
}
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-18 01:27:33 +00:00
// ******************************************************************
// * func: EmuIDirect3D8_KickOffAndWaitForIdle
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3D8_KickOffAndWaitForIdle()
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuD3D8 (0x%X): EmuIDirect3D8_KickOffAndWaitForIdle()\n", GetCurrentThreadId());
}
#endif
EmuSwapFS(); // XBox FS
return;
}
2003-06-13 00:37:41 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_CopyRects
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_CopyRects
(
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
);
if(FAILED(hRet))
EmuCleanup("Hello");
EmuSwapFS(); // Xbox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateImageSurface
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_CreateImageSurface
(
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
// ******************************************************************
// * func: EmuIDirect3DDevice8_GetBackBuffer
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_GetBackBuffer
(
INT BackBuffer,
D3DBACKBUFFER_TYPE Type,
X_D3DSurface **ppBackBuffer
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
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);
}
#endif
*ppBackBuffer = new X_D3DSurface();
g_pD3DDevice8->GetBackBuffer(BackBuffer, D3DBACKBUFFER_TYPE_MONO, &((*ppBackBuffer)->EmuSurface8));
EmuSwapFS(); // Xbox FS
return;
}
2003-06-12 02:05:10 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_GetRenderTarget
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_GetRenderTarget
(
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
{
EmuSwapFS(); // Win2k/XP FS
printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetRenderTarget\n"
"(\n"
" ppRenderTarget : 0x%.08X\n"
");\n",
GetCurrentThreadId(), ppRenderTarget);
EmuSwapFS(); // Xbox FS
}
#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
// ******************************************************************
xd3d8::X_D3DSurface * WINAPI xd3d8::EmuIDirect3DDevice8_GetRenderTarget2()
{
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_GetDepthStencilSurface
(
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;
pSurface8->AddRef();
*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
// ******************************************************************
xd3d8::X_D3DSurface * WINAPI xd3d8::EmuIDirect3DDevice8_GetDepthStencilSurface2()
{
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;
pSurface8->AddRef();
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_GetTile
(
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_SetTileNoWait
(
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_CreateVertexShader
(
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
// ******************************************************************
// * 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,
pHandle,
2003-06-12 02:05:10 +00:00
g_dwVertexShaderUsage // TODO: HACK: Xbox has extensions!
2003-06-09 03:44:07 +00:00
);
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
2003-06-09 03:44:07 +00:00
// hey look, we lied
hRet = D3D_OK;
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetVertexShaderConstant
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_SetVertexShaderConstant
(
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
);
// hey look, we lied
hRet = D3D_OK;
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreatePixelShader
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_CreatePixelShader
(
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
);
// hey look, we lied
hRet = D3D_OK;
EmuSwapFS(); // XBox FS
return hRet;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetPixelShader
// ******************************************************************
HRESULT WINAPI xd3d8::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
);
// hey look, we lied
hRet = D3D_OK;
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-10 03:00:19 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_CreateTexture2
// ******************************************************************
2003-06-10 22:32:31 +00:00
xd3d8::X_D3DResource * WINAPI xd3d8::EmuIDirect3DDevice8_CreateTexture2
2003-06-10 03:00:19 +00:00
(
UINT Width,
UINT Height,
UINT Depth,
UINT Levels,
DWORD Usage,
D3DFORMAT Format,
D3DRESOURCETYPE D3DResource
)
{
// TODO: Verify this function's parameters ^
2003-06-20 18:03:21 +00:00
EmuCleanup("EmuIDirect3DDevice8_CreateTexture2 is unverified!");
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_CreateTexture
(
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)
Format = EmuXB2PC_D3DFormat(Format);
2003-06-05 00:03:28 +00:00
2003-06-10 22:32:31 +00:00
// Create emulated resource datatype (free'd during intercepted release)
*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,
0, // TODO: Xbox Allows a border to be drawn (maybe hack this in software ;[)
2003-06-10 22:32:31 +00:00
Format, D3DPOOL_MANAGED, &((*ppTexture)->EmuTexture8)
2003-06-05 00:03:28 +00:00
);
2003-06-16 16:43:50 +00:00
if(FAILED(hRet))
EmuCleanup("Could not create texture!");
2003-06-05 00:03:28 +00:00
EmuSwapFS(); // XBox FS
return hRet;
}
2003-06-18 08:00:50 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetIndices
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetIndices
(
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
IDirect3DIndexBuffer8 *pIndexBuffer = pIndexData->EmuIndexBuffer8;
if(pIndexBuffer == 0)
{
EmuSwapFS(); // XBox FS
EmuIDirect3DResource8_Register(pIndexData, (PVOID)pIndexData->Data);
EmuSwapFS(); // Win2k/XP FS
// Now we should have an index buffer
pIndexBuffer = pIndexData->EmuIndexBuffer8;
}
g_pD3DDevice8->SetIndices(pIndexBuffer, BaseVertexIndex);
EmuSwapFS(); // XBox FS
return;
}
2003-06-05 06:53:14 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetTexture
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_SetTexture
(
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
HRESULT hRet;
2003-06-18 05:15:02 +00:00
if(pTexture == NULL)
hRet = g_pD3DDevice8->SetTexture(Stage, NULL);
else
{
IDirect3DBaseTexture8 *pBaseTexture8 = pTexture->EmuBaseTexture8;
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
// ******************************************************************
VOID __fastcall xd3d8::EmuIDirect3DDevice8_SwitchTexture
(
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_GetDisplayMode
(
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-04-02 02:23:30 +00:00
HRESULT WINAPI xd3d8::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"
" Z : 0x%.08X\n"
" 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-02-22 07:49:02 +00:00
if(Flags & 0x000000f0l)
newFlags |= D3DCLEAR_TARGET;
2003-02-20 08:07:52 +00:00
2003-02-22 07:49:02 +00:00
if(Flags & 0x00000001l)
newFlags |= D3DCLEAR_ZBUFFER;
2003-02-20 08:07:52 +00:00
2003-02-22 07:49:02 +00:00
if(Flags & 0x00000002l)
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_Present
(
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
2003-06-10 22:32:31 +00:00
HRESULT ret = g_pD3DDevice8->Present(pSourceRect, pDestRect, (HWND)pDummy1, (CONST RGNDATA*)pDummy2);
2003-05-05 06:35:37 +00:00
EmuSwapFS(); // XBox FS
return ret;
}
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-04-02 02:23:30 +00:00
HRESULT WINAPI xd3d8::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-05-28 07:21:41 +00:00
EmuCleanup("xd3d8::EmuIDirect3DDevice8_Swap: Flags != 0");
2003-02-21 00:07:28 +00:00
// Swap(0) is equivalent to present(0,0,0,0)
2003-06-10 22:32:31 +00:00
HRESULT ret = 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 ret;
2003-05-02 02:42:29 +00:00
}
2003-06-18 05:15:02 +00:00
// ******************************************************************
// * func: EmuCheckAllocationSize
// ******************************************************************
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);
}
2003-06-10 22:32:31 +00:00
// ******************************************************************
// * func: EmuIDirect3DResource8_Register
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DResource8_Register
(
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
2003-06-19 05:37:16 +00:00
/*
static DWORD dwStaticBase = -1, dwTrueBase = -1, dwBaseIncrement;
2003-06-10 22:32:31 +00:00
2003-06-19 05:37:16 +00:00
if((DWORD)pBase == dwStaticBase)
{
dwTrueBase += dwBaseIncrement;
pBase = (PVOID)dwTrueBase;
}
else
{
dwStaticBase = dwTrueBase = (DWORD)pBase;
dwBaseIncrement = 0;
}
*/
2003-06-10 22:32:31 +00:00
HRESULT hRet;
X_D3DResource *pResource = (X_D3DResource*)pThis;
// ******************************************************************
// * Determine the resource type, and initialize
// ******************************************************************
switch(pResource->Common & X_D3DCOMMON_TYPE_MASK)
{
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);
HRESULT hRet = g_pD3DDevice8->CreateVertexBuffer
(
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-06-10 22:32:31 +00:00
case X_D3DCOMMON_TYPE_TEXTURE:
{
2003-06-19 05:37:16 +00:00
#ifdef _DEBUG_TRACE
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);
DWORD dwWidth, dwHeight, dwBPP, dwMipMap;
BOOL bSwizzled;
dwMipMap = (pPixelContainer->Format & X_D3DFORMAT_MIPMAP_MASK) >> X_D3DFORMAT_MIPMAP_SHIFT;
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);
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);
dwBPP = 2;
}
else if(X_Format == 0x12 /* X_D3DFORMAT_A8R8G8B8 */)
{
bSwizzled = FALSE;
// Linear 32 Bit
dwWidth = (pPixelContainer->Size & D3DSIZE_WIDTH_MASK) + 1;
dwHeight = ((pPixelContainer->Size & D3DSIZE_HEIGHT_MASK) >> D3DSIZE_HEIGHT_SHIFT) + 1;
dwBPP = 4;
}
2003-06-10 22:32:31 +00:00
else
{
2003-06-19 05:37:16 +00:00
EmuCleanup("Temporarily Unrecognized Format (0x%.08X)", Format);
2003-06-10 22:32:31 +00:00
}
// ******************************************************************
// * Create the happy little texture
// ******************************************************************
hRet = g_pD3DDevice8->CreateTexture
(
// TODO: HACK: These are temporarily FIXED until we deswizzle
2003-06-19 05:37:16 +00:00
dwWidth, dwHeight, dwMipMap, 0, Format,
2003-06-10 22:32:31 +00:00
D3DPOOL_MANAGED, &pResource->EmuTexture8
);
// ******************************************************************
2003-06-19 05:37:16 +00:00
// * Copy over data (deswizzle if necessary)
2003-06-10 22:32:31 +00:00
// ******************************************************************
{
D3DLOCKED_RECT LockedRect;
pResource->EmuTexture8->LockRect(0, &LockedRect, NULL, 0);
RECT iRect = {0,0,0,0};
POINT iPoint = {0,0};
2003-06-19 05:37:16 +00:00
if(bSwizzled)
{
DWORD dwDepth = 1 << ((pPixelContainer->Format & X_D3DFORMAT_PSIZE_MASK) >> X_D3DFORMAT_PSIZE_SHIFT);
xg::EmuXGUnswizzleRect
(
pBase, dwWidth, dwHeight, dwDepth, LockedRect.pBits,
LockedRect.Pitch, iRect, iPoint, dwBPP
);
}
else
{
BYTE *pDest = (BYTE*)LockedRect.pBits;
BYTE *pSrc = (BYTE*)pBase;
// TODO: Faster copy (maybe unnecessary)
for(DWORD v=0;v<dwHeight;v++)
{
memcpy(pDest, pSrc, dwWidth*dwBPP);
pDest += LockedRect.Pitch;
pSrc += dwWidth*dwBPP;
}
}
2003-06-10 22:32:31 +00:00
pResource->EmuTexture8->UnlockRect(0);
}
}
break;
default:
2003-06-18 08:00:50 +00:00
EmuCleanup("IDirect3DResource8::Register Unknown Common Type (0x%.08X)", pResource->Common & X_D3DCOMMON_TYPE_MASK);
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-06-10 22:32:31 +00:00
ULONG WINAPI xd3d8::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
// ******************************************************************
BOOL WINAPI xd3d8::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-05 00:03:28 +00:00
// ******************************************************************
// * func: EmuIDirect3DSurface8_GetDesc
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DSurface8_GetDesc
(
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
2003-06-05 06:53:14 +00:00
D3DSURFACE_DESC SurfaceDesc;
2003-06-10 22:32:31 +00:00
IDirect3DSurface8 *pSurface8 = pThis->EmuSurface8;
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-06-05 00:03:28 +00:00
pDesc->MultiSampleType = (xd3d8::D3DMULTISAMPLE_TYPE)0x0011;
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DSurface8_LockRect
(
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-06-13 00:37:41 +00:00
if(Flags & 0x40)
2003-06-17 02:23:53 +00:00
printf("*Warning* D3DLOCK_TILED ignored!\n");
2003-06-05 03:09:52 +00:00
}
#endif
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
2003-06-05 23:42:45 +00:00
// This is lame, but we have no choice (afaik)
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DBaseTexture8_GetLevelCount
(
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
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-06-10 22:32:31 +00:00
xd3d8::X_D3DResource * WINAPI xd3d8::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-05 00:03:28 +00:00
// ******************************************************************
// * func: EmuIDirect3DTexture8_GetSurfaceLevel
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DTexture8_GetSurfaceLevel
(
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
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-05-06 06:40:09 +00:00
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_CreateVertexBuffer
(
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-06-10 22:32:31 +00:00
xd3d8::X_D3DVertexBuffer* WINAPI xd3d8::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
// Create emulated resource datatype (free'd during intercepted release)
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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetTextureState_TexCoordIndex
(
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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_NormalizeNormals
(
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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_TextureFactor
(
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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_ZBias
(
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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_EdgeAntiAlias
(
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);
printf("*Warning* SetRenderState_EdgeAntiAlias not implemented!\n");
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_FillMode
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_FillMode
(
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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_FogColor
(
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
printf("*Warning* SetRenderState_FogColor not implemented!\n");
EmuSwapFS(); // XBox FS
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetRenderState_Dxt1NoiseEnable
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_Dxt1NoiseEnable
(
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
// ******************************************************************
VOID __fastcall xd3d8::EmuIDirect3DDevice8_SetRenderState_Simple
(
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
for(int v=0;v<82;v++)
{
if(EmuD3DRenderStateSimpleEncoded[v] == Method)
{
State = v;
break;
}
}
if(State == -1)
{
printf("RenderState_Simple(0x%.08X, 0x%.08X) is unsupported\n", Method, Value);
2003-06-20 18:03:21 +00:00
EmuCleanup("RenderState_Simple(0x%.08X, 0x%.08X) is unsupported", Method, Value);
2003-06-20 16:42:31 +00:00
}
else
{
2003-06-20 18:03:21 +00:00
switch(State)
{
case D3DRS_SRCBLEND:
case D3DRS_DESTBLEND:
Value = EmuXB2PC_D3DBLEND(Value);
break;
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-05-05 06:35:37 +00:00
// * func: EmuIDirect3DDevice8_SetRenderState_CullMode
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_CullMode
(
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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_ZEnable
(
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
// ******************************************************************
VOID WINAPI xd3d8::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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetRenderState_MultiSampleAntiAlias
(
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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_SetTransform
(
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
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_GetTransform
(
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-05-06 06:40:09 +00:00
VOID WINAPI xd3d8::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
// ******************************************************************
BYTE* WINAPI xd3d8::EmuIDirect3DVertexBuffer8_Lock2
(
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-05-06 06:40:09 +00:00
HRESULT WINAPI xd3d8::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-06-10 22:32:31 +00:00
IDirect3DVertexBuffer8 *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-05-06 06:40:09 +00:00
HRESULT WINAPI xd3d8::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-06-13 19:21:10 +00:00
using namespace xd3d8;
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-06-13 00:37:41 +00:00
if(xd3d8::EmuD3DDeferredRenderState != 0)
{
2003-06-20 16:42:31 +00:00
if(xd3d8::EmuD3DDeferredRenderState[10] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_LIGHTING, xd3d8::EmuD3DDeferredRenderState[10]);
if(xd3d8::EmuD3DDeferredRenderState[20] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, xd3d8::EmuD3DDeferredRenderState[20]);
if(xd3d8::EmuD3DDeferredRenderState[23] != X_D3DRS_UNK)
g_pD3DDevice8->SetRenderState(D3DRS_AMBIENT, xd3d8::EmuD3DDeferredRenderState[23]);
2003-06-13 00:37:41 +00:00
}
// Certain D3DTS values need to be checked on each Draw[Indexed]Vertices
if(xd3d8::EmuD3DDeferredTextureState != 0)
{
2003-06-15 00:37:03 +00:00
// TODO: HACK: Handle more than just stage 1 !!!! Make sure pCur is calculated right!
2003-06-18 08:00:50 +00:00
for(int v=0;v<4;v++)
2003-06-13 00:37:41 +00:00
{
2003-06-15 00:37:03 +00:00
DWORD *pCur = xd3d8::EmuD3DDeferredTextureState+v;
2003-06-13 00:37:41 +00:00
2003-06-20 16:42:31 +00:00
if(pCur[21] != X_D3DTSS_UNK)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_TEXTURETRANSFORMFLAGS, pCur[21]);
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)
2003-06-18 08:00:50 +00:00
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_COLOROP, pCur[12]);
2003-06-13 00:37:41 +00:00
// TODO: I think these are OK, but verify this eventually
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)
g_pD3DDevice8->SetTextureStageState(v, D3DTSS_ALPHAOP, pCur[16]);
2003-06-13 00:37:41 +00:00
}
}
2003-06-13 19:21:10 +00:00
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_DrawVertices
// ******************************************************************
2003-06-18 08:00:50 +00:00
VOID WINAPI xd3d8::EmuIDirect3DDevice8_DrawVertices
2003-06-13 19:21:10 +00:00
(
D3DPRIMITIVETYPE PrimitiveType,
UINT StartVertex,
UINT VertexCount
)
{
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-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
PrimitiveType = EmuPrimitiveType(PrimitiveType);
2003-06-18 08:00:50 +00:00
g_pD3DDevice8->DrawPrimitive
2003-05-02 02:42:29 +00:00
(
PrimitiveType,
StartVertex,
2003-05-23 02:55:39 +00:00
PrimitiveCount
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-06-18 08:00:50 +00:00
VOID WINAPI xd3d8::EmuIDirect3DDevice8_DrawVerticesUP
2003-06-13 19:21:10 +00:00
(
D3DPRIMITIVETYPE PrimitiveType,
UINT VertexCount,
CONST PVOID pVertexStreamZeroData,
UINT VertexStreamZeroStride
)
{
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-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
PrimitiveType = EmuPrimitiveType(PrimitiveType);
2003-06-18 08:00:50 +00:00
g_pD3DDevice8->DrawPrimitiveUP
2003-06-13 19:21:10 +00:00
(
PrimitiveType,
PrimitiveCount,
pVertexStreamZeroData,
VertexStreamZeroStride
);
EmuSwapFS(); // XBox FS
2003-06-18 08:00:50 +00:00
return;
}
// ******************************************************************
// * func: EmuIDirect3DDevice8_DrawIndexedVertices
// ******************************************************************
VOID WINAPI xd3d8::EmuIDirect3DDevice8_DrawIndexedVertices
(
D3DPRIMITIVETYPE PrimitiveType,
UINT VertexCount,
CONST PWORD pIndexData
)
{
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();
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
PrimitiveType = EmuPrimitiveType(PrimitiveType);
g_pD3DDevice8->DrawIndexedPrimitive
(
PrimitiveType, 0, PrimitiveCount,
0, PrimitiveCount
);
EmuSwapFS(); // XBox FS
return;
2003-06-13 19:21:10 +00:00
}
2003-05-28 07:21:41 +00:00
// ******************************************************************
// * func: EmuIDirect3DDevice8_SetLight
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_SetLight
(
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_SetMaterial
(
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
// ******************************************************************
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_LightEnable
(
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;
}