mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:37:51 +02:00
Cleanup TextRenderer3D methods args
This commit is contained in:
parent
47634a48a6
commit
d7b9a1b032
3 changed files with 24 additions and 38 deletions
|
@ -280,9 +280,9 @@ enum TextRendererType {
|
||||||
};
|
};
|
||||||
|
|
||||||
static TextRenderer3D* textRenderer(TextRendererType type) {
|
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);
|
false, TextRenderer3D::SHADOW_EFFECT);
|
||||||
static TextRenderer3D* displayNameRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, 12);
|
static TextRenderer3D* displayNameRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY);
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case CHAT:
|
case CHAT:
|
||||||
|
|
|
@ -30,11 +30,6 @@
|
||||||
#include "GeometryCache.h"
|
#include "GeometryCache.h"
|
||||||
#include "DeferredLightingEffect.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
|
// Helper functions for reading binary data from an IO device
|
||||||
template<class T>
|
template<class T>
|
||||||
void readStream(QIODevice& in, T& t) {
|
void readStream(QIODevice& in, T& t) {
|
||||||
|
@ -117,7 +112,7 @@ public:
|
||||||
|
|
||||||
// Render string to batch
|
// Render string to batch
|
||||||
void drawString(gpu::Batch& batch, float x, float y, const QString& str,
|
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);
|
const glm::vec2& bound);
|
||||||
|
|
||||||
private:
|
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) {
|
TextRenderer3D::EffectType effectType, const glm::vec2& bounds) {
|
||||||
if (str == "") {
|
if (str == "") {
|
||||||
return;
|
return;
|
||||||
|
@ -429,39 +424,33 @@ void Font3D::drawString(gpu::Batch& batch, float x, float y, const QString& str,
|
||||||
setupGPU();
|
setupGPU();
|
||||||
batch.setPipeline(_pipeline);
|
batch.setPipeline(_pipeline);
|
||||||
batch.setUniformTexture(_fontLoc, _texture);
|
batch.setUniformTexture(_fontLoc, _texture);
|
||||||
batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)&color);
|
|
||||||
batch._glUniform1i(_outlineLoc, (effectType == TextRenderer3D::OUTLINE_EFFECT));
|
batch._glUniform1i(_outlineLoc, (effectType == TextRenderer3D::OUTLINE_EFFECT));
|
||||||
|
batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)color);
|
||||||
|
|
||||||
batch.setInputFormat(_format);
|
batch.setInputFormat(_format);
|
||||||
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);
|
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);
|
||||||
batch.draw(gpu::QUADS, _numVertices, 0);
|
batch.draw(gpu::QUADS, _numVertices, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextRenderer3D* TextRenderer3D::getInstance(const char* family, float pointSize,
|
TextRenderer3D* TextRenderer3D::getInstance(const char* family,
|
||||||
int weight, bool italic, EffectType effect, int effectThickness,
|
int weight, bool italic, EffectType effect, int effectThickness) {
|
||||||
const QColor& color) {
|
return new TextRenderer3D(family, weight, italic, effect, effectThickness);
|
||||||
if (pointSize < 0) {
|
|
||||||
pointSize = DEFAULT_POINT_SIZE;
|
|
||||||
}
|
|
||||||
return new TextRenderer3D(family, pointSize, weight, italic, effect,
|
|
||||||
effectThickness, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextRenderer3D::TextRenderer3D(const char* family, float pointSize, int weight, bool italic,
|
TextRenderer3D::TextRenderer3D(const char* family, int weight, bool italic,
|
||||||
EffectType effect, int effectThickness, const QColor& color) :
|
EffectType effect, int effectThickness) :
|
||||||
_effectType(effect),
|
_effectType(effect),
|
||||||
_effectThickness(effectThickness),
|
_effectThickness(effectThickness),
|
||||||
_color(toGlm(color)),
|
|
||||||
_font(loadFont3D(family)) {
|
_font(loadFont3D(family)) {
|
||||||
if (!_font) {
|
if (!_font) {
|
||||||
qWarning() << "Unable to load font with family " << family;
|
qWarning() << "Unable to load font with family " << family;
|
||||||
_font = loadFont3D("Courier");
|
_font = loadFont3D("Courier");
|
||||||
}
|
}
|
||||||
if (1 != _effectThickness) {
|
if (1 != _effectThickness) {
|
||||||
qWarning() << "Effect thickness not current supported";
|
qWarning() << "Effect thickness not currently supported";
|
||||||
}
|
}
|
||||||
if (NO_EFFECT != _effectType && OUTLINE_EFFECT != _effectType) {
|
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) {
|
const glm::vec2& bounds) {
|
||||||
// The font does all the OpenGL work
|
// The font does all the OpenGL work
|
||||||
if (_font) {
|
if (_font) {
|
||||||
glm::vec4 actualColor(color);
|
// Cache color so that the pointer stays valid.
|
||||||
if (actualColor.r < 0) {
|
_color = color;
|
||||||
actualColor = _color;
|
_font->drawString(batch, x, y, str, &_color, _effectType, bounds);
|
||||||
}
|
|
||||||
_font->drawString(batch, x, y, str, actualColor, _effectType, bounds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,25 +39,24 @@ class Batch;
|
||||||
class Font3D;
|
class Font3D;
|
||||||
|
|
||||||
// TextRenderer3D is actually a fairly thin wrapper around a Font class
|
// TextRenderer3D is actually a fairly thin wrapper around a Font class
|
||||||
// defined in the cpp file.
|
// defined in the cpp file.
|
||||||
class TextRenderer3D {
|
class TextRenderer3D {
|
||||||
public:
|
public:
|
||||||
enum EffectType { NO_EFFECT, SHADOW_EFFECT, OUTLINE_EFFECT };
|
enum EffectType { NO_EFFECT, SHADOW_EFFECT, OUTLINE_EFFECT };
|
||||||
|
|
||||||
static TextRenderer3D* getInstance(const char* family, float pointSize = -1, int weight = -1, bool italic = false,
|
static TextRenderer3D* getInstance(const char* family, int weight = -1, bool italic = false,
|
||||||
EffectType effect = NO_EFFECT, int effectThickness = 1, const QColor& color = QColor(255, 255, 255));
|
EffectType effect = NO_EFFECT, int effectThickness = 1);
|
||||||
|
|
||||||
~TextRenderer3D();
|
~TextRenderer3D();
|
||||||
|
|
||||||
glm::vec2 computeExtent(const QString& str) const;
|
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),
|
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));
|
const glm::vec2& bounds = glm::vec2(-1.0f));
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextRenderer3D(const char* family, float pointSize = -1, int weight = -1, bool italic = false,
|
TextRenderer3D(const char* family, int weight = -1, bool italic = false,
|
||||||
EffectType effect = NO_EFFECT, int effectThickness = 1, const QColor& color = QColor(255, 255, 255));
|
EffectType effect = NO_EFFECT, int effectThickness = 1);
|
||||||
|
|
||||||
// the type of effect to apply
|
// the type of effect to apply
|
||||||
const EffectType _effectType;
|
const EffectType _effectType;
|
||||||
|
@ -66,7 +65,7 @@ private:
|
||||||
const int _effectThickness;
|
const int _effectThickness;
|
||||||
|
|
||||||
// text color
|
// text color
|
||||||
const glm::vec4 _color;
|
glm::vec4 _color;
|
||||||
|
|
||||||
Font3D* _font;
|
Font3D* _font;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue