#pragma once
#include "DirectXFramework.h"
#include "DDSTextureLoader.h"
#include "SharedMethods.h"
#include "SceneNode.h"

typedef struct SkyVertex
{
	XMFLOAT3 Position;
} SkyVertex;

struct SCBUFFER
{
	XMMATRIX    completeTransformation;	
};

class SkyNode : public SceneNode
{
public:
	SkyNode(wstring name, wstring skyCubeTextureName, float skyRadius);
	~SkyNode();

	bool Initialise(void);
	void Render(void);
	void Shutdown(void);

private:	
	float _skyRadius;

	UINT _indicesCount;
	UINT _vertexCount;

	vector<SkyVertex> _skyDomeVerts;
	vector<int> _indices;

	ComPtr<ID3D11Device> _device;
	ComPtr<ID3D11DeviceContext> _deviceContext;

	ComPtr<ID3D11Buffer> _vertexBuffer;
	ComPtr<ID3D11Buffer> _indexBuffer;

	ComPtr<ID3DBlob> _vertexShaderByteCode = nullptr;
	ComPtr<ID3DBlob> _pixelShaderByteCode = nullptr;
	ComPtr<ID3D11VertexShader> _vertexShader;
	ComPtr<ID3D11PixelShader> _pixelShader;
	ComPtr<ID3D11InputLayout> _layout;
	ComPtr<ID3D11Buffer> _constantBuffer;

	ComPtr<ID3D11RasterizerState>   _defaultRasteriserState;
	ComPtr<ID3D11RasterizerState>   _noCullRasteriserState;

	ComPtr<ID3D11DepthStencilState>	 _stencilState;

	ComPtr<ID3D11ShaderResourceView> _skyCubeTexture;
	wstring _skyCubeTextureName;
		
	void CreateSphere(float radius, size_t tessellation);
	void GenerateBuffers();
	void BuildShaders();
	void BuildVertexLayout();
	void BuildConstantBuffer();
	void BuildRendererStates();
	void BuildDepthStencilState();

	void LoadSkyboxTexture();
};

