From Art Tevs, "here are a small extension to the osg::Image class, which do computes data type from the given format, i.e. (GL_RGB32F_ARB -> GL_FLOAT). The method is very usefull to find out which data type a texture or an image have based on the internal/pixel format."
This commit is contained in:
@@ -255,6 +255,7 @@ class OSG_EXPORT Image : public Object
|
||||
|
||||
static bool isPackedType(GLenum type);
|
||||
static GLenum computePixelFormat(GLenum pixelFormat);
|
||||
static GLenum computeFormatDataType(GLenum pixelFormat);
|
||||
static unsigned int computeNumComponents(GLenum pixelFormat);
|
||||
static unsigned int computePixelSizeInBits(GLenum pixelFormat,GLenum type);
|
||||
static unsigned int computeRowWidthInBytes(int width,GLenum pixelFormat,GLenum type,int packing);
|
||||
@@ -294,6 +295,15 @@ class OSG_EXPORT Image : public Object
|
||||
{
|
||||
return _data+getMipmapOffset(mipmapLevel);
|
||||
}
|
||||
|
||||
/*inline const unsigned char* getMipmapData(unsigned int row, unsigned int column, unsigned int mipmapLevel) const
|
||||
{
|
||||
if (!_data) return NULL;
|
||||
return getMipmapData(mipmapLevel) + (column*getPixelSizeInBits())/8+row*getRowSizeInBytes();
|
||||
}*/
|
||||
|
||||
/** Build all mipmap levels and change the image type to \"contain mipmaps\" **/
|
||||
void buildMipmaps();
|
||||
|
||||
/** Return true if this image is translucent - i.e. it has alpha values that are less 1.0 (when normalized). */
|
||||
bool isImageTranslucent() const;
|
||||
|
||||
@@ -226,6 +226,62 @@ GLenum Image::computePixelFormat(GLenum format)
|
||||
}
|
||||
}
|
||||
|
||||
GLenum Image::computeFormatDataType(GLenum pixelFormat)
|
||||
{
|
||||
switch (pixelFormat)
|
||||
{
|
||||
case GL_LUMINANCE32F_ARB:
|
||||
case GL_LUMINANCE16F_ARB:
|
||||
case GL_LUMINANCE_ALPHA32F_ARB:
|
||||
case GL_LUMINANCE_ALPHA16F_ARB:
|
||||
case GL_RGB32F_ARB:
|
||||
case GL_RGB16F_ARB:
|
||||
case GL_RGBA32F_ARB:
|
||||
case GL_RGBA16F_ARB: return GL_FLOAT;
|
||||
|
||||
case GL_RGBA32UI_EXT:
|
||||
case GL_RGB32UI_EXT:
|
||||
case GL_LUMINANCE32UI_EXT:
|
||||
case GL_LUMINANCE_ALPHA32UI_EXT: return GL_UNSIGNED_INT;
|
||||
|
||||
case GL_RGB16UI_EXT:
|
||||
case GL_RGBA16UI_EXT:
|
||||
case GL_LUMINANCE16UI_EXT:
|
||||
case GL_LUMINANCE_ALPHA16UI_EXT: return GL_UNSIGNED_SHORT;
|
||||
|
||||
case GL_RGBA8UI_EXT:
|
||||
case GL_RGB8UI_EXT:
|
||||
case GL_LUMINANCE8UI_EXT:
|
||||
case GL_LUMINANCE_ALPHA8UI_EXT: return GL_UNSIGNED_BYTE;
|
||||
|
||||
case GL_RGBA32I_EXT:
|
||||
case GL_RGB32I_EXT:
|
||||
case GL_LUMINANCE32I_EXT:
|
||||
case GL_LUMINANCE_ALPHA32I_EXT: return GL_INT;
|
||||
|
||||
case GL_RGBA16I_EXT:
|
||||
case GL_RGB16I_EXT:
|
||||
case GL_LUMINANCE16I_EXT:
|
||||
case GL_LUMINANCE_ALPHA16I_EXT: return GL_SHORT;
|
||||
|
||||
case GL_RGB8I_EXT:
|
||||
case GL_RGBA8I_EXT:
|
||||
case GL_LUMINANCE8I_EXT:
|
||||
case GL_LUMINANCE_ALPHA8I_EXT: return GL_BYTE;
|
||||
|
||||
case GL_RGBA:
|
||||
case GL_RGB:
|
||||
case GL_LUMINANCE:
|
||||
case GL_LUMINANCE_ALPHA: return GL_UNSIGNED_BYTE;
|
||||
|
||||
default:
|
||||
{
|
||||
notify(WARN)<<"error computeFormatType = "<<std::hex<<pixelFormat<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int Image::computeNumComponents(GLenum pixelFormat)
|
||||
{
|
||||
switch(pixelFormat)
|
||||
|
||||
Reference in New Issue
Block a user