From 71c7480299b9e48e63315bb328acbc84c80fc4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 13 Apr 2013 21:03:54 +0200 Subject: [PATCH] Fixed one-value AbstractShaderProgram::setUniform(). The original workaround for enums didn't work (all enums were treated as UnsignedInt even though they had Int as underlying type), moreover the solution didn't scale for other possible types with implicit conversions. Now explicitly listing all scalar types and templated vectors/matrices, it should work for most cases. --- src/AbstractShaderProgram.h | 39 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 9bb375aad..1dbf1d640 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -42,18 +42,6 @@ namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Attribute; - - /* Used in setUniform(Int, const T&), otherwise it would not be possible to - pass enum values as uniforms */ - struct NonEnumType { - template inline static typename std::enable_if::value, const typename std::conditional::value, UnsignedInt, Int>::type&>::type cast(const T& value) { - return static_cast::value, UnsignedInt, Int>::type&>(value); - } - - template inline static typename std::enable_if::value, const T&>::type cast(const T& value) { - return value; - } - }; } #endif @@ -694,9 +682,32 @@ class MAGNUM_EXPORT AbstractShaderProgram { * Convenience alternative for setting one value, see * setUniform(Int, UnsignedInt, const Float*) for more information. */ - template inline void setUniform(Int location, const T& value) { - setUniform(location, 1, &Implementation::NonEnumType::cast(value)); + #ifdef DOXYGEN_GENERATING_OUTPUT + template inline void setUniform(Int location, const T& value); + #else + inline void setUniform(Int location, Float value) { + setUniform(location, 1, &value); + } + inline void setUniform(Int location, Int value) { + setUniform(location, 1, &value); + } + #ifndef MAGNUM_TARGET_GLES2 + inline void setUniform(Int location, UnsignedInt value) { + setUniform(location, 1, &value); + } + #endif + #ifndef MAGNUM_TARGET_GLES + inline void setUniform(Int location, Double value) { + setUniform(location, 1, &value); } + #endif + template inline void setUniform(Int location, const Math::Vector& value) { + setUniform(location, 1, &value); + } + template inline void setUniform(Int location, const Math::RectangularMatrix& value) { + setUniform(location, 1, &value); + } + #endif /** * @brief Set uniform values