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

Clear vertex buffer on empty instance buffer inside drawInstance #6208

Conversation

heretique
Copy link
Contributor

This PR handles a corner case that we found when doing instanced draw calls.
Inside the Renderer.drawInstance method if the instancingData.count is zero there is no device.draw called which leaves the GraphicsDevice.vertexBuffers list uncleared (that list is only cleared on a successful draw call) thus making next draw call to bind more vertex buffers then needed (plus create extra temporary VAOs) and in some cases if the material changes from a draw call to the next and it has different attribute requirements it breaks the draw call (sometimes with visible artifacts) and WebGL logs warnings:

FIREFOX:  WebGL warning: drawElementsInstanced: Indexed vertex fetch requires 462 vertices, but attribs only supply 376.
EDGE: [.WebGL-0x11c0055cb00] GL_INVALID_OPERATION: Vertex buffer is not big enough for the draw call.

It took a long time to figure this one out so we're hoping this PR would benefit others who also rely a lot on instancing.

image

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

@kpal81xd kpal81xd merged commit 0ab9deb into playcanvas:main Apr 2, 2024
7 checks passed
Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for this!

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

Successfully merging this pull request may close these issues.

3 participants