refactor(rendering): factor out MutableChunkMesh#4998
Conversation
|
An alternate structure might be, instead of having a MutableChunkMesh and a ChunkMesh interface and one is descended from the other, to have some kind of builder object. The builder object wouldn't have a I think that's a cleaner separation than subclassing. |
|
the generated mesh has to be scheduled back on the main thread to push it to opengl. all opengl calls are sequential and the operation is unbound after the mesh is submitted. The worst that can happen is you schedule it at a bad time and cause a pipeline stall. I would worry about this more if this was like vulkan where that kind of behavior can be a problem. opengl is "fairly safe in this regards". |
| ChunkMesh result = new ChunkMeshImpl(); | ||
| MutableChunkMesh result = new ChunkMeshImpl(); | ||
| for (ChunkMesh.RenderType renderType : ChunkMesh.RenderType.values()) { | ||
| result.getVertexElements(renderType).buffer.replace(asBuffers.remove(0)); |
There was a problem hiding this comment.
this probably should be changed. these are raw buffers for opengl so they follow the endiness of the machine if two machines have different endiness then it will be garbled. network order is little endian I believe
One of the things that made working on ChunkMeshWorker for #4987 scary was the concern that a ChunkMesh's data might be updated while it was in the middle of updating the mesh for OpenGL.
Upon closer examination, it looks like in practice that a new instance of ChunkMesh is created each time the chunk is dirtied. That means
Chunk.meshcould be a reference to a safer, non-mutable interface.I experimented with this (see attached 269f823), moving the methods
vertexElements,updateMeshanddisposeDatato a newMutableMeshinterface.Outstanding before merging
There are a few things that need to be addressed:
updateMeshanddiscardDataon its RenderableChunk. Should that change? Or is the LodChunkProvider code redundant with the ChunkMeshWorker code?update), but it really only updates the material. In fact, I see only one implementation of this, and it looks like it could be a static method.