// -------------------------------------------------------------------------- // ========================================================================== // File: TDx9_3D.CPP // Authors: BCB_Code_Generator v2.00, // Darren Dwyer (source code, documentation, demos, website), // Hugh Edwards (documentation, icons) // Description: This file contains the code for the TDx9_3D Component // // "TDx9_Graphics_Library v1.00" // (c) 2005 BCB-Tools.com Pty. Ltd., Sydney, Australia. // All Rights Reserved. // // Refer to the 'Licence.Txt' file for licencing & copyright information. // ========================================================================== // -------------------------------------------------------------------------- // #includes ... // -------------------------------------------------------------------------- #include #pragma hdrstop // -------------------------------------------------------------------------- #include "TDx9_3D.H" // -------------------------------------------------------------------------- // external classes used by TDx9_3D methods. #include "TDx9_3DDevice.H" // -------------------------------------------------------------------------- #pragma link "TDx_Library_Defns" #pragma link "TDx_Library_Functions" #pragma link "TDx9_Graphics_Library_Defns" #pragma link "TDx9_Graphics_Library_Functions" // -------------------------------------------------------------------------- // Object Registration... // -------------------------------------------------------------------------- #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ #pragma package(smart_init) #endif // -------------------------------------------------------------------------- static inline void ValidCtrCheck(TDx9_3D*) { new TDx9_3D(NULL); } // -------------------------------------------------------------------------- namespace Tdx9_3d { #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ void __fastcall PACKAGE Register() #else void __fastcall Register() #endif { TComponentClass classes[1] = {__classid(TDx9_3D)}; RegisterComponents("TDx9_Graphics", classes, 0); } } // -------------------------------------------------------------------------- // Constructor: TDx9_3D::TDx9_3D() // Description: The default constructor for the TDx9_3D object. // -------------------------------------------------------------------------- __fastcall TDx9_3D::TDx9_3D(TComponent* Owner) : TComponent(Owner) { fErrorValue = D3D_OK; fCreated = false; } // -------------------------------------------------------------------------- // Destructor: TDx9_3D::~TDx9_3D() // Description: The destructor for the TDx9_3D object. // -------------------------------------------------------------------------- __fastcall TDx9_3D::~TDx9_3D() { // destroy internals if (Created) Destroy(); } // -------------------------------------------------------------------------- // Property: Created // Description: The Created property is true if the internal LPDIRECT3D9 used // in this component has been successfully created, otherwise // Created is false. // // To create the internal LPDIRECT3D9, call the // TDx9_3D::Create() method. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::FGetCreated() { return fCreated; } // -------------------------------------------------------------------------- void __fastcall TDx9_3D::FSetCreated( bool pCreated ) { fCreated = (pCreated && (fLPDIRECT3D9==NULL)); } // -------------------------------------------------------------------------- // Property: ErrorValue // Description: The ErrorValue property contains the last error value // returned from a call to a TDx9_3D method or fget/fset. eg. // D3D_OK or DDERR_SURFACELOST or TDX_ERROR // -------------------------------------------------------------------------- HRESULT __fastcall TDx9_3D::FGetErrorValue() { return fErrorValue; } // -------------------------------------------------------------------------- void __fastcall TDx9_3D::FSetErrorValue( HRESULT pErrorValue ) { fErrorValue = pErrorValue; } // -------------------------------------------------------------------------- // Method: CheckDepthStencilMatch() // Description: The TDx9_3D::CheckDepthStencilMatch() method will check that // a specific depth stencil format is compatible with a render // target format in a particular display mode. // // This method is included in DirectX9 to enable applications to // work with hardware that requires certain depth formats only // work with certain render target formats. // Unlike DirectX 8.1, D24x8 and D32 depth-stencil formats are // not assumed to work with 32- or 16-bit render targets, it // will now return successfully for these formats only if the // device is capable of mixed-depth operations. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when a parameter is invalid. // D3DERR_NOTAVAILABLE when the check indicates incompatible // formats. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter to query. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pDeviceType - // The DeviceType parameter specifies the device type, as a // value of the D3DDEVTYPE enumerated type. // pAdapterFormat - // The AdapterFormat parameter specifies which display mode // format the adapter will be set to, as a value of the // D3DFORMAT enumerated type. // pRenderTargetFormat - // The RenderTargetFormat parameter specifies which render // target format is to be tested, as a value of the D3DFORMAT // enumerated type. // pDepthStencilFormat - // The DepthStencilFormat parameter specifies which depth // stencil format is to be tested, as a value of the D3DFORMAT // enumerated type. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::CheckDepthStencilMatch( uint pAdapter, D3DDEVTYPE pDeviceType, D3DFORMAT pAdapterFormat, D3DFORMAT pRenderTargetFormat, D3DFORMAT pDepthStencilFormat ) { // Original Function Definition // HRESULT CheckDepthStencilMatch( // UINT Adapter, // D3DDEVTYPE DeviceType, // D3DFORMAT AdapterFormat, // D3DFORMAT RenderTargetFormat, // D3DFORMAT DepthStencilFormat // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::CheckDepthStencilMatch()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->CheckDepthStencilMatch( (UINT) pAdapter, pDeviceType, pAdapterFormat, pRenderTargetFormat, pDepthStencilFormat ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::CheckDepthStencilMatch()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: CheckDeviceFormat() // Description: The TDx9_3D::CheckDeviceFormat() method will check that a // specific surface format is available as a specified resource // type and can be used as a texture, depth stencil buffer, // render target or any combination of the three, on a device // representing this adapter. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when Adapter >= the number of display // adapters in the system or is an unsupported DeviceType. // D3DERR_NOTAVAILABLE when the specified device and usage will // not accept the format. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter to query. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pDeviceType - // The DeviceType parameter specifies the device type, as a // value of the D3DDEVTYPE enumerated type. // pAdapterFormat - // The AdapterFormat parameter specifies which display mode // format the adapter will be set to, as a value of the // D3DFORMAT enumerated type. // pUsage - // The Usage parameter defines the usage options for the surface // as any combination of the D3DUSAGE and D3DUSAGE_QUERY // constants. // Some D3DUSAGE's are invalid for this method. // pRType - // The RType parameter specifies which resource type is // requested for use with the queried format, as a value of the // D3DRESOURCETYPE enumerated type. // pCheckFormat - // The CheckFormat parameter specifies the format of the // surfaces whose use is defined by Usage, as a value of the // D3DFORMAT enumerated type. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::CheckDeviceFormat( uint pAdapter, D3DDEVTYPE pDeviceType, D3DFORMAT pAdapterFormat, dword pUsage, D3DRESOURCETYPE pRType, D3DFORMAT pCheckFormat ) { // Original Function Definition // HRESULT CheckDeviceFormat( // UINT Adapter, // D3DDEVTYPE DeviceType, // D3DFORMAT AdapterFormat, // DWORD Usage, // D3DRESOURCETYPE RType, // D3DFORMAT CheckFormat // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::CheckDeviceFormat()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->CheckDeviceFormat( (UINT) pAdapter, pDeviceType, pAdapterFormat, (DWORD) pUsage, pRType, pCheckFormat ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::CheckDeviceFormat()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: CheckDeviceFormatConversion() // Description: The TDx9_3D::CheckDeviceFormatConversion() method will check // whether the device can convert from one display format to // another. // // When you use TDx9_3D::CheckDeviceType() to test compatibility // between a back buffer and a display of a different format, it // will return values that reflect the device capabilities. This // means when the device cannot render to the requested back // buffer format, the call will return D3DERR_NOTAVAILABLE even // if color conversion is availble. If the device can render, // but not color convert, the return value will also be // D3DERR_NOTAVAILABLE. // This method helps an application discover what hardware // support is available for the presentation itself, as distinct // from rendering capabilities. // No software emulation for the color-converting presentation // itself will be offered. // This method also helps determine the source and destination // surface formats are permissible in // TDx9_3DDevice::StretchRect(). // // Color conversion is restricted to the following source and // target formats. // The source must be a four-character code (FOURCC) format or // valid back buffer format. // The target format must be one of these unsigned formats: // D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5, D3DFMT_R5G6B5, // D3DFMT_R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, // D3DFMT_A2R10G10B10, D3DFMT_A16B16G16R16, D3DFMT_A2B10G10R10, // D3DFMT_A8B8G8R8, D3DFMT_X8B8G8R8, D3DFMT_A16B16G16R16F or // D3DFMT_A32B32G32R32F. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when the method simply fails. // D3DERR_NOTAVAILABLE when the specified conversion is not // supported. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter to query. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pDeviceType - // The DeviceType parameter specifies the device type, as a // value of the D3DDEVTYPE enumerated type. // pSourceFormat - // The SourceFormat parameter specifies the source format, as a // value of the D3DFORMAT enumerated type. // pTargetFormat - // The TargetFormat parameter specifies the destination format, // as a value of the D3DFORMAT enumerated type. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::CheckDeviceFormatConversion( uint pAdapter, D3DDEVTYPE pDeviceType, D3DFORMAT pSourceFormat, D3DFORMAT pTargetFormat ) { // Original Function Definition // HRESULT CheckDeviceFormatConversion( // UINT Adapter, // D3DDEVTYPE DeviceType, // D3DFORMAT SourceFormat, // D3DFORMAT TargetFormat // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::CheckDeviceFormatConversion()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->CheckDeviceFormatConversion( (UINT) pAdapter, pDeviceType, pSourceFormat, pTargetFormat ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::CheckDeviceFormatConversion()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: CheckDeviceMultiSampleType() // Description: The TDx9_3D::CheckDeviceMultiSampleType() method will check // whether the device supports a specified multisampling // technique. // // Check both render target and depth stencil surfaces using // this method when using multisampling because both must be // multisampled if you want to use them together. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when Adapter or MultiSampleType is // invalid. // D3DERR_NOTAVAILABLE when the specified multisampling // technique is not supported. // D3DERR_INVALIDDEVICE when the DeviceType does not apply to // this adapter. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter to query. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pDeviceType - // The DeviceType parameter specifies the device type, as a // value of the D3DDEVTYPE enumerated type. // pSurfaceFormat - // The SurfaceFormat parameter specifies the surface format you // want to multisample, as a value of the D3DFORMAT enumerated // type. // pWindowed - // The Windowed parameter indicates whether windowed // multisampling is being checked. // Set TRUE to check windowed multisampling and FALSE to check // full screen multisampling. // pMultiSampleType - // The MultiSampleType parameter specifies which multisample // type to check, as a value of the D3DMULTISAMPLE_TYPE // enumerated type. // pQualityLevels - // The QualityLevels parameter will indicate how many quality // stops are available for the specified multisample type. // Can be NULL if this return value is not required. // -------------------------------------------------------------------------- HRESULT __fastcall TDx9_3D::CheckDeviceMultiSampleType( uint pAdapter, D3DDEVTYPE pDeviceType, D3DFORMAT pSurfaceFormat, bool pWindowed, D3DMULTISAMPLE_TYPE pMultiSampleType, dword* pQualityLevels ) { // Original Function Definition // HRESULT CheckDeviceMultiSampleType( // UINT Adapter, // D3DDEVTYPE DeviceType, // D3DFORMAT SurfaceFormat, // BOOL Windowed, // D3DMULTISAMPLE_TYPE MultiSampleType, // DWORD* pQualityLevels // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::CheckDeviceMultiSampleType()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return fErrorValue; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->CheckDeviceMultiSampleType( (UINT) pAdapter, pDeviceType, pSurfaceFormat, (BOOL) pWindowed, pMultiSampleType, (DWORD*) pQualityLevels ); // Success! return fErrorValue; } // -------------------------------------------------------------------------- // Method: CheckDeviceType() // Description: The TDx9_3D::CheckDeviceType() method will check whether the // adapter supports a specific hardware accelerated device type. // // This method checks if the hardware and drivers necessary for // a specified Hardware Abstraction Layer (HAL) device type are // available. // Specifying a DisplayFormat with an alpha channel for a full // screen application will fail this method. Back buffer alpha // channels are allowed, but the two display formats must be // otherwise identical. // For example: A DisplayFormat of D3DFMT_X1R5G5B5 works with a // BackBufferFormat of D3DFMT_X1R5G5B5 or D3DFMT_A1R5G5B5 but // not D3DFMT_R5G6B5. // // When you use TDx9_3D::CheckDeviceType() to test compatibility // between a back buffer and a display of a different format, it // will return values that reflect the device capabilities. This // means when the device cannot render to the requested back // buffer format, the call will return D3DERR_NOTAVAILABLE even // if color conversion is availble. If the device can render, // but not color convert, the return value will also be // D3DERR_NOTAVAILABLE. // The TDx9_3D::CheckDeviceFormatConversion() method helps an // application discover what hardware support is available for // the presentation itself, as distinct from rendering // capabilities. // No software emulation for the color-converting presentation // itself will be offered. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when Adapter >= the number of display // adapters in the system or is an unsupported DeviceType. // D3DERR_NOTAVAILABLE when the specified back buffer format is // not supported or there is no hardware acceleration for the // specified formats. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter to enumerate. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pDeviceType - // The DeviceType parameter specifies the device type to check, // as a value of the D3DDEVTYPE enumerated type. // pDisplayFormat - // The DisplayFormat parameter specifies which display mode to // check the device under, as a value of the D3DFORMAT // enumerated type. // pBackBufferFormat - // The BackBufferFormat parameter specifies which back buffer // format to check the device under, as a value of the D3DFORMAT // enumerated type. // // This must be a render target format, // TDx9_3DDevice::GetDisplayMode() can be used to retrieve the // current format. // Windowed applications can have a back buffer format that is // different to the display format, but only if there is // hardware support for color conversion. Possible back buffer // formats are limited in these circumstances, but any valid // backbuffer format will be presented to any desktop format. // However, the device must also be operable in desktop mode, as // many devices do not operate in 8 bits per pixel modes. // Full-screen applications cannot do color conversion. // The D3DFMT_UNKNOWN value is allowed for windowed mode. // pWindowed - // The Windowed parameter indicates whether the device type will // be checked for windowed operation. // Set TRUE to check windowed operation and FALSE to check full // screen operation. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::CheckDeviceType( uint pAdapter, D3DDEVTYPE pDeviceType, D3DFORMAT pDisplayFormat, D3DFORMAT pBackBufferFormat, bool pWindowed ) { // Original Function Definition // HRESULT CheckDeviceType( // UINT Adapter, // D3DDEVTYPE DeviceType, // D3DFORMAT DisplayFormat, // D3DFORMAT BackBufferFormat, // BOOL Windowed // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::CheckDeviceType()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->CheckDeviceType( (UINT) pAdapter, pDeviceType, pDisplayFormat, pBackBufferFormat, (BOOL) pWindowed ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::CheckDeviceType()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: Create() // Description: The Create() method is used to automatically create the // internal LPDIRECT3D9 interface used in the TDx9_3D component // and must be called before any methods of the TDx9_3D // component will function. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::Create() { // Original Function Definition // virtual bool __fastcall Create(); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::Create()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function //fErrorValue = (uint) fLPDIRECT3D9->Create( ); // Success! return true; } // -------------------------------------------------------------------------- // Method: CreateDevice() // Description: The TDx9_3D::CreateDevice() method is used to create a device // to represent the display adapter. // // A fully working device interface is returned, already set to // the required display or windowed mode and with the requested // back buffers. // To begin rendering, just create and set a depth buffer if // EnableAutoDepthStencil is set to FALSE in // PresentationParameters. // // When creating the TDx9_3DDevice, two window handles are // needed, the FocusWindow parameter and DeviceWindow property // of PresentationParameters: // The focus window indicates to Direct3D when switching from // foreground mode to background mode due to events like Alt-Tab // or minimise. There is only one focus window that is shared by // each device created by an application. // The device window determines the location and size of the // back buffer on screen and is used during // TDx9_3DDevice::Present() when the back buffer contents are // copied to the front buffer. // // Window handles should never be passed to Direct3D while // handling WM_CREATE and this method is no exception. Calls to // create, release or reset the device must be done by the same // thread as the window procedure of the focus window. // // One of the mutually exclusive processing flags, // D3DCREATE_HARDWARE_VERTEXPROCESSING, // D3DCREATE_MIXED_VERTEXPROCESSING and // D3DCREATE_SOFTWARE_VERTEXPROCESSING, must be set. // // D3DPRESENTFLAG_LOCKABLE_BACKBUFFER must be set in the // PresentationParameters for the back buffer to be lockable, // but multisampled back buffers and depth surfaces are never // lockable. // // The TDx9_3DDevice::Reset(), IUnknown::Release() and // TDx9_3DDevice::TestCooperativeLevel() methods must be called // from the same thread as created the device. // // When using windowed mode, D3DFMT_UNKNOWN can be specified as // the back buffer format in TDx9_3D::CreateDevice(), // TDx9_3DDevice::Reset() and // TDx9_3DDevice::CreateAdditionalSwapChain(). As a result, you // don't need to retrieve the desktop format before the create // call. // In full screen mode, the back buffer format must always be // specified. // Attempts to create a device on a 0x0 sized window will fail. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_DEVICELOST when the device is lost but cannot be reset // at the moment. Rendering is not possible. // D3DERR_INVALIDCALL for invalid parameters or settings. // D3DERR_NOTAVAILABLE when the device doesn't support the // specified settings. // D3DERR_OUTOFVIDEOMEMORY if there is insufficient display // memory for the device to be created. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pDeviceType - // The DeviceType parameter specifies the device type to create, // as a value of the D3DDEVTYPE enumerated type. // If the type is unsupported, the method will fail. // pFocusWindow - // The FocusWindow parameter specifies the focus window that // alerts Direct3D when the application switches from foreground // mode to background mode. // This must be a top level window for full screen mode. // NULL may be specified for windowed mode, but then you must // provide a non-NULL handle in either // TDx9_3DDevice::Present->DestWndOverride or // TD3DPresent_Parameters->DeviceWindow when calling // TDx9_3DDevice::Present(). // pBehaviorFlags - // The BehaviorFlags parameter contains device creation settings // as defined by the D3DCREATE constant. // pPresentationParameters - // The PresentationParameters parameter references a // TD3DPresent_Parameters component containing the presentation // settings for the device to be created. // // After the create call, the returned TD3DPresent_Parameters // may have several different values, specifically: // If BackBufferCount, BackBufferWidth and BackBufferHeight were // 0, they will be set to the appropriate values when the method // returns. // If BackBufferFormat was D3DFMT_UNKNOWN, then it will be set // to the appropriate format when the method returns. // // If D3DCREATE_ADAPTERGROUP_DEVICE is specified in // BehaviorFlags, then TD3DPresent_Parameters can contain // multiple instances of presentation parameters. // No matter how many heads exist, only one depth/stencil // surface is created automatically. // // For Win2K and XP, the full-screen device display refresh rate // will be set to the closest supported rate below it, in this // order: // User specified nonzero ForcedRefreshRate registry key, if // supported. // Application specified nonzero refresh rate value in the // presentation parameter. // Refresh rate of the latest desktop mode, if supported. // 75 hertz if supported. // 60 hertz if supported. // Device default. // pReturnedDeviceInterface - // The ReturnedDeviceInterface parameter will reference the // address of the created TDx9_3DDevice. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::CreateDevice( uint pAdapter, D3DDEVTYPE pDeviceType, HWND pFocusWindow, dword pBehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, TDx9_3DDevice* pReturnedDeviceInterface ) { // Original Function Definition // HRESULT CreateDevice( // UINT Adapter, // D3DDEVTYPE DeviceType, // HWND hFocusWindow, // DWORD BehaviorFlags, // D3DPRESENT_PARAMETERS *pPresentationParameters, // LPDIRECT3DDEVICE9* ppReturnedDeviceInterface // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::CreateDevice()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->CreateDevice( (UINT) pAdapter, pDeviceType, pFocusWindow, (DWORD) pBehaviorFlags, pPresentationParameters, (pReturnedDeviceInterface==NULL) ? NULL : pReturnedDeviceInterface->Internal_LPDIRECT3DDEVICE9_Ptr ); // Translate Data returned from Function if (pReturnedDeviceInterface!=NULL) pReturnedDeviceInterface->Internal_LPDIRECT3DDEVICE9_Update(); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::CreateDevice()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: Destroy() // Description: The Destroy() method is used to automatically destroy the // internal LPDIRECT3D9 interface used in the TDx9_3D component // and should be called when the internal interface is no longer // required. // // Note: This method is called by the component's destructor. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::Destroy() { // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::Destroy()", "TDX_NOTCREATED", "The "+Name+"::Destroy() method was called before being created successfully." ); return false; } // code that destroys the internal interfaces if (FOnDestroy) FOnDestroy(this); if (fLPDIRECT3D9==NULL) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, Name+"::Destroy()", "TDX_ERROR", "The "+Name+" component's internal LPDIRECT3D9 is NULL. Aborting the Destroy()." ); return false; } try { fLPDIRECT3D9->Release(); } catch (...) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, Name+"::Destroy()", "TDX_ERROR", "An exception occurred in LPDIRECT3D9->Release(). Check you are destroying all components in reverse order of creation." ); } // successful destruction fLPDIRECT3D9 = NULL; fCreated = false; return true; } // -------------------------------------------------------------------------- // Method: EnumAdapterModes() // Description: The TDx9_3D::EnumAdapterModes() method checks that an adapter // supports the requested display mode and format. // // By utilizing this method in a loop, all available adapter // modes can be enumerated. // Enumeration is restricted to display modes exactly matching // the provided format, ignoring alpha. // // Pixel formats 565 and 555 are treated as equivalent and the // correct version will be returned. // The difference only affects anything when locking the back // buffer, which requires an explicit flag to be set by the // application. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when Adapter >= available display // adapters. // D3DERR_NOTAVAILABLE when there is no support for the surface // format or acceleration is not available. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pFormat - // The Format parameter specifies the surface format you want to // enumerate, as a value of the D3DFORMAT enumerated type. // // Allowed values are D3DFMT_A1R5G5B5, D3DFMT_A2R10G10B10, // D3DFMT_A8R8G8B8, D3DFMT_R5G6B5, D3DFMT_X1R5G5B5 and // D3DFMT_X8R8G8B8. // pMode - // The Mode parameter specifies the display mode index. // // This value must be an unsigned integer between 0 and one less // than the return value of TDx9_3D::GetAdapterModeCount(). // pDisplayMode - // The DisplayMode parameter will reference a TD3DDisplayMode // component describing the available display mode. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::EnumAdapterModes( uint pAdapter, D3DFORMAT pFormat, uint pMode, D3DDISPLAYMODE* pDisplayMode ) { // Original Function Definition // HRESULT EnumAdapterModes( UINT Adapter, // D3DFORMAT Format, // UINT Mode, // D3DDISPLAYMODE* pMode // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::EnumAdapterModes()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->EnumAdapterModes( (UINT) pAdapter, pFormat, (UINT) pMode, pDisplayMode ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::EnumAdapterModes()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: GetAdapterCount() // Description: The TDx9_3D::GetAdapterCount() method will return an unsigned // integer specifying how many adapters were available when this // TDx9_3D component was created. // -------------------------------------------------------------------------- UINT __fastcall TDx9_3D::GetAdapterCount() { // Original Function Definition // UINT GetAdapterCount(); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetAdapterCount()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return fErrorValue; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->GetAdapterCount( ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetAdapterCount()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return fErrorValue; } // Success! return fErrorValue; } // -------------------------------------------------------------------------- // Method: GetAdapterDisplayMode() // Description: The TDx9_3D::GetAdapterDisplayMode() method retrieves the // current display mode. // // Extended formats will not be returned accurately, reporting // X8R8G8B8 instead. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when Adapter >= available display adapters // or Mode is invaild. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter to query. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pMode - // The Mode parameter references a TD3DDisplayMode component for // holding the returned display mode. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::GetAdapterDisplayMode( uint pAdapter, D3DDISPLAYMODE* pMode ) { // Original Function Definition // HRESULT GetAdapterDisplayMode( // UINT Adapter, // D3DDISPLAYMODE *pMode // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetAdapterDisplayMode()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->GetAdapterDisplayMode( (UINT) pAdapter, pMode ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetAdapterDisplayMode()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: GetAdapterIdentifier() // Description: The TDx9_3D::GetAdapterIdentifier() method will retrieve // information about the specified display adapter. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when Adapter >= available display // adapters, Flags has unrecognized flags or Identifier is NULL // or unwritable. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pFlags - // The Flags parameter specifies the value of // TD3DAdapter_Identifier->WHQLLevel. // // This value can be 0 or D3DENUM_WHQL_LEVEL. // When D3DENUM_WHQL_LEVEL is set, this call can connect to the // internet and retrieve new Windows Hardware Quality Labs // (WHQL) certificates. // Flags: // D3DENUM_WHQL_LEVEL - // The D3DENUM_WHQL_LEVEL Flag is possibly unused. // pIdentifier - // The Identifier parameter references a TD3DAdapter_Identifier // component for holding the returned information. // // If Adapter is out of range, TD3DAdapter_Identifier will be // zero'd. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::GetAdapterIdentifier( uint pAdapter, dword pFlags, D3DADAPTER_IDENTIFIER9* pIdentifier ) { // Original Function Definition // HRESULT GetAdapterIdentifier( // UINT Adapter, // DWORD Flags, // D3DADAPTER_IDENTIFIER9 *pIdentifier // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetAdapterIdentifier()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->GetAdapterIdentifier( (UINT) pAdapter, (DWORD) pFlags, pIdentifier ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetAdapterIdentifier()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: GetAdapterModeCount() // Description: The TDx9_3D::GetAdapterModeCount() method will retrieve how // many display modes are available on the specified adapter for // a given format. // // This method will return 0 if Adapter >= available display // adapters. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pFormat - // The Format parameter specifies the surface format you want to // use, as a value of the D3DFORMAT enumerated type. // // TDx9_3D::EnumAdapterModes() can be used to retrieve valid // formats for the adapter. // -------------------------------------------------------------------------- UINT __fastcall TDx9_3D::GetAdapterModeCount( uint pAdapter, D3DFORMAT pFormat ) { // Original Function Definition // UINT GetAdapterModeCount( // UINT Adapter, // D3DFORMAT Format // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetAdapterModeCount()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return fErrorValue; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->GetAdapterModeCount( (UINT) pAdapter, pFormat ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetAdapterModeCount()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return fErrorValue; } // Success! return fErrorValue; } // -------------------------------------------------------------------------- // Method: GetAdapterMonitor() // Description: The TDx9_3D::GetAdapterMonitor() method will return this // components associated monitor handle. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // -------------------------------------------------------------------------- HMONITOR __fastcall TDx9_3D::GetAdapterMonitor( uint pAdapter ) { // Original Function Definition // HMONITOR GetAdapterMonitor( // UINT Adapter // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetAdapterMonitor()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return (HMONITOR) fErrorValue; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->GetAdapterMonitor( (UINT) pAdapter ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetAdapterMonitor()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return (HMONITOR) fErrorValue; } // Success! return (HMONITOR) fErrorValue; } // -------------------------------------------------------------------------- // Method: GetDeviceCaps() // Description: The TDx9_3D::GetDeviceCaps() method will retrieve the // capabilities of an adapter for a specified device type. // // Do not assume vertex processing capabilities across Direct3D // devices as the exposed capabilities depend on the parameter // settings of the TDx9_3D::CreateDevice() call. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when there are invalid parameters. // D3DERR_INVALIDDEVICE for an invalid device type. // D3DERR_OUTOFVIDEOMEMORY if there is not enough display memory // for the operation. // Params: pAdapter - // The Adapter parameter specifies the ordinal of the display // adapter. // D3DADAPTER_DEFAULT always indicates the primary display // adapter. // pDeviceType - // The DeviceType parameter specifies the device type as a value // of the D3DDEVTYPE enumerated type. // pCaps - // The Caps parameter references a TD3DCaps component that will // be filled with the capability information for the specified // adapter and device type. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::GetDeviceCaps( uint pAdapter, D3DDEVTYPE pDeviceType, D3DCAPS9* pCaps ) { // Original Function Definition // HRESULT GetDeviceCaps( // UINT Adapter, // D3DDEVTYPE DeviceType, // D3DCAPS9 *pCaps // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetDeviceCaps()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->GetDeviceCaps( (UINT) pAdapter, pDeviceType, pCaps ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetDeviceCaps()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: RegisterSoftwareDevice() // Description: The TDx9_3D::RegisterSoftwareDevice() method will register a // pluggable software device, which can enable the application // to access a variety of software rasterisers and other // emulated devices. // // When there is no 3D acceleration hardware, software emulation // may be needed. Software rasterization devices emulate color // 3D hardware. // Emulation is slower than specialized hardware but can take // advantage of CPU instructions like the AMD 3DNow! or Intel // MMX instruction sets. // Direct3D used 3D-Now! for some lighting operations and MMX // for rasterization acceleration. // // Software devices communicate with Direct3D through an // interface similar to the hardware device driver interface // (DDI). // The Direct3D Driver Development Kit (DDK) provides the // documentation and headers for developing pluggable software // devices. // // If the method call fails, the OnError event will be triggered // with one of the following values: // D3DERR_INVALIDCALL when there are invalid parameters. // D3DERR_OUTOFVIDEOMEMORY if there is not enough display memory // for the operation. // Params: pInitializeFunction - // The InitializeFunction parameter references the software // device's initialization function. // -------------------------------------------------------------------------- bool __fastcall TDx9_3D::RegisterSoftwareDevice( void* pInitializeFunction ) { // Original Function Definition // HRESULT RegisterSoftwareDevice( // void *pInitializeFunction // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::RegisterSoftwareDevice()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPDIRECT3D9->RegisterSoftwareDevice( pInitializeFunction ); // Handle any Known Results if (fErrorValue!=D3D_OK) { // Failure. if (FOnError) FOnError( this, Name+"::RegisterSoftwareDevice()", TDx9_Graphics_Library_ErrorString(fErrorValue), TDx9_Graphics_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Internal Interface Access // -------------------------------------------------------------------------- LPDIRECT3D9 __fastcall TDx9_3D::FGetInternal_LPDIRECT3D9() { return fLPDIRECT3D9; } // -------------------------------------------------------------------------- LPDIRECT3D9* __fastcall TDx9_3D::FGetInternal_LPDIRECT3D9_Ptr() { return &fLPDIRECT3D9; } // -------------------------------------------------------------------------- void __fastcall TDx9_3D::FSetInternal_LPDIRECT3D9( LPDIRECT3D9 pLPDIRECT3D9 ) { if (!fCreated) { fLPDIRECT3D9 = pLPDIRECT3D9; fCreated = (fLPDIRECT3D9!=NULL); } } // -------------------------------------------------------------------------- void __fastcall TDx9_3D::Internal_LPDIRECT3D9_Update() { fCreated = (fLPDIRECT3D9!=NULL); } // --------------------------------------------------------------------------