IContextManager::activateContext can now also be used to reset the context.

The reset was prevented before, likely to make the use in beginScene easier. But it's necessary for using an OGL context from another thread.
Only implemented for WGL so far, GLX implementation will follow soon.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5784 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2019-03-14 16:18:03 +00:00
parent 3f0278bfe2
commit ed6d0d58fc
7 changed files with 29 additions and 8 deletions

View File

@ -1,5 +1,6 @@
--------------------------
Changes in 1.9 (not yet released)
- EditBox now still allows overwriting characters when the text-length is at max.
- Bugfix: CMatrix4::transformPlane was calculating the wrong plane-normal before.
- SViewFrustum::recalculateBoundingBox no longer includes camera position in the bounding-box. Only using frustum corners now. Thx @DevSH for bugreport & patch.
- Camera uses now OGL projection matrices with OpenGL driver. Fixes wrong near-plane values with OpenGL (showed too much before).

View File

@ -12,6 +12,7 @@ namespace irr
{
namespace video
{
// For system specific window contexts (used for OpenGL)
class IContextManager : public virtual IReferenceCounted
{
public:
@ -37,7 +38,15 @@ namespace video
virtual const SExposedVideoData& getContext() const =0;
//! Change render context, disable old and activate new defined by videoData
virtual bool activateContext(const SExposedVideoData& videoData) =0;
//\param restorePrimaryOnZero When true: restore original driver context when videoData is set to 0 values.
// When false: resets the context when videoData is set to 0 values.
/** This is mostly used internally by IVideoDriver::beginScene().
But if you want to switch threads which access your OpenGL driver you will have to
call this function as follows:
Old thread gives up context with: activateContext(irr::video::SExposedVideoData());
New thread takes over context with: activateContext(videoDriver->getExposedVideoData());
Note that only 1 thread at a time may access an OpenGL context. */
virtual bool activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero=false) =0;
//! Swap buffers.
virtual bool swapBuffers() =0;

View File

@ -345,8 +345,10 @@ const SExposedVideoData& CGLXManager::getContext() const
return CurrentContext;
}
bool CGLXManager::activateContext(const SExposedVideoData& videoData)
bool CGLXManager::activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero)
{
//TODO: handle restorePrimaryOnZero
if (videoData.OpenGLLinux.X11Window)
{
if (videoData.OpenGLLinux.X11Display && videoData.OpenGLLinux.X11Context)

View File

@ -55,7 +55,7 @@ namespace video
const SExposedVideoData& getContext() const;
//! Change render context, disable old and activate new defined by videoData
bool activateContext(const SExposedVideoData& videoData);
bool activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero);
// Swap buffers.
bool swapBuffers();

View File

@ -72,7 +72,7 @@ bool COpenGLDriver::initDriver()
ContextManager->generateSurface();
ContextManager->generateContext();
ExposedData = ContextManager->getContext();
ContextManager->activateContext(ExposedData);
ContextManager->activateContext(ExposedData, false);
genericDriverInit();
@ -288,7 +288,7 @@ bool COpenGLDriver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth,
CNullDriver::beginScene(clearFlag, clearColor, clearDepth, clearStencil, videoData, sourceRect);
if (ContextManager)
ContextManager->activateContext(videoData);
ContextManager->activateContext(videoData, true);
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
if ( DeviceType == EIDT_SDL )

View File

@ -179,7 +179,7 @@ bool CWGLManager::initialize(const SIrrlichtCreationParameters& params, const SE
CurrentContext.OpenGLWin32.HRc = hrc;
CurrentContext.OpenGLWin32.HWnd = temporary_wnd;
if (!activateContext(CurrentContext))
if (!activateContext(CurrentContext, false))
{
os::Printer::log("Cannot activate a temporary GL rendering context.", ELL_ERROR);
wglDeleteContext(hrc);
@ -438,7 +438,7 @@ const SExposedVideoData& CWGLManager::getContext() const
return CurrentContext;
}
bool CWGLManager::activateContext(const SExposedVideoData& videoData)
bool CWGLManager::activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero)
{
if (videoData.OpenGLWin32.HWnd && videoData.OpenGLWin32.HDc && videoData.OpenGLWin32.HRc)
{
@ -449,6 +449,15 @@ bool CWGLManager::activateContext(const SExposedVideoData& videoData)
}
CurrentContext=videoData;
}
else if (!restorePrimaryOnZero && !videoData.OpenGLWin32.HDc && !videoData.OpenGLWin32.HRc)
{
if (!wglMakeCurrent((HDC)0, (HGLRC)0))
{
os::Printer::log("Render Context reset failed.");
return false;
}
CurrentContext = videoData;
}
// set back to main context
else if (!videoData.OpenGLWin32.HWnd && CurrentContext.OpenGLWin32.HDc != PrimaryContext.OpenGLWin32.HDc)
{

View File

@ -53,7 +53,7 @@ namespace video
const SExposedVideoData& getContext() const;
//! Change render context, disable old and activate new defined by videoData
bool activateContext(const SExposedVideoData& videoData);
bool activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero);
// Swap buffers.
bool swapBuffers();