StelPainter.cpp   StelPainter.cpp 
skipping to change at line 48 skipping to change at line 48
#define GL_MULTISAMPLE 0x809D #define GL_MULTISAMPLE 0x809D
#endif #endif
#ifndef NDEBUG #ifndef NDEBUG
QMutex* StelPainter::globalMutex = new QMutex(); QMutex* StelPainter::globalMutex = new QMutex();
#endif #endif
QPainter* StelPainter::qPainter = NULL; QPainter* StelPainter::qPainter = NULL;
QGLContext* StelPainter::glContext = NULL; QGLContext* StelPainter::glContext = NULL;
bool StelPainter::isNoPowerOfTwoAllowed;
#ifdef STELPAINTER_GL2 #ifdef STELPAINTER_GL2
QGLShaderProgram* StelPainter::colorShaderProgram=NULL; QGLShaderProgram* StelPainter::colorShaderProgram=NULL;
QGLShaderProgram* StelPainter::texturesShaderProgram=NULL; QGLShaderProgram* StelPainter::texturesShaderProgram=NULL;
QGLShaderProgram* StelPainter::basicShaderProgram=NULL; QGLShaderProgram* StelPainter::basicShaderProgram=NULL;
QGLShaderProgram* StelPainter::texturesColorShaderProgram=NULL; QGLShaderProgram* StelPainter::texturesColorShaderProgram=NULL;
StelPainter::BasicShaderVars StelPainter::basicShaderVars; StelPainter::BasicShaderVars StelPainter::basicShaderVars;
StelPainter::TexturesShaderVars StelPainter::texturesShaderVars; StelPainter::TexturesShaderVars StelPainter::texturesShaderVars;
StelPainter::TexturesColorShaderVars StelPainter::texturesColorShaderVars; StelPainter::TexturesColorShaderVars StelPainter::texturesColorShaderVars;
#endif #endif
skipping to change at line 454 skipping to change at line 456
int j; int j;
static Vec3f lightPos3; static Vec3f lightPos3;
static Vec4f ambientLight; static Vec4f ambientLight;
static Vec4f diffuseLight; static Vec4f diffuseLight;
float c; float c;
const bool isLightOn = light.isEnabled(); const bool isLightOn = light.isEnabled();
if (isLightOn) if (isLightOn)
{ {
lightPos3.set(light.getPosition()[0], light.getPosition()[1] , light.getPosition()[2]); lightPos3.set(light.getPosition()[0], light.getPosition()[1] , light.getPosition()[2]);
lightPos3 -= prj->modelViewMatrixf * Vec3f(0.f); // -posCent Vec3f tmpv(0.f);
erEye prj->getModelViewTransform()->forward(tmpv); // -posCenterEy
lightPos3 = prj->modelViewMatrixf.transpose().multiplyWithou e
tTranslation(lightPos3); lightPos3 -= tmpv;
//lightPos3 = prj->modelViewMatrixf.transpose().multiplyWith
outTranslation(lightPos3);
prj->getModelViewTransform()->backward(lightPos3);
lightPos3.normalize(); lightPos3.normalize();
ambientLight = light.getAmbient(); ambientLight = light.getAmbient();
diffuseLight = light.getDiffuse(); diffuseLight = light.getDiffuse();
} }
const float nsign = orientInside?-1.f:1.f; const float nsign = orientInside?-1.f:1.f;
const float dr = (rMax-rMin) / stacks; const float dr = (rMax-rMin) / stacks;
const float dtheta = 2.f * M_PI / slices; const float dtheta = 2.f * M_PI / slices;
if (slices < 0) slices = -slices; if (slices < 0) slices = -slices;
skipping to change at line 645 skipping to change at line 650
/************************************************************************* /*************************************************************************
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
*************************************************************************/ *************************************************************************/
// Container for one cached string texture // Container for one cached string texture
struct StringTexture struct StringTexture
{ {
GLuint texture; GLuint texture;
int width; int width;
int height; int height;
int subTexWidth;
int subTexHeight;
StringTexture() : texture(0) {;} StringTexture() : texture(0) {;}
~StringTexture() ~StringTexture()
{ {
if (texture != 0) if (texture != 0)
glDeleteTextures(1, &texture); glDeleteTextures(1, &texture);
} }
}; };
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)
skipping to change at line 671 skipping to change at line 678
else else
{ {
static const int cacheLimitByte = 7000000; static const int cacheLimitByte = 7000000;
static QCache<QByteArray,StringTexture> texCache(cacheLimitB yte); static QCache<QByteArray,StringTexture> texCache(cacheLimitB yte);
int pixelSize = qPainter->font().pixelSize(); int pixelSize = qPainter->font().pixelSize();
QByteArray hash = str.toUtf8() + QByteArray::number(pixelSiz e); QByteArray hash = str.toUtf8() + QByteArray::number(pixelSiz e);
const StringTexture* cachedTex = texCache.object(hash); const StringTexture* cachedTex = texCache.object(hash);
if (cachedTex == NULL) // need to create texture if (cachedTex == NULL) // need to create texture
{ {
StringTexture* newTex = new StringTexture();
// Create temp image and render text into it // Create temp image and render text into it
QRect strRect = getFontMetrics().boundingRect(str); QRect strRect = getFontMetrics().boundingRect(str);
QPixmap strImage(strRect.width()+1+(int)(0.02f*strR newTex->subTexWidth = strRect.width()+1+(int)(0.02f*
ect.width()), strRect.height()); strRect.width());
newTex->subTexHeight = strRect.height();
QPixmap strImage;
if (isNoPowerOfTwoAllowed)
strImage = QPixmap(newTex->subTexWidth, newT
ex->subTexHeight);
else
strImage = QPixmap(StelUtils::getBiggerPower
OfTwo(newTex->subTexWidth), StelUtils::getBiggerPowerOfTwo(newTex->subTexHe
ight));
newTex->width = strImage.width();
newTex->height = strImage.height();
strImage.fill(Qt::transparent); strImage.fill(Qt::transparent);
QPainter painter(&strImage); QPainter painter(&strImage);
painter.setFont(qPainter->font()); painter.setFont(qPainter->font());
painter.setRenderHints(QPainter::TextAntialiasing); painter.setRenderHints(QPainter::TextAntialiasing);
painter.setPen(Qt::white); painter.setPen(Qt::white);
painter.drawText(-strRect.x(), -strRect.y(), str); painter.drawText(-strRect.x(), -strRect.y(), str);
// Create and bind texture, and add it to the list o f cached textures // Create and bind texture, and add it to the list o f cached textures
StringTexture* newTex = new StringTexture();
newTex->texture = StelPainter::glContext->bindTextur e(strImage, GL_TEXTURE_2D, GL_RGBA, QGLContext::NoBindOption); newTex->texture = StelPainter::glContext->bindTextur e(strImage, GL_TEXTURE_2D, GL_RGBA, QGLContext::NoBindOption);
newTex->width = strImage.width();
newTex->height = strImage.height();
texCache.insert(hash, newTex, 3*newTex->width*newTex ->height); texCache.insert(hash, newTex, 3*newTex->width*newTex ->height);
cachedTex=newTex; cachedTex=newTex;
} }
else else
{ {
// The texture was found in the cache // The texture was found in the cache
glBindTexture(GL_TEXTURE_2D, cachedTex->texture); glBindTexture(GL_TEXTURE_2D, cachedTex->texture);
} }
// Translate/rotate // Translate/rotate
skipping to change at line 713 skipping to change at line 728
// compute the vertex coordinates applying the translation a nd the rotation // compute the vertex coordinates applying the translation a nd the rotation
static const float vertexBase[] = {0., 0., 1., 0., 0., 1., 1 ., 1.}; static const float vertexBase[] = {0., 0., 1., 0., 0., 1., 1 ., 1.};
if (std::fabs(angleDeg)>1.f*M_PI/180.f) 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_MIN_FILTER , GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR);
const float cosr = std::cos(angleDeg * M_PI/180.); const float cosr = std::cos(angleDeg * M_PI/180.);
const float sinr = std::sin(angleDeg * M_PI/180.); const float sinr = std::sin(angleDeg * M_PI/180.);
for (int i = 0; i < 8; i+=2) for (int i = 0; i < 8; i+=2)
{ {
vertexData[i] = int(x + (cachedTex->width*ve vertexData[i] = int(x + (cachedTex->subTexWi
rtexBase[i]+xshift) * cosr - (cachedTex->height*vertexBase[i+1]+yshift) * s dth*vertexBase[i]+xshift) * cosr - (cachedTex->subTexHeight*vertexBase[i+1]
inr); +yshift) * sinr);
vertexData[i+1] = int(y + (cachedTex->width vertexData[i+1] = int(y + (cachedTex->subTe
*vertexBase[i]+xshift) * sinr + (cachedTex->height*vertexBase[i+1]+yshift) xWidth*vertexBase[i]+xshift) * sinr + (cachedTex->subTexHeight*vertexBase[i
* cosr); +1]+yshift) * cosr);
} }
} }
else else
{ {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_NEAREST);
for (int i = 0; i < 8; i+=2) for (int i = 0; i < 8; i+=2)
{ {
vertexData[i] = int(x + cachedTex->width*ver vertexData[i] = int(x + cachedTex->subTexWid
texBase[i]+xshift); th*vertexBase[i]+xshift);
vertexData[i+1] = int(y + cachedTex->height vertexData[i+1] = int(y + cachedTex->subTex
*vertexBase[i+1]+yshift); Height*vertexBase[i+1]+yshift);
} }
} }
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
enableClientStates(true, true); enableClientStates(true, true);
setVertexPointer(2, GL_FLOAT, vertexData); setVertexPointer(2, GL_FLOAT, vertexData);
setTexCoordPointer(2, GL_FLOAT, texCoordData);
float* texCoords = NULL;
if (isNoPowerOfTwoAllowed)
setTexCoordPointer(2, GL_FLOAT, texCoordData);
else
{
texCoords = new float[8];
for (int i=0;i<8;i+=2)
{
texCoords[i] = texCoordData[i]*(float)cached
Tex->subTexWidth/cachedTex->width;
texCoords[i+1] = texCoordData[i+1]*(float)ca
chedTex->subTexHeight/cachedTex->height;
}
setTexCoordPointer(2, GL_FLOAT, texCoords);
}
drawFromArray(TriangleStrip, 4, 0, false); drawFromArray(TriangleStrip, 4, 0, false);
enableClientStates(false); enableClientStates(false);
if (!isNoPowerOfTwoAllowed)
delete[] texCoords;
} }
} }
// Recursive method cutting a small circle in small segments // Recursive method cutting a small circle in small segments
inline void fIter(const StelProjectorP& prj, const Vec3d& p1, const Vec3d& p2, Vec3d& win1, Vec3d& win2, QLinkedList<Vec3d>& vertexList, const QLinked List<Vec3d>::iterator& iter, double radius, const Vec3d& center, int nbI=0, bool checkCrossDiscontinuity=true) inline void fIter(const StelProjectorP& prj, const Vec3d& p1, const Vec3d& p2, Vec3d& win1, Vec3d& win2, QLinkedList<Vec3d>& vertexList, const QLinked List<Vec3d>::iterator& iter, double radius, const Vec3d& center, int nbI=0, bool checkCrossDiscontinuity=true)
{ {
const bool crossDiscontinuity = checkCrossDiscontinuity && prj->inte rsectViewportDiscontinuity(p1+center, p2+center); const bool crossDiscontinuity = checkCrossDiscontinuity && prj->inte rsectViewportDiscontinuity(p1+center, p2+center);
if (crossDiscontinuity && nbI>=10) if (crossDiscontinuity && nbI>=10)
{ {
win1[2]=-2.; win1[2]=-2.;
skipping to change at line 1546 skipping to change at line 1578
// static rather than on the stack. But why? // static rather than on the stack. But why?
// Is the constructor/destructor so expensive? // Is the constructor/destructor so expensive?
static Vec3f lightPos3; static Vec3f lightPos3;
static Vec4f ambientLight; static Vec4f ambientLight;
static Vec4f diffuseLight; static Vec4f diffuseLight;
float c; float c;
const bool isLightOn = light.isEnabled(); const bool isLightOn = light.isEnabled();
if (isLightOn) if (isLightOn)
{ {
lightPos3.set(light.getPosition()[0], light.getPosition()[1] , light.getPosition()[2]); lightPos3.set(light.getPosition()[0], light.getPosition()[1] , light.getPosition()[2]);
lightPos3 -= prj->modelViewMatrixf * Vec3f(0.f); Vec3f tmpv(0.f);
lightPos3 = prj->modelViewMatrixf.transpose().multiplyWithou prj->getModelViewTransform()->forward(tmpv); // -posCenterEy
tTranslation(lightPos3); e
lightPos3 -= tmpv;
//lightPos3 = prj->modelViewMatrixf.transpose().multiplyWith
outTranslation(lightPos3);
prj->getModelViewTransform()->backward(lightPos3);
lightPos3.normalize(); lightPos3.normalize();
ambientLight = light.getAmbient(); ambientLight = light.getAmbient();
diffuseLight = light.getDiffuse(); diffuseLight = light.getDiffuse();
} }
GLfloat x, y, z; GLfloat x, y, z;
GLfloat s=0.f, t=0.f; GLfloat s=0.f, t=0.f;
GLint i, j; GLint i, j;
GLfloat nsign; GLfloat nsign;
skipping to change at line 1773 skipping to change at line 1808
#else #else
texture2dEnabled = b; texture2dEnabled = b;
#endif #endif
} }
void StelPainter::initSystemGLInfo(QGLContext* ctx) void StelPainter::initSystemGLInfo(QGLContext* ctx)
{ {
Q_ASSERT(glContext==NULL); Q_ASSERT(glContext==NULL);
glContext = ctx; glContext = ctx;
makeMainGLContextCurrent();
isNoPowerOfTwoAllowed = QGLFormat::openGLVersionFlags().testFlag(QGL
Format::OpenGL_Version_2_0) || QGLFormat::openGLVersionFlags().testFlag(QGL
Format::OpenGL_ES_Version_2_0);
#ifdef STELPAINTER_GL2 #ifdef STELPAINTER_GL2
// Basic shader: just vertex filled with plain color // Basic shader: just vertex filled with plain color
QGLShader *vshader3 = new QGLShader(QGLShader::Vertex); QGLShader *vshader3 = new QGLShader(QGLShader::Vertex);
const char *vsrc3 = const char *vsrc3 =
"attribute mediump vec3 vertex;\n" "attribute mediump vec3 vertex;\n"
"uniform mediump mat4 projectionMatrix;\n" "uniform mediump mat4 projectionMatrix;\n"
"void main(void)\n" "void main(void)\n"
"{\n" "{\n"
" gl_Position = projectionMatrix*vec4(vertex, 1.);\n" " gl_Position = projectionMatrix*vec4(vertex, 1.);\n"
"}\n"; "}\n";
 End of changes. 13 change blocks. 
23 lines changed or deleted 69 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/