- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/vtf/ReaderWriterVTF.cpp
r12597 r13041 6 6 * into an osg::Image. 7 7 * 8 * Borrows heavily from the DDS plugin for OSG, as well 8 * Borrows heavily from the DDS plugin for OSG, as well 9 9 * as the Valve Source SDK 10 10 * … … 362 362 int mipSize; 363 363 int mipOffset; 364 364 365 365 // Validate the file with the 'VTF\0' magic number 366 366 _istream.read(&vtf_header.magic_number[0], 4); … … 395 395 // No depth in textures earlier than version 7.2 396 396 if ((vtf_header.file_version[0] < 7) || 397 ((vtf_header.file_version[0] == 7) && 397 ((vtf_header.file_version[0] == 7) && 398 398 (vtf_header.file_version[1] < 2))) 399 399 { … … 485 485 486 486 // Allocate an osg::Image for the lo-res image metadata 487 osg::ref_ptr<osg::Image> loResImage = new osg::Image(); 487 osg::ref_ptr<osg::Image> loResImage = new osg::Image(); 488 488 489 489 // Set the image metadata, and figure out how many bytes to read … … 504 504 supported = ConvertImageFormat(vtf_header.image_format, internalFormat, 505 505 pixelFormat, dataType); 506 506 507 507 // Bail if the format isn't supported 508 508 if (!supported) … … 528 528 529 529 // Create the mipmap offsets vector 530 osg::Image::MipmapDataType mipmaps; 530 osg::Image::MipmapDataType mipmaps; 531 531 532 532 // Deal with mipmaps, if necessary … … 548 548 int height = vtf_header.image_height; 549 549 int blockSize; 550 550 551 551 if ((vtf_header.image_format == VTF_FORMAT_DXT1) || 552 552 (vtf_header.image_format == VTF_FORMAT_DXT1_ONEBITALPHA)) … … 608 608 609 609 // Allocate the resulting osg::Image 610 osg::ref_ptr<osg::Image> osgImage = new osg::Image(); 610 osg::ref_ptr<osg::Image> osgImage = new osg::Image(); 611 611 612 612 // Set the image meta-data, including dimensions, format, data type, … … 697 697 imageData, osg::Image::USE_NEW_DELETE); 698 698 if (mipmaps.size()>0) osgImage->setMipmapLevels(mipmaps); 699 699 700 700 // Finally, return the image 701 701 return osgImage.release(); … … 706 706 { 707 707 // Not supported 708 return false; 708 return false; 709 709 } 710 710 … … 714 714 public: 715 715 virtual const char* className() const 716 { 717 return "VTF Image Reader/Writer"; 716 { 717 return "VTF Image Reader/Writer"; 718 718 } 719 719 720 720 virtual bool acceptsExtension(const std::string& extension) const 721 { 722 return osgDB::equalCaseInsensitive(extension, "vtf"); 721 { 722 return osgDB::equalCaseInsensitive(extension, "vtf"); 723 723 } 724 724 … … 739 739 740 740 std::string fileName = osgDB::findDataFile( file, options ); 741 741 742 742 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 743 743 744 744 osgDB::ifstream stream(fileName.c_str(), std::ios::in | std::ios::binary); 745 745 if(!stream) return ReadResult::FILE_NOT_HANDLED; … … 753 753 osg::Image* osgImage = ReadVTFFile(fin); 754 754 if (osgImage==NULL) return ReadResult::FILE_NOT_HANDLED; 755 755 756 756 if (options && options->getOptionString().find("vtf_flip")!=std::string::npos) 757 757 { 758 758 osgImage->flipVertical(); 759 759 } 760 760 761 761 return osgImage; 762 762 }
