/*
** surface.h for Factory 0.1
**
** Made by caput_r
** Login caput_r <caput_r@epita.fr>
**
** Started on  Tue Sep 27 01:34:52 2005 remi caput
** Last update Tue Sep 27 02:51:08 2005 remi caput
*/

#ifndef SURFACE_H_
#define SURFACE_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__APPLE__) && defined(__MACH__)
#define SURFACE_BENDIAN
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#define SURFACE_LENDIAN
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include "png.h"

#define SURFACE_REALLOC_ALPHA	16
#define SURFACE_REALLOC_BUFFER	256
#define SURFACE_REALLOC_ITEM	32

#define SURFACE_TYPE(A, B, C)	((A) * 1 + (B) * 256 + (C) * 65536)

enum	surface_alpha
{
	SURFACE_ALPHA_CREATE,
	SURFACE_ALPHA_REPLACE,
	SURFACE_ALPHA_SOURCE
};

enum	surface_mipmap
{
	SURFACE_MIPMAP_OFF,
	SURFACE_MIPMAP_ON
};

struct				s_surface_color
{
	unsigned char	alpha;
	unsigned char	blue;
	unsigned char	green;
	unsigned char	red;
};

struct				s_surface_item
{
	unsigned int	offset;
	GLuint			handle;
};

struct 				s_surface_texture
{
	unsigned int	height;
	unsigned int	width;
	unsigned char	*pixels;
	GLuint			depth;
};

struct						s_surface
{
	struct s_surface_color*	alpha_array;
	unsigned int			alpha_count;
	unsigned char			alpha_default;
	unsigned int			alpha_size;
	char*					buffer_array;
	unsigned int			buffer_count;
	unsigned int			buffer_size;
	struct s_surface_item*	item_array;
	unsigned int			item_count;
	unsigned int			item_size;
	enum surface_alpha		mode_alpha;
	enum surface_mipmap		mode_mipmap;
};

int		surface_internal_alpha (struct s_surface*, struct s_surface_texture*);
int		surface_internal_load_bmp (struct s_surface_texture*, const char*);
int		surface_internal_load_png (struct s_surface_texture*, const char*);
int		surface_internal_read (FILE*, void*, size_t);

int		surface_alpha_define (struct s_surface*, unsigned char, unsigned char, unsigned char, unsigned char);
void	surface_alpha_reset (struct s_surface*, unsigned char);

int		surface_init (struct s_surface*);
int		surface_load (struct s_surface*, const char*, GLuint*);
void	surface_mode (struct s_surface*, enum surface_alpha, enum surface_mipmap);
void	surface_stop (struct s_surface*);

#ifdef __cplusplus
}
#endif

#endif
