Sign in to follow this  
indigox3

partial texture transfers using PBOs

Recommended Posts

Hello,

I'm using PBOs to transfer texture data from system memory to the GPU.
I'm basically following the tutorial here: [url="http://www.mathematik.uni-dortmund.de/%7Egoeddeke/gpgpu/tutorial3.html#pbodownload"]http://www.mathemati...tml#pbodownload[/url]
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);
[/code]

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this