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