aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-05-21 15:19:57 +0200
committersfan5 <sfan5@live.de>2022-05-21 15:26:38 +0200
commit593103a26148b7154b159b9ae728fd53b4e7ca84 (patch)
treee36f3a85315d090d050a681fab10f15c36ffd703
parent0732807cc8c52881287c53963b836b2fc445dd9f (diff)
downloadirrlicht-593103a26148b7154b159b9ae728fd53b4e7ca84.tar.xz
Refactor SDL device to use the same abstraction as other devices
In particular this makes the OpenGL procedure stuff work. fixes https://github.com/minetest/minetest/issues/12265
-rw-r--r--source/Irrlicht/CIrrDeviceSDL.cpp23
-rw-r--r--source/Irrlicht/CMakeLists.txt1
-rw-r--r--source/Irrlicht/COpenGLDriver.cpp52
-rw-r--r--source/Irrlicht/COpenGLDriver.h10
-rw-r--r--source/Irrlicht/CSDLManager.cpp56
-rw-r--r--source/Irrlicht/CSDLManager.h53
6 files changed, 121 insertions, 74 deletions
diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp
index bf7da7f..c66cfda 100644
--- a/source/Irrlicht/CIrrDeviceSDL.cpp
+++ b/source/Irrlicht/CIrrDeviceSDL.cpp
@@ -26,28 +26,26 @@
#include <emscripten.h>
#endif
+#ifdef _IRR_COMPILE_WITH_OPENGL_
+#include "CSDLManager.h"
+#endif
+
static int SDLDeviceInstances = 0;
namespace irr
{
namespace video
{
- #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
- IVideoDriver* createDirectX9Driver(const irr::SIrrlichtCreationParameters& params,
- io::IFileSystem* io, HWND window);
- #endif
-
#ifdef _IRR_COMPILE_WITH_OPENGL_
- IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
- io::IFileSystem* io, CIrrDeviceSDL* device);
+ IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
#endif
- #if defined(_IRR_COMPILE_WITH_OGLES2_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)
- IVideoDriver* createOGLES2Driver(const irr::SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
+ #ifdef _IRR_COMPILE_WITH_OGLES2_
+ IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
#endif
- #if defined(_IRR_COMPILE_WITH_WEBGL1_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)
- IVideoDriver* createWebGL1Driver(const irr::SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
+ #ifdef _IRR_COMPILE_WITH_WEBGL1_
+ IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
#endif
} // end namespace video
@@ -461,7 +459,8 @@ void CIrrDeviceSDL::createDriver()
case video::EDT_OPENGL:
#ifdef _IRR_COMPILE_WITH_OPENGL_
- VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this);
+ ContextManager = new video::CSDLManager(this);
+ VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager);
#else
os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
#endif
diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt
index 21e9977..d63361d 100644
--- a/source/Irrlicht/CMakeLists.txt
+++ b/source/Irrlicht/CMakeLists.txt
@@ -188,6 +188,7 @@ set(IRRDRVROBJ
CGLXManager.cpp
CWGLManager.cpp
CEGLManager.cpp
+ CSDLManager.cpp
mt_opengl_loader.cpp
)
diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp
index c03ac34..8883a3e 100644
--- a/source/Irrlicht/COpenGLDriver.cpp
+++ b/source/Irrlicht/COpenGLDriver.cpp
@@ -20,10 +20,6 @@
#include "mt_opengl.h"
-#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
-#include "CIrrDeviceSDL.h"
-#endif
-
namespace irr
{
namespace video
@@ -32,7 +28,6 @@ namespace video
// Statics variables
const u16 COpenGLDriver::Quad2DIndices[4] = { 0, 1, 2, 3 };
-#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
: CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), CacheHandler(0), CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
Transformation3DChanged(true), AntiAlias(params.AntiAlias), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE), Params(params),
@@ -42,23 +37,6 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFil
setDebugName("COpenGLDriver");
#endif
}
-#endif
-
-#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
-COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL* device)
- : CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(), CacheHandler(0),
- CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true),
- AntiAlias(params.AntiAlias), ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE),
- Params(params), SDLDevice(device), ContextManager(0)
-{
-#ifdef _DEBUG
- setDebugName("COpenGLDriver");
-#endif
-
- genericDriverInit();
-}
-
-#endif
bool COpenGLDriver::initDriver()
{
@@ -267,11 +245,6 @@ bool COpenGLDriver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth,
if (ContextManager)
ContextManager->activateContext(videoData, true);
-#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
- if (SDLDevice)
- glFrontFace(GL_CW);
-#endif
-
clearBuffers(clearFlag, clearColor, clearDepth, clearStencil);
return true;
@@ -288,14 +261,6 @@ bool COpenGLDriver::endScene()
if (ContextManager)
status = ContextManager->swapBuffers();
-#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
- if (SDLDevice)
- {
- SDLDevice->SwapWindow();
- status = true;
- }
-#endif
-
// todo: console device present
return status;
@@ -4437,7 +4402,6 @@ namespace irr
namespace video
{
-#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
{
#ifdef _IRR_COMPILE_WITH_OPENGL_
@@ -4454,22 +4418,6 @@ namespace video
return 0;
#endif
}
-#endif
-
-// -----------------------------------
-// SDL VERSION
-// -----------------------------------
-#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
-IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
- io::IFileSystem* io, CIrrDeviceSDL* device)
-{
-#ifdef _IRR_COMPILE_WITH_OPENGL_
- return new COpenGLDriver(params, io, device);
-#else
- return 0;
-#endif // _IRR_COMPILE_WITH_OPENGL_
-}
-#endif // _IRR_COMPILE_WITH_SDL_DEVICE_
} // end namespace
} // end namespace
diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h
index 281605f..a82f683 100644
--- a/source/Irrlicht/COpenGLDriver.h
+++ b/source/Irrlicht/COpenGLDriver.h
@@ -44,13 +44,7 @@ namespace video
EOFPS_DISABLE_TO_ENABLE // switch from programmable to fixed pipeline.
};
-#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
-#endif
-
-#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
- COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL* device);
-#endif
bool initDriver();
@@ -520,10 +514,6 @@ namespace video
S3DVertex Quad2DVertices[4];
static const u16 Quad2DIndices[4];
- #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
- CIrrDeviceSDL *SDLDevice;
- #endif
-
IContextManager* ContextManager;
};
diff --git a/source/Irrlicht/CSDLManager.cpp b/source/Irrlicht/CSDLManager.cpp
new file mode 100644
index 0000000..3132b60
--- /dev/null
+++ b/source/Irrlicht/CSDLManager.cpp
@@ -0,0 +1,56 @@
+// Copyright (C) 2022 sfan5
+// This file is part of the "Irrlicht Engine".
+// For conditions of distribution and use, see copyright notice in Irrlicht.h
+
+#include "CSDLManager.h"
+
+#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) && defined(_IRR_COMPILE_WITH_OPENGL_)
+
+#include "CIrrDeviceSDL.h"
+#include "COpenGLCommon.h"
+
+namespace irr
+{
+namespace video
+{
+
+CSDLManager::CSDLManager(CIrrDeviceSDL* device) : IContextManager(), SDLDevice(device)
+{
+ #ifdef _DEBUG
+ setDebugName("CSDLManager");
+ #endif
+}
+
+bool CSDLManager::initialize(const SIrrlichtCreationParameters& params, const SExposedVideoData& data)
+{
+ Data = data;
+ return true;
+}
+
+const SExposedVideoData& CSDLManager::getContext() const
+{
+ return Data;
+}
+
+bool CSDLManager::activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero)
+{
+ // unclear if this is still needed:
+ glFrontFace(GL_CW);
+ return true;
+}
+
+void* CSDLManager::getProcAddress(const std::string &procName)
+{
+ return SDL_GL_GetProcAddress(procName.c_str());
+}
+
+bool CSDLManager::swapBuffers()
+{
+ SDLDevice->SwapWindow();
+ return true;
+}
+
+}
+}
+
+#endif
diff --git a/source/Irrlicht/CSDLManager.h b/source/Irrlicht/CSDLManager.h
new file mode 100644
index 0000000..e3ca3d0
--- /dev/null
+++ b/source/Irrlicht/CSDLManager.h
@@ -0,0 +1,53 @@
+// Copyright (C) 2022 sfan5
+// This file is part of the "Irrlicht Engine".
+// For conditions of distribution and use, see copyright notice in Irrlicht.h
+
+#ifndef __C_SDL_MANAGER_H_INCLUDED__
+#define __C_SDL_MANAGER_H_INCLUDED__
+
+#include "IrrCompileConfig.h"
+
+#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) && defined(_IRR_COMPILE_WITH_OPENGL_)
+
+#include "IContextManager.h"
+
+namespace irr
+{
+ class CIrrDeviceSDL;
+
+namespace video
+{
+
+ // Manager for SDL with OpenGL
+ class CSDLManager : public IContextManager
+ {
+ public:
+ CSDLManager(CIrrDeviceSDL* device);
+
+ virtual ~CSDLManager() {}
+
+ virtual bool initialize(const SIrrlichtCreationParameters& params, const SExposedVideoData& data) _IRR_OVERRIDE_;
+
+ virtual void terminate() _IRR_OVERRIDE_ {};
+ virtual bool generateSurface() _IRR_OVERRIDE_ { return true; };
+ virtual void destroySurface() _IRR_OVERRIDE_ {};
+ virtual bool generateContext() _IRR_OVERRIDE_ { return true; };
+ virtual void destroyContext() _IRR_OVERRIDE_ {};
+
+ virtual const SExposedVideoData& getContext() const _IRR_OVERRIDE_;
+
+ virtual bool activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero=false) _IRR_OVERRIDE_;
+
+ virtual void* getProcAddress(const std::string &procName) _IRR_OVERRIDE_;
+
+ virtual bool swapBuffers() _IRR_OVERRIDE_;
+
+ private:
+ SExposedVideoData Data;
+ CIrrDeviceSDL *SDLDevice;
+ };
+}
+}
+
+#endif
+#endif