Textures and pixel buffer objects

I had assumed that it would be possible to create a “dynamic texture” by storing the texture data in a pixel buffer object and then mapping that buffer to edit the data every frame. That is, I assumed it would be possible until I actually tried it. What happens is that my texture uses the initial color values - those that were present at the time glTexImage2D was called - and never reads the updated values. This surprised me since I thought OpenGL just stored textures in graphics memory, which I should be able to access with the pixel buffer object. If OpenGL does not read textures directly from graphics memory when it renders each frame, where does it actually store texture data? Does this have something to do with “resident textures”? Thanks.

PBO is just intermediate buffer during pixel transfer. When you want to change pixels in texture you must refresh texture data by glTexSubImage2D call. So…

  1. Generate texture
  2. call glTexImage2D for first time
  3. create PBO
  4. write pixels into PBO memory
  5. bind texture and call glTexSubImage2D

You can use one PBO for many textures. After glTexImage2D or glTexSubImage2D real texture data is copyed in GPU/video memory and PBO can be reused for other textures.


Thanks, Yooyo - that clears some things up. I am still curious about OpenGL’s inner workings, though. If my texture data is already stored in graphics memory (since I used a pixel buffer object), where does OpenGL copy the texture memory to in order to render it? I suspect it must be copied to some memory location that is inacessible to the user, since the texture data cannot be edited directly.

All texture and framebuffer data is accessible only through opengl functions. You can’t get “pointer” to texture or framebuffer memory.

Right. That’s what I’m wondering about. Vertex buffer objects and pixel buffer objects give you a pointer to graphics memory. Since I can’t access textures with a PBO pointer, I am thinking that they must be stored either in some other kind of memory (I only know of system memory, AGP memory, and graphics memory) or they are stored in graphics memory in such a way that PBO pointers can’t get to them. I guess part of the reason I am confused is that you can easily manipulate vertex data with a mapped VBO - why would texture data be any different? I guess this is more of a GL architecture question than it is a coding question.

Texture storage memory format may differ on various hardware. Maybe some HW use set of 256x256 texture for bigger textures, or maybe they can interleave mipmaps or convert 15, 16 & 24bit textures to 32bpp.

Vertex arrays is just array… nothing more.