//
// metaobjects.h
//

#ifndef __METAOBJECTS_H_
#define __METAOBJECTS_H_


#define	MO_COOKIE				0xfeedface		// set at head of every object for validation


		/* OBJECT TYPES */
enum
{
	MO_TYPE_GROUP		= 	'grup',
	MO_TYPE_MESH		=	'mesh',
	MO_TYPE_MATERIAL	=	'matl',
	MO_TYPE_MATRIX		=	'mtrx'
};


		/* META OBJECT HEADER */
		//
		// This structure is always at the head of any metaobject
		//

struct MetaObjectHeader
{
	u_long		cookie;						// this value should always == MO_COOKIE
	long		refCount;					// # times this is referenced
	u_long		type;						// object type
	u_long		subType;					// object sub-type
	void		*data;						// pointer to meta object's specific data	
	
	struct MetaObjectHeader *parentGroup;			// illegal reference to parent group, or nil if no parent
		
	struct MetaObjectHeader *prevNode;			// ptr to previous node in linked list
	struct MetaObjectHeader *nextNode;			// ptr to next node in linked list
};
typedef struct MetaObjectHeader MetaObjectHeader;

typedef	void * MetaObjectPtr;


		/****************/
		/* GROUP OBJECT */
		/****************/
		
#define	MO_MAX_ITEMS_IN_GROUP	70
		
typedef struct
{
	int					numObjectsInGroup;	
	MetaObjectHeader	*groupContents[MO_MAX_ITEMS_IN_GROUP];
}MOGroupData;
		
typedef struct
{
	MetaObjectHeader	objectHeader;
	MOGroupData			objectData;
}MOGroupObject;


		/*******************/
		/* MATERIAL OBJECT */
		/*******************/

typedef struct
{	
	u_long			flags;	
	OGLColorRGBA	diffuseColor;					// rgba diffuse color
	
	Boolean			hasTexture;	
	u_long			width,height;					// dimensions of texture
	void			*texturePixels;					// ptr to texture pixels
	GLuint			textureName;					// texture name assigned by OpenGL
}MOMaterialData;
		
typedef struct
{
	MetaObjectHeader	objectHeader;
	MOMaterialData		objectData;
}MOMaterialObject;



		/********************************/
		/* VERTEX ARRAY GEOMETRY OBJECT */
		/********************************/
		
typedef struct
{
	GLuint vertexIndices[3];
}MOTriangleIndecies;
		
typedef struct
{
	short				groupNum;							// which group # does this mesh belong to?

	MOMaterialObject 	*materials;							// a reference to a material meta object
	
	int					numPoints;							// # vertices in the model
	int					numTriangles;						// # triangls in the model
	OGLPoint3D			*points;							// ptr to array of vertex x,y,z coords
	OGLVector3D			*normals;							// ptr to array of vertex normals
	OGLTextureCoord		*uvs;								// ptr to array of vertex uv's for each layer
	OGLColorRGBA		*colorsFloat;
	MOTriangleIndecies	*triangles;							// ptr to array of triangle triad indecies

}MOMeshData;
		
typedef struct
{
	MetaObjectHeader	objectHeader;
	MOMeshData	objectData;
}MOMeshObject;



		/*****************/
		/* MATRIX OBJECT */
		/*****************/
		
typedef struct
{
	MetaObjectHeader	objectHeader;
	OGLMatrix4x4		matrix;
}MOMatrixObject;

	
	
//-----------------------------

void MO_InitHandler(void);
MetaObjectPtr MO_CreateNewObjectOfType(u_long type, u_long subType, void *data);
MetaObjectPtr MO_GetNewReference(MetaObjectPtr mo);
void MO_AppendToGroup(MOGroupObject *group, MetaObjectPtr newObject);
void MO_DrawMesh(const MOMeshData *data);
void MO_DrawGroup(const MOGroupObject *object);
void MO_DrawObject(const MetaObjectPtr object);
void MO_DrawMaterial(MOMaterialObject *matObj);
void MO_DrawMatrix(const MOMatrixObject *matObj);
void MO_DisposeObjectReference(MetaObjectPtr obj);
void MO_DeleteObjectInfo_Mesh(MOMeshData *data);
MOMaterialObject *MO_GetTextureFromFile(FSSpec *spec, int destPixelFormat);


#endif