2007-12-19 17:41:05 +00:00
/*
* COPYRIGHT : See COPYING in the top level directory
* PROJECT : ReactOS ReactX
* FILE : dll / directx / d3d9 / d3d9_impl . c
* PURPOSE : IDirect3D9 implementation
* PROGRAMERS : Gregor Brunmar < gregor ( dot ) brunmar ( at ) home ( dot ) se >
*/
2008-01-13 11:45:31 +00:00
# include "d3d9_common.h"
# include <d3d9.h>
2007-12-19 17:41:05 +00:00
# include <debug.h>
2008-02-04 21:33:12 +00:00
# include "d3d9_helpers.h"
# include "adapter.h"
2008-02-26 21:33:04 +00:00
# include "format.h"
2007-12-19 17:41:05 +00:00
2008-05-04 11:48:06 +00:00
# define LOCK_D3D9() EnterCriticalSection(&This->d3d9_cs);
# define UNLOCK_D3D9() LeaveCriticalSection(&This->d3d9_cs);
/* Convert a IDirect3D9 pointer safely to the internal implementation struct */
static LPDIRECT3D9_INT impl_from_IDirect3D9 ( LPDIRECT3D9 iface )
{
if ( IsBadWritePtr ( iface , sizeof ( LPDIRECT3D9_INT ) ) )
return NULL ;
return ( LPDIRECT3D9_INT ) ( ( ULONG_PTR ) iface - FIELD_OFFSET ( DIRECT3D9_INT , lpVtbl ) ) ;
}
2007-12-19 17:41:05 +00:00
/* IDirect3D9: IUnknown implementation */
2007-12-19 19:49:10 +00:00
static HRESULT WINAPI IDirect3D9Impl_QueryInterface ( LPDIRECT3D9 iface , REFIID riid , LPVOID * ppvObject )
2007-12-19 17:41:05 +00:00
{
2007-12-19 20:44:43 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
2007-12-19 20:06:34 +00:00
2007-12-19 19:49:10 +00:00
if ( IsEqualGUID ( riid , & IID_IUnknown ) | | IsEqualGUID ( riid , & IID_IDirect3D9 ) )
{
2007-12-19 20:44:43 +00:00
IUnknown_AddRef ( iface ) ;
2007-12-19 20:06:34 +00:00
* ppvObject = & This - > lpVtbl ;
2007-12-19 19:49:10 +00:00
return S_OK ;
}
2007-12-19 17:41:05 +00:00
2007-12-19 20:06:34 +00:00
* ppvObject = NULL ;
2007-12-19 17:41:05 +00:00
return E_NOINTERFACE ;
}
static ULONG WINAPI IDirect3D9Impl_AddRef ( LPDIRECT3D9 iface )
{
2007-12-19 20:44:43 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
2008-05-04 11:48:06 +00:00
ULONG ref = InterlockedIncrement ( & This - > lRefCnt ) ;
2007-12-19 17:41:05 +00:00
return ref ;
}
static ULONG WINAPI IDirect3D9Impl_Release ( LPDIRECT3D9 iface )
{
2007-12-19 20:44:43 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
2008-05-04 11:48:06 +00:00
ULONG ref = InterlockedDecrement ( & This - > lRefCnt ) ;
2007-12-19 17:41:05 +00:00
if ( ref = = 0 )
{
EnterCriticalSection ( & This - > d3d9_cs ) ;
/* TODO: Free resources here */
LeaveCriticalSection ( & This - > d3d9_cs ) ;
2007-12-20 21:18:42 +00:00
AlignedFree ( This ) ;
2007-12-19 17:41:05 +00:00
}
return ref ;
}
/* IDirect3D9 interface */
static HRESULT WINAPI IDirect3D9Impl_RegisterSoftwareDevice ( LPDIRECT3D9 iface , void * pInitializeFunction )
{
UNIMPLEMENTED
return D3D_OK ;
}
2008-02-04 21:33:12 +00:00
/*++
* @ name IDirect3D9 : : GetAdapterCount
* @ implemented
*
* The function IDirect3D9Impl_GetAdapterCount returns the number of adapters
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-02-04 21:33:12 +00:00
*
2008-02-07 17:32:49 +00:00
* @ return UINT
2008-02-04 21:33:12 +00:00
* The number of display adapters on the system when Direct3DCreate9 ( ) was called .
*
*/
2007-12-19 17:41:05 +00:00
static UINT WINAPI IDirect3D9Impl_GetAdapterCount ( LPDIRECT3D9 iface )
{
2008-02-04 21:33:12 +00:00
UINT NumDisplayAdapters ;
2007-12-19 17:41:05 +00:00
2008-02-04 21:33:12 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
NumDisplayAdapters = This - > NumDisplayAdapters ;
UNLOCK_D3D9 ( ) ;
return NumDisplayAdapters ;
2007-12-19 17:41:05 +00:00
}
2008-02-04 21:33:12 +00:00
/*++
* @ name IDirect3D9 : : GetAdapterIdentifier
* @ implemented
*
* The function IDirect3D9Impl_GetAdapterIdentifier gathers information about
* a specified display adapter and fills the pIdentifier argument with the available information .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-02-04 21:33:12 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D : : GetAdapterCount ( ) - 1.
2008-02-04 21:33:12 +00:00
*
* @ param DWORD Flags
* Ignored at the moment , but the only valid flag is D3DENUM_WHQL_LEVEL
*
* @ param D3DADAPTER_IDENTIFIER9 * pIdentifier
* Pointer to a D3DADAPTER_IDENTIFIER9 structure to be filled with the available information
* about the display adapter .
*
2008-02-07 17:32:49 +00:00
* @ return HRESULT
2008-02-04 21:33:12 +00:00
* If the method successfully fills the pIdentified structure , the return value is D3D_OK .
* If Adapter is out of range , Flags is invalid or pIdentifier is a bad pointer , the return value
* will be D3DERR_INVALIDCALL .
*
*/
HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier ( LPDIRECT3D9 iface , UINT Adapter , DWORD Flags ,
2007-12-19 17:41:05 +00:00
D3DADAPTER_IDENTIFIER9 * pIdentifier )
{
2008-02-04 21:33:12 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( Flags & ~ D3DENUM_WHQL_LEVEL )
{
DPRINT1 ( " Invalid Flags specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( IsBadWritePtr ( pIdentifier , sizeof ( D3DADAPTER_IDENTIFIER9 ) ) )
{
2008-02-10 08:44:06 +00:00
DPRINT1 ( " Invalid pIdentifier parameter specified " ) ;
2008-02-04 21:33:12 +00:00
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
memset ( pIdentifier , 0 , sizeof ( D3DADAPTER_IDENTIFIER9 ) ) ;
if ( FALSE = = GetAdapterInfo ( This - > DisplayAdapters [ Adapter ] . szDeviceName , pIdentifier ) )
{
DPRINT1 ( " Internal error: Couldn't get the adapter info for device (%d): %s " , Adapter , This - > DisplayAdapters [ Adapter ] . szDeviceName ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
2007-12-19 17:41:05 +00:00
2008-02-07 17:32:49 +00:00
UNLOCK_D3D9 ( ) ;
2007-12-19 17:41:05 +00:00
return D3D_OK ;
}
2008-02-10 08:44:06 +00:00
/*++
* @ name IDirect3D9 : : GetAdapterModeCount
* @ implemented
*
* The function IDirect3D9Impl_GetAdapterModeCount looks if the specified display adapter supports
* a specific pixel format and counts the available display modes for that format .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-02-10 08:44:06 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D9 : : GetAdapterCount ( ) - 1.
2008-02-10 08:44:06 +00:00
*
* @ param D3DFORMAT Format
* The pixel format to search for
*
* @ return HRESULT
2008-02-10 08:54:25 +00:00
* If the method is successful it returns the number of display modes with the specified Format .
2008-02-10 08:44:06 +00:00
* If Adapter is out of range , the return value will be 0.
*
*/
2007-12-19 17:41:05 +00:00
static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount ( LPDIRECT3D9 iface , UINT Adapter , D3DFORMAT Format )
{
2008-02-10 08:44:06 +00:00
UINT AdapterModeCount ;
2007-12-19 17:41:05 +00:00
2008-02-10 08:44:06 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
2008-02-10 09:08:50 +00:00
if ( Format ! = D3DFMT_A2R10G10B10 )
2008-02-10 08:44:06 +00:00
{
AdapterModeCount = GetDisplayFormatCount (
Format ,
This - > DisplayAdapters [ Adapter ] . pSupportedD3DFormats ,
This - > DisplayAdapters [ Adapter ] . NumSupportedD3DFormats ) ;
}
else
{
AdapterModeCount = GetDisplayFormatCount (
Format ,
This - > DisplayAdapters [ Adapter ] . pSupportedD3DExtendedFormats ,
This - > DisplayAdapters [ Adapter ] . NumSupportedD3DExtendedFormats ) ;
}
UNLOCK_D3D9 ( ) ;
return AdapterModeCount ;
2007-12-19 17:41:05 +00:00
}
2008-02-10 08:44:06 +00:00
/*++
* @ name IDirect3D9 : : EnumAdapterModes
* @ implemented
*
* The function IDirect3D9Impl_EnumAdapterModes looks if the specified display adapter supports
* a specific pixel format and fills the pMode argument with the available display modes for that format .
* This function is often used in a loop to enumerate all the display modes the adapter supports .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-02-10 08:44:06 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D9 : : GetAdapterCount ( ) - 1.
2008-02-10 08:44:06 +00:00
*
* @ param D3DFORMAT Format
* The pixel format to search for
*
* @ param UINT Mode
* Index within the pixel format to be returned .
2008-05-04 12:47:57 +00:00
* The maximym value for this is the value returned by IDirect3D9 : : GetAdapterModeCount ( ) - 1.
2008-02-10 08:44:06 +00:00
*
* @ param D3DDISPLAYMODE * pMode
* Pointer to a D3DDISPLAYMODE structure to be filled with the display mode information
* for the specified format .
*
* @ return HRESULT
* If the method successfully fills the pMode structure , the return value is D3D_OK .
* If Adapter is out of range , pMode is a bad pointer or , no modes for the specified
* format was found or the mode parameter was invalid - the return value will be D3DERR_INVALIDCALL .
*
*/
2007-12-19 17:41:05 +00:00
static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes ( LPDIRECT3D9 iface , UINT Adapter , D3DFORMAT Format ,
UINT Mode , D3DDISPLAYMODE * pMode )
{
2008-02-10 08:44:06 +00:00
const D3DDISPLAYMODE * pMatchingDisplayFormat ;
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( IsBadWritePtr ( pMode , sizeof ( D3DDISPLAYMODE ) ) )
{
DPRINT1 ( " Invalid pMode parameter specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
2008-02-10 09:08:50 +00:00
if ( Format ! = D3DFMT_A2R10G10B10 )
2008-02-10 08:44:06 +00:00
{
pMatchingDisplayFormat = FindDisplayFormat (
Format ,
Mode ,
This - > DisplayAdapters [ Adapter ] . pSupportedD3DFormats ,
This - > DisplayAdapters [ Adapter ] . NumSupportedD3DFormats ) ;
}
else
{
pMatchingDisplayFormat = FindDisplayFormat (
Format ,
Mode ,
This - > DisplayAdapters [ Adapter ] . pSupportedD3DExtendedFormats ,
This - > DisplayAdapters [ Adapter ] . NumSupportedD3DExtendedFormats ) ;
}
if ( pMatchingDisplayFormat ! = NULL )
{
* pMode = * pMatchingDisplayFormat ;
}
UNLOCK_D3D9 ( ) ;
if ( pMatchingDisplayFormat = = NULL )
return D3DERR_INVALIDCALL ;
2007-12-19 17:41:05 +00:00
return D3D_OK ;
}
2008-02-12 17:30:32 +00:00
/*++
* @ name IDirect3D9 : : GetAdapterDisplayMode
* @ implemented
*
* The function IDirect3D9Impl_GetAdapterDisplayMode fills the pMode argument with the
* currently set display mode .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-02-12 17:30:32 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D9 : : GetAdapterCount ( ) - 1.
2008-02-12 17:30:32 +00:00
*
* @ param D3DDISPLAYMODE * pMode
* Pointer to a D3DDISPLAYMODE structure to be filled with the current display mode information .
*
* @ return HRESULT
* If the method successfully fills the pMode structure , the return value is D3D_OK .
* If Adapter is out of range or pMode is a bad pointer , the return value will be D3DERR_INVALIDCALL .
*
2008-02-16 11:17:46 +00:00
*/
static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode ( LPDIRECT3D9 iface , UINT Adapter , D3DDISPLAYMODE * pMode )
2007-12-19 17:41:05 +00:00
{
2008-02-12 17:30:32 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
2007-12-19 17:41:05 +00:00
2008-02-12 17:30:32 +00:00
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( IsBadWritePtr ( pMode , sizeof ( D3DDISPLAYMODE ) ) )
{
DPRINT1 ( " Invalid pMode parameter specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
/* TODO: Handle (This->DisplayAdapters[Adapter].bInUseFlag == FALSE) */
if ( FALSE = = GetAdapterMode ( This - > DisplayAdapters [ Adapter ] . szDeviceName , pMode ) )
DPRINT1 ( " Internal error, GetAdapterMode() failed. " ) ;
UNLOCK_D3D9 ( ) ;
2007-12-19 17:41:05 +00:00
return D3D_OK ;
}
2008-02-26 21:33:04 +00:00
/*++
* @ name IDirect3D9 : : CheckDeviceType
* @ implemented
*
* The function IDirect3D9Impl_CheckDeviceType checks if a specific D3DFORMAT is hardware accelerated
* on the specified display adapter .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-02-26 21:33:04 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D9 : : GetAdapterCount ( ) - 1.
2008-02-26 21:33:04 +00:00
*
* @ param D3DDEVTYPE DeviceType
* One of the D3DDEVTYPE enum members .
*
* @ param D3DFORMAT DisplayFormat
* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN for the display adapter mode to be checked .
*
* @ param D3DFORMAT BackBufferFormat
2008-03-02 12:29:35 +00:00
* One of the D3DFORMAT enum members for the render target mode to be checked . D3DFMT_UNKNOWN is only allowed in windowed mode .
2008-02-26 21:33:04 +00:00
*
* @ param BOOL Windowed
* If this value is TRUE , the D3DFORMAT check will be done for windowed mode and FALSE equals fullscreen mode .
*
* @ return HRESULT
* If the format is hardware accelerated , the method returns D3D_OK .
* If the format isn ' t hardware accelerated or unsupported - the return value will be D3DERR_NOTAVAILABLE .
* If Adapter is out of range , DeviceType is invalid ,
* DisplayFormat or BackBufferFormat is invalid - the return value will be D3DERR_INVALIDCALL .
*
*/
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType ( LPDIRECT3D9 iface , UINT Adapter , D3DDEVTYPE DeviceType ,
2007-12-19 17:41:05 +00:00
D3DFORMAT DisplayFormat , D3DFORMAT BackBufferFormat , BOOL Windowed )
{
2008-02-26 21:33:04 +00:00
HRESULT hResult ;
2007-12-19 17:41:05 +00:00
2008-02-26 21:33:04 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( DeviceType ! = D3DDEVTYPE_HAL & &
DeviceType ! = D3DDEVTYPE_REF & &
DeviceType ! = D3DDEVTYPE_SW )
{
DPRINT1 ( " Invalid DeviceType specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( BackBufferFormat = = D3DFMT_UNKNOWN & &
Windowed = = TRUE )
{
BackBufferFormat = DisplayFormat ;
}
if ( DisplayFormat = = D3DFMT_UNKNOWN & & BackBufferFormat = = D3DFMT_UNKNOWN )
{
DPRINT1 ( " Invalid D3DFORMAT specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( FALSE = = IsBackBufferFormat ( BackBufferFormat ) )
{
DPRINT1 ( " Invalid D3DFORMAT specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_NOTAVAILABLE ;
}
if ( TRUE = = Windowed & & TRUE = = IsExtendedFormat ( DisplayFormat ) )
{
DPRINT1 ( " Extended diplay modes can only be used in fullscreen mode " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_NOTAVAILABLE ;
}
2008-03-02 12:29:35 +00:00
hResult = CheckDeviceType ( & This - > DisplayAdapters [ Adapter ] . DriverCaps , DisplayFormat , BackBufferFormat , Windowed ) ;
2008-02-26 21:33:04 +00:00
UNLOCK_D3D9 ( ) ;
return hResult ;
2007-12-19 17:41:05 +00:00
}
2008-03-02 12:29:35 +00:00
/*++
* @ name IDirect3D9 : : CheckDeviceFormat
* @ implemented
*
* The function IDirect3D9Impl_CheckDeviceFormat checks if a specific D3DFORMAT
* can be used for a specific purpose like texture , depth / stencil buffer or as a render target
* on the specified display adapter .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-03-02 12:29:35 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D9 : : GetAdapterCount ( ) - 1.
2008-03-02 12:29:35 +00:00
*
* @ param D3DDEVTYPE DeviceType
* One of the D3DDEVTYPE enum members .
*
* @ param D3DFORMAT AdapterFormat
* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN for the display adapter mode to be checked .
*
* @ param DWORD Usage
* Valid values are any of the D3DUSAGE_QUERY constants or any of these D3DUSAGE constants :
* D3DUSAGE_AUTOGENMIPMAP , D3DUSAGE_DEPTHSTENCIL , D3DUSAGE_DMAP , D3DUSAGE_DYNAMIC ,
* D3DUSAGE_NONSECURE , D3DUSAGE_RENDERTARGET and D3DUSAGE_SOFTWAREPROCESSING .
*
* @ param D3DRESOURCETYPE RType
* One of the D3DRESOURCETYPE enum members . Specifies what format will be used for .
*
* @ param D3DFORMAT CheckFormat
* One of the D3DFORMAT enum members for the surface format to be checked .
*
* @ return HRESULT
* If the format is compatible with the specified usage and resource type , the method returns D3D_OK .
* If the format isn ' t compatible with the specified usage and resource type - the return value will be D3DERR_NOTAVAILABLE .
* If Adapter is out of range , DeviceType is invalid , AdapterFormat or CheckFormat is invalid ,
* Usage and RType isn ' t compatible - the return value will be D3DERR_INVALIDCALL .
*
*/
2007-12-19 17:41:05 +00:00
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat ( LPDIRECT3D9 iface , UINT Adapter , D3DDEVTYPE DeviceType ,
D3DFORMAT AdapterFormat , DWORD Usage , D3DRESOURCETYPE RType ,
D3DFORMAT CheckFormat )
{
2008-03-02 12:29:35 +00:00
LPD3D9_DRIVERCAPS pDriverCaps ;
BOOL bIsTextureRType = FALSE ;
HRESULT hResult ;
2007-12-19 17:41:05 +00:00
2008-03-02 12:29:35 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( DeviceType ! = D3DDEVTYPE_HAL & &
DeviceType ! = D3DDEVTYPE_REF & &
DeviceType ! = D3DDEVTYPE_SW )
{
DPRINT1 ( " Invalid DeviceType specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( AdapterFormat = = D3DFMT_UNKNOWN | |
CheckFormat = = D3DFMT_UNKNOWN )
{
DPRINT1 ( " Invalid D3DFORMAT specified " ) ;
UNLOCK_D3D9 ( ) ;
2008-03-04 17:39:33 +00:00
return D3DERR_INVALIDCALL ;
2008-03-02 12:29:35 +00:00
}
if ( ( Usage & ( D3DUSAGE_DONOTCLIP | D3DUSAGE_NPATCHES | D3DUSAGE_POINTS | D3DUSAGE_RTPATCHES | D3DUSAGE_TEXTAPI | D3DUSAGE_WRITEONLY ) ) ! = 0 )
{
DPRINT1 ( " Invalid Usage specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( RType = = D3DRTYPE_TEXTURE | |
RType = = D3DRTYPE_VOLUMETEXTURE | |
RType = = D3DRTYPE_CUBETEXTURE )
{
bIsTextureRType = TRUE ;
}
else if ( RType = = D3DRTYPE_SURFACE & &
( Usage & ( D3DUSAGE_DEPTHSTENCIL | D3DUSAGE_RENDERTARGET ) ) = = 0 & &
Usage ! = 0 )
{
DPRINT1 ( " When RType is set to D3DRTYPE_SURFACE, Usage must be 0 or have set D3DUSAGE_DEPTHSTENCIL or D3DUSAGE_RENDERTARGET " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( ( Usage & D3DUSAGE_DEPTHSTENCIL ) ! = 0 )
{
if ( FALSE = = IsZBufferFormat ( CheckFormat ) )
{
DPRINT1 ( " Invalid CheckFormat Z-Buffer format " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( ( Usage & D3DUSAGE_AUTOGENMIPMAP ) ! = 0 )
{
DPRINT1 ( " Invalid Usage specified, D3DUSAGE_DEPTHSTENCIL and D3DUSAGE_AUTOGENMIPMAP can't be combined. " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
}
if ( FALSE = = bIsTextureRType & &
RType ! = D3DRTYPE_SURFACE & &
RType ! = D3DRTYPE_VOLUME )
{
DPRINT1 ( " Invalid RType specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( ( Usage & ( D3DUSAGE_AUTOGENMIPMAP | D3DUSAGE_DEPTHSTENCIL | D3DUSAGE_RENDERTARGET ) ) ! = 0 )
{
if ( RType = = D3DRTYPE_VOLUME | | RType = = D3DRTYPE_VOLUMETEXTURE )
{
DPRINT1 ( " Invalid Usage specified, D3DUSAGE_AUTOGENMIPMAP, D3DUSAGE_DEPTHSTENCIL and D3DUSAGE_RENDERTARGET can't be combined with RType D3DRTYPE_VOLUME or D3DRTYPE_VOLUMETEXTURE " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
}
if ( FALSE = = bIsTextureRType & &
( Usage & D3DUSAGE_QUERY_VERTEXTEXTURE ) ! = 0 )
{
DPRINT1 ( " Invalid Usage specified, D3DUSAGE_QUERY_VERTEXTEXTURE can only be used with a texture RType " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( ( Usage & D3DUSAGE_AUTOGENMIPMAP ) ! = 0 & &
TRUE = = IsMultiElementFormat ( CheckFormat ) )
{
DPRINT1 ( " Invalid Usage specified, D3DUSAGE_AUTOGENMIPMAP can't be used with a multi-element format " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
pDriverCaps = & This - > DisplayAdapters [ Adapter ] . DriverCaps ;
if ( ( Usage & D3DUSAGE_DYNAMIC ) ! = 0 & & bIsTextureRType = = TRUE )
{
if ( ( pDriverCaps - > DriverCaps9 . Caps2 & D3DCAPS2_DYNAMICTEXTURES ) = = 0 )
{
DPRINT1 ( " Driver doesn't support dynamic textures " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_NOTAVAILABLE ;
}
if ( ( Usage & ( D3DUSAGE_DEPTHSTENCIL | D3DUSAGE_RENDERTARGET ) ) ! = 0 )
{
DPRINT1 ( " Invalid Usage specified, D3DUSAGE_DEPTHSTENCIL and D3DUSAGE_RENDERTARGET can't be combined with D3DUSAGE_DYNAMIC and a texture RType " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
}
if ( ( Usage & D3DUSAGE_DMAP ) ! = 0 )
{
if ( ( pDriverCaps - > DriverCaps9 . DevCaps2 & ( D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH | D3DDEVCAPS2_DMAPNPATCH ) ) = = 0 )
{
DPRINT1 ( " Driver doesn't support displacement mapping " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_NOTAVAILABLE ;
}
if ( RType ! = D3DRTYPE_TEXTURE )
{
DPRINT1 ( " Invalid Usage speficied, D3DUSAGE_DMAP must be combined with RType D3DRTYPE_TEXTURE " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
}
hResult = CheckDeviceFormat ( pDriverCaps , AdapterFormat , Usage , RType , CheckFormat ) ;
UNLOCK_D3D9 ( ) ;
return hResult ;
2007-12-19 17:41:05 +00:00
}
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType ( LPDIRECT3D9 iface , UINT Adapter , D3DDEVTYPE DeviceType ,
D3DFORMAT SurfaceFormat , BOOL Windowed ,
D3DMULTISAMPLE_TYPE MultiSampleType , DWORD * pQualityLevels )
{
UNIMPLEMENTED
return D3D_OK ;
}
2008-03-04 17:39:33 +00:00
/*++
* @ name IDirect3D9 : : CheckDepthStencilMatch
* @ implemented
*
* The function IDirect3D9Impl_CheckDepthStencilMatch checks if a specific combination
* of a render target D3DFORMAT and a depth - stencil D3DFORMAT can be used with a specified
* D3DFORMAT on the specified display adapter .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-03-04 17:39:33 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D9 : : GetAdapterCount ( ) - 1.
2008-03-04 17:39:33 +00:00
*
* @ param D3DDEVTYPE DeviceType
* One of the D3DDEVTYPE enum members .
*
* @ param D3DFORMAT AdapterFormat
* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN that the display adapter mode where the test should occurr .
*
* @ param D3DFORMAT RenderTargetFormat
* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN for the display adapter mode ' s render target format to be tested .
*
* @ param D3DFORMAT DepthStencilFormat
* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN for the display adapter mode ' s depth - stencil format to be tested .
*
* @ return HRESULT
* If the DepthStencilFormat can be used with the RenderTargetFormat under the specified AdapterFormat ,
* the method returns D3D_OK .
* If the DepthStencilFormat can NOT used with the RenderTargetFormat under the specified AdapterFormat ,
* the method returns D3DERR_NOTAVAILABLE .
* If Adapter is out of range , DeviceType is invalid ,
* AdapterFormat , RenderTargetFormat or DepthStencilFormat is invalid , the method returns D3DERR_INVALIDCALL .
*
*/
2007-12-19 17:41:05 +00:00
static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch ( LPDIRECT3D9 iface , UINT Adapter , D3DDEVTYPE DeviceType ,
D3DFORMAT AdapterFormat , D3DFORMAT RenderTargetFormat ,
D3DFORMAT DepthStencilFormat )
{
2008-03-04 17:39:33 +00:00
HRESULT hResult ;
2007-12-19 17:41:05 +00:00
2008-03-04 17:39:33 +00:00
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( DeviceType ! = D3DDEVTYPE_HAL & &
DeviceType ! = D3DDEVTYPE_REF & &
DeviceType ! = D3DDEVTYPE_SW )
{
DPRINT1 ( " Invalid DeviceType specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( AdapterFormat = = D3DFMT_UNKNOWN | |
RenderTargetFormat = = D3DFMT_UNKNOWN | |
DepthStencilFormat = = D3DFMT_UNKNOWN )
{
DPRINT1 ( " Invalid D3DFORMAT specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
hResult = CheckDepthStencilMatch ( & This - > DisplayAdapters [ Adapter ] . DriverCaps , AdapterFormat , RenderTargetFormat , DepthStencilFormat ) ;
UNLOCK_D3D9 ( ) ;
return hResult ;
2007-12-19 17:41:05 +00:00
}
2008-03-02 14:12:24 +00:00
/*++
* @ name IDirect3D9 : : CheckDeviceFormatConversion
* @ implemented
*
* The function IDirect3D9Impl_CheckDeviceFormatConversion checks if a specific D3DFORMAT
* can be converted to another on the specified display adapter .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-03-02 14:12:24 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D9 : : GetAdapterCount ( ) - 1.
2008-03-02 14:12:24 +00:00
*
* @ param D3DDEVTYPE DeviceType
* One of the D3DDEVTYPE enum members . Only D3DDEVTYPE_HAL can potentially return D3D_OK .
*
* @ param D3DFORMAT SourceFormat
* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN for the display adapter mode to be converted from .
*
* @ param D3DFORMAT TargetFormat
* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN for the display adapter mode to be converted to .
*
* @ return HRESULT
* If the SourceFormat can be converted to the TargetFormat , the method returns D3D_OK .
* If the SourceFormat can NOT be converted to the TargetFormat , the method returns D3DERR_NOTAVAILABLE .
* If Adapter is out of range , DeviceType is invalid ,
* SourceFormat or TargetFormat is invalid , the method returns D3DERR_INVALIDCALL .
*
*/
2007-12-19 17:41:05 +00:00
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion ( LPDIRECT3D9 iface , UINT Adapter , D3DDEVTYPE DeviceType ,
D3DFORMAT SourceFormat , D3DFORMAT TargetFormat )
{
2008-03-02 14:12:24 +00:00
HRESULT hResult ;
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
2007-12-19 17:41:05 +00:00
2008-03-02 14:12:24 +00:00
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( DeviceType ! = D3DDEVTYPE_HAL & &
DeviceType ! = D3DDEVTYPE_REF & &
DeviceType ! = D3DDEVTYPE_SW )
{
DPRINT1 ( " Invalid DeviceType specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( SourceFormat = = D3DFMT_UNKNOWN | |
TargetFormat = = D3DFMT_UNKNOWN )
{
DPRINT1 ( " Invalid D3DFORMAT specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_NOTAVAILABLE ;
}
if ( DeviceType = = D3DDEVTYPE_HAL )
{
hResult = CheckDeviceFormatConversion ( & This - > DisplayAdapters [ Adapter ] . DriverCaps , SourceFormat , TargetFormat ) ;
}
else
{
hResult = D3DERR_NOTAVAILABLE ;
}
UNLOCK_D3D9 ( ) ;
return hResult ;
2007-12-19 17:41:05 +00:00
}
2008-02-16 11:17:46 +00:00
/*++
* @ name IDirect3D9 : : GetDeviceCaps
* @ implemented
*
* The function IDirect3D9Impl_GetDeviceCaps fills the pCaps argument with the
* capabilities of the specified adapter and device type .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-02-16 11:17:46 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D9 : : GetAdapterCount ( ) - 1.
2008-02-16 11:17:46 +00:00
*
* @ param D3DDEVTYPE DeviceType
* One of the D3DDEVTYPE enum members .
* NOTE : Currently only D3DDEVTYPE_HAL is implemented .
*
* @ param D3DCAPS9 * pCaps
* Pointer to a D3DCAPS9 structure to be filled with the adapter ' s device type capabilities .
*
* @ return HRESULT
* If the method successfully fills the pCaps structure , the return value is D3D_OK .
* If Adapter is out of range or pCaps is a bad pointer , the return value will be D3DERR_INVALIDCALL .
* If DeviceType is invalid , the return value will be D3DERR_INVALIDDEVICE .
*
*/
2007-12-19 17:41:05 +00:00
static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps ( LPDIRECT3D9 iface , UINT Adapter , D3DDEVTYPE DeviceType , D3DCAPS9 * pCaps )
{
2008-02-16 11:17:46 +00:00
HRESULT hResult ;
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
2007-12-19 17:41:05 +00:00
2008-02-16 11:17:46 +00:00
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( IsBadWritePtr ( pCaps , sizeof ( D3DCAPS9 ) ) )
{
DPRINT1 ( " Invalid pCaps parameter specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
hResult = GetAdapterCaps ( & This - > DisplayAdapters [ Adapter ] , DeviceType , pCaps ) ;
UNLOCK_D3D9 ( ) ;
return hResult ;
2007-12-19 17:41:05 +00:00
}
2008-02-07 17:32:49 +00:00
/*++
* @ name IDirect3D9 : : GetAdapterMonitor
* @ implemented
*
* The function IDirect3D9Impl_GetAdapterMonitor returns the monitor associated
* with the specified display adapter .
*
* @ param LPDIRECT3D iface
2008-05-04 12:47:57 +00:00
* Pointer to the IDirect3D9 object returned from Direct3DCreate9 ( )
2008-02-07 17:32:49 +00:00
*
* @ param UINT Adapter
* Adapter index to get information about . D3DADAPTER_DEFAULT is the primary display .
2008-05-04 12:47:57 +00:00
* The maximum value for this is the value returned by IDirect3D9 : : GetAdapterCount ( ) - 1.
2008-02-07 17:32:49 +00:00
*
* @ return HMONITOR
* If the method successfully it returns the HMONITOR belonging to the specified adapter .
* If the method fails , the return value is NULL .
*
*/
2007-12-19 17:41:05 +00:00
static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor ( LPDIRECT3D9 iface , UINT Adapter )
{
2008-02-07 17:32:49 +00:00
HMONITOR hAdapterMonitor = NULL ;
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
if ( Adapter < This - > NumDisplayAdapters )
{
hAdapterMonitor = GetAdapterMonitor ( This - > DisplayAdapters [ Adapter ] . szDeviceName ) ;
}
else
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
}
2007-12-19 17:41:05 +00:00
2008-02-07 17:32:49 +00:00
UNLOCK_D3D9 ( ) ;
return hAdapterMonitor ;
2007-12-19 17:41:05 +00:00
}
static HRESULT WINAPI IDirect3D9Impl_CreateDevice ( LPDIRECT3D9 iface , UINT Adapter , D3DDEVTYPE DeviceType ,
HWND hFocusWindow , DWORD BehaviourFlags ,
D3DPRESENT_PARAMETERS * pPresentationParameters ,
2007-12-19 19:49:10 +00:00
struct IDirect3DDevice9 * * ppReturnedDeviceInterface )
2007-12-19 17:41:05 +00:00
{
2008-03-12 19:29:10 +00:00
DWORD NumAdaptersToCreate ;
LPDIRECT3D9_INT This = impl_from_IDirect3D9 ( iface ) ;
LOCK_D3D9 ( ) ;
if ( Adapter > = This - > NumDisplayAdapters )
{
DPRINT1 ( " Invalid Adapter number specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( DeviceType ! = D3DDEVTYPE_HAL & &
DeviceType ! = D3DDEVTYPE_REF & &
DeviceType ! = D3DDEVTYPE_SW )
{
DPRINT1 ( " Invalid DeviceType specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( DeviceType ! = D3DDEVTYPE_HAL )
{
UNIMPLEMENTED
DPRINT1 ( " Sorry, only D3DDEVTYPE_HAL is implemented at this time... " ) ;
return D3DERR_INVALIDCALL ;
}
if ( hFocusWindow ! = NULL & & FALSE = = IsWindow ( hFocusWindow ) )
{
DPRINT1 ( " Invalid hFocusWindow parameter specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( IsBadWritePtr ( ppReturnedDeviceInterface , sizeof ( IDirect3DDevice9 * ) ) )
{
DPRINT1 ( " Invalid ppReturnedDeviceInterface parameter specified " ) ;
UNLOCK_D3D9 ( ) ;
return D3DERR_INVALIDCALL ;
}
if ( ( BehaviourFlags & D3DCREATE_ADAPTERGROUP_DEVICE ) ! = 0 )
NumAdaptersToCreate = This - > DisplayAdapters [ Adapter ] . NumAdaptersInGroup ;
else
NumAdaptersToCreate = 1 ;
* ppReturnedDeviceInterface = 0 ;
2007-12-19 17:41:05 +00:00
UNIMPLEMENTED
return D3D_OK ;
}
2008-02-04 21:33:12 +00:00
IDirect3D9Vtbl Direct3D9_Vtbl =
2007-12-19 17:41:05 +00:00
{
/* IUnknown */
IDirect3D9Impl_QueryInterface ,
IDirect3D9Impl_AddRef ,
IDirect3D9Impl_Release ,
/* IDirect3D9 */
IDirect3D9Impl_RegisterSoftwareDevice ,
IDirect3D9Impl_GetAdapterCount ,
IDirect3D9Impl_GetAdapterIdentifier ,
IDirect3D9Impl_GetAdapterModeCount ,
IDirect3D9Impl_EnumAdapterModes ,
IDirect3D9Impl_GetAdapterDisplayMode ,
IDirect3D9Impl_CheckDeviceType ,
IDirect3D9Impl_CheckDeviceFormat ,
IDirect3D9Impl_CheckDeviceMultiSampleType ,
IDirect3D9Impl_CheckDepthStencilMatch ,
IDirect3D9Impl_CheckDeviceFormatConversion ,
IDirect3D9Impl_GetDeviceCaps ,
IDirect3D9Impl_GetAdapterMonitor ,
IDirect3D9Impl_CreateDevice
} ;