| | 86 | |
| | 87 | void clampToNearestValidPowerOfTwo(int& sizeX, int& sizeY, int& sizeZ, int s_maximumTextureSize, int t_maximumTextureSize, int r_maximumTextureSize) |
| | 88 | { |
| | 89 | // compute nearest powers of two for each axis. |
| | 90 | int s_nearestPowerOfTwo = 1; |
| | 91 | while(s_nearestPowerOfTwo<sizeX && s_nearestPowerOfTwo<s_maximumTextureSize) s_nearestPowerOfTwo*=2; |
| | 92 | |
| | 93 | int t_nearestPowerOfTwo = 1; |
| | 94 | while(t_nearestPowerOfTwo<sizeY && t_nearestPowerOfTwo<t_maximumTextureSize) t_nearestPowerOfTwo*=2; |
| | 95 | |
| | 96 | int r_nearestPowerOfTwo = 1; |
| | 97 | while(r_nearestPowerOfTwo<sizeZ && r_nearestPowerOfTwo<r_maximumTextureSize) r_nearestPowerOfTwo*=2; |
| | 98 | |
| | 99 | sizeX = s_nearestPowerOfTwo; |
| | 100 | sizeY = t_nearestPowerOfTwo; |
| | 101 | sizeZ = r_nearestPowerOfTwo; |
| | 102 | } |
| | 103 | |
| | 104 | #if 1 |
| | 105 | struct ModulateAlphaByLuminanceOperator |
| | 106 | { |
| | 107 | ModulateAlphaByLuminanceOperator() {} |
| | 108 | |
| | 109 | inline void luminance(float&) const {} |
| | 110 | inline void alpha(float&) const {} |
| | 111 | inline void luminance_alpha(float& l,float& a) const { a*= l; } |
| | 112 | inline void rgb(float&,float&,float&) const {} |
| | 113 | inline void rgba(float& r,float& g,float& b,float& a) const { float l = (r+g+b)*0.3333333; a *= l;} |
| | 114 | }; |
| | 115 | |
| | 116 | osg::Image* createTexture3D(osg::ImageList& imageList, |
| | 117 | unsigned int numComponentsDesired, |
| | 118 | int s_maximumTextureSize, |
| | 119 | int t_maximumTextureSize, |
| | 120 | int r_maximumTextureSize, |
| | 121 | bool resizeToPowerOfTwo) |
| | 122 | { |
| | 123 | |
| | 124 | GLenum desiredPixelFormat = 0; |
| | 125 | bool modulateAlphaByLuminance = false; |
| | 126 | if (numComponentsDesired==0) |
| | 127 | { |
| | 128 | unsigned int maxNumComponents = osg::maximimNumOfComponents(imageList); |
| | 129 | if (maxNumComponents==3) |
| | 130 | { |
| | 131 | desiredPixelFormat = GL_RGBA; |
| | 132 | modulateAlphaByLuminance = true; |
| | 133 | } |
| | 134 | } |
| | 135 | else |
| | 136 | { |
| | 137 | switch(numComponentsDesired) |
| | 138 | { |
| | 139 | case(1) : desiredPixelFormat = GL_LUMINANCE; break; |
| | 140 | case(2) : desiredPixelFormat = GL_LUMINANCE_ALPHA; break; |
| | 141 | case(3) : desiredPixelFormat = GL_RGB; break; |
| | 142 | case(4) : desiredPixelFormat = GL_RGBA; break; |
| | 143 | } |
| | 144 | } |
| | 145 | |
| | 146 | osg::ref_ptr<osg::Image> image = osg::createImage3D(imageList, |
| | 147 | desiredPixelFormat, |
| | 148 | s_maximumTextureSize, |
| | 149 | t_maximumTextureSize, |
| | 150 | r_maximumTextureSize, |
| | 151 | resizeToPowerOfTwo); |
| | 152 | if (image.valid()) |
| | 153 | { |
| | 154 | if (modulateAlphaByLuminance) |
| | 155 | { |
| | 156 | osg::modifyImage(image.get(), ModulateAlphaByLuminanceOperator()); |
| | 157 | } |
| | 158 | return image.release(); |
| | 159 | } |
| | 160 | else |
| | 161 | { |
| | 162 | return 0; |
| | 163 | } |
| | 164 | } |
| | 165 | #else |
| 438 | | |
| 439 | | void clampToNearestValidPowerOfTwo(int& sizeX, int& sizeY, int& sizeZ, int s_maximumTextureSize, int t_maximumTextureSize, int r_maximumTextureSize) |
| 440 | | { |
| 441 | | // compute nearest powers of two for each axis. |
| 442 | | int s_nearestPowerOfTwo = 1; |
| 443 | | while(s_nearestPowerOfTwo<sizeX && s_nearestPowerOfTwo<s_maximumTextureSize) s_nearestPowerOfTwo*=2; |
| 444 | | |
| 445 | | int t_nearestPowerOfTwo = 1; |
| 446 | | while(t_nearestPowerOfTwo<sizeY && t_nearestPowerOfTwo<t_maximumTextureSize) t_nearestPowerOfTwo*=2; |
| 447 | | |
| 448 | | int r_nearestPowerOfTwo = 1; |
| 449 | | while(r_nearestPowerOfTwo<sizeZ && r_nearestPowerOfTwo<r_maximumTextureSize) r_nearestPowerOfTwo*=2; |
| 450 | | |
| 451 | | sizeX = s_nearestPowerOfTwo; |
| 452 | | sizeY = t_nearestPowerOfTwo; |
| 453 | | sizeZ = r_nearestPowerOfTwo; |
| 454 | | } |
| 455 | | |
| 456 | | osg::Image* createTexture3D(ImageList& imageList, ProcessRow& processRow, |
| | 516 | osg::Image* createTexture3D(osg::ImageList& imageList, |
| 770 | | }; |
| 771 | | |
| 772 | | struct ModulateAlphaByLuminanceOperator |
| 773 | | { |
| 774 | | ModulateAlphaByLuminanceOperator() {} |
| 775 | | |
| 776 | | inline void luminance(float&) const {} |
| 777 | | inline void alpha(float&) const {} |
| 778 | | inline void luminance_alpha(float& l,float& a) const { a*= l; } |
| 779 | | inline void rgb(float&,float&,float&) const {} |
| 780 | | inline void rgba(float& r,float& g,float& b,float& a) const { float l = (r+g+b)*0.3333333; a *= l;} |