StelApp.cpp   StelApp.cpp 
skipping to change at line 23 skipping to change at line 23
* 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.
*/ */
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelMainView.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "ConstellationMgr.hpp" #include "ConstellationMgr.hpp"
#include "NebulaMgr.hpp" #include "NebulaMgr.hpp"
#include "LandscapeMgr.hpp" #include "LandscapeMgr.hpp"
#include "CustomObjectMgr.hpp" #include "CustomObjectMgr.hpp"
#include "GridLinesMgr.hpp" #include "GridLinesMgr.hpp"
#include "MilkyWay.hpp" #include "MilkyWay.hpp"
#include "ZodiacalLight.hpp" #include "ZodiacalLight.hpp"
skipping to change at line 204 skipping to change at line 205
} }
void StelApp::deinitStatic() void StelApp::deinitStatic()
{ {
StelApp::startMSecs = 0; StelApp::startMSecs = 0;
} }
/************************************************************************* /*************************************************************************
Create and initialize the main Stellarium application. Create and initialize the main Stellarium application.
*************************************************************************/ *************************************************************************/
StelApp::StelApp(QObject* parent) StelApp::StelApp(StelMainView *parent)
: QObject(parent) : QObject(parent)
, mainWin(parent)
, core(NULL) , core(NULL)
, moduleMgr(NULL) , moduleMgr(NULL)
, localeMgr(NULL) , localeMgr(NULL)
, skyCultureMgr(NULL) , skyCultureMgr(NULL)
, actionMgr(NULL) , actionMgr(NULL)
, propMgr(NULL) , propMgr(NULL)
, textureMgr(NULL) , textureMgr(NULL)
, stelObjectMgr(NULL) , stelObjectMgr(NULL)
, planetLocationMgr(NULL) , planetLocationMgr(NULL)
, networkAccessManager(NULL) , networkAccessManager(NULL)
skipping to change at line 228 skipping to change at line 230
, skyImageMgr(NULL) , skyImageMgr(NULL)
#ifndef DISABLE_SCRIPTING #ifndef DISABLE_SCRIPTING
, scriptAPIProxy(NULL) , scriptAPIProxy(NULL)
, scriptMgr(NULL) , scriptMgr(NULL)
#endif #endif
, stelGui(NULL) , stelGui(NULL)
, devicePixelsPerPixel(1.f) , devicePixelsPerPixel(1.f)
, globalScalingRatio(1.f) , globalScalingRatio(1.f)
, fps(0) , fps(0)
, frame(0) , frame(0)
, timefr(0.) , frameTimeAccum(0.)
, timeBase(0.)
, flagNightVision(false) , flagNightVision(false)
, confSettings(NULL) , confSettings(NULL)
, initialized(false) , initialized(false)
, saveProjW(-1) , saveProjW(-1)
, saveProjH(-1) , saveProjH(-1)
, nbDownloadedFiles(0) , nbDownloadedFiles(0)
, totalDownloadedSize(0) , totalDownloadedSize(0)
, nbUsedCache(0) , nbUsedCache(0)
, totalUsedCacheSize(0) , totalUsedCacheSize(0)
, baseFontSize(13) , baseFontSize(13)
, renderBuffer(NULL) , renderBuffer(NULL)
, viewportEffect(NULL) , viewportEffect(NULL)
, flagShowDecimalDegrees(false) , flagShowDecimalDegrees(false)
, flagUseAzimuthFromSouth(false) , flagUseAzimuthFromSouth(false)
#ifdef ENABLE_SPOUT #ifdef ENABLE_SPOUT
, spoutSender(NULL) , spoutSender(NULL)
#endif #endif
, currentFbo(0)
{ {
setObjectName("StelApp"); setObjectName("StelApp");
// Can't create 2 StelApp instances // Can't create 2 StelApp instances
Q_ASSERT(!singleton); Q_ASSERT(!singleton);
singleton = this; singleton = this;
moduleMgr = new StelModuleMgr(); moduleMgr = new StelModuleMgr();
wheelEventTimer = new QTimer(this); wheelEventTimer = new QTimer(this);
skipping to change at line 392 skipping to change at line 394
"runScript", "runScript",
Qt::QueuedConnection, Qt::QueuedConnection,
Q_ARG(QString, startupScript)); Q_ARG(QString, startupScript));
} }
#else #else
void StelApp::initScriptMgr() {} void StelApp::initScriptMgr() {}
#endif #endif
void StelApp::init(QSettings* conf) void StelApp::init(QSettings* conf)
{ {
gl = QOpenGLContext::currentContext()->functions();
confSettings = conf; confSettings = conf;
devicePixelsPerPixel = QOpenGLContext::currentContext()->screen()->d evicePixelRatio(); devicePixelsPerPixel = QOpenGLContext::currentContext()->screen()->d evicePixelRatio();
setBaseFontSize(confSettings->value("gui/base_font_size", 13).toInt( )); setBaseFontSize(confSettings->value("gui/base_font_size", 13).toInt( ));
core = new StelCore(); core = new StelCore();
if (saveProjW!=-1 && saveProjH!=-1) if (saveProjW!=-1 && saveProjH!=-1)
core->windowHasBeenResized(0, 0, saveProjW, saveProjH); core->windowHasBeenResized(0, 0, saveProjW, saveProjH);
skipping to change at line 613 skipping to change at line 616
scriptMgr->stopScript(); scriptMgr->stopScript();
#endif #endif
QCoreApplication::processEvents(); QCoreApplication::processEvents();
getModuleMgr().unloadAllPlugins(); getModuleMgr().unloadAllPlugins();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
StelPainter::deinitGLShaders(); StelPainter::deinitGLShaders();
} }
StelProgressController* StelApp::addProgressBar() StelProgressController* StelApp::addProgressBar()
{ {
StelProgressController* p = new StelProgressController(); StelProgressController* p = new StelProgressController(this);
progressControllers.append(p); progressControllers.append(p);
emit(progressBarAdded(p)); emit(progressBarAdded(p));
return p; return p;
} }
void StelApp::removeProgressBar(StelProgressController* p) void StelApp::removeProgressBar(StelProgressController* p)
{ {
progressControllers.removeOne(p); progressControllers.removeOne(p);
emit(progressBarRemoved(p)); emit(progressBarRemoved(p));
delete p; delete p;
} }
void StelApp::update(double deltaTime) void StelApp::update(double deltaTime)
{ {
if (!initialized) if (!initialized)
return; return;
++frame; ++frame;
timefr+=deltaTime; frameTimeAccum+=deltaTime;
if (timefr-timeBase > 1.) if (frameTimeAccum > 1.)
{ {
// Calc the FPS rate every seconds // Calc the FPS rate every seconds
fps=(double)frame/(timefr-timeBase); fps=(double)frame/frameTimeAccum;
frame = 0; frame = 0;
timeBase+=1.; frameTimeAccum=0.;
} }
core->update(deltaTime); core->update(deltaTime);
moduleMgr->update(); moduleMgr->update();
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionU pdate)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionU pdate))
{ {
i->update(deltaTime); i->update(deltaTime);
skipping to change at line 662 skipping to change at line 665
} }
void StelApp::prepareRenderBuffer() void StelApp::prepareRenderBuffer()
{ {
if (!viewportEffect) return; if (!viewportEffect) return;
if (!renderBuffer) if (!renderBuffer)
{ {
StelProjector::StelProjectorParams params = core->getCurrent StelProjectorParams(); StelProjector::StelProjectorParams params = core->getCurrent StelProjectorParams();
int w = params.viewportXywh[2]; int w = params.viewportXywh[2];
int h = params.viewportXywh[3]; int h = params.viewportXywh[3];
viewportEffect = new StelViewportDistorterFisheyeToSphericMi renderBuffer = new QOpenGLFramebufferObject(w, h, QOpenGLFra
rror(w, h); mebufferObject::Depth); // we only need depth here
renderBuffer = new QOpenGLFramebufferObject(w, h, QOpenGLFra
mebufferObject::CombinedDepthStencil);
} }
renderBuffer->bind(); renderBuffer->bind();
} }
void StelApp::applyRenderBuffer(int drawFbo) void StelApp::applyRenderBuffer(GLuint drawFbo)
{ {
if (!renderBuffer) return; if (!renderBuffer) return;
renderBuffer->release(); GL(gl->glBindFramebuffer(GL_FRAMEBUFFER, drawFbo));
if (drawFbo) GL(glBindFramebuffer(GL_FRAMEBUFFER, drawFbo));
viewportEffect->paintViewportBuffer(renderBuffer); viewportEffect->paintViewportBuffer(renderBuffer);
} }
//! Main drawing function called at each frame //! Main drawing function called at each frame
void StelApp::draw() void StelApp::draw()
{ {
if (!initialized) if (!initialized)
return; return;
int drawFbo; //find out which framebuffer is the current one
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &drawFbo); //this is usually NOT the "zero" FBO, but one provided by QOpenGLWid
get
GLint drawFbo;
GL(gl->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &drawFbo));
prepareRenderBuffer(); prepareRenderBuffer();
currentFbo = renderBuffer ? renderBuffer->handle() : drawFbo;
core->preDraw(); core->preDraw();
const QList<StelModule*> modules = moduleMgr->getCallOrders(StelModu le::ActionDraw); const QList<StelModule*> modules = moduleMgr->getCallOrders(StelModu le::ActionDraw);
foreach(StelModule* module, modules) foreach(StelModule* module, modules)
{ {
module->draw(core); module->draw(core);
} }
core->postDraw(); core->postDraw();
#ifdef ENABLE_SPOUT #ifdef ENABLE_SPOUT
// At this point, the sky scene has been drawn, but no GUI panels. // At this point, the sky scene has been drawn, but no GUI panels.
if(spoutSender) if(spoutSender)
spoutSender->captureAndSendFrame(drawFbo); spoutSender->captureAndSendFrame(drawFbo);
#endif #endif
applyRenderBuffer(drawFbo); applyRenderBuffer(drawFbo);
} }
/************************************************************************* /*************************************************************************
Call this when the size of the GL window has changed Call this when the size of the GL window has changed
*************************************************************************/ *************************************************************************/
void StelApp::glWindowHasBeenResized(float x, float y, float w, float h) void StelApp::glWindowHasBeenResized(const QRectF& rect)
{ {
if (core) if (core)
core->windowHasBeenResized(x, y, w, h); core->windowHasBeenResized(rect.x(), rect.y(), rect.width(), rect.height());
else else
{ {
saveProjW = w; saveProjW = rect.width();
saveProjH = h; saveProjH = rect.height();
} }
if (renderBuffer) if (renderBuffer)
{ {
ensureGLContextCurrent();
delete renderBuffer; delete renderBuffer;
renderBuffer = NULL; renderBuffer = NULL;
} }
#ifdef ENABLE_SPOUT #ifdef ENABLE_SPOUT
if (spoutSender) if (spoutSender)
spoutSender->resize(w,h); spoutSender->resize(rect.width(),rect.height());
#endif #endif
} }
// Handle mouse clics // Handle mouse clics
void StelApp::handleClick(QMouseEvent* inputEvent) void StelApp::handleClick(QMouseEvent* inputEvent)
{ {
QPointF pos = inputEvent->pos(); QPointF pos = inputEvent->pos();
float x, y; float x, y;
x = pos.x(); x = pos.x();
y = pos.y(); y = pos.y();
skipping to change at line 788 skipping to change at line 794
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseClicks)) { foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseClicks)) {
i->handleMouseWheel(&deltaEvent); i->handleMouseWheel(&deltaEvent);
if (deltaEvent.isAccepted()) { if (deltaEvent.isAccepted()) {
event->accept(); event->accept();
break; break;
} }
} }
} }
// Handle mouse move // Handle mouse move
void StelApp::handleMove(float x, float y, Qt::MouseButtons b) bool StelApp::handleMove(float x, float y, Qt::MouseButtons b)
{ {
if (viewportEffect) if (viewportEffect)
viewportEffect->distortXY(x, y); viewportEffect->distortXY(x, y);
// Send the event to every StelModule // Send the event to every StelModule
foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseMoves)) foreach (StelModule* i, moduleMgr->getCallOrders(StelModule::ActionH andleMouseMoves))
{ {
if (i->handleMouseMoves(x*devicePixelsPerPixel, y*devicePixe lsPerPixel, b)) if (i->handleMouseMoves(x*devicePixelsPerPixel, y*devicePixe lsPerPixel, b))
return; return true;
} }
return false;
} }
// Handle key press and release // Handle key press and release
void StelApp::handleKeys(QKeyEvent* event) void StelApp::handleKeys(QKeyEvent* event)
{ {
event->setAccepted(false); event->setAccepted(false);
// First try to trigger a shortcut. // First try to trigger a shortcut.
if (event->type() == QEvent::KeyPress) if (event->type() == QEvent::KeyPress)
{ {
if (getStelActionManager()->pushKey(event->key() + event->mo difiers())) if (getStelActionManager()->pushKey(event->key() + event->mo difiers()))
skipping to change at line 856 skipping to change at line 863
} }
// Update translations and font for sky everywhere in the program // Update translations and font for sky everywhere in the program
void StelApp::updateI18n() void StelApp::updateI18n()
{ {
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
emit(languageChanged()); emit(languageChanged());
#endif #endif
} }
void StelApp::ensureGLContextCurrent()
{
mainWin->glContextMakeCurrent();
}
// Return the time since when stellarium is running in second. // Return the time since when stellarium is running in second.
double StelApp::getTotalRunTime() double StelApp::getTotalRunTime()
{ {
return (double)(QDateTime::currentMSecsSinceEpoch() - StelApp::start MSecs)/1000.; return (double)(QDateTime::currentMSecsSinceEpoch() - StelApp::start MSecs)/1000.;
} }
// Return the scaled time since when stellarium is running in second. // Return the scaled time since when stellarium is running in second.
double StelApp::getAnimationTime() double StelApp::getAnimationTime()
{ {
return (double)(QDateTime::currentMSecsSinceEpoch() - StelApp::start MSecs)*StelApp::animationScale/1000.; return (double)(QDateTime::currentMSecsSinceEpoch() - StelApp::start MSecs)*StelApp::animationScale/1000.;
skipping to change at line 906 skipping to change at line 918
params.devicePixelsPerPixel = devicePixelsPerPixel; params.devicePixelsPerPixel = devicePixelsPerPixel;
core->setCurrentStelProjectorParams(params); core->setCurrentStelProjectorParams(params);
} }
} }
void StelApp::setViewportEffect(const QString& name) void StelApp::setViewportEffect(const QString& name)
{ {
if (name == getViewportEffect()) return; if (name == getViewportEffect()) return;
if (renderBuffer) if (renderBuffer)
{ {
ensureGLContextCurrent();
delete renderBuffer; delete renderBuffer;
renderBuffer = NULL; renderBuffer = NULL;
} }
if (viewportEffect) if (viewportEffect)
{ {
delete viewportEffect; delete viewportEffect;
viewportEffect = NULL; viewportEffect = NULL;
} }
if (name == "none") return; if (name == "none") return;
 End of changes. 25 change blocks. 
24 lines changed or deleted 37 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/