From 4838eb2f7de8477ef5be7e064d072954ff78e36c Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 2 Nov 2024 15:51:44 +0100 Subject: [PATCH] Non-SDL: Add opengl3 support --- irr/src/CIrrDeviceLinux.cpp | 58 ++++++++++++++----------------------- irr/src/CIrrDeviceOSX.mm | 9 +----- irr/src/CIrrDeviceSDL.cpp | 47 ------------------------------ irr/src/CIrrDeviceStub.cpp | 36 +++++++++++++++++++++++ irr/src/CIrrDeviceStub.h | 10 ++++++- irr/src/CIrrDeviceWin32.cpp | 36 +++++++++-------------- irr/src/CMakeLists.txt | 18 ++++++++---- irr/src/COpenGLDriver.cpp | 18 ++---------- irr/src/OpenGL/Driver.cpp | 4 +-- irr/src/OpenGL3/Driver.cpp | 10 +++++-- 10 files changed, 107 insertions(+), 139 deletions(-) diff --git a/irr/src/CIrrDeviceLinux.cpp b/irr/src/CIrrDeviceLinux.cpp index f20be36f7..e88902936 100644 --- a/irr/src/CIrrDeviceLinux.cpp +++ b/irr/src/CIrrDeviceLinux.cpp @@ -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 @@ -69,24 +69,6 @@ #endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ -namespace irr -{ -namespace video -{ -#ifdef _IRR_COMPILE_WITH_OPENGL_ -IVideoDriver *createOpenGLDriver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#endif - -#ifdef _IRR_COMPILE_WITH_OGLES2_ -IVideoDriver *createOGLES2Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#endif - -#ifdef _IRR_COMPILE_WITH_WEBGL1_ -IVideoDriver *createWebGL1Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#endif -} -} // end namespace irr - namespace { Atom X_ATOM_CLIPBOARD; @@ -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); @@ -539,51 +522,54 @@ 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); @@ -591,7 +577,7 @@ void CIrrDeviceLinux::createDriver() 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; diff --git a/irr/src/CIrrDeviceOSX.mm b/irr/src/CIrrDeviceOSX.mm index 43c1c81b6..4b46e5e29 100644 --- a/irr/src/CIrrDeviceOSX.mm +++ b/irr/src/CIrrDeviceOSX.mm @@ -433,14 +433,6 @@ long GetDictionaryLong(CFDictionaryRef theDict, const void *key) return value; } -namespace irr -{ -namespace video -{ -IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶m, io::IFileSystem *io, IContextManager *contextManager); -} -} // end namespace irr - static bool firstLaunch = true; @implementation CIrrDelegateOSX { @@ -721,6 +713,7 @@ void CIrrDeviceMacOSX::createDriver() #endif break; + case video::EDT_OPENGL3: case video::EDT_OGLES2: os::Printer::log("This driver is not available on OSX.", ELL_ERROR); break; diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index 408027761..543bea63e 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -29,53 +29,6 @@ static int SDLDeviceInstances = 0; -namespace irr -{ -namespace video -{ -#ifdef _IRR_COMPILE_WITH_OPENGL_ -IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#else -static IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, 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 ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#else -static IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters ¶ms, 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 ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#else -static IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters ¶ms, 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 ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#else -static IVideoDriver *createWebGL1Driver(const SIrrlichtCreationParameters ¶ms, 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_ diff --git a/irr/src/CIrrDeviceStub.cpp b/irr/src/CIrrDeviceStub.cpp index fd8e458c8..2bd0fb1d0 100644 --- a/irr/src/CIrrDeviceStub.cpp +++ b/irr/src/CIrrDeviceStub.cpp @@ -17,6 +17,42 @@ namespace irr { +namespace video +{ +#ifndef _IRR_COMPILE_WITH_OPENGL_ +IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, 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 ¶ms, 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 ¶ms, 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 ¶ms, io::IFileSystem *io, IContextManager *contextManager) +{ + os::Printer::log("No WebGL 1 support compiled in.", ELL_ERROR); + return nullptr; +} +#endif +} + + //! constructor CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters ¶ms) : IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0), diff --git a/irr/src/CIrrDeviceStub.h b/irr/src/CIrrDeviceStub.h index 9a1966f01..c46fd64fc 100644 --- a/irr/src/CIrrDeviceStub.h +++ b/irr/src/CIrrDeviceStub.h @@ -33,7 +33,15 @@ IFileSystem *createFileSystem(); namespace video { -IVideoDriver *createNullDriver(io::IFileSystem *io, const core::dimension2d &screenSize); + IVideoDriver *createNullDriver(io::IFileSystem *io, const core::dimension2d &screenSize); + + IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); + + IVideoDriver *createOpenGL3Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); + + IVideoDriver *createOGLES2Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); + + IVideoDriver *createWebGL1Driver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); } //! Stub for an Irrlicht Device implementation diff --git a/irr/src/CIrrDeviceWin32.cpp b/irr/src/CIrrDeviceWin32.cpp index 366be8013..417694517 100644 --- a/irr/src/CIrrDeviceWin32.cpp +++ b/irr/src/CIrrDeviceWin32.cpp @@ -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 ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#endif - -#ifdef _IRR_COMPILE_WITH_OGLES2_ -IVideoDriver *createOGLES2Driver(const irr::SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager); -#endif -} -} // end namespace irr - namespace irr { struct SJoystickWin32Control @@ -880,14 +866,23 @@ 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_ @@ -895,14 +890,11 @@ void CIrrDeviceWin32::createDriver() 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); diff --git a/irr/src/CMakeLists.txt b/irr/src/CMakeLists.txt index 3b578d699..b95c3ef73 100644 --- a/irr/src/CMakeLists.txt +++ b/irr/src/CMakeLists.txt @@ -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) @@ -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") @@ -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() diff --git a/irr/src/COpenGLDriver.cpp b/irr/src/COpenGLDriver.cpp index ee63fc845..2cbf6d8e6 100644 --- a/irr/src/COpenGLDriver.cpp +++ b/irr/src/COpenGLDriver.cpp @@ -3239,19 +3239,9 @@ COpenGLCacheHandler *COpenGLDriver::getCacheHandler() const return CacheHandler; } -} // end namespace -} // end namespace - -#endif // _IRR_COMPILE_WITH_OPENGL_ - -namespace irr -{ -namespace video -{ IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, io::IFileSystem *io, IContextManager *contextManager) { -#ifdef _IRR_COMPILE_WITH_OPENGL_ COpenGLDriver *ogl = new COpenGLDriver(params, io, contextManager); if (!ogl->initDriver()) { @@ -3260,10 +3250,8 @@ IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters ¶ms, io:: } return ogl; -#else - return 0; -#endif } -} // end namespace -} // end namespace +} // end namespace video +} // end namespace irr +#endif // opengl diff --git a/irr/src/OpenGL/Driver.cpp b/irr/src/OpenGL/Driver.cpp index fe9a24758..4f3ac627a 100644 --- a/irr/src/OpenGL/Driver.cpp +++ b/irr/src/OpenGL/Driver.cpp @@ -226,8 +226,8 @@ void COpenGL3DriverBase::initVersion() printVersion(); // print renderer information - VendorName = GL.GetString(GL_VENDOR); - os::Printer::log("Vendor", VendorName.c_str(), ELL_INFORMATION); + VendorName = GL.GetString(GL_RENDERER); + os::Printer::log("Renderer", VendorName.c_str(), ELL_INFORMATION); Version = getVersionFromOpenGL(); } diff --git a/irr/src/OpenGL3/Driver.cpp b/irr/src/OpenGL3/Driver.cpp index fd018b91d..53cb8c7ed 100644 --- a/irr/src/OpenGL3/Driver.cpp +++ b/irr/src/OpenGL3/Driver.cpp @@ -34,8 +34,14 @@ OpenGLVersion COpenGL3Driver::getVersionFromOpenGL() const void COpenGL3Driver::initFeatures() { - assert(Version.Spec == OpenGLSpec::Compat); - assert(isVersionAtLeast(3, 2)); + if (Version.Spec != OpenGLSpec::Compat) { + os::Printer::log("OpenGL 3 driver requires Compatibility Mode", ELL_ERROR); + throw std::exception(); + } + if (!isVersionAtLeast(3, 2)) { + os::Printer::log("OpenGL 3 driver requires OpenGL >= 3.2 ", ELL_ERROR); + throw std::exception(); + } initExtensions(); TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}; // WARNING: may not be renderable