diff options
author | Zaba999 <zaba.marcin@gmail.com> | 2012-09-18 22:39:10 +0200 |
---|---|---|
committer | Zaba999 <zaba.marcin@gmail.com> | 2012-09-18 22:39:10 +0200 |
commit | 7bce8f073c9212247d104266d417e46e884b72c2 (patch) | |
tree | 89da914094bf7d0e92c5da1e14e9e4298340c799 /src/graphics/opengl/gldevice.cpp | |
parent | 36ae984ac77c5545d3d11dde7e37913a8eff0b0d (diff) | |
parent | da5d4edeb3a41462ec987cb4994a6897823f3f76 (diff) | |
download | colobot-7bce8f073c9212247d104266d417e46e884b72c2.tar.gz colobot-7bce8f073c9212247d104266d417e46e884b72c2.tar.bz2 colobot-7bce8f073c9212247d104266d417e46e884b72c2.zip |
Merge branch 'dev' of https://github.com/adiblol/colobot into dev
Conflicts:
src/ui/slider.cpp
Diffstat (limited to 'src/graphics/opengl/gldevice.cpp')
-rw-r--r-- | src/graphics/opengl/gldevice.cpp | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 09efeb3..881e273 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -436,7 +436,10 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr else glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); + + bool convert = false; GLenum sourceFormat = 0; + if (params.format == Gfx::TEX_IMG_RGB) { sourceFormat = GL_RGB; @@ -461,26 +464,26 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr { if (data->surface->format->Amask != 0) { - if ((data->surface->format->Rmask == 0xFF000000) && - (data->surface->format->Gmask == 0x00FF0000) && - (data->surface->format->Bmask == 0x0000FF00) && - (data->surface->format->Amask == 0x000000FF)) + if ((data->surface->format->Amask == 0xFF000000) && + (data->surface->format->Rmask == 0x00FF0000) && + (data->surface->format->Gmask == 0x0000FF00) && + (data->surface->format->Bmask == 0x000000FF)) { sourceFormat = GL_BGRA; result.alpha = true; } - else if ((data->surface->format->Bmask == 0xFF000000) && - (data->surface->format->Gmask == 0x00FF0000) && - (data->surface->format->Rmask == 0x0000FF00) && - (data->surface->format->Amask == 0x000000FF)) + else if ((data->surface->format->Amask == 0xFF000000) && + (data->surface->format->Bmask == 0x00FF0000) && + (data->surface->format->Gmask == 0x0000FF00) && + (data->surface->format->Rmask == 0x000000FF)) { sourceFormat = GL_RGBA; result.alpha = true; } else { - GetLogger()->Error("Auto texture format failed\n"); - return Gfx::Texture(); // other format? + sourceFormat = GL_RGBA; + convert = true; } } else @@ -501,16 +504,43 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr } else { - GetLogger()->Error("Auto texture format failed\n"); - return Gfx::Texture(); // other format? + sourceFormat = GL_RGBA; + convert = true; } } } else assert(false); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data->surface->w, data->surface->h, - 0, sourceFormat, GL_UNSIGNED_BYTE, data->surface->pixels); + SDL_Surface* actualSurface = data->surface; + SDL_Surface* convertedSurface = nullptr; + + if (convert) + { + SDL_PixelFormat format; + format.BytesPerPixel = 4; + format.BitsPerPixel = 32; + format.alpha = 0; + format.colorkey = 0; + format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0; + format.Amask = 0xFF000000; + format.Ashift = 24; + format.Bmask = 0x00FF0000; + format.Bshift = 16; + format.Gmask = 0x0000FF00; + format.Gshift = 8; + format.Rmask = 0x000000FF; + format.Rshift = 0; + format.palette = nullptr; + convertedSurface = SDL_ConvertSurface(data->surface, &format, SDL_SWSURFACE); + if (convertedSurface != nullptr) + actualSurface = convertedSurface; + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, actualSurface->w, actualSurface->h, + 0, sourceFormat, GL_UNSIGNED_BYTE, actualSurface->pixels); + + SDL_FreeSurface(convertedSurface); // Restore the previous state of 1st stage |