ofThreadChannel ofTexture

#1

I want to push my texture to a threaded saver, but the img saved is all grey, seems like is saving the ofPixels empty without the part that read texture to pixels.

Why this do not work¿

#pragma once
#include "ofMain.h"

class threadSaver : public ofThread
{
public:
	threadSaver()
	{
		startThread();
	}

	~threadSaver()
	{
		toSave.close();
		waitForThread(true);
	}

	void paSave(ofTexture & text) {
		toSave.send(text);
	}

private:
	void threadedFunction() {
		
		ofTexture text;
		while (toSave.receive(text)) {
			ofPixels pxs;
			text.readToPixels(pxs);
			
			ofSaveImage(pxs, "C:/Users/natxo/Documents/" + ofToString(ofGetElapsedTimeMillis()) + ".png");
		}
	}
	ofThreadChannel<ofTexture> toSave;
};
#2

you can’t do opengl operations on a different thread, including readToPixels. you can do an asynchronous read back from the gpu using a PBO, there’s some examples in the gl folder

#3

Ok, thank you, i will try the PBO approach