diff --git a/src/OpenGl/OpenGl_Texture.hxx b/src/OpenGl/OpenGl_Texture.hxx index 4c43896135..e3433a6afb 100644 --- a/src/OpenGl/OpenGl_Texture.hxx +++ b/src/OpenGl/OpenGl_Texture.hxx @@ -49,6 +49,11 @@ struct OpenGl_TextureFormatSelector return GL_NONE; } } + + static GLint DataType() + { + return GL_UNSIGNED_BYTE; + } }; template<> @@ -70,6 +75,11 @@ struct OpenGl_TextureFormatSelector return GL_NONE; } } + + static GLint DataType() + { + return GL_UNSIGNED_SHORT; + } }; template<> @@ -91,8 +101,120 @@ struct OpenGl_TextureFormatSelector return GL_NONE; } } + + static GLint DataType() + { + return GL_FLOAT; + } }; +template<> +struct OpenGl_TextureFormatSelector +{ + static GLint Internal (GLuint theChannels) + { + switch (theChannels) + { + case 1: + return GL_RED; + case 2: + return GL_RG; + case 3: + return GL_RGB; + case 4: + return GL_RGBA; + default: + return GL_NONE; + } + } + + static GLint DataType() + { + return GL_UNSIGNED_INT; + } +}; + +//! Only unsigned formats are available in OpenGL ES 2.0 +#if !defined(GL_ES_VERSION_2_0) +template<> +struct OpenGl_TextureFormatSelector +{ + static GLint Internal (GLuint theChannels) + { + switch (theChannels) + { + case 1: + return GL_R8_SNORM; + case 2: + return GL_RG8_SNORM; + case 3: + return GL_RGB8_SNORM; + case 4: + return GL_RGBA8_SNORM; + default: + return GL_NONE; + } + } + + static GLint DataType() + { + return GL_BYTE; + } +}; + +template<> +struct OpenGl_TextureFormatSelector +{ + static GLint Internal (GLuint theChannels) + { + switch (theChannels) + { + case 1: + return GL_R16_SNORM; + case 2: + return GL_RG16_SNORM; + case 3: + return GL_RGB16_SNORM; + case 4: + return GL_RGBA16_SNORM; + default: + return GL_NONE; + } + } + + static GLint DataType() + { + return GL_SHORT; + } +}; + +template<> +struct OpenGl_TextureFormatSelector +{ + static GLint Internal (GLuint theChannels) + { + switch (theChannels) + { + case 1: + return GL_RED_SNORM; + case 2: + return GL_RG_SNORM; + case 3: + return GL_RGB_SNORM; + case 4: + return GL_RGBA_SNORM; + default: + return GL_NONE; + } + } + + static GLint DataType() + { + return GL_INT; + } +}; +#endif + //! Stores parameters of OpenGL texture format. class OpenGl_TextureFormat { @@ -124,25 +246,36 @@ public: return myInternal; } + //! Returns OpenGL data type of the pixel data. + inline GLint DataType() const + { + return myDataType; + } + //! Returns texture format for specified type and number of channels. template static OpenGl_TextureFormat Create() { - return OpenGl_TextureFormat (N, OpenGl_TextureFormatSelector::Internal (N)); + return OpenGl_TextureFormat (N, + OpenGl_TextureFormatSelector::Internal(N), + OpenGl_TextureFormatSelector::DataType()); } private: //! Creates new texture format. OpenGl_TextureFormat (const GLint theChannels, - const GLint theInternal) + const GLint theInternal, + const GLint theDataType) : myInternal (theInternal), - myChannels (theChannels) {} + myChannels (theChannels), + myDataType (theDataType) {} private: GLint myInternal; //!< OpenGL internal format of the pixel data GLint myChannels; //!< Number of channels for each pixel (from 1 to 4) + GLint myDataType; //!< OpenGL data type of input pixel data };