From d7b9a1b0321c5f6046bad0f86a045ea52a18af25 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 17:31:22 +0200 Subject: [PATCH] Cleanup TextRenderer3D methods args --- interface/src/avatar/Avatar.cpp | 4 +- libraries/render-utils/src/TextRenderer3D.cpp | 39 +++++++------------ libraries/render-utils/src/TextRenderer3D.h | 19 +++++---- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 4c4bc93036..9b1d161177 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -280,9 +280,9 @@ enum TextRendererType { }; static TextRenderer3D* textRenderer(TextRendererType type) { - static TextRenderer3D* chatRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, 24, -1, + static TextRenderer3D* chatRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, -1, false, TextRenderer3D::SHADOW_EFFECT); - static TextRenderer3D* displayNameRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, 12); + static TextRenderer3D* displayNameRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY); switch(type) { case CHAT: diff --git a/libraries/render-utils/src/TextRenderer3D.cpp b/libraries/render-utils/src/TextRenderer3D.cpp index 5894a2a258..d202d89aba 100644 --- a/libraries/render-utils/src/TextRenderer3D.cpp +++ b/libraries/render-utils/src/TextRenderer3D.cpp @@ -30,11 +30,6 @@ #include "GeometryCache.h" #include "DeferredLightingEffect.h" -// FIXME support the shadow effect, or remove it from the API -// FIXME figure out how to improve the anti-aliasing on the -// interior of the outline fonts -const float DEFAULT_POINT_SIZE = 12; - // Helper functions for reading binary data from an IO device template void readStream(QIODevice& in, T& t) { @@ -117,7 +112,7 @@ public: // Render string to batch void drawString(gpu::Batch& batch, float x, float y, const QString& str, - const glm::vec4& color, TextRenderer3D::EffectType effectType, + const glm::vec4* color, TextRenderer3D::EffectType effectType, const glm::vec2& bound); private: @@ -367,7 +362,7 @@ void Font3D::setupGPU() { } } -void Font3D::drawString(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color, +void Font3D::drawString(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4* color, TextRenderer3D::EffectType effectType, const glm::vec2& bounds) { if (str == "") { return; @@ -429,39 +424,33 @@ void Font3D::drawString(gpu::Batch& batch, float x, float y, const QString& str, setupGPU(); batch.setPipeline(_pipeline); batch.setUniformTexture(_fontLoc, _texture); - batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)&color); batch._glUniform1i(_outlineLoc, (effectType == TextRenderer3D::OUTLINE_EFFECT)); + batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)color); batch.setInputFormat(_format); batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); batch.draw(gpu::QUADS, _numVertices, 0); } -TextRenderer3D* TextRenderer3D::getInstance(const char* family, float pointSize, - int weight, bool italic, EffectType effect, int effectThickness, - const QColor& color) { - if (pointSize < 0) { - pointSize = DEFAULT_POINT_SIZE; - } - return new TextRenderer3D(family, pointSize, weight, italic, effect, - effectThickness, color); +TextRenderer3D* TextRenderer3D::getInstance(const char* family, + int weight, bool italic, EffectType effect, int effectThickness) { + return new TextRenderer3D(family, weight, italic, effect, effectThickness); } -TextRenderer3D::TextRenderer3D(const char* family, float pointSize, int weight, bool italic, - EffectType effect, int effectThickness, const QColor& color) : +TextRenderer3D::TextRenderer3D(const char* family, int weight, bool italic, + EffectType effect, int effectThickness) : _effectType(effect), _effectThickness(effectThickness), - _color(toGlm(color)), _font(loadFont3D(family)) { if (!_font) { qWarning() << "Unable to load font with family " << family; _font = loadFont3D("Courier"); } if (1 != _effectThickness) { - qWarning() << "Effect thickness not current supported"; + qWarning() << "Effect thickness not currently supported"; } if (NO_EFFECT != _effectType && OUTLINE_EFFECT != _effectType) { - qWarning() << "Effect thickness not current supported"; + qWarning() << "Effect type not currently supported"; } } @@ -486,11 +475,9 @@ void TextRenderer3D::draw(gpu::Batch& batch, float x, float y, const QString& st const glm::vec2& bounds) { // The font does all the OpenGL work if (_font) { - glm::vec4 actualColor(color); - if (actualColor.r < 0) { - actualColor = _color; - } - _font->drawString(batch, x, y, str, actualColor, _effectType, bounds); + // Cache color so that the pointer stays valid. + _color = color; + _font->drawString(batch, x, y, str, &_color, _effectType, bounds); } } diff --git a/libraries/render-utils/src/TextRenderer3D.h b/libraries/render-utils/src/TextRenderer3D.h index 9f6a16d743..c4200a8d23 100644 --- a/libraries/render-utils/src/TextRenderer3D.h +++ b/libraries/render-utils/src/TextRenderer3D.h @@ -39,25 +39,24 @@ class Batch; class Font3D; // TextRenderer3D is actually a fairly thin wrapper around a Font class -// defined in the cpp file. +// defined in the cpp file. class TextRenderer3D { public: enum EffectType { NO_EFFECT, SHADOW_EFFECT, OUTLINE_EFFECT }; - static TextRenderer3D* getInstance(const char* family, float pointSize = -1, int weight = -1, bool italic = false, - EffectType effect = NO_EFFECT, int effectThickness = 1, const QColor& color = QColor(255, 255, 255)); - + static TextRenderer3D* getInstance(const char* family, int weight = -1, bool italic = false, + EffectType effect = NO_EFFECT, int effectThickness = 1); ~TextRenderer3D(); glm::vec2 computeExtent(const QString& str) const; - float getFontSize() const; + float getFontSize() const; // Pixel size - void draw(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color = glm::vec4(-1.0f), - const glm::vec2& bounds = glm::vec2(-1.0f)); + void draw(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color = glm::vec4(1.0f), + const glm::vec2& bounds = glm::vec2(-1.0f)); private: - TextRenderer3D(const char* family, float pointSize = -1, int weight = -1, bool italic = false, - EffectType effect = NO_EFFECT, int effectThickness = 1, const QColor& color = QColor(255, 255, 255)); + TextRenderer3D(const char* family, int weight = -1, bool italic = false, + EffectType effect = NO_EFFECT, int effectThickness = 1); // the type of effect to apply const EffectType _effectType; @@ -66,7 +65,7 @@ private: const int _effectThickness; // text color - const glm::vec4 _color; + glm::vec4 _color; Font3D* _font; };