diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index fba03b68..a5edd95b 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -94,7 +94,7 @@ IsleApp::IsleApp() m_cdPath = NULL; m_deviceId = NULL; m_savePath = NULL; - m_fullScreen = FALSE; + m_fullScreen = TRUE; m_flipSurfaces = FALSE; m_backBuffersInVram = TRUE; m_using8bit = FALSE; @@ -378,7 +378,6 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) // [library:window] // Remaining functionality to be implemented: - // Full screen - crashes when minimizing/maximizing, but this will probably be fixed once DirectDraw is replaced // WM_TIMER - use SDL_Timer functionality instead #ifdef __EMSCRIPTEN__ @@ -387,6 +386,17 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) static bool detectedTouchEvents = false; #endif + switch (event->type) { + case SDL_EVENT_MOUSE_MOTION: + case SDL_EVENT_MOUSE_BUTTON_DOWN: + case SDL_EVENT_MOUSE_BUTTON_UP: + IDirect3DRMMiniwinDevice* device = GetD3DRMMiniwinDevice(); + if (device && !device->ConvertEventToRenderCoordinates(event)) { + SDL_Log("Failed to convert event coordinates: %s", SDL_GetError()); + } + break; + } + switch (event->type) { case SDL_EVENT_WINDOW_FOCUS_GAINED: if (!IsleDebug_Enabled()) { diff --git a/LEGO1/mxdirectx/legodxinfo.cpp b/LEGO1/mxdirectx/legodxinfo.cpp index 4121e9a9..38ced82d 100644 --- a/LEGO1/mxdirectx/legodxinfo.cpp +++ b/LEGO1/mxdirectx/legodxinfo.cpp @@ -284,11 +284,6 @@ int LegoDeviceEnumerate::FUN_1009d210() } for (list::iterator it = m_list.begin(); it != m_list.end();) { - if (!DriverSupportsRequiredDisplayMode(*it)) { - m_list.erase(it++); - continue; - } - MxDriver& driver = *it; for (list::iterator it2 = driver.m_devices.begin(); it2 != driver.m_devices.end();) { @@ -315,27 +310,6 @@ int LegoDeviceEnumerate::FUN_1009d210() return 0; } -// FUNCTION: CONFIG 0x00402b00 -// FUNCTION: LEGO1 0x1009d370 -// FUNCTION: BETA10 0x1011d176 -unsigned char LegoDeviceEnumerate::DriverSupportsRequiredDisplayMode(MxDriver& p_driver) -{ -#ifdef __EMSCRIPTEN__ - return true; -#endif - - for (list::iterator it = p_driver.m_displayModes.begin(); it != p_driver.m_displayModes.end(); - it++) { - if ((*it).m_width == 640 && (*it).m_height == 480) { - if ((*it).m_bitsPerPixel == 8 || (*it).m_bitsPerPixel == 16) { - return TRUE; - } - } - } - - return FALSE; -} - // FUNCTION: CONFIG 0x00402b60 // FUNCTION: LEGO1 0x1009d3d0 // FUNCTION: BETA10 0x1011d235 diff --git a/LEGO1/mxdirectx/legodxinfo.h b/LEGO1/mxdirectx/legodxinfo.h index 0cc81adb..d94aaaff 100644 --- a/LEGO1/mxdirectx/legodxinfo.h +++ b/LEGO1/mxdirectx/legodxinfo.h @@ -18,7 +18,6 @@ class LegoDeviceEnumerate : public MxDeviceEnumerate { static bool SupportsSIMD(); static bool SupportsCPUID(); int FUN_1009d210(); - unsigned char DriverSupportsRequiredDisplayMode(MxDriver& p_driver); unsigned char FUN_1009d3d0(Direct3DDeviceInfo& p_device); // SYNTHETIC: BETA10 0x100d8d10 diff --git a/LEGO1/mxdirectx/mxdirect3d.cpp b/LEGO1/mxdirectx/mxdirect3d.cpp index d0e0f94d..f9e0f74d 100644 --- a/LEGO1/mxdirectx/mxdirect3d.cpp +++ b/LEGO1/mxdirectx/mxdirect3d.cpp @@ -167,14 +167,6 @@ BOOL MxDirect3D::D3DSetMode() } DeviceModesInfo::Mode mode = *CurrentMode(); - - if (IsFullScreen()) { - if (!IsSupportedMode(mode.width, mode.height, mode.bitsPerPixel)) { - Error("This device cannot support the current display mode", DDERR_GENERIC); - return FALSE; - } - } - LPDIRECTDRAWSURFACE frontBuffer = FrontBuffer(); LPDIRECTDRAWSURFACE backBuffer = BackBuffer(); @@ -277,21 +269,6 @@ BOOL MxDirect3D::SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_dri *d->m_deviceInfo->m_guid = *driver.m_guid; } - d->m_deviceInfo->m_count = driver.m_displayModes.size(); - - if (d->m_deviceInfo->m_count > 0) { - int j = 0; - d->m_deviceInfo->m_modeArray = new DeviceModesInfo::Mode[d->m_deviceInfo->m_count]; - - for (list::iterator it2 = driver.m_displayModes.begin(); - it2 != driver.m_displayModes.end(); - it2++, j++) { - d->m_deviceInfo->m_modeArray[j].width = (*it2).m_width; - d->m_deviceInfo->m_modeArray[j].height = (*it2).m_height; - d->m_deviceInfo->m_modeArray[j].bitsPerPixel = (*it2).m_bitsPerPixel; - } - } - d->m_deviceInfo->m_ddcaps = driver.m_ddCaps; if (i == 0) { diff --git a/LEGO1/mxdirectx/mxdirectdraw.cpp b/LEGO1/mxdirectx/mxdirectdraw.cpp index 40c353ed..6f3dfd78 100644 --- a/LEGO1/mxdirectx/mxdirectdraw.cpp +++ b/LEGO1/mxdirectx/mxdirectdraw.cpp @@ -283,23 +283,6 @@ BOOL MxDirectDraw::DDInit(BOOL fullscreen) return TRUE; } -// FUNCTION: LEGO1 0x1009d9d0 -// FUNCTION: BETA10 0x10120e45 -BOOL MxDirectDraw::IsSupportedMode(int width, int height, int bpp) -{ - DeviceModesInfo::Mode mode = {width, height, bpp}; - - assert(m_currentDevInfo); - - for (int i = 0; i < m_currentDevInfo->m_count; i++) { - if (m_currentDevInfo->m_modeArray[i] == mode) { - return TRUE; - } - } - - return FALSE; -} - // FUNCTION: LEGO1 0x1009da20 // FUNCTION: BETA10 0x10120efb void EnableResizing(HWND p_hwnd, BOOL p_flag) @@ -339,12 +322,6 @@ BOOL MxDirectDraw::DDSetMode(int width, int height, int bpp) } #endif - if (!IsSupportedMode(width, height, bpp)) { - width = m_currentDevInfo->m_modeArray[0].width; - height = m_currentDevInfo->m_modeArray[0].height; - bpp = m_currentDevInfo->m_modeArray[0].bitsPerPixel; - } - m_bIgnoreWMSIZE = TRUE; result = m_pDirectDraw->SetDisplayMode(width, height, bpp); m_bIgnoreWMSIZE = FALSE; diff --git a/LEGO1/mxdirectx/mxdirectdraw.h b/LEGO1/mxdirectx/mxdirectdraw.h index b430751c..574f8e54 100644 --- a/LEGO1/mxdirectx/mxdirectdraw.h +++ b/LEGO1/mxdirectx/mxdirectdraw.h @@ -55,8 +55,6 @@ class MxDirectDraw { // FUNCTION: BETA10 0x1011c170 BOOL IsFullScreen() { return m_bFullScreen; } - BOOL IsSupportedMode(int width, int height, int bpp); - int Pause(BOOL); BOOL RestoreSurfaces(); diff --git a/LEGO1/mxdirectx/mxdirectxinfo.cpp b/LEGO1/mxdirectx/mxdirectxinfo.cpp index f2d32e9c..c5100031 100644 --- a/LEGO1/mxdirectx/mxdirectxinfo.cpp +++ b/LEGO1/mxdirectx/mxdirectxinfo.cpp @@ -216,7 +216,6 @@ BOOL MxDeviceEnumerate::EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc BuildErrorString("DirectDraw Create failed: %s\n", EnumerateErrorToString(result)); } else { - lpDD->EnumDisplayModes(0, NULL, this, DisplayModesEnumerateCallback); newDevice.m_ddCaps.dwSize = sizeof(newDevice.m_ddCaps); result = lpDD->GetCaps(&newDevice.m_ddCaps, NULL); @@ -267,18 +266,6 @@ void MxDeviceEnumerate::BuildErrorString(const char* p_format, ...) va_end(args); } -// FUNCTION: CONFIG 0x00401bf0 -// FUNCTION: LEGO1 0x1009c4f0 -// FUNCTION: BETA10 0x1011e1dd -HRESULT CALLBACK MxDeviceEnumerate::DisplayModesEnumerateCallback(LPDDSURFACEDESC p_ddsd, LPVOID p_context) -{ - if (p_context == NULL) { - assert(0); - } - - return ((MxDeviceEnumerate*) p_context)->EnumDisplayModesCallback(p_ddsd); -} - // FUNCTION: CONFIG 0x00401c10 // FUNCTION: LEGO1 0x1009c510 // FUNCTION: BETA10 0x1011e226 @@ -299,20 +286,6 @@ HRESULT CALLBACK MxDeviceEnumerate::DevicesEnumerateCallback( ->EnumDevicesCallback(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc); } -// FUNCTION: CONFIG 0x00401c40 -// FUNCTION: LEGO1 0x1009c540 -// FUNCTION: BETA10 0x1011e27f -HRESULT MxDeviceEnumerate::EnumDisplayModesCallback(LPDDSURFACEDESC p_ddsd) -{ - assert(m_list.size() > 0); - assert(p_ddsd); - - // TODO: compat_mode? - MxDisplayMode displayMode(p_ddsd->dwWidth, p_ddsd->dwHeight, p_ddsd->ddpfPixelFormat.dwRGBBitCount); - m_list.back().m_displayModes.push_back(displayMode); - return DDENUMRET_OK; -} - // FUNCTION: CONFIG 0x00401cd0 // FUNCTION: LEGO1 0x1009c5d0 // FUNCTION: BETA10 0x1011e32f @@ -582,8 +555,4 @@ DeviceModesInfo::~DeviceModesInfo() if (m_guid != NULL) { delete m_guid; } - - if (m_modeArray != NULL) { - delete[] m_modeArray; - } } diff --git a/LEGO1/mxdirectx/mxdirectxinfo.h b/LEGO1/mxdirectx/mxdirectxinfo.h index 3b3c0600..a4ebef91 100644 --- a/LEGO1/mxdirectx/mxdirectxinfo.h +++ b/LEGO1/mxdirectx/mxdirectxinfo.h @@ -28,11 +28,10 @@ struct DeviceModesInfo { DeviceModesInfo(); ~DeviceModesInfo(); - GUID* m_guid; // 0x00 - Mode* m_modeArray; // 0x04 - int m_count; // 0x08 - DDCAPS m_ddcaps; // 0x0c - void* m_unk0x178; // 0x178 + GUID* m_guid; // 0x00 + int m_count; // 0x08 + DDCAPS m_ddcaps; // 0x0c + void* m_unk0x178; // 0x178 // SYNTHETIC: BETA10 0x1011c650 // DeviceModesInfo::`scalar deleting destructor' @@ -128,7 +127,6 @@ struct MxDriver { char* m_driverName; // 0x08 DDCAPS m_ddCaps; // 0x0c list m_devices; // 0x178 - list m_displayModes; // 0x184 int operator==(MxDriver) const { return 0; } int operator<(MxDriver) const { return 0; } @@ -199,7 +197,6 @@ class MxDeviceEnumerate { virtual int DoEnumerate(); // vtable+0x00 BOOL EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName); - HRESULT EnumDisplayModesCallback(LPDDSURFACEDESC p_ddsd); HRESULT EnumDevicesCallback( LPGUID p_guid, LPCSTR p_deviceDesc, @@ -211,7 +208,6 @@ class MxDeviceEnumerate { static void BuildErrorString(const char*, ...); static BOOL CALLBACK DirectDrawEnumerateCallback(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName, LPVOID p_context); - static HRESULT CALLBACK DisplayModesEnumerateCallback(LPDDSURFACEDESC p_ddsd, LPVOID p_context); static HRESULT CALLBACK DevicesEnumerateCallback( LPGUID p_guid, LPSTR p_deviceDesc, diff --git a/miniwin/include/miniwin/miniwindevice.h b/miniwin/include/miniwin/miniwindevice.h index 032e776d..2434175f 100644 --- a/miniwin/include/miniwin/miniwindevice.h +++ b/miniwin/include/miniwin/miniwindevice.h @@ -3,6 +3,7 @@ DEFINE_GUID(IID_IDirect3DRMMiniwinDevice, 0x6eb09673, 0x8d30, 0x4d8a, 0x8d, 0x81, 0x34, 0xea, 0x69, 0x30, 0x12, 0x01); struct IDirect3DRMMiniwinDevice : virtual public IUnknown { + virtual bool ConvertEventToRenderCoordinates(SDL_Event* event) = 0; virtual float GetShininessFactor() = 0; virtual HRESULT SetShininessFactor(float factor) = 0; }; diff --git a/miniwin/src/d3drm/d3drmdevice.cpp b/miniwin/src/d3drm/d3drmdevice.cpp index 2000cf56..58ff7c2c 100644 --- a/miniwin/src/d3drm/d3drmdevice.cpp +++ b/miniwin/src/d3drm/d3drmdevice.cpp @@ -144,6 +144,11 @@ float Direct3DRMDevice2Impl::GetShininessFactor() return m_renderer->GetShininessFactor(); } +bool Direct3DRMDevice2Impl::ConvertEventToRenderCoordinates(SDL_Event* event) +{ + return m_renderer->ConvertEventToRenderCoordinates(event); +} + HRESULT Direct3DRMDevice2Impl::SetShininessFactor(float factor) { return m_renderer->SetShininessFactor(factor); diff --git a/miniwin/src/ddraw/ddraw.cpp b/miniwin/src/ddraw/ddraw.cpp index 80fa2d73..6842c7ac 100644 --- a/miniwin/src/ddraw/ddraw.cpp +++ b/miniwin/src/ddraw/ddraw.cpp @@ -17,6 +17,9 @@ SDL_Window* DDWindow; SDL_Surface* DDBackBuffer; +SDL_Texture* HWBackBuffer; +SDL_PixelFormat HWBackBufferFormat; +SDL_Renderer* DDRenderer; HRESULT DirectDrawImpl::QueryInterface(const GUID& riid, void** ppvObject) { @@ -302,6 +305,8 @@ HRESULT DirectDrawImpl::SetCooperativeLevel(HWND hWnd, DDSCLFlags dwFlags) return DDERR_GENERIC; } DDWindow = sdlWindow; + DDRenderer = SDL_CreateRenderer(DDWindow, NULL); + SDL_SetRenderLogicalPresentation(DDRenderer, 640, 480, SDL_LOGICAL_PRESENTATION_LETTERBOX); } return DD_OK; } diff --git a/miniwin/src/ddraw/ddsurface.cpp b/miniwin/src/ddraw/ddsurface.cpp index 5c8ee6db..7a767e87 100644 --- a/miniwin/src/ddraw/ddsurface.cpp +++ b/miniwin/src/ddraw/ddsurface.cpp @@ -55,6 +55,31 @@ static SDL_Rect ConvertRect(const RECT* r) return {r->left, r->top, r->right - r->left, r->bottom - r->top}; } +bool SetupHWBackBuffer() +{ + HWBackBuffer = SDL_CreateTextureFromSurface(DDRenderer, DDBackBuffer); + if (!HWBackBuffer) { + return false; + } + + SDL_PropertiesID props = SDL_GetTextureProperties(HWBackBuffer); + if (!props) { + SDL_DestroyTexture(HWBackBuffer); + HWBackBuffer = nullptr; + return false; + } + + HWBackBufferFormat = + (SDL_PixelFormat) SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN); + if (HWBackBufferFormat == SDL_PIXELFORMAT_UNKNOWN) { + SDL_DestroyTexture(HWBackBuffer); + HWBackBuffer = nullptr; + return false; + } + + return true; +} + HRESULT DirectDrawSurfaceImpl::Blt( LPRECT lpDestRect, LPDIRECTDRAWSURFACE lpDDSrcSurface, @@ -69,6 +94,9 @@ HRESULT DirectDrawSurfaceImpl::Blt( } if (m_autoFlip) { DDBackBuffer = srcSurface->m_surface; + if (!HWBackBuffer && !SetupHWBackBuffer()) { + return DDERR_GENERIC; + } return Flip(nullptr, DDFLIP_WAIT); } @@ -126,18 +154,15 @@ HRESULT DirectDrawSurfaceImpl::BltFast( HRESULT DirectDrawSurfaceImpl::Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags) { - if (!DDBackBuffer) { + if (!DDBackBuffer || !DDRenderer) { return DDERR_GENERIC; } - SDL_Surface* windowSurface = SDL_GetWindowSurface(DDWindow); - if (!windowSurface) { - return DDERR_GENERIC; - } - SDL_Rect srcRect{0, 0, DDBackBuffer->w, DDBackBuffer->h}; - SDL_Surface* copy = SDL_ConvertSurface(DDBackBuffer, windowSurface->format); - SDL_BlitSurface(copy, &srcRect, windowSurface, &srcRect); + + SDL_Surface* copy = SDL_ConvertSurface(DDBackBuffer, HWBackBufferFormat); + SDL_UpdateTexture(HWBackBuffer, nullptr, copy->pixels, copy->pitch); SDL_DestroySurface(copy); - SDL_UpdateWindowSurface(DDWindow); + SDL_RenderTexture(DDRenderer, HWBackBuffer, nullptr, nullptr); + SDL_RenderPresent(DDRenderer); return DD_OK; } @@ -147,6 +172,9 @@ HRESULT DirectDrawSurfaceImpl::GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTD return DDERR_INVALIDPARAMS; } DDBackBuffer = m_surface; + if (!SetupHWBackBuffer()) { + return DDERR_GENERIC; + } *lplpDDAttachedSurface = static_cast(this); return DD_OK; } diff --git a/miniwin/src/internal/d3drmdevice_impl.h b/miniwin/src/internal/d3drmdevice_impl.h index e96bcd43..5b902ef6 100644 --- a/miniwin/src/internal/d3drmdevice_impl.h +++ b/miniwin/src/internal/d3drmdevice_impl.h @@ -33,6 +33,7 @@ struct Direct3DRMDevice2Impl : public Direct3DRMObjectBaseImpl