Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use Irrlicht functions to query npot texture support
  • Loading branch information
sfan5 committed May 5, 2021
1 parent de85bc9 commit 08f1a7f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 48 deletions.
14 changes: 5 additions & 9 deletions src/CMakeLists.txt
Expand Up @@ -102,11 +102,11 @@ endif()
option(ENABLE_GLES "Use OpenGL ES instead of OpenGL" FALSE)
mark_as_advanced(ENABLE_GLES)
if(BUILD_CLIENT)
if(ENABLE_GLES)
find_package(OpenGLES2 REQUIRED)
else()
# transitive dependency from Irrlicht (see longer explanation below)
if(NOT WIN32)
# transitive dependency from Irrlicht (see longer explanation below)
if(NOT WIN32)
if(ENABLE_GLES)
find_package(OpenGLES2 REQUIRED)
else()
set(OPENGL_GL_PREFERENCE "LEGACY" CACHE STRING
"See CMake Policy CMP0072 for reference. GLVND is broken on some nvidia setups")
set(OpenGL_GL_PREFERENCE ${OPENGL_GL_PREFERENCE})
Expand Down Expand Up @@ -523,10 +523,6 @@ include_directories(
${PROJECT_SOURCE_DIR}/script
)

if(ENABLE_GLES)
include_directories(${OPENGLES2_INCLUDE_DIR} ${EGL_INCLUDE_DIR})
endif()

if(USE_GETTEXT)
include_directories(${GETTEXT_INCLUDE_DIR})
endif()
Expand Down
3 changes: 1 addition & 2 deletions src/client/guiscalingfilter.cpp
Expand Up @@ -23,7 +23,6 @@ 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
Expand Down Expand Up @@ -117,7 +116,7 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
#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()) {
if (!driver->queryFeature(video::EVDF_TEXTURE_NPOT)) {
video::IImage *po2img = driver->createImage(src->getColorFormat(),
core::dimension2d<u32>(npot2((u32)destrect.getWidth()),
npot2((u32)destrect.getHeight())));
Expand Down
38 changes: 3 additions & 35 deletions src/client/tile.cpp
Expand Up @@ -34,15 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiscalingfilter.h"
#include "renderingengine.h"


#if ENABLE_GLES
#ifdef _IRR_COMPILE_WITH_OGLES1_
#include <GLES/gl.h>
#else
#include <GLES2/gl2.h>
#endif
#endif

/*
A cache from texture name to texture path
*/
Expand Down Expand Up @@ -1013,42 +1004,19 @@ video::IImage* TextureSource::generateImage(const std::string &name)

#if ENABLE_GLES


static inline u16 get_GL_major_version()
{
const GLubyte *gl_version = glGetString(GL_VERSION);
return (u16) (gl_version[0] - '0');
}

/**
* 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, 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;
}

/**
* 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)
video::IImage *Align2Npot2(video::IImage *image,
video::IVideoDriver *driver)
{
if (image == NULL)
return image;

if (hasNPotSupport())
if (driver->queryFeature(video::EVDF_TEXTURE_NPOT))
return image;

core::dimension2d<u32> dim = image->getDimension();
Expand Down
3 changes: 1 addition & 2 deletions src/client/tile.h
Expand Up @@ -134,8 +134,7 @@ class IWritableTextureSource : public ITextureSource
IWritableTextureSource *createTextureSource();

#if ENABLE_GLES
bool hasNPotSupport();
video::IImage * Align2Npot2(video::IImage * image, irr::video::IVideoDriver* driver);
video::IImage *Align2Npot2(video::IImage *image, video::IVideoDriver *driver);
#endif

enum MaterialType{
Expand Down

0 comments on commit 08f1a7f

Please sign in to comment.