Added flipDepth() method

This commit is contained in:
Robert Osfield 2011-10-21 10:59:42 +00:00
parent 088d00c651
commit d3cebab9a3
2 changed files with 37 additions and 2 deletions

View File

@ -282,12 +282,14 @@ class OSG_EXPORT Image : public BufferData
Vec4 getColor(const Vec3& texcoord) const;
/** Flip the image horizontally. */
/** Flip the image horizontally, around s dimension. */
void flipHorizontal();
/** Flip the image vertically. */
/** Flip the image vertically, around t dimension. */
void flipVertical();
/** Flip the image around the r dimension. Only relevent for 3D textures. */
void flipDepth();
/** Ensure image dimensions are a power of two.
* Mipmapped textures require the image dimensions to be

View File

@ -1181,6 +1181,39 @@ void Image::flipVertical()
dirty();
}
void Image::flipDepth()
{
if (_data==NULL)
{
OSG_WARN << "Error Image::flipVertical() do not succeed : cannot flip NULL image."<<std::endl;
return;
}
if (_r==1)
{
return;
}
if (!_mipmapData.empty() && _r>1)
{
OSG_WARN << "Error Image::flipVertical() do not succeed : flipping of mipmap 3d textures not yet supported."<<std::endl;
return;
}
unsigned int sizeOfSlice = getImageSizeInBytes();
int r_top = 0;
int r_bottom = _r-1;
for(; r_top<r_bottom; ++r_top,--r_bottom)
{
unsigned char* top_slice = data(0,0,r_top);
unsigned char* bottom_slice = data(0,0,r_bottom);
for(unsigned int i=0; i<sizeOfSlice; ++i, ++top_slice, ++bottom_slice)
{
std::swap(*top_slice, *bottom_slice);
}
}
}
void Image::ensureValidSizeForTexturing(GLint maxTextureSize)