[2.1] PsoCacheHelper Usage Questions (porting imgui)

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
Herb
Orc
Posts: 412
Joined: Thu Jun 04, 2009 3:21 am
Location: Kalamazoo,MI
x 38

[2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Herb »

Ok, I'm working on a new app with 2.1 and trying to use imgui for the GUI.

I found a nice person who ported the code to an earlier version of 2.1
https://bitbucket.org/ChaosCreator/imgu ... .1-binding

However, the 2.1 API has changed. I found dark_sylinc has made a helper class for this called PsoCacheHelper with some comments in there for usage, this was geared for Gorilla but imgui should be able to use it being an immediate gui.

So, referencing code in the above repo with the old 2.1 API, there's a class called ImguiManager where the tweaks are needed. I added a PsoCacheHelper to the class.

In Imgui::render, is where the fixes are needed.

Link to raw ImguiManager.cpp file HERE

This

Code: Select all

	const Ogre::HlmsBlendblock *blendblock = mPass->getBlendblock();
	const Ogre::HlmsMacroblock *macroblock = mPass->getMacroblock();
	mSceneMgr->getDestinationRenderSystem()->_setHlmsBlendblock(blendblock);
	mSceneMgr->getDestinationRenderSystem()->_setHlmsMacroblock(macroblock);
Changed to:

Code: Select all

    const Ogre::HlmsBlendblock *blendblock = mPass->getBlendblock();
    const Ogre::HlmsMacroblock *macroblock = mPass->getMacroblock();
    //mSceneMgr->getDestinationRenderSystem()->_setHlmsBlendblock(blendblock);
    //mSceneMgr->getDestinationRenderSystem()->_setHlmsMacroblock(macroblock);

    mPSOCache->clearState();
    /// @todo What do I put here????
    mPSOCache->setRenderTarget(?);

    mPSOCache->setMacroblock(macroblock);
    mPSOCache->setBlendblock(blendblock);
This makes sense, but I'm not sure what to put into the render target.... Anybody know?

This:

Code: Select all

			//render the object
			mSceneMgr->_injectRenderWithPass(mPass, mRenderables[i], 0, false, false);
Changed to:

Code: Select all

			//render the object
            //mSceneMgr->_injectRenderWithPass(mPass, mRenderables[i], 0, false, false);

            // xtitus - changes for 2.1 rendering with PSO
            Ogre::v1::RenderOperation renderOp;
            mRenderables[i]->getRenderOperation(renderOp, false);

            bool enablePrimitiveRestart = true;  // is this right???


            Ogre::VertexElement2VecVec vertexElements = renderOp.vertexData->
                    vertexDeclaration->convertToV2();
            mPSOCache->setVertexFormat( vertexElements,
                                      renderOp.operationType,
                                      enablePrimitiveRestart );

            Ogre::HlmsPso *pso = mPSOCache->getPso();
            mSceneMgr->getDestinationRenderSystem()->_setPipelineStateObject( pso );
I think this part looks like I'm on the right track, but wasn't sure on the "enablePrimitiveRestart"... Thoughts?

Thanks in advance for any help on this as I'm newer to using Ogre 2.1, been using Ogre 1.9 and lower for years... :)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by dark_sylinc »

Hi!

Regarding setRenderTarget, that goes the RenderTarget you're currently rendering to (could be the RenderWindow, a RenderTexture from the compositor, etc).
Since rendering is done inside a compositor, this information is in CompositorPass::mTarget. I don't know how IMGUI is interfaced with Ogre. If a custom compositor pass is used, then accessing that info should already be easy. If not, then sceneManager->getCurrentViewport()->getTarget() may have that info.

Code: Select all

I think this part looks like I'm on the right track, but wasn't sure on the "enablePrimitiveRestart"... Thoughts?
Primitive restart is used for rendering triangle strips. If IMGUI doesn't use tri strips, then this setting is not relevant. If IMGUI does use tri strip; if it doesn't need prim restart; then setting this value to true will very rarely produce rendering errors. If you set it to false and IMGUI does rely on it, then it will be easy to spot it (lots of glitches will be visible). To sumarize:
  • IMGUI needs it. enablePrimitiveRestart = true -> Correct render
  • IMGUI doesn't need it. enablePrimitiveRestart = true -> Most likely always correct, but could be ocassional glitch
  • IMGUI needs it. enablePrimitiveRestart = false -> Extreme glitches. Impossible not to notice.
  • IMGUI doesn't need it. enablePrimitiveRestart = false -> Correct render
My suggestion is leave it as false. If you see extreme corruption then you likely need it to be true.

Cheers
User avatar
Herb
Orc
Posts: 412
Joined: Thu Jun 04, 2009 3:21 am
Location: Kalamazoo,MI
x 38

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Herb »

Ah, ok. That really helps explain on the rendertarget. Should be easy enough. I'll make the changes and see how it's working. Thanks dark_sylinc! :D
User avatar
Herb
Orc
Posts: 412
Joined: Thu Jun 04, 2009 3:21 am
Location: Kalamazoo,MI
x 38

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Herb »

Finally got a chunk of time to work on dark_sylinc's advice, but having no luck....not sure on how really to debug this further... Anyone have any luck with the PsoCacheHelper class? I know dark_sylinc said it was not tested. :wink:

So, I init the ImGUIManager class doing:

Code: Select all

mPSOCache = new Ogre::PsoCacheHelper(Ogre::Root::getSingletonPtr()->getRenderSystem());
Then in the render I had to make a couple of changes... First see below with the commented out code what was in there before.

Code: Select all

    const Ogre::HlmsBlendblock *blendblock = mPass->getBlendblock();
    const Ogre::HlmsMacroblock *macroblock = mPass->getMacroblock();
    //mSceneMgr->getDestinationRenderSystem()->_setHlmsBlendblock(blendblock);
    //mSceneMgr->getDestinationRenderSystem()->_setHlmsMacroblock(macroblock);

    mPSOCache->clearState();
    mPSOCache->setRenderTarget(vp->getTarget());   // dark_sylinc's advice on setting rendertarget, which looks like the renderwindow obj)

    mPSOCache->setMacroblock(macroblock);
    mPSOCache->setBlendblock(blendblock);
Then I need to loop through all the Ogre::Renderables to draw. So for each object to render here's the main snippet.

Code: Select all

	    //render the object
            
            // this is no longer available in newer 2.1 API
            //mSceneMgr->_injectRenderWithPass(mPass, mRenderables[i], 0, false, false);

            // xtitus - changes for 2.1 rendering with PSO
            Ogre::v1::RenderOperation renderOp;
            mRenderables[i]->getRenderOperation(renderOp, false);

            bool enablePrimitiveRestart = true;  // tried both true and false...no change

            Ogre::VertexElement2VecVec vertexElements = renderOp.vertexData->
                    vertexDeclaration->convertToV2();
            mPSOCache->setVertexFormat( vertexElements,
                                      renderOp.operationType,
                                      enablePrimitiveRestart );

            Ogre::HlmsPso *pso = mPSOCache->getPso();
            mSceneMgr->getDestinationRenderSystem()->_setPipelineStateObject( pso );
Does anything look wrong in this? Thoughts @dark_sylinc? Just don't get anything on the screen, so not sure where to poke at next. Also coming up on 2.1 as most of years of ogre have been in the 1.7-1.9 version. Thanks!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by dark_sylinc »

At no point I see you're actually issuing a rendering command.
You're never calling RenderSystem::_render(const v1::RenderOperation& op), thus nothing will be drawn. You're basically loading a truck with all the things you need to send to destination, ensure the gas tank is full, but never actually dispatching the truck driver to perform the trip.
User avatar
Herb
Orc
Posts: 412
Joined: Thu Jun 04, 2009 3:21 am
Location: Kalamazoo,MI
x 38

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Herb »

Yeah, I was wondering how the render happened... I didn't see any render call in your code comments in OgrePsoCacheHelper header so had the impression it was being called differently. Ok, so I added that to the very end.

So, every IMGUI renderable gets rendered with:

Code: Select all

mSceneMgr->getDestinationRenderSystem()->_render(renderOp);
I still don't have anything rendering to the screen... :cry: I'll keep digging. It's sounding like something really small.
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Jay721 »

Did you get this working? I’m looking into getting ImGui on ogre too.
User avatar
Herb
Orc
Posts: 412
Joined: Thu Jun 04, 2009 3:21 am
Location: Kalamazoo,MI
x 38

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Herb »

No, I didn’t.... I made the suggested changes and i’ve looked through the debugger at all the objects and everything looks good, but nothing is displayed on the screen... i’ve paused on it for the moment until I can think of something else to try.
Scalu
Gnoblar
Posts: 2
Joined: Wed Mar 14, 2018 10:11 pm

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Scalu »

Hi,

I was hoping to use imgui with 2.1 as well, but it seems that this latest attempt to get it working with the latest code stalled. I might give it a try, but being a Ogre newb, I don't imagine I will make any headway. If someone has managed to get it rendering since the last post, please let me know. I might check some other gui libs if they are reported to be working with 2.1. Thanks!
Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 614
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 25

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Slicky »

I took a stab at this using 2.1 and did not have success. I do get some random rendering that flickers in different parts of the screen and once in a while I see some text rendered what looks like at 90 degrees but it flickers on and off. I also just get random lines.

Hardly a success and all I can go on is reading other forum posts.

I am using the psocachelper class.

Has anyone got any GUI type implementation to work using this class? I think it might be a common solution but I see zero people with a working version.
User avatar
Aiden
Halfling
Posts: 54
Joined: Fri Jul 14, 2017 3:16 pm
x 5

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Aiden »

I've managed to fix ogre-ffmpeg player to work, I also created ogre-assimp adaptor which somebody ported to 2.1. Had to downgrade abit to 1.11 so I could use IMGUI.
What is the current progress on getting IMGUI to work n ogre 2.1 ?
I might give it a try, maybe I might get as lucky as I was on the other ogre plugin projects. After all, I only need some good time messing around with it and learning more about the ogre rendering api.
If anyone has some code that almost works, It might be useful right now.
Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 614
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 25

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Slicky »

Some people have ImGui working with 2.1.

I haven't seen a complete solution posted. I was able to get some flickering using psocachelper but nothing recognisable.
Sweenie
Silver Sponsor
Silver Sponsor
Posts: 92
Joined: Wed Mar 23, 2005 3:29 pm
Location: Sweden
x 1

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Sweenie »

Hi.

I've been trying to get this working lately and got a bit further.
First I noticed using RenderDoc that the ProjectionMatrix uniform wasn't set but found another post there dark_sylinc mentioned that the following call was needed.

Code: Select all

mSceneMgr->getDestinationRenderSystem()->bindGpuProgramParameters(Ogre::GPT_VERTEX_PROGRAM, mPass->getVertexProgramParameters(), Ogre::GPV_ALL);
Now I actually get the ImGui window to display but the font texture is messed up.

The font texture is created like this, the same way as in the code at the start of this thread.

Code: Select all

mFontTex = Ogre::TextureManager::getSingleton().createManual("ImguiFontTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, 1, 1, Ogre::PF_R8G8B8A8);
The texture generated by ImGui is 512x64 in size and has the format R8G8B8A8

But when I use RenderDoc to preview the texture, Renderdoc is showing that the texture is 512x512 and has the format R8G8_UNORM
The texture should be black with white characters but in RenderDoc it's red with yellow characters.

What could cause the texture to have the wrong format on the GPU side?

This is with OpenGL. Have tried with DX11 but the vertexbuffer seems messed up when using DX11, the indexbuffer seems ok. But i'm focusing on OpenGL first.

Image
Sweenie
Silver Sponsor
Silver Sponsor
Posts: 92
Joined: Wed Mar 23, 2005 3:29 pm
Location: Sweden
x 1

Re: [2.1] PsoCacheHelper Usage Questions (porting imgui)

Post by Sweenie »

Ah, I'm an idiot.

The texture hasn't changed format, it's simply not the ImGui texture used for the drawcall but Ogre's own font texture.
The ImGui texture doesn't show up at all in renderdoc, not sure why but I suspect I have to make my draw calls to use the right texture.

[EDIT]

Yay!
Added this line

Code: Select all

mSceneMgr->getDestinationRenderSystem()->_setTexture(0, true, "ImguiFontTex" );
and now it looks like it should. :D

Image
Post Reply