Check if file to load texture from exists, display error if not
This commit is contained in:
parent
ac0a4989bd
commit
b399fed33b
3 changed files with 19 additions and 1 deletions
|
|
@ -104,6 +104,9 @@ namespace vks
|
|||
|
||||
free(textureData);
|
||||
#else
|
||||
if (!vks::tools::fileExists(filename)) {
|
||||
vks::tools::exitFatal("Could not load texture from " + filename, "File not found");
|
||||
}
|
||||
gli::texture2d tex2D(gli::load(filename.c_str()));
|
||||
#endif
|
||||
assert(!tex2D.empty());
|
||||
|
|
@ -582,9 +585,11 @@ namespace vks
|
|||
|
||||
free(textureData);
|
||||
#else
|
||||
if (!vks::tools::fileExists(filename)) {
|
||||
vks::tools::exitFatal("Could not load texture from " + filename, "File not found");
|
||||
}
|
||||
gli::texture2d_array tex2DArray(gli::load(filename));
|
||||
#endif
|
||||
|
||||
assert(!tex2DArray.empty());
|
||||
|
||||
this->device = device;
|
||||
|
|
@ -791,6 +796,9 @@ namespace vks
|
|||
|
||||
free(textureData);
|
||||
#else
|
||||
if (!vks::tools::fileExists(filename)) {
|
||||
vks::tools::exitFatal("Could not load texture from " + filename, "File not found");
|
||||
}
|
||||
gli::texture_cube texCube(gli::load(filename));
|
||||
#endif
|
||||
assert(!texCube.empty());
|
||||
|
|
|
|||
|
|
@ -375,5 +375,11 @@ namespace vks
|
|||
|
||||
return shaderModule;
|
||||
}
|
||||
|
||||
bool fileExists(const std::string &filename)
|
||||
{
|
||||
std::ifstream f(filename.c_str());
|
||||
return !f.fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#include <fcntl.h>
|
||||
|
|
@ -123,5 +124,8 @@ namespace vks
|
|||
// Load a GLSL shader (text)
|
||||
// Note: GLSL support requires vendor-specific extensions to be enabled and is not a core-feature of Vulkan
|
||||
VkShaderModule loadShaderGLSL(const char *fileName, VkDevice device, VkShaderStageFlagBits stage);
|
||||
|
||||
/** @brief Checks if a file exists */
|
||||
bool fileExists(const std::string &filename);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue