Changeset 13041 for OpenSceneGraph/trunk/src/osg/Image.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osg/Image.cpp (modified) (53 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osg/Image.cpp
r13025 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 112 112 // advance to next row 113 113 ++_rowNum; 114 114 115 115 if (_rowNum>=_image->t()) 116 116 { … … 128 128 } 129 129 } 130 130 131 131 assign(); 132 132 } … … 141 141 return; 142 142 } 143 143 144 144 //OSG_NOTICE<<"DataIterator::assign B"<<std::endl; 145 145 … … 154 154 return; 155 155 } 156 156 157 157 //OSG_NOTICE<<"DataIterator::assign C"<<std::endl; 158 158 … … 168 168 } 169 169 const unsigned char* ptr = _image->getMipmapData(_mipmapNum); 170 170 171 171 int rowLength = _image->getRowLength()>>_mipmapNum; 172 172 if (rowLength==0) rowLength = 1; 173 173 174 174 int imageHeight = _image->t()>>_mipmapNum; 175 175 if (imageHeight==0) imageHeight = 1; 176 176 177 177 unsigned int rowWidthInBytes = Image::computeRowWidthInBytes(rowLength,_image->getPixelFormat(),_image->getDataType(),_image->getPacking()); 178 178 unsigned int imageSizeInBytes = rowWidthInBytes*imageHeight; 179 179 180 180 _currentPtr = ptr + rowWidthInBytes*_rowNum + imageSizeInBytes*_imageNum; 181 181 _currentSize = rowWidthInBytes; … … 216 216 _data(0L) 217 217 { 218 setDataVariance(STATIC); 218 setDataVariance(STATIC); 219 219 } 220 220 … … 288 288 289 289 // slowest comparison at the bottom! 290 COMPARE_StateAttribute_Parameter(getFileName()) 290 COMPARE_StateAttribute_Parameter(getFileName()) 291 291 292 292 return 0; … … 323 323 case(GL_UNSIGNED_INT_2_10_10_10_REV): return true; 324 324 default: return false; 325 } 325 } 326 326 } 327 327 … … 370 370 case(GL_INTENSITY16UI_EXT): 371 371 case(GL_INTENSITY32UI_EXT): 372 OSG_WARN<<"Image::computePixelFormat("<<std::hex<<format<<std::dec<<") intensity pixel format is not correctly specified, so assume GL_LUMINANCE_INTEGER."<<std::endl; 372 OSG_WARN<<"Image::computePixelFormat("<<std::hex<<format<<std::dec<<") intensity pixel format is not correctly specified, so assume GL_LUMINANCE_INTEGER."<<std::endl; 373 373 return GL_LUMINANCE_INTEGER_EXT; 374 374 case(GL_LUMINANCE_ALPHA8I_EXT): … … 404 404 { 405 405 case GL_LUMINANCE32F_ARB: 406 case GL_LUMINANCE16F_ARB: 406 case GL_LUMINANCE16F_ARB: 407 407 case GL_LUMINANCE_ALPHA32F_ARB: 408 case GL_LUMINANCE_ALPHA16F_ARB: 408 case GL_LUMINANCE_ALPHA16F_ARB: 409 409 case GL_RGB32F_ARB: 410 case GL_RGB16F_ARB: 410 case GL_RGB16F_ARB: 411 411 case GL_RGBA32F_ARB: 412 412 case GL_RGBA16F_ARB: return GL_FLOAT; … … 419 419 case GL_RGB16UI_EXT: 420 420 case GL_RGBA16UI_EXT: 421 case GL_LUMINANCE16UI_EXT: 421 case GL_LUMINANCE16UI_EXT: 422 422 case GL_LUMINANCE_ALPHA16UI_EXT: return GL_UNSIGNED_SHORT; 423 423 … … 427 427 case GL_LUMINANCE_ALPHA8UI_EXT: return GL_UNSIGNED_BYTE; 428 428 429 case GL_RGBA32I_EXT: 429 case GL_RGBA32I_EXT: 430 430 case GL_RGB32I_EXT: 431 431 case GL_LUMINANCE32I_EXT: … … 437 437 case GL_LUMINANCE_ALPHA16I_EXT: return GL_SHORT; 438 438 439 case GL_RGB8I_EXT: 440 case GL_RGBA8I_EXT: 441 case GL_LUMINANCE8I_EXT: 439 case GL_RGB8I_EXT: 440 case GL_RGBA8I_EXT: 441 case GL_LUMINANCE8I_EXT: 442 442 case GL_LUMINANCE_ALPHA8I_EXT: return GL_BYTE; 443 443 … … 448 448 case GL_ALPHA: return GL_UNSIGNED_BYTE; 449 449 450 default: 450 default: 451 451 { 452 452 OSG_WARN<<"error computeFormatType = "<<std::hex<<pixelFormat<<std::dec<<std::endl; … … 467 467 case(GL_COMPRESSED_RED_RGTC1_EXT): return 1; 468 468 case(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT): return 2; 469 case(GL_COMPRESSED_RED_GREEN_RGTC2_EXT): return 2; 469 case(GL_COMPRESSED_RED_GREEN_RGTC2_EXT): return 2; 470 470 case(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG): return 3; 471 471 case(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG): return 3; … … 564 564 return 0; 565 565 } 566 } 566 } 567 567 } 568 568 … … 633 633 switch(type) 634 634 { 635 635 636 636 case(GL_BITMAP): return computeNumComponents(format); 637 637 638 638 case(GL_BYTE): 639 639 case(GL_UNSIGNED_BYTE): return 8*computeNumComponents(format); 640 640 641 641 case(GL_HALF_FLOAT_NV): 642 642 case(GL_SHORT): 643 643 case(GL_UNSIGNED_SHORT): return 16*computeNumComponents(format); 644 644 645 645 case(GL_INT): 646 646 case(GL_UNSIGNED_INT): 647 647 case(GL_FLOAT): return 32*computeNumComponents(format); 648 649 650 case(GL_UNSIGNED_BYTE_3_3_2): 648 649 650 case(GL_UNSIGNED_BYTE_3_3_2): 651 651 case(GL_UNSIGNED_BYTE_2_3_3_REV): return 8; 652 652 653 653 case(GL_UNSIGNED_SHORT_5_6_5): 654 654 case(GL_UNSIGNED_SHORT_5_6_5_REV): … … 657 657 case(GL_UNSIGNED_SHORT_5_5_5_1): 658 658 case(GL_UNSIGNED_SHORT_1_5_5_5_REV): return 16; 659 659 660 660 case(GL_UNSIGNED_INT_8_8_8_8): 661 661 case(GL_UNSIGNED_INT_8_8_8_8_REV): 662 662 case(GL_UNSIGNED_INT_10_10_10_2): 663 663 case(GL_UNSIGNED_INT_2_10_10_10_REV): return 32; 664 default: 664 default: 665 665 { 666 666 OSG_WARN<<"error type = "<<type<<std::endl; 667 667 return 0; 668 668 } 669 } 669 } 670 670 671 671 } … … 711 711 { 712 712 if (width==0 || height==0 || depth==0) return 0; 713 713 714 714 return osg::maximum( 715 715 Image::computeRowWidthInBytes(width,pixelFormat,type,packing)*height*depth, … … 758 758 case(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT): 759 759 case(GL_COMPRESSED_RED_GREEN_RGTC2_EXT): 760 case(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG): 760 case(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG): 761 761 case(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG): 762 762 case(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG): … … 771 771 unsigned int Image::getTotalSizeInBytesIncludingMipmaps() const 772 772 { 773 if (_mipmapData.empty()) 773 if (_mipmapData.empty()) 774 774 { 775 775 // no mips so just return size of main image 776 776 return getTotalSizeInBytes(); 777 777 } 778 778 779 779 int s = _s; 780 780 int t = _t; … … 784 784 { 785 785 totalSize += computeImageSizeInBytes(s, t, r, _pixelFormat, _dataType, _packing); 786 786 787 787 s >>= 1; 788 788 t >>= 1; … … 797 797 } 798 798 799 void Image::setRowLength(int length) 800 { 799 void Image::setRowLength(int length) 800 { 801 801 _rowLength = length; 802 802 #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) 803 if (length > 0) 803 if (length > 0) 804 804 { 805 805 OSG_WARN << "Image::setRowLength is not supported on this platform, ignoring" << std::endl; … … 811 811 void Image::setInternalTextureFormat(GLint internalFormat) 812 812 { 813 // won't do any sanity checking right now, leave it to 813 // won't do any sanity checking right now, leave it to 814 814 // OpenGL to make the call. 815 815 _internalTextureFormat = internalFormat; … … 844 844 845 845 unsigned int previousTotalSize = 0; 846 846 847 847 if (_data) previousTotalSize = computeRowWidthInBytes(_s,_pixelFormat,_dataType,_packing)*_t*_r; 848 848 849 849 unsigned int newTotalSize = computeRowWidthInBytes(s,format,type,packing)*t*r; 850 850 … … 866 866 _packing = packing; 867 867 _rowLength = 0; 868 868 869 869 // preserve internalTextureFormat if already set, otherwise 870 870 // use the pixelFormat as the source for the format. … … 873 873 else 874 874 { 875 875 876 876 // failed to allocate memory, for now, will simply set values to 0. 877 877 _s = 0; … … 882 882 _packing = 0; 883 883 _rowLength = 0; 884 884 885 885 // commenting out reset of _internalTextureFormat as we are changing 886 886 // policy so that allocateImage honours previous settings of _internalTextureFormat. 887 887 //_internalTextureFormat = 0; 888 888 } 889 889 890 890 dirty(); 891 891 } … … 913 913 _packing = packing; 914 914 _rowLength = rowLength; 915 915 916 916 dirty(); 917 917 … … 939 939 const osg::Texture2DArray::Extensions* extensions2DArray = osg::Texture2DArray::getExtensions(contextID,true); 940 940 941 941 942 942 GLboolean binding1D = GL_FALSE, binding2D = GL_FALSE, binding3D = GL_FALSE, binding2DArray = GL_FALSE, bindingCubeMap = GL_FALSE; 943 943 … … 977 977 } 978 978 } 979 979 980 980 if (textureMode==0) return; 981 981 … … 1003 1003 numMipMaps = 1; 1004 1004 } 1005 1005 1006 1006 // OSG_NOTICE<<"Image::readImageFromCurrentTexture() : numMipMaps = "<<numMipMaps<<std::endl; 1007 1007 1008 1008 1009 1009 GLint compressed = 0; 1010 1010 … … 1030 1030 } 1031 1031 } 1032 1033 1034 1032 1033 1034 1035 1035 /* if the compression has been successful */ 1036 1036 if (compressed == GL_TRUE) … … 1038 1038 1039 1039 MipmapDataType mipMapData; 1040 1040 1041 1041 unsigned int total_size = 0; 1042 1042 GLint i; … … 1044 1044 { 1045 1045 if (i>0) mipMapData.push_back(total_size); 1046 1046 1047 1047 GLint compressed_size; 1048 1048 glGetTexLevelParameteriv(textureMode, i, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &compressed_size); 1049 1049 1050 1050 total_size += compressed_size; 1051 1051 } 1052 1053 1052 1053 1054 1054 unsigned char* data = new unsigned char[total_size]; 1055 1055 if (!data) 1056 1056 { 1057 1057 OSG_WARN<<"Warning: Image::readImageFromCurrentTexture(..) out of memory, now image read."<<std::endl; 1058 return; 1058 return; 1059 1059 } 1060 1060 … … 1074 1074 _t = height; 1075 1075 _r = depth; 1076 1076 1077 1077 _pixelFormat = internalformat; 1078 1078 _dataType = type; … … 1089 1089 1090 1090 dirty(); 1091 1091 1092 1092 } 1093 1093 else … … 1108 1108 { 1109 1109 if (i>0) mipMapData.push_back(total_size); 1110 1110 1111 1111 glGetTexLevelParameteriv(textureMode, i, GL_TEXTURE_WIDTH, &width); 1112 1112 glGetTexLevelParameteriv(textureMode, i, GL_TEXTURE_HEIGHT, &height); 1113 1113 glGetTexLevelParameteriv(textureMode, i, GL_TEXTURE_DEPTH, &depth); 1114 1114 1115 1115 unsigned int level_size = computeRowWidthInBytes(width,internalformat,type,packing)*height*depth; 1116 1116 1117 1117 total_size += level_size; 1118 1118 } 1119 1120 1119 1120 1121 1121 unsigned char* data = new unsigned char[total_size]; 1122 1122 if (!data) 1123 1123 { 1124 1124 OSG_WARN<<"Warning: Image::readImageFromCurrentTexture(..) out of memory, now image read."<<std::endl; 1125 return; 1125 return; 1126 1126 } 1127 1127 … … 1136 1136 _t = height; 1137 1137 _r = depth; 1138 1138 1139 1139 _pixelFormat = computePixelFormat(internalformat); 1140 1140 _dataType = type; … … 1144 1144 _packing = packing; 1145 1145 _rowLength = rowLength; 1146 1146 1147 1147 for(i=0;i<numMipMaps;++i) 1148 1148 { … … 1151 1151 1152 1152 dirty(); 1153 } 1153 } 1154 1154 #else 1155 1155 OSG_NOTICE<<"Warning: Image::readImageFromCurrentTexture() not supported."<<std::endl; … … 1287 1287 unsigned int rowStepInBytes = getRowStepInBytes(); 1288 1288 unsigned int imageStepInBytes = getImageStepInBytes(); 1289 1289 1290 1290 for(int r=0;r<_r;++r) 1291 1291 { … … 1313 1313 return; 1314 1314 } 1315 1315 1316 1316 dirty(); 1317 1317 } … … 1363 1363 unsigned char* top = data(0,0,r); 1364 1364 unsigned char* bottom = top + (_t-1)*rowStep; 1365 1365 1366 1366 flipImageVertical(top, bottom, rowSize, rowStep); 1367 1367 } … … 1398 1398 } 1399 1399 } 1400 } 1400 } 1401 1401 1402 1402 dirty(); … … 1429 1429 { 1430 1430 for(int row=0; row<_t; ++row) 1431 { 1431 { 1432 1432 unsigned char* front = data(0, row, r_front); 1433 1433 unsigned char* back = data(0, row, r_back); … … 1445 1445 int new_s = computeNearestPowerOfTwo(_s); 1446 1446 int new_t = computeNearestPowerOfTwo(_t); 1447 1447 1448 1448 if (new_s>maxTextureSize) new_s = maxTextureSize; 1449 1449 if (new_t>maxTextureSize) new_t = maxTextureSize; 1450 1450 1451 1451 if (new_s!=_s || new_t!=_t) 1452 1452 { … … 1470 1470 1471 1471 1472 template <typename T> 1472 template <typename T> 1473 1473 bool _findLowerAlphaValueInRow(unsigned int num, T* data,T value, unsigned int delta) 1474 1474 { … … 1481 1481 } 1482 1482 1483 template <typename T> 1483 template <typename T> 1484 1484 bool _maskedFindLowerAlphaValueInRow(unsigned int num, T* data,T value, T mask, unsigned int delta) 1485 1485 { … … 1592 1592 0x00000003u, 1)) 1593 1593 return true; 1594 break; 1594 break; 1595 1595 case(GL_UNSIGNED_INT_2_10_10_10_REV): 1596 1596 if (_maskedFindLowerAlphaValueInRow(s(), (unsigned int*)d, … … 1620 1620 1621 1621 1622 #include <osg/TextureRectangle> 1622 #include <osg/TextureRectangle> 1623 1623 1624 1624 … … 1705 1705 } 1706 1706 1707 template <typename T> 1707 template <typename T> 1708 1708 Vec4 _readColor(GLenum pixelFormat, T* data,float scale) 1709 1709 {
