Directly accessing texture data

Started by
7 comments, last by _the_phantom_ 18 years, 10 months ago
Hello. Is it possible to access the texture data after creating a texture (I want it to be edited in real-time). Or would it be possible to delete the texture from memory and then create a new one? Would that be really slow? Thanks!
Advertisement
You can't access the texture data directly. To modify an existing texture, you use glTexSubImage. You should not delete it and recreate it.
Quote:Original post by Brother Bob
You can't access the texture data directly.
Not entirely true, you can copy texture data from the server to the client using glGetTexImage but its probably very slow.
If you want to modify something in a texture keep a local copy of the data in an easy to edit array or similar then use glTexSubImage to update portions of the OpenGL texture (or the whole thing I guess) either way, I wouldnt expect super-performance from either method..
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
Quote:Original post by silvermace
Quote:Original post by Brother Bob
You can't access the texture data directly.
Not entirely true, you can copy texture data from the server to the client using glGetTexImage but its probably very slow.

I consider that indirect access to the texture data, not direct access which I said was not possible. As you said, it's a copy, so changing the data you get from glGetTexImage will not change the original texture, and that is not what i consider to be direct access.
Why do you need to modify it? In most cases its much better to just keep a local copy of texture in system memory if you need frequent changes. The alternative would be to use fragment program & FBO to modify it (if whole modification can be expressed as FP) fully on GPU.
You should never let your fears become the boundaries of your dreams.
Would it be possible to somehow render a lightmap on top of texture? (without multitexturing)
Quote:Original post by _DarkWIng_
Why do you need to modify it? In most cases its much better to just keep a local copy of texture in system memory if you need frequent changes. The alternative would be to use fragment program & FBO to modify it (if whole modification can be expressed as FP) fully on GPU.


I do this for my terrain texture. I generate it procedurally and keep the original data in system memory, then have some options to do additional things to the texture like toggle the blending of other [rock] textures, apply a gaussian blur, and so on. I modify the texture image data that is in system memory and then rebind the texture with the following lines:

glBindTexture(GL_TEXTURE_2D,texID);glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,imgWidth,imgHeight,0,GL_RGB,GL_UNSIGNED_BYTE,imgData);


Don't forget to do the rebind, otherwise your changes will not be loaded back to the video card memory for that texture ID.

Actually, I'm not entirely sure if this actually "overwrites" the exiting data in the video card memory for the texture ID, or something else is happening behind the scenes like continually new allocations of memory are being made. That would be bad. I've never researched the side effects of this method.

hth
F451
Nope, that's fine.

You don't allocate new memory until you call glGenTextures() and then upload
texture data to it.

As a point of reference, if your texture size doesnt change then glTexSubImage2D() is a faster method of uploading new texture data to the gfx card.

This topic is closed to new replies.

Advertisement