MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / LoadCubeMapMipmapsHDR

Method LoadCubeMapMipmapsHDR

Source/Graphics/textures.cpp:457–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

455}
456
457TextureRef Textures::LoadCubeMapMipmapsHDR(const char* filename) {
458 TextureRef tex;
459 FILE* cache_file = my_fopen(filename, "rb");
460 if (cache_file) {
461 int version;
462 fread(&version, sizeof(int), 1, cache_file);
463 if (version == kCubeMapHDRVersion) {
464 int size, width;
465 fread(&size, sizeof(int), 1, cache_file);
466 fread(&width, sizeof(int), 1, cache_file);
467 float* data = (float*)alloc.stack.Alloc(sizeof(float) * size);
468 fread(&data[0], sizeof(float), size, cache_file);
469 fclose(cache_file);
470 tex = Textures::Instance()->makeCubemapTexture(128, 128, GL_RGBA16F, GL_RGBA, Textures::MIPMAPS);
471 Textures::Instance()->SetTextureName(tex, filename);
472 int mip_level = 0;
473 int index = 0;
474 while (width > 1) {
475 for (int i = 0; i < 6; i++) {
476 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, mip_level, 0, 0, width, width, GL_BGRA, GL_FLOAT, &data[index]);
477 index += width * width * 4;
478 }
479 ++mip_level;
480 width /= 2;
481 }
482 alloc.stack.Free(data);
483 }
484 }
485 return tex;
486}
487
488void Texture::Init() {
489 width = 0;

Callers

nothing calls this directly

Calls 5

my_fopenFunction · 0.85
makeCubemapTextureMethod · 0.80
SetTextureNameMethod · 0.80
AllocMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected