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