Author Topic: How to force object creation?  (Read 1108 times)

Offline zbych

  • int
  • **
  • Posts: 75
    • View Profile
How to force object creation?
« on: December 10, 2013, 10:02:33 am »
Hi.
When I create my scene some objects are not created immediately, they are created when camera get closer to them (or camera is pointing on them not sure).
I want to avoid it, I want to force to create VBOs for all objects on scene. Is any possiblity to do that (beside moving camera to different locations)?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to force object creation?
« Reply #1 on: December 10, 2013, 10:19:12 am »

Offline zbych

  • int
  • **
  • Posts: 75
    • View Profile
Re: How to force object creation?
« Reply #2 on: January 06, 2014, 04:55:47 pm »
I am still unable to resolve this problem. The objects are added to world and their visibility is set to FALSE. In the initialization procedure I want to force objects to be created, so I make something like this (the objects might appear behind camera):
Code: [Select]
for(int i=0;i< _blocks.length; ++i) {
  _blocks[i].lBlockObj.setVisibility(true);
  _blocks[i].rBlockObj.setVisibility(true);
  _trackGen.getPositionAtTime(_tempVector, 2000, 0);
  _blocks[i].lBlockObj.root.clearTranslation();
  _blocks[i].lBlockObj.root.translate(_tempVector);
}
world.compileAllObjects();
world.renderScene(frameBuf);
world.draw(frameBuf);
clenup();

but instead of series of messages "VBO created for object 'object' " I got:
I/jPCT-AE(7001): Additional visibility list (195) created with size: 512
The cleanup procedure makes objects invisible again. I am suspecting that this group of objects might freeze the game for a few seconds on slow devices. The objects have attached a shader so there is additional pause for shader compilation. Am I doing something wrong?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to force object creation?
« Reply #3 on: January 06, 2014, 05:24:33 pm »
Each call to draw() that's not followed by a display()-call in that iteration will cause a new display list to be created. If you then call display(), all these objects will be rendered as many times as you have called draw. It's actually not a good idea to call renderScene/draw from anywhere but onDrawFrame().
You should also call build() (i don't see this in your code snippet). So actually this should be more like a build/compileAllObjects-sequence.
Do these blocks share geometry?

Offline zbych

  • int
  • **
  • Posts: 75
    • View Profile
Re: How to force object creation?
« Reply #4 on: January 06, 2014, 08:12:52 pm »
Maybe I have explained it wrong, but the problem is with "VBO creation". The objects are build and compiled but when I call FrameBuffer.draw() only for few of them are created VBOs, and during the game I can see all the time messages: "creating buffers" and "VBO created for object..", and in situation when the larger group of objects becomes visible for the camera, the slow devices are freezed for few seconds.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to force object creation?
« Reply #5 on: January 06, 2014, 08:38:37 pm »
You actually can't create VBOs outside of a current and active context, which is why it still happens at render time no matter if you call compileAllObjects() or not. You can disable VBO-support in Config, which might help to get rid of these hick-ups, but it might be slower then (highly depends on the device).
However, that's why i asked if the blocks share (or could share) the same geometry. Because in that case, you can make it so that this process happens only once and not per block.
« Last Edit: January 06, 2014, 08:42:15 pm by EgonOlsen »

Offline zbych

  • int
  • **
  • Posts: 75
    • View Profile
Re: How to force object creation?
« Reply #6 on: January 06, 2014, 08:45:33 pm »
The "blocks" share geometry but the other types of objects not necessarily (for example track segments can't share geometry).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to force object creation?
« Reply #7 on: January 06, 2014, 09:10:06 pm »
If they share geometry, make sure that they use are using http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#shareCompiledData(com.threed.jpct.Object3D) as well. For the parts that don't share geometry....well, my only advice is to disable VBOs at least for slower devices.

Offline zbych

  • int
  • **
  • Posts: 75
    • View Profile
Re: How to force object creation?
« Reply #8 on: January 06, 2014, 09:33:21 pm »
Thanks for advices. Disabling VBO looks as best option for me.