Browse Source

Support for texture layers.

pull/279/head
Vladimír Vondruš 15 years ago
parent
commit
715d9910a8
  1. 14
      src/AbstractTexture.cpp
  2. 7
      src/AbstractTexture.h
  3. 3
      src/CubeMapTexture.h
  4. 3
      src/Texture.h

14
src/AbstractTexture.cpp

@ -17,6 +17,19 @@
namespace Magnum { namespace Magnum {
#ifndef DOXYGEN_GENERATING_OUTPUT
/* Check corretness of GL_TEXTURE0 + N == GL_TEXTUREN */
#define texture_assert(num) static_assert(GL_TEXTURE0 + num == GL_TEXTURE##num,\
"Unsupported constants for GL texture layers")
texture_assert(0); texture_assert(8); texture_assert(16); texture_assert(24);
texture_assert(1); texture_assert(9); texture_assert(17); texture_assert(25);
texture_assert(2); texture_assert(10); texture_assert(18); texture_assert(26);
texture_assert(3); texture_assert(11); texture_assert(19); texture_assert(27);
texture_assert(4); texture_assert(12); texture_assert(20); texture_assert(28);
texture_assert(5); texture_assert(13); texture_assert(21); texture_assert(29);
texture_assert(6); texture_assert(14); texture_assert(22); texture_assert(30);
texture_assert(7); texture_assert(15); texture_assert(23); texture_assert(31);
/* Check correctness of binary OR in setMinificationFilter(). If nobody fucks /* Check correctness of binary OR in setMinificationFilter(). If nobody fucks
anything up, this assert should produce the same results on all dimensions, anything up, this assert should produce the same results on all dimensions,
thus testing only on AbstractTexture. */ thus testing only on AbstractTexture. */
@ -27,6 +40,7 @@ static_assert(((AbstractTexture::NearestNeighborFilter|AbstractTexture::BaseMipL
((AbstractTexture::LinearFilter|AbstractTexture::NearestMipLevel) == GL_LINEAR_MIPMAP_NEAREST) && ((AbstractTexture::LinearFilter|AbstractTexture::NearestMipLevel) == GL_LINEAR_MIPMAP_NEAREST) &&
((AbstractTexture::LinearFilter|AbstractTexture::LinearMipInterpolation) == GL_LINEAR_MIPMAP_LINEAR), ((AbstractTexture::LinearFilter|AbstractTexture::LinearMipInterpolation) == GL_LINEAR_MIPMAP_LINEAR),
"Unsupported constants for GL texture filtering"); "Unsupported constants for GL texture filtering");
#endif
void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) {
/* Only base mip level is supported on rectangle textures */ /* Only base mip level is supported on rectangle textures */

7
src/AbstractTexture.h

@ -108,11 +108,13 @@ class AbstractTexture {
/** /**
* @brief Constructor * @brief Constructor
* @param layer Texture layer (number between 0 and 31)
* @param target Target, e.g. @c GL_TEXTURE_2D. * @param target Target, e.g. @c GL_TEXTURE_2D.
* *
* Creates one OpenGL texture. * Creates one OpenGL texture.
*/ */
inline AbstractTexture(GLenum target): target(target) { inline AbstractTexture(GLint layer, GLenum target): target(target), _layer(layer) {
glActiveTexture(GL_TEXTURE0 + layer);
glGenTextures(1, &texture); glGenTextures(1, &texture);
} }
@ -127,6 +129,7 @@ class AbstractTexture {
/** @brief Bind texture for usage / rendering */ /** @brief Bind texture for usage / rendering */
inline void bind() const { inline void bind() const {
glActiveTexture(GL_TEXTURE0 + _layer);
glBindTexture(target, texture); glBindTexture(target, texture);
} }
@ -137,6 +140,7 @@ class AbstractTexture {
* particular one. * particular one.
*/ */
inline void unbind() const { inline void unbind() const {
glActiveTexture(GL_TEXTURE0 + _layer);
glBindTexture(target, 0); glBindTexture(target, 0);
} }
@ -231,6 +235,7 @@ class AbstractTexture {
}; };
private: private:
const GLint _layer;
GLuint texture; GLuint texture;
}; };

3
src/CubeMapTexture.h

@ -48,10 +48,11 @@ class CubeMapTexture: public Texture2D {
public: public:
/** /**
* @brief Constructor * @brief Constructor
* @param layer Texture layer (number between 0 and 31)
* *
* Creates texture with target @c GL_TEXTURE_CUBE_MAP. * Creates texture with target @c GL_TEXTURE_CUBE_MAP.
*/ */
inline CubeMapTexture(): Texture2D(GL_TEXTURE_CUBE_MAP) {} inline CubeMapTexture(GLint layer = 0): Texture2D(layer, GL_TEXTURE_CUBE_MAP) {}
protected: protected:
/** @brief Deleted. Use setDataPositiveX() and others instead. */ /** @brief Deleted. Use setDataPositiveX() and others instead. */

3
src/Texture.h

@ -53,13 +53,14 @@ template<size_t dimensions> class Texture: public AbstractTexture {
/** /**
* @brief Constructor * @brief Constructor
* @param layer Texture layer (number between 0 and 31)
* @param target Target, e.g. @c GL_TEXTURE_RECTANGLE. If not set, * @param target Target, e.g. @c GL_TEXTURE_RECTANGLE. If not set,
* target is based on dimension count (@c GL_TEXTURE_1D, * target is based on dimension count (@c GL_TEXTURE_1D,
* @c GL_TEXTURE_2D, @c GL_TEXTURE_3D). * @c GL_TEXTURE_2D, @c GL_TEXTURE_3D).
* *
* Creates one OpenGL texture. * Creates one OpenGL texture.
*/ */
inline Texture(GLenum target = DataHelper<dimensions>::target()): AbstractTexture(target) {} inline Texture(GLint layer = 0, GLenum target = DataHelper<dimensions>::target()): AbstractTexture(layer, target) {}
/** /**
* @brief Set wrapping * @brief Set wrapping

Loading…
Cancel
Save