Unify OpenGL ES support
authorsfan5 <sfan5@live.de>
Wed, 24 Jul 2019 22:01:25 +0000 (00:01 +0200)
committersfan5 <sfan5@live.de>
Sun, 4 Aug 2019 14:12:52 +0000 (16:12 +0200)
build/android/jni/Android.mk
src/client/renderingengine.cpp
src/client/sky.cpp
src/client/tile.cpp
src/client/tile.h
src/defaultsettings.cpp
src/gui/guiEngine.cpp
src/itemdef.cpp

index ade2bb9c507cde3f299bc9181e5ef8f8f0531d26..17b2606ceab0a3340fea7c6339c27f33b2584ae9 100644 (file)
@@ -65,6 +65,7 @@ endif
 
 LOCAL_CFLAGS := -D_IRR_ANDROID_PLATFORM_      \
                -DHAVE_TOUCHSCREENGUI         \
+               -DENABLE_GLES=1               \
                -DUSE_CURL=1                  \
                -DUSE_SOUND=1                 \
                -DUSE_FREETYPE=1              \
index 631616c06fc09b6e4d34053d3cb50724fe2b5cb3..6e6509eebba8ad4b88490caa9d71299df67a1e55 100644 (file)
@@ -48,7 +48,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #endif
 
-#ifdef __ANDROID__
+#if ENABLE_GLES
 #include "filesys.h"
 #endif
 
@@ -131,6 +131,11 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
        params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM + "media" +
                DIR_DELIM + "Shaders" + DIR_DELIM).c_str();
        // clang-format on
+#elif ENABLE_GLES
+       // there is no standardized path for these on desktop
+       std::string rel_path = std::string("client") + DIR_DELIM
+                       + "shaders" + DIR_DELIM + "Irrlicht";
+       params.OGLES2ShaderPath = (porting::path_share + DIR_DELIM + rel_path + DIR_DELIM).c_str();
 #endif
 
        m_device = createDeviceEx(params);
index 9d095745052f05c70f3784ac157a249d4042d3fb..346cd0642cecbb4d6422483476cad2e9d9b0f5d4 100644 (file)
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client/renderingengine.h"
 #include "settings.h"
 #include "camera.h"  // CameraModes
+#include "config.h"
 
 
 Sky::Sky(s32 id, ITextureSource *tsrc):
@@ -44,7 +45,7 @@ Sky::Sky(s32 id, ITextureSource *tsrc):
 
        video::SMaterial mat;
        mat.Lighting = false;
-#ifdef __ANDROID__
+#if ENABLE_GLES
        mat.ZBuffer = video::ECFN_DISABLED;
 #else
        mat.ZBuffer = video::ECFN_NEVER;
@@ -273,7 +274,7 @@ void Sky::render()
                        // Stars are only drawn when brighter than skycolor
                        if (starcolor.getBlue() < m_skycolor.getBlue())
                                break;
-#ifdef __ANDROID__
+#if ENABLE_GLES
                        u16 indices[SKY_STAR_COUNT * 3];
                        video::S3DVertex vertices[SKY_STAR_COUNT * 3];
                        for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
index 72f7358b1c6a2d2e6f53c0ab5b1619576f18dc53..82f989d89f543358b26f76e8edbf4bf784f3812f 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include <algorithm>
 #include <ICameraSceneNode.h>
+#include <IrrCompileConfig.h>
 #include "util/string.h"
 #include "util/container.h"
 #include "util/thread.h"
@@ -34,8 +35,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "renderingengine.h"
 
 
-#ifdef __ANDROID__
+#if ENABLE_GLES
+#ifdef _IRR_COMPILE_WITH_OGLES1_
 #include <GLES/gl.h>
+#else
+#include <GLES2/gl2.h>
+#endif
 #endif
 
 /*
@@ -595,7 +600,7 @@ u32 TextureSource::generateTexture(const std::string &name)
        video::ITexture *tex = NULL;
 
        if (img != NULL) {
-#ifdef __ANDROID__
+#if ENABLE_GLES
                img = Align2Npot2(img, driver);
 #endif
                // Create texture from resulting image
@@ -752,7 +757,7 @@ void TextureSource::rebuildImagesAndTextures()
        // Recreate textures
        for (TextureInfo &ti : m_textureinfo_cache) {
                video::IImage *img = generateImage(ti.name);
-#ifdef __ANDROID__
+#if ENABLE_GLES
                img = Align2Npot2(img, driver);
 #endif
                // Create texture from resulting image
@@ -989,8 +994,7 @@ video::IImage* TextureSource::generateImage(const std::string &name)
        return baseimg;
 }
 
-#ifdef __ANDROID__
-#include <GLES/gl.h>
+#if ENABLE_GLES
 /**
  * Check and align image to npot2 if required by hardware
  * @param image image to check for npot2 alignment
@@ -998,7 +1002,7 @@ video::IImage* TextureSource::generateImage(const std::string &name)
  * @return image or copy of image aligned to npot2
  */
 
-inline u16 get_GL_major_version()
+static inline u16 get_GL_major_version()
 {
        const GLubyte *gl_version = glGetString(GL_VERSION);
        return (u16) (gl_version[0] - '0');
@@ -1078,7 +1082,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
        // Stuff starting with [ are special commands
        if (part_of_name.empty() || part_of_name[0] != '[') {
                video::IImage *image = m_sourcecache.getOrLoad(part_of_name);
-#ifdef __ANDROID__
+#if ENABLE_GLES
                image = Align2Npot2(image, driver);
 #endif
                if (image == NULL) {
index d0c45b4a4025fa7cdbec67039cfaaf7f129fb4a8..3021e119da21b6f4e46d2379156a8bc78958ca0d 100644 (file)
@@ -27,8 +27,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <SMaterial.h>
 #include <memory>
 #include "util/numeric.h"
+#include "config.h"
 
-#if __ANDROID__
+#if ENABLE_GLES
 #include <IVideoDriver.h>
 #endif
 
@@ -133,7 +134,7 @@ public:
 
 IWritableTextureSource *createTextureSource();
 
-#ifdef __ANDROID__
+#if ENABLE_GLES
 video::IImage * Align2Npot2(video::IImage * image, irr::video::IVideoDriver* driver);
 #endif
 
index dfaad0c637b85f9458eddf27f020aea2743aee9e..4c39a44e10e3b6af4113580cfebefc9751c28245 100644 (file)
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include <IrrCompileConfig.h>
 #include "settings.h"
 #include "porting.h"
 #include "filesys.h"
@@ -182,7 +183,15 @@ void set_default_settings(Settings *settings)
        settings->setDefault("lighting_boost_spread", "0.2");
        settings->setDefault("texture_path", "");
        settings->setDefault("shader_path", "");
+#if ENABLE_GLES
+#ifdef _IRR_COMPILE_WITH_OGLES1_
+       settings->setDefault("video_driver", "ogles1");
+#else
+       settings->setDefault("video_driver", "ogles2");
+#endif
+#else
        settings->setDefault("video_driver", "opengl");
+#endif
        settings->setDefault("cinematic", "false");
        settings->setDefault("camera_smoothing", "0");
        settings->setDefault("cinematic_camera_smoothing", "0.7");
@@ -217,7 +226,11 @@ void set_default_settings(Settings *settings)
        settings->setDefault("texture_clean_transparent", "false");
        settings->setDefault("texture_min_size", "64");
        settings->setDefault("ambient_occlusion_gamma", "2.2");
+#if ENABLE_GLES
+       settings->setDefault("enable_shaders", "false");
+#else
        settings->setDefault("enable_shaders", "true");
+#endif
        settings->setDefault("enable_particles", "true");
        settings->setDefault("arm_inertia", "true");
 
@@ -429,9 +442,7 @@ void set_default_settings(Settings *settings)
 #ifdef __ANDROID__
        settings->setDefault("screen_w", "0");
        settings->setDefault("screen_h", "0");
-       settings->setDefault("enable_shaders", "false");
        settings->setDefault("fullscreen", "true");
-       settings->setDefault("video_driver", "ogles1");
        settings->setDefault("touchtarget", "true");
        settings->setDefault("TMPFolder", porting::getDataPath("tmp" DIR_DELIM));
        settings->setDefault("touchscreen_threshold","20");
index f0a8f40eb230dc12d8255704abafecb42ed1048f..241144a2aa3678111932eb6dcbd599367e29082a 100644 (file)
@@ -39,9 +39,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client/guiscalingfilter.h"
 #include "irrlicht_changes/static_text.h"
 
-#ifdef __ANDROID__
+#if ENABLE_GLES
 #include "client/tile.h"
-#include <GLES/gl.h>
 #endif
 
 
@@ -78,7 +77,7 @@ video::ITexture *MenuTextureSource::getTexture(const std::string &name, u32 *id)
 
        m_to_delete.insert(name);
 
-#ifdef __ANDROID__
+#if ENABLE_GLES
        video::ITexture *retval = m_driver->findTexture(name.c_str());
        if (retval)
                return retval;
index 9d6068bab8e9199fd5af25fa4a2b97d01a52a2d7..0d0afeb2b869b8f6b2082d9f1ff4d64c7b52d821 100644 (file)
@@ -38,10 +38,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <map>
 #include <set>
 
-#ifdef __ANDROID__
-#include <GLES/gl.h>
-#endif
-
 /*
        ItemDefinition
 */