staticskizzles
Member
Is there a quicker method to remove what's stored on a vertex buffer than this?
I'm hoping someone with experience editing buffers knows a way to correct me here.
I have a marketplace asset that generates many grass vertex on a layer, with some extra code to ensure it only generates on certain tiles.
The part that freezes my game for up to 3 seconds is when I remove a specific grass vertex from the buffer.
When I want to remove a grass vertex mid game:
- I create 2 identical non vertex buffers via buffer_create_from_vertex_buffer so I can edit them. Consider one a "main" the other a "throwaway".
- Then using buffer_get_size and buffer_peek , I locate the area in the buffer that's storing data for drawing the specific vertex I want to remove by finding a matching x y.
- Due to no such thing as "buffer_erase_part", I copy everything after the chunk I want to remove, to replace the part in the middle of the buffer I want to erase.
For example: the buffer looks like ABCDE. there's no function for removing C, so to achieve that I copy DE to replace C and turn the buffer into ABDEE.
(all done with buffer_copy copying from the "throwaway" buffer to the "main" buffer. Then I delete the "throwaway" buffer with buffer_delete).
- I trim the end of buffer with buffer_resize . Turning ABDEE into ABDE. Meaning I successfuly yet painfully removed the grass vertex aka C.
- I delete the current vertex buffer the shader is using with vertex_delete_buffer .
- Then create a new vertex buffer using my edited "main" buffer vertex_create_buffer_from_buffer .
- I erase the main buffer with buffer_delete.
I think the copy and resize functions are freezing the game momentarily, although it could be any part of this.
My previous method used only one buffer with buffer_peek and buffer_poke to copy paste byte by byte, then buffer_resize. This caused a much much longer freeze of up to 20 sec.
I tried having multiple instances with unique vertex buffers but this slowed my game down to 20fps, and worsened when I walked around the room.
I apolagise for the lack of screenshots, It's interwined with a lot more code I don't particularly want to share.
I'm hoping someone with experience editing buffers knows a way to correct me here.
I have a marketplace asset that generates many grass vertex on a layer, with some extra code to ensure it only generates on certain tiles.
The part that freezes my game for up to 3 seconds is when I remove a specific grass vertex from the buffer.
When I want to remove a grass vertex mid game:
- I create 2 identical non vertex buffers via buffer_create_from_vertex_buffer so I can edit them. Consider one a "main" the other a "throwaway".
- Then using buffer_get_size and buffer_peek , I locate the area in the buffer that's storing data for drawing the specific vertex I want to remove by finding a matching x y.
- Due to no such thing as "buffer_erase_part", I copy everything after the chunk I want to remove, to replace the part in the middle of the buffer I want to erase.
For example: the buffer looks like ABCDE. there's no function for removing C, so to achieve that I copy DE to replace C and turn the buffer into ABDEE.
(all done with buffer_copy copying from the "throwaway" buffer to the "main" buffer. Then I delete the "throwaway" buffer with buffer_delete).
- I trim the end of buffer with buffer_resize . Turning ABDEE into ABDE. Meaning I successfuly yet painfully removed the grass vertex aka C.
- I delete the current vertex buffer the shader is using with vertex_delete_buffer .
- Then create a new vertex buffer using my edited "main" buffer vertex_create_buffer_from_buffer .
- I erase the main buffer with buffer_delete.
I think the copy and resize functions are freezing the game momentarily, although it could be any part of this.
My previous method used only one buffer with buffer_peek and buffer_poke to copy paste byte by byte, then buffer_resize. This caused a much much longer freeze of up to 20 sec.
I tried having multiple instances with unique vertex buffers but this slowed my game down to 20fps, and worsened when I walked around the room.
I apolagise for the lack of screenshots, It's interwined with a lot more code I don't particularly want to share.
Last edited: