00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _STELTEXTUREMGR_HPP_
00021 #define _STELTEXTUREMGR_HPP_
00022
00023 #include <config.h>
00024 #include "GLee.h"
00025 #include "fixx11h.h"
00026
00027 #include <QObject>
00028 #include <QMap>
00029 #include <QMutex>
00030
00031 #include "StelTexture.hpp"
00032
00035 class ImageLoader
00036 {
00037 public:
00038 struct TexInfo
00039 {
00040 GLsizei width;
00041 GLsizei height;
00042 GLenum format;
00043 GLint internalFormat;
00044 GLubyte* texels;
00045 GLenum type;
00046 QString fullPath;
00047 };
00048
00049 virtual ~ImageLoader() {;}
00053 virtual bool loadImage(const QString& filename, TexInfo& texInfo) = 0;
00054 };
00055
00058 class PngLoader : public ImageLoader
00059 {
00060 virtual bool loadImage(const QString& filename, TexInfo& texinfo);
00061 };
00062
00065 class JpgLoader : public ImageLoader
00066 {
00067 virtual bool loadImage(const QString& filename, TexInfo& texinfo);
00068 public:
00074 static bool loadFromMemory(const QByteArray& data, TexInfo& texinfo);
00075 };
00076
00083 class StelTextureMgr : QObject
00084 {
00085 public:
00086 StelTextureMgr();
00087 virtual ~StelTextureMgr();
00088
00091 void init();
00092
00096 StelTextureSP createTexture(const QString& filename);
00097
00103 StelTextureSP createTextureThread(const QString& url, const QString& fileExtension="", bool lazyLoading=true);
00104
00106 void setMipmapsMode(bool b = false) {mipmapsMode = b;}
00107
00111 void setWrapMode(GLint m = GL_CLAMP) {wrapMode = m;}
00112
00117 void setMinFilter(GLint m = GL_NEAREST) {minFilter = m;}
00118
00122 void setMagFilter(GLint m = GL_LINEAR) {magFilter = m;}
00123
00125 void setDefaultParams();
00126
00129 void setDynamicRangeMode(StelTextureTypes::DynamicRangeMode dMode = StelTextureTypes::Linear) {dynamicRangeMode = dMode;}
00130
00132 void registerImageLoader(const QString& fileExtension, ImageLoader* loader)
00133 {
00134 imageLoaders[fileExtension] = loader;
00135 }
00136
00137 private:
00138 friend class StelTexture;
00139
00141 StelTextureSP initTex();
00142
00144 bool loadImage(StelTexture* tex);
00145
00147 bool reScale(StelTexture* tex);
00148
00150 QMap<QString, ImageLoader*> imageLoaders;
00151
00152 bool mipmapsMode;
00153 GLint wrapMode;
00154 GLint minFilter;
00155 GLint magFilter;
00156 StelTextureTypes::DynamicRangeMode dynamicRangeMode;
00157
00159 GLint maxTextureSize;
00160
00162 bool isNoPowerOfTwoAllowed;
00163 };
00164
00167 class TexMalloc
00168 {
00169 public:
00171 static void* malloc(size_t size);
00173 static void free(void *ptr);
00175 static void clear();
00176 private:
00178 static QMultiMap<size_t, void*> cache;
00180 static QMap<void*, size_t> newInsert;
00182 static QMutex mutex;
00183 };
00184
00185 #endif // _STELTEXTUREMGR_HPP_