diff options
author | sfan5 <sfan5@live.de> | 2019-07-25 00:11:30 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2019-08-04 16:12:52 +0200 |
commit | 6c2ded4cac1d421355059ca2db919c064978243a (patch) | |
tree | ad4cabf77ae0873921b732a73fe9cb25b457cece | |
parent | ca363d3ef805a39fe4e821813b1efa53b2c9c805 (diff) | |
download | minetest-6c2ded4cac1d421355059ca2db919c064978243a.tar.gz minetest-6c2ded4cac1d421355059ca2db919c064978243a.tar.bz2 minetest-6c2ded4cac1d421355059ca2db919c064978243a.zip |
Unify GLES support in gui scaling filter
-rw-r--r-- | src/client/guiscalingfilter.cpp | 24 | ||||
-rw-r--r-- | src/client/tile.cpp | 57 | ||||
-rw-r--r-- | src/client/tile.h | 1 |
3 files changed, 44 insertions, 38 deletions
diff --git a/src/client/guiscalingfilter.cpp b/src/client/guiscalingfilter.cpp index 3490c47e8..2ff57ab74 100644 --- a/src/client/guiscalingfilter.cpp +++ b/src/client/guiscalingfilter.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include <cstdio> #include "client/renderingengine.h" +#include "client/tile.h" // hasNPotSupport() /* Maintain a static cache to store the images that correspond to textures * in a format that's manipulable by code. Some platforms exhibit issues @@ -113,17 +114,18 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver, (u32)destrect.getHeight())); imageScaleNNAA(srcimg, srcrect, destimg); -#ifdef __ANDROID__ - // Android is very picky about textures being powers of 2, so expand - // the image dimensions to the next power of 2, if necessary, for - // that platform. - video::IImage *po2img = driver->createImage(src->getColorFormat(), - core::dimension2d<u32>(npot2((u32)destrect.getWidth()), - npot2((u32)destrect.getHeight()))); - po2img->fill(video::SColor(0, 0, 0, 0)); - destimg->copyTo(po2img); - destimg->drop(); - destimg = po2img; +#if ENABLE_GLES + // Some platforms are picky about textures being powers of 2, so expand + // the image dimensions to the next power of 2, if necessary. + if (!hasNPotSupport()) { + video::IImage *po2img = driver->createImage(src->getColorFormat(), + core::dimension2d<u32>(npot2((u32)destrect.getWidth()), + npot2((u32)destrect.getHeight()))); + po2img->fill(video::SColor(0, 0, 0, 0)); + destimg->copyTo(po2img); + destimg->drop(); + destimg = po2img; + } #endif // Convert the scaled image back into a texture. diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 82f989d89..009237c51 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -995,12 +995,7 @@ video::IImage* TextureSource::generateImage(const std::string &name) } #if ENABLE_GLES -/** - * Check and align image to npot2 if required by hardware - * @param image image to check for npot2 alignment - * @param driver driver to use for image operations - * @return image or copy of image aligned to npot2 - */ + static inline u16 get_GL_major_version() { @@ -1008,47 +1003,55 @@ static inline u16 get_GL_major_version() return (u16) (gl_version[0] - '0'); } -video::IImage * Align2Npot2(video::IImage * image, - video::IVideoDriver* driver) -{ - if (image == NULL) { - return image; - } - - core::dimension2d<u32> dim = image->getDimension(); +/** + * Check if hardware requires npot2 aligned textures + * @return true if alignment NOT(!) requires, false otherwise + */ +bool hasNPotSupport() +{ // Only GLES2 is trusted to correctly report npot support - // Note: we cache the boolean result. GL context will never change on Android. - static const bool hasNPotSupport = get_GL_major_version() > 1 && + // Note: we cache the boolean result, the GL context will never change. + static const bool supported = get_GL_major_version() > 1 && glGetString(GL_EXTENSIONS) && strstr((char *)glGetString(GL_EXTENSIONS), "GL_OES_texture_npot"); + return supported; +} - if (hasNPotSupport) +/** + * Check and align image to npot2 if required by hardware + * @param image image to check for npot2 alignment + * @param driver driver to use for image operations + * @return image or copy of image aligned to npot2 + */ + +video::IImage * Align2Npot2(video::IImage * image, + video::IVideoDriver* driver) +{ + if (image == NULL) + return image; + + if (hasNPotSupport()) return image; + core::dimension2d<u32> dim = image->getDimension(); unsigned int height = npot2(dim.Height); unsigned int width = npot2(dim.Width); - if ((dim.Height == height) && - (dim.Width == width)) { + if (dim.Height == height && dim.Width == width) return image; - } - if (dim.Height > height) { + if (dim.Height > height) height *= 2; - } - - if (dim.Width > width) { + if (dim.Width > width) width *= 2; - } video::IImage *targetimage = driver->createImage(video::ECF_A8R8G8B8, core::dimension2d<u32>(width, height)); - if (targetimage != NULL) { + if (targetimage != NULL) image->copyToScaling(targetimage); - } image->drop(); return targetimage; } diff --git a/src/client/tile.h b/src/client/tile.h index 3021e119d..3a3ec58a3 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -135,6 +135,7 @@ public: IWritableTextureSource *createTextureSource(); #if ENABLE_GLES +bool hasNPotSupport(); video::IImage * Align2Npot2(video::IImage * image, irr::video::IVideoDriver* driver); #endif |