JacksonHoggard / voodoo2d

👹 2D Java Game Engine built in OpenGL
MIT License
130 stars 51 forks source link

Batch Rendering #20

Open PixelRifts opened 4 years ago

PixelRifts commented 4 years ago

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 :(

JacksonHoggard commented 4 years ago

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

xGREGKERSEYx commented 10 months ago

Is this still available?

JacksonHoggard commented 10 months ago

This is still open! Have at it!

xGREGKERSEYx commented 10 months ago

!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

JacksonHoggard commented 10 months ago

@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.

xGREGKERSEYx commented 9 months ago

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

JacksonHoggard commented 9 months ago

@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! :)