mirror of
https://github.com/isledecomp/isle-portable.git
synced 2025-09-24 04:26:55 -04: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)
|
||||
endif()
|
||||
|
||||
#if (NOT WIN32)
|
||||
add_library(miniwin STATIC EXCLUDE_FROM_ALL
|
||||
miniwin/miniwin/src/miniwin.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_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 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/miniwin/miniwin/src/include")
|
||||
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_IDirectDrawSurface3, 0xDA044E00, 0x69B2, 0x11D0, 0xA1, 0xD5, 0x00, 0xAA, 0x00, 0xB8, 0xDF, 0xBB);
|
||||
|
||||
extern SDL_Window* DDWindow;
|
||||
|
||||
// --- Enums ---
|
||||
#define DDCKEY_SRCBLT DDColorKeyFlags::SRCBLT
|
||||
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 SetEntries(DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries) override;
|
||||
|
||||
private:
|
||||
SDL_Palette* m_palette;
|
||||
};
|
||||
|
@ -3,8 +3,6 @@
|
||||
#include "miniwin_d3d.h"
|
||||
#include "miniwin_ddraw.h"
|
||||
|
||||
extern struct SDL_Renderer* renderer;
|
||||
|
||||
struct DirectDrawImpl : public IDirectDraw2, public IDirect3D2 {
|
||||
// IUnknown interface
|
||||
HRESULT QueryInterface(const GUID& riid, void** ppvObject) override;
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
struct DirectDrawSurfaceImpl : public IDirectDrawSurface3 {
|
||||
DirectDrawSurfaceImpl();
|
||||
DirectDrawSurfaceImpl(int width, int height);
|
||||
DirectDrawSurfaceImpl(int width, int height, SDL_PixelFormat format);
|
||||
~DirectDrawSurfaceImpl() override;
|
||||
|
||||
// IUnknown interface
|
||||
@ -34,9 +34,11 @@ struct DirectDrawSurfaceImpl : public IDirectDrawSurface3 {
|
||||
HRESULT SetClipper(LPDIRECTDRAWCLIPPER lpDDClipper) override;
|
||||
HRESULT SetColorKey(DDColorKeyFlags dwFlags, LPDDCOLORKEY lpDDColorKey) override;
|
||||
HRESULT SetPalette(LPDIRECTDRAWPALETTE lpDDPalette) override;
|
||||
void SetAutoFlip(bool enabled);
|
||||
HRESULT Unlock(LPVOID lpSurfaceData) override;
|
||||
|
||||
private:
|
||||
SDL_Texture* m_texture = nullptr;
|
||||
bool m_autoFlip = false;
|
||||
SDL_Surface* m_surface = nullptr;
|
||||
IDirectDrawPalette* m_palette = nullptr;
|
||||
};
|
||||
|
@ -14,12 +14,7 @@
|
||||
SDL_LogError(LOG_CATEGORY_MINIWIN, "%s:%s", __func__, MSG); \
|
||||
} while (0)
|
||||
|
||||
static SDL_FRect ConvertRect(const RECT* r)
|
||||
static SDL_Rect ConvertRect(const RECT* r)
|
||||
{
|
||||
SDL_FRect sdlRect;
|
||||
sdlRect.x = r->left;
|
||||
sdlRect.y = r->top;
|
||||
sdlRect.w = r->right - r->left;
|
||||
sdlRect.h = r->bottom - r->top;
|
||||
return sdlRect;
|
||||
return {r->left, r->top, r->right - r->left, r->bottom - r->top};
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
SDL_Renderer* renderer;
|
||||
SDL_Window* DDWindow;
|
||||
|
||||
HRESULT DirectDrawImpl::QueryInterface(const GUID& riid, void** ppvObject)
|
||||
{
|
||||
@ -58,6 +58,24 @@ HRESULT DirectDrawImpl::CreateSurface(
|
||||
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->ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER) {
|
||||
if ((lpDDSurfaceDesc->dwFlags & DDSD_ZBUFFERBITDEPTH) != DDSD_ZBUFFERBITDEPTH) {
|
||||
@ -72,8 +90,11 @@ HRESULT DirectDrawImpl::CreateSurface(
|
||||
SDL_Log("Todo: Switch to %d buffering", lpDDSurfaceDesc->dwBackBufferCount);
|
||||
}
|
||||
int width, height;
|
||||
SDL_GetRenderOutputSize(renderer, &width, &height);
|
||||
*lplpDDSurface = static_cast<IDirectDrawSurface*>(new DirectDrawSurfaceImpl(width, height));
|
||||
SDL_GetWindowSize(DDWindow, &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;
|
||||
}
|
||||
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)) {
|
||||
return DDERR_INVALIDPARAMS;
|
||||
}
|
||||
|
||||
int width = lpDDSurfaceDesc->dwWidth;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -127,11 +145,18 @@ HRESULT DirectDrawImpl::EnumDisplayModes(
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
|
||||
SDL_PixelFormat format;
|
||||
HRESULT status = S_OK;
|
||||
|
||||
for (int i = 0; i < count_modes; i++) {
|
||||
const SDL_PixelFormatDetails* format = SDL_GetPixelFormatDetails(modes[i]->format);
|
||||
if (!format) {
|
||||
#ifdef MINIWIN_PIXELFORMAT
|
||||
format = MINIWIN_PIXELFORMAT;
|
||||
#else
|
||||
format = modes[i]->format;
|
||||
#endif
|
||||
|
||||
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(format);
|
||||
if (!details) {
|
||||
continue;
|
||||
}
|
||||
DDSURFACEDESC ddsd = {};
|
||||
@ -141,11 +166,13 @@ HRESULT DirectDrawImpl::EnumDisplayModes(
|
||||
ddsd.dwHeight = modes[i]->h;
|
||||
ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
|
||||
ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
||||
ddsd.ddpfPixelFormat.dwRGBBitCount =
|
||||
(format->bits_per_pixel == 8) ? 8 : 16; // Game only accepts 8 or 16 bit mode
|
||||
ddsd.ddpfPixelFormat.dwRBitMask = format->Rmask;
|
||||
ddsd.ddpfPixelFormat.dwGBitMask = format->Gmask;
|
||||
ddsd.ddpfPixelFormat.dwBBitMask = format->Bmask;
|
||||
ddsd.ddpfPixelFormat.dwRGBBitCount = details->bits_per_pixel;
|
||||
if (details->bits_per_pixel == 8) {
|
||||
ddsd.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
|
||||
}
|
||||
ddsd.ddpfPixelFormat.dwRBitMask = details->Rmask;
|
||||
ddsd.ddpfPixelFormat.dwGBitMask = details->Gmask;
|
||||
ddsd.ddpfPixelFormat.dwBBitMask = details->Bmask;
|
||||
|
||||
if (!lpEnumModesCallback(&ddsd, lpContext)) {
|
||||
status = DDERR_GENERIC;
|
||||
@ -185,6 +212,26 @@ HRESULT DirectDrawImpl::EnumDevices(LPD3DENUMDEVICESCALLBACK cb, void* ctx)
|
||||
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";
|
||||
|
||||
for (int i = 0; i < numDrivers; ++i) {
|
||||
@ -199,7 +246,7 @@ HRESULT DirectDrawImpl::EnumDevices(LPD3DENUMDEVICESCALLBACK cb, void* ctx)
|
||||
halDesc.dcmColorModel = D3DCOLORMODEL::RGB;
|
||||
halDesc.dwFlags = D3DDD_DEVICEZBUFFERBITDEPTH;
|
||||
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.dwShadeCaps = D3DPSHADECAPS_ALPHAFLATBLEND;
|
||||
halDesc.dpcTriCaps.dwTextureFilterCaps = D3DPTFILTERCAPS_LINEAR;
|
||||
@ -226,16 +273,26 @@ HRESULT DirectDrawImpl::GetDisplayMode(LPDDSURFACEDESC lpDDSurfaceDesc)
|
||||
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->dwWidth = mode->w;
|
||||
lpDDSurfaceDesc->dwHeight = mode->h;
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = details->bits_per_pixel;
|
||||
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;
|
||||
if (details->bits_per_pixel == 8) {
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8;
|
||||
}
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = details->Rmask;
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = details->Gmask;
|
||||
lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = details->Bmask;
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
@ -262,7 +319,7 @@ HRESULT DirectDrawImpl::SetCooperativeLevel(HWND hWnd, DDSCLFlags dwFlags)
|
||||
if (!SDL_SetWindowFullscreen(hWnd, fullscreen)) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
renderer = SDL_CreateRenderer(hWnd, NULL);
|
||||
DDWindow = hWnd;
|
||||
}
|
||||
return DD_OK;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "miniwin_ddpalette_p.h"
|
||||
#include "miniwin_ddraw_p.h"
|
||||
#include "miniwin_ddsurface_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);
|
||||
if (!m_texture) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create texture: %s", SDL_GetError());
|
||||
m_surface = SDL_CreateSurface(width, height, format);
|
||||
if (!m_surface) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create surface: %s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
DirectDrawSurfaceImpl::~DirectDrawSurfaceImpl()
|
||||
{
|
||||
if (m_texture) {
|
||||
SDL_DestroyTexture(m_texture);
|
||||
if (m_surface) {
|
||||
SDL_DestroySurface(m_surface);
|
||||
}
|
||||
if (m_palette) {
|
||||
m_palette->Release();
|
||||
@ -43,6 +44,12 @@ HRESULT DirectDrawSurfaceImpl::AddAttachedSurface(LPDIRECTDRAWSURFACE lpDDSAttac
|
||||
{
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
void DirectDrawSurfaceImpl::SetAutoFlip(bool enabled)
|
||||
{
|
||||
m_autoFlip = enabled;
|
||||
}
|
||||
|
||||
HRESULT DirectDrawSurfaceImpl::Blt(
|
||||
LPRECT lpDestRect,
|
||||
LPDIRECTDRAWSURFACE lpDDSrcSurface,
|
||||
@ -51,25 +58,46 @@ HRESULT DirectDrawSurfaceImpl::Blt(
|
||||
LPDDBLTFX lpDDBltFx
|
||||
)
|
||||
{
|
||||
if (!renderer) {
|
||||
auto srcSurface = static_cast<DirectDrawSurfaceImpl*>(lpDDSrcSurface);
|
||||
if (!srcSurface || !srcSurface->m_surface) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
auto srcSurface = static_cast<DirectDrawSurfaceImpl*>(lpDDSrcSurface);
|
||||
SDL_FRect srcRect, dstRect;
|
||||
|
||||
SDL_Rect srcRect;
|
||||
if (lpSrcRect) {
|
||||
srcRect = ConvertRect(lpSrcRect);
|
||||
}
|
||||
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) {
|
||||
dstRect = ConvertRect(lpDestRect);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -81,32 +109,29 @@ HRESULT DirectDrawSurfaceImpl::BltFast(
|
||||
DDBltFastFlags dwTrans
|
||||
)
|
||||
{
|
||||
if (!renderer) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
auto srcSurface = static_cast<DirectDrawSurfaceImpl*>(lpDDSrcSurface);
|
||||
SDL_FRect srcRect;
|
||||
if (lpSrcRect) {
|
||||
srcRect = ConvertRect(lpSrcRect);
|
||||
}
|
||||
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;
|
||||
RECT destRect = {
|
||||
(int) dwX,
|
||||
(int) dwY,
|
||||
(int) (lpSrcRect->right - lpSrcRect->left + dwX),
|
||||
(int) (lpSrcRect->bottom - lpSrcRect->top + dwY)
|
||||
};
|
||||
return Blt(&destRect, lpDDSrcSurface, lpSrcRect, DDBLT_NONE, nullptr);
|
||||
}
|
||||
|
||||
HRESULT DirectDrawSurfaceImpl::Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags)
|
||||
{
|
||||
if (!renderer || !m_texture) {
|
||||
if (!m_surface) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
float width, height;
|
||||
SDL_FRect rect{0, 0, (float) m_texture->w, (float) m_texture->h};
|
||||
SDL_RenderTexture(renderer, m_texture, &rect, &rect);
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_Surface* windowSurface = SDL_GetWindowSurface(DDWindow);
|
||||
if (!windowSurface) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -136,22 +161,34 @@ HRESULT DirectDrawSurfaceImpl::GetPalette(LPDIRECTDRAWPALETTE* lplpDDPalette)
|
||||
|
||||
HRESULT DirectDrawSurfaceImpl::GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat)
|
||||
{
|
||||
if (!m_surface) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
memset(lpDDPixelFormat, 0, sizeof(*lpDDPixelFormat));
|
||||
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;
|
||||
}
|
||||
|
||||
HRESULT DirectDrawSurfaceImpl::GetSurfaceDesc(LPDDSURFACEDESC lpDDSurfaceDesc)
|
||||
{
|
||||
if (!m_texture) {
|
||||
if (!m_surface) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
const SDL_PixelFormatDetails* format = SDL_GetPixelFormatDetails(m_texture->format);
|
||||
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;
|
||||
lpDDSurfaceDesc->dwFlags = DDSD_PIXELFORMAT;
|
||||
GetPixelFormat(&lpDDSurfaceDesc->ddpfPixelFormat);
|
||||
if (m_surface) {
|
||||
lpDDSurfaceDesc->dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
|
||||
lpDDSurfaceDesc->dwWidth = m_surface->w;
|
||||
lpDDSurfaceDesc->dwHeight = m_surface->h;
|
||||
}
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
@ -167,24 +204,17 @@ HRESULT DirectDrawSurfaceImpl::Lock(
|
||||
HANDLE hEvent
|
||||
)
|
||||
{
|
||||
if (!m_texture) {
|
||||
if (!m_surface) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
|
||||
int pitch = 0;
|
||||
void* pixels = nullptr;
|
||||
if (SDL_LockTexture(m_texture, (SDL_Rect*) lpDestRect, &pixels, &pitch) < 0) {
|
||||
if (SDL_LockSurface(m_surface) < 0) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
|
||||
lpDDSurfaceDesc->lpSurface = pixels;
|
||||
lpDDSurfaceDesc->lPitch = pitch;
|
||||
const SDL_PixelFormatDetails* format = SDL_GetPixelFormatDetails(m_texture->format);
|
||||
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;
|
||||
GetSurfaceDesc(lpDDSurfaceDesc);
|
||||
lpDDSurfaceDesc->lpSurface = m_surface->pixels;
|
||||
lpDDSurfaceDesc->lPitch = m_surface->pitch;
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
@ -211,16 +241,25 @@ HRESULT DirectDrawSurfaceImpl::SetColorKey(DDColorKeyFlags dwFlags, LPDDCOLORKEY
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
HRESULT DirectDrawSurfaceImpl::Unlock(LPVOID lpSurfaceData)
|
||||
{
|
||||
if (!m_texture) {
|
||||
if (!m_surface) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
SDL_UnlockTexture(m_texture);
|
||||
SDL_UnlockSurface(m_surface);
|
||||
return DD_OK;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user