Skip to content

Commit df92fd0

Browse files
committed
Implement the Load() function
1 parent 454e093 commit df92fd0

File tree

3 files changed

+107
-5
lines changed

3 files changed

+107
-5
lines changed

Dllmain/BuildNo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILD_NUMBER 6663
1+
#define BUILD_NUMBER 6664

ddraw/IDirect3DDeviceX.cpp

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,68 @@ HRESULT m_IDirect3DDeviceX::Load(LPDIRECTDRAWSURFACE7 lpDestTex, LPPOINT lpDestP
439439

440440
if (Config.Dd7to9)
441441
{
442-
LOG_LIMIT(100, __FUNCTION__ << " Not Implemented");
443-
return DDERR_UNSUPPORTED;
442+
if (!lpDestTex || !lpSrcTex)
443+
{
444+
return DDERR_INVALIDPARAMS;
445+
}
446+
447+
// ToDo: support the following dwFlags:
448+
// DDSCAPS2_CUBEMAP_ALLFACES - All faces should be loaded with the image data within the source texture.
449+
// DDSCAPS2_CUBEMAP_NEGATIVEX, DDSCAPS2_CUBEMAP_NEGATIVEY, or DDSCAPS2_CUBEMAP_NEGATIVEZ
450+
// The negative x, y, or z faces should receive the image data.
451+
// DDSCAPS2_CUBEMAP_POSITIVEX, DDSCAPS2_CUBEMAP_POSITIVEY, or DDSCAPS2_CUBEMAP_POSITIVEZ
452+
// The positive x, y, or z faces should receive the image data.
453+
454+
if (dwFlags)
455+
{
456+
LOG_LIMIT(100, __FUNCTION__ << " Warning: flags not supported. dwFlags: " << Logging::hex(dwFlags));
457+
}
458+
459+
// ToDo: check if source and destination surfaces are valid
460+
461+
if (!lprcSrcRect && (!lpDestPoint || (lpDestPoint && lpDestPoint->x == 0 && lpDestPoint->y == 0)))
462+
{
463+
return lpDestTex->Blt(nullptr, lpSrcTex, nullptr, 0, nullptr);
464+
}
465+
else
466+
{
467+
// Get source rect
468+
RECT SrcRect = {};
469+
if (lprcSrcRect)
470+
{
471+
SrcRect = *lprcSrcRect;
472+
}
473+
else
474+
{
475+
DDSURFACEDESC2 Desc2 = {};
476+
Desc2.dwSize = sizeof(DDSURFACEDESC2);
477+
lpSrcTex->GetSurfaceDesc(&Desc2);
478+
479+
if ((Desc2.dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) != (DDSD_WIDTH | DDSD_HEIGHT))
480+
{
481+
return DDERR_GENERIC;
482+
}
483+
484+
SrcRect = { 0, 0, (LONG)Desc2.dwWidth, (LONG)Desc2.dwHeight };
485+
}
486+
487+
// Get destination point
488+
POINT DestPoint = {};
489+
if (lpDestPoint)
490+
{
491+
DestPoint = *lpDestPoint;
492+
}
493+
494+
// Get destination rect
495+
RECT DestRect = {
496+
DestPoint.x, // left
497+
DestPoint.y, // top
498+
DestPoint.x + (SrcRect.right - SrcRect.left), // right
499+
DestPoint.y + (SrcRect.bottom - SrcRect.top), // bottom
500+
};
501+
502+
return lpDestTex->Blt(&DestRect, lpSrcTex, &SrcRect, 0, nullptr);
503+
}
444504
}
445505

446506
if (lpDestTex)

ddraw/IDirect3DTextureX.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,50 @@ HRESULT m_IDirect3DTextureX::Load(LPDIRECT3DTEXTURE2 lpD3DTexture2)
208208

209209
if (!ProxyInterface)
210210
{
211-
LOG_LIMIT(100, __FUNCTION__ << " Not Implemented");
212-
return DDERR_UNSUPPORTED;
211+
if (lpD3DTexture2)
212+
{
213+
return DDERR_INVALIDPARAMS;
214+
}
215+
216+
if (!D3DDeviceInterface)
217+
{
218+
LOG_LIMIT(100, __FUNCTION__ << " Error: D3DDevice does not exist!");
219+
return DDERR_GENERIC;
220+
}
221+
222+
if (!DDrawSurface)
223+
{
224+
LOG_LIMIT(100, __FUNCTION__ << " Error: surface is not attached!");
225+
return DDERR_GENERIC;
226+
}
227+
228+
m_IDirect3DTextureX* pSrcTextureX = nullptr;
229+
lpD3DTexture2->QueryInterface(IID_GetInterfaceX, (LPVOID*)&pSrcTextureX);
230+
231+
if (!pSrcTextureX)
232+
{
233+
LOG_LIMIT(100, __FUNCTION__ << " Error: could not get texture wrapper!");
234+
return DDERR_GENERIC;
235+
}
236+
237+
m_IDirectDrawSurfaceX* pSrcSurfaceX = pSrcTextureX->GetSurface();
238+
if (!pSrcSurfaceX)
239+
{
240+
LOG_LIMIT(100, __FUNCTION__ << " Error: could not get surface!");
241+
return DDERR_GENERIC;
242+
}
243+
244+
IDirectDrawSurface7* pSrcSurface7 = (IDirectDrawSurface7*)pSrcSurfaceX->GetWrapperInterfaceX(7);
245+
IDirectDrawSurface7* pDestSurface7 = (IDirectDrawSurface7*)DDrawSurface->GetWrapperInterfaceX(7);
246+
247+
if (!pDestSurface7 || !pSrcSurface7)
248+
{
249+
LOG_LIMIT(100, __FUNCTION__ << " Error: could not get v7 surface interface!");
250+
return DDERR_GENERIC;
251+
}
252+
253+
POINT Point = {};
254+
return (*D3DDeviceInterface)->Load(pDestSurface7, &Point, pSrcSurface7, nullptr, 0);
213255
}
214256

215257
if (lpD3DTexture2)

0 commit comments

Comments
 (0)