Share a texture across multiple windows


#1

Dear list,
I don’t manage to use a single texture on two separate windows.
I have been reading various threads on this forum and tried various solutions (including threaded buffers (concurrentcircularbuffers)).
I tried to use gl::Context::getCurrent() and context->makeCurrent(); functions without any success on a Linux box (ubuntu 17.10).
Below a very simple example to start with.
The image is only shown on the second window which i understand as being the latest opengl context before the texture is loaded on the GPU.
Any advices most welcome !
thanks by advance,
Vincent

#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
using namespace ci;
using namespace ci::app;
using namespace std;

class TestApp : public App {
public:	
	WindowRef win1, win2;
	gl::TextureRef mtex;
	ImageSourceRef img;
	void setup(){		
		win1 = getWindow();
		win1->getSignalDraw().connect( std::bind( &TestApp::draw1, this ) );
 		win2 = createWindow();
		win2->getSignalDraw().connect( std::bind( &TestApp::draw2, this ) );
		img = loadImage( loadResource ("e08.tga")) ;
		mtex = gl::Texture2d::create(img);
	}
	void draw1() {
		gl::clear( Color(0,0,0));
		if( mtex ) gl::draw(mtex);
	}
	void draw2() {
		gl::clear( Color(0,0,0));
		if (mtex) gl::draw(mtex);
	}
};
CINDER_APP(TestApp, RendererGl())

#2

This deserves a github issue.

Context sharing between windows on Linux is not implemented it seems.The window to share context with should be passed as an argument to glfwCreateWindow which does not currently happen and instead NULL is passed essentially disabling sharing.

Cheers,
Petros


#3

I made some modifications in the past to share Fbo textures across multiple windows in Linux.

It is not perfect as I remember. It needed the Fbo to be created before the second window.

Gabor


#4

I tried to change the createWindow method but got into problems with WindowRef and GLFWwindow handling. too complex for me… thanks anyway it helped me understand that it was feasible :slight_smile:


#5

This is working very nicely as far as i can tell.
Thanks a lot Gabor !


#6

I’ve created a PR which hopefully will address this. It’s a little more elaborate than yours @gabor_papp though the net result should be the same; just a bit more future-proofed for when we (likely) eventually allow users to opt-out of sharing.

https://github.com/cinder/Cinder/pull/1936