Various DirectDraw items (#1411)

This commit is contained in:
MS
2025-03-15 11:12:10 -04:00
committed by GitHub
parent b0b68052d4
commit 51fc69e49f
5 changed files with 184 additions and 93 deletions

View File

@@ -12,21 +12,24 @@ DECOMP_SIZE_ASSERT(MxDirect3D, 0x894)
}
// FUNCTION: LEGO1 0x1009b0a0
// FUNCTION: BETA10 0x1011b220
MxDirect3D::MxDirect3D()
{
this->m_pDirect3d = NULL;
this->m_pDirect3dDevice = NULL;
this->m_bTexturesDisabled = FALSE;
this->m_assignedDevice = NULL;
m_pDirect3d = NULL;
m_pDirect3dDevice = NULL;
m_bTexturesDisabled = FALSE;
m_currentDeviceInfo = NULL;
}
// FUNCTION: LEGO1 0x1009b140
// FUNCTION: BETA10 0x1011b2c3
MxDirect3D::~MxDirect3D()
{
Destroy();
}
// FUNCTION: LEGO1 0x1009b1a0
// FUNCTION: BETA10 0x1011b333
BOOL MxDirect3D::Create(
HWND hWnd,
BOOL fullscreen_1,
@@ -40,22 +43,33 @@ BOOL MxDirect3D::Create(
)
{
BOOL success = FALSE;
BOOL ret = MxDirectDraw::Create(
hWnd,
fullscreen_1,
surface_fullscreen,
onlySystemMemory,
width,
height,
bpp,
pPaletteEntries,
paletteEntryCount
);
assert(m_currentDeviceInfo);
if (ret && D3DCreate() && D3DSetMode()) {
success = TRUE;
if (!MxDirectDraw::Create(
hWnd,
fullscreen_1,
surface_fullscreen,
onlySystemMemory,
width,
height,
bpp,
pPaletteEntries,
paletteEntryCount
)) {
goto done;
}
if (!D3DCreate()) {
goto done;
}
if (!D3DSetMode()) {
goto done;
}
success = TRUE;
done:
if (!success) {
FUN_1009d920();
}
@@ -64,24 +78,26 @@ BOOL MxDirect3D::Create(
}
// FUNCTION: LEGO1 0x1009b210
// FUNCTION: BETA10 0x1011b41d
void MxDirect3D::Destroy()
{
RELEASE(m_pDirect3dDevice);
RELEASE(m_pDirect3d);
if (this->m_assignedDevice) {
delete m_assignedDevice;
this->m_assignedDevice = NULL;
if (m_currentDeviceInfo) {
delete m_currentDeviceInfo;
m_currentDeviceInfo = NULL;
}
if (m_pCurrentDeviceModesList) {
m_pCurrentDeviceModesList = NULL;
if (m_currentDevInfo) {
m_currentDevInfo = NULL;
}
MxDirectDraw::Destroy();
}
// FUNCTION: LEGO1 0x1009b290
// FUNCTION: BETA10 0x1011b50a
void MxDirect3D::DestroyButNotDirectDraw()
{
RELEASE(m_pDirect3dDevice);
@@ -90,6 +106,7 @@ void MxDirect3D::DestroyButNotDirectDraw()
}
// FUNCTION: LEGO1 0x1009b2d0
// FUNCTION: BETA10 0x1011b592
BOOL MxDirect3D::D3DCreate()
{
HRESULT result;
@@ -103,46 +120,50 @@ BOOL MxDirect3D::D3DCreate()
}
// FUNCTION: LEGO1 0x1009b310
// FUNCTION: BETA10 0x1011b617
BOOL MxDirect3D::D3DSetMode()
{
if (m_assignedDevice->m_flags & MxAssignedDevice::c_hardwareMode) {
assert(m_currentDeviceInfo);
if (m_currentDeviceInfo->m_flags & MxAssignedDevice::c_hardwareMode) {
if (m_bOnlySoftRender) {
Error("Failed to place vital surfaces in video memory for hardware driver", DDERR_GENERIC);
return FALSE;
}
if (m_assignedDevice->m_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) {
if (m_currentDeviceInfo->m_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) {
m_bTexturesDisabled = FALSE;
}
else {
m_bTexturesDisabled = TRUE;
}
if (!CreateZBuffer(DDSCAPS_VIDEOMEMORY, ZBufferDepth(m_assignedDevice))) {
if (!CreateZBuffer(DDSCAPS_VIDEOMEMORY, ZBufferDepth(m_currentDeviceInfo))) {
return FALSE;
}
}
else {
if (m_assignedDevice->m_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) {
if (m_currentDeviceInfo->m_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_PERSPECTIVE) {
m_bTexturesDisabled = FALSE;
}
else {
m_bTexturesDisabled = TRUE;
}
if (!CreateZBuffer(DDSCAPS_SYSTEMMEMORY, ZBufferDepth(m_assignedDevice))) {
if (!CreateZBuffer(DDSCAPS_SYSTEMMEMORY, ZBufferDepth(m_currentDeviceInfo))) {
return FALSE;
}
}
HRESULT result = m_pDirect3d->CreateDevice(m_assignedDevice->m_guid, m_pBackBuffer, &m_pDirect3dDevice);
LPDIRECTDRAWSURFACE backBuf = BackBuffer();
HRESULT result = m_pDirect3d->CreateDevice(m_currentDeviceInfo->m_guid, backBuf, &m_pDirect3dDevice);
if (result != DD_OK) {
Error("Create D3D device failed", result);
return FALSE;
}
DeviceModesInfo::Mode mode = m_currentMode;
DeviceModesInfo::Mode mode = *CurrentMode();
if (IsFullScreen()) {
if (!IsSupportedMode(mode.width, mode.height, mode.bitsPerPixel)) {
@@ -151,8 +172,8 @@ BOOL MxDirect3D::D3DSetMode()
}
}
LPDIRECTDRAWSURFACE frontBuffer = m_pFrontBuffer;
LPDIRECTDRAWSURFACE backBuffer = m_pBackBuffer;
LPDIRECTDRAWSURFACE frontBuffer = FrontBuffer();
LPDIRECTDRAWSURFACE backBuffer = BackBuffer();
DDSURFACEDESC desc;
memset(&desc, 0, sizeof(desc));
@@ -161,7 +182,7 @@ BOOL MxDirect3D::D3DSetMode()
if (backBuffer->Lock(NULL, &desc, DDLOCK_WAIT, NULL) == DD_OK) {
unsigned char* surface = (unsigned char*) desc.lpSurface;
for (int i = mode.height; i > 0; i--) {
for (int i = 0; i < mode.height; i++) {
memset(surface, 0, mode.width * desc.ddpfPixelFormat.dwRGBBitCount / 8);
surface += desc.lPitch;
}
@@ -172,14 +193,14 @@ BOOL MxDirect3D::D3DSetMode()
OutputDebugString("MxDirect3D::D3DSetMode() back lock failed\n");
}
if (m_bFullScreen) {
if (IsFullScreen()) {
memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc);
if (frontBuffer->Lock(NULL, &desc, DDLOCK_WAIT, NULL) == DD_OK) {
unsigned char* surface = (unsigned char*) desc.lpSurface;
for (int i = mode.height; i > 0; i--) {
for (int i = 0; i < mode.height; i++) {
memset(surface, 0, mode.width * desc.ddpfPixelFormat.dwRGBBitCount / 8);
surface += desc.lPitch;
}
@@ -195,6 +216,7 @@ BOOL MxDirect3D::D3DSetMode()
}
// FUNCTION: LEGO1 0x1009b5a0
// FUNCTION: BETA10 0x1011babb
int MxDirect3D::ZBufferDepth(MxAssignedDevice* p_assignedDevice)
{
int depth;
@@ -230,10 +252,10 @@ int MxDirect3D::ZBufferDepth(MxAssignedDevice* p_assignedDevice)
// FUNCTION: BETA10 0x1011bbca
BOOL MxDirect3D::SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_driver, Direct3DDeviceInfo* p_device)
{
if (m_assignedDevice) {
delete m_assignedDevice;
m_assignedDevice = NULL;
m_pCurrentDeviceModesList = NULL;
if (m_currentDeviceInfo) {
delete m_currentDeviceInfo;
m_currentDeviceInfo = NULL;
m_currentDevInfo = NULL;
}
MxAssignedDevice* d = new MxAssignedDevice;
@@ -287,15 +309,15 @@ BOOL MxDirect3D::SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_dri
d->m_desc = device.m_HELDesc;
}
m_assignedDevice = d;
m_pCurrentDeviceModesList = d->m_deviceInfo;
m_currentDeviceInfo = d;
m_currentDevInfo = d->m_deviceInfo;
break;
}
}
}
}
if (!m_assignedDevice) {
if (!m_currentDeviceInfo) {
delete d;
return FALSE;
}