4
4
#include " IdleTextures.hpp"
5
5
#include " MilkdropNoise.hpp"
6
6
#include " Texture.hpp"
7
+ #include " Utils.hpp"
7
8
8
9
#include < SOIL2/SOIL2.h>
9
10
@@ -165,7 +166,6 @@ void TextureManager::PurgeTextures()
165
166
166
167
auto TextureManager::TryLoadingTexture (const std::string& name) -> TextureSamplerDescriptor
167
168
{
168
- TextureSamplerDescriptor texDesc;
169
169
GLint wrapMode{0 };
170
170
GLint filterMode{0 };
171
171
std::string unqualifiedName;
@@ -174,24 +174,22 @@ auto TextureManager::TryLoadingTexture(const std::string& name) -> TextureSample
174
174
175
175
ScanTextures ();
176
176
177
- std::string lowerCaseFileName (name);
178
- std::transform (lowerCaseFileName.begin (), lowerCaseFileName.end (), lowerCaseFileName.begin (), tolower);
179
-
177
+ std::string lowerCaseUnqualifiedName = Utils::ToLower (unqualifiedName);
180
178
for (const auto & file : m_scannedTextureFiles)
181
179
{
182
- if (file.lowerCaseBaseName != unqualifiedName )
180
+ if (file.lowerCaseBaseName != lowerCaseUnqualifiedName )
183
181
{
184
182
continue ;
185
183
}
186
184
187
- texDesc = LoadTexture (file. filePath , name );
185
+ auto texture = LoadTexture (file);
188
186
189
- if (!texDesc. Empty () )
187
+ if (texture )
190
188
{
191
189
#ifdef DEBUG
192
190
std::cerr << " Loaded texture " << unqualifiedName << std::endl;
193
191
#endif
194
- return texDesc ;
192
+ return {texture, m_samplers. at ({wrapMode, filterMode}), name, unqualifiedName}; ;
195
193
}
196
194
}
197
195
@@ -203,24 +201,20 @@ auto TextureManager::TryLoadingTexture(const std::string& name) -> TextureSample
203
201
return {m_placeholderTexture, m_samplers.at ({wrapMode, filterMode}), name, unqualifiedName};
204
202
}
205
203
206
- auto TextureManager::LoadTexture (const std::string& fileName, const std::string& name) -> TextureSamplerDescriptor
204
+ auto TextureManager::LoadTexture (const ScannedFile& file) -> std::shared_ptr<Texture>
207
205
{
208
- GLint wrapMode;
209
- GLint filterMode;
210
206
std::string unqualifiedName;
211
207
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 ())
215
209
{
216
- return { m_textures.at (name), sampler, name, unqualifiedName} ;
210
+ return m_textures.at (file. lowerCaseBaseName ) ;
217
211
}
218
212
219
213
int width{};
220
214
int height{};
221
215
222
216
unsigned int const tex = SOIL_load_OGL_texture (
223
- fileName .c_str (),
217
+ file. filePath .c_str (),
224
218
SOIL_LOAD_RGBA,
225
219
SOIL_CREATE_NEW_ID,
226
220
SOIL_FLAG_MULTIPLY_ALPHA, &width, &height);
@@ -232,10 +226,10 @@ auto TextureManager::LoadTexture(const std::string& fileName, const std::string&
232
226
233
227
uint32_t memoryBytes = width * height * 4 ; // RGBA, unsigned byte color channels.
234
228
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}});
237
231
238
- return { newTexture, sampler, name, unqualifiedName} ;
232
+ return newTexture;
239
233
}
240
234
241
235
auto TextureManager::GetRandomTexture (const std::string& randomName) -> TextureSamplerDescriptor
@@ -247,8 +241,7 @@ auto TextureManager::GetRandomTexture(const std::string& randomName) -> TextureS
247
241
248
242
ScanTextures ();
249
243
250
- std::string lowerCaseName (randomName);
251
- std::transform (lowerCaseName.begin (), lowerCaseName.end (), lowerCaseName.begin (), tolower);
244
+ std::string lowerCaseName = Utils::ToLower (randomName);
252
245
253
246
if (m_scannedTextureFiles.empty ())
254
247
{
@@ -300,8 +293,7 @@ auto TextureManager::GetRandomTexture(const std::string& randomName) -> TextureS
300
293
301
294
void TextureManager::AddTextureFile (const std::string& fileName, const std::string& baseName)
302
295
{
303
- std::string lowerCaseBaseName (baseName);
304
- std::transform (lowerCaseBaseName.begin (), lowerCaseBaseName.end (), lowerCaseBaseName.begin (), tolower);
296
+ std::string lowerCaseBaseName = Utils::ToLower (baseName);
305
297
306
298
ScannedFile file;
307
299
file.filePath = fileName;
@@ -320,8 +312,7 @@ void TextureManager::ExtractTextureSettings(const std::string& qualifiedName, GL
320
312
return ;
321
313
}
322
314
323
- std::string lowerQualifiedName (qualifiedName);
324
- std::transform (lowerQualifiedName.begin (), lowerQualifiedName.end (), lowerQualifiedName.begin (), tolower);
315
+ std::string lowerQualifiedName = Utils::ToLower (qualifiedName);
325
316
326
317
// Default mode for user textures is "fw" (bilinear filtering + wrap).
327
318
wrapMode = GL_REPEAT;
0 commit comments