00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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_