1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00
DDrawCompat/DDrawCompat/DDraw/Surfaces/PalettizedTexture.cpp
2022-09-27 21:45:20 +02:00

78 lines
2.9 KiB
C++

#include <memory>
#include <Common/Log.h>
#include <D3dDdi/Device.h>
#include <D3dDdi/FormatInfo.h>
#include <D3dDdi/Resource.h>
#include <DDraw/DirectDrawSurface.h>
#include <DDraw/Surfaces/PalettizedTexture.h>
#include <DDraw/Surfaces/PalettizedTextureImpl.h>
namespace DDraw
{
template <typename TDirectDraw, typename TSurface, typename TSurfaceDesc>
HRESULT PalettizedTexture::create(CompatRef<TDirectDraw> dd, TSurfaceDesc desc, TSurface*& surface)
{
LOG_FUNC("PalettizedTexture::create", &dd, desc, surface);
DDSURFACEDESC d = {};
memcpy(&d, &desc, sizeof(d));
d.dwSize = sizeof(d);
auto dd1(CompatPtr<IDirectDraw>::from(&dd));
CompatPtr<IDirectDrawSurface> palettizedSurface;
HRESULT result = Surface::create<IDirectDraw>(*dd1, d, palettizedSurface.getRef(),
std::make_unique<DDraw::Surface>(desc.ddsCaps.dwCaps));
if (FAILED(result))
{
return LOG_RESULT(result);
}
auto privateData(std::make_unique<PalettizedTexture>(desc.ddsCaps.dwCaps));
auto data = privateData.get();
data->m_palettizedSurface = palettizedSurface;
desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS |
(desc.dwFlags & (DDSD_CKSRCBLT | DDSD_CKDESTBLT));
desc.ddpfPixelFormat = D3dDdi::getPixelFormat(D3DDDIFMT_A8R8G8B8);
desc.ddsCaps = {};
desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY;
result = Surface::create(dd, desc, surface, std::move(privateData));
if (FAILED(result))
{
return LOG_RESULT(result);
}
auto palettizedResource = D3dDdi::Device::findResource(
DDraw::DirectDrawSurface::getDriverResourceHandle(*data->m_palettizedSurface));
auto paletteResolvedResource = D3dDdi::Device::findResource(
DDraw::DirectDrawSurface::getDriverResourceHandle(*surface));
paletteResolvedResource->setPalettizedTexture(*palettizedResource);
return LOG_RESULT(DD_OK);
}
template HRESULT PalettizedTexture::create(
CompatRef<IDirectDraw> dd, DDSURFACEDESC desc, IDirectDrawSurface*& surface);
template HRESULT PalettizedTexture::create(
CompatRef<IDirectDraw2> dd, DDSURFACEDESC desc, IDirectDrawSurface*& surface);
template HRESULT PalettizedTexture::create(
CompatRef<IDirectDraw4> dd, DDSURFACEDESC2 desc, IDirectDrawSurface4*& surface);
template HRESULT PalettizedTexture::create(
CompatRef<IDirectDraw7> dd, DDSURFACEDESC2 desc, IDirectDrawSurface7*& surface);
PalettizedTexture::~PalettizedTexture()
{
LOG_FUNC("PalettizedTexture::~PalettizedTexture", this);
}
void PalettizedTexture::createImpl()
{
m_impl.reset(new PalettizedTextureImpl<IDirectDrawSurface>(*this, m_palettizedSurface));
m_impl2.reset(new PalettizedTextureImpl<IDirectDrawSurface2>(*this, m_palettizedSurface));
m_impl3.reset(new PalettizedTextureImpl<IDirectDrawSurface3>(*this, m_palettizedSurface));
m_impl4.reset(new PalettizedTextureImpl<IDirectDrawSurface4>(*this, m_palettizedSurface));
m_impl7.reset(new PalettizedTextureImpl<IDirectDrawSurface7>(*this, m_palettizedSurface));
}
}