/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


		#include "core/shader_input.h"

		using namespace GS;
		using namespace GS::Core;


//------------------------------------------------------------------------------
ShaderInput::SemanticDesc ShaderInput::semantic_desc[LastSemantic + 1] =
{
	{	"Position", CategoryVertexStream, Vector3, MediumP	},
	{	"Normal", CategoryVertexStream, Vector3, LowP	},
	{	"UV0", CategoryVertexStream, Vector2, MediumP	},
	{	"UV1", CategoryVertexStream, Vector2, MediumP	},
	{	"UV2", CategoryVertexStream, Vector2, MediumP	},
	{	"VertexColor", CategoryVertexStream, Vector4, LowP	},
	{	"Tangent", CategoryVertexStream, Vector3, LowP	},
	{	"Bitangent", CategoryVertexStream, Vector3, LowP	},
	{	"BoneIndex", CategoryVertexStream, Vector4, LowP	},
	{	"BoneWeight", CategoryVertexStream, Vector4, LowP	},

	// Data uniform.
	{	"Constant", CategoryConstant, Vector4, MediumP	},

	{	"Texture2D", CategoryTexture, DataTexture2D, NoP	},
	{	"Texture3D", CategoryTexture, DataTexture2D, NoP	},
	{	"TextureCube", CategoryTexture, DataTextureCube, NoP	},

	{	"Clock", CategoryRenderer, Float, MediumP	},
	{	"TimeOfDay", CategoryRenderer, Float, MediumP	},
	{	"ViewVector", CategoryRenderer, Vector3, MediumP	},
	{	"ViewPosition", CategoryRenderer, Vector4, MediumP	},
	{	"Viewport", CategoryRenderer, Vector4, MediumP	},
	{	"ZNear", CategoryRenderer, Float, MediumP	},
	{	"ZFar", CategoryRenderer, Float, MediumP	},
	{	"ZoomFactor", CategoryRenderer, Float, MediumP	},
	{	"FxScale", CategoryRenderer, Float, MediumP	},
	{	"InverseBufferSize", CategoryRenderer, Vector2, LowP	},
	{	"InverseViewportSize", CategoryRenderer, Vector2, LowP	},
	{	"DisplayBufferRatio", CategoryRenderer, Vector2, MediumP	},
	{	"ViewportRatio", CategoryRenderer, Vector2, MediumP	},
	{	"ViewDepthOffset", CategoryRenderer, Float, MediumP	},
	{	"AmbientColor", CategoryRenderer, Vector3, LowP	},
	{	"FogColor", CategoryRenderer, Vector3, LowP	},
	{	"FogNear", CategoryRenderer, Float, MediumP	},
	{	"FogFar", CategoryRenderer, Float, MediumP	},
	{	"FogInverseRange", CategoryRenderer, Float, LowP	},
	{	"DepthBuffer", CategoryRenderer, DataTexture2D, NoP	},
	{	"FrameBuffer", CategoryRenderer, DataTexture2D, NoP	},
	{	"GBuffer0", CategoryRenderer, DataTexture2D, NoP	},
	{	"GBuffer1", CategoryRenderer, DataTexture2D, NoP	},
	{	"GBuffer2", CategoryRenderer, DataTexture2D, NoP	},
	{	"GBuffer3", CategoryRenderer, DataTexture2D, NoP	},
	{	"NoiseMap", CategoryRenderer, DataTexture2D, NoP	},

	{	"NormalMatrix", CategoryTransform, Matrix3, LowP	},
	{	"NormalViewMatrix", CategoryTransform, Matrix3, HighP	},
	{	"ModelMatrix", CategoryTransform, Matrix4, HighP	},
	{	"ViewMatrix", CategoryTransform, Matrix4, HighP	},
	{	"ProjectionMatrix", CategoryTransform, Matrix4, HighP	},
	{	"ModelViewMatrix", CategoryTransform, Matrix4, HighP	},
	{	"ModelViewProjectionMatrix", CategoryTransform, Matrix4, HighP	},
	{	"InverseViewProjectionMatrix", CategoryTransform, Matrix4, HighP },
	{	"InverseViewProjectionMatrixAtOrigin", CategoryTransform, Matrix4, HighP },

	{	"PreviousModelViewMatrix", CategoryPreviousTransform, Matrix4, HighP	},
	{	"PreviousModelViewProjectionMatrix", CategoryPreviousTransform, Matrix4, HighP	},

	{	"MaterialOpacity", CategoryMaterialOpacity, Float, LowP	},

	{	"MaterialDiffuse", CategoryMaterial, Vector4, LowP	},
	{	"MaterialSpecular", CategoryMaterial, Vector4, LowP	},
	{	"MaterialSelf", CategoryMaterial, Vector4, LowP	},
	{	"MaterialAmbient", CategoryMaterial, Vector4, LowP	},
	{	"MaterialGlossiness", CategoryMaterial, Float, LowP	},
	{	"MaterialReflection", CategoryMaterial, Float, LowP	},
	{	"MaterialAlphaThreshold", CategoryMaterial, Float, LowP	},
	{	"MaterialDepthBias", CategoryMaterial, Float, LowP	},
	{	"MaterialTexture0", CategoryMaterial, DataTexture2D, NoP	},
	{	"MaterialTexture1", CategoryMaterial, DataTexture2D, NoP	},
	{	"MaterialTexture2", CategoryMaterial, DataTexture2D, NoP	},
	{	"MaterialTexture3", CategoryMaterial, DataTexture2D, NoP	},
	{	"MaterialTexture4", CategoryMaterial, DataTexture2D, NoP	},
	{	"MaterialTexture5", CategoryMaterial, DataTexture2D, NoP	},
	{	"MaterialTexture6", CategoryMaterial, DataTexture2D, NoP	},
	{	"MaterialTexture7", CategoryMaterial, DataTexture2D, NoP	},

	{	"LightRange", CategoryLight, Float, MediumP	},
	{	"LightSpotEdge", CategoryLight, Float, MediumP	},
	{	"LightSpotCone", CategoryLight, Float, MediumP	},
	{	"LightShadowBias", CategoryLight, Float, MediumP	},
	{	"LightDiffuseColor", CategoryLight, Vector3, LowP	},
	{	"LightSpecularColor", CategoryLight, Vector3, LowP	},
	{	"LightShadowColor", CategoryLight, Vector3, LowP	},
	{	"LightViewPosition", CategoryLight, Vector3, MediumP	},
	{	"LightViewDirection", CategoryLight, Vector3, LowP	},
	{	"LightShadowMatrix0", CategoryLight, Matrix4, MediumP	},
	{	"LightShadowMatrix1", CategoryLight, Matrix4, MediumP	},
	{	"LightShadowMatrix2", CategoryLight, Matrix4, MediumP	},
	{	"LightShadowMatrix3", CategoryLight, Matrix4, MediumP	},
	{	"LightShadowMatrix4", CategoryLight, Matrix4, MediumP	},
	{	"LightShadowMatrix5", CategoryLight, Matrix4, MediumP	},
	{	"InverseShadowMapSize", CategoryLight, Float, LowP	},
	{	"LightShadowMap0", CategoryLight, DataTextureShadow, NoP	},
	{	"LightShadowMap1", CategoryLight, DataTextureShadow, NoP	},
	{	"LightShadowMap2", CategoryLight, DataTextureShadow, NoP	},
	{	"LightShadowMap3", CategoryLight, DataTextureShadow, NoP	},
	{	"LightShadowMap4", CategoryLight, DataTextureShadow, NoP	},
	{	"LightShadowMap5", CategoryLight, DataTextureShadow, NoP	},
	{	"LightPSSMSliceDistance0", CategoryLight, Float, MediumP	},
	{	"LightPSSMSliceDistance1", CategoryLight, Float, MediumP	},
	{	"LightPSSMSliceDistance2", CategoryLight, Float, MediumP	},
	{	"LightPSSMSliceDistance3", CategoryLight, Float, MediumP	},
	{	"ViewToLightMatrix", CategoryLight, Matrix4, MediumP	},
	{	"LightProjectionMap", CategoryLight, DataTexture2D, NoP	},

	{	"BoneMatrix", CategorySkin, Matrix4, MediumP	},
	{	"PreviousBoneMatrix", CategorySkin, Matrix4, MediumP	},

	{	"SemanticLast", CategoryLast, NoData, NoP	}
};
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
const char			*ShaderInput::GetCategoryName(Category category)
{
	static const char *cat[CategoryLast] =
	{
		"VertexStream",
		"Constant",
		"Texture",
		"Skin",
		"Renderer",
		"MaterialOpacity",
		"Material",
		"Transform",
		"PreviousTransform",
		"Light"
	};
	return cat[category];
}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
bool				ShaderInput::ConsumesTextureUnit() const
{
	switch (data_type)
	{
		case DataTexture2D:
		case DataTexture3D:
		case DataTextureCube:
		case DataTextureShadow:
			return true;

		default: break;
	}
	return false;
}
//------------------------------------------------------------------------------

ShaderInput::ShaderInput()
{
	type = None;
	scope = Vertex | Pixel;
	semantic = LastSemantic;
	array_size = 1;

	parm_v.Set(0, 0, 0);
	data_type = NoData;
}
