C++ 哪个头文件包含DirectX 12中的ThrowIfFailed()
我是DirectX 12或游戏编程的初学者,并从Microsoft文档学习。在使用函数ThrowIfFailed时,vs2015编辑器的intellisense出现了一个错误 此声明没有存储类或类型说明符C++ 哪个头文件包含DirectX 12中的ThrowIfFailed(),c++,visual-c++,directx,directx-12,C++,Visual C++,Directx,Directx 12,我是DirectX 12或游戏编程的初学者,并从Microsoft文档学习。在使用函数ThrowIfFailed时,vs2015编辑器的intellisense出现了一个错误 此声明没有存储类或类型说明符 任何人都可以帮助。此错误是因为您的某些代码不在任何函数范围内 您的错误就在这里: void D3D12HelloTriangle::LoadPipeline() { #if defined(_DEBUG) { //<= this brack is simply ignore becaus
任何人都可以帮助。此错误是因为您的某些代码不在任何函数范围内 您的错误就在这里:
void D3D12HelloTriangle::LoadPipeline() {
#if defined(_DEBUG) { //<= this brack is simply ignore because on a pre-processor line
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))) {
debugController->EnableDebugLayer();
}
} // So, this one closes method LoadPipeline
#endif
// From here, you are out of any function
ComPtr<IDXGIFactory4> factory;
ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
因此,要纠正它:
void D3D12HelloTriangle::LoadPipeline() {
#if defined(_DEBUG)
{ //<= just put this bracket on it's own line
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))) {
debugController->EnableDebugLayer();
}
} // So, this one close method LoadPipeline
#endif
// From here, you are out of any function
ComPtr<IDXGIFactory4> factory;
ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
由于您是DirectX编程新手,我强烈建议您从DirectX 11开始,而不是从DirectX 12开始。DirectX 12假定您已经是DirectX 11的专家级开发人员,并且是一个非常不可原谅的API。如果你打算成为一名图形开发人员,这绝对值得学习,但从DX 12开始学习DX 11是一项艰巨的任务。有关和/或的详细信息,请参阅DirectX工具包教程
对于现代DirectX示例代码和VS DirectX模板,Microsoft使用标准帮助函数ThrowIfFailed。它不是操作系统或系统头的一部分;它只是在本地项目的预编译头文件pch.h中定义的:
这不是标题问题。您只需在任何函数外编写代码请发布您的代码以帮助我们了解其在LoadPipeline函数内编写的情况好的,那么,您的代码是什么我已经编写了相同的代码,您推荐DirectX11或github的任何书籍就够了吗?@ShivamKushwaha您可以在internet上找到许多教程
#include <exception>
namespace DX
{
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
// Set a breakpoint on this line to catch DirectX API errors
throw std::exception();
}
}
}
#include <exception>
namespace DX
{
// Helper class for COM exceptions
class com_exception : public std::exception
{
public:
com_exception(HRESULT hr) : result(hr) {}
virtual const char* what() const override
{
static char s_str[64] = {};
sprintf_s(s_str, "Failure with HRESULT of %08X",
static_cast<unsigned int>(result));
return s_str;
}
private:
HRESULT result;
};
// Helper utility converts D3D API failures into exceptions.
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
throw com_exception(hr);
}
}
}