[RasterTek/DirectX 11] #3 DirectX 11 ์ด๊ธฐํ
๐ ์ฐธ๊ณ ์๋ฃ
๐ฅ๏ธ ๊ฐ๋ฐํ๊ฒฝ
- Window 11
- Visual Studio 2022
Updated Framework
---
title: Framework
config:
look: handDrawn
theme: neutral
---
graph TD
WinMain --- SystemClass
SystemClass --- InputClass
SystemClass --- ApplicationClass
ApplicationClass --- D3DClass
Direct3D ๊ธฐ๋ฅ์ ์ฒ๋ฆฌํ๋ ์ ํด๋์ค๋ฅผ ์ถ๊ฐํ๋ค(D3DClass
).
ApplicationClass ๋ด๋ถ์ ๊ทธ๋ํฝ ๊ด๋ จ ํด๋์ค๊ฐ ์บก์ํ๋๋ฏ๋ก, D3DClass๋ ApplicationClass ๋ด๋ถ์ ํฌํจ๋๋ค.
ApplicationClass.h
1
2
3
4
5
////////////////////////////////////////////////////////////////////////////////
// Filename: applicationclass.h
////////////////////////////////////////////////////////////////////////////////
#ifndef _APPLICATIONCLASS_H_
#define _APPLICATIONCLASS_H_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
///////////////////////
// MY CLASS INCLUDES //
///////////////////////
#include "d3dclass.h"
/////////////
// GLOBALS //
/////////////
const bool FULL_SCREEN = false;
const bool VSYNC_ENABLED = true;
const float SCREEN_DEPTH = 1000.0f;
const float SCREEN_NEAR = 0.3f;
////////////////////////////////////////////////////////////////////////////////
// Class name: ApplicationClass
////////////////////////////////////////////////////////////////////////////////
class ApplicationClass
{
public:
ApplicationClass();
ApplicationClass(const ApplicationClass&);
~ApplicationClass();
bool Initialize(int, int, HWND);
void Shutdown();
bool Frame();
private:
bool Render();
private:
D3DClass* m_Direct3D;
};
#endif
๋ณ๊ฒฝ์
windows.h
๋์d3dclass.h
๋ฅผ include- D3DClass์ ์ private ํฌ์ธํฐ(
m_Direct3D
) ์ถ๊ฐm_
: ํด๋์ค ๋ฉค๋ฒ ๋ณ์์ธ์ง ๊ตฌ๋ณ
ApplicationClass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "applicationclass.h"
ApplicationClass::ApplicationClass()
{
m_Direct3D = 0;
}
ApplicationClass::ApplicationClass(const ApplicationClass& other)
{
}
ApplicationClass::~ApplicationClass()
{
}
bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{
bool result;
// D3D ๊ฐ์ฒด ์์ฑ ๋ฐ ์ด๊ธฐํ
m_Direct3D = new D3DClass;
result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
if (!result)
{
MessageBox(hwnd, L"Could not initialize Direct3D", L"Error", MB_OK);
return false;
}
return true;
}
void ApplicationClass::Shutdown()
{
// D3D ๊ฐ์ฒด ํด์
if (m_Direct3D)
{
m_Direct3D->Shutdown();
delete m_Direct3D;
m_Direct3D = 0;
}
return;
}
bool ApplicationClass::Frame()
{
bool result;
// ๊ทธ๋ํฝ ๋ ๋๋ง
result = Render();
if (!result)
{
return false;
}
return true;
}
bool ApplicationClass::Render()
{
// ๋ฒํผ๋ฅผ ๋น์ฐ๊ณ scene ์์
m_Direct3D->BeginScene(0.5f, 0.5f, 0.5f, 1.0f);
// ๋ ๋๋ง๋ scene์ ํ๋ฉด์ ํ์
m_Direct3D->EndScene();
return true;
}
๋ณ๊ฒฝ์
์์ฑ์
ํฌ์ธํฐ
nullptr
์ด๊ธฐํํฌ์ธํฐ๋ฅผ ์์ ํ๊ฒ ๊ด๋ฆฌํ๋ ค๋ฉด ๋ณ์๋ฅผ ํญ์ ์ด๊ธฐํํ๋ ๊ฒ์ด ์ข๋ค!
Initialize
- D3DClass ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ์ด๊ธฐํ ํจ์ ํธ์ถ
- ํ๋ฉด ๋๋น, ๋์ด, ํธ๋ค,
ApplicationClass
์ ์ญ ๋ณ์ ์ ๋ฌ - D3D๊ฐ ๋งค๊ฐ๋ณ์๋ฅผ ๋ฐ์ D3D System ์ค์
- ํ๋ฉด ๋๋น, ๋์ด, ํธ๋ค,
- D3DClass ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ์ด๊ธฐํ ํจ์ ํธ์ถ
shutdown
D3DClass ์ข ๋ฃ ์ฝ๋ ์ถ๊ฐ
๋ชจ๋ ๊ทธ๋ํฝ ๊ฐ์ฒด๋ ์ด ํจ์์์ ์ข ๋ฃ๋๋ค!
ํฌ์ธํฐ๋ฅผ
nullptr
๋ก ์ด๊ธฐํํฌ์ธํฐ๊ฐ ์ด๊ธฐํ๋์ง ์์๋ค๋ฉด ํ๋ก๊ทธ๋จ์ด ์ข ๋ฃ๋์ง ์์
ํฌ์ธํฐ๊ฐ ์ ํจํ ๊ฒฝ์ฐ
shutdown()
์ ํธ์ถํ๊ณ , ๋ฉ๋ชจ๋ฆฌ ํด์ ๋ง์ฝ, ์ด๋ฏธ
nullptr
์ด๋ฉด ์์ง ๊ฐ์ฒด๊ฐ ์์ฑ๋์ง ์์์ผ๋ฏ๋ก, ๋ถํ์ํ shutdown ํธ์ถx
Frame
- ๊ฐ ํ๋ ์๋ง๋ค
Render
ํจ์ ํธ์ถ => ๊ทธ๋ํฝ ๋ ๋๋ง
- ๊ฐ ํ๋ ์๋ง๋ค
Render
- D3D๋ฅผ ์ฌ์ฉํด ํ๋ฉด์ ํ์์ผ๋ก ์ด๊ธฐํ
- ์ด๊ธฐํ ํ
EndScene
์ ํธ์ถํด ๋ ๋๋ง๋ ์ฌ์ ์๋์ฐ์ ํ์
D3dclass.h
1
2
3
4
5
////////////////////////////////////////////////////////////////////////////////
// Filename: d3dclass.h
////////////////////////////////////////////////////////////////////////////////
#ifndef _D3DCLASS_H_
#define _D3DCLASS_H_
LINKING
1
2
3
4
5
6
/////////////
// LINKING //
/////////////
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3dcompiler.lib")
ํค๋์์ ์ฒซ ๋ฒ์งธ๋ก ํ ์ผ: ์ค๋ธ์ ํธ ๋ชจ๋์ ์ฌ์ฉํ ๋ ๋งํฌํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ง์
d3d11.lib
: D3D์ ๋ชจ๋ ๊ธฐ๋ฅ ํฌํจ- DX11์์ 3D ๊ทธ๋ํฝ์ ์ค์ ํ๊ณ ๊ทธ๋ฆฌ๋๋ฐ ์ฌ์ฉ
dxgi.lib
: ์ปดํจํฐ์ ํ๋์จ์ด์ ์ํธ์์ฉํ๋ ๋๊ตฌ ํฌํจ- ๋ชจ๋ํฐ์ ์ฃผ์ฌ์จ(refresh rate), ๊ทธ๋ํฝ์นด๋ ์ ๋ณด ๋ฑ์ ์ ๊ณต๋ฐ์
d3dcompiler.lib
: ์ ฐ์ด๋ ์ปดํ์ผ ๊ธฐ๋ฅ ํฌํจ
INCLUDE
1
2
3
#include <d3d11.h>
#include <directxmath.h>
using namespace DirectX;
d3d11.h
: ์ค๋ธ์ ํธ ๋ชจ๋์ ๋งํฌํ ๋ผ์ด๋ธ๋ฌ๋ฆฌdirectxmath.h
: DX ํ์ ์ ์, ์ํ ์ฐ์ฐ ๊ธฐ๋ฅe.g.) ์ํ ์ฐ์ฐ, ๊ทธ๋ํฝ ๋ฐ์ดํฐ ๋ฑ -> ๋ฒกํฐ, ํ๋ ฌ, ์ขํ, ์์ ๋ฑ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class D3DClass
{
public:
D3DClass();
D3DClass(const D3DClass&);
~D3DClass();
/* D3D ์ด๊ธฐํ ๋ฐ ํด์ */
bool Initialize(int, int, bool, HWND, bool, float, float); // D3D ์ด๊ธฐํ
void Shutdown(); // D3D ๊ฐ์ฒด/๋ฉ๋ชจ๋ฆฌ ํด์
/* getter / setter */
// Scene ์์ ๋ฐ ์ถ๋ ฅ
void BeginScene(float, float, float, float); // ํ๋ฉด ๊ทธ๋ฆฌ๊ธฐ ์ , ๋ฒํผ ์ด๊ธฐํ
void EndScene(); // ๋ ๋๋ง ํ ๋ฒํผ ์ถ๋ ฅ
ID3D11Device* GetDevice(); // D3D ๋๋ฐ์ด์ค ๊ฐ์ฒด(๊ทธ๋ํฝ ๋ฆฌ์์ค ์์ฑ)
ID3D11DeviceContext* GetDeviceContext(); // D3D ๋๋ฐ์ด์ค ์ปจํ
์คํธ(ํ์ดํ๋ผ์ธ ์คํ
์ด์ง๋ก ์ ๊ทผํด GPU์ ๋ ๋๋ง ๋ช
๋ น)
// ํ๋ ฌ ๋ฐํ
void GetProjectionMatrix(XMMATRIX&); // 3D ํฌ์ ํ๋ ฌ
void GetWorldMatrix(XMMATRIX&); // 3D ์๋ ๋ณํ ํ๋ ฌ(3D ์ค๋ธ์ ํธ ์์น ๋ฐ ํ์ ๋ณํ)
void GetOrthoMatrix(XMMATRIX&); // 2D ์ง๊ต ํ๋ ฌ (2D ๋ ๋๋ง ์ํจ)
void GetVideoCardInfo(char* cardName, int& memory); // ๋น๋์ค ์นด๋ ์ ๋ณด(์ด๋ฆ, ํฌ๊ธฐ)
void SetBackBufferRenderTarget(); // ๋ฐฑ ๋ฒํผ๋ฅผ ํ์ฌ ๋ ๋ ํ๊ฒ์ผ๋ก ์ค์ (๋ ๋๋ง ๋์)
void ResetViewport(); // ๋ทฐํฌํธ ์ด๊ธฐํ(ํฌ๊ธฐ, ์์น)
private:
bool m_vsync_enabled; // ์์ง ๋๊ธฐํ ํ์ฑํ
int m_videoCardMemory; // ๋น๋์ค ์นด๋ ๋ฉ๋ชจ๋ฆฌ(mb)
char m_videoCardDescription[128]; // ๋น๋์ค ์นด๋ ์ด๋ฆ
IDXGISwapChain* m_swapChain; // ์ค์ ์ฒด์ธ(๋๋ธ ๋ฒํผ๋ง์ฉ)
ID3D11Device* m_device; // D3D ๋๋ฐ์ด์ค ๊ฐ์ฒด (GPU๋ฆฌ์์ค ๊ด๋ฆฌ)
ID3D11DeviceContext* m_deviceContext; // D3D ๋๋ฐ์ด์ค ์ปจํ
์คํธ (์ด์น๊ตฌ๊ฐ ๋ ๋๋ง ๋ช
๋ น ๋ด๋ฆผ)
ID3D11RenderTargetView* m_renderTargetView; // ๋ ๋ ํ๊ฒ ๋ทฐ(๋ ๋๋ง ์ถ๋ ฅ)
ID3D11Texture2D* m_depthStencilBuffer; // ๊น์ด ์คํ
์ค ๋ฒํผ
ID3D11DepthStencilState* m_depthStencilState; // ๊น์ด ์คํ
์ค ์ํ
ID3D11DepthStencilView* m_depthStencilView; // ๊น์ด ์คํ
์ค ๋ทฐ
ID3D11RasterizerState* m_rasterState; // ๋์คํฐ๋ผ์ด์ ์ํ(์ปฌ๋ง, ์์ด์ดํ๋ ์ ๋ฑ)
XMMATRIX m_projectionMatrix; // ํฌ์ ํ๋ ฌ
XMMATRIX m_worldMatrix; // ์๋ ํ๋ ฌ
XMMATRIX m_orthoMatrix; // ์ง๊ต ํ๋ ฌ
D3D11_VIEWPORT m_viewport; // ๋ทฐํฌํธ ์ค์ (๊ตฌ์กฐ์ฒด)
};
#endif
D3DClass์ ํด๋์ค ์ ์๋ ์ต๋ํ ๊ฐ๋จํ๊ฒ ์์ฑ๋์๋ค.
- ๊ธฐ๋ณธ ์์ฑ์, ๋ณต์ฌ ์์ฑ์, ์๋ฉธ์
์ด๋ฒ ํํ ๋ฆฌ์ผ์์๋ Initialize
, Shutdown
ํจ์๋ฅผ ์ค์ ์ผ๋ก ํ๋ค.
๋ทฐ ํ๋ ฌ(View Matrix)๋ ์นด๋ฉ๋ผ ํด๋์ค์ ํฌํจ๋ ์์ ์ด๋ฏ๋ก, ํด๋น ํด๋์ค์ ๋ณ์๋ฅผ ์์ฑํ์ง ์์๋ค.
D3dclass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
D3DClass::D3DClass()
{
m_swapChain = 0;
m_device = 0;
m_deviceContext = 0;
m_renderTargetView = 0;
m_depthStencilBuffer = 0;
m_depthStencilState = 0;
m_depthStencilView = 0;
m_rasterState = 0;
}
D3DClass::D3DClass(const D3DClass&)
{
}
D3DClass::~D3DClass()
{
}
์์ฑ์์์ ๋ชจ๋ ๋ฉค๋ฒ ํฌ์ธํฐ ๋ณ์๋ฅผ null
์ผ๋ก ์ด๊ธฐํํ๋ค.
Initialize()
๋งค๊ฐ ๋ณ์
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenDepth, float screenNear)
{
HRESULT result;
IDXGIFactory* factory;
IDXGIAdapter* adapter;
IDXGIOutput* adapterOutput;
unsigned int numModes, i, numerator, denominator;
unsigned long long stringLength;
DXGI_MODE_DESC* displayModeList;
DXGI_ADAPTER_DESC adapterDesc;
int error;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
D3D_FEATURE_LEVEL featureLevel;
ID3D11Texture2D* backBufferPtr;
D3D11_TEXTURE2D_DESC depthBufferDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
D3D11_RASTERIZER_DESC rasterDesc;
float fieldOfView, screenAspect;
// vsync ์ค์ ์ ์ฅ
m_vsync_enabled = vsync;
D3DClass::Initialize: DX11 ์ ์ฒด ์ค์
- ๋งค๊ฐ๋ณ์
ScreenWidth
: ์๋์ฐ ๋๋นScreenHeight
: ์๋์ฐ ๋์ดhwnd
: ์๋์ฐ ํธ๋ค(D3D๊ฐ ์๋์ฐ์ ์ ๊ทผ)fullscreen
: ์ ์ฒด ํ๋ฉด ๋ชจ๋screenDepth
: 3Dํ๋ฉด์ ๊น์ด(์๊ทผ ํฌ์) ์ค์ . Z-FarscreenNear
: 3Dํ๋ฉด์ ๊น์ด(์๊ทผ ํฌ์) ์ค์ . Z-Nearvsync
: ์์ง ๋๊ธฐํ ์ค์ (t
: ์ฃผ์ฌ์จ์ ๋ง์ถฐ ๋ ๋๋ง,f
: ์ต๋ํ ๋น ๋ฅด๊ฒ ๋ ๋๋ง)
๋ชจ๋ํฐ ์ฃผ์ฌ์จ ํ์ธ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// DX ๊ทธ๋ํฝ ์ธํฐํ์ด์ค ํฉํ ๋ฆฌ ์์ฑ
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if(FAILED(result))
{
return false;
}
// ํฉํ ๋ฆฌ๋ฅผ ์ฌ์ฉํด ๊ธฐ๋ณธ ๊ทธ๋ํฝ ์ธํฐํ์ด์ค(๋น๋์ค ์นด๋) ์ด๋ํฐ ์์ฑ
result = factory->EnumAdapters(0, &adapter);
if(FAILED(result))
{
return false;
}
// ๊ธฐ๋ณธ ์ดํญํฐ ์ถ๋ ฅ(๋ชจ๋ํฐ) ์ด๊ฑฐ
result = adapter->EnumOutputs(0, &adapterOutput);
if(FAILED(result))
{
return false;
}
// ์ด๋ํฐ ์ถ๋ ฅ(๋ชจ๋ํฐ)์ ๋ํด DXGI_FORMAT_R8G8B8A8_UNORM ๋์คํ๋ ์ด ํฌ๋งท์ ์ง์ํ๋ ๋ชจ๋ ๊ฐ์ ๊ฐ์ ธ์ด
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if(FAILED(result))
{
return false;
}
// ํ์ฌ ๋ชจ๋ํฐ, ๋น๋์ค ์นด๋ ์กฐํฉ์ ๋ํด ๊ฐ๋ฅํ ๋ชจ๋ ๋์คํ๋ ์ด ๋ชจ๋๋ฅผ ์ ์ฅํ ๋ฆฌ์คํธ
displayModeList = new DXGI_MODE_DESC[numModes];
if(!displayModeList)
{
return false;
}
// ๋์คํ๋ ์ด ๋ชจ๋ ๊ตฌ์กฐ์ฒด์ ์ ๋ณด ์ ์ฅ
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if(FAILED(result))
{
return false;
}
// ๋ชจ๋ ๋์คํ๋ ์ด ๋ชจ๋ ๊ฒ์ฌ -> ํ๋ฉด ๋๋น์ ๋์ด๊ฐ ์ผ์นํ๋ ๋ชจ๋ ํ์
// ์ผ์นํ๋ ๋ชจ๋๋ฅผ ์ฐพ์ผ๋ฉด -> ๋ชจ๋ํฐ ์ฃผ์ฌ์จ์ ๋ถ์(Numerator)์ ๋ถ๋ชจ(Denominator)๋ฅผ ์ ์ฅ
for(i=0; i<numModes; i++)
{
if(displayModeList[i].Width == (unsigned int)screenWidth)
{
if(displayModeList[i].Height == (unsigned int)screenHeight)
{
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
๋น๋์ค ์นด๋/์ฃผ์ฌ์จ ์ ๋ณด
D3D ์ด๊ธฐํ ์ , ๋น๋์ค ์นด๋ ๋ฐ ๋ชจ๋ํฐ์ ์ฃผ์ฌ์จ ์ ๋ณด ์์ฒญ
์? ์ปดํจํฐ๋ง๋ค ์ฃผ์ฌ์จ์ด ๋ค๋ฅด๋ฏ๋ก, ์ด๋ฅผ ์ฟผ๋ฆฌํด ํ์ธํด์ผ ํ๋ค!
- ๋ถ์, ๋ถ๋ชจ๊ฐ์ ์ฟผ๋ฆฌํ ํ, DX ์ค์ ์์ ํด๋น ๊ฐ ์ ๋ฌ
- DX๋ ๋ถ์/๋ถ๋ชจ๊ฐ์ ํ ๋๋ก ์ ํํ ์ฃผ์ฌ์จ์ ๊ณ์ฐ
๐ฑ ๋ง์ฝ, ์ฃผ์ฌ์จ ๊ณ์ฐ ๊ณผ์ ์ ์๋ตํ๋ค๋ฉด(๊ธฐ๋ณธ๊ฐ ์ค์ )?
=> DX๊ฐ ๋ฒํผ ํ๋ฆฝ ๋์ blit์ ์ํํด ๋ ๋๋ง ์ฑ๋ฅ ์ ํ, ๋๋ฒ๊ทธ ์ถ๋ ฅ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์๋ค.
- ๋ถ์, ๋ถ๋ชจ๊ฐ์ ์ฟผ๋ฆฌํ ํ, DX ์ค์ ์์ ํด๋น ๊ฐ ์ ๋ฌ
๐ก Buffer filp VS blit
buffer filp(
DXGI_SWAP_EFFECT_FLIP_DISCARD
): ํ๋ก ํธ ๋ฒํผ์ ๋ฐฑ ๋ฒํผ ์ค์์นญblit(
DXGI_SWAP_EFFECT_DISCARD
): ํ๋ ์์ ์ง์ ๋ณต์ฌํด ํ๋ฉด์ ๊ทธ๋ฆผBitBlit ๋ชจ๋ธ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ง์ ๋ณต์ฌ์ ํ๋ฉด์ ๊ทธ๋ฆฌ๊ธฐ ๋๋ฌธ์ GPU ์ฐ์ฐ์ด ๋ถ๊ณผ๋๋ค.
GPU ์ฐ์ฐ ๋ถ๋ด์ ๋ฎ์ถ๊ธฐ ์ํด UWP ์ ํ๋ฆฌ์ผ์ด์ ์ Flip ์ค์์ ์ฌ์ฉํ๋๋ก ์ค์ ๋์ด ์๋ค.
DXGI_SWAP_EFFECT_DISCARD
๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ, UWP ํ๊ฒฝ์ผ๋ก ํฌํ ํ๋ฉด Win32 ํ๊ฒฝ๊ณผ ๋ค๋ฅด๊ฒ ๋์ํ ์ ์๋ค. => GPU ์ฑ๋ฅ ์ ํ๋ฅผ ์ผ์ผํฌ ์ ์๋ค.
์ฐธ๊ณ :
๋น๋์ค ์นด๋ ์ ๋ณด
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// ์ด๋ํฐ(๋น๋์ค ์นด๋) ์ค๋ช
์ ๋ณด ๊ฐ์ ธ์ด
result = adapter->GetDesc(&adapterDesc);
if(FAILED(result))
{
return false;
}
// ๋น๋์ค ์นด๋ ๋ฉ๋ชจ๋ฆฌ ์ ์ฅ(๋จ์: megabytes)
m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
// ๋น๋์ค ์นด๋ ์ด๋ฆ์ char ๋ฐฐ์ด๋ก ๋ณํ ํ ์ ์ฅ
error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
if(error != 0)
{
return false;
}
์ด๋ํฐ๋ฅผ ์ฌ์ฉํด ๋น๋์ค ๋ฉ๋ชจ๋ฆฌ ํฌ๊ธฐ(m_videoCardMemory
)์ ์ด๋ฆ(m_videoCardDescription
)์ ๊ฐ์ ธ์ฌ ์ ์๋ค.
์ฌ์ฉํ ๊ตฌ์กฐ์ฒด์ ์ธํฐํ์ด์ค ํด์
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// ๋์คํ๋ ์ด ๋ชจ๋ ๋ฆฌ์คํธ ํด์
delete [] displayModeList;
displayModeList = 0;
// ์ด๋ํฐ ์ถ๋ ฅ ํด์
adapterOutput->Release();
adapterOutput = 0;
// ์ด๋ํฐ ํด์
adapter->Release();
adapter = 0;
// DXGI ํฉํ ๋ฆฌ ํด์
factory->Release();
factory = 0;
์ฃผ์ฌ์จ ๋ถ์, ๋ถ๋ชจ ๊ฐ๊ณผ ๋น๋์ค์นด๋ ์ ๋ณด๋ฅผ ์ ์ฅํ์ผ๋ฏ๋ก, ์ ๋ณด๋ฅผ ์ป๊ธฐ ์ํด ์ฌ์ฉํ๋ ๊ตฌ์กฐ์ฒด์ ์ธํฐํ์ด์ค๋ฅผ ํด์ ํ๋ค.
์ค์ ์ฒด์ธ ์ด๊ธฐํ
1
2
3
4
5
6
7
8
9
10
11
12
// ์ค์ ์ฒด์ธ Desc ์ด๊ธฐํ
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
// ์ฑ๊ธ ๋ฐฑ ๋ฒํผ ์ค์
swapChainDesc.BufferCount = 1;
// ๋ฐฑ ๋ฒํผ์ ๋๋น ๋ฐ ๋์ด ์ค์
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
// ๋ฐฑ ๋ฒํผ์ ์์ ํ์์ ์ผ๋ฐ 32-bit์ผ๋ก ์ง์
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
SwapChainDesc
SwapChain
: ํ๋ก ํธ ๋ฒํผ - ๋ฐฑ ๋ฒํผ๋ฅผ ํฌํจํ๋ ๊ตฌ์กฐ- ๋ฐฑ ๋ฒํผ์์ ๋ ๋๋งํ ํ ํ๋ก ํธ ๋ฒํผ๋ก ์ค์ํด ํ๋ฉด์ ํ์
์ฃผ์ฌ์จ(Refresh rate) ์ค์
1
2
3
4
5
6
7
8
9
10
11
// ๋ฐฑ ๋ฒํผ์ ์ฃผ์ฌ์จ ์ค์
if (m_vsync_enabled)
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
}
else
{
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
}
์ฃผ์ฌ์จ: ๋ฐฑ ๋ฒํผ๋ฅผ ํ๋ก ํธ ๋ฒํผ๋ก ์ด๋น ๋ช ๋ฒ ์ ํํ๋์ง ๋ํ๋ด๋ ๋น์จ
vsync == true
- ์ฃผ์ฌ์จ์ด ์์คํ ์ค์ ์ ๋ฐ๋ฆ (e.g.) 60Hz)
vsync == false
- DX๊ฐ ์ฃผ์ฌ์จ์ ๋ฌด์ํ๊ณ ์ต๋ํ ๋น ๋ฅธ ์๋๋ก ํ๋ฉด ๊ฐฑ์
- ๋จ, ์๊ฐ์ ์ํฐํฉํธ๊ฐ ๋ฐ์ํ ์ ์์ (e.g. Screen Tearing)
๐ก Hz VS FPS
- ์ฃผ์ฌ์จ(Hz): ๋ชจ๋ํฐ๊ฐ 1์ด๋ง๋ค ํ๋ฉด์ ์์ฑํ๋ ์ด๋ฏธ์ง ๊ฐ์
- ํ๋ ์ ๋ ์ดํธ(FPS): GPU๊ฐ 1์ด๋ง๋ค ์์ฑํ๋ ํ๋ ์ ๊ฐ์
์ค์ ์ฒด์ธ ์ค์
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// ๋ฐฑ ๋ฒํผ์ ์ฌ์ฉ ๋ชฉ์ ์ค์
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // ๋ ๋ ํ๊ฒ ์ถ๋ ฅ(GPU๊ฐ ๋ฐฑ ๋ฒํผ์ ๊ทธ๋ฆฌ๊ธฐ ๊ฐ๋ฅ)
// ๋ ๋๋งํ ์๋์ฐ ํธ๋ค ์ค์
swapChainDesc.OutputWindow = hwnd;
// ๋ฉํฐ ์ํ๋ง ๋นํ์ฑํ
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
// Fullscreen | Windowed ์ค์
if (fullscreen)
{
swapChainDesc.Windowed = false;
}
else
{
swapChainDesc.Windowed = true;
}
// scan line ์์ ๋ฐ ์ค์ผ์ผ๋ง์ ๋ฏธ์ง์ ์ผ๋ก ์ค์
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
// ์ฌ์ฉ ํ ๋ฐฑ ๋ฒํผ ๋ด์ฉ ์ญ์
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
// ๊ณ ๊ธ ํ๋๊ทธ ์ค์ x
swapChainDesc.Flags = 0;
DXGI_USAGE: ๋ฐฑ ๋ฒํผ์ ์ฌ์ฉ ๋ชฉ์ ์ค์
DXGI_USAGE_BACK_BUFFER
: ๋ฐฑ ๋ฒํผ ์ฌ์ฉ- ์ค์ ์ฒด์ธ์ ์ฌ์ฉํ ๋ ํด๋น ํ๋๊ทธ๋ฅผ ์ ๋ฌํ ํ์๋ ์์ง๋ง, ๋ฆฌ์์ค๊ฐ ์ค์ ์ฒด์ธ์ ์ํด ์๋์ง ํ์ธํ ์ ์๋ค!
DXGI_USAGE_DISCARD_ON_PRESENT
: ์ ํ๋ ์์ ๊ทธ๋ฆฐ ํ ๋ฐฑ ๋ฒํผ๋ ์๋ ์ญ์ DXGI_USAGE_READ_ONLY
: ๋ฆฌ์์ค๋ฅผ ์ฝ๊ธฐ ์ ์ฉ ๋ฆฌ์์ค๋ก ์ฌ์ฉDXGI_USAGE_RENDER_TARGET_OUTPUT
: GPU๊ฐ ๋ ๋๋ง ํ๊ฒ/๋ฆฌ์์ค๋ฅผ ์ถ๋ ฅ (ํ๋ฉด์ ํ์ํ ๋ฐฑ ๋ฒํผ)DXGI_USAGE_SHADER_INPUT
: ์ ฐ์ด๋์์ ์ฌ์ฉํ๋ ํ ์ค์ฒ, ๋ฒํผ ๋ฐ์ดํฐDXGI_USAGE_SHARED
: ๋ ๋ ํ๊ฒ์ด๋ ๋ฆฌ์์ค ๊ณต์DXGI_USAGE_UNORDERED_ACCESS
: GPU๋ก ์ฐ์ฐํ๊ธฐ ์ํด ์ ๊ทผ ๊ฐ๋ฅํ ๋ฆฌ์์ค- GPU ๋ณ๋ ฌ ์ฐ์ฐ -> ์์๋ฅผ ๊ณ ๋ คํ์ง ์๊ณ ๋น ๋ฅด๊ฒ ๋ฐ์ดํฐ ์ฝ๊ณ ์ธ ์ ์๋๋ก!
Feature Level
1
2
// DX11์ Feature Level๋ก ์ง์
featureLevel = D3D_FEATURE_LEVEL_11_0;
Feature Level
- DirectX์์ ์ฌ์ฉํ ๋ฒ์ ์ ํ
swap chain, D3D device ์์ฑ
1
2
3
4
5
6
7
8
// ์ค์ ์ฒด์ธ, D3D ๋๋ฐ์ด์ค, D3D ๋๋ฐ์ด์ค ์ปจํ
์คํธ ์์ฑ
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0,
&featureLevel, 1, D3D11_SDK_VERSION,
&swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
if (FAILED(result))
{
return false;
}
์์ ์ค์ ์ฒด์ธ๊ณผ Feature Level์ ์ค์ ์ ์๋ฃํ๋ค. ์ค์ ์ฒด์ธ๊ณผ Direct3D ๋๋ฐ์ด์ค, ๋๋ฐ์ด์ค ์ปจํ ์คํธ๋ฅผ ๋ง๋ค ์ ์๋ค.
Direct3D ๋๋ฐ์ด์ค, ๋๋ฐ์ด์ค ์ปจํ ์คํธ๋ ๋ชจ๋ Direct3D ํจ์์ ๋ํ ์ธํฐํ์ด์ค๊ฐ ๋๋ค. ๋งค์ฐ ์ค์ํ ๊ธฐ๋ฅ์!
๊ฑฐ์ ๋ชจ๋ ๊ทธ๋ํฝ ์ฝ๋ฉ ๊ณผ์ ์์ ๋๋ฐ์ด์ค์ ๋๋ฐ์ด์ค ์ปจํ ์คํธ๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋ค.
DX11 ์ด์ ๋ฒ์ ์ ์ฌ์ฉํ๋ค๋ฉด, Direct3D ๋๋ฐ์ด์ค ์ปจํ ์คํธ๋ ์์ํ ๊ฒ์ด๋ค. ์ด์ ๋ฒ์ ์ ๊ธฐ์กด ๊ธฐ๋ฅ์ ๋๋ฐ์ด์ค์ ๋๋ฐ์ด์ค ์ปจํ ์คํธ๋ก ๋ถ๋ฆฌํ๊ธฐ ๋๋ฌธ.
๋ ๊ธฐ๋ฅ์ ํจ๊ป ์ฌ์ฉํด์ผ ํ๋ค.
DirectX 11 ๊ทธ๋ํฝ ์นด๋๊ฐ ์์ ๊ฒฝ์ฐ, ํจ์๋ฅผ ํธ์ถํด๋ ๋๋ฐ์ด์ค์ ๋๋ฐ์ด์ค ์ปจํ ์คํธ๋ฅผ ๋ง๋ค ์ ์๋ค.
๊ทธ๋ํฝ ์นด๋๊ฐ ์๋ค๋ฉด, D3D_DRIVER_TYPE_HARDWARE
๋ฅผ D3D_DRIVER_TYPE_REFERENCE
๋ก ๋ฐ๊พธ์ด CPU๊ฐ ๋์ ๋ ๋๋งํ๋๋ก ์ค์ ํ ์ ์๋ค. (๋จ, ์ฑ๋ฅ์ด 1/1000 ์ ๋๋ค.)
๋๋ฐ์ด์ค๋ฅผ ์์ฑํ ๋, ์ฃผ ๊ทธ๋ํฝ ์นด๋๊ฐ DirectX11์ ์ง์ํ์ง ์๋๋ค๋ฉด ์คํจํ ์ ์๋ค.
์ฃผ ๊ทธ๋ํฝ ์นด๋๊ฐDirectX10, ๋ณด์กฐ ๊ทธ๋ํฝ ์นด๋๊ฐ DirectX11์ธ ๊ฒฝ์ฐ
์ผ๋ถ ํ์ด๋ธ๋ฆฌ๋ ๊ทธ๋ํฝ ์นด๋(์ฃผ๋ฅผ ์ ์ ๋ ฅ Intel, ๋ณด์กฐ๋ฅผ ๊ณ ์ ๋ ฅ Nvidia๋ก ์ฌ์ฉํ ๊ฒฝ์ฐ)
์ด๋ฅผ ํด๊ฒฐํ๋ ค๋ฉด ๊ธฐ๋ณธ ๋๋ฐ์ด์ค๋ฅผ ์ฌ์ฉํ์ง ์๊ณ , ๋ชจ๋ ๊ทธ๋ํฝ ์นด๋๋ฅผ ๋์ดํ ํ, ์ฌ์ฉ์๊ฐ ์ง์ GPU๋ฅผ ์ ํํด์ผ ํ๋ค.
Back Buffer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// ๋ฐฑ ๋ฒํผ ํฌ์ธํฐ ๊ฐ์ ธ์ด
result = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
if (FAILED(result))
{
return false;
}
// ๋ฐฑ ๋ฒํผ๋ฅผ ๋ ๋ ํ๊ฒ ๋ทฐ๋ก ์ค์
result = m_device->CreateRenderTargetView(backBufferPtr, NULL, &m_renderTargetView);
if (FAILED(result))
{
return false;
}
// ๋ฐฑ ๋ฒํผ ํฌ์ธํฐ ๋ณ์๊ฐ ๋์ด์ ํ์ํ์ง ์์ผ๋ฏ๋ก ํด์
backBufferPtr->Release();
backBufferPtr = 0;
์ฐจํ ๋ฒํผ ์ค์์ ์ํด, ๋ฐฑ ๋ฒํผ์ ํฌ์ธํฐ๋ฅผ ์ค์ ์ฒด์ธ์ ์ฐ๊ฒฐํด์ผ ํ๋ค.
CreateRenderTargetView
ํจ์๋ฅผ ์ฌ์ฉํด ๋ฐฑ ๋ฒํผ๋ฅผ ๋ ๋ ํ๊ฒ์ผ๋ก ์ค์ - ๋ ๋ ํ๊ฒ ๋ทฐ๊ฐ ์์ฑ๋๋ฉด ๋ฐฑ ๋ฒํผ ํฌ์ธํฐ๋ฅผ ์ง์ ์ฌ์ฉํ์ง ์์ผ๋ฏ๋ก, ํฌ์ธํฐ ๋ณ์ ํด์
Release()
ํธ์ถ ์ DirectX ๋ด๋ถ์์ ์ฐธ์กฐ ์นด์ดํธ ๊ฐ์(๋ฉ๋ชจ๋ฆฌ ์ ๋ฆฌ)
๐ฑ ๋ ๋ ํ๊ฒ ๋ทฐ (Render Target View)
- ๋ฐฑ ๋ฒํผ๋ ๋ฉ๋ชจ๋ฆฌ์๋ง ์กด์ฌํ๋ฏ๋ก, ๋ ๋๋ง ํ์ดํ๋ผ์ธ์์ ์ฌ์ฉํ ์ ์์
- ๋ ๋๋ง์ ์ํด ๋ฐฑ ๋ฒํผ๋ฅผ ๋ ๋ ํ๊ฒ ๋ทฐ๋ก ์ค์ (
CreateRenderTargetView
)
- ๋ ๋ ํ๊ฒ(๋ ๋๋งํ ๊ณต๊ฐ)์ GPU๊ฐ ์ ๊ทผํ ์ ์๊ฒ ๋๋ค!
- Direct3D์์ ๋ ๋ ํ๊ฒ ๋ทฐ๋ฅผ ํตํด ๊ทธ๋ํฝ ์์ ์ด ๊ฐ๋ฅํด์ง
- RTV๋ OM ์คํ ์ด์ง์์ ์ฌ์ฉ๋จ
OMSetRenderTargets
๋ก ์ ์ฉํด์ผ ์ค์ง์ ์ธ ๋ ๋๋ง์ด ์ด๋ฃจ์ด์ง
Depth Buffer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Depth Buffer Desc ์ด๊ธฐํ
ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
// Depth Buffer Desc ์ค์
depthBufferDesc.Width = screenWidth;
depthBufferDesc.Height = screenHeight;
depthBufferDesc.MipLevels = 1;
depthBufferDesc.ArraySize = 1;
depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthBufferDesc.SampleDesc.Count = 1;
depthBufferDesc.SampleDesc.Quality = 0;
depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthBufferDesc.CPUAccessFlags = 0;
depthBufferDesc.MiscFlags = 0;
// ์ด๊ธฐํํ Desc๋ฅผ ์ฌ์ฉํด ๊น์ด ๋ฒํผ ์์ฑ
result = m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
if (FAILED(result))
{
return false;
}
Depth Buffer (๊น์ด ๋ฒํผ, Z-๋ฒํผ)
- ํด๋ฆฌ๊ณค์ด 3D ํ๊ฒฝ์์ ์ ๋๋ก ๋ ๋๋ง๋ ์ ์๋๋ก ๊น์ด ๋ฒํผ ์์ฑ
- ๊น์ด ๋ฒํผ์ ์คํ
์ค ๋ฒํผ ์ถ๊ฐ
- ๋ชจ์ ๋ธ๋ฌ, Volumetric Shadows ๊ฐ์ ๊ทธ๋ํฝ ํจ๊ณผ ๊ตฌํ ๊ฐ๋ฅ
์ ๊น์ด ๋ฒํผ๋ฅผ ์์ฑํ๋๋ฐ CreateTexture2D
ํจ์๋ฅผ ์ฌ์ฉํ์๊น?
- ๊น์ด ๋ฒํผ๋ 2D ํ
์ค์ฒ๋ก ์ด๋ฃจ์ด์ง
- ํด๋ฆฌ๊ณค์ด ์ ๋ ฌ๋๊ณ ๋์คํฐํ๋ ํ, 2D๋ก ๋งคํ๋์ด ํ๋ฉด์ ์ถ๋ ฅ๋๊ธฐ ๋๋ฌธ!
Depth Stencil ์ค์
Depth Stencil Desc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Depth Stencil Desc ์ด๊ธฐํ
ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));
// Depth Stencil Desc ์ค์
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
depthStencilDesc.StencilEnable = true;
depthStencilDesc.StencilReadMask = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;
// ํฝ์
์ด Front-Facing์ธ ๊ฒฝ์ฐ ์คํ
์ค ์ฐ์ฐ
depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
// ํฝ์
์ด Back-Facing์ธ ๊ฒฝ์ฐ ์คํ
์ค ์ฐ์ฐ
depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
๊น์ด ์คํ ์ค ์ค๋ช (Depth Stencil Desc)์ ์ค์ ํ๋ค.
D3D๊ฐ ๊ฐ ํฝ์ ์ ๋ํด ์ด๋ค ์ ํ์ ๊น์ด ํ ์คํธ๋ฅผ ์ํํ ์ง ์ ์ดํ ์ ์๋ค.
Depth Stencil State
1
2
3
4
5
6
7
8
9
// ๊น์ด ์คํ
์ค ์ํ ์์ฑ (๋๋ฐ์ด์ค ์ฌ์ฉ)
result = m_device->CreateDepthStencilState(&depthStencilDesc, &m_depthStencilState);
if (FAILED(result))
{
return false;
}
// ๊น์ด ์คํ
์ค ์ํ ์ ์ฉ (๋๋ฐ์ด์ค ์ปจํ
์คํธ ์ฌ์ฉ)
m_deviceContext->OMSetDepthStencilState(m_depthStencilState, 1);
Desc๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊น์ด ์คํ ์ค ์ํ(Depth Stencil State) ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค.
์์ฑ๋ ๊น์ด ์คํ ์ค ์ํ๋ฅผ OM ์คํ ์ด์ง์ ์ ์ฉ์ํฌ ์ ์๋ค. ์ด๋, ๋๋ฐ์ด์ค ์ปจํ ์คํธ๋ฅผ ์ฌ์ฉํด ์ค์ ํ๋ค.
๐ฑ ๊น์ด ์คํ ์ค ์ํ
desc
๋ก ์ ์ฅํ ์ค์ ๊ฐ์ ์ํ ๊ฐ์ฒด๋ก ๋ง๋ค์ด ๊น์ด-์คํ
์ค ํ
์คํธ๋ฅผ ์ํํ ์ ์๋๋ก ํ๋ค.
๐ฑ ์ ๋๋ฐ์ด์ค ์ปจํ ์คํธ ์ฌ์ฉ?
๋ ๋๋ง ์ํ๋ฅผ ๋ณ๊ฒฝํ๊ฑฐ๋, ์ด๋ ํ ๊ทธ๋ํฝ ๋ช ๋ น์ ์คํํ๋ ค๋ฉด ๋๋ฐ์ด์ค ์ปจํ ์คํธ๋ฅผ ์ฌ์ฉํด์ผ ํ๊ธฐ ๋๋ฌธ!
cf) ๊น์ด ์คํ ์ค ์ํ๋ฅผ ์์ฑํ ๋๋ ๋๋ฐ์ด์ค์ ๋ด์ฅ ํจ์๋ฅผ ํธ์ถํ๋ค.
Depth Stencil View
1
2
3
4
5
6
7
8
9
10
// Depth Stencil View ์ด๊ธฐํ
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
// Depth Stencil View Desc ์ค์
depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilViewDesc.Texture2D.MipSlice = 0;
// Depth Stencil View Desc ์์ฑ
result = m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
๊น์ด ์คํ ์ค ๋ทฐ ์ค๋ช (Depth Stencil View Desc)๋ฅผ ์ค์ ํ๋ค.
D3D๋ Depth Stencil Buffer๋ฅผ ๋ฐ๋ก ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์, ๊น์ด ์คํ ์ค ๋ทฐ๋ฅผ ๋ง๋ค์ด D3D๊ฐ ๊น์ด ๋ฐ ์คํ ์ค ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์๋๋ก ํ๋ค!
1
2
// ๋ ๋ ํ๊ฒ ๋ทฐ์ ๊น์ด ์คํ
์ค ๋ฒํผ๋ฅผ Output Merger ํ์ดํ๋ผ์ธ์ ๋ฐ์ธ๋ฉ
m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
Depth Stencil View๊ฐ ์์ฑ๋์์ผ๋ฏ๋ก, OMSetRenderTargets
๋ฅผ ํธ์ถํ ์ ์๋ค.
- ๋ ๋ ํ๊ฒ ๋ทฐ์ ๊น์ด-์คํ ์ค ๋ฒํผ๋ฅผ ์ถ๋ ฅ ๋ ๋ ํ์ดํ๋ผ์ธ์ ๋ฐ์ธ๋ฉ
- ํ์ดํ๋ผ์ธ์ด ๋ ๋๋งํ ๊ทธ๋ํฝ์ด ์ด์ ์ ์์ฑํ ๋ฐฑ ๋ฒํผ์ ๊ทธ๋ ค์ง
- ๊ทธ๋ํฝ์ด ๋ฐฑ ๋ฒํผ์ ๊ธฐ๋ก๋๋ฉด ํ๋ก ํธ ๋ฒํผ๋ก ์ค์ => ์ฌ์ฉ์ ํ๋ฉด์ ๊ทธ๋ํฝ ์ถ๋ ฅ!
๐ฑ ํ๋ฆ ์ดํดํด๋ณด์!
D3D11_DEPTH_STENCIL_DESC
๊ตฌ์กฐ์ฒด๋ฅผ ์ฌ์ฉํด ๊น์ด/์คํ ์ค ํ ์คํธ ์ค์
- ๊น์ด ๋น๊ต ํจ์, ์คํ ์ค ์ฐ์ฐ ๋ฑ ์ ์
์์ฑํ
D3D11DepthStencilState
๊ฐ์ฒด๋ฅผ OM stage์ ์ค์ -> ํ ์คํธ ๊ท์น์ด ํ์ฑํ๋จ
- ๊ฐ์ฒด ์์ฑ:
Device->CreateDepthStencilState()
- ๊ท์น ์ ์ฉ:
DeviceContext->OMSetDepthStencilState()
D3D11_DEPTH_STENCIL_VIEW_DESC
๋ฅผ ์ค์ ํด ๊น์ด/์คํ ์ค ๋ฒํผ ๋ทฐ ์ ์
- ํ ์ค์ฒ(๊น์ด-์คํ ์ค ๋ฒํผ)์ ํน์ ๋ฆฌ์์ค์ ์ ๊ทผํ ์ ์๋๋ก ํจ
ID3D11DepthStencilView
๊ฐ์ฒด๋ฅผ OM stage์ ์ฐ๊ฒฐํด ํ ์ค์ฒ ํ์ฉ(์์ ์ ์ฉํ ํ ์คํธ ๊ท์น์ด ์ํ๋จ)
๊ฐ์ฒด ์์ฑ:
device->CreateDepthStencilView()
๊น์ด/์คํ ์ค ๋ทฐ, ๋ ๋ ํ๊ฒ ๋ทฐ ์ ์ฉ:
deviceContext->OMSetRenderTargets()
Rasterizer State
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Raster Desc์ ์ค์ ํด ํด๋ฆฌ๊ณค์ด ์ด๋ป๊ฒ ๊ทธ๋ ค์ง์ง ๊ฒฐ์
rasterDesc.AntialiasedLineEnable = false;
rasterDesc.CullMode = D3D11_CULL_BACK;
rasterDesc.DepthBias = 0;
rasterDesc.DepthBiasClamp = 0.0f;
rasterDesc.DepthClipEnable = true;
rasterDesc.FillMode = D3D11_FILL_SOLID;
rasterDesc.FrontCounterClockwise = false;
rasterDesc.MultisampleEnable = false;
rasterDesc.ScissorEnable = false;
rasterDesc.SlopeScaledDepthBias = 0.0f;
// desc๋ฅผ ๊ธฐ๋ฐ์ผ๋ก Rasterizer state ์์ฑ
result = m_device->CreateRasterizerState(&rasterDesc, &m_rasterState);
if (FAILED(result))
{
return false;
}
// Rasterizer ์ํ ์ค์
m_deviceContext->RSSetState(m_rasterState);
๋ ๋ ํ๊ฒ์ด ์ค์ ๋์์ผ๋ฏ๋ก, ์ฌ์ ๋์ฑ ์ปจํธ๋กค ํ ์ ์๋ ๋ช๊ฐ์ง ์ถ๊ฐ ๊ธฐ๋ฅ์ ์ค์ ํ ์ ์๋ค.
- ๋์คํฐ๋ผ์ด์ ์ํ(Rasterizer State) ์์ฑ
- ํด๋ฆฌ๊ณค์ด ๋ ๋๋ง๋๋ ๋ฐฉ์ ์ ์ด
- e.g. ์ฌ์ ์์ด์ดํ๋ ์ ๋ชจ๋๋ก ๋ ๋๋ง, DirectX๊ฐ ํด๋ฆฌ๊ณค์ ์๋ฉด๊ณผ ๋ท๋ฉด์ ๋ชจ๋ ๊ทธ๋ฆฌ๊ธฐ
- ๊ธฐ๋ณธ์ ์ผ๋ก DirectX๋ ์ผ๋ฐ์ ์ธ ๋์คํฐ๋ผ์ด์ ์ํ๊ฐ ์ค์ ๋์ด ์์
- ๋จ, ์ง์ ๋์คํฐ๋ผ์ด์ ์ํ๋ฅผ ์ค์ ํ์ง ์์ผ๋ฉด ์ ์ดํ ์ ์๋ค
Viewport ์ค์
1
2
3
4
5
6
7
8
9
10
// ๋ ๋๋ง์ ์ํด ๋ทฐํฌํธ ์ค์
m_viewport.Width = (float)screenWidth;
m_viewport.Height = (float)screenHeight;
m_viewport.MinDepth = 0.0f;
m_viewport.MaxDepth = 1.0f;
m_viewport.TopLeftX = 0.0f;
m_viewport.TopLeftY = 0.0f;
// ๋ทฐํฌํธ ์์ฑ
m_deviceContext->RSSetViewports(1, &m_viewport);
๋ทฐํฌํธ(Viewport) ์ค์
- Direct3D๊ฐ ํด๋ฆฝ ๊ณต๊ฐ ์ขํ๋ฅผ ๋ ๋ ํ๊ฒ ๊ณต๊ฐ์ ๋งคํ ๊ฐ๋ฅ
- ๋ทฐํฌํธ ํฌ๊ธฐ๋ฅผ ์ฐฝ ์ ์ฒด๋ก ์ค์
ํ๋ ฌ ์์ฑ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// ํฌ์ ํ๋ ฌ ์ค์
fieldOfView = 3.141592654f / 4.0f;
screenAspect = (float)screenWidth / (float)screenHeight;
// 3D ๋ ๋๋ง์ ์ํด ํฌ์ ํ๋ ฌ ์์ฑ (projection matrix)
m_projectionMatrix = XMMatrixPerspectiveFovLH(fieldOfView, screenAspect, screenNear, screenDepth);
// ์๋ ํ๋ ฌ ์์ฑ (world matrix)
m_worldMatrix = XMMatrixIdentity();
// 2D ๋ ๋๋ง์ ์ํด ์ง๊ต ํฌ์ ํ๋ ฌ ์์ฑ (orthographic projection matrix)
m_orthoMatrix = XMMatrixOrthographicLH((float)screenWidth, (float)screenHeight, screenNear, screenDepth);
return true;
}
ํฌ์ ํ๋ ฌ (projection matrix)
3D ์ฌ์ 2D ๋ทฐํฌํธ๋ก ๋ณํํ๋๋ฐ ์ฌ์ฉ
ํ๋ ฌ ์ฌ๋ณธ ์ ์ง(
m_projectionMatrix
)=> ๋ ๋๋งํ ์ฌ์ ์ ฐ์ด๋๋ก ์ ๋ฌํ ๋ ํ์ํ๊ธฐ ๋๋ฌธ!
XMMatrixPerspectiveFovLH
: ์ผ์ ์ขํ๊ณ์์ ์๊ทผ ํฌ์ ํ๋ ฌ ์์ฑ(perspective projection matrix)
- ์๊ทผ๊ฐ ์ ์ง => ๊ฐ๊น์ด ๊ฐ์ฒด๋ฅผ ํฌ๊ฒ, ๋จผ ๊ฐ์ฒด๋ฅผ ์๊ฒ ๋ณด์ด๊ฒ ํจ
์๋ ํ๋ ฌ (world matrix)
- ๊ฐ์ฒด์ ์ ์ ์ 3D ์ฌ์์์ ์ ์ ์ผ๋ก ๋ณํํจ
- 3D ๊ณต๊ฐ์์ ๊ฐ์ฒด๋ฅผ ํ์ , ์ด๋, ํฌ๊ธฐ ์กฐ์ ํ๋ ๋ฐ์๋ ์ฌ์ฉ๋๋ค!
- ์ด๊ธฐ ๋จ๊ณ์์๋ ๋จ์ ํ๋ ฌ๋ก ์ค์
- ๋ ๋๋ง์ ์ํด ์
ฐ์ด๋์ ์ ๋ฌํ ์ ์๋๋ก ์ฌ๋ณธ ์ ์ง(
m_worldMatrix
)
๋ทฐ ํ๋ ฌ (View matrix)
- ์ฌ์ ์ด๋ค ์์น์์ ๋ฐ๋ผ๋ณผ์ง ๊ณ์ฐ(์นด๋ฉ๋ผ ์ญํ )
- ๊ธฐ๋ณธ์ ์ผ๋ก๋
Initialize
ํจ์์์ ์์ฑํ๋, ์นด๋ฉ๋ผ ํด๋์ค์์ ๋ค๋ฃจ๋ ๊ฒ์ด ์ค์ ํ๋ก์ ํธ ๊ด๋ฆฌ์ ์ฉ์ดํจ! (ํนํ ์นด๋ฉ๋ผ ์ด๋, ํ์ ๊ธฐ๋ฅ์ ์ถ๊ฐํ ๊ฒฝ์ฐ)
์ง๊ต ํฌ์ ํ๋ ฌ (orthographic projection matrix)
- 2D UI ์์๋ฅผ ํ๋ฉด์ ๋ ๋๋งํ ๋ ์ฌ์ฉ
- 3D ๋ ๋๋ง์ ๊ฑฐ์น์ง ์๊ณ 2D ๊ทธ๋ํฝ์ ์ง์ ๋ ๋๋งํ ์ ์๋ค!
- 2D ๊ทธ๋ํฝ ๋ฐ ํฐํธ ๋ ๋๋ง์ ๋ค๋ฃฐ ๋ ์ฌ์ฉ๋จ
Shutdown()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
void D3DClass::Shutdown()
{
// D3D ์ข
๋ฃ ์ ์ ์๋์ฐ ๋ชจ๋๋ก ๋ณ๊ฒฝ(์์ธ ๋ฐฉ์ง)
if (m_swapChain)
{
m_swapChain->SetFullscreenState(false, NULL);
}
if (m_rasterState)
{
m_rasterState->Release();
m_rasterState = 0;
}
if (m_depthStencilView)
{
m_depthStencilView->Release();
m_depthStencilView = 0;
}
if (m_depthStencilState)
{
m_depthStencilState->Release();
m_depthStencilState = 0;
}
if (m_depthStencilBuffer)
{
m_depthStencilBuffer->Release();
m_depthStencilBuffer = 0;
}
if (m_renderTargetView)
{
m_renderTargetView->Release();
m_renderTargetView = 0;
}
if (m_deviceContext)
{
m_deviceContext->Release();
m_deviceContext = 0;
}
if (m_device)
{
m_device->Release();
m_device = 0;
}
if (m_swapChain)
{
m_swapChain->Release();
m_swapChain = 0;
}
return;
}
D3DClass::Shutdown()
Initialize
ํจ์์์ ์ฌ์ฉ๋ ํฌ์ธํฐ ํด์ ๋ฐ ์ ๋ฆฌ- D3D ๊ฐ์ฒด๋ง๋ค
Release()
ํจ์๋ฅผ ํธ์ถํด ํด์ - ํฌ์ธํฐ๋ฅผ
0
(nullptr
)์ผ๋ก ์ค์
- D3D ๊ฐ์ฒด๋ง๋ค
- ์ฃผ์ํ ์
- ์ค์ ์ฒด์ธ์ ํด์ ํ๊ธฐ ์ ์ ์๋์ฐ ๋ชจ๋๋ก ์ ํํ ๊ฒ! (
SetFullscreenState(false, NULL)
) - ํ ์คํฌ๋ฆฐ ์ํ์์ ์ค์ ์ฒด์ธ์ ํด์ ํ๋ ค๊ณ ํ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ ์ ์์
- ์ค์ ์ฒด์ธ์ ํด์ ํ๊ธฐ ์ ์ ์๋์ฐ ๋ชจ๋๋ก ์ ํํ ๊ฒ! (
๐ฑ ํ ์คํฌ๋ฆฐ์์ ์ค์ ์ฒด์ธ์ ํด์ ํ๋ฉด ์ด๋ค ์์ธ๊ฐ ๋ฐ์ํ ๊น?
Windowed VS Full Screen
Windowed
: ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ์ด์ ์ฒด์ ๊ฐ ๋์คํ๋ ์ด ๊ณต์Full Screen
: ์ ํ๋ฆฌ์ผ์ด์ ์ด ์๋์ฐ๋ฅผ ๋ชจ๋ ์ฐจ์งํจ => ๋ค๋ฅธ ํ๋ก๊ทธ๋จ์ด๋ OS์ UI๊ฐ ์ ๊ทผx์ ์ฒดํ๋ฉด์ D3D๊ฐ ์ง์ ๋์คํ๋ ์ด ์ ์ด
- ๋ฐ๋ก ์ค์ ์ฒด์ธ์ ํด์ ํ๋ฉด ๋์คํ๋ ์ด ๋ชจ๋ ์ถฉ๋ ๋ฐ์
๋์คํ๋ ์ด ๋ชจ๋ ์ถฉ๋
- e.g.1) OS ์ถฉ๋: D3D๊ฐ ์ ์ฒดํ๋ฉด์์ ํด์๋ ๋ฑ์ ๋ณ๊ฒฝํ ํ, OS๊ฐ ์๋ ๋์คํ๋ ์ด ์ค์ ์ผ๋ก ๋ณต์ํ์ง ๋ชปํจ
- e.g.2) ํ๋ก๊ทธ๋จ ๊ฐ์ ์ข ๋ฃ: D3D๊ฐ ๋์คํ๋ ์ด๋ฅผ ์ฐจ์งํ๊ณ ์์ด, ๋ค๋ฅธ ํ๋ก๊ทธ๋จ์ด ๋์คํ๋ ์ด๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ๋ฉด ์ถฉ๋ํ ์ ์์
SetFullscreenState(false, NULL)
- ์ ์ฒดํ๋ฉด์์ ์ฌ์ฉํ๋ ํด์๋์ ์ฃผ์ฌ์จ ๋ณต์
- D3D ๋ ์ ํด์ => OS์ ๋ค๋ฅธ ํ๋ก๊ทธ๋จ์ด ๋์คํ๋ ์ด ์ ๊ทผ
๐ ์ฐธ๊ณ
Microsoft Learn - DXGI flip model
- ํ์คํฌ๋ฆฐ ๋ชจ๋ -> WindowManager๊ฐ ๊ด๋ฆฌ X, DXGI๊ฐ ์ง์ ๋์คํ๋ ์ด์ ํต์
- ํ๋ ์ ๋ฒํผ ์ถ๋ ฅ ๋ฐ VSync ์ค์ ์ DXGI๊ฐ ์ฒ๋ฆฌ
Microsoft Learn - IDXGISwapChain::SetFullscreenState method (dxgi.h)
- ๋์คํ๋ ์ด ๋ชจ๋ ์ถฉ๋์ด ๋ฐ์ํ์ง ์๋๋ก
SetFullscreenState(FALSE, NULL);
ํธ์ถ
- ์ ์ฒดํ๋ฉด => ์ ํ๋ฆฌ์ผ์ด์ ์ด ๋์คํ๋ ์ด์ ๋ํ ์ ๊ทผ ๊ถํ ์ ๋ ์ ์ผ๋ก ๊ฐ์ง
DXGI_ERROR_NOT_CURRENTLY_AVAILABLE
- OS์์ ํ์คํฌ๋ฆฐ๋ชจ๋๊ฐ ๋ค๋ฅธ ํ๋ก๊ทธ๋จ๊ณผ ์ถฉ๋
DXGI_STATUS_MODE_CHANGE_IN_PROGRESS
- ์ค์์ฒด์ธ์ ํด์ ํ์ง ์๊ณ ์ฐฝ-์ ์ฒดํ๋ฉด์ ๋ณ๊ฒฝํ๋ฉด ์์ธ ๋ฐ์
BeginScene, EndScene
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void D3DClass::BeginScene(float red, float green, float blue, float alpha)
{
float color[4];
// ๋ฐฑ ๋ฒํผ๋ฅผ ์ง์ธ ์์ ์ค์
color[0] = red;
color[1] = green;
color[2] = blue;
color[3] = alpha;
// ๋ฐฑ ๋ฒํผ ์ ๋ฆฌ
m_deviceContext->ClearRenderTargetView(m_renderTargetView, color);
// ๊น์ด ๋ฒํผ ์ ๋ฆฌ
m_deviceContext->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
return;
}
D3DClass::BeginScene
- ํ๋ ์์ ์์์์, ์ 3D๋ฅผ ๊ทธ๋ฆด ๋๋ง๋ค ํธ์ถ
- ๋ฒํผ๋ฅผ ์ด๊ธฐํ์์ผ ์ ํ๋ ์์ ๊ทธ๋ฆฌ๊ธฐ ์ค๋น
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void D3DClass::EndScene()
{
// ๋ ๋๋ง์ด ์๋ฃ๋์์ผ๋ฏ๋ก, ๋ฐฑ ๋ฒํผ๋ฅผ ํ๋ฉด์ ์ถ๋ ฅ
if (m_vsync_enabled)
{
// ์ฃผ์ฌ์จ์ ๋ง๊ฒ ์ถ๋ ฅ
m_swapChain->Present(1, 0);
}
else
{
// ์ต๋ํ ๋น ๋ฅด๊ฒ ์ถ๋ ฅ (VSync ๋นํ์ฑํ)
m_swapChain->Present(0, 0);
}
}
D3DClass::EndScene
- ํ๋ ์ ์์
๋ง์ง๋ง์ ํธ์ถ(๋ ๋๋ง์ด ์๋ฃ๋ ์ดํ)
- ๋ฐฑ ๋ฒํผ๋ฅผ ํ๋ก ํธ ๋ฒํผ๋ก ์ค์ํ๋ ์ญํ !
- ๊ทธ๋ฆฌ๊ธฐ๊ฐ ์๋ฃ๋๋ฉด ์ค์ ์ฒด์ธ์ 3D ์ฌ์ ์ถ๋ ฅํ๋ผ๊ณ ๋ช ๋ น
m_vsync_enabled
: ์ฃผ์ฌ์จ ๋๊ธฐํ ์ฌ๋ถtrue
: ๋ชจ๋ํฐ ์ฃผ์ฌ์จ์ ๋ง๊ฒ ํ๋ ์ ์ถ๋ ฅfalse
์ฃผ์ฌ์จ์ ๋ฌด์ํ๊ณ ์ต๋ํ ๋น ๋ฅด๊ฒ ํ๋ ์ ์ถ๋ ฅ
Device/Context getter
1
2
3
4
5
6
7
8
9
ID3D11Device* D3DClass::GetDevice()
{
return m_device;
}
ID3D11DeviceContext* D3DClass::GetDeviceContext()
{
return m_deviceContext;
}
Direct3D Device์ Device Context์ ๋ํ ํฌ์ธํฐ๋ฅผ ๋ฐํํ๋ค. ์ ํฌํผ ํจ์๋ ํ๋ ์์ํฌ์์ ์์ฃผ ํธ์ถ๋๋ค.
ํ๋ ฌ ๊ด๋ จ getter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void D3DClass::GetProjectionMatrix(XMMATRIX& projectionMatrix)
{
projectionMatrix = m_projectionMatrix;
return;
}
void D3DClass::GetWorldMatrix(XMMATRIX& worldMatrix)
{
worldMatrix = m_worldMatrix;
return;
}
void D3DClass::GetOrthoMatrix(XMMATRIX& orthoMatrix)
{
orthoMatrix = m_orthoMatrix;
return;
}
๊ฐ ํ๋ ฌ์ ์ฌ๋ณธ์ ์ธ๋ถ์์ ์ฌ์ฉํ ์ ์๋๋ก ๋ฐํํ๋ค.
- ๋๋ถ๋ถ์ ์
ฐ์ด๋๊ฐ ๋ ๋๋ง์ ํ๊ธฐ ์ํด ํ๋ ฌ์ด ํ์
- ์ธ๋ถ ๊ฐ์ฒด๊ฐ ํ๋ ฌ์ ์ฌ๋ณธ์ ์ฝ๊ฒ ์ป์ ์ ์๋๋ก getter ์ ๊ณต
(ํํ ๋ฆฌ์ผ์์๋ ์ ํจ์๋ฅผ ํธ์ถํ์ง ์์ง๋ง, ์ฝ๋์ ์ ์์ฑ๋์ด ์๋์ง ์ค๋ช ํ๋ค!)
๐ฑ ํ๋ ฌ getter๊ฐ ์ฐ์ด๋ ๋ถ๋ถ
GetProjectionMatrix
: ์ ฐ์ด๋์์ ์๊ทผ ํฌ์ ๋ ๋๋ง์ ์ฌ์ฉGetWorldMatrix
: ๋ชจ๋ธ ์ขํ๊ณ๋ฅผ์ ์๋ ์ขํ๊ณ๋ก ๋งคํํ๋๋ฐ ์ฌ์ฉ (Model Space -> World Space)GetOrthoMatrix
: 2D ๋ ๋๋ง์ ํ์ํ ํ๋ ฌ
๋น๋์ค์นด๋ ์ ๋ณด getter
1
2
3
4
5
6
void D3DClass::GetVideoCardInfo(char* cardName, int& memory)
{
strcpy_s(cardName, 128, m_videoCardDescription);
memory = m_videoCardMemory;
return;
}
- ๋น๋์ค ์นด๋ ์ด๋ฆ, ๋ฉ๋ชจ๋ฆฌ ํฌ๊ธฐ๋ฅผ ์ฐธ์กฐ๋ก ๋ฐํ
- ๋น๋์ค ์นด๋ ์ด๋ฆ์ ๋ค์ํ ํ๊ฒฝ์์ ๋๋ฒ๊น ํ ๋ ๋์์ ์ค
๐ฑ ๋น๋์ค ์นด๋ ์ ๋ณด๊ฐ ์ด๋์ ์ฐ์ผ๊น?
cardName
์m_videoCardDescription
๋ด์ฉ ์ ์ฅ
strcpy_s
์ฌ์ฉ: ์์ ํ ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ!
- ๋ฒํผ ์ค๋ฒํ๋ก์ฐ ๋ฐฉ์ง => ๋ฒํผ ํฌ๊ธฐ(128byte)๋ฅผ ๋์ด๊ฐ๋ฉด ์์ธ ๋ฐ์
- ๋ค์ํ ํ๊ฒฝ? ๊ทธ๋ํฝ ์นด๋์ ์ด๋ฆ์ ์๋ฉด ์ฌ๋ฌ GPU ํ๊ฒฝ์์ ๊ฐ ์ฑ๋ฅ์ ๋น๊ตํ ์ ์๋ค!
๋ฒํผ ๋ฐ ๋ทฐํฌํธ ์ค์
1
2
3
4
5
6
7
8
9
10
11
12
13
void D3DClass::SetBackBufferRenderTarget()
{
// ๋ ๋ ํ์ผ ๋ทฐ์ ์คํ
์ค ๋ฒํผ๋ฅผ ์ถ๋ ฅ ๋ ๋๋ง ํ์ดํ๋ผ์ธ์ ๋ฐ์ธ๋ฉ
m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
return;
}
void D3DClass::ResetViewport()
{
// ๋ทฐํฌํธ ์ค์
m_deviceContext->RSSetViewports(1, &m_viewport);
}
์ถํ Render To Texture์์ ์ฌ์ฉ๋ ํฌํผ ํจ์.
๐ฑ ๊ฐ๋จํ ํจ์ ์ฐ์
- ๋ ๋ ํ์ผ ๋ทฐ์ ์คํ ์ค ๋ฒํผ๋ฅผ OM Stage์ ๋ฐ์ธ๋ฉ
- ๋ฐฑ ๋ฒํผ๋ฅผ ๊ธฐ๋ณธ ๋ ๋ ํ๊ฒ์ผ๋ก ์ค์
- ์ต๋ 8๊ฐ์ ๋ ๋ ํ๊ฒ์ ์ฌ์ฉํ ์ ์์ (PS๊ฐ ๋์์ ์ถ๋ ฅํ ์ ์์ด์ผ ํจ)
- ์ฌ๊ธฐ์ ์ค๋ณต ์ค์ ๋ฐฉ์ง, ํฌ๊ธฐ์ ๊ท์น์ ๋ฐ๋ฅด๊ฒ ํจ
OMSetRenderTargets(0, nullptr, nullptr);
๋ฅผ ํธ์ถํ๋ฉด ๋ชจ๋ ๋ฐ์ธ๋ฉํด์
- ๋ทฐํฌํธ๋ฅผ RS Stage์ ๋ฐ์ธ๋ฉ
- ๋ชจ๋ ๋ทฐํฌํธ๋ ์์์ฑ ์ ์ง => ํธ์ถ๋์ง ์์ ๋ทฐํฌํธ๋ ์ฌ์ฉx
- ์ฌ์ฉํ ๋ทฐํฌํธ๋ ๊ธฐํ ๋ํ ์ธ์ด๋์ ์ํด ๊ฒฐ์ ๋จ
- ์๊ฐ ๋ฐ๋ก ์ง์ ํ์ง ์์ผ๋ฉด D3D๋ ์ฒซ ๋ฒ์งธ ๋ทฐํฌํธ ์ฌ์ฉ
Summary
- D3D๋ฅผ ์ด๊ธฐํํ๊ณ ์ข ๋ฃํ ์ ์๋ค
- ์ฝ๋๋ฅผ ์ปดํ์ผํ๊ณ ์คํํ๋ฉด D3D๊ฐ ์ด๊ธฐํ๋๊ณ ์๋์ฐ๊ฐ ํ์์ผ๋ก ์ฑ์์ง๋ค
To Do Exercises
- ์ฝ๋๋ฅผ ์ปดํ์ผํ๊ณ ํ๋ก๊ทธ๋จ์ ์คํํด DirectX๊ฐ ์คํ๋๋์ง ํ์ธ
- ์ ๋๋ก ๋์ํ์ง ์์ผ๋ฉด ์ฒ์ ํํ ๋ฆฌ์ผ์ ์ฐธ๊ณ ํด ๋๋ฒ๊น
- ์ฐฝ์ด ํ์๋๋ฉด ESCํค๋ฅผ ๋๋ฌ ์ข ๋ฃ
- applicationclass.h์ ์ ์ญ๋ณ์๋ฅผ ์ ์ฒดํ๋ฉด์ผ๋ก ๋ณ๊ฒฝ
- ApplicationClass::Render์ clear color๋ฅผ ๋ ธ๋์์ผ๋ก ๋ณ๊ฒฝ
- ๋น๋์ค ์นด๋ ์ด๋ฆ์ ํ ์คํธ ํ์ผ๋ก ์ ์ฅ