UltravioletFramework / ultraviolet

The Ultraviolet Framework is a .NET game development framework written in C#.
https://github.com/UltravioletFramework/ultraviolet/wiki
MIT License
542 stars 46 forks source link

Dynamic Vertices? #71

Closed schn4v1d closed 6 years ago

schn4v1d commented 6 years ago

I've recently picked up your framework as it looks very promising.

In your tutorial for Rendering Geometry you showed assigning vertices to a buffer -> a stream etc. As far as I understand it these vertices are then not modifiable. Is it possible to dynamically change the vertices and the amount of vertices inside a stream in the OnUpdate Method?

schn4v1d commented 6 years ago

Other than disposing the stream and buffers and creating new ones of course

tlgkccampbell commented 6 years ago

You can update the data inside of a vertex or index buffer by calling their SetData() methods. For buffers which are going to be dynamically updated after they're created, it's best to use the DynamicVertexBuffer and DynamicIndexBuffer classes so that the graphics subsystem can configure them for best performance.

This is how SpriteBatch works internally; check out FlushSprites() for an example of how it works. This code actually uses SetDataAligned() as an optimization for this use case, but the idea is the same.

schn4v1d commented 6 years ago

Thank you very much!