IDirect3D9学习

来源:互联网 发布:资生堂有淘宝旗舰店吗 编辑:程序博客网 时间:2024/06/06 15:06

IDirect3D9接口共14个方法,分别是:

1.创建设备

HRESULT CreateDevice(  UINT Adapter,  D3DDEVTYPE DeviceType,  HWND hFocusWindow,  DWORD BehaviorFlags,  D3DPRESENT_PARAMETERS * pPresentationParameters,  IDirect3DDevice9 ** ppReturnedDeviceInterface);

参数

[I]Adapter:显卡的序列号,一般使用主显卡D3DADAPTER_DEFAULT

[I]DeviceType:设备类型,HAL or REF,一般都是使用D3DDEVTYPE_HAL

[I]hFocusWindow:窗口句柄

[I]BehaviorFlags:一般使用D3DCREATE_HARDWARE_VERTEXPROCESSING,不过需要用GetDeviceCaps获取caps进行确认

[I]pPresentationParameters:这个结构体在之后会详细说明

[OUT]ppReturnedDeviceInterface:二级指针,返回一个D3D设备接口

用法:

LPDIRECT3DDEVICE9 pDevice = NULL;D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) );d3dpp.Windowed   = TRUE;d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT,                                   D3DDEVTYPE_HAL,                                  hWnd,                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING,  &d3dpp,                                   &d3dDevice)))return E_FAIL;

2.检测在一个特定的显示mode下,一个depth-stencil格式是否与渲染目标的格式兼容

HRESULT CheckDepthStencilMatch(  UINT Adapter,  D3DDEVTYPE DeviceType,  D3DFORMAT AdapterFormat,  D3DFORMAT RenderTargetFormat,  D3DFORMAT DepthStencilFormat);

参数:

【I】Adapter:显示设备

【I】DeviceType:设备类型

【I】AdapterFormat:显卡格式

【I】RenderTargetFormat:渲染目标格式

【I】DepthStencilFormat:深度模板格式

用法:

BOOL IsDepthFormatOk(D3DFORMAT DepthFormat,                           D3DFORMAT AdapterFormat,                           D3DFORMAT BackBufferFormat){        // 检查这个depth-stencil格式是否有效    HRESULT hr = pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT,                                         D3DDEVTYPE_HAL,                                         AdapterFormat,                                         D3DUSAGE_DEPTHSTENCIL,                                         D3DRTYPE_SURFACE,                                         DepthFormat);        if(FAILED(hr)) return FALSE;        // 检查the depth format 和  BackBuffer format是否兼容    hr = pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT,                                      D3DDEVTYPE_HAL,                                      AdapterFormat,                                      BackBufferFormat,                                      DepthFormat);        return SUCCEEDED(hr);    }

3.在一个显示设备上,检查一个格式(这个格式被用于:texture,depth-stencil buffer,render target,或者这三个的组合)是否可用的

HRESULT CheckDeviceFormat(  UINT Adapter,  D3DDEVTYPE DeviceType,  D3DFORMAT AdapterFormat,  DWORD Usage,  D3DRESOURCETYPE RType,  D3DFORMAT CheckFormat);
参数:

【I】Adapter:显示设备

【I】DeviceType:设备类型

【I】AdapterFormat:显卡格式

【I】Usage:检查类型

【I】RType:资源类型

【I】CheckFormat:被检查的格式

用法:参照2
4.测试设备,以确定它是否支持从一种显示格式到另一种显示格式的转换
HRESULT CheckDeviceFormatConversion(  UINT Adapter,  D3DDEVTYPE DeviceType,  D3DFORMAT SourceFormat,  D3DFORMAT TargetFormat);

【I】Adapter:显示设备

【I】DeviceType:设备类型

【I】SourceFormat:要检查的格式,必须是FOURCC format or a valid back buffer format

【I】argetFormat:被检查的格式


5.确定多级取样技术在当前设备中是否可用。

HRESULT CheckDeviceMultiSampleType(  UINT Adapter,  D3DDEVTYPE DeviceType,  D3DFORMAT SurfaceFormat,  BOOL Windowed,  D3DMULTISAMPLE_TYPE MultiSampleType,  DWORD* pQualityLevels);

【I】Adapter:显示设备

【I】DeviceType:设备类型

【I】SurfaceFormat用于标识要进行多级取样的图面

【I】Windowed设为 true,则查询有窗口的多级取样。设为 false,则查询全屏多级取样

【I】MultiSampleType用于标识要测试的多级取样技术

【out】pQualityLevels:一般为NULL

用法:

if( SUCCEEDED(pD3D->CheckDeviceMultiSampleType( pCaps->AdapterOrdinal,                                 pCaps->DeviceType, BackBufferFormat,                                 FALSE, D3DMULTISAMPLE_3_SAMPLES, NULL ) ) &&         SUCCEEDED(pD3D->CheckDeviceMultiSampleType( pCaps->AdapterOrdinal,                                 pCaps->DeviceType, DepthBufferFormat,                                 FALSE, D3DMULTISAMPLE_3_SAMPLES, NULL ) ) )    return S_OK;

6.检查一种硬件加速设备类型是否可以在指定显示上使用

HRESULT CheckDeviceType(  UINT Adapter,  D3DDEVTYPE DeviceType,  D3DFORMAT DisplayFormat,  D3DFORMAT BackBufferFormat,  BOOL Windowed);

参数:

【I】Adapter:显示设备

【I】DeviceType:设备类型

【I】DisplayFormat被检查的类型

【I】BackBufferFormat:D3DFMT_UNKNOWN is allowed for windowed mode.

【I】WindowedTRUE:窗口,FALSE:全屏


7,获取显卡的当前Display模式

HRESULT GetAdapterDisplayMode(  UINT Adapter,  D3DDISPLAYMODE * pMode);
参数:

【I】Adapter:显示设备

【I】pModeD3DDISPLAYMODE 结构体指针


D3DDISPLAYMODE 如下:

typedef struct D3DDISPLAYMODE {    UINT Width;    UINT Height;    UINT RefreshRate;    D3DFORMAT Format;} D3DDISPLAYMODE, *LPD3DDISPLAYMODE;
成员说明:

Width:屏幕宽,单位像素

Height:屏幕高,单位像素

RefreshRate:刷新()

Format:显示模式的平面格式

8、获取设备的具体信息

HRESULT GetDeviceCaps(  UINT Adapter,  D3DDEVTYPE DeviceType,  D3DCAPS9 * pCaps);
参数:

Adapter:显示设备

DeviceType:设备类型

pCapsD3DCAPS9结构体指针

原创粉丝点击