-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
refactor(rendering): factor out MutableChunkMesh #4998
base: develop
Are you sure you want to change the base?
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". |
@@ -44,7 +45,7 @@ protected PersistedData serializeNonNull(ChunkMesh value, PersistedDataSerialize | |||
directBuffer.rewind(); | |||
asBuffers.add(directBuffer); | |||
} | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.mesh
could be a reference to a safer, non-mutable interface.I experimented with this (see attached 269f823), moving the methods
vertexElements
,updateMesh
anddisposeData
to a newMutableMesh
interface.Outstanding before merging
There are a few things that need to be addressed:
updateMesh
anddiscardData
on 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.