Commit ca26976f authored by Administrator's avatar Administrator
Browse files

follow hw3d, throw macro organized into headers

parent 942244ec
...@@ -25,11 +25,6 @@ void App::DoFrame() ...@@ -25,11 +25,6 @@ void App::DoFrame()
{ {
const float c = sin(timer.Peek()) / 2.0f + 0.5f; const float c = sin(timer.Peek()) / 2.0f + 0.5f;
wnd.Gfx().ClearBuffer(c, c, 1.0f); wnd.Gfx().ClearBuffer(c, c, 1.0f);
wnd.Gfx().DrawTestTriangle(
-timer.Peek(),
0.0f,
0.0f
);
wnd.Gfx().DrawTestTriangle( wnd.Gfx().DrawTestTriangle(
timer.Peek(), timer.Peek(),
wnd.mouse.GetPosX() / 400.0f - 1.0f, wnd.mouse.GetPosX() / 400.0f - 1.0f,
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
#include "Graphics.h" #include "Graphics.h"
#include <dxgidebug.h> #include <dxgidebug.h>
#include <memory> #include <memory>
#include "GraphicsThrowMacros.h"
#include "WindowsThrowMacros.h"
#pragma comment(lib, "dxguid.lib") #pragma comment(lib, "dxguid.lib")
#define GFX_THROW_NOINFO(hrcall) if( FAILED( hr = (hrcall) ) ) throw Graphics::HrException( __LINE__,__FILE__,hr )
DxgiInfoManager::DxgiInfoManager() DxgiInfoManager::DxgiInfoManager()
{ {
// define function signature of DXGIGetDebugInterface // define function signature of DXGIGetDebugInterface
......
...@@ -3,30 +3,14 @@ ...@@ -3,30 +3,14 @@
#include <sstream> #include <sstream>
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <DirectXMath.h> #include <DirectXMath.h>
#include "GraphicsThrowMacros.h"
namespace dx = DirectX;
namespace wrl = Microsoft::WRL; namespace wrl = Microsoft::WRL;
namespace dx = DirectX;
#pragma comment(lib,"d3d11.lib") #pragma comment(lib,"d3d11.lib")
#pragma comment(lib,"D3DCompiler.lib") #pragma comment(lib,"D3DCompiler.lib")
// graphics exception checking/throwing macros (some with dxgi infos)
#define GFX_EXCEPT_NOINFO(hr) Graphics::HrException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_NOINFO(hrcall) if( FAILED( hr = (hrcall) ) ) throw Graphics::HrException( __LINE__,__FILE__,hr )
#ifndef NDEBUG
#define GFX_EXCEPT(hr) Graphics::HrException( __LINE__,__FILE__,(hr),infoManager.GetMessages() )
#define GFX_THROW_INFO(hrcall) infoManager.Set(); if( FAILED( hr = (hrcall) ) ) throw GFX_EXCEPT(hr)
#define GFX_DEVICE_REMOVED_EXCEPT(hr) Graphics::DeviceRemovedException( __LINE__,__FILE__,(hr),infoManager.GetMessages() )
#define GFX_THROW_INFO_ONLY(call) infoManager.Set(); (call); {auto v = infoManager.GetMessages(); if(!v.empty()) {throw Graphics::InfoException( __LINE__,__FILE__,v);}}
#else
#define GFX_EXCEPT(hr) Graphics::HrException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_INFO(hrcall) GFX_THROW_NOINFO(hrcall)
#define GFX_DEVICE_REMOVED_EXCEPT(hr) Graphics::DeviceRemovedException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_INFO_ONLY(call) (call)
#endif
Graphics::Graphics( HWND hWnd ) Graphics::Graphics( HWND hWnd )
{ {
// 交换链的参数定义 // 交换链的参数定义
......
#pragma once
// HRESULT hr should exist in the local scope for these macros to work
#define GFX_EXCEPT_NOINFO(hr) Graphics::HrException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_NOINFO(hrcall) if( FAILED( hr = (hrcall) ) ) throw Graphics::HrException( __LINE__,__FILE__,hr )
#ifndef NDEBUG
#define GFX_EXCEPT(hr) Graphics::HrException( __LINE__,__FILE__,(hr),infoManager.GetMessages() )
#define GFX_THROW_INFO(hrcall) infoManager.Set(); if( FAILED( hr = (hrcall) ) ) throw GFX_EXCEPT(hr)
#define GFX_DEVICE_REMOVED_EXCEPT(hr) Graphics::DeviceRemovedException( __LINE__,__FILE__,(hr),infoManager.GetMessages() )
#define GFX_THROW_INFO_ONLY(call) infoManager.Set(); (call); {auto v = infoManager.GetMessages(); if(!v.empty()) {throw Graphics::InfoException( __LINE__,__FILE__,v);}}
#else
#define GFX_EXCEPT(hr) Graphics::HrException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_INFO(hrcall) GFX_THROW_NOINFO(hrcall)
#define GFX_DEVICE_REMOVED_EXCEPT(hr) Graphics::DeviceRemovedException( __LINE__,__FILE__,(hr) )
#define GFX_THROW_INFO_ONLY(call) (call)
#endif
// macro for importing infomanager into local scope
// this.GetInfoManager() must exist
#ifdef NDEBUG
#define INFOMAN() HRESULT hr
#else
#define INFOMAN() HRESULT hr; DxgiInfoManager& infoManager = GetInfoManager()
#endif
...@@ -157,11 +157,13 @@ ...@@ -157,11 +157,13 @@
<ClInclude Include="dxerr.h" /> <ClInclude Include="dxerr.h" />
<ClInclude Include="DxgiInfoManager.h" /> <ClInclude Include="DxgiInfoManager.h" />
<ClInclude Include="Graphics.h" /> <ClInclude Include="Graphics.h" />
<ClInclude Include="GraphicsThrowMacros.h" />
<ClInclude Include="Keyboard.h" /> <ClInclude Include="Keyboard.h" />
<ClInclude Include="Mouse.h" /> <ClInclude Include="Mouse.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="Window.h" /> <ClInclude Include="Window.h" />
<ClInclude Include="WindowsMessageMap.h" /> <ClInclude Include="WindowsMessageMap.h" />
<ClInclude Include="WindowsThrowMacros.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="StudyDx.rc" /> <ResourceCompile Include="StudyDx.rc" />
......
...@@ -92,6 +92,12 @@ ...@@ -92,6 +92,12 @@
<ClInclude Include="DxgiInfoManager.h"> <ClInclude Include="DxgiInfoManager.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="GraphicsThrowMacros.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="WindowsThrowMacros.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="StudyDx.rc"> <ResourceCompile Include="StudyDx.rc">
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "Window.h" #include "Window.h"
#include <sstream> #include <sstream>
#include "resource.h" #include "resource.h"
#include "WindowsThrowMacros.h"
// Window Class Stuff // Window Class Stuff
Window::WindowClass Window::WindowClass::wndClass; Window::WindowClass Window::WindowClass::wndClass;
...@@ -282,6 +282,7 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex ...@@ -282,6 +282,7 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
{ {
const POINTS pt = MAKEPOINTS(lParam); const POINTS pt = MAKEPOINTS(lParam);
mouse.OnLeftPressed(pt.x, pt.y); mouse.OnLeftPressed(pt.x, pt.y);
SetForegroundWindow(hWnd);
break; break;
} }
......
...@@ -90,10 +90,4 @@ private: ...@@ -90,10 +90,4 @@ private:
HWND hWnd; HWND hWnd;
// 成员变量gfx在Window的构造函数执行的过程中才会被初始化,因此定义指针变量,用于初始化gfx // 成员变量gfx在Window的构造函数执行的过程中才会被初始化,因此定义指针变量,用于初始化gfx
std::unique_ptr<Graphics> pGfx; std::unique_ptr<Graphics> pGfx;
}; };
\ No newline at end of file
// error exception helper macro
#define CHWND_EXCEPT( hr ) Window::HrException( __LINE__,__FILE__,(hr) )
#define CHWND_LAST_EXCEPT() Window::HrException( __LINE__,__FILE__,GetLastError() )
#define CHWND_NOGFX_EXCEPT() Window::NoGfxException( __LINE__,__FILE__ )
\ No newline at end of file
#pragma once
#define CHWND_EXCEPT( hr ) Window::HrException( __LINE__,__FILE__,(hr) )
#define CHWND_LAST_EXCEPT() Window::HrException( __LINE__,__FILE__,GetLastError() )
#define CHWND_NOGFX_EXCEPT() Window::NoGfxException( __LINE__,__FILE__ )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment