Browse Source

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!).
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
7f36c4537c
  1. 6
      src/Magnum/AbstractTexture.cpp
  2. 2
      src/Magnum/AbstractTexture.h
  3. 4
      src/Magnum/CubeMapTexture.h
  4. 4
      src/Magnum/CubeMapTextureArray.h
  5. 4
      src/Magnum/TextureArray.h

6
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<Sampler::Wrapping>& 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
}

2
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<Sampler::Wrapping>& 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

4
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<Sampler::Wrapping>& wrapping) {
DataHelper<3>::setWrapping(*this, wrapping);
CubeMapTexture& setWrapping(const Array2D<Sampler::Wrapping>& wrapping) {
DataHelper<2>::setWrapping(*this, wrapping);
return *this;
}

4
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<Sampler::Wrapping>& wrapping) {
DataHelper<3>::setWrapping(*this, wrapping);
CubeMapTextureArray& setWrapping(const Array2D<Sampler::Wrapping>& wrapping) {
DataHelper<2>::setWrapping(*this, wrapping);
return *this;
}

4
src/Magnum/TextureArray.h

@ -224,8 +224,8 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
*
* See @ref Texture::setWrapping() for more information.
*/
TextureArray<dimensions>& setWrapping(const Array<dimensions+1, Sampler::Wrapping>& wrapping) {
DataHelper<dimensions+1>::setWrapping(*this, wrapping);
TextureArray<dimensions>& setWrapping(const Array<dimensions, Sampler::Wrapping>& wrapping) {
DataHelper<dimensions>::setWrapping(*this, wrapping);
return *this;
}

Loading…
Cancel
Save