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