• Home
  • About
    • 게임 개발자 유정룡 photo

      게임 개발자 유정룡

      포트폴리오

    • Learn More
    • Email
    • Github
    • Bitbucket
  • Projects
    • All Projects
    • All Tags

DirectX11 공부 6일차(Wrapping Class - BlendState, Camera)

06 Jun 2021

Reading time ~2 minutes

Wrapping Class - BlendState

이젠 BlendState 뤠핑 할 순서이다.

딱히 특이한건 없고 그냥 클래스 생성 뿐이라 따로 설명은 없을거 같다….

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;
}


변경하는 부분은 따로 적진 않겠다. 바뀐게 많이 없다.

Wrapping Class - Camera

이젠 Camera 뤠핑 할 순서이다.

여기도 설명할게 없다.

Camera.h

#pragma once

class Camera final
{
public:
	Camera();
	~Camera() = default;

	const D3DXMATRIX& GetView() { return view; }
	const D3DXMATRIX& GetProjection() { return proj; }

	void Update();

private:
	void UpdateViewMatrix();
	void UpdateProjectionMatrix();

private:
	D3DXMATRIX view;
	D3DXMATRIX proj;
};

Camera.cpp

#include "stdafx.h"
#include "Camera.h"

Camera::Camera()
{
	D3DXMatrixIdentity(&view);
	D3DXMatrixIdentity(&proj);

	UpdateViewMatrix();
	UpdateProjectionMatrix();
}

void Camera::Update()
{
	UpdateViewMatrix();
	UpdateProjectionMatrix();
}

void Camera::UpdateViewMatrix()
{
	D3DXVECTOR3 eye = D3DXVECTOR3(0, 0, 0);
	D3DXVECTOR3 at = D3DXVECTOR3(0, 0, 1);
	D3DXVECTOR3 up = D3DXVECTOR3(0, 1, 0);

	D3DXMatrixLookAtLH(&view, &eye, &at, &up);
}

void Camera::UpdateProjectionMatrix()
{
	D3DXMatrixOrthoLH(&proj, Settings::Get().GetWidth(), Settings::Get().GetHeight(), 0.0f, 1.0f);
}

후기

후… 파이프라인 남았다….



DirectX Share Tweet +1