I am now stuck again…
I am trying to render more objects but calling mesh.render() every frame is eating everything up
so i need to make a method that binds an object and then render all the same objects and then unbind it for multiple times
How would i do this in Libgdx?
When rendering 500 objects on
PC: just about 110 FPS
Android (Samsung Galaxy Ace 2) about 7 FPS
The only solution i have found is using the Renderable which is provided via Libgdx but the problem i have found with that is i cannot use my own shader and i keep getting this error “Cannot use offsets when Element Array Buffer Object is disabled”
Code i have attempted (Making my own rendering system)
for (Entity e : preparedEntity) {
Mesh mesh = e.getModel().getModel().getMesh().getMeshData();
Gdx.gl20.glEnable(GL20.GL_ARRAY_BUFFER_BINDING);
Gdx.gl.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, Usage.Position); // <-- not sure if that is the VBO ID
Gdx.gl30.glVertexAttribIPointer(GL20.GL_ELEMENT_ARRAY_BUFFER, mesh.getNumVertices(), GL20.GL_FLOAT, 0, 0);
Gdx.gl.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, Usage.Normal);
VertexAttribute normal = mesh.getVertexAttribute(Usage.Normal);
Gdx.gl30.glVertexAttribIPointer(GL20.GL_ELEMENT_ARRAY_BUFFER, mesh.getNumVertices(), GL20.GL_FLOAT, 0,normal.offset);
Gdx.gl.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, Usage.TextureCoordinates);
VertexAttribute tex = mesh.getVertexAttribute(Usage.TextureCoordinates);
Gdx.gl30.glVertexAttribIPointer(GL20.GL_ELEMENT_ARRAY_BUFFER, mesh.getNumVertices(), GL20.GL_FLOAT, 0,tex.offset);
Gdx.gl.glDrawElements(GL20.GL_TRIANGLES, mesh.getNumIndices(), GL20.GL_UNSIGNED_INT, mesh.getIndicesBuffer());
My code before (Using Mesh.render) which is provided with libgdx
e.getModel().getTexture().bind(0);
shader.setUniformMatrix(Utils.TRANSFORM_UNIFORM, e.getModel().getModel().getTransform().getTransformationMatrix());
shader.setUniformf(Utils.COLOUR_UNIFORM, e.getModel().getModel().getColour());
if (MasterRenderer.getRenderCollisionMesh()) {
e.getCollisionMesh().unsignedRender(GameWindow.getDefaultShader(), GameWindow.getCamera());
}
e.getModel().unsignedRender(GameWindow.getDefaultShader(), GameWindow.getCamera(), false);
Inside render
int type = GL20.GL_LINE_STRIP;
if(wireframe == false){
type = GL20.GL_TRIANGLES;
}
rawModel.getMesh().getMeshData().render(shader, type);