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


		#include "binding_helpers.h"
		#include "scene3d/mlight.h"

		using namespace GS::S3D;
		using namespace GS::Script;


static CObjectType light_derived_types[] = { typetag_Item, typetag_Light, typetag_Undefined };

SQInteger	LightGetDiffuseIntensity(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNFLOAT(l->diffuse_intensity)
}

SQInteger	LightSetProjectionTexture(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETSAFEPTR(t, GS::Render::Texture, typetag_Texture)
	l->render_data->projection_texture = t;
	__SQ_GETEND
	__SQ_RETURN
}
SQInteger	LightSetDiffuseIntensity(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETFLOAT(i)
	__SQ_GETEND
	l->diffuse_intensity = i;
	__SQ_RETURN
}
SQInteger	LightGetDiffuseColor(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNVECTOR(l->diffuse_color)
}
SQInteger	LightSetDiffuseColor(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETVECTOR(color)
	__SQ_GETEND
	l->diffuse_color = color;
	__SQ_RETURN
}
SQInteger	LightGetSpecularIntensity(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNFLOAT(l->specular_intensity)
}
SQInteger	LightSetSpecularIntensity(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETFLOAT(i)
	__SQ_GETEND
	l->specular_intensity = i;
	__SQ_RETURN
}
SQInteger	LightGetSpecularColor(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNVECTOR(l->specular_color)
}
SQInteger	LightSetSpecularColor(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETVECTOR(color)
	__SQ_GETEND
	l->specular_color = color;
	__SQ_RETURN
}

//------------------------------------------------------------------------------
SQInteger	LightSetConeAngle(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETFLOAT(angle)
	__SQ_GETEND
	l->cone_angle = angle;
	__SQ_RETURN
}
SQInteger	LightGetConeAngle(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNFLOAT(l->cone_angle)
}
SQInteger	LightSetEdgeAngle(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETFLOAT(angle)
	__SQ_GETEND
	l->edge_angle = angle;
	__SQ_RETURN
}
SQInteger	LightGetEdgeAngle(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNFLOAT(l->edge_angle)
}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
SQInteger	LightSetRange(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETFLOAT(range)
	__SQ_GETEND
	l->range = range;
	__SQ_RETURN
}
SQInteger	LightGetRange(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNFLOAT(l->range)
}
SQInteger	LightSetShadowRange(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
		__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
		__SQ_GETFLOAT(shadow_range)
		__SQ_GETEND
		l->shadow_range = shadow_range;
	__SQ_RETURN
}
SQInteger	LightGetShadowRange(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
		__SQ_RETURNFLOAT(l->shadow_range)
}
SQInteger	LightSetVolumeRange(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETFLOAT(range)
	__SQ_GETEND
	l->volume_range = range;
	__SQ_RETURN
}
SQInteger	LightGetVolumeRange(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNFLOAT(l->volume_range)
}
//------------------------------------------------------------------------------

SQInteger	LightGetItem(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNSAFEPTR((MItem *)l, typetag_Item)
}
SQInteger	LightGetType(HSQUIRRELVM vm)
{
	__SQ_GETSINGLE(__SQ_GETCOBJECTBASE(l, MLight, light_derived_types))
	__SQ_RETURNINT(l->model)
}
SQInteger	LightSetType(HSQUIRRELVM vm)
{
	__SQ_GETSTART(2)
	__SQ_GETCOBJECTBASE(l, MLight, light_derived_types)
	__SQ_GETINT(_type)
	__SQ_GETEND
	l->model = (GS::Core::Light::Model)_type;
	__SQ_RETURN
}

//------------------------------------------------------------------------------
void		RegisterLightBinding(HSQUIRRELVM vm)
{
/*#
	Topic: Light
	Type: Light
	Related: Item
#*/

/*#
	Section: LightColor
	Desc: Light color functions
#*/
	/*#
		Func: LightGetDiffuseIntensity
		Proto: float:Light
		Desc: Get light diffuse intensity.
	#*/
	sq_register(vm, LightGetDiffuseIntensity, "LightGetDiffuseIntensity", _SC(".x"));
	/*#
		Func: LightGetDiffuseColor
		Proto: Vector:Light
		Desc: Get light diffuse color.
	#*/
	sq_register(vm, LightGetDiffuseColor, "LightGetDiffuseColor", _SC(".x"));
	/*#
		Func: LightSetDiffuseIntensity
		Proto: void:Light,float intensity
		Desc: Set light diffuse intensity.
	#*/
	sq_register(vm, LightSetDiffuseIntensity, "LightSetDiffuseIntensity", _SC(".xn"));
	/*#
		Func: LightSetDiffuseColor
		Proto: void:Light,Vector color
		Desc: Set light diffuse color.
	#*/
	sq_register(vm, LightSetDiffuseColor, "LightSetDiffuseColor", _SC(".xx"));
	/*#
		Func: LightGetSpecularIntensity
		Proto: float:Light
		Desc: Get light specular intensity.
	#*/
	sq_register(vm, LightGetSpecularIntensity, "LightGetSpecularIntensity", _SC(".x"));
	/*#
		Func: LightGetSpecularColor
		Proto: Vector:Light
		Desc: Get light specular color.
	#*/
	sq_register(vm, LightGetSpecularColor, "LightGetSpecularColor", _SC(".x"));
	/*#
		Func: LightSetSpecularIntensity
		Proto: void:Light,float intensity
		Desc: Set light specular intensity.
	#*/
	sq_register(vm, LightSetSpecularIntensity, "LightSetSpecularIntensity", _SC(".xn"));
	/*#
		Func: LightSetSpecularColor
		Proto: void:Light,Vector color
		Desc: Set light specular color.
	#*/
	sq_register(vm, LightSetSpecularColor, "LightSetSpecularColor", _SC(".xx"));

/*#
	Section: LightSpot
	Desc: Spot functions
#*/
	/*#
		Func: LightSetConeAngle
		Proto: void:Light,float angle
		Desc: Set light cone angle in radian, the cone angle is the spot area where intensity is at its maximum.
	#*/
	sq_register(vm, LightSetConeAngle, "LightSetConeAngle", _SC(".xn"));
	/*#
		Func: LightSetEdgeAngle
		Proto: void:Light,float angle
		Desc: Set light edge angle in radian, the edge angle is the spot area where intensity decreases from its maximum toward zero.
	#*/
	sq_register(vm, LightSetEdgeAngle, "LightSetEdgeAngle", _SC(".xn"));
	/*#
		Func: LightGetConeAngle
		Proto: float:Light
		Desc: Get light cone angle in radian.
	#*/
	sq_register(vm, LightGetConeAngle, "LightGetConeAngle", _SC(".x"));
	/*#
		Func: LightGetEdgeAngle
		Proto: float:Light
		Desc: Get light edge angle in radian.
	#*/
	sq_register(vm, LightGetEdgeAngle, "LightGetEdgeAngle", _SC(".x"));

/*#
	Section: LightGeneric
	Desc: Generic functions
#*/
	/*#
		Func: LightSetRange
		Proto: void:Light,float range
		Desc: Set the light range in meter.
	#*/
	sq_register(vm, LightSetRange, "LightSetRange", _SC(".xn"));
	/*#
		Func: LightGetRange
		Proto: float:Light
		Desc: Return the light range in meter.
	#*/
	sq_register(vm, LightGetRange, "LightGetRange", _SC(".x"));
	/*#
	Func: LightSetShadowRange
	Proto: void:Light,float range
	Desc: Set the light range in meter.
	#*/
	sq_register(vm, LightSetShadowRange, "LightSetShadowRange", _SC(".xn"));
	/*#
	Func: LightGetRange
	Proto: float:Light
	Desc: Return the light range in meter.
	#*/
	sq_register(vm, LightGetShadowRange, "LightGetShadowRange", _SC(".x"));
	/*#
		Func: LightSetVolumeRange
		Proto: void:Light,float range
		Desc: Set the light volume range in meter. The volume range has no relation with the volumetric system and is only a performance hint used by some renderer. If unsure this value should be kept equal to the light range.
	#*/
	sq_register(vm, LightSetVolumeRange, "LightSetVolumeRange", _SC(".xn"));
	/*#
		Func: LightGetVolumeRange
		Proto: float:Light
		Desc: Return the light volume range in meter.
	#*/
	sq_register(vm, LightGetVolumeRange, "LightGetVolumeRange", _SC(".x"));

	/*#
		Func: LightSetProjectionTexture
		Proto: void:Light,Texture
		Desc: Set light projection texture.
	#*/
	sq_register(vm, LightSetProjectionTexture, "LightSetProjectionTexture", _SC(".xx"));
	/*#
		Func: LightGetItem
		Proto: Item:Light
		Desc: Get light item.
	#*/
	sq_register(vm, LightGetItem, "LightGetItem", _SC(".x"));
	/*#
		Func: LightGetType
		Proto: LightType:Light
		Desc: Get light type.
	#*/
	sq_register(vm, LightGetType, "LightGetType", _SC(".x"));
	/*#
		Func: LightSetType
		Proto: void:Light,LightType type
		Desc: Set light type.
	#*/
	sq_register(vm, LightSetType, "LightSetType", _SC(".xi"));

	/*#
		Enum: LightType
		Values: LightTypeNone,LightTypeSpot,LightTypeLinear,LightTypePoint
	#*/
	using GS::Core::Light;

	sq_pushstring(vm, "LightTypeNone", -1); sq_pushinteger(vm, Light::Model_None); sq_newslot(vm, -3, true);
	sq_pushstring(vm, "LightTypeSpot", -1); sq_pushinteger(vm, Light::Model_Spot); sq_newslot(vm, -3, true);
	sq_pushstring(vm, "LightTypeLinear", -1); sq_pushinteger(vm, Light::Model_Linear); sq_newslot(vm, -3, true);
	sq_pushstring(vm, "LightTypePoint", -1); sq_pushinteger(vm, Light::Model_Point); sq_newslot(vm, -3, true);
}
//------------------------------------------------------------------------------
