Assume that EGL version is always greater than 1.3 because otherwise we won't be able to create GLES 2.0/3.0 context.

This commit is contained in:
Deve 2017-04-05 21:41:25 +02:00
parent 635ea89cd0
commit 1d39030f51
2 changed files with 98 additions and 125 deletions

View File

@ -21,6 +21,12 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params,
const SExposedVideoData& data)
{
EglDisplay = EGL_NO_DISPLAY;
EglSurface = EGL_NO_SURFACE;
EglContext = EGL_NO_CONTEXT;
EglConfig = 0;
EglWindow = 0;
EGLVersionMajor = 1;
EGLVersionMinor = 0;
IsCoreContext = true;
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
@ -41,23 +47,23 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params,
if (EglDisplay == EGL_NO_DISPLAY)
{
os::Printer::log("Getting OpenGL-ES2 display.");
os::Printer::log("Getting EGL display.");
EglDisplay = eglGetDisplay((NativeDisplayType) EGL_DEFAULT_DISPLAY);
}
if (EglDisplay == EGL_NO_DISPLAY)
{
os::Printer::log("Could not get OpenGL-ES2 display.");
os::Printer::log("Could not get EGL display.");
}
EGLint majorVersion, minorVersion;
if (!eglInitialize(EglDisplay, &majorVersion, &minorVersion))
if (!eglInitialize(EglDisplay, &EGLVersionMajor, &EGLVersionMinor))
{
os::Printer::log("Could not initialize OpenGL-ES2 display.");
os::Printer::log("Could not initialize EGL display.");
}
else
{
char text[64];
sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", majorVersion, minorVersion);
sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", EGLVersionMajor, EGLVersionMinor);
os::Printer::log(text);
}
@ -85,9 +91,7 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params,
EGL_STENCIL_SIZE, params.Stencilbuffer,
EGL_SAMPLE_BUFFERS, params.AntiAlias ? 1:0,
EGL_SAMPLES, params.AntiAlias,
#ifdef EGL_VERSION_1_3
EGL_RENDERABLE_TYPE, EglOpenGLBIT,
#endif
EGL_NONE, 0
};
@ -187,40 +191,33 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params,
ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, format);
#endif
os::Printer::log(" Creating EglSurface with nativeWindow...");
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, NULL);
if (EGL_NO_SURFACE == EglSurface)
{
os::Printer::log("FAILED\n");
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, NULL);
os::Printer::log("Creating EglSurface without nativeWindows...");
}
else
os::Printer::log("SUCCESS\n");
if (EGL_NO_SURFACE == EglSurface)
{
os::Printer::log("FAILED\n");
os::Printer::log("Could not create surface for OpenGL-ES2 display.");
}
else
os::Printer::log("SUCCESS\n");
#ifdef EGL_VERSION_1_2
if (minorVersion>1)
if (EGL_NO_SURFACE == EglSurface)
{
os::Printer::log("FAILED");
os::Printer::log("Creating EglSurface without nativeWindows...");
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, NULL);
}
if (EGL_NO_SURFACE == EglSurface)
{
os::Printer::log("FAILED");
os::Printer::log("Could not create surface for EGL display.");
}
eglBindAPI(EGL_OPENGL_ES_API);
#endif
os::Printer::log("Creating EglContext...");
EglContext = EGL_NO_CONTEXT;
if (!params.ForceLegacyDevice)
{
os::Printer::log("Trying to create Context for OpenGL-ES3.");
os::Printer::log("Trying to create Context for OpenGL ES3.");
EGLint contextAttrib[] =
{
#ifdef EGL_VERSION_1_3
EGL_CONTEXT_CLIENT_VERSION, 3,
#endif
EGL_NONE, 0
};
@ -229,52 +226,27 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params,
if (EGL_NO_CONTEXT == EglContext)
{
os::Printer::log("Trying to create Context for OpenGL-ES2.");
IsCoreContext = false;
os::Printer::log("Trying to create Context for OpenGL ES2.");
EGLint contextAttrib[] =
{
#ifdef EGL_VERSION_1_3
EGL_CONTEXT_CLIENT_VERSION, 2,
#endif
EGL_NONE, 0
};
EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib);
if (EGL_NO_CONTEXT == EglContext)
{
os::Printer::log("FAILED\n");
os::Printer::log("Could not create Context for OpenGL-ES2 display.");
}
IsCoreContext = false;
}
eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext);
if (testEGLError())
{
os::Printer::log("Could not make Context current for OpenGL-ES2 display.");
os::Printer::log("Could not make Context current for EGL display.");
}
//~ #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
//~ int backingWidth;
//~ int backingHeight;
//~ eglQuerySurface(EglDisplay, EglSurface, EGL_WIDTH, &backingWidth);
//~ eglQuerySurface(EglDisplay, EglSurface, EGL_HEIGHT, &backingHeight);
//~ core::dimension2d<u32> WindowSize(backingWidth, backingHeight);
//~ CNullDriver::ScreenSize = WindowSize;
//~ #endif
// set vsync
if (params.Vsync)
eglSwapInterval(EglDisplay, 1);
const f32 egl_ver = core::fast_atof(reinterpret_cast<const c8*>(eglQueryString(EglDisplay, EGL_VERSION)));
EGLVersion = static_cast<u16>(core::floor32(egl_ver)*100+core::round32(core::fract(egl_ver)*10.0f));
core::stringc eglExtensions = eglQueryString(EglDisplay, EGL_EXTENSIONS);
os::Printer::log(eglExtensions.c_str());
os::Printer::log(eglQueryString(EglDisplay, EGL_CLIENT_APIS));
}
@ -326,7 +298,7 @@ void ContextEGL::reloadEGLSurface(void* window)
#endif
if (!EglWindow)
os::Printer::log("Invalid Egl window.");
os::Printer::log("Invalid EGL window.");
eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

View File

@ -48,7 +48,8 @@ private:
void* EglSurface;
void* EglContext;
EGLConfig EglConfig;
u16 EGLVersion;
int EGLVersionMajor;
int EGLVersionMinor;
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
HDC HDc;