diff --git a/lib/ivis_opengl/gfx_api.cpp b/lib/ivis_opengl/gfx_api.cpp index 06f39257808..11c47538573 100644 --- a/lib/ivis_opengl/gfx_api.cpp +++ b/lib/ivis_opengl/gfx_api.cpp @@ -221,13 +221,13 @@ optional gfx_api::getMaxTextureCompressi #include "png_util.h" -static gfx_api::texture* loadImageTextureFromFile_PNG(const std::string& filename, gfx_api::texture_type textureType, int maxWidth /*= -1*/, int maxHeight /*= -1*/) +static gfx_api::texture* loadImageTextureFromFile_PNG(const std::string& filename, gfx_api::texture_type textureType, int maxWidth /*= -1*/, int maxHeight /*= -1*/, bool quiet) { iV_Image loadedUncompressedImage; // 1.) Load the PNG into an iV_Image bool forceRGB = (textureType == gfx_api::texture_type::game_texture) || (textureType == gfx_api::texture_type::user_interface); - if (!iV_loadImage_PNG2(filename.c_str(), loadedUncompressedImage, forceRGB)) + if (!iV_loadImage_PNG2(filename.c_str(), loadedUncompressedImage, forceRGB, quiet)) { // Failed to load the image return nullptr; @@ -301,7 +301,7 @@ bool gfx_api::checkImageFilesWouldLoadFromSameParentMountPath(const std::vector< // Load a texture from a file // (which loads straight to a texture based on the appropriate texture_type, handling mip_maps, compression, etc) -gfx_api::texture* gfx_api::context::loadTextureFromFile(const char *filename, gfx_api::texture_type textureType, int maxWidth /*= -1*/, int maxHeight /*= -1*/) +gfx_api::texture* gfx_api::context::loadTextureFromFile(const char *filename, gfx_api::texture_type textureType, int maxWidth /*= -1*/, int maxHeight /*= -1*/, bool quiet /*= false*/) { auto imageLoadFilename = imageLoadFilenameFromInputFilename(filename); @@ -314,7 +314,7 @@ gfx_api::texture* gfx_api::context::loadTextureFromFile(const char *filename, gf #endif if (imageLoadFilename.endsWith(".png")) { - return loadImageTextureFromFile_PNG(imageLoadFilename.toUtf8(), textureType, maxWidth, maxHeight); + return loadImageTextureFromFile_PNG(imageLoadFilename.toUtf8(), textureType, maxWidth, maxHeight, quiet); } else { diff --git a/lib/ivis_opengl/gfx_api.h b/lib/ivis_opengl/gfx_api.h index ae8e945f09d..8520cb223a0 100644 --- a/lib/ivis_opengl/gfx_api.h +++ b/lib/ivis_opengl/gfx_api.h @@ -427,7 +427,7 @@ namespace gfx_api virtual void draw_elements_instanced(const std::size_t& offset, const std::size_t& count, const primitive_type& primitive, const index_type& index, std::size_t instance_count) = 0; public: // High-level API for getting a texture object from file / uncompressed bitmap - gfx_api::texture* loadTextureFromFile(const char *filename, gfx_api::texture_type textureType, int maxWidth = -1, int maxHeight = -1); + gfx_api::texture* loadTextureFromFile(const char *filename, gfx_api::texture_type textureType, int maxWidth = -1, int maxHeight = -1, bool quiet = false); gfx_api::texture* loadTextureFromUncompressedImage(iV_Image&& image, gfx_api::texture_type textureType, const std::string& filename, int maxWidth = -1, int maxHeight = -1); typedef std::function (int width, int height, int channels)> GenerateDefaultTextureFunc; gfx_api::texture_array* loadTextureArrayFromFiles(const std::vector& filenames, gfx_api::texture_type textureType, int maxWidth = -1, int maxHeight = -1, const GenerateDefaultTextureFunc& defaultTextureGenerator = nullptr, const std::function& progressCallback = nullptr, const std::string& debugName = ""); diff --git a/lib/ivis_opengl/png_util.cpp b/lib/ivis_opengl/png_util.cpp index 8e3da6c1697..330c60d752f 100644 --- a/lib/ivis_opengl/png_util.cpp +++ b/lib/ivis_opengl/png_util.cpp @@ -214,7 +214,7 @@ bool iV_loadImage_PNG(const char *fileName, iV_Image *image) return true; } -bool iV_loadImage_PNG2(const char *fileName, iV_Image& image, bool forceRGBA8 /*= false*/) +bool iV_loadImage_PNG2(const char *fileName, iV_Image& image, bool forceRGBA8 /*= false*/, bool quietOnOpenFail /*= false*/) { unsigned char PNGheader[PNG_BYTES_TO_CHECK]; PHYSFS_sint64 readSize; @@ -234,7 +234,17 @@ bool iV_loadImage_PNG2(const char *fileName, iV_Image& image, bool forceRGBA8 /* // Open file PHYSFS_file *fileHandle = PHYSFS_openRead(fileName); - ASSERT_OR_RETURN(false, fileHandle != nullptr, "Could not open %s: %s", fileName, WZ_PHYSFS_getLastError()); + if (fileHandle == nullptr) + { + if (!quietOnOpenFail) + { + ASSERT_OR_RETURN(false, fileHandle != nullptr, "Could not open %s: %s", fileName, WZ_PHYSFS_getLastError()); + } + else + { + return false; + } + } WZ_PHYSFS_SETBUFFER(fileHandle, 4096)//; // Read PNG header from file diff --git a/lib/ivis_opengl/png_util.h b/lib/ivis_opengl/png_util.h index 22962a1aa73..3df0197fca5 100644 --- a/lib/ivis_opengl/png_util.h +++ b/lib/ivis_opengl/png_util.h @@ -51,7 +51,7 @@ struct IMGSaveError */ bool iV_loadImage_PNG(const char *fileName, iV_Image *image); -bool iV_loadImage_PNG2(const char *fileName, iV_Image& image, bool forceRGBA8 = false); +bool iV_loadImage_PNG2(const char *fileName, iV_Image& image, bool forceRGBA8 = false, bool quietOnOpenFail = false); /*! * Load a PNG from a memory buffer into an image diff --git a/lib/ivis_opengl/tex.cpp b/lib/ivis_opengl/tex.cpp index e58cf46b799..eb5c7cfcf74 100644 --- a/lib/ivis_opengl/tex.cpp +++ b/lib/ivis_opengl/tex.cpp @@ -207,14 +207,21 @@ optional iV_GetTexture(const char *filename, gfx_api::texture_type textu return it->second; } - // Try to load it - std::string loadPath = "texpages/"; + // First, try to load from the current graphics_overrides (if enabled) + std::string loadPath = WZ_CURRENT_GRAPHICS_OVERRIDES_PREFIX "/texpages/"; loadPath += filename; - gfx_api::texture *pTexture = gfx_api::context::get().loadTextureFromFile(loadPath.c_str(), textureType, maxWidth, maxHeight); + gfx_api::texture *pTexture = gfx_api::context::get().loadTextureFromFile(loadPath.c_str(), textureType, maxWidth, maxHeight, true); if (!pTexture) { - debug(LOG_ERROR, "Failed to load %s", loadPath.c_str()); - return nullopt; + // Try to load it from the regular path + loadPath = "texpages/"; + loadPath += filename; + pTexture = gfx_api::context::get().loadTextureFromFile(loadPath.c_str(), textureType, maxWidth, maxHeight); + if (!pTexture) + { + debug(LOG_ERROR, "Failed to load %s", loadPath.c_str()); + return nullopt; + } } size_t page = pie_AddTexPage(pTexture, path.c_str(), textureType);