GUID
텍스쳐나 쉐이더등 리소스를 읽을때 재사용을 줄이기 위해 ID 부여 해서 체크한다.
일단 ID부여하는 클래스 및 함수를 먼저 만든다.
GUID_Generator.h
#pragma once
class GUID_Generator final
{
public:
static const uint Generate();
static const std::string GenerateToString();
};
static클래스 임으로 생성자와 소멸자는 제외한다.
GUID_Generator.cpp
```#include “stdafx.h” #include “GUID_Generator.h”
#include
const uint GUID_Generator::Generate() { std::hash<std::string> haser; return static_cast
const std::string GUID_Generator::GenerateToString() { GUID guid; HRESULT hr = CoCreateGuid(&guid);
if (SUCCEEDED(hr))
{
std::stringstream sstream;
sstream
<< std::hex << std::uppercase
<< std::setw(8) << std::setfill('0') << guid.Data1 << "-"
<< std::setw(4) << std::setfill('0') << guid.Data2 << "-"
<< std::setw(4) << std::setfill('0') << guid.Data3 << "-"
<< std::setw(2) << std::setfill('0') << static_cast<uint>(guid.Data4[0])
<< std::setw(2) << std::setfill('0') << static_cast<uint>(guid.Data4[1])
<< std::setw(2) << std::setfill('0') << static_cast<uint>(guid.Data4[2])
<< std::setw(2) << std::setfill('0') << static_cast<uint>(guid.Data4[3])
<< std::setw(2) << std::setfill('0') << static_cast<uint>(guid.Data4[4])
<< std::setw(2) << std::setfill('0') << static_cast<uint>(guid.Data4[5])
<< std::setw(2) << std::setfill('0') << static_cast<uint>(guid.Data4[6])
<< std::setw(2) << std::setfill('0') << static_cast<uint>(guid.Data4[7]);
return sstream.str();
}
assert(false);
return "N/A"; } ``` 뭐가 많다.
일단 GUID의 구조체의 구성을 보자
typedef struct _GUID {
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[ 8 ];
} GUID;
4 byte ulong, 2 byte short * 2, 1byte char * 8 총 16바이트의 구조체이다. 이 구조체를 문자열로 채운다.
FBA99296-C277-4A92-94646199371ED0B1
예시로 이런 값이 나오고 이 값을 Generate()을 통해 해시맵에 저장한다.
예시로 어떤 값이 나오냐 하면
// 두 값은 서로 다른 값이다.
E6EB9AC9-8C61-4E08-AB026B95657BF836
481450028
이런 값이 나온다.
그냥 해시값 부여 한거다.
Wrapping Class - Pipeline
이젠 Pipeline 뤠핑 할 순서이다.
이번에는 새롭게 많이 추가된다. 거의다 복사 붙여넣기 이지만
D3D11_BlendState.h
#pragma once
class D3D11_BlendState final
{
public:
D3D11_BlendState(class Graphics* graphics);
~D3D11_BlendState();
ID3D11BlendState* GetResource()const { return state; }
float GetBlendFactor() const { return blend_factor; }
uint GetSampleMask() const { return sample_mask; }
void Create
(
const bool& is_blend_enabled,
const D3D11_BLEND& src_blend = D3D11_BLEND_SRC_ALPHA,
const D3D11_BLEND& dst_blend = D3D11_BLEND_INV_SRC_ALPHA,
const D3D11_BLEND_OP& blend_op = D3D11_BLEND_OP_ADD,
const D3D11_BLEND& src_blend_alpha =D3D11_BLEND_ONE,
const D3D11_BLEND& dst_blend_alpha = D3D11_BLEND_ZERO,
const D3D11_BLEND_OP& blend_op_alpha = D3D11_BLEND_OP_ADD,
const float& factor = 0.0f,
const D3D11_COLOR_WRITE_ENABLE& color_mask = D3D11_COLOR_WRITE_ENABLE_ALL
);
void Clear();
private:
ID3D11Device* device = nullptr;
ID3D11BlendState* state = nullptr;
float blend_factor = 0.0;
uint sample_mask = 0xffffffff;
};
D3D11_BlendState.cpp
#include "stdafx.h"
#include "D3D11_BlendState.h"
D3D11_BlendState::D3D11_BlendState(Graphics* graphics)
{
device = graphics->GetDevice();
}
D3D11_BlendState::~D3D11_BlendState()
{
Clear();
}
void D3D11_BlendState::Create(const bool& is_blend_enabled, const D3D11_BLEND& src_blend, const D3D11_BLEND& dst_blend, const D3D11_BLEND_OP& blend_op, const D3D11_BLEND& src_blend_alpha, const D3D11_BLEND& dst_blend_alpha, const D3D11_BLEND_OP& blend_op_alpha, const float& factor, const D3D11_COLOR_WRITE_ENABLE& color_mask)
{
D3D11_BLEND_DESC desc;
ZeroMemory(&desc, sizeof(D3D11_BLEND_DESC));
desc.AlphaToCoverageEnable = false;
desc.IndependentBlendEnable = false;
desc.RenderTarget[0].BlendEnable = is_blend_enabled;
desc.RenderTarget[0].SrcBlend = src_blend;
desc.RenderTarget[0].DestBlend = dst_blend;
desc.RenderTarget[0].BlendOp = blend_op;
desc.RenderTarget[0].SrcBlendAlpha = src_blend_alpha;
desc.RenderTarget[0].DestBlendAlpha = dst_blend_alpha;
desc.RenderTarget[0].BlendOpAlpha = blend_op_alpha;
desc.RenderTarget[0].RenderTargetWriteMask = color_mask;
HRESULT hr = device->CreateBlendState(&desc, &state);
assert(SUCCEEDED(hr));
blend_factor = factor;
}
void D3D11_BlendState::Clear()
{
SAFE_RELEASE(state);
blend_factor = 0.0f;
sample_mask = 0xffffffff;
}
변경하는 부분은 따로 적진 않겠다. 바뀐게 많이 없다.
Object
각 객체에 id 값을 부여해주면 된다.
Object.h
#pragma once
#include "stdafx.h"
class Object
{
public:
Object() { id = GUID_Generator::Generate(); }
virtual ~Object() = default;
uint GetID() const { return id; }
void SetID(const uint& id) { this->id = id; }
private:
uint id = 0;
};
그 후, 각 Wrapping Class에 Object를 상속해주면 비교할 수 있는 ID가 부여된다.