Skip to content

Commit 5158ecb

Browse files
committed
Load image file and create texture separately with SOIL2
The new combined function no longer returns the image size, so we need to load the image ourselves, store the size and then pass the buffer to SOIL_create_OGL_texture().
1 parent 413c6d7 commit 5158ecb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/libprojectM/Renderer/TextureManager.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,23 @@ auto TextureManager::LoadTexture(const ScannedFile& file) -> std::shared_ptr<Tex
212212

213213
int width{};
214214
int height{};
215+
int channels{};
215216

216-
unsigned int const tex = SOIL_load_OGL_texture(
217-
file.filePath.c_str(),
218-
SOIL_LOAD_RGBA,
217+
std::unique_ptr<unsigned char, decltype(&SOIL_free_image_data)> imageData(SOIL_load_image(file.filePath.c_str(), &width, &height, &channels, SOIL_LOAD_RGBA), SOIL_free_image_data);
218+
219+
if (imageData == nullptr)
220+
{
221+
return {};
222+
}
223+
224+
unsigned int const tex = SOIL_create_OGL_texture(
225+
imageData.get(),
226+
&width, &height, SOIL_LOAD_RGBA,
219227
SOIL_CREATE_NEW_ID,
220228
SOIL_FLAG_MULTIPLY_ALPHA);
221229

230+
imageData.reset();
231+
222232
if (tex == 0)
223233
{
224234
return {};

0 commit comments

Comments
 (0)