10-03-2010, 12:16 AM
Is it possible to design a texture loader that reads in one mipmap at a time with OpenGL? I ask because textures that use the mipmap filter must be mipmap-complete, and there is no way to shift the array of mipmaps as the next one is loaded:
Frame 3 (texture is done loading)
10-03-2010, 12:39 AM
Is it possible to design a texture loader that reads in one mipmap at a time with OpenGL?
Each texture object has two parameters that control what mipmaps OpenGL will sample from. The GL_TEXTURE_BASE_LEVEL defines what the largest mipmap level is, and GL_TEXTURE_MAX_LEVEL defines what the smallest one is. Let's use your texture as an example.
The final texture size is 64x64. So when it's fully loaded, that will be the texture's overall size.
On frame 1, you have loaded the smallest two mipmap levels. Since the final size is 64x64, the 2x2 mip level's number is 5 (0 is 64x64, 1 is 32x32, etc) and the 1x1 is 6.
So on frame 1, you make two calls to glTexImage2d, loading the 2x2 image to mip level 5 and the 1x1 to mip level 6. Then you set set the base level to 5, and the max level to 6 with glTexParameter.
On frame 2, you make two more glTexImage2d calls, loading mip levels 3 and 4. Then you change the base level to 3.
And on frame 3, you load mip levels 0, 1, and 2, then change the base level to 0.
Note: when you first create the texture, you may want to call glTexImage2d for the unfilled mipmap levels, with NULL as the data parameter. This will tell OpenGL to reserve the memory for it if it doesn't already. Afterwards, you can just call glTexSubImage2d to upload the image data.
10-07-2010, 02:43 PM
Oh, I did not know you can change the base level. Cool, thanks.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.