[osg-users] Optimizing memory usage by Texture of size 4096x2048

Glenn Waldron gwaldron at gmail.com
Tue Nov 19 05:48:09 PST 2013


What's the data type of your image? Show the code where you allocate the
image data.

You can also call this, which will free the CPU memory once the texture
gets to the GPU:

   texture->setUnRefImageDataAfterApply(true);


Glenn Waldron / @glennwaldron


On Tue, Nov 19, 2013 at 8:11 AM, John Moore <kaharoth at gmail.com> wrote:

> Hi,
>
> In my app I am using 2 textures of size 4096x2048.
> I have a serious problem of memory usage.
>
>
> Code:
>
> osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
>         texture->setDataVariance(osg::Object::STATIC);
>         texture->setFilter(osg::Texture::MIN_FILTER,
> osg::Texture::LINEAR_MIPMAP_LINEAR);
>         texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
>         texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);
>         texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP);
>         texture->setImage(image.release());
>
> sphere->getOrCreateStateSet()->setTextureAttributeAndModes(0,texture.get());
>
>         osg::ref_ptr<osg::Texture2D> texture2 = new osg::Texture2D;
>         texture2->setDataVariance(osg::Object::STATIC);
>         texture2->setFilter(osg::Texture::MIN_FILTER,
> osg::Texture::LINEAR_MIPMAP_LINEAR);
>         texture2->setFilter(osg::Texture::MAG_FILTER, osg::Texture::
> LINEAR);
>         texture2->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);
>         texture2->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP);
>         texture2->setImage(image2.release());
>
> sphere->getOrCreateStateSet()->setTextureAttributeAndModes(1,texture2.get());
>
>
>
>
>
> using this code my app jumps from 20 MB of memory to 250 MB of memory usage
>
> Since I am developing on mobile platform this is a huge waste of memory.
>
> I partially solved the problem by changing the MIN_FILTER from
> LINEAR_MIPMAP_LINEAR to LINEAR
> Now the memory usage is 150MB
>
> It's still a lot!
>
> Do you know a way to optimize the memory usage of these 2 textures?
>
> Thank you,
> Have a nice day (or night :) ),
>
> John
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=57295#57295
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20131119/1648b587/attachment.htm>


More information about the osg-users mailing list