Non-SDL: Add opengl3 support

This commit is contained in:
SmallJoker 2024-11-02 15:51:44 +01:00 committed by sfan5
parent 87ac32edea
commit 4838eb2f7d
10 changed files with 107 additions and 139 deletions

@ -38,7 +38,7 @@
#include "CEGLManager.h" #include "CEGLManager.h"
#endif #endif
#if defined(_IRR_COMPILE_WITH_OPENGL_) #if defined(_IRR_COMPILE_WITH_GLX_MANAGER_)
#include "CGLXManager.h" #include "CGLXManager.h"
#endif #endif
@ -69,24 +69,6 @@
#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ #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 namespace
{ {
Atom X_ATOM_CLIPBOARD; Atom X_ATOM_CLIPBOARD;
@ -397,10 +379,11 @@ bool CIrrDeviceLinux::createWindow()
if (WMCheck != None) if (WMCheck != None)
HasNetWM = true; 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 // don't use the XVisual with OpenGL, because it ignores all requested
// properties of the CreationParams // properties of the CreationParams
if (CreationParams.DriverType == video::EDT_OPENGL) { if (CreationParams.DriverType == video::EDT_OPENGL
|| CreationParams.DriverType == video::EDT_OPENGL3) {
video::SExposedVideoData data; video::SExposedVideoData data;
data.OpenGLLinux.X11Display = XDisplay; data.OpenGLLinux.X11Display = XDisplay;
ContextManager = new video::CGLXManager(CreationParams, data, Screennr); ContextManager = new video::CGLXManager(CreationParams, data, Screennr);
@ -539,51 +522,54 @@ void CIrrDeviceLinux::createDriver()
switch (CreationParams.DriverType) { switch (CreationParams.DriverType) {
#ifdef _IRR_COMPILE_WITH_X11_ #ifdef _IRR_COMPILE_WITH_X11_
case video::EDT_OPENGL: case video::EDT_OPENGL:
#ifdef _IRR_COMPILE_WITH_OPENGL_
{ {
#ifdef _IRR_COMPILE_WITH_OPENGL_
video::SExposedVideoData data; video::SExposedVideoData data;
data.OpenGLLinux.X11Window = XWindow; data.OpenGLLinux.X11Window = XWindow;
data.OpenGLLinux.X11Display = XDisplay; data.OpenGLLinux.X11Display = XDisplay;
ContextManager->initialize(CreationParams, data); ContextManager->initialize(CreationParams, data);
#endif
VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager);
} }
#else break;
os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); case video::EDT_OPENGL3:
{
#ifdef ENABLE_OPENGL3
video::SExposedVideoData data;
data.OpenGLLinux.X11Window = XWindow;
data.OpenGLLinux.X11Display = XDisplay;
ContextManager->initialize(CreationParams, data);
#endif #endif
VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager);
}
break; break;
case video::EDT_OGLES2: case video::EDT_OGLES2:
#ifdef _IRR_COMPILE_WITH_OGLES2_
{ {
#ifdef _IRR_COMPILE_WITH_OGLES2_
video::SExposedVideoData data; video::SExposedVideoData data;
data.OpenGLLinux.X11Window = XWindow; data.OpenGLLinux.X11Window = XWindow;
data.OpenGLLinux.X11Display = XDisplay; data.OpenGLLinux.X11Display = XDisplay;
ContextManager = new video::CEGLManager(); ContextManager = new video::CEGLManager();
ContextManager->initialize(CreationParams, data); ContextManager->initialize(CreationParams, data);
#endif
VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager);
} }
#else
os::Printer::log("No OpenGL-ES2 support compiled in.", ELL_ERROR);
#endif
break; break;
case video::EDT_WEBGL1: case video::EDT_WEBGL1:
#ifdef _IRR_COMPILE_WITH_WEBGL1_
{ {
#ifdef _IRR_COMPILE_WITH_WEBGL1_
video::SExposedVideoData data; video::SExposedVideoData data;
data.OpenGLLinux.X11Window = XWindow; data.OpenGLLinux.X11Window = XWindow;
data.OpenGLLinux.X11Display = XDisplay; data.OpenGLLinux.X11Display = XDisplay;
ContextManager = new video::CEGLManager(); ContextManager = new video::CEGLManager();
ContextManager->initialize(CreationParams, data); ContextManager->initialize(CreationParams, data);
#endif
VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager); VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager);
} }
#else
os::Printer::log("No WebGL1 support compiled in.", ELL_ERROR);
#endif
break; break;
case video::EDT_NULL: case video::EDT_NULL:
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
@ -591,7 +577,7 @@ void CIrrDeviceLinux::createDriver()
default: default:
os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR);
break; break;
#else #else // no X11
case video::EDT_NULL: case video::EDT_NULL:
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
break; break;

@ -433,14 +433,6 @@ long GetDictionaryLong(CFDictionaryRef theDict, const void *key)
return value; return value;
} }
namespace irr
{
namespace video
{
IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters &param, io::IFileSystem *io, IContextManager *contextManager);
}
} // end namespace irr
static bool firstLaunch = true; static bool firstLaunch = true;
@implementation CIrrDelegateOSX { @implementation CIrrDelegateOSX {
@ -721,6 +713,7 @@ void CIrrDeviceMacOSX::createDriver()
#endif #endif
break; break;
case video::EDT_OPENGL3:
case video::EDT_OGLES2: case video::EDT_OGLES2:
os::Printer::log("This driver is not available on OSX.", ELL_ERROR); os::Printer::log("This driver is not available on OSX.", ELL_ERROR);
break; break;

@ -29,53 +29,6 @@
static int SDLDeviceInstances = 0; 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 namespace irr
{ {
#ifdef _IRR_EMSCRIPTEN_PLATFORM_ #ifdef _IRR_EMSCRIPTEN_PLATFORM_

@ -17,6 +17,42 @@
namespace irr 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 //! constructor
CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters &params) : CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters &params) :
IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0), IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),

@ -33,7 +33,15 @@ IFileSystem *createFileSystem();
namespace video 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 //! Stub for an Irrlicht Device implementation

@ -34,24 +34,10 @@
#include "CEGLManager.h" #include "CEGLManager.h"
#endif #endif
#if defined(_IRR_COMPILE_WITH_OPENGL_) #if defined(_IRR_COMPILE_WITH_WGL_MANAGER_)
#include "CWGLManager.h" #include "CWGLManager.h"
#endif #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 namespace irr
{ {
struct SJoystickWin32Control struct SJoystickWin32Control
@ -880,14 +866,23 @@ void CIrrDeviceWin32::createDriver()
ContextManager = new video::CWGLManager(); ContextManager = new video::CWGLManager();
ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd)); ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd));
#endif
VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager);
if (!VideoDriver) if (!VideoDriver)
os::Printer::log("Could not create OpenGL driver.", ELL_ERROR); os::Printer::log("Could not create OpenGL driver.", ELL_ERROR);
#else break;
os::Printer::log("OpenGL driver was not compiled in.", ELL_ERROR); case video::EDT_OPENGL3:
#ifdef ENABLE_OPENGL3
switchToFullScreen();
ContextManager = new video::CWGLManager();
ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd));
#endif #endif
VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager);
if (!VideoDriver)
os::Printer::log("Could not create OpenGL 3 driver.", ELL_ERROR);
break; break;
case video::EDT_OGLES2: case video::EDT_OGLES2:
#ifdef _IRR_COMPILE_WITH_OGLES2_ #ifdef _IRR_COMPILE_WITH_OGLES2_
@ -895,14 +890,11 @@ void CIrrDeviceWin32::createDriver()
ContextManager = new video::CEGLManager(); ContextManager = new video::CEGLManager();
ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd)); ContextManager->initialize(CreationParams, video::SExposedVideoData(HWnd));
#endif
VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager);
if (!VideoDriver) if (!VideoDriver)
os::Printer::log("Could not create OpenGL-ES2 driver.", ELL_ERROR); 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; break;
case video::EDT_WEBGL1: case video::EDT_WEBGL1:
os::Printer::log("WebGL1 driver not supported on Win32 device.", ELL_ERROR); os::Printer::log("WebGL1 driver not supported on Win32 device.", ELL_ERROR);

@ -123,10 +123,10 @@ if(USE_SDL2)
if(NOT ANDROID) if(NOT ANDROID)
set(DEFAULT_OPENGL3 TRUE) set(DEFAULT_OPENGL3 TRUE)
endif() endif()
option(ENABLE_OPENGL3 "Enable OpenGL 3+" ${DEFAULT_OPENGL3})
else() else()
set(ENABLE_OPENGL3 FALSE) set(DEFAULT_OPENGL3 FALSE)
endif() endif()
option(ENABLE_OPENGL3 "Enable OpenGL 3+" ${DEFAULT_OPENGL3})
if(ANDROID OR EMSCRIPTEN) if(ANDROID OR EMSCRIPTEN)
set(ENABLE_OPENGL FALSE) set(ENABLE_OPENGL FALSE)
@ -152,9 +152,11 @@ else()
endif() endif()
endif() endif()
if(ENABLE_OPENGL) if(ENABLE_OPENGL OR (ENABLE_OPENGL3 AND NOT USE_SDL2))
if(ENABLE_OPENGL)
add_definitions(-D_IRR_COMPILE_WITH_OPENGL_) add_definitions(-D_IRR_COMPILE_WITH_OPENGL_)
set(OPENGL_DIRECT_LINK TRUE) # driver relies on this set(OPENGL_DIRECT_LINK TRUE) # driver relies on this
endif()
if(DEVICE STREQUAL "WINDOWS") if(DEVICE STREQUAL "WINDOWS")
add_definitions(-D_IRR_COMPILE_WITH_WGL_MANAGER_) add_definitions(-D_IRR_COMPILE_WITH_WGL_MANAGER_)
elseif(DEVICE STREQUAL "X11") elseif(DEVICE STREQUAL "X11")
@ -165,7 +167,11 @@ if(ENABLE_OPENGL)
endif() endif()
if(ENABLE_OPENGL3) 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") message(FATAL_ERROR "OpenGL 3 driver requires SDL2")
endif() endif()
endif() endif()

@ -3239,19 +3239,9 @@ COpenGLCacheHandler *COpenGLDriver::getCacheHandler() const
return CacheHandler; return CacheHandler;
} }
} // end namespace
} // end namespace
#endif // _IRR_COMPILE_WITH_OPENGL_
namespace irr
{
namespace video
{
IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager) IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters &params, io::IFileSystem *io, IContextManager *contextManager)
{ {
#ifdef _IRR_COMPILE_WITH_OPENGL_
COpenGLDriver *ogl = new COpenGLDriver(params, io, contextManager); COpenGLDriver *ogl = new COpenGLDriver(params, io, contextManager);
if (!ogl->initDriver()) { if (!ogl->initDriver()) {
@ -3260,10 +3250,8 @@ IVideoDriver *createOpenGLDriver(const SIrrlichtCreationParameters &params, io::
} }
return ogl; return ogl;
#else
return 0;
#endif
} }
} // end namespace } // end namespace video
} // end namespace } // end namespace irr
#endif // opengl

@ -226,8 +226,8 @@ void COpenGL3DriverBase::initVersion()
printVersion(); printVersion();
// print renderer information // print renderer information
VendorName = GL.GetString(GL_VENDOR); VendorName = GL.GetString(GL_RENDERER);
os::Printer::log("Vendor", VendorName.c_str(), ELL_INFORMATION); os::Printer::log("Renderer", VendorName.c_str(), ELL_INFORMATION);
Version = getVersionFromOpenGL(); Version = getVersionFromOpenGL();
} }

@ -34,8 +34,14 @@ OpenGLVersion COpenGL3Driver::getVersionFromOpenGL() const
void COpenGL3Driver::initFeatures() void COpenGL3Driver::initFeatures()
{ {
assert(Version.Spec == OpenGLSpec::Compat); if (Version.Spec != OpenGLSpec::Compat) {
assert(isVersionAtLeast(3, 2)); 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(); initExtensions();
TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}; // WARNING: may not be renderable TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}; // WARNING: may not be renderable