Multiwindow linux gl resource sharing?


I encountered an issue when porting an OSX app to Linux. Created a basic test with and Fbo whose color texture should be shared between the two windows, but it isn’t. What is the correct way of doing this? If I remember correctly this has worked before for me on Linux.
Latest Cinder git master with gtx 1080, proprietary driver 375.39, on Fedora 25.




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

using namespace ci;
using namespace ci::app;

class MultiWindowTestApp : public App
	void setup() override;
	void update() override;

	app::WindowRef mWindow0;
	app::WindowRef mWindow1;

	void drawWindow( size_t windowId );

	void renderFbo();

	gl::FboRef mFbo;

void MultiWindowTestApp::setup()
    mFbo = gl::Fbo::create( 1920, 1080 );

	mWindow0 = app::getWindow();
	mWindow0->getSignalDraw().connect( [ & ]() { drawWindow( 0 ); } );

	mWindow1 = createWindow( Window::Format().size( ivec2( 400 ) ) );
	mWindow1->getSignalDraw().connect( [ & ]() { drawWindow( 1 ); } );

void MultiWindowTestApp::renderFbo()
	gl::ScopedFramebuffer fbo( mFbo );
	gl::ScopedViewport viewport( mFbo->getSize() );
	gl::clear( Color( 1.0f, 0.0f, 0.2f ) );

void MultiWindowTestApp::update()

void MultiWindowTestApp::drawWindow( size_t windowId )
	gl::viewport( getWindowSize() );
	gl::setMatricesWindow( getWindowSize() );

	gl::draw( mFbo->getColorTexture(), getWindowBounds() );

CINDER_APP( MultiWindowTestApp, RendererGl )

It seems I didn’t remember it right, I had to modify Cinder and pass the first window to glfwCreateWindow before to share the context.

This is true.

Unfortunately in GLFW the abstractions make the concept of Window and Context virtually inseparable. The only way to share context in GLFW-land is the way you describe so we would have to figure out a way to allow this, potentially with a Linux-GLFW ifdef clause inside cinder::app::Window::Format which allows one to pass a pointer of the window to share context with.

Probably deserves an issue ticket on its own.

Thanks Petros. The way I hacked it in, is that I’m sharing the context of the first window with all other windows automatically in WindowImplLinux. Is it how it works on other platforms, isn’t it?