voodoo2d icon indicating copy to clipboard operation
voodoo2d copied to clipboard

Batch Rendering

Open PixelRifts opened this issue 4 years ago • 7 comments

I see that in this Project every single GameObject is rendered using a separate draw call. (Very Slow)

Batch Rendering is not hard to implement. Only thing is one has to overhaul the entire Renderer :(

PixelRifts avatar Aug 24 '20 04:08 PixelRifts

Thanks for the suggestion! I'm still sort of new to OpenGL and didn't know that this was possible.

JacksonHoggard avatar Sep 23 '20 20:09 JacksonHoggard

Is this still available?

xGREGKERSEYx avatar Jan 17 '24 14:01 xGREGKERSEYx

This is still open! Have at it!

JacksonHoggard avatar Jan 18 '24 00:01 JacksonHoggard

!Assign (please assign it to me)

for (GameObject gameObject : gameObjects) {
           // Set model view matrix for this item
           Matrix4f modelViewMatrix = transformation.getModelViewMatrix(gameObject, viewMatrix);
           shaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
           // Render the mesh for this game item
           gameObject.getMesh().render();
       }
       

Is this the area causing the issue? I see the GameObject class used to model the Object, and then this Renderer class which renders the gameItem

xGREGKERSEYx avatar Jan 18 '24 17:01 xGREGKERSEYx

@xGREGKERSEYx It looks like that for loop is at least part of the code causing the issue. If you look at the render function in the Mesh class, you can see where the draw function is called:

public void render() {
    // Activate firs texture bank
    glActiveTexture(GL_TEXTURE0);
    // Bind the texture
    if(hasSpriteSheet)
        glBindTexture(GL_TEXTURE_2D, spriteSheet.getTextures()[currentFrame].getId());
    else
        glBindTexture(GL_TEXTURE_2D, texture.getId());

    // Draw the mesh
    glBindVertexArray(getVaoId());

    glDrawElements(GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0);

    // Restore state
    glBindVertexArray(0);
}

You could probably modify that code to draw multiple gameObjects with one call to the draw function.

JacksonHoggard avatar Jan 18 '24 19:01 JacksonHoggard

@JacksonHoggard Hello! I sent you an e-mail [[email protected]] last week. Just wanted to make sure I had everything setup right. I can re-send it or just drop it in here, later.

xGREGKERSEYx avatar Jan 22 '24 16:01 xGREGKERSEYx

@xGREGKERSEYx Hey! Just replied to your email. I tried to be as verbose as possible, but please let me know if you have any questions or if you need any help. Best of luck! :)

JacksonHoggard avatar Jan 23 '24 00:01 JacksonHoggard