mirror of
https://github.com/holub/mame
synced 2025-07-03 09:06:08 +03:00
render/bgfx: Fix failure to load texture .png files when -artpath contains multiple directories
This commit is contained in:
parent
bcf647342a
commit
f806cfd21c
@ -155,7 +155,7 @@ void path_iterator::reset()
|
|||||||
// in the search path
|
// in the search path
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
|
|
||||||
const osd::directory::entry *file_enumerator::next()
|
const osd::directory::entry *file_enumerator::next(const char *subdir)
|
||||||
{
|
{
|
||||||
// loop over potentially empty directories
|
// loop over potentially empty directories
|
||||||
while (true)
|
while (true)
|
||||||
@ -164,7 +164,7 @@ const osd::directory::entry *file_enumerator::next()
|
|||||||
while (!m_curdir)
|
while (!m_curdir)
|
||||||
{
|
{
|
||||||
// if we fail to get anything more, we're done
|
// if we fail to get anything more, we're done
|
||||||
if (!m_iterator.next(m_pathbuffer))
|
if (!m_iterator.next(m_pathbuffer, subdir))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// open the path
|
// open the path
|
||||||
|
@ -107,7 +107,7 @@ public:
|
|||||||
file_enumerator &operator=(file_enumerator const &) = delete;
|
file_enumerator &operator=(file_enumerator const &) = delete;
|
||||||
|
|
||||||
// iterator
|
// iterator
|
||||||
const osd::directory::entry *next();
|
const osd::directory::entry *next(const char *subdir = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// internal state
|
// internal state
|
||||||
|
@ -109,59 +109,48 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, std::s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get directory of file
|
// get directory of file
|
||||||
std::string directory_path = std::string(chains.options().art_path());
|
|
||||||
std::string file_directory = "";
|
|
||||||
const size_t last_slash = texture_name.rfind('/');
|
const size_t last_slash = texture_name.rfind('/');
|
||||||
if (last_slash != std::string::npos)
|
const std::string file_directory = last_slash != std::string::npos ? texture_name.substr(0, last_slash) : std::string();
|
||||||
|
file_enumerator directory_path(chains.options().art_path());
|
||||||
|
while (const osd::directory::entry *entry = directory_path.next(file_directory.empty() ? nullptr : file_directory.c_str()))
|
||||||
{
|
{
|
||||||
file_directory = texture_name.substr(0, last_slash);
|
if (entry->type == osd::directory::entry::entry_type::FILE)
|
||||||
|
|
||||||
directory_path += "/" + file_directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
osd::directory::ptr directory = osd::directory::open(directory_path);
|
|
||||||
if (directory)
|
|
||||||
{
|
|
||||||
for (const osd::directory::entry *entry = directory->read(); entry != nullptr; entry = directory->read())
|
|
||||||
{
|
{
|
||||||
if (entry->type == osd::directory::entry::entry_type::FILE)
|
std::string file(entry->name);
|
||||||
|
std::string extension(".png");
|
||||||
|
|
||||||
|
// split into file name and extension
|
||||||
|
std::string file_name;
|
||||||
|
std::string file_extension;
|
||||||
|
const size_t last_dot = file.rfind('.');
|
||||||
|
if (last_dot != std::string::npos)
|
||||||
{
|
{
|
||||||
std::string file(entry->name);
|
file_name = file.substr(0, last_dot);
|
||||||
std::string extension(".png");
|
file_extension = file.substr(last_dot, file.length() - last_dot);
|
||||||
|
}
|
||||||
|
|
||||||
// split into file name and extension
|
std::string file_path;
|
||||||
std::string file_name;
|
if (file_directory == "")
|
||||||
std::string file_extension;
|
{
|
||||||
const size_t last_dot = file.rfind('.');
|
file_path = file;
|
||||||
if (last_dot != std::string::npos)
|
}
|
||||||
{
|
else
|
||||||
file_name = file.substr(0, last_dot);
|
{
|
||||||
file_extension = file.substr(last_dot, file.length() - last_dot);
|
file_path = file_directory + "/" + file;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string file_path;
|
// check for .png extension
|
||||||
if (file_directory == "")
|
if (file_extension == extension && std::find(texture_names.begin(), texture_names.end(), file_path) == texture_names.end())
|
||||||
|
{
|
||||||
|
// create textures for all files containd in the path of the specified file name
|
||||||
|
uint32_t flags = bilinear ? 0u : (BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT | BGFX_SAMPLER_MIP_POINT);
|
||||||
|
flags |= clamp ? (BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP | BGFX_SAMPLER_W_CLAMP) : 0u;
|
||||||
|
bgfx_texture* texture = chains.textures().create_png_texture(chains.options().art_path(), file_path, file_path, flags, screen_index);
|
||||||
|
if (texture == nullptr)
|
||||||
{
|
{
|
||||||
file_path = file;
|
return nullptr;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
file_path = file_directory + "/" + file;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for .png extension
|
|
||||||
if (file_extension == extension)
|
|
||||||
{
|
|
||||||
// create textures for all files containd in the path of the specified file name
|
|
||||||
uint32_t flags = bilinear ? 0u : (BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT | BGFX_SAMPLER_MIP_POINT);
|
|
||||||
flags |= clamp ? (BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP | BGFX_SAMPLER_W_CLAMP) : 0u;
|
|
||||||
bgfx_texture* texture = chains.textures().create_png_texture(chains.options().art_path(), file_path, file_path, flags, screen_index);
|
|
||||||
if (texture == nullptr)
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
texture_names.push_back(file_path);
|
|
||||||
}
|
}
|
||||||
|
texture_names.push_back(file_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user