MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / bitmap_load

Function bitmap_load

TheForceEngine/TFE_Jedi/Level/rtexture.cpp:320–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318 }
319
320 TextureData* bitmap_load(const char* name, u32 decompress, AssetPool pool, bool addToCache)
321 {
322 // TFE: Keep track of per-level texture state for serialization.
323 // This is also useful for handling per-level GPU texture mirrors.
324 TextureTable::iterator iTex = s_textureTable[pool].find(name);
325 if (iTex != s_textureTable[pool].end())
326 {
327 return s_textureList[pool][iTex->second].texture;
328 }
329
330 FilePath filepath;
331 if (!TFE_Paths::getFilePath(name, &filepath))
332 {
333 return nullptr;
334 }
335
336 FileStream file;
337 if (!file.open(&filepath, Stream::MODE_READ))
338 {
339 return nullptr;
340 }
341
342 size_t size = file.getSize();
343 s_buffer.resize(size);
344 file.readBuffer(s_buffer.data(), (u32)size);
345 file.close();
346
347 TextureData* texture = (TextureData*)region_alloc(s_texState.memoryRegion, sizeof(TextureData));
348 memset(texture, 0, sizeof(TextureData));
349
350 const u8* data = s_buffer.data();
351 const u8* end = data + size;
352 const u8* fheader = data;
353 data += 3;
354
355 if (strncmp((char*)fheader, "BM ", 3))
356 {
357 TFE_System::logWrite(LOG_ERROR, "bitmap_load", "File '%s' is not a valid BM file.", filepath);
358 return nullptr;
359 }
360
361 u8 version = readByte(data);
362 if (version != DF_BM_VERSION)
363 {
364 TFE_System::logWrite(LOG_ERROR, "bitmap_load", "File '%s' has invalid BM version '%u'.", filepath, version);
365 return nullptr;
366 }
367
368 texture->width = readUShort(data);
369 texture->height = readUShort(data);
370 texture->uvWidth = readShort(data);
371 texture->uvHeight = readShort(data);
372 texture->flags = readByte(data);
373 texture->logSizeY = readByte(data);
374 texture->compressed = readByte(data);
375 texture->palIndex = 1;
376 texture->animIndex = -1;
377 texture->frameIdx = -1;

Callers 8

parseModelFunction · 0.85
level_loadTextureListBinFunction · 0.85
level_loadGeometryFunction · 0.85
hud_loadTextureFunction · 0.85
loadWeaponTextureFunction · 0.85
gameStartupFunction · 0.85
loadAgentAndLevelDataFunction · 0.85

Calls 15

region_allocFunction · 0.85
logWriteFunction · 0.85
readByteFunction · 0.85
readUShortFunction · 0.85
readShortFunction · 0.85
readIntFunction · 0.85
decompressColumn_Type1Function · 0.85
decompressColumn_Type2Function · 0.85
isAssetCustomFunction · 0.85
bitmap_loadHDFunction · 0.85
dataMethod · 0.80
push_backMethod · 0.80

Tested by

no test coverage detected