+ // Using 1 cross image
+ else if(crossProp) {
+ SG_LOG(SG_INPUT, SG_DEBUG, "try cross map ");
+
+ std::string texname = crossProp->getStringValue();
+
+ // Try to find existing cube map
+ CrossCubeMap::iterator itr = _crossmaps.find(texname);
+ if (itr != _crossmaps.end())
+ return itr->second.get();
+
+ osgDB::ReaderWriter::ReadResult result;
+ result = osgDB::readImageFile(texname, options);
+ if(result.success()) {
+ osg::Image* image = result.getImage();
+ image->flipVertical(); // Seems like the image coordinates are somewhat funny, flip to get better ones
+
+ //cubeTexture->setResizeNonPowerOfTwoHint(false);
+
+ // Size of a single image, 4 rows and 3 columns
+ int width = image->s() / 3;
+ int height = image->t() / 4;
+ int depth = image->r();
+
+ TextureCubeMap* cubeTexture = new osg::TextureCubeMap;
+
+ // Copy the 6 sub-images and push them
+ for(int n=0; n<6; n++) {
+
+ SG_LOG(SG_INPUT, SG_DEBUG, "Copying the " << n << "th sub-images and pushing it" );
+
+ osg::ref_ptr<osg::Image> subimg = new osg::Image();
+ subimg->allocateImage(width, height, depth, image->getPixelFormat(), image->getDataType()); // Copy attributes
+
+ // Choose correct image
+ switch(n) {
+ case 0: // Front
+ copySubImage(image, width, 0, width, height, subimg.get(), 0, 0);
+ cubeTexture->setImage(TextureCubeMap::POSITIVE_Y, subimg.get());
+ cubeTexture->setWrap(osg::Texture3D::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
+ break;
+ case 1: // Left
+ copySubImage(image, 0, height, width, height, subimg.get(), 0, 0);
+ cubeTexture->setImage(TextureCubeMap::NEGATIVE_X, subimg.get());
+ cubeTexture->setWrap(osg::Texture2D::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
+ break;
+ case 2: // Top
+ copySubImage(image, width, height, width, height, subimg.get(), 0, 0);
+ cubeTexture->setImage(TextureCubeMap::POSITIVE_Z, subimg.get());
+ cubeTexture->setWrap(osg::Texture3D::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
+ break;
+ case 3: // Right
+ copySubImage(image, width*2, height, width, height, subimg.get(), 0, 0);
+ cubeTexture->setImage(TextureCubeMap::POSITIVE_X, subimg.get());
+ cubeTexture->setWrap(osg::Texture3D::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
+ break;
+ case 4: // Back
+ copySubImage(image, width, height*2, width, height, subimg.get(), 0, 0);
+ cubeTexture->setImage(TextureCubeMap::NEGATIVE_Y, subimg.get());
+ cubeTexture->setWrap(osg::Texture3D::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
+ break;
+ case 5: // Bottom
+ copySubImage(image, width, height*3, width, height, subimg.get(), 0, 0);
+ cubeTexture->setImage(TextureCubeMap::NEGATIVE_Z, subimg.get());
+ cubeTexture->setWrap(osg::Texture3D::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
+ cubeTexture->setWrap(osg::Texture3D::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
+ break;
+ };
+
+ }
+
+ _crossmaps[texname] = cubeTexture;
+
+ return cubeTexture;
+
+ } else {
+ throw BuilderException("Could not load cube cross");
+ }
+ }
+
+ return NULL;