Stellarium 0.11.4
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

core/StelTexture.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2006 Fabien Chereau
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00018  */
00019 
00020 #ifndef _STELTEXTURE_HPP_
00021 #define _STELTEXTURE_HPP_
00022 
00023 #include "StelTextureTypes.hpp"
00024 
00025 #include <QObject>
00026 #include <QImage>
00027 #include <QtOpenGL>
00028 //FIXME: After fully migrate to Qt 4.8 this condition need drop
00029 #if QT_VERSION>=0x040800
00030 #include <QGLFunctions>
00031 #endif
00032 
00033 class QFile;
00034 class StelTextureMgr;
00035 class QNetworkReply;
00036 
00037 #ifndef GL_CLAMP_TO_EDGE
00038 #define GL_CLAMP_TO_EDGE 0x812F
00039 #endif
00040 
00041 // This class is just used internally to load the texture data.
00042 class ImageLoader : QObject
00043 {
00044     Q_OBJECT
00045 
00046 private:
00047     friend class StelTextureMgr;
00048     friend class StelTexture;
00049 
00050     ImageLoader(const QString& path, int delay);
00051     void abort();
00052 
00053 signals:
00054     void finished(QImage);
00055     void error(const QString& errorMsg);
00056 
00057 public slots:
00058     void start();
00059 
00060 private slots:
00061     void onNetworkReply();
00062     void directLoad();
00063 
00064 private:
00065     QString path;
00066     QNetworkReply* networkReply;
00067 };
00068 
00072 class StelTexture
00073 //FIXME: After fully migrate to Qt 4.8 this condition need drop
00074 #if QT_VERSION>=0x040800
00075         : public QObject, protected QGLFunctions
00076 #else
00077         : public QObject
00078 #endif
00079 {
00080     Q_OBJECT
00081 
00082 public:
00084     struct StelTextureParams
00085     {
00086         StelTextureParams(bool qgenerateMipmaps=false, GLint afiltering=GL_LINEAR, GLint awrapMode=GL_CLAMP_TO_EDGE) :
00087                 generateMipmaps(qgenerateMipmaps),
00088                 filtering(afiltering),
00089                 wrapMode(awrapMode) {;}
00091         bool generateMipmaps;
00093         GLint filtering;
00095         GLint wrapMode;
00096     };
00097 
00099     virtual ~StelTexture();
00100 
00104     
00105     bool bind();
00106 
00108     bool canBind() const {return id!=0;}
00109 
00111     bool getDimensions(int &width, int &height);
00112 
00115     const QString& getErrorMessage() const {return errorMessage;}
00116 
00119     const QString& getFullPath() const {return fullPath;}
00120 
00122     bool isLoading() const {return isLoadingImage && !canBind();}
00123 
00127     bool glLoad();
00128 
00129 signals:
00134     void loadingProcessFinished(bool error);
00135 
00136 private slots:
00138     void onImageLoaded(QImage image);
00140     void onLoadingError(const QString& errorMessage) {reportError(errorMessage);}
00141 
00142 private:
00143     friend class StelTextureMgr;
00144     friend class TextureLoader;
00145 
00147     StelTexture();
00148 
00151     void reportError(const QString& errorMessage);
00152 
00153     StelTextureParams loadParams;
00154 
00156     ImageLoader* loader;
00157 
00159     bool downloaded;
00161     bool isLoadingImage;
00162 
00164     QString fullPath;
00165 
00167     QImage qImage;
00168 
00170     QString fileExtension;
00171 
00173     bool errorOccured;
00174 
00176     QString errorMessage;
00177 
00179     GLuint id;
00180 
00182     float avgLuminance;
00183 
00184     GLsizei width;  
00185     GLsizei height; 
00186 };
00187 
00188 
00189 #endif // _STELTEXTURE_HPP_
Generated on Sat Aug 25 22:13:30 2012 for Stellarium by  doxygen 1.6.3