Isle
|
Class responsible for interfacing with DirectDraw to manage rendering surfaces, palettes, and fullscreen/windowed device modes. More...
#include <mxdirectdraw.h>
Public Types | |
typedef void(* | ErrorHandler) (const char *, HRESULT, void *) |
Function pointer type for error handling callbacks. More... | |
Public Member Functions | |
MxDirectDraw () | |
Constructs a MxDirectDraw instance and initializes its members. More... | |
virtual | ~MxDirectDraw () |
Virtual destructor. More... | |
virtual BOOL | Create (HWND hWnd, BOOL fullscreen_1, BOOL surface_fullscreen, BOOL onlySystemMemory, int width, int height, int bpp, const PALETTEENTRY *pPaletteEntries, int paletteEntryCount) |
Creates and initializes the DirectDraw device and associated surfaces/windows/state. More... | |
virtual void | Destroy () |
Shuts down DirectDraw and releases all resources, including device and surfaces. More... | |
virtual void | DestroyButNotDirectDraw () |
Releases all DirectDraw-related resources except the DirectDraw device itself. More... | |
IDirectDraw * | DirectDraw () |
Returns the DirectDraw device interface pointer. More... | |
IDirectDrawSurface * | FrontBuffer () |
Returns the surface used as the primary/front buffer. More... | |
IDirectDrawSurface * | BackBuffer () |
Returns the back buffer surface. More... | |
IDirectDrawClipper * | Clipper () |
Returns the current DirectDraw clipper object used for window clipping. More... | |
DeviceModesInfo::Mode * | CurrentMode () |
Provides access to the current selected display mode (width, height, bpp). More... | |
BOOL | IsFullScreen () |
Returns TRUE if DirectDraw is currently set in exclusive fullscreen mode. More... | |
BOOL | IsSupportedMode (int width, int height, int bpp) |
Checks if the given mode (resolution, bpp) is supported by the current device. More... | |
int | Pause (BOOL) |
Pauses or resumes DirectDraw rendering. More... | |
BOOL | RestoreSurfaces () |
Attempts to restore all DirectDraw surfaces that may have been lost. More... | |
BOOL | TextToTextSurface1 (const char *text) |
Draws the specified text string to the debug "text1" surface. More... | |
BOOL | TextToTextSurface2 (const char *lpString) |
Draws the specified string to the debug "text2" surface. More... | |
virtual const char * | ErrorToString (HRESULT p_error) |
Converts DirectDraw error code to a human-readable string. More... | |
int | FlipToGDISurface () |
Flips to the Windows GDI surface, restoring the desktop when leaving exclusive fullscreen. More... | |
Static Public Member Functions | |
static int | GetPrimaryBitDepth () |
Returns the bit depth (color depth) of the primary display device. More... | |
Protected Member Functions | |
BOOL | SetPaletteEntries (const PALETTEENTRY *pPaletteEntries, int paletteEntryCount, BOOL fullscreen) |
Sets the DirectDraw palette using the provided palette entries. More... | |
BOOL | CacheOriginalPaletteEntries () |
Caches the original Windows/system palette for restoration. More... | |
BOOL | RestoreOriginalPaletteEntries () |
Restores the original Windows palette from backup. More... | |
BOOL | RestorePaletteEntries () |
Restores the active DirectDraw palette entries from the internal palette array. More... | |
BOOL | DDInit (BOOL fullscreen) |
Initializes DirectDraw cooperative level for fullscreen or windowed mode. More... | |
BOOL | DDSetMode (int width, int height, int bpp) |
Changes DirectDraw to the specified display mode and creates relevant surfaces. More... | |
BOOL | DDCreateSurfaces () |
Internal: Creates all necessary front/back/offscreen surfaces for rendering. More... | |
HRESULT | CreateDDSurface (LPDDSURFACEDESC a2, LPDIRECTDRAWSURFACE *a3, IUnknown *a4) |
Creates a DirectDraw surface with the given surface description. More... | |
BOOL | GetDDSurfaceDesc (LPDDSURFACEDESC lpDDSurfDesc, LPDIRECTDRAWSURFACE lpDDSurf) |
Retrieves the surface description for the given DirectDraw surface. More... | |
BOOL | CreateZBuffer (DWORD memorytype, DWORD depth) |
Creates a z-buffer with the given memory type/capabilities and attaches it to the back buffer. More... | |
BOOL | CreateTextSurfaces () |
Creates the two offscreen text surfaces used for debug overlay. More... | |
BOOL | TextToTextSurface (const char *text, IDirectDrawSurface *pSurface, SIZE &textSizeOnSurface) |
Renders a string to the given surface and fills in its onscreen size. More... | |
void | Error (const char *p_message, int p_error) |
Invokes the error handler, optionally destroying the device, and outputs the given error message/code. More... | |
BOOL | RecreateDirectDraw (GUID **a2) |
Recreates the DirectDraw device, deleting and restoring the device object pointer. More... | |
void | FUN_1009e020 () |
Internal: Clears the backbuffer(s), locking and filling with zero color, possibly flipping to front. More... | |
void | FUN_1009d920 () |
Internal: Restores original palette and resets display mode and cooperative level. More... | |
Protected Attributes | |
BOOL | m_bOnlySoftRender |
If TRUE, restricts rendering to software only; disables hardware acceleration. [AI]. More... | |
BOOL | m_bFlipSurfaces |
TRUE if using DirectDraw flipping (fullscreen buffer swap); windowed disables this. [AI]. More... | |
IDirectDraw * | m_pDirectDraw |
Pointer to the DirectDraw COM device. [AI]. More... | |
IDirectDrawSurface * | m_pFrontBuffer |
Primary or front display surface. [AI]. More... | |
IDirectDrawSurface * | m_pBackBuffer |
Backbuffer for offscreen rendering/flipping. [AI]. More... | |
IDirectDrawSurface * | m_pZBuffer |
Attached Z-buffer for 3D rendering. [AI]. More... | |
IDirectDrawSurface * | m_pText1Surface |
Debug overlay surface for "text1". [AI]. More... | |
IDirectDrawSurface * | m_pText2Surface |
Debug overlay surface for "text2". [AI]. More... | |
IDirectDrawClipper * | m_pClipper |
Clipper for managing windowed surface boundaries. [AI]. More... | |
IDirectDrawPalette * | m_pPalette |
DirectDraw palette assigned to the primary/back surfaces. [AI]. More... | |
PALETTEENTRY | m_paletteEntries [256] |
Active 8-bit palette entries for palettized modes. [AI]. More... | |
PALETTEENTRY | m_originalPaletteEntries [256] |
Backup of system/Windows palette for restoration. [AI]. More... | |
SIZE | m_text1SizeOnSurface |
Pixel size of rendered text1 overlay surface. [AI]. More... | |
SIZE | m_text2SizeOnSurface |
Pixel size of rendered text2 overlay surface. [AI]. More... | |
HWND | m_hWndMain |
Main window handle on which DirectDraw is initialized. [AI]. More... | |
HFONT | m_hFont |
Font handle for debug text overlays. [AI]. More... | |
BOOL | m_bIgnoreWMSIZE |
Internal flag to suppress window resize messages during device switching. [AI]. More... | |
BOOL | m_bPrimaryPalettized |
TRUE if primary/backbuffer is using 8-bit palettized mode. [AI]. More... | |
BOOL | m_bFullScreen |
TRUE if device is in exclusive fullscreen mode. [AI]. More... | |
void * | m_unk0x850 |
[AI] Purpose unknown; possibly driver-specific data or reserved. More... | |
BOOL | m_bOnlySystemMemory |
TRUE for system RAM-only surfaces; disables video memory allocation. [AI]. More... | |
BOOL | m_bIsOnPrimaryDevice |
TRUE if rendering on Windows' main display; disables windowed mode for other devices. [AI]. More... | |
ErrorHandler | m_pErrorHandler |
Callback for non-fatal DirectDraw errors. [AI]. More... | |
ErrorHandler | m_pFatalErrorHandler |
Callback invoked for fatal device errors. [AI]. More... | |
void * | m_pErrorHandlerArg |
Custom argument pointer for error handler. [AI]. More... | |
void * | m_pFatalErrorHandlerArg |
Custom argument pointer for fatal error handler. [AI]. More... | |
int | m_pauseCount |
Count of nested pauses; ensures multiple Pause(TRUE)/Pause(FALSE) work correctly. [AI]. More... | |
DeviceModesInfo * | m_currentDevInfo |
Device info array for storing supported display modes. [AI]. More... | |
DeviceModesInfo::Mode | m_currentMode |
Struct with current width, height, and bits per pixel. [AI]. More... | |
Class responsible for interfacing with DirectDraw to manage rendering surfaces, palettes, and fullscreen/windowed device modes.
[AI]
[AI] Manages creation, destruction, and manipulation of primary/back buffers, palettes, display modes, clipper objects, z-buffers, and debug text surfaces for LEGO Island's rendering subsystem. Handles error notification and surface restoration. Allows for windowed and fullscreen operation and provides utility for palette management; also supports custom error handlers. [AI]
Definition at line 17 of file mxdirectdraw.h.
typedef void(* MxDirectDraw::ErrorHandler) (const char *, HRESULT, void *) |
Function pointer type for error handling callbacks.
[AI]
const | char* Error message string. [AI] |
HRESULT | Error code from DirectDraw. [AI] |
void* | User-defined callback argument. [AI] |
Definition at line 25 of file mxdirectdraw.h.
MxDirectDraw::MxDirectDraw | ( | ) |
Constructs a MxDirectDraw instance and initializes its members.
[AI]
Definition at line 25 of file mxdirectdraw.cpp.
|
virtual |
Virtual destructor.
Destroys the DirectDraw instance and releases all resources. [AI]
Definition at line 53 of file mxdirectdraw.cpp.
|
inline |
Returns the back buffer surface.
[AI]
Definition at line 94 of file mxdirectdraw.h.
|
protected |
Caches the original Windows/system palette for restoration.
[AI]
Definition at line 141 of file mxdirectdraw.cpp.
|
inline |
Returns the current DirectDraw clipper object used for window clipping.
[AI]
Definition at line 100 of file mxdirectdraw.h.
|
virtual |
Creates and initializes the DirectDraw device and associated surfaces/windows/state.
[AI]
hWnd | The window handle to attach DirectDraw to. [AI] |
fullscreen_1 | If TRUE, the device is set up for exclusive fullscreen; otherwise windowed. [AI] |
surface_fullscreen | If TRUE, enables flipping surfaces (primary/back) for fullscreen rendering. [AI] |
onlySystemMemory | If TRUE, surfaces are allocated in system RAM only (not video memory). [AI] |
width | Desired screen width. [AI] |
height | Desired screen height. [AI] |
bpp | Desired bits per pixel (color depth). [AI] |
pPaletteEntries | Palette data to use for palettized displays. [AI] |
paletteEntryCount | Number of entries in pPaletteEntries. [AI] |
Reimplemented in MxDirect3D.
Definition at line 86 of file mxdirectdraw.cpp.
|
protected |
Creates a DirectDraw surface with the given surface description.
[AI]
a2 | The DDSURFACEDESC that specifies the new surface parameters. [AI] |
a3 | Receives the created surface pointer. [AI] |
a4 | Optional: outer COM object for aggregation, usually NULL. [AI] |
Definition at line 446 of file mxdirectdraw.cpp.
|
protected |
Creates the two offscreen text surfaces used for debug overlay.
[AI]
Definition at line 639 of file mxdirectdraw.cpp.
Creates a z-buffer with the given memory type/capabilities and attaches it to the back buffer.
[AI]
memorytype | Device memory type (e.g., system or video memory). [AI] |
depth | Number of bits for the z-buffer. [AI] |
Definition at line 778 of file mxdirectdraw.cpp.
|
inline |
Provides access to the current selected display mode (width, height, bpp).
[AI]
Definition at line 106 of file mxdirectdraw.h.
|
protected |
Internal: Creates all necessary front/back/offscreen surfaces for rendering.
[AI]
Definition at line 474 of file mxdirectdraw.cpp.
Initializes DirectDraw cooperative level for fullscreen or windowed mode.
[AI]
fullscreen | Whether to use exclusive fullscreen or not. [AI] |
Definition at line 260 of file mxdirectdraw.cpp.
|
protected |
Changes DirectDraw to the specified display mode and creates relevant surfaces.
[AI]
[AI] Handles resizing and switching window styles for windowed mode; validates that the requested mode exists. [AI]
width | Requested width. [AI] |
height | Requested height. [AI] |
bpp | Requested bits per pixel. [AI] |
Definition at line 321 of file mxdirectdraw.cpp.
|
virtual |
Shuts down DirectDraw and releases all resources, including device and surfaces.
[AI]
Reimplemented in MxDirect3D.
Definition at line 207 of file mxdirectdraw.cpp.
|
virtual |
Releases all DirectDraw-related resources except the DirectDraw device itself.
[AI]
Reimplemented in MxDirect3D.
Definition at line 225 of file mxdirectdraw.cpp.
|
inline |
Returns the DirectDraw device interface pointer.
[AI]
Definition at line 82 of file mxdirectdraw.h.
|
protected |
Invokes the error handler, optionally destroying the device, and outputs the given error message/code.
[AI]
p_message | Description or context message. [AI] |
p_error | DirectDraw HRESULT error or custom error code. [AI] |
Definition at line 916 of file mxdirectdraw.cpp.
|
virtual |
Converts DirectDraw error code to a human-readable string.
[AI]
p_error | HRESULT error code from a DirectDraw operation. [AI] |
Definition at line 936 of file mxdirectdraw.cpp.
int MxDirectDraw::FlipToGDISurface | ( | ) |
Flips to the Windows GDI surface, restoring the desktop when leaving exclusive fullscreen.
[AI]
Definition at line 898 of file mxdirectdraw.cpp.
|
inline |
Returns the surface used as the primary/front buffer.
[AI]
Definition at line 88 of file mxdirectdraw.h.
|
protected |
Internal: Restores original palette and resets display mode and cooperative level.
[AI]
[AI] Used for gracefully transitioning out of exclusive fullscreen or when deinitializing. [AI]
Definition at line 247 of file mxdirectdraw.cpp.
|
protected |
Internal: Clears the backbuffer(s), locking and filling with zero color, possibly flipping to front.
[AI]
[AI] Called after (re)creating surfaces or setting new modes; ensures surface memory is initialized. [AI]
Definition at line 552 of file mxdirectdraw.cpp.
|
protected |
Retrieves the surface description for the given DirectDraw surface.
[AI]
lpDDSurfDesc | Pointer to DDSURFACEDESC to receive surface info. [AI] |
lpDDSurf | The surface to be queried. [AI] |
Definition at line 458 of file mxdirectdraw.cpp.
|
static |
Returns the bit depth (color depth) of the primary display device.
[AI]
[AI] Queries the current display mode and determines if it's palette-indexed. May set a global indicating 8-bit palette mode is active. [AI]
Definition at line 65 of file mxdirectdraw.cpp.
|
inline |
Returns TRUE if DirectDraw is currently set in exclusive fullscreen mode.
[AI]
Definition at line 111 of file mxdirectdraw.h.
BOOL MxDirectDraw::IsSupportedMode | ( | int | width, |
int | height, | ||
int | bpp | ||
) |
Checks if the given mode (resolution, bpp) is supported by the current device.
[AI]
width | Width in pixels. [AI] |
height | Height in pixels. [AI] |
bpp | Bits per pixel. [AI] |
Definition at line 287 of file mxdirectdraw.cpp.
int MxDirectDraw::Pause | ( | BOOL | p_pause | ) |
Pauses or resumes DirectDraw rendering.
Used to handle palette/surface swapping on alt-tab, restoring. [AI]
Flag | indicating whether to pause (TRUE) or resume (FALSE). [AI] |
Definition at line 810 of file mxdirectdraw.cpp.
|
protected |
Recreates the DirectDraw device, deleting and restoring the device object pointer.
[AI]
[AI] Used during device mode switches or DX context loss; can be passed a GUID for the device. [AI]
a2 | Pointer to GUID pointer, usually obtained from DeviceModesInfo. [AI] |
Definition at line 133 of file mxdirectdraw.cpp.
|
protected |
Restores the original Windows palette from backup.
[AI]
Definition at line 874 of file mxdirectdraw.cpp.
|
protected |
Restores the active DirectDraw palette entries from the internal palette array.
[AI]
Definition at line 853 of file mxdirectdraw.cpp.
BOOL MxDirectDraw::RestoreSurfaces | ( | ) |
Attempts to restore all DirectDraw surfaces that may have been lost.
[AI]
[AI] Surfaces can become lost when switching to/from exclusive fullscreen or losing the device context. [AI]
Definition at line 719 of file mxdirectdraw.cpp.
|
protected |
Sets the DirectDraw palette using the provided palette entries.
Used for palettized display modes. [AI]
pPaletteEntries | Pointer to palette entries. [AI] |
paletteEntryCount | Number of palette entries. [AI] |
fullscreen | Whether called in fullscreen context (may affect updates to system palette). [AI] |
Definition at line 155 of file mxdirectdraw.cpp.
|
protected |
Renders a string to the given surface and fills in its onscreen size.
[AI]
text | Null-terminated string to draw. [AI] |
pSurface | Target DirectDraw surface. [AI] |
textSizeOnSurface | Receives the size of the rendered text. [AI] |
Definition at line 592 of file mxdirectdraw.cpp.
BOOL MxDirectDraw::TextToTextSurface1 | ( | const char * | text | ) |
Draws the specified text string to the debug "text1" surface.
[AI]
text | Null-terminated string to draw. [AI] |
Definition at line 625 of file mxdirectdraw.cpp.
BOOL MxDirectDraw::TextToTextSurface2 | ( | const char * | lpString | ) |
Draws the specified string to the debug "text2" surface.
[AI]
lpString | Null-terminated string to draw. [AI] |
Definition at line 632 of file mxdirectdraw.cpp.
|
protected |
TRUE if using DirectDraw flipping (fullscreen buffer swap); windowed disables this. [AI].
Definition at line 287 of file mxdirectdraw.h.
|
protected |
TRUE if device is in exclusive fullscreen mode. [AI].
Definition at line 304 of file mxdirectdraw.h.
|
protected |
Internal flag to suppress window resize messages during device switching. [AI].
Definition at line 302 of file mxdirectdraw.h.
|
protected |
TRUE if rendering on Windows' main display; disables windowed mode for other devices. [AI].
Definition at line 307 of file mxdirectdraw.h.
|
protected |
If TRUE, restricts rendering to software only; disables hardware acceleration. [AI].
Definition at line 286 of file mxdirectdraw.h.
|
protected |
TRUE for system RAM-only surfaces; disables video memory allocation. [AI].
Definition at line 306 of file mxdirectdraw.h.
|
protected |
TRUE if primary/backbuffer is using 8-bit palettized mode. [AI].
Definition at line 303 of file mxdirectdraw.h.
|
protected |
Device info array for storing supported display modes. [AI].
Definition at line 313 of file mxdirectdraw.h.
|
protected |
Struct with current width, height, and bits per pixel. [AI].
Definition at line 314 of file mxdirectdraw.h.
|
protected |
Font handle for debug text overlays. [AI].
Definition at line 301 of file mxdirectdraw.h.
|
protected |
Main window handle on which DirectDraw is initialized. [AI].
Definition at line 300 of file mxdirectdraw.h.
|
protected |
Backup of system/Windows palette for restoration. [AI].
Definition at line 297 of file mxdirectdraw.h.
|
protected |
Active 8-bit palette entries for palettized modes. [AI].
Definition at line 296 of file mxdirectdraw.h.
|
protected |
Count of nested pauses; ensures multiple Pause(TRUE)/Pause(FALSE) work correctly. [AI].
Definition at line 312 of file mxdirectdraw.h.
|
protected |
Backbuffer for offscreen rendering/flipping. [AI].
Definition at line 290 of file mxdirectdraw.h.
|
protected |
Clipper for managing windowed surface boundaries. [AI].
Definition at line 294 of file mxdirectdraw.h.
|
protected |
Pointer to the DirectDraw COM device. [AI].
Definition at line 288 of file mxdirectdraw.h.
|
protected |
Callback for non-fatal DirectDraw errors. [AI].
Definition at line 308 of file mxdirectdraw.h.
|
protected |
Custom argument pointer for error handler. [AI].
Definition at line 310 of file mxdirectdraw.h.
|
protected |
Callback invoked for fatal device errors. [AI].
Definition at line 309 of file mxdirectdraw.h.
|
protected |
Custom argument pointer for fatal error handler. [AI].
Definition at line 311 of file mxdirectdraw.h.
|
protected |
Primary or front display surface. [AI].
Definition at line 289 of file mxdirectdraw.h.
|
protected |
DirectDraw palette assigned to the primary/back surfaces. [AI].
Definition at line 295 of file mxdirectdraw.h.
|
protected |
Debug overlay surface for "text1". [AI].
Definition at line 292 of file mxdirectdraw.h.
|
protected |
Debug overlay surface for "text2". [AI].
Definition at line 293 of file mxdirectdraw.h.
|
protected |
Attached Z-buffer for 3D rendering. [AI].
Definition at line 291 of file mxdirectdraw.h.
|
protected |
Pixel size of rendered text1 overlay surface. [AI].
Definition at line 298 of file mxdirectdraw.h.
|
protected |
Pixel size of rendered text2 overlay surface. [AI].
Definition at line 299 of file mxdirectdraw.h.
|
protected |
[AI] Purpose unknown; possibly driver-specific data or reserved.
Definition at line 305 of file mxdirectdraw.h.