Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public BitmapImage RetrieveImage(UFile filePath)
using (var texTool = new TextureTool())
{
texImage = texTool.Load(filePath, false);
texTool.Decompress(texImage, texImage.Format.IsSRgb);
texTool.Decompress(texImage, texImage.Format.IsSRgb());
if (texImage.Format == PixelFormat.R16G16B16A16_UNorm)
texTool.Convert(texImage, PixelFormat.R8G8B8A8_UNorm);
var image = texTool.ConvertToStrideImage(texImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandC
using (var texImage = texTool.Load(image, Parameters.SRgb))
{
// Rescale image so that it fits the thumbnail asked resolution
texTool.Decompress(texImage, texImage.Format.IsSRgb);
texTool.Decompress(texImage, texImage.Format.IsSRgb());
texTool.Resize(texImage, thumbnailSize.X, thumbnailSize.Y, Filter.Rescaling.Lanczos3);

// Save
Expand Down
4 changes: 2 additions & 2 deletions sources/engine/Stride.Assets.Tests/TexturePackerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ public void TestImageCreationGetAndSet()

var source = Image.New2D(width, height, 1, PixelFormat.R8G8B8A8_UNorm);

Assert.Equal(source.TotalSizeInBytes, PixelFormat.R8G8B8A8_UNorm.SizeInBytes * width * height);
Assert.Equal(source.TotalSizeInBytes, PixelFormat.R8G8B8A8_UNorm.SizeInBytes() * width * height);
Assert.Equal(1, source.PixelBuffer.Count);

Assert.Equal(1, source.Description.MipLevels);
Expand Down Expand Up @@ -777,7 +777,7 @@ public void TestImageDataPointerManipulation()

var source = Image.New2D(width, height, 1, PixelFormat.R8G8B8A8_UNorm);

Assert.Equal(source.TotalSizeInBytes, PixelFormat.R8G8B8A8_UNorm.SizeInBytes * width * height);
Assert.Equal(source.TotalSizeInBytes, PixelFormat.R8G8B8A8_UNorm.SizeInBytes() * width * height);
Assert.Equal(1, source.PixelBuffer.Count);

Assert.Equal(1, source.Description.MipLevels);
Expand Down
2 changes: 1 addition & 1 deletion sources/engine/Stride.Assets/Skyboxes/SkyboxGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static SkyboxResult Compile(SkyboxAsset asset, SkyboxGeneratorContext con
if (textureSize < 64) textureSize = 64;

// TODO: Add support for HDR 32bits
var filteringTextureFormat = skyboxTexture.Format.IsHDR ? skyboxTexture.Format : PixelFormat.R8G8B8A8_UNorm;
var filteringTextureFormat = skyboxTexture.Format.IsHDR() ? skyboxTexture.Format : PixelFormat.R8G8B8A8_UNorm;

//var outputTexture = Texture.New2D(graphicsDevice, 256, 256, skyboxTexture.Format, TextureFlags.ShaderResource | TextureFlags.UnorderedAccess, 6);
using (var outputTexture = Texture.New2D(context.GraphicsDevice, textureSize, textureSize, true, filteringTextureFormat, TextureFlags.ShaderResource | TextureFlags.RenderTarget, 6))
Expand Down
10 changes: 5 additions & 5 deletions sources/engine/Stride.Assets/Textures/TextureHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static PixelFormat DetermineOutputFormat(ImportParameters parameters, Siz
{
case PlatformType.Android:
case PlatformType.iOS:
if (inputImageFormat.IsHDR)
if (inputImageFormat.IsHDR())
{
outputFormat = inputImageFormat;
}
Expand Down Expand Up @@ -304,7 +304,7 @@ public static PixelFormat DetermineOutputFormat(ImportParameters parameters, Siz
{
outputFormat = PixelFormat.BC4_UNorm;
}
else if (inputImageFormat.IsHDR)
else if (inputImageFormat.IsHDR())
{
// BC6H is too slow to compile
//outputFormat = parameters.GraphicsProfile >= GraphicsProfile.Level_11_0 && alphaMode == AlphaFormat.None ? PixelFormat.BC6H_Uf16 : inputImageFormat;
Expand All @@ -314,7 +314,7 @@ public static PixelFormat DetermineOutputFormat(ImportParameters parameters, Siz
}
break;
case GraphicsPlatform.OpenGLES: // OpenGLES on Windows
if (inputImageFormat.IsHDR)
if (inputImageFormat.IsHDR())
{
outputFormat = inputImageFormat;
}
Expand Down Expand Up @@ -452,7 +452,7 @@ public static ResultStatus ImportTextureImageRaw(TextureTool textureTool, TexIma
return ResultStatus.Cancelled;

// Pre-multiply alpha only for relevant formats
if (parameters.PremultiplyAlpha && texImage.Format.Is32bppWithAlpha)
if (parameters.PremultiplyAlpha && texImage.Format.Is32bppWithAlpha())
textureTool.PreMultiplyAlpha(texImage);

if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded
Expand All @@ -462,7 +462,7 @@ public static ResultStatus ImportTextureImageRaw(TextureTool textureTool, TexIma
// Generate mipmaps
if (parameters.GenerateMipmaps)
{
var boxFilteringIsSupported = !texImage.Format.IsSRgb || (MathUtil.IsPow2(targetSize.Width) && MathUtil.IsPow2(targetSize.Height));
var boxFilteringIsSupported = !texImage.Format.IsSRgb() || (MathUtil.IsPow2(targetSize.Width) && MathUtil.IsPow2(targetSize.Height));
textureTool.GenerateMipMaps(texImage, boxFilteringIsSupported? Filter.MipMapGeneration.Box: Filter.MipMapGeneration.Linear);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override void DrawImpl()

public static Texture GenerateCubemap(IServiceRegistry services, RenderDrawContext renderDrawContext, Texture input, int outputSize)
{
var pixelFormat = input.Format.IsHDR ? PixelFormat.R16G16B16A16_Float : input.Format.IsSRgb ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm;
var pixelFormat = input.Format.IsHDR() ? PixelFormat.R16G16B16A16_Float : input.Format.IsSRgb() ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm;
return GenerateCubemap(new CubemapFromTextureRenderer(services, renderDrawContext, input, outputSize, pixelFormat), Vector3.Zero);
}
}
Expand Down
4 changes: 2 additions & 2 deletions sources/engine/Stride.Graphics.Regression/ImageTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static bool CompareImage(Image image, string testFilename)
|| buffer.RowStride != referenceBuffer.RowStride)
return false;

var swapBGR = buffer.Format.IsBgraOrder != referenceBuffer.Format.IsBgraOrder;
var swapBGR = buffer.Format.IsBGRAOrder() != referenceBuffer.Format.IsBGRAOrder();
// For now, we handle only those specific cases
if ((buffer.Format != PixelFormat.R8G8B8A8_UNorm_SRgb && buffer.Format != PixelFormat.B8G8R8A8_UNorm_SRgb)
|| referenceBuffer.Format != PixelFormat.B8G8R8A8_UNorm)
Expand All @@ -74,7 +74,7 @@ public static bool CompareImage(Image image, string testFilename)
return false;
}

bool checkAlpha = buffer.Format.AlphaSizeInBits > 0;
bool checkAlpha = buffer.Format.AlphaSizeInBits() > 0;

// Compare remaining bytes.
int allowedDiff = 2;
Expand Down
8 changes: 4 additions & 4 deletions sources/engine/Stride.Graphics.Tests/TestTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public void TestCopy(GraphicsProfile profile, GraphicsResourceUsage usageSource)
{
foreach (var pixelFormat in pixelFormats)
{
ColorComputer colorComputer = pixelFormat.SizeInBytes == 1
ColorComputer colorComputer = pixelFormat.SizeInBytes() == 1
? ColorComputerR8
: DefaultColorComputer;

Expand Down Expand Up @@ -592,7 +592,7 @@ public void TestCopy(GraphicsProfile profile, GraphicsResourceUsage usageSource)
/// <returns>A byte array containing the generated Texture data.</returns>
private static byte[] CreateDebugTextureData(int width, int height, int mipmaps, int arraySize, PixelFormat format, ColorComputer dataComputer)
{
var formatSize = format.SizeInBytes;
var formatSize = format.SizeInBytes();

var mipmapSize = 0;
for (int i = 0; i < mipmaps; i++)
Expand Down Expand Up @@ -650,7 +650,7 @@ private static byte[] CreateDebugTextureData(int width, int height, int mipmaps,
/// </returns>
private unsafe Texture CreateDebugTexture(GraphicsDevice device, byte[] data, int width, int height, int mipmaps, int arraySize, PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage)
{
var sizeInBytes = format.SizeInBytes;
var sizeInBytes = format.SizeInBytes();

var offset = 0;
var dataBoxes = new DataBox[arraySize * mipmaps];
Expand Down Expand Up @@ -701,7 +701,7 @@ private void CheckDebugTextureData(GraphicsContext graphicsContext, Texture debu
int width, int height, int mipmaps, int arraySize,
PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage, ColorComputer dataComputer)
{
var pixelSize = format.SizeInBytes;
var pixelSize = format.SizeInBytes();

for (int arraySlice = 0; arraySlice < arraySize; arraySlice++)
for (int mipLevel = 0; mipLevel < mipmaps; mipLevel++)
Expand Down
2 changes: 1 addition & 1 deletion sources/engine/Stride.Graphics/Buffer.Typed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static class Typed
/// <returns>A new instance of <see cref="Buffer"/>.</returns>
public static Buffer New(GraphicsDevice device, int elementCount, PixelFormat elementFormat, bool unorderedAccess = false, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
{
return Buffer.New(device, bufferSize: elementCount * elementFormat.SizeInBytes, BufferFlags.ShaderResource | (unorderedAccess ? BufferFlags.UnorderedAccess : BufferFlags.None), elementFormat, usage);
return Buffer.New(device, bufferSize: elementCount * elementFormat.SizeInBytes(), BufferFlags.ShaderResource | (unorderedAccess ? BufferFlags.UnorderedAccess : BufferFlags.None), elementFormat, usage);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void Write(SerializationStream stream)

// Determine whether we can store initial image
StorageHeader.InitialImage = true;
if (Image.Description.Format.IsCompressed)
if (Image.Description.Format.IsCompressed())
{
// Compressed: mips need to be multiple of 4, otherwise we can't do it
var initialImageWidth = Image.PixelBuffers[skippedMipCount].Width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters

// Texture.InitializeFromImpl also increments the reference count when storing the COM pointer;
// compensate with Release() to return the reference count to its previous value
backBuffer.InitializeFromImpl(nativeBackBuffer, Description.BackBufferFormat.IsSRgb);
backBuffer.InitializeFromImpl(nativeBackBuffer, Description.BackBufferFormat.IsSRgb());
nativeBackBuffer.Release();

// Reload should get Back-Buffer from Swap-Chain as well
Expand Down Expand Up @@ -395,7 +395,7 @@ public override void Present()

// Texture.InitializeFromImpl also increments the reference count when storing the COM pointer;
// compensate with Release() to return the reference count to its previous value
backBuffer.InitializeFromImpl(nextBackBuffer, Description.BackBufferFormat.IsSRgb);
backBuffer.InitializeFromImpl(nextBackBuffer, Description.BackBufferFormat.IsSRgb());
nextBackBuffer.Release();
#endif
}
Expand Down Expand Up @@ -440,7 +440,7 @@ public override void OnRecreated()
// Put it in our Back-Buffer Texture
// Texture.InitializeFromImpl also increments the reference count when storing the COM pointer;
// compensate with Release() to return the reference count to its previous value
backBuffer.InitializeFromImpl(backBufferTexture, Description.BackBufferFormat.IsSRgb);
backBuffer.InitializeFromImpl(backBufferTexture, Description.BackBufferFormat.IsSRgb());
backBufferTexture.Release();

backBuffer.LifetimeState = GraphicsResourceLifetimeState.Active;
Expand Down Expand Up @@ -506,7 +506,7 @@ protected override void ResizeBackBuffer(int width, int height, PixelFormat form
// Put it in our Back-Buffer Texture
// Texture.InitializeFromImpl also increments the reference count when storing the COM pointer;
// compensate with Release() to return the reference count to its previous value
backBuffer.InitializeFromImpl(backBufferTexture, Description.BackBufferFormat.IsSRgb);
backBuffer.InitializeFromImpl(backBufferTexture, Description.BackBufferFormat.IsSRgb());
backBufferTexture.Release();

foreach (var childTexture in childrenTextures)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void InitCountAndViewFormat(out int count, ref PixelFormat viewFormat)
{
// TODO: The way to calculate the count is not always correct depending on the ViewFlags...etc.
count = ViewFlags.HasFlag(BufferFlags.RawBuffer) ? Description.SizeInBytes / sizeof(int) :
ViewFlags.HasFlag(BufferFlags.ShaderResource) ? Description.SizeInBytes / viewFormat.SizeInBytes :
ViewFlags.HasFlag(BufferFlags.ShaderResource) ? Description.SizeInBytes / viewFormat.SizeInBytes() :
0;
}
else
Expand Down Expand Up @@ -298,7 +298,7 @@ internal ComPtr<ID3D11RenderTargetView> GetRenderTargetView(PixelFormat pixelFor

Buffer = new()
{
ElementWidth = (uint) (pixelFormat.SizeInBytes * width),
ElementWidth = (uint) (pixelFormat.SizeInBytes() * width),
ElementOffset = 0
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public unsafe partial class Texture
private const int TextureRowPitchAlignment = 1;
private const int TextureSubresourceAlignment = 1;

private int TexturePixelSize => Format.SizeInBytes;
private int TexturePixelSize => Format.SizeInBytes();

private ID3D11RenderTargetView* renderTargetView;
private ID3D11DepthStencilView* depthStencilView;
Expand Down Expand Up @@ -1109,7 +1109,7 @@ private Texture3DDesc ConvertToNativeDescription3D()
private static TextureDescription CheckMipLevels(GraphicsDevice device, ref TextureDescription description)
{
if (device.Features.CurrentProfile < GraphicsProfile.Level_10_0 &&
description.Flags.HasFlag(TextureFlags.DepthStencil) && description.Format.IsCompressed)
description.Flags.HasFlag(TextureFlags.DepthStencil) && description.Format.IsCompressed())
{
description.MipLevelCount = Math.Min(CalculateMipCount(description.Width, description.Height), description.MipLevelCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void InitCountAndViewFormat(out int count, ref PixelFormat viewFormat)
{
// TODO: The way to calculate the count is not always correct depending on the ViewFlags...etc.
count = ViewFlags.HasFlag(BufferFlags.RawBuffer) ? Description.SizeInBytes / sizeof(int) :
ViewFlags.HasFlag(BufferFlags.ShaderResource) ? Description.SizeInBytes / viewFormat.SizeInBytes :
ViewFlags.HasFlag(BufferFlags.ShaderResource) ? Description.SizeInBytes / viewFormat.SizeInBytes() :
0;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public unsafe partial class Texture
private const int TextureRowPitchAlignment = D3D12.TextureDataPitchAlignment;
private const int TextureSubresourceAlignment = D3D12.TextureDataPlacementAlignment;

private int TexturePixelSize => Format.SizeInBytes;
private int TexturePixelSize => Format.SizeInBytes();

/// <summary>
/// A handle to the CPU-accessible Render Target View (RTV) Descriptor.
Expand Down Expand Up @@ -1052,7 +1052,7 @@ private static TextureDescription CheckMipLevels(GraphicsDevice device, ref Text
// TODO: Stale comment?

if (device.Features.CurrentProfile < GraphicsProfile.Level_10_0 &&
!description.Flags.HasFlag(TextureFlags.DepthStencil) && description.Format.IsCompressed)
!description.Flags.HasFlag(TextureFlags.DepthStencil) && description.Format.IsCompressed())
{
description.MipLevelCount = Math.Min(CalculateMipCount(description.Width, description.Height), description.MipLevelCount);
}
Expand Down
2 changes: 1 addition & 1 deletion sources/engine/Stride.Graphics/MeshExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static bool TryGetElement(this VertexDeclaration declaration, string vert
if (currentElementOffset != VertexElement.AppendAligned)
offset = currentElementOffset;

var elementSize = element.Format.SizeInBytes;
var elementSize = element.Format.SizeInBytes();
if (vertexElementUsage == element.SemanticName && semanticIndex == element.SemanticIndex)
{
result = new VertexElementWithOffset(element, offset, elementSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ internal unsafe void CopyScaler2D(Texture sourceTexture, Texture destTexture, Re
// TODO find a better way to detect if sRGB conversion is needed (need to detect if main frame buffer is sRGB or not at init time)
#if STRIDE_GRAPHICS_API_OPENGLES
// If we are copying from an SRgb texture to a non SRgb texture, we use a special SRGb copy shader
bool needSRgbConversion = sourceTexture.Description.Format.IsSRgb && destTexture == GraphicsDevice.WindowProvidedRenderTexture;
bool needSRgbConversion = sourceTexture.Description.Format.IsSRgb() && destTexture == GraphicsDevice.WindowProvidedRenderTexture;
#else
bool needSRgbConversion = false;
#endif
Expand Down
6 changes: 3 additions & 3 deletions sources/engine/Stride.Graphics/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public TextureDimension ViewDimension
/// Gets a value indicating if the Texture is a using a block compress format (BC1, BC2, BC3, BC4, BC5, BC6H, BC7).
/// </summary>
/// <seealso cref="Format"/>
public bool IsBlockCompressed => Description.Format.IsCompressed;
public bool IsBlockCompressed => Description.Format.IsCompressed();

/// <summary>
/// Gets the largestSize of the Texture or Texture View.
Expand Down Expand Up @@ -830,7 +830,7 @@ public unsafe int CalculateWidth<TData>(int mipLevel = 0) where TData : unmanage
{
var mipWidth = CalculateMipSize(Width, mipLevel);

var rowStride = mipWidth * Format.SizeInBytes;
var rowStride = mipWidth * Format.SizeInBytes();
var dataStrideInBytes = mipWidth * sizeof(TData);

var (width, rem) = Math.DivRem(rowStride * mipWidth, dataStrideInBytes);
Expand Down Expand Up @@ -1453,7 +1453,7 @@ public unsafe void SetData<TData>(CommandList commandList, ReadOnlySpan<TData> f
depth = regionToCheck.Depth;
}

var sizePerElement = Format.SizeInBytes;
var sizePerElement = Format.SizeInBytes();

// Compute actual pitch
Image.ComputePitch(Format, width, height, out var rowStride, out var textureDepthStride, out width, out height);
Expand Down
Loading
Loading