mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-18 05:33:52 +01:00
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
This commit is contained in:
parent
0732807cc8
commit
593103a261
@ -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
|
||||
|
@ -188,6 +188,7 @@ set(IRRDRVROBJ
|
||||
CGLXManager.cpp
|
||||
CWGLManager.cpp
|
||||
CEGLManager.cpp
|
||||
CSDLManager.cpp
|
||||
mt_opengl_loader.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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
56
source/Irrlicht/CSDLManager.cpp
Normal file
56
source/Irrlicht/CSDLManager.cpp
Normal file
@ -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
|
53
source/Irrlicht/CSDLManager.h
Normal file
53
source/Irrlicht/CSDLManager.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user