Sign in to follow this  
ImperfectFreak

Non-Contigious Texture Sub-Imaging

Recommended Posts

That sounds impressive. Basically I just want to know what the fastest way to do this is. Basically I want to replace sections of one texture with data. I attempted using glTexSubImage2D, only it needs contiguous memory. My question is would it be fastest to rebuild the entire texture, or go one line at a time with glTexSubImage2D for the height of the little bit of data I want to add, or should I somehow get the texture data of the original texture and fill it in where needed.

Share this post


Link to post
Share on other sites
Check out the unpack pixel store modes. In particular, look at glPixelStore and the parameters GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_ROWS and GL_UNPACK_SKIP_PIXELS. Then use glTexSubImage.

Share this post


Link to post
Share on other sites
They allow you to specify a region of the source data to use in a larger image. Say you have a 256x256 image, and a 64x64 subimage inside it you want to reference. The subimage starts on row 10, 20 pixels into the image.

glPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 10);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 20);

Passing the pointer to the image and reading a 64x64 subimage will now correctly extract the subimage from the larger image. The settings mean that after each row is read, skip pixels as if the image is 256 pixels wide, to reach the start of the next row. Before reading, skip 10 rows and another 20 pixels.

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