#pragma once
#include <d3d11.h>
#pragma comment (lib, "d3d11.lib")
#include <d3dcompiler.h>
#pragma comment (lib, "d3dcompiler.lib")

#include <wrl.h>
#include <d3dcompiler.h>
#include <DirectXMath.h>
#include "Logger.h"

namespace wrl = Microsoft::WRL;

class Graphics
{
	friend class Bindable;
public:
	// 构造函数
	Graphics(HWND hWnd, int width, int height);

	// 单例设计模式，禁止复制
	Graphics(const Graphics&) = delete;
	Graphics& operator=(const Graphics&) = delete;
	~Graphics() = default;

	// 初始化3大件，Device/SwapChain/deviceContext
	void InitD3D(HWND hWnd, int width, int heigh);
	void RendorFrame(void);
	void EndFrame(void);

	//void DrawTestTriangle(float angle, float x, float y);
	void DrawIndexed(UINT count) noexcept;
	void SetProjection(DirectX::FXMMATRIX proj) noexcept;
	DirectX::XMMATRIX GetProjection() const noexcept;

	// for camera
	void SetCamera(
		Logger& logger,
		DirectX::XMVECTOR eyePosition,
		DirectX::XMVECTOR focusPosition,
		DirectX::XMVECTOR upDirection) noexcept;
	
	DirectX::XMMATRIX getLookAtMatrix() noexcept;

	// for debug
	wrl::ComPtr<ID3D11Device> getDevice();
	wrl::ComPtr<IDXGISwapChain> getSwapChain();
	wrl::ComPtr<ID3D11DeviceContext> getContext();

private:
	int width;
	int height;
	DirectX::XMMATRIX projection;
	// 指向Device的指针
	wrl::ComPtr<ID3D11Device> pDevice;
	// 指向交换链的指针
	wrl::ComPtr<IDXGISwapChain> pSwapChain;
	// 指向Context的指针
	wrl::ComPtr<ID3D11DeviceContext> pContext;
	// 指向View的指针
	wrl::ComPtr<ID3D11RenderTargetView> pTarget;
	// 指向Depth Buffer View的指针
	wrl::ComPtr<ID3D11DepthStencilView> pDSView;
	// for camera
	DirectX::XMVECTOR upDirection;
	DirectX::XMVECTOR eyePosition;
	DirectX::XMVECTOR focusPosition;
};