Skip to content

Commit

Permalink
[Graphics] - Fixed issue with copying immutable textures to another t…
Browse files Browse the repository at this point in the history
…exture (for some reason this was disabled?)

[Animation] - Fixed issue with animation codec where it would write out specific format values for textures when there was no guarantee that the format would even match for the future texture. This caused an exception when loading a animation with a texture item already attached, but with a different format.
[Animation/Animation Editor] - Fixed a bug where loading an animation without texture view data would cause the keyframe associated with that texture to not display anything if a texture array > 0 was used.
[Animation Editor] - Fixed exception issue when creating an animation without a primary sprite.
  • Loading branch information
Tape-Worm committed Feb 3, 2022
1 parent ac0abfa commit b7d2b32
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 61 deletions.
18 changes: 4 additions & 14 deletions Gorgon/Gorgon.Graphics.Core/Textures/GorgonTexture1D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private void CopyResource(GorgonTexture1D destTexture)
throw new ArgumentException(string.Format(Resources.GORGFX_ERR_TEXTURE_NOT_SAME_TYPE, destTexture.Name, destTexture.ResourceType, ResourceType), nameof(destTexture));
}

if (Usage == ResourceUsage.Immutable)
if (destTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -555,7 +555,7 @@ public void CopyTo(GorgonTexture1D destinationTexture, GorgonRange? sourceRange
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_CANNOT_COPY_SAME_SUBRESOURCE);
}

if (Usage == ResourceUsage.Immutable)
if (destinationTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -692,7 +692,7 @@ public void CopyTo(GorgonTexture2D destinationTexture, GorgonRange? sourceRange
throw new NotSupportedException(string.Format(Resources.GORGFX_ERR_TEXTURE_COPY_CANNOT_CONVERT, destinationTexture.Format, Format));
}

if (Usage == ResourceUsage.Immutable)
if (destinationTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -834,7 +834,7 @@ public void CopyTo(GorgonTexture3D destinationTexture, GorgonRange? sourceRange
throw new NotSupportedException(string.Format(Resources.GORGFX_ERR_TEXTURE_COPY_CANNOT_CONVERT, destinationTexture.Format, Format));
}

if (Usage == ResourceUsage.Immutable)
if (destinationTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -903,11 +903,6 @@ public void CopyTo(GorgonTexture3D destinationTexture, GorgonRange? sourceRange
/// </remarks>
public GorgonTexture1D GetStagingTexture()
{
if (Usage == ResourceUsage.Immutable)
{
throw new GorgonException(GorgonResult.AccessDenied, string.Format(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE));
}

var info = new GorgonTexture1DInfo(_info)
{
Name = $"{Name}_[Staging]",
Expand Down Expand Up @@ -1172,11 +1167,6 @@ public IGorgonImage ToImage(int mipLevel, int? arrayIndex = null)
/// <exception cref="GorgonException">Thrown when this texture has a <see cref="GorgonGraphicsResource.Usage"/> set to <see cref="ResourceUsage.Immutable"/>.</exception>
public IGorgonImage ToImage()
{
if (Usage == ResourceUsage.Immutable)
{
throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE));
}

GorgonTexture1D stagingTexture = this;
GorgonImage image = null;

Expand Down
18 changes: 4 additions & 14 deletions Gorgon/Gorgon.Graphics.Core/Textures/GorgonTexture2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ private void CopyResource(GorgonTexture2D destTexture)
throw new ArgumentException(string.Format(Resources.GORGFX_ERR_TEXTURE_NOT_SAME_TYPE, destTexture.Name, destTexture.ResourceType, ResourceType), nameof(destTexture));
}

if (Usage == ResourceUsage.Immutable)
if (destTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -807,7 +807,7 @@ public void CopyTo(GorgonTexture1D destinationTexture, GorgonRange? sourceRange
throw new NotSupportedException(string.Format(Resources.GORGFX_ERR_TEXTURE_COPY_CANNOT_CONVERT, destinationTexture.Format, Format));
}

if (Usage == ResourceUsage.Immutable)
if (destinationTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -960,7 +960,7 @@ public void CopyTo(GorgonTexture2D destinationTexture, in DX.Rectangle? sourceRe
throw new NotSupportedException(string.Format(Resources.GORGFX_ERR_TEXTURE_COPY_CANNOT_CONVERT, destinationTexture.Format, Format));
}

if (Usage == ResourceUsage.Immutable)
if (destinationTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -1117,7 +1117,7 @@ public void CopyTo(GorgonTexture3D destinationTexture, in DX.Rectangle? sourceRe
throw new NotSupportedException(string.Format(Resources.GORGFX_ERR_TEXTURE_COPY_CANNOT_CONVERT, destinationTexture.Format, Format));
}

if (Usage == ResourceUsage.Immutable)
if (destinationTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -1296,11 +1296,6 @@ public void ResolveTo(GorgonTexture2D destination, BufferFormat resolveFormat =
/// </remarks>
public GorgonTexture2D GetStagingTexture()
{
if (Usage == ResourceUsage.Immutable)
{
throw new GorgonException(GorgonResult.AccessDenied, string.Format(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE));
}

var info = new GorgonTexture2DInfo(_info)
{
Name = $"{Name}_[Staging]",
Expand Down Expand Up @@ -1594,11 +1589,6 @@ public IGorgonImage ToImage(int mipLevel, int? arrayIndex = null)
/// <exception cref="GorgonException">Thrown when this texture has a <see cref="GorgonGraphicsResource.Usage"/> set to <see cref="ResourceUsage.Immutable"/>.</exception>
public IGorgonImage ToImage()
{
if (Usage == ResourceUsage.Immutable)
{
throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE));
}

GorgonTexture2D stagingTexture = this;
GorgonImage image = null;

Expand Down
18 changes: 4 additions & 14 deletions Gorgon/Gorgon.Graphics.Core/Textures/GorgonTexture3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ private void CopyResource(GorgonTexture3D destTexture)
throw new ArgumentException(string.Format(Resources.GORGFX_ERR_TEXTURE_NOT_SAME_TYPE, destTexture.Name, destTexture.ResourceType, ResourceType), nameof(destTexture));
}

if (Usage == ResourceUsage.Immutable)
if (destTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -633,7 +633,7 @@ public void CopyTo(GorgonTexture1D destinationTexture, GorgonRange? sourceRange
throw new NotSupportedException(string.Format(Resources.GORGFX_ERR_TEXTURE_COPY_CANNOT_CONVERT, destinationTexture.Format, Format));
}

if (Usage == ResourceUsage.Immutable)
if (destinationTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -777,7 +777,7 @@ public void CopyTo(GorgonTexture2D destinationTexture, in DX.Rectangle? sourceRe
throw new NotSupportedException(string.Format(Resources.GORGFX_ERR_TEXTURE_COPY_CANNOT_CONVERT, destinationTexture.Format, Format));
}

if (Usage == ResourceUsage.Immutable)
if (destinationTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -950,7 +950,7 @@ public void CopyTo(GorgonTexture3D destinationTexture, in DX.Rectangle? sourceRe
throw new NotSupportedException(string.Format(Resources.GORGFX_ERR_TEXTURE_COPY_CANNOT_CONVERT, destinationTexture.Format, Format));
}

if (Usage == ResourceUsage.Immutable)
if (destinationTexture.Usage == ResourceUsage.Immutable)
{
throw new NotSupportedException(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE);
}
Expand Down Expand Up @@ -1026,11 +1026,6 @@ public void CopyTo(GorgonTexture3D destinationTexture, in DX.Rectangle? sourceRe
/// </remarks>
public GorgonTexture3D GetStagingTexture()
{
if (Usage == ResourceUsage.Immutable)
{
throw new GorgonException(GorgonResult.AccessDenied, string.Format(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE));
}

#if NET6_0_OR_GREATER
GorgonTexture3DInfo info = _info with
{
Expand Down Expand Up @@ -1261,11 +1256,6 @@ public void SetData(IGorgonImageBuffer imageBuffer, in DX.Rectangle? destRectang
/// </remarks>
public IGorgonImage ToImage(int mipLevel, int? depthSlice = null)
{
if (Usage == ResourceUsage.Immutable)
{
throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_ERR_TEXTURE_IMMUTABLE));
}

GorgonTexture3D stagingTexture = this;
GorgonImage image = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using Gorgon.Graphics;
using Gorgon.Graphics.Core;
using Gorgon.IO.Properties;
using Gorgon.Math;
using Gorgon.Renderers;
using DX = SharpDX;

Expand Down Expand Up @@ -132,7 +133,20 @@ private GorgonTexture2DView LoadTexture(GorgonBinaryReader reader, out string te
// Locate the texture resource.
GorgonTexture2D texture = Renderer.Graphics.Locate2DTextureByName(textureName, textureWidth, textureHeight, textureFormat, textureArrayCount, textureMipCount);

return texture?.GetShaderResourceView(viewFormat, viewMipSlice, viewMipCount, viewArrayIndex, viewArrayCount);
if (viewArrayCount == -1)
{
viewArrayCount = texture.ArrayCount;
}

if (viewMipCount == -1)
{
viewMipCount = texture.MipLevels;
}

return texture?.GetShaderResourceView(viewFormat, viewMipSlice.Max(0).Min(texture.MipLevels - 1),
viewMipCount.Max(1).Min(texture.MipLevels),
viewArrayIndex.Max(0).Min(texture.ArrayCount - 1),
viewArrayCount.Max(1).Min(texture.ArrayCount));
}

/// <summary>
Expand Down Expand Up @@ -211,14 +225,14 @@ private void WriteTextureTrackValues(GorgonChunkFileWriter writer, ulong chunkID
// If we don't have any texture reference, write out default values.
binWriter.Write(0);
binWriter.Write(0);
binWriter.WriteValue(BufferFormat.R8G8B8A8_UNorm);
binWriter.Write(1);
binWriter.Write(1);
binWriter.WriteValue(BufferFormat.Unknown);
binWriter.Write(-1);
binWriter.Write(-1);
binWriter.Write(0);
binWriter.Write(1);
binWriter.Write(-1);
binWriter.Write(0);
binWriter.Write(1);
binWriter.WriteValue(BufferFormat.R8G8B8A8_UNorm);
binWriter.Write(-1);
binWriter.WriteValue(BufferFormat.Unknown);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ internal static class GorgonGraphicExtensions
/// <param name="width">The width of the texture to locate.</param>
/// <param name="height">The height of the texture to locate.</param>
/// <param name="format">The format of the texture to locate.</param>
/// <param name="arrayCount">The number of array indices in the texture to locate.</param>
/// <param name="mipCount">The number of mip map levels in the texture to locate.</param>
/// <param name="arrayCount">The number of array indices in the texture to locate. Pass -1 to ignore.</param>
/// <param name="mipCount">The number of mip map levels in the texture to locate. Pass -1 to ignore.</param>
/// <returns>The texture resource if found, or <b>null</b> if not.</returns>
public static GorgonTexture2D Locate2DTextureByName(this GorgonGraphics graphics, string textureName, int width, int height, BufferFormat format, int arrayCount, int mipCount)
{
Expand Down Expand Up @@ -75,8 +75,8 @@ public static GorgonTexture2D Locate2DTextureByName(this GorgonGraphics graphics
if ((texture.Width == width)
&& (texture.Height == height)
&& (texture.Format == format)
&& (texture.ArrayCount == arrayCount)
&& (texture.MipLevels == mipCount))
&& ((arrayCount < 1) || (texture.ArrayCount == arrayCount))
&& ((mipCount < 1) || (texture.MipLevels == mipCount)))
{
return texture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ RecyclableMemoryStream CreateAnimation(string name, float length, float fps, ICo
if ((!string.IsNullOrWhiteSpace(texturePath)) && (ContentFileManager.FileExists(texturePath)))
{
if (_settings.AddTextureTrackForPrimarySprite)
{
{
builder.Edit2DTexture(GorgonSpriteAnimationController.TextureTrack.TrackName)
.SetKey(new GorgonKeyTexture2D(0, texturePath, sprite.TextureRegion, sprite.TextureArrayIndex))
.EndEdit();
Expand Down Expand Up @@ -1212,7 +1212,7 @@ protected async override Task<IEditorContent> OnOpenContentAsync(IContentFile fi
GetKeys(animation, tracks, fileManager, maxKeyCount);

IEnumerable<ITrack> textureTracks = tracks.Where(item => (item.ID == GorgonSpriteAnimationController.TextureTrack.ID)
&& (item.KeyFrames.Any(item2 => item2 is not null)));
&& (item.KeyFrames.Any(item2 => item2 is not null)));
foreach (ITrack track in textureTracks)
{
await UpdateTextureCacheAsync(track.KeyFrames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private async void FilePrimarySprite_FileEntrySelected(object sender, ContentFil
{
// If we cannot convert, then use a placeholder.
image.Dispose();
PictureSpritePreview.Image = _previewImage = Resources.no_thumb_sprite_64x64;
PictureSpritePreview.Image = _previewImage = (Image)Resources.no_thumb_sprite_64x64.Clone();
return;
}
}
Expand Down Expand Up @@ -318,7 +318,7 @@ private async void FileTextures_FileEntrySelected(object sender, ContentFileEntr
{
// If we cannot convert, then use a placeholder.
image.Dispose();
PictureTexturePreview.Image = _previewImage = Resources.no_thumb_sprite_64x64;
PictureTexturePreview.Image = _previewImage = (Image)Resources.no_thumb_sprite_64x64.Clone();
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ protected override void DrawGizmos()
/// <summary>Function to draw the animation.</summary>
protected override void DrawAnimation()
{
Renderer.Begin();
Renderer.Begin();
Renderer.DrawSprite(Sprite);
Renderer.End();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2171,8 +2171,14 @@ protected override void OnInitialize(AnimationContentParameters injectionParamet
Tracks = injectionParameters.Tracks;
_trackList.AddRange(Tracks);

float x = _primarySprite.sprite.Position.X;
float y = _primarySprite.sprite.Position.Y;
float x = 0;
float y = 0;

if (_primarySprite.sprite is not null)
{
x = _primarySprite.sprite.Position.X;
y = _primarySprite.sprite.Position.Y;
}

if (File.Metadata.Attributes.TryGetValue(AnimationIOService.StartPositionAttrX, out string startX))
{
Expand All @@ -2190,7 +2196,12 @@ protected override void OnInitialize(AnimationContentParameters injectionParamet
_controller.Pause();
}

_primaryStart = PrimarySprite.Position = WorkingSprite.Position = new Vector2(x, y);
_primaryStart = WorkingSprite.Position = new Vector2(x, y);

if (PrimarySprite is not null)
{
PrimarySprite.Position = _primaryStart;
}
}

/// <summary>Function called when the associated view is loaded.</summary>
Expand Down

0 comments on commit b7d2b32

Please sign in to comment.