/* Single vertex and triangular face, respectively */
typedef struct mesh_vertex_s
{
	u32_t	vertex;				/* Index of geometry vertex */
	u32_t	texcoord;			/* Index of texture vertex / texinfo */
	u32_t	texcoord2;			/* Same as above, secondary channel */
	u32_t	normal;				/* Index of normal vector */
	u32_t	color;				/* Index of vertex color */
}	mesh_vertex_t, *mesh_vertex_p, mesh_face_t[3];

/* Texture map */
typedef	struct	mesh_map_s
{
	char		file_name[_MAX_PATH];
	/* if need_reload == true, texture must be reloaded using
	 * glTexSubimage2d */
	vboolean	need_reload;
	GLuint		handle;			/* for glBindTexture() */
	u32_t		env;			/* GL_DECAL / GL_MODULATE */
	GLuint		min_filter, mag_filter; /* GL_NEAREST, ... */
	GLuint		clamp_s, clamp_t;	/* GL_CLAMP / GL_REPEAT */
}	mesh_map_t, *mesh_map_p;

/* Material */
typedef struct	mesh_mtl_s
{
	vec4_t		diffuse;		/* diffuse color */
	vec4_t		specular;		/* specular color */
	vec4_t		emissive;		/* emissive color */
	vec_t		specular_power;
	u32_t		map_primary;	/* index of diffuse map */
	u32_t		map_secondary;	/* index of FX map */
}	mesh_mtl_t, *mesh_mtl_p;

/* This structure represent all objects in mesh */
typedef struct	scene_s
{
	u32_t				num_vertices;	/* Number of vertices */
	u32_t				vertex_count;	/* Number of added vertices */
	u32_t				num_texcoords;	/* Number of texture coords */
	u32_t				texcoord_count;	/* Number of added texcoords */
	u32_t				num_normals;	/* Number of normals */
	u32_t				normal_count;	/* Number of added normals */
	u32_t				num_faces;		/* Number of faces */
	u32_t				face_count;		/* Number of added faces */
	u32_t				num_objects;	/* Number of objects */
	u32_t				object_count;	/* Number of added objects */
	u32_t				num_colors;		/* Number of color vertices */
	u32_t				color_count;	/* Number of added color verts */
	u32_t				num_maps;		/* Number of texture maps */
	u32_t				map_count;		/* Number of added texture maps */
	u32_t				num_mtls;		/* Number of materials */
	u32_t				mtl_count;		/* Number of added materials */
	vec3_t				mins, maxs;		/* Mesh bounding box */
	vec3_t				*vertices;		/* Vertex pool */
	vec2_t				*texcoords;		/* Texture coord. pool */
	vec3_t				*normals;		/* Vert. normal vector pool */
	mesh_face_t			*faces;			/* Face pool */
	vec3_t				*face_centers;	/* Centers used when sorting */
	plane3_t			*face_planes;	/* Face normals & dists */
	mesh_object_t		*objects;		/* Object pool */
	color4b_t			*colors;		/* Color vertices */
	mesh_map_t			*maps;			/* Texture maps */
	mesh_mtl_t			*mtls;			/* Materials */
}	scene_t, *scene_p;

/*	Static set of solid objects */
typedef struct	mesh_s
{
	libv_object_t base;
	bstack_t	vertices;		/* Vertex pool */
	bstack_t	texcoords;		/* Texture coord. pool */
	bstack_t	normals;		/* Vert. normal vector pool */
	bstack_t	faces;			/* Face pool */
	bstack_t	face_centers;	/* Face centers for Z-sort */
	bstack_t	face_planes;	/* Face normals & dists */
	bstack_t	objects;		/* Object pool */
	bstack_t	colors;			/* Color vertices */
	bstack_t	maps;			/* Texture maps */
	bstack_t	mtls;			/* Materials */
}	mesh_t, *mesh_p;

#ifdef	__cplusplus
extern "C" {
#endif	/* __cplusplus */
	/* Texture managing: creates/destroys texture maps.
	 * Implemented in geom/meshmap.c. */
	vhandle_t	V_GLOBAL	meshCreateTextureMap(char_p image_file);
	void 		V_GLOBAL	meshDestroyTextureMap(vhandle_t self);
	/* Mesh managind.
	
	vhandle_t	V_GLOBAL	meshCreate(void);
	u32_t			V_GLOBAL	meshDestroy(vhandle_t mesh);
	/*
	 *	Note: meshClear() just sets all counters to 0, but NOT
	 *	memFree()'s all blocks; it can be called every frame
	 *	without significant performance loss.
	 */
	void	V_GLOBAL	meshClear(vhandle_t mesh);
	/*
	 *	Querring functions.
	 */
	
	
		u32_t num_vertices,
		u32_t num_texcoords,
		u32_t num_normals,
		u32_t num_faces,
		u32_t num_objects,
		u32_t num_colors,
		u32_t num_maps,
		u32_t num_mtls);
	/* Returns malloc()'ed block */
	mesh_p		V_GLOBAL	objLoad(char *filename);
	/* Do NOT frees any memory, just saves mesh */
	vboolean	V_GLOBAL	objSave(char *filename,mesh_t *obj);
#ifdef	__cplusplus
}
#endif	/* __cplusplus */

#endif	/* V_OBJLIB_H */
/*</pre></strong></body></html>*/
/*EOF*/
