1

if my vertex data was layed out

example:

struct Vertex
{
   float position[4];
   float normal[3];
   float texCoord[2];
}

i know we use

    glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_uiVertBufferHandle );

    //get the pointer position where we can add verts
    void* pPositionBuffer = glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_READ_WRITE );

    //now copy into our memory spot
    //which we need to move to the right position
    memcpy( ((char*)pPositionBuffer) + ( uiVertLocation*sizeof(VertexFormat) ), pVerts, iNumVerts*sizeof(VertexFormat));

    //now stop mapping
    glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);

for a full copy location this is how i been doing it but i just need to edit the position data of the vertices and not change any of the other attributes

i am just updating the positional data on the cpu side for some testing

struct Vertex
{
   float position[4]; <----
   float normal[3];
   float texCoord[2];
}
Franky Rivera
  • 553
  • 8
  • 20
  • You probably ought to use `GL_WRITE_ONLY` in this case, since you do not want to read the values, you just want to send GL a new one. That said, if you do this frequently you probably also want to use `glMapBufferRange (...)` and invalidation to tell GL that it can discard the old memory to minimize synchronization overhead. Since you are using ***ARB*** buffer objects, I have a feeling that is not an option (explicit buffer range invalidation is quite new). – Andon M. Coleman Feb 02 '14 at 20:51

2 Answers2

1

You could re-arrange the data in your buffer by first storing all the vertices, then all the normals and then all the texture coordinates. Then just use glMapBufferRange and map only the portion containing the vertices, and update only that portion.

Broxzier
  • 2,909
  • 17
  • 36
smani
  • 1,953
  • 17
  • 13
1

After mapping buffer you can use its memory just like any other memory in your program. For example, you can just write this code:

Vertex *cur_vertex = (Vertex *)pPositionBuffer + uiVertLocation;
for (int i = 0; i < iNumVerts; i++)
  cur_vertex[i]->position = pVerts[i]->position;

instead of memcpy

Alex Telishev
  • 2,264
  • 13
  • 15
  • i understand that part. i just mean i need to map it back. are you saying i can just grab my data back and just treat it like their format and fill those spaces. and thats it? just stop mapping and it should be fine? – Franky Rivera Feb 02 '14 at 21:20
  • When you call glUnmapBufferARB every change that you have made will be transferred back to the device, you don't need to care about anything. – Alex Telishev Feb 02 '14 at 21:25