Browse Source

Use min() / max() / minmax() from Math instead of std::.

First step to avoid the <algorithm> header.
pull/331/head
Vladimír Vondruš 7 years ago
parent
commit
b24ffa4a3e
  1. 4
      src/Magnum/GL/AbstractShaderProgram.cpp
  2. 5
      src/Magnum/GL/Shader.cpp
  3. 6
      src/Magnum/Math/Test/QuaternionTest.cpp
  4. 3
      src/Magnum/Math/Test/TypeTraitsTest.cpp
  5. 14
      src/Magnum/MeshTools/CompressIndices.cpp

4
src/Magnum/GL/AbstractShaderProgram.cpp

@ -327,7 +327,7 @@ std::pair<bool, std::string> AbstractShaderProgram::validate() {
std::string message(logLength, '\n');
if(message.size() > 1)
glGetProgramInfoLog(_id, message.size(), nullptr, &message[0]);
message.resize(std::max(logLength, 1)-1);
message.resize(Math::max(logLength, 1)-1);
return {success, std::move(message)};
}
@ -415,7 +415,7 @@ bool AbstractShaderProgram::link(std::initializer_list<Containers::Reference<Abs
std::string message(logLength, '\n');
if(message.size() > 1)
glGetProgramInfoLog(shader._id, message.size(), nullptr, &message[0]);
message.resize(std::max(logLength, 1)-1);
message.resize(Math::max(logLength, 1)-1);
/* Show error log */
if(!success) {

5
src/Magnum/GL/Shader.cpp

@ -38,6 +38,7 @@
#endif
#include "Magnum/GL/Implementation/State.h"
#include "Magnum/GL/Implementation/ShaderState.h"
#include "Magnum/Math/Functions.h"
/* libgles-omap3-dev_4.03.00.02-r15.6 on BeagleBoard/Ångström linux 2011.3 doesn't have GLchar */
#ifdef MAGNUM_TARGET_GLES
@ -757,7 +758,7 @@ bool Shader::compile(std::initializer_list<Containers::Reference<Shader>> shader
std::size_t maxSourceCount = 0;
for(Shader& shader: shaders) {
CORRADE_ASSERT(shader._sources.size() > 1, "GL::Shader::compile(): no files added", false);
maxSourceCount = std::max(shader._sources.size(), maxSourceCount);
maxSourceCount = Math::max(shader._sources.size(), maxSourceCount);
}
/** @todo ArrayTuple/VLAs */
Containers::Array<const GLchar*> pointers(maxSourceCount);
@ -788,7 +789,7 @@ bool Shader::compile(std::initializer_list<Containers::Reference<Shader>> shader
std::string message(logLength, '\0');
if(message.size() > 1)
glGetShaderInfoLog(shader._id, message.size(), nullptr, &message[0]);
message.resize(std::max(logLength, 1)-1);
message.resize(Math::max(logLength, 1)-1);
/* Show error log */
if(!success) {

6
src/Magnum/Math/Test/QuaternionTest.cpp

@ -511,7 +511,7 @@ void QuaternionTest::matrix() {
Quaternion q2 = Quaternion::rotation(Deg(130.0f), axis);
CORRADE_COMPARE_AS(m2.trace(), 0.0f, Corrade::TestSuite::Compare::Less);
CORRADE_COMPARE_AS(m2.diagonal()[2],
std::max(m2.diagonal()[0], m2.diagonal()[1]),
Math::max(m2.diagonal()[0], m2.diagonal()[1]),
Corrade::TestSuite::Compare::Greater);
CORRADE_COMPARE(Quaternion::fromMatrix(m2), q2);
@ -521,7 +521,7 @@ void QuaternionTest::matrix() {
Quaternion q3 = Quaternion::rotation(Deg(130.0f), axis2);
CORRADE_COMPARE_AS(m3.trace(), 0.0f, Corrade::TestSuite::Compare::Less);
CORRADE_COMPARE_AS(m3.diagonal()[1],
std::max(m3.diagonal()[0], m3.diagonal()[2]),
Math::max(m3.diagonal()[0], m3.diagonal()[2]),
Corrade::TestSuite::Compare::Greater);
CORRADE_COMPARE(Quaternion::fromMatrix(m3), q3);
@ -531,7 +531,7 @@ void QuaternionTest::matrix() {
Quaternion q4 = Quaternion::rotation(Deg(130.0f), axis3);
CORRADE_COMPARE_AS(m4.trace(), 0.0f, Corrade::TestSuite::Compare::Less);
CORRADE_COMPARE_AS(m4.diagonal()[0],
std::max(m4.diagonal()[1], m4.diagonal()[2]),
Math::max(m4.diagonal()[1], m4.diagonal()[2]),
Corrade::TestSuite::Compare::Greater);
CORRADE_COMPARE(Quaternion::fromMatrix(m4), q4);
}

3
src/Magnum/Math/Test/TypeTraitsTest.cpp

@ -24,9 +24,6 @@
*/
#include <Corrade/TestSuite/Tester.h>
#ifdef _MSC_VER
#include <algorithm> /* std::max() */
#endif
#include "Magnum/Math/TypeTraits.h"
#include "Magnum/Math/Constants.h"

14
src/Magnum/MeshTools/CompressIndices.cpp

@ -26,8 +26,8 @@
#include "CompressIndices.h"
#include <cstring>
#include <algorithm>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayViewStl.h>
#include "Magnum/Math/Functions.h"
@ -49,10 +49,10 @@ template<class T> inline Containers::Array<char> compress(const std::vector<Unsi
std::tuple<Containers::Array<char>, MeshIndexType, UnsignedInt, UnsignedInt> compressIndices(const std::vector<UnsignedInt>& indices) {
/** @todo Performance hint when range can be represented by smaller value? */
const auto minmax = std::minmax_element(indices.begin(), indices.end());
const auto minmax = Math::minmax<UnsignedInt>(indices);
Containers::Array<char> data;
MeshIndexType type;
switch(Math::log(256, *minmax.second)) {
switch(Math::log(256, minmax.second)) {
case 0:
data = compress<UnsignedByte>(indices);
type = MeshIndexType::UnsignedByte;
@ -68,16 +68,16 @@ std::tuple<Containers::Array<char>, MeshIndexType, UnsignedInt, UnsignedInt> com
break;
default:
CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << *minmax.second << "elements.", {});
CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << minmax.second << "elements.", {});
}
return std::make_tuple(std::move(data), type, *minmax.first, *minmax.second);
return std::make_tuple(std::move(data), type, minmax.first, minmax.second);
}
template<class T> Containers::Array<T> compressIndicesAs(const std::vector<UnsignedInt>& indices) {
#if !defined(CORRADE_NO_ASSERT) || defined(CORRADE_GRACEFUL_ASSERT)
const auto max = std::max_element(indices.begin(), indices.end());
CORRADE_ASSERT(Math::log(256, *max) < sizeof(T), "MeshTools::compressIndicesAs(): type too small to represent value" << *max, {});
const auto max = Math::max<UnsignedInt>(indices);
CORRADE_ASSERT(Math::log(256, max) < sizeof(T), "MeshTools::compressIndicesAs(): type too small to represent value" << max, {});
#endif
Containers::Array<T> buffer(indices.size());

Loading…
Cancel
Save