IDirect3D9学习

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结构体指针

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值