coastline 0.0.4
Loading...
Searching...
No Matches
renderer.h File Reference

The DirectDraw and Direct3D renderer of a window, and the host the game uses it through. More...

#include <cstring>
#include <d3d.h>
#include <ddraw.h>
#include <windows.h>
#include "common/textureentry.h"
#include "common/texturetile.h"
Include dependency graph for renderer.h:

Go to the source code of this file.

Classes

class  DirectDrawDriver
 A DirectDraw driver the game found. More...
class  D3DDeviceNode
 A Direct3D device of a driver. More...
class  DisplayMode
 A display mode of a driver. More...
class  D3DMaterial
 A Direct3D material and the description it was set from. More...
class  D3DTexture
 A texture of Direct3D created from an image in memory. More...
class  DirectDrawRenderer
 The DirectDraw and Direct3D objects of a window. More...
class  RenderHost
 What the game draws through: the renderer of the main window. More...
struct  DriverEnumContext
 What the search of the DirectDraw drivers found. More...

Macros

#define RENDERER_E_NOT_IN_GDI_MODE   static_cast<HRESULT>(0x88762711)
 A renderer told to take the screen back from GDI that had not given it.
#define RENDERER_E_OUT_OF_MEMORY   static_cast<HRESULT>(0x88762714)
 A renderer that ran out of memory.
#define RENDERER_E_NOT_CREATED   static_cast<HRESULT>(0x88762712)
 A renderer that is missing its window or its host.
#define RENDERER_E_NOT_READY   static_cast<HRESULT>(0x88762713)
 A renderer that is not ready to draw.
#define WM_RENDERER_CREATED   0xbd0
 The message a renderer sends its window after it creates its objects, with itself.
#define WM_RENDERER_DESTROYING   0xbd1
 The message a renderer sends its window before it releases its objects, with itself.
#define WM_RENDERER_IS_READY   0x7e8
 Query the window for whether its renderer can draw.
#define WM_RENDERER_GET   0x7e9
 Query the window for its renderer.
#define WM_RENDERER_GET_BACK_BUFFER   0x7ea
 Query the window for the back buffer of its renderer.
#define RENDERER_STATE_READY   0x1f
 The bits of DirectDrawRenderer::dwRenderStateFlags of a renderer that can draw.
#define DIRECTDRAW_DRIVER_USABLE   0x1
 A DirectDraw driver usable by the game.
#define DIRECTDRAW_DRIVER_PRIMARY   0x2
 The primary DirectDraw driver, selected without a GUID.

Functions

IDirectDraw * GetDirectDrawFromD3DDevice (IDirect3DDevice2 *pDevice)
 Find the DirectDraw object of a device through its render target.
DirectDrawDriver * FindDirectDrawDriverOrDefault (GUID *pGuid)
 The first DirectDraw driver the game found with a GUID, or the default.
HRESULT AppendDirectDrawDriverNode (DirectDrawDriver *pDriver)
 Add a driver to the end of the list of drivers.
DirectDrawDriver * FindDirectDrawDriverByGuid (GUID *pGuid, DirectDrawDriver **ppPrimary, DirectDrawDriver *pFirst)
 Find the driver a GUID selects, and the primary driver on the way.
void InitializeAllTextureSurfaces (void)
 Load every texture the game loaded into its texture surface again, after the surfaces were lost.
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.
HRESULT EnsureDirectDrawDriversEnumerated (void)
 Find the DirectDraw drivers and their devices and modes, once.
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.
bool FindDesktopDisplayModeAndDevice (DirectDrawDriver *pDriver, GUID *pDeviceGuid, DisplayMode **ppMode, D3DDeviceNode **ppDevice)
 Select a device of a driver and the mode of the desktop.
D3DDeviceNode * ResolveRenderDeviceOrFind (DirectDrawDriver *pDriver, GUID *pDeviceGuid, DisplayMode *pMode)
 Resolve a device by GUID and optional display mode, using the reported fallback on failure.
int DDBDToBitDepth (DWORD dwMask)
 The bits of a depth from the DDBD_ flags of the depths.
DWORD BitDepthToDDBD (int nBitDepth)
 The DDBD_ flag of a depth.
HRESULT WINAPI EnumDisplayModesCallback_AddMode (DDSURFACEDESC *pDesc, LPVOID pContext)
 Record a display mode of a driver that DirectDraw reports.
HRESULT WINAPI EnumDeviceTextureFormatsCallback_AddFormat (DDSURFACEDESC *pDesc, LPVOID pContext)
 Record a texture format of a device that Direct3D reports.
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.
BOOL WINAPI EnumDirectDrawDriversCallback (GUID *pGuid, LPSTR pszDescription, LPSTR pszName, LPVOID pContext)
 Record a DirectDraw driver that DirectDraw reports.
HRESULT EnumerateDirectDrawDrivers (void)
 Find the DirectDraw drivers and their devices and modes.
void QueryD3DDeviceCaps (IDirect3DDevice2 *pD3DDevice)
 Read what a Direct3D device can do.
void EnumerateTextureFormats (IDirect3DDevice2 *pD3DDevice)
 Find the texture formats of a Direct3D device for each entry of g_aTexturePixelFormats, at most 8 bits a pixel first, then 16, then 32 when no format of 16 bits was found.
bool IsPixelFormatPalettized (const DDPIXELFORMAT *pFormat)
 Whether a pixel format indexes a palette of 1, 2, 4, or 8 bits.
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.
void PresentFrameCallback_FlipSurfaces (void)
 Flip the frame of the main window.
static DirectDrawRenderer * GetWindowRenderer (HWND hWnd)
 The renderer a window stores, set by AttachRenderDeviceToWindow().
DirectDrawDriver * FindDisplayDeviceByGuid (GUID *pGuid)
 Find the DirectDraw driver of a GUID and make it the selected one.
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 of the window, in the display mode of the driver nearest a size and a depth.

Variables

RenderHost * g_pRenderHost
 The host the game draws through.
IDirect3D2 * g_pDirect3D2
 The Direct3D interface of the renderer that created it last.
DirectDrawDriver * g_pDirectDrawDriverListHead
 The DirectDraw drivers the game found, linked by DirectDrawDriver::pNext.
IDirect3DDevice2 * g_pD3DDevice2
 The Direct3D device of the renderer that created it last.
D3DTexture ** g_ppTextureIdTable
 The textures of Direct3D by identifier.
unsigned char g_bDirectDrawDriversEnumerated
 Whether the DirectDraw drivers were found, in bit 0.
D3DDEVICEDESC g_D3DHalDeviceDesc
 What the hardware of the device created last does.
D3DDEVICEDESC g_D3DHelDeviceDesc
 What the emulation of the device created last does.
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.
int g_dwSelectedDisplayDeviceIndex
 The index in the list of DirectDraw drivers of the driver the menu of devices selects.
DirectDrawDriver * g_pSelectedDisplayDriver
 The DirectDraw driver chosen in the configuration.

Detailed Description

The DirectDraw and Direct3D renderer of a window, and the host the game uses it through.

Macro Definition Documentation

◆ RENDERER_E_NOT_IN_GDI_MODE

#define RENDERER_E_NOT_IN_GDI_MODE   static_cast<HRESULT>(0x88762711)

A renderer told to take the screen back from GDI that had not given it.

◆ RENDERER_E_OUT_OF_MEMORY

#define RENDERER_E_OUT_OF_MEMORY   static_cast<HRESULT>(0x88762714)

A renderer that ran out of memory.

◆ RENDERER_E_NOT_CREATED

#define RENDERER_E_NOT_CREATED   static_cast<HRESULT>(0x88762712)

A renderer that is missing its window or its host.

◆ RENDERER_E_NOT_READY

#define RENDERER_E_NOT_READY   static_cast<HRESULT>(0x88762713)

A renderer that is not ready to draw.

◆ WM_RENDERER_CREATED

#define WM_RENDERER_CREATED   0xbd0

The message a renderer sends its window after it creates its objects, with itself.

◆ WM_RENDERER_DESTROYING

#define WM_RENDERER_DESTROYING   0xbd1

The message a renderer sends its window before it releases its objects, with itself.

◆ WM_RENDERER_IS_READY

#define WM_RENDERER_IS_READY   0x7e8

Query the window for whether its renderer can draw.

◆ WM_RENDERER_GET

#define WM_RENDERER_GET   0x7e9

Query the window for its renderer.

◆ WM_RENDERER_GET_BACK_BUFFER

#define WM_RENDERER_GET_BACK_BUFFER   0x7ea

Query the window for the back buffer of its renderer.

◆ RENDERER_STATE_READY

#define RENDERER_STATE_READY   0x1f

The bits of DirectDrawRenderer::dwRenderStateFlags of a renderer that can draw.

◆ DIRECTDRAW_DRIVER_USABLE

#define DIRECTDRAW_DRIVER_USABLE   0x1

A DirectDraw driver usable by the game.

◆ DIRECTDRAW_DRIVER_PRIMARY

#define DIRECTDRAW_DRIVER_PRIMARY   0x2

The primary DirectDraw driver, selected without a GUID.

Function Documentation

◆ GetDirectDrawFromD3DDevice()

IDirectDraw * GetDirectDrawFromD3DDevice ( IDirect3DDevice2 * pDevice)

Find the DirectDraw object of a device through its render target.

The reference the lookup takes is released before the object is returned.

Parameters
pDeviceThe device.
Returns
The DirectDraw object, or null when a step fails.
Ghidra address:
BRD3D: 0x10009e30

◆ FindDirectDrawDriverOrDefault()

DirectDrawDriver * FindDirectDrawDriverOrDefault ( GUID * pGuid)

The first DirectDraw driver the game found with a GUID, or the default.

Parameters
pGuidThe GUID of the driver, or nullptr for the default.
Returns
The driver, or nullptr when none was found.
Ghidra address:
BRD3D: 0x1001a550

◆ AppendDirectDrawDriverNode()

HRESULT AppendDirectDrawDriverNode ( DirectDrawDriver * pDriver)

Add a driver to the end of the list of drivers.

Parameters
pDriverThe driver.
Returns
S_OK, or E_INVALIDARG without a driver.
Ghidra address:
BRD3D: 0x1001ba10

◆ FindDirectDrawDriverByGuid()

DirectDrawDriver * FindDirectDrawDriverByGuid ( GUID * pGuid,
DirectDrawDriver ** ppPrimary,
DirectDrawDriver * pFirst )

Find the driver a GUID selects, and the primary driver on the way.

Parameters
pGuidThe GUID, or nullptr for the primary driver.
ppPrimaryReceives the primary driver, or the first driver searched, unless nullptr.
pFirstThe driver the search starts at, or nullptr for the first driver found.
Returns
The driver, or nullptr when the GUID selects none.
Ghidra address:
BRD3D: 0x1001ba70

◆ InitializeAllTextureSurfaces()

void InitializeAllTextureSurfaces ( void )

Load every texture the game loaded into its texture surface again, after the surfaces were lost.

Ghidra address:
BRD3D: 0x10024bb0

◆ SelectDriverDeviceAndModeFromConfig()

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.

A mode is matched to the size requested, or the mode of the desktop is taken.

Parameters
pDriverGuidThe DirectDraw driver, or nullptr for the default.
nWidthThe width of the mode, or 0.
nHeightThe height of the mode, or 0.
nBitDepthThe bits of a pixel of the mode, or 0.
pSurfaceFormatThe format of the surfaces, or nullptr.
pDeviceGuidThe Direct3D device, or nullptr for the default.
bMatchModeWhether a mode is matched to the size rather than taken from the desktop.
ppDriverReceives the driver.
ppModeReceives the mode.
ppDeviceReceives the device.
Returns
S_OK, the error of the search for drivers, RENDERER_E_NOT_CREATED without a driver or an output, or RENDERER_E_NOT_IN_GDI_MODE without a device and a mode.
Ghidra address:
BRD3D: 0x1001a790

◆ EnsureDirectDrawDriversEnumerated()

HRESULT EnsureDirectDrawDriversEnumerated ( void )

Find the DirectDraw drivers and their devices and modes, once.

Returns
S_OK, or the error of DirectDraw.
Ghidra address:
BRD3D: 0x1001b970

◆ SelectDeviceAndDisplayMode()

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.

Parameters
pDriverThe driver.
pDeviceGuidThe Direct3D device, or nullptr for the default.
nWidthThe width of the mode.
nHeightThe height of the mode.
nBitDepthThe bits of a pixel of the mode.
pSurfaceFormatThe format of the surfaces, or nullptr.
ppModeReceives the mode.
ppDeviceReceives the device.
Returns
Whether a device and a mode were found.
Ghidra address:
BRD3D: 0x1001a6e0

◆ FindDesktopDisplayModeAndDevice()

bool FindDesktopDisplayModeAndDevice ( DirectDrawDriver * pDriver,
GUID * pDeviceGuid,
DisplayMode ** ppMode,
D3DDeviceNode ** ppDevice )

Select a device of a driver and the mode of the desktop.

Parameters
pDriverThe driver.
pDeviceGuidThe Direct3D device, or nullptr for the default.
ppModeReceives the mode.
ppDeviceReceives the device.
Returns
Whether a device and a mode were found.
Ghidra address:
BRD3D: 0x1001a610

◆ ResolveRenderDeviceOrFind()

D3DDeviceNode * ResolveRenderDeviceOrFind ( DirectDrawDriver * pDriver,
GUID * pDeviceGuid,
DisplayMode * pMode )

Resolve a device by GUID and optional display mode, using the reported fallback on failure.

Ghidra address:
BRD3D: 0x1001a5d0

◆ DDBDToBitDepth()

int DDBDToBitDepth ( DWORD dwMask)

The bits of a depth from the DDBD_ flags of the depths.

Parameters
dwMaskThe flags of the depths, of which the shallowest counts.
Returns
The bits, or 0 without a depth.
Ghidra address:
BRD3D: 0x1001a870

◆ BitDepthToDDBD()

DWORD BitDepthToDDBD ( int nBitDepth)

The DDBD_ flag of a depth.

Parameters
nBitDepthThe bits, 1, 2, 4, 8, 16, 24, or 32.
Returns
The flag, or 0 for another depth.
Ghidra address:
BRD3D: 0x1001a8c0

◆ EnumDisplayModesCallback_AddMode()

HRESULT WINAPI EnumDisplayModesCallback_AddMode ( DDSURFACEDESC * pDesc,
LPVOID pContext )

Record a display mode of a driver that DirectDraw reports.

Parameters
pDescThe description of the mode.
pContextThe DriverEnumContext of the search.
Returns
Whether the search goes on.
Ghidra address:
BRD3D: 0x1001aa70

◆ EnumDeviceTextureFormatsCallback_AddFormat()

HRESULT WINAPI EnumDeviceTextureFormatsCallback_AddFormat ( DDSURFACEDESC * pDesc,
LPVOID pContext )

Record a texture format of a device that Direct3D reports.

Parameters
pDescThe description of the format.
pContextThe DriverEnumContext of the search.
Returns
Whether the search goes on.
Ghidra address:
BRD3D: 0x1001ab00

◆ EnumD3DDevicesCallback()

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.

Parameters
pGuidThe GUID of the device.
pszDescriptionThe description of the device.
pszNameThe name of the device.
pHardwareDescWhat the hardware of the device does.
pSoftwareDescWhat the emulation of the device does.
pContextThe DriverEnumContext of the search.
Returns
Whether the search goes on.
Ghidra address:
BRD3D: 0x1001ab90

◆ EnumDirectDrawDriversCallback()

BOOL WINAPI EnumDirectDrawDriversCallback ( GUID * pGuid,
LPSTR pszDescription,
LPSTR pszName,
LPVOID pContext )

Record a DirectDraw driver that DirectDraw reports.

Parameters
pGuidThe GUID of the driver, or nullptr for the primary.
pszDescriptionThe description of the driver.
pszNameThe name of the driver.
pContextThe DriverEnumContext of the search.
Returns
Whether the search goes on.
Ghidra address:
BRD3D: 0x1001a990

◆ EnumerateDirectDrawDrivers()

HRESULT EnumerateDirectDrawDrivers ( void )

Find the DirectDraw drivers and their devices and modes.

Returns
S_OK, the error of DirectDraw, or RENDERER_E_NOT_IN_GDI_MODE when a driver was not recorded.
Ghidra address:
BRD3D: 0x1001b9a0

◆ QueryD3DDeviceCaps()

void QueryD3DDeviceCaps ( IDirect3DDevice2 * pD3DDevice)

Read what a Direct3D device can do.

Parameters
pD3DDeviceThe device.
Ghidra address:
BRD3D: 0x10008d90

◆ EnumerateTextureFormats()

void EnumerateTextureFormats ( IDirect3DDevice2 * pD3DDevice)

Find the texture formats of a Direct3D device for each entry of g_aTexturePixelFormats, at most 8 bits a pixel first, then 16, then 32 when no format of 16 bits was found.

Parameters
pD3DDeviceThe device.
Ghidra address:
BRD3D: 0x10009bd0

◆ IsPixelFormatPalettized()

bool IsPixelFormatPalettized ( const DDPIXELFORMAT * pFormat)

Whether a pixel format indexes a palette of 1, 2, 4, or 8 bits.

Parameters
pFormatThe pixel format, or nullptr.
Returns
Whether the format indexes a palette.
Ghidra address:
BRD3D: 0x1001a950

◆ FindDisplayModeWithFallback()

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.

Parameters
pDriverThe driver.
nWidthThe width of the mode.
nHeightThe height of the mode.
nBitDepthThe bits of a pixel of the mode.
nUnknownThe fourth value of the display mode, 0 from some callers. Its meaning is not recovered yet.
pDeviceThe device, or nullptr.
Returns
The mode, or nullptr when the driver has none.
Ghidra address:
BRD3D: 0x1001a570

◆ PresentFrameCallback_FlipSurfaces()

void PresentFrameCallback_FlipSurfaces ( void )

Flip the frame of the main window.

Ghidra address:
BRD3D: 0x1001bad0

◆ GetWindowRenderer()

DirectDrawRenderer * GetWindowRenderer ( HWND hWnd)
inlinestatic

The renderer a window stores, set by AttachRenderDeviceToWindow().

Parameters
hWndThe window.
Returns
The renderer, or null.

◆ FindDisplayDeviceByGuid()

DirectDrawDriver * FindDisplayDeviceByGuid ( GUID * pGuid)

Find the DirectDraw driver of a GUID and make it the selected one.

Parameters
pGuidThe GUID.
Returns
The driver, or the first driver when none has the GUID.
Ghidra address:
BRD3D: 0x1007a7d0

◆ ApplySelectedDisplayMode()

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 of the window, in the display mode of the driver nearest a size and a depth.

Parameters
nWidthThe width of the display mode.
nHeightThe height of the display mode.
nBitDepthThe bits of a pixel of the display mode.
nExtraThe fourth value of the display mode.
Returns
Whether the window moved to the driver.
Ghidra address:
BRD3D: 0x1007ac20

Variable Documentation

◆ g_pRenderHost

RenderHost* g_pRenderHost
extern

The host the game draws through.

Ghidra address:
BRD3D: 0x118abe08

◆ g_pDirect3D2

IDirect3D2* g_pDirect3D2
extern

The Direct3D interface of the renderer that created it last.

Ghidra address:
BRD3D: 0x10277478

◆ g_pDirectDrawDriverListHead

DirectDrawDriver* g_pDirectDrawDriverListHead
extern

The DirectDraw drivers the game found, linked by DirectDrawDriver::pNext.

Ghidra address:
BRD3D: 0x104bbe20

◆ g_pD3DDevice2

IDirect3DDevice2* g_pD3DDevice2
extern

The Direct3D device of the renderer that created it last.

Ghidra address:
BRD3D: 0x10277368

◆ g_ppTextureIdTable

D3DTexture** g_ppTextureIdTable
extern

The textures of Direct3D by identifier.

Ghidra address:
BRD3D: 0x1057542c

◆ g_bDirectDrawDriversEnumerated

unsigned char g_bDirectDrawDriversEnumerated
extern

Whether the DirectDraw drivers were found, in bit 0.

Ghidra address:
BRD3D: 0x104bbe18

◆ g_D3DHalDeviceDesc

D3DDEVICEDESC g_D3DHalDeviceDesc
extern

What the hardware of the device created last does.

Ghidra address:
BRD3D: 0x10277480

◆ g_D3DHelDeviceDesc

D3DDEVICEDESC g_D3DHelDeviceDesc
extern

What the emulation of the device created last does.

Ghidra address:
BRD3D: 0x10277580

◆ g_dwScreenBitDepth

int g_dwScreenBitDepth
extern

The bits of a pixel of the display mode set.

Ghidra address:
BRD3D: 0x100aa8a8

◆ g_dwActiveDisplayDeviceIndex

int g_dwActiveDisplayDeviceIndex
extern

The index in the list of DirectDraw drivers of the driver in use.

Ghidra address:
BRD3D: 0x10aa2860

◆ g_dwSelectedDisplayDeviceIndex

int g_dwSelectedDisplayDeviceIndex
extern

The index in the list of DirectDraw drivers of the driver the menu of devices selects.

Ghidra address:
BRD3D: 0x10aa2a2c

◆ g_pSelectedDisplayDriver

DirectDrawDriver* g_pSelectedDisplayDriver
extern

The DirectDraw driver chosen in the configuration.

Ghidra address:
BRD3D: 0x118ac238