alexlarsson / gthree

Gthree is a GObject/Gtk+ port of three.js
MIT License
84 stars 13 forks source link

Make resources fully per-renderer #68

Closed alexlarsson closed 4 years ago

alexlarsson commented 5 years ago

The current code assumes that each GthreeRenderer has full access to the gl context (it tracks the current state after all). GthreeResources are then realized for a particular renderer with e.g. gthree_resource_set_realized_for().

However, we're currently only storing one copy of the gl resources for the various resources (textures, attributes, render-targets), which is not quite right. If you're using the same resources in multiple renderers we should really allocate once for each renderer.

With the current code we should really assert that we realize for the right renderer, however that will break the current multi-view demo which currently works by chance due to the way Gtk+ makes all gl contexts in the same window share resources...

alexlarsson commented 4 years ago

Started the wip/per-renderer-resources branch to work on this. That contains the infrastructure for this, passing down the renderer into the unrealize function and into the various places we realize things. We now only use the current_renderer in unrealize() to know if we have to do an unrealize-in-idle-with-make-current.

However, GthreeResource->renderer is still only a singleton, and we need to make the actual gl resources hang of separate per-resource structs.

alexlarsson commented 4 years ago

Some more work. Still not done though. GthreeMaterial needs per-renderer state too, for e.g. the program and the shaders. Also, with the changes currently we're creating duplicated buffers for interlaced and stacked GthreeAttributes.

alexlarsson commented 4 years ago

Uniforms needs_update need to be per renderer too.