StelPainter.cpp   StelPainter.cpp 
skipping to change at line 39 skipping to change at line 39
#include <QString> #include <QString>
#include <QSettings> #include <QSettings>
#include <QLinkedList> #include <QLinkedList>
#include <QPainter> #include <QPainter>
#include <QMutex> #include <QMutex>
#include <QVarLengthArray> #include <QVarLengthArray>
#include <QPaintEngine> #include <QPaintEngine>
#include <QCache> #include <QCache>
#include <QOpenGLPaintDevice> #include <QOpenGLPaintDevice>
#include <QOpenGLShader> #include <QOpenGLShader>
#include <QOpenGLTexture>
#include <QApplication>
static const int TEX_CACHE_LIMIT = 7000000;
#ifndef NDEBUG #ifndef NDEBUG
QMutex* StelPainter::globalMutex = new QMutex(); QMutex* StelPainter::globalMutex = new QMutex();
#endif #endif
QCache<QByteArray, StringTexture> StelPainter::texCache(TEX_CACHE_LIMIT);
QOpenGLShaderProgram* StelPainter::texturesShaderProgram=NULL; QOpenGLShaderProgram* StelPainter::texturesShaderProgram=NULL;
QOpenGLShaderProgram* StelPainter::basicShaderProgram=NULL; QOpenGLShaderProgram* StelPainter::basicShaderProgram=NULL;
QOpenGLShaderProgram* StelPainter::colorShaderProgram=NULL; QOpenGLShaderProgram* StelPainter::colorShaderProgram=NULL;
QOpenGLShaderProgram* StelPainter::texturesColorShaderProgram=NULL; QOpenGLShaderProgram* StelPainter::texturesColorShaderProgram=NULL;
StelPainter::BasicShaderVars StelPainter::basicShaderVars; StelPainter::BasicShaderVars StelPainter::basicShaderVars;
StelPainter::TexturesShaderVars StelPainter::texturesShaderVars; StelPainter::TexturesShaderVars StelPainter::texturesShaderVars;
StelPainter::BasicShaderVars StelPainter::colorShaderVars; StelPainter::BasicShaderVars StelPainter::colorShaderVars;
StelPainter::TexturesColorShaderVars StelPainter::texturesColorShaderVars; StelPainter::TexturesColorShaderVars StelPainter::texturesColorShaderVars;
StelPainter::GLState::GLState() StelPainter::GLState::GLState()
skipping to change at line 481 skipping to change at line 486
{ {
Vec3d win; Vec3d win;
if (prj->project(v, win)) if (prj->project(v, win))
drawText(win[0], win[1], str, angleDeg, xshift, yshift, noGr avity); drawText(win[0], win[1], str, angleDeg, xshift, yshift, noGr avity);
} }
/************************************************************************* /*************************************************************************
Draw the string at the given position and angle with the given font Draw the string at the given position and angle with the given font
*************************************************************************/ *************************************************************************/
// Methods taken from text-use-opengl-buffer
// Container for one cached string texture // Container for one cached string texture
struct StringTexture struct StringTexture
{ {
GLuint texture; QOpenGLTexture* texture;
int width; QSize size;
int height; QSizeF getTexSize() const {
int subTexWidth; return QSizeF((float)size.width() / texture->width(),
int subTexHeight; (float)size.height() / texture->height());
StringTexture()
: texture(0),
width(0),
height(0),
subTexWidth(0),
subTexHeight(0) {;}
~StringTexture()
{
if (texture != 0)
glDeleteTextures(1, &texture);
} }
StringTexture(QOpenGLTexture* tex, const QSize& size) :
texture(tex), size(size) {}
~StringTexture() {delete texture;}
}; };
StringTexture* StelPainter::getTexTexture(const QString& str, int pixelSize
)
{
// Render first the text into a QPixmap, then create a QOpenGLTextur
e
// from it. We could optimize by directly using a QImage, but for s
ome
// reason the result is not exactly the same than with a QPixmap.
QByteArray hash = str.toUtf8() + QByteArray::number(pixelSize);
StringTexture* cachedTex = texCache.object(hash);
if (cachedTex)
return cachedTex;
QFont tmpFont = currentFont;
tmpFont.setPixelSize(currentFont.pixelSize()*prj->getDevicePixelsPer
Pixel()*StelApp::getInstance().getGlobalScalingRatio());
QRect strRect = QFontMetrics(tmpFont).boundingRect(str);
int w = strRect.width()+1+(int)(0.02f*strRect.width());
int h = strRect.height();
QPixmap strImage = QPixmap(StelUtils::getBiggerPowerOfTwo(w), StelUt
ils::getBiggerPowerOfTwo(h));
strImage.fill(Qt::transparent);
QPainter painter(&strImage);
tmpFont.setStyleStrategy(QFont::NoAntialias);
painter.setFont(tmpFont);
//painter.setRenderHints(QPainter::TextAntialiasing);
painter.setPen(Qt::white);
painter.drawText(-strRect.x(), -strRect.y(), str);
StringTexture* newTex = new StringTexture(new QOpenGLTexture(strImag
e.toImage()), QSize(w, h));
texCache.insert(hash, newTex, 3*w*h);
// simply returning newTex is dangerous as the object is owned by th
e cache now. (Coverity Scan barks.)
return texCache.object(hash);
}
void StelPainter::drawText(float x, float y, const QString& str, float angl eDeg, float xshift, float yshift, bool noGravity) void StelPainter::drawText(float x, float y, const QString& str, float angl eDeg, float xshift, float yshift, bool noGravity)
{ {
//StelPainter::GLState state; // Will restore the opengl state at th e end of the function. //StelPainter::GLState state; // Will restore the opengl state at th e end of the function.
if (prj->gravityLabels && !noGravity) if (prj->gravityLabels && !noGravity)
{ {
drawTextGravity180(x, y, str, xshift, yshift); drawTextGravity180(x, y, str, xshift, yshift);
} }
else if (qApp->property("text_texture")==true) // CLI option -t give
n?
{
//qDebug() << "Text texture" << str;
// This is taken from branch text-use-opengl-buffer. This is
essential on devices like Raspberry Pi (2016-03).
StringTexture* tex = getTexTexture(str, currentFont.pixelSiz
e());
Q_ASSERT(tex);
if (!noGravity)
angleDeg += prj->defaultAngleForGravityText;
tex->texture->bind();
enableTexture2d(true);
static float vertexData[8];
// compute the vertex coordinates applying the translation a
nd the rotation
static const float vertexBase[] = {0., 0., 1., 0., 0., 1., 1
., 1.};
if (std::fabs(angleDeg)>1.f*M_PI/180.f)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR);
const float cosr = std::cos(angleDeg * M_PI/180.);
const float sinr = std::sin(angleDeg * M_PI/180.);
for (int i = 0; i < 8; i+=2)
{
vertexData[i] = int(x + (tex->size.width()*v
ertexBase[i]+xshift) * cosr - (tex->size.height()*vertexBase[i+1]+yshift) *
sinr);
vertexData[i+1] = int(y + (tex->size.width(
)*vertexBase[i]+xshift) * sinr + (tex->size.height()*vertexBase[i+1]+yshift
) * cosr);
}
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_NEAREST);
for (int i = 0; i < 8; i+=2)
{
vertexData[i] = int(x + tex->size.width()*ve
rtexBase[i]+xshift);
vertexData[i+1] = int(y + tex->size.height(
)*vertexBase[i+1]+yshift);
}
}
float* texCoords = new float[8];
for (int i=0;i<4;i++)
{
texCoords[i*2+0] = tex->getTexSize().width() * (i %
2);
texCoords[i*2+1] = tex->getTexSize().height() * (1 -
i / 2);
}
setTexCoordPointer(2, GL_FLOAT, texCoords);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
enableClientStates(true, true);
setVertexPointer(2, GL_FLOAT, vertexData);
drawFromArray(TriangleStrip, 4, 0, false);
enableClientStates(false, false);
tex->texture->release();
delete[] texCoords;
}
else else
{ {
QOpenGLPaintDevice device; QOpenGLPaintDevice device;
device.setSize(QSize(prj->getViewportWidth(), prj->getViewpo rtHeight())); device.setSize(QSize(prj->getViewportWidth(), prj->getViewpo rtHeight()));
// This doesn't seem to work correctly, so implement the hac k below instead. // This doesn't seem to work correctly, so implement the hac k below instead.
// Maybe check again later, or check on mac with retina.. // Maybe check again later, or check on mac with retina..
// device.setDevicePixelRatio(prj->getDevicePixelsPerPixel() ); // device.setDevicePixelRatio(prj->getDevicePixelsPerPixel() );
// painter.setFont(currentFont); // painter.setFont(currentFont);
QPainter painter(&device); QPainter painter(&device);
skipping to change at line 1898 skipping to change at line 1979
void StelPainter::deinitGLShaders() void StelPainter::deinitGLShaders()
{ {
delete basicShaderProgram; delete basicShaderProgram;
basicShaderProgram = NULL; basicShaderProgram = NULL;
delete colorShaderProgram; delete colorShaderProgram;
colorShaderProgram = NULL; colorShaderProgram = NULL;
delete texturesShaderProgram; delete texturesShaderProgram;
texturesShaderProgram = NULL; texturesShaderProgram = NULL;
delete texturesColorShaderProgram; delete texturesColorShaderProgram;
texturesColorShaderProgram = NULL; texturesColorShaderProgram = NULL;
texCache.clear();
} }
void StelPainter::setArrays(const Vec3d* vertices, const Vec2f* texCoords, const Vec3f* colorArray, const Vec3f* normalArray) void StelPainter::setArrays(const Vec3d* vertices, const Vec2f* texCoords, const Vec3f* colorArray, const Vec3f* normalArray)
{ {
enableClientStates(vertices, texCoords, colorArray, normalArray); enableClientStates(vertices, texCoords, colorArray, normalArray);
setVertexPointer(3, GL_DOUBLE, vertices); setVertexPointer(3, GL_DOUBLE, vertices);
setTexCoordPointer(2, GL_FLOAT, texCoords); setTexCoordPointer(2, GL_FLOAT, texCoords);
setColorPointer(3, GL_FLOAT, colorArray); setColorPointer(3, GL_FLOAT, colorArray);
setNormalPointer(GL_FLOAT, normalArray); setNormalPointer(GL_FLOAT, normalArray);
} }
 End of changes. 8 change blocks. 
16 lines changed or deleted 122 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/