StelTextureMgr.hpp   StelTextureMgr.hpp 
skipping to change at line 24 skipping to change at line 24
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#ifndef _STELTEXTUREMGR_HPP_ #ifndef _STELTEXTUREMGR_HPP_
#define _STELTEXTUREMGR_HPP_ #define _STELTEXTUREMGR_HPP_
#include <config.h> #include <config.h>
#include "GLee.h"
#include "fixx11h.h"
#include <QObject>
#include <QMap>
#include <QMutex>
#include <QtOpenGL>
#include "StelTexture.hpp" #include "StelTexture.hpp"
#include <QObject>
//! @class ImageLoader
//! Abstract class for any Image loaders.
class ImageLoader
{
public:
struct TexInfo
{
GLsizei width; //! Texture image width
GLsizei height; //! Texture image height
GLenum format;
GLint internalFormat;
GLubyte* texels;
GLenum type;
QString fullPath;
};
virtual ~ImageLoader() {;}
//! Load the data from the image and store it into tex.texels
//! The caller is responsible for freeing the memory allocated in te
x.texels
//! This method must be thread compliant
virtual bool loadImage(const QString& filename, TexInfo& texInfo) =
0;
};
//! @class PngLoader
//! Define a PNG loader. This implementation supports LUMINANCE, LUMINANCE+
ALPHA, RGB, RGBA.
class PngLoader : public ImageLoader
{
virtual bool loadImage(const QString& filename, TexInfo& texinfo);
};
//! @class JpgLoader
//! Define a JPG loader. This implementation supports LUMINANCE or RGB.
class JpgLoader : public ImageLoader
{
virtual bool loadImage(const QString& filename, TexInfo& texinfo);
public:
//! Load the jpeg data from a buffer already in memory.
//! The implementation doesn't use the Qt loading for performances r
easons.
//! @param data the array containing the raw compressed image bytes
//! @param texinfo the texinfo to generate
//! @return false in case of loading error
static bool loadFromMemory(const QByteArray& data, TexInfo& texinfo)
;
};
//! @class StelTextureMgr //! @class StelTextureMgr
//! Manage textures loading and manipulation. //! Manage textures loading.
//! The texture loader has a current state defining the way the textures wi //! It provides method for loading images in a separate thread.
ll be loaded in memory,
//! that is, whether mimap should be generated, the wrap mode or mag and mi
n filters.
//! The state should be reinitialized by calling the StelTextureMgr::setDef
aultParams method before any texture loading.
//! It provides function for loading images in a separate threads.
class StelTextureMgr : QObject class StelTextureMgr : QObject
{ {
public: public:
StelTextureMgr(); StelTextureMgr();
virtual ~StelTextureMgr(); virtual ~StelTextureMgr();
//! Initialize some variable from the openGL contex. //! Initialize some variable from the openGL contex.
//! Must be called after the creation of the GLContext. //! Must be called after the creation of the GLContext.
void init(); void init();
//! Load an image from a file and create a new texture from it //! Load an image from a file and create a new texture from it
//! @param filename the texture file name, can be absolute path if s tarts with '/' otherwise //! @param filename the texture file name, can be absolute path if s tarts with '/' otherwise
//! the file will be looked in stellarium standard textures direc tories. //! the file will be looked in stellarium standard textures direc tories.
StelTextureSP createTexture(const QString& filename); StelTextureSP createTexture(const QString& filename, const StelTextu re::StelTextureParams& params=StelTexture::StelTextureParams());
//! Load an image from a file and create a new texture from it in a new thread. //! Load an image from a file and create a new texture from it in a new thread.
//! @param url the texture file name or URL, can be absolute path if starts with '/' otherwise //! @param url the texture file name or URL, can be absolute path if starts with '/' otherwise
//! the file will be looked in stellarium standard textures direc tories. //! the file will be looked in stellarium standard textures direc tories.
//! @param fileExtension the file extension to assume. If not set th e extension is determined from url //! @param fileExtension the file extension to assume. If not set th e extension is determined from url
//! @param lazyLoading define whether the texture should be actually loaded only when needed, i.e. when bind() is called the first time. //! @param lazyLoading define whether the texture should be actually loaded only when needed, i.e. when bind() is called the first time.
StelTextureSP createTextureThread(const QString& url, const QString& StelTextureSP createTextureThread(const QString& url, const StelText
fileExtension="", bool lazyLoading=true); ure::StelTextureParams& params=StelTexture::StelTextureParams(), const QStr
ing& fileExtension=QString(), bool lazyLoading=true);
//! Define if mipmaps must be created while creating textures
void setMipmapsMode(bool b = false) {mipmapsMode = b;}
//! Define the texture wrapping mode to use while creating textures
//! @param m can be either GL_CLAMP, GL_CLAMP_TO_EDGE, or GL_REPEAT.
//! See doc for glTexParameter for more info.
void setWrapMode(GLint m = GL_CLAMP) {wrapMode = m;}
//! Define the texture min filter to use while creating textures
//! @param m can be either GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_
NEAREST,
//! GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MI
PMAP_LINEAR
//! See doc for glTexParameter for more info.
void setMinFilter(GLint m = GL_NEAREST) {minFilter = m;}
//! Define the texture magnification filter to use while creating te
xtures
//! @param m can be either GL_NEAREST, GL_LINEAR
//! See doc for glTexParameter for more info.
void setMagFilter(GLint m = GL_LINEAR) {magFilter = m;}
//! Set default parameters for Mipmap mode, wrap mode, min and mag f
ilters
void setDefaultParams();
//! Define how the dynamic range of the image will be adapted to fit
on 8 bits
//! Note that using linear mode on 8 bits images does nothing
void setDynamicRangeMode(StelTextureTypes::DynamicRangeMode dMode =
StelTextureTypes::Linear) {dynamicRangeMode = dMode;}
//! Register a new image loader for a given image file extension
void registerImageLoader(const QString& fileExtension, ImageLoader*
loader)
{
imageLoaders[fileExtension] = loader;
}
private: private:
friend class StelTexture; friend class StelTexture;
//! Internal
StelTextureSP initTex();
//! Load the image memory
bool loadImage(StelTexture* tex);
//! Adapt the scaling for the texture. Return true if there was no e
rrors
bool reScale(StelTexture* tex);
//! List of image loaders providing image loading for the given file
s extensions
QMap<QString, ImageLoader*> imageLoaders;
bool mipmapsMode;
GLint wrapMode;
GLint minFilter;
GLint magFilter;
StelTextureTypes::DynamicRangeMode dynamicRangeMode;
//! The maximum texture size supported by the video card
GLint maxTextureSize;
//! Whether ARB_texture_non_power_of_two is supported on this card //! Whether ARB_texture_non_power_of_two is supported on this card
bool isNoPowerOfTwoAllowed; bool isNoPowerOfTwoAllowed;
}; };
//! @class TexMalloc
//! A special multithreaded malloc which manages a memory pool to reuse the
memory already allocated for loading previous textures.
class TexMalloc
{
public:
//! Equivalent to standard C malloc function
static void* malloc(size_t size);
//! Equivalent to standard C free function
static void free(void *ptr);
//! Clear the cache and release all memory
static void clear();
private:
//! Cache memory block size/pointer
static QMultiMap<size_t, void*> cache;
//! Reversed cache, gives the size of an allocated memory block
static QMap<void*, size_t> newInsert;
//! Used for thread safety
static QMutex mutex;
};
#endif // _STELTEXTUREMGR_HPP_ #endif // _STELTEXTUREMGR_HPP_
 End of changes. 8 change blocks. 
149 lines changed or deleted 8 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/