Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch Rendering #20

Open
PixelRifts opened this issue Aug 24, 2020 · 7 comments
Open

Batch Rendering #20

PixelRifts opened this issue Aug 24, 2020 · 7 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@PixelRifts
Copy link

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 PixelRifts added the enhancement New feature or request label Aug 24, 2020
@JacksonHoggard
Copy link
Owner

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

@JacksonHoggard JacksonHoggard added this to the 1.0 milestone Sep 23, 2020
@JacksonHoggard JacksonHoggard mentioned this issue Oct 1, 2021
8 tasks
@xGREGKERSEYx
Copy link

Is this still available?

@JacksonHoggard
Copy link
Owner

This is still open! Have at it!

@xGREGKERSEYx
Copy link

xGREGKERSEYx commented Jan 18, 2024

!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
Copy link
Owner

@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
Copy link

@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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants