go-qml / qml

QML support for the Go language
Other
1.96k stars 189 forks source link

Run code in rendering thread #95

Closed neclepsio closed 9 years ago

neclepsio commented 9 years ago

While it's possible to make a chan func() to be run in the Paint method, it could be useful (and more elegant) to have a qml function analogous to RunMain to run something in the rendering thread.

My use case is an event handler using OpenGL commands.

niemeyer commented 9 years ago

Why would you want to do that except for painting-related tasks (OpenGL), which is supported by the Paint method?

neclepsio commented 9 years ago

In my case, I do object selection. I paint the scene with special colors using scissor test, query the pixel under the cursor and understand to which object it belongs according to its color.

Now I schedule this for the next Paint, but I think it's not too elegant.

niemeyer commented 9 years ago

It doesn't sound too bad, considering the logic involved. You can basically have a custom ObjectSelection type that schedules itself to be painted and thus have access to both the correct thread and the OpenGL context. This ObjectSelection type also gives you a good spot for customizing it with events and properties that may tweak its behavior.

It doesn't sound like RunPaint or similar would be a superior design. We'd have to implement pretty equivalent logic to achieve it, adding unnecessary complexity and overhead, and at the end we'd have less. We'd need to figure out which context the function is interested in, for instance, and would lose the convenient handle that the custom object gives us.

neclepsio commented 9 years ago

It's ok for me.