OGRE  1.9.0
OgreTexture.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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#include "OgreHeaderPrefix.h"
36
37namespace Ogre {
38
64
82
86 {
88 MIP_UNLIMITED = 0x7FFFFFFF,
90 MIP_DEFAULT = -1
91 };
92
103 {
104 public:
105 Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
106 const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
107
108 virtual ~Texture() {}
109
112 virtual void setTextureType(TextureType ttype ) { mTextureType = ttype; }
113
116 virtual TextureType getTextureType(void) const { return mTextureType; }
117
120 virtual uint8 getNumMipmaps(void) const {return mNumMipmaps;}
121
126 virtual void setNumMipmaps(uint8 num) {mNumRequestedMipmaps = mNumMipmaps = num;}
127
132 virtual bool getMipmapsHardwareGenerated(void) const { return mMipmapsHardwareGenerated; }
133
136 virtual float getGamma(void) const { return mGamma; }
137
146 virtual void setGamma(float g) { mGamma = g; }
147
166 virtual void setHardwareGammaEnabled(bool enabled) { mHwGamma = enabled; }
167
171 virtual bool isHardwareGammaEnabled() const { return mHwGamma; }
172
180 virtual void setFSAA(uint fsaa, const String& fsaaHint) { mFSAA = fsaa; mFSAAHint = fsaaHint; }
181
185 virtual uint getFSAA() const { return mFSAA; }
186
189 virtual const String& getFSAAHint() const { return mFSAAHint; }
190
193 virtual uint32 getHeight(void) const { return mHeight; }
194
197 virtual uint32 getWidth(void) const { return mWidth; }
198
201 virtual uint32 getDepth(void) const { return mDepth; }
202
205 virtual uint32 getSrcHeight(void) const { return mSrcHeight; }
206
209 virtual uint32 getSrcWidth(void) const { return mSrcWidth; }
210
213 virtual uint32 getSrcDepth(void) const { return mSrcDepth; }
214
217 virtual void setHeight(uint32 h) { mHeight = mSrcHeight = h; }
218
221 virtual void setWidth(uint32 w) { mWidth = mSrcWidth = w; }
222
226 virtual void setDepth(uint32 d) { mDepth = mSrcDepth = d; }
227
230 virtual int getUsage() const
231 {
232 return mUsage;
233 }
234
242 virtual void setUsage(int u) { mUsage = u; }
243
255 virtual void createInternalResources(void);
256
259 virtual void freeInternalResources(void);
260
263 virtual void copyToTexture( TexturePtr& target );
264
271 virtual void loadImage( const Image &img );
272
283 virtual void loadRawData( DataStreamPtr& stream,
284 ushort uWidth, ushort uHeight, PixelFormat eFormat);
285
291 virtual void _loadImages( const ConstImagePtrList& images );
292
294 virtual PixelFormat getFormat() const
295 {
296 return mFormat;
297 }
298
300 virtual PixelFormat getDesiredFormat(void) const
301 {
302 return mDesiredFormat;
303 }
304
308 virtual PixelFormat getSrcFormat(void) const
309 {
310 return mSrcFormat;
311 }
312
314 virtual void setFormat(PixelFormat pf);
315
317 virtual bool hasAlpha(void) const;
318
325
329
335 virtual void setDesiredFloatBitDepth(ushort bits);
336
339 virtual ushort getDesiredFloatBitDepth(void) const;
340
343 virtual void setDesiredBitDepths(ushort integerBits, ushort floatBits);
344
347 virtual void setTreatLuminanceAsAlpha(bool asAlpha);
348
351 virtual bool getTreatLuminanceAsAlpha(void) const;
352
356 virtual size_t getNumFaces() const;
357
370 virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0) = 0;
371
372
377 virtual void convertToImage(Image& destImage, bool includeMipMaps = false);
378
384 virtual void getCustomAttribute(const String& name, void* pData);
385
386
387
388 protected:
392
396 float mGamma;
400
403 int mUsage;
404
406 uint32 mSrcWidth, mSrcHeight, mSrcDepth;
407
410 unsigned short mDesiredFloatBitDepth;
412
414
416 size_t calculateSize(void) const;
417
418
421 virtual void createInternalResourcesImpl(void) = 0;
422
425 virtual void freeInternalResourcesImpl(void) = 0;
426
428 void unloadImpl(void);
429
434
435 };
439}
440
441#include "OgreHeaderSuffix.h"
442
443#endif
#define _OgreExport
@ HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE
Combination of HBU_DYNAMIC, HBU_WRITE_ONLY and HBU_DISCARDABLE.
@ HBU_WRITE_ONLY
Indicates the application will never read the contents of the buffer back, it will only ever write da...
@ HBU_STATIC_WRITE_ONLY
Combination of HBU_STATIC and HBU_WRITE_ONLY.
@ HBU_STATIC
Static buffer which the application rarely modifies once created.
@ HBU_DYNAMIC_WRITE_ONLY
Combination of HBU_DYNAMIC and HBU_WRITE_ONLY.
@ HBU_DYNAMIC
Indicates the application would like to modify this buffer with the CPU fairly often.
Shared pointer implementation used to share pixel buffers.
Class representing an image file.
Definition OgreImage.h:62
Interface describing a manual resource loader.
Defines a generic resource handler.
Abstract class representing a loadable resource (e.g.
Abstract class representing a Texture resource.
virtual void copyToTexture(TexturePtr &target)
Copies (and maybe scales to fit) the contents of this texture to another texture.
virtual void setUsage(int u)
Sets the TextureUsage identifier for this Texture; only useful before load()
virtual PixelFormat getSrcFormat(void) const
Returns the pixel format of the original input texture (may differ due to hardware requirements and p...
virtual ~Texture()
virtual void _loadImages(const ConstImagePtrList &images)
Internal method to load the texture from a set of images.
virtual PixelFormat getFormat() const
Returns the pixel format for the texture surface.
unsigned short mDesiredIntegerBitDepth
virtual void loadRawData(DataStreamPtr &stream, ushort uWidth, ushort uHeight, PixelFormat eFormat)
Loads the data from a raw stream.
size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
PixelFormat mSrcFormat
Bit field, so this can't be TextureUsage.
Texture(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual=false, ManualResourceLoader *loader=0)
virtual void setDesiredIntegerBitDepth(ushort bits)
Sets desired bit depth for integer pixel format textures.
uint8 mNumRequestedMipmaps
virtual void setNumMipmaps(uint8 num)
Sets the number of mipmaps to be used for this texture.
virtual void setGamma(float g)
Sets the gamma adjustment factor applied to this texture on loading the data.
virtual void setHardwareGammaEnabled(bool enabled)
Sets whether this texture will be set up so that on sampling it, hardware gamma correction is applied...
virtual void freeInternalResources(void)
Frees internal texture resources for this texture.
PixelFormat mDesiredFormat
void unloadImpl(void)
Default implementation of unload which calls freeInternalResources.
virtual bool isHardwareGammaEnabled() const
Gets whether this texture will be set up so that on sampling it, hardware gamma correction is applied...
virtual bool hasAlpha(void) const
Returns true if the texture has an alpha layer.
virtual HardwarePixelBufferSharedPtr getBuffer(size_t face=0, size_t mipmap=0)=0
Return hardware pixel buffer for a surface.
virtual const String & getFSAAHint() const
Get the multisample AA hint if this texture is a rendertarget.
virtual void setHeight(uint32 h)
Set the height of the texture; can only do this before load();.
virtual int getUsage() const
Returns the TextureUsage identifier for this Texture.
virtual void setWidth(uint32 w)
Set the width of the texture; can only do this before load();.
PixelFormat mFormat
bool mMipmapsHardwareGenerated
virtual bool getMipmapsHardwareGenerated(void) const
Are mipmaps hardware generated?
virtual void freeInternalResourcesImpl(void)=0
Implementation of freeing internal texture resources.
virtual ushort getDesiredIntegerBitDepth(void) const
gets desired bit depth for integer pixel format textures.
virtual void setDepth(uint32 d)
Set the depth of the texture (only applicable for 3D textures); can only do this before load();.
virtual void createInternalResources(void)
Creates the internal texture resources for this texture.
virtual bool getTreatLuminanceAsAlpha(void) const
Gets whether luminace pixel format will treated as alpha format when load this texture.
virtual void setTextureType(TextureType ttype)
Sets the type of texture; can only be changed before load()
virtual uint32 getDepth(void) const
Returns the depth of the texture (only applicable for 3D textures).
unsigned short mDesiredFloatBitDepth
virtual void setDesiredFloatBitDepth(ushort bits)
Sets desired bit depth for float pixel format textures.
virtual void setTreatLuminanceAsAlpha(bool asAlpha)
Sets whether luminace pixel format will treated as alpha format when load this texture.
virtual ushort getDesiredFloatBitDepth(void) const
gets desired bit depth for float pixel format textures.
bool mTreatLuminanceAsAlpha
TextureType mTextureType
virtual uint32 getSrcWidth(void) const
Returns the width of the original input texture (may differ due to hardware requirements).
virtual uint32 getSrcHeight(void) const
Returns the height of the original input texture (may differ due to hardware requirements).
virtual void setFSAA(uint fsaa, const String &fsaaHint)
Set the level of multisample AA to be used if this texture is a rendertarget.
virtual size_t getNumFaces() const
Return the number of faces this texture has.
virtual uint8 getNumMipmaps(void) const
Gets the number of mipmaps to be used for this texture.
virtual void loadImage(const Image &img)
Loads the data from an image.
virtual uint32 getWidth(void) const
Returns the width of the texture.
virtual void getCustomAttribute(const String &name, void *pData)
Retrieve a platform or API-specific piece of information from this texture.
virtual PixelFormat getDesiredFormat(void) const
Returns the desired pixel format for the texture surface.
virtual void convertToImage(Image &destImage, bool includeMipMaps=false)
Populate an Image with the contents of this texture.
virtual TextureType getTextureType(void) const
Gets the type of texture.
String getSourceFileType() const
Identify the source file type as a string, either from the extension or from a magic number.
virtual uint32 getHeight(void) const
Returns the height of the texture.
virtual float getGamma(void) const
Returns the gamma adjustment factor applied to this texture on loading.
bool mInternalResourcesCreated
virtual void setDesiredBitDepths(ushort integerBits, ushort floatBits)
Sets desired bit depth for integer and float pixel format.
virtual void createInternalResourcesImpl(void)=0
Implementation of creating internal texture resources.
virtual uint32 getSrcDepth(void) const
Returns the original depth of the input texture (only applicable for 3D textures).
virtual void setFormat(PixelFormat pf)
Sets the pixel format for the texture surface; can only be set before load().
virtual uint getFSAA() const
Get the level of multisample AA to be used if this texture is a rendertarget.
vector< constImage * >::type ConstImagePtrList
Definition OgreImage.h:503
PixelFormat
The pixel format used for images, textures, and render surfaces.
TextureMipmap
Enum identifying special mipmap numbers.
Definition OgreTexture.h:86
TextureType
Enum identifying the texture type.
Definition OgreTexture.h:68
TextureUsage
Enum identifying the texture usage.
Definition OgreTexture.h:48
@ MIP_DEFAULT
Use TextureManager default.
Definition OgreTexture.h:90
@ MIP_UNLIMITED
Generate mipmaps up to 1x1.
Definition OgreTexture.h:88
@ TEX_TYPE_2D_ARRAY
2D texture array
Definition OgreTexture.h:78
@ TEX_TYPE_1D
1D texture, used in combination with 1D texture coordinates
Definition OgreTexture.h:70
@ TEX_TYPE_2D_RECT
2D non-square texture, used in combination with 2D texture coordinates
Definition OgreTexture.h:80
@ TEX_TYPE_3D
3D volume texture, used in combination with 3D texture coordinates
Definition OgreTexture.h:74
@ TEX_TYPE_CUBE_MAP
3D cube map, used in combination with 3D texture coordinates
Definition OgreTexture.h:76
@ TEX_TYPE_2D
2D texture, used in combination with 2D texture coordinates (default)
Definition OgreTexture.h:72
@ TU_STATIC_WRITE_ONLY
Definition OgreTexture.h:53
@ TU_STATIC
Enums describing buffer usage; not mutually exclusive.
Definition OgreTexture.h:50
@ TU_DYNAMIC_WRITE_ONLY_DISCARDABLE
Definition OgreTexture.h:55
@ TU_AUTOMIPMAP
Mipmaps will be automatically generated for this texture.
Definition OgreTexture.h:57
@ TU_DYNAMIC_WRITE_ONLY
Definition OgreTexture.h:54
@ TU_DEFAULT
Default to automatic mipmap generation static textures.
Definition OgreTexture.h:62
@ TU_DYNAMIC
Definition OgreTexture.h:51
@ TU_RENDERTARGET
This texture will be a render target, i.e.
Definition OgreTexture.h:60
@ TU_WRITE_ONLY
Definition OgreTexture.h:52
unsigned char uint8
unsigned int uint
unsigned int uint32
unsigned long long int ResourceHandle
_StringBase String
unsigned short ushort