Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DirectX - How does the VertexBuffer work?

I'm learning DirectX right now, I read alot about VertexBuffer. Since you cant learn from programming by just reading, I'm making a small Engine with DX11 (Well my question isn't really version dependent)

As far as I understood in a VertexBuffer I store Vertices, and actually I store it on the Graphic card. Well I read about dynamic and static buffers. So If I understand correctly, a static buffer is initialized with vertices and the initialized vertices wont change. OKay but when do I really need it. I mean in a Game or whatever, when do I have constant vertices? Maybe for some UI objects..? - but even these aren't constant everytime.. you can move their 2D position... etc..

The next point is about dynamic vertex buffers, for example: I have a Buffer with some vertices in it, these vertices are drawn. Then I want to add or remove some vertices. What now.. So I would simply "update" the buffer. But is this really right and good for performance? Imagine a terrain editor. There you have to update tons of vertices.

like image 210
Aurus Avatar asked Nov 13 '12 19:11

Aurus


1 Answers

I mean in a Game or whatever, when do I have constant vertices?

All the time actually. For example, static geometry, the UI objects you mentioned etc. There is a slight misunderstanding on your part about moving objects, hence the confusion - you don't move objects by changing their vertices. Instead, you will put your vertices through the shader pipeline. In the vertex shader, you can apply arbitrary transformations to your vertices. So, for example, if you have a tree that's moved around the world for some reason (maybe it's on a floating island or something), rather than changing the vertices that make up the tree, you change the transformation that is applied to the vertices.

Imagine a terrain editor

It depends on what your terrain editor is supposed to do, but generally you again aren't going to change vertices here. I.e. when editing the height, rather then moving vertices up and down, you write to a height map (most of the time a greyscale texture), and again compute the transformation on the GPU in the shader pipeline.

like image 180
Cubic Avatar answered Oct 12 '22 23:10

Cubic