oakes / play-clj

A Clojure game library
The Unlicense
939 stars 73 forks source link

Use cases for on-gl #13

Closed anthgur closed 10 years ago

anthgur commented 10 years ago

When should on-gl be used? I've noticed that you need to use it from the repl to call screenshot! and set-screen!.

Do the functions given to defscreen get executed in the gl context automatically? If so, how? If not, calls to screenshot! will need to be wrapped in on-gl or it with throw an exception due to not having the gl context (from the call to ScreenUtils/get...Pixels). I thought I would ask, because I'm not sure how to test it other than building an uberjar for play-clj and running one of the example projects with it.

Is there a way to tell which functions will need the gl context without trying them manually?

oakes commented 10 years ago

You are correct that functions in defscreen are run on the GL thread; their execution is determined by LibGDX, so this is guaranteed. Running commands in a REPL is certainly a major reason for having on-gl, but it is also useful when running code in a separate thread using, for example, future or pmap. I don't think there is a documented way to know which functions must be run on the GL thread, but you can usually tell just by thinking about whether it would need to interact with OpenGL in some way.