mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-28 07:48:37 -04:00
egl: Further robustify EGL device initialization process
Sometimes, the default device fails to initialize, so then we need to fall back to alternatives (eg. GBM)
This commit is contained in:
parent
3955c71435
commit
2d9cc2dea0
@ -49,6 +49,8 @@ eglGraphicsPipe() {
|
|||||||
<< "EGL client extensions not supported.\n";
|
<< "EGL client extensions not supported.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EGLint major, minor;
|
||||||
|
|
||||||
//NB. if the X11 display failed to open, _display will be 0, which is a valid
|
//NB. if the X11 display failed to open, _display will be 0, which is a valid
|
||||||
// input to eglGetDisplay - it means to open the default display.
|
// input to eglGetDisplay - it means to open the default display.
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
@ -56,6 +58,12 @@ eglGraphicsPipe() {
|
|||||||
#else
|
#else
|
||||||
_egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
_egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
#endif
|
#endif
|
||||||
|
if (_egl_display && !eglInitialize(_egl_display, &major, &minor)) {
|
||||||
|
egldisplay_cat.warning()
|
||||||
|
<< "Couldn't initialize the default EGL display: "
|
||||||
|
<< get_egl_error_string(eglGetError()) << "\n";
|
||||||
|
_egl_display = EGL_NO_DISPLAY;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_egl_display &&
|
if (!_egl_display &&
|
||||||
std::find(extensions.begin(), extensions.end(), "EGL_EXT_platform_device") != extensions.end() &&
|
std::find(extensions.begin(), extensions.end(), "EGL_EXT_platform_device") != extensions.end() &&
|
||||||
@ -65,7 +73,9 @@ eglGraphicsPipe() {
|
|||||||
(PFNEGLQUERYDEVICESEXTPROC)eglGetProcAddress("eglQueryDevicesEXT");
|
(PFNEGLQUERYDEVICESEXTPROC)eglGetProcAddress("eglQueryDevicesEXT");
|
||||||
|
|
||||||
EGLint num_devices = 0;
|
EGLint num_devices = 0;
|
||||||
if (eglQueryDevicesEXT(0, nullptr, &num_devices) && num_devices > 0) {
|
if (eglQueryDevicesEXT != nullptr &&
|
||||||
|
eglQueryDevicesEXT(0, nullptr, &num_devices) &&
|
||||||
|
num_devices > 0) {
|
||||||
EGLDeviceEXT *devices = (EGLDeviceEXT *)alloca(sizeof(EGLDeviceEXT) * num_devices);
|
EGLDeviceEXT *devices = (EGLDeviceEXT *)alloca(sizeof(EGLDeviceEXT) * num_devices);
|
||||||
eglQueryDevicesEXT(num_devices, devices, &num_devices);
|
eglQueryDevicesEXT(num_devices, devices, &num_devices);
|
||||||
|
|
||||||
@ -77,25 +87,33 @@ eglGraphicsPipe() {
|
|||||||
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT =
|
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT =
|
||||||
(PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
|
(PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
|
||||||
|
|
||||||
for (EGLint i = 0; i < num_devices && !_egl_display; ++i) {
|
if (eglGetPlatformDisplayEXT != nullptr) {
|
||||||
_egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT, devices[i], nullptr);
|
for (EGLint i = 0; i < num_devices && !_egl_display; ++i) {
|
||||||
}
|
_egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT, devices[i], nullptr);
|
||||||
}
|
|
||||||
|
|
||||||
if (!_egl_display) {
|
if (_egl_display && !eglInitialize(_egl_display, &major, &minor)) {
|
||||||
egldisplay_cat.error()
|
egldisplay_cat.warning()
|
||||||
<< "Couldn't find a suitable EGL platform device.\n";
|
<< "Couldn't initialize EGL platform display " << i << ": "
|
||||||
|
<< get_egl_error_string(eglGetError()) << "\n";
|
||||||
|
_egl_display = EGL_NO_DISPLAY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!eglInitialize(_egl_display, nullptr, nullptr)) {
|
if (!_egl_display) {
|
||||||
egldisplay_cat.error()
|
egldisplay_cat.error()
|
||||||
<< "Couldn't initialize the EGL display: "
|
<< "Failed to find or initialize a suitable EGL display connection.\n";
|
||||||
<< get_egl_error_string(eglGetError()) << "\n";
|
|
||||||
_is_valid = false;
|
_is_valid = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (egldisplay_cat.is_debug()) {
|
||||||
|
egldisplay_cat.debug()
|
||||||
|
<< "Successfully initialized EGL display, got version " << major << "." << minor << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(OPENGLES_1) || defined(OPENGLES_2)
|
#if defined(OPENGLES_1) || defined(OPENGLES_2)
|
||||||
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
|
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
|
||||||
egldisplay_cat.error()
|
egldisplay_cat.error()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user