naev 0.10.4
Data Structures | Functions | Variables
opengl_tex.c File Reference

This file handles the opengl texture wrapper routines. More...

#include "array.h"
#include "conf.h"
#include "gui.h"
#include "log.h"
#include "md5.h"
#include "nfile.h"
#include "nstring.h"
#include "opengl.h"

Go to the source code of this file.

Data Structures

struct  glTexList
 Represents a node in the texture list. More...
 

Functions

static int SDL_IsTrans (SDL_Surface *s, int x, int y)
 Checks to see if a position of the surface is transparent. More...
 
static uint8_t * SDL_MapTrans (SDL_Surface *s, int w, int h)
 Maps the surface transparency. More...
 
static size_t gl_transSize (const int w, const int h)
 
static GLuint gl_texParameters (unsigned int flags)
 Sets default texture parameters. More...
 
static GLuint gl_loadSurface (SDL_Surface *surface, unsigned int flags, int freesur)
 Loads a surface into an opengl texture. More...
 
static glTexturegl_loadNewImage (const char *path, const unsigned int flags)
 Only loads the image, does not add to stack unlike gl_newImage. More...
 
static glTexturegl_loadNewImageRWops (const char *path, SDL_RWops *rw, unsigned int flags)
 Only loads the image, does not add to stack unlike gl_newImage. More...
 
static glTexturegl_texExists (const char *path, int sx, int sy)
 Check to see if a texture matching a path already exists. More...
 
static int gl_texAdd (glTexture *tex, int sx, int sy)
 Adds a texture to the list under the name of path. More...
 
int gl_fboCreate (GLuint *fbo, GLuint *tex, GLsizei width, GLsizei height)
 Creates a framebuffer and its associated texture. More...
 
glTexturegl_loadImageData (float *data, int w, int h, int sx, int sy, const char *name)
 
glTexturegl_loadImagePadTrans (const char *name, SDL_Surface *surface, SDL_RWops *rw, unsigned int flags, int w, int h, int sx, int sy, int freesur)
 Wrapper for gl_loadImagePad that includes transparency mapping. More...
 
glTexturegl_loadImagePad (const char *name, SDL_Surface *surface, unsigned int flags, int w, int h, int sx, int sy, int freesur)
 Loads the already padded SDL_Surface to a glTexture. More...
 
glTexturegl_loadImage (SDL_Surface *surface, unsigned int flags)
 Loads the SDL_Surface to a glTexture. More...
 
glTexturegl_newImage (const char *path, const unsigned int flags)
 Loads an image as a texture. More...
 
glTexturegl_newImageRWops (const char *path, SDL_RWops *rw, const unsigned int flags)
 Loads an image as a texture. More...
 
glTexturegl_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. More...
 
glTexturegl_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. More...
 
void gl_freeTexture (glTexture *texture)
 Frees a texture. More...
 
glTexturegl_dupTexture (const glTexture *texture)
 Duplicates a texture. More...
 
int gl_isTrans (const glTexture *t, const int x, const int y)
 Checks to see if a pixel is transparent in a texture. More...
 
void gl_getSpriteFromDir (int *x, int *y, const glTexture *t, const double dir)
 Sets x and y to be the appropriate sprite for glTexture using dir. More...
 
glTexture ** gl_copyTexArray (glTexture **tex, int *n)
 Copy a texture array. More...
 
int gl_initTextures (void)
 Initializes the opengl texture subsystem. More...
 
void gl_exitTextures (void)
 Cleans up the opengl texture subsystem. More...
 
glTexture ** gl_addTexArray (glTexture **tex, int *n, glTexture *t)
 Adds an element to a texture array. More...
 

Variables

static glTexListtexture_list = NULL
 

Detailed Description

This file handles the opengl texture wrapper routines.

Definition in file opengl_tex.c.

Function Documentation

◆ gl_addTexArray()

glTexture ** gl_addTexArray ( glTexture **  tex,
int *  n,
glTexture t 
)

Adds an element to a texture array.

Definition at line 934 of file opengl_tex.c.

◆ gl_copyTexArray()

glTexture ** gl_copyTexArray ( glTexture **  tex,
int *  n 
)

Copy a texture array.

Definition at line 892 of file opengl_tex.c.

◆ gl_dupTexture()

glTexture * gl_dupTexture ( const glTexture texture)

Duplicates a texture.

Parameters
textureTexture to duplicate.
Returns
Duplicate of texture.

Definition at line 809 of file opengl_tex.c.

◆ gl_exitTextures()

void gl_exitTextures ( void  )

Cleans up the opengl texture subsystem.

Definition at line 921 of file opengl_tex.c.

◆ gl_fboCreate()

int gl_fboCreate ( GLuint *  fbo,
GLuint *  tex,
GLsizei  width,
GLsizei  height 
)

Creates a framebuffer and its associated texture.

Parameters
[out]fboFramebuffer object id.
[out]texTexture id.
widthWidth to use.
heightHeight to use.
Returns
0 on success.

Definition at line 203 of file opengl_tex.c.

◆ gl_freeTexture()

void gl_freeTexture ( glTexture texture)

Frees a texture.

Parameters
textureTexture to free. (If NULL, function does nothing.)

Definition at line 755 of file opengl_tex.c.

◆ gl_getSpriteFromDir()

void gl_getSpriteFromDir ( int *  x,
int *  y,
const glTexture t,
const double  dir 
)

Sets x and y to be the appropriate sprite for glTexture using dir.

Very slow, try to cache if possible like the pilots do instead of using in O(n^2) or worse functions.

Parameters
[out]xX sprite to use.
[out]yY sprite to use.
tTexture to get sprite from.
dirDirection to get sprite from.

Definition at line 857 of file opengl_tex.c.

◆ gl_initTextures()

int gl_initTextures ( void  )

Initializes the opengl texture subsystem.

Returns
0 on success.

Definition at line 913 of file opengl_tex.c.

◆ gl_isTrans()

int gl_isTrans ( const glTexture t,
const int  x,
const int  y 
)

Checks to see if a pixel is transparent in a texture.

Parameters
tTexture to check for transparency.
xX position of the pixel.
yY position of the pixel.
Returns
1 if the pixel is transparent or 0 if it isn't.

Definition at line 838 of file opengl_tex.c.

◆ gl_loadImage()

glTexture * gl_loadImage ( SDL_Surface *  surface,
unsigned int  flags 
)

Loads the SDL_Surface to a glTexture.

Parameters
surfaceSurface to load.
flagsFlags to use.
Returns
The glTexture for surface.

Definition at line 493 of file opengl_tex.c.

◆ gl_loadImageData()

glTexture * gl_loadImageData ( float *  data,
int  w,
int  h,
int  sx,
int  sy,
const char *  name 
)

Definition at line 237 of file opengl_tex.c.

◆ gl_loadImagePad()

glTexture * gl_loadImagePad ( const char *  name,
SDL_Surface *  surface,
unsigned int  flags,
int  w,
int  h,
int  sx,
int  sy,
int  freesur 
)

Loads the already padded SDL_Surface to a glTexture.

Parameters
nameName to load with.
surfaceSurface to load.
flagsFlags to use.
wNon-padded width.
hNon-padded height.
sxX sprites.
syY sprites.
freesurWhether or not to free the surface.
Returns
The glTexture for surface.

Definition at line 444 of file opengl_tex.c.

◆ gl_loadImagePadTrans()

glTexture * gl_loadImagePadTrans ( const char *  name,
SDL_Surface *  surface,
SDL_RWops *  rw,
unsigned int  flags,
int  w,
int  h,
int  sx,
int  sy,
int  freesur 
)

Wrapper for gl_loadImagePad that includes transparency mapping.

Parameters
nameName to load with.
surfaceSurface to load.
rwRWops containing data to hash.
flagsFlags to use.
wNon-padded width.
hNon-padded height.
sxX sprites.
syY sprites.
freesurWhether or not to free the surface.
Returns
The glTexture for surface.

Definition at line 331 of file opengl_tex.c.

◆ gl_loadNewImage()

static glTexture * gl_loadNewImage ( const char *  path,
const unsigned int  flags 
)
static

Only loads the image, does not add to stack unlike gl_newImage.

Parameters
pathImage to load.
flagsFlags to control image parameters.
Returns
Texture loaded from image.

Definition at line 615 of file opengl_tex.c.

◆ gl_loadNewImageRWops()

static glTexture * gl_loadNewImageRWops ( const char *  path,
SDL_RWops *  rw,
unsigned int  flags 
)
static

Only loads the image, does not add to stack unlike gl_newImage.

Parameters
pathOnly used for debugging. Can be set to NULL.
rwSDL_Rwops structure to use to load.
flagsFlags to control image parameters.
Returns
Texture loaded from image.

Definition at line 646 of file opengl_tex.c.

◆ gl_loadSurface()

static GLuint gl_loadSurface ( SDL_Surface *  surface,
unsigned int  flags,
int  freesur 
)
static

Loads a surface into an opengl texture.

Parameters
surfaceSurface to load into a texture.
flagsFlags to use.
freesurWhether or not to free the surface.
Returns
The opengl texture id.

Definition at line 280 of file opengl_tex.c.

◆ gl_newImage()

glTexture * gl_newImage ( const char *  path,
const unsigned int  flags 
)

Loads an image as a texture.

May not necessarily load the image but use one if it's already open.

Parameters
pathImage to load.
flagsFlags to control image parameters.
Returns
Texture loaded from image.

Definition at line 570 of file opengl_tex.c.

◆ gl_newImageRWops()

glTexture * gl_newImageRWops ( const char *  path,
SDL_RWops *  rw,
const unsigned int  flags 
)

Loads an image as a texture.

May not necessarily load the image but use one if it's already open.

Note
Does not close the SDL_RWops file.
Parameters
pathPath name used for checking cache and error reporting.
rwSDL_RWops structure to load from.
flagsFlags to control image parameters.
Returns
Texture loaded from image.

Definition at line 595 of file opengl_tex.c.

◆ gl_newSprite()

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.

Parameters
pathImage to load.
sxNumber of X sprites in image.
syNumber of Y sprites in image.
flagsFlags to control image parameters.
Returns
Texture loaded.

Definition at line 684 of file opengl_tex.c.

◆ gl_newSpriteRWops()

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.

Parameters
pathImage name for deduplication.
rwSDL_RWops structure to load for.
sxNumber of X sprites in image.
syNumber of Y sprites in image.
flagsFlags to control image parameters.
Returns
Texture loaded.

Definition at line 722 of file opengl_tex.c.

◆ gl_texAdd()

static int gl_texAdd ( glTexture tex,
int  sx,
int  sy 
)
static

Adds a texture to the list under the name of path.

Definition at line 537 of file opengl_tex.c.

◆ gl_texExists()

static glTexture * gl_texExists ( const char *  path,
int  sx,
int  sy 
)
static

Check to see if a texture matching a path already exists.

Note this increments the used counter if it exists.

Parameters
pathPath to the texture.
sxX sprites.
syY sprites.
Returns
The texture, or NULL if none was found.

Definition at line 508 of file opengl_tex.c.

◆ gl_texParameters()

static GLuint gl_texParameters ( unsigned int  flags)
static

Sets default texture parameters.

Definition at line 162 of file opengl_tex.c.

◆ gl_transSize()

static size_t gl_transSize ( const int  w,
const int  h 
)
static

Definition at line 153 of file opengl_tex.c.

◆ SDL_IsTrans()

static int SDL_IsTrans ( SDL_Surface *  s,
int  x,
int  y 
)
static

Checks to see if a position of the surface is transparent.

Parameters
sSurface to check for transparency.
xX position of the pixel to check.
yY position of the pixel to check.
Returns
0 if the pixel isn't transparent, 0 if it is.

Definition at line 70 of file opengl_tex.c.

◆ SDL_MapTrans()

static uint8_t * SDL_MapTrans ( SDL_Surface *  s,
int  w,
int  h 
)
static

Maps the surface transparency.

Basically generates a map of what pixels are transparent. Good for pixel perfect collision routines.

Parameters
sSurface to map it's transparency.
wWidth to map.
hHeight to map.
Returns
0 on success.

Definition at line 118 of file opengl_tex.c.

Variable Documentation

◆ texture_list

glTexList* texture_list = NULL
static

Texture list.

Definition at line 44 of file opengl_tex.c.