StelSkyImageTile.cpp   StelSkyImageTile.cpp 
skipping to change at line 20 skipping to change at line 20
* 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.
*/ */
#include "StelSkyImageTile.hpp" #include "StelSkyImageTile.hpp"
#include "StelTextureMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "renderer/StelRenderer.hpp" #include "StelTexture.hpp"
#include "renderer/StelTextureParams.hpp"
#include "renderer/StelTextureNew.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelToneReproducer.hpp" #include "StelToneReproducer.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "StelPainter.hpp"
#include <QDebug> #include <QDebug>
#include <stdio.h>
StelSkyImageTile::StelSkyImageTile() StelSkyImageTile::StelSkyImageTile()
{ {
initCtor(); initCtor();
} }
void StelSkyImageTile::initCtor() void StelSkyImageTile::initCtor()
{ {
minResolution = -1; minResolution = -1;
luminance = -1; luminance = -1;
alphaBlend = false; alphaBlend = false;
noTexture = false; noTexture = false;
texFader = NULL; texFader = NULL;
tex = NULL;
} }
// Constructor // Constructor
StelSkyImageTile::StelSkyImageTile(const QString& url, StelSkyImageTile* pa StelSkyImageTile::StelSkyImageTile(const QString& url, StelSkyImageTile* pa
rent) rent) : MultiLevelJsonBase(parent)
: MultiLevelJsonBase(parent)
{ {
initCtor(); initCtor();
if (parent!=NULL) if (parent!=NULL)
{ {
luminance = parent->luminance; luminance = parent->luminance;
alphaBlend = parent->alphaBlend; alphaBlend = parent->alphaBlend;
} }
initFromUrl(url); initFromUrl(url);
} }
skipping to change at line 76 skipping to change at line 76
{ {
luminance = parent->luminance; luminance = parent->luminance;
alphaBlend = parent->alphaBlend; alphaBlend = parent->alphaBlend;
} }
initFromQVariantMap(map); initFromQVariantMap(map);
} }
// Destructor // Destructor
StelSkyImageTile::~StelSkyImageTile() StelSkyImageTile::~StelSkyImageTile()
{ {
if(NULL != tex)
{
delete tex;
tex = NULL;
}
} }
void StelSkyImageTile::draw(StelCore* core, StelRenderer* renderer, StelPro jectorP projector, float) void StelSkyImageTile::draw(StelCore* core, StelPainter& sPainter, float)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000)
;
const float limitLuminance = core->getSkyDrawer()->getLimitLuminance (); const float limitLuminance = core->getSkyDrawer()->getLimitLuminance ();
QMultiMap<double, StelSkyImageTile*> result; QMultiMap<double, StelSkyImageTile*> result;
getTilesToDraw(result, core, renderer, projector->getViewportConvexP olygon(0, 0), limitLuminance, true); getTilesToDraw(result, core, prj->getViewportConvexPolygon(0, 0), li mitLuminance, true);
int numToBeLoaded=0; int numToBeLoaded=0;
foreach (StelSkyImageTile* t, result) foreach (StelSkyImageTile* t, result)
if (t->isReadyToDisplay()==false) if (t->isReadyToDisplay()==false)
++numToBeLoaded; ++numToBeLoaded;
updatePercent(result.size(), numToBeLoaded); updatePercent(result.size(), numToBeLoaded);
// Draw in the right order // Draw in the good order
sPainter.enableTexture2d(true);
glBlendFunc(GL_ONE, GL_ONE);
QMap<double, StelSkyImageTile*>::Iterator i = result.end(); QMap<double, StelSkyImageTile*>::Iterator i = result.end();
while (i!=result.begin()) while (i!=result.begin())
{ {
--i; --i;
i.value()->drawTile(core, renderer, projector); i.value()->drawTile(core, sPainter);
} }
deleteUnusedSubTiles(); deleteUnusedSubTiles();
} }
// Return the list of tiles which should be drawn. // Return the list of tiles which should be drawn.
void StelSkyImageTile::getTilesToDraw void StelSkyImageTile::getTilesToDraw(QMultiMap<double, StelSkyImageTile*>&
(QMultiMap<double, StelSkyImageTile*>& result, StelCore* core, result, StelCore* core, const SphericalRegionP& viewPortPoly, float limitL
StelRenderer* renderer, const SphericalRegionP& viewPortPoly, uminance, bool recheckIntersect)
float limitLuminance, bool recheckIntersect)
{ {
#ifndef NDEBUG #ifndef NDEBUG
// When this method is called, we can assume that: // When this method is called, we can assume that:
// - the parent tile min resolution was reached // - the parent tile min resolution was reached
// - the parent tile is intersecting FOV // - the parent tile is intersecting FOV
// - the parent tile is not scheduled for deletion // - the parent tile is not scheduled for deletion
const StelSkyImageTile* parent = qobject_cast<StelSkyImageTile*>(QOb ject::parent()); const StelSkyImageTile* parent = qobject_cast<StelSkyImageTile*>(QOb ject::parent());
if (parent!=NULL) if (parent!=NULL)
{ {
skipping to change at line 189 skipping to change at line 185
scheduleChildsDeletion(); scheduleChildsDeletion();
return; return;
} }
// The tile is in screen, and it is a precondition that its resoluti on is higher than the limit // The tile is in screen, and it is a precondition that its resoluti on is higher than the limit
// make sure that it's not going to be deleted // make sure that it's not going to be deleted
cancelDeletion(); cancelDeletion();
if (noTexture==false) if (noTexture==false)
{ {
if (NULL == tex) if (!tex)
{ {
// The tile has an associated texture, but it is not yet loaded: load it now // The tile has an associated texture, but it is not yet loaded: load it now
tex = renderer->createTexture(absoluteImageURI, Text StelTextureMgr& texMgr=StelApp::getInstance().getTex
ureParams().generateMipmaps(), tureManager();
TextureLoadingMode_Laz tex = texMgr.createTextureThread(absoluteImageURI, S
yAsynchronous); telTexture::StelTextureParams(true));
if (tex->getStatus() == TextureStatus_Error) if (!tex)
{ {
qWarning() << "WARNING : Can't create tile: " << absoluteImageURI; qWarning() << "WARNING : Can't create tile: " << absoluteImageURI;
errorOccured = true; errorOccured = true;
return; return;
} }
} }
// The tile is in screen and has a texture: every test passe d :) The tile will be displayed // The tile is in screen and has a texture: every test passe d :) The tile will be displayed
result.insert(minResolution, this); result.insert(minResolution, this);
} }
skipping to change at line 229 skipping to change at line 225
{ {
Q_ASSERT(s.type()==QVariant::String) ; Q_ASSERT(s.type()==QVariant::String) ;
nt = new StelSkyImageTile(s.toString (), this); nt = new StelSkyImageTile(s.toString (), this);
} }
subTiles.append(nt); subTiles.append(nt);
} }
} }
// Try to add the subtiles // Try to add the subtiles
foreach (MultiLevelJsonBase* tile, subTiles) foreach (MultiLevelJsonBase* tile, subTiles)
{ {
qobject_cast<StelSkyImageTile*>(tile)->getTilesToDra w(result, core, renderer, viewPortPoly, limitLuminance, !fullInScreen); qobject_cast<StelSkyImageTile*>(tile)->getTilesToDra w(result, core, viewPortPoly, limitLuminance, !fullInScreen);
} }
} }
else else
{ {
// The subtiles should not be displayed because their resolu tion is too high // The subtiles should not be displayed because their resolu tion is too high
scheduleChildsDeletion(); scheduleChildsDeletion();
} }
} }
// Draw the image on the screen. // Draw the image on the screen.
bool StelSkyImageTile::drawTile(StelCore* core, StelRenderer* renderer, Ste // Assume GL_TEXTURE_2D is enabled
lProjectorP projector) bool StelSkyImageTile::drawTile(StelCore* core, StelPainter& sPainter)
{ {
StelSkyDrawer* drawer = core->getSkyDrawer(); if (!tex->bind())
Extinction extinction=core->getSkyDrawer()->getExtinction(); return false;
const bool withExtinction=(drawer->getFlagHasAtmosphere() && extinct
ion.getExtinctionCoefficient()>=0.01f);
tex->bind();
if (!texFader) if (!texFader)
{ {
texFader = new QTimeLine(1000, this); texFader = new QTimeLine(1000, this);
texFader->start(); texFader->start();
} }
// Draw the real texture for this image // Draw the real texture for this image
const float ad_lum = float ad_lum = (luminance>0) ? core->getToneReproducer()->adaptLumin
(luminance>0) ? core->getToneReproducer()->adaptLuminanceSca anceScaled(luminance) : 1.f;
led(luminance) : 1.f; ad_lum=std::min(1.f, ad_lum);
Vec4f color; Vec4f color;
if (alphaBlend==true || texFader->state()==QTimeLine::Running) if (alphaBlend==true || texFader->state()==QTimeLine::Running)
{ {
// This is a bit weird, but rewritten to mirror pre-refactor if (!alphaBlend)
code glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /
if(!alphaBlend) / Normal transparency mode
{
renderer->setBlendMode(BlendMode_Alpha);
}
else else
{ glBlendFunc(GL_ONE, GL_ONE);
renderer->setBlendMode(BlendMode_Add); glEnable(GL_BLEND);
}
color.set(ad_lum,ad_lum,ad_lum, texFader->currentValue()); color.set(ad_lum,ad_lum,ad_lum, texFader->currentValue());
} }
else else
{ {
renderer->setBlendMode(BlendMode_None); glDisable(GL_BLEND);
color.set(ad_lum,ad_lum,ad_lum, 1.); color.set(ad_lum,ad_lum,ad_lum, 1.f);
} }
color[0] = std::min(color[0], 1.0f); const bool withExtinction=(core->getSkyDrawer()->getFlagHasAtmospher
color[1] = std::min(color[1], 1.0f); e() && core->getSkyDrawer()->getExtinction().getExtinctionCoefficient()>=0.
color[2] = std::min(color[2], 1.0f); 01f);
color[3] = std::min(color[3], 1.0f);
// color is the pre-extinction color
sPainter.enableTexture2d(true);
foreach (const SphericalRegionP& poly, skyConvexPolygons) foreach (const SphericalRegionP& poly, skyConvexPolygons)
{ {
Vec4f extinctedColor=color; Vec4f extinctedColor = color;
if (withExtinction) if (withExtinction)
{ {
Vec3d bary= poly->getPointInside(); // This is a J00 0.0 vector that points "somewhere" in the first triangle. Vec3d bary= poly->getPointInside(); // This is a J00 0.0 vector that points "somewhere" in the first triangle.
Vec3d altAz = core->j2000ToAltAz(bary, StelCore::Ref ractionOn); Vec3d altAz = core->j2000ToAltAz(bary, StelCore::Ref ractionOff);
float extinctionMagnitude=0.0f; float extinctionMagnitude=0.0f;
extinction.forward(&(altAz[2]), &extinctionMagnitude altAz.normalize();
); core->getSkyDrawer()->getExtinction().forward(altAz,
&extinctionMagnitude);
// compute a simple factor from magnitude loss. // compute a simple factor from magnitude loss.
float extinctionFactor=pow(0.4f , extinctionMagnitud e); // drop of one magnitude: factor 2.5 or 40% float extinctionFactor=std::pow(0.4f , extinctionMag nitude); // drop of one magnitude: factor 2.5 or 40%
extinctedColor[0]*=fabs(extinctionFactor); extinctedColor[0]*=fabs(extinctionFactor);
extinctedColor[1]*=fabs(extinctionFactor); extinctedColor[1]*=fabs(extinctionFactor);
extinctedColor[2]*=fabs(extinctionFactor); extinctedColor[2]*=fabs(extinctionFactor);
} }
renderer->setGlobalColor(extinctedColor); sPainter.setColor(extinctedColor[0], extinctedColor[1], exti
// GZ: this was the original code now. nctedColor[2], extinctedColor[3]);
poly->drawFill(renderer, SphericalRegion::DrawParams(&(*proj sPainter.drawSphericalRegion(poly.data(), StelPainter::Spher
ector))); icalPolygonDrawModeTextureFill);
} }
#ifdef DEBUG_STELSKYIMAGE_TILE #ifdef DEBUG_STELSKYIMAGE_TILE
if (debugFont==NULL)
{
debugFont = &StelApp::getInstance().getFontManager().getStan
dardFont(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), 12);
}
color.set(1.0,0.5,0.5,1.0); color.set(1.0,0.5,0.5,1.0);
renderer->setGlobalColor(color);
foreach (const SphericalRegionP& poly, skyConvexPolygons) foreach (const SphericalRegionP& poly, skyConvexPolygons)
{ {
Vec3d win; Vec3d win;
Vec3d bary = poly->getPointInside(); Vec3d bary = poly->getPointInside();
projector->project(bary, win); sPainter.getProjector()->project(bary,win);
renderer->drawText(TextParams(win[0], win[1], getAbsoluteIma sPainter.drawText(debugFont, win[0], win[1], getAbsoluteImag
geURI())); eURI());
sPainter.enableTexture2d(false);
poly->drawOutline(renderer, SphericalRegion::DrawParams(&(*p sPainter.drawSphericalRegion(poly.get(), StelPainter::Spheri
rojector))); calPolygonDrawModeBoundary, &color);
sPainter.enableTexture2d(true);
} }
#endif #endif
if (!alphaBlend)
{
renderer->setBlendMode(BlendMode_Add); // Revert
}
return true; return true;
} }
// Return true if the tile is fully loaded and can be displayed // Return true if the tile is fully loaded and can be displayed
bool StelSkyImageTile::isReadyToDisplay() const bool StelSkyImageTile::isReadyToDisplay() const
{ {
return NULL != tex && tex->getStatus() == TextureStatus_Loaded; return tex && tex->canBind();
} }
// Load the tile from a valid QVariantMap // Load the tile from a valid QVariantMap
void StelSkyImageTile::loadFromQVariantMap(const QVariantMap& map) void StelSkyImageTile::loadFromQVariantMap(const QVariantMap& map)
{ {
if (map.contains("imageCredits")) if (map.contains("imageCredits"))
{ {
QVariantMap dsCredits = map.value("imageCredits").toMap(); QVariantMap dsCredits = map.value("imageCredits").toMap();
dataSetCredits.shortCredits = dsCredits.value("short").toStr ing(); dataSetCredits.shortCredits = dsCredits.value("short").toStr ing();
dataSetCredits.fullCredits = dsCredits.value("full").toStrin g(); dataSetCredits.fullCredits = dsCredits.value("full").toStrin g();
skipping to change at line 386 skipping to change at line 373
if (map.contains("luminance")) if (map.contains("luminance"))
{ {
luminance = map.value("luminance").toFloat(&ok); luminance = map.value("luminance").toFloat(&ok);
if (!ok) if (!ok)
throw std::runtime_error("luminance expect a float v alue"); throw std::runtime_error("luminance expect a float v alue");
qWarning() << "luminance in preview JSON files is deprecated . Replace with maxBrightness."; qWarning() << "luminance in preview JSON files is deprecated . Replace with maxBrightness.";
} }
if (map.contains("maxBrightness")) if (map.contains("maxBrightness"))
{ {
// maxBrightness is the maximum nebula brightness in Vmag/ar cmin^2
luminance = map.value("maxBrightness").toFloat(&ok); luminance = map.value("maxBrightness").toFloat(&ok);
if (!ok) if (!ok)
throw std::runtime_error("maxBrightness expect a flo at value"); throw std::runtime_error("maxBrightness expect a flo at value");
luminance = StelApp::getInstance().getCore()->getSkyDrawer() ->surfacebrightnessToLuminance(luminance); luminance = StelApp::getInstance().getCore()->getSkyDrawer() ->surfacebrightnessToLuminance(luminance);
} }
if (map.contains("alphaBlend")) if (map.contains("alphaBlend"))
{ {
alphaBlend = map.value("alphaBlend").toBool(); alphaBlend = map.value("alphaBlend").toBool();
} }
skipping to change at line 458 skipping to change at line 446
if (map.contains("imageUrl")) if (map.contains("imageUrl"))
{ {
QString imageUrl = map.value("imageUrl").toString(); QString imageUrl = map.value("imageUrl").toString();
if (baseUrl.startsWith("http://")) if (baseUrl.startsWith("http://"))
{ {
absoluteImageURI = baseUrl+imageUrl; absoluteImageURI = baseUrl+imageUrl;
} }
else else
{ {
try absoluteImageURI = StelFileMgr::findFile(baseUrl+ima
{ geUrl);
absoluteImageURI = StelFileMgr::findFile(bas if (absoluteImageURI.isEmpty())
eUrl+imageUrl);
}
catch (std::runtime_error& er)
{ {
// Maybe the user meant a file in stellarium local files // Maybe the user meant a file in stellarium local files
absoluteImageURI = imageUrl; absoluteImageURI = imageUrl;
} }
} }
} }
else else
noTexture = true; noTexture = true;
// This is a list of URLs to the child tiles or a list of already lo aded map containing child information // This is a list of URLs to the child tiles or a list of already lo aded map containing child information
 End of changes. 36 change blocks. 
82 lines changed or deleted 72 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/