Texture Subloading

Sometimes it's useful to only change a portion of a texture at a time.

This is accomplished using the function glTexSubImage2D().

Base texture (glTexImage2D) Sub texture (glTexSubImage2D) Result
==>

One use of subloading is when the size of the texture image is not a power of 2; subloading avoids the need to resize the image data before using it.

One can create a base texture with a size that is a power of 2, subload the real image data into a portion of the full texture, and then assign appropriate texture coordinates so that only the desired portion of the texture is seen.

texture coordinates (0, 0) - (1, 1) texture coordinates (0, 0) - (0.625, 0.9375)

I have added a new function to the dms::Texture2D class - subload() - for this feature.
To use it, assign an initial image to the texture & call define(). Then, you can later assign a different image to the texture and call subload(). Make sure that the new, subloaded image is no larger than the original image.

Example: subload.cpp



next