chrisdill / raylib-cs

C# bindings for raylib, a simple and easy-to-use library to learn videogames programming
http://www.raylib.com/
zlib License
824 stars 73 forks source link

Safe UpdateMeshBuffer Util Method #262

Closed nickyMcDonald closed 2 months ago

nickyMcDonald commented 3 months ago

The UpdateMeshBuffer Method is important for updating GPU mesh data repeatedly in a performant manner.

This pull request intends to add a safe utility version of this method by accepting a span wrapper of the data rather than a pointer.

This method (including the interop version) requires an index to whichever buffer the user wishes to update—for example vertices, texture coordinates, colors etcetera. This is why I added VboIdIndex constants to the mesh class to help users access the right vertex buffer object (VBO) ID for the UpdateMeshBuffer Method.

For whatever reason raysan5/raylib does not include an enum or definitions for these VBO indexes. The closest thing I could find to these indexes being defined anywhere was in the raylib source code in UploadMesh.

I also added an example showing a good use case for the safe UpdateMeshBuffer Method and the VBO definitions. Here is what you should expect from the example program: ezgif-1-5eb15b5140

chrisdill commented 2 months ago

Thanks, merged!