From 6f191bd7dacf2b7b4c9a1a14d29f7ccdc1950476 Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 8 Jan 2017 13:31:10 +0800 Subject: [PATCH] Fix gles Because in the past call texture->lock() will return unmodified cached image (always bgra), now the image will be converted dependently --- src/graphics/skybox.cpp | 12 ++++++++---- src/graphics/spherical_harmonics.cpp | 19 +++++++++++++++++-- src/graphics/stk_texture.cpp | 2 ++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/graphics/skybox.cpp b/src/graphics/skybox.cpp index cfa80d443..51bc63ea7 100644 --- a/src/graphics/skybox.cpp +++ b/src/graphics/skybox.cpp @@ -167,11 +167,15 @@ void Skybox::generateCubeMapFromTextures() img->copyToScaling(rgba[i], size, size); #if defined(USE_GLES2) - for (unsigned int j = 0; j < size * size; j++) + if (CVS->isEXTTextureFormatBGRA8888Usable()) { - char tmp_val = rgba[i][j*4]; - rgba[i][j*4] = rgba[i][j*4 + 2]; - rgba[i][j*4 + 2] = tmp_val; + // BGRA image returned by getTextureImage causes black sky in gles + for (unsigned int j = 0; j < size * size; j++) + { + char tmp_val = rgba[i][j * 4]; + rgba[i][j * 4] = rgba[i][j * 4 + 2]; + rgba[i][j * 4 + 2] = tmp_val; + } } #endif diff --git a/src/graphics/spherical_harmonics.cpp b/src/graphics/spherical_harmonics.cpp index 55198c217..86b7e64b0 100644 --- a/src/graphics/spherical_harmonics.cpp +++ b/src/graphics/spherical_harmonics.cpp @@ -17,8 +17,11 @@ #ifndef SERVER_ONLY -#include "graphics/irr_driver.hpp" #include "graphics/spherical_harmonics.hpp" +#if defined(USE_GLES2) +#include "graphics/central_settings.hpp" +#endif +#include "graphics/irr_driver.hpp" #include "graphics/stk_texture.hpp" #include "utils/log.hpp" @@ -410,6 +413,18 @@ void SphericalHarmonics::setTextures(const std::vector &spher (m_spherical_harmonics_textures[idx])->getTextureImage(); assert(img != NULL); img->copyToScaling(sh_rgba[i], sh_w, sh_h); +#if defined(USE_GLES2) + if (!CVS->isEXTTextureFormatBGRA8888Usable()) + { + // Code here assume color format is BGRA + for (unsigned int j = 0; j < sh_w * sh_h; j++) + { + char tmp_val = sh_rgba[i][j * 4]; + sh_rgba[i][j * 4] = sh_rgba[i][j * 4 + 2]; + sh_rgba[i][j * 4 + 2] = tmp_val; + } + } +#endif } //for (unsigned i = 0; i < 6; i++) Color *float_tex_cube[6]; @@ -420,7 +435,7 @@ void SphericalHarmonics::setTextures(const std::vector &spher { delete[] sh_rgba[i]; delete[] float_tex_cube[i]; - } + } } //setSphericalHarmonicsTextures /** Compute spherical harmonics coefficients from ambient light */ diff --git a/src/graphics/stk_texture.cpp b/src/graphics/stk_texture.cpp index 9f48b564c..2386218ef 100644 --- a/src/graphics/stk_texture.cpp +++ b/src/graphics/stk_texture.cpp @@ -28,7 +28,9 @@ #include #include +#if !defined(USE_GLES2) static const uint8_t CACHE_VERSION = 1; +#endif // ---------------------------------------------------------------------------- STKTexture::STKTexture(const std::string& path, bool srgb, bool premul_alpha, bool set_material, bool mesh_tex, bool no_upload)