18#define RENDERER_E_NOT_IN_GDI_MODE static_cast<HRESULT>(0x88762711)
21#define RENDERER_E_OUT_OF_MEMORY static_cast<HRESULT>(0x88762714)
24#define RENDERER_E_NOT_CREATED static_cast<HRESULT>(0x88762712)
27#define RENDERER_E_NOT_READY static_cast<HRESULT>(0x88762713)
30#define WM_RENDERER_CREATED 0xbd0
33#define WM_RENDERER_DESTROYING 0xbd1
36#define WM_RENDERER_IS_READY 0x7e8
39#define WM_RENDERER_GET 0x7e9
42#define WM_RENDERER_GET_BACK_BUFFER 0x7ea
45#define RENDERER_STATE_READY 0x1f
48#define DIRECTDRAW_DRIVER_USABLE 0x1
51#define DIRECTDRAW_DRIVER_PRIMARY 0x2
65 int nDisplayModeCount;
88 void FlushDirectDrawModeEnumerationList();
105 int FlushDirect3DDeviceList();
122 return static_cast<unsigned>(nDisplayModeCount);
126 return pDisplayModesHead;
153 memset(&hardwareCaps, 0,
sizeof(hardwareCaps));
154 hardwareCaps.dwSize =
sizeof(hardwareCaps);
155 memset(&softwareCaps, 0,
sizeof(softwareCaps));
156 softwareCaps.dwSize =
sizeof(softwareCaps);
157 nDisplayModeCount = 0;
158 pDisplayModesHead =
nullptr;
159 pDisplayModesTail =
nullptr;
161 pD3DDevicesHead =
nullptr;
162 pD3DDevicesTail =
nullptr;
297 char *pszDescription;
301 int nTextureFormatCount;
312 void FlushTextureFormatList();
321 return &hardwareDesc;
325 return &softwareDesc;
363 : pszDescription(nullptr), pszName(nullptr), nTextureFormatCount(0),
364 pTextureFormatsHead(nullptr), pTextureFormatsTail(nullptr), pPrev(nullptr),
372 memset(&hardwareDesc, 0,
sizeof(hardwareDesc));
373 hardwareDesc.dwSize =
sizeof(hardwareDesc);
374 memset(&softwareDesc, 0,
sizeof(softwareDesc));
375 softwareDesc.dwSize =
sizeof(softwareDesc);
390 LPSTR pszNewDescription,
435 int GetSurfaceDescBitDepth();
461 memset(&desc, 0,
sizeof(desc));
462 desc.dwSize =
sizeof(desc);
515 desc.dcvDiffuse.r = red;
516 desc.dcvDiffuse.g = green;
517 desc.dcvDiffuse.b = blue;
523 desc.dwRampSize = size;
529 return pMaterial->SetMaterial(&desc);
564 [[maybe_unused]]
unsigned char abUnknown10[0x10];
605 IDirect3DDevice2 *pDevice,
void *pImage,
int nWidth,
int nHeight,
int nPixelFormatId);
654 [[maybe_unused]]
int anUnknown0[2];
659 [[maybe_unused]]
int nUnknown18;
660 int dwRenderStateFlags;
662 int nGdiModeRefCount;
663 [[maybe_unused]]
int nUnknown28;
672 unsigned nPaletteEntryCount;
679 [[maybe_unused]]
int anUnknown68[4];
683 inline void RecordDisplayMode(
int nWidth,
int nHeight,
int nBitDepth);
693 int DestroyDirectDrawRendererObjects();
705 HRESULT InitializeDirectDraw();
715 HRESULT SelectDriverDeviceAndMode();
723 HRESULT CreateDirectDrawObjects();
731 int ReleaseDirectDrawObjects();
755 int RestoreDisplayMode();
763 HRESULT CreatePrimaryFlipChain();
771 HRESULT InitializePrimaryPalette();
779 int ReleasePrimarySurface();
787 int ReleasePrimaryPalette();
795 HRESULT InitializeRenderDevice();
803 HRESULT CreateAndAttachViewport();
811 HRESULT InitializeViewportAndRenderContext();
820 int DestroyD3DDevice();
828 int ReleaseViewportAndMaterial();
836 HRESULT RestoreGdiPaletteAndFlipToGdi();
844 HRESULT RestoreGamePaletteEntries();
869 return dwRenderStateFlags;
873 return nGdiModeRefCount;
897 return pPrimarySurface;
946 void *pSurfaceFormat,
1049 HRESULT ValidateObjectRenderResources();
1101 const char *pszImage,
1102 unsigned nImageKey);
1211 void *pSurfaceFormat,
1252 void *pSurfaceFormat,
1352 LPSTR pszDescription,
1369 LPSTR pszDescription,
A Direct3D device of a driver.
Definition renderer.h:293
HRESULT InitD3DDeviceNode(GUID *pGuid, LPSTR pszNewDescription, LPSTR pszNewName, D3DDEVICEDESC *pHardwareDesc, D3DDEVICEDESC *pSoftwareDesc)
Read a device Direct3D reports.
bool IsHardwareDevice()
Whether the device is a device of the hardware, one with a colour model of its own.
D3DDeviceNode * GetNext() const
Definition renderer.h:332
HRESULT EnumerateDeviceTextureFormats(IDirect3DDevice2 *pD3DDevice)
Find the texture formats a device created from the node supports.
const D3DDEVICEDESC * GetHardwareDescription() const
Definition renderer.h:320
HRESULT EnqueueTextureFormatNode(DisplayMode *pFormat)
Add a texture format to the end of the formats of the device.
const D3DDEVICEDESC * GetSoftwareDescription() const
Definition renderer.h:324
void ReleaseD3DDeviceNode()
Free the texture formats, the description, and the name of the device, and unlink it,...
void SetNext(D3DDeviceNode *device)
Link the following device.
Definition renderer.h:340
bool CompareD3DDeviceGuid(const GUID *pGuid)
Whether a GUID names the device, a device that was read alone.
GUID * GetGuid()
Definition renderer.h:316
void SetPrevious(D3DDeviceNode *device)
Link the preceding device.
Definition renderer.h:336
D3DDeviceNode * GetPrevious() const
Definition renderer.h:328
D3DDeviceNode()
Start a device without texts, with empty descriptions.
Definition renderer.h:362
A Direct3D material and the description it was set from.
Definition renderer.h:500
void SetDiffuseColor(float red, float green, float blue)
Set the diffuse red, green, and blue components and mark the material dirty.
Definition renderer.h:514
HRESULT CommitMaterialIfDirty()
Give desc to the material of Direct3D when it changed.
void SetRampSize(DWORD size)
Set the material's colour-ramp size.
Definition renderer.h:522
void Release()
Release the material of Direct3D.
D3DMaterial(IDirect3D2 *pDirect3D2, IDirect3DDevice2 *pD3DDevice)
Create an opaque material of Direct3D and its handle on a device.
D3DMATERIALHANDLE GetMaterialHandle() const
Definition renderer.h:509
HRESULT ApplyDescription()
Apply the material description to the Direct3D material.
Definition renderer.h:527
A texture of Direct3D created from an image in memory.
Definition renderer.h:558
bool LoadSysMemTextureToDevice()
Restore the texture surface and load it from the surface in system memory.
bool CreateD3DTexture(IDirect3DDevice2 *pDevice, void *pImage, int nWidth, int nHeight, int nPixelFormatId, DWORD dwColorKey)
Create the texture from an image.
D3DTEXTUREHANDLE GetTextureHandle() const
Definition renderer.h:568
void ReleaseD3DTextureInterfaces()
Release the interfaces of the texture and clear its handle.
bool UploadSurfaceToTexture(const void *pImage, int nWidth, int nHeight)
Copy an image into the surface in system memory and load the texture surface from it.
bool CreateD3DTextureDefault(IDirect3DDevice2 *pDevice, void *pImage, int nWidth, int nHeight, int nPixelFormatId)
Create the texture from an image with no transparent colour.
A DirectDraw driver the game found.
Definition renderer.h:57
bool CompareDirectDrawDriverGuid(const GUID *pGuid)
Whether a GUID selects the driver, a usable driver alone.
HRESULT AppendDirect3DDeviceNode(D3DDeviceNode *pDevice)
Add a Direct3D device to the end of the devices of the driver.
DirectDrawDriver * GetPrevious() const
Definition renderer.h:129
void SetPrevious(DirectDrawDriver *driver)
Link the preceding driver.
Definition renderer.h:137
DirectDrawDriver()
Start a driver that is not usable, with empty abilities.
Definition renderer.h:146
GUID * GetDirectDrawDriverGuid()
The GUID that selects the driver.
DisplayMode * GetDisplayModesHead() const
Definition renderer.h:125
void ShutdownDirectDrawDriver()
Free the devices and the modes of the driver.
unsigned GetDisplayModeCount() const
Definition renderer.h:121
const GUID * GetGuid() const
Definition renderer.h:113
const char * GetName() const
Definition renderer.h:117
HRESULT EnqueueDirectDrawModeNode(DisplayMode *pMode)
Add a display mode to the end of the modes of the driver.
void SetNext(DirectDrawDriver *driver)
Link the following driver.
Definition renderer.h:141
DirectDrawDriver * GetNext() const
Definition renderer.h:133
D3DDeviceNode * SelectPreferredD3DDevice(GUID *pGuid, D3DDeviceNode **ppPreferred, D3DDeviceNode *pFirst)
Select the device a GUID names, or report the device the game prefers: a device of the hardware,...
unsigned GetFlags() const
Definition renderer.h:109
D3DDeviceNode * FindRenderDevice(GUID *pGuid, DisplayMode *pMode, D3DDeviceNode **ppFallback, D3DDeviceNode *pFirst)
Find the device a GUID names that supports a display mode.
HRESULT InitializeDirectDrawDriver(GUID *pGuid, LPSTR pszName, LPSTR pszDescription)
Read a driver DirectDraw reports, with its devices and its modes.
DisplayMode * FindDisplayModeForDevice(int nWidth, int nHeight, int nBitDepth, void *pUnused, D3DDeviceNode *pDevice, DisplayMode **ppFallback, DisplayMode *pFirst)
Find a display mode of a size and a depth that a device supports.
DisplayMode * FindDisplayMode(int nWidth, int nHeight, int nBitDepth, void *pUnused, DisplayMode **ppFallback, DisplayMode *pFirst)
Find a display mode of a size and a depth.
The DirectDraw and Direct3D objects of a window.
Definition renderer.h:652
DirectDrawRenderer()
Clear the renderer.
void Cleanup()
Release every object of the renderer and forget its window.
HRESULT ChangeDisplayModeAndReinitDirectDraw(GUID *pGuid, D3DDeviceNode *pDevice, DisplayMode *pMode)
Move the renderer to another DirectDraw driver, a device, and a display mode, and create its DirectDr...
D3DDeviceNode * GetDevice() const
Definition renderer.h:884
HRESULT SetDeviceNotificationCallback(RenderHost *pRenderHost)
Give the renderer the host that draws through it, and give the host the renderer.
HRESULT GetDeviceViewportRect(RECT *pRect)
The rectangle of the viewport.
HRESULT BeginRenderScene()
Create the material of the background of the viewport.
HRESULT RestoreLostSurfaces()
Restore the front, back, and depth buffers that were lost, and the textures of the host.
IDirect3DViewport2 * GetViewport() const
Definition renderer.h:908
void FlipPrimarySurfaceAndWait()
Flip the back buffer to the front, waiting first until the front buffer can flip when g_bD3DWaitCanFl...
void AddFlags(int flags)
Add flags to the renderer flags.
Definition renderer.h:860
DirectDrawDriver * GetDriver() const
Definition renderer.h:876
D3DMaterial * GetMaterial() const
Definition renderer.h:848
IDirectDrawSurface * GetPrimarySurface() const
Definition renderer.h:896
void RemoveFlags(int flags)
Remove flags from the renderer flags.
Definition renderer.h:864
int GetDeviceInit() const
Definition renderer.h:852
int GetFlags() const
Definition renderer.h:856
IDirect3DDevice2 * GetD3DDevice() const
Definition renderer.h:904
DisplayMode * GetMode() const
Definition renderer.h:880
HRESULT AdjustGdiModeRefCount(bool bEnter)
Give the screen to GDI or take it back.
IDirectDrawSurface * GetBackBuffer() const
Definition renderer.h:900
HRESULT InitializeWindow(HWND hWnd, GUID *pDriverGuid, int nWidth, int nHeight, int nBitDepth, void *pSurfaceFormat, GUID *pDeviceGuid, bool bOption)
Select a driver, a device, and a mode, and create the objects that draw into a window.
IDirect3D2 * GetDirect3D2() const
Definition renderer.h:892
int SwitchDisplayModeAndRebuildDevice(int nWidth, int nHeight, int nBitDepth, int nExtra)
Switch the display mode of the window and create the device again.
IDirectDraw2 * GetDirectDraw2() const
Definition renderer.h:888
int GetRenderStateFlags() const
Definition renderer.h:868
int GetGdiModeRefCount() const
Definition renderer.h:872
HRESULT SetPrimarySurfacePalette()
Give the palette to the front buffer.
A display mode of a driver.
Definition renderer.h:423
void SetNext(DisplayMode *mode)
Link the following mode.
Definition renderer.h:455
DisplayMode()
Start an empty mode.
Definition renderer.h:460
void SetPrevious(DisplayMode *mode)
Link the preceding mode.
Definition renderer.h:451
DisplayMode * GetNext() const
Definition renderer.h:447
DisplayMode * GetPrevious() const
Definition renderer.h:443
bool IsDisplayModeMatch(int nWidth, int nHeight, int nBitDepth)
Whether the mode has a size and a depth.
bool IsDisplayModeSupportedByDevice(D3DDeviceNode *pDevice)
Whether a device can draw in the depth of the mode.
HRESULT GetSurfaceDescDimensions(int *pnWidth, int *pnHeight, int *pnBitDepth, int *pnRefreshRate)
The size and the bits of a pixel of the mode.
void SetDescription(const DDSURFACEDESC &description)
Replace the mode's DirectDraw surface description.
Definition renderer.h:439
What the game draws through: the renderer of the main window.
Definition renderer.h:1039
DirectDrawRenderer * GetRenderer() const
Definition renderer.h:1053
RenderHost()
Start without a renderer.
int OnDestroyDevice()
Prepare for the device of the renderer to go.
HRESULT ValidateRenderDeviceState()
Whether the renderer is ready and has its Direct3D objects.
HRESULT SetRenderer(DirectDrawRenderer *pNewRenderer)
Draw through a renderer.
int ReloadTextureSurfacesAfterRestore()
Load the textures again after the surfaces of the renderer were restored.
HRESULT RenderLoadingScreen(DirectDrawRenderer *pWindowRenderer, const char *pszImage, unsigned nImageKey)
Show an image of the game while the game loads.
IDirectDraw * GetDirectDrawFromD3DDevice(IDirect3DDevice2 *pDevice)
Find the DirectDraw object of a device through its render target.
void PresentFrameCallback_FlipSurfaces(void)
Flip the frame of the main window.
DirectDrawDriver * FindDirectDrawDriverByGuid(GUID *pGuid, DirectDrawDriver **ppPrimary, DirectDrawDriver *pFirst)
Find the driver a GUID selects, and the primary driver on the way.
int g_dwScreenBitDepth
The bits of a pixel of the display mode set.
int g_dwActiveDisplayDeviceIndex
The index in the list of DirectDraw drivers of the driver in use.
#define DIRECTDRAW_DRIVER_USABLE
A DirectDraw driver usable by the game.
Definition renderer.h:48
IDirect3D2 * g_pDirect3D2
The Direct3D interface of the renderer that created it last.
DWORD BitDepthToDDBD(int nBitDepth)
The DDBD_ flag of a depth.
HRESULT WINAPI EnumDeviceTextureFormatsCallback_AddFormat(DDSURFACEDESC *pDesc, LPVOID pContext)
Record a texture format of a device that Direct3D reports.
IDirect3DDevice2 * g_pD3DDevice2
The Direct3D device of the renderer that created it last.
HRESULT WINAPI EnumDisplayModesCallback_AddMode(DDSURFACEDESC *pDesc, LPVOID pContext)
Record a display mode of a driver that DirectDraw reports.
bool FindDesktopDisplayModeAndDevice(DirectDrawDriver *pDriver, GUID *pDeviceGuid, DisplayMode **ppMode, D3DDeviceNode **ppDevice)
Select a device of a driver and the mode of the desktop.
HRESULT WINAPI EnumD3DDevicesCallback(GUID *pGuid, LPSTR pszDescription, LPSTR pszName, D3DDEVICEDESC *pHardwareDesc, D3DDEVICEDESC *pSoftwareDesc, LPVOID pContext)
Record a Direct3D device of a driver that Direct3D reports.
void EnumerateTextureFormats(IDirect3DDevice2 *pD3DDevice)
Find the texture formats of a Direct3D device for each entry of g_aTexturePixelFormats,...
static DirectDrawRenderer * GetWindowRenderer(HWND hWnd)
The renderer a window stores, set by AttachRenderDeviceToWindow().
Definition renderer.h:1448
D3DTexture ** g_ppTextureIdTable
The textures of Direct3D by identifier.
HRESULT EnsureDirectDrawDriversEnumerated(void)
Find the DirectDraw drivers and their devices and modes, once.
D3DDEVICEDESC g_D3DHelDeviceDesc
What the emulation of the device created last does.
D3DDEVICEDESC g_D3DHalDeviceDesc
What the hardware of the device created last does.
DisplayMode * FindDisplayModeWithFallback(DirectDrawDriver *pDriver, int nWidth, int nHeight, int nBitDepth, int nUnknown, D3DDeviceNode *pDevice)
Find a mode of a driver for a size and a depth, for a device.
D3DDeviceNode * ResolveRenderDeviceOrFind(DirectDrawDriver *pDriver, GUID *pDeviceGuid, DisplayMode *pMode)
Resolve a device by GUID and optional display mode, using the reported fallback on failure.
int g_dwSelectedDisplayDeviceIndex
The index in the list of DirectDraw drivers of the driver the menu of devices selects.
RenderHost * g_pRenderHost
The host the game draws through.
int DDBDToBitDepth(DWORD dwMask)
The bits of a depth from the DDBD_ flags of the depths.
DirectDrawDriver * g_pDirectDrawDriverListHead
The DirectDraw drivers the game found, linked by DirectDrawDriver::pNext.
bool IsPixelFormatPalettized(const DDPIXELFORMAT *pFormat)
Whether a pixel format indexes a palette of 1, 2, 4, or 8 bits.
HRESULT AppendDirectDrawDriverNode(DirectDrawDriver *pDriver)
Add a driver to the end of the list of drivers.
BOOL WINAPI EnumDirectDrawDriversCallback(GUID *pGuid, LPSTR pszDescription, LPSTR pszName, LPVOID pContext)
Record a DirectDraw driver that DirectDraw reports.
bool SelectDeviceAndDisplayMode(DirectDrawDriver *pDriver, GUID *pDeviceGuid, int nWidth, int nHeight, int nBitDepth, void *pSurfaceFormat, DisplayMode **ppMode, D3DDeviceNode **ppDevice)
Select a device of a driver and a mode that matches a size.
void InitializeAllTextureSurfaces(void)
Load every texture the game loaded into its texture surface again, after the surfaces were lost.
bool ApplySelectedDisplayMode(int nWidth, int nHeight, int nBitDepth, int nExtra)
Move the main window to the DirectDraw driver of g_GlobalRallyConfig when it differs from the driver ...
DirectDrawDriver * FindDirectDrawDriverOrDefault(GUID *pGuid)
The first DirectDraw driver the game found with a GUID, or the default.
HRESULT SelectDriverDeviceAndModeFromConfig(GUID *pDriverGuid, int nWidth, int nHeight, int nBitDepth, void *pSurfaceFormat, GUID *pDeviceGuid, bool bMatchMode, DirectDrawDriver **ppDriver, DisplayMode **ppMode, D3DDeviceNode **ppDevice)
Select the driver, device, and mode of a renderer, finding the drivers first if the game has not.
unsigned char g_bDirectDrawDriversEnumerated
Whether the DirectDraw drivers were found, in bit 0.
HRESULT EnumerateDirectDrawDrivers(void)
Find the DirectDraw drivers and their devices and modes.
void QueryD3DDeviceCaps(IDirect3DDevice2 *pD3DDevice)
Read what a Direct3D device can do.
DirectDrawDriver * g_pSelectedDisplayDriver
The DirectDraw driver chosen in the configuration.
DirectDrawDriver * FindDisplayDeviceByGuid(GUID *pGuid)
Find the DirectDraw driver of a GUID and make it the selected one.
typedef D3DMATERIALHANDLE
What the search of the DirectDraw drivers found.
Definition renderer.h:1312
int bSucceeded
Definition renderer.h:1313
void * pOwner
The driver whose modes or devices, or the device whose formats, are found, if any.
Definition renderer.h:1316
int nFound
Definition renderer.h:1314