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 4 of 4

Thread: partial texture transfers using PBOs

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    2

    partial texture transfers using PBOs

    Hello,

    I'm using PBOs to transfer texture data from system memory to the GPU.
    I'm basically following the tutorial here:
    http://www.mathematik.uni-dortmund.d...ml#pbodownload

    Except, I'm modifying the code to only transfer a region of the texture:

    Code :
    struct Rect
    {
    int x;          // bottom-left corner of the rectangle (assuming lower-left origin)
    int y; 
     
    int nx;         // height and width of the rectangle
    int ny;
    };
     
    Rect dirtyRect; // region of the texture to update
     
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, ioBuf[array]);
    glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, dirtyRect.nx*dirtyRect.ny*sizeof(float), 
                            NULL, GL_STREAM_DRAW);
    void* ioMem = glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY);
    assert(ioMem); 
     
    // modified to copy only the portion of data specified by dirtyRect...
    copy(chunks[chunk][array], ioMem);
     
     
    glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB);
    glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, dirtyRect.x, dirtyRect.y, dirtyRect.nx, dirtyRect.ny, 
                    GL_LUMINANCE, GL_FLOAT, BUFFER_OFFSET(0));
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);


    This seems to work when the format of the texture is GL_RGBA and the type of data is GL_UNSIGNED_BYTE, however it does not always work when the format is GL_LUMINANCE_ALPHA. Sometimes it succeeds, and sometimes GL_INVALID_OPERATION is returned from the glTexSubImage call. (This is on a Quadro 4800) The success of the operation seems to be dependent on the region of the texture to be uploaded.

    The docs on glBufferData aren’t clear to me as to what should be specified for the size argument. Should it be the size of the dirty region passed into glTexSubImage? Or should it be the whole texture?

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: partial texture transfers using PBOs

    It could be a byte alignment issue, where previously you 'got away with it' via a 4-byte RGBA format.
    Now that you are using LUMINANCE_ALPHA (2 byte) you may need to specify a different pack alignment:

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    or
    glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
    should get the job done.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    2

    Re: partial texture transfers using PBOs

    Ah, yeah, that was the problem. Setting the unpack alignment fixes the problem. Thanks so much!

  4. #4
    Member Regular Contributor
    Join Date
    Apr 2007
    Posts
    271

    Re: partial texture transfers using PBOs

    It probably also "sometimes" succeeds if the width is even.

    The reason is alignment depends not only on the number of components, the size in bytes of the type of the component but also depends on the width of a row.

    I usually uses this kind of code to determine the optimal value for alignment (it goes from 1 (slowest) to 8 (fastest)):
    Code :
    int components; // 1,2,3,4
    int width;
     
    // row size in bytes
    int rowsize=components*sizeof(component_type)*width;
     
    int alignment;
    if(rowsize%8==0) {
      alignment=8;
    } else {
      if(rowsize%4==0) {
        alignment=4;
      } else {
        if(rowsize%2==0) {
          alignment=2;
        } else {
          alignment=1;
        }
      }
    }

Posting Permissions

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