How do i integrate ogre-next into qt when using vulkan backend

Problems building or running the engine, queries about how to use features etc.
Post Reply
maz_1
Gnoblar
Posts: 7
Joined: Tue Aug 24, 2021 7:52 am

How do i integrate ogre-next into qt when using vulkan backend

Post by maz_1 »

Ogre Version: ogre-next master branch :?:
Operating System: Archlinux :?:
Render System: Vulkan :?:

The following code works for qt5 and gl3plus backend

Code: Select all

    Ogre::String winHandle;
    #ifdef WIN32
    winHandle += Ogre::StringConverter::toString((unsigned long)(winId()));
    #else
    winHandle  = Ogre::StringConverter::toString((unsigned long)(QX11Info::display()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned int)(QX11Info::appScreen()));
    winHandle += ":";
    winHandle += Ogre::StringConverter::toString((unsigned long)(winId()));
    #endif
    std::cout << "winHandle: " << winHandle << std::endl;
    misc["parentWindowHandle"] = winHandle;

    //When using the GL3+ renderer, by default the RenderWindow creation create a GL Context.
    //Ogre expect to use only one GL Context, so subsequent window need to use the context of the 1st one.
    if(Ogre::Root::getSingleton().getRenderSystem()->getName() == "OpenGL 3+ Rendering Subsystem")
    {
            //At this point, everything will go bad if this window don't use the same GL context
            misc["externalGLContext"] = std::to_string(size_t(wglGetCurrentContext()));
    }
But when I switch to vulkan backend, two windows are created. What should I do?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5292
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: How do i integrate ogre-next into qt when using vulkan backend

Post by dark_sylinc »

Honestly... I don't know.

I haven't researched that bit yet, so I don't know.

For starters I'd believe there would be two ways:
  1. Let Qt initialize a QVulkanWindow and ask for the instance and send it to Ogre (that would be problematic because Qt does the same with OpenGL, but OpenGL works just fine if the application requests newer features; but Vulkan all needed features must be asked on front)
  2. Use a regular QWindow and use OpenGL - Vulkan interoperability to present to OpenGL from Vulkan
And neither of these options have been researched yet. Therefore I can't tell you there's a solution. It hasn't been coded yet. Maybe you're lucky by providing a "SDL2x11" struct to Ogre (which asks for a X11's Display and Window handles, it's not specific to SDL2). If you're lucky that may just work.
maz_1
Gnoblar
Posts: 7
Joined: Tue Aug 24, 2021 7:52 am

Re: How do i integrate ogre-next into qt when using vulkan backend

Post by maz_1 »

OK, I just explorered the source code, seems that vulkan backend only support "externalWindowHandle" parameter on windows. So maybe I will see if "SDL2x11" solves my problem
maz_1
Gnoblar
Posts: 7
Joined: Tue Aug 24, 2021 7:52 am

Re: How do i integrate ogre-next into qt when using vulkan backend

Post by maz_1 »

Thanks, I am able to embed vulkan interface into qwidget with something like this :D :

Code: Select all

...
    struct
    {
        Display *display;           /**< The X11 display */
        unsigned long window;              /**< The X11 window */
    } x11;
...
    x11.display = QX11Info::display();
    x11.window = (unsigned long)(winId());
    misc["SDL2x11"] = Ogre::StringConverter::toString( (uintptr_t)&x11 );
However the render area does not expand when I resize the window
I already wrote

Code: Select all

Window->requestResolution(width(), height());
Window->windowMovedOrResized();


in resizeEvent and this bug does not occur with opengl backend

Image
Last edited by maz_1 on Mon Aug 30, 2021 1:25 pm, edited 1 time in total.
maz_1
Gnoblar
Posts: 7
Joined: Tue Aug 24, 2021 7:52 am

Re: How do i integrate ogre-next into qt when using vulkan backend

Post by maz_1 »

By the way, this is what prints in terminal when I resize the window:

Code: Select all

...
Trying presentMode = IMMEDIATE_KHR
Chosen presentMode = IMMEDIATE_KHR
surfaceCaps.currentTransform = 1
Trying presentMode = IMMEDIATE_KHR
Chosen presentMode = IMMEDIATE_KHR
surfaceCaps.currentTransform = 1
Trying presentMode = IMMEDIATE_KHR
Chosen presentMode = IMMEDIATE_KHR
...
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5292
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: How do i integrate ogre-next into qt when using vulkan backend

Post by dark_sylinc »

Wait, it worked!?!?!?

I'm shocked :shock:

As for your new issue (resizing problem), windowMovedOrResized just reads the resolution from X11. It must be reading the old version I suppose.

It's possible the windowMovedOrResized call must happen later.

Alternatively it might get solved by adding a "xcb_flush( mConnection );" call at the beginning:

Code: Select all

void VulkanXcbWindow::windowMovedOrResized( void )
{
    if( mClosed || !mXcbWindow )
        return;
    
    xcb_flush( mConnection ); // <-- Here

    xcb_get_geometry_cookie_t geomCookie = xcb_get_geometry( mConnection, mXcbWindow );
    xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply( mConnection, geomCookie, NULL );
See if that solves it. Otherwise I'll have to ask you to step into with the debugger and ask you to post the contents of "geom" variable which is where the resolution is stored.

If geom contains the old resolution, then it's likely the windowMovedOrResized call must happen later and thus you're calling it too early yet.
maz_1
Gnoblar
Posts: 7
Joined: Tue Aug 24, 2021 7:52 am

Re: How do i integrate ogre-next into qt when using vulkan backend

Post by maz_1 »

Code: Select all

xcb_flush( mConnection );
does not work

Instead of debugger I add some lines to print the resoltion, this is what I get when I resize the window a bit (the original size is 640 x 480):

Code: Select all

GET RESOLUTION: 640, 481 			# <- value of geom->width and geom->height in VulkanXcbWindow::windowMovedOrResized
Trying presentMode = IMMEDIATE_KHR
Chosen presentMode = IMMEDIATE_KHR
surfaceCaps.currentTransform = 1
Widget geom: 640, 481				# <- value of widget->width() and widget->height() 
maz_1
Gnoblar
Posts: 7
Joined: Tue Aug 24, 2021 7:52 am

Re: How do i integrate ogre-next into qt when using vulkan backend

Post by maz_1 »

Today I compiled my demo under windows and ran into the same bug:


Image


So it's not a problem specific to X11 I think...
zxz
Gremlin
Posts: 184
Joined: Sat Apr 16, 2016 9:25 pm
x 19

Re: How do i integrate ogre-next into qt when using vulkan backend

Post by zxz »

For reference, I've tried this method with a recent master build of ogre-next, and it appears to be working fine now. Resizing and all.

Post Reply