1.10 D3D9 - Viewport not clearing/background unset

Problems building or running the engine, queries about how to use features etc.
Post Reply
Stymgade
Gnoblar
Posts: 10
Joined: Sat Jan 04, 2014 8:31 pm

1.10 D3D9 - Viewport not clearing/background unset

Post by Stymgade »

I've spent days trying to figure this one out to no avail - I'm currently integrating ocornuts ImGui into a base application, and when dragging their windows, it's leaving a 'ghost image' of the window in its previous position.

I initially thought it was ImGui, and spent a while debugging it, but it seems to be sourced from Ogre as when I changed the viewports background colour, it isn't taking effect.

A picture is worth a thousand words:
Image

This 'ghosting' remains until I open an empty menubar item (screenshot in top left shows the remnants of a non-empty menubar item), drag the window so it breaches the viewport edge, or collapse the window so it becomes a simple bar, at which point the entire viewport looks completely normal. The Ogre head always displays without issues.

I've tried various tweaks to the viewport, render system and lighting, and checked a whole bunch of examples, but can't see what I'm doing wrong (if anything!). Compacted, relevant code below.

Code: Select all

bool OgreImGui::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
	// ... imgui code ...
}

bool OgreApplication::Init()
{
	render_system = new D3D9RenderSystem(GetModuleHandle(NULL));
	root->setRenderSystem(render_system);
	// ... set config options, get width/height etc ...
	render_window = root->initialise(true, "OgreRenderWindow");
	render_window->setVisible(true);
	render_window->setActive(true);
	render_window->resize(w, h);

	scene_mgr = root->createSceneManager(Ogre::ST_GENERIC, "MainScene");
	scene_mgr->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f));
	camera = scene_mgr->createCamera("MainCamera");
	camera->setPosition(250, 5, 250);
	camera->lookAt(0, 5, 0);
	viewport = render_window->addViewport(camera);
	const Real      aspect_ratio = Real(viewport->getActualWidth()) / Real(viewport->getActualHeight());
	camera->setAspectRatio(aspect_ratio);
	camera->setAutoAspectRatio(true);

	viewport->setAutoUpdated(true); // no difference
	viewport->setBackgroundColour(ColourValue(1.0f, 1.0f, 0.8f));
	viewport->setClearEveryFrame(true); // no difference
	// ... create lights ...
	// ... load resources ...

	// ... create OgreImGui, add listener ...
}
Is this something I'm doing incorrectly with Ogre, or does it just appear to be the way ImGui is being presented?

Thanks in advance
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: 1.10 D3D9 - Viewport not clearing/background unset

Post by Wolfmanfx »

Can you provide a simple repo case?
omar
Gnoblar
Posts: 3
Joined: Mon Apr 11, 2016 1:26 pm
x 2

Re: 1.10 D3D9 - Viewport not clearing/background unset

Post by omar »

Your imgui renderer is perhaps setting a scissor that is affecting Ogre clear operation.
Maybe sure to disable scissoring after you are done with rendering.
Stymgade
Gnoblar
Posts: 10
Joined: Sat Jan 04, 2014 8:31 pm

Re: 1.10 D3D9 - Viewport not clearing/background unset

Post by Stymgade »

Wolfmanfx wrote:Can you provide a simple repo case?
I've minimized the code into two files (while stripping out anything irrelevant/useless), and supplied the latest imgui source alongside it in the attached zip. Should compile in Visual Studio 2015 if added to a project as is, depending on paths.

The imgui implementation is a direct copy from their d3d9 example, which does display normally.

On the machine I'm currently on (Intel HD 4600) the window actually flashes perpetually from the outset, but it provides the same ghosting effect as my other machine (AMD R9 290).
Attachments
amalgamated_test.zip
Code that can reproduce the issue
(236.39 KiB) Downloaded 70 times
Stymgade
Gnoblar
Posts: 10
Joined: Sat Jan 04, 2014 8:31 pm

Re: 1.10 D3D9 - Viewport not clearing/background unset

Post by Stymgade »

omar wrote:Your imgui renderer is perhaps setting a scissor that is affecting Ogre clear operation.
Maybe sure to disable scissoring after you are done with rendering.
Looks like you've got it - I've added the code below to the end of the RenderDrawLists function call, and it's displaying normally - no screen flashing either!

Code: Select all

device->SetRenderState(D3DRS_SCISSORTESTENABLE, 0);
I'll confirm that it sorts out the original machine too and mark this solved if good.

Thanks! :D
omar
Gnoblar
Posts: 3
Joined: Mon Apr 11, 2016 1:26 pm
x 2

Re: 1.10 D3D9 - Viewport not clearing/background unset

Post by omar »

The code in imgui_impl_dx9.cpp is faulty for not restoring all the state it modifies (whereas the DX10,DX11,OpenGL equivalent are all saving/restoring state now). So it should ideally be fixed there, I just fixed some of it.

Lots of engine just set all state they need but because scissoring is so rarely used by most engine they may never see it.
Stymgade
Gnoblar
Posts: 10
Joined: Sat Jan 04, 2014 8:31 pm

Re: 1.10 D3D9 - Viewport not clearing/background unset

Post by Stymgade »

Thanks for the info, that does explain a couple of bits.

Just seen your latest commit, looking good - confirmed this is all ok with both the quick fix, and the new example code.
Post Reply