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) const SExposedVideoData& data)
{ {
EglDisplay = EGL_NO_DISPLAY; EglDisplay = EGL_NO_DISPLAY;
EglSurface = EGL_NO_SURFACE;
EglContext = EGL_NO_CONTEXT;
EglConfig = 0;
EglWindow = 0;
EGLVersionMajor = 1;
EGLVersionMinor = 0;
IsCoreContext = true; IsCoreContext = true;
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) #if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
@ -28,38 +34,38 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params,
#endif #endif
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) #if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
EglWindow = (NativeWindowType)data.OpenGLWin32.HWnd; EglWindow = (NativeWindowType)data.OpenGLWin32.HWnd;
HDc = GetDC((HWND)EglWindow); HDc = GetDC((HWND)EglWindow);
EglDisplay = eglGetDisplay((NativeDisplayType)HDc); EglDisplay = eglGetDisplay((NativeDisplayType)HDc);
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
EglWindow = (NativeWindowType)data.OpenGLLinux.X11Window; EglWindow = (NativeWindowType)data.OpenGLLinux.X11Window;
EglDisplay = eglGetDisplay((NativeDisplayType)data.OpenGLLinux.X11Display); EglDisplay = eglGetDisplay((NativeDisplayType)data.OpenGLLinux.X11Display);
#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) #elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
EglWindow = ((struct android_app *)(params.PrivateData))->window; EglWindow = ((struct android_app *)(params.PrivateData))->window;
EglDisplay = EGL_NO_DISPLAY; EglDisplay = EGL_NO_DISPLAY;
#endif #endif
if (EglDisplay == EGL_NO_DISPLAY) if (EglDisplay == EGL_NO_DISPLAY)
{ {
os::Printer::log("Getting OpenGL-ES2 display."); os::Printer::log("Getting EGL display.");
EglDisplay = eglGetDisplay((NativeDisplayType) EGL_DEFAULT_DISPLAY); EglDisplay = eglGetDisplay((NativeDisplayType) EGL_DEFAULT_DISPLAY);
} }
if (EglDisplay == EGL_NO_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, &EGLVersionMajor, &EGLVersionMinor))
if (!eglInitialize(EglDisplay, &majorVersion, &minorVersion)) {
{ os::Printer::log("Could not initialize EGL display.");
os::Printer::log("Could not initialize OpenGL-ES2 display."); }
} else
else {
{ char text[64];
char text[64]; sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", EGLVersionMajor, EGLVersionMinor);
sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", majorVersion, minorVersion); os::Printer::log(text);
os::Printer::log(text); }
}
EGLint EglOpenGLBIT = 0; EGLint EglOpenGLBIT = 0;
@ -85,9 +91,7 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params,
EGL_STENCIL_SIZE, params.Stencilbuffer, EGL_STENCIL_SIZE, params.Stencilbuffer,
EGL_SAMPLE_BUFFERS, params.AntiAlias ? 1:0, EGL_SAMPLE_BUFFERS, params.AntiAlias ? 1:0,
EGL_SAMPLES, params.AntiAlias, EGL_SAMPLES, params.AntiAlias,
#ifdef EGL_VERSION_1_3
EGL_RENDERABLE_TYPE, EglOpenGLBIT, EGL_RENDERABLE_TYPE, EglOpenGLBIT,
#endif
EGL_NONE, 0 EGL_NONE, 0
}; };
@ -177,105 +181,73 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params,
if (params.Bits > Attribs[9]) if (params.Bits > Attribs[9])
os::Printer::log("No full color buffer."); os::Printer::log("No full color buffer.");
#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
* As soon as we picked a EGLConfig, we can safely reconfigure the * As soon as we picked a EGLConfig, we can safely reconfigure the
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
EGLint format; EGLint format;
eglGetConfigAttrib(EglDisplay, EglConfig, 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, EglConfig, EglWindow, NULL);
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.");
}
ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, format); eglBindAPI(EGL_OPENGL_ES_API);
#endif
os::Printer::log(" Creating EglSurface with nativeWindow..."); os::Printer::log("Creating EglContext...");
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, NULL);
if (EGL_NO_SURFACE == EglSurface) if (!params.ForceLegacyDevice)
{
os::Printer::log("Trying to create Context for OpenGL ES3.");
EGLint contextAttrib[] =
{ {
os::Printer::log("FAILED\n"); EGL_CONTEXT_CLIENT_VERSION, 3,
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, NULL); EGL_NONE, 0
os::Printer::log("Creating EglSurface without nativeWindows..."); };
}
else EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib);
os::Printer::log("SUCCESS\n"); }
if (EGL_NO_SURFACE == EglSurface)
if (EGL_NO_CONTEXT == EglContext)
{
os::Printer::log("Trying to create Context for OpenGL ES2.");
EGLint contextAttrib[] =
{ {
os::Printer::log("FAILED\n"); EGL_CONTEXT_CLIENT_VERSION, 2,
os::Printer::log("Could not create surface for OpenGL-ES2 display."); EGL_NONE, 0
} };
else
os::Printer::log("SUCCESS\n"); EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib);
IsCoreContext = false;
}
#ifdef EGL_VERSION_1_2 eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext);
if (minorVersion>1) if (testEGLError())
eglBindAPI(EGL_OPENGL_ES_API); {
#endif os::Printer::log("Could not make Context current for EGL display.");
os::Printer::log("Creating EglContext..."); }
EglContext = EGL_NO_CONTEXT;
if (!params.ForceLegacyDevice) // set vsync
{ if (params.Vsync)
os::Printer::log("Trying to create Context for OpenGL-ES3."); eglSwapInterval(EglDisplay, 1);
EGLint contextAttrib[] = os::Printer::log(eglQueryString(EglDisplay, EGL_CLIENT_APIS));
{
#ifdef EGL_VERSION_1_3
EGL_CONTEXT_CLIENT_VERSION, 3,
#endif
EGL_NONE, 0
};
EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib);
}
if (EGL_NO_CONTEXT == EglContext)
{
os::Printer::log("Trying to create Context for OpenGL-ES2.");
IsCoreContext = false;
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.");
}
}
eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext);
if (testEGLError())
{
os::Printer::log("Could not make Context current for OpenGL-ES2 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 #endif
if (!EglWindow) 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); eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

View File

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