2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Bmpman/BmpMan.h $
15 * Prototypes for Bitmap Manager functions
18 * Revision 1.2 2002/06/09 04:41:12 relnev
19 * added copyright header
21 * Revision 1.1.1.1 2002/05/03 03:28:11 root
25 * 16 8/10/99 6:54p Dave
26 * Mad optimizations. Added paging to the nebula effect.
28 * 15 8/06/99 1:52p Dave
29 * Bumped up MAX_BITMAPS for the demo.
31 * 14 7/15/99 9:20a Andsager
32 * FS2_DEMO initial checkin
34 * 13 7/13/99 1:15p Dave
35 * 32 bit support. Whee!
37 * 12 6/29/99 10:35a Dave
38 * Interface polygon bitmaps! Whee!
40 * 11 6/16/99 4:06p Dave
41 * New pilot info popup. Added new draw-bitmap-as-poly function.
43 * 10 5/05/99 9:02p Dave
44 * Fixed D3D aabitmap rendering. Spiffed up nebula effect a bit (added
45 * rotations, tweaked values, made bitmap selection more random). Fixed
46 * D3D beam weapon clipping problem. Added D3d frame dumping.
48 * 9 2/08/99 5:07p Dave
49 * FS2 chat server support. FS2 specific validated missions.
51 * 8 2/05/99 12:52p Dave
52 * Fixed Glide nondarkening textures.
54 * 7 2/03/99 11:44a Dave
55 * Fixed d3d transparent textures.
57 * 6 12/06/98 2:36p Dave
58 * Drastically improved nebula fogging.
60 * 5 12/01/98 4:46p Dave
61 * Put in targa bitmap support (16 bit).
63 * 4 12/01/98 8:06a Dave
64 * Temporary checkin to fix some texture transparency problems in d3d.
66 * 3 11/30/98 1:07p Dave
67 * 16 bit conversion, first run.
69 * 2 10/07/98 10:52a Dave
72 * 1 10/07/98 10:48a Dave
74 * 32 4/16/98 6:31p Hoffoss
75 * Added function to get filename of a bitmap handle, which we don't have
78 * 31 4/02/98 11:40a Lawrance
79 * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
81 * 30 3/30/98 4:02p John
82 * Made machines with < 32 MB of RAM use every other frame of certain
83 * bitmaps. Put in code to ke7ep track of how much RAM we've malloc'd.
85 * 29 3/29/98 4:05p John
86 * New paging code that loads everything necessary at level startup.
88 * 28 3/26/98 5:21p John
89 * Added new code to preload all bitmaps at the start of a level.
90 * Commented it out, though.
92 * 27 3/24/98 6:18p John
93 * Hacked MAX_BITMAPS up to 3500
95 * 26 3/10/98 4:18p John
96 * Cleaned up graphics lib. Took out most unused gr functions. Made D3D
97 * & Glide have popups and print screen. Took out all >8bpp software
98 * support. Made Fred zbuffer. Made zbuffer allocate dynamically to
99 * support Fred. Made zbuffering key off of functions rather than one
102 * 25 3/02/98 6:46p John
103 * Upped MAX_BITMAPS to 2000
105 * 24 3/02/98 6:00p John
106 * Moved MAX_BITMAPS into BmpMan.h so the stuff in the graphics code that
107 * is dependent on it won't break if it changes. Made ModelCache slots
108 * be equal to MAX_OBJECTS which is what it is.
110 * 23 2/06/98 8:25p John
111 * Added code for new bitmaps since last frame
113 * 22 2/06/98 8:10p John
114 * Added code to show amout of texture usage each frame.
116 * 21 1/29/98 11:48a John
117 * Added new counter measure rendering as model code. Made weapons be
118 * able to have impact explosion.
120 * 20 1/11/98 2:14p John
121 * Changed a lot of stuff that had to do with bitmap loading. Made cfile
122 * not do callbacks, I put that in global code. Made only bitmaps that
123 * need to load for a level load.
125 * 19 9/03/97 4:19p John
126 * changed bmpman to only accept ani and pcx's. made passing .pcx or .ani
127 * to bm_load functions not needed. Made bmpman keep track of palettes
128 * for bitmaps not mapped into game palettes.
130 * 18 8/25/97 11:14p Lawrance
131 * added support for .ani files in bm_load_animation()
133 * 17 7/16/97 3:07p John
135 * 16 6/17/97 8:58p Lawrance
136 * fixed bug with not nulling bm.data with USER bitmaps
138 * 15 6/12/97 2:44a Lawrance
139 * changed bm_unlock() to take an index into bm_bitmaps(). Added
140 * ref_count to bitmap_entry struct
142 * 14 5/20/97 10:36a John
143 * Fixed problem with user bitmaps and direct3d caching.
145 * 13 3/24/97 3:25p John
146 * Cleaned up and restructured model_collide code and fvi code. In fvi
147 * made code that finds uvs work.. Added bm_get_pixel to BmpMan.
149 * 12 2/17/97 5:18p John
150 * Added a bunch of RCS headers to a bunch of old files that don't have
162 #define MAX_BITMAPS 3500
164 #define MAX_BITMAPS 3500 // How many bitmaps the game can handle
167 // 16 bit pixel formats
168 #define BM_PIXEL_FORMAT_ARGB 0 // for glide - can assume certain things, like 1555 LFB writes, whee!
169 #define BM_PIXEL_FORMAT_D3D 1 // d3d - card dependant. booo!
170 #define BM_PIXEL_FORMAT_ARGB_D3D 2 // this card has nice 1555 textures like Glide - ahhhhh!
172 // 16 bit pixel formats
173 extern int Bm_pixel_format;
175 #define BYTES_PER_PIXEL(x) ((x+7)/8)
177 // how many bytes of textures are used.
178 extern int bm_texture_ram;
180 // This loads a bitmap so we can draw with it later.
181 // It returns a negative number if it couldn't load
182 // the bitmap. On success, it returns the bitmap
184 int bm_load(char * filename);
186 // special load function. basically allows you to load a bitmap which already exists (by filename).
187 // this is useful because in some cases we need to have a bitmap which is locked in screen format
188 // _and_ texture format, such as pilot pics and squad logos
189 int bm_load_duplicate(char *filename);
191 // Creates a bitmap that exists in RAM somewhere, instead
192 // of coming from a disk file. You pass in a pointer to a
193 // block of data. The data can be in the following formats:
194 // 8 bpp (mapped into game palette)
196 // On success, it returns the bitmap number. You cannot
197 // free that RAM until bm_release is called on that bitmap.
198 // See example at bottom of this file
199 int bm_create( int bpp, int w, int h, void * data, int flags = 0);
201 // Frees up a bitmap's data, but bitmap number 'n' can
202 // still be used, it will just have to be paged in next
203 // time it is locked.
204 int bm_unload( int n );
206 // Frees up a bitmap's data, and it's slot, so bitmap
207 // number 'n' cannot be used anymore, and bm_load or
208 // bm_create might reuse the slot.
209 void bm_release(int n);
211 // This loads a bitmap sequence so we can draw with it later.
212 // It returns a negative number if it couldn't load
213 // the bitmap. On success, it returns the bitmap
214 // number of the first frame and nframes is set.
215 extern int bm_load_animation( char * filename, int * nframes, int *fps = NULL, int can_drop_frames = 0 );
217 // This locks down a bitmap and returns a pointer to a bitmap
218 // that can be accessed until you call bm_unlock. Only lock
219 // a bitmap when you need it! This will convert it into the
220 // appropriate format also.
221 extern bitmap * bm_lock( int bitmapnum, ubyte bpp, ubyte flags );
223 // The signature is a field that gets filled in with
224 // a unique signature for each bitmap. The signature for each bitmap
225 // will also change when the bitmap's data changes.
226 extern uint bm_get_signature( int bitmapnum);
229 extern void bm_unlock( int bitmapnum );
231 // Gets info. w,h,or flags,nframes or fps can be NULL if you don't care.
232 extern void bm_get_info( int bitmapnum, int *w=NULL, int * h=NULL, ubyte * flags=NULL, int *nframes=NULL, int *fps=NULL, bitmap_section_info **sections = NULL );
235 extern void bm_get_filename(int bitmapnum, char *filename);
237 // resyncs all the bitmap palette
238 extern void bm_update();
240 // call to load all data for all bitmaps that have been requested to be loaded
241 extern void bm_load_all();
242 extern void bm_unload_all();
244 // call to get the palette for a bitmap
245 extern void bm_get_palette(int n, ubyte *pal, char *name);
247 // Hacked function to get a pixel from a bitmap.
248 // Only works good in 8bpp mode.
249 void bm_get_pixel( int bitmap, float u, float v, ubyte *r, ubyte *g, ubyte *b );
251 // Returns number of bytes of bitmaps locked this frame
252 // ntotal = number of bytes of bitmaps locked this frame
253 // nnew = number of bytes of bitmaps locked this frame that weren't locked last frame
254 void bm_get_frame_usage(int *ntotal, int *nnew);
257 * Example on using bm_create
260 static int test_inited = 0;
262 static uint test_bmp_data[128*64];
264 if ( !test_inited ) {
266 // Create the new bitmap and fill in its data.
267 // When you're done with it completely, call
268 // bm_release to free up the bitmap handle
269 test_bmp = bm_create( 32, 128, 64, test_bmp_data );
271 for (i=0; i<64; i++ ) {
272 for (j=0; j<64; j++ ) {
274 test_bmp_data[j+i*128] = r;
279 bm_unload(test_bmp); // this pages out the data, so that the
280 // next bm_lock will convert the new data to the
287 for (x=0; x<128; x++ )
288 test_bmp_data[y*128+x] = 15;
290 // Draw the bitmap to upper left corner
291 gr_set_bitmap(test_bmp);
297 //============================================================================
299 //============================================================================
301 void bm_page_in_start();
302 void bm_page_in_stop();
304 // Paging code in a library should call these functions
305 // in its page in function.
307 // Marks a texture as being used for this level
308 // If num_frames is passed, assume this is an animation
309 void bm_page_in_texture( int bitmapnum, int num_frames=1 );
311 // Marks a texture as being used for this level
312 // If num_frames is passed, assume this is an animation
313 void bm_page_in_nondarkening_texture( int bitmap, int num_frames=1 );
315 // marks a texture as being a transparent textyre used for this level
316 // Marks a texture as being used for this level
317 // If num_frames is passed, assume this is an animation
318 void bm_page_in_xparent_texture( int bitmapnum, int num_frames=1 );
320 // Marks an aabitmap as being used for this level
321 // If num_frames is passed, assume this is an animation
322 void bm_page_in_aabitmap( int bitmapnum, int num_frames=1 );
325 // Mode: 0 = High memory
326 // 1 = Low memory ( every other frame of ani's)
327 // 2 = Debug low memory ( only use first frame of each ani )
328 void bm_set_low_mem( int mode );
330 char *bm_get_filename(int handle);
332 void BM_SELECT_SCREEN_FORMAT();
333 void BM_SELECT_TEX_FORMAT();
334 void BM_SELECT_ALPHA_TEX_FORMAT();
336 // convert a 24 bit value to a 16 bit value
337 void bm_24_to_16(int bit_24, ushort *bit_16);
339 // set the rgba components of a pixel, any of the parameters can be NULL
340 extern void (*bm_set_components)(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
341 void bm_set_components_argb(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
342 void bm_set_components_d3d(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
343 void bm_set_components_argb_d3d_16_screen(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
344 void bm_set_components_argb_d3d_32_screen(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
345 void bm_set_components_argb_d3d_16_tex(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
346 void bm_set_components_argb_d3d_32_tex(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
348 // get the rgba components of a pixel, any of the parameters can be NULL
349 void bm_get_components(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
351 //============================================================================
352 // section info stuff
353 //============================================================================
355 // given a bitmap and a section, return the size (w, h)
356 void bm_get_section_size(int bitmapnum, int sx, int sy, int *w, int *h);