Feature/separate instance data from mesh #7459
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey :)
This change adds an
InstanceDatafield toRenderableandModelInstanceto allow rendering the same mesh with different InstanceData buffers or without instances.Currently LibGDX only supports enabling instanced rendering on a Mesh instance (with
enableInstancedRenderingmethod) so it can only be rendered with it's own InstanceData buffer and can't be rendered regularly unless you unset it's instances property.An example use-case for this feature (from my game) is rendering instanced "chunks" to optimize rendering by culling out chunks that are out of view, and still using instanced rendering to optimize rendering each chunk.
Without this change I'm pretty sure the only way to implement this is by duplicating the Mesh object, which is extremely messy.
Also I think it's more intuitive to have the instance data per
ModelInstancerather than perMesh.Enabling instanced rendering on a
ModelInstancewould look something like this:This change doesn't change/break the current flow of the rendering code unless the new
instancesproperty is set in theRenderablethat's being drawn.Using instance data on a
Meshstill works.These are the changes I made in each file:
Renderable- Added optional instances field.ModelInstace- Added optional instances field, and changedgetRenderableto use it.Mesh- Addbind,unbind,rendermethods that receive an external InstanceData object.MeshPart- Addrendermethod that receives an external InstanceData object.BaseShader- Changerender,end,registermethods to use the renderable's instances if set. Also addcurrentInstancesproperty to hold the last renderable's instances to use similarly tocurrentMesh.I tested this on an Android device with my own game, which uses both instanced rendering and regular rendering so I know this doesn't break any standard functionality.
If you think it's necessary I could come up with some minimal demo project for you guys to test it out yourself.