Commit 845dcfa8 authored by Illya Kovalevskyy's avatar Illya Kovalevskyy Committed by Bernhard Beschow
Browse files

Cache the atmosphere (increases performance).

Backported from commit cb2e071a.

BUG: 311119
REVIEW: 107581
parent 5d0906b8
......@@ -7,9 +7,10 @@
//
// Copyright 2006-2007 Torsten Rahn <tackat@kde.org>
// Copyright 2007 Inge Wallin <ingwa@kde.org>
// Copyright 2008, 2009, 2010 Jens-Michael Hoffmann <jmho@c-xx.com>
// Copyright 2008-2009 Patrick Spendrin <ps_ml@gmx.de>
// Copyright 2008-2010 Jens-Michael Hoffmann <jmho@c-xx.com>
// Copyright 2008-2009 Patrick Spendrin <ps_ml@gmx.de>
// Copyright 2010-2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
// Copyright 2012 Kovalevskyy Illya <illya.kovalevskyy@gmail.com>
//
#include "AtmospherePlugin.h"
......@@ -21,12 +22,14 @@ namespace Marble
{
AtmospherePlugin::AtmospherePlugin() :
RenderPlugin( 0 )
RenderPlugin( 0 ),
m_renderRadius(-1)
{
}
AtmospherePlugin::AtmospherePlugin( const MarbleModel *marbleModel ) :
RenderPlugin( marbleModel )
RenderPlugin( marbleModel ),
m_renderRadius(-1)
{
}
......@@ -124,32 +127,41 @@ bool AtmospherePlugin::render( GeoPainter *painter,
if ( viewParams->mapCoversViewport() )
return true;
// Ok, now we know that at least a little of the atmosphere is
// visible, if nothing else in the corners. Draw the atmosphere
// by using a circular gradient. This is a pure visual effect and
// has nothing to do with real physics.
// Gradient should be recalculated only if planet size changed
if(viewParams->radius() != m_renderRadius) {
m_renderRadius = viewParams->radius();
repaintPixmap(viewParams);
}
int imageHalfWidth = viewParams->width() / 2;
int imageHalfHeight = viewParams->height() / 2;
painter->drawPixmap(imageHalfWidth - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ),
imageHalfHeight - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ),
m_renderPixmap);
return true;
}
void AtmospherePlugin::repaintPixmap(const ViewportParams *viewParams)
{
const int radius = 1.05 * viewParams->radius();
const int diameter = 2.1 * viewParams->radius();
m_renderPixmap = QPixmap(diameter, diameter);
m_renderPixmap.fill(QColor(Qt::transparent));
QPainter renderPainter(&m_renderPixmap);
// Recalculate the atmosphere effect and paint it to canvasImage.
QRadialGradient grad1( QPointF( imageHalfWidth, imageHalfHeight ),
1.05 * viewParams->radius() );
grad1.setColorAt( 0.91, QColor( 255, 255, 255, 255 ) );
grad1.setColorAt( 1.00, QColor( 255, 255, 255, 0 ) );
QBrush brush1( grad1 );
QPen pen1( Qt::NoPen );
painter->setBrush( brush1 );
painter->setPen( pen1 );
painter->setRenderHint( QPainter::Antialiasing, false );
painter->drawEllipse( imageHalfWidth - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ),
imageHalfHeight - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ),
(int) ( 2.1 * (qreal) ( viewParams->radius()) ),
(int) ( 2.1 * (qreal) ( viewParams->radius()) ) );
QRadialGradient gradient( radius, radius, 1.05 * viewParams->radius() );
gradient.setColorAt( 0.91, QColor( 255, 255, 255, 255 ) );
gradient.setColorAt( 1.00, QColor( 255, 255, 255, 0 ) );
return true;
QBrush brush(gradient);
renderPainter.setBrush(brush);
renderPainter.setPen(Qt::NoPen);
renderPainter.setRenderHint(QPainter::Antialiasing, false);
// Let's paint elipse we want in this::render(..) on pixmap from point (0;0)
renderPainter.drawEllipse(0, 0, diameter, diameter);
}
}
......
......@@ -57,6 +57,11 @@ public:
bool isInitialized() const;
bool render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer = 0 );
void repaintPixmap(const ViewportParams *viewParams);
private:
QPixmap m_renderPixmap;
int m_renderRadius;
};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment