GLTexture* MapTextureManager::getTexture(string name, bool mixed) { // Get texture matching name map_tex_t& mtex = textures[name.Upper()]; // Get desired filter type int filter = 1; if (map_tex_filter == 0) filter = GLTexture::NEAREST_LINEAR_MIN; else if (map_tex_filter == 1) filter = GLTexture::LINEAR; else if (map_tex_filter == 2) filter = GLTexture::LINEAR_MIPMAP; else if (map_tex_filter == 3) filter = GLTexture::NEAREST_MIPMAP; // If the texture is loaded if (mtex.texture) { // If the texture filter matches the desired one, return it if (mtex.texture->getFilter() == filter) return mtex.texture; else { // Otherwise, reload the texture if (mtex.texture != &(GLTexture::missingTex())) delete mtex.texture; mtex.texture = NULL; } } // Texture not found or unloaded, look for it Palette8bit* pal = getResourcePalette(); // Look for stand-alone textures first ArchiveEntry* etex = theResourceManager->getTextureEntry(name, "hires", archive); int textypefound = TEXTYPE_HIRES; if (etex == NULL) { etex = theResourceManager->getTextureEntry(name, "textures", archive); textypefound = TEXTYPE_TEXTURE; } /* if (etex == NULL) { etex = theResourceManager->getTextureEntry(name, "flats", archive); textypefound = TEXTYPE_FLAT; } */ if (etex) { SImage image; // Get image format hint from type, if any if (Misc::loadImageFromEntry(&image, etex)) { mtex.texture = new GLTexture(false); mtex.texture->setFilter(filter); mtex.texture->loadImage(&image, pal); } } // Try composite textures then CTexture* ctex = theResourceManager->getTexture(name, archive); if (ctex && (!mtex.texture || textypefound == TEXTYPE_FLAT)) { textypefound = TEXTYPE_WALLTEXTURE; SImage image; if (ctex->toImage(image, archive, pal)) { mtex.texture = new GLTexture(false); mtex.texture->setFilter(filter); mtex.texture->loadImage(&image, pal); } } // Not found if (!mtex.texture) { // Try flats if mixed if (mixed) return getFlat(name, false); // Otherwise use missing texture else mtex.texture = &(GLTexture::missingTex()); } return mtex.texture; }
/* MapTextureManager::getTexture * Returns the texture matching [name]. Loads it from resources if * necessary. If [mixed] is true, flats are also searched if no * matching texture is found *******************************************************************/ GLTexture* MapTextureManager::getTexture(string name, bool mixed) { // Get texture matching name map_tex_t& mtex = textures[name.Upper()]; // Get desired filter type int filter = 1; if (map_tex_filter == 0) filter = GLTexture::NEAREST_LINEAR_MIN; else if (map_tex_filter == 1) filter = GLTexture::LINEAR; else if (map_tex_filter == 2) filter = GLTexture::LINEAR_MIPMAP; else if (map_tex_filter == 3) filter = GLTexture::NEAREST_MIPMAP; // If the texture is loaded if (mtex.texture) { // If the texture filter matches the desired one, return it if (mtex.texture->getFilter() == filter) return mtex.texture; else { // Otherwise, reload the texture if (mtex.texture != &(GLTexture::missingTex())) delete mtex.texture; mtex.texture = NULL; } } // Texture not found or unloaded, look for it //Palette8bit* pal = getResourcePalette(); // Look for stand-alone textures first ArchiveEntry* etex = theResourceManager->getTextureEntry(name, "hires", archive); int textypefound = TEXTYPE_HIRES; if (etex == NULL) { etex = theResourceManager->getTextureEntry(name, "textures", archive); textypefound = TEXTYPE_TEXTURE; } if (etex) { SImage image; // Get image format hint from type, if any if (Misc::loadImageFromEntry(&image, etex)) { mtex.texture = new GLTexture(false); mtex.texture->setFilter(filter); mtex.texture->loadImage(&image, palette); // Handle hires texture scale if (textypefound == TEXTYPE_HIRES) { ArchiveEntry* ref = theResourceManager->getTextureEntry(name, "textures", archive); if (ref) { SImage imgref; if (Misc::loadImageFromEntry(&imgref, ref)) { int w, h, sw, sh; w = image.getWidth(); h = image.getHeight(); sw = imgref.getWidth(); sh = imgref.getHeight(); mtex.texture->setScale((double)sw/(double)w, (double)sh/(double)h); } } } } } // Try composite textures then CTexture* ctex = theResourceManager->getTexture(name, archive); if (ctex && (!mtex.texture || textypefound == TEXTYPE_FLAT)) { textypefound = TEXTYPE_WALLTEXTURE; SImage image; if (ctex->toImage(image, archive, palette)) { mtex.texture = new GLTexture(false); mtex.texture->setFilter(filter); mtex.texture->loadImage(&image, palette); double sx = ctex->getScaleX(); if (sx == 0) sx = 1.0; double sy = ctex->getScaleY(); if (sy == 0) sy = 1.0; mtex.texture->setScale(1.0/sx, 1.0/sy); } } // Not found if (!mtex.texture) { // Try flats if mixed if (mixed) return getFlat(name, false); // Otherwise use missing texture else mtex.texture = &(GLTexture::missingTex()); } return mtex.texture; }