Skip to content

Commit

Permalink
GLSupport: EGL - provide PBuffer based Window for transparent fallback
Browse files Browse the repository at this point in the history
if X11 is not available
  • Loading branch information
paroj committed Feb 2, 2021
1 parent 9046fe4 commit b2e9598
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 68 deletions.
Expand Up @@ -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);
Expand Down
Expand Up @@ -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);
Expand Down
15 changes: 10 additions & 5 deletions RenderSystems/GLSupport/include/EGL/OgreEGLWindow.h
Expand Up @@ -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);
Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -57,10 +57,6 @@ namespace Ogre {
{
}

void AndroidEGLWindow::reposition( int left, int top )
{
}

void AndroidEGLWindow::resize(uint width, uint height)
{
width *= mScale;
Expand Down Expand Up @@ -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)
{
Expand Down
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/GLSupport/src/EGL/OgreEGLSupport.cpp
Expand Up @@ -44,7 +44,7 @@ namespace Ogre {

EGLSupport::EGLSupport(int profile)
: GLNativeSupport(profile), mGLDisplay(0),
mNativeDisplay(0)
mNativeDisplay(EGL_DEFAULT_DISPLAY)
{
}

Expand Down
76 changes: 75 additions & 1 deletion RenderSystems/GLSupport/src/EGL/OgreEGLWindow.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
}
22 changes: 1 addition & 21 deletions RenderSystems/GLSupport/src/EGL/WIN32/OgreWin32EGLWindow.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}

}
23 changes: 16 additions & 7 deletions RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLSupport.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 1 addition & 15 deletions RenderSystems/GLSupport/src/EGL/X11/OgreX11EGLWindow.cpp
Expand Up @@ -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();
}

}
Expand Down

0 comments on commit b2e9598

Please sign in to comment.