StelSkyImageTile.cpp   StelSkyImageTile.cpp 
skipping to change at line 19 skipping to change at line 19
* 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.
*/ */
#include "StelTextureMgr.hpp"
#include "StelSkyImageTile.hpp" #include "StelSkyImageTile.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelTexture.hpp" #include "renderer/StelRenderer.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>
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) : MultiLevelJsonBase(parent) rent)
: 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 74 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, StelPainter& sPainter, float) void StelSkyImageTile::draw(StelCore* core, StelRenderer* renderer, StelPro jectorP projector, 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, prj->getViewportConvexPolygon(0, 0), li mitLuminance, true); getTilesToDraw(result, core, renderer, projector->getViewportConvexP olygon(0, 0), limitLuminance, 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 good order // Draw in the right 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, sPainter); i.value()->drawTile(core, renderer, projector);
} }
deleteUnusedSubTiles(); deleteUnusedSubTiles();
} }
// Return the list of tiles which should be drawn. // Return the list of tiles which should be drawn.
void StelSkyImageTile::getTilesToDraw(QMultiMap<double, StelSkyImageTile*>& void StelSkyImageTile::getTilesToDraw
result, StelCore* core, const SphericalRegionP& viewPortPoly, float limitL (QMultiMap<double, StelSkyImageTile*>& result, StelCore* core,
uminance, bool recheckIntersect) StelRenderer* renderer, const SphericalRegionP& viewPortPoly,
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 183 skipping to change at line 189
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 (!tex) if (NULL == 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
StelTextureMgr& texMgr=StelApp::getInstance().getTex tex = renderer->createTexture(absoluteImageURI, Text
tureManager(); ureParams().generateMipmaps(),
tex = texMgr.createTextureThread(absoluteImageURI, S TextureLoadingMode_Laz
telTexture::StelTextureParams(true)); yAsynchronous);
if (!tex) if (tex->getStatus() == TextureStatus_Error)
{ {
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 223 skipping to change at line 229
{ {
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, viewPortPoly, limitLuminance, !fullInScreen); qobject_cast<StelSkyImageTile*>(tile)->getTilesToDra w(result, core, renderer, 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.
// Assume GL_TEXTURE_2D is enabled bool StelSkyImageTile::drawTile(StelCore* core, StelRenderer* renderer, Ste
bool StelSkyImageTile::drawTile(StelCore* core, StelPainter& sPainter) lProjectorP projector)
{ {
if (!tex->bind()) tex->bind();
return false;
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 = (luminance>0) ? core->getToneReproducer()->adap const float ad_lum =
tLuminanceScaled(luminance) : 1.f; (luminance>0) ? core->getToneReproducer()->adaptLuminanceSca
led(luminance) : 1.f;
Vec4f color; Vec4f color;
if (alphaBlend==true || texFader->state()==QTimeLine::Running) if (alphaBlend==true || texFader->state()==QTimeLine::Running)
{ {
if (!alphaBlend) // This is a bit weird, but rewritten to mirror pre-refactor
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); / code
/ Normal transparency mode if(!alphaBlend)
glEnable(GL_BLEND); {
renderer->setBlendMode(BlendMode_Alpha);
}
else
{
renderer->setBlendMode(BlendMode_Add);
}
color.set(ad_lum,ad_lum,ad_lum, texFader->currentValue()); color.set(ad_lum,ad_lum,ad_lum, texFader->currentValue());
} }
else else
{ {
glDisable(GL_BLEND); renderer->setBlendMode(BlendMode_None);
color.set(ad_lum,ad_lum,ad_lum, 1.); color.set(ad_lum,ad_lum,ad_lum, 1.);
} }
sPainter.setColor(color[0], color[1], color[2], color[3]); color[0] = std::min(color[0], 1.0f);
sPainter.enableTexture2d(true); color[1] = std::min(color[1], 1.0f);
color[2] = std::min(color[2], 1.0f);
color[3] = std::min(color[3], 1.0f);
renderer->setGlobalColor(color);
foreach (const SphericalRegionP& poly, skyConvexPolygons) foreach (const SphericalRegionP& poly, skyConvexPolygons)
{ {
sPainter.drawSphericalRegion(poly.data(), StelPainter::Spher icalPolygonDrawModeTextureFill); poly->drawFill(renderer, SphericalRegion::DrawParams(&(*proj ector)));
} }
#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();
sPainter.getProjector()->project(bary,win); projector->project(bary, win);
sPainter.drawText(debugFont, win[0], win[1], getAbsoluteImag renderer->drawText(TextParams(win[0], win[1], getAbsoluteIma
eURI()); geURI()));
sPainter.enableTexture2d(false);
sPainter.drawSphericalRegion(poly.get(), StelPainter::Spheri poly->drawOutline(renderer, SphericalRegion::DrawParams(&(pr
calPolygonDrawModeBoundary, &color); ojector)));
sPainter.enableTexture2d(true);
} }
#endif #endif
if (!alphaBlend) if (!alphaBlend)
glBlendFunc(GL_ONE, GL_ONE); // Revert {
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 tex && tex->canBind(); return NULL != tex && tex->getStatus() == TextureStatus_Loaded;
} }
// 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();
 End of changes. 27 change blocks. 
52 lines changed or deleted 61 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/