Page 1 of 1

patch for android w/ gles2 crash

Posted: Sun Jan 20, 2013 5:33 am
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/

Re: patch for android w/ gles2 crash

Posted: Sun Jan 20, 2013 12:07 pm
by Nadro
Thanks for this patch. I'll test them today or tomorrow and next apply them to core :)

Re: patch for android w/ gles2 crash

Posted: Sun Jan 20, 2013 6:27 pm
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.

Re: patch for android w/ gles2 crash

Posted: Sun Jan 20, 2013 6:36 pm
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)
 

Re: patch for android w/ gles2 crash

Posted: Sun Jan 20, 2013 6:42 pm
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.

Re: patch for android w/ gles2 crash

Posted: Mon Jan 21, 2013 6:59 pm
by Nadro
Thanks for update. I'll test it on the latest NDK + SDK.

Re: patch for android w/ gles2 crash

Posted: Thu Apr 18, 2013 5:12 am
by Nadro
Patch applied to ogl-es.