2012-09-19 15:15:01 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Copyright (c) 2012 GarageGames, LLC
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to
|
|
|
|
|
// deal in the Software without restriction, including without limitation the
|
|
|
|
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
|
// sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
// IN THE SOFTWARE.
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2021-07-19 06:07:08 +00:00
|
|
|
#pragma once
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
#ifndef _GFXTEXTUREPROFILE_H_
|
|
|
|
|
#define _GFXTEXTUREPROFILE_H_
|
|
|
|
|
|
|
|
|
|
#ifndef _TORQUE_STRING_H_
|
|
|
|
|
#include "core/util/str.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
class GFXTextureObject;
|
|
|
|
|
|
|
|
|
|
/// Helper struct for gathering profile stats.
|
|
|
|
|
class GFXTextureProfileStats
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// Constructs and clears the stats.
|
|
|
|
|
GFXTextureProfileStats() { clear(); }
|
|
|
|
|
|
|
|
|
|
/// Zeros all the stats.
|
|
|
|
|
void clear()
|
|
|
|
|
{
|
|
|
|
|
dMemset( this, 0, sizeof( GFXTextureProfileStats ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Adds stats together.
|
|
|
|
|
GFXTextureProfileStats& operator += ( const GFXTextureProfileStats &stats )
|
|
|
|
|
{
|
|
|
|
|
activeCount += stats.activeCount;
|
|
|
|
|
activeTexels += stats.activeTexels;
|
|
|
|
|
activeBytes += stats.activeBytes;
|
|
|
|
|
allocatedTextures += stats.allocatedTextures;
|
|
|
|
|
allocatedTexels += stats.allocatedTexels;
|
|
|
|
|
allocatedBytes += stats.allocatedBytes;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U32 activeCount; ///< Count of textures of this profile type allocated.
|
|
|
|
|
U32 activeTexels; ///< Amount of texelspace currently allocated under this profile.
|
|
|
|
|
U32 activeBytes; ///< Amount of storage currently allocated under this profile.
|
|
|
|
|
U32 allocatedTextures; ///< Total number of textures allocated under this profile.
|
|
|
|
|
U32 allocatedTexels; ///< Total number of texels allocated under this profile.
|
|
|
|
|
U32 allocatedBytes; ///< Total number of bytes allocated under this profile.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GFXTextureProfile
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
enum Types
|
|
|
|
|
{
|
|
|
|
|
DiffuseMap,
|
|
|
|
|
NormalMap,
|
|
|
|
|
AlphaMap,
|
|
|
|
|
LuminanceMap
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum Flags
|
|
|
|
|
{
|
|
|
|
|
PreserveSize = BIT(0), ///< Never shrink this bitmap in low VRAM situations.
|
|
|
|
|
NoMipmap = BIT(1), ///< Do not generate mipmap chain for this texture.
|
|
|
|
|
SystemMemory = BIT(2), ///< System memory texture - isn't uploaded to card - useful as target for copying surface data out of video ram
|
|
|
|
|
RenderTarget = BIT(3), ///< This texture will be used as a render target.
|
|
|
|
|
Dynamic = BIT(4), ///< This texture may be refreshed. (Precludes Static)
|
|
|
|
|
Static = BIT(5), ///< This texture will never be modified once loaded. (Precludes Dynamic)
|
|
|
|
|
NoPadding = BIT(6), ///< Do not pad this texture if it's non pow2.
|
|
|
|
|
KeepBitmap = BIT(7), ///< Always keep a copy of this texture's bitmap. (Potentially in addition to the API managed copy?)
|
|
|
|
|
ZTarget = BIT(8), ///< This texture will be used as a Z target.
|
2017-06-23 16:36:20 +00:00
|
|
|
SRGB = BIT(9), ///< sRGB texture
|
2025-12-22 10:29:01 +00:00
|
|
|
CubeMap = BIT(10), ///< Cubemap texture
|
2012-09-19 15:15:01 +00:00
|
|
|
/// Track and pool textures of this type for reuse.
|
|
|
|
|
///
|
|
|
|
|
/// You should use this profile flag sparingly. Odd
|
|
|
|
|
/// sized textures and spikes in allocation can cause
|
|
|
|
|
/// the pool to contain unused textures which will remain
|
|
|
|
|
/// in memory until a flush occurs.
|
|
|
|
|
///
|
2025-12-22 10:29:01 +00:00
|
|
|
Pooled = BIT(11),
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
/// A hint that the device is not allowed to discard the content
|
|
|
|
|
/// of a target texture after presentation or deactivated.
|
|
|
|
|
///
|
|
|
|
|
/// This is mainly a depth buffer optimization.
|
2025-12-22 10:29:01 +00:00
|
|
|
NoDiscard = BIT(12),
|
2016-03-21 15:10:14 +00:00
|
|
|
|
2025-12-22 10:29:01 +00:00
|
|
|
NoModify = BIT(12)
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum Compression
|
|
|
|
|
{
|
2014-04-06 22:03:52 +00:00
|
|
|
NONE,
|
2017-06-23 16:36:20 +00:00
|
|
|
BC1,
|
|
|
|
|
BC2,
|
|
|
|
|
BC3,
|
|
|
|
|
BC4,
|
|
|
|
|
BC5,
|
2012-09-19 15:15:01 +00:00
|
|
|
};
|
|
|
|
|
|
2014-04-06 22:03:52 +00:00
|
|
|
GFXTextureProfile(const String &name, Types type, U32 flags, Compression compression = NONE);
|
2017-06-23 16:36:20 +00:00
|
|
|
// Equality operators
|
|
|
|
|
inline bool operator==(const GFXTextureProfile &in_Cmp) const { return (mName == in_Cmp.mName && mProfile == in_Cmp.mProfile); }
|
|
|
|
|
inline bool operator!=(const GFXTextureProfile &in_Cmp) const { return !(*this == in_Cmp); }
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
|
String getName() const { return mName; };
|
|
|
|
|
Types getType() const { return (Types)(mProfile & (BIT(TypeBits) - 1)); }
|
|
|
|
|
const Compression getCompression() const { return (Compression)((mProfile >> (FlagBits + TypeBits)) & (BIT(CompressionBits + 1) - 1)); };
|
|
|
|
|
|
|
|
|
|
bool testFlag(Flags flag) const
|
|
|
|
|
{
|
|
|
|
|
return (mProfile & (flag << TypeBits)) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mutators
|
|
|
|
|
const U32 getDownscale() const { return mDownscale; }
|
|
|
|
|
void setDownscale(const U32 shift) { mDownscale = shift; }
|
|
|
|
|
void incActiveCopies() { mStats.activeCount++; }
|
|
|
|
|
void decActiveCopies() { AssertFatal( mStats.activeCount != 0, "Ran out of extant copies!"); mStats.activeCount--; }
|
|
|
|
|
|
|
|
|
|
// And static interface...
|
|
|
|
|
static void init();
|
|
|
|
|
static GFXTextureProfile *find(const String &name);
|
|
|
|
|
static void updateStatsForCreation(GFXTextureObject *t);
|
|
|
|
|
static void updateStatsForDeletion(GFXTextureObject *t);
|
|
|
|
|
|
|
|
|
|
/// Collects the total stats for all the profiles which
|
|
|
|
|
/// include any of the flag bits.
|
|
|
|
|
static void collectStats( Flags flags, GFXTextureProfileStats *stats );
|
|
|
|
|
|
|
|
|
|
/// Returns the total profile count in the list.
|
|
|
|
|
static U32 getProfileCount() { return smProfileCount; }
|
|
|
|
|
|
|
|
|
|
/// Returns the head of the profile list.
|
|
|
|
|
static GFXTextureProfile* getHead() { return smHead; }
|
|
|
|
|
|
|
|
|
|
/// Returns the next profile in the list.
|
|
|
|
|
GFXTextureProfile* getNext() const { return mNext; }
|
|
|
|
|
|
|
|
|
|
/// Returns the allocation stats for this texture profile.
|
|
|
|
|
inline const GFXTextureProfileStats& getStats() const { return mStats; }
|
|
|
|
|
|
|
|
|
|
// Helper functions...
|
|
|
|
|
inline bool doStoreBitmap() const { return testFlag(KeepBitmap); }
|
|
|
|
|
inline bool canDownscale() const { return !testFlag(PreserveSize); }
|
|
|
|
|
inline bool isDynamic() const { return testFlag(Dynamic); }
|
|
|
|
|
inline bool isRenderTarget() const { return testFlag(RenderTarget); }
|
|
|
|
|
inline bool isZTarget() const { return testFlag(ZTarget); }
|
|
|
|
|
inline bool isSystemMemory() const { return testFlag(SystemMemory); }
|
|
|
|
|
inline bool noMip() const { return testFlag(NoMipmap); }
|
|
|
|
|
inline bool isPooled() const { return testFlag(Pooled); }
|
|
|
|
|
inline bool canDiscard() const { return !testFlag(NoDiscard); }
|
2017-06-23 16:36:20 +00:00
|
|
|
inline bool isSRGB() const { return testFlag(SRGB); }
|
2025-12-22 10:29:01 +00:00
|
|
|
inline bool isCubeMap() const { return testFlag(CubeMap); }
|
2017-06-23 16:36:20 +00:00
|
|
|
//compare profile flags for equality
|
|
|
|
|
inline bool compareFlags(const GFXTextureProfile& in_Cmp) const{ return (mProfile == in_Cmp.mProfile); }
|
2012-09-19 15:15:01 +00:00
|
|
|
private:
|
|
|
|
|
/// These constants control the packing for the profile; if you add flags, types, or
|
|
|
|
|
/// compression info then make sure these are giving enough bits!
|
|
|
|
|
enum Constants
|
|
|
|
|
{
|
|
|
|
|
TypeBits = 2,
|
2017-06-23 16:36:20 +00:00
|
|
|
FlagBits = 12,
|
2012-09-19 15:15:01 +00:00
|
|
|
CompressionBits = 3,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
String mName; ///< Name of this profile...
|
|
|
|
|
U32 mDownscale; ///< Amount to shift textures of this type down, if any.
|
|
|
|
|
U32 mProfile; ///< Stores a munged version of the profile data.
|
|
|
|
|
U32 mActiveCount; ///< Count of textures of this profile type allocated.
|
|
|
|
|
U32 mActiveTexels; ///< Amount of texelspace currently allocated under this profile.
|
|
|
|
|
U32 mActiveBytes; ///< Amount of storage currently allocated under this profile.
|
|
|
|
|
U32 mAllocatedTextures; ///< Total number of textures allocated under this profile.
|
|
|
|
|
U32 mAllocatedTexels; ///< Total number of texels allocated under this profile.
|
|
|
|
|
U32 mAllocatedBytes; ///< Total number of bytes allocated under this profile.
|
|
|
|
|
|
|
|
|
|
/// The texture profile stats.
|
|
|
|
|
GFXTextureProfileStats mStats;
|
|
|
|
|
|
|
|
|
|
/// The number of profiles in the system.
|
|
|
|
|
static U32 smProfileCount;
|
|
|
|
|
|
|
|
|
|
/// Keep a list of all the profiles.
|
|
|
|
|
GFXTextureProfile *mNext;
|
|
|
|
|
static GFXTextureProfile *smHead;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define GFX_DeclareTextureProfile(name) extern GFXTextureProfile name
|
|
|
|
|
#define GFX_ImplementTextureProfile(name, type, flags, compression) GFXTextureProfile name(#name, type, flags, compression)
|
|
|
|
|
|
2025-12-22 10:29:01 +00:00
|
|
|
// Default 2D Texture profiles
|
2012-09-19 15:15:01 +00:00
|
|
|
// Texture we can render to.
|
2017-06-23 16:36:20 +00:00
|
|
|
GFX_DeclareTextureProfile(GFXRenderTargetProfile);
|
|
|
|
|
GFX_DeclareTextureProfile(GFXRenderTargetSRGBProfile);
|
|
|
|
|
// Standard static diffuse textures
|
|
|
|
|
GFX_DeclareTextureProfile(GFXStaticTextureProfile);
|
|
|
|
|
GFX_DeclareTextureProfile(GFXStaticTextureSRGBProfile);
|
|
|
|
|
// Standard static diffuse textures that are persistent in memory
|
|
|
|
|
GFX_DeclareTextureProfile(GFXTexturePersistentProfile);
|
|
|
|
|
GFX_DeclareTextureProfile(GFXTexturePersistentSRGBProfile);
|
2012-09-19 15:15:01 +00:00
|
|
|
// Texture that resides in system memory - used to copy data to
|
2017-06-23 16:36:20 +00:00
|
|
|
GFX_DeclareTextureProfile(GFXSystemMemTextureProfile);
|
|
|
|
|
// normal map profiles
|
|
|
|
|
GFX_DeclareTextureProfile(GFXNormalMapProfile);
|
|
|
|
|
GFX_DeclareTextureProfile(GFXNormalMapBC3Profile);
|
|
|
|
|
GFX_DeclareTextureProfile(GFXNormalMapBC5Profile);
|
2012-09-19 15:15:01 +00:00
|
|
|
// Depth buffer texture
|
2017-06-23 16:36:20 +00:00
|
|
|
GFX_DeclareTextureProfile(GFXZTargetProfile);
|
2016-04-24 16:36:28 +00:00
|
|
|
// Dynamic Texure
|
|
|
|
|
GFX_DeclareTextureProfile(GFXDynamicTextureProfile);
|
2017-06-23 16:36:20 +00:00
|
|
|
GFX_DeclareTextureProfile(GFXDynamicTextureSRGBProfile);
|
2012-09-19 15:15:01 +00:00
|
|
|
|
2025-12-22 10:29:01 +00:00
|
|
|
// Default Cubemap Texture profiles
|
|
|
|
|
// Dynamic Texure
|
|
|
|
|
GFX_DeclareTextureProfile(GFXDynamicCubemapTextureProfile);
|
|
|
|
|
// Texture we can render to.
|
|
|
|
|
GFX_DeclareTextureProfile(GFXCubemapRenderTargetProfile);
|
|
|
|
|
// Standard static diffuse textures
|
|
|
|
|
GFX_DeclareTextureProfile(GFXCubemapStaticTextureProfile);
|
|
|
|
|
// Standard static diffuse textures that are persistent in memory
|
|
|
|
|
GFX_DeclareTextureProfile(GFXCubemapTexturePersistentProfile);
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
#endif
|