3
* Copyright (C) 2006 Fabien Chereau
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#ifndef _STEXTURE_HPP_
21
#define _STEXTURE_HPP_
26
#include "STextureTypes.hpp"
36
//! Base texture class
37
class STexture : public QObject
41
friend class StelTextureMgr;
42
friend class ImageLoadThread;
48
//! Bind the texture so that it can be used for openGL drawing (calls glBindTexture).
49
//! If the texture is lazyly loaded, this starts the loading and return false immediately.
50
//! @return true if the binding successfully occured, false if the texture is not yet loaded.
53
//! Return whether the texture can be binded, i.e. it is fully loaded
54
bool canBind() const {return id!=0;}
56
//! Get the average texture luminance.
57
//! @param lum 0 is black, 1 is white
58
//! @return true if the returned luminance is known, false if not. In this later case, the value of num is undefined.
59
bool getAverageLuminance(float& lum);
61
//! Return the width and heigth of the texture in pixels
62
bool getDimensions(int &width, int &height);
64
//! Return the position of the 4 corners of the texture in texture coordinates
65
const Vec2d* getCoordinates() const {return texCoordinates;}
67
//! Get the error message which caused the texture loading to fail
68
//! @return the human friendly error message or empty string if no errors occured
69
const QString& getErrorMessage() const {return errorMessage;}
71
//! Return the full path to the image file
72
const QString& getFullPath() const {return fullPath;}
74
//! Return whether the image is currently being loaded
75
bool isLoading() const {return isLoadingImage && !canBind();}
78
//! Emitted when the texture is ready to be bind(), i.e. when downloaded, imageLoading and glLoading is over
79
//! or when an error occured and the texture will never be available
80
//! In case of error, you can query what the problem was by calling getErrorMessage()
81
//! @param error is equal to true if an error occured while loading the texture
82
void loadingProcessFinished(bool error);
85
//! Called when the download for the texture file terminated
86
void downloadFinished();
88
//! Called when the file loading thread has terminated
89
void fileLoadFinished();
92
//! Private constructor
95
//! Load the texture already in the RAM to the openGL memory
96
//! This function uses openGL routines and must be called in the main thread
97
//! @return false if an error occured
100
//! Loading of the image data.
101
//! This method is thread safe
102
//! @return false if an error occured
105
//! This method should be called if the texture loading failed for any reasons
106
//! @param errorMessage the human friendly error message
107
void reportError(const QString& errorMessage);
109
//! Define the range mode used to rescale the texture when loading
110
STextureTypes::DynamicRangeMode dynamicRangeMode;
112
//! Used to download remote files if needed
113
class QNetworkReply* httpReply;
115
//! Used to load in thread
116
class ImageLoadThread* loadThread;
118
//! Define if the texture was already downloaded if it was a remote one
120
//! Define whether the image is already loading
123
//! The URL where to download the file
126
//! The data that was laoded from http
127
QByteArray downloadedData;
130
//! Used ony when creating temporary file
131
QString fileExtension;
133
//! True when something when wrong in the loading process
136
//! Human friendly error message if loading failed
137
QString errorMessage;
146
///////////////////////////////////////////////////////////////////////////
147
// Attributes protected by the Mutex
148
//! Mutex used to protect all the attributes below
151
//! Cached average luminance
154
GLsizei width; //! Texture image width
155
GLsizei height; //! Texture image height
157
GLint internalFormat;
161
//! Position of the 4 corners of the texture in texture coordinates
162
Vec2d texCoordinates[4];
164
//! Fix a limit to the number of maximum simultaneous loading threads
165
static QSemaphore* maxLoadThreadSemaphore;
169
#endif // _STEXTURE_HPP_