From 7f36c4537cd76e36f43a8638705f857e4dc1914e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 May 2015 20:30:22 +0200 Subject: [PATCH] Fixed texture wrapping for cube map and array textures (with story!). The original problem was that I was using 3D wrapping mode (S, T, R) for cube map textures, but GL_TEXTURE_WRAP_R was not defined on ES2 so it seemed rather suspicious. Google seems to be lost on this and most of the online tutorials seem to be setting GL_TEXTURE_WRAP_R even for cube map textures, so I need to investigate myself. As seen in the rather old ARB_texture_cube_map extension, there is no new GL_TEXTURE_WRAP_R token added, it is defined only for 3D textures and there is no apparent dependency between these two. The wrap mode for cube maps is defined as follows: * The sampler determines one of the six faces and then employs conventional 2D texture mapping on given face. Thus wrapping mode for CubeMapTexture is now changed to be only two-dimensional (instead of 3D). For texture arrays the mode is also only one- or two-dimensional (not two- or three-dimensional), because, as said in the (also rather old) EXT_texture_array extension, the texture layer is _always_ (independently of any sampling state) selected as follows: l = clamp(round(t), 0, num_layers - 1) Thus wrapping mode for Texture1DArray is now changed to be only one-dimensional (instead of 2D) and for Texture2DArray only two-dimensional (instead of 3D). Wrapping for CubeMapTextureArray is now also two-dimensional instead of 3D (with the original way of thinking it would have needed to be 4D!). --- src/Magnum/AbstractTexture.cpp | 6 +++++- src/Magnum/AbstractTexture.h | 2 -- src/Magnum/CubeMapTexture.h | 4 ++-- src/Magnum/CubeMapTextureArray.h | 4 ++-- src/Magnum/TextureArray.h | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Magnum/AbstractTexture.cpp b/src/Magnum/AbstractTexture.cpp index 930bba84c..90d2616b7 100644 --- a/src/Magnum/AbstractTexture.cpp +++ b/src/Magnum/AbstractTexture.cpp @@ -1520,15 +1520,19 @@ void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture& texture, const (texture.*state.parameteriImplementation)(GL_TEXTURE_WRAP_T, GLint(wrapping.y())); } +#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture& texture, const Array3D& wrapping) { const Implementation::TextureState& state = *Context::current()->state().texture; (texture.*state.parameteriImplementation)(GL_TEXTURE_WRAP_S, GLint(wrapping.x())); (texture.*state.parameteriImplementation)(GL_TEXTURE_WRAP_T, GLint(wrapping.y())); - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 (texture.*state.parameteriImplementation)(GL_TEXTURE_WRAP_R, GLint(wrapping.z())); + #else + (texture.*state.parameteriImplementation)(GL_TEXTURE_WRAP_R_OES, GLint(wrapping.z())); #endif } #endif +#endif } diff --git a/src/Magnum/AbstractTexture.h b/src/Magnum/AbstractTexture.h index e80476d45..1380fd526 100644 --- a/src/Magnum/AbstractTexture.h +++ b/src/Magnum/AbstractTexture.h @@ -619,11 +619,9 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { #ifndef MAGNUM_TARGET_GLES2 static Vector3i imageSize(AbstractTexture& texture, GLint level); #endif - #endif static void setWrapping(AbstractTexture& texture, const Array3D& wrapping); - #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) static void setStorage(AbstractTexture& texture, GLsizei levels, TextureFormat internalFormat, const Vector3i& size); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Magnum/CubeMapTexture.h b/src/Magnum/CubeMapTexture.h index 201513b59..26c62cb20 100644 --- a/src/Magnum/CubeMapTexture.h +++ b/src/Magnum/CubeMapTexture.h @@ -235,8 +235,8 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture { * * See @ref Texture::setWrapping() for more information. */ - CubeMapTexture& setWrapping(const Array3D& wrapping) { - DataHelper<3>::setWrapping(*this, wrapping); + CubeMapTexture& setWrapping(const Array2D& wrapping) { + DataHelper<2>::setWrapping(*this, wrapping); return *this; } diff --git a/src/Magnum/CubeMapTextureArray.h b/src/Magnum/CubeMapTextureArray.h index a104fdef2..ab590ec7a 100644 --- a/src/Magnum/CubeMapTextureArray.h +++ b/src/Magnum/CubeMapTextureArray.h @@ -204,8 +204,8 @@ class MAGNUM_EXPORT CubeMapTextureArray: public AbstractTexture { * * See @ref Texture::setWrapping() for more information. */ - CubeMapTextureArray& setWrapping(const Array3D& wrapping) { - DataHelper<3>::setWrapping(*this, wrapping); + CubeMapTextureArray& setWrapping(const Array2D& wrapping) { + DataHelper<2>::setWrapping(*this, wrapping); return *this; } diff --git a/src/Magnum/TextureArray.h b/src/Magnum/TextureArray.h index 23bed1ede..b78b669ff 100644 --- a/src/Magnum/TextureArray.h +++ b/src/Magnum/TextureArray.h @@ -224,8 +224,8 @@ template class TextureArray: public AbstractTexture { * * See @ref Texture::setWrapping() for more information. */ - TextureArray& setWrapping(const Array& wrapping) { - DataHelper::setWrapping(*this, wrapping); + TextureArray& setWrapping(const Array& wrapping) { + DataHelper::setWrapping(*this, wrapping); return *this; }