return 0;\r
}\r
\r
-osg::Vec4 computeColor( osg::Vec4 colors[2][2][2], bool colorValid[2][2][2], MipMapTuple attrs )\r
+osg::Vec4 computeColor( osg::Vec4 colors[2][2][2], bool colorValid[2][2][2], MipMapTuple attrs, GLenum pixelFormat )\r
{\r
osg::Vec4 result;\r
+ unsigned int nbComponents = osg::Image::computeNumComponents( pixelFormat );\r
result[0] = computeComponent( 0, colors, colorValid, attrs.get<0>() );\r
- result[1] = computeComponent( 1, colors, colorValid, attrs.get<1>() );\r
- result[2] = computeComponent( 2, colors, colorValid, attrs.get<2>() );\r
- result[3] = computeComponent( 3, colors, colorValid, attrs.get<3>() );\r
+ if ( nbComponents >= 2 )\r
+ result[1] = computeComponent( 1, colors, colorValid, attrs.get<1>() );\r
+ if ( nbComponents >= 3 )\r
+ result[2] = computeComponent( 2, colors, colorValid, attrs.get<2>() );\r
+ if ( nbComponents == 4 )\r
+ result[3] = computeComponent( 3, colors, colorValid, attrs.get<3>() );\r
return result;\r
}\r
\r
osg::Image* computeMipmap( osg::Image* image, MipMapTuple attrs )\r
{\r
bool computeMipmap = false;\r
+ unsigned int nbComponents = osg::Image::computeNumComponents( image->getPixelFormat() );\r
if ( attrs.get<0>() != AUTOMATIC &&\r
- attrs.get<1>() != AUTOMATIC &&\r
- attrs.get<2>() != AUTOMATIC &&\r
- attrs.get<3>() != AUTOMATIC )\r
+ ( attrs.get<1>() != AUTOMATIC || nbComponents < 2 ) &&\r
+ ( attrs.get<2>() != AUTOMATIC || nbComponents < 3 ) &&\r
+ ( attrs.get<3>() != AUTOMATIC || nbComponents < 4 ) )\r
{\r
computeMipmap = true;\r
}\r
else if ( attrs.get<0>() != AUTOMATIC ||\r
- attrs.get<1>() != AUTOMATIC ||\r
- attrs.get<2>() != AUTOMATIC ||\r
- attrs.get<3>() != AUTOMATIC )\r
+ ( attrs.get<1>() != AUTOMATIC && nbComponents >= 2 ) ||\r
+ ( attrs.get<2>() != AUTOMATIC && nbComponents >= 3 ) ||\r
+ ( attrs.get<3>() != AUTOMATIC && nbComponents == 4 ) )\r
{\r
throw BuilderException("invalid mipmap control function combination");\r
}\r
}\r
\r
unsigned char *ptr = imageData( dest, image->getPixelFormat(), image->getDataType(), ns, nt, image->getPacking(), i/2, j/2, k/2 );\r
- osg::Vec4 color = computeColor( colors, colorValid, attrs );\r
+ osg::Vec4 color = computeColor( colors, colorValid, attrs, image->getPixelFormat() );\r
setColor( ptr, image->getPixelFormat(), image->getDataType(), color );\r
}\r
}\r