TODO

/*<html><pre>*/
#include <v_lib.h>
#include <../source/geom/mesh.h>

/*
**	Materials & maps.
*/

/*
**	Bitmap (texture) map.
*/

typedef struct tmap_s
{
	mesh_map_t	base;
	GLuint		handle;			/* for glBindTexture() */
    vboolean	bound;
	char_p		file_name;		/* Path to image file */
}	tmap_t, *tmap_p;

#ifdef	CHECKED_BUILD
#define	TMAP_MAGIC		0x544D4150  /* "TMAP" */
V_LOCAL	char_p			tmap_object="texture map";
#endif	CHECKED_BUILD

V_LOCAL u32_t V_CALL
tmapDestroy(vhandle_t self)
{
	tmap_p tmap=(tmap_p)self;
	if(tmap->bound)
    	glBindTexture(GL_TEXTURE_2D,0);
    if(tmap->handle)
    	glDeleteTextures(&tmap->handle,1);
	memFreeObject(self);
    return 0;
}

V_LOCAL void V_CALL
tmapBind(vhandle_t self)
{
	tmap_p tmap=(tmap_p)self;
	if(!tmap->bound)
    {
    	glBindTexture(GL_TEXTURE_2D,tmap->handle);
    	tmap->bound=true;
    }
}

V_LOCAL vboolean V_CALL
tmapReload(vhandle_t self)
{
	tmap_p tmap=(tmap_p)self;
    if(tmap->bound)
    {
    	glBindTexture(GL_TEXTURE_2D,0);
	    tmap->bound=false;
	}
    if(tmap->handle)
    	glDeleteTextures(&tmap->handle,1);
	tmap->handle=vglLoadTexture(map->file_name,
    	GL_LINEAR_MIPMAP_NEAREST,
    	GL_REPEAT,
        GL_MODULATE);
	if(!tmap->handle)
    	return false;
	return true;
}

vhandle_t	V_GLOBAL
meshCreateTextureMap(char_p image_file)
{
	u32_t extra;
	tmap_p tmap;
    extra=INT_ALIGN(strlen(image_file)+1);
	ALLOC_OBJECT(tmap,texture_map_t,extra,TMAP_MAGIC);
    tmap->base.base.destroy=tmapDestroy;
    tmap->base.bind=tmapBind;
    tmap->base.reload=tmapReload;
    tmap->handle=0;
    tmap->bound=false;
    tmap->file_name=(char_p)(tmap+1);
    strCopy(tmap->file_name,image_file,extra);
	if(tmap->base.reload(tmap)) /* load image file */
	    return (vhandle_t)tmap;
    __libvCloseHandle(tmap); 	/* load failed - destroy object */
    return NULL;
}

void V_GLOBAL
meshDestroyTextureMap(vhandle_t self)
{
	libvCloseHandle(self,"meshDestroyTextureMap",TMAP_OBJECT,tmap_magic);
}

/*
**	Simple material
*/
typede

typedef struct	mesh_mtl_s
{
	vec4_t		diffuse;			/* Diffuse color */
	vec4_t		specular;			/* Specular color */
	vec4_t		emissive;			/* Emissive color */
	vec_t		specular_power;		/* Specular power */
	u32_t		env;				/* GL_DECAL | GL_MODULATE */
	u32_t		map_diffuse;		/* Index of diffuse texmap */
}	mesh_mtl_t, *mesh_mtl_p;

/*<html><pre>*/
/*EOF*/
