#pragma once
#include "Gui/3D/Shader.h"
#include "Surface.h"
#include "Buffer.h"

#ifdef GUI_WIN32

namespace gui {

	/**
	 * A vertex shader in Direct3D.
	 *
	 * Includes data for input mapping from a vertex buffer.
	 */
	class D3DVertexShader {
	public:
		// Create and initialize.
		D3DVertexShader(VertexShader *shader, D3DSurface &surface);

		// The vertex shader itself.
		ComPtr<ID3D10VertexShader> shader;

		// The input layout -- description of how to map things to shader inputs.
		ComPtr<ID3D10InputLayout> inputLayout;

		// Cleanup.
		static void cleanup(void *obj) {
			delete (D3DVertexShader *)obj;
		}
	};


	/**
	 * A pixel shader in Direct3D.
	 */
	class D3DPixelShader {
	public:
		// Create and initialize.
		D3DPixelShader(PixelShader *shader, D3DSurface &surface);

		// The shader itself.
		ComPtr<ID3D10PixelShader> shader;

		// Cleanup.
		static void cleanup(void *obj) {
			delete (D3DPixelShader *)obj;
		}
	};


	/**
	 * Resources needed in a pipeline.
	 */
	class D3DPipeline {
	public:
		// Create and initialize.
		D3DPipeline(D3DVertexShader *vertex, D3DPixelShader *pixel, Pipeline *pipeline);

		// Collected state from the shaders.
		ComPtr<ID3D10InputLayout> inputLayout;
		ComPtr<ID3D10VertexShader> vertex;
		ComPtr<ID3D10PixelShader> pixel;

		// Buffers for shader uniforms.
		vector<ComPtr<ID3D10Buffer>> constantBuffers;

		// Buffers for textures.
		vector<ComPtr<ID3D10ShaderResourceView>> resourceViews;

		// Update constant buffers.
		void update(Graphics3D *graphics, Pipeline *pipeline, DirtyRange dirty);

		// Cleanup.
		static void cleanup(void *obj) {
			delete (D3DPipeline *)obj;
		}
	};

}

#endif
