D3D Interface

Describes the D3DInterface and all its constants

Summary
D3D InterfaceDescribes the D3DInterface and all its constants
FlagsUsed to keep track of the valid modes in D3DInterface
Enumerations
D3D_STATE_TYPUsed to describe the state of the D3DInterface class
D3DInterfaceThis is the main interface into Direct3D.
D3DInterfaceGets a handle to the DIRECT3D9 Interface if there is none already
~D3DInterfaceCloses the interface, but does not shutdown the handle unless explicitely told to.
Access FunctionsThe first two do not require any interface and are declared static so anything can access them.
getStateGets the current state of the D3DInterface
getFlagsGets the current flags of the D3DInterface
TestStateTests the coop mode and adjust the state as neccessary
EnumDisplayModesFills the windows control with all the available display modes.
CheckoutDeviceUse the D3DDevice for using these functions to stay exception safe.
ReturnDeviceUse the D3DDevice for using these functions to stay exception safe.
Static Functions
InitDeviceUses the startup settings from CStartup to setup the display mode
ResetDeviceUses the previous init settings to recreate a lost device
__WindowedModeGet the ResetDevice ready windowed mode
__FullscreenModeGet the ResetDevice ready fullscreen mode
__ResizeResizes the backbuffer from a window size change
ShutdownDeviceShutsdown all the D3D Interfaces.
Exception Classes
xD3DCreateFailedThis is thrown when the interface is unable to Query a D3D COM object
xD3DEnumFailedThis is thrown when the interface is unable to Enumerate the display modes available.
D3DDeviceThis will grab the D3D Device in an exception-safe way.
D3DDeviceGrabs a Direct3DDevice9 from the D3D Interface and stores the ID.
~D3DDeviceIf there is a device attached, it returns it with the ID saved in the constructor
Operators
operator->Indirection operator so you can use this class as if its the device.
operator LPDIRECT3DDEVICE9Used to provide the class directly whenever a function needs a D3DDevice pointer
operator!Polls wether a D3DDevice has been checkout or not
Functions
ReturnDeviceReturns the device before the class goes out of scope

Flags

Used to keep track of the valid modes in D3DInterface

D3D_A1R5G5B516bit RGBA Mode
D3D_A2R10G10B1032bit 10bit Channel RGBA Mode
D3D_A8R8G8B832bit 8bit Channel RGBA Mode
D3D_R5G6B516bit RGB Mode
D3D_X1R5G5B516bit RGB Mode
D3D_X8R8G8B832bit RGB Mode
D3D_SOFTWAREUses Software Vertex Processing
D3D_MIXEDUses a mix of Software and Hardware Vertex Processing
D3D_HARDWAREUses Hardware Vertex Processing

Enumerations

D3D_STATE_TYP

Used to describe the state of the D3DInterface class

D3D_STATE_ERRORInterface is in an errored mode
D3D_STATE_CLEANInterface is not initialized
D3D_STATE_RESTOREInterface is ready to be restored
D3D_STATE_WAITInterface must wait to be used
D3D_STATE_READYInterface is ready to use

D3DInterface

class D3DInterface

This is the main interface into Direct3D.  Mainly used by the Startup to setup all the mode and to prepare the surfaces.

Summary
D3DInterfaceGets a handle to the DIRECT3D9 Interface if there is none already
~D3DInterfaceCloses the interface, but does not shutdown the handle unless explicitely told to.
Access FunctionsThe first two do not require any interface and are declared static so anything can access them.
getStateGets the current state of the D3DInterface
getFlagsGets the current flags of the D3DInterface
TestStateTests the coop mode and adjust the state as neccessary
EnumDisplayModesFills the windows control with all the available display modes.
CheckoutDeviceUse the D3DDevice for using these functions to stay exception safe.
ReturnDeviceUse the D3DDevice for using these functions to stay exception safe.
Static Functions
InitDeviceUses the startup settings from CStartup to setup the display mode
ResetDeviceUses the previous init settings to recreate a lost device
__WindowedModeGet the ResetDevice ready windowed mode
__FullscreenModeGet the ResetDevice ready fullscreen mode
__ResizeResizes the backbuffer from a window size change
ShutdownDeviceShutsdown all the D3D Interfaces.
Exception Classes
xD3DCreateFailedThis is thrown when the interface is unable to Query a D3D COM object
xD3DEnumFailedThis is thrown when the interface is unable to Enumerate the display modes available.

D3DInterface

D3DInterface()

Gets a handle to the DIRECT3D9 Interface if there is none already

Throws

xD3DCreateFailed if it fails to create a handle

~D3DInterface

~D3DInterface()

Closes the interface, but does not shutdown the handle unless explicitely told to.

Access Functions

The first two do not require any interface and are declared static so anything can access them.

getState

static D3D_STATE_TYP getState()

Gets the current state of the D3DInterface

Returns

D3D_STATE_TYP for the current running mode

getFlags

static DWORD getFlags()

Gets the current flags of the D3DInterface

Returns

DWORD with the Flags of the current runnning mode

TestState

static D3D_STATE_TYP TestState()

Tests the coop mode and adjust the state as neccessary

Returns

D3D_STATE_TYP with the new state the Interface is in

EnumDisplayModes

int EnumDisplayModes (const HWND hwnd,
const int rcResource) const

Fills the windows control with all the available display modes.  Not Static and requires an interface to Direct3D9, but not to Direct3DDevice9.

The window pointer to by the HWND will now contain all of the available display modes in this format.

WidthxHeight hz Color=D3DFORMAT_RGBSTRING

Parameters

hwndHWND The window with the control to fill
rcResourceINT the control ID in the window to fill

Returns

False if successful, error code otherwise.

Throws

xD3DEnumFailed if unable to grab any data.

CheckoutDevice

const LPDIRECT3DDEVICE9 CheckoutDevice(int &ID)

Use the D3DDevice for using these functions to stay exception safe.

This function will checkout a Direct3DDevice9 for use.

Parameters

IDINT This is filled with an unique ID that must be returned to the ReturnDevice to avoid an assertion error.

Returns

LPDIRECT3DDEVICE9 for the current running mode.  Locks a mutex until ReturnDevice is called.

ReturnDevice

void ReturnDevice(int &ID)

Use the D3DDevice for using these functions to stay exception safe.

Returns the device that was sent by CheckoutDevice

Parameters

IDINT This must be the same ID number that was filled into it by CheckoutDevice

Static Functions

InitDevice

static int InitDevice(const HWND hwnd)

Uses the startup settings from CStartup to setup the display mode

Parameters

hwndHWND Used to specify which window the device will be created for

Returns

False if succesful, error code otherwise.

ResetDevice

static int ResetDevice()

Uses the previous init settings to recreate a lost device

Returns

False if successful, error code otherwise

__WindowedMode

static int __WindowedMode()

Get the ResetDevice ready windowed mode

Returns

False if successful, error code otherwise

__FullscreenMode

static int __FullscreenMode()

Get the ResetDevice ready fullscreen mode

Returns

False if successful, error code otherwise

__Resize

static int __Resize()

Resizes the backbuffer from a window size change

Returns

False if successful, error code otherwise

ShutdownDevice

static void ShutdownDevice()

Shutsdown all the D3D Interfaces.  Make sure to run this only after everything has been released that was created using the D3DDevice.

Exception Classes

xD3DCreateFailed

This is thrown when the interface is unable to Query a D3D COM object

class xD3DCreateFailed : public std::exception

xD3DEnumFailed

This is thrown when the interface is unable to Enumerate the display modes available.

class xD3DEnumFailed : public std::exception

D3DDevice

class D3DDevice : public boost::noncopyable

This will grab the D3D Device in an exception-safe way.  When D3DInterface is in D3D_STATE_READY, it allows you to use the indirection operator-> to access the device type directly.

Summary
D3DDeviceGrabs a Direct3DDevice9 from the D3D Interface and stores the ID.
~D3DDeviceIf there is a device attached, it returns it with the ID saved in the constructor
Operators
operator->Indirection operator so you can use this class as if its the device.
operator LPDIRECT3DDEVICE9Used to provide the class directly whenever a function needs a D3DDevice pointer
operator!Polls wether a D3DDevice has been checkout or not
Functions
ReturnDeviceReturns the device before the class goes out of scope

D3DDevice

D3DDevice() : d3ddev(NULL), id3d(), ID(0)

Grabs a Direct3DDevice9 from the D3D Interface and stores the ID.

~D3DDevice

~D3DDevice()

If there is a device attached, it returns it with the ID saved in the constructor

Operators

operator->

const LPDIRECT3DDEVICE9 operator->() const

Indirection operator so you can use this class as if its the device.

Returns

LPDIRECTD3DDEVICE9 interface

operator LPDIRECT3DDEVICE9

operator LPDIRECT3DDEVICE9() const

Used to provide the class directly whenever a function needs a D3DDevice pointer

operator!

BOOL operator!() const

Polls wether a D3DDevice has been checkout or not

Returns

False if d3ddev, true otherwise

Functions

ReturnDevice

void ReturnDevice(void)

Returns the device before the class goes out of scope

class D3DInterface
This is the main interface into Direct3D.
D3DInterface()
Gets a handle to the DIRECT3D9 Interface if there is none already
~D3DInterface()
Closes the interface, but does not shutdown the handle unless explicitely told to.
static D3D_STATE_TYP getState()
Gets the current state of the D3DInterface
static DWORD getFlags()
Gets the current flags of the D3DInterface
static D3D_STATE_TYP TestState()
Tests the coop mode and adjust the state as neccessary
int EnumDisplayModes (const HWND hwnd,
const int rcResource) const
Fills the windows control with all the available display modes.
const LPDIRECT3DDEVICE9 CheckoutDevice(int &ID)
Use the D3DDevice for using these functions to stay exception safe.
class D3DDevice : public boost::noncopyable
This will grab the D3D Device in an exception-safe way.
void ReturnDevice(int &ID)
Use the D3DDevice for using these functions to stay exception safe.
static int InitDevice(const HWND hwnd)
Uses the startup settings from CStartup to setup the display mode
class CStartup
Interface to control and query the running state of the program.
static int ResetDevice()
Uses the previous init settings to recreate a lost device
static int __WindowedMode()
Get the ResetDevice ready windowed mode
static int __FullscreenMode()
Get the ResetDevice ready fullscreen mode
static int __Resize()
Resizes the backbuffer from a window size change
static void ShutdownDevice()
Shutsdown all the D3D Interfaces.
D3DDevice() : d3ddev(NULL), id3d(), ID(0)
Grabs a Direct3DDevice9 from the D3D Interface and stores the ID.
~D3DDevice()
If there is a device attached, it returns it with the ID saved in the constructor
const LPDIRECT3DDEVICE9 operator->() const
Indirection operator so you can use this class as if its the device.
operator LPDIRECT3DDEVICE9() const
Used to provide the class directly whenever a function needs a D3DDevice pointer
BOOL operator!() const
Polls wether a D3DDevice has been checkout or not
void ReturnDevice(void)
Returns the device before the class goes out of scope
This is thrown when the interface is unable to Query a D3D COM object
Used to describe the state of the D3DInterface class
This is thrown when the interface is unable to Enumerate the display modes available.
Interface is ready to use
Close