mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 12:31:15 +00:00
Merge branch 'master' into a
This commit is contained in:
commit
a94401b764
@ -84,15 +84,15 @@ if (ISLE_UBSAN)
|
|||||||
add_link_options(-fsanitize=undefined)
|
add_link_options(-fsanitize=undefined)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#if (NOT WIN32)
|
|
||||||
add_library(miniwin STATIC EXCLUDE_FROM_ALL
|
add_library(miniwin STATIC EXCLUDE_FROM_ALL
|
||||||
miniwin/miniwin/src/miniwin.cpp
|
miniwin/miniwin/src/miniwin.cpp
|
||||||
miniwin/miniwin/src/miniwin_ddclipper.cpp
|
|
||||||
miniwin/miniwin/src/miniwin_ddpalette.cpp
|
miniwin/miniwin/src/miniwin_ddpalette.cpp
|
||||||
miniwin/miniwin/src/miniwin_ddsurface.cpp
|
miniwin/miniwin/src/miniwin_ddsurface.cpp
|
||||||
miniwin/miniwin/src/miniwin_ddraw.cpp
|
miniwin/miniwin/src/miniwin_ddraw.cpp
|
||||||
miniwin/miniwin/src/miniwin_d3drm.cpp
|
miniwin/miniwin/src/miniwin_d3drm.cpp
|
||||||
)
|
)
|
||||||
|
# Force reported render mods from MiniWin
|
||||||
|
target_compile_definitions(miniwin PRIVATE MINIWIN_PIXELFORMAT=SDL_PIXELFORMAT_INDEX8)
|
||||||
target_include_directories(miniwin PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/miniwin/miniwin/include>")
|
target_include_directories(miniwin PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/miniwin/miniwin/include>")
|
||||||
target_include_directories(miniwin PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/miniwin/miniwin/src/include")
|
target_include_directories(miniwin PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/miniwin/miniwin/src/include")
|
||||||
target_compile_definitions(miniwin PUBLIC "MINIWIN")
|
target_compile_definitions(miniwin PUBLIC "MINIWIN")
|
||||||
|
|||||||
@ -44,7 +44,7 @@ LegoAnimMMPresenter::~LegoAnimMMPresenter()
|
|||||||
VideoManager()->UnregisterPresenter(*this);
|
VideoManager()->UnregisterPresenter(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_unk0x68;
|
delete[] m_unk0x68;
|
||||||
|
|
||||||
NotificationManager()->Unregister(this);
|
NotificationManager()->Unregister(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ MxControlPresenter::MxControlPresenter()
|
|||||||
MxControlPresenter::~MxControlPresenter()
|
MxControlPresenter::~MxControlPresenter()
|
||||||
{
|
{
|
||||||
if (m_states) {
|
if (m_states) {
|
||||||
delete m_states;
|
delete[] m_states;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -97,7 +97,7 @@ MxResult LegoModelPresenter::CreateROI(MxDSChunk* p_chunk)
|
|||||||
SDL_strlwr(textureName);
|
SDL_strlwr(textureName);
|
||||||
|
|
||||||
if (textureName[0] == '^') {
|
if (textureName[0] == '^') {
|
||||||
strcpy(textureName, textureName + 1);
|
memmove(textureName, textureName + 1, strlen(textureName));
|
||||||
|
|
||||||
if (g_modelPresenterConfig) {
|
if (g_modelPresenterConfig) {
|
||||||
texture = new LegoTexture();
|
texture = new LegoTexture();
|
||||||
|
|||||||
@ -35,7 +35,7 @@ LegoWEGEdge::~LegoWEGEdge()
|
|||||||
delete[] m_edgeNormals;
|
delete[] m_edgeNormals;
|
||||||
}
|
}
|
||||||
if (m_pathTrigger) {
|
if (m_pathTrigger) {
|
||||||
delete m_pathTrigger;
|
delete[] m_pathTrigger;
|
||||||
}
|
}
|
||||||
if (m_unk0x50) {
|
if (m_unk0x50) {
|
||||||
delete m_unk0x50;
|
delete m_unk0x50;
|
||||||
|
|||||||
@ -400,7 +400,7 @@ BOOL MxDirectDraw::DDSetMode(int width, int height, int bpp)
|
|||||||
|
|
||||||
DDSURFACEDESC ddsd;
|
DDSURFACEDESC ddsd;
|
||||||
|
|
||||||
FUN_1009e020();
|
ClearBackBuffers();
|
||||||
|
|
||||||
if (!GetDDSurfaceDesc(&ddsd, m_pBackBuffer)) {
|
if (!GetDDSurfaceDesc(&ddsd, m_pBackBuffer)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -550,7 +550,7 @@ BOOL MxDirectDraw::DDCreateSurfaces()
|
|||||||
|
|
||||||
// FUNCTION: LEGO1 0x1009e020
|
// FUNCTION: LEGO1 0x1009e020
|
||||||
// FUNCTION: BETA10 0x10121700
|
// FUNCTION: BETA10 0x10121700
|
||||||
void MxDirectDraw::FUN_1009e020()
|
void MxDirectDraw::ClearBackBuffers()
|
||||||
{
|
{
|
||||||
HRESULT result;
|
HRESULT result;
|
||||||
byte* line;
|
byte* line;
|
||||||
|
|||||||
@ -85,7 +85,7 @@ class MxDirectDraw {
|
|||||||
void Error(const char* p_message, int p_error);
|
void Error(const char* p_message, int p_error);
|
||||||
|
|
||||||
BOOL RecreateDirectDraw(GUID** a2);
|
BOOL RecreateDirectDraw(GUID** a2);
|
||||||
void FUN_1009e020();
|
void ClearBackBuffers();
|
||||||
void FUN_1009d920();
|
void FUN_1009d920();
|
||||||
|
|
||||||
// SYNTHETIC: LEGO1 0x1009d510
|
// SYNTHETIC: LEGO1 0x1009d510
|
||||||
|
|||||||
@ -136,15 +136,16 @@ void MxSoundManager::AudioStreamCallback(
|
|||||||
int p_totalAmount
|
int p_totalAmount
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
static MxU8 g_buffer[4096];
|
static vector<MxU8> g_buffer;
|
||||||
|
g_buffer.reserve(p_additionalAmount);
|
||||||
|
|
||||||
MxSoundManager* manager = (MxSoundManager*) p_userdata;
|
MxSoundManager* manager = (MxSoundManager*) p_userdata;
|
||||||
ma_uint32 bytesPerFrame = ma_get_bytes_per_frame(ma_format_f32, ma_engine_get_channels(&manager->m_engine));
|
ma_uint32 bytesPerFrame = ma_get_bytes_per_frame(ma_format_f32, ma_engine_get_channels(&manager->m_engine));
|
||||||
ma_uint32 bufferSizeInFrames = (ma_uint32) SDL_min(sizeof(g_buffer), p_additionalAmount) / bytesPerFrame;
|
ma_uint32 bufferSizeInFrames = (ma_uint32) p_additionalAmount / bytesPerFrame;
|
||||||
ma_uint64 framesRead;
|
ma_uint64 framesRead;
|
||||||
|
|
||||||
if (ma_engine_read_pcm_frames(&manager->m_engine, g_buffer, bufferSizeInFrames, &framesRead) == MA_SUCCESS) {
|
if (ma_engine_read_pcm_frames(&manager->m_engine, g_buffer.data(), bufferSizeInFrames, &framesRead) == MA_SUCCESS) {
|
||||||
SDL_PutAudioStreamData(manager->m_stream, g_buffer, framesRead * bytesPerFrame);
|
SDL_PutAudioStreamData(manager->m_stream, g_buffer.data(), framesRead * bytesPerFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ MxFlcPresenter::MxFlcPresenter()
|
|||||||
MxFlcPresenter::~MxFlcPresenter()
|
MxFlcPresenter::~MxFlcPresenter()
|
||||||
{
|
{
|
||||||
if (this->m_flcHeader) {
|
if (this->m_flcHeader) {
|
||||||
delete this->m_flcHeader;
|
delete[] ((MxU8*) this->m_flcHeader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ void MxStillPresenter::Destroy(MxBool p_fromDestructor)
|
|||||||
m_criticalSection.Enter();
|
m_criticalSection.Enter();
|
||||||
|
|
||||||
if (m_bitmapInfo) {
|
if (m_bitmapInfo) {
|
||||||
delete m_bitmapInfo;
|
delete[] ((MxU8*) m_bitmapInfo);
|
||||||
}
|
}
|
||||||
m_bitmapInfo = NULL;
|
m_bitmapInfo = NULL;
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ void MxStillPresenter::Destroy(MxBool p_fromDestructor)
|
|||||||
void MxStillPresenter::LoadHeader(MxStreamChunk* p_chunk)
|
void MxStillPresenter::LoadHeader(MxStreamChunk* p_chunk)
|
||||||
{
|
{
|
||||||
if (m_bitmapInfo) {
|
if (m_bitmapInfo) {
|
||||||
delete m_bitmapInfo;
|
delete[] ((MxU8*) m_bitmapInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
MxU8* data = new MxU8[p_chunk->GetLength()];
|
MxU8* data = new MxU8[p_chunk->GetLength()];
|
||||||
@ -55,7 +55,7 @@ void MxStillPresenter::CreateBitmap()
|
|||||||
m_frameBitmap = new MxBitmap;
|
m_frameBitmap = new MxBitmap;
|
||||||
m_frameBitmap->ImportBitmapInfo(m_bitmapInfo);
|
m_frameBitmap->ImportBitmapInfo(m_bitmapInfo);
|
||||||
|
|
||||||
delete m_bitmapInfo;
|
delete[] ((MxU8*) m_bitmapInfo);
|
||||||
m_bitmapInfo = NULL;
|
m_bitmapInfo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -443,9 +443,9 @@ inline Result ViewRender(IDirect3DRMViewport* pViewport, const IDirect3DRMFrame2
|
|||||||
pViewportAppData->m_backgroundColorGreen,
|
pViewportAppData->m_backgroundColorGreen,
|
||||||
pViewportAppData->m_backgroundColorBlue
|
pViewportAppData->m_backgroundColorBlue
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
assert(Succeeded(result));
|
assert(Succeeded(result));
|
||||||
|
}
|
||||||
|
|
||||||
result = ResultVal(pViewport->Render(const_cast<IDirect3DRMFrame2*>(pGroup)));
|
result = ResultVal(pViewport->Render(const_cast<IDirect3DRMFrame2*>(pGroup)));
|
||||||
assert(Succeeded(result));
|
assert(Succeeded(result));
|
||||||
|
|||||||
@ -29,7 +29,7 @@ To achieve our goal of platform independence, we need to replace any Windows-onl
|
|||||||
| Keyboard/Mouse, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) |
|
| Keyboard/Mouse, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) |
|
||||||
| Joystick/Gamepad, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) |
|
| Joystick/Gamepad, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) |
|
||||||
| WinMM, DirectSound (Audio) | [SDL3](https://www.libsdl.org/), [miniaudio](https://miniaud.io/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aaudio%5D%22&type=code) |
|
| WinMM, DirectSound (Audio) | [SDL3](https://www.libsdl.org/), [miniaudio](https://miniaud.io/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aaudio%5D%22&type=code) |
|
||||||
| DirectDraw (2D video) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A2d%5D%22&type=code) |
|
| DirectDraw (2D video) | [SDL3](https://www.libsdl.org/) | 🚧 | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A2d%5D%22&type=code) |
|
||||||
| [Smacker](https://github.com/isledecomp/isle/tree/master/3rdparty/smacker) | [libsmacker](https://github.com/foxtacles/libsmacker) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable%20%22%2F%2F%20%5Blibrary%3Alibsmacker%5D%22&type=code) |
|
| [Smacker](https://github.com/isledecomp/isle/tree/master/3rdparty/smacker) | [libsmacker](https://github.com/foxtacles/libsmacker) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable%20%22%2F%2F%20%5Blibrary%3Alibsmacker%5D%22&type=code) |
|
||||||
| Direct3D (3D video) | [SDL3](https://www.libsdl.org/), OpenGL ES (**TBD**) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A3d%5D%22&type=code) |
|
| Direct3D (3D video) | [SDL3](https://www.libsdl.org/), OpenGL ES (**TBD**) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A3d%5D%22&type=code) |
|
||||||
| Direct3D Retained Mode | Custom re-implementation (**TBD**) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aretained%5D%22&type=code) |
|
| Direct3D Retained Mode | Custom re-implementation (**TBD**) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aretained%5D%22&type=code) |
|
||||||
|
|||||||
@ -81,7 +81,7 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
int result = wndTop->ExitInstance();
|
int result = wndTop->ExitInstance();
|
||||||
free(afxCurrentAppName);
|
delete[] afxCurrentAppName;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -103,6 +103,8 @@
|
|||||||
DEFINE_GUID(IID_IDirectDraw2, 0xB3A6F3E0, 0x2B43, 0x11CF, 0xA2, 0xDE, 0x00, 0xAA, 0x00, 0xB9, 0x33, 0x56);
|
DEFINE_GUID(IID_IDirectDraw2, 0xB3A6F3E0, 0x2B43, 0x11CF, 0xA2, 0xDE, 0x00, 0xAA, 0x00, 0xB9, 0x33, 0x56);
|
||||||
DEFINE_GUID(IID_IDirectDrawSurface3, 0xDA044E00, 0x69B2, 0x11D0, 0xA1, 0xD5, 0x00, 0xAA, 0x00, 0xB8, 0xDF, 0xBB);
|
DEFINE_GUID(IID_IDirectDrawSurface3, 0xDA044E00, 0x69B2, 0x11D0, 0xA1, 0xD5, 0x00, 0xAA, 0x00, 0xB8, 0xDF, 0xBB);
|
||||||
|
|
||||||
|
extern SDL_Window* DDWindow;
|
||||||
|
|
||||||
// --- Enums ---
|
// --- Enums ---
|
||||||
#define DDCKEY_SRCBLT DDColorKeyFlags::SRCBLT
|
#define DDCKEY_SRCBLT DDColorKeyFlags::SRCBLT
|
||||||
enum class DDColorKeyFlags : uint32_t {
|
enum class DDColorKeyFlags : uint32_t {
|
||||||
@ -292,14 +294,13 @@ typedef LOGPALETTE* LPLOGPALETTE;
|
|||||||
|
|
||||||
typedef struct IDirectDraw* LPDIRECTDRAW;
|
typedef struct IDirectDraw* LPDIRECTDRAW;
|
||||||
struct IDirectDrawPalette : virtual public IUnknown {
|
struct IDirectDrawPalette : virtual public IUnknown {
|
||||||
virtual HRESULT GetCaps(LPDWORD lpdwCaps) = 0;
|
|
||||||
virtual HRESULT GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries) = 0;
|
virtual HRESULT GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries) = 0;
|
||||||
virtual HRESULT SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries) = 0;
|
virtual HRESULT SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries) = 0;
|
||||||
};
|
};
|
||||||
typedef struct IDirectDrawPalette* LPDIRECTDRAWPALETTE;
|
typedef struct IDirectDrawPalette* LPDIRECTDRAWPALETTE;
|
||||||
|
|
||||||
struct IDirectDrawClipper : virtual public IUnknown {
|
struct IDirectDrawClipper : virtual public IUnknown {
|
||||||
virtual HRESULT SetHWnd(DWORD unnamedParam1, HWND hWnd) = 0;
|
virtual HRESULT SetHWnd(DWORD unnamedParam1, HWND hWnd) { return DD_OK; }
|
||||||
};
|
};
|
||||||
typedef IDirectDrawClipper* LPDIRECTDRAWCLIPPER;
|
typedef IDirectDrawClipper* LPDIRECTDRAWCLIPPER;
|
||||||
|
|
||||||
@ -323,9 +324,7 @@ struct IDirectDrawSurface : virtual public IUnknown {
|
|||||||
) = 0;
|
) = 0;
|
||||||
virtual HRESULT Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags) = 0;
|
virtual HRESULT Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags) = 0;
|
||||||
virtual HRESULT GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE* lplpDDAttachedSurface) = 0;
|
virtual HRESULT GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE* lplpDDAttachedSurface) = 0;
|
||||||
virtual HRESULT GetCaps(LPDDSCAPS lpDDSCaps) = 0;
|
|
||||||
virtual HRESULT GetDC(HDC* lphDC) = 0;
|
virtual HRESULT GetDC(HDC* lphDC) = 0;
|
||||||
virtual HRESULT GetOverlayPosition(LPLONG lplX, LPLONG lplY) = 0;
|
|
||||||
virtual HRESULT GetPalette(LPDIRECTDRAWPALETTE* lplpDDPalette) = 0;
|
virtual HRESULT GetPalette(LPDIRECTDRAWPALETTE* lplpDDPalette) = 0;
|
||||||
virtual HRESULT GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat) = 0;
|
virtual HRESULT GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat) = 0;
|
||||||
virtual HRESULT GetSurfaceDesc(LPDDSURFACEDESC lpDDSurfaceDesc) = 0;
|
virtual HRESULT GetSurfaceDesc(LPDDSURFACEDESC lpDDSurfaceDesc) = 0;
|
||||||
|
|||||||
@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#include <miniwin_ddraw.h>
|
|
||||||
|
|
||||||
class DirectDrawImpl;
|
|
||||||
|
|
||||||
struct DirectDrawClipperImpl : public IDirectDrawClipper {
|
|
||||||
DirectDrawClipperImpl(DirectDrawImpl* lpDD);
|
|
||||||
~DirectDrawClipperImpl() override;
|
|
||||||
|
|
||||||
// IDirectDrawClipper interface
|
|
||||||
HRESULT SetHWnd(DWORD unnamedParam1, HWND hWnd) override;
|
|
||||||
};
|
|
||||||
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
struct DirectDrawPaletteImpl : public IDirectDrawPalette {
|
struct DirectDrawPaletteImpl : public IDirectDrawPalette {
|
||||||
DirectDrawPaletteImpl(LPPALETTEENTRY lpColorTable);
|
DirectDrawPaletteImpl(LPPALETTEENTRY lpColorTable);
|
||||||
HRESULT GetCaps(LPDWORD lpdwCaps) override;
|
~DirectDrawPaletteImpl() override;
|
||||||
HRESULT GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries) override;
|
HRESULT GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries) override;
|
||||||
HRESULT SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries) override;
|
HRESULT SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries) override;
|
||||||
|
|
||||||
|
SDL_Palette* m_palette;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,8 +3,6 @@
|
|||||||
#include "miniwin_d3d.h"
|
#include "miniwin_d3d.h"
|
||||||
#include "miniwin_ddraw.h"
|
#include "miniwin_ddraw.h"
|
||||||
|
|
||||||
extern struct SDL_Renderer* renderer;
|
|
||||||
|
|
||||||
struct DirectDrawImpl : public IDirectDraw2, public IDirect3D2 {
|
struct DirectDrawImpl : public IDirectDraw2, public IDirect3D2 {
|
||||||
// IUnknown interface
|
// IUnknown interface
|
||||||
HRESULT QueryInterface(const GUID& riid, void** ppvObject) override;
|
HRESULT QueryInterface(const GUID& riid, void** ppvObject) override;
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
struct DirectDrawSurfaceImpl : public IDirectDrawSurface3 {
|
struct DirectDrawSurfaceImpl : public IDirectDrawSurface3 {
|
||||||
DirectDrawSurfaceImpl();
|
DirectDrawSurfaceImpl();
|
||||||
DirectDrawSurfaceImpl(int width, int height);
|
DirectDrawSurfaceImpl(int width, int height, SDL_PixelFormat format);
|
||||||
~DirectDrawSurfaceImpl() override;
|
~DirectDrawSurfaceImpl() override;
|
||||||
|
|
||||||
// IUnknown interface
|
// IUnknown interface
|
||||||
@ -23,9 +23,7 @@ struct DirectDrawSurfaceImpl : public IDirectDrawSurface3 {
|
|||||||
override;
|
override;
|
||||||
HRESULT Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags) override;
|
HRESULT Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags) override;
|
||||||
HRESULT GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE* lplpDDAttachedSurface) override;
|
HRESULT GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE* lplpDDAttachedSurface) override;
|
||||||
HRESULT GetCaps(LPDDSCAPS lpDDSCaps) override;
|
|
||||||
HRESULT GetDC(HDC* lphDC) override;
|
HRESULT GetDC(HDC* lphDC) override;
|
||||||
HRESULT GetOverlayPosition(LPLONG lplX, LPLONG lplY) override;
|
|
||||||
HRESULT GetPalette(LPDIRECTDRAWPALETTE* lplpDDPalette) override;
|
HRESULT GetPalette(LPDIRECTDRAWPALETTE* lplpDDPalette) override;
|
||||||
HRESULT GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat) override;
|
HRESULT GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat) override;
|
||||||
HRESULT GetSurfaceDesc(LPDDSURFACEDESC lpDDSurfaceDesc) override;
|
HRESULT GetSurfaceDesc(LPDDSURFACEDESC lpDDSurfaceDesc) override;
|
||||||
@ -36,9 +34,11 @@ struct DirectDrawSurfaceImpl : public IDirectDrawSurface3 {
|
|||||||
HRESULT SetClipper(LPDIRECTDRAWCLIPPER lpDDClipper) override;
|
HRESULT SetClipper(LPDIRECTDRAWCLIPPER lpDDClipper) override;
|
||||||
HRESULT SetColorKey(DDColorKeyFlags dwFlags, LPDDCOLORKEY lpDDColorKey) override;
|
HRESULT SetColorKey(DDColorKeyFlags dwFlags, LPDDCOLORKEY lpDDColorKey) override;
|
||||||
HRESULT SetPalette(LPDIRECTDRAWPALETTE lpDDPalette) override;
|
HRESULT SetPalette(LPDIRECTDRAWPALETTE lpDDPalette) override;
|
||||||
|
void SetAutoFlip(bool enabled);
|
||||||
HRESULT Unlock(LPVOID lpSurfaceData) override;
|
HRESULT Unlock(LPVOID lpSurfaceData) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Texture* m_texture = nullptr;
|
bool m_autoFlip = false;
|
||||||
|
SDL_Surface* m_surface = nullptr;
|
||||||
IDirectDrawPalette* m_palette = nullptr;
|
IDirectDrawPalette* m_palette = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -14,12 +14,7 @@
|
|||||||
SDL_LogError(LOG_CATEGORY_MINIWIN, "%s:%s", __func__, MSG); \
|
SDL_LogError(LOG_CATEGORY_MINIWIN, "%s:%s", __func__, MSG); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static SDL_FRect ConvertRect(const RECT* r)
|
static SDL_Rect ConvertRect(const RECT* r)
|
||||||
{
|
{
|
||||||
SDL_FRect sdlRect;
|
return {r->left, r->top, r->right - r->left, r->bottom - r->top};
|
||||||
sdlRect.x = r->left;
|
|
||||||
sdlRect.y = r->top;
|
|
||||||
sdlRect.w = r->right - r->left;
|
|
||||||
sdlRect.h = r->bottom - r->top;
|
|
||||||
return sdlRect;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -197,7 +197,7 @@ struct Direct3DRMMeshImpl : public Direct3DRMObjectBase<IDirect3DRMMesh> {
|
|||||||
{
|
{
|
||||||
if (SDL_memcmp(&iid, &IID_IDirect3DRMMesh, sizeof(GUID)) == 0) {
|
if (SDL_memcmp(&iid, &IID_IDirect3DRMMesh, sizeof(GUID)) == 0) {
|
||||||
*object = static_cast<IDirect3DRMMesh*>(new Direct3DRMMeshImpl);
|
*object = static_cast<IDirect3DRMMesh*>(new Direct3DRMMeshImpl);
|
||||||
return S_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
@ -206,8 +206,7 @@ struct Direct3DRMMeshImpl : public Direct3DRMObjectBase<IDirect3DRMMesh> {
|
|||||||
HRESULT AddGroup(int vertexCount, int faceCount, int vertexPerFace, void* faceBuffer, D3DRMGROUPINDEX* groupIndex)
|
HRESULT AddGroup(int vertexCount, int faceCount, int vertexPerFace, void* faceBuffer, D3DRMGROUPINDEX* groupIndex)
|
||||||
override
|
override
|
||||||
{
|
{
|
||||||
assert(false && "Unimplemented");
|
return DD_OK;
|
||||||
return DDERR_GENERIC;
|
|
||||||
}
|
}
|
||||||
HRESULT GetGroup(
|
HRESULT GetGroup(
|
||||||
int groupIndex,
|
int groupIndex,
|
||||||
@ -236,6 +235,7 @@ struct Direct3DRMMeshImpl : public Direct3DRMObjectBase<IDirect3DRMMesh> {
|
|||||||
if (!m_groupTexture) {
|
if (!m_groupTexture) {
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
|
m_groupTexture->AddRef();
|
||||||
*texture = m_groupTexture;
|
*texture = m_groupTexture;
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
@ -249,6 +249,16 @@ struct Direct3DRMMeshImpl : public Direct3DRMObjectBase<IDirect3DRMMesh> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Direct3DRMTextureImpl : public Direct3DRMObjectBase<IDirect3DRMTexture2> {
|
struct Direct3DRMTextureImpl : public Direct3DRMObjectBase<IDirect3DRMTexture2> {
|
||||||
|
HRESULT QueryInterface(const GUID& riid, void** ppvObject) override
|
||||||
|
{
|
||||||
|
if (SDL_memcmp(&riid, &IID_IDirect3DRMTexture2, sizeof(GUID)) == 0) {
|
||||||
|
this->IUnknown::AddRef();
|
||||||
|
*ppvObject = static_cast<IDirect3DRMTexture2*>(this);
|
||||||
|
return DD_OK;
|
||||||
|
}
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Direct3DRMTextureImpl does not implement guid");
|
||||||
|
return E_NOINTERFACE;
|
||||||
|
}
|
||||||
HRESULT Clone(void** ppObject) override
|
HRESULT Clone(void** ppObject) override
|
||||||
{
|
{
|
||||||
*ppObject = static_cast<void*>(new Direct3DRMTextureImpl);
|
*ppObject = static_cast<void*>(new Direct3DRMTextureImpl);
|
||||||
@ -440,7 +450,7 @@ struct Direct3DRMImpl : virtual public IDirect3DRM2 {
|
|||||||
if (SDL_memcmp(&riid, &IID_IDirect3DRM2, sizeof(GUID)) == 0) {
|
if (SDL_memcmp(&riid, &IID_IDirect3DRM2, sizeof(GUID)) == 0) {
|
||||||
this->IUnknown::AddRef();
|
this->IUnknown::AddRef();
|
||||||
*ppvObject = static_cast<IDirect3DRM2*>(this);
|
*ppvObject = static_cast<IDirect3DRM2*>(this);
|
||||||
return S_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "DirectDrawImpl does not implement guid");
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "DirectDrawImpl does not implement guid");
|
||||||
return E_NOINTERFACE;
|
return E_NOINTERFACE;
|
||||||
@ -450,7 +460,7 @@ struct Direct3DRMImpl : virtual public IDirect3DRM2 {
|
|||||||
override
|
override
|
||||||
{
|
{
|
||||||
*outDevice = static_cast<IDirect3DRMDevice2*>(new Direct3DRMDevice2Impl);
|
*outDevice = static_cast<IDirect3DRMDevice2*>(new Direct3DRMDevice2Impl);
|
||||||
return S_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
HRESULT CreateDeviceFromSurface(
|
HRESULT CreateDeviceFromSurface(
|
||||||
const GUID* guid,
|
const GUID* guid,
|
||||||
@ -460,17 +470,17 @@ struct Direct3DRMImpl : virtual public IDirect3DRM2 {
|
|||||||
) override
|
) override
|
||||||
{
|
{
|
||||||
*outDevice = static_cast<IDirect3DRMDevice2*>(new Direct3DRMDevice2Impl);
|
*outDevice = static_cast<IDirect3DRMDevice2*>(new Direct3DRMDevice2Impl);
|
||||||
return S_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
HRESULT CreateTexture(D3DRMIMAGE* image, IDirect3DRMTexture2** outTexture) override
|
HRESULT CreateTexture(D3DRMIMAGE* image, IDirect3DRMTexture2** outTexture) override
|
||||||
{
|
{
|
||||||
*outTexture = static_cast<IDirect3DRMTexture2*>(new Direct3DRMTextureImpl);
|
*outTexture = static_cast<IDirect3DRMTexture2*>(new Direct3DRMTextureImpl);
|
||||||
return S_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
HRESULT CreateTextureFromSurface(LPDIRECTDRAWSURFACE surface, IDirect3DRMTexture2** outTexture) override
|
HRESULT CreateTextureFromSurface(LPDIRECTDRAWSURFACE surface, IDirect3DRMTexture2** outTexture) override
|
||||||
{
|
{
|
||||||
*outTexture = static_cast<IDirect3DRMTexture2*>(new Direct3DRMTextureImpl);
|
*outTexture = static_cast<IDirect3DRMTexture2*>(new Direct3DRMTextureImpl);
|
||||||
return S_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
HRESULT CreateMesh(IDirect3DRMMesh** outMesh) override
|
HRESULT CreateMesh(IDirect3DRMMesh** outMesh) override
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
#include "miniwin_ddclipper_p.h"
|
|
||||||
#include "miniwin_ddraw_p.h"
|
|
||||||
|
|
||||||
DirectDrawClipperImpl::DirectDrawClipperImpl(DirectDrawImpl* lpDD)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DirectDrawClipperImpl::~DirectDrawClipperImpl()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT DirectDrawClipperImpl::SetHWnd(DWORD unnamedParam1, HWND hWnd)
|
|
||||||
{
|
|
||||||
return DD_OK;
|
|
||||||
}
|
|
||||||
@ -1,21 +1,41 @@
|
|||||||
#include "miniwin_ddpalette_p.h"
|
#include "miniwin_ddpalette_p.h"
|
||||||
#include "miniwin_ddraw.h"
|
#include "miniwin_ddraw.h"
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
DirectDrawPaletteImpl::DirectDrawPaletteImpl(LPPALETTEENTRY lpColorTable)
|
DirectDrawPaletteImpl::DirectDrawPaletteImpl(LPPALETTEENTRY lpColorTable)
|
||||||
{
|
{
|
||||||
|
m_palette = SDL_CreatePalette(256);
|
||||||
|
SetEntries(0, 0, 256, lpColorTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawPaletteImpl::GetCaps(LPDWORD lpdwCaps)
|
DirectDrawPaletteImpl::~DirectDrawPaletteImpl()
|
||||||
{
|
{
|
||||||
return DD_OK;
|
SDL_DestroyPalette(m_palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawPaletteImpl::GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries)
|
HRESULT DirectDrawPaletteImpl::GetEntries(DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries)
|
||||||
{
|
{
|
||||||
|
for (int i = dwBase; i < dwNumEntries; i++) {
|
||||||
|
lpEntries[i].peRed = m_palette->colors[i].r;
|
||||||
|
lpEntries[i].peGreen = m_palette->colors[i].g;
|
||||||
|
lpEntries[i].peBlue = m_palette->colors[i].b;
|
||||||
|
lpEntries[i].peFlags = PC_NONE;
|
||||||
|
}
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawPaletteImpl::SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries)
|
HRESULT DirectDrawPaletteImpl::SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries)
|
||||||
{
|
{
|
||||||
|
SDL_Color colors[256];
|
||||||
|
for (int i = 0; i < dwCount; i++) {
|
||||||
|
colors[i].r = lpEntries[i].peRed;
|
||||||
|
colors[i].g = lpEntries[i].peGreen;
|
||||||
|
colors[i].b = lpEntries[i].peBlue;
|
||||||
|
colors[i].a = SDL_ALPHA_OPAQUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetPaletteColors(m_palette, colors, dwStartingEntry, dwCount);
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
#include "miniwin_d3d.h"
|
#include "miniwin_d3d.h"
|
||||||
#include "miniwin_ddclipper_p.h"
|
|
||||||
#include "miniwin_ddpalette_p.h"
|
#include "miniwin_ddpalette_p.h"
|
||||||
#include "miniwin_ddraw_p.h"
|
#include "miniwin_ddraw_p.h"
|
||||||
#include "miniwin_ddsurface_p.h"
|
#include "miniwin_ddsurface_p.h"
|
||||||
@ -12,7 +11,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
SDL_Renderer* renderer;
|
SDL_Window* DDWindow;
|
||||||
|
|
||||||
HRESULT DirectDrawImpl::QueryInterface(const GUID& riid, void** ppvObject)
|
HRESULT DirectDrawImpl::QueryInterface(const GUID& riid, void** ppvObject)
|
||||||
{
|
{
|
||||||
@ -33,7 +32,7 @@ HRESULT DirectDrawImpl::QueryInterface(const GUID& riid, void** ppvObject)
|
|||||||
// IDirectDraw interface
|
// IDirectDraw interface
|
||||||
HRESULT DirectDrawImpl::CreateClipper(DWORD dwFlags, LPDIRECTDRAWCLIPPER* lplpDDClipper, IUnknown* pUnkOuter)
|
HRESULT DirectDrawImpl::CreateClipper(DWORD dwFlags, LPDIRECTDRAWCLIPPER* lplpDDClipper, IUnknown* pUnkOuter)
|
||||||
{
|
{
|
||||||
*lplpDDClipper = static_cast<IDirectDrawClipper*>(new DirectDrawClipperImpl(this));
|
*lplpDDClipper = new IDirectDrawClipper;
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
@ -45,6 +44,10 @@ HRESULT DirectDrawImpl::CreatePalette(
|
|||||||
IUnknown* pUnkOuter
|
IUnknown* pUnkOuter
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if ((dwFlags & DDPCAPS_8BIT) != DDPCAPS_8BIT) {
|
||||||
|
return DDERR_INVALIDPARAMS;
|
||||||
|
}
|
||||||
|
|
||||||
*lplpDDPalette = static_cast<LPDIRECTDRAWPALETTE>(new DirectDrawPaletteImpl(lpColorTable));
|
*lplpDDPalette = static_cast<LPDIRECTDRAWPALETTE>(new DirectDrawPaletteImpl(lpColorTable));
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
@ -55,6 +58,24 @@ HRESULT DirectDrawImpl::CreateSurface(
|
|||||||
IUnknown* pUnkOuter
|
IUnknown* pUnkOuter
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
SDL_PixelFormat format;
|
||||||
|
#ifdef MINIWIN_PIXELFORMAT
|
||||||
|
format = MINIWIN_PIXELFORMAT;
|
||||||
|
#else
|
||||||
|
format = SDL_PIXELFORMAT_RGBA8888;
|
||||||
|
#endif
|
||||||
|
if ((lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) == DDSD_PIXELFORMAT) {
|
||||||
|
if ((lpDDSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_RGB) == DDPF_RGB) {
|
||||||
|
switch (lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount) {
|
||||||
|
case 8:
|
||||||
|
format = SDL_PIXELFORMAT_INDEX8;
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
format = SDL_PIXELFORMAT_RGB565;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((lpDDSurfaceDesc->dwFlags & DDSD_CAPS) == DDSD_CAPS) {
|
if ((lpDDSurfaceDesc->dwFlags & DDSD_CAPS) == DDSD_CAPS) {
|
||||||
if ((lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER) {
|
if ((lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER) {
|
||||||
if ((lpDDSurfaceDesc->dwFlags & DDSD_ZBUFFERBITDEPTH) != DDSD_ZBUFFERBITDEPTH) {
|
if ((lpDDSurfaceDesc->dwFlags & DDSD_ZBUFFERBITDEPTH) != DDSD_ZBUFFERBITDEPTH) {
|
||||||
@ -69,8 +90,11 @@ HRESULT DirectDrawImpl::CreateSurface(
|
|||||||
SDL_Log("Todo: Switch to %d buffering", lpDDSurfaceDesc->dwBackBufferCount);
|
SDL_Log("Todo: Switch to %d buffering", lpDDSurfaceDesc->dwBackBufferCount);
|
||||||
}
|
}
|
||||||
int width, height;
|
int width, height;
|
||||||
SDL_GetRenderOutputSize(renderer, &width, &height);
|
SDL_GetWindowSize(DDWindow, &width, &height);
|
||||||
*lplpDDSurface = static_cast<IDirectDrawSurface*>(new DirectDrawSurfaceImpl(width, height));
|
bool implicitFlip = (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_FLIP) != DDSCAPS_FLIP;
|
||||||
|
auto frontBuffer = new DirectDrawSurfaceImpl(width, height, format);
|
||||||
|
frontBuffer->SetAutoFlip(implicitFlip);
|
||||||
|
*lplpDDSurface = static_cast<IDirectDrawSurface*>(frontBuffer);
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
if ((lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_OFFSCREENPLAIN) == DDSCAPS_OFFSCREENPLAIN) {
|
if ((lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_OFFSCREENPLAIN) == DDSCAPS_OFFSCREENPLAIN) {
|
||||||
@ -90,19 +114,16 @@ HRESULT DirectDrawImpl::CreateSurface(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) == DDSD_PIXELFORMAT) {
|
|
||||||
if ((lpDDSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_RGB) == DDPF_RGB) {
|
|
||||||
SDL_Log("DDPF_RGB"); // Use dwRGBBitCount to choose the texture format
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((lpDDSurfaceDesc->dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) != (DDSD_WIDTH | DDSD_HEIGHT)) {
|
if ((lpDDSurfaceDesc->dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) != (DDSD_WIDTH | DDSD_HEIGHT)) {
|
||||||
return DDERR_INVALIDPARAMS;
|
return DDERR_INVALIDPARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int width = lpDDSurfaceDesc->dwWidth;
|
int width = lpDDSurfaceDesc->dwWidth;
|
||||||
int height = lpDDSurfaceDesc->dwHeight;
|
int height = lpDDSurfaceDesc->dwHeight;
|
||||||
*lplpDDSurface = static_cast<IDirectDrawSurface*>(new DirectDrawSurfaceImpl(width, height));
|
if (width == 0 || height == 0) {
|
||||||
|
return DDERR_INVALIDPARAMS;
|
||||||
|
}
|
||||||
|
*lplpDDSurface = static_cast<IDirectDrawSurface*>(new DirectDrawSurfaceImpl(width, height, format));
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,11 +145,18 @@ HRESULT DirectDrawImpl::EnumDisplayModes(
|
|||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_PixelFormat format;
|
||||||
HRESULT status = S_OK;
|
HRESULT status = S_OK;
|
||||||
|
|
||||||
for (int i = 0; i < count_modes; i++) {
|
for (int i = 0; i < count_modes; i++) {
|
||||||
const SDL_PixelFormatDetails* format = SDL_GetPixelFormatDetails(modes[i]->format);
|
#ifdef MINIWIN_PIXELFORMAT
|
||||||
if (!format) {
|
format = MINIWIN_PIXELFORMAT;
|
||||||
|
#else
|
||||||
|
format = modes[i]->format;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(format);
|
||||||
|
if (!details) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
DDSURFACEDESC ddsd = {};
|
DDSURFACEDESC ddsd = {};
|
||||||
@ -138,11 +166,13 @@ HRESULT DirectDrawImpl::EnumDisplayModes(
|
|||||||
ddsd.dwHeight = modes[i]->h;
|
ddsd.dwHeight = modes[i]->h;
|
||||||
ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
|
ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
|
||||||
ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
||||||
ddsd.ddpfPixelFormat.dwRGBBitCount =
|
ddsd.ddpfPixelFormat.dwRGBBitCount = details->bits_per_pixel;
|
||||||
(format->bits_per_pixel == 8) ? 8 : 16; // Game only accepts 8 or 16 bit mode
|
if (details->bits_per_pixel == 8) {
|
||||||
ddsd.ddpfPixelFormat.dwRBitMask = format->Rmask;
|
ddsd.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
|
||||||
ddsd.ddpfPixelFormat.dwGBitMask = format->Gmask;
|
}
|
||||||
ddsd.ddpfPixelFormat.dwBBitMask = format->Bmask;
|
ddsd.ddpfPixelFormat.dwRBitMask = details->Rmask;
|
||||||
|
ddsd.ddpfPixelFormat.dwGBitMask = details->Gmask;
|
||||||
|
ddsd.ddpfPixelFormat.dwBBitMask = details->Bmask;
|
||||||
|
|
||||||
if (!lpEnumModesCallback(&ddsd, lpContext)) {
|
if (!lpEnumModesCallback(&ddsd, lpContext)) {
|
||||||
status = DDERR_GENERIC;
|
status = DDERR_GENERIC;
|
||||||
@ -182,6 +212,26 @@ HRESULT DirectDrawImpl::EnumDevices(LPD3DENUMDEVICESCALLBACK cb, void* ctx)
|
|||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DDBitDepths renderBitDepth = DDBD_32;
|
||||||
|
|
||||||
|
#ifdef MINIWIN_PIXELFORMAT
|
||||||
|
SDL_PixelFormat format = MINIWIN_PIXELFORMAT;
|
||||||
|
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(format);
|
||||||
|
switch (details->bits_per_pixel) {
|
||||||
|
case 8:
|
||||||
|
renderBitDepth = DDBD_8;
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
renderBitDepth = DDBD_16;
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
renderBitDepth = DDBD_24;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const char* deviceDesc = "SDL3 SDL_Renderer";
|
const char* deviceDesc = "SDL3 SDL_Renderer";
|
||||||
|
|
||||||
for (int i = 0; i < numDrivers; ++i) {
|
for (int i = 0; i < numDrivers; ++i) {
|
||||||
@ -196,7 +246,7 @@ HRESULT DirectDrawImpl::EnumDevices(LPD3DENUMDEVICESCALLBACK cb, void* ctx)
|
|||||||
halDesc.dcmColorModel = D3DCOLORMODEL::RGB;
|
halDesc.dcmColorModel = D3DCOLORMODEL::RGB;
|
||||||
halDesc.dwFlags = D3DDD_DEVICEZBUFFERBITDEPTH;
|
halDesc.dwFlags = D3DDD_DEVICEZBUFFERBITDEPTH;
|
||||||
halDesc.dwDeviceZBufferBitDepth = DDBD_8 | DDBD_16 | DDBD_24 | DDBD_32;
|
halDesc.dwDeviceZBufferBitDepth = DDBD_8 | DDBD_16 | DDBD_24 | DDBD_32;
|
||||||
halDesc.dwDeviceRenderBitDepth = DDBD_8 | DDBD_16;
|
halDesc.dwDeviceRenderBitDepth = renderBitDepth;
|
||||||
halDesc.dpcTriCaps.dwTextureCaps = D3DPTEXTURECAPS_PERSPECTIVE;
|
halDesc.dpcTriCaps.dwTextureCaps = D3DPTEXTURECAPS_PERSPECTIVE;
|
||||||
halDesc.dpcTriCaps.dwShadeCaps = D3DPSHADECAPS_ALPHAFLATBLEND;
|
halDesc.dpcTriCaps.dwShadeCaps = D3DPSHADECAPS_ALPHAFLATBLEND;
|
||||||
halDesc.dpcTriCaps.dwTextureFilterCaps = D3DPTFILTERCAPS_LINEAR;
|
halDesc.dpcTriCaps.dwTextureFilterCaps = D3DPTFILTERCAPS_LINEAR;
|
||||||
@ -223,16 +273,26 @@ HRESULT DirectDrawImpl::GetDisplayMode(LPDDSURFACEDESC lpDDSurfaceDesc)
|
|||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SDL_PixelFormatDetails* format = SDL_GetPixelFormatDetails(mode->format);
|
SDL_PixelFormat format;
|
||||||
|
#ifdef MINIWIN_PIXELFORMAT
|
||||||
|
format = MINIWIN_PIXELFORMAT;
|
||||||
|
#else
|
||||||
|
format = mode->format;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(format);
|
||||||
|
|
||||||
lpDDSurfaceDesc->dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
|
lpDDSurfaceDesc->dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
|
||||||
lpDDSurfaceDesc->dwWidth = mode->w;
|
lpDDSurfaceDesc->dwWidth = mode->w;
|
||||||
lpDDSurfaceDesc->dwHeight = mode->h;
|
lpDDSurfaceDesc->dwHeight = mode->h;
|
||||||
|
lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = details->bits_per_pixel;
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB;
|
lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB;
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = (format->bits_per_pixel == 8) ? 8 : 16;
|
if (details->bits_per_pixel == 8) {
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = format->Rmask;
|
lpDDSurfaceDesc->ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = format->Gmask;
|
}
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = format->Bmask;
|
lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = details->Rmask;
|
||||||
|
lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = details->Gmask;
|
||||||
|
lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = details->Bmask;
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
@ -259,7 +319,7 @@ HRESULT DirectDrawImpl::SetCooperativeLevel(HWND hWnd, DDSCLFlags dwFlags)
|
|||||||
if (!SDL_SetWindowFullscreen(hWnd, fullscreen)) {
|
if (!SDL_SetWindowFullscreen(hWnd, fullscreen)) {
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
renderer = SDL_CreateRenderer(hWnd, NULL);
|
DDWindow = hWnd;
|
||||||
}
|
}
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
@ -268,6 +328,7 @@ HRESULT DirectDrawImpl::SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBP
|
|||||||
{
|
{
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IDirect3D2 interface
|
// IDirect3D2 interface
|
||||||
HRESULT DirectDrawImpl::CreateDevice(const GUID& guid, void* pBackBuffer, IDirect3DDevice2** ppDirect3DDevice)
|
HRESULT DirectDrawImpl::CreateDevice(const GUID& guid, void* pBackBuffer, IDirect3DDevice2** ppDirect3DDevice)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#include "miniwin_ddpalette_p.h"
|
||||||
#include "miniwin_ddraw_p.h"
|
#include "miniwin_ddraw_p.h"
|
||||||
#include "miniwin_ddsurface_p.h"
|
#include "miniwin_ddsurface_p.h"
|
||||||
#include "miniwin_p.h"
|
#include "miniwin_p.h"
|
||||||
@ -8,18 +9,21 @@ DirectDrawSurfaceImpl::DirectDrawSurfaceImpl()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectDrawSurfaceImpl::DirectDrawSurfaceImpl(int width, int height)
|
DirectDrawSurfaceImpl::DirectDrawSurfaceImpl(int width, int height, SDL_PixelFormat format)
|
||||||
{
|
{
|
||||||
m_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height);
|
m_surface = SDL_CreateSurface(width, height, format);
|
||||||
if (!m_texture) {
|
if (!m_surface) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create texture: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create surface: %s", SDL_GetError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectDrawSurfaceImpl::~DirectDrawSurfaceImpl()
|
DirectDrawSurfaceImpl::~DirectDrawSurfaceImpl()
|
||||||
{
|
{
|
||||||
if (m_texture) {
|
if (m_surface) {
|
||||||
SDL_DestroyTexture(m_texture);
|
SDL_DestroySurface(m_surface);
|
||||||
|
}
|
||||||
|
if (m_palette) {
|
||||||
|
m_palette->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +44,12 @@ HRESULT DirectDrawSurfaceImpl::AddAttachedSurface(LPDIRECTDRAWSURFACE lpDDSAttac
|
|||||||
{
|
{
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DirectDrawSurfaceImpl::SetAutoFlip(bool enabled)
|
||||||
|
{
|
||||||
|
m_autoFlip = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::Blt(
|
HRESULT DirectDrawSurfaceImpl::Blt(
|
||||||
LPRECT lpDestRect,
|
LPRECT lpDestRect,
|
||||||
LPDIRECTDRAWSURFACE lpDDSrcSurface,
|
LPDIRECTDRAWSURFACE lpDDSrcSurface,
|
||||||
@ -48,13 +58,46 @@ HRESULT DirectDrawSurfaceImpl::Blt(
|
|||||||
LPDDBLTFX lpDDBltFx
|
LPDDBLTFX lpDDBltFx
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!renderer) {
|
auto srcSurface = static_cast<DirectDrawSurfaceImpl*>(lpDDSrcSurface);
|
||||||
|
if (!srcSurface || !srcSurface->m_surface) {
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
SDL_FRect srcRect = ConvertRect(lpSrcRect);
|
|
||||||
SDL_FRect dstRect = ConvertRect(lpDestRect);
|
SDL_Rect srcRect;
|
||||||
SDL_RenderTexture(renderer, static_cast<DirectDrawSurfaceImpl*>(lpDDSrcSurface)->m_texture, &srcRect, &dstRect);
|
if (lpSrcRect) {
|
||||||
SDL_RenderPresent(renderer);
|
srcRect = ConvertRect(lpSrcRect);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
srcRect = {0, 0, srcSurface->m_surface->w, srcSurface->m_surface->h};
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Rect dstRect;
|
||||||
|
if (lpDestRect) {
|
||||||
|
dstRect = ConvertRect(lpDestRect);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dstRect = {0, 0, m_surface->w, m_surface->h};
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Surface* blitSource = srcSurface->m_surface;
|
||||||
|
|
||||||
|
if (srcSurface->m_surface->format != m_surface->format) {
|
||||||
|
blitSource = SDL_ConvertSurface(srcSurface->m_surface, m_surface->format);
|
||||||
|
if (!blitSource) {
|
||||||
|
return DDERR_GENERIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SDL_BlitSurfaceScaled(blitSource, &srcRect, m_surface, &dstRect, SDL_SCALEMODE_NEAREST)) {
|
||||||
|
return DDERR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blitSource != srcSurface->m_surface) {
|
||||||
|
SDL_DestroySurface(blitSource);
|
||||||
|
}
|
||||||
|
if (m_autoFlip) {
|
||||||
|
return Flip(nullptr, DDFLIP_WAIT);
|
||||||
|
}
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,31 +109,29 @@ HRESULT DirectDrawSurfaceImpl::BltFast(
|
|||||||
DDBltFastFlags dwTrans
|
DDBltFastFlags dwTrans
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!renderer) {
|
RECT destRect = {
|
||||||
return DDERR_GENERIC;
|
(int) dwX,
|
||||||
}
|
(int) dwY,
|
||||||
SDL_FRect dstRect = {
|
(int) (lpSrcRect->right - lpSrcRect->left + dwX),
|
||||||
(float) dwX,
|
(int) (lpSrcRect->bottom - lpSrcRect->top + dwY)
|
||||||
(float) dwY,
|
|
||||||
(float) (lpSrcRect->right - lpSrcRect->left),
|
|
||||||
(float) (lpSrcRect->bottom - lpSrcRect->top)
|
|
||||||
};
|
};
|
||||||
SDL_FRect srcRect = ConvertRect(lpSrcRect);
|
return Blt(&destRect, lpDDSrcSurface, lpSrcRect, DDBLT_NONE, nullptr);
|
||||||
SDL_RenderTexture(renderer, static_cast<DirectDrawSurfaceImpl*>(lpDDSrcSurface)->m_texture, &srcRect, &dstRect);
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
return DD_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags)
|
HRESULT DirectDrawSurfaceImpl::Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags)
|
||||||
{
|
{
|
||||||
if (!renderer || !m_texture) {
|
if (!m_surface) {
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
float width, height;
|
SDL_Surface* windowSurface = SDL_GetWindowSurface(DDWindow);
|
||||||
SDL_GetTextureSize(m_texture, &width, &height);
|
if (!windowSurface) {
|
||||||
SDL_FRect rect{0, 0, width, height};
|
return DDERR_GENERIC;
|
||||||
SDL_RenderTexture(renderer, m_texture, &rect, &rect);
|
}
|
||||||
SDL_RenderPresent(renderer);
|
SDL_Rect srcRect{0, 0, m_surface->w, m_surface->h};
|
||||||
|
SDL_Surface* copy = SDL_ConvertSurface(m_surface, windowSurface->format);
|
||||||
|
SDL_BlitSurface(copy, &srcRect, windowSurface, &srcRect);
|
||||||
|
SDL_DestroySurface(copy);
|
||||||
|
SDL_UpdateWindowSurface(DDWindow);
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,21 +144,11 @@ HRESULT DirectDrawSurfaceImpl::GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTD
|
|||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::GetCaps(LPDDSCAPS lpDDSCaps)
|
|
||||||
{
|
|
||||||
return DD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::GetDC(HDC* lphDC)
|
HRESULT DirectDrawSurfaceImpl::GetDC(HDC* lphDC)
|
||||||
{
|
{
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::GetOverlayPosition(LPLONG lplX, LPLONG lplY)
|
|
||||||
{
|
|
||||||
return DD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::GetPalette(LPDIRECTDRAWPALETTE* lplpDDPalette)
|
HRESULT DirectDrawSurfaceImpl::GetPalette(LPDIRECTDRAWPALETTE* lplpDDPalette)
|
||||||
{
|
{
|
||||||
if (!m_palette) {
|
if (!m_palette) {
|
||||||
@ -130,22 +161,34 @@ HRESULT DirectDrawSurfaceImpl::GetPalette(LPDIRECTDRAWPALETTE* lplpDDPalette)
|
|||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat)
|
HRESULT DirectDrawSurfaceImpl::GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat)
|
||||||
{
|
{
|
||||||
|
if (!m_surface) {
|
||||||
|
return DDERR_GENERIC;
|
||||||
|
}
|
||||||
memset(lpDDPixelFormat, 0, sizeof(*lpDDPixelFormat));
|
memset(lpDDPixelFormat, 0, sizeof(*lpDDPixelFormat));
|
||||||
lpDDPixelFormat->dwFlags = DDPF_RGB;
|
lpDDPixelFormat->dwFlags = DDPF_RGB;
|
||||||
|
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(m_surface->format);
|
||||||
|
if (details->bits_per_pixel == 8) {
|
||||||
|
lpDDPixelFormat->dwFlags |= DDPF_PALETTEINDEXED8;
|
||||||
|
}
|
||||||
|
lpDDPixelFormat->dwRGBBitCount = details->bits_per_pixel;
|
||||||
|
lpDDPixelFormat->dwRBitMask = details->Rmask;
|
||||||
|
lpDDPixelFormat->dwGBitMask = details->Gmask;
|
||||||
|
lpDDPixelFormat->dwBBitMask = details->Bmask;
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::GetSurfaceDesc(LPDDSURFACEDESC lpDDSurfaceDesc)
|
HRESULT DirectDrawSurfaceImpl::GetSurfaceDesc(LPDDSURFACEDESC lpDDSurfaceDesc)
|
||||||
{
|
{
|
||||||
if (!m_texture) {
|
if (!m_surface) {
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
const SDL_PixelFormatDetails* format = SDL_GetPixelFormatDetails(m_texture->format);
|
lpDDSurfaceDesc->dwFlags = DDSD_PIXELFORMAT;
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB;
|
GetPixelFormat(&lpDDSurfaceDesc->ddpfPixelFormat);
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = (format->bits_per_pixel == 8) ? 8 : 16;
|
if (m_surface) {
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = format->Rmask;
|
lpDDSurfaceDesc->dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = format->Gmask;
|
lpDDSurfaceDesc->dwWidth = m_surface->w;
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = format->Bmask;
|
lpDDSurfaceDesc->dwHeight = m_surface->h;
|
||||||
|
}
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +196,7 @@ HRESULT DirectDrawSurfaceImpl::IsLost()
|
|||||||
{
|
{
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::Lock(
|
HRESULT DirectDrawSurfaceImpl::Lock(
|
||||||
LPRECT lpDestRect,
|
LPRECT lpDestRect,
|
||||||
LPDDSURFACEDESC lpDDSurfaceDesc,
|
LPDDSURFACEDESC lpDDSurfaceDesc,
|
||||||
@ -160,24 +204,17 @@ HRESULT DirectDrawSurfaceImpl::Lock(
|
|||||||
HANDLE hEvent
|
HANDLE hEvent
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!m_texture) {
|
if (!m_surface) {
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pitch = 0;
|
if (SDL_LockSurface(m_surface) < 0) {
|
||||||
void* pixels = nullptr;
|
|
||||||
if (SDL_LockTexture(m_texture, (SDL_Rect*) lpDestRect, &pixels, &pitch) < 0) {
|
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
lpDDSurfaceDesc->lpSurface = pixels;
|
GetSurfaceDesc(lpDDSurfaceDesc);
|
||||||
lpDDSurfaceDesc->lPitch = pitch;
|
lpDDSurfaceDesc->lpSurface = m_surface->pixels;
|
||||||
const SDL_PixelFormatDetails* format = SDL_GetPixelFormatDetails(m_texture->format);
|
lpDDSurfaceDesc->lPitch = m_surface->pitch;
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB;
|
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = (format->bits_per_pixel == 8) ? 8 : 16;
|
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = format->Rmask;
|
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = format->Gmask;
|
|
||||||
lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = format->Bmask;
|
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
@ -199,19 +236,41 @@ HRESULT DirectDrawSurfaceImpl::SetClipper(LPDIRECTDRAWCLIPPER lpDDClipper)
|
|||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::SetColorKey(DDColorKeyFlags dwFlags, LPDDCOLORKEY lpDDColorKey)
|
HRESULT DirectDrawSurfaceImpl::SetColorKey(DDColorKeyFlags dwFlags, LPDDCOLORKEY lpDDColorKey)
|
||||||
{
|
{
|
||||||
|
if (!lpDDColorKey) {
|
||||||
|
return DDERR_INVALIDPARAMS;
|
||||||
|
}
|
||||||
|
if (m_surface->format != SDL_PIXELFORMAT_INDEX8) {
|
||||||
|
return DDERR_GENERIC; // Not currently supported
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDL_SetSurfaceColorKey(m_surface, true, lpDDColorKey->dwColorSpaceLowValue) != 0) {
|
||||||
|
return DDERR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::SetPalette(LPDIRECTDRAWPALETTE lpDDPalette)
|
HRESULT DirectDrawSurfaceImpl::SetPalette(LPDIRECTDRAWPALETTE lpDDPalette)
|
||||||
{
|
{
|
||||||
|
if (m_surface->format != SDL_PIXELFORMAT_INDEX8) {
|
||||||
|
return DDERR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_palette) {
|
||||||
|
m_palette->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_palette = lpDDPalette;
|
||||||
|
SDL_SetSurfacePalette(m_surface, ((DirectDrawPaletteImpl*) m_palette)->m_palette);
|
||||||
|
m_palette->AddRef();
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DirectDrawSurfaceImpl::Unlock(LPVOID lpSurfaceData)
|
HRESULT DirectDrawSurfaceImpl::Unlock(LPVOID lpSurfaceData)
|
||||||
{
|
{
|
||||||
if (!m_texture) {
|
if (!m_surface) {
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
SDL_UnlockTexture(m_texture);
|
SDL_UnlockSurface(m_surface);
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user