Multiwindow update/draw call issue


#1

I have encountered a strange issue in a multiwindow setting on OSX 10.12 that I haven’t seen before.
If I call some gl commands from update, like drawing to an Fbo, it seems to be interfering with the multiwindow draw methods.

Here’s a small sample that opens two windows and draws a window size rectangle in both of them that should look like this:

But sometimes (about 2 out of 5 times) it looks like this when switching between the windows.

As far as I know update is called before all the window draw's, so I don’t really understand what is happening. Am I doing something wrong? Any help would be appreciated.

#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"

using namespace ci;
using namespace ci::app;

class MultiWindowApp : public App
{
 public:
	void setup() override;
	void update() override;
	void drawWindow1();
	void drawWindow2();

 private:
	app::WindowRef mWindow1;
	app::WindowRef mWindow2;
};

void MultiWindowApp::setup()
{
	mWindow1 = app::getWindow();
	mWindow1->setTitle( "Window1" );
	mWindow1->getSignalDraw().connect( std::bind( &MultiWindowApp::drawWindow1, this ) );

	mWindow2 = createWindow( Window::Format().size( 800, 600 ) );
	mWindow2->setTitle( "Window2" );
	mWindow2->getSignalDraw().connect( std::bind( &MultiWindowApp::drawWindow2, this ) );
}

void MultiWindowApp::update()
{
	// this triggers the weird behaviour
	gl::ScopedViewport viewport( getWindowSize() / 2 );
}

void MultiWindowApp::drawWindow1()
{
	gl::ScopedViewport viewport( getWindowSize() );
	gl::ScopedMatrices matrices;
	gl::setMatricesWindow( getWindowSize() );

	gl::clear();
	gl::ScopedColor color( Color( 1, 0, 0 ) );
	gl::drawSolidRect( getWindowBounds() );
}

void MultiWindowApp::drawWindow2()
{
	gl::ScopedViewport viewport( getWindowSize() );
	gl::ScopedMatrices matrices;
	gl::setMatricesWindow( getWindowSize() );

	gl::clear();
	gl::ScopedColor color( Color( 1, 0, 1 ) );
	gl::drawSolidRect( getWindowBounds() );
}

CINDER_APP( MultiWindowApp, RendererGl )

#2

I am wondering if you need to specify which WindowSize you want to apply in the viewport for that window.

You could try getWindowIndex(…)->getSize() or something like that…

L


#3

Thanks. I think it should work like this, but tried using mWindow1->getSize(), mWindow1->getBounds(), etc, but it didn’t help.


#4

Hey @gabor_papp, did you come to any conclusion with this issue ?
I’m experiencing the exact same thing ; my main window uses a Fbo, so I have to call some gl commands before the draw (at least to allocate / re-allocate it on resize).
I’m really confused by how random it is. I’m guessing the problem occurs during the initialization, since it only appears from time to time (like you said, about 2 out of 5 times).


#5

I moved the fbo drawing from update to one of the draw methods as a workaround. Could not find any better solutions.


#6

I see. I’ll do the same for now but it looks like a behavior that should be discussed somewhere.


#7

YourApp::update() is only called once per frame, and YourApp::draw() is called once for each window per frame.


#8

I meant that I put the fbo render in one of the window’s draw like drawWindow1() in the example. Ideally it would be better in update() as it needs to be called once each frame, but it didn’t work for the reason discussed above.