How can I iterate a buffer with a stride? For example, I saved the pointer to a vertex buffer for later use. I've got the stride, the pointer, and triangle count for vertices. I want to iterate my pointer using this info to get the vertices. I'm doing it wrong right now because it doesn't display all of them.
Anyone have any idea how I can use this information to get each vertex?
struct BufferObject
{
GLint ID;
GLsizei Size;
GLboolean Reserved;
GLenum Type, Usage;
const GLvoid* BufferPointer;
};
BufferObject CurrentBuffer;
std::vector ListOfBuffers;
GL_EXPORT __stdcall void GLHook_glBindBufferARB(GLenum target, GLuint buffer)
{
BufferBound = true;
CurrentBuffer.Type = target;
CurrentBuffer.ID = buffer;
(*optr_glBindBufferARB) (target, buffer);
}
GL_EXPORT __stdcall void GLHook_glBufferDataARB(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage)
{
if (BufferBound)
{
BufferBound = false;
CurrentBuffer.Size = size;
CurrentBuffer.Usage = usage;
CurrentBuffer.BufferPointer = data;
ListOfBuffers.push_back(CurrentBuffer);
}
(*optr_glBufferDataARB) (target, size, data, usage);
}
void IterateModelVertices()
{
for (size_t I = 0; I < ListOfBuffers.size(); I++)
{
if (ListOfBuffers[I].ID == CurrentBuffer.ID)
{
const GLfloat* Ptr = static_cast(ListOfBuffers[I].BufferPointer);
for (int J = 0; J < ModelPtr->TriangleCount; J++)
{
Not sure if I'm using it correctly though.
ModelPtr->Vertices.push_back(Vector3D(*(Ptr + (J * ModelPtr->Stride)), *(Ptr + (J * ModelPtr->Stride + 1)), *(Ptr + (J * ModelPtr->Stride + 2))));
}
break;
}
}
}
I've also tried:
for (int I = 0; I < TriangleCount; I++)
{
cout<<"X: " << *(Pointer + (I * Stride))<<endl;
cout<<"Y: " << *(Pointer + (I * Stride + 1))<<endl;
cout<<"Z: " << *(Pointer + (I * Stride + 2))<<endl;
}