Allow to make single build with both x11 and wayland device

This commit is contained in:
Deve 2017-05-06 21:53:32 +02:00
parent 2f1b61b798
commit e02a8f4448
10 changed files with 138 additions and 69 deletions

View File

@ -21,6 +21,7 @@ option(USE_FRIBIDI "Support for right-to-left languages" ON)
option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON) option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON)
option(USE_SYSTEM_ANGELSCRIPT "Use system angelscript instead of built-in angelscript. If you enable this option, make sure to use a compatible version." OFF) option(USE_SYSTEM_ANGELSCRIPT "Use system angelscript instead of built-in angelscript. If you enable this option, make sure to use a compatible version." OFF)
option(ENABLE_NETWORK_MULTIPLAYER "Enable network multiplayer. This will replace the online profile GUI in the main menu with the network multiplayer GUI" OFF) option(ENABLE_NETWORK_MULTIPLAYER "Enable network multiplayer. This will replace the online profile GUI in the main menu with the network multiplayer GUI" OFF)
option(ENABLE_WAYLAND_DEVICE "Enable Wayland device for linux build" OFF)
CMAKE_DEPENDENT_OPTION(BUILD_RECORDER "Build opengl recorder" ON CMAKE_DEPENDENT_OPTION(BUILD_RECORDER "Build opengl recorder" ON
"NOT SERVER_ONLY;NOT USE_GLES2;NOT APPLE" OFF) "NOT SERVER_ONLY;NOT USE_GLES2;NOT APPLE" OFF)
@ -413,7 +414,7 @@ if(NOT SERVER_ONLY)
if(NOT USE_GLES2) if(NOT USE_GLES2)
target_link_libraries(supertuxkart ${OPENGL_gl_LIBRARY} glew graphics_utils) target_link_libraries(supertuxkart ${OPENGL_gl_LIBRARY} glew graphics_utils)
else() else()
target_link_libraries(supertuxkart EGL GLESv2) target_link_libraries(supertuxkart GLESv2)
endif() endif()
endif() endif()
@ -426,7 +427,6 @@ if(UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
target_link_libraries(supertuxkart "-fsanitize=address") target_link_libraries(supertuxkart "-fsanitize=address")
endif() endif()
target_link_libraries(supertuxkart wayland-client wayland-egl wayland-cursor EGL xkbcommon)
endif() endif()
if(BUILD_RECORDER) if(BUILD_RECORDER)

View File

@ -11,6 +11,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/"
if (SERVER_ONLY) if (SERVER_ONLY)
add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_) add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_)
add_definitions(-DNO_IRR_COMPILE_WITH_X11_) add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
add_definitions(-DNO_IRR_COMPILE_WITH_WAYLAND)
else() else()
if(NOT USE_GLES2) if(NOT USE_GLES2)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
@ -23,6 +24,10 @@ if (UNIX AND NOT APPLE)
include_directories(${X11_INCLUDE_DIR}) include_directories(${X11_INCLUDE_DIR})
endif() endif()
if(ENABLE_WAYLAND_DEVICE)
add_definitions(-D_IRR_COMPILE_WITH_WAYLAND)
endif()
if(APPLE) if(APPLE)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/source/Irrlicht/MacOSX" "${CMAKE_CURRENT_SOURCE_DIR}/source/Irrlicht") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/source/Irrlicht/MacOSX" "${CMAKE_CURRENT_SOURCE_DIR}/source/Irrlicht")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64")
@ -552,6 +557,14 @@ endif()
add_library(stkirrlicht STATIC ${IRRLICHT_SOURCES}) add_library(stkirrlicht STATIC ${IRRLICHT_SOURCES})
target_link_libraries(stkirrlicht ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARY}) target_link_libraries(stkirrlicht ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARY})
if(USE_GLES2 OR ENABLE_WAYLAND_DEVICE)
target_link_libraries(stkirrlicht EGL)
endif()
if(ENABLE_WAYLAND_DEVICE)
target_link_libraries(stkirrlicht wayland-client wayland-egl wayland-cursor xkbcommon)
endif()
if(WIN32) if(WIN32)
target_link_libraries(stkirrlicht imm32) target_link_libraries(stkirrlicht imm32)
endif() endif()

View File

@ -127,8 +127,16 @@
#endif #endif
#define _IRR_POSIX_API_ #define _IRR_POSIX_API_
#define _IRR_COMPILE_WITH_X11_DEVICE_ #define _IRR_COMPILE_WITH_X11_DEVICE_
//#define _IRR_COMPILE_WITH_WAYLAND
#endif #endif
#ifdef NO_IRR_COMPILE_WITH_WAYLAND
#undef _IRR_COMPILE_WITH_WAYLAND
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND
#define _IRR_COMPILE_WITH_EGL_
#endif
//! Define _IRR_COMPILE_WITH_JOYSTICK_SUPPORT_ if you want joystick events. //! Define _IRR_COMPILE_WITH_JOYSTICK_SUPPORT_ if you want joystick events.
#define _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ #define _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
@ -211,14 +219,6 @@ define out. */
#undef _IRR_COMPILE_WITH_X11_ #undef _IRR_COMPILE_WITH_X11_
#endif #endif
#define _IRR_COMPILE_WITH_WAYLAND
#ifdef _IRR_COMPILE_WITH_WAYLAND
#define _IRR_COMPILE_WITH_EGL_
#undef _IRR_COMPILE_WITH_X11_
#undef _IRR_COMPILE_WITH_X11_DEVICE_
#endif
//! Define _IRR_OPENGL_USE_EXTPOINTER_ if the OpenGL renderer should use OpenGL extensions via function pointers. //! Define _IRR_OPENGL_USE_EXTPOINTER_ if the OpenGL renderer should use OpenGL extensions via function pointers.
/** On some systems there is no support for the dynamic extension of OpenGL /** On some systems there is no support for the dynamic extension of OpenGL
via function pointers such that this has to be undef'ed. */ via function pointers such that this has to be undef'ed. */

View File

@ -1,7 +1,6 @@
extern bool GLContextDebugBit;
#include "CIrrDeviceWayland.h" #include "CIrrDeviceWayland.h"
#ifdef _IRR_COMPILE_WITH_WAYLAND
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -615,6 +614,21 @@ const wl_registry_listener WaylandCallbacks::registry_listener = {
//const char* wmDeleteWindow = "WM_DELETE_WINDOW"; //const char* wmDeleteWindow = "WM_DELETE_WINDOW";
bool CIrrDeviceWayland::isWaylandDeviceWorking()
{
bool is_working = false;
wl_display* display = wl_display_connect(NULL);
if (display != NULL)
{
is_working = true;
wl_display_disconnect(display);
}
return is_working;
}
//! constructor //! constructor
CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& param) CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), : CIrrDeviceStub(param),
@ -1401,3 +1415,5 @@ void CIrrDeviceWayland::initXAtoms()
} }
} // end namespace } // end namespace
#endif

View File

@ -3,6 +3,8 @@
#include "IrrCompileConfig.h" #include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_WAYLAND
#include "CIrrDeviceStub.h" #include "CIrrDeviceStub.h"
#include "IrrlichtDevice.h" #include "IrrlichtDevice.h"
#include "IImagePresenter.h" #include "IImagePresenter.h"
@ -236,6 +238,7 @@ namespace irr
ContextManagerEGL* EglContext; ContextManagerEGL* EglContext;
public: public:
static bool isWaylandDeviceWorking();
void signalEvent(const SEvent&); void signalEvent(const SEvent&);
void addMode(const core::dimension2du &mode) { Modes.push_back(mode); } void addMode(const core::dimension2du &mode) { Modes.push_back(mode); }
void setCurrentMode(const core::dimension2du &mode) { CurrentModes = mode; } void setCurrentMode(const core::dimension2du &mode) { CurrentModes = mode; }
@ -322,5 +325,7 @@ private:
} // end namespace irr } // end namespace irr
#endif
#endif // CIRRDEVICEWAYLAND_H #endif // CIRRDEVICEWAYLAND_H

View File

@ -22,6 +22,9 @@
#endif #endif
#endif #endif
#include <cassert>
#include "IrrlichtDevice.h"
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) #if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
#include "CIrrDeviceLinux.h" #include "CIrrDeviceLinux.h"
#endif #endif
@ -35,24 +38,16 @@
namespace irr namespace irr
{ {
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
// constructor linux // constructor linux
COSOperator::COSOperator(const core::stringc& osVersion, CIrrDeviceLinux* device) COSOperator::COSOperator(const core::stringc& osVersion, IrrlichtDevice* device)
: OperatingSystem(osVersion), IrrDeviceLinux(device) : OperatingSystem(osVersion), IrrDevice(device)
{ {
} }
#endif
#if defined(_IRR_COMPILE_WITH_WAYLAND)
// constructor linux
COSOperator::COSOperator(const core::stringc& osVersion, CIrrDeviceWayland* device)
: OperatingSystem(osVersion), IrrDeviceWayland(device)
{
}
#endif
// constructor // constructor
COSOperator::COSOperator(const core::stringc& osVersion) : OperatingSystem(osVersion) COSOperator::COSOperator(const core::stringc& osVersion)
: OperatingSystem(osVersion), IrrDevice(NULL)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("COSOperator"); setDebugName("COSOperator");
@ -128,13 +123,29 @@ void COSOperator::copyToClipboard(const c8* text) const
#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_) #elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
OSXCopyToClipboard(text); OSXCopyToClipboard(text);
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_WAYLAND)
if ( IrrDeviceLinux ) if (IrrDevice != NULL)
IrrDeviceLinux->copyToClipboard(text); {
#elif defined(_IRR_COMPILE_WITH_WAYLAND) #if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
if ( IrrDeviceWayland ) if (IrrDevice->getType() == EIDT_X11)
IrrDeviceWayland->copyToClipboard(text); {
CIrrDeviceLinux* device = dynamic_cast<CIrrDeviceLinux*>(IrrDevice);
assert(device);
device->copyToClipboard(text);
}
#endif
#if defined(_IRR_COMPILE_WITH_WAYLAND)
if (IrrDevice->getType() == EIDT_WAYLAND)
{
CIrrDeviceWayland* device = dynamic_cast<CIrrDeviceWayland*>(IrrDevice);
assert(device);
device->copyToClipboard(text);
}
#endif
}
#else #else
#endif #endif
@ -185,16 +196,32 @@ const c8* COSOperator::getTextFromClipboard() const
#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_) #elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
return (OSXCopyFromClipboard()); return (OSXCopyFromClipboard());
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_WAYLAND)
if ( IrrDeviceLinux ) if (IrrDevice != NULL)
return IrrDeviceLinux->getTextFromClipboard(); {
return 0; #if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
if (IrrDevice->getType() == EIDT_X11)
#elif defined(_IRR_COMPILE_WITH_WAYLAND) {
if ( IrrDeviceWayland ) CIrrDeviceLinux* device = dynamic_cast<CIrrDeviceLinux*>(IrrDevice);
return IrrDeviceWayland->getTextFromClipboard(); assert(device);
return 0;
return device->getTextFromClipboard();
}
#endif
#if defined(_IRR_COMPILE_WITH_WAYLAND)
if (IrrDevice->getType() == EIDT_WAYLAND)
{
CIrrDeviceWayland* device = dynamic_cast<CIrrDeviceWayland*>(IrrDevice);
assert(device);
return device->getTextFromClipboard();
}
#endif
}
return 0;
#else #else

View File

@ -10,8 +10,7 @@
namespace irr namespace irr
{ {
class CIrrDeviceLinux; class IrrlichtDevice;
class CIrrDeviceWayland;
//! The Operating system operator provides operation system specific methods and informations. //! The Operating system operator provides operation system specific methods and informations.
class COSOperator : public IOSOperator class COSOperator : public IOSOperator
@ -19,12 +18,7 @@ class COSOperator : public IOSOperator
public: public:
// constructor // constructor
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) COSOperator(const core::stringc& osversion, IrrlichtDevice* device);
COSOperator(const core::stringc& osversion, CIrrDeviceLinux* device);
#endif
#if defined(_IRR_COMPILE_WITH_WAYLAND)
COSOperator(const core::stringc& osversion, CIrrDeviceWayland* device);
#endif
COSOperator(const core::stringc& osversion); COSOperator(const core::stringc& osversion);
//! returns the current operation system version as string. //! returns the current operation system version as string.
@ -59,14 +53,7 @@ public:
private: private:
core::stringc OperatingSystem; core::stringc OperatingSystem;
IrrlichtDevice* IrrDevice;
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
CIrrDeviceLinux * IrrDeviceLinux;
#endif
#if defined(_IRR_COMPILE_WITH_WAYLAND)
CIrrDeviceWayland * IrrDeviceWayland;
#endif
}; };

View File

@ -704,6 +704,7 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params,
bool COpenGLDriver::changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWayland* device) bool COpenGLDriver::changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWayland* device)
{ {
//TODO
return true; return true;
} }
@ -722,7 +723,7 @@ bool COpenGLDriver::initDriver(CIrrDeviceWayland* device)
return true; return true;
} }
#endif // _IRR_COMPILE_WITH_X11_DEVICE_ #endif // _IRR_COMPILE_WITH_WAYLAND

View File

@ -95,7 +95,12 @@ namespace irr
#ifdef _IRR_COMPILE_WITH_WAYLAND #ifdef _IRR_COMPILE_WITH_WAYLAND
if (params.DeviceType == EIDT_WAYLAND || (!dev && params.DeviceType == EIDT_BEST)) if (params.DeviceType == EIDT_WAYLAND || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceWayland(params); {
if (CIrrDeviceWayland::isWaylandDeviceWorking())
{
dev = new CIrrDeviceWayland(params);
}
}
#endif #endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #ifdef _IRR_COMPILE_WITH_X11_DEVICE_

View File

@ -109,8 +109,12 @@ CGUIEditBox::~CGUIEditBox()
if (Operator) if (Operator)
Operator->drop(); Operator->drop();
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #ifdef _IRR_COMPILE_WITH_X11_DEVICE_
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice()); if (irr_driver->getDevice()->getType() == irr::EIDT_X11)
dl->setIMEEnable(false); {
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(
irr_driver->getDevice());
dl->setIMEEnable(false);
}
#endif #endif
#endif #endif
} }
@ -243,7 +247,6 @@ bool CGUIEditBox::OnEvent(const SEvent& event)
#ifndef SERVER_ONLY #ifndef SERVER_ONLY
if (isEnabled()) if (isEnabled())
{ {
switch(event.EventType) switch(event.EventType)
{ {
case EET_GUI_EVENT: case EET_GUI_EVENT:
@ -255,16 +258,24 @@ bool CGUIEditBox::OnEvent(const SEvent& event)
setTextMarkers(0,0); setTextMarkers(0,0);
} }
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #ifdef _IRR_COMPILE_WITH_X11_DEVICE_
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice()); if (irr_driver->getDevice()->getType() == irr::EIDT_X11)
dl->setIMEEnable(false); {
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(
irr_driver->getDevice());
dl->setIMEEnable(false);
}
#endif #endif
} }
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_ #ifdef _IRR_COMPILE_WITH_X11_DEVICE_
else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED) else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED)
{ {
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice()); if (irr_driver->getDevice()->getType() == irr::EIDT_X11)
dl->setIMEEnable(true); {
dl->setIMELocation(calculateICPos()); CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(
irr_driver->getDevice());
dl->setIMEEnable(true);
dl->setIMELocation(calculateICPos());
}
} }
#endif #endif
break; break;
@ -1634,10 +1645,14 @@ void CGUIEditBox::calculateScrollPos()
// todo: adjust scrollbar // todo: adjust scrollbar
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) #if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice()); if (irr_driver->getDevice()->getType() == irr::EIDT_X11)
if (dl)
{ {
dl->setIMELocation(calculateICPos()); CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(
irr_driver->getDevice());
if (dl)
{
dl->setIMELocation(calculateICPos());
}
} }
#endif #endif
#endif // SERVER_ONLY #endif // SERVER_ONLY