Isle
Loading...
Searching...
No Matches
MxDirect3D Class Reference

[AI] MxDirect3D provides Direct3D (D3D) rendering capabilities layered on top of MxDirectDraw, managing device selection, initialization, and drawing contexts for LEGO Island's 3D rendering. More...

#include <mxdirect3d.h>

Inheritance diagram for MxDirect3D:
Collaboration diagram for MxDirect3D:

Public Member Functions

 MxDirect3D ()
 [AI] Constructs a new MxDirect3D object. More...
 
 ~MxDirect3D () override
 [AI] Destroys the MxDirect3D object, releasing associated Direct3D interfaces and memory for assigned devices. More...
 
BOOL Create (HWND hWnd, BOOL fullscreen_1, BOOL surface_fullscreen, BOOL onlySystemMemory, int width, int height, int bpp, const PALETTEENTRY *pPaletteEntries, int paletteEntryCount) override
 [AI] Initializes DirectDraw and Direct3D, prepares primary surfaces and selects the video mode, optionally honoring palette/bit-depth and device selection. More...
 
void Destroy () override
 [AI] Tears down the Direct3D environment, including releasing D3D and D3DDevice objects, and destroys allocated context state and surfaces. More...
 
void DestroyButNotDirectDraw () override
 [AI] Like Destroy(), but preserves the DirectDraw context; only Direct3D/3DDevice and D3D-specific objects are released. More...
 
MxAssignedDeviceAssignedDevice ()
 [AI] Returns the currently selected/active rendering device information for 3D output. More...
 
IDirect3D2 * Direct3D ()
 [AI] Provides access to the underlying IDirect3D2 interface for advanced 3D rendering operations. More...
 
IDirect3DDevice2 * Direct3DDevice ()
 [AI] Provides access to the currently selected Direct3D device interface. More...
 
BOOL SetDevice (MxDeviceEnumerate &p_deviceEnumerate, MxDriver *p_driver, Direct3DDeviceInfo *p_device)
 [AI] Selects which Direct3D device to be used for rendering, given an enumeration of available devices, a preferred driver, and device info. More...
 
- Public Member Functions inherited from MxDirectDraw
 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::ModeCurrentMode ()
 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...
 

Protected Member Functions

BOOL D3DCreate ()
 [AI] Internal D3D initialization helper: acquires the IDirect3D2 interface from DirectDraw. More...
 
BOOL D3DSetMode ()
 [AI] Internal method to initialize D3D video mode, create devices, ZBuffer, and clear surfaces as needed for selected hardware/software settings. More...
 
int ZBufferDepth (MxAssignedDevice *p_assignedDevice)
 [AI] Determines the suitable ZBuffer depth for a selected rendering device, according to its capabilities. More...
 
- Protected Member Functions inherited from MxDirectDraw
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...
 

Additional Inherited Members

- Public Types inherited from MxDirectDraw
typedef void(* ErrorHandler) (const char *, HRESULT, void *)
 Function pointer type for error handling callbacks. More...
 
- Static Public Member Functions inherited from MxDirectDraw
static int GetPrimaryBitDepth ()
 Returns the bit depth (color depth) of the primary display device. More...
 
- Protected Attributes inherited from MxDirectDraw
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...
 
DeviceModesInfom_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...
 

Detailed Description

[AI] MxDirect3D provides Direct3D (D3D) rendering capabilities layered on top of MxDirectDraw, managing device selection, initialization, and drawing contexts for LEGO Island's 3D rendering.

This class manages Direct3D interfaces and connected devices, handles the creation and teardown of Direct3D objects and devices, ZBuffer creation/selection, as well as switching between fullscreen/windowed rendering modes and hardware/software rendering paths. It is also responsible for supporting palette and pixel format handling, and for tracking the availability and type of texture support at runtime.

It is the base rendering system for 3D content in LEGO Island, providing all D3D context and resource management for the rest of the rendering pipeline.

[AI] MxDirect3D wraps DirectX 5's DirectDraw and Direct3D2 interfaces, and stores references to selected D3D devices. It handles choosing the best rendering device based on hardware/software support, managing the device list from enumeration, and setting video modes. It allows toggling textures, manages creation/locking/zeroing of drawing surfaces, and creating the correct ZBuffer format. This class is intended to be used by higher-level abstractions to provide scene rendering services.

Definition at line 24 of file mxdirect3d.h.

Constructor & Destructor Documentation

◆ MxDirect3D()

MxDirect3D::MxDirect3D ( )

[AI] Constructs a new MxDirect3D object.

Initializes member pointers to null and disables texture optimization by default.

Definition at line 16 of file mxdirect3d.cpp.

◆ ~MxDirect3D()

MxDirect3D::~MxDirect3D ( )
override

[AI] Destroys the MxDirect3D object, releasing associated Direct3D interfaces and memory for assigned devices.

Definition at line 26 of file mxdirect3d.cpp.

Member Function Documentation

◆ AssignedDevice()

MxAssignedDevice * MxDirect3D::AssignedDevice ( )
inline

[AI] Returns the currently selected/active rendering device information for 3D output.

Returns
MxAssignedDevice* [AI] Current rendering device context, including flags, GUID, and caps.

Definition at line 75 of file mxdirect3d.h.

◆ Create()

BOOL MxDirect3D::Create ( HWND  hWnd,
BOOL  fullscreen_1,
BOOL  surface_fullscreen,
BOOL  onlySystemMemory,
int  width,
int  height,
int  bpp,
const PALETTEENTRY *  pPaletteEntries,
int  paletteEntryCount 
)
overridevirtual

[AI] Initializes DirectDraw and Direct3D, prepares primary surfaces and selects the video mode, optionally honoring palette/bit-depth and device selection.

Parameters
hWnd[AI] Window handle to attach DirectDraw/3D context to.
fullscreen_1[AI] Whether the video mode should be fullscreen.
surface_fullscreen[AI] Whether drawing surfaces should be fullscreen.
onlySystemMemory[AI] If TRUE, only use system memory and avoid video memory when creating surfaces.
width[AI] Width of the desired video mode.
height[AI] Height of the desired video mode.
bpp[AI] Bits per pixel for the desired video mode.
pPaletteEntries[AI] Optional palette entries for indexed color modes.
paletteEntryCount[AI] Number of palette entries used. May be 0 if not palette-based.
Returns
BOOL [AI] TRUE if creation and initialization succeed, FALSE if any part of DirectDraw or Direct3D setup fails.

Reimplemented from MxDirectDraw.

Definition at line 33 of file mxdirect3d.cpp.

◆ D3DCreate()

BOOL MxDirect3D::D3DCreate ( )
protected

[AI] Internal D3D initialization helper: acquires the IDirect3D2 interface from DirectDraw.

Returns
BOOL [AI] TRUE if D3D is set up, FALSE on error.

Definition at line 110 of file mxdirect3d.cpp.

◆ D3DSetMode()

BOOL MxDirect3D::D3DSetMode ( )
protected

[AI] Internal method to initialize D3D video mode, create devices, ZBuffer, and clear surfaces as needed for selected hardware/software settings.

Returns
BOOL [AI] TRUE if device/mode setup succeeds, FALSE on error.

Definition at line 124 of file mxdirect3d.cpp.

◆ Destroy()

void MxDirect3D::Destroy ( )
overridevirtual

[AI] Tears down the Direct3D environment, including releasing D3D and D3DDevice objects, and destroys allocated context state and surfaces.

Reimplemented from MxDirectDraw.

Definition at line 82 of file mxdirect3d.cpp.

◆ DestroyButNotDirectDraw()

void MxDirect3D::DestroyButNotDirectDraw ( )
overridevirtual

[AI] Like Destroy(), but preserves the DirectDraw context; only Direct3D/3DDevice and D3D-specific objects are released.

Reimplemented from MxDirectDraw.

Definition at line 101 of file mxdirect3d.cpp.

◆ Direct3D()

IDirect3D2 * MxDirect3D::Direct3D ( )
inline

[AI] Provides access to the underlying IDirect3D2 interface for advanced 3D rendering operations.

Returns
IDirect3D2* [AI] Pointer to the IDirect3D2 COM interface; may be NULL if not initialized.

Definition at line 81 of file mxdirect3d.h.

◆ Direct3DDevice()

IDirect3DDevice2 * MxDirect3D::Direct3DDevice ( )
inline

[AI] Provides access to the currently selected Direct3D device interface.

Returns
IDirect3DDevice2* [AI] Pointer to the IDirect3DDevice2 COM interface; may be NULL if not initialized.

Definition at line 87 of file mxdirect3d.h.

◆ SetDevice()

BOOL MxDirect3D::SetDevice ( MxDeviceEnumerate p_deviceEnumerate,
MxDriver p_driver,
Direct3DDeviceInfo p_device 
)

[AI] Selects which Direct3D device to be used for rendering, given an enumeration of available devices, a preferred driver, and device info.

Parameters
p_deviceEnumerate[AI] Enumerated device/driver/format list to select from.
p_driver[AI] Specific driver to select.
p_device[AI] Desired Direct3D device info.
Returns
BOOL [AI] TRUE if device was set successfully, FALSE on failure or not found.

Definition at line 253 of file mxdirect3d.cpp.

◆ ZBufferDepth()

int MxDirect3D::ZBufferDepth ( MxAssignedDevice p_assignedDevice)
protected

[AI] Determines the suitable ZBuffer depth for a selected rendering device, according to its capabilities.

Parameters
p_assignedDevice[AI] The device for which to query the ZBuffer depth.
Returns
int [AI] Depth in bits (e.g., 8/16/24/32), or -1 on failure.

Definition at line 220 of file mxdirect3d.cpp.


The documentation for this class was generated from the following files: