patch for android w/ gles2 crash

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
mchiasson
Posts: 12
Joined: Wed Feb 01, 2012 12:29 pm
Location: Ottawa, Ontario, Canada

patch for android w/ gles2 crash

Post by mchiasson »

My very first contribution to irrlicht! ^_^

Code: Select all

 
Index: source/Irrlicht/CIrrDeviceAndroid.cpp
===================================================================
--- source/Irrlicht/CIrrDeviceAndroid.cpp   (revision 4446)
+++ source/Irrlicht/CIrrDeviceAndroid.cpp   (working copy)
@@ -90,15 +90,17 @@
    // Create cursor control
    CursorControl = new CCursorControl(this);
 
+    // This step needs to be done before creating the driver for Android in order to be able to load the GLES2 shaders from the media folder
+    io::CAndroidAssetFileArchive *assets = io::createAndroidAssetFileArchive(false, false);
+    assets->addDirectory("media");
+    FileSystem->addFileArchive(assets);
+
    // Create the driver.
    createDriver();
        
    if (VideoDriver)    
        createGUIAndScene();
        
-   io::CAndroidAssetFileArchive *assets = io::createAndroidAssetFileArchive(false, false);
-   assets->addDirectory("media");
-   FileSystem->addFileArchive(assets);
    // TODO
    //
    // if engine->app->savedState is not NULL then use postEventFromUser() 
Index: source/Irrlicht/COGLES2Driver.cpp
===================================================================
--- source/Irrlicht/COGLES2Driver.cpp   (revision 4446)
+++ source/Irrlicht/COGLES2Driver.cpp   (working copy)
@@ -26,6 +26,9 @@
 #else
 #include <EGL/egl.h>
 #include <GLES2/gl2.h>
+#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
+#include "android_native_app_glue.h"
+#endif
 #endif
 
 namespace irr
@@ -68,6 +71,9 @@
        EglDisplay = eglGetDisplay((NativeDisplayType)ExposedData.OpenGLLinux.X11Display);
 #elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
        Device = device;
+#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
+    EglWindow = ((struct android_app *)(params.PrivateData))->window;
+    EglDisplay = EGL_NO_DISPLAY;
 #endif
 #ifdef EGL_VERSION_1_0
        if (EglDisplay == EGL_NO_DISPLAY)
Index: include/IrrCompileConfig.h
===================================================================
--- include/IrrCompileConfig.h  (revision 4446)
+++ include/IrrCompileConfig.h  (working copy)
@@ -206,6 +206,8 @@
 #ifndef IRR_OGLES2_SHADER_PATH
 #ifdef _IRR_COMPILE_WITH_IPHONE_DEVICE_
 #define IRR_OGLES2_SHADER_PATH ""
+#elif defined(_IRR_ANDROID_PLATFORM_)
+#define IRR_OGLES2_SHADER_PATH "media/Shaders/"
 #else
 #define IRR_OGLES2_SHADER_PATH "../../media/Shaders/"
 #endif
 
this is for https://irrlicht.svn.sourceforge.net/sv ... es/ogl-es/
Last edited by mchiasson on Sun Jan 20, 2013 6:38 pm, edited 2 times in total.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: patch for android w/ gles2 crash

Post by Nadro »

Thanks for this patch. I'll test them today or tomorrow and next apply them to core :)
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
mchiasson
Posts: 12
Joined: Wed Feb 01, 2012 12:29 pm
Location: Ottawa, Ontario, Canada

Re: patch for android w/ gles2 crash

Post by mchiasson »

No problem Nadro.

I actually made one last modification to IrrCompileConfig.h

Code: Select all

 
Index: include/IrrCompileConfig.h
===================================================================
--- include/IrrCompileConfig.h  (revision 4446)
+++ include/IrrCompileConfig.h  (working copy)
@@ -206,6 +206,8 @@
 #ifndef IRR_OGLES2_SHADER_PATH
 #ifdef _IRR_COMPILE_WITH_IPHONE_DEVICE_
 #define IRR_OGLES2_SHADER_PATH ""
+#elif defined(_IRR_ANDROID_PLATFORM_)
+#define IRR_OGLES2_SHADER_PATH "media/Shaders/"
 #else
 #define IRR_OGLES2_SHADER_PATH "../../media/Shaders/"
 #endif
 
I realized too late that I was breaking Linux Desktop OpenGL-ES2 support. This way, both platform will work.
mchiasson
Posts: 12
Joined: Wed Feb 01, 2012 12:29 pm
Location: Ottawa, Ontario, Canada

Re: patch for android w/ gles2 crash

Post by mchiasson »

Same with COGLES2Driver.cpp. Should only include android_native_app_glue.h when we're on Android. This way, I'm not breaking Linux Desktop GLES2 support.

Code: Select all

 
Index: source/Irrlicht/COGLES2Driver.cpp
===================================================================
--- source/Irrlicht/COGLES2Driver.cpp   (revision 4446)
+++ source/Irrlicht/COGLES2Driver.cpp   (working copy)
@@ -26,6 +26,9 @@
 #else
 #include <EGL/egl.h>
 #include <GLES2/gl2.h>
+#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
+#include "android_native_app_glue.h"
+#endif
 #endif
 
 namespace irr
@@ -68,6 +71,9 @@
        EglDisplay = eglGetDisplay((NativeDisplayType)ExposedData.OpenGLLinux.X11Display);
 #elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
        Device = device;
+#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
+    EglWindow = ((struct android_app *)(params.PrivateData))->window;
+    EglDisplay = EGL_NO_DISPLAY;
 #endif
 #ifdef EGL_VERSION_1_0
        if (EglDisplay == EGL_NO_DISPLAY)
 
mchiasson
Posts: 12
Joined: Wed Feb 01, 2012 12:29 pm
Location: Ottawa, Ontario, Canada

Re: patch for android w/ gles2 crash

Post by mchiasson »

I updated my first patch in my first post accordingly.

To test this on Android, I used the example #08, dropped the entire media folder in the assets folder, used Android SDK r21 and Android NDK android-ndk-r8d. I did not submit my modified Android.mk into this patch because I do not know which NDK you guys are using.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: patch for android w/ gles2 crash

Post by Nadro »

Thanks for update. I'll test it on the latest NDK + SDK.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: patch for android w/ gles2 crash

Post by Nadro »

Patch applied to ogl-es.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Post Reply