gfxTextureProfile.h
Engine/source/gfx/gfxTextureProfile.h
Classes:
class
class
Helper struct for gathering profile stats.
Public Defines
define
GFX_DeclareTextureProfile(name) extern name
define
GFX_ImplementTextureProfile(name, type, flags, compression) name(#name, type, flags, compression)
Public Functions
GFX_DeclareTextureProfile(GFXDefaultPersistentProfile )
GFX_DeclareTextureProfile(GFXDefaultRenderTargetProfile )
GFX_DeclareTextureProfile(GFXDefaultStaticDiffuseProfile )
GFX_DeclareTextureProfile(GFXDefaultStaticDXT5nmProfile )
GFX_DeclareTextureProfile(GFXDefaultStaticNormalMapProfile )
GFX_DeclareTextureProfile(GFXDefaultZTargetProfile )
GFX_DeclareTextureProfile(GFXDynamicTextureProfile )
GFX_DeclareTextureProfile(GFXSystemMemProfile )
Detailed Description
Public Defines
GFX_DeclareTextureProfile(name) extern name
GFX_ImplementTextureProfile(name, type, flags, compression) name(#name, type, flags, compression)
Public Functions
GFX_DeclareTextureProfile(GFXDefaultPersistentProfile )
GFX_DeclareTextureProfile(GFXDefaultRenderTargetProfile )
GFX_DeclareTextureProfile(GFXDefaultStaticDiffuseProfile )
GFX_DeclareTextureProfile(GFXDefaultStaticDXT5nmProfile )
GFX_DeclareTextureProfile(GFXDefaultStaticNormalMapProfile )
GFX_DeclareTextureProfile(GFXDefaultZTargetProfile )
GFX_DeclareTextureProfile(GFXDynamicTextureProfile )
GFX_DeclareTextureProfile(GFXSystemMemProfile )
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 _GFXTEXTUREPROFILE_H_ 25#define _GFXTEXTUREPROFILE_H_ 26 27#ifndef _TORQUE_STRING_H_ 28#include "core/util/str.h" 29#endif 30 31class GFXTextureObject; 32 33/// Helper struct for gathering profile stats. 34class GFXTextureProfileStats 35{ 36public: 37 38 /// Constructs and clears the stats. 39 GFXTextureProfileStats() { clear(); } 40 41 /// Zeros all the stats. 42 void clear() 43 { 44 dMemset( this, 0, sizeof( GFXTextureProfileStats ) ); 45 } 46 47 /// Adds stats together. 48 GFXTextureProfileStats& operator +=( const GFXTextureProfileStats &stats ) 49 { 50 activeCount += stats.activeCount; 51 activeTexels += stats.activeTexels; 52 activeBytes += stats.activeBytes; 53 allocatedTextures += stats.allocatedTextures; 54 allocatedTexels += stats.allocatedTexels; 55 allocatedBytes += stats.allocatedBytes; 56 return *this; 57 } 58 59 U32 activeCount; ///< Count of textures of this profile type allocated. 60 U32 activeTexels; ///< Amount of texelspace currently allocated under this profile. 61 U32 activeBytes; ///< Amount of storage currently allocated under this profile. 62 U32 allocatedTextures; ///< Total number of textures allocated under this profile. 63 U32 allocatedTexels; ///< Total number of texels allocated under this profile. 64 U32 allocatedBytes; ///< Total number of bytes allocated under this profile. 65}; 66 67 68class GFXTextureProfile 69{ 70public: 71 enum Types 72 { 73 DiffuseMap, 74 NormalMap, 75 AlphaMap, 76 LuminanceMap 77 }; 78 79 enum Flags 80 { 81 PreserveSize = BIT(0), ///< Never shrink this bitmap in low VRAM situations. 82 NoMipmap = BIT(1), ///< Do not generate mipmap chain for this texture. 83 SystemMemory = BIT(2), ///< System memory texture - isn't uploaded to card - useful as target for copying surface data out of video ram 84 RenderTarget = BIT(3), ///< This texture will be used as a render target. 85 Dynamic = BIT(4), ///< This texture may be refreshed. (Precludes Static) 86 Static = BIT(5), ///< This texture will never be modified once loaded. (Precludes Dynamic) 87 NoPadding = BIT(6), ///< Do not pad this texture if it's non pow2. 88 KeepBitmap = BIT(7), ///< Always keep a copy of this texture's bitmap. (Potentially in addition to the API managed copy?) 89 ZTarget = BIT(8), ///< This texture will be used as a Z target. 90 91 /// Track and pool textures of this type for reuse. 92 /// 93 /// You should use this profile flag sparingly. Odd 94 /// sized textures and spikes in allocation can cause 95 /// the pool to contain unused textures which will remain 96 /// in memory until a flush occurs. 97 /// 98 Pooled = BIT(9), 99 100 /// A hint that the device is not allowed to discard the content 101 /// of a target texture after presentation or deactivated. 102 /// 103 /// This is mainly a depth buffer optimization. 104 NoDiscard = BIT(10), 105 106 /// Texture is managed by another process, thus should not be modified 107 NoModify = BIT(11) 108 109 }; 110 111 enum Compression 112 { 113 NONE, 114 DXT1, 115 DXT2, 116 DXT3, 117 DXT4, 118 DXT5, 119 }; 120 121 GFXTextureProfile(const String &name, Types type, U32 flags, Compression compression = NONE); 122 123 // Accessors 124 String getName() const { return mName; }; 125 Types getType() const { return (Types)(mProfile & (BIT(TypeBits) - 1)); } 126 const Compression getCompression() const { return (Compression)((mProfile >> (FlagBits + TypeBits)) & (BIT(CompressionBits + 1) - 1)); }; 127 128 bool testFlag(Flags flag) const 129 { 130 return (mProfile & (flag << TypeBits)) != 0; 131 } 132 133 // Mutators 134 const U32 getDownscale() const { return mDownscale; } 135 void setDownscale(const U32 shift) { mDownscale = shift; } 136 void incActiveCopies() { mStats.activeCount++; } 137 void decActiveCopies() { AssertFatal( mStats.activeCount != 0, "Ran out of extant copies!"); mStats.activeCount--; } 138 139 // And static interface... 140 static void init(); 141 static GFXTextureProfile *find(const String &name); 142 static void updateStatsForCreation(GFXTextureObject *t); 143 static void updateStatsForDeletion(GFXTextureObject *t); 144 145 /// Collects the total stats for all the profiles which 146 /// include any of the flag bits. 147 static void collectStats( Flags flags, GFXTextureProfileStats *stats ); 148 149 /// Returns the total profile count in the list. 150 static U32 getProfileCount() { return smProfileCount; } 151 152 /// Returns the head of the profile list. 153 static GFXTextureProfile* getHead() { return smHead; } 154 155 /// Returns the next profile in the list. 156 GFXTextureProfile* getNext() const { return mNext; } 157 158 /// Returns the allocation stats for this texture profile. 159 inline const GFXTextureProfileStats& getStats() const { return mStats; } 160 161 // Helper functions... 162 inline bool doStoreBitmap() const { return testFlag(KeepBitmap); } 163 inline bool canDownscale() const { return !testFlag(PreserveSize); } 164 inline bool isDynamic() const { return testFlag(Dynamic); } 165 inline bool isRenderTarget() const { return testFlag(RenderTarget); } 166 inline bool isZTarget() const { return testFlag(ZTarget); } 167 inline bool isSystemMemory() const { return testFlag(SystemMemory); } 168 inline bool noMip() const { return testFlag(NoMipmap); } 169 inline bool isPooled() const { return testFlag(Pooled); } 170 inline bool canDiscard() const { return !testFlag(NoDiscard); } 171 inline bool canModify() const { return !testFlag(NoModify); } 172 173private: 174 /// These constants control the packing for the profile; if you add flags, types, or 175 /// compression info then make sure these are giving enough bits! 176 enum Constants 177 { 178 TypeBits = 2, 179 FlagBits = 11, 180 CompressionBits = 3, 181 }; 182 183 String mName; ///< Name of this profile... 184 U32 mDownscale; ///< Amount to shift textures of this type down, if any. 185 U32 mProfile; ///< Stores a munged version of the profile data. 186 U32 mActiveCount; ///< Count of textures of this profile type allocated. 187 U32 mActiveTexels; ///< Amount of texelspace currently allocated under this profile. 188 U32 mActiveBytes; ///< Amount of storage currently allocated under this profile. 189 U32 mAllocatedTextures; ///< Total number of textures allocated under this profile. 190 U32 mAllocatedTexels; ///< Total number of texels allocated under this profile. 191 U32 mAllocatedBytes; ///< Total number of bytes allocated under this profile. 192 193 /// The texture profile stats. 194 GFXTextureProfileStats mStats; 195 196 /// The number of profiles in the system. 197 static U32 smProfileCount; 198 199 /// Keep a list of all the profiles. 200 GFXTextureProfile *mNext; 201 static GFXTextureProfile *smHead; 202}; 203 204#define GFX_DeclareTextureProfile(name) extern GFXTextureProfile name 205#define GFX_ImplementTextureProfile(name, type, flags, compression) GFXTextureProfile name(#name, type, flags, compression) 206 207// Set up some defaults.. 208 209// Texture we can render to. 210GFX_DeclareTextureProfile(GFXDefaultRenderTargetProfile); 211// Standard diffuse texture that stays in system memory. 212GFX_DeclareTextureProfile(GFXDefaultPersistentProfile); 213// Generic diffusemap. This works in most cases. 214GFX_DeclareTextureProfile(GFXDefaultStaticDiffuseProfile); 215// Generic normal map. 216GFX_DeclareTextureProfile(GFXDefaultStaticNormalMapProfile); 217// DXT5 swizzled normal map 218GFX_DeclareTextureProfile(GFXDefaultStaticDXT5nmProfile); 219// Texture that resides in system memory - used to copy data to 220GFX_DeclareTextureProfile(GFXSystemMemProfile); 221// Depth buffer texture 222GFX_DeclareTextureProfile(GFXDefaultZTargetProfile); 223// Dynamic Texure 224GFX_DeclareTextureProfile(GFXDynamicTextureProfile); 225 226#endif 227
