Skip to content

Commit

Permalink
Ui: workaround the dreaded std::to_string() issue on Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Jan 21, 2017
1 parent c080e1b commit 9fcd95b
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/Magnum/Ui/Style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

#include "Magnum/Ui/Widget.h"

#ifdef CORRADE_TARGET_ANDROID
#include <sstream>
#endif

#ifdef MAGNUM_BUILD_STATIC
static void importShaderResources() {
CORRADE_RESOURCE_INITIALIZE(MagnumUi_RESOURCES)
Expand Down Expand Up @@ -786,10 +790,17 @@ BackgroundShader::BackgroundShader() {
Version::GLES300,
#endif
Shader::Type::Fragment};
vert.addSource("#define BACKGROUND_COLOR_COUNT " + std::to_string(Implementation::BackgroundColorCount) + "\n")
.addSource(rs.get("BackgroundShader.vert"));
frag.addSource("#define BACKGROUND_COLOR_COUNT " + std::to_string(Implementation::BackgroundColorCount) + "\n")
.addSource(rs.get("BackgroundShader.frag"));
#ifndef CORRADE_TARGET_ANDROID
vert.addSource("#define BACKGROUND_COLOR_COUNT " + std::to_string(Implementation::BackgroundColorCount) + "\n");
frag.addSource("#define BACKGROUND_COLOR_COUNT " + std::to_string(Implementation::BackgroundColorCount) + "\n");
#else
std::ostringstream out;
out << Implementation::BackgroundColorCount;
vert.addSource("#define BACKGROUND_COLOR_COUNT " + out.str() + "\n");
frag.addSource("#define BACKGROUND_COLOR_COUNT " + out.str() + "\n");
#endif
vert.addSource(rs.get("BackgroundShader.vert"));
frag.addSource(rs.get("BackgroundShader.frag"));

CORRADE_INTERNAL_ASSERT(Shader::compile({vert, frag}));
attachShaders({vert, frag});
Expand Down Expand Up @@ -828,10 +839,17 @@ ForegroundShader::ForegroundShader() {
Version::GLES300,
#endif
Shader::Type::Fragment};
vert.addSource("#define FOREGROUND_COLOR_COUNT " + std::to_string(Implementation::ForegroundColorCount) + "\n")
.addSource(rs.get("ForegroundShader.vert"));
frag.addSource("#define FOREGROUND_COLOR_COUNT " + std::to_string(Implementation::ForegroundColorCount) + "\n")
.addSource(rs.get("ForegroundShader.frag"));
#ifndef CORRADE_TARGET_ANDROID
vert.addSource("#define FOREGROUND_COLOR_COUNT " + std::to_string(Implementation::ForegroundColorCount) + "\n");
frag.addSource("#define FOREGROUND_COLOR_COUNT " + std::to_string(Implementation::ForegroundColorCount) + "\n");
#else
std::ostringstream out;
out << Implementation::ForegroundColorCount;
vert.addSource("#define FOREGROUND_COLOR_COUNT " + out.str() + "\n");
frag.addSource("#define FOREGROUND_COLOR_COUNT " + out.str() + "\n");
#endif
vert.addSource(rs.get("ForegroundShader.vert"));
frag.addSource(rs.get("ForegroundShader.frag"));

CORRADE_INTERNAL_ASSERT(Shader::compile({vert, frag}));
attachShaders({vert, frag});
Expand Down Expand Up @@ -871,8 +889,14 @@ TextShader::TextShader() {
#endif
Shader::Type::Fragment};
vert.addSource(rs.get("TextShader.vert"));
frag.addSource("#define TEXT_COLOR_COUNT " + std::to_string(Implementation::TextColorCount) + "\n")
.addSource(rs.get("TextShader.frag"));
#ifndef CORRADE_TARGET_ANDROID
frag.addSource("#define TEXT_COLOR_COUNT " + std::to_string(Implementation::TextColorCount) + "\n");
#else
std::ostringstream out;
out << Implementation::TextColorCount;
frag.addSource("#define TEXT_COLOR_COUNT " + out.str() + "\n");
#endif
frag.addSource(rs.get("TextShader.frag"));

CORRADE_INTERNAL_ASSERT(Shader::compile({vert, frag}));
attachShaders({vert, frag});
Expand Down

0 comments on commit 9fcd95b

Please sign in to comment.