[osg-users] Optimizing texture power of two resizing

168 views
Skip to first unread message

Chris Kuliukas

unread,
Dec 15, 2015, 9:30:55 PM12/15/15
to osg-...@lists.openscenegraph.org
Hi,

We've had some troubles with stuttering when going from one screen to another, and a big part of the problem seems to be that we have textures that aren't to the power of two and need to be resized.

This resize happens right at the last minute before the data is sent to the graphics card, and it happens every time the texture needs to be reloaded.


I hacked osg/Image.cpp Image::setImage so that images are resized as they are loaded instead, but I had to set it to only resize images with a width above 50 so that it doesn't resize font textures, which causes an exception.

This does seem to be having a positive effect and working fine, but it also feels like a hack. I'm wondering how would someone who knows OSG well do this? Or if there's some other alternative I haven't thought of?

(Resizing all the textures offline would be ideal, but would take too long given the amount of models we use and import)


Thank you!

Cheers,
Chris

------------------------
http://www.hrwallingford.com/facilities/ship-simulation-centre (http://www.hrwallingford.com/facilities/ship-simulation-centre)

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





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

Robert Osfield

unread,
Dec 16, 2015, 3:27:03 AM12/16/15
to OpenSceneGraph Users
Hi Chris,

On modern graphics cards you can change the osg::Texture ResizeNonPowerOfTwoHint setting so that non power of two textures are passed to the GL driver without resizing.  From the include/osg/Texture header:

         /** Sets whether to force the texture to resize images that have dimensions
          * that are not a power of two. If enabled, NPOT images will be resized,
          * whether or not NPOT textures are supported by the hardware. If disabled,
          * NPOT images will not be resized if supported by hardware. */
        inline void setResizeNonPowerOfTwoHint(bool flag) { _resizeNonPowerOfTwoHint = flag; }


Another alternative is to simply pre-process the osg::Image by rescaling them with a custom visitor that is applied to a newly loaded subgraph that does the reszie - there should be no need to hack osg::Image to this. 

Robert.

Chris Kuliukas

unread,
Dec 16, 2015, 9:56:13 PM12/16/15
to osg-...@lists.openscenegraph.org
Thanks Robert, that sounds like a better solution.
http://forum.openscenegraph.org/viewtopic.php?p=65884#65884

Chris Kuliukas

unread,
Dec 16, 2015, 9:58:55 PM12/16/15
to osg-...@lists.openscenegraph.org
Thanks Robert, that sounds like a better solution.

http://forum.openscenegraph.org/viewtopic.php?p=65885#65885

Chris Kuliukas

unread,
Dec 17, 2015, 2:45:02 AM12/17/15
to osg-...@lists.openscenegraph.org
By the way while I have your attention is this how you would do a visitor to access all images?


Code:

void ImageResizeVisitor::apply(osg::Node& node)
{
osg::StateSet* ss = node.getStateSet();
if ( ss )
{
osg::StateAttribute* sa = ss->getAttribute(osg::StateAttribute::TEXTURE);
for( int j = 0; j < ss->getNumTextureAttributeLists(); j++ )
{
osg::Texture2D* tex = dynamic_cast<osg::Texture2D*>( ss->getTextureAttribute(j, osg::StateAttribute::TEXTURE) );
if( tex )
{
for(int i = 0; i < tex->getNumImages(); i++)
{
osg::Image* im = tex->getImage(i);




It works but took quite a while to tease the images out.
http://forum.openscenegraph.org/viewtopic.php?p=65887#65887
Reply all
Reply to author
Forward
0 new messages