From c51ea03b5b580c7516eba20b60a08facb995e468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 1 Dec 2011 18:44:51 +0100 Subject: [PATCH] Texture Filter and Mipmap enum refactoring. Renamed the constants so they are better readable when passed to setMinificationFilter(). Using self-documenting values for Mipmap enum, added static_assert which checks their correctness. --- src/Texture.cpp | 11 +++++++++++ src/Texture.h | 14 +++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Texture.cpp b/src/Texture.cpp index 81a7dd7f2..3a10b53f1 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -17,6 +17,17 @@ namespace Magnum { +/* Check correctness of binary OR in setMinificationFilter(). If nobody fucks + anything up, this assert should produce the same results on all dimensions, + thus testing only on Texture1D. */ +static_assert(((Texture1D::NearestNeighborFilter|Texture1D::BaseMipLevel) == GL_NEAREST) && + ((Texture1D::NearestNeighborFilter|Texture1D::NearestMipLevel) == GL_NEAREST_MIPMAP_NEAREST) && + ((Texture1D::NearestNeighborFilter|Texture1D::LinearMipInterpolation) == GL_NEAREST_MIPMAP_LINEAR) && + ((Texture1D::LinearFilter|Texture1D::BaseMipLevel) == GL_LINEAR) && + ((Texture1D::LinearFilter|Texture1D::NearestMipLevel) == GL_LINEAR_MIPMAP_NEAREST) && + ((Texture1D::LinearFilter|Texture1D::LinearMipInterpolation) == GL_LINEAR_MIPMAP_LINEAR), + "Unsupported constants for GL texture filtering"); + template void Texture::setWrapping(const Math::Vector& wrapping) { bind(); for(int i = 0; i != dimensions; ++i) switch(i) { diff --git a/src/Texture.h b/src/Texture.h index e15ed687d..b5cb81ad7 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -43,30 +43,30 @@ template class Texture { /** * Nearest neighbor filtering */ - NearestNeighbor = GL_NEAREST, + NearestNeighborFilter = GL_NEAREST, /** * Linear filtering */ - Linear = GL_LINEAR + LinearFilter = GL_LINEAR }; /** @brief Mip level selection */ enum Mipmap { /** - * Select base mipmap level. + * Select base mip level. */ - BaseLevel = 0, + BaseMipLevel = GL_NEAREST & ~GL_NEAREST, /** * Select nearest mip level. */ - NearestLevel = 0x100, + NearestMipLevel = GL_NEAREST_MIPMAP_NEAREST & ~GL_NEAREST, /** * Linear interpolation of nearest mip levels. */ - LinearInterpolation = 0x102 + LinearMipInterpolation = GL_NEAREST_MIPMAP_LINEAR & ~GL_NEAREST }; /** @brief Texture wrapping on the edge */ @@ -161,7 +161,7 @@ template class Texture { * creating the texture, otherwise it will be unusable. * @see generateMipmap() */ - inline void setMinificationFilter(Filter filter, Mipmap mipmap = BaseLevel) { + inline void setMinificationFilter(Filter filter, Mipmap mipmap = BaseMipLevel) { bind(); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filter|mipmap); unbind();