Today we use Vertexbuffer to rendering a cube, I use Trianglestrip, with 18 top points. In fact, our cube is only 8 top points. The previous rendering method is full of 10 top points. For the cube, this is like a small entity, this does not reduce our performance and occupation too Large space, however, if you have a thousands of entities, repeated use of the vertices can be an unhappy overhead! How to reduce overhead? INDEXBUFFER can be used. It creates an index for each vertex. When we need to render the top, we can reuse a vertex by index. First, it is first established VertexBuffer, but only 8 top points in VertexBuffer, that is, 8 of our cubes The vertex. Then establish our index property indices: private short [] indices = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 1, 7, 3, 5, 0, 6, 2 After instantiation VertexBuffer, we will instantiate IndexBuffer below, and the parameters of the specific constructor can be found in SDK, which is similar to VertexBuffer. Such as: indexbuffer = new indexbuffer (Typeof (Short), INDES.LENGTH, Device, USAGE .Writeonly, pool.default; the first parameter is the type of index array, for short, the second is the array length, behind .... 嘿 and VertexBuffer. After instantiation, respond to the CREATED event immediately, specify our Indic to IndexBuffer, use setData method, such as indexbuffer = (indexbuffer) Sender; ib.setdata (indices, 0, lockflags.none); this index top point The establishment and initialization are all completed, and the following is rendering. The method of using the index vertex rendering is: Device. DrawIndexedprimitives argument does not say it, SDK is clear.
I am not right? Not right, please point out, thank you!