[osg-users] Questions about mip maps

20 views
Skip to first unread message

Aurelien Albert

unread,
Dec 14, 2012, 6:08:01 PM12/14/12
to osg-...@lists.openscenegraph.org
Hi,

I have a set of pre-computed procedurals textures, and my texture generation system can produce high-quality downsampled textures.

So I would like to use them as mipmaps for my textures :

- is it possible to allocate and load mipmaps from CPU, just like we load an osg::Image into an osg::Texture2D ?

- is there any example of that ?

- is it mandatory that each mipmap level is exactly half size of the previous ?

- is it mandatory that texture size is a power of two ? how to deal with odd texture size ? (or odd n-th mipmap size) ?

Thank you!

Cheers,
Aurelien

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51590#51590





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Jason Daly

unread,
Dec 14, 2012, 7:16:28 PM12/14/12
to osg-...@lists.openscenegraph.org
On 12/14/2012 06:08 PM, Aurelien Albert wrote:
> Hi,
>
> I have a set of pre-computed procedurals textures, and my texture generation system can produce high-quality downsampled textures.
>
> So I would like to use them as mipmaps for my textures :
>
> - is it possible to allocate and load mipmaps from CPU, just like we load an osg::Image into an osg::Texture2D ?

Yes. As far as I know, the way to do it is to pass the entire set of
images (with the mipmaps) to osg::Image::setData(), then call
osg::Image::setMipmapLevels() with a vector indicating the byte offset
to the start of each of the mipmaps.


> - is there any example of that ?

The only example I know of off the top of my head is in the DDS plugin
(search for the call to setMipmapLevels to see where). There are
probably others, too.


> - is it mandatory that each mipmap level is exactly half size of the previous ?

Not exactly, but each successive level should be an integer quotient of
the previous level's size and two. They don't need to be powers of two
either, as long as you're targeting relatively recent hardware.

Essentially, you take the floor of size/2 to get the size of the next
level. Say you start with a size of 999. The mip levels would then be
499, 249, 124, 62, 31, 15, 7, and 3.

The textures also don't need to be square. The mip levels stop when any
of the dimensions reaches 1, so you shouldn't create any mipmaps that
are, for example, 4x1.

Hope this helps!

--"J"

Jason Daly

unread,
Dec 14, 2012, 7:20:22 PM12/14/12
to osg-...@lists.openscenegraph.org
On 12/14/2012 07:16 PM, Jason Daly wrote:
> The textures also don't need to be square. The mip levels stop when
> any of the dimensions reaches 1, so you shouldn't create any mipmaps
> that are, for example, 4x1.

Actually, this isn't exactly correct. You should create mipmaps until
you get to a size with a 1 pixel dimension, and then you should stop,
so, for example, a 63x21 texture would have mipmaps of 31x10, 15x5, 7x2,
and 2x1 (but not 1x1).

Aurelien Albert

unread,
Dec 15, 2012, 6:10:09 AM12/15/12
to osg-...@lists.openscenegraph.org
Thanks a lot for this very precise answer !

Just one more question, you said :


> each successive level should be an integer quotient of
> the previous level's size and two


So, for n-th level, the size should be :

(size of n-1 level) / (2*k) with arbitrary k ?

Is it possible to have multiple levels with the same size ?

For example :

Texture : 512x512
Level 1 : 256x256
Level 2 : 256x256
Level 3 : 256x256
Level 4 : 256x256
Level 5 : 128x128
Level 6 : 128x128
Level 7 : 128x128
Level 8 : 128x128
Level 9 : 1x1

Mipmaps levels stop here.

I know this is a little weird, but my procedural textures can be generated for any size and any "distance", so in my case tghis should be interesting to have mulitple levels with the same texture resolution, but different "spatial resolution" inside the texture.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51594#51594

Daly, Jason

unread,
Dec 16, 2012, 3:54:43 PM12/16/12
to osg-...@lists.openscenegraph.org
No, OpenGL requires all dimensions to be reduced by half at each level.


Sent from my cell phone

Aurelien Albert <aurelie...@alyotech.fr> wrote:
Reply all
Reply to author
Forward
0 new messages