Jump to content
  • Advertisement
Sign in to follow this  
Giedrius

Directly accessing texture data

This topic is 4877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Nope, that's fine.

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!