From 61bceb84622e4ba7953277b03e2896dca0e591f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 May 2012 18:31:16 +0200 Subject: [PATCH] Cube map texture array. --- src/AbstractTexture.h | 3 +- src/CubeMapTexture.h | 3 +- src/CubeMapTextureArray.h | 131 ++++++++++++++++++++++++++++++++++++++ src/Texture.h | 2 +- 4 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/CubeMapTextureArray.h diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index f48e2ca6d..296e75332 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -26,7 +26,8 @@ namespace Magnum { /** @brief Non-templated base for one-, two- or three-dimensional textures. -See Texture, CubeMapTexture documentation for more information. +See Texture, CubeMapTexture and CubeMapTextureArray documentation for more +information. @todo Add glPixelStore encapsulation @todo Anisotropic filtering */ diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index aedb52a5f..05882293d 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -43,7 +43,8 @@ textures, coordinates for cube map textures is signed three-part vector from the center of the cube, which intersects one of the six sides of the cube map. See Texture documentation for more information about usage. -@todo Cube map arrays (OpenGL 4.0, ARB_texture_cube_map_array) + +@see CubeMapTextureArray */ class CubeMapTexture: public AbstractTexture { public: diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h new file mode 100644 index 000000000..129b4fb4c --- /dev/null +++ b/src/CubeMapTextureArray.h @@ -0,0 +1,131 @@ +#ifndef Magnum_CubeMapTextureArray_h +#define Magnum_CubeMapTextureArray_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::CubeMapTextureArray + */ + +#include "Texture.h" + +namespace Magnum { + +/** +@brief Cube map texture array + +For information about usage, see CubeMapTexture class documentation. + +When using cube map texture in the shader, use `samplerCubeArray`. Unlike +classic textures, coordinates for cube map textures is signed three-part +vector from the center of the cube, which intersects one of the six sides of +the cube map. + +@requires_gl40 Extension ARB_texture_cube_map_array +*/ +class CubeMapTextureArray: public AbstractTexture { + public: + /** @brief Cube map coordinate */ + enum Coordinate: GLsizei { + PositiveX = 0, /**< +X cube side */ + NegativeX = 1, /**< -X cube side */ + PositiveY = 2, /**< +Y cube side */ + NegativeY = 3, /**< -Y cube side */ + PositiveZ = 4, /**< +Z cube side */ + NegativeZ = 5 /**< -Z cube side */ + }; + + /** + * @brief Enable/disable seamless cube map textures + * + * @requires_gl32 Extension ARB_seamless_cube_map + */ + inline static void setSeamless(bool enabled) { + enabled ? glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS) : glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); + } + + /** + * @brief Constructor + * @param layer Texture layer (number between 0 and 31) + * + * Creates one cube map OpenGL texture. + */ + inline CubeMapTextureArray(GLint layer = 0): AbstractTexture(layer, GL_TEXTURE_CUBE_MAP_ARRAY) {} + + /** + * @copydoc Texture::setWrapping() + */ + inline void setWrapping(const Math::Vector<3, Wrapping>& wrapping) { + bind(); + DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP_ARRAY, wrapping); + } + + /** + * @copydoc Texture::setData(GLint, InternalFormat, Image*) + * + * Sets texture data from three-dimensional image for all cube faces + * for all layers. Each group of 6 2D images is one cube map layer. + * The images are ordered the same way as Coordinate enum. + */ + template inline void setData(GLint mipLevel, InternalFormat internalFormat, T* image) { + bind(); + DataHelper<3>::set(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); + } + + /** + * @brief Set texture subdata from 3D image + * @param mipLevel Mip level + * @param offset Offset where to put data in the texture + * @param image Three-dimensional Image, BufferedImage or for + * example Trade::ImageData + * + * Sets texture subdata from given image. The image is not deleted + * afterwards. + * + * Z coordinate of @p offset specifies layer and cube map face. If + * you want to start at given face in layer *n*, you have to specify + * Z coordinate as @f$ 6n + i @f$, where i is face index as specified + * in Coordinate enum. + * + * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) + */ + template inline void setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { + bind(); + DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector())); + } + + /** + * @brief Set texture subdata from 2D image + * @param layer Array layer + * @param coordinate Coordinate + * @param mipLevel Mip level + * @param offset Offset where to put data in the texture + * @param image Two-dimensional Image, BufferedImage or for + * example Trade::ImageData + * + * Sets texture subdata from given image. The image is not deleted + * afterwards. + * + * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) + */ + template inline void setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { + bind(); + DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); + } +}; + +} + +#endif diff --git a/src/Texture.h b/src/Texture.h index 644d1300e..b735bef78 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -50,7 +50,7 @@ for more information. @requires_gl31 Extension ARB_texture_rectangle (rectangle textures) -@see CubeMapTexture +@see CubeMapTexture, CubeMapTextureArray */ template class Texture: public AbstractTexture { public: