Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
StudyDx
Commits
ca26976f
Commit
ca26976f
authored
Dec 26, 2022
by
Administrator
Browse files
follow hw3d, throw macro organized into headers
parent
942244ec
Changes
9
Hide whitespace changes
Inline
Side-by-side
StudyDx/App.cpp
View file @
ca26976f
...
...
@@ -25,11 +25,6 @@ void App::DoFrame()
{
const
float
c
=
sin
(
timer
.
Peek
())
/
2.0
f
+
0.5
f
;
wnd
.
Gfx
().
ClearBuffer
(
c
,
c
,
1.0
f
);
wnd
.
Gfx
().
DrawTestTriangle
(
-
timer
.
Peek
(),
0.0
f
,
0.0
f
);
wnd
.
Gfx
().
DrawTestTriangle
(
timer
.
Peek
(),
wnd
.
mouse
.
GetPosX
()
/
400.0
f
-
1.0
f
,
...
...
StudyDx/DxgiInfoManager.cpp
View file @
ca26976f
...
...
@@ -3,11 +3,11 @@
#include "Graphics.h"
#include <dxgidebug.h>
#include <memory>
#include "GraphicsThrowMacros.h"
#include "WindowsThrowMacros.h"
#pragma comment(lib, "dxguid.lib")
#define GFX_THROW_NOINFO(hrcall) if( FAILED( hr = (hrcall) ) ) throw Graphics::HrException( __LINE__,__FILE__,hr )
DxgiInfoManager
::
DxgiInfoManager
()
{
// define function signature of DXGIGetDebugInterface
...
...
StudyDx/Graphics.cpp
View file @
ca26976f
...
...
@@ -3,30 +3,14 @@
#include <sstream>
#include <d3dcompiler.h>
#include <DirectXMath.h>
namespace
dx
=
DirectX
;
#include "GraphicsThrowMacros.h"
namespace
wrl
=
Microsoft
::
WRL
;
namespace
dx
=
DirectX
;
#pragma comment(lib,"d3d11.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
)
{
// 交换链的参数定义
...
...
StudyDx/GraphicsThrowMacros.h
0 → 100644
View file @
ca26976f
#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
StudyDx/StudyDx.vcxproj
View file @
ca26976f
...
...
@@ -157,11 +157,13 @@
<ClInclude
Include=
"dxerr.h"
/>
<ClInclude
Include=
"DxgiInfoManager.h"
/>
<ClInclude
Include=
"Graphics.h"
/>
<ClInclude
Include=
"GraphicsThrowMacros.h"
/>
<ClInclude
Include=
"Keyboard.h"
/>
<ClInclude
Include=
"Mouse.h"
/>
<ClInclude
Include=
"resource.h"
/>
<ClInclude
Include=
"Window.h"
/>
<ClInclude
Include=
"WindowsMessageMap.h"
/>
<ClInclude
Include=
"WindowsThrowMacros.h"
/>
</ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"StudyDx.rc"
/>
...
...
StudyDx/StudyDx.vcxproj.filters
View file @
ca26976f
...
...
@@ -92,6 +92,12 @@
<ClInclude
Include=
"DxgiInfoManager.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"GraphicsThrowMacros.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"WindowsThrowMacros.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"StudyDx.rc"
>
...
...
StudyDx/Window.cpp
View file @
ca26976f
...
...
@@ -20,7 +20,7 @@
#include "Window.h"
#include <sstream>
#include "resource.h"
#include "WindowsThrowMacros.h"
// Window Class Stuff
Window
::
WindowClass
Window
::
WindowClass
::
wndClass
;
...
...
@@ -282,6 +282,7 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
mouse
.
OnLeftPressed
(
pt
.
x
,
pt
.
y
);
SetForegroundWindow
(
hWnd
);
break
;
}
...
...
StudyDx/Window.h
View file @
ca26976f
...
...
@@ -90,10 +90,4 @@ private:
HWND
hWnd
;
// 成员变量gfx在Window的构造函数执行的过程中才会被初始化,因此定义指针变量,用于初始化gfx
std
::
unique_ptr
<
Graphics
>
pGfx
;
};
// 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
};
\ No newline at end of file
StudyDx/WindowsThrowMacros.h
0 → 100644
View file @
ca26976f
#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__ )
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment