# Threaded GL Content Loading in Cinder

**URL:** <https://discourse.libcinder.org/t/threaded-gl-content-loading-in-cinder/398>\
**Category:** Using Cinder\
**Created:** [November 21, 2016, 9:00am UTC](https://discourse.libcinder.org/t/threaded-gl-content-loading-in-cinder/398 "2016-11-21T09:00:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![julapy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/julapy/32/231_2.png) [@julapy](https://discourse.libcinder.org/u/julapy)\
**Post date:** [November 21, 2016, 9:00am UTC](https://discourse.libcinder.org/t/threaded-gl-content-loading-in-cinder/398/1 "2016-11-21T09:00:23Z")

</div>

hey there ci::Folk,

ive come up against some slow downs in my app when loading various content,  
and now working on mitigating using some threaded loading.

have been sticking close to the **FlickrTestMultithreaded** sample,  
and have implemented threaded image loading in my app,  
this has been working great but was not enough to stop the jerkiness on load.

my app is generating a lot of custom text using `ci::TextBox` as well as other FBOs for content which im hoping to off-load to a background thread.

i thought that maybe following the **FlickrTestMultithreaded** sample, i could do all my FBO initialisation and text generation on a background GL thread. the way ive approached this is by passing my content object as a shared\_ptr (using `ConcurrentCircularBuffer`) to the background thread and calling a method on it to create and render FBOs and text.

the results were promising on OSX, seemed to be working fine but on Windows im getting blank FBOs, suggesting that FBOs don’t like to be created or rendered on the background GL thread.

would love to know if what im trying to achieve is even possible?  
and if so, what the correct way of doing it would be?

cheers, L.

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [November 21, 2016, 9:27am UTC](https://discourse.libcinder.org/t/threaded-gl-content-loading-in-cinder/398/2 "2016-11-21T09:27:40Z")

</div>

I’m pretty sure FBOs can’t be shared across contexts, but the textures / renderbuffers they contain can. Are you creating the FBO on the secondary thread as well as rendering to it there?

---

<div class="post-metadata">

**Author:** ![julapy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/julapy/32/231_2.png) [@julapy](https://discourse.libcinder.org/u/julapy)\
**Post date:** [November 21, 2016, 11:01pm UTC](https://discourse.libcinder.org/t/threaded-gl-content-loading-in-cinder/398/3 "2016-11-21T23:01:44Z")

</div>

hey @lithium, yes the FBOs are being created on the background thread.  
sounds like this is where the issue is… ☹

i have been considering creating a number of FBOs when the app first launches and then reusing them for the content rendering, so there is a way i can get around the FBO issue.

but the app is still generating a lot of text using `ci::TextBox` which i have noticed slows down the app quite a bit.  
im assuming that under the hood the text is being rendered into an FBO also.  
is there any way of somehow generating dynamic text in cinder on a background thread?

cheers.

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [November 21, 2016, 11:15pm UTC](https://discourse.libcinder.org/t/threaded-gl-content-loading-in-cinder/398/4 "2016-11-21T23:15:19Z")

</div>

My understanding is that `TextBox` is entirely CPU side and renders to a `Surface`. With this case you could either share a context and do the texture upload on the background thread, or just do the CPU side text rendering on the background thread and push the `Surface` back to the main thread via `App::dispatchAsync()` for GPU uploading.

I can’t help you with the FBO side of things though, thankfully it’s not an issue I’ve come across before.

---

<div class="post-metadata">

**Author:** ![julapy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/julapy/32/231_2.png) [@julapy](https://discourse.libcinder.org/u/julapy)\
**Post date:** [November 21, 2016, 11:36pm UTC](https://discourse.libcinder.org/t/threaded-gl-content-loading-in-cinder/398/5 "2016-11-21T23:36:02Z")

</div>

@lithium.snepe, thanks for the info about `ci::TextBox`  
i’ll investigate some more and try to generate the text on the background thread.  
once the text is generated ill be rendering it to an FBO on the main thread.  
hopefully that works… will report back with results.

didn’t know about `App::dispatchAsync()`…  
but i might stick to using the `ConcurrentCircularBuffer` approach as ive become familiar with it… assuming both approaches are just mechanisms for getting content back onto the main thread.
