# Information from Indexbuffers

This topic is 4316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all! This is my first topic at Gamedev.net, and i think it will be many more after this one :). So, the first question here will be: Is it possible to get the information out from indexbuffers ? I know how to get the information out from the vertexbuffer, but now I need to get the information (the numbers) out from the indexbuffer to. (I need it to calculate the trimesh data in ODE - Open Dynamics Engine). I guessed it would be the same way as when i gather the information from the vertexbuffer, but I come up with fuc*ed values. int* I; m_Sphere.m_SphereModel->GetIndexBuffer()->Lock(0, 0, (void**)&I, 0); for(int i = 0; i < "size of indexbuffer"; i++) { MyArray = *I; } m_Sphere.m_SphereModel->GetIndexBuffer()->Unlock(); //BUT //MyArray[0] = 65000!!! And this i wrong :P When I try to gather the info, I begin to lock the buffer with a correct pointer, then I go through the whole buffer and saves all the values in a array. But, the first value that i get in the array dosn't match up with the one in the xfile. (the value i get is 65000+, so im pretty sure it's wrong.) Am I doing it wrong, or is it not possible to get the values from the indexbuffer. Thanks for any help. PS: If anyone would give me a hint in how to write "codelike" code here, it would be appreciated.

##### Share on other sites
Hi, welcome to GameDev.Net [smile]

To do code-like code, you use [ source ] [ /source ] tags.

As for your problem, it's likely that the index data is 16-bit, and an int is 32-bit. If you change int* I; to unsigned short* I;, it should work.

If it's possible to get the index data in some other way, not going through D3D, you should prefer that. Locking any resource for reading is pretty expensive.

##### Share on other sites
Quote:
 Original post by Evil SteveAs for your problem, it's likely that the index data is 16-bit, and an int is 32-bit. If you change int* I; to unsigned short* I;, it should work.
Just as an additional option, the VStudio compilers allow unsigned __int16 and unsigned __int32 quantities - the more standard short/int/long measures are more portable but equally there is a bit of room for them to change between compilers. I prefer explicitly marking them __int16 or __int32 as it becomes immediately obvious what width they are...

Oh, and for the 32bit vs 16bit - you can query the index buffer for a description and check the format againt D3DFMT_INDEX16 or D3DFMT_INDEX32. I then tend to generalize my index-buffer code using templates:

<template T>void ManipulateIndices( T** ppData );if( D3DFMT_INDEX16 == ibDesc.Format )    ManipulateIndices< unsigned __int16 >( reintpret_cast< unsigned __int16** >( ibData ) );else if( D3DFMT_INDEX32 == ibDesc.Format )    ManipulateIndices< unsigned __int32 >( reintpret_cast< unsigned __int32** >( ibData ) );

May or may not be of any use [smile]

hth
Jack

1. 1
Rutin
64
2. 2
3. 3
4. 4
5. 5

• 16
• 10
• 29
• 20
• 9
• ### Forum Statistics

• Total Topics
633413
• Total Posts
3011759
• ### Who's Online (See full list)

There are no registered users currently online

×