Browse Source

Method chaining for textures.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
f3a07f82f4
  1. 10
      src/AbstractTexture.cpp
  2. 18
      src/AbstractTexture.h
  3. 11
      src/CubeMapTexture.h
  4. 14
      src/CubeMapTextureArray.h
  5. 12
      src/Texture.h

10
src/AbstractTexture.cpp

@ -48,23 +48,25 @@ GLfloat AbstractTexture::maxSupportedAnisotropy() {
} }
#endif #endif
void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { AbstractTexture* AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", ); CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", this);
#endif #endif
bind(); bind();
glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, glTexParameteri(_target, GL_TEXTURE_MIN_FILTER,
static_cast<GLint>(filter)|static_cast<GLint>(mipmap)); static_cast<GLint>(filter)|static_cast<GLint>(mipmap));
return this;
} }
void AbstractTexture::generateMipmap() { AbstractTexture* AbstractTexture::generateMipmap() {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", ); CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", this);
#endif #endif
bind(); bind();
glGenerateMipmap(_target); glGenerateMipmap(_target);
return this;
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES

18
src/AbstractTexture.h

@ -587,6 +587,7 @@ class MAGNUM_EXPORT AbstractTexture {
* @param mipmap Mipmap filtering. If set to anything else than * @param mipmap Mipmap filtering. If set to anything else than
* BaseMipLevel, make sure textures for all mip levels are set or * BaseMipLevel, make sure textures for all mip levels are set or
* call generateMipmap(). * call generateMipmap().
* @return Pointer to self (for method chaining)
* *
* Sets filter used when the object pixel size is smaller than the * Sets filter used when the object pixel size is smaller than the
* texture size. * texture size.
@ -595,55 +596,62 @@ class MAGNUM_EXPORT AbstractTexture {
* @ref AbstractTexture::Mipmap "Mipmap" documentation for more * @ref AbstractTexture::Mipmap "Mipmap" documentation for more
* information. * information.
*/ */
void setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel); AbstractTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel);
/** /**
* @brief Set magnification filter * @brief Set magnification filter
* @param filter Filter * @param filter Filter
* @return Pointer to self (for method chaining)
* *
* Sets filter used when the object pixel size is larger than largest * Sets filter used when the object pixel size is larger than largest
* texture size. * texture size.
*/ */
inline void setMagnificationFilter(Filter filter) { inline AbstractTexture* setMagnificationFilter(Filter filter) {
bind(); bind();
glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(filter)); glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(filter));
return this;
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/** /**
* @brief Set border color * @brief Set border color
* @return Pointer to self (for method chaining)
* *
* Border color when @ref AbstractTexture::Wrapping "wrapping" is set * Border color when @ref AbstractTexture::Wrapping "wrapping" is set
* to `ClampToBorder`. * to `ClampToBorder`.
* @requires_gl * @requires_gl
*/ */
inline void setBorderColor(const Color4<GLfloat>& color) { inline AbstractTexture* setBorderColor(const Color4<GLfloat>& color) {
bind(); bind();
glTexParameterfv(_target, GL_TEXTURE_BORDER_COLOR, color.data()); glTexParameterfv(_target, GL_TEXTURE_BORDER_COLOR, color.data());
return this;
} }
/** /**
* @brief Set max anisotropy * @brief Set max anisotropy
* @return Pointer to self (for method chaining)
* *
* Default value is `1.0`, which means no anisotropy. Set to value * Default value is `1.0`, which means no anisotropy. Set to value
* greater than `1.0` for anisotropic filtering. * greater than `1.0` for anisotropic filtering.
* @see maxSupportedAnisotropy() * @see maxSupportedAnisotropy()
* @requires_extension @extension{EXT,texture_filter_anisotropic} * @requires_extension @extension{EXT,texture_filter_anisotropic}
*/ */
inline void setMaxAnisotropy(GLfloat anisotropy) { inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) {
bind(); bind();
glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);
return this;
} }
#endif #endif
/** /**
* @brief Generate mipmap * @brief Generate mipmap
* @return Pointer to self (for method chaining)
* *
* Can not be used for rectangle textures. * Can not be used for rectangle textures.
* @see setMinificationFilter() * @see setMinificationFilter()
* @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_gl30 Extension @extension{EXT,framebuffer_object}
*/ */
void generateMipmap(); AbstractTexture* generateMipmap();
protected: protected:
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT

11
src/CubeMapTexture.h

@ -81,27 +81,32 @@ class CubeMapTexture: public AbstractTexture {
/** /**
* @copydoc Texture::setWrapping() * @copydoc Texture::setWrapping()
*/ */
inline void setWrapping(const Math::Vector<3, Wrapping>& wrapping) { inline CubeMapTexture* setWrapping(const Math::Vector<3, Wrapping>& wrapping) {
bind(); bind();
DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP, wrapping); DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP, wrapping);
return this;
} }
/** /**
* @copydoc Texture::setData(GLint, InternalFormat, Image*) * @copydoc Texture::setData(GLint, InternalFormat, Image*)
* @param coordinate Coordinate * @param coordinate Coordinate
* @return Pointer to self (for method chaining)
*/ */
template<class Image> inline void setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { template<class Image> inline CubeMapTexture* setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) {
bind(); bind();
DataHelper<2>::set(static_cast<GLenum>(coordinate), mipLevel, internalFormat, image); DataHelper<2>::set(static_cast<GLenum>(coordinate), mipLevel, internalFormat, image);
return this;
} }
/** /**
* @copydoc Texture::setSubData(GLint, const Math::Vector<Dimensions, GLint>&, Image*) * @copydoc Texture::setSubData(GLint, const Math::Vector<Dimensions, GLint>&, Image*)
* @param coordinate Coordinate * @param coordinate Coordinate
* @return Pointer to self (for method chaining)
*/ */
template<class Image> inline void setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { template<class Image> inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) {
bind(); bind();
DataHelper<2>::setSub(static_cast<GLenum>(coordinate), mipLevel, offset, image); DataHelper<2>::setSub(static_cast<GLenum>(coordinate), mipLevel, offset, image);
return this;
} }
}; };

14
src/CubeMapTextureArray.h

@ -66,9 +66,10 @@ class CubeMapTextureArray: public AbstractTexture {
/** /**
* @copydoc Texture::setWrapping() * @copydoc Texture::setWrapping()
*/ */
inline void setWrapping(const Math::Vector<3, Wrapping>& wrapping) { inline CubeMapTextureArray* setWrapping(const Math::Vector<3, Wrapping>& wrapping) {
bind(); bind();
DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP_ARRAY, wrapping); DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP_ARRAY, wrapping);
return this;
} }
/** /**
@ -78,9 +79,10 @@ class CubeMapTextureArray: public AbstractTexture {
* for all layers. Each group of 6 2D images is one cube map layer. * for all layers. Each group of 6 2D images is one cube map layer.
* The images are ordered the same way as Coordinate enum. * The images are ordered the same way as Coordinate enum.
*/ */
template<class T> inline void setData(GLint mipLevel, InternalFormat internalFormat, T* image) { template<class T> inline CubeMapTextureArray* setData(GLint mipLevel, InternalFormat internalFormat, T* image) {
bind(); bind();
DataHelper<3>::set(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); DataHelper<3>::set(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image);
return this;
} }
/** /**
@ -89,6 +91,7 @@ class CubeMapTextureArray: public AbstractTexture {
* @param offset Offset where to put data in the texture * @param offset Offset where to put data in the texture
* @param image Three-dimensional Image, BufferedImage or for * @param image Three-dimensional Image, BufferedImage or for
* example Trade::ImageData * example Trade::ImageData
* @return Pointer to self (for method chaining)
* *
* Sets texture subdata from given image. The image is not deleted * Sets texture subdata from given image. The image is not deleted
* afterwards. * afterwards.
@ -100,9 +103,10 @@ class CubeMapTextureArray: public AbstractTexture {
* *
* @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*)
*/ */
template<class Image> inline void setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { template<class Image> inline CubeMapTextureArray* setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) {
bind(); bind();
DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector<Image::Dimensions, GLsizei>())); DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector<Image::Dimensions, GLsizei>()));
return this;
} }
/** /**
@ -113,15 +117,17 @@ class CubeMapTextureArray: public AbstractTexture {
* @param offset Offset where to put data in the texture * @param offset Offset where to put data in the texture
* @param image Two-dimensional Image, BufferedImage or for * @param image Two-dimensional Image, BufferedImage or for
* example Trade::ImageData * example Trade::ImageData
* @return Pointer to self (for method chaining)
* *
* Sets texture subdata from given image. The image is not deleted * Sets texture subdata from given image. The image is not deleted
* afterwards. * afterwards.
* *
* @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*)
*/ */
template<class Image> inline void setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { template<class Image> inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) {
bind(); bind();
DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast<GLsizei>(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector<Image::Dimensions, GLsizei>())); DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast<GLsizei>(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector<Image::Dimensions, GLsizei>()));
return this;
} }
}; };

12
src/Texture.h

@ -114,6 +114,7 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
/** /**
* @brief Set wrapping * @brief Set wrapping
* @param wrapping Wrapping type for all texture dimensions * @param wrapping Wrapping type for all texture dimensions
* @return Pointer to self (for method chaining)
* *
* Sets wrapping type for coordinates out of range (0, 1) for normal * Sets wrapping type for coordinates out of range (0, 1) for normal
* textures and (0, textureSizeInGivenDirection-1) for rectangle * textures and (0, textureSizeInGivenDirection-1) for rectangle
@ -122,9 +123,10 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
* see @ref AbstractTexture::Wrapping "Wrapping" documentation for * see @ref AbstractTexture::Wrapping "Wrapping" documentation for
* more information. * more information.
*/ */
inline void setWrapping(const Math::Vector<Dimensions, Wrapping>& wrapping) { inline Texture<Dimensions>* setWrapping(const Math::Vector<Dimensions, Wrapping>& wrapping) {
bind(); bind();
DataHelper<Dimensions>::setWrapping(_target, wrapping); DataHelper<Dimensions>::setWrapping(_target, wrapping);
return this;
} }
/** /**
@ -133,13 +135,15 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
* @param internalFormat Internal texture format * @param internalFormat Internal texture format
* @param image Image, BufferedImage or for example * @param image Image, BufferedImage or for example
* Trade::ImageData of the same dimension count * Trade::ImageData of the same dimension count
* @return Pointer to self (for method chaining)
* *
* Sets texture data from given image. The image is not deleted * Sets texture data from given image. The image is not deleted
* afterwards. * afterwards.
*/ */
template<class Image> inline void setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { template<class Image> inline Texture<Dimensions>* setData(GLint mipLevel, InternalFormat internalFormat, Image* image) {
bind(); bind();
DataHelper<Dimensions>::set(_target, mipLevel, internalFormat, image); DataHelper<Dimensions>::set(_target, mipLevel, internalFormat, image);
return this;
} }
/** /**
@ -148,6 +152,7 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
* @param offset Offset where to put data in the texture * @param offset Offset where to put data in the texture
* @param image Image, BufferedImage or for example * @param image Image, BufferedImage or for example
* Trade::ImageData * Trade::ImageData
* @return Pointer to self (for method chaining)
* *
* Sets texture subdata from given image. The image is not deleted * Sets texture subdata from given image. The image is not deleted
* afterwards. The image can have either the same dimension count or * afterwards. The image can have either the same dimension count or
@ -158,9 +163,10 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
* for e.g. updating 3D texture with multiple 2D images or for filling * for e.g. updating 3D texture with multiple 2D images or for filling
* 1D texture array (which is two-dimensional) with 1D images. * 1D texture array (which is two-dimensional) with 1D images.
*/ */
template<class Image> inline void setSubData(GLint mipLevel, const Math::Vector<Dimensions, GLint>& offset, Image* image) { template<class Image> inline Texture<Dimensions>* setSubData(GLint mipLevel, const Math::Vector<Dimensions, GLint>& offset, Image* image) {
bind(); bind();
DataHelper<Dimensions>::setSub(_target, mipLevel, offset, image); DataHelper<Dimensions>::setSub(_target, mipLevel, offset, image);
return this;
} }
}; };

Loading…
Cancel
Save