龙书D3D11 Demo配置(VS2015+win10)

来源:互联网 发布:lol是哪个国家域名 编辑:程序博客网 时间:2024/06/15 10:00

原文地址: http://www.d3dcoder.net/Data/Book4/d3d11Win10.htm


说明:

1.提供了在最新的环境VS2015+Win10中编译、运行龙书D3D11所有Demos的方法。

2.由于修改步骤较为麻烦,初学此书推荐使用VS2010 + DirectX SDK(june 2010)。



简要信息:

1.从Win8开始,DirectX SDK内置在操作系统中(C:\Program Files (x86)\Windows Kits),并随Windows更新而更新。

2.D3DX库现在从SDK中移除了,但大部分代码已经开源了。

3.XNA Math库现在更名为DirectX Math。

4.dxerr.lib与VS2015不兼容,原因:https://blogs.msdn.microsoft.com/chuckw/2012/04/24/wheres-dxerr-lib/

5.Effects库现已开源。


具体步骤:

1.找出Demo中使用到的D3DX函数,并替换成其他形式。

    1.1 如果Demo中使用到纹理,做如下替换:从https://github.com/Microsoft/DirectXTex下载DDSTextureLoader,将DDSTextureLoader.h/cpp放置到Common文件夹下,并加入到你的Demo中。

    1.2 想使用D3DX的Mesh相关函数集,这部分代码也是开源的:

https://blogs.msdn.microsoft.com/chuckw/2014/06/27/directxmesh/

https://github.com/Microsoft/DirectXMesh


2.找出使用XNA Math的地方,在使用前加上DirectX::命名空间(如XMMATRIX, 现在要写成DirectX::XMMATRIX)。


3.为dxerr.lib找到替代品,或者不使用它(在本书代码中,修改HR宏为不使用DXTrace处理异常)。

    3.1 可以从简要信息4提供的链接下载到dxerr_nov2015.zip,将其中的dxerr.h和dxerr.cpp放入Common文件夹中并加入到你的Demo中来正常使用dxerr.lib。


4.从https://github.com/Microsoft/FX11下载Effects源码,找到Effects11_2015.sln,用vs2015打开项目后Rebuild得到新的Effecs11d.lib和Effecs11.lib替换之前本书中供VS2010使用的版本,注意还要将新版本的d3dx11effect.h复制到Common文件夹(FX11库的API设计与之前相比有点变动)。


你可以在https://blogs.msdn.microsoft.com/chuckw/阅读到上述变更的具体信息。



这里举第九章的BlendDemo为例:

1.移除代码中的#include <d3dx11.h>, 以及链接的d3dx11.lib, 还有其他一切依赖于d3dx11的代码。

2.移除链接的dxerr.lib, 添加dxerr.h/cpp到Demo中,修改#include <dxerr.h>为#include “dxerr.h”。

3.添加#include "DDSTextureLoader.h"到 d3dUtil.h。

4.替换#include <xnamath.h>为#include <DirectXMath.h>和#include <DirectXPackedVector.h>。

5.在使用类似XMVector,XMMatrixTranspose时, 改为DirectX::XMVector, DirectX::XMMatrixTranspose。

6.在使用XMCOLOR的地方,改为DirectX::PackedVector::XMCOLOR。

7.移除所有使用D3DX11INLINE的地方,或者替换为C++关键字inline。

8.取消使用d3dHelper::CreateTexture2DArraySRV,推荐使用texassemble工具(https://directxtex.codeplex.com/wikipage?title=Texassemble&referringTitle=Texconv)离线创建纹理数组。

9.在d3dUtil.h中,替换DXTrace调用时用到的参数__FILE__为__FILEW__, 因为现在获取文件名以宽字符串的方式。

10.在d3dUtil.h中,修改ExtractFrustumPlanes函数:

void ExtractFrustumPlanes(XMFLOAT4 planes[6], CXMMATRIX T){XMFLOAT4X4 M;XMStoreFloat4x4(&M, T); //// Left//  planes[0].x = M(0,3) + M(0,0);planes[0].y = M(1,3) + M(1,0);planes[0].z = M(2,3) + M(2,0);planes[0].w = M(3,3) + M(3,0); //// Right//planes[1].x = M(0,3) - M(0,0);planes[1].y = M(1,3) - M(1,0);planes[1].z = M(2,3) - M(2,0);planes[1].w = M(3,3) - M(3,0); //// Bottom//planes[2].x = M(0,3) + M(0,1);planes[2].y = M(1,3) + M(1,1);planes[2].z = M(2,3) + M(2,1);planes[2].w = M(3,3) + M(3,1); //// Top//planes[3].x = M(0,3) - M(0,1);planes[3].y = M(1,3) - M(1,1);planes[3].z = M(2,3) - M(2,1);planes[3].w = M(3,3) - M(3,1); //// Near//planes[4].x = M(0,2);planes[4].y = M(1,2);planes[4].z = M(2,2);planes[4].w = M(3,2); //// Far//planes[5].x = M(0,3) - M(0,2);planes[5].y = M(1,3) - M(1,2);planes[5].z = M(2,3) - M(2,2);planes[5].w = M(3,3) - M(3,2); // Normalize the plane equations.for(int i = 0; i < 6; ++i){    XMVECTOR v = XMPlaneNormalize(XMLoadFloat4(&planes[i]));    XMStoreFloat4(&planes[i], v);}}
11.替换D3DX11CreateShaderResourceViewFormFile为DirectX::CreateDDSTextureFromFile, 在BlendDemo中:
HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice,    L"Textures/grass.dds", 0, 0, &mGrassMapSRV, 0 )); HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice,    L"Textures/water2.dds", 0, 0, &mWavesMapSRV, 0 )); HR(D3DX11CreateShaderResourceViewFromFile(md3dDevice,    L"Textures/WireFence.dds", 0, 0, &mBoxMapSRV, 0 ));
替换为:

ID3D11Resource* texResource = nullptr;HR(DirectX::CreateDDSTextureFromFile(md3dDevice,    L"Textures/grass.dds", &texResource, &mGrassMapSRV));ReleaseCOM(texResource); // view saves reference HR(DirectX::CreateDDSTextureFromFile(md3dDevice,    L"Textures/water2.dds", &texResource, &mWavesMapSRV));    ReleaseCOM(texResource); // view saves reference HR(DirectX::CreateDDSTextureFromFile(md3dDevice,    L"Textures/WireFence.dds", &texResource, &mBoxMapSRV));ReleaseCOM(texResource); // view saves reference




补充:

1.xnamath->DirectXMath的方便做法:

#include <DirectXMath.h>#include <DirectXPackedVector.h>using namespace DirectX;
如若用到XMCOLOR,

using namespace DirectX::PackedVector;

2.出现找不到入口点"main":

对于.fx文件,选择不参与生成,然后在项目build之前手动用fxc命令生成出fxo即可。


最后:

供VS2015使用的Common文件夹 : https://github.com/DrinkMoon/directx11-pratices/tree/master/Common_vs2015

按上述配置好的BlendDemo: https://github.com/DrinkMoon/directx11-pratices/tree/master/Exercises/d3dDemo



1 0
原创粉丝点击