Running Something Only After a New Frame Has Been Rendered

Simply put, is there a way to run a piece of code only after at least one new frame has been rendered?

To explain: For a project that I’m working on, I want to implement a very simple loading screen–no threading, just a static screen that’s shown until loading is finished.

However, past experience tells me that I can’t just attach a quad and then proceed with loading: the quad may well not be rendered until after the loading is done. And, if I recall correctly, even running the load after a very short “doMethodLater” may not be reliable.

So, what I want then is to put up my quad, wait until that has been rendered at least once, and only then proceed with the actual loading.

But I’m not sure of how to handle the “wait until rendered” part. Is there a way to detect that, or to get a callback on it happening…?

I think this is what you describe, but with synchronous loading, you can simply return True from the function.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import CallbackNode, NodePath
import time

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

        сall = CallbackNode('screen')
        сall.set_draw_callback(self.draw)

        object_geom = NodePath(сall)
        object_geom.reparent_to(render)
        object_geom.hide()

        time.sleep(3)

    def draw(self, cbdata):
        print("rendered")
        cbdata.upcall()

app = MyApp()
app.run()

To make it work, just comment out object_geom.hide()

Ah, that does indeed seem to work! Thank you! :slight_smile: