1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
#pragma once
#include "Runtime/BaseClasses/NamedObject.h"
#include "TextureFormat.h"
#include "TextureSettings.h"
#include "Runtime/GfxDevice/GfxDeviceTypes.h"
#include "Runtime/Utilities/dynamic_array.h"
#include "Runtime/Math/ColorSpaceConversion.h"
#include "Runtime/Modules/ExportModules.h"
#define TRACK_TEXTURE_SIZES (UNITY_EDITOR || ENABLE_PROFILER)
class ImageReference;
namespace ShaderLab { class TexEnv; }
class EXPORT_COREMODULE Texture : public NamedObject
{
protected:
TextureSettings m_TextureSettings;
TextureID m_TexID;
int m_UsageMode;
int m_ColorSpace;
// Used by movie textures so that 0..1 range covers only the
// movie portion. For all other textures this is (1,1).
float m_UVScaleX, m_UVScaleY;
// Texel size. This is 1/size for all textures.
float m_TexelSizeX, m_TexelSizeY;
// TexEnvs that use this texture
dynamic_array<ShaderLab::TexEnv*> m_TexEnvUsers;
public:
REGISTER_DERIVED_ABSTRACT_CLASS (Texture, NamedObject)
Texture(MemLabelId label, ObjectCreationMode mode);
virtual bool MainThreadCleanup();
virtual void Reset ();
virtual void CheckConsistency();
virtual TextureDimension GetDimension () const = 0;
// Blits the textures contents into image.
// Will use the closest matching mipmap.
virtual bool ExtractImage (ImageReference* image, int imageIndex = 0) const = 0;
TextureID GetTextureID() const { return m_TexID; }
TextureUsageMode GetUsageMode() const { return static_cast<TextureUsageMode>(m_UsageMode); }
void SetUsageMode(TextureUsageMode mode);
// The Color space the texture is imported for.
void SetStoredColorSpace(TextureColorSpace space);
// Needed to avoid an odd corner case for srgb cube render textures.
// If a render texture has the apply function called a texture id will be created and
// it will cause an error as it will be the wrong dimension when cubemap is set
// This function sets the stored color space without applying it. It will be applied
// when the create on the cubemap is called.
void SetStoredColorSpaceNoDirtyNoApply(TextureColorSpace space);
TextureColorSpace GetStoredColorSpace() const { return static_cast<TextureColorSpace>(m_ColorSpace); }
// The active color space of the texture
// Depending on if we are in linear or gamma rendering mode, textures will be tagged as sRGB or non-SRGB.
TextureColorSpace GetActiveTextureColorSpace() const { return (GetActiveColorSpace() == kLinearColorSpace) ? GetStoredColorSpace() : kTexColorSpaceLinear; }
#if ENABLE_PROFILER
virtual int GetStorageMemorySize() const = 0;
#endif
virtual TextureID GetUnscaledTextureID() const { return m_TexID; }
// Raw (original) texture size. For NPOT textures these values are NPOT.
virtual int GetDataWidth() const = 0;
virtual int GetDataHeight() const = 0;
// Size as used by GL. In most cases this matches Data width/height, except for NPOT textures
// where this is scaled up to next power of two.
virtual int GetGLWidth() const { return GetDataWidth(); }
virtual int GetGLHeight() const { return GetDataHeight(); }
virtual bool HasMipMap () const = 0;
virtual int CountMipmaps () const = 0;
static void SetMasterTextureLimit (int i, bool reloadTextures = true);
static int GetMasterTextureLimit ();
static void ReloadAll (bool unload = true, bool load = true, bool forceUnloadAll = false);
/// this is at the wrong place
enum { kDisableAniso = 0, kEnableAniso = 1, kForceEnableAniso = 2 };
// Get/Set the global texture anisotrophy levels
static void SetAnisoLimit (int aniso);
static int GetAnisoLimit ();
static void SetGlobalAnisoLimits(int forcedMin, int globalMax);
static Texture* FindTextureByID (TextureID tid)
{
TextureIDMap::iterator it = s_TextureIDMap.find(tid);
return it == s_TextureIDMap.end() ? NULL : it->second;
}
// Set the filtering mode for this texture.
// TextureFilterMode kTexFilterNearest, kTexFilterBilinear, kTexFilterTrilinear
void SetFilterMode( int mode );
int GetFilterMode() const { return m_TextureSettings.m_FilterMode; }
void SetWrapMode (int mode);
int GetWrapMode () const { return m_TextureSettings.m_WrapMode; }
void SetAnisoLevel (int mode);
int GetAnisoLevel () const { return m_TextureSettings.m_Aniso; }
float GetMipMapBias () const { return m_TextureSettings.m_MipBias; }
void SetMipMapBias (float bias);
const TextureSettings& GetSettings() const { return m_TextureSettings; }
TextureSettings& GetSettings() { return m_TextureSettings; }
virtual void ApplySettings();
float GetUVScaleX() const { return m_UVScaleX; }
float GetUVScaleY() const { return m_UVScaleY; }
void SetUVScale( float x, float y ) { m_UVScaleX = x; m_UVScaleY = y; NotifyUVScaleChanged(); }
float GetTexelSizeX() const { return m_TexelSizeX; }
float GetTexelSizeY() const { return m_TexelSizeY; }
void SetTexelSize( float x, float y ) { m_TexelSizeX = x; m_TexelSizeY = y; }
void AddTexEnvUser(ShaderLab::TexEnv* texenv);
void RemoveTexEnvUser(ShaderLab::TexEnv* texenv, size_t index);
virtual bool ShouldIgnoreInGarbageDependencyTracking ();
#if UNITY_EDITOR
void SetAnisoLevelNoDirty (int level);
void SetWrapModeNoDirty (int mode);
void SetMipMapBiasNoDirty (float mipBias);
void SetFilterModeNoDirty (int mode);
virtual bool IgnoreMasterTextureLimit () const;
virtual TextureFormat GetEditorUITextureFormat () const = 0;
#endif
void* GetNativeTexturePtr();
UInt32 GetNativeTextureID();
protected:
void NotifyMipBiasChanged();
void NotifyUVScaleChanged();
// Used when changing master texture mip limit or explicitly reloading/unloading
// all resources.
virtual void UnloadFromGfxDevice(bool forceUnloadAll) = 0;
virtual void UploadToGfxDevice() = 0;
typedef std::map<TextureID, Texture*> TextureIDMap;
static TextureIDMap s_TextureIDMap;
};
|