#include <Assert.h>#include "WBitmap.h"#include "GBSPFile.h"#include "Ram.h"#include "Bitmap.h"#include "Errorlog.h"#include "Bitmap._h"Go to the source code of this file.
|
|
Definition at line 189 of file WBitmap.c. Referenced by geWBitmap_Pool_CreateAllWBitmaps(). |
|
|
Definition at line 41 of file WBitmap.c. Referenced by geWBitmap_Pool_Create(). |
|
|
|
|
|
|
|
|
Definition at line 515 of file WBitmap.c. References geWBitmap::Bitmap. Referenced by geWorld_BitmapListInit(), and RenderFace().
00516 {
00517 assert(WBitmap);
00518
00519 return WBitmap->Bitmap;
00520 }
|
|
|
Definition at line 505 of file WBitmap.c. References geWBitmap::Flags, and uint32. Referenced by geWorld_BitmapListInit().
00506 {
00507 assert(WBitmap);
00508
00509 return WBitmap->Flags;
00510 }
|
|
|
Definition at line 525 of file WBitmap.c. References int32, and geWBitmap::VisFrame. Referenced by geWorld_BitmapIsVisible().
00526 {
00527 assert(WBitmap);
00528
00529 return WBitmap->VisFrame;
00530 }
|
|
|
Definition at line 63 of file WBitmap.c. References GE_RAM_ALLOCATE_STRUCT, geErrorLog_AddString, geWBitmap_Pool_CreateAllWBitmaps(), geWBitmap_Pool_Destroy(), NULL, and ZeroMem. Referenced by geWorld_Create().
00064 {
00065 geWBitmap_Pool *Pool;
00066
00067 assert(BSPData);
00068
00069 Pool = GE_RAM_ALLOCATE_STRUCT(geWBitmap_Pool);
00070
00071 if (!Pool)
00072 {
00073 geErrorLog_AddString(-1, "geWBitmap_Pool_Create: Could not create the Pool. Out of memory.", NULL);
00074 goto ExitWithError;
00075 }
00076
00077 // Clear out the memory for the Pool
00078 ZeroMem(Pool);
00079
00080 // Create all the bitmaps from the bspdata... (this should eventually just stream right out of the file...)
00081 if (!geWBitmap_Pool_CreateAllWBitmaps(Pool, BSPData))
00082 {
00083 geErrorLog_AddString(-1, "geWBitmap_Pool_Create: geWBitmap_Pool_CreateAllWBitmaps failed.", NULL);
00084 goto ExitWithError;
00085 }
00086
00087 return Pool; // Done, good to go
00088
00089 // Error
00090 ExitWithError:
00091 {
00092 if (Pool)
00093 geWBitmap_Pool_Destroy(Pool);
00094
00095 return NULL;
00096 }
00097 }
|
|
||||||||||||
|
Definition at line 194 of file WBitmap.c. References DRV_RGB::b, geWBitmap::Bitmap, GFX_TexInfo::Flags, GFX_Texture::Flags, DRV_RGB::g, GE_FALSE, GE_PIXELFORMAT_32BIT_ARGB, GE_PIXELFORMAT_32BIT_XRGB, GE_RAM_ALLOCATE_ARRAY, GE_TRUE, geBitmap_Create(), geBitmap_GetBits(), geBitmap_GetInfo(), geBitmap_LockForWrite(), geBitmap_Palette_Create(), geBitmap_Palette_Destroy(), geBitmap_Palette_Lock(), geBitmap_Palette_UnLock(), geBitmap_SetColorKey(), geBitmap_SetDriverFlags(), geBitmap_SetPalette(), geBitmap_UnLock(), geBoolean, geErrorLog_AddString, gePixelFormat, geRam_Free, geWBitmap_Pool_DestroyAllWBitmaps(), GBSP_BSPData::GFXFaces, GBSP_BSPData::GFXPalettes, GBSP_BSPData::GFXTexData, GBSP_BSPData::GFXTexInfo, GBSP_BSPData::GFXTextures, GFX_Texture::Height, geBitmap_Info::Height, int32, MAX_MIPS_ALLOWED, geWBitmap::Name, GFX_Texture::Name, NULL, GBSP_BSPData::NumGFXFaces, GBSP_BSPData::NumGFXTextures, geWBitmap_Pool::NumWBitmaps, GFX_Texture::Offset, GFX_Texture::PaletteIndex, DRV_RGB::r, RDRIVER_PF_3D, RDRIVER_PF_COMBINE_LIGHTMAP, geBitmap_Info::Stride, GFX_Face::TexInfo, TEXINFO_TRANS, GFX_TexInfo::Texture, TEXTURE_SKYBOX, uint32, uint8, geWBitmap_Pool::WBitmaps, GFX_Texture::Width, and geBitmap_Info::Width. Referenced by geWBitmap_Pool_Create().
00195 {
00196 int32 i;
00197 geWBitmap *pWBitmap;
00198 GFX_Texture *pGFXTexture;
00199 uint8 *BitmapIsTransparent;
00200 GFX_Face *pFace;
00201 geBoolean UseColorKey;
00202 uint32 ColorKey;
00203
00204 assert(Pool);
00205 assert(BSPData);
00206 assert(Pool->NumWBitmaps == 0);
00207 assert(Pool->WBitmaps == NULL);
00208
00209 if (!BSPData->NumGFXTextures)
00210 return GE_TRUE;
00211
00212 assert(BSPData->GFXTextures);
00213
00214 // BitmapIsTransparent is a temporary array, that is filled in with a 1, if any face that uses it, has the
00215 // TEXINFO_TRANS flag set. If they expect to "see" thru the surface, then they should have set this flag
00216 // in the editor. If this flag is not set, then we won't allow a color key on the surface...
00217 BitmapIsTransparent = GE_RAM_ALLOCATE_ARRAY(uint8, BSPData->NumGFXTextures);
00218
00219 if (!BitmapIsTransparent)
00220 {
00221 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: Could not create the BitmapIsTransparent array. Out of memory.", NULL);
00222 goto ExitWithError;
00223 }
00224
00225 memset(BitmapIsTransparent,0,BSPData->NumGFXTextures);
00226
00227 // Now, go mark all the bitmaps that have transparent set in the texinfo
00228 pFace = BSPData->GFXFaces;
00229 for (i=0; i< BSPData->NumGFXFaces; i++, pFace++)
00230 {
00231 GFX_TexInfo *pTexInfo;
00232
00233 pTexInfo = &BSPData->GFXTexInfo[pFace->TexInfo];
00234
00235 assert(pTexInfo->Texture >= 0 || pTexInfo->Texture < BSPData->NumGFXTextures);
00236
00237 if (pTexInfo->Flags & TEXINFO_TRANS)
00238 {
00239 BitmapIsTransparent[pTexInfo->Texture] = 1; // This face has the transparent value set, so mark the bitmap it references
00240 }
00241 }
00242
00243 // Create the bitmap pool.
00244 Pool->WBitmaps = GE_RAM_ALLOCATE_ARRAY(geWBitmap, BSPData->NumGFXTextures);
00245
00246 if (!Pool->WBitmaps)
00247 {
00248 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: Could not create the Pool bitmaps. Out of memory.", NULL);
00249 goto ExitWithError;
00250 }
00251
00252 // Clear the bitmap array
00253 memset(Pool->WBitmaps,0,sizeof(geWBitmap)*BSPData->NumGFXTextures);
00254 Pool->NumWBitmaps = BSPData->NumGFXTextures; // Store the number of slots
00255
00256 pWBitmap = Pool->WBitmaps;
00257 pGFXTexture = BSPData->GFXTextures;
00258
00259 for (i=0; i< BSPData->NumGFXTextures; i++, pGFXTexture++, pWBitmap++)
00260 {
00261 geBitmap *Mips[MAX_MIPS_ALLOWED];
00262 int32 NumMips, m, Width, Height, Stride;
00263 uint8 *pSrc;
00264
00265 if (BitmapIsTransparent[i])
00266 {
00267 UseColorKey = GE_TRUE;
00268 //Start Dec2001DCS - ColorKey = 24 bit version of bright magenta. NOTE: Blue value is 254 (0xfe)
00269 // because I couldn't make a 24 bit bitmap
00270 // with MSPaint using the color
00271 // 255 0 255. Even though Paint said it
00272 // was the right value, by the time the
00273 // bitmap got to Genesis it was read as
00274 // 255 0 254 ???
00275 ColorKey = 0xffff00fe;
00276 //End Dec2001DCS
00277 }
00278 else
00279 {
00280 UseColorKey = GE_FALSE;
00281 ColorKey = 0;
00282 }
00283
00284 strcpy(pWBitmap->Name, pGFXTexture->Name);
00285
00286 // <> CB this is the main loop where GFX BSP textures are made into bitmaps
00287
00288 // Get width and height
00289 Width = pGFXTexture->Width;
00290 Height = pGFXTexture->Height;
00291
00292 if (pGFXTexture->Flags & TEXTURE_SKYBOX)
00293 NumMips = 1;
00294 else
00295 NumMips = 4;
00296
00297 assert(NumMips <= MAX_MIPS_ALLOWED);
00298
00299 // Create the bitmap
00300 //Start Dec2001DCS - Changed format to 32 bit
00301 // added transparent textures
00302 pWBitmap->Bitmap = geBitmap_Create(Width, Height, NumMips, GE_PIXELFORMAT_32BIT_ARGB);
00303 //End Dec2001DCS
00304
00305 if (!pWBitmap->Bitmap)
00306 {
00307 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: Could not create geBitmap.", NULL);
00308 goto ExitWithError;
00309 }
00310
00311 // Set the driver flags
00312 if (pGFXTexture->Flags & TEXTURE_SKYBOX)
00313 {
00314 geBitmap_SetDriverFlags(pWBitmap->Bitmap, RDRIVER_PF_3D); // Skybox textures do not need to combine with lightmaps
00315 }
00316 else
00317 {
00318 geBitmap_SetDriverFlags(pWBitmap->Bitmap, RDRIVER_PF_3D | RDRIVER_PF_COMBINE_LIGHTMAP);
00319 }
00320
00321 //<>
00322 NumMips = 1;
00323 // Lock all the miplevels
00324 if (!geBitmap_LockForWrite(pWBitmap->Bitmap, Mips, 0, NumMips-1))
00325 {
00326 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: geBitmap_LockForWrite failed.", NULL);
00327 goto ExitWithError;
00328 }
00329
00330 // Get the src from the .bsp texture data
00331 pSrc = &BSPData->GFXTexData[pGFXTexture->Offset];
00332
00333 // Fill all the mip levels
00334 for (m=0; m< NumMips; m++)
00335 {
00336 uint8 *pDest;
00337 geBitmap_Info Info;
00338
00339 if (!geBitmap_GetInfo(Mips[m], &Info, NULL))
00340 {
00341 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: geBitmap_GetInfo failed.", NULL);
00342 goto ExitWithError;
00343 }
00344
00345 pDest = geBitmap_GetBits(Mips[m]);
00346 assert( pDest );
00347
00348 Stride = Info.Stride;
00349 Width = Info.Width;
00350 Height = Info.Height;
00351
00352 assert(Stride >= Width);
00353
00354 if ( Stride == Width )
00355 {
00356 //Start Dec2001DCS - Added * 4 since textures are now 32 bit
00357 // added transparent textures
00358 memcpy(pDest,pSrc,Width*Height*4);
00359 //End Dec2001DCS
00360 }
00361 else
00362 {
00363 int h;
00364 for (h=Height;h--;)
00365 {
00366 //Start Dec2001DCS - Added * 4 since textures are now 32 bit
00367 // added transparent textures
00368 memcpy(pDest,pSrc,Width*4);
00369 //End Dec2001DCS
00370 pSrc += Width*4;
00371 pDest += Stride*4;
00372 }
00373 }
00374
00375 // Unlock this mip level, it is filled with the data
00376 if (!geBitmap_UnLock(Mips[m]))
00377 {
00378 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: geBitmap_Unlock failed.", NULL);
00379 goto ExitWithError;
00380 }
00381 }
00382
00383 // Create the palette...
00384 {
00385 geBitmap_Palette *Pal;
00386 int32 PalSize,cnt;
00387 gePixelFormat Format;
00388 uint32 *DstPalPtr,*DstPalData;
00389 DRV_RGB *SrcPalPtr;
00390
00391 //Pal = geBitmap_Palette_Create(GE_PIXELFORMAT_32BIT_ARGB, 256);
00392 Pal = geBitmap_Palette_Create(GE_PIXELFORMAT_32BIT_XRGB, 256);
00393
00394 if (!Pal)
00395 {
00396 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: geBitmap_Palette_Create failed.", NULL);
00397 return GE_FALSE;
00398 }
00399
00400 if (!geBitmap_Palette_Lock(Pal, &DstPalData, &Format, &PalSize))
00401 {
00402 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: geBitmap_Palette_Lock failed.", NULL);
00403 return GE_FALSE;
00404 }
00405
00406 //cnt = sizeof(DRV_Palette);
00407 // <> this doesn't seem to respect the pragma pack in dcommon !
00408 // I get size == 768
00409
00410 SrcPalPtr = BSPData->GFXPalettes[pGFXTexture->PaletteIndex];
00411 DstPalPtr = DstPalData;
00412 for(cnt=PalSize;cnt--;)
00413 {
00414 *DstPalPtr++ = ((uint32)0xFF000000) + ((SrcPalPtr->r)<<16) + ((SrcPalPtr->g)<<8) + (SrcPalPtr->b);
00415 SrcPalPtr ++;
00416 }
00417 //debug to see if anyone is using entry 255 :
00418 // DstPalData[255] = 255; // color key (it's bright blue & transparent)
00419 //or black it : DstPalData[255] = 0;
00420
00421 if (!geBitmap_Palette_UnLock(Pal))
00422 {
00423 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: geBitmap_Palette_UnLock failed.", NULL);
00424 return GE_FALSE;
00425 }
00426
00427 if (!geBitmap_SetPalette(pWBitmap->Bitmap, Pal))
00428 {
00429 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: geBitmap_SetPalette failed.", NULL);
00430 return GE_FALSE;
00431 }
00432
00433 geBitmap_Palette_Destroy(&Pal);
00434 } //done making the palette
00435
00436 if (!geBitmap_SetColorKey(pWBitmap->Bitmap, UseColorKey, ColorKey, GE_TRUE))
00437 {
00438 geErrorLog_AddString(-1, "geWBitmap_Pool_CreateAllWBitmaps: geBitmap_SetColorKey failed.", NULL);
00439 goto ExitWithError;
00440 }
00441
00442 }
00443
00444 // added to stop a leak
00445 if (BitmapIsTransparent)
00446 {
00447 geRam_Free(BitmapIsTransparent);
00448 BitmapIsTransparent = NULL;
00449 }
00450
00451 return GE_TRUE;
00452
00453 // Error
00454 ExitWithError:
00455 {
00456 if (Pool->WBitmaps)
00457 {
00458 geWBitmap_Pool_DestroyAllWBitmaps(Pool);
00459 Pool->WBitmaps = NULL;
00460 }
00461
00462 if (BitmapIsTransparent)
00463 {
00464 geRam_Free(BitmapIsTransparent);
00465 BitmapIsTransparent = NULL;
00466 }
00467
00468 return GE_FALSE;
00469 }
00470 }
|
|
|
Definition at line 102 of file WBitmap.c. References geRam_Free, and geWBitmap_Pool_DestroyAllWBitmaps(). Referenced by geWBitmap_Pool_Create(), and geWorld_Free().
00103 {
00104 assert(Pool);
00105
00106 geWBitmap_Pool_DestroyAllWBitmaps(Pool);
00107
00108 geRam_Free(Pool);
00109 }
|
|
|
Definition at line 475 of file WBitmap.c. References geWBitmap::Bitmap, geBitmap_Destroy(), geRam_Free, int32, NULL, geWBitmap_Pool::NumWBitmaps, and geWBitmap_Pool::WBitmaps. Referenced by geWBitmap_Pool_CreateAllWBitmaps(), and geWBitmap_Pool_Destroy().
00476 {
00477 assert(Pool);
00478
00479 if (Pool->WBitmaps)
00480 {
00481 int32 i;
00482 geWBitmap *pWBitmap;
00483
00484 pWBitmap = Pool->WBitmaps;
00485
00486 for (i=0; i< Pool->NumWBitmaps; i++, pWBitmap++)
00487 {
00488 // Destroy the geBitmap
00489 if (pWBitmap->Bitmap)
00490 {
00491 geBitmap_Destroy(&pWBitmap->Bitmap);
00492 pWBitmap->Bitmap = NULL;
00493 }
00494 }
00495
00496 geRam_Free(Pool->WBitmaps);
00497 }
00498
00499 Pool->WBitmaps = NULL; // Just to be sure
00500 }
|
|
||||||||||||
|
Definition at line 158 of file WBitmap.c. References geWBitmap::Bitmap, and geWBitmap_Pool::WBitmaps. Referenced by RenderSkyThroughFrustum(), and RenderTransPoly().
|
|
||||||||||||
|
Definition at line 171 of file WBitmap.c. References geWBitmap::Bitmap, int32, geWBitmap::Name, NULL, geWBitmap_Pool::NumWBitmaps, and geWBitmap_Pool::WBitmaps. Referenced by geWorld_GetBitmapByName().
00172 {
00173 geWBitmap *pWBitmap;
00174 int32 i;
00175
00176 assert(Pool);
00177 assert(BitmapName);
00178
00179 pWBitmap = Pool->WBitmaps;
00180 for (i=0; i< Pool->NumWBitmaps; i++, pWBitmap++)
00181 {
00182 if (!stricmp(pWBitmap->Name, BitmapName))
00183 return pWBitmap->Bitmap; // Found it
00184 }
00185
00186 return NULL;
00187 }
|
|
||||||||||||
|
Definition at line 136 of file WBitmap.c. References geWBitmap::Bitmap, int32, NULL, geWBitmap_Pool::NumWBitmaps, and geWBitmap_Pool::WBitmaps. Referenced by geWorld_BitmapIsVisible().
00137 {
00138 geWBitmap *pWBitmap;
00139 int32 i;
00140
00141 assert(Pool);
00142 assert(Bitmap);
00143
00144 pWBitmap = Pool->WBitmaps;
00145
00146 for (i=0; i< Pool->NumWBitmaps; i++, pWBitmap++)
00147 {
00148 if (pWBitmap->Bitmap == Bitmap)
00149 return pWBitmap;
00150 }
00151
00152 return NULL;
00153 }
|
|
||||||||||||
|
Definition at line 124 of file WBitmap.c. References geWBitmap_Pool::WBitmaps. Referenced by geWorld_BitmapListInit(), and RenderFace().
00125 {
00126 assert(Pool);
00127 assert(Index >= 0);
00128 assert(Index < Pool->NumWBitmaps);
00129
00130 return &Pool->WBitmaps[Index];
00131 }
|
|
|
Definition at line 114 of file WBitmap.c. References int32, and geWBitmap_Pool::NumWBitmaps. Referenced by geWorld_BitmapListInit().
00115 {
00116 assert(Pool);
00117
00118 return Pool->NumWBitmaps;
00119 }
|
|
||||||||||||
|
Definition at line 549 of file WBitmap.c. References geWBitmap::Bitmap, int32, geWBitmap::Name, NULL, geWBitmap_Pool::NumWBitmaps, and geWBitmap_Pool::WBitmaps.
00550 {
00551 geWBitmap *pWBitmap;
00552 int32 i;
00553
00554 assert(Pool);
00555 assert(Bitmap);
00556
00557 pWBitmap = Pool->WBitmaps;
00558
00559 for (i=0; i< Pool->NumWBitmaps; i++, pWBitmap++)
00560 {
00561 char str[100];
00562 sprintf(str,"WBitmap : %x\n",pWBitmap->Bitmap);
00563 OutputDebugString(str);
00564 if (pWBitmap->Bitmap == Bitmap)
00565 return pWBitmap->Name;
00566 }
00567
00568 return NULL;
00569 }
|
|
||||||||||||
|
Definition at line 535 of file WBitmap.c. References GE_TRUE, geBoolean, and geWBitmap::VisFrame. Referenced by RenderFace().
|
1.3.2