Author Topic: compileAllObjects in another thread  (Read 1797 times)

Offline Luka

  • byte
  • *
  • Posts: 2
    • View Profile
compileAllObjects in another thread
« on: March 14, 2016, 04:28:33 pm »
Hi
I have an app in which user can choose which 3d object wants to see. When the user taps on the button, I call loadSerializedObjectArray, set up the textures and everything, and at the end, call compileAllObjects. However, this method is rather slow and sometimes it takes around 3-5 seconds to execute. This blocks OpenGL thread and, of course, the screen freezes. Would it be possible to call compileAllObjects in another thread? This way, the rendering of the rest of the scene would continue normally and the object would be shown when ready. Would it be possible to somehow do the compilation beforehand?  I've tried calling object.compile() in another thead, but still compileAllObjects takes too long.

Thanks for the help,

Luka

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: compileAllObjects in another thread
« Reply #1 on: March 14, 2016, 04:51:24 pm »
Maybe you can...I've done nothing to ensure thread safety there, but it doesn't make use of the GL context, so it might work. However, you somehow have to ensure that objects that are processed by compileAllObjects() are not rendered at the same time. Maybe by adding them to another, otherwise unused instance of World just for compilation purposes.

Offline Luka

  • byte
  • *
  • Posts: 2
    • View Profile
Re: compileAllObjects in another thread
« Reply #2 on: March 17, 2016, 10:45:14 am »
Thanks, this really did it. I just created fake world to do only compilation.
However, compilation is still rather slow. It takes 4-5 seconds to compile a model with 4500 polygons. Would it be possible to somehow compile the object beforehand? The ideal solution would be to include the compiled object in serialized object file. Other solution could be to cache the compiled instance and serialize it on target device. Maybe use reflection to get ArrayList<CompiledInstance> compiled in Object3D and save it to disk when compiled for the first time?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: compileAllObjects in another thread
« Reply #3 on: March 17, 2016, 10:51:34 am »
No, that's not possible, I'm afraid. Which device is that? 4-5 secs for 4500 polygons sounds a little too much for a current device!?