FS2_Open
Open source remastering of the Freespace 2 engine
bmpman.h
Go to the documentation of this file.
1 #ifndef _BMPMAN_H
2 #define _BMPMAN_H
3 /*
4  * Copyright (C) Volition, Inc. 1999. All rights reserved.
5  *
6  * All source code herein is the property of Volition, Inc. You may not sell
7  * or otherwise commercially exploit the source or things you created based on the
8  * source.
9  *
10  */
11 
22 #include "cfile/cfile.h"
23 #include "globalincs/pstypes.h"
24 
25 #ifndef NDEBUG
26 #define BMPMAN_NDEBUG
27 #endif
28 
48 #define MAX_BITMAPS 4750
49 
50 // Flag positions for bitmap.flags
51 // ***** NOTE: bitmap.flags is an 8-bit value, no more BMP_TEX_* flags can be added unless the type is changed!! ******
52 #define BMP_AABITMAP (1<<0)
53 #define BMP_TEX_XPARENT (1<<1)
54 #define BMP_TEX_OTHER (1<<2)
55 #define BMP_TEX_DXT1 (1<<3)
56 #define BMP_TEX_DXT3 (1<<4)
57 #define BMP_TEX_DXT5 (1<<5)
58 #define BMP_TEX_CUBEMAP (1<<6)
59 
60 // Combined flags
61 #define BMP_TEX_COMP ( BMP_TEX_DXT1 | BMP_TEX_DXT3 | BMP_TEX_DXT5 )
62 #define BMP_TEX_NONCOMP ( BMP_TEX_XPARENT | BMP_TEX_OTHER )
63 #define BMP_TEX_ANY ( BMP_TEX_COMP | BMP_TEX_NONCOMP )
64 
65 // Flag positions for bitmap.type
66 #define BMP_FLAG_RENDER_TARGET_STATIC (1<<0)
67 #define BMP_FLAG_RENDER_TARGET_DYNAMIC (1<<1)
68 #define BMP_FLAG_CUBEMAP (1<<2)
69 
70 // Bitmap types
71 enum BM_TYPE
72 {
82 
83  // special types
86 
87  // Compressed types (bitmap.c_type)
95 };
96 
101 struct bitmap
102 {
103  short w;
104  short h;
105  short rowsize;
113 };
114 
115 extern int bm_texture_ram;
116 
117 extern int Bm_paging;
118 
119 extern const BM_TYPE bm_type_list[];
120 extern const char *bm_ext_list[];
121 extern const int BM_NUM_TYPES;
122 extern const BM_TYPE bm_ani_type_list[];
123 extern const char *bm_ani_ext_list[];
124 extern const int BM_ANI_NUM_TYPES;
125 
126 extern int GLOWMAP;
127 extern int SPECMAP;
128 extern int ENVMAP;
129 extern int NORMMAP;
130 extern int HEIGHTMAP;
131 extern int MISCMAP;
132 
136 void bm_init();
137 
141 void bm_close();
142 
152 int bm_get_cache_slot(int bitmap_id, int separate_ani_frames);
153 
157 int bm_get_next_handle();
158 
168 void *bm_malloc(int handle, int size);
169 
175 void bm_update_memory_used(int n, int size);
176 
178  ubyte *Bitmap_data;
179 
180  int Width;
181  int Height;
182  int Num_channels;
183 
184  float map_texture_address(float address);
185 public:
186  bitmap_lookup(int bitmap_num);
187  ~bitmap_lookup();
188 
189  bool valid();
190 
191  float get_channel_red(float u, float v);
192  float get_channel_green(float u, float v);
193  float get_channel_blue(float u, float v);
194  float get_channel_alpha(float u, float v);
195 };
196 
205 int bm_load(const char* filename);
206 
215 int bm_load(const SCP_string& filename);
216 
229 int bm_load_duplicate(const char *filename);
230 
242 int bm_create(int bpp, int w, int h, void *data = NULL, int flags = 0);
243 
257 int bm_unload(int handle, int clear_render_targets = 0, bool nodebug = false);
258 
270 int bm_unload_fast(int handle, int clear_render_targets = 0);
271 
287 int bm_release(int handle, int clear_render_targets = 0);
288 
302 int bm_load_animation(const char *filename, int *nframes = NULL, int *fps = NULL, int *keyframe = NULL, int can_drop_frames = 0, int dir_type = CF_TYPE_ANY);
303 
317 int bm_load_either(const char *filename, int *nframes = NULL, int *fps = NULL, int *keyframe = NULL, int can_drop_frames = 0, int dir_type = CF_TYPE_ANY);
318 
333 bitmap* bm_lock(int handle, ubyte bpp, ubyte flags, bool nodebug = false);
334 
340 uint bm_get_signature(int handle);
341 
345 BM_TYPE bm_get_type(int handle);
346 
353 void bm_unlock(int handle);
354 
368 int bm_is_valid(int handle);
369 
383 int bm_get_info(int handle, int *w = NULL, int * h = NULL, ubyte * flags = NULL, int *nframes = NULL, int *fps = NULL);
384 
392 void bm_get_filename(int bitmapnum, char *filename);
393 
405 const char *bm_get_filename(int handle);
406 
412 void bm_gfx_load_all();
413 
420 void bm_unload_all();
421 
430 void bm_get_palette(int handle, ubyte *pal, char *name);
431 
439 void bm_gfx_get_pixel(int bitmap, float u, float v, ubyte *r, ubyte *g, ubyte *b);
440 
451 void bm_get_frame_usage(int *ntotal, int *nnew);
452 
463 int bm_reload(int bitmap_handle, const char* filename);
464 
468 void bm_page_in_start();
469 
473 void bm_page_in_stop();
474 
475 // Paging code in a library should call these functions
476 // in its page in function.
477 
483 void bm_page_in_texture(int bitmapnum, int num_frames = 0);
484 
490 void bm_page_in_xparent_texture(int bitmapnum, int num_frames = 1);
491 
497 void bm_page_in_aabitmap(int bitmapnum, int num_frames = 1);
498 
506 bool bm_page_out(int handle);
507 
517 void bm_set_low_mem(int mode);
518 
523 
527 void BM_SELECT_TEX_FORMAT();
528 
533 
554 extern void(*bm_set_components)(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
555 
564 extern void(*bm_set_components_32)(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
565 
572 
579 
586 
593 
599 void bm_get_components(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
600 
604 int bm_is_compressed(int handle);
605 
609 int bm_get_tcache_type(int handle);
610 
614 size_t bm_get_size(int handle);
615 
619 int bm_get_num_mipmaps(int handle);
620 
626 bool bm_has_alpha_channel(int handle);
627 
631 void bm_print_bitmaps();
632 
641 int bm_make_render_target(int width, int height, int flags);
642 
649 int bm_is_render_target(int handle);
650 
657 bool bm_set_render_target(int handle, int face = -1);
658 
672 bool bm_load_and_parse_eff(const char *filename, int dir_type, int *nframes, int *nfps, int *key, BM_TYPE *type);
673 
674 #endif
cfbp dir_type
Definition: cfile.cpp:1069
void bm_set_low_mem(int mode)
Sets BMPMAN's memory mode.
Definition: bmpman.cpp:2803
ubyte bpp
Requested bitdepth of each pixel. ( 7, 8, 15, 16, 24, 32)
Definition: bmpman.h:106
generic DDS cubemap (uncompressed cubemap surface)
Definition: bmpman.h:91
int bm_unload(int handle, int clear_render_targets=0, bool nodebug=false)
Unloads a bitmap's data, but not the bitmap info.
Definition: bmpman.cpp:2890
const BM_TYPE bm_type_list[]
List of valid bitmap types.
Definition: bmpman.cpp:68
int bm_get_tcache_type(int handle)
Gets the correct TCACHE_TYPE for compressed graphics (uncompressed are assumed TCACHE_TYPE_NORMAL) ...
Definition: bmpman.cpp:887
void bm_get_palette(int handle, ubyte *pal, char *name)
Gets the palette for a given bitmap indexed by handle, and optionally the filename.
Definition: bmpman.cpp:850
GLfloat GLfloat GLfloat GLfloat h
Definition: Glext.h:7280
int bm_get_num_mipmaps(int handle)
Gets the number of mipmaps of the indexed texture.
Definition: bmpman.cpp:838
const char * bm_ext_list[]
List of extensions for those types.
Definition: bmpman.cpp:69
PCX.
Definition: bmpman.h:75
void bm_unlock(int handle)
Unlocks a bitmap.
Definition: bmpman.cpp:3005
24-bit cubemap (compressed cubemap surface)
Definition: bmpman.h:92
ubyte true_bpp
The image's actual bitdepth.
Definition: bmpman.h:107
ubyte flags
Various texture type flags.
Definition: bmpman.h:108
void bm_set_components_argb_32_screen(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a)
Sets the 32bpp screen pixel to the specified RGBA value.
Definition: bmpman.cpp:2780
bool bm_load_and_parse_eff(const char *filename, int dir_type, int *nframes, int *nfps, int *key, BM_TYPE *type)
Loads and parses an .EFF.
Definition: bmpman.cpp:1239
int bm_get_info(int handle, int *w=NULL, int *h=NULL, ubyte *flags=NULL, int *nframes=NULL, int *fps=NULL)
Gets info on the bitmap indexed by handle.
Definition: bmpman.cpp:769
bool bm_has_alpha_channel(int handle)
Checks to see if the indexed bitmap has an alpha channel.
Definition: bmpman.cpp:903
bool bm_page_out(int handle)
Unloads the bitmap indexed by handle that was previously paged-in.
Definition: bmpman.cpp:2559
enum_h * u
Definition: lua.cpp:12649
int bm_get_cache_slot(int bitmap_id, int separate_ani_frames)
Definition: bmpman.cpp:669
void bm_get_components(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a)
Gets the RGBA components of a pixel according to the selected mode.
Definition: bmpman.cpp:685
GLenum mode
Definition: Glext.h:5794
const int BM_NUM_TYPES
Calculated number of bitmap types.
Definition: bmpman.cpp:70
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
int key
void bm_update_memory_used(int n, int size)
(DEBUG) Similar to bm_malloc, but only updates how much memory is used
Definition: bmpman.cpp:3028
GLsizeiptr size
Definition: Glext.h:5496
void bm_get_frame_usage(int *ntotal, int *nnew)
(DEBUG) Gets memory size, in bytes, of the locked bitmaps
Definition: bmpman.cpp:749
No type.
Definition: bmpman.h:73
short h
Height, in number of pixels.
Definition: bmpman.h:104
32 bit with 8 bit alpha
Definition: bmpman.h:90
in-house ANI format
Definition: bmpman.h:80
int bm_reload(int bitmap_handle, const char *filename)
Reloads an existing bmpman slot with different bitmap.
Definition: bmpman.cpp:2699
GLenum type
Definition: Gl.h:1492
GLint GLsizei width
Definition: Gl.h:1505
ubyte * palette
Pointer to this bitmap's palette (if it has one).
Definition: bmpman.h:110
int bm_make_render_target(int width, int height, int flags)
Creates a render target as close to the desired resolution as possible.
Definition: bmpman.cpp:2267
int bm_unload_fast(int handle, int clear_render_targets=0)
Quickly unloads a bitmap's data, ignoring the load_count.
Definition: bmpman.cpp:2968
GLenum GLuint GLint GLenum face
Definition: Glext.h:6586
void bm_unload_all()
Unloads all used bitmaps, should only ever be called by game_shutdown()
Definition: bmpman.cpp:2952
void bm_set_components_argb_16_tex(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a)
Sets the 16bpp texture pixel to the specified RGBA value.
Definition: bmpman.cpp:2768
GLdouble GLdouble GLdouble r
Definition: Glext.h:5337
unsigned int uint
Definition: pstypes.h:64
GLboolean GLboolean g
Definition: Glext.h:5781
32 bit jpeg
Definition: bmpman.h:79
GLboolean GLboolean GLboolean GLboolean a
Definition: Glext.h:5781
int Bm_paging
Bool type that indicates if BMPMAN is currently paging.
Definition: bmpman.cpp:65
specifies any type of animated image, the EFF itself is just text
Definition: bmpman.h:81
char * filename
const BM_TYPE bm_ani_type_list[]
List of valid bitmap animation types.
Definition: bmpman.cpp:72
int bm_is_valid(int handle)
Checks if the bitmap indexed by handle is valid.
Definition: bmpman.cpp:1006
PNG.
Definition: bmpman.h:78
void(* bm_set_components)(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a)
Functional pointer that references any of the bm_set_components functions.
Definition: bmpman.cpp:76
24 bit with switchable alpha
Definition: bmpman.h:88
short w
Width, in number of pixels.
Definition: bmpman.h:103
BM_TYPE bm_get_type(int handle)
Returns the image type of the given bitmap handle.
Definition: bmpman.cpp:894
short rowsize
What you need to add to go to next row.
Definition: bmpman.h:105
32-bit cubemap (compressed cubemap surface)
Definition: bmpman.h:94
void bm_page_in_xparent_texture(int bitmapnum, int num_frames=1)
Marks a textures as being used for level and is transparant.
Definition: bmpman.cpp:2514
Definition: bmpman.h:101
int bm_load_either(const char *filename, int *nframes=NULL, int *fps=NULL, int *keyframe=NULL, int can_drop_frames=0, int dir_type=CF_TYPE_ANY)
Loads either animation (bm_load_animation) or still image (bm_load)
Definition: bmpman.cpp:1683
in-memory
Definition: bmpman.h:74
float get_channel_alpha(float u, float v)
Definition: bmpman.cpp:186
16 or 32 bit targa
Definition: bmpman.h:76
void BM_SELECT_ALPHA_TEX_FORMAT()
Sets bm_set_components and bm_get_components to reference texture format functions (with alpha) ...
Definition: bmpman.cpp:2721
BM_TYPE
Definition: bmpman.h:71
float get_channel_blue(float u, float v)
Definition: bmpman.cpp:176
void bm_page_in_texture(int bitmapnum, int num_frames=0)
Marks a texture as being used for this level.
Definition: bmpman.cpp:2462
void * bm_malloc(int handle, int size)
Allocates memory for the given handle.
Definition: bmpman.cpp:2339
int bm_create(int bpp, int w, int h, void *data=NULL, int flags=0)
Definition: bmpman.cpp:469
void bm_get_filename(int bitmapnum, char *filename)
Gets the filename of the bitmap indexed by handle.
Definition: bmpman.cpp:735
void bm_page_in_aabitmap(int bitmapnum, int num_frames=1)
Marks a texture as being used for this level, and is anti-aliased.
Definition: bmpman.cpp:2354
GLclampd n
Definition: Glext.h:7286
unsigned char ubyte
Definition: pstypes.h:62
bitmap_lookup(int bitmap_num)
Definition: bmpman.cpp:109
float get_channel_green(float u, float v)
Definition: bmpman.cpp:163
size_t bm_get_size(int handle)
Gets the size, in bytes, taken up by the bitmap indexed by handle.
Definition: bmpman.cpp:878
void bm_close()
Closes the bitmap manager, freeing any allocated memory used by bitmaps. Is called at program close...
Definition: bmpman.cpp:459
void bm_set_components_argb_32_tex(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a)
Sets the 32bpp texture pixel to the specified RGBA value.
Definition: bmpman.cpp:2791
const int BM_ANI_NUM_TYPES
Calculated number of bitmap animation types.
Definition: bmpman.cpp:74
void bm_gfx_load_all()
Loads all data for all bitmaps that have been requested to be loaded.
GLbitfield flags
Definition: Glext.h:6722
24/32 bit setup internally as a dynamic render target
Definition: bmpman.h:85
int MISCMAP
Utility map, to be utilized for various things shader authors can come up with.
Definition: bmpman.cpp:62
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
GLuint const GLchar * name
Definition: Glext.h:5608
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
int bm_is_render_target(int handle)
Checks to see if the given bitmap indexed by handle is a render target.
Definition: bmpman.cpp:993
void BM_SELECT_SCREEN_FORMAT()
Sets bm_set_components and bm_get_components to reference screen format functions.
Definition: bmpman.cpp:2733
GLint GLsizei GLsizei height
Definition: Gl.h:1505
GLubyte GLubyte GLubyte GLubyte w
Definition: Glext.h:5679
int bm_texture_ram
how many bytes of textures are used.
Definition: bmpman.cpp:64
uint bm_get_signature(int handle)
Returns a unique signiature for the bitmap indexed by handle.
Definition: bmpman.cpp:869
void bm_page_in_stop()
Tells bmpman to stop paging (?)
Definition: bmpman.cpp:2393
unsigned int ptr_u
Definition: pstypes.h:57
const char * bm_ani_ext_list[]
List of extensions for those types.
Definition: bmpman.cpp:73
generic identifier for DDS
Definition: bmpman.h:77
int bm_get_next_handle()
Gets the next available bitmap slot.
Definition: bmpman.cpp:820
bool bm_set_render_target(int handle, int face=-1)
(GR function) Calls gr_bm_set_render target for the given bitmap indexed by handle ...
Definition: bmpman.cpp:2810
int bm_is_compressed(int handle)
Returns the compression type of the bitmap indexed by handle.
Definition: bmpman.cpp:952
GLenum GLsizei GLenum GLenum const GLvoid * data
Definition: Gl.h:1509
int bm_release(int handle, int clear_render_targets=0)
Frees both a bitmap's data and it's associated slot.
Definition: bmpman.cpp:2603
24/32 bit setup internally as a static render target
Definition: bmpman.h:84
int HEIGHTMAP
Height map for normal mapping.
Definition: bmpman.cpp:61
ptr_u data
Pointer to data, or maybe offset into VRAM.
Definition: bmpman.h:109
void bm_set_components_argb_16_screen(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a)
Sets the 16bpp screen pixel to the specified RGBA value.
Definition: bmpman.cpp:2757
void bm_page_in_start()
Tells bmpman to start keeping track of what bitmaps are used where.
Definition: bmpman.cpp:2372
void bm_gfx_get_pixel(int bitmap, float u, float v, ubyte *r, ubyte *g, ubyte *b)
Hack to get a pixel from a bitmap.
int NORMMAP
Normal mapping.
Definition: bmpman.cpp:60
32-bit cubemap (compressed cubemap surface)
Definition: bmpman.h:93
void BM_SELECT_TEX_FORMAT()
Sets bm_set_components and bm_get_components to reference texture format functions.
Definition: bmpman.cpp:2745
int bm_load_animation(const char *filename, int *nframes=NULL, int *fps=NULL, int *keyframe=NULL, int can_drop_frames=0, int dir_type=CF_TYPE_ANY)
Loads a bitmap sequance so we can draw with it.
Definition: bmpman.cpp:1420
bitmap * bm_lock(int handle, ubyte bpp, ubyte flags, bool nodebug=false)
Locks down the bitmap indexed by bitmapnum.
Definition: bmpman.cpp:1754
bool valid()
Definition: bmpman.cpp:139
int bm_load_duplicate(const char *filename)
Reloads a bitmap as a duplicate.
Definition: bmpman.cpp:1668
void(* bm_set_components_32)(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a)
Functional pointer that references any of the bm_set_components_32 functions.
Definition: bmpman.cpp:77
#define CF_TYPE_ANY
Definition: cfile.h:42
float get_channel_red(float u, float v)
Definition: bmpman.cpp:150
const GLdouble * v
Definition: Glext.h:5322
int ENVMAP
References a map that is for environment mapping -Bobboau.
Definition: bmpman.cpp:59
32 bit with 4 bit alpha
Definition: bmpman.h:89
int bm_load(const char *filename)
Loads a bitmap so we can draw with it later.
Definition: bmpman.cpp:1119
void bm_print_bitmaps()
(DEBUG) Prints all loaded bitmaps to an outwindow
Definition: bmpman.cpp:2586
GLuint address
Definition: Glext.h:8864
void bm_init()
Initilizes the bitmap manager.
Definition: bmpman.cpp:916
int SPECMAP
References a map that is for specular mapping -Bobboau.
Definition: bmpman.cpp:58
int GLOWMAP
References a map that is a fully lit version of its index -Bobboau.
Definition: bmpman.cpp:57