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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 
00029 class QMutex;
00030 class QSemaphore;
00031 class QFile;
00032 
00033 #ifndef GL_CLAMP_TO_EDGE
00034 #define GL_CLAMP_TO_EDGE 0x812F
00035 #endif
00036 
00040 class StelTexture : public QObject
00041 {
00042     Q_OBJECT
00043 
00044 public:
00046     struct StelTextureParams
00047     {
00048         StelTextureParams(bool qgenerateMipmaps=false, GLint afiltering=GL_LINEAR, GLint awrapMode=GL_CLAMP_TO_EDGE) :
00049                 generateMipmaps(qgenerateMipmaps),
00050                 filtering(afiltering),
00051                 wrapMode(awrapMode) {;}
00053         bool generateMipmaps;
00055         GLint filtering;
00057         GLint wrapMode;
00058     };
00059 
00061     virtual ~StelTexture();
00062 
00066     bool bind();
00067 
00069     bool canBind() const {return id!=0;}
00070 
00072     bool getDimensions(int &width, int &height);
00073 
00076     const QString& getErrorMessage() const {return errorMessage;}
00077 
00080     const QString& getFullPath() const {return fullPath;}
00081 
00083     bool isLoading() const {return isLoadingImage && !canBind();}
00084 
00088     bool glLoad();
00089 
00090 signals:
00095     void loadingProcessFinished(bool error);
00096 
00097 private slots:
00099     void downloadFinished();
00100 
00102     void fileLoadFinished();
00103 
00104 private:
00105     friend class StelTextureMgr;
00106     friend class ImageLoadThread;
00107 
00109     StelTexture();
00110 
00114     bool imageLoad();
00115 
00118     void reportError(const QString& errorMessage);
00119 
00120     StelTextureParams loadParams;
00121 
00123     class QNetworkReply* httpReply;
00124 
00126     class ImageLoadThread* loadThread;
00127 
00129     bool downloaded;
00131     bool isLoadingImage;
00132 
00134     QString fullPath;
00135 
00137     QByteArray downloadedData;
00138     QImage qImage;
00139 
00141     QString fileExtension;
00142 
00144     bool errorOccured;
00145 
00147     QString errorMessage;
00148 
00150     GLuint id;
00151 
00153     // Attributes protected by the Mutex
00155     QMutex* mutex;
00156 
00158     float avgLuminance;
00159 
00160     GLsizei width;  
00161     GLsizei height; 
00162 
00164     static QSemaphore* maxLoadThreadSemaphore;
00165 };
00166 
00167 
00168 #endif // _STELTEXTURE_HPP_

Generated on Mon Mar 22 09:55:38 2010 for Stellarium by  doxygen 1.5.5