Merge branch 'wayland'

This commit is contained in:
Deve 2017-05-18 21:25:53 +02:00
commit 8968706c09
17 changed files with 2087 additions and 93 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(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_WAYLAND_DEVICE "Enable Wayland device for linux build" OFF)
CMAKE_DEPENDENT_OPTION(BUILD_RECORDER "Build opengl recorder" ON
"NOT SERVER_ONLY;NOT USE_GLES2;NOT APPLE" OFF)
@ -413,7 +414,7 @@ if(NOT SERVER_ONLY)
if(NOT USE_GLES2)
target_link_libraries(supertuxkart ${OPENGL_gl_LIBRARY} glew graphics_utils)
else()
target_link_libraries(supertuxkart EGL GLESv2)
target_link_libraries(supertuxkart GLESv2)
endif()
endif()

View File

@ -14064,6 +14064,9 @@ GLenum glxewContextInit (GLXEW_CONTEXT_ARG_DEF_LIST)
GLXEW_VERSION_1_2 = GL_TRUE;
GLXEW_VERSION_1_3 = GL_TRUE;
GLXEW_VERSION_1_4 = GL_TRUE;
/* Check if GLX display is available */
if (glXGetCurrentDisplay == NULL || glXGetCurrentDisplay() == NULL)
return GLEW_OK;
/* query GLX version */
glXQueryVersion(glXGetCurrentDisplay(), &major, &minor);
if (major == 1 && minor <= 3)

View File

@ -11,6 +11,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/"
if (SERVER_ONLY)
add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_)
add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
add_definitions(-DNO_IRR_COMPILE_WITH_WAYLAND_DEVICE_)
else()
if(NOT USE_GLES2)
find_package(OpenGL REQUIRED)
@ -23,6 +24,10 @@ if (UNIX AND NOT APPLE)
include_directories(${X11_INCLUDE_DIR})
endif()
if(ENABLE_WAYLAND_DEVICE)
add_definitions(-D_IRR_COMPILE_WITH_WAYLAND_DEVICE_)
endif()
if(APPLE)
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")
@ -119,6 +124,7 @@ source/Irrlicht/CIrrDeviceFB.cpp
source/Irrlicht/CIrrDeviceLinux.cpp
source/Irrlicht/CIrrDeviceSDL.cpp
source/Irrlicht/CIrrDeviceStub.cpp
source/Irrlicht/CIrrDeviceWayland.cpp
source/Irrlicht/CIrrDeviceWin32.cpp
source/Irrlicht/CLightSceneNode.cpp
source/Irrlicht/CLimitReadFile.cpp
@ -252,6 +258,7 @@ source/Irrlicht/CIrrDeviceFB.h
source/Irrlicht/CIrrDeviceLinux.h
source/Irrlicht/CIrrDeviceSDL.h
source/Irrlicht/CIrrDeviceStub.h
source/Irrlicht/CIrrDeviceWayland.h
source/Irrlicht/CIrrDeviceWin32.h
source/Irrlicht/CLightSceneNode.h
source/Irrlicht/CLimitReadFile.h
@ -550,6 +557,14 @@ endif()
add_library(stkirrlicht STATIC ${IRRLICHT_SOURCES})
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)
target_link_libraries(stkirrlicht imm32)
endif()

View File

@ -20,6 +20,9 @@ namespace irr
/** This device works on Windows Mobile, Pocket PC and Microsoft SmartPhone devices */
EIDT_WINCE,
//! A device native to Linux
EIDT_WAYLAND,
//! A device native to Unix style operating systems.
/** This device uses the X11 windowing system and works in Linux, Solaris, FreeBSD, OSX and
other operating systems which support X11. */

View File

@ -127,8 +127,16 @@
#endif
#define _IRR_POSIX_API_
#define _IRR_COMPILE_WITH_X11_DEVICE_
//#define _IRR_COMPILE_WITH_WAYLAND_DEVICE_
#endif
#ifdef NO_IRR_COMPILE_WITH_WAYLAND_DEVICE_
#undef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
#define _IRR_COMPILE_WITH_EGL_
#endif
//! Define _IRR_COMPILE_WITH_JOYSTICK_SUPPORT_ if you want joystick events.
#define _IRR_COMPILE_WITH_JOYSTICK_EVENTS_

View File

@ -449,6 +449,15 @@ bool ContextManagerEGL::swapBuffers()
}
bool ContextManagerEGL::makeCurrent()
{
bool success = eglMakeCurrent(m_egl_display, m_egl_surface, m_egl_surface,
m_egl_context);
return success;
}
void ContextManagerEGL::reloadEGLSurface(void* window)
{
#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_

View File

@ -78,6 +78,7 @@ public:
void reloadEGLSurface(void* window);
bool swapBuffers();
bool makeCurrent();
bool isLegacyDevice() {return m_is_legacy_device;}
bool getSurfaceDimensions(int* width, int* height);
};

View File

@ -516,6 +516,7 @@ void IrrPrintXGrabError(int grabResult, const c8 * grabCommand )
#endif
#ifdef _IRR_COMPILE_WITH_OPENGL_
#ifdef _IRR_COMPILE_WITH_X11_
static GLXContext getMeAGLContext(Display *display, GLXFBConfig glxFBConfig, bool force_legacy_context)
{
GLXContext Context;
@ -600,7 +601,7 @@ static GLXContext getMeAGLContext(Display *display, GLXFBConfig glxFBConfig, boo
Context = glXCreateNewContext(display, glxFBConfig, GLX_RGBA_TYPE, NULL, True);
return Context;
}
#endif
#endif
bool CIrrDeviceLinux::createWindow()

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,335 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2016-2017 Dawid Gan
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef CIRRDEVICEWAYLAND_H
#define CIRRDEVICEWAYLAND_H
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
#include "CIrrDeviceStub.h"
#include "IImagePresenter.h"
#include "ICursorControl.h"
#include <wayland-client.h>
#include <wayland-cursor.h>
#include <wayland-egl.h>
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-compose.h>
#include <map>
#include <vector>
class ContextManagerEGL;
namespace irr
{
class CIrrDeviceWayland : public CIrrDeviceStub,
public video::IImagePresenter
{
public:
friend class WaylandCallbacks;
//! constructor
CIrrDeviceWayland(const SIrrlichtCreationParameters& param);
//! destructor
virtual ~CIrrDeviceWayland();
//! runs the device. Returns false if device wants to be deleted
virtual bool run();
//! Cause the device to temporarily pause execution and let other
//! processes to run. This should bring down processor usage without
//! major performance loss for Irrlicht
virtual void yield();
//! Pause execution and let other processes to run for a specified
//! amount of time.
virtual void sleep(u32 timeMs, bool pauseTimer);
//! sets the caption of the window
virtual void setWindowCaption(const wchar_t* text);
//! returns if window is active. if not, nothing need to be drawn
virtual bool isWindowActive() const;
//! returns if window has focus.
virtual bool isWindowFocused() const;
//! returns if window is minimized.
virtual bool isWindowMinimized() const;
//! returns color format of the window.
virtual video::ECOLOR_FORMAT getColorFormat() const;
//! presents a surface in the client area
virtual bool present(video::IImage* surface, void* windowId=0,
core::rect<s32>* src=0);
//! notifies the device that it should close itself
virtual void closeDevice();
//! \return Returns a pointer to a list with all video modes
//! supported by the gfx adapter.
video::IVideoModeList* getVideoModeList();
//! Sets if the window should be resizable in windowed mode.
virtual void setResizable(bool resize=false);
//! Minimizes the window.
virtual void minimizeWindow();
//! Maximizes the window.
virtual void maximizeWindow();
//! Restores the window size.
virtual void restoreWindow();
//! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo);
//! Set the current Gamma Value for the Display
virtual bool setGammaRamp(f32 red, f32 green, f32 blue,
f32 brightness, f32 contrast);
//! Get the current Gamma Value for the Display
virtual bool getGammaRamp(f32 &red, f32 &green, f32 &blue,
f32 &brightness, f32 &contrast);
//! gets text from the clipboard
//! \return Returns 0 if no string is in there.
virtual const c8* getTextFromClipboard() const;
//! copies text to the clipboard
virtual void copyToClipboard(const c8* text) const;
//! Remove all messages pending in the system message loop
virtual void clearSystemMessages();
//! Get the device type
virtual E_DEVICE_TYPE getType() const
{
return EIDT_WAYLAND;
}
static bool isWaylandDeviceWorking();
ContextManagerEGL* getEGLContext() {return m_egl_context;}
void swapBuffers();
void updateCursor();
unsigned int getWidth() {return m_width;}
unsigned int getHeight() {return m_height;}
private:
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
struct JoystickInfo
{
int fd;
int axes;
int buttons;
SEvent persistentData;
JoystickInfo() : fd(-1), axes(0), buttons(0) { }
};
core::array<JoystickInfo> m_active_joysticks;
#endif
wl_compositor* m_compositor;
wl_cursor* m_cursor;
wl_cursor_theme* m_cursor_theme;
wl_display* m_display;
wl_egl_window* m_egl_window;
wl_keyboard* m_keyboard;
wl_output* m_output;
wl_pointer* m_pointer;
wl_registry* m_registry;
wl_seat* m_seat;
wl_shell* m_shell;
wl_shell_surface* m_shell_surface;
wl_shm* m_shm;
wl_surface* m_cursor_surface;
wl_surface* m_surface;
uint32_t m_enter_serial;
xkb_context* m_xkb_context;
xkb_compose_table* m_xkb_compose_table;
xkb_compose_state* m_xkb_compose_state;
xkb_keymap* m_xkb_keymap;
xkb_state* m_xkb_state;
xkb_mod_mask_t m_xkb_control_mask;
xkb_mod_mask_t m_xkb_alt_mask;
xkb_mod_mask_t m_xkb_shift_mask;
uint32_t m_xkb_modifiers;
uint32_t m_mouse_button_states;
unsigned int m_width;
unsigned int m_height;
bool m_window_has_focus;
bool m_window_minimized;
mutable core::stringc m_clipboard;
std::map<int, EKEY_CODE> m_key_map;
std::vector<SEvent> m_events;
std::vector<core::dimension2du> m_modes;
ContextManagerEGL* m_egl_context;
void createDriver();
void createKeyMap();
bool createWindow();
bool initEGL();
void signalEvent(const SEvent&);
void pollJoysticks();
void closeJoysticks();
};
//! Implementation of the linux cursor control
class CCursorControl : public gui::ICursorControl
{
public:
CCursorControl(CIrrDeviceWayland* device) : m_device(device),
m_is_visible(true), m_use_reference_rect(false) {};
~CCursorControl() {};
//! Changes the visible state of the mouse cursor.
virtual void setVisible(bool visible)
{
if (visible == m_is_visible)
return;
m_is_visible = visible;
m_device->updateCursor();
}
//! Returns if the cursor is currently visible.
virtual bool isVisible() const
{
return m_is_visible;
}
//! Sets the new position of the cursor.
virtual void setPosition(const core::position2d<f32> &pos)
{
setPosition(pos.X, pos.Y);
}
//! Sets the new position of the cursor.
virtual void setPosition(f32 x, f32 y)
{
setPosition((s32)(x * m_device->getWidth()),
(s32)(y * m_device->getHeight()));
}
//! Sets the new position of the cursor.
virtual void setPosition(const core::position2d<s32> &pos)
{
setPosition(pos.X, pos.Y);
}
//! Sets the new position of the cursor.
virtual void setPosition(s32 x, s32 y)
{
m_cursor_pos.X = x;
m_cursor_pos.Y = y;
}
//! Returns the current position of the mouse cursor.
virtual const core::position2d<s32>& getPosition()
{
return m_cursor_pos;
}
virtual core::position2d<f32> getRelativePosition()
{
if (!m_use_reference_rect)
{
return core::position2d<f32>(
m_cursor_pos.X / (f32)m_device->getWidth(),
m_cursor_pos.Y / (f32)m_device->getHeight());
}
return core::position2d<f32>(
m_cursor_pos.X / (f32)m_reference_rect.getWidth(),
m_cursor_pos.Y / (f32)m_reference_rect.getHeight());
}
virtual void setReferenceRect(core::rect<s32>* rect=0)
{
m_use_reference_rect = false;
if (rect)
{
m_reference_rect = *rect;
m_use_reference_rect = true;
// prevent division through zero and uneven sizes
if (m_reference_rect.getHeight() == 0 ||
m_reference_rect.getHeight() % 2)
m_reference_rect.LowerRightCorner.Y += 1;
if (m_reference_rect.getWidth() == 0 ||
m_reference_rect.getWidth() % 2)
m_reference_rect.LowerRightCorner.X += 1;
}
}
//! Sets the active cursor icon
virtual void setActiveIcon(gui::ECURSOR_ICON iconId) {};
//! Gets the currently active icon
virtual gui::ECURSOR_ICON getActiveIcon() const
{
return gui::ECI_NORMAL;
}
//! Add a custom sprite as cursor icon.
virtual gui::ECURSOR_ICON addIcon(const gui::SCursorSprite& icon)
{
return gui::ECI_NORMAL;
}
//! replace the given cursor icon.
virtual void changeIcon(gui::ECURSOR_ICON iconId,
const gui::SCursorSprite& icon) {}
/** Return a system-specific size which is supported for cursors.
Larger icons will fail, smaller icons might work. */
virtual core::dimension2di getSupportedIconSize() const
{
return core::dimension2di(0, 0);
}
private:
CIrrDeviceWayland* m_device;
core::position2d<s32> m_cursor_pos;
core::rect<s32> m_reference_rect;
bool m_is_visible;
bool m_use_reference_rect;
};
} // end namespace irr
#endif
#endif // CIRRDEVICEWAYLAND_H

View File

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

View File

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

View File

@ -26,6 +26,11 @@ extern bool GLContextDebugBit;
#include "MacOSX/CIrrDeviceMacOSX.h"
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
#include "CIrrDeviceWayland.h"
#include "CContextEGL.h"
#endif
namespace irr
{
namespace video
@ -677,6 +682,51 @@ bool COpenGLDriver::initDriver(CIrrDeviceLinux* device)
#endif // _IRR_COMPILE_WITH_X11_DEVICE_
// -----------------------------------------------------------------------
// Wayland CONSTRUCTOR
// -----------------------------------------------------------------------
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
//! Linux constructor and init code
COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceWayland* device)
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(),
CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
Transformation3DChanged(true), AntiAlias(params.AntiAlias),
RenderTargetTexture(0), CurrentRendertargetSize(0, 0), ColorFormat(ECF_R8G8B8),
CurrentTarget(ERT_FRAME_BUFFER), Params(params),
wl_device(device), DeviceType(EIDT_WAYLAND)
{
#ifdef _DEBUG
setDebugName("COpenGLDriver");
#endif
}
bool COpenGLDriver::changeRenderContext(const SExposedVideoData& videoData,
CIrrDeviceWayland* device)
{
if (!device->getEGLContext()->makeCurrent())
{
os::Printer::log("Render Context switch failed.");
return false;
}
return true;
}
//! inits the open gl driver
bool COpenGLDriver::initDriver(CIrrDeviceWayland* device)
{
genericDriverInit();
return true;
}
#endif // _IRR_COMPILE_WITH_WAYLAND_DEVICE
// -----------------------------------------------------------------------
// SDL CONSTRUCTOR
// -----------------------------------------------------------------------
@ -929,6 +979,14 @@ bool COpenGLDriver::endScene()
}
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
if (DeviceType == EIDT_WAYLAND)
{
wl_device->swapBuffers();
return true;
}
#endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
if (DeviceType == EIDT_OSX)
{
@ -996,6 +1054,11 @@ bool COpenGLDriver::beginScene(bool backBuffer, bool zBuffer, SColor color,
case EIDT_X11:
changeRenderContext(videoData, X11Device);
break;
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
case EIDT_WAYLAND:
changeRenderContext(videoData, wl_device);
break;
#endif
default:
changeRenderContext(videoData, (void*)0);
@ -4928,6 +4991,25 @@ IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
#endif // _IRR_COMPILE_WITH_X11_DEVICE_
// -----------------------------------
// Wayland VERSION
// -----------------------------------
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceWayland* device)
{
COpenGLDriver* ogl = new COpenGLDriver(params, io, device);
if (!ogl->initDriver(device))
{
ogl->drop();
ogl = 0;
}
return ogl;
}
#endif // _IRR_COMPILE_WITH_WAYLAND_DEVICE
// -----------------------------------
// SDL VERSION
// -----------------------------------

View File

@ -13,6 +13,7 @@ namespace irr
{
class CIrrDeviceWin32;
class CIrrDeviceLinux;
class CIrrDeviceWayland;
class CIrrDeviceSDL;
class CIrrDeviceMacOSX;
}
@ -44,6 +45,13 @@ namespace video
bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWin32* device);
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceWayland* device);
//! inits the EGL specific parts of the open gl driver
bool initDriver(CIrrDeviceWayland* device);
bool changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWayland* device);
#endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceLinux* device);
//! inits the GLX specific parts of the open gl driver
@ -587,6 +595,9 @@ namespace video
Display* X11Display;
CIrrDeviceLinux *X11Device;
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
CIrrDeviceWayland *wl_device;
#endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
CIrrDeviceMacOSX *OSXDevice;
#endif

View File

@ -26,6 +26,10 @@
#include "CIrrDeviceWinCE.h"
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
#include "CIrrDeviceWayland.h"
#endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
#include "CIrrDeviceLinux.h"
#endif
@ -47,6 +51,8 @@
#include <android/log.h>
#endif
#include <stdio.h>
namespace irr
{
//! stub for calling createDeviceEx
@ -68,53 +74,129 @@ namespace irr
return createDeviceEx(p);
}
static void overrideDeviceType(E_DEVICE_TYPE& device_type)
{
const char* irr_device_type = getenv("IRR_DEVICE_TYPE");
if (irr_device_type == NULL)
return;
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
if (strcmp(irr_device_type, "win32") == 0)
{
device_type = EIDT_WIN32;
}
#endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
if (strcmp(irr_device_type, "osx") == 0)
{
device_type = EIDT_OSX;
}
#endif
#ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
if (strcmp(irr_device_type, "wince") == 0)
{
device_type = EIDT_WINCE;
}
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
if (strcmp(irr_device_type, "wayland") == 0)
{
device_type = EIDT_WAYLAND;
}
#endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
if (strcmp(irr_device_type, "x11") == 0)
{
device_type = EIDT_X11;
}
#endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
if (strcmp(irr_device_type, "sdl") == 0)
{
device_type = EIDT_SDL;
}
#endif
#ifdef _IRR_COMPILE_WITH_FB_DEVICE_
if (strcmp(irr_device_type, "framebuffer") == 0)
{
device_type = EIDT_FRAMEBUFFER;
}
#endif
#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
if (strcmp(irr_device_type, "android") == 0)
{
device_type = EIDT_ANDROID;
}
#endif
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
if (strcmp(irr_device_type, "console") == 0)
{
device_type = EIDT_CONSOLE;
}
#endif
}
extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& params)
{
IrrlichtDevice* dev = 0;
SIrrlichtCreationParameters creation_params = params;
overrideDeviceType(creation_params.DeviceType);
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
if (params.DeviceType == EIDT_WIN32 || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceWin32(params);
if (creation_params.DeviceType == EIDT_WIN32 || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceWin32(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
if (params.DeviceType == EIDT_OSX || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceMacOSX(params);
if (creation_params.DeviceType == EIDT_OSX || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceMacOSX(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_WINDOWS_CE_DEVICE_
if (params.DeviceType == EIDT_WINCE || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceWinCE(params);
if (creation_params.DeviceType == EIDT_WINCE || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceWinCE(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
if (creation_params.DeviceType == EIDT_WAYLAND || (!dev && creation_params.DeviceType == EIDT_BEST))
{
if (CIrrDeviceWayland::isWaylandDeviceWorking())
{
dev = new CIrrDeviceWayland(creation_params);
}
}
#endif
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
if (params.DeviceType == EIDT_X11 || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceLinux(params);
if (creation_params.DeviceType == EIDT_X11 || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceLinux(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
if (params.DeviceType == EIDT_SDL || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceSDL(params);
if (creation_params.DeviceType == EIDT_SDL || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceSDL(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_FB_DEVICE_
if (params.DeviceType == EIDT_FRAMEBUFFER || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceFB(params);
if (creation_params.DeviceType == EIDT_FRAMEBUFFER || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceFB(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_
if (params.DeviceType == EIDT_ANDROID || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceAndroid(params);
if (creation_params.DeviceType == EIDT_ANDROID || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceAndroid(creation_params);
#endif
#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
if (params.DeviceType == EIDT_CONSOLE || (!dev && params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceConsole(params);
if (creation_params.DeviceType == EIDT_CONSOLE || (!dev && creation_params.DeviceType == EIDT_BEST))
dev = new CIrrDeviceConsole(creation_params);
#endif
if (dev && !dev->getVideoDriver() && params.DriverType != video::EDT_NULL)
if (dev && !dev->getVideoDriver() && creation_params.DriverType != video::EDT_NULL)
{
dev->closeDevice(); // destroy window
dev->run(); // consume quit message

View File

@ -312,22 +312,26 @@ void IrrDriver::updateConfigIfRelevant()
Log::warn("irr_driver", "Could not retrieve window location\n");
}
#elif defined(__linux__) && !defined(ANDROID)
const video::SExposedVideoData& videoData =
m_device->getVideoDriver()->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
XWindowAttributes xwa;
XGetWindowAttributes(display, get_toplevel_parent(display,
videoData.OpenGLLinux.X11Window), &xwa);
int wx = xwa.x;
int wy = xwa.y;
Log::verbose("irr_driver",
"Retrieved window location for config : %i %i\n", wx, wy);
if (UserConfigParams::m_window_x != wx || UserConfigParams::m_window_y != wy)
if (m_device->getType() == EIDT_X11)
{
UserConfigParams::m_window_x = wx;
UserConfigParams::m_window_y = wy;
const video::SExposedVideoData& videoData =
m_device->getVideoDriver()->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
XWindowAttributes xwa;
XGetWindowAttributes(display, get_toplevel_parent(display,
videoData.OpenGLLinux.X11Window), &xwa);
int wx = xwa.x;
int wy = xwa.y;
Log::verbose("irr_driver",
"Retrieved window location for config : %i %i\n", wx, wy);
if (UserConfigParams::m_window_x != wx ||
UserConfigParams::m_window_y != wy)
{
UserConfigParams::m_window_x = wx;
UserConfigParams::m_window_y = wy;
}
}
#endif
}
@ -713,16 +717,19 @@ void IrrDriver::initDevice()
if (!ProfileWorld::isNoGraphics())
{
#if defined(__linux__) && !defined(ANDROID) && !defined(SERVER_ONLY)
// Set class hints on Linux, used by Window Managers.
const video::SExposedVideoData& videoData = m_video_driver
->getExposedVideoData();
XClassHint* classhint = XAllocClassHint();
classhint->res_name = (char*)"SuperTuxKart";
classhint->res_class = (char*)"SuperTuxKart";
XSetClassHint((Display*)videoData.OpenGLLinux.X11Display,
videoData.OpenGLLinux.X11Window,
classhint);
XFree(classhint);
if (m_device->getType() == EIDT_X11)
{
// Set class hints on Linux, used by Window Managers.
const video::SExposedVideoData& videoData = m_video_driver
->getExposedVideoData();
XClassHint* classhint = XAllocClassHint();
classhint->res_name = (char*)"SuperTuxKart";
classhint->res_class = (char*)"SuperTuxKart";
XSetClassHint((Display*)videoData.OpenGLLinux.X11Display,
videoData.OpenGLLinux.X11Window,
classhint);
XFree(classhint);
}
#endif
m_device->setWindowCaption(L"SuperTuxKart");
m_device->getVideoDriver()
@ -893,25 +900,29 @@ bool IrrDriver::moveWindow(int x, int y)
return false;
}
#elif defined(__linux__) && !defined(ANDROID)
const video::SExposedVideoData& videoData = m_video_driver->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
int screen = DefaultScreen(display);
int screen_w = DisplayWidth(display, screen);
int screen_h = DisplayHeight(display, screen);
if (x + UserConfigParams::m_width > screen_w)
if (m_device->getType() == EIDT_X11)
{
x = screen_w - UserConfigParams::m_width;
const video::SExposedVideoData& videoData =
m_video_driver->getExposedVideoData();
Display* display = (Display*)videoData.OpenGLLinux.X11Display;
int screen = DefaultScreen(display);
int screen_w = DisplayWidth(display, screen);
int screen_h = DisplayHeight(display, screen);
if (x + UserConfigParams::m_width > screen_w)
{
x = screen_w - UserConfigParams::m_width;
}
if (y + UserConfigParams::m_height > screen_h)
{
y = screen_h - UserConfigParams::m_height;
}
// TODO: Actually handle possible failure
XMoveWindow(display, videoData.OpenGLLinux.X11Window, x, y);
}
if (y + UserConfigParams::m_height > screen_h)
{
y = screen_h - UserConfigParams::m_height;
}
// TODO: Actually handle possible failure
XMoveWindow(display, videoData.OpenGLLinux.X11Window, x, y);
#endif
#endif
return true;

View File

@ -20,6 +20,7 @@
#include "utils/translation.hpp"
#include "utils/time.hpp"
#include "../../../lib/irrlicht/include/IrrCompileConfig.h"
#include "../../../lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.h"
/*
@ -108,8 +109,12 @@ CGUIEditBox::~CGUIEditBox()
if (Operator)
Operator->drop();
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice());
dl->setIMEEnable(false);
if (irr_driver->getDevice()->getType() == irr::EIDT_X11)
{
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(
irr_driver->getDevice());
dl->setIMEEnable(false);
}
#endif
#endif
}
@ -242,7 +247,6 @@ bool CGUIEditBox::OnEvent(const SEvent& event)
#ifndef SERVER_ONLY
if (isEnabled())
{
switch(event.EventType)
{
case EET_GUI_EVENT:
@ -254,16 +258,24 @@ bool CGUIEditBox::OnEvent(const SEvent& event)
setTextMarkers(0,0);
}
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice());
dl->setIMEEnable(false);
if (irr_driver->getDevice()->getType() == irr::EIDT_X11)
{
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(
irr_driver->getDevice());
dl->setIMEEnable(false);
}
#endif
}
#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED)
{
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice());
dl->setIMEEnable(true);
dl->setIMELocation(calculateICPos());
if (irr_driver->getDevice()->getType() == irr::EIDT_X11)
{
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(
irr_driver->getDevice());
dl->setIMEEnable(true);
dl->setIMELocation(calculateICPos());
}
}
#endif
break;
@ -1633,10 +1645,14 @@ void CGUIEditBox::calculateScrollPos()
// todo: adjust scrollbar
#if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice());
if (dl)
if (irr_driver->getDevice()->getType() == irr::EIDT_X11)
{
dl->setIMELocation(calculateICPos());
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(
irr_driver->getDevice());
if (dl)
{
dl->setIMELocation(calculateICPos());
}
}
#endif
#endif // SERVER_ONLY