www.jpct.net
jPCT-AE - a 3d engine for Android => Support => Topic started by: zbych 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)?
-
Yes, you can use this: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/World.html#compileAllObjects() (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/World.html#compileAllObjects())
-
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):
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?
-
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?
-
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.
-
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.
-
The "blocks" share geometry but the other types of objects not necessarily (for example track segments can't share geometry).
-
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) (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.
-
Thanks for advices. Disabling VBO looks as best option for me.