Home · All Namespaces · All Classes · Functions · Coding Style · Plugins · File Structure

core/StelTextureMgr.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 _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_

Generated on Mon Feb 2 17:23:47 2009 for Stellarium by  doxygen 1.5.5