Skip to content

Commit

Permalink
fix Camera3D.AspectRatio -1
Browse files Browse the repository at this point in the history
The camera is updated now with the display settings, retrieving the correct screen size.
  • Loading branch information
MarcosCobena committed Jul 18, 2023
1 parent f7cdc6f commit faedb3d
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 5 deletions.
209 changes: 209 additions & 0 deletions src/Evergine.Mocks/MockCommandBuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
using Evergine.Common.Graphics;
using Evergine.Common.Graphics.Raytracing;
using Evergine.Mathematics;

namespace Evergine.Mocks
{
internal class MockCommandBuffer : CommandBuffer
{
public override string Name { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

protected override GraphicsContext GraphicsContext => throw new NotImplementedException();

public override void Begin()
{
}

public override void BeginDebugMarker(string label)
{
}

public override void BeginQuery(QueryHeap heap, uint index)
{
throw new NotImplementedException();
}

public override BottomLevelAS BuildRaytracingAccelerationStructure(BottomLevelASDescription blas)
{
throw new NotImplementedException();
}

public override TopLevelAS BuildRaytracingAccelerationStructure(TopLevelASDescription tlas)
{
throw new NotImplementedException();
}

public override void Commit()
{
}

public override void Dispatch(uint groupCountX, uint groupCountY, uint groupCountZ)
{
throw new NotImplementedException();
}

public override void DispatchIndirect(Common.Graphics.Buffer argBuffer, uint offset)
{
throw new NotImplementedException();
}

public override void DispatchRays(DispatchRaysDescription description)
{
throw new NotImplementedException();
}

public override void Dispose()
{
throw new NotImplementedException();
}

public override void Draw(uint vertexCount, uint startVertexLocation = 0)
{
throw new NotImplementedException();
}

public override void DrawIndexed(uint indexCount, uint startIndexLocation = 0, uint baseVertexLocation = 0)
{
throw new NotImplementedException();
}

public override void DrawIndexedInstanced(uint indexCountPerInstance, uint instanceCount, uint startIndexLocation = 0, uint baseVertexLocation = 0, uint startInstanceLocation = 0)
{
throw new NotImplementedException();
}

public override void DrawIndexedInstancedIndirect(Common.Graphics.Buffer argBuffer, uint offset, uint drawCount, uint stride)
{
throw new NotImplementedException();
}

public override void DrawInstanced(uint vertexCountPerInstance, uint instanceCount, uint startVertexLocation = 0, uint startInstanceLocation = 0)
{
throw new NotImplementedException();
}

public override void DrawInstancedIndirect(Common.Graphics.Buffer argBuffer, uint offset, uint drawCount, uint stride)
{
throw new NotImplementedException();
}

public override void EndDebugMarker()
{
}

public override void EndQuery(QueryHeap heap, uint index)
{
throw new NotImplementedException();
}

public override void GenerateMipmaps(Texture texture)
{
throw new NotImplementedException();
}

public override void InsertDebugMarker(string label)
{
throw new NotImplementedException();
}

public override void Reset()
{
throw new NotImplementedException();
}

public override void ResourceBarrierUnorderedAccessView(Common.Graphics.Buffer buffer)
{
throw new NotImplementedException();
}

public override void ResourceBarrierUnorderedAccessView(Texture texture)
{
throw new NotImplementedException();
}

public override void SetIndexBuffer(Common.Graphics.Buffer buffer, IndexFormat format = IndexFormat.UInt16, uint offset = 0)
{
throw new NotImplementedException();
}

public override void SetResourceSet(ResourceSet resourceSet, uint index = 0, uint[] constantBufferOffsets = null!)
{
throw new NotImplementedException();
}

public override void SetScissorRectangles(Rectangle[] rectangles)
{
}

public override void SetVertexBuffer(uint slot, Common.Graphics.Buffer buffer, uint offset)
{
throw new NotImplementedException();
}

public override void SetVertexBuffers(Common.Graphics.Buffer[] buffers, int[] offsets)
{
throw new NotImplementedException();
}

public override void SetViewports(Viewport[] viewports)
{
}

public override void UpdateRaytracingAccelerationStructure(ref TopLevelAS tlas, TopLevelASDescription newDescription)
{
throw new NotImplementedException();
}

public override void WriteTimestamp(QueryHeap heap, uint index)
{
throw new NotImplementedException();
}

protected override void BeginRenderPassInternal(ref RenderPassDescription description)
{
}

protected override void Blit(Texture source, uint sourceX, uint sourceY, uint sourceZ, uint sourceMipLevel, uint sourceBasedArrayLayer, Texture destination, uint destinationX, uint destinationY, uint destinationZ, uint destinationMipLevel, uint destinationBasedArrayLayer, uint layerCount)
{
throw new NotImplementedException();
}

protected override void CopyBufferDataToInternal(Common.Graphics.Buffer origin, Common.Graphics.Buffer destination, uint sizeInBytes, uint sourceOffset = 0, uint destinationOffset = 0)
{
throw new NotImplementedException();
}

protected override void CopyTextureDataToInternal(Texture source, uint sourceX, uint sourceY, uint sourceZ, uint sourceMipLevel, uint sourceBasedArrayLayer, Texture destination, uint destinationX, uint destinationY, uint destinationZ, uint destinationMipLevel, uint destinationBasedArrayLayer, uint width, uint height, uint depth, uint layerCount)
{
throw new NotImplementedException();
}

protected override void EndInternal()
{
}

protected override void EndRenderPassInternal()
{
}

protected override void SetComputePipelineStateInternal(ComputePipelineState pipeline)
{
throw new NotImplementedException();
}

protected override void SetGraphicsPipelineStateInternal(GraphicsPipelineState pipeline)
{
throw new NotImplementedException();
}

protected override void SetRaytracingPipelineStateInternal(RaytracingPipelineState pipeline)
{
throw new NotImplementedException();
}

protected override void UpdateBufferDataInternal(Common.Graphics.Buffer buffer, IntPtr source, uint sourceSizeInBytes, uint destinationOffsetInBytes = 0)
{
throw new NotImplementedException();
}
}
}
2 changes: 1 addition & 1 deletion src/Evergine.Mocks/MockCommandQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public MockCommandQueue(CommandQueueType commandQueueType)

public override CommandBuffer CommandBuffer()
{
throw new NotImplementedException();
return new MockCommandBuffer();
}

public override void Dispose()
Expand Down
28 changes: 28 additions & 0 deletions src/Evergine.Mocks/MockFrameBuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Evergine.Common.Graphics;

namespace Evergine.Mocks
{
internal class MockFrameBuffer : FrameBuffer
{
public override string Name
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}

public override bool RequireFlipProjection => false;

public MockFrameBuffer(FrameBufferAttachment? depthTarget, FrameBufferAttachment[] colorTargets)
{
this.DepthStencilTarget = depthTarget;
this.ColorTargets = colorTargets;

if (depthTarget.HasValue)
{
var textureDescription = depthTarget.Value.Texture.Description;
this.Width = textureDescription.Width;
this.Height = textureDescription.Height;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Evergine.Mocks/MockGraphicsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void CreateDeviceInternal()

public override SwapChain CreateSwapChain(SwapChainDescription description)
{
return new MockSwapChain(description);
return new MockSwapChain(this, description);
}

public override bool GenerateTextureMipmapping(Texture texture)
Expand Down
2 changes: 1 addition & 1 deletion src/Evergine.Mocks/MockGraphicsContextCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal class MockGraphicsContextCapabilities : GraphicsContextCapabilities
{
public override bool IsComputeShaderSupported => false;

public override bool FlipProjectionRequired => throw new NotImplementedException();
public override bool FlipProjectionRequired => false;

public override MatrixMajorness MatrixMajorness => throw new NotImplementedException();

Expand Down
2 changes: 1 addition & 1 deletion src/Evergine.Mocks/MockResourceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override ComputePipelineState CreateComputePipelineInternal(ref Comput

protected override FrameBuffer CreateFrameBufferInternal(FrameBufferAttachment? depthTarget, FrameBufferAttachment[] colorTargets, bool disposeAttachments)
{
throw new NotImplementedException();
return new MockFrameBuffer(depthTarget, colorTargets);
}

protected override GraphicsPipelineState CreateGraphicsPipelineInternal(ref GraphicsPipelineDescription description)
Expand Down
6 changes: 5 additions & 1 deletion src/Evergine.Mocks/MockSwapChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ namespace Evergine.Mocks
{
internal class MockSwapChain : SwapChain
{
public MockSwapChain(SwapChainDescription swapChainDescription)
public MockSwapChain(GraphicsContext graphicsContext, SwapChainDescription swapChainDescription)
{
this.GraphicsContext = graphicsContext;
this.FrameBuffer = this.GraphicsContext.Factory.CreateFrameBuffer(
swapChainDescription.Width,
swapChainDescription.Height);
}

public override string Name { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
Expand Down
2 changes: 2 additions & 0 deletions src/Evergine.Mocks/MockWindowsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static MockWindowsSystem Create(Application application, Scene scene)
DepthStencilTargetFlags = TextureFlags.DepthStencil,
SampleCount = TextureSampleCount.None,
RefreshRate = 60,
Width = width,
Height = height,
};
var swapChain = graphicsContext.CreateSwapChain(swapChainDescription);
var graphicsPresenter = application.Container.Resolve<GraphicsPresenter>();
Expand Down
39 changes: 39 additions & 0 deletions src/Sample/Sample.Tests/Camera3dShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Evergine.Framework;
using Evergine.Framework.Graphics;
using Evergine.Mocks;
using System;
using Xunit;

namespace Sample.Tests
{
public class Camera3dShould
{
private readonly Camera3D camera3d;

private readonly MockWindowsSystem windowsSystem;

public Camera3dShould()
{
this.camera3d = new Camera3D();
var entity = new Entity()
.AddComponent(new Transform3D())
.AddComponent(this.camera3d);
var scene = new MockScene();
scene.Add(entity);
var application = new MyApplication();
this.windowsSystem = MockWindowsSystem.Create(application, scene);
}

[Fact]
public void ProvideValidAspectRatio()
{
// Arrange

// Act
this.windowsSystem.RunOneLoop(TimeSpan.FromSeconds(1d / 60));

// Assert
Assert.NotEqual(-1, this.camera3d.AspectRatio);
}
}
}

0 comments on commit faedb3d

Please sign in to comment.