Skip to content

Commit

Permalink
Revert "Irrlicht: Use EGL over GLX (minetest#15286)"
Browse files Browse the repository at this point in the history
This reverts commit aa27311.
  • Loading branch information
sfan5 authored Oct 23, 2024
1 parent d52e4cd commit 2c578e2
Show file tree
Hide file tree
Showing 8 changed files with 548 additions and 128 deletions.
7 changes: 7 additions & 0 deletions irr/include/SExposedVideoData.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ struct SExposedVideoData
void *Window;
};

struct SOpenGLFB
{
//! The EGLNativeWindowType object.
void *Window;
};

struct SOGLESAndroid
{
//! The ANativeWindow object.
Expand All @@ -74,6 +80,7 @@ struct SExposedVideoData
SOpenGLWin32 OpenGLWin32;
SOpenGLLinux OpenGLLinux;
SOpenGLOSX OpenGLOSX;
SOpenGLFB OpenGLFB;
SOGLESAndroid OGLESAndroid;
};
};
Expand Down
116 changes: 34 additions & 82 deletions irr/src/CEGLManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,32 @@ bool CEGLManager::initialize(const SIrrlichtCreationParameters &params, const SE
if (EglWindow != 0 && EglDisplay != EGL_NO_DISPLAY)
return true;

// Window is depend on platform.
setWindow(Data);
// Window is depend on platform.
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
EglWindow = (NativeWindowType)Data.OpenGLWin32.HWnd;
Data.OpenGLWin32.HDc = GetDC((HWND)EglWindow);
EglDisplay = eglGetDisplay((NativeDisplayType)Data.OpenGLWin32.HDc);
#elif defined(_IRR_EMSCRIPTEN_PLATFORM_)
EglWindow = 0;
EglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
EglWindow = (NativeWindowType)Data.OpenGLLinux.X11Window;
EglDisplay = eglGetDisplay((NativeDisplayType)Data.OpenGLLinux.X11Display);
#elif defined(_IRR_COMPILE_WITH_FB_DEVICE_)
EglWindow = (NativeWindowType)Data.OpenGLFB.Window;
EglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
#endif

// We must check if EGL display is valid.
if (EglDisplay == EGL_NO_DISPLAY) {
os::Printer::log("Could not get EGL display.", ELL_ERROR);
os::Printer::log("Could not get EGL display.");
terminate();
return false;
}

// Initialize EGL here.
if (!eglInitialize(EglDisplay, &MajorVersion, &MinorVersion)) {
os::Printer::log("Could not initialize EGL display.", ELL_ERROR);
os::Printer::log("Could not initialize EGL display.");

EglDisplay = EGL_NO_DISPLAY;
terminate();
Expand All @@ -70,22 +76,6 @@ bool CEGLManager::initialize(const SIrrlichtCreationParameters &params, const SE
return true;
}

void CEGLManager::setWindow(const SExposedVideoData &inData)
{
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
Data.OpenGLWin32.HWnd = inData.OpenGLWin32.HWnd;
if (Data.OpenGLWin32.HWnd) {
EglWindow = (NativeWindowType)Data.OpenGLWin32.HWnd;
Data.OpenGLWin32.HDc = GetDC((HWND)EglWindow);
}
#elif defined(_IRR_EMSCRIPTEN_PLATFORM_)
EglWindow = 0;
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
Data.OpenGLLinux.X11Window = inData.OpenGLLinux.X11Window;
EglWindow = (NativeWindowType)Data.OpenGLLinux.X11Window;
#endif
}

void CEGLManager::terminate()
{
if (EglWindow == 0 && EglDisplay == EGL_NO_DISPLAY)
Expand Down Expand Up @@ -118,16 +108,20 @@ bool CEGLManager::generateSurface()
if (EglSurface != EGL_NO_SURFACE)
return true;

if (!EglConfig) {
// We should assign new WindowID on platforms, where WindowID may change at runtime,
// at this time only Android support this feature.
// this needs an update method instead!

#if defined(_IRR_EMSCRIPTEN_PLATFORM_)
EglConfig = chooseConfig(ECS_IRR_CHOOSE);
// eglChooseConfig is currently only implemented as stub in emscripten (version 1.37.22 at point of writing)
// But the other solution would also be fine as it also only generates a single context so there is not much to choose from.
EglConfig = chooseConfig(ECS_IRR_CHOOSE);
#else
EglConfig = chooseConfig(ECS_EGL_CHOOSE_FIRST_LOWER_EXPECTATIONS);
EglConfig = chooseConfig(ECS_EGL_CHOOSE_FIRST_LOWER_EXPECTATIONS);
#endif
}

if (!EglConfig) {
os::Printer::log("Could not choose EGL config.", ELL_ERROR);
if (EglConfig == 0) {
os::Printer::log("Could not get config for EGL display.");
return false;
}

Expand All @@ -138,26 +132,11 @@ bool CEGLManager::generateSurface()
EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, 0);

if (EGL_NO_SURFACE == EglSurface)
os::Printer::log("Could not create EGL surface.", ELL_ERROR);
os::Printer::log("Could not create EGL surface.");

#ifdef EGL_VERSION_1_2
if (MinorVersion > 1) {
EGLBoolean ok = 0;
switch (Params.DriverType) {
case EDT_OGLES2:
case EDT_WEBGL1:
ok = eglBindAPI(EGL_OPENGL_ES_API);
break;
case EDT_OPENGL:
ok = eglBindAPI(EGL_OPENGL_API);
default:
break;
}
if (!ok) {
os::Printer::log("Could not bind EGL API.", ELL_ERROR);
return false;
}
}
if (MinorVersion > 1)
eglBindAPI(EGL_OPENGL_ES_API);
#endif

if (Params.Vsync)
Expand All @@ -166,26 +145,6 @@ bool CEGLManager::generateSurface()
return true;
}

EGLint CEGLManager::getNativeVisualID()
{
if (!EglConfig) {
#if defined(_IRR_EMSCRIPTEN_PLATFORM_)
EglConfig = chooseConfig(ECS_IRR_CHOOSE);
#else
EglConfig = chooseConfig(ECS_EGL_CHOOSE_FIRST_LOWER_EXPECTATIONS);
#endif
}

if (!EglConfig) {
os::Printer::log("Could not choose EGL config.", ELL_WARNING);
return 0;
}

EGLint ret = 0;
eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &ret);
return ret;
}

EGLConfig CEGLManager::chooseConfig(EConfigStyle confStyle)
{
EGLConfig configResult = 0;
Expand All @@ -197,8 +156,6 @@ EGLConfig CEGLManager::chooseConfig(EConfigStyle confStyle)
case EDT_WEBGL1:
eglOpenGLBIT = EGL_OPENGL_ES2_BIT;
break;
case EDT_OPENGL:
eglOpenGLBIT = EGL_OPENGL_BIT;
default:
break;
}
Expand Down Expand Up @@ -339,8 +296,6 @@ EGLConfig CEGLManager::chooseConfig(EConfigStyle confStyle)
}

delete[] configs;
} else {
_IRR_DEBUG_BREAK_IF(1)
}

return configResult;
Expand Down Expand Up @@ -498,36 +453,33 @@ bool CEGLManager::generateContext()
if (EglContext != EGL_NO_CONTEXT)
return true;

std::vector<EGLint> ContextAttrib;
EGLint OpenGLESVersion = 0;

switch (Params.DriverType) {
case EDT_OGLES2:
case EDT_WEBGL1:
#ifdef EGL_VERSION_1_3
ContextAttrib.push_back(EGL_CONTEXT_CLIENT_VERSION);
ContextAttrib.push_back(2);
#endif
break;
case EDT_OPENGL:
#ifdef EGL_VERSION_1_5
ContextAttrib.push_back(EGL_CONTEXT_OPENGL_PROFILE_MASK);
ContextAttrib.push_back(EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT);
#endif
OpenGLESVersion = 2;
break;
default:
break;
}

ContextAttrib.push_back(EGL_NONE);
ContextAttrib.push_back(0);
EGLint ContextAttrib[] = {
#ifdef EGL_VERSION_1_3
EGL_CONTEXT_CLIENT_VERSION, OpenGLESVersion,
#endif
EGL_NONE, 0,
};

EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, ContextAttrib.data());
EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, ContextAttrib);

if (testEGLError()) {
os::Printer::log("Could not create EGL context.", ELL_ERROR);
return false;
}

os::Printer::log("EGL context created with OpenGLESVersion: ", core::stringc((int)OpenGLESVersion), ELL_DEBUG);

return true;
}

Expand Down
7 changes: 0 additions & 7 deletions irr/src/CEGLManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class CEGLManager : public IContextManager
aren't create. */
bool initialize(const SIrrlichtCreationParameters &params, const SExposedVideoData &data) override;

// Set EGL window.
// Call this if window is not known at time of initialize()
void setWindow(const SExposedVideoData &data);

// Terminate EGL.
/* Terminate EGL context. This method break both existed surface and context. */
void terminate() override;
Expand Down Expand Up @@ -70,9 +66,6 @@ class CEGLManager : public IContextManager
// Swap buffers.
bool swapBuffers() override;

// Returns native visual ID. Will choose config if not already done.
EGLint getNativeVisualID();

protected:
enum EConfigStyle
{
Expand Down
Loading

0 comments on commit 2c578e2

Please sign in to comment.