////////////////////////////////////////////////////////////////////////////////
// Filename: lightshaderclass.h
////////////////////////////////////////////////////////////////////////////////
#ifndef _LIGHTSHADERCLASS_H_
#define _LIGHTSHADERCLASS_H_
#pragma once

/////////////
// GLOBALS //
/////////////
constexpr int num_lights = 4;
//////////////
// INCLUDES //
//////////////
#include "Logger.h"
#include <d3d11.h>
#include <d3dcompiler.h>
#include <directxmath.h>
#include <fstream>
using namespace DirectX;
using namespace std;


////////////////////////////////////////////////////////////////////////////////
// Class name: light_shader_class
////////////////////////////////////////////////////////////////////////////////
class light_shader_class
{
private:
    struct matrix_buffer_type
    {
        XMMATRIX world;
        XMMATRIX view;
        XMMATRIX projection;
    };

    struct camera_buffer_type
    {
        XMFLOAT3 cameraPosition;
        float padding;
    };

	struct light_buffer_type
	{
		XMFLOAT4 ambientColor;
		XMFLOAT4 diffuseColor;
		XMFLOAT3 lightDirection;
		float padding;  // Added extra padding so structure is a multiple of 16 for CreateBuffer function requirements.
        float specularPower;
        XMFLOAT4 specularColor;
	};

    struct light_color_buffer_type
    {
        XMFLOAT4 diffuseColor[num_lights];
    };

    struct light_position_buffer_type
    {
        XMFLOAT4 lightPosition[num_lights];
    };

public:
    light_shader_class();
    light_shader_class(const light_shader_class&);
    ~light_shader_class();

	bool initialize(ID3D11Device*, HWND);
	void shutdown();
    bool render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);

private:
    bool initialize_shader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
    void shutdown_shader();
    void output_shader_error_message(ID3D10Blob*, HWND, WCHAR*);

    bool set_shader_parameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);
	void render_shader(ID3D11DeviceContext*, int);

private:
    ID3D11VertexShader* vertex_shader_;
    ID3D11PixelShader* pixel_shader_;
    ID3D11InputLayout* layout_;
    ID3D11SamplerState* sample_state_;
    ID3D11Buffer* matrix_buffer_;
    ID3D11Buffer* camera_buffer_;
    ID3D11Buffer* light_buffer_;
    ID3D11Buffer* light_color_buffer_;
    ID3D11Buffer* light_position_buffer_;
};

#endif