1 /*
2  * See Licensing and Copyright notice in naev.h
3  */
4 
5 
6 #ifndef OPENGL_TEX_H
7 #  define OPENGL_TEX_H
8 
9 
10 #include <stdint.h>
11 
12 #include "SDL.h"
13 #include "SDL_opengl.h"
14 
15 #include "physics.h"
16 #include "colour.h"
17 
18 #include "ncompat.h"
19 
20 
21 /* Recommended for compatibility and such */
22 #if HAS_BIGENDIAN
23 #  define RMASK   0xff000000 /**< Red bit mask. */
24 #  define GMASK   0x00ff0000 /**< Green bit mask. */
25 #  define BMASK   0x0000ff00 /**< Blue bit mask. */
26 #  define AMASK   0x000000ff /**< Alpha bit mask. */
27 #else
28 #  define RMASK   0x000000ff /**< Red bit mask. */
29 #  define GMASK   0x0000ff00 /**< Green bit mask. */
30 #  define BMASK   0x00ff0000 /**< Blue bit mask. */
31 #  define AMASK   0xff000000 /**< Alpha bit mask. */
32 #endif
33 #define RGBAMASK  RMASK,GMASK,BMASK,AMASK
34 
35 
36 /*
37  * Texture flags.
38  */
39 #define OPENGL_TEX_MAPTRANS   (1<<0) /**< Create a transparency map. */
40 #define OPENGL_TEX_MIPMAPS    (1<<1) /**< Creates mipmaps. */
41 
42 /**
43  * @brief Abstraction for rendering sprite sheets.
44  *
45  * The basic unit all the graphic rendering works with.
46  */
47 typedef struct glTexture_ {
48    char *name; /**< name of the graphic */
49 
50    /* dimensions */
51    double w; /**< Real width of the image. */
52    double h; /**< Real height of the image. */
53    double rw; /**< Padded POT width of the image. */
54    double rh; /**< Padded POT height of the image. */
55 
56    /* sprites */
57    double sx; /**< Number of sprites on the x axis. */
58    double sy; /**< Number of sprites on the y axis. */
59    double sw; /**< Width of a sprite. */
60    double sh; /**< Height of a sprite. */
61    double srw; /**< Sprite render width - equivalent to sw/rw. */
62    double srh; /**< Sprite render height - equivalent to sh/rh. */
63 
64    /* data */
65    GLuint texture; /**< the opengl texture itself */
66    uint8_t* trans; /**< maps the transparency */
67 
68    /* properties */
69    uint8_t flags; /**< flags used for texture properties */
70 } glTexture;
71 
72 
73 /*
74  * Init/exit.
75  */
76 int gl_initTextures (void);
77 void gl_exitTextures (void);
78 
79 
80 /*
81  * Preparing.
82  */
83 int gl_pot( int n );
84 SDL_Surface* gl_prepareSurface( SDL_Surface* surface ); /* Only preps it */
85 
86 /*
87  * Creating.
88  */
89 glTexture* gl_loadImagePad( const char *name, SDL_Surface* surface,
90       unsigned int flags, int w, int h, int sx, int sy, int freesur );
91 glTexture* gl_loadImagePadTrans( const char *name, SDL_Surface* surface, SDL_RWops *rw,
92       unsigned int flags, int w, int h, int sx, int sy, int freesur );
93 glTexture* gl_loadImage( SDL_Surface* surface, const unsigned int flags ); /* Frees the surface. */
94 glTexture* gl_newImage( const char* path, const unsigned int flags );
95 glTexture* gl_newSprite( const char* path, const int sx, const int sy,
96       const unsigned int flags );
97 glTexture* gl_dupTexture( glTexture *texture );
98 
99 /*
100  * Clean up.
101  */
102 void gl_freeTexture( glTexture* texture );
103 
104 /*
105  * Info.
106  */
107 int gl_texHasMipmaps (void);
108 int gl_texHasCompress (void);
109 
110 /*
111  * Misc.
112  */
113 int gl_isTrans( const glTexture* t, const int x, const int y );
114 void gl_getSpriteFromDir( int* x, int* y, const glTexture* t, const double dir );
115 int gl_needPOT (void);
116 
117 
118 #endif /* OPENGL_TEX_H */
119 
120