44#include " IdleTextures.hpp"
55#include " MilkdropNoise.hpp"
66#include " Texture.hpp"
7+ #include " Utils.hpp"
78
89#include < SOIL2/SOIL2.h>
910
@@ -165,7 +166,6 @@ void TextureManager::PurgeTextures()
165166
166167auto TextureManager::TryLoadingTexture (const std::string& name) -> TextureSamplerDescriptor
167168{
168- TextureSamplerDescriptor texDesc;
169169 GLint wrapMode{0 };
170170 GLint filterMode{0 };
171171 std::string unqualifiedName;
@@ -174,24 +174,22 @@ auto TextureManager::TryLoadingTexture(const std::string& name) -> TextureSample
174174
175175 ScanTextures ();
176176
177- std::string lowerCaseFileName (name);
178- std::transform (lowerCaseFileName.begin (), lowerCaseFileName.end (), lowerCaseFileName.begin (), tolower);
179-
177+ std::string lowerCaseUnqualifiedName = Utils::ToLower (unqualifiedName);
180178 for (const auto & file : m_scannedTextureFiles)
181179 {
182- if (file.lowerCaseBaseName != unqualifiedName )
180+ if (file.lowerCaseBaseName != lowerCaseUnqualifiedName )
183181 {
184182 continue ;
185183 }
186184
187- texDesc = LoadTexture (file. filePath , name );
185+ auto texture = LoadTexture (file);
188186
189- if (!texDesc. Empty () )
187+ if (texture )
190188 {
191189#ifdef DEBUG
192190 std::cerr << " Loaded texture " << unqualifiedName << std::endl;
193191#endif
194- return texDesc ;
192+ return {texture, m_samplers. at ({wrapMode, filterMode}), name, unqualifiedName}; ;
195193 }
196194 }
197195
@@ -203,24 +201,20 @@ auto TextureManager::TryLoadingTexture(const std::string& name) -> TextureSample
203201 return {m_placeholderTexture, m_samplers.at ({wrapMode, filterMode}), name, unqualifiedName};
204202}
205203
206- auto TextureManager::LoadTexture (const std::string& fileName, const std::string& name) -> TextureSamplerDescriptor
204+ auto TextureManager::LoadTexture (const ScannedFile& file) -> std::shared_ptr<Texture>
207205{
208- GLint wrapMode;
209- GLint filterMode;
210206 std::string unqualifiedName;
211207
212- ExtractTextureSettings (name, wrapMode, filterMode, unqualifiedName);
213- auto sampler = m_samplers.at ({wrapMode, filterMode});
214- if (m_textures.find (name) != m_textures.end ())
208+ if (m_textures.find (file.lowerCaseBaseName ) != m_textures.end ())
215209 {
216- return { m_textures.at (name), sampler, name, unqualifiedName} ;
210+ return m_textures.at (file. lowerCaseBaseName ) ;
217211 }
218212
219213 int width{};
220214 int height{};
221215
222216 unsigned int const tex = SOIL_load_OGL_texture (
223- fileName .c_str (),
217+ file. filePath .c_str (),
224218 SOIL_LOAD_RGBA,
225219 SOIL_CREATE_NEW_ID,
226220 SOIL_FLAG_MULTIPLY_ALPHA, &width, &height);
@@ -232,10 +226,10 @@ auto TextureManager::LoadTexture(const std::string& fileName, const std::string&
232226
233227 uint32_t memoryBytes = width * height * 4 ; // RGBA, unsigned byte color channels.
234228 auto newTexture = std::make_shared<Texture>(unqualifiedName, tex, GL_TEXTURE_2D, width, height, true );
235- m_textures[name ] = newTexture;
236- m_textureStats.insert ({name , {memoryBytes}});
229+ m_textures[file. lowerCaseBaseName ] = newTexture;
230+ m_textureStats.insert ({file. lowerCaseBaseName , {memoryBytes}});
237231
238- return { newTexture, sampler, name, unqualifiedName} ;
232+ return newTexture;
239233}
240234
241235auto TextureManager::GetRandomTexture (const std::string& randomName) -> TextureSamplerDescriptor
@@ -247,8 +241,7 @@ auto TextureManager::GetRandomTexture(const std::string& randomName) -> TextureS
247241
248242 ScanTextures ();
249243
250- std::string lowerCaseName (randomName);
251- std::transform (lowerCaseName.begin (), lowerCaseName.end (), lowerCaseName.begin (), tolower);
244+ std::string lowerCaseName = Utils::ToLower (randomName);
252245
253246 if (m_scannedTextureFiles.empty ())
254247 {
@@ -300,8 +293,7 @@ auto TextureManager::GetRandomTexture(const std::string& randomName) -> TextureS
300293
301294void TextureManager::AddTextureFile (const std::string& fileName, const std::string& baseName)
302295{
303- std::string lowerCaseBaseName (baseName);
304- std::transform (lowerCaseBaseName.begin (), lowerCaseBaseName.end (), lowerCaseBaseName.begin (), tolower);
296+ std::string lowerCaseBaseName = Utils::ToLower (baseName);
305297
306298 ScannedFile file;
307299 file.filePath = fileName;
@@ -320,8 +312,7 @@ void TextureManager::ExtractTextureSettings(const std::string& qualifiedName, GL
320312 return ;
321313 }
322314
323- std::string lowerQualifiedName (qualifiedName);
324- std::transform (lowerQualifiedName.begin (), lowerQualifiedName.end (), lowerQualifiedName.begin (), tolower);
315+ std::string lowerQualifiedName = Utils::ToLower (qualifiedName);
325316
326317 // Default mode for user textures is "fw" (bilinear filtering + wrap).
327318 wrapMode = GL_REPEAT;
0 commit comments