Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Query regarding glCopyBufferSubData()

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    6

    Query regarding glCopyBufferSubData()

    I am trying to copy data within same buffer using glCopyBufferSubData().

    array[24];

    glCopyBufferSubData(GL_ARRAY_BUFFER,GL_ARRAY_BUFFE R,sizeof(array)/2,0,sizeof(array)) ;

    glVertexAttribPointer(index,3, GL_FLOAT, GL_FALSE, 0,&array[12]);

    glDrawElements();


    Above code doesn't seem to work.

    Any suggestions ?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Ok, let's take this apart. First of all, what's array[24] supposed to hold? Are there any concrete values? If you don't specify any the values are undefined. Second, what's the type of the array elements?

    Code :
    glCopyBufferSubData(GL_ARRAY_BUFFER,GL_ARRAY_BUFFE  R,sizeof(array)/2,0,sizeof(array)) ;

    Do you honestly need to determine the offsets and size of the copy operation by deducing from a fixed size array? How can you be sure that sizeof(array) is actually a valid size and that sizeof(array)/2 + sizeof(array) isn't out of range? Equivalent code, which is much more readable, would be:

    Code :
    GLintptr bufferSize = numElements * sizeof(elementType);
    GLintptr readOffset = bufferSize >> 1;
     
    glCopyBufferSubData(GL_ARRAY_BUFFER, GL_ARRAY_BUFFER, readOffset, 0, bufferSize) ;

    I suppose you simply have a buffer of 24 elements and want to copy the second half to the first half. Is that correct?

    Regarding the second call, do you want legacy vertex arrays or do you want to render using vertex buffer objects?

    Please clarify your intent.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    6
    Quote Originally Posted by thokra View Post
    Ok, let's take this apart. First of all, what's array[24] supposed to hold? Are there any concrete values? If you don't specify any the values are undefined. Second, what's the type of the array elements?


    Code :
    glCopyBufferSubData(GL_ARRAY_BUFFER,GL_ARRAY_BUFFE  R,sizeof(array)/2,0,sizeof(array)) ;

    Do you honestly need to determine the offsets and size of the copy operation by deducing from a fixed size array? How can you be sure that sizeof(array) is actually a valid size and that sizeof(array)/2 + sizeof(array) isn't out of range? Equivalent code, which is much more readable, would be:



    Code :
    GLintptr bufferSize = numElements * sizeof(elementType);
    GLintptr readOffset = bufferSize >> 1;
     
    glCopyBufferSubData(GL_ARRAY_BUFFER, GL_ARRAY_BUFFER, readOffset, 0, bufferSize) ;

    I suppose you simply have a buffer of 24 elements and want to copy the second half to the first half. Is that correct?

    Regarding the second call, do you want legacy vertex arrays or do you want to render using vertex buffer objects?

    Please clarify your intent.

    1) The values in the array are concrete for sure.

    2) The values are all within limits. I have done proper error checking in actual code

    3) I wish to render using VBO only , but if the data is in second half ( glCopyBufferSubData will be slightly different in that case ) , nothing is rendered. Either glCopyBufferSubData() fails ( surprisingly no error on NVidia driver ) or glVertexAttribPointer() fails.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Well, think about what &array[12] means as an offset into the vertex buffer's data store. The pointer returned by &array[12] is an address to a stack allocated memory location. What you need is a valid byte offset. For instance, if you store 24 float values and you need to start at the second half of the buffer, your offset would simply be (const GLvoid*)(12 * sizeof(GLfloat)) and not &array[12].
    Last edited by thokra; 10-09-2012 at 02:35 AM.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    6
    You got it right man :-)
    Huge mistake !
    Thanks for the reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •