From 0d0a8a15330226304a6baa265a91e3bf3018823f Mon Sep 17 00:00:00 2001 From: Robert Menzel Date: Fri, 19 Oct 2012 20:49:18 +0200 Subject: [PATCH] added function to get the number of channels from a texture format enum --- include/ACGL/OpenGL/Data/TextureData.hh | 1 - include/ACGL/OpenGL/Tools.hh | 24 ++++++++++++++++++++++++ src/ACGL/OpenGL/Objects/Texture.cc | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/ACGL/OpenGL/Data/TextureData.hh b/include/ACGL/OpenGL/Data/TextureData.hh index 942117a..138e769 100644 --- a/include/ACGL/OpenGL/Data/TextureData.hh +++ b/include/ACGL/OpenGL/Data/TextureData.hh @@ -49,7 +49,6 @@ public: GLsizei getDepth (void) const { return depth; } GLenum getFormat (void) const { return format; } GLenum getType (void) const { return type; } - // ========================================================================================================= \/ // ================================================================================================= SETTERS \/ // ========================================================================================================= \/ diff --git a/include/ACGL/OpenGL/Tools.hh b/include/ACGL/OpenGL/Tools.hh index aef3e0b..061e8a4 100644 --- a/include/ACGL/OpenGL/Tools.hh +++ b/include/ACGL/OpenGL/Tools.hh @@ -40,6 +40,30 @@ inline GLint getGLTypeSize ( GLenum _type ) return 0; } +inline GLuint getNumberOfChannels( GLenum _format ) +{ + if (_format == GL_R || _format == GL_R8I || _format == GL_R16I || _format == GL_R32I + || _format == GL_R8UI || _format == GL_R16UI || _format == GL_R32UI + || _format == GL_R16F || _format == GL_R32F ) return 1; + if (_format == GL_RED_INTEGER || _format == GL_GREEN_INTEGER || _format == GL_BLUE_INTEGER || _format == GL_ALPHA_INTEGER) return 1; + + if (_format == GL_RG || _format == GL_RG8I || _format == GL_RG16I || _format == GL_RG32I + || _format == GL_RG8UI || _format == GL_RG16UI || _format == GL_RG32UI + || _format == GL_RG16F || _format == GL_RG32F ) return 2; + + if (_format == GL_RGB || _format == GL_RGB8I || _format == GL_RGB16I || _format == GL_RGB32I + || _format == GL_RGB8UI || _format == GL_RGB16UI || _format == GL_RGB32UI + || _format == GL_RGB16F || _format == GL_RGB32F ) return 3; + if (_format == GL_BGR || _format == GL_RGB_INTEGER || _format == GL_BGR_INTEGER) return 3; + + if (_format == GL_RGBA || _format == GL_RGBA8I || _format == GL_RGBA16I || _format == GL_RGBA32I + || _format == GL_RGBA8UI || _format == GL_RGBA16UI || _format == GL_RGBA32UI + || _format == GL_RGBA16F || _format == GL_RGBA32F ) return 4; + if (_format == GL_BGRA || _format == GL_RGBA_INTEGER || _format == GL_BGRA_INTEGER) return 4; + + return 1; // unknown number of channels, assume 1 +} + uint32_t getOpenGLMinorVersionNumber(); uint32_t getOpenGLMajorVersionNumber(); diff --git a/src/ACGL/OpenGL/Objects/Texture.cc b/src/ACGL/OpenGL/Objects/Texture.cc index e2600b5..12335d5 100644 --- a/src/ACGL/OpenGL/Objects/Texture.cc +++ b/src/ACGL/OpenGL/Objects/Texture.cc @@ -114,7 +114,7 @@ SharedTextureData Texture::getImageData(GLint _lod, GLenum _type) const dataObject->setHeight(height); dataObject->setDepth(depth); dataObject->setType(_type); - dataObject->setFormat(GL_RGB); + dataObject->setFormat(mFormat); dataObject->setData(imageData); // dataObject will take care of freeing imageData return dataObject; -- GitLab