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

2014-04-01 Thread John Moore
Sorry I missed the answers because of my email settings.
However they are still useful. Thank you very much.

John

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





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


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

2013-11-21 Thread Robert Osfield
Hi John,

I'll add some general comments as others have already provide quite a few
responses.

In OpenGL when you create a texture object you first have the memory for
the imagery in the applications main memory, when you (via osg::Texture2D)
pass that image data to OpenGL fifo, then afterwards the the driver takes
the data from the fifo and creates an internal representation of that data
that is suitable for passing directly to the graphics hardware.  This
representation may have different pixel format depending upon the hardware
and the texture settings you used, and also may create mipmaps for you.
 Finally when the actual texture is needed on the GPU it'll be copied to
local memory on the graphics card.   The result of this pipeline is several
copies of your data, it's not a bug, but just the way that OpenGL/hardware
manages things.

The Texture::setUnRefImageAfterApply(true) usage tells the OSG to unref the
image after the data has been passed into the OpenGL fifo, and as long as
no other references are kept to the osg::Image this data will be deleted so
getting rid of one copy of the data which is why it helps.

Another aspect to take into account is that files on disk that are
compressed in .jpeg etc. are all much smaller than they are once they are
loaded into memory.  However, if you use an OpenGL compressed format such
as S3TC then it'll be stored in a format that you can pass directly to
OpenGL without any unpacking, here the memory usage will be consistent from
disk to OSG memory to driver memory and to the GPU memory, with a caveat
that if you generate mipmaps at runtime this will increase the footprint by
around 40%.

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


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

2013-11-19 Thread John Moore
Hi,

In my app I am using 2 textures of size 4096x2048.
I have a serious problem of memory usage. 


Code:

osg::ref_ptrosg::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_ptrosg::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@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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

2013-11-19 Thread Ulrich Hertlein

Hi John,

Quoting John Moore kahar...@gmail.com:

In my app I am using 2 textures of size 4096x2048.
I have a serious problem of memory usage.

...

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?


You can set 'osg::Texture::setUnRefImageDataAfterApply' on the texture  
if you don't need to keep the osg::Image in memory.


Cheers,
/ulrich


pgpxWspjKSkbs.pgp
Description: PGP Digital Signature
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


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

2013-11-19 Thread Glenn Waldron
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 kahar...@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_ptrosg::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_ptrosg::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@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

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


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

2013-11-19 Thread John Moore
Thank you Gwaldron,
that line of code saved me 40MB. Better than nothing. Now the memory usage is 
around 110 MB.

The format of the image is JPG.
I tried to use PVR but I can't load the image.

This is the complete function (updated with your suggestion) that I use to 
create a sphere with 2 textures.
Then I use a shader to cross fade between the two textures that's why I 
need to have both of them in memory.


Code:

- (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString 
*)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray
{
osg::ref_ptrosg::Geode sphere = new osg::Geode();
sphere-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), 
ray)));
sphere-setName(BubbleNode);

// load image for texture
osg::ref_ptrosg::Image todayImage = 
osgDB::readImageFile(todayTextName.UTF8String);
osg::ref_ptrosg::Image pastImage = 
osgDB::readImageFile(pastTextName.UTF8String);

if (!todayImage || !pastImage)
{
std::cout  Couldn't load texture.  std::endl;
}
else
{
osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;
texture-setDataVariance(osg::Object::STATIC);
texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::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(todayImage.release());
texture-setUnRefImageDataAfterApply(true);

sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get());

osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D;
texture2-setDataVariance(osg::Object::STATIC);
texture2-setFilter(osg::Texture::MIN_FILTER, osg::Texture::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(pastImage.release());
texture-setUnRefImageDataAfterApply(true); 

sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get());

}
return sphere;
}



and then I call this to add the sphere

Code:

osg::ref_ptrosg::Geode sphere = [self 
createSphereWithTodayImage:pathofimage1.jpg pastImage:pathofimage2.jpg 
andRay:1.0f];
_root-addChild(sphere.get());
_root-setDataVariance( osg::Object::DYNAMIC);






gwaldron wrote:
 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  () wrote:
 
   Hi,
  
  In my app I am using 2 textures of size 4096x2048.
  I have a serious problem of memory usage.
  
  
  Code:
  
  osg::ref_ptrosg::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_ptrosg::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 
  (http://forum.openscenegraph.org/viewtopic.php?p=57295#57295)
  
  
  
  
  
  ___
  osg-users mailing list
   ()
  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 
  

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

2013-11-19 Thread Glenn Waldron
110MB -- CPU or GPU memory? For the entire app or just your textures?

Quick math:
2 * 4096 * 2048 * 4 * 1.3 = 87MB.
(4 = RGBA, 1.3 = mipmaps)



Glenn Waldron / @glennwaldron


On Tue, Nov 19, 2013 at 9:18 AM, John Moore kahar...@gmail.com wrote:

 Thank you Gwaldron,
 that line of code saved me 40MB. Better than nothing. Now the memory usage
 is around 110 MB.

 The format of the image is JPG.
 I tried to use PVR but I can't load the image.

 This is the complete function (updated with your suggestion) that I use to
 create a sphere with 2 textures.
 Then I use a shader to cross fade between the two textures that's why
 I need to have both of them in memory.


 Code:

 - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString
 *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray
 {
 osg::ref_ptrosg::Geode sphere = new osg::Geode();
 sphere-addDrawable(new osg::ShapeDrawable(new
 osg::Sphere(osg::Vec3(), ray)));
 sphere-setName(BubbleNode);

 // load image for texture
 osg::ref_ptrosg::Image todayImage =
 osgDB::readImageFile(todayTextName.UTF8String);
 osg::ref_ptrosg::Image pastImage =
 osgDB::readImageFile(pastTextName.UTF8String);

 if (!todayImage || !pastImage)
 {
 std::cout  Couldn't load texture.  std::endl;
 }
 else
 {
 osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;
 texture-setDataVariance(osg::Object::STATIC);
 texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::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(todayImage.release());
 texture-setUnRefImageDataAfterApply(true);

 sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get());

 osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D;
 texture2-setDataVariance(osg::Object::STATIC);
 texture2-setFilter(osg::Texture::MIN_FILTER,
 osg::Texture::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(pastImage.release());
 texture-setUnRefImageDataAfterApply(true);

 sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get());

 }
 return sphere;
 }



 and then I call this to add the sphere

 Code:

 osg::ref_ptrosg::Geode sphere = [self
 createSphereWithTodayImage:pathofimage1.jpg pastImage:pathofimage2.jpg
 andRay:1.0f];
 _root-addChild(sphere.get());
 _root-setDataVariance( osg::Object::DYNAMIC);






 gwaldron wrote:
  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  () wrote:
 
Hi,
  
   In my app I am using 2 textures of size 4096x2048.
   I have a serious problem of memory usage.
  
  
   Code:
  
   osg::ref_ptrosg::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_ptrosg::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:
   

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

2013-11-19 Thread John Moore
Memory usage is for the entire app.
However memory usage of the same scene if I don’t load the texture is 20 MB. So 
I can safely assume the rest is consumed by the fact the textures are applied 
to the sphere.


gwaldron wrote:
 110MB -- CPU or GPU memory? For the entire app or just your textures?
 
 Quick math:
 2 * 4096 * 2048 * 4 * 1.3 = 87MB.
 (4 = RGBA, 1.3 = mipmaps)
 
 
 
 
 
 Glenn Waldron / @glennwaldron
 
 
 On Tue, Nov 19, 2013 at 9:18 AM, John Moore  () wrote:
 
   Thank you Gwaldron,
  that line of code saved me 40MB. Better than nothing. Now the memory usage 
  is around 110 MB.
  
  The format of the image is JPG.
  I tried to use PVR but I can't load the image.
  
  This is the complete function (updated with your suggestion) that I use to 
  create a sphere with 2 textures.
  Then I use a shader to cross fade between the two textures that's why I 
  need to have both of them in memory.
  
  
  Code:
  
  - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString 
  *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray
  {
      osg::ref_ptrosg::Geode sphere = new osg::Geode();
      sphere-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), 
  ray)));
      sphere-setName(BubbleNode);
  
      // load image for texture
      osg::ref_ptrosg::Image todayImage = 
  osgDB::readImageFile(todayTextName.UTF8String);
      osg::ref_ptrosg::Image pastImage = 
  osgDB::readImageFile(pastTextName.UTF8String);
  
      if (!todayImage || !pastImage)
      {
          std::cout  Couldn't load texture.  std::endl;
      }
      else
      {
          osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;
          texture-setDataVariance(osg::Object::STATIC);
  
          texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::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(todayImage.release());
          texture-setUnRefImageDataAfterApply(true);
          
  sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get());
  
          osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D;
          texture2-setDataVariance(osg::Object::STATIC);
  
          texture2-setFilter(osg::Texture::MIN_FILTER, osg::Texture::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(pastImage.release());
          texture-setUnRefImageDataAfterApply(true);
          
  sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get());
  
      }
      return sphere;
  }
  
  
  
  and then I call this to add the sphere
  
  Code:
  
  osg::ref_ptrosg::Geode sphere = [self 
  createSphereWithTodayImage:pathofimage1.jpg pastImage:pathofimage2.jpg 
  andRay:1.0f];
  _root-addChild(sphere.get());
  _root-setDataVariance( osg::Object::DYNAMIC);
  
  
  
  
  
  
  gwaldron wrote:
  
   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  () wrote:
   
   
 Hi,

In my app I am using 2 textures of size 4096x2048.
I have a serious problem of memory usage.


Code:

osg::ref_ptrosg::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_ptrosg::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 
 

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

2013-11-19 Thread Glenn Waldron
Your only further recourse would be to take Luc's advice and DXT-compress
the data on disk (using NVTT e.g.); that will give you 4:1 savings.

Ref:
http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison


Glenn Waldron / @glennwaldron


On Tue, Nov 19, 2013 at 9:51 AM, John Moore kahar...@gmail.com wrote:

 Memory usage is for the entire app.
 However memory usage of the same scene if I don’t load the texture is 20
 MB. So I can safely assume the rest is consumed by the fact the textures
 are applied to the sphere.


 gwaldron wrote:
  110MB -- CPU or GPU memory? For the entire app or just your textures?
 
  Quick math:
  2 * 4096 * 2048 * 4 * 1.3 = 87MB.
  (4 = RGBA, 1.3 = mipmaps)
 
 
 
 
 
  Glenn Waldron / @glennwaldron
 
 
  On Tue, Nov 19, 2013 at 9:18 AM, John Moore  () wrote:
 
Thank you Gwaldron,
   that line of code saved me 40MB. Better than nothing. Now the memory
 usage is around 110 MB.
  
   The format of the image is JPG.
   I tried to use PVR but I can't load the image.
  
   This is the complete function (updated with your suggestion) that I
 use to create a sphere with 2 textures.
   Then I use a shader to cross fade between the two textures that's
 why I need to have both of them in memory.
  
  
   Code:
  
   - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString
 *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray
   {
   osg::ref_ptrosg::Geode sphere = new osg::Geode();
   sphere-addDrawable(new osg::ShapeDrawable(new
 osg::Sphere(osg::Vec3(), ray)));
   sphere-setName(BubbleNode);
  
   // load image for texture
   osg::ref_ptrosg::Image todayImage =
 osgDB::readImageFile(todayTextName.UTF8String);
   osg::ref_ptrosg::Image pastImage =
 osgDB::readImageFile(pastTextName.UTF8String);
  
   if (!todayImage || !pastImage)
   {
   std::cout  Couldn't load texture.  std::endl;
   }
   else
   {
   osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;
   texture-setDataVariance(osg::Object::STATIC);
  
   texture-setFilter(osg::Texture::MIN_FILTER,
 osg::Texture::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(todayImage.release());
   texture-setUnRefImageDataAfterApply(true);
  
 sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get());
  
   osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D;
   texture2-setDataVariance(osg::Object::STATIC);
  
   texture2-setFilter(osg::Texture::MIN_FILTER,
 osg::Texture::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(pastImage.release());
   texture-setUnRefImageDataAfterApply(true);
  
 sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get());
  
   }
   return sphere;
   }
  
  
  
   and then I call this to add the sphere
  
   Code:
  
   osg::ref_ptrosg::Geode sphere = [self
 createSphereWithTodayImage:pathofimage1.jpg pastImage:pathofimage2.jpg
 andRay:1.0f];
   _root-addChild(sphere.get());
   _root-setDataVariance( osg::Object::DYNAMIC);
  
  
  
  
  
  
   gwaldron wrote:
  
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  () wrote:
   
   
  Hi,

 In my app I am using 2 textures of size 4096x2048.
 I have a serious problem of memory usage.


 Code:

 osg::ref_ptrosg::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_ptrosg::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);
 

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

2013-11-19 Thread John Moore
I am not very concerned about disk usage. I am more concerned about RAM. Will 
be there any advantages using this kind of compression? If yes how can I 
compress and then load the data in a osg::Image?

I am asking because I tried to do the compression with PVR (using 
PVRTexToolGUI) but I was not able to load it in a osg::Image.

Thank you.

John


gwaldron wrote:
 Your only further recourse would be to take Luc's advice and DXT-compress the 
 data on disk (using NVTT e.g.); that will give you 4:1 savings.
 
 Ref:
 http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison 
 (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison) 
 
 
 
 Glenn Waldron / @glennwaldron
 
 
 On Tue, Nov 19, 2013 at 9:51 AM, John Moore  () wrote:
 
   Memory usage is for the entire app.
  However memory usage of the same scene if I don’t load the texture is 20 
  MB. So I can safely assume the rest is consumed by the fact the textures 
  are applied to the sphere.
  
  
  gwaldron wrote:
  
   110MB -- CPU or GPU memory? For the entire app or just your textures?
   
   Quick math:
   2 * 4096 * 2048 * 4 * 1.3 = 87MB.
   (4 = RGBA, 1.3 = mipmaps)
   
   
   
   
   
   Glenn Waldron / @glennwaldron
   
   
   
  
  
   On Tue, Nov 19, 2013 at 9:18 AM, John Moore  () wrote:
   
   
 Thank you Gwaldron,
that line of code saved me 40MB. Better than nothing. Now the memory 
usage is around 110 MB.

The format of the image is JPG.
I tried to use PVR but I can't load the image.

This is the complete function (updated with your suggestion) that I use 
to create a sphere with 2 textures.
Then I use a shader to cross fade between the two textures that's 
why I need to have both of them in memory.


Code:

- (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString 
*)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray
{
    osg::ref_ptrosg::Geode sphere = new osg::Geode();
    sphere-addDrawable(new osg::ShapeDrawable(new 
osg::Sphere(osg::Vec3(), ray)));
    sphere-setName(BubbleNode);

    // load image for texture
    osg::ref_ptrosg::Image todayImage = 
osgDB::readImageFile(todayTextName.UTF8String);
    osg::ref_ptrosg::Image pastImage = 
osgDB::readImageFile(pastTextName.UTF8String);

    if (!todayImage || !pastImage)
    {
        std::cout  Couldn't load texture.  std::endl;
    }
    else
    {

   
  
  
   
        osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;
        texture-setDataVariance(osg::Object::STATIC);


   
  
  
   
        texture-setFilter(osg::Texture::MIN_FILTER, 
osg::Texture::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(todayImage.release());
        texture-setUnRefImageDataAfterApply(true);
        
sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get());

        osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D;
        texture2-setDataVariance(osg::Object::STATIC);


   
  
  
   
        texture2-setFilter(osg::Texture::MIN_FILTER, 
osg::Texture::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(pastImage.release());
        texture-setUnRefImageDataAfterApply(true);
        
sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get());

    }
    return sphere;
}



and then I call this to add the sphere

Code:

osg::ref_ptrosg::Geode sphere = [self 
createSphereWithTodayImage:pathofimage1.jpg 
pastImage:pathofimage2.jpg andRay:1.0f];
_root-addChild(sphere.get());
_root-setDataVariance( osg::Object::DYNAMIC);






gwaldron wrote:


 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  () wrote:
 
 
 

   
  
  
   

 
   Hi,
  
  In my app I am using 2 textures of size 4096x2048.
  I have a serious problem of memory usage.
  
  
  Code:
  
  osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;

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

2013-11-19 Thread Glenn Waldron
It stays compressed in memory (CPU and GPU), so you get 4:1 compression in
the app, not just on disk.

No experience with PVR; is it Apple only?


Glenn Waldron / @glennwaldron


On Tue, Nov 19, 2013 at 10:25 AM, John Moore kahar...@gmail.com wrote:

 I am not very concerned about disk usage. I am more concerned about RAM.
 Will be there any advantages using this kind of compression? If yes how can
 I compress and then load the data in a osg::Image?

 I am asking because I tried to do the compression with PVR (using
 PVRTexToolGUI) but I was not able to load it in a osg::Image.

 Thank you.

 John


 gwaldron wrote:
  Your only further recourse would be to take Luc's advice and
 DXT-compress the data on disk (using NVTT e.g.); that will give you 4:1
 savings.
 
  Ref:
 
 http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison(
 http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison
 )
 
 
 
  Glenn Waldron / @glennwaldron
 
 
  On Tue, Nov 19, 2013 at 9:51 AM, John Moore  () wrote:
 
Memory usage is for the entire app.
   However memory usage of the same scene if I don’t load the texture is
 20 MB. So I can safely assume the rest is consumed by the fact the textures
 are applied to the sphere.
  
  
   gwaldron wrote:
  
110MB -- CPU or GPU memory? For the entire app or just your textures?
   
Quick math:
2 * 4096 * 2048 * 4 * 1.3 = 87MB.
(4 = RGBA, 1.3 = mipmaps)
   
   
   
   
   
Glenn Waldron / @glennwaldron
   
   
   
  
  
On Tue, Nov 19, 2013 at 9:18 AM, John Moore  () wrote:
   
   
  Thank you Gwaldron,
 that line of code saved me 40MB. Better than nothing. Now the
 memory usage is around 110 MB.

 The format of the image is JPG.
 I tried to use PVR but I can't load the image.

 This is the complete function (updated with your suggestion) that
 I use to create a sphere with 2 textures.
 Then I use a shader to cross fade between the two textures
 that's why I need to have both of them in memory.


 Code:

 - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString
 *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray
 {
 osg::ref_ptrosg::Geode sphere = new osg::Geode();
 sphere-addDrawable(new osg::ShapeDrawable(new
 osg::Sphere(osg::Vec3(), ray)));
 sphere-setName(BubbleNode);

 // load image for texture
 osg::ref_ptrosg::Image todayImage =
 osgDB::readImageFile(todayTextName.UTF8String);
 osg::ref_ptrosg::Image pastImage =
 osgDB::readImageFile(pastTextName.UTF8String);

 if (!todayImage || !pastImage)
 {
 std::cout  Couldn't load texture.  std::endl;
 }
 else
 {

   
  
  
   
 osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;
 texture-setDataVariance(osg::Object::STATIC);


   
  
  
   
 texture-setFilter(osg::Texture::MIN_FILTER,
 osg::Texture::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(todayImage.release());
 texture-setUnRefImageDataAfterApply(true);

 sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get());

 osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D;
 texture2-setDataVariance(osg::Object::STATIC);


   
  
  
   
 texture2-setFilter(osg::Texture::MIN_FILTER,
 osg::Texture::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(pastImage.release());
 texture-setUnRefImageDataAfterApply(true);

 sphere-getOrCreateStateSet()-setTextureAttributeAndModes(1,texture2.get());

 }
 return sphere;
 }



 and then I call this to add the sphere

 Code:

 osg::ref_ptrosg::Geode sphere = [self
 createSphereWithTodayImage:pathofimage1.jpg pastImage:pathofimage2.jpg
 andRay:1.0f];
 _root-addChild(sphere.get());
 _root-setDataVariance( osg::Object::DYNAMIC);






 gwaldron wrote:


  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  () wrote:
 
 
 

   
  
  

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

2013-11-19 Thread John Moore
Cool, how can use it?

PVR is not Apple.
It's by PowerVR GRaphics. It's optimized for the Power VR GPUs that are mounted 
on most of the mobile devices like iPhone or iPad.

However I can't understand how to use it in OpenSceneGRaph.


gwaldron wrote:
 It stays compressed in memory (CPU and GPU), so you get 4:1 compression in 
 the app, not just on disk.
 
 No experience with PVR; is it Apple only?
 
 
 
 Glenn Waldron / @glennwaldron
 
 
 On Tue, Nov 19, 2013 at 10:25 AM, John Moore  () wrote:
 
   I am not very concerned about disk usage. I am more concerned about RAM. 
  Will be there any advantages using this kind of compression? If yes how can 
  I compress and then load the data in a osg::Image?
  
  I am asking because I tried to do the compression with PVR (using 
  PVRTexToolGUI) but I was not able to load it in a osg::Image.
  
  Thank you.
  
  John
  
  
  gwaldron wrote:
  
   Your only further recourse would be to take Luc's advice and DXT-compress 
   the data on disk (using NVTT e.g.); that will give you 4:1 savings.
   
   Ref:
   
  
  
   http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison

   (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison)

   (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison

   (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison))
   
   
   
   Glenn Waldron / @glennwaldron
   
   
   On Tue, Nov 19, 2013 at 9:51 AM, John Moore  () wrote:
   
   
 Memory usage is for the entire app.
However memory usage of the same scene if I don’t load the texture is 
20 MB. So I can safely assume the rest is consumed by the fact the 
textures are applied to the sphere.


gwaldron wrote:


 110MB -- CPU or GPU memory? For the entire app or just your textures?
 
 Quick math:
 2 * 4096 * 2048 * 4 * 1.3 = 87MB.
 (4 = RGBA, 1.3 = mipmaps)
 
 
 
 
 
 Glenn Waldron / @glennwaldron
 
 
 
 



 On Tue, Nov 19, 2013 at 9:18 AM, John Moore  () wrote:
 
 
 
   Thank you Gwaldron,
  that line of code saved me 40MB. Better than nothing. Now the 
  memory usage is around 110 MB.
  
  The format of the image is JPG.
  I tried to use PVR but I can't load the image.
  
  This is the complete function (updated with your suggestion) that I 
  use to create a sphere with 2 textures.
  Then I use a shader to cross fade between the two textures 
  that's why I need to have both of them in memory.
  
  
  Code:
  
  - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString 
  *)todayTextName pastImage:(NSString *)pastTextName 
  andRay:(CGFloat)ray
  {
      osg::ref_ptrosg::Geode sphere = new osg::Geode();
      sphere-addDrawable(new osg::ShapeDrawable(new 
  osg::Sphere(osg::Vec3(), ray)));
      sphere-setName(BubbleNode);
  
      // load image for texture
      osg::ref_ptrosg::Image todayImage = 
  osgDB::readImageFile(todayTextName.UTF8String);
      osg::ref_ptrosg::Image pastImage = 
  osgDB::readImageFile(pastTextName.UTF8String);
  
      if (!todayImage || !pastImage)
      {
          std::cout  Couldn't load texture.  std::endl;
      }
      else
      {
  
  
 
 



   
  
  
  
   

 
          osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;
          texture-setDataVariance(osg::Object::STATIC);
  
  
  
 
 



   
  
  
   

 
          texture-setFilter(osg::Texture::MIN_FILTER, 
  osg::Texture::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(todayImage.release());
          texture-setUnRefImageDataAfterApply(true);
          
  sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get());
  
          osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D;
          texture2-setDataVariance(osg::Object::STATIC);
  
  
  
 
 



   
  
  
   

 
          texture2-setFilter(osg::Texture::MIN_FILTER, 
  osg::Texture::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(pastImage.release());
          

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

2013-11-19 Thread Alistair Baxter
PVRTC is exclusive to Imagination technology's PowerVR chipsets. All iDevices 
use those chipsets, so it's in common use on iOS, but only certain Android 
devices with the right type of GPU support it.

I don't believe there are any desktop or laptop graphics cards that support it 
directly, but there's a library available to decompress them.

Alistair Baxter
Software Engineer

Have you downloaded your FREE copy of FieldMove Clino?
Find out more about our app for iPhone and Android smartphones:  
http://news.mve.com/fieldmoveclino
Midland Valley Exploration Ltd.
144 West George Street
Glasgow G2 2HG
United Kingdom
Tel: +44 (0) 141 332 2681
Fax:+44 (0) 141 332 6792
The structural geology experts

From: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Glenn Waldron
Sent: 19 November 2013 15:32
To: OpenSceneGraph Users
Subject: Re: [osg-users] Optimizing memory usage by Texture of size 4096x2048

It stays compressed in memory (CPU and GPU), so you get 4:1 compression in the 
app, not just on disk.

No experience with PVR; is it Apple only?


Glenn Waldron / @glennwaldron

On Tue, Nov 19, 2013 at 10:25 AM, John Moore 
kahar...@gmail.commailto:kahar...@gmail.com wrote:
I am not very concerned about disk usage. I am more concerned about RAM. Will 
be there any advantages using this kind of compression? If yes how can I 
compress and then load the data in a osg::Image?

I am asking because I tried to do the compression with PVR (using 
PVRTexToolGUI) but I was not able to load it in a osg::Image.

Thank you.

John


gwaldron wrote:
 Your only further recourse would be to take Luc's advice and DXT-compress the 
 data on disk (using NVTT e.g.); that will give you 4:1 savings.

 Ref:
 http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison 
 (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison)



 Glenn Waldron / @glennwaldron


 On Tue, Nov 19, 2013 at 9:51 AM, John Moore  () wrote:

   Memory usage is for the entire app.
  However memory usage of the same scene if I don't load the texture is 20 
  MB. So I can safely assume the rest is consumed by the fact the textures 
  are applied to the sphere.
 
 
  gwaldron wrote:
 
   110MB -- CPU or GPU memory? For the entire app or just your textures?
  
   Quick math:
   2 * 4096 * 2048 * 4 * 1.3 = 87MB.
   (4 = RGBA, 1.3 = mipmaps)
  
  
  
  
  
   Glenn Waldron / @glennwaldron
  
  
  
 
 
   On Tue, Nov 19, 2013 at 9:18 AM, John Moore  () wrote:
  
  
 Thank you Gwaldron,
that line of code saved me 40MB. Better than nothing. Now the memory 
usage is around 110 MB.
   
The format of the image is JPG.
I tried to use PVR but I can't load the image.
   
This is the complete function (updated with your suggestion) that I use 
to create a sphere with 2 textures.
Then I use a shader to cross fade between the two textures that's 
why I need to have both of them in memory.
   
   
Code:
   
- (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString 
*)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray
{
osg::ref_ptrosg::Geode sphere = new osg::Geode();
sphere-addDrawable(new osg::ShapeDrawable(new 
osg::Sphere(osg::Vec3(), ray)));
sphere-setName(BubbleNode);
   
// load image for texture
osg::ref_ptrosg::Image todayImage = 
osgDB::readImageFile(todayTextName.UTF8String);
osg::ref_ptrosg::Image pastImage = 
osgDB::readImageFile(pastTextName.UTF8String);
   
if (!todayImage || !pastImage)
{
std::cout  Couldn't load texture.  std::endl;
}
else
{
   
  
 
 
  
osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;
texture-setDataVariance(osg::Object::STATIC);
   
   
  
 
 
  
texture-setFilter(osg::Texture::MIN_FILTER, 
osg::Texture::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(todayImage.release());
texture-setUnRefImageDataAfterApply(true);

sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get());
   
osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D;
texture2-setDataVariance(osg::Object::STATIC);
   
   
  
 
 
  
texture2-setFilter(osg::Texture::MIN_FILTER, 
osg::Texture::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(pastImage.release

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

2013-11-19 Thread John Moore
I think I found the osg plugin to decompress PVR but I don't know how to use it.

Do you have any idea?


Alistair Baxter wrote:
 PVRTC is exclusive to Imagination technology’s PowerVR chipsets. All iDevices 
 use those chipsets, so it’s in common use on iOS, but only certain Android 
 devices with the right type of GPU support it. 
 
 I don’t believe there are any desktop or laptop graphics cards that support 
 it directly, but there’s a library available to decompress them. 
 
 Alistair Baxter
 Software Engineer
 
 Have you downloaded your FREE copy of FieldMove Clino? 
 Find out more about our app for iPhone and Android smartphones: 
 http://news.mve.com/fieldmoveclino (http://news.mve.com/fieldmoveclino) 
 Midland Valley Exploration Ltd.
 144 West George Street
 Glasgow G2 2HG
 United Kingdom 
 Tel: +44 (0) 141 332 2681
 Fax: +44 (0) 141 332 6792 
 The structural geology experts  
 
 From:  [mailto:] On Behalf Of Glenn Waldron
 Sent: 19 November 2013 15:32
 To: OpenSceneGraph Users
 Subject: Re:  Optimizing memory usage by Texture of size 4096x2048 
 
 It stays compressed in memory (CPU and GPU), so you get 4:1 compression in 
 the app, not just on disk.  
 
 
 No experience with PVR; is it Apple only? 
 
 
 
 
 
 Glenn Waldron / @glennwaldron 
 
 
 On Tue, Nov 19, 2013 at 10:25 AM, John Moore  () wrote: 
 I am not very concerned about disk usage. I am more concerned about RAM. Will 
 be there any advantages using this kind of compression? If yes how can I 
 compress and then load the data in a osg::Image?
 
 I am asking because I tried to do the compression with PVR (using 
 PVRTexToolGUI) but I was not able to load it in a osg::Image.
 
 Thank you.
 
 John  
 
 
 gwaldron wrote:
 
  Your only further recourse would be to take Luc's advice and DXT-compress 
  the data on disk (using NVTT e.g.); that will give you 4:1 savings.
  
  Ref: 
  
 
 
  http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison 
  (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison)
   
  (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison 
  (http://en.wikipedia.org/wiki/S3_Texture_Compression#S3TC_Format_Comparison))
  
  
  
  Glenn Waldron / @glennwaldron   
  
  
  On Tue, Nov 19, 2013 at 9:51 AM, John Moore  () wrote:
  
  
   Memory usage is for the entire app.
   However memory usage of the same scene if I don’t load the texture is 20 
   MB. So I can safely assume the rest is consumed by the fact the textures 
   are applied to the sphere.
   
   
   gwaldron wrote:
   
   
110MB -- CPU or GPU memory? For the entire app or just your textures?

Quick math:
2 * 4096 * 2048 * 4 * 1.3 = 87MB.
(4 = RGBA, 1.3 = mipmaps)





Glenn Waldron / @glennwaldron




   
   
   
On Tue, Nov 19, 2013 at 9:18 AM, John Moore  () wrote:



 Thank you Gwaldron,
 that line of code saved me 40MB. Better than nothing. Now the memory 
 usage is around 110 MB.
 
 The format of the image is JPG.
 I tried to use PVR but I can't load the image.
 
 This is the complete function (updated with your suggestion) that I 
 use to create a sphere with 2 textures.
 Then I use a shader to cross fade between the two textures that's 
 why I need to have both of them in memory.
 
 
 Code:
 
 - (osg::ref_ptrosg::Geode)createSphereWithTodayImage:(NSString 
 *)todayTextName pastImage:(NSString *)pastTextName andRay:(CGFloat)ray
 {
 osg::ref_ptrosg::Geode sphere = new osg::Geode();
 sphere-addDrawable(new osg::ShapeDrawable(new 
 osg::Sphere(osg::Vec3(), ray)));
 sphere-setName(BubbleNode);
 
 // load image for texture
 osg::ref_ptrosg::Image todayImage = 
 osgDB::readImageFile(todayTextName.UTF8String);
 osg::ref_ptrosg::Image pastImage = 
 osgDB::readImageFile(pastTextName.UTF8String);
 
 if (!todayImage || !pastImage)
 {
 std::cout  Couldn't load texture.  std::endl;
 }
 else
 {
 
 


   
   
   
  
 
 
 
  
   

 osg::ref_ptrosg::Texture2D texture = new osg::Texture2D;
 texture-setDataVariance(osg::Object::STATIC);
 
 
 


   
   
   
  
 
 
  
   

 texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::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(todayImage.release());
 texture-setUnRefImageDataAfterApply(true);  
 sphere-getOrCreateStateSet()-setTextureAttributeAndModes(0,texture.get());
 
 osg::ref_ptrosg::Texture2D texture2 = new osg::Texture2D;
 texture2-setDataVariance(osg::Object::STATIC);
 
 
 



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

2013-11-19 Thread Alistair Baxter
-Original Message-
From: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of John Moore

 I think I found the osg plugin to decompress PVR but I don't know how to use 
 it.

 Do you have any idea?

OK, a brief look at the definitions of the PVRTC OpenGL extension and the osg 
code suggests that osg::Texture knows about the following compressed texture 
formats:

GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG


You ought to be able to specify those as the Internalformat for your texture 
objects somehow. Actually by calling osg::Texture:: 
setInternalFormatMode(osg::Texture::USE_PVRTC_2BPP_COMPRESSION) or 
USE_PVRTC_4BPP_COMPRESSION.

I'm not sure if osg or the drivers will do the compression for you (S3TC 
compression works like that on Windows, Linux and OSX), or whether you have to 
pass in the data you compressed with the tool.

This Apple sample code:
https://developer.apple.com/LIBRARY/IOS/samplecode/PVRTextureLoader/Introduction/Intro.html

should show you the raw OpenGL way of dealing with compressed textures. 
Alternatively the PowerVR Insider SDK should have more samples, covering other 
platforms if need be:

http://www.imgtec.com/powervr/insider/sdkdownloads/index.asp





Alistair Baxter
Software Engineer

Have you downloaded your FREE copy of FieldMove Clino? 
Find out more about our app for iPhone and Android smartphones:  
http://news.mve.com/fieldmoveclino
Midland Valley Exploration Ltd.
144 West George Street
Glasgow G2 2HG
United Kingdom
Tel: +44 (0) 141 332 2681
Fax:+44 (0) 141 332 6792
The structural geology experts 

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