Torque3D Documentation / _generateds / gfxTextureHandle.h

gfxTextureHandle.h

Engine/source/gfx/gfxTextureHandle.h

More...

Classes:

class

A reference counted handle to a texture resource.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _GFXTEXTUREHANDLE_H_
 25#define _GFXTEXTUREHANDLE_H_
 26
 27#ifndef _GFXTEXTUREOBJECT_H_
 28#include "gfx/gfxTextureObject.h"
 29#endif
 30#ifndef _MPOINT2_H_
 31#include "math/mPoint2.h"
 32#endif
 33
 34
 35class GFXTextureProfile;
 36
 37
 38/// A reference counted handle to a texture resource.
 39class GFXTexHandle : public StrongRefPtr<GFXTextureObject>
 40{
 41public:
 42   GFXTexHandle() {}
 43   GFXTexHandle( GFXTextureObject* obj );
 44   GFXTexHandle( const GFXTexHandle &handle, const String &desc );
 45
 46   // load texture
 47   GFXTexHandle( const String &texName, GFXTextureProfile *profile, const String &desc );
 48   bool set( const String &texName, GFXTextureProfile *profile, const String &desc );
 49
 50   // load composite
 51   GFXTexHandle(const String &texNameR, const String &texNameG, const String &texNameB, const String &texNameA, U32 inputKey[4], GFXTextureProfile *profile, const String &desc);
 52   bool set( const String &texNameR, const String &texNameG, const String &texNameB, const String &texNameA, U32 inputKey[4], GFXTextureProfile *profile, const String &desc );
 53
 54   // register texture
 55   GFXTexHandle( GBitmap *bmp, GFXTextureProfile *profile, bool deleteBmp, const String &desc );
 56   bool set( GBitmap *bmp, GFXTextureProfile *profile, bool deleteBmp, const String &desc );
 57
 58   GFXTexHandle( DDSFile *bmp, GFXTextureProfile *profile, bool deleteDDS, const String &desc );
 59   bool set( DDSFile *bmp, GFXTextureProfile *profile, bool deleteDDS, const String &desc );
 60
 61   // Sized bitmap
 62   GFXTexHandle( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1, S32 antialiasLevel = 0);
 63   bool set( U32 width, U32 height, GFXFormat format, GFXTextureProfile *profile, const String &desc, U32 numMipLevels = 1, S32 antialiasLevel = 0);
 64   bool set( U32 width, U32 height, U32 depth, GFXFormat format, GFXTextureProfile* profile, const String& desc, U32 numMipLevels = 1);
 65
 66   /// Returns the width and height as a point.
 67   Point2I getWidthHeight() const { return getPointer() ? Point2I( getPointer()->getWidth(), getPointer()->getHeight() ) : Point2I::Zero; }
 68   
 69   U32 getWidth() const    { return getPointer() ? getPointer()->getWidth()  : 0; }
 70   U32 getHeight() const   { return getPointer() ? getPointer()->getHeight() : 0; }
 71   U32 getDepth() const    { return getPointer() ? getPointer()->getDepth()  : 0; }
 72   GFXFormat getFormat() const { return getPointer() ? getPointer()->getFormat() : GFXFormat_COUNT; }
 73   
 74   /// Reloads the texture.
 75   /// @see GFXTextureManager::reloadTexture
 76   void refresh();
 77
 78   /// Releases the texture handle.
 79   void free() { StrongObjectRef::set( NULL ); }
 80   
 81   GFXLockedRect *lock( U32 mipLevel = 0, RectI *inRect = NULL )
 82   {
 83      return getPointer()->lock(mipLevel, inRect); 
 84   }
 85
 86   void unlock( U32 mipLevel = 0) 
 87   {
 88      getPointer()->unlock(mipLevel); 
 89   }
 90
 91   // copy to bitmap.  see gfxTetureObject.h for description of what types of textures
 92   // can be copied into bitmaps.  returns true if successful, false otherwise
 93   bool copyToBmp(GBitmap* bmp) { return getPointer() ? getPointer()->copyToBmp(bmp) : false; }
 94
 95   //---------------------------------------------------------------------------
 96   // Operator overloads
 97   //---------------------------------------------------------------------------
 98   GFXTexHandle& operator=(const GFXTexHandle &t)
 99   {
100      StrongObjectRef::set(t.getPointer());
101      return *this;
102   }
103   
104   GFXTexHandle& operator=( GFXTextureObject *to)
105   {
106      StrongObjectRef::set(to);
107      return *this;
108   }
109
110   bool operator==(const GFXTexHandle &t) const { return t.getPointer() == getPointer(); }
111   bool operator!=(const GFXTexHandle &t) const { return t.getPointer() != getPointer(); }
112
113   /// Returns the texture object.
114   operator GFXTextureObject*() const { return getPointer(); }
115
116   /// Returns the backing bitmap for this texture.
117   GBitmap* getBitmap() { return getPointer() ? getPointer()->getBitmap() : NULL; }
118   const GBitmap* getBitmap() const { return getPointer() ? getPointer()->getBitmap() : NULL; }
119
120
121   /// Helper 2x2 R8G8B8A8 texture filled with 0.
122   static GFXTexHandle ZERO;
123
124   /// Helper 2x2 R8G8B8A8 texture filled with 255.
125   static GFXTexHandle ONE;
126
127   /// Helper 2x2 R8G8B8A8 normal map texture filled 
128   /// with 128, 128, 255.
129   static GFXTexHandle ZUP;
130
131};
132
133
134#endif // _GFXTEXTUREHANDLE_H_
135