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(GFXDynamicTextureProfile )
GFX_DeclareTextureProfile(GFXDynamicTextureSRGBProfile )
GFX_DeclareTextureProfile(GFXNormalMapBC3Profile )
GFX_DeclareTextureProfile(GFXNormalMapBC5Profile )
GFX_DeclareTextureProfile(GFXNormalMapProfile )
GFX_DeclareTextureProfile(GFXRenderTargetProfile )
GFX_DeclareTextureProfile(GFXRenderTargetSRGBProfile )
GFX_DeclareTextureProfile(GFXStaticTextureProfile )
GFX_DeclareTextureProfile(GFXStaticTextureSRGBProfile )
GFX_DeclareTextureProfile(GFXSystemMemTextureProfile )
GFX_DeclareTextureProfile(GFXTexturePersistentProfile )
GFX_DeclareTextureProfile(GFXTexturePersistentSRGBProfile )
GFX_DeclareTextureProfile(GFXZTargetProfile )
Detailed Description
Public Defines
GFX_DeclareTextureProfile(name) extern name
GFX_ImplementTextureProfile(name, type, flags, compression) name(#name, type, flags, compression)
Public Functions
GFX_DeclareTextureProfile(GFXDynamicTextureProfile )
GFX_DeclareTextureProfile(GFXDynamicTextureSRGBProfile )
GFX_DeclareTextureProfile(GFXNormalMapBC3Profile )
GFX_DeclareTextureProfile(GFXNormalMapBC5Profile )
GFX_DeclareTextureProfile(GFXNormalMapProfile )
GFX_DeclareTextureProfile(GFXRenderTargetProfile )
GFX_DeclareTextureProfile(GFXRenderTargetSRGBProfile )
GFX_DeclareTextureProfile(GFXStaticTextureProfile )
GFX_DeclareTextureProfile(GFXStaticTextureSRGBProfile )
GFX_DeclareTextureProfile(GFXSystemMemTextureProfile )
GFX_DeclareTextureProfile(GFXTexturePersistentProfile )
GFX_DeclareTextureProfile(GFXTexturePersistentSRGBProfile )
GFX_DeclareTextureProfile(GFXZTargetProfile )
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 SRGB = BIT(9), ///< sRGB texture 91 92 /// Track and pool textures of this type for reuse. 93 /// 94 /// You should use this profile flag sparingly. Odd 95 /// sized textures and spikes in allocation can cause 96 /// the pool to contain unused textures which will remain 97 /// in memory until a flush occurs. 98 /// 99 Pooled = BIT(10), 100 101 /// A hint that the device is not allowed to discard the content 102 /// of a target texture after presentation or deactivated. 103 /// 104 /// This is mainly a depth buffer optimization. 105 NoDiscard = BIT(11), 106 107 108 NoModify = BIT(11) 109 110 }; 111 112 enum Compression 113 { 114 NONE, 115 BC1, 116 BC2, 117 BC3, 118 BC4, 119 BC5, 120 }; 121 122 GFXTextureProfile(const String &name, Types type, U32 flags, Compression compression = NONE); 123 // Equality operators 124 inline bool operator==(const GFXTextureProfile &in_Cmp) const { return (mName == in_Cmp.mName && mProfile == in_Cmp.mProfile); } 125 inline bool operator!=(const GFXTextureProfile &in_Cmp) const { return !(*this == in_Cmp); } 126 127 // Accessors 128 String getName() const { return mName; }; 129 Types getType() const { return (Types)(mProfile & (BIT(TypeBits) - 1)); } 130 const Compression getCompression() const { return (Compression)((mProfile >> (FlagBits + TypeBits)) & (BIT(CompressionBits + 1) - 1)); }; 131 132 bool testFlag(Flags flag) const 133 { 134 return (mProfile & (flag << TypeBits)) != 0; 135 } 136 137 // Mutators 138 const U32 getDownscale() const { return mDownscale; } 139 void setDownscale(const U32 shift) { mDownscale = shift; } 140 void incActiveCopies() { mStats.activeCount++; } 141 void decActiveCopies() { AssertFatal( mStats.activeCount != 0, "Ran out of extant copies!"); mStats.activeCount--; } 142 143 // And static interface... 144 static void init(); 145 static GFXTextureProfile *find(const String &name); 146 static void updateStatsForCreation(GFXTextureObject *t); 147 static void updateStatsForDeletion(GFXTextureObject *t); 148 149 /// Collects the total stats for all the profiles which 150 /// include any of the flag bits. 151 static void collectStats( Flags flags, GFXTextureProfileStats *stats ); 152 153 /// Returns the total profile count in the list. 154 static U32 getProfileCount() { return smProfileCount; } 155 156 /// Returns the head of the profile list. 157 static GFXTextureProfile* getHead() { return smHead; } 158 159 /// Returns the next profile in the list. 160 GFXTextureProfile* getNext() const { return mNext; } 161 162 /// Returns the allocation stats for this texture profile. 163 inline const GFXTextureProfileStats& getStats() const { return mStats; } 164 165 // Helper functions... 166 inline bool doStoreBitmap() const { return testFlag(KeepBitmap); } 167 inline bool canDownscale() const { return !testFlag(PreserveSize); } 168 inline bool isDynamic() const { return testFlag(Dynamic); } 169 inline bool isRenderTarget() const { return testFlag(RenderTarget); } 170 inline bool isZTarget() const { return testFlag(ZTarget); } 171 inline bool isSystemMemory() const { return testFlag(SystemMemory); } 172 inline bool noMip() const { return testFlag(NoMipmap); } 173 inline bool isPooled() const { return testFlag(Pooled); } 174 inline bool canDiscard() const { return !testFlag(NoDiscard); } 175 inline bool isSRGB() const { return testFlag(SRGB); } 176 //compare profile flags for equality 177 inline bool compareFlags(const GFXTextureProfile& in_Cmp) const{ return (mProfile == in_Cmp.mProfile); } 178private: 179 /// These constants control the packing for the profile; if you add flags, types, or 180 /// compression info then make sure these are giving enough bits! 181 enum Constants 182 { 183 TypeBits = 2, 184 FlagBits = 12, 185 CompressionBits = 3, 186 }; 187 188 String mName; ///< Name of this profile... 189 U32 mDownscale; ///< Amount to shift textures of this type down, if any. 190 U32 mProfile; ///< Stores a munged version of the profile data. 191 U32 mActiveCount; ///< Count of textures of this profile type allocated. 192 U32 mActiveTexels; ///< Amount of texelspace currently allocated under this profile. 193 U32 mActiveBytes; ///< Amount of storage currently allocated under this profile. 194 U32 mAllocatedTextures; ///< Total number of textures allocated under this profile. 195 U32 mAllocatedTexels; ///< Total number of texels allocated under this profile. 196 U32 mAllocatedBytes; ///< Total number of bytes allocated under this profile. 197 198 /// The texture profile stats. 199 GFXTextureProfileStats mStats; 200 201 /// The number of profiles in the system. 202 static U32 smProfileCount; 203 204 /// Keep a list of all the profiles. 205 GFXTextureProfile *mNext; 206 static GFXTextureProfile *smHead; 207}; 208 209#define GFX_DeclareTextureProfile(name) extern GFXTextureProfile name 210#define GFX_ImplementTextureProfile(name, type, flags, compression) GFXTextureProfile name(#name, type, flags, compression) 211 212// Default Texture profiles 213// Texture we can render to. 214GFX_DeclareTextureProfile(GFXRenderTargetProfile); 215GFX_DeclareTextureProfile(GFXRenderTargetSRGBProfile); 216// Standard static diffuse textures 217GFX_DeclareTextureProfile(GFXStaticTextureProfile); 218GFX_DeclareTextureProfile(GFXStaticTextureSRGBProfile); 219// Standard static diffuse textures that are persistent in memory 220GFX_DeclareTextureProfile(GFXTexturePersistentProfile); 221GFX_DeclareTextureProfile(GFXTexturePersistentSRGBProfile); 222// Texture that resides in system memory - used to copy data to 223GFX_DeclareTextureProfile(GFXSystemMemTextureProfile); 224// normal map profiles 225GFX_DeclareTextureProfile(GFXNormalMapProfile); 226GFX_DeclareTextureProfile(GFXNormalMapBC3Profile); 227GFX_DeclareTextureProfile(GFXNormalMapBC5Profile); 228// Depth buffer texture 229GFX_DeclareTextureProfile(GFXZTargetProfile); 230// Dynamic Texure 231GFX_DeclareTextureProfile(GFXDynamicTextureProfile); 232GFX_DeclareTextureProfile(GFXDynamicTextureSRGBProfile); 233 234#endif 235