Load EGL with glad to fix crash in sf::priv::eglCheckError on DRM

This commit is contained in:
kimci86 2022-06-26 19:36:03 +02:00 committed by Lukas Dürrenberger
parent 5098b6c22b
commit ee8f929bd6
4 changed files with 46 additions and 12 deletions

View File

@ -12,10 +12,6 @@ set(SRC
${SRCROOT}/Cursor.cpp
${INCROOT}/Cursor.hpp
${SRCROOT}/CursorImpl.hpp
${SRCROOT}/EGLCheck.cpp
${SRCROOT}/EGLCheck.hpp
${SRCROOT}/EglContext.cpp
${SRCROOT}/EglContext.hpp
${INCROOT}/Export.hpp
${SRCROOT}/GlContext.cpp
${SRCROOT}/GlContext.hpp
@ -63,8 +59,6 @@ if(SFML_OS_WINDOWS)
${SRCROOT}/Win32/CursorImpl.cpp
${SRCROOT}/Win32/ClipboardImpl.hpp
${SRCROOT}/Win32/ClipboardImpl.cpp
${SRCROOT}/Win32/WglContext.cpp
${SRCROOT}/Win32/WglContext.hpp
${SRCROOT}/Win32/InputImpl.cpp
${SRCROOT}/Win32/InputImpl.hpp
${SRCROOT}/Win32/JoystickImpl.cpp
@ -77,15 +71,40 @@ if(SFML_OS_WINDOWS)
${SRCROOT}/Win32/WindowImplWin32.cpp
${SRCROOT}/Win32/WindowImplWin32.hpp
)
if(SFML_OPENGL_ES)
set(PLATFORM_SRC
${PLATFORM_SRC}
${SRCROOT}/EGLCheck.cpp
${SRCROOT}/EGLCheck.hpp
${SRCROOT}/EglContext.cpp
${SRCROOT}/EglContext.hpp
)
else()
set(PLATFORM_SRC
${PLATFORM_SRC}
${SRCROOT}/Win32/WglContext.cpp
${SRCROOT}/Win32/WglContext.hpp
)
endif()
source_group("windows" FILES ${PLATFORM_SRC})
# make sure that we use the Unicode version of the Win API functions
add_definitions(-DUNICODE -D_UNICODE)
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD)
if(SFML_USE_DRM)
if(SFML_OPENGL_ES)
set(PLATFORM_SRC
${PLATFORM_SRC}
${SRCROOT}/EGLCheck.cpp
${SRCROOT}/EGLCheck.hpp
${SRCROOT}/EglContext.cpp
${SRCROOT}/EglContext.hpp
)
elseif(SFML_USE_DRM)
add_definitions(-DSFML_USE_DRM)
set(PLATFORM_SRC
${PLATFORM_SRC}
${SRCROOT}/EGLCheck.cpp
${SRCROOT}/EGLCheck.hpp
${SRCROOT}/DRM/CursorImpl.hpp
${SRCROOT}/DRM/CursorImpl.cpp
${SRCROOT}/DRM/ClipboardImpl.hpp
@ -146,7 +165,6 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD)
${SRCROOT}/NetBSD/JoystickImpl.cpp
${SRCROOT}/NetBSD/JoystickImpl.hpp
)
endif()
source_group("unix" FILES ${PLATFORM_SRC})
elseif(SFML_OS_MACOSX)
@ -232,6 +250,10 @@ elseif(SFML_OS_IOS)
source_group("ios" FILES ${PLATFORM_SRC})
elseif(SFML_OS_ANDROID)
set(PLATFORM_SRC
${SRCROOT}/EGLCheck.cpp
${SRCROOT}/EGLCheck.hpp
${SRCROOT}/EglContext.cpp
${SRCROOT}/EglContext.hpp
${SRCROOT}/Android/CursorImpl.hpp
${SRCROOT}/Android/CursorImpl.cpp
${SRCROOT}/Android/ClipboardImpl.hpp

View File

@ -37,6 +37,14 @@
#include <poll.h>
#include <unistd.h>
// We check for this definition in order to avoid multiple definitions of GLAD
// entities during unity builds of SFML.
#ifndef SF_GLAD_EGL_IMPLEMENTATION_INCLUDED
#define SF_GLAD_EGL_IMPLEMENTATION_INCLUDED
#define SF_GLAD_EGL_IMPLEMENTATION
#include <glad/egl.h>
#endif
namespace
{
bool initialized = false;
@ -168,11 +176,15 @@ namespace
if (display == EGL_NO_DISPLAY)
{
gladLoaderLoadEGL(EGL_NO_DISPLAY);
eglCheck(display = eglGetDisplay(reinterpret_cast<EGLNativeDisplayType>(gbmDevice)));
EGLint major, minor;
eglCheck(eglInitialize(display, &major, &minor));
gladLoaderLoadEGL(display);
#if defined(SFML_OPENGL_ES)
if (!eglBindAPI(EGL_OPENGL_ES_API))
{

View File

@ -35,9 +35,7 @@
#include <SFML/Window/VideoMode.hpp>
#include <SFML/OpenGL.hpp>
#include <drm-common.h>
#define EGL_NO_X11
#define MESA_EGL_NO_X11_HEADERS
#include <EGL/egl.h>
#include <glad/egl.h>
#include <gbm.h>
#include <xf86drmMode.h>

View File

@ -27,7 +27,6 @@
////////////////////////////////////////////////////////////
#include <SFML/Window/GlContext.hpp>
#include <SFML/Window/Context.hpp>
#include <SFML/Window/EglContext.hpp>
#include <SFML/System/ThreadLocalPtr.hpp>
#include <SFML/System/Mutex.hpp>
#include <SFML/System/Lock.hpp>
@ -48,6 +47,7 @@
#if defined(SFML_OPENGL_ES)
#include <SFML/Window/EglContext.hpp>
typedef sf::priv::EglContext ContextType;
#else
@ -61,6 +61,7 @@
#if defined(SFML_OPENGL_ES)
#include <SFML/Window/EglContext.hpp>
typedef sf::priv::EglContext ContextType;
#elif defined(SFML_USE_DRM)
@ -87,6 +88,7 @@
#elif defined(SFML_SYSTEM_ANDROID)
#include <SFML/Window/EglContext.hpp>
typedef sf::priv::EglContext ContextType;
#endif