设为首页 加入收藏

TOP

(Visual C++)游戏开发笔记二十七 Direct3D 11入门级知识介绍 (二)
2014-11-23 19:38:16 】 浏览:635
Tags:Visual 游戏 开发 笔记 二十七 Direct3D 入门 知识 介绍

DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory( &swapChainDesc, sizeof( swapChainDesc ) );
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.Windowed = true;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;

DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory( &swapChainDesc, sizeof( swapChainDesc ) );
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.Windowed = true;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;

这个范例中定义了D3D的多种取样属性,多重取样(Multisampling)是一种用于采样和平衡渲染像素的创建亮丽色彩变化之间的平滑过渡的一种技术。

缓存的使用和交换链的描述有大量的成员需要设置,但这些设置都是非常简单的。缓存的对交换链的使用是设置下DXGI_USAGE_RENDER_TARGET_OUTPUT,以便交换链能够用于输出,或者换句话说,它能被渲染。

下一步是创建渲染上下文,渲染设备,以及我们拥有的交换链描述。D3D设备一般都是设备本身和硬件之间的通信,而D3D上下文是一种描述设备如何绘制的渲染设备上下文,这也包含了渲染状态和其他的绘图信息。

正如我们讨论过的,交换链是设备和上下文将要绘制的渲染目标。

创建设备上下文,渲染上下文和交换链所需的代码在代码段3中详细列出了,.这段代码为下次内容即将展示的Direct3D 11 BlankWindows Demo的一个片段。

代码段3 Direct3D设备,设备上下文,以及交换链的创建


[cpp]
ID3D11Device device_;
ID3D11Context d3dContext_;
IDXGISwapChain swapChain_;
unsigned int creationFlags = 0;
#ifdef _DEBUG
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
HRESULT result;
unsigned int driver = 0;
for( driver = 0; driver < totalDriverTypes; ++driver )
{
result = D3D11CreateDeviceAndSwapChain( 0, driverTypes[driver],0,
creationFlags, featureLevels, totalFeatureLevels,
D3D11_SDK_VERSION, &swapChainDesc, &swapChain_,
&d3dDevice_, &featureLevel_, &d3dContext_ );
if( SUCCEEDED( result ) )
{
driverType_ = driverTypes[driver];
break;
}
}
if( FAILED( result ) )
{
DXTRACE_MSG( "Failed to create the Direct3D device!");
return false;
}

ID3D11Device device_;
ID3D11Context d3dContext_;
IDXGISwapChain swapChain_;
unsigned int creationFlags = 0;
#ifdef _DEBUG
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
HRESULT result;
unsigned int driver = 0;
for( driver = 0; driver < totalDriverTypes; ++driver )
{
result = D3D11CreateDeviceAndSwapChain( 0, driverTypes[driver],0,
creationFlags, featureLevels, totalFeatureLevels,
D3D11_SDK_VERSION, &swapChainDesc, &swapChain_,
&d3dDevice_, &featureLevel_, &d3dContext_ );
if( SUCCEEDED( result ) )
{
driverType_ = driverTypes[driver];
break;
}
}
if( FAILED( result ) )
{
DXTRACE_MSG( "Failed to create the Direct3D device!");
return false;
}

交换链,设备和渲染上下文可以在单独的Direct3D函数调用中被创建,或者通过特定对象的Direct3D来调用(例如用CreateSwapChain函数来专门创建一个交换链)。

这个函数为D3D11CreateDeviceAndSwapChain。在代码段2中我们在每个驱动类型中循环,试图创建一个合适得设备,或为一个硬件设备,或为一个WARP设备,抑或一个参考设备(reference device)。因为如果创建失败,我们就无法初始化我们的Direct3D。

D3D11CreateDeviceAndSwapChain函数中包含了特征等级作为其参数, 所以如果至少有一个这样的特征等级存在,而且若我们的设备类型也存在,这个函数才会执行成功。

其中D3D11CreateDeviceAndSwapC

首页 上一页 1 2 3 4 5 下一页 尾页 2/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇基于VC++实现PE的修改编程 下一篇VC中将控件保存成图片&&VC中利用G..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目