//------------------------------------------------------------------------------------
// irr::scene::IQ3Shader wrappers
//------------------------------------------------------------------------------------

extern "C" 
{
	f32 IrrScene_Quake3_getAsFloat ( const c8* string, u32 &pos )
	{
		return quake3::getAsFloat(stringc(string),pos);
	}

	vector3df* IrrScene_Quake3_getAsVector3df( const c8* string, u32 &pos )
	{
		return new vector3df(quake3::getAsVector3df(stringc(string),pos));
	}

	// -------------------------------------------------------------
	// SVariable
	// -------------------------------------------------------------
	
	const c8* IrrScene_SVariable_getName(SVariable* var)
	{
		if (var)
			return var->name.c_str();
		else return "";
	}

	void IrrScene_SVariable_setName(SVariable* var,const c8* name)
	{
		if (var)
			var->name=name;
	}

	const c8* IrrScene_SVariable_getContent(SVariable* var)
	{
		if (var)
			return var->content.c_str();
		else return "";
	}

	void IrrScene_SVariable_setContent(SVariable* var,const c8* content)
	{
		if (var)
			var->content=content;
	}
	
	void IrrScene_SVariable_clear(SVariable* var)
	{
		if (var)
			var->clear();
	}
	
	s32 IrrScene_SVariable_isValid(SVariable* var)
	{
		if (var)
			return var->isValid();
		else return -1;
	}

	bool IrrScene_SVariable_EqEq(SVariable* var, SVariable* other)
	{
		if (var)
			return (*var == *other);
		else return false;
	}
			
	// -------------------------------------------------------------
	// SVarGroup
	// -------------------------------------------------------------

	const c8* IrrScene_SVarGroup_get(SVarGroup* grp,const c8* name)
	{
		if (grp)
			return grp->get(name).c_str();
		else return "";
	}

	void IrrScene_SVarGroup_set(SVarGroup* grp,const c8* name, const c8* content=0)
	{
		if (grp)
			grp->set(name, content);
	}
	
	bool IrrScene_SVarGroup_isDefined(SVarGroup* grp,const c8* name, const c8* content=0)
	{
		if (grp)
			return grp->isDefined(name,content);
		else return false;
	}
	
	// do not delete 
	s32 IrrScene_SVarGroup_getVariables(SVarGroup* grp,u32** variables)
	{
		if (grp)	{
			Irr_ptrarray_allocate(variables,grp->Variable.size());
			for (u32 i=0; i<grp->Variable.size(); i++) {
				((u32*)*variables)[i]=(u32)&(grp->Variable[i]);
			}

			return grp->Variable.size();
		} else return 0;
	}

	// -------------------------------------------------------------
	// SVarGroupList extends IUnknown
	// -------------------------------------------------------------

	bool IrrScene_SVarGroupList_drop(SVarGroupList* unk)
	{
		if (unk)
			return unk->drop();
		else return 0;
	}
	
	const c8* IrrScene_SVarGroupList_getDebugName(SVarGroupList* unk)
	{
		if (unk)
			return unk->getDebugName();
		else return "";
	}
	
	void IrrScene_SVarGroupList_grab(SVarGroupList* unk)
	{
		if (unk)
			unk->grab();
	}

	// do not delete 
	s32 IrrScene_SVarGroupList_getVariables(SVarGroupList* grplist,u32** vargroups)
	{
		if (grplist)	{
			Irr_ptrarray_allocate(vargroups,grplist->VariableGroup.size());
			for (u32 i=0; i<grplist->VariableGroup.size(); i++) {
				((u32*)*vargroups)[i]=(u32)&(grplist->VariableGroup[i]);
			}

			return grplist->VariableGroup.size();
		} else return 0;
	}
	
	// -------------------------------------------------------------
	// IShader
	// -------------------------------------------------------------

	bool IrrScene_IShader_EqEq(IShader* ss,IShader* other)
	{
		if (ss)
			return (*ss == *other);
		else return false;
	}

	void IrrScene_IShader_setEq(IShader* ss,IShader* other)
	{
		if (ss && other)
			*ss = *other;
	}

	bool IrrScene_IShader_Less(IShader* ss,IShader* other)
	{
		if (ss)
			return *ss < *other;
		else return false;
	}

	s32 IrrScene_IShader_getID(IShader* ss)
	{
		if (ss)
			return ss->ID;
		else return -1;
	}

	const c8* IrrScene_IShader_getName(IShader* ss)
	{
		if (ss)
			return ss->name.c_str();
		else return "";
	}

	// do not delete
	SVarGroupList* IrrScene_IShader_getVarGroup(IShader* ss)
	{
		if (ss)
			return ss->VarGroup;
		else return 0;
	}
	
	// do not delete
	const SVarGroup* IrrScene_IShader_getGroup(IShader* ss,u32 stage)
	{
		if (ss)
			return ss->getGroup(stage);
		else return 0;
	}
	
	s32 IrrScene_IShader_getGroupSize(IShader* ss) {
		if (ss) 
			return ss->getGroupSize();
		else return -1;
	}
}