StelQGLRenderer.cpp   StelQGLRenderer.cpp 
skipping to change at line 22 skipping to change at line 22
* 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 <cmath> #include <cmath>
#ifdef _MSC_BUILD
#define round(dbl) dbl >= 0.0 ? (int)(dbl + 0.5) : ((dbl - (double)(int)dbl
) <= -0.5 ? (int)dbl : (int)(dbl - 0.5))
#endif
#include "StelQGLRenderer.hpp" #include "StelQGLRenderer.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "QSettings" #include "QSettings"
void StelQGLRenderer::bindTextureBackend void StelQGLRenderer::bindTextureBackend
(StelTextureBackend* const textureBackend, const int textureUnit) (StelTextureBackend* const textureBackend, const int textureUnit)
{ {
invariant(); invariant();
StelQGLTextureBackend* qglTextureBackend = StelQGLTextureBackend* qglTextureBackend =
dynamic_cast<StelQGLTextureBackend*>(textureBackend); dynamic_cast<StelQGLTextureBackend*>(textureBackend);
skipping to change at line 60 skipping to change at line 64
{ {
if(currentlyBoundTextures[textureUnit] != qglTextureBackend) if(currentlyBoundTextures[textureUnit] != qglTextureBackend)
{ {
qglTextureBackend->bind(textureUnit); qglTextureBackend->bind(textureUnit);
currentlyBoundTextures[textureUnit] = qglTextureBack end; currentlyBoundTextures[textureUnit] = qglTextureBack end;
} }
} }
else else
{ {
// by default placeholder is hide but its can be enabled for debugging // by default placeholder is hide but its can be enabled for debugging
bool debugMode = false;
if (conf->value("debug/texture_placeholder_flag", false).toB ool()) if (conf->value("debug/texture_placeholder_flag", false).toB ool())
{ debugMode = true;
getPlaceholderTexture()->bind(textureUnit);
currentlyBoundTextures[textureUnit] = getPlaceholder getPlaceholderTexture(debugMode)->bind(textureUnit);
Texture(); currentlyBoundTextures[textureUnit] = getPlaceholderTexture(
} debugMode);
} }
invariant(); invariant();
} }
void StelQGLRenderer::destroyTextureBackend(StelTextureBackend* const textu reBackend) void StelQGLRenderer::destroyTextureBackend(StelTextureBackend* const textu reBackend)
{ {
invariant(); invariant();
StelQGLTextureBackend* qglTextureBackend = StelQGLTextureBackend* qglTextureBackend =
dynamic_cast<StelQGLTextureBackend*>(textureBackend); dynamic_cast<StelQGLTextureBackend*>(textureBackend);
Q_ASSERT_X(qglTextureBackend != NULL, Q_FUNC_INFO, Q_ASSERT_X(qglTextureBackend != NULL, Q_FUNC_INFO,
skipping to change at line 100 skipping to change at line 106
invariant(); invariant();
const QString fullPath = filename.startsWith("http://") const QString fullPath = filename.startsWith("http://")
? filename ? filename
: glFileSystemTexturePath(filename, pvrSupported); : glFileSystemTexturePath(filename, pvrSupported);
if(fullPath.isEmpty()) if(fullPath.isEmpty())
{ {
QImage image; QImage image;
// Texture in error state will be returned (loaded from NULL image), and // Texture in error state will be returned (loaded from NULL image), and
// when bound, the placeholder texture will be used. // when bound, the placeholder texture will be used.
qWarning() << "createTextureBackend failed: file \"" << file name << "\" not found."; qWarning() << "createTextureBackend failed: file \"" << QDir ::toNativeSeparators(filename) << "\" not found.";
return StelQGLTextureBackend::constructFromImage(this, QStri ng(), params, image); return StelQGLTextureBackend::constructFromImage(this, QStri ng(), params, image);
} }
StelQGLTextureBackend* cached = textureCache.get(fullPath, loadingMo de); StelQGLTextureBackend* cached = textureCache.get(fullPath, loadingMo de);
if(NULL != cached) if(NULL != cached)
{ {
invariant(); invariant();
return cached; return cached;
} }
skipping to change at line 123 skipping to change at line 129
if(loadingMode == TextureLoadingMode_Normal) if(loadingMode == TextureLoadingMode_Normal)
{ {
//Load from a normal image. //Load from a normal image.
if(!fullPath.endsWith(".pvr")) if(!fullPath.endsWith(".pvr"))
{ {
QImage image = QImage(fullPath); QImage image = QImage(fullPath);
if(image.isNull()) if(image.isNull())
{ {
// Texture in error state will be returned ( loaded from NULL image), and // Texture in error state will be returned ( loaded from NULL image), and
// when bound, the placeholder texture will be used. // when bound, the placeholder texture will be used.
qWarning() << "createTextureBackend failed: found image file \"" << fullPath qWarning() << "createTextureBackend failed: found image file \"" << QDir::toNativeSeparators(fullPath)
<< "\" but failed to load image d ata. "; << "\" but failed to load image d ata. ";
} }
//Uploads to GL //Uploads to GL
result = StelQGLTextureBackend::constructFromImage(t his, fullPath, params, image); result = StelQGLTextureBackend::constructFromImage(t his, fullPath, params, image);
} }
//Load from PVR (compressed textures on PowerVR (mobile)). //Load from PVR (compressed textures on PowerVR (mobile)).
else else
{ {
result = StelQGLTextureBackend::constructFromPVR(thi s, fullPath, params); result = StelQGLTextureBackend::constructFromPVR(thi s, fullPath, params);
} }
skipping to change at line 340 skipping to change at line 346
if(params.doNotProject_) if(params.doNotProject_)
{ {
win = params.position_; win = params.position_;
} }
else if(!projector->project(params.position_, win)) else if(!projector->project(params.position_, win))
{ {
viewport.disablePainting(); viewport.disablePainting();
return; return;
} }
const int x = win[0]; const int x = round(win[0]);
const int y = win[1]; const int y = round(win[1]);
// Avoid drawing if outside viewport. // Avoid drawing if outside viewport.
// We do a worst-case approximation as getting exact text dimensions is expensive. // We do a worst-case approximation as getting exact text dimensions is expensive.
// We also account for rotation by assuming the worst case in bot X and Y // We also account for rotation by assuming the worst case in bot X and Y
// (culling with a rotating rectangle would be expensive) // (culling with a rotating rectangle would be expensive)
const int cullDistance = const int cullDistance =
std::max(fontMetrics.height(), params.string_.size() * fontM etrics.maxWidth()); std::max(fontMetrics.height(), params.string_.size() * fontM etrics.maxWidth());
const Vec4i viewXywh = projector->getViewportXywh(); const Vec4i viewXywh = projector->getViewportXywh();
const int viewMinX = viewXywh[0]; const int viewMinX = viewXywh[0];
const int viewMinY = viewXywh[1]; const int viewMinY = viewXywh[1];
skipping to change at line 412 skipping to change at line 418
// The second argument ensures the text is positioned correc tly even if // The second argument ensures the text is positioned correc tly even if
// the image is enlarged to power-of-two. // the image is enlarged to power-of-two.
fontPainter.drawText(-extents.x(), fontPainter.drawText(-extents.x(),
image.height() - requiredHeight - exten ts.y(), image.height() - requiredHeight - exten ts.y(),
params.string_); params.string_);
textTexture = StelQGLTextureBackend::constructFromImage textTexture = StelQGLTextureBackend::constructFromImage
(this, QString(), TextureParams().filtering(TextureF iltering_Linear), image); (this, QString(), TextureParams().filtering(TextureF iltering_Linear), image);
const QSize size = textTexture->getDimensions(); const QSize size = textTexture->getDimensions();
if(!textTexture->getStatus() == TextureStatus_Loaded) if (!(textTexture->getStatus() == TextureStatus_Loaded))
{ {
qWarning() << "Texture error: " << textTexture->getE rrorMessage(); qWarning() << "Texture error: " << textTexture->getE rrorMessage();
Q_ASSERT_X(false, Q_FUNC_INFO, "Failed to construct a text texture"); Q_ASSERT_X(false, Q_FUNC_INFO, "Failed to construct a text texture");
} }
textTextureCache.insert(hash, textTexture, 4 * size.width() * size.height()); textTextureCache.insert(hash, textTexture, 4 * size.width() * size.height());
} }
// Even if NPOT textures are not supported, we always draw the full rectangle // Even if NPOT textures are not supported, we always draw the full rectangle
// of the texture. The extra space is fully transparent, so it's not an issue. // of the texture. The extra space is fully transparent, so it's not an issue.
 End of changes. 7 change blocks. 
10 lines changed or deleted 17 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/