diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index eb6685145..2fb59e011 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -200,8 +200,16 @@ class AbstractTexture { * * Workaround for partial template specialization. */ - template struct DataHelper { + template struct DataHelper { #ifdef DOXYGEN_GENERATING_OUTPUT + /** + * @brief Target for given dimension + * + * Returns @c GL_TEXTURE_1D, @c GL_TEXTURE_2D or @c GL_TEXTURE_3D + * based on dimension count. + */ + inline constexpr static GLenum target(); + /** * @brief Set texture data * @param target Target, such as @c GL_TEXTURE_RECTANGLE @@ -218,32 +226,38 @@ class AbstractTexture { * Calls @c glTexImage1D, @c glTexImage2D, @c glTexImage3D depending * on dimension count. */ - inline void operator()(GLenum target, GLint mipLevel, int internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data); + template inline static void set(GLenum target, GLint mipLevel, int internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data); #endif }; - #ifndef DOXYGEN_GENERATING_OUTPUT - template struct DataHelper { - inline void operator()(GLenum target, GLint mipLevel, int internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { - glTexImage1D(target, mipLevel, internalFormat, dimensions.at(0), 0, colorFormat, TypeTraits::glType(), data); - } - }; - template struct DataHelper { - inline void operator()(GLenum target, GLint mipLevel, int internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { - glTexImage2D(target, mipLevel, internalFormat, dimensions.at(0), dimensions.at(1), 0, colorFormat, TypeTraits::glType(), data); - } - }; - template struct DataHelper { - inline void operator()(GLenum target, GLint mipLevel, int internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { - glTexImage3D(target, mipLevel, internalFormat, dimensions.at(0), dimensions.at(1), dimensions.at(2), 0, colorFormat, TypeTraits::glType(), data); - } - }; - #endif - private: GLuint texture; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +template<> struct AbstractTexture::DataHelper<1> { + inline constexpr static GLenum target() { return GL_TEXTURE_1D; } + + template inline static void set(GLenum target, GLint mipLevel, int internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { + glTexImage1D(target, mipLevel, internalFormat, dimensions.at(0), 0, colorFormat, TypeTraits::glType(), data); + } +}; +template<> struct AbstractTexture::DataHelper<2> { + inline constexpr static GLenum target() { return GL_TEXTURE_2D; } + + template inline static void set(GLenum target, GLint mipLevel, int internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { + glTexImage2D(target, mipLevel, internalFormat, dimensions.at(0), dimensions.at(1), 0, colorFormat, TypeTraits::glType(), data); + } +}; +template<> struct AbstractTexture::DataHelper<3> { + inline constexpr static GLenum target() { return GL_TEXTURE_3D; } + + template inline static void set(GLenum target, GLint mipLevel, int internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, const T* data) { + glTexImage3D(target, mipLevel, internalFormat, dimensions.at(0), dimensions.at(1), dimensions.at(2), 0, colorFormat, TypeTraits::glType(), data); + } +}; +#endif + } #endif diff --git a/src/Texture.h b/src/Texture.h index 7ad89213a..ce9d79c6f 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -59,7 +59,7 @@ template class Texture: public AbstractTexture { * * Creates one OpenGL texture. */ - inline Texture(GLenum target = GL_TEXTURE_1D + dimensions - 1): AbstractTexture(target) {} + inline Texture(GLenum target = DataHelper::target()): AbstractTexture(target) {} /** * @brief Set wrapping @@ -86,7 +86,7 @@ template class Texture: public AbstractTexture { */ template inline void setData(GLint mipLevel, int internalFormat, const Math::Vector& _dimensions, ColorFormat colorFormat, const T* data) { bind(); - DataHelper::TextureType, dimensions>()(target, mipLevel, internalFormat, _dimensions, colorFormat, data); + DataHelper::template set::TextureType>(target, mipLevel, internalFormat, _dimensions, colorFormat, data); unbind(); } };