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
87608150
Commit
87608150
authored
Dec 18, 2022
by
Administrator
Browse files
use com pointer
parent
f4450a4d
Changes
4
Hide whitespace changes
Inline
Side-by-side
StudyDx/DxgiInfoManager.cpp
View file @
87608150
...
@@ -30,15 +30,7 @@ DxgiInfoManager::DxgiInfoManager()
...
@@ -30,15 +30,7 @@ DxgiInfoManager::DxgiInfoManager()
}
}
HRESULT
hr
;
HRESULT
hr
;
GFX_THROW_NOINFO
(
DxgiGetDebugInterface
(
__uuidof
(
IDXGIInfoQueue
),
reinterpret_cast
<
void
**>
(
&
pDxgiInfoQueue
)
)
);
GFX_THROW_NOINFO
(
DxgiGetDebugInterface
(
__uuidof
(
IDXGIInfoQueue
),
&
pDxgiInfoQueue
));
}
DxgiInfoManager
::~
DxgiInfoManager
()
{
if
(
pDxgiInfoQueue
!=
nullptr
)
{
pDxgiInfoQueue
->
Release
();
}
}
}
void
DxgiInfoManager
::
Set
()
noexcept
void
DxgiInfoManager
::
Set
()
noexcept
...
...
StudyDx/DxgiInfoManager.h
View file @
87608150
#pragma once
#pragma once
#include "ChiliWin.h"
#include "ChiliWin.h"
#include <wrl.h>
#include <vector>
#include <vector>
#include <dxgidebug.h>
#include <string>
#include <string>
class
DxgiInfoManager
class
DxgiInfoManager
{
{
public:
public:
DxgiInfoManager
();
DxgiInfoManager
();
~
DxgiInfoManager
();
~
DxgiInfoManager
()
=
default
;
DxgiInfoManager
(
const
DxgiInfoManager
&
)
=
delete
;
DxgiInfoManager
(
const
DxgiInfoManager
&
)
=
delete
;
DxgiInfoManager
&
operator
=
(
const
DxgiInfoManager
&
)
=
delete
;
DxgiInfoManager
&
operator
=
(
const
DxgiInfoManager
&
)
=
delete
;
void
Set
()
noexcept
;
void
Set
()
noexcept
;
std
::
vector
<
std
::
string
>
GetMessages
()
const
;
std
::
vector
<
std
::
string
>
GetMessages
()
const
;
private:
private:
unsigned
long
long
next
=
0u
;
unsigned
long
long
next
=
0u
;
struct
IDXGIInfoQueue
*
pDxgiInfoQueue
=
nullptr
;
Microsoft
::
WRL
::
ComPtr
<
IDXGIInfoQueue
>
pDxgiInfoQueue
;
};
};
\ No newline at end of file
StudyDx/Graphics.cpp
View file @
87608150
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
#include "dxerr.h"
#include "dxerr.h"
#include <sstream>
#include <sstream>
namespace
wrl
=
Microsoft
::
WRL
;
#pragma comment(lib,"d3d11.lib")
#pragma comment(lib,"d3d11.lib")
// graphics exception checking/throwing macros (some with dxgi infos)
// graphics exception checking/throwing macros (some with dxgi infos)
...
@@ -65,37 +67,9 @@ Graphics::Graphics( HWND hWnd )
...
@@ -65,37 +67,9 @@ Graphics::Graphics( HWND hWnd )
// gain access to texture subresource in swap chain (back buffer)
// gain access to texture subresource in swap chain (back buffer)
// 定义指向backBuffer的指针
wrl
::
ComPtr
<
ID3D11Resource
>
pBackBuffer
;
ID3D11Resource
*
pBackBuffer
=
nullptr
;
GFX_THROW_INFO
(
pSwap
->
GetBuffer
(
0
,
__uuidof
(
ID3D11Resource
),
&
pBackBuffer
));
GFX_THROW_INFO
(
pDevice
->
CreateRenderTargetView
(
pBackBuffer
.
Get
(),
nullptr
,
&
pTarget
));
// 通过SwapChian,取得backBuffer
GFX_THROW_INFO
(
pSwap
->
GetBuffer
(
0
,
__uuidof
(
ID3D11Resource
),
reinterpret_cast
<
void
**>
(
&
pBackBuffer
)));
// 取得指向属于backBuffer的View的指针
GFX_THROW_INFO
(
pDevice
->
CreateRenderTargetView
(
pBackBuffer
,
nullptr
,
&
pTarget
));
pBackBuffer
->
Release
();
}
Graphics
::~
Graphics
()
{
// 释放View, Context, SwapChain和Device
if
(
pTarget
!=
nullptr
)
{
pTarget
->
Release
();
}
if
(
pContext
!=
nullptr
)
{
pContext
->
Release
();
}
if
(
pSwap
!=
nullptr
)
{
pSwap
->
Release
();
}
if
(
pDevice
!=
nullptr
)
{
pDevice
->
Release
();
}
}
}
void
Graphics
::
EndFrame
()
void
Graphics
::
EndFrame
()
...
@@ -121,7 +95,7 @@ void Graphics::EndFrame()
...
@@ -121,7 +95,7 @@ void Graphics::EndFrame()
void
Graphics
::
ClearBuffer
(
float
red
,
float
green
,
float
blue
)
noexcept
void
Graphics
::
ClearBuffer
(
float
red
,
float
green
,
float
blue
)
noexcept
{
{
const
float
color
[]
=
{
red
,
green
,
blue
,
1.0
f
};
const
float
color
[]
=
{
red
,
green
,
blue
,
1.0
f
};
pContext
->
ClearRenderTargetView
(
pTarget
,
color
);
pContext
->
ClearRenderTargetView
(
pTarget
.
Get
()
,
color
);
}
}
// Graphics exception stuff
// Graphics exception stuff
...
...
StudyDx/Graphics.h
View file @
87608150
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include "ChiliWin.h"
#include "ChiliWin.h"
#include "ChiliException.h"
#include "ChiliException.h"
#include <d3d11.h>
#include <d3d11.h>
#include <wrl.h>
#include <vector>
#include <vector>
#include "DxgiInfoManager.h"
#include "DxgiInfoManager.h"
...
@@ -38,7 +39,7 @@ public:
...
@@ -38,7 +39,7 @@ public:
Graphics
(
HWND
hWnd
);
Graphics
(
HWND
hWnd
);
Graphics
(
const
Graphics
&
)
=
delete
;
Graphics
(
const
Graphics
&
)
=
delete
;
Graphics
&
operator
=
(
const
Graphics
&
)
=
delete
;
Graphics
&
operator
=
(
const
Graphics
&
)
=
delete
;
~
Graphics
();
~
Graphics
()
=
default
;
void
EndFrame
();
void
EndFrame
();
// 刷新RGB
// 刷新RGB
void
ClearBuffer
(
float
red
,
float
green
,
float
blue
)
noexcept
;
void
ClearBuffer
(
float
red
,
float
green
,
float
blue
)
noexcept
;
...
@@ -47,11 +48,11 @@ private:
...
@@ -47,11 +48,11 @@ private:
DxgiInfoManager
infoManager
;
DxgiInfoManager
infoManager
;
#endif
#endif
// 指向Device的指针
// 指向Device的指针
ID3D11Device
*
pDevice
=
nullptr
;
Microsoft
::
WRL
::
ComPtr
<
ID3D11Device
>
pDevice
;
// 指向交换链的指针
// 指向交换链的指针
IDXGISwapChain
*
pSwap
=
nullptr
;
Microsoft
::
WRL
::
ComPtr
<
IDXGISwapChain
>
pSwap
;
// 指向Context的指针
// 指向Context的指针
ID3D11DeviceContext
*
pContext
=
nullptr
;
Microsoft
::
WRL
::
ComPtr
<
ID3D11DeviceContext
>
pContext
;
// 指向View的指针
// 指向View的指针
ID3D11RenderTargetView
*
pTarget
=
nullptr
;
Microsoft
::
WRL
::
ComPtr
<
ID3D11RenderTargetView
>
pTarget
;
};
};
\ No newline at end of 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