Stellarium 0.11.2
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 
00029 class QFile;
00030 class StelTextureMgr;
00031 class QNetworkReply;
00032 
00033 #ifndef GL_CLAMP_TO_EDGE
00034 #define GL_CLAMP_TO_EDGE 0x812F
00035 #endif
00036 
00037 // This class is just used internally to load the texture data.
00038 class ImageLoader : QObject
00039 {
00040     Q_OBJECT
00041 
00042 private:
00043     friend class StelTextureMgr;
00044     friend class StelTexture;
00045 
00046     ImageLoader(const QString& path, int delay);
00047     void abort();
00048 
00049 signals:
00050     void finished(QImage);
00051     void error(const QString& errorMsg);
00052 
00053 public slots:
00054     void start();
00055 
00056 private slots:
00057     void onNetworkReply();
00058     void directLoad();
00059 
00060 private:
00061     QString path;
00062     QNetworkReply* networkReply;
00063 };
00064 
00068 class StelTexture : public QObject
00069 {
00070     Q_OBJECT
00071 
00072 public:
00074     struct StelTextureParams
00075     {
00076         StelTextureParams(bool qgenerateMipmaps=false, GLint afiltering=GL_LINEAR, GLint awrapMode=GL_CLAMP_TO_EDGE) :
00077                 generateMipmaps(qgenerateMipmaps),
00078                 filtering(afiltering),
00079                 wrapMode(awrapMode) {;}
00081         bool generateMipmaps;
00083         GLint filtering;
00085         GLint wrapMode;
00086     };
00087 
00089     virtual ~StelTexture();
00090 
00094     bool bind();
00095 
00097     bool canBind() const {return id!=0;}
00098 
00100     bool getDimensions(int &width, int &height);
00101 
00104     const QString& getErrorMessage() const {return errorMessage;}
00105 
00108     const QString& getFullPath() const {return fullPath;}
00109 
00111     bool isLoading() const {return isLoadingImage && !canBind();}
00112 
00116     bool glLoad();
00117 
00118 signals:
00123     void loadingProcessFinished(bool error);
00124 
00125 private slots:
00127     void onImageLoaded(QImage image);
00129     void onLoadingError(const QString& errorMessage) {reportError(errorMessage);}
00130 
00131 private:
00132     friend class StelTextureMgr;
00133     friend class TextureLoader;
00134 
00136     StelTexture();
00137 
00140     void reportError(const QString& errorMessage);
00141 
00142     StelTextureParams loadParams;
00143 
00145     ImageLoader* loader;
00146 
00148     bool downloaded;
00150     bool isLoadingImage;
00151 
00153     QString fullPath;
00154 
00156     QImage qImage;
00157 
00159     QString fileExtension;
00160 
00162     bool errorOccured;
00163 
00165     QString errorMessage;
00166 
00168     GLuint id;
00169 
00171     float avgLuminance;
00172 
00173     GLsizei width;  
00174     GLsizei height; 
00175 };
00176 
00177 
00178 #endif // _STELTEXTURE_HPP_