From b2e959880547f0bd7b92b941ba6f43aed01cc4f3 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Tue, 2 Feb 2021 00:37:49 +0100 Subject: [PATCH] GLSupport: EGL - provide PBuffer based Window for transparent fallback if X11 is not available --- .../EGL/Android/OgreAndroidEGLWindow.h | 2 - .../EGL/Emscripten/OgreEmscriptenEGLWindow.h | 1 - .../GLSupport/include/EGL/OgreEGLWindow.h | 15 ++-- .../include/EGL/WIN32/OgreWin32EGLWindow.h | 2 - .../src/EGL/Android/OgreAndroidEGLWindow.cpp | 9 --- .../Emscripten/OgreEmscriptenEGLWindow.cpp | 4 - .../GLSupport/src/EGL/OgreEGLSupport.cpp | 2 +- .../GLSupport/src/EGL/OgreEGLWindow.cpp | 76 ++++++++++++++++++- .../src/EGL/WIN32/OgreWin32EGLWindow.cpp | 22 +----- .../src/EGL/X11/OgreX11EGLSupport.cpp | 23 ++++-- .../src/EGL/X11/OgreX11EGLWindow.cpp | 16 +--- 11 files changed, 104 insertions(+), 68 deletions(-) diff --git a/RenderSystems/GLSupport/include/EGL/Android/OgreAndroidEGLWindow.h b/RenderSystems/GLSupport/include/EGL/Android/OgreAndroidEGLWindow.h index 2e754de0ad4..88f13d30578 100644 --- a/RenderSystems/GLSupport/include/EGL/Android/OgreAndroidEGLWindow.h +++ b/RenderSystems/GLSupport/include/EGL/Android/OgreAndroidEGLWindow.h @@ -55,10 +55,8 @@ namespace Ogre { float mScale; protected: - virtual void reposition(int left, int top); virtual void resize(unsigned int width, unsigned int height); virtual void windowMovedOrResized(); - virtual void switchFullScreen(bool fullscreen); public: AndroidEGLWindow(AndroidEGLSupport* glsupport); diff --git a/RenderSystems/GLSupport/include/EGL/Emscripten/OgreEmscriptenEGLWindow.h b/RenderSystems/GLSupport/include/EGL/Emscripten/OgreEmscriptenEGLWindow.h index a0ca5ab34b6..e004b36fbc7 100644 --- a/RenderSystems/GLSupport/include/EGL/Emscripten/OgreEmscriptenEGLWindow.h +++ b/RenderSystems/GLSupport/include/EGL/Emscripten/OgreEmscriptenEGLWindow.h @@ -57,7 +57,6 @@ namespace Ogre { String mCanvasSelector; protected: - virtual void reposition(int left, int top); virtual void resize(unsigned int width, unsigned int height); virtual void windowMovedOrResized(); virtual void switchFullScreen(bool fullscreen); diff --git a/RenderSystems/GLSupport/include/EGL/OgreEGLWindow.h b/RenderSystems/GLSupport/include/EGL/OgreEGLWindow.h index ee9ed66c9dd..3cb44420bcf 100644 --- a/RenderSystems/GLSupport/include/EGL/OgreEGLWindow.h +++ b/RenderSystems/GLSupport/include/EGL/OgreEGLWindow.h @@ -50,19 +50,24 @@ namespace Ogre { ::EGLSurface createSurfaceFromWindow(::EGLDisplay display, NativeWindowType win); - virtual void switchFullScreen(bool fullscreen) = 0; + virtual void switchFullScreen(bool fullscreen) {} EGLContext * createEGLContext(::EGLContext external = NULL) const { return new EGLContext(mEglDisplay, mGLSupport, mEglConfig, mEglSurface, external); } - virtual void windowMovedOrResized() = 0; + virtual void windowMovedOrResized() {} + + void finaliseWindow(); public: EGLWindow(EGLSupport* glsupport); virtual ~EGLWindow(); -// Moved create to native source because it has native calls in it. -// void create(const String& name, unsigned int width, unsigned int height, -// bool fullScreen, const NameValuePairList *miscParams); + // default, PBuffer based, implementation + void create(const String& name, unsigned int width, unsigned int height, bool fullScreen, + const NameValuePairList* miscParams); + + void reposition(int left, int top) {} + void resize(unsigned int width, unsigned int height) {} virtual void setFullscreen (bool fullscreen, uint width, uint height); void destroy(void); diff --git a/RenderSystems/GLSupport/include/EGL/WIN32/OgreWin32EGLWindow.h b/RenderSystems/GLSupport/include/EGL/WIN32/OgreWin32EGLWindow.h index 99f0226419c..f877764abd2 100644 --- a/RenderSystems/GLSupport/include/EGL/WIN32/OgreWin32EGLWindow.h +++ b/RenderSystems/GLSupport/include/EGL/WIN32/OgreWin32EGLWindow.h @@ -38,10 +38,8 @@ namespace Ogre { { protected: void createNativeWindow( int &left, int &top, uint &width, uint &height, String &title ); - virtual void reposition(int left, int top); virtual void resize(unsigned int width, unsigned int height); virtual void windowMovedOrResized(); - virtual void switchFullScreen(bool fullscreen); public: Win32EGLWindow(Win32EGLSupport* glsupport); diff --git a/RenderSystems/GLSupport/src/EGL/Android/OgreAndroidEGLWindow.cpp b/RenderSystems/GLSupport/src/EGL/Android/OgreAndroidEGLWindow.cpp index 63c49d39d67..b96cbe03615 100644 --- a/RenderSystems/GLSupport/src/EGL/Android/OgreAndroidEGLWindow.cpp +++ b/RenderSystems/GLSupport/src/EGL/Android/OgreAndroidEGLWindow.cpp @@ -57,10 +57,6 @@ namespace Ogre { { } - void AndroidEGLWindow::reposition( int left, int top ) - { - } - void AndroidEGLWindow::resize(uint width, uint height) { width *= mScale; @@ -102,11 +98,6 @@ namespace Ogre { } } - void AndroidEGLWindow::switchFullScreen(bool fullscreen) - { - - } - void AndroidEGLWindow::create(const String& name, uint width, uint height, bool fullScreen, const NameValuePairList *miscParams) { diff --git a/RenderSystems/GLSupport/src/EGL/Emscripten/OgreEmscriptenEGLWindow.cpp b/RenderSystems/GLSupport/src/EGL/Emscripten/OgreEmscriptenEGLWindow.cpp index d0470ea3da6..38995e255a8 100644 --- a/RenderSystems/GLSupport/src/EGL/Emscripten/OgreEmscriptenEGLWindow.cpp +++ b/RenderSystems/GLSupport/src/EGL/Emscripten/OgreEmscriptenEGLWindow.cpp @@ -66,10 +66,6 @@ namespace Ogre { emscripten_set_webglcontextrestored_callback("#canvas", NULL, 0, NULL); } - void EmscriptenEGLWindow::reposition( int left, int top ) - { - } - void EmscriptenEGLWindow::resize(uint width, uint height) { mWidth = width; diff --git a/RenderSystems/GLSupport/src/EGL/OgreEGLSupport.cpp b/RenderSystems/GLSupport/src/EGL/OgreEGLSupport.cpp index fd22e94c9ec..bfe5565207b 100755 --- a/RenderSystems/GLSupport/src/EGL/OgreEGLSupport.cpp +++ b/RenderSystems/GLSupport/src/EGL/OgreEGLSupport.cpp @@ -44,7 +44,7 @@ namespace Ogre { EGLSupport::EGLSupport(int profile) : GLNativeSupport(profile), mGLDisplay(0), - mNativeDisplay(0) + mNativeDisplay(EGL_DEFAULT_DISPLAY) { } diff --git a/RenderSystems/GLSupport/src/EGL/OgreEGLWindow.cpp b/RenderSystems/GLSupport/src/EGL/OgreEGLWindow.cpp index 4b255e90355..c170954c0c9 100644 --- a/RenderSystems/GLSupport/src/EGL/OgreEGLWindow.cpp +++ b/RenderSystems/GLSupport/src/EGL/OgreEGLWindow.cpp @@ -42,7 +42,7 @@ namespace Ogre { EGLWindow::EGLWindow(EGLSupport *glsupport) : GLWindow(), mGLSupport(glsupport), mWindow(0), - mNativeDisplay(0), + mNativeDisplay(EGL_DEFAULT_DISPLAY), mEglDisplay(EGL_NO_DISPLAY), mEglConfig(0), mEglSurface(0) @@ -156,6 +156,60 @@ namespace Ogre { return mGLSupport->getContextProfile() == GLNativeSupport::CONTEXT_ES ? PF_BYTE_RGBA : PF_BYTE_RGB; } + void EGLWindow::create(const String& name, unsigned int width, unsigned int height, bool fullScreen, + const NameValuePairList* miscParams) + { + int samples = 0; + + if (miscParams) + { + NameValuePairList::const_iterator opt; + if ((opt = miscParams->find("FSAA")) != miscParams->end()) + { + samples = StringConverter::parseUnsignedInt(opt->second); + } + } + + int minAttribs[] = { + EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, + EGL_BLUE_SIZE, 5, + EGL_GREEN_SIZE, 6, + EGL_RED_SIZE, 5, + EGL_DEPTH_SIZE, 16, + EGL_NONE + }; + + int maxAttribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_DEPTH_SIZE, 24, + EGL_ALPHA_SIZE, 8, + EGL_STENCIL_SIZE, 8, + EGL_SAMPLE_BUFFERS, 1, + EGL_SAMPLES, samples, + EGL_NONE + }; + + mEglConfig = mGLSupport->selectGLConfig(minAttribs, maxAttribs); + mEglDisplay = mGLSupport->getGLDisplay(); + + int pbufferAttribs[] = { + EGL_WIDTH, int(width), + EGL_HEIGHT, int(height), + EGL_NONE, + }; + + mEglSurface = eglCreatePbufferSurface(mEglDisplay, mEglConfig, pbufferAttribs); + mContext = createEGLContext(NULL); + mIsExternalGLControl = true; // dont want swapBuffers + mName = name; + mWidth = width; + mHeight = height; + + finaliseWindow(); + } + ::EGLSurface EGLWindow::createSurfaceFromWindow(::EGLDisplay display, NativeWindowType win) { @@ -204,4 +258,24 @@ namespace Ogre { eglMakeCurrent (dpy, oldDraw, oldRead, oldContext); EGL_CHECK_ERROR } + + void EGLWindow::finaliseWindow() + { + // query selected config + int Rsz, Gsz, Bsz, Asz, fsaa; + mGLSupport->getGLConfigAttrib(mEglConfig, EGL_RED_SIZE, &Rsz); + mGLSupport->getGLConfigAttrib(mEglConfig, EGL_BLUE_SIZE, &Gsz); + mGLSupport->getGLConfigAttrib(mEglConfig, EGL_GREEN_SIZE, &Bsz); + mGLSupport->getGLConfigAttrib(mEglConfig, EGL_ALPHA_SIZE, &Asz); + mGLSupport->getGLConfigAttrib(mEglConfig, EGL_SAMPLES, &fsaa); + + LogManager::getSingleton().logMessage( + StringUtil::format("EGLWindow: colourBufferSize=%d/%d/%d/%d gamma=%d FSAA=%d", Rsz, Bsz, Gsz, + Asz, mHwGamma, fsaa)); + + mActive = true; + mVisible = true; + mFSAA = fsaa; + mClosed = false; + } } diff --git a/RenderSystems/GLSupport/src/EGL/WIN32/OgreWin32EGLWindow.cpp b/RenderSystems/GLSupport/src/EGL/WIN32/OgreWin32EGLWindow.cpp index 098e3f6c147..2d18d9795c4 100644 --- a/RenderSystems/GLSupport/src/EGL/WIN32/OgreWin32EGLWindow.cpp +++ b/RenderSystems/GLSupport/src/EGL/WIN32/OgreWin32EGLWindow.cpp @@ -258,11 +258,6 @@ namespace Ogre { mEglSurface = createSurfaceFromWindow(mEglDisplay, mWindow); - } - - void Win32EGLWindow::reposition( int left, int top ) - { - } void Win32EGLWindow::resize( unsigned int width, unsigned int height ) @@ -318,11 +313,6 @@ namespace Ogre { resize(width, height); } - void Win32EGLWindow::switchFullScreen( bool fullscreen ) - { - - } - void Win32EGLWindow::create(const String& name, uint width, uint height, bool fullScreen, const NameValuePairList *miscParams) { @@ -461,24 +451,14 @@ namespace Ogre { mContext = createEGLContext(eglContext); mContext->setCurrent(); - ::EGLSurface oldDrawableDraw = eglGetCurrentSurface(EGL_DRAW); - ::EGLSurface oldDrawableRead = eglGetCurrentSurface(EGL_READ); - ::EGLContext oldContext = eglGetCurrentContext(); - - int glConfigID; - - mGLSupport->getGLConfigAttrib(mEglConfig, EGL_CONFIG_ID, &glConfigID); - LogManager::getSingleton().logMessage("EGLWindow::create used FBConfigID = " + StringConverter::toString(glConfigID)); mName = name; mWidth = width; mHeight = height; mLeft = left; mTop = top; - mActive = true; - mVisible = true; - mClosed = false; + finaliseWindow(); } } diff --git a/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp b/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp index b2b464a9f9f..9f47db4715e 100644 --- a/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp +++ b/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp @@ -55,7 +55,16 @@ namespace Ogre { int dummy; - if (XQueryExtension(mNativeDisplay, "RANDR", &dummy, &dummy, &dummy)) + if(mNativeDisplay == EGL_DEFAULT_DISPLAY) + { + // fake video mode + mCurrentMode.width = 0; + mCurrentMode.height = 0; + mCurrentMode.refreshRate = 0; + mOriginalMode = mCurrentMode; + mVideoModes.push_back(mCurrentMode); + } + else if (XQueryExtension(mNativeDisplay, "RANDR", &dummy, &dummy, &dummy)) { XRRScreenConfiguration *screenConfig; @@ -145,13 +154,12 @@ namespace Ogre { { if (!mNativeDisplay) { - mNativeDisplay = (NativeDisplayType)XOpenDisplay(NULL); + mNativeDisplay = (NativeDisplayType)XOpenDisplay(NULL); - if (!mNativeDisplay) + if (mNativeDisplay == EGL_DEFAULT_DISPLAY) { - OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, - "Couldn`t open X display", - "X11EGLSupport::getXDisplay"); + LogManager::getSingleton().logWarning("Couldn't open X display"); + return mNativeDisplay; } mAtomDeleteWindow = XInternAtom((Display*)mNativeDisplay, "WM_DELETE_WINDOW", True); @@ -252,7 +260,8 @@ namespace Ogre { bool fullScreen, const NameValuePairList *miscParams) { - EGLWindow* window = new X11EGLWindow(this); + EGLWindow* window = + mNativeDisplay == EGL_DEFAULT_DISPLAY ? new EGLWindow(this) : new X11EGLWindow(this); window->create(name, width, height, fullScreen, miscParams); return window; diff --git a/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLWindow.cpp b/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLWindow.cpp index 5e4279f80aa..adf394225db 100644 --- a/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLWindow.cpp +++ b/RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLWindow.cpp @@ -559,27 +559,13 @@ namespace Ogre { setVSyncInterval(vsyncInterval); setVSyncEnabled(vsync); - int Rsz, Gsz, Bsz, Asz, fsaa; - mGLSupport->getGLConfigAttrib(mEglConfig, EGL_RED_SIZE, &Rsz); - mGLSupport->getGLConfigAttrib(mEglConfig, EGL_BLUE_SIZE, &Gsz); - mGLSupport->getGLConfigAttrib(mEglConfig, EGL_GREEN_SIZE, &Bsz); - mGLSupport->getGLConfigAttrib(mEglConfig, EGL_ALPHA_SIZE, &Asz); - mGLSupport->getGLConfigAttrib(mEglConfig, EGL_SAMPLES, &fsaa); - - LogManager::getSingleton().logMessage( - StringUtil::format("X11EGLWindow::create colourBufferSize=%d/%d/%d/%d gamma=%d FSAA=%d", Rsz, - Bsz, Gsz, Asz, mHwGamma, fsaa)); - mName = name; mWidth = width; mHeight = height; mLeft = left; mTop = top; - mActive = true; - mVisible = true; - mFSAA = fsaa; - mClosed = false; + finaliseWindow(); } }