mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-01 03:21:15 +00:00
Use SDL_Surface instead of SDL_Texture (#103)
This commit is contained in:
parent
80f5e15cbf
commit
d1e3a69141
@ -84,7 +84,6 @@ 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_ddpalette.cpp
|
miniwin/miniwin/src/miniwin_ddpalette.cpp
|
||||||
@ -92,6 +91,8 @@ add_library(miniwin STATIC EXCLUDE_FROM_ALL
|
|||||||
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")
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -8,6 +8,5 @@ struct DirectDrawPaletteImpl : public IDirectDrawPalette {
|
|||||||
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;
|
||||||
|
|
||||||
private:
|
|
||||||
SDL_Palette* m_palette;
|
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
|
||||||
@ -34,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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,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)
|
||||||
{
|
{
|
||||||
@ -58,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) {
|
||||||
@ -72,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) {
|
||||||
@ -93,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,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 = {};
|
||||||
@ -141,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;
|
||||||
@ -185,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) {
|
||||||
@ -199,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;
|
||||||
@ -226,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;
|
||||||
}
|
}
|
||||||
@ -262,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,18 @@ 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) {
|
if (m_palette) {
|
||||||
m_palette->Release();
|
m_palette->Release();
|
||||||
@ -43,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,
|
||||||
@ -51,25 +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;
|
||||||
}
|
}
|
||||||
auto srcSurface = static_cast<DirectDrawSurfaceImpl*>(lpDDSrcSurface);
|
|
||||||
SDL_FRect srcRect, dstRect;
|
SDL_Rect srcRect;
|
||||||
if (lpSrcRect) {
|
if (lpSrcRect) {
|
||||||
srcRect = ConvertRect(lpSrcRect);
|
srcRect = ConvertRect(lpSrcRect);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
srcRect = {0, 0, (float) srcSurface->m_texture->w, (float) srcSurface->m_texture->h};
|
srcRect = {0, 0, srcSurface->m_surface->w, srcSurface->m_surface->h};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_Rect dstRect;
|
||||||
if (lpDestRect) {
|
if (lpDestRect) {
|
||||||
dstRect = ConvertRect(lpDestRect);
|
dstRect = ConvertRect(lpDestRect);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dstRect = {0, 0, (float) m_texture->w, (float) m_texture->h};
|
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);
|
||||||
}
|
}
|
||||||
SDL_RenderTexture(renderer, srcSurface->m_texture, &srcRect, &dstRect);
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,32 +109,29 @@ HRESULT DirectDrawSurfaceImpl::BltFast(
|
|||||||
DDBltFastFlags dwTrans
|
DDBltFastFlags dwTrans
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!renderer) {
|
RECT destRect = {
|
||||||
return DDERR_GENERIC;
|
(int) dwX,
|
||||||
}
|
(int) dwY,
|
||||||
auto srcSurface = static_cast<DirectDrawSurfaceImpl*>(lpDDSrcSurface);
|
(int) (lpSrcRect->right - lpSrcRect->left + dwX),
|
||||||
SDL_FRect srcRect;
|
(int) (lpSrcRect->bottom - lpSrcRect->top + dwY)
|
||||||
if (lpSrcRect) {
|
};
|
||||||
srcRect = ConvertRect(lpSrcRect);
|
return Blt(&destRect, lpDDSrcSurface, lpSrcRect, DDBLT_NONE, nullptr);
|
||||||
}
|
|
||||||
else {
|
|
||||||
srcRect = {0, 0, (float) srcSurface->m_texture->w, (float) srcSurface->m_texture->h};
|
|
||||||
}
|
|
||||||
SDL_FRect dstRect = {(float) dwX, (float) dwY, srcRect.w, srcRect.h};
|
|
||||||
SDL_RenderTexture(renderer, srcSurface->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_FRect rect{0, 0, (float) m_texture->w, (float) m_texture->h};
|
if (!windowSurface) {
|
||||||
SDL_RenderTexture(renderer, m_texture, &rect, &rect);
|
return DDERR_GENERIC;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,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;
|
||||||
}
|
}
|
||||||
@ -211,16 +241,25 @@ HRESULT DirectDrawSurfaceImpl::SetColorKey(DDColorKeyFlags dwFlags, LPDDCOLORKEY
|
|||||||
|
|
||||||
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;
|
m_palette = lpDDPalette;
|
||||||
|
SDL_SetSurfacePalette(m_surface, ((DirectDrawPaletteImpl*) m_palette)->m_palette);
|
||||||
m_palette->AddRef();
|
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