Update common irrlicht files with modifications from Android branch.

- Added a function in GLES driver, which allows to re-create EGL surface when it's lost after resume event
- Some additional events/keycodes
- Fixed compilation with missing sys/sysctl.h header
This commit is contained in:
deve 2016-11-28 01:56:52 +01:00
parent 21ca9b40f0
commit 716c19325f
9 changed files with 154 additions and 17 deletions

View File

@ -83,6 +83,12 @@ namespace irr
MacOS: Not yet implemented
*/
EET_USER_EVENT,
//! Pass on raw events from the OS
EET_SYSTEM_EVENT,
//! Application state events like a resume, pause etc.
EET_APPLICATION_EVENT,
//! This enum is never used, it only forces the compiler to
//! compile these enumeration values to 32 bit.
@ -191,6 +197,42 @@ namespace irr
//! No real event. Just for convenience to get number of events
ETIE_COUNT
};
enum ESYSTEM_EVENT_TYPE
{
//! From Android command handler for native activity messages
ESET_ANDROID_CMD = 0,
// TODO: for example ESET_WINDOWS_MESSAGE for win32 message loop events
//! No real event, but to get number of event types
ESET_COUNT
};
//! Enumeration for a commonly used application state events (it's useful mainly for mobile devices)
enum EAPPLICATION_EVENT_TYPE
{
//! The application will be resumed.
EAET_WILL_RESUME = 0,
//! The application has been resumed.
EAET_DID_RESUME,
//! The application will be paused.
EAET_WILL_PAUSE,
//! The application has been paused.
EAET_DID_PAUSE,
//! The application will be terminated.
EAET_WILL_TERMINATE,
//! The application received a memory warning.
EAET_MEMORY_WARNING,
//! No real event, but to get number of event types.
EAET_COUNT
};
namespace gui
{
@ -365,12 +407,16 @@ struct SEvent
//! Any kind of keyboard event.
struct SKeyInput
{
//! Character corresponding to the key (0, if not a character)
//! Character corresponding to the key (0, if not a character, value undefined in key releases)
wchar_t Char;
//! Key which has been pressed or released
EKEY_CODE Key;
//! System dependent code. Only set for systems which are described below, otherwise undefined.
//! Android: int32_t with physical key as returned by AKeyEvent_getKeyCode
u32 SystemKeyCode;
//! If not true, then the key was left up
bool PressedDown:1;
@ -518,6 +564,31 @@ struct SEvent
//! Another user specified data as int
s32 UserData2;
};
// Raw events from the OS
struct SSystemEvent
{
//! Android command handler native activity messages.
struct SAndroidCmd
{
//! APP_CMD_ enums defined in android_native_app_glue.h from the Android NDK
s32 Cmd;
};
// TOOD: more structs for iphone, Windows, X11, etc.
ESYSTEM_EVENT_TYPE EventType;
union
{
struct SAndroidCmd AndroidCmd;
};
};
// Application state event
struct SApplicationEvent
{
EAPPLICATION_EVENT_TYPE EventType;
};
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
struct SInputMethodEvent
@ -547,6 +618,8 @@ struct SEvent
struct SJoystickEvent JoystickEvent;
struct SLogEvent LogEvent;
struct SUserEvent UserEvent;
struct SSystemEvent SystemEvent;
struct SApplicationEvent ApplicationEvent;
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
struct SInputMethodEvent InputMethodEvent;
#endif

View File

@ -10,6 +10,7 @@ namespace irr
enum EKEY_CODE
{
KEY_UNKNOWN = 0x0,
KEY_LBUTTON = 0x01, // Left mouse button
KEY_RBUTTON = 0x02, // Right mouse button
KEY_CANCEL = 0x03, // Control-break processing
@ -141,6 +142,20 @@ namespace irr
KEY_RCONTROL = 0xA3, // Right CONTROL key
KEY_LMENU = 0xA4, // Left MENU key
KEY_RMENU = 0xA5, // Right MENU key
KEY_BROWSER_BACK = 0xA6, // Browser Back key
KEY_BROWSER_FORWARD = 0xA7, // Browser Forward key
KEY_BROWSER_REFRESH = 0xA8, // Browser Refresh key
KEY_BROWSER_STOP = 0xA9, // Browser Stop key
KEY_BROWSER_SEARCH = 0xAA, // Browser Search key
KEY_BROWSER_FAVORITES =0xAB, // Browser Favorites key
KEY_BROWSER_HOME = 0xAC, // Browser Start and Home key
KEY_VOLUME_MUTE = 0xAD, // Volume Mute key
KEY_VOLUME_DOWN = 0xAE, // Volume Down key
KEY_VOLUME_UP = 0xAF, // Volume Up key
KEY_MEDIA_NEXT_TRACK = 0xB0, // Next Track key
KEY_MEDIA_PREV_TRACK = 0xB1, // Previous Track key
KEY_MEDIA_STOP = 0xB2, // Stop Media key
KEY_MEDIA_PLAY_PAUSE = 0xB3, // Play/Pause Media key
KEY_OEM_1 = 0xBA, // for US ";:"
KEY_PLUS = 0xBB, // Plus Key "+"
KEY_COMMA = 0xBC, // Comma Key ","

View File

@ -79,6 +79,12 @@ struct SExposedVideoData
void* X11Context;
unsigned long X11Window;
} OpenGLLinux;
struct
{
//! The ANativeWindow object.
void* Window;
} OGLESAndroid;
};
};

View File

@ -195,6 +195,20 @@ For functions: template<class T> _IRR_DEPRECATED_ void test4(void) {}
#define _IRR_DEPRECATED_
#endif
//! Defines an override macro, to protect virtual functions from typos and other mismatches
/** Usage in a derived class:
virtual void somefunc() _IRR_OVERRIDE_;
*/
#if ( ((__GNUC__ > 4 ) || ((__GNUC__ == 4 ) && (__GNUC_MINOR__ >= 7))) && (defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L) )
#define _IRR_OVERRIDE_ override
#elif (_MSC_VER >= 1600 ) /* supported since MSVC 2010 */
#define _IRR_OVERRIDE_ override
#elif (__clang_major__ >= 3)
#define _IRR_OVERRIDE_ override
#else
#define _IRR_OVERRIDE_
#endif
//! Defines a small statement to work around a microsoft compiler bug.
/** The microsoft compiler 7.0 - 7.1 has a bug:
When you call unmanaged code that returns a bool type value of false from managed code,

View File

@ -124,10 +124,9 @@ namespace video
#endif
};
EGLConfig config;
EGLint num_configs;
u32 steps=5;
while (!eglChooseConfig(EglDisplay, attribs, &config, 1, &num_configs) || !num_configs)
while (!eglChooseConfig(EglDisplay, attribs, &EglConfig, 1, &num_configs) || !num_configs)
{
switch (steps)
{
@ -208,16 +207,16 @@ namespace video
* As soon as we picked a EGLConfig, we can safely reconfigure the
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
EGLint format;
eglGetConfigAttrib(EglDisplay, config, EGL_NATIVE_VISUAL_ID, &format);
eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, format);
#endif
os::Printer::log(" Creating EglSurface with nativeWindow...");
EglSurface = eglCreateWindowSurface(EglDisplay, config, EglWindow, NULL);
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, NULL);
if (EGL_NO_SURFACE == EglSurface)
{
os::Printer::log("FAILED\n");
EglSurface = eglCreateWindowSurface(EglDisplay, config, NULL, NULL);
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, NULL, NULL);
os::Printer::log("Creating EglSurface without nativeWindows...");
}
else
@ -249,7 +248,7 @@ namespace video
EGL_NONE, 0
};
EglContext = eglCreateContext(EglDisplay, config, EGL_NO_CONTEXT, contextAttrib);
EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib);
}
if (EGL_NO_CONTEXT == EglContext)
@ -264,7 +263,7 @@ namespace video
EGL_NONE, 0
};
EglContext = eglCreateContext(EglDisplay, config, EGL_NO_CONTEXT, contextAttrib);
EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib);
if (EGL_NO_CONTEXT == EglContext)
{
os::Printer::log("FAILED\n");
@ -375,6 +374,32 @@ namespace video
// METHODS
// -----------------------------------------------------------------------
void COGLES2Driver::reloadEGLSurface(void* window)
{
os::Printer::log("Reload EGL surface.");
#ifdef EGL_VERSION_1_0
#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
EglWindow = (ANativeWindow*)window;
#endif
if (!EglWindow)
os::Printer::log("Invalid Egl window.");
eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface(EglDisplay, EglSurface);
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, 0);
if (EGL_NO_SURFACE == EglSurface)
os::Printer::log("Could not create EGL surface.");
eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext);
#endif
}
bool COGLES2Driver::genericDriverInit(const core::dimension2d<u32>& screenSize, bool stencilBuffer)
{
Name = glGetString(GL_VERSION);

View File

@ -381,6 +381,8 @@ namespace video
//! Get bridge calls.
COGLES2CallBridge* getBridgeCalls() const;
void reloadEGLSurface(void* window);
private:
// Bridge calls.
COGLES2CallBridge* BridgeCalls;
@ -477,6 +479,7 @@ namespace video
void* EglDisplay;
void* EglSurface;
void* EglContext;
EGLConfig EglConfig;
#endif
SIrrlichtCreationParameters Params;

View File

@ -14,9 +14,13 @@
#if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__)
#include <sys/param.h>
#include <sys/types.h>
#ifdef ANDROID
#include <linux/sysctl.h>
#else
#include <sys/sysctl.h>
#endif
#endif
#endif
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
#include "CIrrDeviceLinux.h"

View File

@ -105,11 +105,8 @@ namespace irr
#endif
#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s %d", __FILE__, __LINE__);
if (params.DeviceType == EIDT_ANDROID || (!dev && params.DeviceType == EIDT_BEST)) {
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s %d", __FILE__, __LINE__);
dev = new CIrrDeviceAndroid(params);
}
if (params.DeviceType == EIDT_ANDROID || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceAndroid(params);
#endif
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_

View File

@ -181,7 +181,7 @@ namespace os
void Printer::log(const c8* message, ELOG_LEVEL ll)
{
#ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s", message);
__android_log_print(ANDROID_LOG_VERBOSE, "Irrlicht", "%s", message);
#endif
if (Logger)
Logger->log(message, ll);
@ -192,7 +192,7 @@ namespace os
#ifdef _IRR_ANDROID_PLATFORM_
char test[200];
wcstombs(test, message, 200);
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s", test);
__android_log_print(ANDROID_LOG_VERBOSE, "Irrlicht", "%s", test);
#endif
if (Logger)
Logger->log(message, ll);
@ -201,7 +201,7 @@ namespace os
void Printer::log(const c8* message, const c8* hint, ELOG_LEVEL ll)
{
#ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s %s", message, hint);
__android_log_print(ANDROID_LOG_VERBOSE, "Irrlicht", "%s %s", message, hint);
#endif
if (Logger)
Logger->log(message, hint, ll);
@ -210,7 +210,7 @@ namespace os
void Printer::log(const c8* message, const io::path& hint, ELOG_LEVEL ll)
{
#ifdef _IRR_ANDROID_PLATFORM_
__android_log_print(ANDROID_LOG_VERBOSE, "native-activity", "%s %s", message, core::stringc(hint).c_str());
__android_log_print(ANDROID_LOG_VERBOSE, "Irrlicht", "%s %s", message, core::stringc(hint).c_str());
#endif
if (Logger)
Logger->log(message, hint.c_str(), ll);