summaryrefslogtreecommitdiff
path: root/platform/x11
diff options
context:
space:
mode:
Diffstat (limited to 'platform/x11')
-rw-r--r--platform/x11/context_gl_x11.cpp63
-rw-r--r--platform/x11/os_x11.cpp77
2 files changed, 82 insertions, 58 deletions
diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp
index 5a239e326b..8c1869a1f1 100644
--- a/platform/x11/context_gl_x11.cpp
+++ b/platform/x11/context_gl_x11.cpp
@@ -116,9 +116,14 @@ Error ContextGL_X11::initialize() {
};
int fbcount;
- GLXFBConfig fbconfig;
+ GLXFBConfig fbconfig = 0;
XVisualInfo *vi = NULL;
+ XSetWindowAttributes swa;
+ swa.event_mask = StructureNotifyMask;
+ swa.border_pixel = 0;
+ unsigned long valuemask = CWBorderPixel | CWColormap | CWEventMask;
+
if (OS::get_singleton()->is_layered_allowed()) {
GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs_layered, &fbcount);
ERR_FAIL_COND_V(!fbc, ERR_UNCONFIGURED);
@@ -142,16 +147,10 @@ Error ContextGL_X11::initialize() {
}
ERR_FAIL_COND_V(!fbconfig, ERR_UNCONFIGURED);
- XSetWindowAttributes swa;
-
- swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone);
- swa.border_pixel = 0;
swa.background_pixmap = None;
swa.background_pixel = 0;
swa.border_pixmap = None;
- swa.event_mask = StructureNotifyMask;
-
- x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | CWBackPixel, &swa);
+ valuemask |= CWBackPixel;
} else {
GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs, &fbcount);
@@ -160,42 +159,21 @@ Error ContextGL_X11::initialize() {
vi = glXGetVisualFromFBConfig(x11_display, fbc[0]);
fbconfig = fbc[0];
-
- XSetWindowAttributes swa;
-
- swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone);
- swa.border_pixel = 0;
- swa.event_mask = StructureNotifyMask;
-
- x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &swa);
}
- ERR_FAIL_COND_V(!x11_window, ERR_UNCONFIGURED);
- set_class_hint(x11_display, x11_window);
- XMapWindow(x11_display, x11_window);
-
- int (*oldHandler)(Display *, XErrorEvent *) =
- XSetErrorHandler(&ctxErrorHandler);
+ int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&ctxErrorHandler);
switch (context_type) {
- case GLES_2_0_COMPATIBLE:
case OLDSTYLE: {
+
p->glx_context = glXCreateContext(x11_display, vi, 0, GL_TRUE);
+ ERR_FAIL_COND_V(!p->glx_context, ERR_UNCONFIGURED);
} break;
- /*
- case ContextType::GLES_2_0_COMPATIBLE: {
-
- static int context_attribs[] = {
- GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
- GLX_CONTEXT_MINOR_VERSION_ARB, 0,
- None
- };
+ case GLES_2_0_COMPATIBLE: {
- p->glx_context = glXCreateContextAttribsARB(x11_display, fbconfig, NULL, true, context_attribs);
- ERR_EXPLAIN("Could not obtain an OpenGL 3.0 context!");
+ p->glx_context = glXCreateNewContext(x11_display, fbconfig, GLX_RGBA_TYPE, 0, true);
ERR_FAIL_COND_V(!p->glx_context, ERR_UNCONFIGURED);
} break;
- */
case GLES_3_0_COMPATIBLE: {
static int context_attribs[] = {
@@ -207,24 +185,22 @@ Error ContextGL_X11::initialize() {
};
p->glx_context = glXCreateContextAttribsARB(x11_display, fbconfig, NULL, true, context_attribs);
- ERR_EXPLAIN("Could not obtain an OpenGL 3.3 context!");
ERR_FAIL_COND_V(ctxErrorOccurred || !p->glx_context, ERR_UNCONFIGURED);
} break;
}
+ swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone);
+ x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, valuemask, &swa);
+
+ ERR_FAIL_COND_V(!x11_window, ERR_UNCONFIGURED);
+ set_class_hint(x11_display, x11_window);
+ XMapWindow(x11_display, x11_window);
+
XSync(x11_display, False);
XSetErrorHandler(oldHandler);
glXMakeCurrent(x11_display, x11_window, p->glx_context);
- /*
- glWrapperInit(wrapper_get_proc_address);
- glFlush();
-
- glXSwapBuffers(x11_display,x11_window);
-*/
- //glXMakeCurrent(x11_display, None, NULL);
-
XFree(vi);
return OK;
@@ -297,7 +273,6 @@ ContextGL_X11::ContextGL_X11(::Display *p_x11_display, ::Window &p_x11_window, c
ContextGL_X11::~ContextGL_X11() {
release_current();
glXDestroyContext(x11_display, p->glx_context);
-
memdelete(p);
}
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index e4a72e0715..a62bd714d2 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -274,21 +274,70 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
}
- context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
- context_gl->initialize();
+ bool editor = Engine::get_singleton()->is_editor_hint();
+ bool gl_initialization_error = false;
- switch (opengl_api_type) {
- case ContextGL_X11::GLES_2_0_COMPATIBLE: {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- } break;
- case ContextGL_X11::GLES_3_0_COMPATIBLE: {
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
- } break;
+ context_gl = NULL;
+ while (!context_gl) {
+ context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
+
+ if (context_gl->initialize() != OK) {
+ memdelete(context_gl);
+ context_gl = NULL;
+
+ if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best" || editor) {
+ if (p_video_driver == VIDEO_DRIVER_GLES2) {
+ gl_initialization_error = true;
+ break;
+ }
+
+ p_video_driver = VIDEO_DRIVER_GLES2;
+ opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
+ } else {
+ gl_initialization_error = true;
+ break;
+ }
+ }
+ }
+
+ while (true) {
+ if (opengl_api_type == ContextGL_X11::GLES_3_0_COMPATIBLE) {
+ if (RasterizerGLES3::is_viable() == OK) {
+ RasterizerGLES3::register_config();
+ RasterizerGLES3::make_current();
+ break;
+ } else {
+ if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best" || editor) {
+ p_video_driver = VIDEO_DRIVER_GLES2;
+ opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
+ continue;
+ } else {
+ gl_initialization_error = true;
+ break;
+ }
+ }
+ }
+
+ if (opengl_api_type == ContextGL_X11::GLES_2_0_COMPATIBLE) {
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ break;
+ } else {
+ gl_initialization_error = true;
+ break;
+ }
+ }
+ }
+
+ if (gl_initialization_error) {
+ OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
+ "Please update your drivers or if you have a very old or integrated GPU upgrade it.",
+ "Unable to initialize Video driver");
+ return ERR_UNAVAILABLE;
}
- video_driver_index = p_video_driver; // FIXME TODO - FIX IF DRIVER DETECTION HAPPENS AND GLES2 MUST BE USED
+ video_driver_index = p_video_driver;
context_gl->set_use_vsync(current_videomode.use_vsync);
@@ -339,8 +388,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
set_window_always_on_top(true);
}
- AudioDriverManager::initialize(p_audio_driver);
-
ERR_FAIL_COND_V(!visual_server, ERR_UNAVAILABLE);
ERR_FAIL_COND_V(x11_window == 0, ERR_UNAVAILABLE);
@@ -510,6 +557,8 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
visual_server->init();
+ AudioDriverManager::initialize(p_audio_driver);
+
input = memnew(InputDefault);
window_has_focus = true; // Set focus to true at init