#ifndef _LI_D3DSPIN
#define _LI_D3DSPIN 1

#include <DirectXMath.h>
#include "RenderDvdSpin.hpp"
#include "CdTex.hpp"
#include "CdType.hpp"
#include "../D3D.hpp"

namespace Li::Gui::DvdSpin {
	class D3DSpin : public RenderDvdSpin {
		private:
			CdTex* cdTextureProvider;

			D3D* d3d;
			uint32_t counter;

			// dvd spin state
			DirectX::XMMATRIX camWorld;
			DirectX::XMMATRIX camView;
			DirectX::XMMATRIX camProjection;

			DirectX::XMVECTOR eye;
			DirectX::XMVECTOR at;
			DirectX::XMVECTOR up;


			ID3DBlob* cdVertexShaderBlob;

			ID3D11VertexShader* cdVertexShader;
			ID3D11PixelShader* cdPixelShader;
			ID3D11InputLayout* cdVertexLayout;

			ID3D11Buffer* cdVertexBuffer;
			ID3D11Buffer* cdIndexBuffer;
			ID3D11Buffer* camBuffer;

			ID3D11Texture2D* cdTexture;
			ID3D11SamplerState* cdSampler;
			ID3D11ShaderResourceView* cdResourceView;

			// dvd spin model
			void setupSpinningDVD();

			HRESULT createCdVertexShader();
			HRESULT createCdPixelShader();
			HRESULT createCdVertexLayout();

			HRESULT createCdVertexBuffer();
			HRESULT createCdIndexBuffer();
			HRESULT createCamBuffer();

			void setCdVertexBuffer();
			void setCdIndexBuffer();
			void setCdVertexLayout();

			void updateCdTexture();
			void updateCamBuffer();

			// dvd spin texture
			HRESULT createCdTexture();
			HRESULT createCdSampler();
			HRESULT createCdResourceView();
	public:
		void RenderDVD();
		void UpdateTexture(CdType type);
		D3DSpin(D3D* d3d);
		~D3DSpin();
	};
}

#endif