From 47f518d1c7c4800bbf8b7487096b9820909fa26f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 30 Nov 2008 15:56:47 +0000 Subject: [PATCH] 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." --- include/osg/Image | 10 +++++++++ src/osg/Image.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/include/osg/Image b/include/osg/Image index 4773f9c36..2e937b0a6 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -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; diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index a77155810..90ce0fb58 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -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 = "<