Directx11教程(11) 增加一个debug宏
2012-03-18 13:51
197 查看
现在我们在common.h中增加一个debug的宏,在每个d3d11函数后调用,如果d3d函数出错,它能够给出程序中错误的代码行数。
common.h代码如下:
#pragma once
#include <d3d11.h>
#include <d3dx10math.h>
#if defined(DEBUG) || defined(_DEBUG)
#ifndef D3D_DEBUG_INFO
#define D3D_DEBUG_INFO
#endif
#endif
#if defined(DEBUG) || defined(_DEBUG)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#include <dxerr.h>
#include <cassert>
//一个简单的错误检测宏
#if defined(DEBUG) | defined(_DEBUG)
#ifndef HR
#define HR(x) \
{ \
HRESULT hr = (x); \
if(FAILED(hr)) \
{ \
DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); \
} \
}
#endif
#else
#ifndef HR
#define HR(x) (x)
#endif
#endif
//定义一些常用颜色
const D3DXVECTOR4 WHITE(1.0f, 1.0f, 1.0f, 1.0f);
const D3DXVECTOR4 BLACK(0.0f, 0.0f, 0.0f, 1.0f);
const D3DXVECTOR4 RED(1.0f, 0.0f, 0.0f, 1.0f);
const D3DXVECTOR4 GREEN(0.0f, 1.0f, 0.0f, 1.0f);
const D3DXVECTOR4 BLUE(0.0f, 0.0f, 1.0f, 1.0f);
const D3DXVECTOR4 YELLOW(1.0f, 1.0f, 0.0f, 1.0f);
const D3DXVECTOR4 CYAN(0.0f, 1.0f, 1.0f, 1.0f); //蓝绿色
const D3DXVECTOR4 MAGENTA(1.0f, 0.0f, 1.0f, 1.0f);//洋红色
const D3DXVECTOR4 BEACH_SAND(1.0f, 0.96f, 0.62f, 1.0f);
const D3DXVECTOR4 LIGHT_YELLOW_GREEN(0.48f, 0.77f, 0.46f, 1.0f);
const D3DXVECTOR4 DARK_YELLOW_GREEN(0.1f, 0.48f, 0.19f, 1.0f);
const D3DXVECTOR4 DARKBROWN(0.45f, 0.39f, 0.34f, 1.0f);
现在我们修改每一个D3D11函数的调用,比如
// 创建交换链,设备以及设备上下文.
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL,createDeviceFlags, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
if(FAILED(result))
{
HR(result);
return false;
}
其它类似的代码我就不贴了。
完整的代码请参考:
工程文件myTutorialD3D11_10
代码下载:
http://files.cnblogs.com/mikewolf2002/myTutorialD3D11.zip
common.h代码如下:
#pragma once
#include <d3d11.h>
#include <d3dx10math.h>
#if defined(DEBUG) || defined(_DEBUG)
#ifndef D3D_DEBUG_INFO
#define D3D_DEBUG_INFO
#endif
#endif
#if defined(DEBUG) || defined(_DEBUG)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#include <dxerr.h>
#include <cassert>
//一个简单的错误检测宏
#if defined(DEBUG) | defined(_DEBUG)
#ifndef HR
#define HR(x) \
{ \
HRESULT hr = (x); \
if(FAILED(hr)) \
{ \
DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); \
} \
}
#endif
#else
#ifndef HR
#define HR(x) (x)
#endif
#endif
//定义一些常用颜色
const D3DXVECTOR4 WHITE(1.0f, 1.0f, 1.0f, 1.0f);
const D3DXVECTOR4 BLACK(0.0f, 0.0f, 0.0f, 1.0f);
const D3DXVECTOR4 RED(1.0f, 0.0f, 0.0f, 1.0f);
const D3DXVECTOR4 GREEN(0.0f, 1.0f, 0.0f, 1.0f);
const D3DXVECTOR4 BLUE(0.0f, 0.0f, 1.0f, 1.0f);
const D3DXVECTOR4 YELLOW(1.0f, 1.0f, 0.0f, 1.0f);
const D3DXVECTOR4 CYAN(0.0f, 1.0f, 1.0f, 1.0f); //蓝绿色
const D3DXVECTOR4 MAGENTA(1.0f, 0.0f, 1.0f, 1.0f);//洋红色
const D3DXVECTOR4 BEACH_SAND(1.0f, 0.96f, 0.62f, 1.0f);
const D3DXVECTOR4 LIGHT_YELLOW_GREEN(0.48f, 0.77f, 0.46f, 1.0f);
const D3DXVECTOR4 DARK_YELLOW_GREEN(0.1f, 0.48f, 0.19f, 1.0f);
const D3DXVECTOR4 DARKBROWN(0.45f, 0.39f, 0.34f, 1.0f);
现在我们修改每一个D3D11函数的调用,比如
// 创建交换链,设备以及设备上下文.
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL,createDeviceFlags, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
if(FAILED(result))
{
HR(result);
return false;
}
其它类似的代码我就不贴了。
完整的代码请参考:
工程文件myTutorialD3D11_10
代码下载:
http://files.cnblogs.com/mikewolf2002/myTutorialD3D11.zip
相关文章推荐
- Directx11教程(9) 增加一个TimerClass类
- Directx11教程(3) 一个最基本D3D应用程序(1)
- Directx11教程(20) 一个简单的水面
- Directx11教程(4) 一个最基本D3D应用程序(2)
- OpenScales入门教程 第3节 : 增加一个标注
- titanium开发教程-04-02增加一个搜索栏
- 11周1--2以Point为基类,派生出一个Circle(圆)类,增加数据成员r(半径),以及求面积的成员函数area,实现其他需要的成员函数,设计main函数完成测试;
- Directx11教程(5) 画一个简单的三角形(1)
- Qt教程11--给它一个移动的炮弹
- Win7增加C盘容量及对分区再分区的方法与软件分享(一个盘分两个盘) 图文教程
- TensorFlow 教程 --进阶指南--3.6增加一个新 Op
- SMARTY教程_在循环中获取一个会自动增加的数字
- Direct3D 11教程2:绘制一个三角形
- Directx11教程(8) 一个新的camera类
- Directx11教程(56) 建立一个skydome
- titanium开发教程-02-11增加交互性,在任何view
- Directx11教程(10) 画一个简易坐标轴
- Directx11教程(19) 画一个简单的地形
- Directx11教程41 纹理映射(11)
- Directx11教程(6) 画一个简单的三角形(2)