0
votes

Well i have a texture that is generated every frame and I was wondering the best way to render it in opengl. It is simply pixel data that is generated on the cpu in rgba8 (32-bit, 8 bit for each component) format, I simply need to transfer it to the gpu and draw it onto the screen. I remember there being some sort of pixel buffer or frame buffer that does this without having to generate a new texture every frame in association with glTexImage2d?

1
only needs to be allocated one time after that you just need to upload it when it changes - ratchet freak
@ratchetfreak: Which is every frame. - Andon M. Coleman
but it's not generating but copying - ratchet freak
Well i've tried simply using glTexImage2D to "upload" the data, but it doesn't stick. It still keeps the original image's data. - razr32
On a side note no where have i ever said that glTexImage2D generates images... I said i have an external system, in which has no affiliation with OpenGL, that generates the image and that image is the one i need displayed using OpenGL. And by generate a new texture I mean the glGenTexture() function. - razr32

1 Answers

3
votes

Pixel Buffer Objects do not change the fact that you need to call glTexImage2D (...) to (re-)allocate texture storage and copy your image. PBOs provide a means of asynchronous pixel transfer - basically making it so that a call to glTexImage2D (...) does not have to block until it finishes copying your memory from the client (CPU) to the server (GPU).


The only way this is really going to improve performance for you is if you map the memory in a PBO (Pixel Unpack Buffer) and write to that mapped memory every frame while you are computing the image on the CPU.

While that buffer is bound to GL_PIXEL_UNPACK_BUFFER, call glTexImage2D (...) with NULL for the data parameter and this will upload your texture using memory that is already owned by the server, so it avoids an immediate client->server copy. You might get a marginal improvement in performance by doing this, but do not expect anything huge. It depends on how much work you do between the time you map/unmap the buffer's memory and when you upload the buffer to your texture and use said texture.

Moreover, if you call glTexSubImage2D (...) every frame instead of allocating new texture image storage by calling glTexImage2D (...) (do not worry -- the old storage is reclaimed when no pending command is using it anymore) you may introduce a new source of synchronization overhead that could reduce your performance. What you are looking for here is known as buffer object streaming.

You are more likely to improve performance by using a pixel format that requires no conversion. Newer versions of GL (4.2+) let you query the optimal pixel transfer format using glGetInternalFormativ (...).


mostly pedantic noteglTexImage2D (...)does not generate texturesboundglBindTexture (...)glTexImage2D (...)