StelTexture.hpp   StelTexture.hpp 
skipping to change at line 23 skipping to change at line 23
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* 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 _STELTEXTURE_HPP_ #ifndef _STELTEXTURE_HPP_
#define _STELTEXTURE_HPP_ #define _STELTEXTURE_HPP_
#include "GLee.h"
#include "fixx11h.h"
#include "VecMath.hpp"
#include "StelTextureTypes.hpp" #include "StelTextureTypes.hpp"
#include <QObject> #include <QObject>
#include <QImage> #include <QImage>
#include <QtOpenGL>
class QMutex; class QMutex;
class QSemaphore; class QSemaphore;
class QFile; class QFile;
#ifndef GL_CLAMP_TO_EDGE
#define GL_CLAMP_TO_EDGE 0x812F
#endif
//! @class StelTexture //! @class StelTexture
//! Base texture class. For creating an instance, use StelTextureMgr::creat eTexture() and StelTextureMgr::createTextureThread() //! Base texture class. For creating an instance, use StelTextureMgr::creat eTexture() and StelTextureMgr::createTextureThread()
//! @sa StelTextureSP //! @sa StelTextureSP
class StelTexture : public QObject class StelTexture : public QObject
{ {
Q_OBJECT Q_OBJECT
friend class StelTextureMgr;
friend class ImageLoadThread;
public: public:
//! Contains the parameters defining how a texture is created.
struct StelTextureParams
{
StelTextureParams(bool qgenerateMipmaps=false, GLint afilter
ing=GL_LINEAR, GLint awrapMode=GL_CLAMP_TO_EDGE) :
generateMipmaps(qgenerateMipmaps),
filtering(afiltering),
wrapMode(awrapMode) {;}
//! Define if mipmaps must be created.
bool generateMipmaps;
//! Define the scaling filter to use. Must be one of GL_NEAR
EST or GL_LINEAR
GLint filtering;
//! Define the wrapping mode to use. Must be one of GL_CLAMP
_TO_EDGE, or GL_REPEAT.
GLint wrapMode;
};
//! Destructor //! Destructor
virtual ~StelTexture(); virtual ~StelTexture();
//! Bind the texture so that it can be used for openGL drawing (call s glBindTexture). //! Bind the texture so that it can be used for openGL drawing (call s glBindTexture).
//! If the texture is lazyly loaded, this starts the loading and ret urn false immediately. //! If the texture is lazyly loaded, this starts the loading and ret urn false immediately.
//! @return true if the binding successfully occured, false if the t exture is not yet loaded. //! @return true if the binding successfully occured, false if the t exture is not yet loaded.
bool bind(); bool bind();
//! Return whether the texture can be binded, i.e. it is fully loade d //! Return whether the texture can be binded, i.e. it is fully loade d
bool canBind() const {return id!=0;} bool canBind() const {return id!=0;}
//! Get the average texture luminance.
//! @param lum 0 is black, 1 is white
//! @return true if the returned luminance is known, false if not. I
n this later case, the value of num is undefined.
bool getAverageLuminance(float& lum);
//! Return the width and heigth of the texture in pixels //! Return the width and heigth of the texture in pixels
bool getDimensions(int &width, int &height); bool getDimensions(int &width, int &height);
//! Return the position of the 4 corners of the texture in texture c
oordinates
const Vec2d* getCoordinates() const {return texCoordinates;}
//! Get the error message which caused the texture loading to fail //! Get the error message which caused the texture loading to fail
//! @return the human friendly error message or empty string if no e rrors occured //! @return the human friendly error message or empty string if no e rrors occured
const QString& getErrorMessage() const {return errorMessage;} const QString& getErrorMessage() const {return errorMessage;}
//! Return the full path to the image file. //! Return the full path to the image file.
//! If the texture was downloaded from a remote location, this funct ion return the full URL. //! If the texture was downloaded from a remote location, this funct ion return the full URL.
const QString& getFullPath() const {return fullPath;} const QString& getFullPath() const {return fullPath;}
//! Return whether the image is currently being loaded //! Return whether the image is currently being loaded
bool isLoading() const {return isLoadingImage && !canBind();} bool isLoading() const {return isLoadingImage && !canBind();}
//! Load the texture already in the RAM to the openGL memory
//! This function uses openGL routines and must be called in the mai
n thread
//! @return false if an error occured
bool glLoad();
signals: signals:
//! Emitted when the texture is ready to be bind(), i.e. when downlo aded, imageLoading and glLoading is over //! Emitted when the texture is ready to be bind(), i.e. when downlo aded, imageLoading and glLoading is over
//! or when an error occured and the texture will never be available //! or when an error occured and the texture will never be available
//! In case of error, you can query what the problem was by calling getErrorMessage() //! In case of error, you can query what the problem was by calling getErrorMessage()
//! @param error is equal to true if an error occured while loading the texture //! @param error is equal to true if an error occured while loading the texture
void loadingProcessFinished(bool error); void loadingProcessFinished(bool error);
private slots: private slots:
//! Called when the download for the texture file terminated //! Called when the download for the texture file terminated
void downloadFinished(); void downloadFinished();
//! Called when the file loading thread has terminated //! Called when the file loading thread has terminated
void fileLoadFinished(); void fileLoadFinished();
private: private:
friend class StelTextureMgr;
friend class ImageLoadThread;
//! Private constructor //! Private constructor
StelTexture(); StelTexture();
//! Load the texture already in the RAM to the openGL memory
//! This function uses openGL routines and must be called in the mai
n thread
//! @return false if an error occured
bool glLoad();
//! Loading of the image data. //! Loading of the image data.
//! This method is thread safe //! This method is thread safe
//! @return false if an error occured //! @return false if an error occured
bool imageLoad(); bool imageLoad();
//! This method should be called if the texture loading failed for a ny reasons //! This method should be called if the texture loading failed for a ny reasons
//! @param errorMessage the human friendly error message //! @param errorMessage the human friendly error message
void reportError(const QString& errorMessage); void reportError(const QString& errorMessage);
//! Define the range mode used to rescale the texture when loading StelTextureParams loadParams;
StelTextureTypes::DynamicRangeMode dynamicRangeMode;
//! Used to download remote files if needed //! Used to download remote files if needed
class QNetworkReply* httpReply; class QNetworkReply* httpReply;
//! Used to load in thread //! Used to load in thread
class ImageLoadThread* loadThread; class ImageLoadThread* loadThread;
//! Define if the texture was already downloaded if it was a remote one //! Define if the texture was already downloaded if it was a remote one
bool downloaded; bool downloaded;
//! Define whether the image is already loading //! Define whether the image is already loading
bool isLoadingImage; bool isLoadingImage;
//! The URL where to download the file //! The URL where to download the file
QString fullPath; QString fullPath;
//! The data that was laoded from http //! The data that was loaded from http
QByteArray downloadedData; QByteArray downloadedData;
QImage qImage; QImage qImage;
//! Used ony when creating temporary file //! Used ony when creating temporary file
QString fileExtension; QString fileExtension;
//! True when something when wrong in the loading process //! True when something when wrong in the loading process
bool errorOccured; bool errorOccured;
//! Human friendly error message if loading failed //! Human friendly error message if loading failed
QString errorMessage; QString errorMessage;
//! OpenGL id //! OpenGL id
GLuint id; GLuint id;
bool mipmapsMode;
GLint wrapMode;
GLint minFilter;
GLint magFilter;
//////////////////////////////////////////////////////////////////// /////// //////////////////////////////////////////////////////////////////// ///////
// Attributes protected by the Mutex // Attributes protected by the Mutex
//! Mutex used to protect all the attributes below //! Mutex used to protect all the attributes below
QMutex* mutex; QMutex* mutex;
//! Cached average luminance //! Cached average luminance
float avgLuminance; float avgLuminance;
GLsizei width; //! Texture image width GLsizei width; //! Texture image width
GLsizei height; //! Texture image height GLsizei height; //! Texture image height
GLenum format;
GLint internalFormat;
GLubyte* texels;
GLenum type;
//! Position of the 4 corners of the texture in texture coordinates
Vec2d texCoordinates[4];
//! Fix a limit to the number of maximum simultaneous loading thread s //! Fix a limit to the number of maximum simultaneous loading thread s
static QSemaphore* maxLoadThreadSemaphore; static QSemaphore* maxLoadThreadSemaphore;
}; };
#endif // _STELTEXTURE_HPP_ #endif // _STELTEXTURE_HPP_
 End of changes. 14 change blocks. 
36 lines changed or deleted 34 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/