Fix drawing editor thumbnails when texture used by asset is using dynamic streaming
This commit is contained in:
@@ -47,8 +47,6 @@ namespace FlaxEditor.Content
|
|||||||
_preview = new CubeTexturePreview(false);
|
_preview = new CubeTexturePreview(false);
|
||||||
InitAssetPreview(_preview);
|
InitAssetPreview(_preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: disable streaming for asset during thumbnail rendering (and restore it after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -50,16 +50,12 @@ namespace FlaxEditor.Content
|
|||||||
Offsets = Margin.Zero,
|
Offsets = Margin.Zero,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: disable streaming for asset during thumbnail rendering (and restore it after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool CanDrawThumbnail(ThumbnailRequest request)
|
public override bool CanDrawThumbnail(ThumbnailRequest request)
|
||||||
{
|
{
|
||||||
// Check if asset is streamed enough
|
return ThumbnailsModule.HasMinimumQuality((IESProfile)request.Asset);
|
||||||
var asset = (IESProfile)request.Asset;
|
|
||||||
return asset.ResidentMipLevels >= Mathf.Max(1, (int)(asset.MipLevels * ThumbnailsModule.MinimumRequiredResourcesQuality));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -55,8 +55,6 @@ namespace FlaxEditor.Content
|
|||||||
_preview = new MaterialPreview(false);
|
_preview = new MaterialPreview(false);
|
||||||
InitAssetPreview(_preview);
|
InitAssetPreview(_preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: disable streaming for dependant assets during thumbnail rendering (and restore it after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -99,8 +99,6 @@ namespace FlaxEditor.Content
|
|||||||
_preview = new MaterialPreview(false);
|
_preview = new MaterialPreview(false);
|
||||||
InitAssetPreview(_preview);
|
InitAssetPreview(_preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: disable streaming for dependant assets during thumbnail rendering (and restore it after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ namespace FlaxEditor.Content
|
|||||||
};
|
};
|
||||||
InitAssetPreview(_preview);
|
InitAssetPreview(_preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: disable streaming for asset during thumbnail rendering (and restore it after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -113,8 +113,6 @@ namespace FlaxEditor.Content
|
|||||||
_preview = new PrefabPreview(false);
|
_preview = new PrefabPreview(false);
|
||||||
InitAssetPreview(_preview);
|
InitAssetPreview(_preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: disable streaming for asset during thumbnail rendering (and restore it after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -125,6 +123,7 @@ namespace FlaxEditor.Content
|
|||||||
|
|
||||||
// Check if asset is streamed enough
|
// Check if asset is streamed enough
|
||||||
var asset = (Prefab)request.Asset;
|
var asset = (Prefab)request.Asset;
|
||||||
|
// TODO: check all prefab actors to have loaded resources (models/textures/etc.)
|
||||||
return asset.IsLoaded;
|
return asset.IsLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,8 +101,6 @@ namespace FlaxEditor.Content
|
|||||||
_preview = new AnimatedModelPreview(false);
|
_preview = new AnimatedModelPreview(false);
|
||||||
InitAssetPreview(_preview);
|
InitAssetPreview(_preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: disable streaming for asset during thumbnail rendering (and restore it after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -50,16 +50,12 @@ namespace FlaxEditor.Content
|
|||||||
Offsets = Margin.Zero,
|
Offsets = Margin.Zero,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: disable streaming for asset during thumbnail rendering (and restore it after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool CanDrawThumbnail(ThumbnailRequest request)
|
public override bool CanDrawThumbnail(ThumbnailRequest request)
|
||||||
{
|
{
|
||||||
// Check if asset is streamed enough
|
return ThumbnailsModule.HasMinimumQuality((SpriteAtlas)request.Asset);
|
||||||
var asset = (SpriteAtlas)request.Asset;
|
|
||||||
return asset.ResidentMipLevels >= Mathf.Max(1, (int)(asset.MipLevels * ThumbnailsModule.MinimumRequiredResourcesQuality));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ namespace FlaxEditor.Content
|
|||||||
Offsets = Margin.Zero,
|
Offsets = Margin.Zero,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: disable streaming for asset during thumbnail rendering (and restore it after)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -122,39 +122,43 @@ namespace FlaxEditor.Content.Thumbnails
|
|||||||
|
|
||||||
internal static bool HasMinimumQuality(TextureBase asset)
|
internal static bool HasMinimumQuality(TextureBase asset)
|
||||||
{
|
{
|
||||||
|
// Don't block thumbnails queue when texture fails to stream in (eg. unsupported format)
|
||||||
if (asset.HasStreamingError)
|
if (asset.HasStreamingError)
|
||||||
return true; // Don't block thumbnails queue when texture fails to stream in (eg. unsupported format)
|
return true;
|
||||||
|
|
||||||
|
// Check if enough mip levels are loaded
|
||||||
var mipLevels = asset.MipLevels;
|
var mipLevels = asset.MipLevels;
|
||||||
var minMipLevels = Mathf.Min(mipLevels, 7);
|
var minMipLevels = Mathf.Min(mipLevels, 7);
|
||||||
return asset.IsLoaded && asset.ResidentMipLevels >= Mathf.Max(minMipLevels, (int)(mipLevels * MinimumRequiredResourcesQuality));
|
if (asset.IsLoaded && asset.ResidentMipLevels >= Mathf.Max(minMipLevels, (int)(mipLevels * MinimumRequiredResourcesQuality)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Inform streaming about resource usage to stream it in for the thumbnail
|
||||||
|
asset.SetStreamingVisible();
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool HasMinimumQuality(Model asset)
|
internal static bool HasMinimumQuality(ModelBase asset)
|
||||||
{
|
{
|
||||||
if (!asset.IsLoaded)
|
if (!asset.IsLoaded)
|
||||||
return false;
|
return false;
|
||||||
var lods = asset.LODs.Length;
|
var lods = asset.LODsCount;
|
||||||
var slots = asset.MaterialSlots;
|
var slots = asset.MaterialSlots;
|
||||||
foreach (var slot in slots)
|
|
||||||
{
|
|
||||||
if (slot.Material && !HasMinimumQuality(slot.Material))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return asset.LoadedLODs >= Mathf.Max(1, (int)(lods * MinimumRequiredResourcesQuality));
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static bool HasMinimumQuality(SkinnedModel asset)
|
// Check if all materials are loaded (incl. dependent resources)
|
||||||
{
|
|
||||||
var lods = asset.LODs.Length;
|
|
||||||
if (asset.IsLoaded && lods == 0)
|
|
||||||
return true; // Skeleton-only model
|
|
||||||
var slots = asset.MaterialSlots;
|
|
||||||
foreach (var slot in slots)
|
foreach (var slot in slots)
|
||||||
{
|
{
|
||||||
if (slot.Material && !HasMinimumQuality(slot.Material))
|
if (slot.Material && !HasMinimumQuality(slot.Material))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return asset.LoadedLODs >= Mathf.Max(1, (int)(lods * MinimumRequiredResourcesQuality));
|
|
||||||
|
// Check if enough LODs are loaded
|
||||||
|
if (asset.LoadedLODs >= Mathf.Max(1, (int)(lods * MinimumRequiredResourcesQuality)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// TODO: impl SetStreamingVisible for models similar to textures (ModelsStreamingHandler needs to use it)
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool HasMinimumQuality(MaterialBase asset)
|
internal static bool HasMinimumQuality(MaterialBase asset)
|
||||||
|
|||||||
@@ -302,6 +302,12 @@ bool TextureBase::HasStreamingError() const
|
|||||||
return _texture.Streaming.Error;
|
return _texture.Streaming.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextureBase::SetStreamingVisible() const
|
||||||
|
{
|
||||||
|
if (_texture.GetTexture())
|
||||||
|
_texture.GetTexture()->LastRenderTime = Platform::GetTimeSeconds();
|
||||||
|
}
|
||||||
|
|
||||||
BytesContainer TextureBase::GetMipData(int32 mipIndex, int32& rowPitch, int32& slicePitch)
|
BytesContainer TextureBase::GetMipData(int32 mipIndex, int32& rowPitch, int32& slicePitch)
|
||||||
{
|
{
|
||||||
BytesContainer result;
|
BytesContainer result;
|
||||||
|
|||||||
@@ -153,6 +153,11 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
API_PROPERTY() bool HasStreamingError() const;
|
API_PROPERTY() bool HasStreamingError() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the texture as visible this frame to inform streaming about usage which will stream boost its priority for the streaming.
|
||||||
|
/// </summary>
|
||||||
|
API_FUNCTION() void SetStreamingVisible() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the mip data.
|
/// Gets the mip data.
|
||||||
|
|||||||
Reference in New Issue
Block a user