Allow to use GLES renderer with Wayland device.

It would be nice to simplify it a bit, i.e. decide if OpenGL context should be created on device side or driver side, use single constructor in GLES driver etc... But I'm not really sure how it will look like after Benau's space partitioning work, so some refactoring postponed till later.
This commit is contained in:
Deve 2017-05-30 00:30:00 +02:00
parent c8137fc0fa
commit e00995d099
4 changed files with 83 additions and 12 deletions

View File

@ -64,6 +64,8 @@ namespace irr
extern bool useCoreContext; extern bool useCoreContext;
IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceWayland* device); io::IFileSystem* io, CIrrDeviceWayland* device);
IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceWayland* device);
} }
} }
@ -730,7 +732,11 @@ bool CIrrDeviceWayland::initEGL()
m_egl_context = new ContextManagerEGL(); m_egl_context = new ContextManagerEGL();
ContextEGLParams egl_params; ContextEGLParams egl_params;
#ifdef _IRR_COMPILE_WITH_OGLES2_
egl_params.opengl_api = CEGL_API_OPENGL_ES;
#else
egl_params.opengl_api = CEGL_API_OPENGL; egl_params.opengl_api = CEGL_API_OPENGL;
#endif
egl_params.surface_type = CEGL_SURFACE_WINDOW; egl_params.surface_type = CEGL_SURFACE_WINDOW;
egl_params.force_legacy_device = CreationParams.ForceLegacyDevice; egl_params.force_legacy_device = CreationParams.ForceLegacyDevice;
egl_params.with_alpha_channel = CreationParams.WithAlphaChannel; egl_params.with_alpha_channel = CreationParams.WithAlphaChannel;
@ -819,9 +825,6 @@ void CIrrDeviceWayland::createDriver()
{ {
switch(CreationParams.DriverType) switch(CreationParams.DriverType)
{ {
default:
os::Printer::log("Wayland driver only supports OpenGL.", ELL_ERROR);
break;
case video::EDT_OPENGL: case video::EDT_OPENGL:
#ifdef _IRR_COMPILE_WITH_OPENGL_ #ifdef _IRR_COMPILE_WITH_OPENGL_
VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this); VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this);
@ -829,6 +832,19 @@ void CIrrDeviceWayland::createDriver()
os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
#endif #endif
break; break;
case video::EDT_OGLES2:
#ifdef _IRR_COMPILE_WITH_OGLES2_
VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, this);
#else
os::Printer::log("No OpenGL ES 2.0 support compiled in.", ELL_ERROR);
#endif
break;
case video::EDT_NULL:
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
break;
default:
os::Printer::log("Wayland driver only supports OpenGL.", ELL_ERROR);
break;
} }
} }

View File

@ -54,6 +54,9 @@ namespace video
#endif #endif
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) #if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
, HDc(0) , HDc(0)
#endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
, wl_device(0)
#endif #endif
, Params(params) , Params(params)
{ {
@ -77,7 +80,7 @@ namespace video
HDc = GetDC(data.OpenGLWin32.HWnd); HDc = GetDC(data.OpenGLWin32.HWnd);
egl_params.display = (NativeDisplayType)(HDc); egl_params.display = (NativeDisplayType)(HDc);
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
egl_params.window = data.OpenGLLinux.X11Window; egl_params.window = (EGLNativeWindowType)(data.OpenGLLinux.X11Window);
egl_params.display = (EGLNativeDisplayType)(data.OpenGLLinux.X11Display); egl_params.display = (EGLNativeDisplayType)(data.OpenGLLinux.X11Display);
#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) #elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
egl_params.window = ((struct android_app *)(params.PrivateData))->window; egl_params.window = ((struct android_app *)(params.PrivateData))->window;
@ -133,6 +136,21 @@ namespace video
#endif #endif
} }
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
COGLES2Driver::COGLES2Driver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceWayland* device)
: CNullDriver(io, params.WindowSize), COGLES2ExtensionHandler(),
BridgeCalls(0), CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
Transformation3DChanged(true), AntiAlias(params.AntiAlias),
RenderTargetTexture(0), CurrentRendertargetSize(0, 0),
ColorFormat(ECF_R8G8B8), EglContext(0), Params(params)
{
EglContext = device->getEGLContext();
wl_device = device;
genericDriverInit(params.WindowSize, params.Stencilbuffer);
}
#endif
//! destructor //! destructor
COGLES2Driver::~COGLES2Driver() COGLES2Driver::~COGLES2Driver()
@ -467,7 +485,15 @@ namespace video
CNullDriver::endScene(); CNullDriver::endScene();
#if defined(_IRR_COMPILE_WITH_EGL_) #if defined(_IRR_COMPILE_WITH_EGL_)
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
if (wl_device != NULL)
{
wl_device->swapBuffers();
return true;
}
else
#endif
{
bool res = EglContext->swapBuffers(); bool res = EglContext->swapBuffers();
if (!res) if (!res)
@ -475,7 +501,7 @@ namespace video
os::Printer::log("Could not swap buffers for OpenGL-ES2 driver."); os::Printer::log("Could not swap buffers for OpenGL-ES2 driver.");
return false; return false;
} }
}
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) #elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
glFlush(); glFlush();
glBindRenderbuffer(GL_RENDERBUFFER, ViewRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, ViewRenderbuffer);
@ -2871,6 +2897,22 @@ namespace video
} }
#endif #endif
// -----------------------------------
// WAYLAND VERSION
// -----------------------------------
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceWayland* device)
{
#ifdef _IRR_COMPILE_WITH_OGLES2_
return new COGLES2Driver(params, io, device);
#else
return 0;
#endif // _IRR_COMPILE_WITH_OGLES2_
}
#endif
// ----------------------------------- // -----------------------------------
// MACOSX VERSION // MACOSX VERSION
// ----------------------------------- // -----------------------------------

View File

@ -14,6 +14,8 @@
#include "MacOSX/CIrrDeviceMacOSX.h" #include "MacOSX/CIrrDeviceMacOSX.h"
#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) #elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
#include "iOS/CIrrDeviceiOS.h" #include "iOS/CIrrDeviceiOS.h"
#elif _IRR_COMPILE_WITH_WAYLAND_DEVICE_
#include "CIrrDeviceWayland.h"
#endif #endif
#include "SIrrCreationParameters.h" #include "SIrrCreationParameters.h"
@ -63,6 +65,11 @@ namespace video
io::IFileSystem* io); io::IFileSystem* io);
#endif #endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
COGLES2Driver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceWayland* device);
#endif
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
COGLES2Driver(const SIrrlichtCreationParameters& params, COGLES2Driver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceMacOSX *device); io::IFileSystem* io, CIrrDeviceMacOSX *device);
@ -461,6 +468,9 @@ namespace video
#if defined(_IRR_COMPILE_WITH_EGL_) #if defined(_IRR_COMPILE_WITH_EGL_)
ContextManagerEGL* EglContext; ContextManagerEGL* EglContext;
#endif #endif
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
CIrrDeviceWayland* wl_device;
#endif
#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) #if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
CIrrDeviceIPhone* Device; CIrrDeviceIPhone* Device;
GLuint ViewFramebuffer; GLuint ViewFramebuffer;

View File

@ -4998,6 +4998,7 @@ IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
io::IFileSystem* io, CIrrDeviceWayland* device) io::IFileSystem* io, CIrrDeviceWayland* device)
{ {
#ifdef _IRR_COMPILE_WITH_OPENGL_
COpenGLDriver* ogl = new COpenGLDriver(params, io, device); COpenGLDriver* ogl = new COpenGLDriver(params, io, device);
if (!ogl->initDriver(device)) if (!ogl->initDriver(device))
{ {
@ -5005,7 +5006,9 @@ IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
ogl = 0; ogl = 0;
} }
return ogl; return ogl;
#else
return 0;
#endif // _IRR_COMPILE_WITH_OPENGL_
} }
#endif // _IRR_COMPILE_WITH_WAYLAND_DEVICE #endif // _IRR_COMPILE_WITH_WAYLAND_DEVICE