|
|
|
|
/*
|
|
|
|
|
This file is part of Magnum.
|
|
|
|
|
|
|
|
|
|
Copyright © 2010, 2011, 2012, 2013, 2014
|
|
|
|
|
Vladimír Vondruš <mosra@centrum.cz>
|
|
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
to deal in the Software without restriction, including without limitation
|
|
|
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
|
in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Sampler.h"
|
|
|
|
|
|
|
|
|
|
#include <Corrade/Utility/Debug.h>
|
|
|
|
|
|
|
|
|
|
#include "Magnum/Context.h"
|
|
|
|
|
#include "Magnum/Implementation/State.h"
|
|
|
|
|
#include "Magnum/Implementation/TextureState.h"
|
|
|
|
|
#include "Magnum/Extensions.h"
|
|
|
|
|
|
|
|
|
|
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 AbstractTexture. */
|
|
|
|
|
#define filter_or(filter, mipmap) (GLint(Sampler::Filter::filter)|GLint(Sampler::Mipmap::mipmap))
|
|
|
|
|
static_assert((filter_or(Nearest, Base) == GL_NEAREST) &&
|
|
|
|
|
(filter_or(Nearest, Nearest) == GL_NEAREST_MIPMAP_NEAREST) &&
|
|
|
|
|
(filter_or(Nearest, Linear) == GL_NEAREST_MIPMAP_LINEAR) &&
|
|
|
|
|
(filter_or(Linear, Base) == GL_LINEAR) &&
|
|
|
|
|
(filter_or(Linear, Nearest) == GL_LINEAR_MIPMAP_NEAREST) &&
|
|
|
|
|
(filter_or(Linear, Linear) == GL_LINEAR_MIPMAP_LINEAR),
|
|
|
|
|
"Unsupported constants for GL texture filtering");
|
|
|
|
|
#undef filter_or
|
|
|
|
|
|
|
|
|
|
Float Sampler::maxMaxAnisotropy() {
|
|
|
|
|
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_filter_anisotropic>())
|
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
|
|
GLfloat& value = Context::current()->state().texture->maxMaxAnisotropy;
|
|
|
|
|
|
|
|
|
|
/* Get the value, if not already cached */
|
|
|
|
|
if(value == 0.0f)
|
|
|
|
|
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &value);
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef DOXYGEN_GENERATING_OUTPUT
|
|
|
|
|
Debug operator<<(Debug debug, const Sampler::Filter value) {
|
|
|
|
|
switch(value) {
|
|
|
|
|
#define _c(value) case Sampler::Filter::value: return debug << "Sampler::Filter::" #value;
|
|
|
|
|
_c(Nearest)
|
|
|
|
|
_c(Linear)
|
|
|
|
|
#undef _c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return debug << "Sampler::Filter::(invalid)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug operator<<(Debug debug, const Sampler::Mipmap value) {
|
|
|
|
|
switch(value) {
|
|
|
|
|
#define _c(value) case Sampler::Mipmap::value: return debug << "Sampler::Mipmap::" #value;
|
|
|
|
|
_c(Base)
|
|
|
|
|
_c(Nearest)
|
|
|
|
|
_c(Linear)
|
|
|
|
|
#undef _c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return debug << "Sampler::Mipmap::(invalid)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug operator<<(Debug debug, const Sampler::Wrapping value) {
|
|
|
|
|
switch(value) {
|
|
|
|
|
#define _c(value) case Sampler::Wrapping::value: return debug << "Sampler::Wrapping::" #value;
|
|
|
|
|
_c(Repeat)
|
|
|
|
|
_c(MirroredRepeat)
|
|
|
|
|
_c(ClampToEdge)
|
|
|
|
|
_c(ClampToBorder)
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
_c(MirrorClampToEdge)
|
|
|
|
|
#endif
|
|
|
|
|
#undef _c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return debug << "Sampler::Wrapping::(invalid)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
Debug operator<<(Debug debug, const Sampler::DepthStencilMode value) {
|
|
|
|
|
switch(value) {
|
|
|
|
|
#define _c(value) case Sampler::DepthStencilMode::value: return debug << "Sampler::DepthStencilMode::" #value;
|
|
|
|
|
_c(DepthComponent)
|
|
|
|
|
_c(StencilIndex)
|
|
|
|
|
#undef _c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return debug << "Sampler::DepthStencilMode::(invalid)";
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|