mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-16 18:11:44 +02:00
TextRenderer memory leak
This commit is contained in:
parent
e5d0851337
commit
9b49936d29
4 changed files with 18 additions and 16 deletions
|
@ -11,15 +11,12 @@
|
|||
// include this before QGLWidget, which includes an earlier version of OpenGL
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#include <TextRenderer.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Text3DOverlay.h"
|
||||
|
||||
const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 };
|
||||
const float DEFAULT_BACKGROUND_ALPHA = 0.7f;
|
||||
const float DEFAULT_MARGIN = 0.1f;
|
||||
const int FIXED_FONT_POINT_SIZE = 40;
|
||||
const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 40.0f; // this is a ratio determined through experimentation
|
||||
const float LINE_SCALE_RATIO = 1.2f;
|
||||
|
||||
|
@ -50,6 +47,7 @@ Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
|||
}
|
||||
|
||||
Text3DOverlay::~Text3DOverlay() {
|
||||
delete _textRenderer;
|
||||
}
|
||||
|
||||
xColor Text3DOverlay::getBackgroundColor() {
|
||||
|
@ -106,8 +104,7 @@ void Text3DOverlay::render(RenderArgs* args) {
|
|||
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, quadColor);
|
||||
|
||||
// Same font properties as textSize()
|
||||
TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||
float maxHeight = (float)textRenderer->computeExtent("Xy").y * LINE_SCALE_RATIO;
|
||||
float maxHeight = (float)_textRenderer->computeExtent("Xy").y * LINE_SCALE_RATIO;
|
||||
|
||||
float scaleFactor = (maxHeight / FIXED_FONT_SCALING_RATIO) * _lineHeight;
|
||||
|
||||
|
@ -124,7 +121,7 @@ void Text3DOverlay::render(RenderArgs* args) {
|
|||
enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y);
|
||||
|
||||
glm::vec4 textColor = { _color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, getAlpha() };
|
||||
textRenderer->draw(0, 0, _text, textColor);
|
||||
_textRenderer->draw(0, 0, _text, textColor);
|
||||
|
||||
glDisable(GL_CLIP_PLANE0);
|
||||
glDisable(GL_CLIP_PLANE1);
|
||||
|
@ -228,10 +225,9 @@ Text3DOverlay* Text3DOverlay::createClone() const {
|
|||
}
|
||||
|
||||
QSizeF Text3DOverlay::textSize(const QString& text) const {
|
||||
auto textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||
auto extents = textRenderer->computeExtent(text);
|
||||
auto extents = _textRenderer->computeExtent(text);
|
||||
|
||||
float maxHeight = (float)textRenderer->computeExtent("Xy").y * LINE_SCALE_RATIO;
|
||||
float maxHeight = (float)_textRenderer->computeExtent("Xy").y * LINE_SCALE_RATIO;
|
||||
float pointToWorldScale = (maxHeight / FIXED_FONT_SCALING_RATIO) * _lineHeight;
|
||||
|
||||
return QSizeF(extents.x, extents.y) * pointToWorldScale;
|
||||
|
|
|
@ -17,8 +17,12 @@
|
|||
#include <QString>
|
||||
|
||||
#include <RenderArgs.h>
|
||||
#include <TextRenderer.h>
|
||||
|
||||
#include "Planar3DOverlay.h"
|
||||
|
||||
const int FIXED_FONT_POINT_SIZE = 40;
|
||||
|
||||
class Text3DOverlay : public Planar3DOverlay {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -58,6 +62,8 @@ public:
|
|||
private:
|
||||
void enableClipPlane(GLenum plane, float x, float y, float z, float w);
|
||||
|
||||
TextRenderer* _textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||
|
||||
QString _text;
|
||||
xColor _backgroundColor;
|
||||
float _backgroundAlpha;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <DependencyManager.h>
|
||||
#include <GeometryCache.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <TextRenderer.h>
|
||||
|
||||
#include "TextOverlay.h"
|
||||
|
||||
|
@ -39,6 +38,7 @@ TextOverlay::TextOverlay(const TextOverlay* textOverlay) :
|
|||
}
|
||||
|
||||
TextOverlay::~TextOverlay() {
|
||||
delete _textRenderer;
|
||||
}
|
||||
|
||||
xColor TextOverlay::getBackgroundColor() {
|
||||
|
@ -79,9 +79,6 @@ void TextOverlay::render(RenderArgs* args) {
|
|||
glm::vec2 topLeft(left, top);
|
||||
glm::vec2 bottomRight(right, bottom);
|
||||
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, quadColor);
|
||||
|
||||
// Same font properties as textSize()
|
||||
TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT);
|
||||
|
||||
const int leftAdjust = -1; // required to make text render relative to left edge of bounds
|
||||
const int topAdjust = -2; // required to make text render relative to top edge of bounds
|
||||
|
@ -90,7 +87,7 @@ void TextOverlay::render(RenderArgs* args) {
|
|||
|
||||
float alpha = getAlpha();
|
||||
glm::vec4 textColor = {_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, alpha };
|
||||
textRenderer->draw(x, y, _text, textColor);
|
||||
_textRenderer->draw(x, y, _text, textColor);
|
||||
}
|
||||
|
||||
void TextOverlay::setProperties(const QScriptValue& properties) {
|
||||
|
@ -163,8 +160,7 @@ QScriptValue TextOverlay::getProperty(const QString& property) {
|
|||
}
|
||||
|
||||
QSizeF TextOverlay::textSize(const QString& text) const {
|
||||
auto textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT);
|
||||
auto extents = textRenderer->computeExtent(text);
|
||||
auto extents = _textRenderer->computeExtent(text);
|
||||
|
||||
return QSizeF(extents.x, extents.y);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <QString>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
#include <TextRenderer.h>
|
||||
|
||||
#include "Overlay.h"
|
||||
#include "Overlay2D.h"
|
||||
|
@ -58,6 +59,9 @@ public:
|
|||
QSizeF textSize(const QString& text) const; // Pixels
|
||||
|
||||
private:
|
||||
|
||||
TextRenderer* _textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT);
|
||||
|
||||
QString _text;
|
||||
xColor _backgroundColor;
|
||||
float _backgroundAlpha;
|
||||
|
|
Loading…
Reference in a new issue