naev 0.12.5
opengl_tex.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include "SDL_endian.h"
8#include "SDL_rwops.h"
9#include <stdint.h>
11
12#include "attributes.h"
13#include "colour.h"
14
15/* Recommended for compatibility and such */
16#define RMASK SDL_SwapLE32( 0x000000ff )
17#define GMASK SDL_SwapLE32( 0x0000ff00 )
18#define BMASK SDL_SwapLE32( 0x00ff0000 )
19#define AMASK SDL_SwapLE32( 0xff000000 )
20#define RGBAMASK RMASK, GMASK, BMASK, AMASK
21
22/*
23 * Texture flags.
24 */
25#define OPENGL_TEX_MAPTRANS ( 1 << 0 )
26#define OPENGL_TEX_MIPMAPS ( 1 << 1 )
27#define OPENGL_TEX_VFLIP \
28 ( 1 << 2 )
30#define OPENGL_TEX_SKIPCACHE \
31 ( 1 << 3 )
32#define OPENGL_TEX_SDF \
33 ( 1 << 4 )
34#define OPENGL_TEX_CLAMP_ALPHA \
35 ( 1 << 5 )
36#define OPENGL_TEX_NOTSRGB ( 1 << 6 )
37
43typedef struct glTexture_ {
44 char *name;
45
46 /* dimensions */
47 double w;
48 double h;
49
50 /* sprites */
51 double sx;
52 double sy;
53 double sw;
54 double sh;
55 double srw;
56 double srh;
57
58 /* data */
59 GLuint texture;
60 uint8_t *trans;
61 double vmax;
62
63 /* properties */
64 uint8_t flags;
65} glTexture;
66
67/*
68 * Init/exit.
69 */
70int gl_initTextures( void );
71void gl_exitTextures( void );
72
73/*
74 * Creating.
75 */
76USE_RESULT glTexture *gl_texExistsOrCreate( const char *path,
77 unsigned int flags, int sx, int sy,
78 int *created );
79USE_RESULT glTexture *gl_loadImageData( float *data, int w, int h, int sx,
80 int sy, const char *name );
81USE_RESULT glTexture *gl_newImage( const char *path, const unsigned int flags );
82USE_RESULT glTexture *
83gl_newImageRWops( const char *path, SDL_RWops *rw,
84 const unsigned int flags ); /* Does not close the RWops. */
85USE_RESULT glTexture *gl_newSprite( const char *path, const int sx,
86 const int sy, const unsigned int flags );
87USE_RESULT glTexture *gl_newSpriteRWops( const char *path, SDL_RWops *rw,
88 const int sx, const int sy,
89 const unsigned int flags );
90USE_RESULT glTexture *gl_dupTexture( const glTexture *texture );
91USE_RESULT glTexture *gl_rawTexture( const char *name, GLuint tex, double w,
92 double h );
93
94/*
95 * Clean up.
96 */
97void gl_freeTexture( glTexture *texture );
98
99/*
100 * FBO stuff.
101 */
102int gl_fboCreate( GLuint *fbo, GLuint *tex, GLsizei width, GLsizei height );
103int gl_fboAddDepth( GLuint fbo, GLuint *tex, GLsizei width, GLsizei height );
104
105/*
106 * Misc.
107 */
108void gl_contextSet( void );
109void gl_contextUnset( void );
110int gl_isTrans( const glTexture *t, const int x, const int y );
111void gl_getSpriteFromDir( int *x, int *y, int sx, int sy, double dir );
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
Definition opengl_tex.c:891
USE_RESULT glTexture * gl_texExistsOrCreate(const char *path, unsigned int flags, int sx, int sy, int *created)
Check to see if a texture matching a path already exists.
Definition opengl_tex.c:508
glTexture * gl_newSprite(const char *path, const int sx, const int sy, const unsigned int flags)
Loads the texture immediately, but also sets it as a sprite.
Definition opengl_tex.c:785
void gl_exitTextures(void)
Cleans up the opengl texture subsystem.
glTexture * gl_newImageRWops(const char *path, SDL_RWops *rw, const unsigned int flags)
Loads an image as a texture.
Definition opengl_tex.c:611
USE_RESULT glTexture * gl_rawTexture(const char *name, GLuint texid, double w, double h)
Creates a texture from a raw opengl index.
Definition opengl_tex.c:917
int gl_fboCreate(GLuint *fbo, GLuint *tex, GLsizei width, GLsizei height)
Creates a framebuffer and its associated texture.
Definition opengl_tex.c:268
glTexture * gl_newSpriteRWops(const char *path, SDL_RWops *rw, const int sx, const int sy, const unsigned int flags)
Loads the texture immediately, but also sets it as a sprite.
Definition opengl_tex.c:808
glTexture ** gl_addTexArray(glTexture **tex, glTexture *t)
Adds an element to a texture array.
int gl_isTrans(const glTexture *t, const int x, const int y)
Checks to see if a pixel is transparent in a texture.
Definition opengl_tex.c:957
glTexture ** gl_copyTexArray(glTexture **tex)
Copy a texture array.
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
Definition opengl_tex.c:587
int gl_fboAddDepth(GLuint fbo, GLuint *tex, GLsizei width, GLsizei height)
Adds a depth attachment to an FBO.
Definition opengl_tex.c:313
void gl_getSpriteFromDir(int *x, int *y, int sx, int sy, double dir)
Sets x and y to be the appropriate sprite for glTexture using dir.
Definition opengl_tex.c:977
void gl_freeTexture(glTexture *texture)
Frees a texture.
Definition opengl_tex.c:835
int gl_initTextures(void)
Initializes the opengl texture subsystem.
Abstraction for rendering sprite sheets.
Definition opengl_tex.h:43
double sw
Definition opengl_tex.h:53
double vmax
Definition opengl_tex.h:61
uint8_t * trans
Definition opengl_tex.h:60
double sh
Definition opengl_tex.h:54
double w
Definition opengl_tex.h:47
uint8_t flags
Definition opengl_tex.h:64
double sx
Definition opengl_tex.h:51
double srh
Definition opengl_tex.h:56
char * name
Definition opengl_tex.h:44
GLuint texture
Definition opengl_tex.h:59
double sy
Definition opengl_tex.h:52
double h
Definition opengl_tex.h:48
double srw
Definition opengl_tex.h:55