OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreTexture.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef _Texture_H__
29 #define _Texture_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreHardwareBuffer.h"
33 #include "OgreResource.h"
34 #include "OgreImage.h"
35 
36 namespace Ogre {
37 
47  {
56  TU_AUTOMIPMAP = 0x100,
59  TU_RENDERTARGET = 0x200,
62 
63  };
64 
68  {
77  };
78 
82  {
84  MIP_UNLIMITED = 0x7FFFFFFF,
87  };
88 
89  // Forward declaration
90  class TexturePtr;
91 
101  class _OgreExport Texture : public Resource
102  {
103  public:
104  Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
105  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
106 
109  virtual void setTextureType(TextureType ttype ) { mTextureType = ttype; }
110 
113  virtual TextureType getTextureType(void) const { return mTextureType; }
114 
117  virtual size_t getNumMipmaps(void) const {return mNumMipmaps;}
118 
123  virtual void setNumMipmaps(size_t num) {mNumRequestedMipmaps = mNumMipmaps = num;}
124 
129  virtual bool getMipmapsHardwareGenerated(void) const { return mMipmapsHardwareGenerated; }
130 
133  virtual float getGamma(void) const { return mGamma; }
134 
143  virtual void setGamma(float g) { mGamma = g; }
144 
163  virtual void setHardwareGammaEnabled(bool enabled) { mHwGamma = enabled; }
164 
168  virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
169 
177  virtual void setFSAA(uint fsaa, const String& fsaaHint) { mFSAA = fsaa; mFSAAHint = fsaaHint; }
178 
182  virtual uint getFSAA() const { return mFSAA; }
183 
186  virtual const String& getFSAAHint() const { return mFSAAHint; }
187 
190  virtual size_t getHeight(void) const { return mHeight; }
191 
194  virtual size_t getWidth(void) const { return mWidth; }
195 
198  virtual size_t getDepth(void) const { return mDepth; }
199 
202  virtual size_t getSrcHeight(void) const { return mSrcHeight; }
203 
206  virtual size_t getSrcWidth(void) const { return mSrcWidth; }
207 
210  virtual size_t getSrcDepth(void) const { return mSrcDepth; }
211 
214  virtual void setHeight(size_t h) { mHeight = mSrcHeight = h; }
215 
218  virtual void setWidth(size_t w) { mWidth = mSrcWidth = w; }
219 
223  virtual void setDepth(size_t d) { mDepth = mSrcDepth = d; }
224 
227  virtual int getUsage() const
228  {
229  return mUsage;
230  }
231 
239  virtual void setUsage(int u) { mUsage = u; }
240 
252  virtual void createInternalResources(void);
253 
256  virtual void freeInternalResources(void);
257 
260  virtual void copyToTexture( TexturePtr& target );
261 
268  virtual void loadImage( const Image &img );
269 
280  virtual void loadRawData( DataStreamPtr& stream,
281  ushort uWidth, ushort uHeight, PixelFormat eFormat);
282 
288  virtual void _loadImages( const ConstImagePtrList& images );
289 
291  virtual PixelFormat getFormat() const
292  {
293  return mFormat;
294  }
295 
297  virtual PixelFormat getDesiredFormat(void) const
298  {
299  return mDesiredFormat;
300  }
301 
305  virtual PixelFormat getSrcFormat(void) const
306  {
307  return mSrcFormat;
308  }
309 
311  virtual void setFormat(PixelFormat pf);
312 
314  virtual bool hasAlpha(void) const;
315 
321  virtual void setDesiredIntegerBitDepth(ushort bits);
322 
325  virtual ushort getDesiredIntegerBitDepth(void) const;
326 
332  virtual void setDesiredFloatBitDepth(ushort bits);
333 
336  virtual ushort getDesiredFloatBitDepth(void) const;
337 
340  virtual void setDesiredBitDepths(ushort integerBits, ushort floatBits);
341 
344  virtual void setTreatLuminanceAsAlpha(bool asAlpha);
345 
348  virtual bool getTreatLuminanceAsAlpha(void) const;
349 
353  virtual size_t getNumFaces() const;
354 
367  virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0;
368 
369 
374  virtual void convertToImage(Image& destImage, bool includeMipMaps = false);
375 
381  virtual void getCustomAttribute(const String& name, void* pData) {}
382 
383 
384 
385  protected:
386  size_t mHeight;
387  size_t mWidth;
388  size_t mDepth;
389 
391  size_t mNumMipmaps;
393  float mGamma;
394  bool mHwGamma;
397 
400  int mUsage; // Bit field, so this can't be TextureUsage
401 
403  size_t mSrcWidth, mSrcHeight, mSrcDepth;
404 
406  unsigned short mDesiredIntegerBitDepth;
407  unsigned short mDesiredFloatBitDepth;
409 
411 
413  size_t calculateSize(void) const;
414 
415 
418  virtual void createInternalResourcesImpl(void) = 0;
419 
422  virtual void freeInternalResourcesImpl(void) = 0;
423 
425  void unloadImpl(void);
426 
430  String getSourceFileType() const;
431 
432  };
433 
440  class _OgreExport TexturePtr : public SharedPtr<Texture>
441  {
442  public:
444  explicit TexturePtr(Texture* rep) : SharedPtr<Texture>(rep) {}
447  {
448  // lock & copy other mutex pointer
449  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
450  {
451  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
452  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
453  pRep = static_cast<Texture*>(r.getPointer());
454  pUseCount = r.useCountPointer();
455  if (pUseCount)
456  {
457  ++(*pUseCount);
458  }
459  }
460  }
461 
464  {
465  if (pRep == static_cast<Texture*>(r.getPointer()))
466  return *this;
467  release();
468  // lock & copy other mutex pointer
469  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
470  {
471  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
472  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
473  pRep = static_cast<Texture*>(r.getPointer());
474  pUseCount = r.useCountPointer();
475  if (pUseCount)
476  {
477  ++(*pUseCount);
478  }
479  }
480  else
481  {
482  // RHS must be a null pointer
483  assert(r.isNull() && "RHS must be null if it has no mutex!");
484  setNull();
485  }
486  return *this;
487  }
488  };
492 }
493 
494 #endif
TextureType mTextureType
Definition: OgreTexture.h:398
this texture will be a render target, i.e.
Definition: OgreTexture.h:59
virtual void getCustomAttribute(const String &name, void *pData)
Retrieve a platform or API-specific piece of information from this texture.
Definition: OgreTexture.h:381
T * getPointer() const
TextureMipmap
Enum identifying special mipmap numbers.
Definition: OgreTexture.h:81
#define _OgreExport
Definition: OgrePlatform.h:203
virtual void setGamma(float g)
Sets the gamma adjustment factor applied to this texture on loading the data.
Definition: OgreTexture.h:143
TexturePtr(const TexturePtr &r)
Definition: OgreTexture.h:445
TexturePtr & operator=(const ResourcePtr &r)
Operator used to convert a ResourcePtr to a TexturePtr.
Definition: OgreTexture.h:463
#define OGRE_MUTEX_CONDITIONAL(name)
size_t mNumRequestedMipmaps
Definition: OgreTexture.h:390
virtual void setWidth(size_t w)
Set the width of the texture; can only do this before load();.
Definition: OgreTexture.h:218
Combination of HBU_STATIC and HBU_WRITE_ONLY.
virtual PixelFormat getDesiredFormat(void) const
Returns the desired pixel format for the texture surface.
Definition: OgreTexture.h:297
mipmaps will be automatically generated for this texture
Definition: OgreTexture.h:56
virtual PixelFormat getSrcFormat(void) const
Returns the pixel format of the original input texture (may differ due to hardware requirements and p...
Definition: OgreTexture.h:305
Indicates the application will never read the contents of the buffer back, it will only ever write da...
PixelFormat mSrcFormat
Definition: OgreTexture.h:402
vector< const Image * >::type ConstImagePtrList
Definition: OgreImage.h:503
Interface describing a manual resource loader.
Definition: OgreResource.h:512
virtual int getUsage() const
Returns the TextureUsage indentifier for this Texture.
Definition: OgreTexture.h:227
Combination of HBU_DYNAMIC, HBU_WRITE_ONLY and HBU_DISCARDABLE.
bool mMipmapsHardwareGenerated
Definition: OgreTexture.h:392
virtual void setNumMipmaps(size_t num)
Sets the number of mipmaps to be used for this texture.
Definition: OgreTexture.h:123
unsigned short mDesiredIntegerBitDepth
Definition: OgreTexture.h:406
Indicates the application would like to modify this buffer with the CPU fairly often.
virtual void setFSAA(uint fsaa, const String &fsaaHint)
Set the level of multisample AA to be used if this texture is a rendertarget.
Definition: OgreTexture.h:177
Static buffer which the application rarely modifies once created.
virtual void setHeight(size_t h)
Set the height of the texture; can only do this before load();.
Definition: OgreTexture.h:214
virtual size_t getNumMipmaps(void) const
Gets the number of mipmaps to be used for this texture.
Definition: OgreTexture.h:117
1D texture, used in combination with 1D texture coordinates
Definition: OgreTexture.h:70
PixelFormat
The pixel format used for images, textures, and render surfaces.
Enums describing buffer usage; not mutually exclusive.
Definition: OgreTexture.h:49
Combination of HBU_DYNAMIC and HBU_WRITE_ONLY.
size_t mSrcWidth
Definition: OgreTexture.h:403
bool mInternalResourcesCreated
Definition: OgreTexture.h:410
Specialisation of SharedPtr to allow SharedPtr to be assigned to TexturePtr.
Definition: OgreTexture.h:440
TexturePtr(Texture *rep)
Definition: OgreTexture.h:444
virtual size_t getWidth(void) const
Returns the width of the texture.
Definition: OgreTexture.h:194
virtual uint getFSAA() const
Get the level of multisample AA to be used if this texture is a rendertarget.
Definition: OgreTexture.h:182
virtual size_t getSrcHeight(void) const
Returns the height of the original input texture (may differ due to hardware requirements).
Definition: OgreTexture.h:202
Shared pointer implementation used to share pixel buffers.
virtual bool isHardwareGammaEnabled() const
Gets whether this texture will be set up so that on sampling it, hardware gamma correction is applied...
Definition: OgreTexture.h:168
Class representing an image file.
Definition: OgreImage.h:61
unsigned short ushort
virtual void setUsage(int u)
Sets the TextureUsage indentifier for this Texture; only useful before load()
Definition: OgreTexture.h:239
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
size_t mNumMipmaps
Definition: OgreTexture.h:391
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
bool mTreatLuminanceAsAlpha
Definition: OgreTexture.h:408
#define OGRE_LOCK_MUTEX(name)
virtual void setTextureType(TextureType ttype)
Sets the type of texture; can only be changed before load()
Definition: OgreTexture.h:109
size_t mHeight
Definition: OgreTexture.h:386
virtual void setHardwareGammaEnabled(bool enabled)
Sets whether this texture will be set up so that on sampling it, hardware gamma correction is applied...
Definition: OgreTexture.h:163
virtual float getGamma(void) const
Returns the gamma adjustment factor applied to this texture on loading.
Definition: OgreTexture.h:133
virtual size_t getSrcWidth(void) const
Returns the width of the original input texture (may differ due to hardware requirements).
Definition: OgreTexture.h:206
TextureType
Enum identifying the texture type.
Definition: OgreTexture.h:67
TexturePtr(const ResourcePtr &r)
Definition: OgreTexture.h:446
Defines a generic resource handler.
unsigned int * useCountPointer() const
unsigned short mDesiredFloatBitDepth
Definition: OgreTexture.h:407
2D texture, used in combination with 2D texture coordinates (default)
Definition: OgreTexture.h:72
PixelFormat mDesiredFormat
Definition: OgreTexture.h:405
_StringBase String
Use TextureManager default.
Definition: OgreTexture.h:86
virtual void setDepth(size_t d)
Set the depth of the texture (only applicable for 3D textures); ; can only do this before load();...
Definition: OgreTexture.h:223
virtual const String & getFSAAHint() const
Get the multisample AA hint if this texture is a rendertarget.
Definition: OgreTexture.h:186
virtual size_t getSrcDepth(void) const
Returns the original depth of the input texture (only applicable for 3D textures).
Definition: OgreTexture.h:210
PixelFormat mFormat
Definition: OgreTexture.h:399
default to automatic mipmap generation static textures
Definition: OgreTexture.h:61
virtual size_t getDepth(void) const
Returns the depth of the texture (only applicable for 3D textures).
Definition: OgreTexture.h:198
3D volume texture, used in combination with 3D texture coordinates
Definition: OgreTexture.h:74
virtual bool getMipmapsHardwareGenerated(void) const
Are mipmaps hardware generated?
Definition: OgreTexture.h:129
Generate mipmaps up to 1x1.
Definition: OgreTexture.h:84
Abstract class representing a Texture resource.
Definition: OgreTexture.h:101
virtual size_t getHeight(void) const
Returns the height of the texture.
Definition: OgreTexture.h:190
virtual PixelFormat getFormat() const
Returns the pixel format for the texture surface.
Definition: OgreTexture.h:291
String mFSAAHint
Definition: OgreTexture.h:396
3D cube map, used in combination with 3D texture coordinates
Definition: OgreTexture.h:76
#define OGRE_COPY_AUTO_SHARED_MUTEX(from)
unsigned int uint
virtual TextureType getTextureType(void) const
Gets the type of texture.
Definition: OgreTexture.h:113
bool isNull(void) const
TextureUsage
Enum identifying the texture usage.
Definition: OgreTexture.h:46