Context: I'm building a mobile game targeted for android with libgdx. It's an endless highscore based game. The environment/terrain is build dynamically. It's kind of a maze/wall/block terrain. I'm using the ModelBuilder and MeshPartBuilder API of libgdx to create the model.

Problem: As the game is endless and the terrain random, I need to build the model while rendering preferably at consistent 60fps. I have put the generation code into a worker thread. This works, but the end() method of the ModelBuilder has to be called in the rendering thread, because of the needed opengl context.

Even if I only build a single rectangle using meshpartbuilder, I get a huge framedrop from calling ModelBuilder.end() .


// we are in a worker thread
modelBuilder.begin(); // ModelBuilder instance
MeshPartBuilder wallBuilder = modelBuilder.part("mazePart", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, modelMaterial);

... create some meshes with MeshPartBuilder ...

Gdx.app.postRunnable(new Runnable() {
    public void run() {
        Model model = modelBuilder.end(); // method that causes a framedrop from 60 to ~35

Question: How do I achieve stable fps while building models dynamically in libgdx? Is it even possible?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.