simple question about vertex buffers

Started by
3 comments, last by b3rs3rk 16 years ago
I've been reading up on how vertex buffers work and there seems to be somthing missing. You have all vertex data stored in a buffer where each vertex can include uv coords, normals, color etc. but how does the renderer know which texture to apply(or where it is) if you have texture coordinates for each vertex?
Advertisement
Texture coordinates are just positions in a texture. They can be thought of as indexes into a texture. (0,0) is the top-left pixel, (1,1) is the bottom left pixel, and (0.5,0.5) is the middle pixel.

It's the application's responsibility to set what textures are required - the exact method depends on what you're using. In DirectX9 using fixed function I believe you call SetTexture() or somesuch like that - I don't have much experience with the fixed function pipeline.

When using shaders and the Effects framework, check your respective documentation (whether DX9 or DX10), and there should be functions like SetShaderResource to send textures to the device for rendering.
NextWar: The Quest for Earth available now for Windows Phone 7.
Toghether with the vertex buffer you can have an index buffer that specifies the rendering order of the vertices, and an attribute buffer that stores a DWORD for each face of the geometry. Each DWORD specifies the id of the texture required for that face.

For example, when you load a mesh using D3DXLoadMeshFromX, one of the parameters is DWORD* pNumMaterials, that contains the number of materials/textures for that mesh, and the array ppMaterials that contains the material list.

The DWORDs in the attribute buffer are in the range [0, pNumMaterials).

Hope this helps :)
Quote:
Texture coordinates are just positions in a texture. They can be thought of as indexes into a texture. (0,0) is the top-left pixel, (1,1) is the bottom left pixel, and (0.5,0.5) is the middle pixel.


these are actually just unit values for texture coordinates, the real values should be pre-calculated using u = (u * texture width) v = ((1+v) * texture height), I still don't know why in .x file format they store the v coordinate as (v-1)

Quote:
Toghether with the vertex buffer you can have an index buffer that specifies the rendering order of the vertices, and an attribute buffer that stores a DWORD for each face of the geometry. Each DWORD specifies the id of the texture required for that face.


so, how would this work, the way I see it is:

Vertex VertexBuffer[10] - eg. 10
UINT IndexBuffer[9] - three triangles
UINT attributes[3]

so. IndexBuffer[0 1 and 2] could point to three vertices in vertex buffer and any attributes of this face would be stored in attributes[0]. then IndexBuffer[3 4 and 5] would have attributes in attributes[1] etc.

Is that correct?

Does all this vertex data get stored structured and then copied to the vertex buffer or does D3DXLoadMeshFromX just throw all data into the buffer(assuming its static geometery)?
Quote:
so. IndexBuffer[0 1 and 2] could point to three vertices in vertex buffer and any attributes of this face would be stored in attributes[0]. then IndexBuffer[3 4 and 5] would have attributes in attributes[1] etc.

Is that correct?


Yes.

This topic is closed to new replies.

Advertisement