]> icculus.org git repositories - taylor/freespace2.git/blob - include/bmpman.h
const-char warning fixes
[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 // 16 bit pixel formats
171 #define BM_PIXEL_FORMAT_ARGB                            0                                               // for glide - can assume certain things, like 1555 LFB writes, whee!
172 #define BM_PIXEL_FORMAT_D3D                             1                                               // d3d - card dependant. booo!
173 #define BM_PIXEL_FORMAT_ARGB_D3D                        2                                               // this card has nice 1555 textures like Glide - ahhhhh!
174
175 // 16 bit pixel formats
176 extern int Bm_pixel_format;
177
178 #define BYTES_PER_PIXEL(x)      ((x+7)/8)
179
180 // how many bytes of textures are used.
181 extern int bm_texture_ram;
182
183 // This loads a bitmap so we can draw with it later.
184 // It returns a negative number if it couldn't load
185 // the bitmap.   On success, it returns the bitmap
186 // number.
187 int bm_load(const char * filename);
188
189 // special load function. basically allows you to load a bitmap which already exists (by filename). 
190 // this is useful because in some cases we need to have a bitmap which is locked in screen format
191 // _and_ texture format, such as pilot pics and squad logos
192 int bm_load_duplicate(const char *filename);
193
194 // Creates a bitmap that exists in RAM somewhere, instead
195 // of coming from a disk file.  You pass in a pointer to a
196 // block of data.  The data can be in the following formats:
197 // 8 bpp (mapped into game palette)
198 // 32 bpp
199 // On success, it returns the bitmap number.  You cannot 
200 // free that RAM until bm_release is called on that bitmap.  
201 // See example at bottom of this file
202 int bm_create( int bpp, int w, int h, void * data, int flags = 0);
203
204 // Frees up a bitmap's data, but bitmap number 'n' can
205 // still be used, it will just have to be paged in next
206 // time it is locked.
207 int bm_unload( int n );
208
209 // Frees up a bitmap's data, and it's slot, so bitmap 
210 // number 'n' cannot be used anymore, and bm_load or
211 // bm_create might reuse the slot.
212 void bm_release(int n);
213
214 // This loads a bitmap sequence so we can draw with it later.
215 // It returns a negative number if it couldn't load
216 // the bitmap.   On success, it returns the bitmap
217 // number of the first frame and nframes is set.
218 extern int bm_load_animation( const char * filename, int * nframes, int *fps = NULL, int can_drop_frames = 0 );
219
220 // This locks down a bitmap and returns a pointer to a bitmap
221 // that can be accessed until you call bm_unlock.   Only lock
222 // a bitmap when you need it!  This will convert it into the 
223 // appropriate format also.
224 extern bitmap * bm_lock( int bitmapnum, ubyte bpp, ubyte flags );
225
226 // The signature is a field that gets filled in with 
227 // a unique signature for each bitmap.  The signature for each bitmap
228 // will also change when the bitmap's data changes.
229 extern uint bm_get_signature( int bitmapnum);
230
231 // Unlocks a bitmap
232 extern void bm_unlock( int bitmapnum );
233
234 // Gets info.   w,h,or flags,nframes or fps can be NULL if you don't care.
235 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 );
236
237 // get filename
238 extern void bm_get_filename(int bitmapnum, char *filename);
239
240 // resyncs all the bitmap palette
241 extern void bm_update();
242
243 // call to load all data for all bitmaps that have been requested to be loaded
244 extern void bm_load_all();
245 extern void bm_unload_all();
246
247 // call to get the palette for a bitmap
248 extern void bm_get_palette(int n, ubyte *pal, char *name);
249
250 // Hacked function to get a pixel from a bitmap.
251 // Only works good in 8bpp mode.
252 void bm_get_pixel( int bitmap, float u, float v, ubyte *r, ubyte *g, ubyte *b );
253
254 // Returns number of bytes of bitmaps locked this frame
255 // ntotal = number of bytes of bitmaps locked this frame
256 // nnew = number of bytes of bitmaps locked this frame that weren't locked last frame
257 void bm_get_frame_usage(int *ntotal, int *nnew);
258
259 /* 
260  * Example on using bm_create
261  * 
262         {
263                 static int test_inited = 0;
264                 static int test_bmp;
265                 static uint test_bmp_data[128*64];
266
267                 if ( !test_inited )     {
268                         test_inited = 1;
269                         // Create the new bitmap and fill in its data.
270                         // When you're done with it completely, call
271                         // bm_release to free up the bitmap handle
272                         test_bmp = bm_create( 32, 128, 64, test_bmp_data );
273                         int i,j;
274                         for (i=0; i<64; i++ )   {
275                                 for (j=0; j<64; j++ )   {
276                                         uint r=i*4;
277                                         test_bmp_data[j+i*128] = r;
278                                 }
279                         }
280                 }
281
282                 bm_unload(test_bmp);    // this pages out the data, so that the
283                                                                         // next bm_lock will convert the new data to the
284                                                                         // correct bpp
285
286                 // put in new data
287                 int x,y;
288                 gr_reset_clip();
289                 for (y=0; y<64; y++)
290                         for (x=0; x<128; x++ )
291                                 test_bmp_data[y*128+x] = 15;
292
293                 // Draw the bitmap to upper left corner
294                 gr_set_bitmap(test_bmp);
295                 gr_bitmap( 0,0 );
296         }
297 */
298
299
300 //============================================================================
301 // Paging stuff
302 //============================================================================
303
304 void bm_page_in_start();
305 void bm_page_in_stop();
306
307 // Paging code in a library should call these functions
308 // in its page in function.
309
310 // Marks a texture as being used for this level
311 // If num_frames is passed, assume this is an animation
312 void bm_page_in_texture( int bitmapnum, int num_frames=1 );
313
314 // Marks a texture as being used for this level
315 // If num_frames is passed, assume this is an animation
316 void bm_page_in_nondarkening_texture( int bitmap, int num_frames=1 );
317
318 // marks a texture as being a transparent textyre used for this level
319 // Marks a texture as being used for this level
320 // If num_frames is passed, assume this is an animation
321 void bm_page_in_xparent_texture( int bitmapnum, int num_frames=1 );
322
323 // Marks an aabitmap as being used for this level
324 // If num_frames is passed, assume this is an animation
325 void bm_page_in_aabitmap( int bitmapnum, int num_frames=1 );
326
327 // 
328 // Mode: 0 = High memory
329 //       1 = Low memory ( every other frame of ani's)
330 //       2 = Debug low memory ( only use first frame of each ani )
331 void bm_set_low_mem( int mode );
332
333 char *bm_get_filename(int handle);
334
335 void BM_SELECT_SCREEN_FORMAT();
336 void BM_SELECT_TEX_FORMAT();
337 void BM_SELECT_ALPHA_TEX_FORMAT();
338
339 // convert a 24 bit value to a 16 bit value
340 void bm_24_to_16(int bit_24, ushort *bit_16);
341
342 // set the rgba components of a pixel, any of the parameters can be NULL
343 extern void (*bm_set_components)(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
344 void bm_set_components_argb(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
345 void bm_set_components_d3d(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
346 void bm_set_components_argb_d3d_16_screen(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
347 void bm_set_components_argb_d3d_32_screen(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
348 void bm_set_components_argb_d3d_16_tex(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
349 void bm_set_components_argb_d3d_32_tex(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
350
351 // get the rgba components of a pixel, any of the parameters can be NULL
352 void bm_get_components(ubyte *pixel, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
353
354 //============================================================================
355 // section info stuff
356 //============================================================================
357
358 // given a bitmap and a section, return the size (w, h)
359 void bm_get_section_size(int bitmapnum, int sx, int sy, int *w, int *h);
360
361 #endif
362