StelSkyDrawer.cpp   StelSkyDrawer.cpp 
skipping to change at line 20 skipping to change at line 20
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef GL_POINT_SPRITE
#define GL_POINT_SPRITE 0x8861
#endif
#ifndef GL_VERTEX_PROGRAM_POINT_SIZE
#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
#endif
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelToneReproducer.hpp" #include "StelToneReproducer.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelModuleMgr.hpp"
#include "LandscapeMgr.hpp"
#include "Landscape.hpp"
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <QStringList> #include <QStringList>
#include <QSettings> #include <QSettings>
#include <QDebug> #include <QDebug>
#include <QtGlobal> #include <QtGlobal>
// The 0.025 corresponds to the maximum eye resolution in degree // The 0.025 corresponds to the maximum eye resolution in degree
#define EYE_RESOLUTION (0.25f) #define EYE_RESOLUTION (0.25f)
#define MAX_LINEAR_RADIUS 8.f #define MAX_LINEAR_RADIUS 8.f
StelSkyDrawer::StelSkyDrawer(StelCore* acore) : StelSkyDrawer::StelSkyDrawer(StelCore* acore) :
core(acore), core(acore),
eye(acore->getToneReproducer()), eye(acore->getToneReproducer()),
maxAdaptFov(180.f), maxAdaptFov(180.f),
minAdaptFov(0.1f), minAdaptFov(0.1f),
lnfovFactor(0.f), lnfovFactor(0.f),
flagStarTwinkle(false),
flagForcedTwinkle(false),
twinkleAmount(0.0),
flagStarMagnitudeLimit(false),
flagNebulaMagnitudeLimit(false),
flagPlanetMagnitudeLimit(false),
starRelativeScale(1.f), starRelativeScale(1.f),
starAbsoluteScaleF(1.f), starAbsoluteScaleF(1.f),
starLinearScale(19.569f), starLinearScale(19.569f),
limitMagnitude(-100.f), limitMagnitude(-100.f),
limitLuminance(0.f), limitLuminance(0.f),
customStarMagLimit(0.0),
customNebulaMagLimit(0.0),
customPlanetMagLimit(0.0),
bortleScaleIndex(3), bortleScaleIndex(3),
inScale(1.f), inScale(1.f),
starShaderProgram(NULL), starShaderProgram(NULL),
starShaderVars(StarShaderVars()), starShaderVars(StarShaderVars()),
nbPointSources(0),
maxPointSources(1000),
maxLum(0.f), maxLum(0.f),
oldLum(-1.f), oldLum(-1.f),
flagLuminanceAdaptation(false),
big3dModelHaloRadius(150.f) big3dModelHaloRadius(150.f)
{ {
setObjectName("StelSkyDrawer"); setObjectName("StelSkyDrawer");
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
initColorTableFromConfigFile(conf); initColorTableFromConfigFile(conf);
setFlagHasAtmosphere(conf->value("landscape/flag_atmosphere", true). toBool()); setFlagHasAtmosphere(conf->value("landscape/flag_atmosphere", true). toBool());
setTwinkleAmount(conf->value("stars/star_twinkle_amount",0.3).toFloa t()); setTwinkleAmount(conf->value("stars/star_twinkle_amount",0.3).toFloa t());
setFlagTwinkle(conf->value("stars/flag_star_twinkle",true).toBool()) ; setFlagTwinkle(conf->value("stars/flag_star_twinkle",true).toBool()) ;
setFlagForcedTwinkle(conf->value("stars/flag_forced_twinkle",false). toBool()); setFlagForcedTwinkle(conf->value("stars/flag_forced_twinkle",false). toBool());
skipping to change at line 121 skipping to change at line 130
setAtmosphereTemperature(conf->value("landscape/temperature_C",15.0) .toDouble(&ok)); setAtmosphereTemperature(conf->value("landscape/temperature_C",15.0) .toDouble(&ok));
if (!ok) if (!ok)
setAtmosphereTemperature(15.0); setAtmosphereTemperature(15.0);
setAtmospherePressure(conf->value("landscape/pressure_mbar",1013.0). toDouble(&ok)); setAtmospherePressure(conf->value("landscape/pressure_mbar",1013.0). toDouble(&ok));
if (!ok) if (!ok)
setAtmospherePressure(1013.0); setAtmospherePressure(1013.0);
// Initialize buffers for use by gl vertex array // Initialize buffers for use by gl vertex array
nbPointSources = 0;
maxPointSources = 1000;
vertexArray = new StarVertex[maxPointSources*6]; vertexArray = new StarVertex[maxPointSources*6];
textureCoordArray = new unsigned char[maxPointSources*6*2]; textureCoordArray = new unsigned char[maxPointSources*6*2];
for (unsigned int i=0;i<maxPointSources; ++i) for (unsigned int i=0;i<maxPointSources; ++i)
{ {
static const unsigned char texElems[] = {0, 0, 255, 0, 255, 255, 0, 0, 255, 255, 0, 255}; static const unsigned char texElems[] = {0, 0, 255, 0, 255, 255, 0, 0, 255, 255, 0, 255};
unsigned char* elem = &textureCoordArray[i*6*2]; unsigned char* elem = &textureCoordArray[i*6*2];
memcpy(elem, texElems, 12); memcpy(elem, texElems, 12);
} }
skipping to change at line 149 skipping to change at line 156
delete[] textureCoordArray; delete[] textureCoordArray;
textureCoordArray = NULL; textureCoordArray = NULL;
delete starShaderProgram; delete starShaderProgram;
starShaderProgram = NULL; starShaderProgram = NULL;
} }
// Init parameters from config file // Init parameters from config file
void StelSkyDrawer::init() void StelSkyDrawer::init()
{ {
initializeOpenGLFunctions();
// Load star texture no mipmap: // Load star texture no mipmap:
texHalo = StelApp::getInstance().getTextureManager().createTexture(S telFileMgr::getInstallationDir()+"/textures/star16x16.png"); texHalo = StelApp::getInstance().getTextureManager().createTexture(S telFileMgr::getInstallationDir()+"/textures/star16x16.png");
texBigHalo = StelApp::getInstance().getTextureManager().createTextur e(StelFileMgr::getInstallationDir()+"/textures/haloLune.png"); texBigHalo = StelApp::getInstance().getTextureManager().createTextur e(StelFileMgr::getInstallationDir()+"/textures/haloLune.png");
texSunHalo = StelApp::getInstance().getTextureManager().createTextur e(StelFileMgr::getInstallationDir()+"/textures/halo.png"); texSunHalo = StelApp::getInstance().getTextureManager().createTextur e(StelFileMgr::getInstallationDir()+"/textures/halo.png");
texSunCorona = StelApp::getInstance().getTextureManager().createText ure(StelFileMgr::getInstallationDir()+"/textures/corona.png"); texSunCorona = StelApp::getInstance().getTextureManager().createText ure(StelFileMgr::getInstallationDir()+"/textures/corona.png");
// Create shader program // Create shader program
QOpenGLShader vshader(QOpenGLShader::Vertex); QOpenGLShader vshader(QOpenGLShader::Vertex);
const char *vsrc = const char *vsrc =
"attribute mediump vec2 pos;\n" "attribute mediump vec2 pos;\n"
skipping to change at line 375 skipping to change at line 384
return true; return true;
} }
void StelSkyDrawer::preDrawPointSource(StelPainter* p) void StelSkyDrawer::preDrawPointSource(StelPainter* p)
{ {
Q_ASSERT(p); Q_ASSERT(p);
Q_ASSERT(nbPointSources==0); Q_ASSERT(nbPointSources==0);
// Blending is really important. Otherwise faint stars in the vicini ty of // Blending is really important. Otherwise faint stars in the vicini ty of
// bright star will cause tiny black squares on the bright star, e.g . see Procyon. // bright star will cause tiny black squares on the bright star, e.g . see Procyon.
glEnable(GL_BLEND); p->setBlending(true, GL_ONE, GL_ONE);
glBlendFunc(GL_ONE, GL_ONE);
p->enableTexture2d(true);
} }
// Finalize the drawing of point sources // Finalize the drawing of point sources
void StelSkyDrawer::postDrawPointSource(StelPainter* sPainter) void StelSkyDrawer::postDrawPointSource(StelPainter* sPainter)
{ {
Q_ASSERT(sPainter); Q_ASSERT(sPainter);
if (nbPointSources==0) if (nbPointSources==0)
return; return;
texHalo->bind(); texHalo->bind();
sPainter->enableTexture2d(true); sPainter->setBlending(true, GL_ONE, GL_ONE);
glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);
const Mat4f& m = sPainter->getProjector()->getProjectionMatrix(); const Mat4f& m = sPainter->getProjector()->getProjectionMatrix();
const QMatrix4x4 qMat(m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[1 3], m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]); const QMatrix4x4 qMat(m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[1 3], m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]);
Q_ASSERT(sizeof(StarVertex)==12); Q_ASSERT(sizeof(StarVertex)==12);
starShaderProgram->bind(); starShaderProgram->bind();
starShaderProgram->setAttributeArray(starShaderVars.pos, GL_FLOAT, ( GLfloat*)vertexArray, 2, 12); starShaderProgram->setAttributeArray(starShaderVars.pos, GL_FLOAT, ( GLfloat*)vertexArray, 2, 12);
starShaderProgram->enableAttributeArray(starShaderVars.pos); starShaderProgram->enableAttributeArray(starShaderVars.pos);
starShaderProgram->setAttributeArray(starShaderVars.color, GL_UNSIGN ED_BYTE, (GLubyte*)&(vertexArray[0].color), 3, 12); starShaderProgram->setAttributeArray(starShaderVars.color, GL_UNSIGN ED_BYTE, (GLubyte*)&(vertexArray[0].color), 3, 12);
skipping to change at line 445 skipping to change at line 450
// If the rmag is big, draw a big halo // If the rmag is big, draw a big halo
if (radius>MAX_LINEAR_RADIUS+5.f) if (radius>MAX_LINEAR_RADIUS+5.f)
{ {
float cmag = qMin(rcMag.luminance,(float)(radius-(MAX_LINEAR _RADIUS+5.f))/30.f); float cmag = qMin(rcMag.luminance,(float)(radius-(MAX_LINEAR _RADIUS+5.f))/30.f);
float rmag = 150.f; float rmag = 150.f;
if (cmag>1.f) if (cmag>1.f)
cmag = 1.f; cmag = 1.f;
texBigHalo->bind(); texBigHalo->bind();
sPainter->enableTexture2d(true); sPainter->setBlending(true, GL_ONE, GL_ONE);
glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);
sPainter->setColor(color[0]*cmag, color[1]*cmag, color[2]*cm ag); sPainter->setColor(color[0]*cmag, color[1]*cmag, color[2]*cm ag);
sPainter->drawSprite2dModeNoDeviceScale(win[0], win[1], rmag ); sPainter->drawSprite2dModeNoDeviceScale(win[0], win[1], rmag );
} }
unsigned char starColor[3] = {0, 0, 0}; unsigned char starColor[3] = {0, 0, 0};
starColor[0] = (unsigned char)std::min((int)(color[0]*tw*255+0.5f), 255); starColor[0] = (unsigned char)std::min((int)(color[0]*tw*255+0.5f), 255);
starColor[1] = (unsigned char)std::min((int)(color[1]*tw*255+0.5f), 255); starColor[1] = (unsigned char)std::min((int)(color[1]*tw*255+0.5f), 255);
starColor[2] = (unsigned char)std::min((int)(color[2]*tw*255+0.5f), 255); starColor[2] = (unsigned char)std::min((int)(color[2]*tw*255+0.5f), 255);
// Store the drawing instructions in the vertex arrays // Store the drawing instructions in the vertex arrays
skipping to change at line 479 skipping to change at line 482
// Flush the buffer (draw all buffered stars) // Flush the buffer (draw all buffered stars)
postDrawPointSource(sPainter); postDrawPointSource(sPainter);
} }
return true; return true;
} }
// Draw's the Sun's corona during a solar eclipse on Earth. // Draw's the Sun's corona during a solar eclipse on Earth.
void StelSkyDrawer::drawSunCorona(StelPainter* painter, const Vec3f& v, flo at radius, const Vec3f& color, const float alpha) void StelSkyDrawer::drawSunCorona(StelPainter* painter, const Vec3f& v, flo at radius, const Vec3f& color, const float alpha)
{ {
texSunCorona->bind(); texSunCorona->bind();
glEnable(GL_BLEND); painter->setBlending(true, GL_ONE, GL_ONE);
glBlendFunc(GL_ONE, GL_ONE);
painter->enableTexture2d(true);
Vec3f win; Vec3f win;
painter->getProjector()->project(v, win); painter->getProjector()->project(v, win);
// For some reason we must mix color with the given alpha as well, e lse mixing does not work. // For some reason we must mix color with the given alpha as well, e lse mixing does not work.
painter->setColor(color[0]*alpha, color[1]*alpha, color[2]*alpha, al pha); painter->setColor(color[0]*alpha, color[1]*alpha, color[2]*alpha, al pha);
painter->drawSprite2dMode(win[0], win[1], radius); painter->drawSprite2dMode(win[0], win[1], radius);
postDrawPointSource(painter); postDrawPointSource(painter);
} }
skipping to change at line 506 skipping to change at line 507
// Assume a disk shape // Assume a disk shape
float pixRadius = std::sqrt(illuminatedArea/(60.*60.)*M_PI/180.*M_PI /180.*(pixPerRad*pixPerRad))/M_PI; float pixRadius = std::sqrt(illuminatedArea/(60.*60.)*M_PI/180.*M_PI /180.*(pixPerRad*pixPerRad))/M_PI;
bool noStarHalo = false; bool noStarHalo = false;
if (mag<-15.f) if (mag<-15.f)
{ {
// Sun, halo size varies in function of the magnitude becaus e sun as seen from pluto should look dimmer // Sun, halo size varies in function of the magnitude becaus e sun as seen from pluto should look dimmer
// as the sun as seen from earth // as the sun as seen from earth
texSunHalo->bind(); texSunHalo->bind();
glEnable(GL_BLEND); painter->setBlending(true, GL_ONE, GL_ONE);
glBlendFunc(GL_ONE, GL_ONE);
painter->enableTexture2d(true);
float rmag = big3dModelHaloRadius*(mag+15.f)/-11.f; float rmag = big3dModelHaloRadius*(mag+15.f)/-11.f;
float cmag = 1.f; float cmag = 1.f;
if (rmag<pixRadius*3.f+100.) if (rmag<pixRadius*3.f+100.)
cmag = qMax(0.f, 1.f-(pixRadius*3.f+100-rmag)/100); cmag = qMax(0.f, 1.f-(pixRadius*3.f+100-rmag)/100);
Vec3f win; Vec3f win;
painter->getProjector()->project(v, win); painter->getProjector()->project(v, win);
painter->setColor(color[0]*cmag, color[1]*cmag, color[2]*cma g); painter->setColor(color[0]*cmag, color[1]*cmag, color[2]*cma g);
painter->drawSprite2dModeNoDeviceScale(win[0], win[1], rmag) ; painter->drawSprite2dModeNoDeviceScale(win[0], win[1], rmag) ;
noStarHalo = true; noStarHalo = true;
} }
skipping to change at line 561 skipping to change at line 561
{ {
rcm.luminance=(tStop-pixRadius)/(tStop-tStart); rcm.luminance=(tStop-pixRadius)/(tStop-tStart);
} }
if (truncated && flagLuminanceAdaptation) if (truncated && flagLuminanceAdaptation)
{ {
float wl = findWorldLumForMag(mag, rcm.radius); float wl = findWorldLumForMag(mag, rcm.radius);
if (wl>0) if (wl>0)
{ {
const float f = core->getMovementMgr()->getCurrentFo v(); const float f = core->getMovementMgr()->getCurrentFo v();
reportLuminanceInFov(qMin(700.f, qMin(wl/50, (60.f*6 // Report to the SkyDrawer that a very bright object
0.f)/(f*f)*6.f))); (most notably Sun, Moon, bright planet)
// is in view. LP:1138533 correctly wants no such ef
fect if object is hidden by landscape horizon.
LandscapeMgr* lmgr=GETSTELMODULE(LandscapeMgr);
Q_ASSERT(lmgr);
Landscape *landscape=lmgr->getCurrentLandscape();
Q_ASSERT(landscape);
// Preliminary: create new Vec3d here. Later: consid
er replacing to vec3d in the arguments!
Vec3d vec(v[0], v[1], v[2]);
float opacity=(landscape->getFlagShow() ? landscape-
>getOpacity(core->j2000ToAltAz(vec, StelCore::RefractionAuto)) : 0.0f);
reportLuminanceInFov(qMin(700.f, qMin(wl/50, (60.f*6
0.f)/(f*f)*6.f))*(1.0f-opacity));
} }
} }
if (!noStarHalo) if (!noStarHalo)
{ {
preDrawPointSource(painter); preDrawPointSource(painter);
drawPointSource(painter, v, rcm, color); drawPointSource(painter, v, rcm, color);
postDrawPointSource(painter); postDrawPointSource(painter);
} }
flagStarTwinkle=save; flagStarTwinkle=save;
 End of changes. 14 change blocks. 
26 lines changed or deleted 39 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/