Check if a texture has been successfully loaded to GPU

Is there any way to check at any point if we are inside the render loop or not?

My current issue is that I need to update a texture in one of my methods out of OF loop, if I could know whether a texture will be uploaded successfully or not then I would check a “dirtypixels” flag to warn that it still needs to update.

When loading pixels from disc ofLoadImage() provides a bool on return to check for success. But loading pixels to GPU does not, ofTexture::loadData returns void even if we call it out of the render loop.

Any ideas on how to approach this?

Thank you!

Sorry for insisting. If anybody has any thought about it please let me know. Thnks!

Hey Jordi!
What do you mean by “out of OF loop”?
are you getting problems for uploading to the GPU?

Sorry my understanding of this topic is still a bit fuzzy…

I have a situation where a class extends ofApp.
class A : public ofBaseApp {}

This class A is instanced in another class B by composition and there are calls from B to A. Every time class B is instantiated will create a new ofWindow calling an instance of an ofApp.
Class B basically initializes the ofApp from class A like so:

// create one single  ofLoop
// windows are added to the loop
loop = make_shared<ofMainLoop>();

// instantiate
ofAppPtr = make_shared<A>();
windowPtr = make_shared<ofAppQtWindow>();

// add the window to the main loop and
// initialize the window
ofSetupOpenGL(windowPtr, 400, 400, OF_WINDOW);

// initialize OF
ofRunApp(windowPtr, ofAppPtr);

Then i manually call the ofLoop whenever i want the app to refresh with :


As far as i understand, we can upload/manipulate ofTextures during the OF draw call. Looking at the ofWindow draw() code i guess that we can manipulate textures while renderer is open:

// we can do anything with textures here;

Now, what happens if i want to access textures while being out of the OF draw call? what should i be careful with?
I don’t have an example right now, not sure if it is worth to make one. I was just wondering if it is possible to know if a texture has been uploaded successfully to GPU or not, would i get a runtime error? why ofLoadImage provides a return value en loadData does not?

This is just for some testing, also testing my understanding :stuck_out_tongue:

Thank you for any lights on the topic!

from what i can guess you are trying to open a new window on some event or something like that no? in that case there’s several problems:

  • Usually there’s only one main loop no matter how many windows you have so you don’t need to create the extra main loop as you are doing
  • ofSetupOpenGL is the old style call that sets up everything and it shouldn’t be mixed up with new style ofCreateWindow, creating main loops manually or ofRunApp(window, app)
  • ofSetupOpenGL and ofCreateWindow create windows in the global main loop anyway so the main loop you are creating is not being used at all

So in order to create a new window you just need to do:

ofGLFWWindowSettings settings;
auto window = ofCreateWindow(settings);
auto app = make_shared<A>();
ofRunApp(window, app);

If you are implementing your own window class you might want to implement your own settings class and a version of ofCreateWindow that takes an instance of those settings and returns a window of the new class you are creating.

Then every window you create will create it’s own opengl context, when you create a resource under that context (if you call it from that window’s app setup update draw…) then in principle that resource can only be accessed from that window’s context, that is from it’s setup, update, draw, mousePressed… callbacks and anything that they call

You can optionally share a context between to windows by telling the window to share it’s content with a previous one:

ofGLFWWindowSettings settings;
settings.shareContextWith = previousWindow;
auto window = ofCreateWindow(settings);
auto app = make_shared<A>();
ofRunApp(window, app);

That way you can use the resources created from any of the 2 apps in any of them, that will only work for memory resources though like a texture can be shared but a shader cannot that’s why every window also contains it’s own renderer

1 Like

Hi Arturo,
Thank you very much for the explanation!

In fact the ofLoop is already in a different class and called only once on startup. You can see a working example here, although it does not demonstrate the texture issue i started asking about:

So far it works well. But as you suggest I will move to the new syntax. Actually when i tried it, i saw that I would have to create my own ofCreateWindow() which would mean to modify the core of OF and i remember i had a bit of problems with that.

And about this:

Ok that´s what i was acutally asking for, and i wasn’t sure about it. I will try with sharing context as soon as i get some time. I guess that will be the way to go.

Thank you again for explaining, now it is much much clear.

I don’t think you need to modify OF you can create your own version of ofCreateWindow inside your addon

1 Like