Skip to content

Commit

Permalink
Non-SDL: Add opengl3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker authored and sfan5 committed Nov 15, 2024
1 parent 87ac32e commit 4838eb2
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 139 deletions.
58 changes: 22 additions & 36 deletions irr/src/CIrrDeviceLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "CEGLManager.h"
#endif

#if defined(_IRR_COMPILE_WITH_OPENGL_)
#if defined(_IRR_COMPILE_WITH_GLX_MANAGER_)
#include "CGLXManager.h"
#endif

Expand Down Expand Up @@ -69,24 +69,6 @@

#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_

namespace irr
{
namespace video
{
#ifdef _IRR_COMPILE_WITH_OPENGL_
IVideoDriver *createOpenGLDriver(const irr::SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
#endif

#ifdef _IRR_COMPILE_WITH_OGLES2_
IVideoDriver *createOGLES2Driver(const irr::SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
#endif

#ifdef _IRR_COMPILE_WITH_WEBGL1_
IVideoDriver *createWebGL1Driver(const irr::SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
#endif
}
} // end namespace irr

namespace
{
Atom X_ATOM_CLIPBOARD;
Expand Down Expand Up @@ -397,10 +379,11 @@ bool CIrrDeviceLinux::createWindow()
if (WMCheck != None)
HasNetWM = true;

#if defined(_IRR_COMPILE_WITH_OPENGL_)
#if defined(_IRR_COMPILE_WITH_GLX_MANAGER_)
// don't use the XVisual with OpenGL, because it ignores all requested
// properties of the CreationParams
if (CreationParams.DriverType == video::EDT_OPENGL) {
if (CreationParams.DriverType == video::EDT_OPENGL
|| CreationParams.DriverType == video::EDT_OPENGL3) {
video::SExposedVideoData data;
data.OpenGLLinux.X11Display = XDisplay;
ContextManager = new video::CGLXManager(CreationParams, data, Screennr);
Expand Down Expand Up @@ -539,59 +522,62 @@ void CIrrDeviceLinux::createDriver()
switch (CreationParams.DriverType) {
#ifdef _IRR_COMPILE_WITH_X11_
case video::EDT_OPENGL:
#ifdef _IRR_COMPILE_WITH_OPENGL_
{
#ifdef _IRR_COMPILE_WITH_OPENGL_
video::SExposedVideoData data;
data.OpenGLLinux.X11Window = XWindow;
data.OpenGLLinux.X11Display = XDisplay;

ContextManager->initialize(CreationParams, data);

#endif
VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager);
}
#else
os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
break;
case video::EDT_OPENGL3:
{
#ifdef ENABLE_OPENGL3
video::SExposedVideoData data;
data.OpenGLLinux.X11Window = XWindow;
data.OpenGLLinux.X11Display = XDisplay;

ContextManager->initialize(CreationParams, data);
#endif
VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager);
}
break;
case video::EDT_OGLES2:
#ifdef _IRR_COMPILE_WITH_OGLES2_
{
#ifdef _IRR_COMPILE_WITH_OGLES2_
video::SExposedVideoData data;
data.OpenGLLinux.X11Window = XWindow;
data.OpenGLLinux.X11Display = XDisplay;

ContextManager = new video::CEGLManager();
ContextManager->initialize(CreationParams, data);

#endif
VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager);
}
#else
os::Printer::log("No OpenGL-ES2 support compiled in.", ELL_ERROR);
#endif
break;
case video::EDT_WEBGL1:
#ifdef _IRR_COMPILE_WITH_WEBGL1_
{
#ifdef _IRR_COMPILE_WITH_WEBGL1_
video::SExposedVideoData data;
data.OpenGLLinux.X11Window = XWindow;
data.OpenGLLinux.X11Display = XDisplay;

ContextManager = new video::CEGLManager();
ContextManager->initialize(CreationParams, data);

#endif
VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager);
}
#else
os::Printer::log("No WebGL1 support compiled in.", ELL_ERROR);
#endif
break;
case video::EDT_NULL:
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
break;
default:
os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR);
break;
#else
#else // no X11
case video::EDT_NULL:
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
break;
Expand Down
9 changes: 1 addition & 8 deletions irr/src/CIrrDeviceOSX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,6 @@ long GetDictionaryLong(CFDictionaryRef theDict, const void *key)
return value;
}

namespace irr
{
namespace video
{
IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters &param, io::IFileSystem *io, IContextManager *contextManager);
}
} // end namespace irr

static bool firstLaunch = true;

@implementation CIrrDelegateOSX {
Expand Down Expand Up @@ -721,6 +713,7 @@ - (BOOL)isQuit
#endif
break;

case video::EDT_OPENGL3:
case video::EDT_OGLES2:
os::Printer::log("This driver is not available on OSX.", ELL_ERROR);
break;
Expand Down
47 changes: 0 additions & 47 deletions irr/src/CIrrDeviceSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,6 @@

static int SDLDeviceInstances = 0;

namespace irr
{
namespace video
{
#ifdef _IRR_COMPILE_WITH_OPENGL_
IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
#else
static IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager)
{
os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
return nullptr;
}
#endif

#ifdef ENABLE_OPENGL3
IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
#else
static IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager)
{
os::Printer::log("No OpenGL 3 support compiled in.", ELL_ERROR);
return nullptr;
}
#endif

#ifdef _IRR_COMPILE_WITH_OGLES2_
IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
#else
static IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager)
{
os::Printer::log("No OpenGL ES 2 support compiled in.", ELL_ERROR);
return nullptr;
}
#endif

#ifdef _IRR_COMPILE_WITH_WEBGL1_
IVideoDriver *createWebGL1Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
#else
static IVideoDriver *createWebGL1Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager)
{
os::Printer::log("No WebGL 1 support compiled in.", ELL_ERROR);
return nullptr;
}
#endif
} // end namespace video

} // end namespace irr

namespace irr
{
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
Expand Down
36 changes: 36 additions & 0 deletions irr/src/CIrrDeviceStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,42 @@

namespace irr
{
namespace video
{
#ifndef _IRR_COMPILE_WITH_OPENGL_
IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager)
{
os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
return nullptr;
}
#endif

#ifndef ENABLE_OPENGL3
IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager)
{
os::Printer::log("No OpenGL 3 support compiled in.", ELL_ERROR);
return nullptr;
}
#endif

#ifndef _IRR_COMPILE_WITH_OGLES2_
IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager)
{
os::Printer::log("No OpenGL ES 2 support compiled in.", ELL_ERROR);
return nullptr;
}
#endif

#ifndef _IRR_COMPILE_WITH_WEBGL1_
IVideoDriver *createWebGL1Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager)
{
os::Printer::log("No WebGL 1 support compiled in.", ELL_ERROR);
return nullptr;
}
#endif
}


//! constructor
CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters &params) :
IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
Expand Down
10 changes: 9 additions & 1 deletion irr/src/CIrrDeviceStub.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ IFileSystem *createFileSystem();

namespace video
{
IVideoDriver *createNullDriver(io::IFileSystem *io, const core::dimension2d<u32> &screenSize);
IVideoDriver *createNullDriver(io::IFileSystem *io, const core::dimension2d<u32> &screenSize);

IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);

IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);

IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);

IVideoDriver *createWebGL1Driver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
}

//! Stub for an Irrlicht Device implementation
Expand Down
36 changes: 14 additions & 22 deletions irr/src/CIrrDeviceWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,10 @@
#include "CEGLManager.h"
#endif

#if defined(_IRR_COMPILE_WITH_OPENGL_)
#if defined(_IRR_COMPILE_WITH_WGL_MANAGER_)
#include "CWGLManager.h"
#endif

namespace irr
{
namespace video
{
#ifdef _IRR_COMPILE_WITH_OPENGL_
IVideoDriver *createOpenGLDriver(const irr::SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
#endif

#ifdef _IRR_COMPILE_WITH_OGLES2_
IVideoDriver *createOGLES2Driver(const irr::SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager);
#endif
}
} // end namespace irr

namespace irr
{
struct SJoystickWin32Control
Expand Down Expand Up @@ -880,29 +866,35 @@ void CIrrDeviceWin32::createDriver()

ContextManager = new video::CWGLManager();
ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd));

#endif
VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager);

if (!VideoDriver)
os::Printer::log("Could not create OpenGL driver.", ELL_ERROR);
#else
os::Printer::log("OpenGL driver was not compiled in.", ELL_ERROR);
break;
case video::EDT_OPENGL3:
#ifdef ENABLE_OPENGL3
switchToFullScreen();

ContextManager = new video::CWGLManager();
ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd));
#endif
VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager);

if (!VideoDriver)
os::Printer::log("Could not create OpenGL 3 driver.", ELL_ERROR);
break;
case video::EDT_OGLES2:
#ifdef _IRR_COMPILE_WITH_OGLES2_
switchToFullScreen();

ContextManager = new video::CEGLManager();
ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd));

#endif
VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager);

if (!VideoDriver)
os::Printer::log("Could not create OpenGL-ES2 driver.", ELL_ERROR);
#else
os::Printer::log("OpenGL-ES2 driver was not compiled in.", ELL_ERROR);
#endif
break;
case video::EDT_WEBGL1:
os::Printer::log("WebGL1 driver not supported on Win32 device.", ELL_ERROR);
Expand Down
18 changes: 12 additions & 6 deletions irr/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ if(USE_SDL2)
if(NOT ANDROID)
set(DEFAULT_OPENGL3 TRUE)
endif()
option(ENABLE_OPENGL3 "Enable OpenGL 3+" ${DEFAULT_OPENGL3})
else()
set(ENABLE_OPENGL3 FALSE)
set(DEFAULT_OPENGL3 FALSE)
endif()
option(ENABLE_OPENGL3 "Enable OpenGL 3+" ${DEFAULT_OPENGL3})

if(ANDROID OR EMSCRIPTEN)
set(ENABLE_OPENGL FALSE)
Expand All @@ -152,9 +152,11 @@ else()
endif()
endif()

if(ENABLE_OPENGL)
add_definitions(-D_IRR_COMPILE_WITH_OPENGL_)
set(OPENGL_DIRECT_LINK TRUE) # driver relies on this
if(ENABLE_OPENGL OR (ENABLE_OPENGL3 AND NOT USE_SDL2))
if(ENABLE_OPENGL)
add_definitions(-D_IRR_COMPILE_WITH_OPENGL_)
set(OPENGL_DIRECT_LINK TRUE) # driver relies on this
endif()
if(DEVICE STREQUAL "WINDOWS")
add_definitions(-D_IRR_COMPILE_WITH_WGL_MANAGER_)
elseif(DEVICE STREQUAL "X11")
Expand All @@ -165,7 +167,11 @@ if(ENABLE_OPENGL)
endif()

if(ENABLE_OPENGL3)
if (NOT USE_SDL2)
if(DEVICE STREQUAL "WINDOWS")
# supported
elseif(DEVICE STREQUAL "X11")
# supported
elseif (NOT USE_SDL2)
message(FATAL_ERROR "OpenGL 3 driver requires SDL2")
endif()
endif()
Expand Down
Loading

0 comments on commit 4838eb2

Please sign in to comment.