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 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
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_