diff --git a/.github/workflows/sync-bot.yml b/.github/workflows/sync-bot.yml index 91f2d0423..46ce3b938 100644 --- a/.github/workflows/sync-bot.yml +++ b/.github/workflows/sync-bot.yml @@ -13,7 +13,7 @@ on: jobs: sync_bot: - name: Sync Bot Status Check + name: Sync Bot if: ${{ !github.event.issue.pull_request }} runs-on: ubuntu-latest steps: @@ -32,7 +32,7 @@ jobs: Write-Host "::notice::Issue: $issueNumber"; if ($manuallyExecuted -and $issueNumber -eq "0") { - Write-Host "::notice::The issue or PR number must be a value greater than 0."; + Write-Host "::error::The issue or PR number must be a value greater than 0."; exit 1; } @@ -40,12 +40,13 @@ jobs: 1. Organization name 2. Project name 3. Issue number - 4. Event Type - set to issue event type + 4. Event type - set to issue event type 5. PAT #> deno run ` --allow-net ` "$scriptUrl" ` + "${{ vars.ORGANIZATION_NAME }}" ` "${{ vars.PROJECT_NAME }}" ` "$issueNumber" ` "issue" ` diff --git a/Testing/VelaptorTesting/MainWindow.cs b/Testing/VelaptorTesting/MainWindow.cs index 6aa3763a2..76e6ce4d9 100644 --- a/Testing/VelaptorTesting/MainWindow.cs +++ b/Testing/VelaptorTesting/MainWindow.cs @@ -7,10 +7,11 @@ namespace VelaptorTesting; using System.Collections.Generic; using System.Drawing; using System.Linq; +using System.Text; using Scenes; using Velaptor; +using Velaptor.Batching; using Velaptor.Factories; -using Velaptor.Graphics.Renderers; using Velaptor.Input; using Velaptor.UI; @@ -28,6 +29,7 @@ public class MainWindow : Window private readonly IAppInput keyboard; private readonly Button nextButton; private readonly Button previousButton; + private readonly IBatcher batcher; private KeyboardState prevKeyState; /// @@ -35,12 +37,15 @@ public class MainWindow : Window /// public MainWindow() { + var rendererFactory = new RendererFactory(); + this.batcher = rendererFactory.CreateBatcher(); + this.keyboard = InputFactory.CreateKeyboard(); this.nextButton = new Button { Text = "-->" }; this.previousButton = new Button { Text = "<--" }; - IRenderer.ClearColor = Color.FromArgb(255, 42, 42, 46); + this.batcher.ClearColor = Color.FromArgb(255, 42, 42, 46); var textRenderingScene = new TextRenderingScene { @@ -140,15 +145,12 @@ protected override void OnLoad() this.previousButton.Position = new Point(buttonGroupLeft, buttonTops); this.nextButton.Position = new Point(this.previousButton.Position.X + (int)this.previousButton.Width + buttonSpacing, buttonTops); - SceneManager.LoadContent(); base.OnLoad(); } /// protected override void OnUpdate(FrameTime frameTime) { - SceneManager.Update(frameTime); - Title = $"Scene: {SceneManager.CurrentScene?.Name ?? "No Scene Loaded"}"; var currentKeyState = this.keyboard.GetState(); @@ -174,17 +176,18 @@ protected override void OnUpdate(FrameTime frameTime) /// protected override void OnDraw(FrameTime frameTime) { - IRenderer.Clear(); - IRenderer.Begin(); + base.OnDraw(frameTime); - SceneManager.Render(); + // Render the buttons after the 'base.OnDraw()'. With the rendering being set to auto, + // additional drawings have to be done after the base.OnDraw() call with the use of + // the 'Begin()' and 'End()` methods. + this.batcher.Begin(); // Render the scene manager UI on top of all other textures this.nextButton.Render(); this.previousButton.Render(); - IRenderer.End(); - base.OnDraw(frameTime); + this.batcher.End(); } /// @@ -205,7 +208,7 @@ private static string SplitByUpperCase(string value) { var sections = new List(); - var currentSection = string.Empty; + var currentSection = new StringBuilder(); for (var i = 0; i < value.Length; i++) { @@ -213,18 +216,18 @@ private static string SplitByUpperCase(string value) if (UpperCaseChars.Contains(character) && i != 0) { - sections.Add(currentSection); + sections.Add(currentSection.ToString()); - currentSection = string.Empty; - currentSection += character; + currentSection.Clear(); + currentSection.Append(character); } else { - currentSection += character; + currentSection.Append(character); } } - sections.Add(currentSection); + sections.Add(currentSection.ToString()); var result = sections.Aggregate(string.Empty, (current, section) => current + $"{section} "); diff --git a/Testing/VelaptorTesting/Scenes/TextRenderingScene.cs b/Testing/VelaptorTesting/Scenes/TextRenderingScene.cs index 967927da1..57f3fef92 100644 --- a/Testing/VelaptorTesting/Scenes/TextRenderingScene.cs +++ b/Testing/VelaptorTesting/Scenes/TextRenderingScene.cs @@ -6,6 +6,7 @@ namespace VelaptorTesting.Scenes; using System; using System.Collections.Immutable; +using System.ComponentModel; using System.Drawing; using System.Linq; using Velaptor.Scene; @@ -180,13 +181,15 @@ public override void LoadContent() this.btnSetStyle.MouseUp += (_, _) => { + const string argName = $"{nameof(TextRenderingScene)}.{nameof(this.textFont)}.{nameof(this.textFont.Style)}"; + this.textFont.Style = this.textFont.Style switch { FontStyle.Regular => FontStyle.Bold, FontStyle.Bold => FontStyle.Italic, FontStyle.Italic => FontStyle.Bold | FontStyle.Italic, FontStyle.Bold | FontStyle.Italic => FontStyle.Regular, - _ => throw new ArgumentOutOfRangeException(nameof(this.textFont.Style), "FontStyle value invalid."), + _ => throw new InvalidEnumArgumentException(argName, (int)this.textFont.Style, typeof(FontStyle)), }; this.btnSetStyle.Text = $"Style: {this.textFont.Style}"; @@ -356,7 +359,8 @@ private void LayoutButtonsLeftSide() } var totalHeight = (from b in buttons - select (int)b.Height).ToArray().Sum(); + select (int)b.Height).Sum(); + totalHeight += (buttons.Length - 1) * VertButtonSpacing; var totalHalfHeight = totalHeight / 2; diff --git a/Testing/VelaptorTests/Batching/BatcherTests.cs b/Testing/VelaptorTests/Batching/BatcherTests.cs new file mode 100644 index 000000000..4ccab9a44 --- /dev/null +++ b/Testing/VelaptorTests/Batching/BatcherTests.cs @@ -0,0 +1,309 @@ +// +// Copyright (c) KinsonDigital. All rights reserved. +// + +namespace VelaptorTests.Batching; + +using System; +using System.Drawing; +using Carbonate.Core.NonDirectional; +using Carbonate.NonDirectional; +using Carbonate.UniDirectional; +using FluentAssertions; +using FluentAssertions.Execution; +using NSubstitute; +using Velaptor; +using Velaptor.Batching; +using Velaptor.Graphics.Renderers.Exceptions; +using Velaptor.NativeInterop.OpenGL; +using Velaptor.OpenGL; +using Velaptor.ReactableData; +using Xunit; + +/// +/// Tests the class. +/// +public class BatcherTests +{ + private readonly IGLInvoker mockGLInvoker; + private readonly IPushReactable mockPushReactable; + private readonly IPushReactable mockBatchSizeReactable; + private readonly IDisposable mockUnsubscriber; + private IReceiveReactor? reactor; + + /// + /// Initializes a new instance of the class. + /// + public BatcherTests() + { + this.mockGLInvoker = Substitute.For(); + + this.mockUnsubscriber = Substitute.For(); + + this.mockPushReactable = Substitute.For(); + this.mockPushReactable.Subscribe(Arg.Any()) + .Returns(this.mockUnsubscriber) + .AndDoes((callInfo) => + { + var reactorParam = callInfo.Arg(); + + if (reactorParam is null) + { + const string methodName = $"{nameof(this.mockPushReactable)}.{nameof(IPushReactable)}.{nameof(IPushReactable.Subscribe)}()"; + throw new AssertionFailedException($"The '{methodName}' parameter '{nameof(reactorParam)}' cannot be null."); + } + + this.reactor = reactorParam; + }); + + this.mockBatchSizeReactable = Substitute.For>(); + } + + #region Reactable Tests + [Fact] + public void GLInitSubscription_WhenReceivingNotification_ExecutesCorrectly() + { + // Arrange + _ = CreateSystemUnderTest(); + + // Act + this.reactor.OnReceive(); + this.reactor.OnReceive(); + + // Assert + this.mockGLInvoker.Received(1).Enable(GLEnableCap.Blend); + this.mockGLInvoker.Received(1).BlendFunc(GLBlendingFactor.SrcAlpha, GLBlendingFactor.OneMinusSrcAlpha); + + // Testing the sending of batch size notifications for different batch types + this.mockBatchSizeReactable.Received(1) + .Push(new BatchSizeData { BatchSize = 1000, TypeOfBatch = BatchType.Texture }, PushNotifications.BatchSizeChangedId); + this.mockBatchSizeReactable.Received(1) + .Push(new BatchSizeData { BatchSize = 1000, TypeOfBatch = BatchType.Font }, PushNotifications.BatchSizeChangedId); + this.mockBatchSizeReactable.Received(1) + .Push(new BatchSizeData { BatchSize = 1000, TypeOfBatch = BatchType.Rect }, PushNotifications.BatchSizeChangedId); + this.mockBatchSizeReactable.Received(1) + .Push(new BatchSizeData { BatchSize = 1000, TypeOfBatch = BatchType.Line }, PushNotifications.BatchSizeChangedId); + + this.mockBatchSizeReactable.Received(1).Unsubscribe(PushNotifications.BatchSizeChangedId); + } + + [Fact] + public void GLInitSubscription_WhenUnsubscribing_InvokesUnsubscriber() + { + // Arrange + _ = CreateSystemUnderTest(); + + // Act + this.reactor.OnUnsubscribe(); + this.reactor.OnUnsubscribe(); + + // Assert + this.mockUnsubscriber.Received(1).Dispose(); + } + #endregion + + #region Constructor Tests + [Fact] + public void Ctor_WithNullGLInvokerParam_ThrowsException() + { + // Arrange & Act + var act = () => + { + _ = new Batcher(null, this.mockPushReactable, this.mockBatchSizeReactable); + }; + + // Assert + act.Should() + .Throw() + .WithMessage("Value cannot be null. (Parameter 'glInvoker')"); + } + + [Fact] + public void Ctor_WithNullPushReactableParam_ThrowsException() + { + // Arrange & Act + var act = () => + { + _ = new Batcher(this.mockGLInvoker, null, this.mockBatchSizeReactable); + }; + + // Assert + act.Should() + .Throw() + .WithMessage("Value cannot be null. (Parameter 'pushReactable')"); + } + + [Fact] + public void Ctor_WithNullBatchSizeReactableParam_ThrowsException() + { + // Arrange & Act + var act = () => + { + _ = new Batcher(this.mockGLInvoker, this.mockPushReactable, null); + }; + + // Assert + act.Should() + .Throw() + .WithMessage("Value cannot be null. (Parameter 'batchSizeReactable')"); + } + #endregion + + #region Prop Tests + [Fact] + public void ClearColor_WhenCachingAndSettingValue_ReturnsCorrectResult() + { + // Arrange + // Setup the GLInvoker to return a different color than magenta so we can + // make sure that the cached value is being returned. + var colorValues = new float[4]; + this.mockGLInvoker.When(x => x.GetFloat(GLGetPName.ColorClearValue, colorValues)) + .Do(ci => + { + var values = ci.ArgAt(1); + + values[0] = 1; + values[1] = 0; + values[2] = 1; + values[3] = 1; + }); + + var sut = CreateSystemUnderTest(); + + // Act + sut.ClearColor = Color.Magenta; + + // Assert + sut.ClearColor.Should().Be(Color.Magenta); + } + + [Fact] + public void ClearColor_WhenNotCachingAndSettingValue_ReturnsCorrectResult() + { + // Arrange + // Setup the GLInvoker to return a different color than magenta so we can + // make sure that the cached value is being returned. + this.mockGLInvoker.When(x => x.GetFloat(GLGetPName.ColorClearValue, Arg.Any())) + .Do(ci => + { + var values = ci.ArgAt(1); + + values[0] = 1; + values[1] = 0; + values[2] = 1; + values[3] = 1; + }); + + var sut = CreateSystemUnderTest(); + this.reactor.OnReceive(); + + // Act + sut.ClearColor = Color.Magenta; + var actual = sut.ClearColor; + + // Assert + this.mockGLInvoker.Received(1).ClearColor(1, 0, 1, 1); + this.mockGLInvoker.Received(1).GetFloat(GLGetPName.ColorClearValue, Arg.Any()); + + actual.A.Should().Be(Color.Magenta.A); + actual.R.Should().Be(Color.Magenta.R); + actual.G.Should().Be(Color.Magenta.G); + actual.B.Should().Be(Color.Magenta.B); + } + #endregion + + #region Method Tests + [Fact] + public void Begin_WhenInvokedWithoutBeingInitialized_ThrowsException() + { + // Arrange + var sut = CreateSystemUnderTest(); + + // Act + var act = () => sut.Begin(); + + // Assert + act.Should().Throw() + .WithMessage("The renderer is not initialized."); + } + + [Fact] + public void Begin_WhenInvokedAfterBeingInitialized_SendsBatchBegunNotification() + { + // Arrange + var sut = CreateSystemUnderTest(); + this.reactor.OnReceive(); + + // Act + sut.Begin(); + + // Assert + this.mockPushReactable.Received(1).Push(PushNotifications.BatchHasBegunId); + sut.HasBegun.Should().BeTrue(); + } + + [Fact] + public void Clear_WhenInvokedWithoutBeingInitialized_ThrowsException() + { + // Arrange + var sut = CreateSystemUnderTest(); + + // Act + var act = () => sut.Clear(); + + // Assert + act.Should().Throw() + .WithMessage("The renderer is not initialized."); + } + + [Fact] + public void Clear_WhenInvokedAfterBeingInitialized_SendsBatchBegunNotification() + { + // Arrange + var sut = CreateSystemUnderTest(); + this.reactor.OnReceive(); + + // Act + sut.Clear(); + + // Assert + this.mockGLInvoker.Received(1).Clear(GLClearBufferMask.ColorBufferBit); + } + + [Fact] + public void End_WhenInvokedWithoutBeingInitialized_ThrowsException() + { + // Arrange + var sut = CreateSystemUnderTest(); + + // Act + var act = () => sut.End(); + + // Assert + act.Should().Throw() + .WithMessage("The renderer is not initialized."); + } + + [Fact] + public void End_WhenInvokedAfterBeingInitialized_SendsBatchBegunNotification() + { + // Arrange + var sut = CreateSystemUnderTest(); + this.reactor.OnReceive(); + + // Act + sut.End(); + + // Assert + this.mockPushReactable.Received(1).Push(PushNotifications.BatchHasEndedId); + sut.HasBegun.Should().BeFalse(); + } + #endregion + + /// + /// Creates a new instance of for the purpose of testing. + /// + /// The instance to test. + private Batcher CreateSystemUnderTest() + => new (this.mockGLInvoker, this.mockPushReactable, this.mockBatchSizeReactable); +} diff --git a/Testing/VelaptorTests/Batching/BatchingManagerTests.cs b/Testing/VelaptorTests/Batching/BatchingManagerTests.cs index 94640fd7b..a994086f9 100644 --- a/Testing/VelaptorTests/Batching/BatchingManagerTests.cs +++ b/Testing/VelaptorTests/Batching/BatchingManagerTests.cs @@ -34,14 +34,14 @@ public class BatchingManagerTests private readonly Mock mockShutDownUnsubscriber; private readonly Mock mockTexturePullUnsubscriber; private readonly Mock mockFontPullUnsubscriber; - private readonly Mock mockRectPullUnsubscriber; + private readonly Mock mockShapePullUnsubscriber; private readonly Mock mockLinePullUnsubscriber; private IReceiveReactor? batchSizeReactor; private IReceiveReactor? shutDownReactor; private IReceiveReactor? emptyBatchReactor; private IRespondReactor>>? textureBatchPullReactor; private IRespondReactor>>? fontBatchPullReactor; - private IRespondReactor>>? rectBatchPullReactor; + private IRespondReactor>>? shapeBatchPullReactor; private IRespondReactor>>? lineBatchPullReactor; /// @@ -61,8 +61,8 @@ public BatchingManagerTests() this.mockFontPullUnsubscriber = new Mock(); this.mockFontPullUnsubscriber.Name = nameof(this.mockFontPullUnsubscriber); - this.mockRectPullUnsubscriber = new Mock(); - this.mockRectPullUnsubscriber.Name = nameof(this.mockRectPullUnsubscriber); + this.mockShapePullUnsubscriber = new Mock(); + this.mockShapePullUnsubscriber.Name = nameof(this.mockShapePullUnsubscriber); this.mockLinePullUnsubscriber = new Mock(); this.mockLinePullUnsubscriber.Name = nameof(this.mockLinePullUnsubscriber); @@ -169,26 +169,26 @@ public BatchingManagerTests() return null; }); - var mockRectBatchPullReactable = new Mock>(); - mockRectBatchPullReactable + var mockShapeBatchPullReactable = new Mock>(); + mockShapeBatchPullReactable .Setup(m => m.Subscribe(It.IsAny>>>())) .Callback>>>(reactor => { reactor.Should().NotBeNull("it is required for unit testing."); - if (reactor.Id == PullResponses.GetRectItemsId) + if (reactor.Id == PullResponses.GetShapeItemsId) { - this.rectBatchPullReactor = reactor; + this.shapeBatchPullReactor = reactor; } }) .Returns>>>(reactor => { reactor.Should().NotBeNull("it is required for unit testing."); - reactor.Name.Should().Be($"BatchingManagerTests.Ctor - {nameof(PullResponses.GetRectItemsId)}"); + reactor.Name.Should().Be($"BatchingManagerTests.Ctor - {nameof(PullResponses.GetShapeItemsId)}"); - if (reactor.Id == PullResponses.GetRectItemsId) + if (reactor.Id == PullResponses.GetShapeItemsId) { - return this.mockRectPullUnsubscriber.Object; + return this.mockShapePullUnsubscriber.Object; } Assert.Fail($"The notification ID '{reactor.Id}' has not been properly mocked."); @@ -231,8 +231,8 @@ public BatchingManagerTests() .Returns(mockTextureBatchPullReactable.Object); this.mockReactableFactory.Setup(m => m.CreateFontPullBatchReactable()) .Returns(mockFontBatchPullReactable.Object); - this.mockReactableFactory.Setup(m => m.CreateRectPullBatchReactable()) - .Returns(mockRectBatchPullReactable.Object); + this.mockReactableFactory.Setup(m => m.CreateShapePullBatchReactable()) + .Returns(mockShapeBatchPullReactable.Object); this.mockReactableFactory.Setup(m => m.CreateLinePullBatchReactable()) .Returns(mockLineBatchPullReactable.Object); } @@ -270,7 +270,7 @@ public void PushReactable_WhenReceivingShutDownNotification_ShutDownManager() this.mockShutDownUnsubscriber.VerifyOnce(m => m.Dispose()); this.mockTexturePullUnsubscriber.VerifyOnce(m => m.Dispose()); this.mockFontPullUnsubscriber.VerifyOnce(m => m.Dispose()); - this.mockRectPullUnsubscriber.VerifyOnce(m => m.Dispose()); + this.mockShapePullUnsubscriber.VerifyOnce(m => m.Dispose()); this.mockLinePullUnsubscriber.VerifyOnce(m => m.Dispose()); } @@ -287,7 +287,7 @@ public void PushReactable_WhenReceivingEmptyBatchNotification_EmptiesBatch() var textureItems = BatchItemFactory.CreateTextureItemsWithOrderedValues(totalItems: halfBatchSize); var fontItems = BatchItemFactory.CreateFontItemsWithOrderedValues(totalItems: halfBatchSize); - var rectItems = BatchItemFactory.CreateRectItemsWithOrderedValues(totalItems: halfBatchSize); + var shapeItems = BatchItemFactory.CreateShapeItemsWithOrderedValues(totalItems: halfBatchSize); var lineItems = BatchItemFactory.CreateLineItemsWithOrderedValues(totalItems: halfBatchSize); for (var i = 0; i < textureItems.Length; i++) @@ -300,9 +300,9 @@ public void PushReactable_WhenReceivingEmptyBatchNotification_EmptiesBatch() sut.AddFontItem(fontItems[i], i, DateTime.Now); } - for (var i = 0; i < rectItems.Length; i++) + for (var i = 0; i < shapeItems.Length; i++) { - sut.AddRectItem(rectItems[i], i, DateTime.Now); + sut.AddShapeItem(shapeItems[i], i, DateTime.Now); } for (var i = 0; i < lineItems.Length; i++) @@ -320,7 +320,7 @@ public void PushReactable_WhenReceivingEmptyBatchNotification_EmptiesBatch() sut.FontItems.ToArray().Should().AllSatisfy(expected => expected.Should().BeEquivalentTo(default(RenderItem))); - sut.RectItems.ToArray().Should().AllSatisfy(expected => + sut.ShapeItems.ToArray().Should().AllSatisfy(expected => expected.Should().BeEquivalentTo(default(RenderItem))); sut.LineItems.ToArray().Should().AllSatisfy(expected => @@ -346,8 +346,8 @@ public void BatchSizeReactable_WhenReceivingNotification_SetsUpBatchArrays() sut.FontItems.ToArray().Should() .AllSatisfy(expected => expected.Should().BeEquivalentTo(default(RenderItem))); - sut.RectItems.ToArray().Should().HaveCount(2); - sut.RectItems.ToArray().Should() + sut.ShapeItems.ToArray().Should().HaveCount(2); + sut.ShapeItems.ToArray().Should() .AllSatisfy(expected => expected.Should().BeEquivalentTo(default(RenderItem))); sut.LineItems.ToArray().Should().HaveCount(2); @@ -376,7 +376,7 @@ public void TextureBatchPullReactable_WhenRequestingResponseFromPartiallyEmptyBa // Assert actual.ToArray().Should().HaveCount(2); - actual.ToArray().Select(i => i.Item).ToArray().Should().NotContain(itemC); + actual.ToArray().Select(i => i.Item).Should().NotContain(itemC); actual.ToArray()[0].Layer.Should().Be(1); actual.ToArray()[0].Item.Should().BeEquivalentTo(itemA); @@ -403,7 +403,7 @@ public void FontBatchPullReactable_WhenRequestingResponseFromPartiallyEmptyBatch // Assert actual.ToArray().Should().HaveCount(2); - actual.ToArray().Select(i => i.Item).ToArray().Should().NotContain(itemC); + actual.ToArray().Select(i => i.Item).Should().NotContain(itemC); actual.ToArray()[0].Layer.Should().Be(1); actual.ToArray()[0].Item.Should().BeEquivalentTo(itemA); @@ -412,25 +412,25 @@ public void FontBatchPullReactable_WhenRequestingResponseFromPartiallyEmptyBatch } [Fact] - public void RectBatchPullReactable_WhenRequestingResponseFromPartiallyEmptyBatch_ReturnsCorrectResult() + public void ShapeBatchPullReactable_WhenRequestingResponseFromPartiallyEmptyBatch_ReturnsCorrectResult() { // Arrange var sut = CreateSystemUnderTest(); this.batchSizeReactor.OnReceive(new BatchSizeData { BatchSize = 3 }); - var itemA = BatchItemFactory.CreateRectItemWithOrderedValues(new Vector2(11, 22)); - var itemB = BatchItemFactory.CreateRectItemWithOrderedValues(new Vector2(33, 44)); - var itemC = BatchItemFactory.CreateRectItemWithOrderedValues(new Vector2(55, 66)); + var itemA = BatchItemFactory.CreateShapeItemWithOrderedValues(new Vector2(11, 22)); + var itemB = BatchItemFactory.CreateShapeItemWithOrderedValues(new Vector2(33, 44)); + var itemC = BatchItemFactory.CreateShapeItemWithOrderedValues(new Vector2(55, 66)); - sut.AddRectItem(itemA, 1, DateTime.Now); - sut.AddRectItem(itemB, 2, DateTime.Now); + sut.AddShapeItem(itemA, 1, DateTime.Now); + sut.AddShapeItem(itemB, 2, DateTime.Now); // Act - var actual = this.rectBatchPullReactor.OnRespond(); + var actual = this.shapeBatchPullReactor.OnRespond(); // Assert actual.ToArray().Should().HaveCount(2); - actual.ToArray().Select(i => i.Item).ToArray().Should().NotContain(itemC); + actual.ToArray().Select(i => i.Item).Should().NotContain(itemC); actual.ToArray()[0].Layer.Should().Be(1); actual.ToArray()[0].Item.Should().BeEquivalentTo(itemA); @@ -457,7 +457,7 @@ public void LineBatchPullReactable_WhenRequestingResponseFromPartiallyEmptyBatch // Assert actual.ToArray().Should().HaveCount(2); - actual.ToArray().Select(i => i.Item).ToArray().Should().NotContain(itemC); + actual.ToArray().Select(i => i.Item).Should().NotContain(itemC); actual.ToArray()[0].Layer.Should().Be(1); actual.ToArray()[0].Item.Should().BeEquivalentTo(itemA); @@ -475,9 +475,9 @@ public void AddTextureItem_WithFullBatch_ResizesTextureBatch() var itemB = BatchItemFactory.CreateTextureItemWithOrderedValues(new RectangleF(50, 60, 70, 80)); var itemC = BatchItemFactory.CreateTextureItemWithOrderedValues(new RectangleF(90, 100, 110, 120)); - var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10); - var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20); - var renderStampC = new DateTime(1, 2, 3, 0, 0, 0, 30); + var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10, DateTimeKind.Utc); + var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20, DateTimeKind.Utc); + var renderStampC = new DateTime(1, 2, 3, 0, 0, 0, 30, DateTimeKind.Utc); var expectedA = new RenderItem { Layer = 1, Item = itemA, RenderStamp = renderStampA }; var expectedB = new RenderItem { Layer = 2, Item = itemB, RenderStamp = renderStampB }; @@ -555,8 +555,8 @@ public void AddTextureItem_WhenInvoked_SetsNewBatchItem() var itemA = BatchItemFactory.CreateTextureItemWithOrderedValues(textureId: 123); var itemB = BatchItemFactory.CreateTextureItemWithOrderedValues(textureId: 456); - var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10); - var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20); + var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10, DateTimeKind.Utc); + var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20, DateTimeKind.Utc); // Act sut.AddTextureItem(itemA, 1, renderStampA); @@ -575,9 +575,9 @@ public void AddFontItem_WithFullBatch_ResizesFontBatch() var itemB = BatchItemFactory.CreateFontItemWithOrderedValues(new RectangleF(50, 60, 70, 80)); var itemC = BatchItemFactory.CreateFontItemWithOrderedValues(new RectangleF(90, 100, 110, 120)); - var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10); - var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20); - var renderStampC = new DateTime(1, 2, 3, 0, 0, 0, 30); + var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10, DateTimeKind.Utc); + var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20, DateTimeKind.Utc); + var renderStampC = new DateTime(1, 2, 3, 0, 0, 0, 30, DateTimeKind.Utc); var expectedA = new RenderItem { Layer = 1, Item = itemA, RenderStamp = renderStampA }; var expectedB = new RenderItem { Layer = 2, Item = itemB, RenderStamp = renderStampB }; @@ -622,8 +622,8 @@ public void AddFontItem_WhenInvoked_SetsNewBatchItem() var itemA = BatchItemFactory.CreateFontItemWithOrderedValues(textureId: 123); var itemB = BatchItemFactory.CreateFontItemWithOrderedValues(textureId: 456); - var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10); - var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20); + var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10, DateTimeKind.Utc); + var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20, DateTimeKind.Utc); // Act sut.AddFontItem(itemA, 1, renderStampA); @@ -635,16 +635,16 @@ public void AddFontItem_WhenInvoked_SetsNewBatchItem() } [Fact] - public void AddRectItem_WithFullBatch_ResizesRectBatch() + public void AddShapeItem_WithFullBatch_ResizesShapeBatch() { // Arrange - var itemA = BatchItemFactory.CreateRectItemWithOrderedValues(new Vector2(10, 20)); - var itemB = BatchItemFactory.CreateRectItemWithOrderedValues(new Vector2(30, 40)); - var itemC = BatchItemFactory.CreateRectItemWithOrderedValues(new Vector2(50, 60)); + var itemA = BatchItemFactory.CreateShapeItemWithOrderedValues(new Vector2(10, 20)); + var itemB = BatchItemFactory.CreateShapeItemWithOrderedValues(new Vector2(30, 40)); + var itemC = BatchItemFactory.CreateShapeItemWithOrderedValues(new Vector2(50, 60)); - var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10); - var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20); - var renderStampC = new DateTime(1, 2, 3, 0, 0, 0, 30); + var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10, DateTimeKind.Utc); + var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20, DateTimeKind.Utc); + var renderStampC = new DateTime(1, 2, 3, 0, 0, 0, 30, DateTimeKind.Utc); var expectedA = new RenderItem { Layer = 1, Item = itemA, RenderStamp = renderStampA }; var expectedB = new RenderItem { Layer = 2, Item = itemB, RenderStamp = renderStampB }; @@ -661,44 +661,44 @@ public void AddRectItem_WithFullBatch_ResizesRectBatch() // Initialize batch size this.batchSizeReactor.OnReceive(new BatchSizeData { BatchSize = 2, TypeOfBatch = BatchType.Rect }); - sut.AddRectItem(itemA, 1, renderStampA); - sut.AddRectItem(itemB, 2, renderStampB); + sut.AddShapeItem(itemA, 1, renderStampA); + sut.AddShapeItem(itemB, 2, renderStampB); // Act - sut.AddRectItem(itemC, 3, renderStampC); + sut.AddShapeItem(itemC, 3, renderStampC); // Assert - sut.RectItems.ToArray().Should().HaveCount(3, "the total number of items should of increased."); + sut.ShapeItems.ToArray().Should().HaveCount(3, "the total number of items should of increased."); - sut.RectItems.ToArray().Should().Contain(expectedA); - sut.RectItems[0].Should().BeEquivalentTo(expectedA, "the previously added items should be in the same order."); + sut.ShapeItems.ToArray().Should().Contain(expectedA); + sut.ShapeItems[0].Should().BeEquivalentTo(expectedA, "the previously added items should be in the same order."); - sut.RectItems.ToArray().Should().Contain(expectedB); - sut.RectItems[1].Should().BeEquivalentTo(expectedB, "the previously added items should be in the same order."); + sut.ShapeItems.ToArray().Should().Contain(expectedB); + sut.ShapeItems[1].Should().BeEquivalentTo(expectedB, "the previously added items should be in the same order."); - sut.RectItems.ToArray().Should().Contain(expectedC); - sut.RectItems[2].Should().BeEquivalentTo(expectedC, "the previously added items should be in the same order."); + sut.ShapeItems.ToArray().Should().Contain(expectedC); + sut.ShapeItems[2].Should().BeEquivalentTo(expectedC, "the previously added items should be in the same order."); } [Fact] - public void AddRectItem_WhenInvoked_SetsNewLineBatchItem() + public void AddShapeItem_WhenInvoked_SetsNewLineBatchItem() { // Arrange var sut = CreateSystemUnderTest(); this.batchSizeReactor.OnReceive(new BatchSizeData { BatchSize = 2 }); - var itemA = BatchItemFactory.CreateRectItemWithOrderedValues(new Vector2(10, 20)); - var itemB = BatchItemFactory.CreateRectItemWithOrderedValues(new Vector2(30, 40)); + var itemA = BatchItemFactory.CreateShapeItemWithOrderedValues(new Vector2(10, 20)); + var itemB = BatchItemFactory.CreateShapeItemWithOrderedValues(new Vector2(30, 40)); - var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10); - var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20); + var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10, DateTimeKind.Utc); + var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20, DateTimeKind.Utc); // Act - sut.AddRectItem(itemA, 1, renderStampA); - sut.AddRectItem(itemB, 2, renderStampB); + sut.AddShapeItem(itemA, 1, renderStampA); + sut.AddShapeItem(itemB, 2, renderStampB); // Assert - sut.RectItems.ToArray().Should().Contain(new RenderItem { Layer = 1, Item = itemA, RenderStamp = renderStampA }); - sut.RectItems.ToArray().Should().Contain(new RenderItem { Layer = 2, Item = itemB, RenderStamp = renderStampB }); + sut.ShapeItems.ToArray().Should().Contain(new RenderItem { Layer = 1, Item = itemA, RenderStamp = renderStampA }); + sut.ShapeItems.ToArray().Should().Contain(new RenderItem { Layer = 2, Item = itemB, RenderStamp = renderStampB }); } [Fact] @@ -709,9 +709,9 @@ public void AddLineItem_WithFullBatch_ResizesLineBatch() var itemB = BatchItemFactory.CreateLineItemWithOrderedValues(new Vector2(30, 40)); var itemC = BatchItemFactory.CreateLineItemWithOrderedValues(new Vector2(50, 60)); - var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10); - var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20); - var renderStampC = new DateTime(1, 2, 3, 0, 0, 0, 30); + var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10, DateTimeKind.Utc); + var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20, DateTimeKind.Utc); + var renderStampC = new DateTime(1, 2, 3, 0, 0, 0, 30, DateTimeKind.Utc); var expectedA = new RenderItem { Layer = 1, Item = itemA, RenderStamp = renderStampA }; var expectedB = new RenderItem { Layer = 2, Item = itemB, RenderStamp = renderStampB }; @@ -756,8 +756,8 @@ public void AddLineItem_WhenInvoked_SetsNewBatchItem() var itemA = BatchItemFactory.CreateLineItemWithOrderedValues(new Vector2(10, 20)); var itemB = BatchItemFactory.CreateLineItemWithOrderedValues(new Vector2(30, 40)); - var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10); - var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20); + var renderStampA = new DateTime(1, 2, 3, 0, 0, 0, 10, DateTimeKind.Utc); + var renderStampB = new DateTime(1, 2, 3, 0, 0, 0, 20, DateTimeKind.Utc); // Act sut.AddLineItem(itemA, 1, renderStampA); diff --git a/Testing/VelaptorTests/Content/TextureTests.cs b/Testing/VelaptorTests/Content/TextureTests.cs index 3830b898a..ee43f4308 100644 --- a/Testing/VelaptorTests/Content/TextureTests.cs +++ b/Testing/VelaptorTests/Content/TextureTests.cs @@ -266,7 +266,7 @@ public void InternalCtor_WithEmptyImageData_ThrowsException() } [Fact] - public void InternalCtor_WhenInvoked_UploadsTextureDataToGPU() + public void InternalCtor_WhenInvoked_UploadsTextureDataToGpu() { // Arrange var expectedPixelData = new List(); diff --git a/Testing/VelaptorTests/ExtensionMethods/GPUDataTypeExtensionsTests.cs b/Testing/VelaptorTests/ExtensionMethods/GpuDataTypeExtensionsTests.cs similarity index 89% rename from Testing/VelaptorTests/ExtensionMethods/GPUDataTypeExtensionsTests.cs rename to Testing/VelaptorTests/ExtensionMethods/GpuDataTypeExtensionsTests.cs index 6a6300164..64f073d24 100644 --- a/Testing/VelaptorTests/ExtensionMethods/GPUDataTypeExtensionsTests.cs +++ b/Testing/VelaptorTests/ExtensionMethods/GpuDataTypeExtensionsTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -13,19 +13,19 @@ namespace VelaptorTests.ExtensionMethods; using Moq; using Velaptor.ExtensionMethods; using Velaptor.OpenGL; -using Velaptor.OpenGL.GPUData; +using Velaptor.OpenGL.GpuData; using Xunit; /// -/// Tests the extension methods for the and types. +/// Tests the extension methods for the and types. /// -public class GPUDataTypeExtensionsTests +public class GpuDataTypeExtensionsTests { [Fact] - public void SetVertexPos_WithRectGPUDataAndInvalidVertexValue_ThrowsException() + public void SetVertexPos_WithRectGpuDataAndInvalidVertexValue_ThrowsException() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act var act = () => gpuData.SetVertexPos(It.IsAny(), (VertexNumber)1234); @@ -40,11 +40,11 @@ public void SetVertexPos_WithRectGPUDataAndInvalidVertexValue_ThrowsException() [InlineData((int)VertexNumber.Two)] [InlineData((int)VertexNumber.Three)] [InlineData((int)VertexNumber.Four)] - public void SetVertexPos_WhenInvokedWithRectGPUData_ReturnsCorrectResult(int vertexNumberNumericalValue) + public void SetVertexPos_WhenInvokedWithRectGpuData_ReturnsCorrectResult(int vertexNumberNumericalValue) { // Arrange var vertexNumber = (VertexNumber)vertexNumberNumericalValue; - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expectedVertex = vertexNumber switch { VertexNumber.One => gpuData.Vertex1, @@ -65,7 +65,7 @@ public void SetVertexPos_WhenInvokedWithRectGPUData_ReturnsCorrectResult(int ver // Assert expectedVertex.IsSolid.Should().BeFalse(); actual.VertexPos.Should().Be(new Vector2(1111f, 2222f)); - actual.Rectangle.Should().Be(expectedVertex.Rectangle); + actual.BoundingBox.Should().Be(expectedVertex.BoundingBox); actual.Color.Should().Be(expectedVertex.Color); actual.BorderThickness.Should().Be(expectedVertex.BorderThickness); actual.TopLeftCornerRadius.Should().Be(expectedVertex.TopLeftCornerRadius); @@ -78,7 +78,7 @@ public void SetVertexPos_WhenInvokedWithRectGPUData_ReturnsCorrectResult(int ver public void SetVertexPos_WithInvalidVertexNumber_ThrowsException() { // Arrange - var gpuData = new LineGPUData( + var gpuData = new LineGpuData( new LineVertexData(Vector2.Zero, Color.Empty), new LineVertexData(Vector2.Zero, Color.Empty), new LineVertexData(Vector2.Zero, Color.Empty), @@ -96,7 +96,7 @@ public void SetVertexPos_WithInvalidVertexNumber_ThrowsException() public void SetRectangle_WithInvalidVertexValue_ThrowsException() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act & Assert var act = () => gpuData.SetRectangle(It.IsAny(), (VertexNumber)1234); @@ -113,7 +113,7 @@ public void SetRectangle_WhenInvoked_ReturnsCorrectResult(int vertexNumberNumeri { // Arrange var vertexNumber = (VertexNumber)vertexNumberNumericalValue; - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expectedVertex = vertexNumber switch { VertexNumber.One => gpuData.Vertex1, @@ -134,7 +134,7 @@ public void SetRectangle_WhenInvoked_ReturnsCorrectResult(int vertexNumberNumeri // Assert expectedVertex.IsSolid.Should().BeFalse(); actual.VertexPos.Should().Be(expectedVertex.VertexPos); - actual.Rectangle.Should().Be(new Vector4(1111f, 2222f, 3333f, 4444f)); + actual.BoundingBox.Should().Be(new Vector4(1111f, 2222f, 3333f, 4444f)); actual.Color.Should().Be(expectedVertex.Color); actual.BorderThickness.Should().Be(expectedVertex.BorderThickness); actual.TopLeftCornerRadius.Should().Be(expectedVertex.TopLeftCornerRadius); @@ -147,24 +147,24 @@ public void SetRectangle_WhenInvoked_ReturnsCorrectResult(int vertexNumberNumeri public void SetRectangle_WhenUpdatingAll_ReturnsCorrectResult() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expected = new Vector4(111, 222, 333, 444); // Act var actual = gpuData.SetRectangle(new Vector4(111, 222, 333, 444)); // Assert - actual.Vertex1.Rectangle.Should().Be(expected); - actual.Vertex2.Rectangle.Should().Be(expected); - actual.Vertex3.Rectangle.Should().Be(expected); - actual.Vertex4.Rectangle.Should().Be(expected); + actual.Vertex1.BoundingBox.Should().Be(expected); + actual.Vertex2.BoundingBox.Should().Be(expected); + actual.Vertex3.BoundingBox.Should().Be(expected); + actual.Vertex4.BoundingBox.Should().Be(expected); } [Fact] public void SetAsSolid_WithInvalidVertexValue_ThrowsException() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act var act = () => gpuData.SetAsSolid(It.IsAny(), (VertexNumber)1234); @@ -183,7 +183,7 @@ public void SetAsSolid_WhenInvoked_ReturnsCorrectResult(int vertexNumberNumerica { // Arrange var vertexNumber = (VertexNumber)vertexNumberNumericalValue; - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expectedVertex = vertexNumber switch { VertexNumber.One => gpuData.Vertex1, @@ -204,7 +204,7 @@ public void SetAsSolid_WhenInvoked_ReturnsCorrectResult(int vertexNumberNumerica // Assert actual.IsSolid.Should().BeTrue(); actual.VertexPos.Should().Be(expectedVertex.VertexPos); - actual.Rectangle.Should().Be(expectedVertex.Rectangle); + actual.BoundingBox.Should().Be(expectedVertex.BoundingBox); actual.Color.Should().Be(expectedVertex.Color); actual.BorderThickness.Should().Be(expectedVertex.BorderThickness); actual.TopLeftCornerRadius.Should().Be(expectedVertex.TopLeftCornerRadius); @@ -217,7 +217,7 @@ public void SetAsSolid_WhenInvoked_ReturnsCorrectResult(int vertexNumberNumerica public void SetAsSolid_WhenUpdatingAll_ReturnsCorrectResult() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act var actual = gpuData.SetAsSolid(true); @@ -233,7 +233,7 @@ public void SetAsSolid_WhenUpdatingAll_ReturnsCorrectResult() public void SetBorderThickness_WithInvalidVertexValue_ThrowsException() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act var act = () => gpuData.SetBorderThickness(It.IsAny(), (VertexNumber)1234); @@ -252,7 +252,7 @@ public void SetBorderThickness_WhenInvoked_ReturnsCorrectResult(int vertexNumber { // Arrange var vertexNumber = (VertexNumber)vertexNumberNumericalValue; - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expectedVertex = vertexNumber switch { VertexNumber.One => gpuData.Vertex1, @@ -273,7 +273,7 @@ public void SetBorderThickness_WhenInvoked_ReturnsCorrectResult(int vertexNumber // Assert actual.BorderThickness.Should().Be(123f); actual.VertexPos.Should().Be(expectedVertex.VertexPos); - actual.Rectangle.Should().Be(expectedVertex.Rectangle); + actual.BoundingBox.Should().Be(expectedVertex.BoundingBox); actual.Color.Should().Be(expectedVertex.Color); actual.IsSolid.Should().Be(expectedVertex.IsSolid); actual.TopLeftCornerRadius.Should().Be(expectedVertex.TopLeftCornerRadius); @@ -286,7 +286,7 @@ public void SetBorderThickness_WhenInvoked_ReturnsCorrectResult(int vertexNumber public void SetBorderThickness_WhenUpdatingAll_ReturnsCorrectResult() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); const float expected = 123f; // Act @@ -303,7 +303,7 @@ public void SetBorderThickness_WhenUpdatingAll_ReturnsCorrectResult() public void SetTopLeftCornerRadius_WithInvalidVertexValue_ThrowsException() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act var act = () => gpuData.SetTopLeftCornerRadius(It.IsAny(), (VertexNumber)1234); @@ -322,7 +322,7 @@ public void SetTopLeftCornerRadius_WhenInvoked_ReturnsCorrectResult(int vertexNu { // Arrange var vertexNumber = (VertexNumber)vertexNumberNumericalValue; - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expectedVertex = vertexNumber switch { VertexNumber.One => gpuData.Vertex1, @@ -344,7 +344,7 @@ public void SetTopLeftCornerRadius_WhenInvoked_ReturnsCorrectResult(int vertexNu expectedVertex.IsSolid.Should().BeFalse(); actual.TopLeftCornerRadius.Should().Be(1234f); actual.VertexPos.Should().Be(expectedVertex.VertexPos); - actual.Rectangle.Should().Be(expectedVertex.Rectangle); + actual.BoundingBox.Should().Be(expectedVertex.BoundingBox); actual.Color.Should().Be(expectedVertex.Color); actual.BorderThickness.Should().Be(expectedVertex.BorderThickness); actual.BottomLeftCornerRadius.Should().Be(expectedVertex.BottomLeftCornerRadius); @@ -356,7 +356,7 @@ public void SetTopLeftCornerRadius_WhenInvoked_ReturnsCorrectResult(int vertexNu public void SetTopLeftCornerRadius_WhenUpdatingAll_ReturnsCorrectResult() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); const float expected = 123f; // Act @@ -373,7 +373,7 @@ public void SetTopLeftCornerRadius_WhenUpdatingAll_ReturnsCorrectResult() public void SetBottomLeftCornerRadius_WithInvalidVertexValue_ThrowsException() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act var act = () => gpuData.SetBottomLeftCornerRadius(It.IsAny(), (VertexNumber)1234); @@ -392,7 +392,7 @@ public void SetBottomLeftCornerRadius_WhenInvoked_ReturnsCorrectResult(int verte { // Arrange var vertexNumber = (VertexNumber)vertexNumberNumericalValue; - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expectedVertex = vertexNumber switch { VertexNumber.One => gpuData.Vertex1, @@ -414,7 +414,7 @@ public void SetBottomLeftCornerRadius_WhenInvoked_ReturnsCorrectResult(int verte expectedVertex.IsSolid.Should().BeFalse(); actual.BottomLeftCornerRadius.Should().Be(1234f); actual.VertexPos.Should().Be(expectedVertex.VertexPos); - actual.Rectangle.Should().Be(expectedVertex.Rectangle); + actual.BoundingBox.Should().Be(expectedVertex.BoundingBox); actual.Color.Should().Be(expectedVertex.Color); actual.BorderThickness.Should().Be(expectedVertex.BorderThickness); actual.TopLeftCornerRadius.Should().Be(expectedVertex.TopLeftCornerRadius); @@ -426,7 +426,7 @@ public void SetBottomLeftCornerRadius_WhenInvoked_ReturnsCorrectResult(int verte public void SetBottomLeftCornerRadius_WhenUpdatingAll_ReturnsCorrectResult() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); const float expected = 123f; // Act @@ -443,7 +443,7 @@ public void SetBottomLeftCornerRadius_WhenUpdatingAll_ReturnsCorrectResult() public void SetBottomRightCornerRadius_WithInvalidVertexValue_ThrowsException() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act var act = () => gpuData.SetBottomRightCornerRadius(It.IsAny(), (VertexNumber)1234); @@ -462,7 +462,7 @@ public void SetBottomRightCornerRadius_WhenInvoked_ReturnsCorrectResult(int vert { // Arrange var vertexNumber = (VertexNumber)vertexNumberNumericalValue; - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expectedVertex = vertexNumber switch { VertexNumber.One => gpuData.Vertex1, @@ -484,7 +484,7 @@ public void SetBottomRightCornerRadius_WhenInvoked_ReturnsCorrectResult(int vert expectedVertex.IsSolid.Should().BeFalse(); actual.BottomRightCornerRadius.Should().Be(1234f); actual.VertexPos.Should().Be(expectedVertex.VertexPos); - actual.Rectangle.Should().Be(expectedVertex.Rectangle); + actual.BoundingBox.Should().Be(expectedVertex.BoundingBox); actual.Color.Should().Be(expectedVertex.Color); actual.BorderThickness.Should().Be(expectedVertex.BorderThickness); actual.TopLeftCornerRadius.Should().Be(expectedVertex.TopLeftCornerRadius); @@ -496,7 +496,7 @@ public void SetBottomRightCornerRadius_WhenInvoked_ReturnsCorrectResult(int vert public void SetBottomRightCornerRadius_WhenUpdatingAll_ReturnsCorrectResult() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); const float expected = 123f; // Act @@ -513,7 +513,7 @@ public void SetBottomRightCornerRadius_WhenUpdatingAll_ReturnsCorrectResult() public void SetTopRightCornerRadius_WithInvalidVertexValue_ThrowsException() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act var act = () => gpuData.SetTopRightCornerRadius(It.IsAny(), (VertexNumber)1234); @@ -532,7 +532,7 @@ public void SetTopRightCornerRadius_WhenInvoked_ReturnsCorrectResult(int vertexN { // Arrange var vertexNumber = (VertexNumber)vertexNumberNumericalValue; - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expectedVertex = vertexNumber switch { VertexNumber.One => gpuData.Vertex1, @@ -554,7 +554,7 @@ public void SetTopRightCornerRadius_WhenInvoked_ReturnsCorrectResult(int vertexN expectedVertex.IsSolid.Should().BeFalse(); actual.TopRightCornerRadius.Should().Be(1234f); actual.VertexPos.Should().Be(expectedVertex.VertexPos); - actual.Rectangle.Should().Be(expectedVertex.Rectangle); + actual.BoundingBox.Should().Be(expectedVertex.BoundingBox); actual.Color.Should().Be(expectedVertex.Color); actual.BorderThickness.Should().Be(expectedVertex.BorderThickness); actual.TopLeftCornerRadius.Should().Be(expectedVertex.TopLeftCornerRadius); @@ -566,7 +566,7 @@ public void SetTopRightCornerRadius_WhenInvoked_ReturnsCorrectResult(int vertexN public void SetTopRightCornerRadius_WhenUpdatingAll_ReturnsCorrectResult() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); const float expected = 123f; // Act @@ -583,7 +583,7 @@ public void SetTopRightCornerRadius_WhenUpdatingAll_ReturnsCorrectResult() public void SetColor_WithInvalidVertexValue_ThrowsException() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); // Act var act = () => gpuData.SetColor(It.IsAny(), (VertexNumber)1234); @@ -602,7 +602,7 @@ public void SetColor_WhenInvoked_ReturnsCorrectResult(int vertexNumberNumericalV { // Arrange var vertexNumber = (VertexNumber)vertexNumberNumericalValue; - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expectedVertex = vertexNumber switch { VertexNumber.One => gpuData.Vertex1, @@ -623,7 +623,7 @@ public void SetColor_WhenInvoked_ReturnsCorrectResult(int vertexNumberNumericalV // Assert expectedVertex.IsSolid.Should().BeFalse(); actual.VertexPos.Should().Be(expectedVertex.VertexPos); - actual.Rectangle.Should().Be(expectedVertex.Rectangle); + actual.BoundingBox.Should().Be(expectedVertex.BoundingBox); actual.Color.Should().Be(Color.Blue); actual.BorderThickness.Should().Be(expectedVertex.BorderThickness); actual.TopLeftCornerRadius.Should().Be(expectedVertex.TopLeftCornerRadius); @@ -636,7 +636,7 @@ public void SetColor_WhenInvoked_ReturnsCorrectResult(int vertexNumberNumericalV public void SetColor_WhenUpdatingAll_ReturnsCorrectResult() { // Arrange - var gpuData = GenerateGPUDataInSequence(0); + var gpuData = GenerateGpuDataInSequence(0); var expected = Color.FromArgb(220, 230, 240, 250); // Act @@ -650,10 +650,10 @@ public void SetColor_WhenUpdatingAll_ReturnsCorrectResult() } [Fact] - public void SetColor_WhenSettingLineGPUData_SetsColorToAllVertexData() + public void SetColor_WhenSettingLineGpuData_SetsColorToAllVertexData() { // Arrange - var data = new LineGPUData( + var data = new LineGpuData( new LineVertexData(Vector2.Zero, Color.White), new LineVertexData(Vector2.Zero, Color.White), new LineVertexData(Vector2.Zero, Color.White), @@ -674,12 +674,12 @@ public void SetColor_WhenSettingLineGPUData_SetsColorToAllVertexData() [InlineData(VertexNumber.Two)] [InlineData(VertexNumber.Three)] [InlineData(VertexNumber.Four)] - internal void SetVertexPos_WhenInvokedWithLineGPUData_ReturnsCorrectResult(VertexNumber vertexNumber) + internal void SetVertexPos_WhenInvokedWithLineGpuData_ReturnsCorrectResult(VertexNumber vertexNumber) { // Arrange var expectedPos = new Vector2(10, 20); - var gpuData = new LineGPUData( + var gpuData = new LineGpuData( new LineVertexData(Vector2.Zero, Color.Empty), new LineVertexData(Vector2.Zero, Color.Empty), new LineVertexData(Vector2.Zero, Color.Empty), @@ -704,7 +704,7 @@ internal void SetVertexPos_WhenInvokedWithLineGPUData_ReturnsCorrectResult(Verte /// /// The value to start the sequential assignment. /// The GPU data to test. - private static RectGPUData GenerateGPUDataInSequence(int startValue) + private static ShapeGpuData GenerateGpuDataInSequence(int startValue) { var vertex1 = GenerateVertexDataInSequence(startValue); startValue += 11; @@ -714,7 +714,7 @@ private static RectGPUData GenerateGPUDataInSequence(int startValue) startValue += 11; var vertex4 = GenerateVertexDataInSequence(startValue); - return new RectGPUData(vertex1, vertex2, vertex3, vertex4); + return new ShapeGpuData(vertex1, vertex2, vertex3, vertex4); } /// @@ -723,9 +723,9 @@ private static RectGPUData GenerateGPUDataInSequence(int startValue) /// /// The value to start the sequential assignment. /// The vertex data to test. - private static RectVertexData GenerateVertexDataInSequence(int startValue) + private static ShapeVertexData GenerateVertexDataInSequence(int startValue) { - return new RectVertexData( + return new ShapeVertexData( new Vector2(startValue + 1f, startValue + 2f), new Vector4(startValue + 3, startValue + 4, startValue + 5, startValue + 6), Color.FromArgb(startValue + 7, startValue + 8, startValue + 9, startValue + 10), diff --git a/Testing/VelaptorTests/Fakes/GPUBufferFake.cs b/Testing/VelaptorTests/Fakes/GpuBufferFake.cs similarity index 93% rename from Testing/VelaptorTests/Fakes/GPUBufferFake.cs rename to Testing/VelaptorTests/Fakes/GpuBufferFake.cs index 8b985bfba..2115c017c 100644 --- a/Testing/VelaptorTests/Fakes/GPUBufferFake.cs +++ b/Testing/VelaptorTests/Fakes/GpuBufferFake.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -12,17 +12,17 @@ namespace VelaptorTests.Fakes; using NETSizeF = System.Drawing.SizeF; /// -/// Used to test the abstract class . +/// Used to test the abstract class . /// -internal sealed class GPUBufferFake : GPUBufferBase +internal sealed class GpuBufferFake : GpuBufferBase { /// - /// Initializes a new instance of the class for the purpose of testing. + /// Initializes a new instance of the class for the purpose of testing. /// /// Mocked for OpenGL function calls. /// Mocked for OpenGL function calls. /// Mocked for creating reactables. - public GPUBufferFake(IGLInvoker gl, + public GpuBufferFake(IGLInvoker gl, IOpenGLService openGLService, IReactableFactory reactableFactory) : base(gl, openGLService, reactableFactory) diff --git a/Testing/VelaptorTests/Fakes/WindowFake.cs b/Testing/VelaptorTests/Fakes/WindowFake.cs index 59ca35097..b960ea238 100644 --- a/Testing/VelaptorTests/Fakes/WindowFake.cs +++ b/Testing/VelaptorTests/Fakes/WindowFake.cs @@ -4,6 +4,7 @@ namespace VelaptorTests.Fakes; +using Velaptor.Batching; using Velaptor.Scene; using Velaptor.UI; @@ -15,11 +16,12 @@ public class WindowFake : Window /// /// Initializes a new instance of the class. /// - /// Mocked window.. + /// Mocked window. /// Mocked scene manager. + /// Mocked batcher. /// This is used to help test the abstract class. - internal WindowFake(IWindow window, ISceneManager sceneManager) - : base(window, sceneManager) + internal WindowFake(IWindow window, ISceneManager sceneManager, IBatcher batcher) + : base(window, sceneManager, batcher) { } } diff --git a/Testing/VelaptorTests/GameHelpersTests.cs b/Testing/VelaptorTests/GameHelpersTests.cs index 4d66220de..c0da51a4e 100644 --- a/Testing/VelaptorTests/GameHelpersTests.cs +++ b/Testing/VelaptorTests/GameHelpersTests.cs @@ -308,10 +308,10 @@ public void ApplySize_WithFloat_ReturnsCorrectResult(float value, float expected public void ApplySize_WithSizeF_ReturnsCorrectResult() { // Arrange - var rect = new SizeF(10, 20); + var size = new SizeF(10, 20); // Act - var actual = rect.ApplySize(2f); + var actual = size.ApplySize(2f); // Assert actual.Width.Should().Be(30f); diff --git a/Testing/VelaptorTests/Graphics/RectShapeTests.cs b/Testing/VelaptorTests/Graphics/RectShapeTests.cs index f7633e6e8..8937957b3 100644 --- a/Testing/VelaptorTests/Graphics/RectShapeTests.cs +++ b/Testing/VelaptorTests/Graphics/RectShapeTests.cs @@ -189,19 +189,19 @@ public static IEnumerable IsEmptyTestData() public void Ctor_WhenInvoked_SetsDefaultValues() { // Arrange & Act - var rect = new RectShape(); + var sut = new RectShape(); // Assert - Assert.Equal(Vector2.Zero, rect.Position); - Assert.Equal(1f, rect.Width); - Assert.Equal(1f, rect.Height); - Assert.Equal(Color.White, rect.Color); - Assert.True(rect.IsSolid); - Assert.Equal(1f, rect.BorderThickness); - Assert.Equal(new CornerRadius(1f, 1f, 1f, 1f), rect.CornerRadius); - Assert.Equal(ColorGradient.None, rect.GradientType); - Assert.Equal(Color.White, rect.GradientStart); - Assert.Equal(Color.White, rect.GradientStop); + Assert.Equal(Vector2.Zero, sut.Position); + Assert.Equal(1f, sut.Width); + Assert.Equal(1f, sut.Height); + Assert.Equal(Color.White, sut.Color); + Assert.True(sut.IsSolid); + Assert.Equal(1f, sut.BorderThickness); + Assert.Equal(new CornerRadius(1f, 1f, 1f, 1f), sut.CornerRadius); + Assert.Equal(ColorGradient.None, sut.GradientType); + Assert.Equal(Color.White, sut.GradientStart); + Assert.Equal(Color.White, sut.GradientStop); } #endregion @@ -213,11 +213,11 @@ public void Ctor_WhenInvoked_SetsDefaultValues() public void Width_WhenSettingValue_ReturnsCorrectResult(float value, float expected) { // Arrange - var rect = default(RectShape); + var sut = default(RectShape); // Act - rect.Width = value; - var actual = rect.Width; + sut.Width = value; + var actual = sut.Width; // Assert Assert.Equal(expected, actual); @@ -230,11 +230,11 @@ public void Width_WhenSettingValue_ReturnsCorrectResult(float value, float expec public void Height_WhenSettingValue_ReturnsCorrectResult(float value, float expected) { // Arrange - var rect = default(RectShape); + var sut = default(RectShape); // Act - rect.Height = value; - var actual = rect.Height; + sut.Height = value; + var actual = sut.Height; // Assert Assert.Equal(expected, actual); @@ -244,11 +244,11 @@ public void Height_WhenSettingValue_ReturnsCorrectResult(float value, float expe public void HalfWidth_WhenGettingValue_ReturnsCorrectResult() { // Arrange - var rect = default(RectShape); - rect.Width = 100; + var sut = default(RectShape); + sut.Width = 100; // Act - var actual = rect.HalfWidth; + var actual = sut.HalfWidth; // Assert Assert.Equal(50f, actual); @@ -258,11 +258,11 @@ public void HalfWidth_WhenGettingValue_ReturnsCorrectResult() public void HalfHeight_WhenGettingValue_ReturnsCorrectResult() { // Arrange - var rect = default(RectShape); - rect.Height = 100; + var sut = default(RectShape); + sut.Height = 100; // Act - var actual = rect.HalfHeight; + var actual = sut.HalfHeight; // Assert Assert.Equal(50f, actual); @@ -280,13 +280,13 @@ public void BorderThickness_WhenSettingValue_ReturnsCorrectResult( float expected) { // Arrange - var rect = default(RectShape); - rect.Width = width; - rect.Height = height; + var sut = default(RectShape); + sut.Width = width; + sut.Height = height; // Act - rect.BorderThickness = borderThickness; - var actual = rect.BorderThickness; + sut.BorderThickness = borderThickness; + var actual = sut.BorderThickness; // Assert Assert.Equal(expected, actual); @@ -296,10 +296,10 @@ public void BorderThickness_WhenSettingValue_ReturnsCorrectResult( public void CornerRadius_WhenGettingDefaultValue_ReturnsCorrectResult() { // Arrange - var rect = default(RectShape); + var sut = default(RectShape); // Act - var actual = rect.CornerRadius; + var actual = sut.CornerRadius; // Assert AssertExtensions.EqualWithMessage(0f, actual.TopLeft, "The top left value is incorrect."); @@ -312,11 +312,11 @@ public void CornerRadius_WhenGettingDefaultValue_ReturnsCorrectResult() public void CornerRadius_WhenInvoked_ReturnsCorrectResult() { // Arrange - var rect = default(RectShape); + var sut = default(RectShape); // Act - rect.CornerRadius = new CornerRadius(11f, 22f, 33f, 44f); - var actual = rect.CornerRadius; + sut.CornerRadius = new CornerRadius(11f, 22f, 33f, 44f); + var actual = sut.CornerRadius; // Assert AssertExtensions.EqualWithMessage(11f, actual.TopLeft, "The top left value is incorrect."); @@ -329,76 +329,76 @@ public void CornerRadius_WhenInvoked_ReturnsCorrectResult() public void Top_WhenSettingValue_ReturnsCorrectResult() { // Arrange - var rect = default(RectShape); - rect.Position = new Vector2(100, 100); - rect.Width = 100; - rect.Height = 50; + var sut = default(RectShape); + sut.Position = new Vector2(100, 100); + sut.Width = 100; + sut.Height = 50; // Act - rect.Top = 40f; - var actual = rect.Top; + sut.Top = 40f; + var actual = sut.Top; // Assert AssertExtensions.EqualWithMessage(40f, actual, $"{nameof(RectShape.Top)} value incorrect."); - AssertExtensions.EqualWithMessage(100, rect.Position.X, $"{nameof(RectShape.Position.X)} value incorrect."); - AssertExtensions.EqualWithMessage(65f, rect.Position.Y, $"{nameof(RectShape.Position.Y)} value incorrect."); + AssertExtensions.EqualWithMessage(100, sut.Position.X, $"{nameof(RectShape.Position.X)} value incorrect."); + AssertExtensions.EqualWithMessage(65f, sut.Position.Y, $"{nameof(RectShape.Position.Y)} value incorrect."); } [Fact] public void Right_WhenSettingValue_ReturnsCorrectResult() { // Arrange - var rect = default(RectShape); - rect.Position = new Vector2(200, 100); - rect.Width = 100; - rect.Height = 50; + var sut = default(RectShape); + sut.Position = new Vector2(200, 100); + sut.Width = 100; + sut.Height = 50; // Act - rect.Right = 100f; - var actual = rect.Right; + sut.Right = 100f; + var actual = sut.Right; // Assert AssertExtensions.EqualWithMessage(100f, actual, $"{nameof(RectShape.Right)} value incorrect."); - AssertExtensions.EqualWithMessage(50, rect.Position.X, $"{nameof(RectShape.Position.X)} value incorrect."); - AssertExtensions.EqualWithMessage(100f, rect.Position.Y, $"{nameof(RectShape.Position.Y)} value incorrect."); + AssertExtensions.EqualWithMessage(50, sut.Position.X, $"{nameof(RectShape.Position.X)} value incorrect."); + AssertExtensions.EqualWithMessage(100f, sut.Position.Y, $"{nameof(RectShape.Position.Y)} value incorrect."); } [Fact] public void Bottom_WhenSettingValue_ReturnsCorrectResult() { // Arrange - var rect = default(RectShape); - rect.Position = new Vector2(100, 100); - rect.Width = 100; - rect.Height = 50; + var sut = default(RectShape); + sut.Position = new Vector2(100, 100); + sut.Width = 100; + sut.Height = 50; // Act - rect.Bottom = 40f; - var actual = rect.Bottom; + sut.Bottom = 40f; + var actual = sut.Bottom; // Assert AssertExtensions.EqualWithMessage(40f, actual, $"{nameof(RectShape.Bottom)} value incorrect."); - AssertExtensions.EqualWithMessage(100, rect.Position.X, $"{nameof(RectShape.Position.X)} value incorrect."); - AssertExtensions.EqualWithMessage(15f, rect.Position.Y, $"{nameof(RectShape.Position.Y)} value incorrect."); + AssertExtensions.EqualWithMessage(100, sut.Position.X, $"{nameof(RectShape.Position.X)} value incorrect."); + AssertExtensions.EqualWithMessage(15f, sut.Position.Y, $"{nameof(RectShape.Position.Y)} value incorrect."); } [Fact] public void Left_WhenSettingValue_ReturnsCorrectResult() { // Arrange - var rect = default(RectShape); - rect.Position = new Vector2(200, 100); - rect.Width = 100; - rect.Height = 50; + var sut = default(RectShape); + sut.Position = new Vector2(200, 100); + sut.Width = 100; + sut.Height = 50; // Act - rect.Left = 100f; - var actual = rect.Left; + sut.Left = 100f; + var actual = sut.Left; // Assert AssertExtensions.EqualWithMessage(100f, actual, $"{nameof(RectShape.Left)} value incorrect."); - AssertExtensions.EqualWithMessage(150, rect.Position.X, $"{nameof(RectShape.Position.X)} value incorrect."); - AssertExtensions.EqualWithMessage(100f, rect.Position.Y, $"{nameof(RectShape.Position.Y)} value incorrect."); + AssertExtensions.EqualWithMessage(150, sut.Position.X, $"{nameof(RectShape.Position.X)} value incorrect."); + AssertExtensions.EqualWithMessage(100f, sut.Position.Y, $"{nameof(RectShape.Position.Y)} value incorrect."); } #endregion @@ -444,20 +444,20 @@ public void IsEmpty_WhenInvoked_ReturnsCorrectResult( bool expected) { // Arrange - var rect = default(RectShape); - rect.Position = position; - rect.Width = width; - rect.Height = height; - rect.Color = color; - rect.IsSolid = isSolid; - rect.BorderThickness = borderThickness; - rect.CornerRadius = cornerRadius; - rect.GradientType = gradientType; - rect.GradientStart = gradientStart; - rect.GradientStop = gradientStop; + var sut = default(RectShape); + sut.Position = position; + sut.Width = width; + sut.Height = height; + sut.Color = color; + sut.IsSolid = isSolid; + sut.BorderThickness = borderThickness; + sut.CornerRadius = cornerRadius; + sut.GradientType = gradientType; + sut.GradientStart = gradientStart; + sut.GradientStop = gradientStop; // Act - var actual = rect.IsEmpty(); + var actual = sut.IsEmpty(); // Assert Assert.Equal(expected, actual); @@ -467,32 +467,32 @@ public void IsEmpty_WhenInvoked_ReturnsCorrectResult( public void Empty_WhenInvoked_EmptiesStruct() { // Arrange - var rect = default(RectShape); - rect.Position = new Vector2(1, 2); - rect.Width = 50f; - rect.Height = 60f; - rect.Color = Color.FromArgb(5, 6, 7, 8); - rect.IsSolid = true; - rect.BorderThickness = 9f; - rect.CornerRadius = new CornerRadius(10, 11, 12, 13); - rect.GradientType = ColorGradient.Horizontal; - rect.GradientStart = Color.FromArgb(14, 15, 16, 17); - rect.GradientStop = Color.FromArgb(18, 19, 20, 21); + var sut = default(RectShape); + sut.Position = new Vector2(1, 2); + sut.Width = 50f; + sut.Height = 60f; + sut.Color = Color.FromArgb(5, 6, 7, 8); + sut.IsSolid = true; + sut.BorderThickness = 9f; + sut.CornerRadius = new CornerRadius(10, 11, 12, 13); + sut.GradientType = ColorGradient.Horizontal; + sut.GradientStart = Color.FromArgb(14, 15, 16, 17); + sut.GradientStop = Color.FromArgb(18, 19, 20, 21); // Act - rect.Empty(); + sut.Empty(); // Assert - Assert.Equal(Vector2.Zero, rect.Position); - Assert.Equal(1f, rect.Width); - Assert.Equal(1f, rect.Height); - Assert.Equal(Color.Empty, rect.Color); - Assert.False(rect.IsSolid); - Assert.Equal(1f, rect.BorderThickness); - Assert.Equal(new CornerRadius(0f, 0f, 0f, 0f), rect.CornerRadius); - Assert.Equal(ColorGradient.None, rect.GradientType); - Assert.Equal(Color.Empty, rect.GradientStart); - Assert.Equal(Color.Empty, rect.GradientStop); + Assert.Equal(Vector2.Zero, sut.Position); + Assert.Equal(1f, sut.Width); + Assert.Equal(1f, sut.Height); + Assert.Equal(Color.Empty, sut.Color); + Assert.False(sut.IsSolid); + Assert.Equal(1f, sut.BorderThickness); + Assert.Equal(new CornerRadius(0f, 0f, 0f, 0f), sut.CornerRadius); + Assert.Equal(ColorGradient.None, sut.GradientType); + Assert.Equal(Color.Empty, sut.GradientStart); + Assert.Equal(Color.Empty, sut.GradientStop); } #endregion } diff --git a/Testing/VelaptorTests/Graphics/RenderMediatorTests.cs b/Testing/VelaptorTests/Graphics/RenderMediatorTests.cs index cc3aafd58..4e897af98 100644 --- a/Testing/VelaptorTests/Graphics/RenderMediatorTests.cs +++ b/Testing/VelaptorTests/Graphics/RenderMediatorTests.cs @@ -29,16 +29,16 @@ public class RenderMediatorTests private readonly Mock mockShutDownUnsubscriber; private readonly Mock>> mockTextureComparer; private readonly Mock>> mockFontComparer; - private readonly Mock>> mockRectComparer; + private readonly Mock>> mockShapeComparer; private readonly Mock>> mockLineComparer; private readonly Mock> mockTextureRenderBatchReactable; private readonly Mock> mockFontRenderBatchReactable; - private readonly Mock> mockRectRenderBatchReactable; + private readonly Mock> mockShapeRenderBatchReactable; private readonly Mock> mockLineRenderBatchReactable; private readonly Mock> mockTexturePullReactable; private readonly Mock> mockFontPullReactable; - private readonly Mock> mockRectPullReactable; + private readonly Mock> mockShapePullReactable; private readonly Mock> mockLinePullReactable; private IReceiveReactor? endBatchReactor; @@ -90,12 +90,12 @@ public RenderMediatorTests() this.mockTexturePullReactable = new Mock>(); this.mockFontPullReactable = new Mock>(); - this.mockRectPullReactable = new Mock>(); + this.mockShapePullReactable = new Mock>(); this.mockLinePullReactable = new Mock>(); this.mockTextureRenderBatchReactable = new Mock>(); this.mockFontRenderBatchReactable = new Mock>(); - this.mockRectRenderBatchReactable = new Mock>(); + this.mockShapeRenderBatchReactable = new Mock>(); this.mockLineRenderBatchReactable = new Mock>(); this.mockReactableFactory = new Mock(); @@ -105,8 +105,8 @@ public RenderMediatorTests() .Returns(this.mockTexturePullReactable.Object); this.mockReactableFactory.Setup(m => m.CreateFontPullBatchReactable()). Returns(this.mockFontPullReactable.Object); - this.mockReactableFactory.Setup(m => m.CreateRectPullBatchReactable()). - Returns(this.mockRectPullReactable.Object); + this.mockReactableFactory.Setup(m => m.CreateShapePullBatchReactable()). + Returns(this.mockShapePullReactable.Object); this.mockReactableFactory.Setup(m => m.CreateLinePullBatchReactable()). Returns(this.mockLinePullReactable.Object); @@ -114,14 +114,14 @@ public RenderMediatorTests() .Returns(this.mockTextureRenderBatchReactable.Object); this.mockReactableFactory.Setup(m => m.CreateRenderFontReactable()) .Returns(this.mockFontRenderBatchReactable.Object); - this.mockReactableFactory.Setup(m => m.CreateRenderRectReactable()) - .Returns(this.mockRectRenderBatchReactable.Object); + this.mockReactableFactory.Setup(m => m.CreateRenderShapeReactable()) + .Returns(this.mockShapeRenderBatchReactable.Object); this.mockReactableFactory.Setup(m => m.CreateRenderLineReactable()) .Returns(this.mockLineRenderBatchReactable.Object); this.mockTextureComparer = new Mock>>(); this.mockFontComparer = new Mock>>(); - this.mockRectComparer = new Mock>>(); + this.mockShapeComparer = new Mock>>(); this.mockLineComparer = new Mock>>(); } @@ -136,7 +136,7 @@ public void Ctor_WithNullReactableFactoryParam_ThrowsException() null, this.mockTextureComparer.Object, this.mockFontComparer.Object, - this.mockRectComparer.Object, + this.mockShapeComparer.Object, this.mockLineComparer.Object); }; @@ -156,7 +156,7 @@ public void Ctor_WithNullTextureItemComparerParam_ThrowsException() this.mockReactableFactory.Object, null, this.mockFontComparer.Object, - this.mockRectComparer.Object, + this.mockShapeComparer.Object, this.mockLineComparer.Object); }; @@ -176,7 +176,7 @@ public void Ctor_WithNullFontItemComparerParam_ThrowsException() this.mockReactableFactory.Object, this.mockTextureComparer.Object, null, - this.mockRectComparer.Object, + this.mockShapeComparer.Object, this.mockLineComparer.Object); }; @@ -187,7 +187,7 @@ public void Ctor_WithNullFontItemComparerParam_ThrowsException() } [Fact] - public void Ctor_WithNullRectItemComparerParam_ThrowsException() + public void Ctor_WithNullShapeItemComparerParam_ThrowsException() { // Arrange & Act var act = () => @@ -203,7 +203,7 @@ public void Ctor_WithNullRectItemComparerParam_ThrowsException() // Assert act.Should() .Throw() - .WithMessage("The parameter must not be null. (Parameter 'rectItemComparer')"); + .WithMessage("The parameter must not be null. (Parameter 'shapeItemComparer')"); } [Fact] @@ -216,7 +216,7 @@ public void Ctor_WithNullNullItemComparerParam_ThrowsException() this.mockReactableFactory.Object, this.mockTextureComparer.Object, this.mockFontComparer.Object, - this.mockRectComparer.Object, + this.mockShapeComparer.Object, null); }; @@ -248,17 +248,17 @@ public void PushReactable_WithBatchEndNotification_CoordinatesRenderCalls() // Arrange var textureItemA = CreateRenderItem(BatchItemFactory.CreateTextureItemWithOrderedValues(), 4); var fontItemA = CreateRenderItem(BatchItemFactory.CreateFontItemWithOrderedValues(), 3); - var rectItemA = CreateRenderItem(BatchItemFactory.CreateRectItemWithOrderedValues(), 2); + var shapeItemA = CreateRenderItem(BatchItemFactory.CreateShapeItemWithOrderedValues(), 2); var lineItemA = CreateRenderItem(BatchItemFactory.CreateLineItemWithOrderedValues(), 1); var textureItemB = CreateRenderItem(BatchItemFactory.CreateTextureItemWithOrderedValues(), 4); var fontItemB = CreateRenderItem(BatchItemFactory.CreateFontItemWithOrderedValues(), 3); - var rectItemB = CreateRenderItem(BatchItemFactory.CreateRectItemWithOrderedValues(), 2); + var shapeItemB = CreateRenderItem(BatchItemFactory.CreateShapeItemWithOrderedValues(), 2); var lineItemB = CreateRenderItem(BatchItemFactory.CreateLineItemWithOrderedValues(), 1); var textureItems = new[] { textureItemA, textureItemB }; var fontItems = new[] { fontItemA, fontItemB }; - var rectItems = new[] { rectItemA, rectItemB }; + var shapeItems = new[] { shapeItemA, shapeItemB }; var lineItems = new[] { lineItemA, lineItemB }; this.mockTexturePullReactable.Setup(m => m.Pull(It.IsAny())) @@ -267,8 +267,8 @@ public void PushReactable_WithBatchEndNotification_CoordinatesRenderCalls() this.mockFontPullReactable.Setup(m => m.Pull(It.IsAny())) .Returns(_ => new Memory>(fontItems)); - this.mockRectPullReactable.Setup(m => m.Pull(It.IsAny())) - .Returns(_ => new Memory>(rectItems)); + this.mockShapePullReactable.Setup(m => m.Pull(It.IsAny())) + .Returns(_ => new Memory>(shapeItems)); this.mockLinePullReactable.Setup(m => m.Pull(It.IsAny())) .Returns(_ => new Memory>(lineItems)); @@ -281,9 +281,9 @@ public void PushReactable_WithBatchEndNotification_CoordinatesRenderCalls() .Setup(m => m.Push(It.Ref>>.IsAny, It.IsAny())) .Callback(AssertFontItems); - this.mockRectRenderBatchReactable + this.mockShapeRenderBatchReactable .Setup(m => m.Push(It.Ref>>.IsAny, It.IsAny())) - .Callback(AssertRectItems); + .Callback(AssertShapeItems); this.mockLineRenderBatchReactable .Setup(m => m.Push(It.Ref>>.IsAny, It.IsAny())) @@ -297,7 +297,7 @@ public void PushReactable_WithBatchEndNotification_CoordinatesRenderCalls() // Assert this.mockTexturePullReactable.VerifyOnce(m => m.Pull(PullResponses.GetTextureItemsId)); this.mockFontPullReactable.VerifyOnce(m => m.Pull(PullResponses.GetFontItemsId)); - this.mockRectPullReactable.VerifyOnce(m => m.Pull(PullResponses.GetRectItemsId)); + this.mockShapePullReactable.VerifyOnce(m => m.Pull(PullResponses.GetShapeItemsId)); this.mockLinePullReactable.VerifyOnce(m => m.Pull(PullResponses.GetLineItemsId)); void AssertTextureItems(in Memory> data, Guid eventId) @@ -312,9 +312,9 @@ void AssertFontItems(in Memory> data, Guid eventI data.Span.ToArray().Should().HaveCount(2); } - void AssertRectItems(in Memory> data, Guid eventId) + void AssertShapeItems(in Memory> data, Guid eventId) { - eventId.Should().Be(PushNotifications.RenderRectsId); + eventId.Should().Be(PushNotifications.RenderShapesId); data.Span.ToArray().Should().HaveCount(2); } @@ -338,6 +338,6 @@ private RenderMediator CreateSystemUnderTest() => new (this.mockReactableFactory.Object, this.mockTextureComparer.Object, this.mockFontComparer.Object, - this.mockRectComparer.Object, + this.mockShapeComparer.Object, this.mockLineComparer.Object); } diff --git a/Testing/VelaptorTests/Graphics/Renderers/FontRendererTests.cs b/Testing/VelaptorTests/Graphics/Renderers/FontRendererTests.cs index 32f150eb5..50a52bb34 100644 --- a/Testing/VelaptorTests/Graphics/Renderers/FontRendererTests.cs +++ b/Testing/VelaptorTests/Graphics/Renderers/FontRendererTests.cs @@ -48,7 +48,7 @@ public class FontRendererTests private const char InvalidCharacter = '□'; private readonly Mock mockGL; private readonly Mock mockGLService; - private readonly Mock> mockGPUBuffer; + private readonly Mock> mockGpuBuffer; private readonly Mock mockShader; private readonly Mock mockFont; private readonly Mock mockBatchingManager; @@ -83,7 +83,7 @@ public FontRendererTests() this.mockShader = new Mock(); this.mockShader.SetupGet(p => p.ShaderId).Returns(FontShaderId); - this.mockGPUBuffer = new Mock>(); + this.mockGpuBuffer = new Mock>(); this.mockBatchingManager = new Mock(); @@ -173,7 +173,7 @@ public void Ctor_WithNullOpenGLServiceParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, null, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, this.mockBatchingManager.Object); }; @@ -215,7 +215,7 @@ public void Ctor_WithNullShaderParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, null, this.mockBatchingManager.Object); }; @@ -236,7 +236,7 @@ public void Ctor_WithNullBatchManagerParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, null); }; @@ -283,7 +283,7 @@ public void Render_WithNoFontItemsToRender_SetsUpCorrectDebugGroupAndExits() m.BeginGroup(It.Is(value => value.StartsWith("Update Character Data - TextureID")))); this.mockGL.VerifyNever(m => m.ActiveTexture(It.IsAny())); this.mockGLService.VerifyNever(m => m.BindTexture2D(It.IsAny())); - this.mockGPUBuffer.VerifyNever(m => + this.mockGpuBuffer.VerifyNever(m => m.UploadData(It.IsAny(), It.IsAny())); this.mockGLService.VerifyNever(m => m.BeginGroup(It.Is(value => value.StartsWith("Render ") && value.EndsWith(" Font Elements")))); @@ -872,7 +872,7 @@ public void Render_WhenInvoked_RendersFont() GLDrawElementsType.UnsignedInt, nint.Zero)); this.mockGLService.VerifyOnce(m => m.BindTexture2D(AtlasTextureId)); - this.mockGPUBuffer + this.mockGpuBuffer .VerifyExactly(m => m.UploadData(It.IsAny(), It.IsAny()), renderText.Length); } @@ -932,7 +932,7 @@ private FontRenderer CreateSystemUnderTest() => new (this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, this.mockBatchingManager.Object); diff --git a/Testing/VelaptorTests/Graphics/Renderers/LineRendererTests.cs b/Testing/VelaptorTests/Graphics/Renderers/LineRendererTests.cs index 842cd286e..075e68d4f 100644 --- a/Testing/VelaptorTests/Graphics/Renderers/LineRendererTests.cs +++ b/Testing/VelaptorTests/Graphics/Renderers/LineRendererTests.cs @@ -43,7 +43,7 @@ public class LineRendererTests private readonly Mock mockGL; private readonly Mock mockGLService; private readonly Mock mockShader; - private readonly Mock> mockGPUBuffer; + private readonly Mock> mockGpuBuffer; private readonly Mock mockBatchingManager; private readonly Mock mockReactableFactory; private readonly Mock mockBatchBegunUnsubscriber; @@ -67,7 +67,7 @@ public LineRendererTests() this.mockShader = new Mock(); this.mockShader.Setup(m => m.ShaderId).Returns(LineShaderId); - this.mockGPUBuffer = new Mock>(); + this.mockGpuBuffer = new Mock>(); this.mockBatchingManager = new Mock(); @@ -154,7 +154,7 @@ public void Ctor_WithNullOpenGLServiceParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, null, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, this.mockBatchingManager.Object); }; @@ -196,7 +196,7 @@ public void Ctor_WithNullShaderParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, null, this.mockBatchingManager.Object); }; @@ -217,7 +217,7 @@ public void Ctor_WithNullBatchManagerParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, null); }; @@ -383,7 +383,7 @@ public void Render_WithNoLineItemsToRender_SetsUpCorrectDebugGroupAndExits() m.BeginGroup(It.Is(value => value.StartsWith("Update Line Data - TextureID")))); this.mockGL.VerifyNever(m => m.ActiveTexture(It.IsAny())); this.mockGLService.VerifyNever(m => m.BindTexture2D(It.IsAny())); - this.mockGPUBuffer.VerifyNever(m => + this.mockGpuBuffer.VerifyNever(m => m.UploadData(It.IsAny(), It.IsAny())); this.mockGLService.VerifyNever(m => m.BeginGroup(It.Is(value => value.StartsWith("Render ") && value.EndsWith(" Texture Elements")))); @@ -400,7 +400,7 @@ public void Render_WhenInvoked_RendersLine() // Arrange const uint batchIndex = 0; - var rect = new Line( + var line = new Line( new Vector2(1, 2), new Vector2(3, 4), Color.FromArgb(5, 6, 7, 8), @@ -418,7 +418,7 @@ public void Render_WhenInvoked_RendersLine() var sut = CreateSystemUnderTest(); this.batchHasBegunReactor.OnReceive(); - sut.Render(rect); + sut.Render(line); // Act this.renderReactor.OnReceive(renderItems); @@ -427,7 +427,7 @@ public void Render_WhenInvoked_RendersLine() this.mockGLService.VerifyOnce(m => m.BeginGroup("Render 6 Line Elements")); this.mockGLService.VerifyExactly(m => m.EndGroup(), 3); this.mockGL.VerifyOnce(m => m.DrawElements(GLPrimitiveType.Triangles, 6, GLDrawElementsType.UnsignedInt, nint.Zero)); - this.mockGPUBuffer.VerifyOnce(m => m.UploadData(batchItem, batchIndex)); + this.mockGpuBuffer.VerifyOnce(m => m.UploadData(batchItem, batchIndex)); } #endregion @@ -457,7 +457,7 @@ private LineRenderer CreateSystemUnderTest() => new (this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, this.mockBatchingManager.Object); } diff --git a/Testing/VelaptorTests/Graphics/Renderers/ShapeRendererTests.cs b/Testing/VelaptorTests/Graphics/Renderers/ShapeRendererTests.cs index 0c294f0ca..30de7fe2e 100644 --- a/Testing/VelaptorTests/Graphics/Renderers/ShapeRendererTests.cs +++ b/Testing/VelaptorTests/Graphics/Renderers/ShapeRendererTests.cs @@ -38,11 +38,11 @@ namespace VelaptorTests.Graphics.Renderers; /// public class ShapeRendererTests { - private const uint RectShaderId = 3333u; + private const uint ShapeShaderId = 3333u; private readonly Mock mockGL; private readonly Mock mockGLService; private readonly Mock mockShader; - private readonly Mock> mockGPUBuffer; + private readonly Mock> mockGpuBuffer; private readonly Mock mockBatchingManager; private readonly Mock mockBatchBegunUnsubscriber; private readonly Mock mockRenderUnsubscriber; @@ -64,9 +64,9 @@ public ShapeRendererTests() this.mockGLService.Setup(m => m.GetViewPortSize()).Returns(new Size(800, 600)); this.mockShader = new Mock(); - this.mockShader.SetupGet(p => p.ShaderId).Returns(RectShaderId); + this.mockShader.SetupGet(p => p.ShaderId).Returns(ShapeShaderId); - this.mockGPUBuffer = new Mock>(); + this.mockGpuBuffer = new Mock>(); this.mockBatchingManager = new Mock(); this.mockBatchingManager.Name = nameof(this.mockBatchingManager); @@ -110,19 +110,19 @@ public ShapeRendererTests() return null; }); - var mockRectRenderBatchReactable = new Mock>(); - mockRectRenderBatchReactable + var mockShapeRenderBatchReactable = new Mock>(); + mockShapeRenderBatchReactable .Setup(m => m.Subscribe(It.IsAny())) .Callback(reactor => { reactor.Should().NotBeNull("it is required for unit testing."); - reactor.Name.Should().Be($"ShapeRendererTests.Ctor - {nameof(PushNotifications.RenderRectsId)}"); + reactor.Name.Should().Be($"ShapeRendererTests.Ctor - {nameof(PushNotifications.RenderShapesId)}"); this.renderReactor = reactor; }) .Returns(reactor => { - if (reactor.Id == PushNotifications.RenderRectsId) + if (reactor.Id == PushNotifications.RenderShapesId) { return this.mockRenderUnsubscriber.Object; } @@ -134,8 +134,8 @@ public ShapeRendererTests() this.mockReactableFactory = new Mock(); this.mockReactableFactory.Setup(m => m.CreateNoDataPushReactable()) .Returns(mockPushReactable.Object); - this.mockReactableFactory.Setup(m => m.CreateRenderRectReactable()) - .Returns(mockRectRenderBatchReactable.Object); + this.mockReactableFactory.Setup(m => m.CreateRenderShapeReactable()) + .Returns(mockShapeRenderBatchReactable.Object); var mockFontTextureAtlas = new Mock(); mockFontTextureAtlas.SetupGet(p => p.Width).Returns(200); @@ -153,7 +153,7 @@ public void Ctor_WithNullOpenGLServiceParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, null, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, this.mockBatchingManager.Object); }; @@ -195,7 +195,7 @@ public void Ctor_WithNullShaderParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, null, this.mockBatchingManager.Object); }; @@ -216,7 +216,7 @@ public void Ctor_WithNullBatchManagerParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, null); }; @@ -230,10 +230,10 @@ public void Ctor_WithNullBatchManagerParam_ThrowsException() #region Method Tests [Fact] - public void Render_WhenRenderingRect_AddsRectToBatch() + public void Render_WhenRenderingShape_AddsShapeToBatch() { // Arrange - var rect = new RectShape + var rectShape = new RectShape { Position = new Vector2(11, 22), Width = 33u, @@ -263,10 +263,10 @@ public void Render_WhenRenderingRect_AddsRectToBatch() this.batchHasBegunReactor.OnReceive(); // Act - sut.Render(rect, 123); + sut.Render(rectShape, 123); // Assert - this.mockBatchingManager.VerifyOnce(m => m.AddRectItem(expected, 123, It.IsAny())); + this.mockBatchingManager.VerifyOnce(m => m.AddShapeItem(expected, 123, It.IsAny())); } [Fact] @@ -310,10 +310,10 @@ public void Render_WhenRenderingRect_RendersRectangle() this.renderReactor.OnReceive(renderItems); // Assert - this.mockGLService.VerifyOnce(m => m.BeginGroup("Render 6 Rectangle Elements")); + this.mockGLService.VerifyOnce(m => m.BeginGroup("Render 6 Shape Elements")); this.mockGLService.VerifyExactly(m => m.EndGroup(), 3); this.mockGL.VerifyOnce(m => m.DrawElements(GLPrimitiveType.Triangles, 6, GLDrawElementsType.UnsignedInt, nint.Zero)); - this.mockGPUBuffer.VerifyOnce(m => m.UploadData(batchItem, batchIndex)); + this.mockGpuBuffer.VerifyOnce(m => m.UploadData(batchItem, batchIndex)); } [Fact] @@ -321,11 +321,11 @@ public void Render_WhenRenderingRectAndBegunHasNotBeenInvoked_ThrowsException() { // Arrange const string expected = "The 'Begin()' method must be invoked first before any 'Render()' methods."; - var rect = default(RectShape); + var rectShape = default(RectShape); var sut = CreateSystemUnderTest(); // Act - var act = () => sut.Render(rect); + var act = () => sut.Render(rectShape); // Assert act.Should().Throw() @@ -367,7 +367,7 @@ public void Render_WhenRenderingCircle_AddsCircleToBatch() sut.Render(circle, 123); // Assert - this.mockBatchingManager.VerifyOnce(m => m.AddRectItem(expected, 123, It.IsAny())); + this.mockBatchingManager.VerifyOnce(m => m.AddShapeItem(expected, 123, It.IsAny())); } [Fact] @@ -409,10 +409,10 @@ public void Render_WhenRenderingCircle_RendersCircle() this.renderReactor.OnReceive(renderItems); // Assert - this.mockGLService.VerifyOnce(m => m.BeginGroup("Render 6 Rectangle Elements")); + this.mockGLService.VerifyOnce(m => m.BeginGroup("Render 6 Shape Elements")); this.mockGLService.VerifyExactly(m => m.EndGroup(), 3); this.mockGL.VerifyOnce(m => m.DrawElements(GLPrimitiveType.Triangles, 6, GLDrawElementsType.UnsignedInt, nint.Zero)); - this.mockGPUBuffer.VerifyOnce(m => m.UploadData(batchItem, batchIndex)); + this.mockGpuBuffer.VerifyOnce(m => m.UploadData(batchItem, batchIndex)); } [Fact] @@ -452,7 +452,7 @@ public void PushReactable_WithShutDownNotification_ShutsDownRenderer() public void Render_WithNoRectItemsToRender_SetsUpCorrectDebugGroupAndExits() { // Arrange - const string shaderName = "TestRectShader"; + const string shaderName = "TestShapeShader"; this.mockShader.SetupGet(p => p.Name).Returns(shaderName); _ = CreateSystemUnderTest(); @@ -460,15 +460,15 @@ public void Render_WithNoRectItemsToRender_SetsUpCorrectDebugGroupAndExits() this.renderReactor.OnReceive(default); // Assert - this.mockGLService.VerifyOnce(m => m.BeginGroup("Render Rectangle Process - Nothing To Render")); + this.mockGLService.VerifyOnce(m => m.BeginGroup("Render Shape Process - Nothing To Render")); this.mockGLService.VerifyOnce(m => m.EndGroup()); - this.mockGLService.VerifyNever(m => m.BeginGroup($"Render Rectangle Process With {shaderName} Shader")); + this.mockGLService.VerifyNever(m => m.BeginGroup($"Render Shape Process With {shaderName} Shader")); this.mockShader.VerifyNever(m => m.Use()); this.mockGLService.VerifyNever(m => m.BeginGroup(It.Is(value => value.StartsWith("Update Rectangle Data - TextureID")))); this.mockGL.VerifyNever(m => m.ActiveTexture(It.IsAny())); this.mockGLService.VerifyNever(m => m.BindTexture2D(It.IsAny())); - this.mockGPUBuffer.VerifyNever(m => + this.mockGpuBuffer.VerifyNever(m => m.UploadData(It.IsAny(), It.IsAny())); this.mockGLService.VerifyNever(m => m.BeginGroup(It.Is(value => value.StartsWith("Render ") && value.EndsWith(" Texture Elements")))); @@ -488,7 +488,7 @@ private ShapeRenderer CreateSystemUnderTest() => new (this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, this.mockBatchingManager.Object); } diff --git a/Testing/VelaptorTests/Graphics/Renderers/TextureRendererTests.cs b/Testing/VelaptorTests/Graphics/Renderers/TextureRendererTests.cs index 59e1cb966..506f2be08 100644 --- a/Testing/VelaptorTests/Graphics/Renderers/TextureRendererTests.cs +++ b/Testing/VelaptorTests/Graphics/Renderers/TextureRendererTests.cs @@ -42,7 +42,7 @@ public class TextureRendererTests private const uint TextureId = 456u; private readonly Mock mockGL; private readonly Mock mockGLService; - private readonly Mock> mockGPUBuffer; + private readonly Mock> mockGpuBuffer; private readonly Mock mockShader; private readonly Mock mockBatchingManager; private readonly Mock mockReactableFactory; @@ -60,7 +60,7 @@ public TextureRendererTests() this.mockGL = new Mock(); this.mockGLService = new Mock(); this.mockShader = new Mock(); - this.mockGPUBuffer = new Mock>(); + this.mockGpuBuffer = new Mock>(); this.mockBatchingManager = new Mock(); this.mockBatchingManager.Name = nameof(this.mockBatchingManager); @@ -140,7 +140,7 @@ public void Ctor_WithNullOpenGLServiceParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, null, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, this.mockBatchingManager.Object); }; @@ -182,7 +182,7 @@ public void Ctor_WithNullShaderParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, null, this.mockBatchingManager.Object); }; @@ -203,7 +203,7 @@ public void Ctor_WithNullBatchManagerParam_ThrowsException() this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, null); }; @@ -302,7 +302,7 @@ public void Render_WithNoTextureItemsToRender_SetsUpCorrectDebugGroupAndExits() m.BeginGroup(It.Is(value => value.StartsWith("Update Texture Data - TextureID")))); this.mockGL.VerifyNever(m => m.ActiveTexture(It.IsAny())); this.mockGLService.VerifyNever(m => m.BindTexture2D(It.IsAny())); - this.mockGPUBuffer.VerifyNever(m => + this.mockGpuBuffer.VerifyNever(m => m.UploadData(It.IsAny(), It.IsAny())); this.mockGLService.VerifyNever(m => m.BeginGroup(It.Is(value => value.StartsWith("Render ") && value.EndsWith(" Texture Elements")))); @@ -778,8 +778,8 @@ public void Render_With8ParamOverload_RendersTexture() this.mockGL.VerifyOnce(m => m.DrawElements(GLPrimitiveType.Triangles, expectedTotalElements, GLDrawElementsType.UnsignedInt, nint.Zero)); this.mockGLService.VerifyOnce(m => m.BindTexture2D(TextureId)); - this.mockGPUBuffer.VerifyOnce(m => m.UploadData(batchItemA, itemABatchIndex)); - this.mockGPUBuffer.VerifyOnce(m => m.UploadData(batchItemB, itemBBatchIndex)); + this.mockGpuBuffer.VerifyOnce(m => m.UploadData(batchItemA, itemABatchIndex)); + this.mockGpuBuffer.VerifyOnce(m => m.UploadData(batchItemB, itemBBatchIndex)); } #endregion @@ -863,7 +863,7 @@ private TextureRenderer CreateSystemUnderTest() => new (this.mockGL.Object, this.mockReactableFactory.Object, this.mockGLService.Object, - this.mockGPUBuffer.Object, + this.mockGpuBuffer.Object, this.mockShader.Object, this.mockBatchingManager.Object); } diff --git a/Testing/VelaptorTests/Helpers/AssertExtensions.cs b/Testing/VelaptorTests/Helpers/AssertExtensions.cs index f089738cf..c028f28e6 100644 --- a/Testing/VelaptorTests/Helpers/AssertExtensions.cs +++ b/Testing/VelaptorTests/Helpers/AssertExtensions.cs @@ -41,7 +41,7 @@ public static void DoesNotThrow(Action? testCode) { if (testCode is null) { - Assert.Fail($"{TableFlip}Cannot perform assertion with null '{testCode}' parameter."); + Fail($"{TableFlip}Cannot perform assertion with null '{testCode}' parameter."); } try @@ -50,7 +50,7 @@ public static void DoesNotThrow(Action? testCode) } catch (T) { - Assert.Fail($"{TableFlip}Expected the exception {typeof(T).Name} to not be thrown."); + Fail($"{TableFlip}Expected the exception {typeof(T).Name} to not be thrown."); } } @@ -69,32 +69,32 @@ public static void SectionEquals(float[]? expectedItems, float[]? actualItems, i { if (expectedItems is null) { - Assert.Fail($"The '{nameof(SectionEquals)}()' method param '{nameof(expectedItems)}' must not be null."); + Fail($"The '{nameof(SectionEquals)}()' method param '{nameof(expectedItems)}' must not be null."); } if (actualItems is null) { - Assert.Fail($"The '{nameof(SectionEquals)}()' method param '{nameof(actualItems)}' must not be null."); + Fail($"The '{nameof(SectionEquals)}()' method param '{nameof(actualItems)}' must not be null."); } if (expectedItems.Length - 1 < indexStart) { - Assert.Fail($"The '{nameof(indexStart)}' value must be less than the '{nameof(expectedItems)}'.Length."); + Fail($"The '{nameof(indexStart)}' value must be less than the '{nameof(expectedItems)}'.Length."); } if (expectedItems.Length - 1 < indexStop) { - Assert.Fail($"The '{nameof(indexStop)}' value must be less than the '{nameof(actualItems)}'.Length."); + Fail($"The '{nameof(indexStop)}' value must be less than the '{nameof(actualItems)}'.Length."); } if (actualItems.Length - 1 < indexStart) { - Assert.Fail($"The '{nameof(indexStart)}' value must be less than the '{nameof(expectedItems)}'.Length."); + Fail($"The '{nameof(indexStart)}' value must be less than the '{nameof(expectedItems)}'.Length."); } if (actualItems.Length - 1 < indexStop) { - Assert.Fail($"The '{nameof(indexStop)}' value must be less than the '{nameof(actualItems)}'.Length."); + Fail($"The '{nameof(indexStop)}' value must be less than the '{nameof(actualItems)}'.Length."); } for (var i = indexStart; i < indexStop; i++) @@ -139,7 +139,7 @@ public static void All(T[,] collection, uint width, uint height, Action."; userMessage += " Are there any items?"; - Assert.True(actionInvoked, userMessage); + True(actionInvoked, userMessage); } /// @@ -162,7 +162,7 @@ public static void All(T[] collection, Action action) userMessage += $"No assertions were actually made in {nameof(AssertExtensions)}.{nameof(All)}."; userMessage += " Are there any items?"; - Assert.True(actionInvoked, userMessage); + True(actionInvoked, userMessage); } /// @@ -177,7 +177,7 @@ public static void EqualWithMessage(T? expected, T? actual, string message) { try { - Assert.True(expected.Equals(actual), string.IsNullOrEmpty(message) ? string.Empty : message); + True(expected.Equals(actual), string.IsNullOrEmpty(message) ? string.Empty : message); } catch (Exception) { diff --git a/Testing/VelaptorTests/Helpers/BatchItemFactory.cs b/Testing/VelaptorTests/Helpers/BatchItemFactory.cs index d769989dd..d29465e24 100644 --- a/Testing/VelaptorTests/Helpers/BatchItemFactory.cs +++ b/Testing/VelaptorTests/Helpers/BatchItemFactory.cs @@ -163,7 +163,7 @@ public static FontGlyphBatchItem[] CreateFontItemsWithOrderedValues( "StyleCop.CSharp.DocumentationRules", "SA1611:Element parameters should be documented", Justification = "Not required for unit testing.")] - public static ShapeBatchItem CreateRectItemWithOrderedValues( + public static ShapeBatchItem CreateShapeItemWithOrderedValues( Vector2 position = default, float width = 0f, float height = 0f, @@ -193,7 +193,7 @@ public static ShapeBatchItem CreateRectItemWithOrderedValues( "StyleCop.CSharp.DocumentationRules", "SA1611:Element parameters should be documented", Justification = "Not required for unit testing.")] - public static ShapeBatchItem[] CreateRectItemsWithOrderedValues( + public static ShapeBatchItem[] CreateShapeItemsWithOrderedValues( Vector2 position = default, float width = 0f, float height = 0f, @@ -210,7 +210,7 @@ public static ShapeBatchItem[] CreateRectItemsWithOrderedValues( for (var i = 0; i < totalItems; i++) { - result.Add(CreateRectItemWithOrderedValues( + result.Add(CreateShapeItemWithOrderedValues( position, width, height, diff --git a/Testing/VelaptorTests/Helpers/RectGPUDataGenerator.cs b/Testing/VelaptorTests/Helpers/ShapeGpuDataGenerator.cs similarity index 89% rename from Testing/VelaptorTests/Helpers/RectGPUDataGenerator.cs rename to Testing/VelaptorTests/Helpers/ShapeGpuDataGenerator.cs index 45d0e0e01..2c5054b58 100644 --- a/Testing/VelaptorTests/Helpers/RectGPUDataGenerator.cs +++ b/Testing/VelaptorTests/Helpers/ShapeGpuDataGenerator.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -7,38 +7,38 @@ namespace VelaptorTests.Helpers; using System.Diagnostics.CodeAnalysis; using System.Drawing; using System.Numerics; -using Velaptor.OpenGL.GPUData; +using Velaptor.OpenGL.GpuData; /// -/// Helps generate easily for the purpose of testing. +/// Helps generate easily for the purpose of testing. /// [SuppressMessage("csharpsquid", "S101", Justification = "Class naming is fine.")] -internal static class RectGPUDataGenerator +internal static class ShapeGpuDataGenerator { /// - /// Generates a instance with the component values beginning at value + /// Generates a instance with the component values beginning at value /// with each component getting larger by 1. /// /// The start value of the component values. /// The instance used for testing. - public static RectGPUData GenerateGPUData(float start) + public static ShapeGpuData GenerateGpuData(float start) { var vertex1 = GenerateVertexData(start, out var next); var vertex2 = GenerateVertexData(next, out next); var vertex3 = GenerateVertexData(next, out next); var vertex4 = GenerateVertexData(next, out next); - return new RectGPUData(vertex1, vertex2, vertex3, vertex4); + return new ShapeGpuData(vertex1, vertex2, vertex3, vertex4); } /// - /// Generates a instance with the component values beginning at the given value + /// Generates a instance with the component values beginning at the given value /// with each component getting larger by 1. /// /// The start value of the component values. /// The next value available after all values have been used relative to the given value. /// The instance used for testing. - public static RectVertexData GenerateVertexData(float start, out float next) + public static ShapeVertexData GenerateVertexData(float start, out float next) { var pos = GenerateVector2(start, out next); var rect = GenerateVector4(next, out next); @@ -59,7 +59,7 @@ public static RectVertexData GenerateVertexData(float start, out float next) var topRightRadius = next; next += 1; - return new RectVertexData( + return new ShapeVertexData( pos, rect, color, diff --git a/Testing/VelaptorTests/InternalExtensionMethodsTests.cs b/Testing/VelaptorTests/InternalExtensionMethodsTests.cs index 692e9b3fd..71ecaad03 100644 --- a/Testing/VelaptorTests/InternalExtensionMethodsTests.cs +++ b/Testing/VelaptorTests/InternalExtensionMethodsTests.cs @@ -350,7 +350,7 @@ public void IncreaseBy_WhenInvoked_CorrectlyIncreasesItems() } [Fact] - public void ToBatchItem_WithRectShapeOverload_ReturnsCorrectResult() + public void ToBatchItem_WithShapeOverload_ReturnsCorrectResult() { // Arrange var expected = new ShapeBatchItem(new Vector2(1, 2), diff --git a/Testing/VelaptorTests/OpenGL/Buffers/FontGPUBufferTests.cs b/Testing/VelaptorTests/OpenGL/Buffers/FontGpuBufferTests.cs similarity index 96% rename from Testing/VelaptorTests/OpenGL/Buffers/FontGPUBufferTests.cs rename to Testing/VelaptorTests/OpenGL/Buffers/FontGpuBufferTests.cs index ff66ccbd7..6514e49ad 100644 --- a/Testing/VelaptorTests/OpenGL/Buffers/FontGPUBufferTests.cs +++ b/Testing/VelaptorTests/OpenGL/Buffers/FontGpuBufferTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -25,7 +25,7 @@ namespace VelaptorTests.OpenGL.Buffers; using Velaptor.ReactableData; using Xunit; -public class FontGPUBufferTests +public class FontGpuBufferTests { private const uint VertexArrayId = 111; private const uint VertexBufferId = 222; @@ -43,9 +43,9 @@ public class FontGPUBufferTests private bool indexBufferCreated; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public FontGPUBufferTests() + public FontGpuBufferTests() { this.mockGL = new Mock(); this.mockGL.Setup(m => m.GenVertexArray()).Returns(VertexArrayId); @@ -145,7 +145,7 @@ public void Ctor_WithNullReactableFactoryParam_ThrowsException() // Arrange & Act var act = () => { - _ = new FontGPUBuffer( + _ = new FontGpuBuffer( this.mockGL.Object, this.mockGLService.Object, null); @@ -366,7 +366,7 @@ public void BatchSizeReactable_WhenSubscribing_UsesCorrectReactorName() void Act(IReactor reactor) { reactor.Should().NotBeNull("it is required for this unit test."); - reactor.Name.Should().Be("FontGPUBufferTests.Ctor - BatchSizeChangedId"); + reactor.Name.Should().Be("FontGpuBufferTests.Ctor - BatchSizeChangedId"); } } @@ -397,7 +397,7 @@ public void BatchSizeReactable_WhenReceivingNotificationWhenNotInitialized_Updat } [Fact] - public void BatchSizeReactable_WhenReceivingNotificationWhenAlreadyInitialized_UpdatesBatchSizeAndResizesBatchDataOnGPU() + public void BatchSizeReactable_WhenReceivingNotificationWhenAlreadyInitialized_UpdatesBatchSizeAndResizesBatchDataOnGpu() { // Arrange var sut = CreateSystemUnderTest(); @@ -430,10 +430,10 @@ public void ShutDownReactable_WhenReceivingNotification_ShutsDownShader() #endregion /// - /// Creates a new instance of for the purpose of testing. + /// Creates a new instance of for the purpose of testing. /// /// The instance to test. - private FontGPUBuffer CreateSystemUnderTest() => new ( + private FontGpuBuffer CreateSystemUnderTest() => new ( this.mockGL.Object, this.mockGLService.Object, this.mockReactableFactory.Object); diff --git a/Testing/VelaptorTests/OpenGL/Buffers/GPUBufferBaseTests.cs b/Testing/VelaptorTests/OpenGL/Buffers/GpuBufferBaseTests.cs similarity index 93% rename from Testing/VelaptorTests/OpenGL/Buffers/GPUBufferBaseTests.cs rename to Testing/VelaptorTests/OpenGL/Buffers/GpuBufferBaseTests.cs index 811d7f9c4..0c77117f0 100644 --- a/Testing/VelaptorTests/OpenGL/Buffers/GPUBufferBaseTests.cs +++ b/Testing/VelaptorTests/OpenGL/Buffers/GpuBufferBaseTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -24,9 +24,9 @@ namespace VelaptorTests.OpenGL.Buffers; using Xunit; /// -/// Initializes a new instance of . +/// Initializes a new instance of . /// -public class GPUBufferBaseTests +public class GpuBufferBaseTests { private const string BufferName = "UNKNOWN BUFFER"; private const uint VertexArrayId = 1256; @@ -45,9 +45,9 @@ public class GPUBufferBaseTests private IReceiveReactor? viewPortSizeReactor; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public GPUBufferBaseTests() + public GpuBufferBaseTests() { this.mockGL = new Mock(); this.mockGL.Setup(m => m.GenBuffer()).Returns(() => @@ -144,7 +144,7 @@ public void Ctor_WithNullGLInvokerParam_ThrowsException() // Arrange & Act & Assert AssertExtensions.ThrowsWithMessage(() => { - _ = new GPUBufferFake( + _ = new GpuBufferFake( null, this.mockGLService.Object, this.mockReactableFactory.Object); @@ -157,7 +157,7 @@ public void Ctor_WithNullOpenGLServiceParam_ThrowsException() // Arrange & Act & Assert AssertExtensions.ThrowsWithMessage(() => { - _ = new GPUBufferFake( + _ = new GpuBufferFake( this.mockGL.Object, null, this.mockReactableFactory.Object); @@ -170,7 +170,7 @@ public void Ctor_WithNullReactableFactoryParam_ThrowsException() // Arrange & Act & Assert AssertExtensions.ThrowsWithMessage(() => { - _ = new GPUBufferFake( + _ = new GpuBufferFake( this.mockGL.Object, this.mockGLService.Object, null); @@ -267,7 +267,7 @@ public void OpenGLInit_WhenInvoked_GeneratesVertexData() this.glInitReactor.OnReceive(); // Assert - Assert.True(sut.GenerateDataInvoked, $"The method '{nameof(GPUBufferBase.GenerateData)}'() has not been invoked."); + Assert.True(sut.GenerateDataInvoked, $"The method '{nameof(GpuBufferBase.GenerateData)}'() has not been invoked."); } [Fact] @@ -280,7 +280,7 @@ public void OpenGLInit_WhenInvoked_GeneratesIndicesData() this.glInitReactor.OnReceive(); // Assert - Assert.True(sut.GenerateIndicesInvoked, $"The method '{nameof(GPUBufferBase.GenerateData)}'() has not been invoked."); + Assert.True(sut.GenerateIndicesInvoked, $"The method '{nameof(GpuBufferBase.GenerateData)}'() has not been invoked."); } [Fact] @@ -325,7 +325,7 @@ public void OpenGLInit_WhenInvoked_SetsUpVertexArrayObject() this.glInitReactor.OnReceive(); // Assert - Assert.True(sut.SetupVAOInvoked, $"The method '{nameof(GPUBufferBase.SetupVAO)}'() has not been invoked."); + Assert.True(sut.SetupVAOInvoked, $"The method '{nameof(GpuBufferBase.SetupVAO)}'() has not been invoked."); } [Fact] @@ -365,7 +365,7 @@ public void OpenGLInit_WhenInvoked_SetsUpProperGLGrouping() this.glInitReactor.OnReceive(); // Assert - VerifyBatchDataIsUploadedToGPU(); + VerifyBatchDataIsUploadedToGpu(); this.mockGLService.Verify(m => m.BeginGroup(It.IsAny()), Times.Exactly(3)); this.mockGLService.Verify(m => m.BeginGroup(setupDataGroupName), Times.Once); this.mockGLService.Verify(m => m.BeginGroup(uploadVertexDataGroupName), Times.Once); @@ -379,7 +379,7 @@ public void OpenGLInit_WhenInvoked_SetsUpProperGLGrouping() } [Fact] - public void UploadData_WhenInvoked_PreparesGPUForDataUpload() + public void UploadData_WhenInvoked_PreparesGpuForDataUpload() { // Arrange var sut = CreateSystemUnderTest(); @@ -389,11 +389,11 @@ public void UploadData_WhenInvoked_PreparesGPUForDataUpload() sut.UploadData(batchItem, 0u); // Assert - Assert.True(sut.PrepareForUseInvoked, $"The method '{nameof(GPUBufferBase.PrepareForUpload)}'() has not been invoked."); + Assert.True(sut.PrepareForUseInvoked, $"The method '{nameof(GpuBufferBase.PrepareForUpload)}'() has not been invoked."); } [Fact] - public void UploadData_WhenInvoked_UpdatesGPUData() + public void UploadData_WhenInvoked_UpdatesGpuData() { // Arrange var sut = CreateSystemUnderTest(); @@ -403,7 +403,7 @@ public void UploadData_WhenInvoked_UpdatesGPUData() sut.UploadData(batchItem, 0u); // Assert - Assert.True(sut.UpdateVertexDataInvoked, $"The method '{nameof(GPUBufferBase.UploadVertexData)}'() has not been invoked."); + Assert.True(sut.UpdateVertexDataInvoked, $"The method '{nameof(GpuBufferBase.UploadVertexData)}'() has not been invoked."); } [Fact] @@ -451,7 +451,7 @@ public void PushReactable_WhenSubscribingToGLInitializedNotification_UsesCorrect void Act(IReactor reactor) { reactor.Should().NotBeNull("it is required for this unit test."); - reactor.Name.Should().Be("GPUBufferFake.Ctor - GLInitializedId"); + reactor.Name.Should().Be("GpuBufferFake.Ctor - GLInitializedId"); } } @@ -478,7 +478,7 @@ public void PushReactable_WhenSubscribingToSystemShutDownNotification_UsesCorrec void Act(IReactor reactor) { reactor.Should().NotBeNull("it is required for this unit test."); - reactor.Name.Should().Be("GPUBufferFake.Ctor - SystemShuttingDownId"); + reactor.Name.Should().Be("GpuBufferFake.Ctor - SystemShuttingDownId"); } } @@ -499,7 +499,7 @@ public void ViewPortSizeReactable_WhenSubscribing_UsesCorrectReactorName() void Act(IReactor reactor) { reactor.Should().NotBeNull("it is required for this unit test."); - reactor.Name.Should().Be("GPUBufferFake.Ctor - ViewPortSizeChangedId"); + reactor.Name.Should().Be("GpuBufferFake.Ctor - ViewPortSizeChangedId"); } } @@ -531,11 +531,11 @@ public void ViewPortSizeReactable_WhenReceivingNotification_UpdatesViewPortSize( #endregion /// - /// Creates an instance of the type for the purpose of - /// testing the abstract class . + /// Creates an instance of the type for the purpose of + /// testing the abstract class . /// /// The instance to test. - private GPUBufferFake CreateSystemUnderTest() => new ( + private GpuBufferFake CreateSystemUnderTest() => new ( this.mockGL.Object, this.mockGLService.Object, this.mockReactableFactory.Object); @@ -543,7 +543,7 @@ public void ViewPortSizeReactable_WhenReceivingNotification_UpdatesViewPortSize( /// /// Verifies that the correct GPU data has been sent to the GPU. /// - private void VerifyBatchDataIsUploadedToGPU() + private void VerifyBatchDataIsUploadedToGpu() { this.mockGLService.Verify(m => m.BindVBO(VertexBufferId), Times.AtLeastOnce); diff --git a/Testing/VelaptorTests/OpenGL/Buffers/LineGPUBufferTests.cs b/Testing/VelaptorTests/OpenGL/Buffers/LineGpuBufferTests.cs similarity index 93% rename from Testing/VelaptorTests/OpenGL/Buffers/LineGPUBufferTests.cs rename to Testing/VelaptorTests/OpenGL/Buffers/LineGpuBufferTests.cs index 7bcb905dc..f34d44d4e 100644 --- a/Testing/VelaptorTests/OpenGL/Buffers/LineGPUBufferTests.cs +++ b/Testing/VelaptorTests/OpenGL/Buffers/LineGpuBufferTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -29,9 +29,9 @@ namespace VelaptorTests.OpenGL.Buffers; using Xunit; /// -/// Tests the class. +/// Tests the class. /// -public class LineGPUBufferTests +public class LineGpuBufferTests { private const uint VAO = 123u; private const uint VBO = 456u; @@ -50,9 +50,9 @@ public class LineGPUBufferTests private bool vboGenerated; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public LineGPUBufferTests() + public LineGpuBufferTests() { this.mockGL = new Mock(); this.mockGL.Setup(m => m.GenVertexArray()).Returns(VAO); @@ -148,7 +148,7 @@ public void Ctor_WithNullReactableFactoryParam_ThrowsException() // Arrange & Act var act = () => { - _ = new LineGPUBuffer( + _ = new LineGpuBuffer( this.mockGL.Object, this.mockGLService.Object, null); @@ -181,8 +181,8 @@ public void UploadVertexData_WhenInvoked_BeginsAndEndsGLDebugGroup() // Arrange var executionLocations = new List { - $"1 time in the '{nameof(GPUBufferBase.UploadVertexData)}()' method.", - $"3 times in the private $'{nameof(GPUBufferBase)}.Init()' method.", + $"1 time in the '{nameof(GpuBufferBase.UploadVertexData)}()' method.", + $"3 times in the private $'{nameof(GpuBufferBase)}.Init()' method.", }; var failMessage = string.Join(Environment.NewLine, executionLocations); @@ -206,8 +206,8 @@ public void UploadVertexData_WhenInvoked_BindsAndUnbindsVBO() // Arrange var executionLocations = new List { - $"1 time in the private '{nameof(GPUBufferBase)}.Init()' method.", - $"1 time in the '{nameof(GPUBufferBase.UploadVertexData)}()' method.", + $"1 time in the private '{nameof(GpuBufferBase)}.Init()' method.", + $"1 time in the '{nameof(GpuBufferBase.UploadVertexData)}()' method.", }; var failMessage = string.Join($"{Environment.NewLine}", executionLocations); @@ -229,7 +229,7 @@ public void UploadVertexData_WhenInvoked_BindsAndUnbindsVBO() } [Fact] - public void UploadVertexData_WhenInvoked_UploadsGPUBufferData() + public void UploadVertexData_WhenInvoked_UploadsGpuBufferData() { // Arrange var expectedData = new[] @@ -291,8 +291,8 @@ public void PrepareForUpload_WhenInitialized_BindsVAO() // Arrange var executionLocations = new List { - $"1 time in the '{nameof(LineGPUBuffer.PrepareForUpload)}()' method.", - $"1 time in the '{nameof(GPUBufferBase)}.Init()' method.", + $"1 time in the '{nameof(LineGpuBuffer.PrepareForUpload)}()' method.", + $"1 time in the '{nameof(GpuBufferBase)}.Init()' method.", }; var failMessage = string.Join(Environment.NewLine, executionLocations); @@ -395,7 +395,7 @@ public void BatchSizeReactable_WhenSubscribing_UsesCorrectReactorName() void Act(IReactor reactor) { reactor.Should().NotBeNull("it is required for this unit test."); - reactor.Name.Should().Be("LineGPUBufferTests.Ctor - BatchSizeChangedId"); + reactor.Name.Should().Be("LineGpuBufferTests.Ctor - BatchSizeChangedId"); } } @@ -426,7 +426,7 @@ public void BatchSizeReactable_WhenReceivingNotificationWhenNotInitialized_Updat } [Fact] - public void BatchSizeReactable_WhenReceivingNotificationWhenAlreadyInitialized_UpdatesBatchSizeAndResizesBatchDataOnGPU() + public void BatchSizeReactable_WhenReceivingNotificationWhenAlreadyInitialized_UpdatesBatchSizeAndResizesBatchDataOnGpu() { // Arrange var sut = CreateSystemUnderTest(); @@ -485,13 +485,13 @@ private static IEnumerable CreateExpectedIndicesData(uint batchSize) } /// - /// Creates a new instance of class for the purpose of testing. + /// Creates a new instance of class for the purpose of testing. /// /// If true, will mock the initialization of the mocked sut. /// The instance to test. - private LineGPUBuffer CreateSystemUnderTest(bool initialize = true) + private LineGpuBuffer CreateSystemUnderTest(bool initialize = true) { - var result = new LineGPUBuffer( + var result = new LineGpuBuffer( this.mockGL.Object, this.mockGLService.Object, this.mockReactableFactory.Object); diff --git a/Testing/VelaptorTests/OpenGL/Buffers/ShapeGPUBufferTests.cs b/Testing/VelaptorTests/OpenGL/Buffers/ShapeGpuBufferTests.cs similarity index 91% rename from Testing/VelaptorTests/OpenGL/Buffers/ShapeGPUBufferTests.cs rename to Testing/VelaptorTests/OpenGL/Buffers/ShapeGpuBufferTests.cs index 1b0752ec2..f7656a6ee 100644 --- a/Testing/VelaptorTests/OpenGL/Buffers/ShapeGPUBufferTests.cs +++ b/Testing/VelaptorTests/OpenGL/Buffers/ShapeGpuBufferTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -30,16 +30,16 @@ namespace VelaptorTests.OpenGL.Buffers; using Xunit; /// -/// Tests the class. +/// Tests the class. /// -public class ShapeGPUBufferTests +public class ShapeGpuBufferTests { private const uint VAO = 123u; private const uint VBO = 456u; private const uint EBO = 789u; private const uint ViewPortWidth = 100u; private const uint ViewPortHeight = 200u; - private const string BufferName = "Rectangle"; + private const string BufferName = "Shape"; private readonly Mock mockGL; private readonly Mock mockGLService; private readonly Mock mockReactableFactory; @@ -51,9 +51,9 @@ public class ShapeGPUBufferTests private bool vboGenerated; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public ShapeGPUBufferTests() + public ShapeGpuBufferTests() { this.mockGL = new Mock(); this.mockGL.Setup(m => m.GenVertexArray()).Returns(VAO); @@ -149,7 +149,7 @@ public void Ctor_WithNullReactableFactoryParam_ThrowsException() // Arrange & Act var act = () => { - _ = new TextureGPUBuffer( + _ = new TextureGpuBuffer( this.mockGL.Object, this.mockGLService.Object, null); @@ -169,20 +169,20 @@ public void UploadVertexData_WhenInvoked_BeginsAndEndsGLDebugGroup() // Arrange var executionLocations = new List { - $"1 time in the '{nameof(GPUBufferBase.UploadVertexData)}()' method.", - $"3 times in the private '{nameof(GPUBufferBase)}.Init()' method.", + $"1 time in the '{nameof(GpuBufferBase.UploadVertexData)}()' method.", + $"3 times in the private '{nameof(GpuBufferBase)}.Init()' method.", }; var failMessage = string.Join(Environment.NewLine, executionLocations); - var rect = default(ShapeBatchItem); + var shape = default(ShapeBatchItem); var sut = CreateSystemUnderTest(); // Act - sut.UploadVertexData(rect, 123); + sut.UploadVertexData(shape, 123); // Assert - this.mockGLService.Verify(m => m.BeginGroup("Update Rectangle - BatchItem(123)"), Times.Once); + this.mockGLService.Verify(m => m.BeginGroup("Update Shape - BatchItem(123)"), Times.Once); this.mockGLService.Verify(m => m.EndGroup(), Times.Exactly(4), failMessage); @@ -194,17 +194,17 @@ public void UploadVertexData_WhenInvoked_BindsAndUnbindsVBO() // Arrange var executionLocations = new List { - $"1 time in the private '{nameof(GPUBufferBase)}.Init()' method.", - $"1 time in the '{nameof(GPUBufferBase.UploadVertexData)}()' method.", + $"1 time in the private '{nameof(GpuBufferBase)}.Init()' method.", + $"1 time in the '{nameof(GpuBufferBase.UploadVertexData)}()' method.", }; var failMessage = string.Join(Environment.NewLine, executionLocations); - var rect = default(ShapeBatchItem); + var shape = default(ShapeBatchItem); var sut = CreateSystemUnderTest(); // Act - sut.UploadVertexData(rect, 0); + sut.UploadVertexData(shape, 0); // Assert this.mockGLService.Verify(m => m.BindVBO(VBO), @@ -217,7 +217,7 @@ public void UploadVertexData_WhenInvoked_BindsAndUnbindsVBO() } [Fact] - public void UploadVertexData_WithSolidColor_UpdatesGPUData() + public void UploadVertexData_WithSolidColor_UpdatesGpuData() { // Arrange const nint expectedOffset = 0; @@ -230,7 +230,7 @@ public void UploadVertexData_WithSolidColor_UpdatesGPUData() -0.949999988f, 0.959999979f, 1f, 2f, 3f, 4f, 6f, 7f, 8f, 5f, 1f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, }; - var rect = new ShapeBatchItem( + var shape = new ShapeBatchItem( new Vector2(1, 2), 3, 4, @@ -258,7 +258,7 @@ public void UploadVertexData_WithSolidColor_UpdatesGPUData() this.viewPortSizeReactor.OnReceive(viewPortSizeData); // Act - sut.UploadVertexData(rect, 0); + sut.UploadVertexData(shape, 0); // Assert this.mockGL.Verify(m => @@ -271,19 +271,19 @@ public void UploadVertexData_WithSolidColor_UpdatesGPUData() public void UploadVertexData_WithInvalidColorGradientValue_ThrowsException() { // Arrange - var rect = BatchItemFactory.CreateRectItemWithOrderedValues(gradientType: (ColorGradient)1234); + var shape = BatchItemFactory.CreateShapeItemWithOrderedValues(gradientType: (ColorGradient)1234); var sut = CreateSystemUnderTest(); // Act & Assert AssertExtensions.ThrowsWithMessage(() => { - sut.UploadVertexData(rect, 0); + sut.UploadVertexData(shape, 0); }, "The gradient type is invalid. (Parameter 'GradientType')"); } [Fact] - public void UploadVertexData_WithSolidColor_UpdatesGPUDataWithCorrectColor() + public void UploadVertexData_WithSolidColor_UpdatesGpuDataWithCorrectColor() { // Arrange // We only care about the section of raw data where the color is located. @@ -323,7 +323,7 @@ public void UploadVertexData_WithSolidColor_UpdatesGPUDataWithCorrectColor() }); #pragma warning disable SA1117 - var rect = new ShapeBatchItem( + var shape = new ShapeBatchItem( position: new Vector2(1, 2), width: 3, height: 4, @@ -339,7 +339,7 @@ public void UploadVertexData_WithSolidColor_UpdatesGPUDataWithCorrectColor() var sut = CreateSystemUnderTest(); // Act - sut.UploadVertexData(rect, 0); + sut.UploadVertexData(shape, 0); // Assert AssertExtensions.SectionEquals(expectedRawData, actualRawData, 6, 9); // Vertex 1 Color @@ -349,7 +349,7 @@ public void UploadVertexData_WithSolidColor_UpdatesGPUDataWithCorrectColor() } [Fact] - public void UploadVertexData_WithHorizontalColorGradient_UpdatesGPUDataWithCorrectColor() + public void UploadVertexData_WithHorizontalColorGradient_UpdatesGpuDataWithCorrectColor() { // Arrange // We only care about the section of raw data where the color is located. @@ -389,7 +389,7 @@ public void UploadVertexData_WithHorizontalColorGradient_UpdatesGPUDataWithCorre }); #pragma warning disable SA1117 - var rect = new ShapeBatchItem( + var shape = new ShapeBatchItem( position: new Vector2(1, 2), width: 3, height: 4, @@ -405,7 +405,7 @@ public void UploadVertexData_WithHorizontalColorGradient_UpdatesGPUDataWithCorre var sut = CreateSystemUnderTest(); // Act - sut.UploadVertexData(rect, 0); + sut.UploadVertexData(shape, 0); // Assert AssertExtensions.SectionEquals(expectedRawData, actualRawData, 6, 9); // Vertex 1 Color | Grad Start @@ -415,7 +415,7 @@ public void UploadVertexData_WithHorizontalColorGradient_UpdatesGPUDataWithCorre } [Fact] - public void UploadVertexData_WithVerticalColorGradient_UpdatesGPUDataWithCorrectColor() + public void UploadVertexData_WithVerticalColorGradient_UpdatesGpuDataWithCorrectColor() { // Arrange // We only care about the section of raw data where the color is located. @@ -454,12 +454,12 @@ public void UploadVertexData_WithVerticalColorGradient_UpdatesGPUDataWithCorrect actualRawData = data; }); - var rect = BatchItemFactory.CreateRectItemWithOrderedValues(); + var shape = BatchItemFactory.CreateShapeItemWithOrderedValues(); var sut = CreateSystemUnderTest(); // Act - sut.UploadVertexData(rect, 0); + sut.UploadVertexData(shape, 0); // Assert AssertExtensions.SectionEquals(expectedRawData, actualRawData, 6, 9); // Vertex 1 Color | Grad Start @@ -478,7 +478,7 @@ public void PrepareForUpload_WhenNotInitialized_ThrowsException() AssertExtensions.ThrowsWithMessage(() => { sut.PrepareForUpload(); - }, "The rectangle buffer has not been initialized."); + }, "The shape buffer has not been initialized."); } [Fact] @@ -487,8 +487,8 @@ public void PrepareForUpload_WhenInitialized_BindsVAO() // Arrange var executionLocations = new List { - $"1 time in the '{nameof(ShapeGPUBuffer.PrepareForUpload)}()' method.", - $"1 time in the '{nameof(GPUBufferBase)}.Init()' method.", + $"1 time in the '{nameof(ShapeGpuBuffer.PrepareForUpload)}()' method.", + $"1 time in the '{nameof(GpuBufferBase)}.Init()' method.", }; var failMessage = string.Join(Environment.NewLine, executionLocations); @@ -507,7 +507,7 @@ public void GenerateData_WhenInvoked_ReturnsCorrectResult() // Arrange var expected = TestDataLoader .LoadTestData(string.Empty, - $"{nameof(ShapeGPUBufferTests)}.{nameof(GenerateData_WhenInvoked_ReturnsCorrectResult)}.json"); + $"{nameof(ShapeGpuBufferTests)}.{nameof(GenerateData_WhenInvoked_ReturnsCorrectResult)}.json"); var sut = CreateSystemUnderTest(false); // Act @@ -607,7 +607,7 @@ public void BatchSizeReactable_WhenSubscribing_UsesCorrectReactorName() void Act(IReactor reactor) { reactor.Should().NotBeNull("it is required for this unit test."); - reactor.Name.Should().Be("ShapeGPUBufferTests.Ctor - BatchSizeChangedId"); + reactor.Name.Should().Be("ShapeGpuBufferTests.Ctor - BatchSizeChangedId"); } } @@ -638,7 +638,7 @@ public void BatchSizeReactable_WhenReceivingNotificationWhenNotInitialized_Updat } [Fact] - public void BatchSizeReactable_WhenReceivingNotificationWhenAlreadyInitialized_UpdatesBatchSizeAndResizesBatchDataOnGPU() + public void BatchSizeReactable_WhenReceivingNotificationWhenAlreadyInitialized_UpdatesBatchSizeAndResizesBatchDataOnGpu() { // Arrange var sut = CreateSystemUnderTest(); @@ -697,13 +697,13 @@ private static uint[] CreateExpectedIndicesData(uint batchSize) } /// - /// Creates a new instance of class for the purpose of testing. + /// Creates a new instance of class for the purpose of testing. /// /// If true, will mock the initialization of the mocked sut. /// The instance to test. - private ShapeGPUBuffer CreateSystemUnderTest(bool initialize = true) + private ShapeGpuBuffer CreateSystemUnderTest(bool initialize = true) { - var result = new ShapeGPUBuffer( + var result = new ShapeGpuBuffer( this.mockGL.Object, this.mockGLService.Object, this.mockReactableFactory.Object); diff --git a/Testing/VelaptorTests/OpenGL/Buffers/TextureGPUBufferTests.cs b/Testing/VelaptorTests/OpenGL/Buffers/TextureGpuBufferTests.cs similarity index 96% rename from Testing/VelaptorTests/OpenGL/Buffers/TextureGPUBufferTests.cs rename to Testing/VelaptorTests/OpenGL/Buffers/TextureGpuBufferTests.cs index fbf4f4d32..6be918c39 100644 --- a/Testing/VelaptorTests/OpenGL/Buffers/TextureGPUBufferTests.cs +++ b/Testing/VelaptorTests/OpenGL/Buffers/TextureGpuBufferTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -28,9 +28,9 @@ namespace VelaptorTests.OpenGL.Buffers; using Xunit; /// -/// Tests the class. +/// Tests the class. /// -public class TextureGPUBufferTests +public class TextureGpuBufferTests { private const uint VertexArrayId = 111; private const uint VertexBufferId = 222; @@ -48,9 +48,9 @@ public class TextureGPUBufferTests private bool indexBufferCreated; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public TextureGPUBufferTests() + public TextureGpuBufferTests() { this.mockGL = new Mock(); this.mockGL.Setup(m => m.GenVertexArray()).Returns(VertexArrayId); @@ -139,7 +139,7 @@ public TextureGPUBufferTests() /// Provides sample data to test if the correct data is being sent to the GPU. /// /// The data to test against. - public static IEnumerable GetGPUUploadTestData() + public static IEnumerable GetGpuUploadTestData() { yield return new object[] { @@ -194,7 +194,7 @@ public void Ctor_WithNullReactableFactoryParam_ThrowsException() // Arrange & Act var act = () => { - _ = new TextureGPUBuffer( + _ = new TextureGpuBuffer( this.mockGL.Object, this.mockGLService.Object, null); @@ -269,7 +269,7 @@ public void UploadVertexData_WhenInvoked_CreatesOpenGLDebugGroups() } [Theory] - [MemberData(nameof(GetGPUUploadTestData))] + [MemberData(nameof(GetGpuUploadTestData))] public void UploadVertexData_WhenInvoked_UploadsData(RenderEffects effects, float[] expected) { // Arrange @@ -428,7 +428,7 @@ public void BatchSizeReactable_WhenSubscribing_UsesCorrectReactorName() void Act(IReactor reactor) { reactor.Should().NotBeNull("it is required for this unit test."); - reactor.Name.Should().Be("TextureGPUBufferTests.Ctor - BatchSizeChangedId"); + reactor.Name.Should().Be("TextureGpuBufferTests.Ctor - BatchSizeChangedId"); } } @@ -459,7 +459,7 @@ public void BatchSizeReactable_WhenReceivingNotificationWhenNotInitialized_Updat } [Fact] - public void BatchSizeReactable_WhenReceivingNotificationWhenAlreadyInitialized_UpdatesBatchSizeAndResizesBatchDataOnGPU() + public void BatchSizeReactable_WhenReceivingNotificationWhenAlreadyInitialized_UpdatesBatchSizeAndResizesBatchDataOnGpu() { // Arrange var sut = CreateSystemUnderTest(); @@ -492,10 +492,10 @@ public void ShutDownReactable_WhenReceivingNotification_ShutsDownShader() #endregion /// - /// Creates a new instance of for the purpose of testing. + /// Creates a new instance of for the purpose of testing. /// /// The instance to test. - private TextureGPUBuffer CreateSystemUnderTest() => new ( + private TextureGpuBuffer CreateSystemUnderTest() => new ( this.mockGL.Object, this.mockGLService.Object, this.mockReactableFactory.Object); diff --git a/Testing/VelaptorTests/OpenGL/GPUBufferNameAttributeTests.cs b/Testing/VelaptorTests/OpenGL/GpuBufferNameAttributeTests.cs similarity index 73% rename from Testing/VelaptorTests/OpenGL/GPUBufferNameAttributeTests.cs rename to Testing/VelaptorTests/OpenGL/GpuBufferNameAttributeTests.cs index cd1277956..b04e37615 100644 --- a/Testing/VelaptorTests/OpenGL/GPUBufferNameAttributeTests.cs +++ b/Testing/VelaptorTests/OpenGL/GpuBufferNameAttributeTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -10,9 +10,9 @@ namespace VelaptorTests.OpenGL; using Xunit; /// -/// Tests the class. +/// Tests the class. /// -public class GPUBufferNameAttributeTests +public class GpuBufferNameAttributeTests { #region Constructor Tests [Theory] @@ -23,7 +23,7 @@ public void Ctor_WithNullOrEmptyNameParam_ThrowsException(string value) // Act & Assert AssertExtensions.ThrowsWithMessage(() => { - _ = new GPUBufferNameAttribute(value); + _ = new GpuBufferNameAttribute(value); }, "The string parameter must not be null or empty. (Parameter 'name')"); } @@ -31,7 +31,7 @@ public void Ctor_WithNullOrEmptyNameParam_ThrowsException(string value) public void Ctor_WhenInvoked_SetsProperty() { // Arrange & Act - var attribute = new GPUBufferNameAttribute("test-name"); + var attribute = new GpuBufferNameAttribute("test-name"); // Assert Assert.Equal("test-name", attribute.Name); diff --git a/Testing/VelaptorTests/OpenGL/GPUData/LineGPUDataTests.cs b/Testing/VelaptorTests/OpenGL/GpuData/LineGpuDataTests.cs similarity index 90% rename from Testing/VelaptorTests/OpenGL/GPUData/LineGPUDataTests.cs rename to Testing/VelaptorTests/OpenGL/GpuData/LineGpuDataTests.cs index 8c321c943..ac112cda3 100644 --- a/Testing/VelaptorTests/OpenGL/GPUData/LineGPUDataTests.cs +++ b/Testing/VelaptorTests/OpenGL/GpuData/LineGpuDataTests.cs @@ -1,20 +1,20 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // -namespace VelaptorTests.OpenGL.GPUData; +namespace VelaptorTests.OpenGL.GpuData; using System.Drawing; using System.Numerics; using FluentAssertions; using Helpers; -using Velaptor.OpenGL.GPUData; +using Velaptor.OpenGL.GpuData; using Xunit; /// -/// Tests the struct. +/// Tests the struct. /// -public class LineGPUDataTests +public class LineGpuDataTests { #region Constructor Tests [Fact] @@ -27,7 +27,7 @@ public void Ctor_WhenInvoked_CorrectlySetsProps() var expectedV4 = CreateVertexData(4); // Act - var sut = new LineGPUData(expectedV1, expectedV2, expectedV3, expectedV4); + var sut = new LineGpuData(expectedV1, expectedV2, expectedV3, expectedV4); // Assert sut.Vertex1.Should().Be(expectedV1); @@ -40,7 +40,7 @@ public void Ctor_WhenInvoked_CorrectlySetsProps() public void GetTotalBytes_WhenInvoked_ReturnsCorrectResult() { // Arrange & Act - var actual = LineGPUData.GetTotalBytes(); + var actual = LineGpuData.GetTotalBytes(); // Assert actual.Should().Be(96); @@ -50,13 +50,13 @@ public void GetTotalBytes_WhenInvoked_ReturnsCorrectResult() public void ToArray_WhenInvoked_ReturnsCorrectResult() { // Arrange - const string testDataFileName = $"{nameof(LineGPUDataTests)}.{nameof(ToArray_WhenInvoked_ReturnsCorrectResult)}.json"; + const string testDataFileName = $"{nameof(LineGpuDataTests)}.{nameof(ToArray_WhenInvoked_ReturnsCorrectResult)}.json"; var expected = TestDataLoader .LoadTestData(string.Empty, testDataFileName); var allVertexData = CreateAllOrderedVertexData(0); - var sut = new LineGPUData(allVertexData[0], allVertexData[1], allVertexData[2], allVertexData[3]); + var sut = new LineGpuData(allVertexData[0], allVertexData[1], allVertexData[2], allVertexData[3]); // Act var actual = sut.ToArray(); diff --git a/Testing/VelaptorTests/OpenGL/GPUData/LineVertexDataTests.cs b/Testing/VelaptorTests/OpenGL/GpuData/LineVertexDataTests.cs similarity index 95% rename from Testing/VelaptorTests/OpenGL/GPUData/LineVertexDataTests.cs rename to Testing/VelaptorTests/OpenGL/GpuData/LineVertexDataTests.cs index 9d81c8de6..912cc5f21 100644 --- a/Testing/VelaptorTests/OpenGL/GPUData/LineVertexDataTests.cs +++ b/Testing/VelaptorTests/OpenGL/GpuData/LineVertexDataTests.cs @@ -2,12 +2,12 @@ // Copyright (c) KinsonDigital. All rights reserved. // -namespace VelaptorTests.OpenGL.GPUData; +namespace VelaptorTests.OpenGL.GpuData; using System.Drawing; using System.Numerics; using FluentAssertions; -using Velaptor.OpenGL.GPUData; +using Velaptor.OpenGL.GpuData; using Xunit; /// diff --git a/Testing/VelaptorTests/OpenGL/GPUData/RectGPUDataTests.cs b/Testing/VelaptorTests/OpenGL/GpuData/ShapeGpuDataTests.cs similarity index 57% rename from Testing/VelaptorTests/OpenGL/GPUData/RectGPUDataTests.cs rename to Testing/VelaptorTests/OpenGL/GpuData/ShapeGpuDataTests.cs index 4f337f542..df8b2a82b 100644 --- a/Testing/VelaptorTests/OpenGL/GPUData/RectGPUDataTests.cs +++ b/Testing/VelaptorTests/OpenGL/GpuData/ShapeGpuDataTests.cs @@ -1,32 +1,32 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // -namespace VelaptorTests.OpenGL.GPUData; +namespace VelaptorTests.OpenGL.GpuData; using System.Linq; using FluentAssertions; using Helpers; -using Velaptor.OpenGL.GPUData; +using Velaptor.OpenGL.GpuData; using Xunit; /// -/// Tests the struct. +/// Tests the struct. /// -public class RectGPUDataTests +public class ShapeGpuDataTests { #region Constructor Tests [Fact] public void Ctor_WhenInvoked_SetsProperties() { // Arrange - var vertex1 = RectGPUDataGenerator.GenerateVertexData(1, out var next); - var vertex2 = RectGPUDataGenerator.GenerateVertexData(next, out next); - var vertex3 = RectGPUDataGenerator.GenerateVertexData(next, out next); - var vertex4 = RectGPUDataGenerator.GenerateVertexData(next, out next); + var vertex1 = ShapeGpuDataGenerator.GenerateVertexData(1, out var next); + var vertex2 = ShapeGpuDataGenerator.GenerateVertexData(next, out next); + var vertex3 = ShapeGpuDataGenerator.GenerateVertexData(next, out next); + var vertex4 = ShapeGpuDataGenerator.GenerateVertexData(next, out next); // Act - var data = new RectGPUData(vertex1, vertex2, vertex3, vertex4); + var data = new ShapeGpuData(vertex1, vertex2, vertex3, vertex4); // Assert data.Vertex1.Should().Be(vertex1); @@ -41,12 +41,12 @@ public void Ctor_WhenInvoked_SetsProperties() public void ToArray_WhenInvoked_ReturnsCorrectResult() { // Arrange - const string testDataFileName = $"{nameof(RectGPUData)}TestData.json"; + const string testDataFileName = $"{nameof(ShapeGpuData)}TestData.json"; var expected = TestDataLoader .LoadTestData<(string name, int index, float value)[]>(string.Empty, testDataFileName) .Select(i => i.value).ToArray(); - var data = RectGPUDataGenerator.GenerateGPUData(1); + var data = ShapeGpuDataGenerator.GenerateGpuData(1); // Act var actual = data.ToArray(); diff --git a/Testing/VelaptorTests/OpenGL/GPUData/RectVertexDataTests.cs b/Testing/VelaptorTests/OpenGL/GpuData/ShapeVertexDataTests.cs similarity index 86% rename from Testing/VelaptorTests/OpenGL/GPUData/RectVertexDataTests.cs rename to Testing/VelaptorTests/OpenGL/GpuData/ShapeVertexDataTests.cs index 4e523af2c..a7087f58a 100644 --- a/Testing/VelaptorTests/OpenGL/GPUData/RectVertexDataTests.cs +++ b/Testing/VelaptorTests/OpenGL/GpuData/ShapeVertexDataTests.cs @@ -1,27 +1,27 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // -namespace VelaptorTests.OpenGL.GPUData; +namespace VelaptorTests.OpenGL.GpuData; using System.Drawing; using System.Linq; using System.Numerics; using FluentAssertions; -using Velaptor.OpenGL.GPUData; +using Velaptor.OpenGL.GpuData; using Xunit; /// -/// Tests the struct. +/// Tests the struct. /// -public class RectVertexDataTests +public class ShapeVertexDataTests { #region Constructor Tests [Fact] public void Ctor_WhenInvoked_SetsProperties() { // Arrange & Act - var data = new RectVertexData( + var data = new ShapeVertexData( new Vector2(1, 2), new Vector4(3, 4, 5, 6), Color.FromArgb(7, 8, 9, 10), @@ -35,7 +35,7 @@ public void Ctor_WhenInvoked_SetsProperties() // Assert data.IsSolid.Should().BeTrue(); data.VertexPos.Should().Be(new Vector2(1, 2)); - data.Rectangle.Should().Be(new Vector4(3, 4, 5, 6)); + data.BoundingBox.Should().Be(new Vector4(3, 4, 5, 6)); data.Color.Should().Be(Color.FromArgb(7, 8, 9, 10)); data.BorderThickness.Should().Be(11); data.TopLeftCornerRadius.Should().Be(12); @@ -50,12 +50,12 @@ public void Ctor_WhenInvoked_SetsProperties() public void Empty_WhenInvoked_ReturnsEmptyInstance() { // Arrange & Act - var actual = RectVertexData.Empty(); + var actual = ShapeVertexData.Empty(); // Assert actual.IsSolid.Should().BeFalse(); actual.VertexPos.Should().Be(Vector2.Zero); - actual.Rectangle.Should().Be(Vector4.Zero); + actual.BoundingBox.Should().Be(Vector4.Zero); actual.Color.Should().Be(Color.Empty); actual.BorderThickness.Should().Be(0f); actual.TopLeftCornerRadius.Should().Be(0f); @@ -68,7 +68,7 @@ public void Empty_WhenInvoked_ReturnsEmptyInstance() public void GetTotalBytes_WhenInvoked_ReturnsCorrectResult() { // Arrange & Act - var actual = RectVertexData.GetStride(); + var actual = ShapeVertexData.GetStride(); // Assert actual.Should().Be(64u); @@ -78,7 +78,7 @@ public void GetTotalBytes_WhenInvoked_ReturnsCorrectResult() public void ToArray_WhenInvoked_ReturnsCorrectResult() { // Arrange - var data = new RectVertexData( + var data = new ShapeVertexData( new Vector2(1f, 2f), new Vector4(3f, 4f, 5f, 6f), Color.FromArgb(7, 8, 9, 10), diff --git a/Testing/VelaptorTests/OpenGL/GPUData/TextureGPUDataTesting.cs b/Testing/VelaptorTests/OpenGL/GpuData/TextureGpuDataTesting.cs similarity index 72% rename from Testing/VelaptorTests/OpenGL/GPUData/TextureGPUDataTesting.cs rename to Testing/VelaptorTests/OpenGL/GpuData/TextureGpuDataTesting.cs index 148cf53b8..6d0a6afb6 100644 --- a/Testing/VelaptorTests/OpenGL/GPUData/TextureGPUDataTesting.cs +++ b/Testing/VelaptorTests/OpenGL/GpuData/TextureGpuDataTesting.cs @@ -1,26 +1,26 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // -namespace VelaptorTests.OpenGL.GPUData; +namespace VelaptorTests.OpenGL.GpuData; using System.Numerics; using FluentAssertions; -using Velaptor.OpenGL.GPUData; +using Velaptor.OpenGL.GpuData; using Xunit; /// -/// Tests the struct. +/// Tests the struct. /// -public class TextureGPUDataTesting +public class TextureGpuDataTesting { #region Overloaded Operator Tests [Fact] public void EqualsOperator_WithBothOperandsEqual_ReturnsTrue() { // Arrange - var sutA = default(TextureGPUData); - var sutB = default(TextureGPUData); + var sutA = default(TextureGpuData); + var sutB = default(TextureGpuData); // Act var actual = sutA == sutB; @@ -33,8 +33,8 @@ public void EqualsOperator_WithBothOperandsEqual_ReturnsTrue() public void EqualsOperator_WithBothOperandsNotEqual_ReturnsFalse() { // Arrange - var sutA = default(TextureGPUData); - var sutB = new TextureGPUData( + var sutA = default(TextureGpuData); + var sutB = new TextureGpuData( new TextureVertexData( new Vector2(11, 22), default, @@ -56,7 +56,7 @@ public void EqualsOperator_WithBothOperandsNotEqual_ReturnsFalse() public void GetTotalBytes_WhenInvoked_ReturnsCorrectResult() { // Act - var actual = TextureGPUData.GetTotalBytes(); + var actual = TextureGpuData.GetTotalBytes(); // Assert actual.Should().Be(128u); @@ -66,8 +66,8 @@ public void GetTotalBytes_WhenInvoked_ReturnsCorrectResult() public void Equals_WithEqualParam_ReturnsTrue() { // Arrange - var sut = default(TextureGPUData); - var dataB = default(TextureGPUData); + var sut = default(TextureGpuData); + var dataB = default(TextureGpuData); // Act var actual = sut.Equals(dataB); @@ -80,7 +80,7 @@ public void Equals_WithEqualParam_ReturnsTrue() public void Equals_WhenInvokedWithParamOfDifferentType_ReturnsFalse() { // Arrange - var sut = default(TextureGPUData); + var sut = default(TextureGpuData); var dataB = new object(); // Act @@ -94,8 +94,8 @@ public void Equals_WhenInvokedWithParamOfDifferentType_ReturnsFalse() public void Equals_WhenInvokedWithEqualParamOfSameType_ReturnsTrue() { // Arrange - var sutA = default(TextureGPUData); - object sutB = default(TextureGPUData); + var sutA = default(TextureGpuData); + object sutB = default(TextureGpuData); // Act var actual = sutA.Equals(sutB); diff --git a/Testing/VelaptorTests/OpenGL/GPUData/TextureVertexDataTests.cs b/Testing/VelaptorTests/OpenGL/GpuData/TextureVertexDataTests.cs similarity index 98% rename from Testing/VelaptorTests/OpenGL/GPUData/TextureVertexDataTests.cs rename to Testing/VelaptorTests/OpenGL/GpuData/TextureVertexDataTests.cs index ca908289e..d871d7b52 100644 --- a/Testing/VelaptorTests/OpenGL/GPUData/TextureVertexDataTests.cs +++ b/Testing/VelaptorTests/OpenGL/GpuData/TextureVertexDataTests.cs @@ -2,12 +2,12 @@ // Copyright (c) KinsonDigital. All rights reserved. // -namespace VelaptorTests.OpenGL.GPUData; +namespace VelaptorTests.OpenGL.GpuData; using System.Drawing; using System.Numerics; using FluentAssertions; -using Velaptor.OpenGL.GPUData; +using Velaptor.OpenGL.GpuData; using Xunit; /// diff --git a/Testing/VelaptorTests/OpenGL/OpenGLExtensionMethodsTests.cs b/Testing/VelaptorTests/OpenGL/OpenGLExtensionMethodsTests.cs index e536d8349..c9f132748 100644 --- a/Testing/VelaptorTests/OpenGL/OpenGLExtensionMethodsTests.cs +++ b/Testing/VelaptorTests/OpenGL/OpenGLExtensionMethodsTests.cs @@ -8,7 +8,7 @@ namespace VelaptorTests.OpenGL; using System.Drawing; using System.Numerics; using Velaptor.OpenGL; -using Velaptor.OpenGL.GPUData; +using Velaptor.OpenGL.GpuData; using Xunit; /// @@ -149,7 +149,7 @@ public void ToArray_WithTextureQuadDataOverload_ReturnsCorrectResult() new Vector2(27, 28), Color.FromArgb(29, 30, 31, 32)); - var quadData = new TextureGPUData( + var quadData = new TextureGpuData( vertex1, vertex2, vertex3, @@ -245,7 +245,7 @@ public void ToArray_WithTextureQuadDataListParamOverload_ReturnsCorrectResult() 57f, 58f, 59f, 60f, 62f, 63f, 64f, 61f, // Quad 2 Vertex 4 }; - var quads = new List { CreateNewQuad(1), CreateNewQuad(33) }; + var quads = new List { CreateNewQuad(1), CreateNewQuad(33) }; // Act var actual = OpenGLExtensionMethods.ToArray(quads); @@ -277,9 +277,9 @@ public void ToArray_WithVector4Param_ReturnsCorrectResult() /// /// The starting value to base the values from. /// The texture quad data to test. - private static TextureGPUData CreateNewQuad(int start) + private static TextureGpuData CreateNewQuad(int start) { - var result = new TextureGPUData( + var result = new TextureGpuData( new TextureVertexData( new Vector2(start, start + 1), new Vector2(start + 2, start + 3), diff --git a/Testing/VelaptorTests/OpenGL/Shaders/RectangleShaderTests.cs b/Testing/VelaptorTests/OpenGL/Shaders/ShapeShaderTests.cs similarity index 90% rename from Testing/VelaptorTests/OpenGL/Shaders/RectangleShaderTests.cs rename to Testing/VelaptorTests/OpenGL/Shaders/ShapeShaderTests.cs index 0c7fe32fa..75126a3b0 100644 --- a/Testing/VelaptorTests/OpenGL/Shaders/RectangleShaderTests.cs +++ b/Testing/VelaptorTests/OpenGL/Shaders/ShapeShaderTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -22,7 +22,10 @@ namespace VelaptorTests.OpenGL.Shaders; using Velaptor.ReactableData; using Xunit; -public class RectangleShaderTests +/// +/// Tests the class. +/// +public class ShapeShaderTests { private readonly Mock mockGL; private readonly Mock mockGLService; @@ -32,9 +35,9 @@ public class RectangleShaderTests private IReceiveReactor? batchSizeReactor; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public RectangleShaderTests() + public ShapeShaderTests() { this.mockGL = new Mock(); this.mockGLService = new Mock(); @@ -82,7 +85,7 @@ public void Ctor_WithNullReactableFactoryParam_ThrowsException() // Arrange & Act var act = () => { - _ = new RectangleShader( + _ = new ShapeShader( new Mock().Object, new Mock().Object, new Mock().Object, @@ -99,7 +102,7 @@ public void Ctor_WithNullReactableFactoryParam_ThrowsException() public void Ctor_WhenInvoked_SetsNameProp() { // Arrange - var customAttributes = Attribute.GetCustomAttributes(typeof(RectangleShader)); + var customAttributes = Attribute.GetCustomAttributes(typeof(ShapeShader)); var containsAttribute = customAttributes.Any(i => i is ShaderNameAttribute); // Act @@ -109,7 +112,7 @@ public void Ctor_WhenInvoked_SetsNameProp() containsAttribute .Should() .BeTrue($"the '{nameof(ShaderNameAttribute)}' is required on a shader implementation to set the shader name."); - sut.Name.Should().Be("Rectangle"); + sut.Name.Should().Be("Shape"); } #endregion @@ -146,10 +149,10 @@ public void BatchSizeReactable_WithUnsubscribeNotification_UnsubscribesFromReact #endregion /// - /// Creates a new instance of for the purpose of testing. + /// Creates a new instance of for the purpose of testing. /// /// The instance to test. - private RectangleShader CreateSystemUnderTest() + private ShapeShader CreateSystemUnderTest() => new (this.mockGL.Object, this.mockGLService.Object, this.mockShaderLoader.Object, diff --git a/Testing/VelaptorTests/PushNotificationsTests.cs b/Testing/VelaptorTests/PushNotificationsTests.cs index b1dd32f61..352b9a162 100644 --- a/Testing/VelaptorTests/PushNotificationsTests.cs +++ b/Testing/VelaptorTests/PushNotificationsTests.cs @@ -113,10 +113,10 @@ public void RenderFontsId_WhenGettingValue_ReturnsCorrectResult() } [Fact] - public void RenderRectsId_WhenGettingValue_ReturnsCorrectResult() + public void RenderShapesId_WhenGettingValue_ReturnsCorrectResult() { // Arrange & Act & Assert - PushNotifications.RenderRectsId.Should().Be("27c20138-52d3-4b5d-936d-3b62e3b7db4d"); + PushNotifications.RenderShapesId.Should().Be("27c20138-52d3-4b5d-936d-3b62e3b7db4d"); } [Fact] diff --git a/Testing/VelaptorTests/SampleTestData/LineGPUDataTests.ToArray_WhenInvoked_ReturnsCorrectResult.json b/Testing/VelaptorTests/SampleTestData/LineGpuDataTests.ToArray_WhenInvoked_ReturnsCorrectResult.json similarity index 100% rename from Testing/VelaptorTests/SampleTestData/LineGPUDataTests.ToArray_WhenInvoked_ReturnsCorrectResult.json rename to Testing/VelaptorTests/SampleTestData/LineGpuDataTests.ToArray_WhenInvoked_ReturnsCorrectResult.json diff --git a/Testing/VelaptorTests/SampleTestData/ShapeGPUBufferTests.GenerateData_WhenInvoked_ReturnsCorrectResult.json b/Testing/VelaptorTests/SampleTestData/ShapeGpuBufferTests.GenerateData_WhenInvoked_ReturnsCorrectResult.json similarity index 100% rename from Testing/VelaptorTests/SampleTestData/ShapeGPUBufferTests.GenerateData_WhenInvoked_ReturnsCorrectResult.json rename to Testing/VelaptorTests/SampleTestData/ShapeGpuBufferTests.GenerateData_WhenInvoked_ReturnsCorrectResult.json diff --git a/Testing/VelaptorTests/SampleTestData/RectGPUDataTestData.json b/Testing/VelaptorTests/SampleTestData/ShapeGpuDataTestData.json similarity index 100% rename from Testing/VelaptorTests/SampleTestData/RectGPUDataTestData.json rename to Testing/VelaptorTests/SampleTestData/ShapeGpuDataTestData.json diff --git a/Testing/VelaptorTests/UI/TextCursorTests.cs b/Testing/VelaptorTests/UI/TextCursorTests.cs index 35ebb4ed7..add506864 100644 --- a/Testing/VelaptorTests/UI/TextCursorTests.cs +++ b/Testing/VelaptorTests/UI/TextCursorTests.cs @@ -22,7 +22,6 @@ namespace VelaptorTests.UI; /// public class TextCursorTests { - private readonly Guid textBoxDataEventId = new ("71931561-826B-431B-BCE6-B139034A1FF4"); private readonly Mock> textBoxStateReactable; private IReceiveReactor? reactor; @@ -119,53 +118,10 @@ public void Color_WhenSettingValue_ReturnsCorrectResult() [InlineData("t", "", 15, 20, 0, 10, 100)] [InlineData("t", "t", 15, 20, 0, 10, 115)] [InlineData("", "test-value", 40, 50, 6, 10, 115)] - public void Update_WhenAddingCharacterWhenCursorIsAtRightEndOfText_SetsCursorToLeftSideOfChar( - string preText, - string postText, - int cursorRight, - int preTextRight, - int postCharIndex, - int postTextLength, - int expectedCursorLeft) - { - // Arrange - var preMutateState = new TextBoxStateData - { - TextMutateType = MutateType.PreMutate, - Text = new StringBuilder(preText), - TextRight = preTextRight, - }; - - var postMutateState = new TextBoxStateData - { - TextMutateType = MutateType.PostMutate, - Event = TextBoxEvent.AddingCharacter, - Text = new StringBuilder(postText), - CharIndex = postCharIndex, - TextLeft = 100, - TextView = new RectShape { Left = 100 }, - TextLength = postTextLength, - CurrentCharLeft = 115, - CurrentCharRight = 125, - }; - - var sut = CreateSystemUnderTest(); - sut.Cursor = new RectShape { Right = cursorRight, }; - - // Act - this.reactor.OnReceive(preMutateState); - this.reactor.OnReceive(postMutateState); - sut.Update(); - - // Assert - sut.Cursor.Left.Should().Be(expectedCursorLeft); - } - - [Theory] [InlineData("", "", 0, 0, 0, 0, 100)] [InlineData("t", "", 20, 15, 0, 0, 100)] [InlineData("t", "z", 20, 15, 0, 0, 125)] - public void Update_WhenAddingCharacterWhenCursorIsAtRightEndOfText_SetsCursorToRightSideOfChar( + public void Update_WhenAddingCharacterWhenCursorIsAtRightEndOfText_SetsCursorToLeftSideOfChar( string preText, string postText, int cursorRight, diff --git a/Testing/VelaptorTests/UI/WindowTests.cs b/Testing/VelaptorTests/UI/WindowTests.cs index 6b03c91e3..ea111fed6 100644 --- a/Testing/VelaptorTests/UI/WindowTests.cs +++ b/Testing/VelaptorTests/UI/WindowTests.cs @@ -13,6 +13,7 @@ namespace VelaptorTests.UI; using Helpers; using Moq; using Velaptor; +using Velaptor.Batching; using Velaptor.Content; using Velaptor.Scene; using Velaptor.UI; @@ -26,6 +27,7 @@ public class WindowTests private readonly Mock mockWindow; private readonly Mock mockContentLoader; private readonly Mock mockSceneManager; + private readonly Mock mockBatcher; /// /// Initializes a new instance of the class. @@ -34,6 +36,7 @@ public WindowTests() { this.mockContentLoader = new Mock(); this.mockSceneManager = new Mock(); + this.mockBatcher = new Mock(); this.mockWindow = new Mock(); this.mockWindow.SetupGet(p => p.ContentLoader).Returns(this.mockContentLoader.Object); @@ -51,7 +54,7 @@ public void Ctor_WithNullWindowParam_ThrowsException() // Arrange & Act var act = () => { - _ = new WindowFake(null, this.mockSceneManager.Object); + _ = new WindowFake(null, this.mockSceneManager.Object, this.mockBatcher.Object); }; // Assert @@ -66,7 +69,7 @@ public void Ctor_WithNullSceneManagerParam_ThrowsException() // Arrange & Act var act = () => { - _ = new WindowFake(this.mockWindow.Object, null); + _ = new WindowFake(this.mockWindow.Object, null, this.mockBatcher.Object); }; // Assert @@ -415,5 +418,5 @@ public void Dispose_WhenInvoked_DisposesOfMangedResources() /// of testing the abstract class. /// /// The instance used for testing. - private WindowFake CreateSystemUnderTest() => new (this.mockWindow.Object, this.mockSceneManager.Object); + private WindowFake CreateSystemUnderTest() => new (this.mockWindow.Object, this.mockSceneManager.Object, this.mockBatcher.Object); } diff --git a/Testing/VelaptorTests/VelaptorTests.csproj b/Testing/VelaptorTests/VelaptorTests.csproj index 60cd2f22f..917faef9c 100644 --- a/Testing/VelaptorTests/VelaptorTests.csproj +++ b/Testing/VelaptorTests/VelaptorTests.csproj @@ -60,13 +60,13 @@ Always - + Always - + Always - + Always @@ -128,6 +128,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + all diff --git a/Velaptor.sln.DotSettings b/Velaptor.sln.DotSettings index 63ffbcbeb..51d4b0054 100644 --- a/Velaptor.sln.DotSettings +++ b/Velaptor.sln.DotSettings @@ -6,7 +6,6 @@ EBO GL GLFW - GPU JSON NDC OSX @@ -103,6 +102,7 @@ public void $MEMBER_UNDER_TEST$_$SCENARIO_UNDER_TEST$_$EXPECTED_RESULT$() /// <returns>The instance to test.</returns> private $OBJECT_TYPE$ CreateSystemUnderTest() => new ($END$); + True True True True @@ -111,7 +111,6 @@ private $OBJECT_TYPE$ CreateSystemUnderTest() True True True - True True True True diff --git a/Velaptor/Batching/Batcher.cs b/Velaptor/Batching/Batcher.cs new file mode 100644 index 000000000..09b50447a --- /dev/null +++ b/Velaptor/Batching/Batcher.cs @@ -0,0 +1,146 @@ +// +// Copyright (c) KinsonDigital. All rights reserved. +// + +namespace Velaptor.Batching; + +using System; +using System.Drawing; +using Carbonate.NonDirectional; +using Carbonate.UniDirectional; +using Graphics.Renderers.Exceptions; +using NativeInterop.OpenGL; +using OpenGL; +using ReactableData; + +/// +internal sealed class Batcher : IBatcher +{ + private const string RenderExceptionMsg = "The renderer is not initialized."; + private const uint InitialBatchSize = 1000; + private readonly IDisposable? glInitUnsubscriber; + private readonly IGLInvoker glInvoker; + private readonly IPushReactable pushReactable; + private readonly CachedValue cachedClearColor; + private bool isInitialized; + + /// + /// Initializes a new instance of the class. + /// + /// Invokes OpenGL functions. + /// Gets a notification that OpenGL is initialized. + /// Sends notifications of the batch sizes to the different types of renderers. + public Batcher( + IGLInvoker glInvoker, + IPushReactable pushReactable, + IPushReactable batchSizeReactable) + { + ArgumentNullException.ThrowIfNull(glInvoker); + ArgumentNullException.ThrowIfNull(pushReactable); + ArgumentNullException.ThrowIfNull(batchSizeReactable); + + this.glInvoker = glInvoker; + this.pushReactable = pushReactable; + + const string glInitName = $"{nameof(Batcher)}.Ctor - {nameof(PushNotifications.GLInitializedId)}"; + this.glInitUnsubscriber = pushReactable.Subscribe(new ReceiveReactor( + eventId: PushNotifications.GLInitializedId, + name: glInitName, + onReceive: () => + { + if (this.isInitialized) + { + return; + } + + glInvoker.Enable(GLEnableCap.Blend); + glInvoker.BlendFunc(GLBlendingFactor.SrcAlpha, GLBlendingFactor.OneMinusSrcAlpha); + + foreach (var batchType in Enum.GetValues()) + { + batchSizeReactable.Push( + new BatchSizeData { BatchSize = InitialBatchSize, TypeOfBatch = batchType }, + PushNotifications.BatchSizeChangedId); + } + + batchSizeReactable.Unsubscribe(PushNotifications.BatchSizeChangedId); + + if (this.cachedClearColor is not null) + { + this.cachedClearColor.IsCaching = false; + } + + this.isInitialized = true; + }, + onUnsubscribe: () => this.glInitUnsubscriber?.Dispose())); + + this.cachedClearColor = new CachedValue( + Color.FromArgb(255, 16, 29, 36), + () => + { + var colorValues = new float[4]; + this.glInvoker.GetFloat(GLGetPName.ColorClearValue, colorValues); + + var red = colorValues[0].MapValue(0, 1, 0, 255); + var green = colorValues[1].MapValue(0, 1, 0, 255); + var blue = colorValues[2].MapValue(0, 1, 0, 255); + var alpha = colorValues[3].MapValue(0, 1, 0, 255); + + return Color.FromArgb((byte)alpha, (byte)red, (byte)green, (byte)blue); + }, + value => + { + var red = value.R.MapValue(0f, 255f, 0f, 1f); + var green = value.G.MapValue(0f, 255f, 0f, 1f); + var blue = value.B.MapValue(0f, 255f, 0f, 1f); + var alpha = value.A.MapValue(0f, 255f, 0f, 1f); + + this.glInvoker.ClearColor(red, green, blue, alpha); + }); + } + + /// + public Color ClearColor + { + get => this.cachedClearColor.GetValue(); + set => this.cachedClearColor.SetValue(value); + } + + /// + public bool HasBegun { get; private set; } + + /// + public void Begin() + { + if (this.isInitialized is false) + { + throw new RendererException(RenderExceptionMsg); + } + + HasBegun = true; + this.pushReactable.Push(PushNotifications.BatchHasBegunId); + } + + /// + public void Clear() + { + if (this.isInitialized is false) + { + throw new RendererException(RenderExceptionMsg); + } + + this.glInvoker.Clear(GLClearBufferMask.ColorBufferBit); + } + + /// + public void End() + { + if (this.isInitialized is false) + { + throw new RendererException(RenderExceptionMsg); + } + + HasBegun = false; + this.pushReactable.Push(PushNotifications.BatchHasEndedId); + } +} diff --git a/Velaptor/Batching/BatchingManager.cs b/Velaptor/Batching/BatchingManager.cs index fc7232832..1c0c9cb83 100644 --- a/Velaptor/Batching/BatchingManager.cs +++ b/Velaptor/Batching/BatchingManager.cs @@ -22,20 +22,20 @@ internal sealed class BatchingManager : IBatchingManager private readonly IDisposable shutDownUnsubscriber; private readonly IDisposable texturePullUnsubscriber; private readonly IDisposable fontPullUnsubscriber; - private readonly IDisposable rectPullUnsubscriber; + private readonly IDisposable shapePullUnsubscriber; private readonly IDisposable linePullUnsubscriber; private readonly IDisposable emptyBatchUnsubscriber; private readonly IPushReactable batchSizeReactable; private readonly BatchType[] batchTypes = Enum.GetValues(); private Memory> textureItems; private Memory> fontItems; - private Memory> rectItems; + private Memory> shapeItems; private Memory> lineItems; private bool isShutDown; private bool firstTimeSettingBatchSize = true; private uint textureBatchSize; private uint fontBatchSize; - private uint rectBatchSize; + private uint shapeBatchSize; private uint lineBatchSize; /// @@ -106,18 +106,18 @@ public BatchingManager(IReactableFactory reactableFactory) : this.fontItems[..lastFullItemIndex]; })); - var rectPullReactable = reactableFactory.CreateRectPullBatchReactable(); - var rectPullReactorName = this.GetExecutionMemberName(nameof(PullResponses.GetRectItemsId)); - this.rectPullUnsubscriber = rectPullReactable.Subscribe(new RespondReactor>>( - respondId: PullResponses.GetRectItemsId, - name: rectPullReactorName, + var shapePullReactable = reactableFactory.CreateShapePullBatchReactable(); + var shapePullReactorName = this.GetExecutionMemberName(nameof(PullResponses.GetShapeItemsId)); + this.shapePullUnsubscriber = shapePullReactable.Subscribe(new RespondReactor>>( + respondId: PullResponses.GetShapeItemsId, + name: shapePullReactorName, onRespond: () => { - var lastFullItemIndex = this.rectItems.IndexOf(i => i.IsEmpty()); + var lastFullItemIndex = this.shapeItems.IndexOf(i => i.IsEmpty()); return lastFullItemIndex < 0 - ? this.rectItems - : this.rectItems[..lastFullItemIndex]; + ? this.shapeItems + : this.shapeItems[..lastFullItemIndex]; })); var linePullReactable = reactableFactory.CreateLinePullBatchReactable(); @@ -148,10 +148,10 @@ public BatchingManager(IReactableFactory reactableFactory) public Span> FontItems => this.fontItems.Span; /// - /// Gets the rectangle items. + /// Gets the shape items. /// /// USED FOR UNIT TESTING. - public Span> RectItems => this.rectItems.Span; + public Span> ShapeItems => this.shapeItems.Span; /// /// Gets the line items. @@ -208,14 +208,14 @@ public void AddFontItem(FontGlyphBatchItem item, int layer, DateTime renderStamp } /// - public void AddRectItem(ShapeBatchItem item, int layer, DateTime renderStamp) + public void AddShapeItem(ShapeBatchItem item, int layer, DateTime renderStamp) { - var emptyItemIndex = this.rectItems. + var emptyItemIndex = this.shapeItems. FirstItemIndex(i => i.Item.IsEmpty()); if (emptyItemIndex == -1) { - emptyItemIndex = this.rectItems.Length; + emptyItemIndex = this.shapeItems.Length; var newBatchSize = CalcNewBatchSize(BatchType.Rect); this.batchSizeReactable.Push( @@ -223,7 +223,7 @@ public void AddRectItem(ShapeBatchItem item, int layer, DateTime renderStamp) PushNotifications.BatchSizeChangedId); } - this.rectItems.Span[emptyItemIndex] = new RenderItem + this.shapeItems.Span[emptyItemIndex] = new RenderItem { Layer = layer, Item = item, @@ -263,7 +263,7 @@ private void InitBatchItems(uint size) { this.textureBatchSize = size; this.fontBatchSize = size; - this.rectBatchSize = size; + this.shapeBatchSize = size; this.lineBatchSize = size; this.textureItems = new RenderItem[size]; @@ -278,10 +278,10 @@ private void InitBatchItems(uint size) this.fontItems.Span[i] = default; } - this.rectItems = new RenderItem[size]; + this.shapeItems = new RenderItem[size]; for (var i = 0; i < size; i++) { - this.rectItems.Span[i] = default; + this.shapeItems.Span[i] = default; } this.lineItems = new RenderItem[size]; @@ -307,7 +307,7 @@ private uint CalcNewBatchSize(BatchType batchType) => { BatchType.Texture => (uint)(this.textureBatchSize + (this.textureBatchSize * BatchIncreasePercentage)), BatchType.Font => (uint)(this.fontBatchSize + (this.fontBatchSize * BatchIncreasePercentage)), - BatchType.Rect => (uint)(this.rectBatchSize + (this.rectBatchSize * BatchIncreasePercentage)), + BatchType.Rect => (uint)(this.shapeBatchSize + (this.shapeBatchSize * BatchIncreasePercentage)), BatchType.Line => (uint)(this.lineBatchSize + (this.lineBatchSize * BatchIncreasePercentage)), }; #pragma warning restore CS8524 @@ -332,7 +332,7 @@ private void SetNewBatchSize(uint newBatchSize, BatchType batchType) { BatchType.Texture => newBatchSize - this.textureBatchSize, BatchType.Font => newBatchSize - this.fontBatchSize, - BatchType.Rect => newBatchSize - this.rectBatchSize, + BatchType.Rect => newBatchSize - this.shapeBatchSize, BatchType.Line => newBatchSize - this.lineBatchSize, }; #pragma warning restore CS8524 @@ -349,8 +349,8 @@ private void SetNewBatchSize(uint newBatchSize, BatchType batchType) this.fontItems.IncreaseBy(increaseAmount); break; case BatchType.Rect: - this.rectBatchSize = newBatchSize; - this.rectItems.IncreaseBy(increaseAmount); + this.shapeBatchSize = newBatchSize; + this.shapeItems.IncreaseBy(increaseAmount); break; case BatchType.Line: this.lineBatchSize = newBatchSize; @@ -386,14 +386,14 @@ private void EmptyBatch() this.fontItems.Span[i] = default; } - for (var i = 0; i < this.rectItems.Length; i++) + for (var i = 0; i < this.shapeItems.Length; i++) { - if (this.rectItems.Span[i].Item.IsEmpty()) + if (this.shapeItems.Span[i].Item.IsEmpty()) { break; } - this.rectItems.Span[i] = default; + this.shapeItems.Span[i] = default; } for (var i = 0; i < this.lineItems.Length; i++) @@ -421,7 +421,7 @@ private void ShutDown() this.emptyBatchUnsubscriber.Dispose(); this.texturePullUnsubscriber.Dispose(); this.fontPullUnsubscriber.Dispose(); - this.rectPullUnsubscriber.Dispose(); + this.shapePullUnsubscriber.Dispose(); this.linePullUnsubscriber.Dispose(); this.isShutDown = true; diff --git a/Velaptor/Batching/IBatcher.cs b/Velaptor/Batching/IBatcher.cs new file mode 100644 index 000000000..1edaa9f3f --- /dev/null +++ b/Velaptor/Batching/IBatcher.cs @@ -0,0 +1,42 @@ +// +// Copyright (c) KinsonDigital. All rights reserved. +// + +namespace Velaptor.Batching; + +using System.Drawing; + +/// +/// Provides the ability to start and end the batch rendering process. +/// +public interface IBatcher +{ + /// + /// Gets or sets the color of the back buffer when cleared. + /// + Color ClearColor { get; set; } + + /// + /// Gets a value indicating whether or not the batch process has begun. + /// + bool HasBegun { get; } + + /// + /// Starts the batch rendering process. Must be called before invoking any render methods. + /// + void Begin(); + + /// + /// Clears the buffers. + /// + /// + /// It is best to clear the buffer before rendering all of the textures. + /// This is to make sure smearing does not occur during texture movement or animation. + /// + void Clear(); + + /// + /// Ends the batch process. Calling this will perform the actual GPU render process. + /// + void End(); +} diff --git a/Velaptor/Batching/IBatchingManager.cs b/Velaptor/Batching/IBatchingManager.cs index 1834caed0..0f013b9ae 100644 --- a/Velaptor/Batching/IBatchingManager.cs +++ b/Velaptor/Batching/IBatchingManager.cs @@ -29,12 +29,12 @@ internal interface IBatchingManager void AddFontItem(FontGlyphBatchItem item, int layer, DateTime renderStamp); /// - /// Adds a rectangle item to the batch. + /// Adds a shape item to the batch. /// /// The item to add. /// The layer to add the item. /// The date and time of the when the item was rendered. - void AddRectItem(ShapeBatchItem item, int layer, DateTime renderStamp); + void AddShapeItem(ShapeBatchItem item, int layer, DateTime renderStamp); /// /// Adds a line item to the batch. diff --git a/Velaptor/Content/Texture.cs b/Velaptor/Content/Texture.cs index a62b99f4b..cab17b900 100644 --- a/Velaptor/Content/Texture.cs +++ b/Velaptor/Content/Texture.cs @@ -182,7 +182,7 @@ private void Init(IPushReactable disposeReactable, string na Name = name; - UploadDataToGPU(name, imageData); + UploadDataToGpu(name, imageData); this.openGLService.UnbindTexture2D(); } @@ -192,7 +192,7 @@ private void Init(IPushReactable disposeReactable, string na /// /// The name of the texture. /// The image data of the texture. - private void UploadDataToGPU(string name, ImageData imageData) + private void UploadDataToGpu(string name, ImageData imageData) { /*NOTE: * The incoming image data is in the ARGB byte layout. diff --git a/Velaptor/ExtensionMethods/GPUDataTypeExtensions.cs b/Velaptor/ExtensionMethods/GpuDataTypeExtensions.cs similarity index 64% rename from Velaptor/ExtensionMethods/GPUDataTypeExtensions.cs rename to Velaptor/ExtensionMethods/GpuDataTypeExtensions.cs index 281b73746..c1b0f3b8b 100644 --- a/Velaptor/ExtensionMethods/GPUDataTypeExtensions.cs +++ b/Velaptor/ExtensionMethods/GpuDataTypeExtensions.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -9,23 +9,23 @@ namespace Velaptor.ExtensionMethods; using System.Drawing; using System.Numerics; using OpenGL; -using OpenGL.GPUData; +using OpenGL.GpuData; /// /// Provides extensions methods for GPU data related types. /// [SuppressMessage("csharpsquid", "S101", Justification = "Acronym is acceptable .")] -internal static class GPUDataTypeExtensions +internal static class GpuDataTypeExtensions { - /// - /// Updates the using the given for the given . + /// + /// Updates the using the given for the given . /// The end result will also be converted to NDC coordinates. /// /// The GPU data to update. /// The position to apply to a vertex. /// The vertex to update. /// The updated GPU data. - public static RectGPUData SetVertexPos(this RectGPUData gpuData, Vector2 pos, VertexNumber vertexNumber) + public static ShapeGpuData SetVertexPos(this ShapeGpuData gpuData, Vector2 pos, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -36,9 +36,9 @@ public static RectGPUData SetVertexPos(this RectGPUData gpuData, Vector2 pos, Ve _ => throw new ArgumentOutOfRangeException(nameof(vertexNumber), "The vertex number is invalid.") }; - var newVertexData = new RectVertexData( + var newVertexData = new ShapeVertexData( pos, - oldVertex.Rectangle, + oldVertex.BoundingBox, oldVertex.Color, oldVertex.IsSolid, oldVertex.BorderThickness, @@ -50,22 +50,22 @@ public static RectGPUData SetVertexPos(this RectGPUData gpuData, Vector2 pos, Ve #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new RectGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new RectGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new ShapeGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new ShapeGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the using the given for the given . + /// Updates the using the given for the given . /// /// The GPU data to update. /// The position to apply to a vertex. /// The vertex to update. /// The updated GPU data. - public static LineGPUData SetVertexPos(this LineGPUData gpuData, Vector2 pos, VertexNumber vertexNumber) + public static LineGpuData SetVertexPos(this LineGpuData gpuData, Vector2 pos, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -83,22 +83,22 @@ public static LineGPUData SetVertexPos(this LineGPUData gpuData, Vector2 pos, Ve #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new LineGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new LineGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new LineGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new LineGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new LineGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new LineGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new LineGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new LineGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the of a vertex using the given for the given . + /// Updates the of a vertex using the given for the given . /// /// The GPU data to update. /// The rectangle to apply to a vertex. /// The vertex to update. /// The updated GPU data. - public static RectGPUData SetRectangle(this RectGPUData gpuData, Vector4 rect, VertexNumber vertexNumber) + public static ShapeGpuData SetRectangle(this ShapeGpuData gpuData, Vector4 rect, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -109,7 +109,7 @@ public static RectGPUData SetRectangle(this RectGPUData gpuData, Vector4 rect, V _ => throw new ArgumentOutOfRangeException(nameof(vertexNumber), "The vertex number is invalid.") }; - var newVertexData = new RectVertexData( + var newVertexData = new ShapeVertexData( oldVertex.VertexPos, rect, oldVertex.Color, @@ -123,21 +123,21 @@ public static RectGPUData SetRectangle(this RectGPUData gpuData, Vector4 rect, V #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new RectGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new RectGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new ShapeGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new ShapeGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the for all of the vertex data in the given . + /// Updates the for all of the vertex data in the given . /// /// The GPU data to update. /// The rectangle to apply to all vertex data. /// The updated GPU data. - public static RectGPUData SetRectangle(this RectGPUData gpuData, Vector4 rectangle) + public static ShapeGpuData SetRectangle(this ShapeGpuData gpuData, Vector4 rectangle) { gpuData = gpuData.SetRectangle(rectangle, VertexNumber.One); gpuData = gpuData.SetRectangle(rectangle, VertexNumber.Two); @@ -148,14 +148,14 @@ public static RectGPUData SetRectangle(this RectGPUData gpuData, Vector4 rectang } /// - /// Updates the setting of a vertex using the given + /// Updates the setting of a vertex using the given /// for the given . /// /// The GPU data to update. /// The solid setting to apply to a vertex. /// The vertex to update. /// The updated GPU data. - public static RectGPUData SetAsSolid(this RectGPUData gpuData, bool isSolid, VertexNumber vertexNumber) + public static ShapeGpuData SetAsSolid(this ShapeGpuData gpuData, bool isSolid, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -166,9 +166,9 @@ public static RectGPUData SetAsSolid(this RectGPUData gpuData, bool isSolid, Ver _ => throw new ArgumentOutOfRangeException(nameof(vertexNumber), "The vertex number is invalid.") }; - var newVertexData = new RectVertexData( + var newVertexData = new ShapeVertexData( oldVertex.VertexPos, - oldVertex.Rectangle, + oldVertex.BoundingBox, oldVertex.Color, isSolid, oldVertex.BorderThickness, @@ -180,21 +180,21 @@ public static RectGPUData SetAsSolid(this RectGPUData gpuData, bool isSolid, Ver #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new RectGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new RectGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new ShapeGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new ShapeGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the setting for all of the vertex data in the given . + /// Updates the setting for all of the vertex data in the given . /// /// The GPU data to update. /// The setting to apply to all vertex data. /// The updated GPU data. - public static RectGPUData SetAsSolid(this RectGPUData gpuData, bool isSolid) + public static ShapeGpuData SetAsSolid(this ShapeGpuData gpuData, bool isSolid) { gpuData = gpuData.SetAsSolid(isSolid, VertexNumber.One); gpuData = gpuData.SetAsSolid(isSolid, VertexNumber.Two); @@ -205,14 +205,14 @@ public static RectGPUData SetAsSolid(this RectGPUData gpuData, bool isSolid) } /// - /// Updates the setting of a vertex using the given + /// Updates the setting of a vertex using the given /// for the given . /// /// The GPU data to update. /// The border thickness to apply to the vertex. /// The vertex to update. /// The updated GPU data. - public static RectGPUData SetBorderThickness(this RectGPUData gpuData, float borderThickness, VertexNumber vertexNumber) + public static ShapeGpuData SetBorderThickness(this ShapeGpuData gpuData, float borderThickness, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -223,9 +223,9 @@ public static RectGPUData SetBorderThickness(this RectGPUData gpuData, float bor _ => throw new ArgumentOutOfRangeException(nameof(vertexNumber), "The vertex number is invalid.") }; - var newVertexData = new RectVertexData( + var newVertexData = new ShapeVertexData( oldVertex.VertexPos, - oldVertex.Rectangle, + oldVertex.BoundingBox, oldVertex.Color, oldVertex.IsSolid, borderThickness, @@ -237,21 +237,21 @@ public static RectGPUData SetBorderThickness(this RectGPUData gpuData, float bor #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new RectGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new RectGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new ShapeGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new ShapeGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the setting for all of the vertex data in the given . + /// Updates the setting for all of the vertex data in the given . /// /// The GPU data to update. /// The setting to apply to all vertex data. /// The updated GPU data. - public static RectGPUData SetBorderThickness(this RectGPUData gpuData, float borderThickness) + public static ShapeGpuData SetBorderThickness(this ShapeGpuData gpuData, float borderThickness) { gpuData = gpuData.SetBorderThickness(borderThickness, VertexNumber.One); gpuData = gpuData.SetBorderThickness(borderThickness, VertexNumber.Two); @@ -262,14 +262,14 @@ public static RectGPUData SetBorderThickness(this RectGPUData gpuData, float bor } /// - /// Updates the setting of a vertex using the given + /// Updates the setting of a vertex using the given /// for the given . /// /// The GPU data to update. /// The top left corner radius to apply to a vertex. /// The vertex to update. /// The updated GPU data. - public static RectGPUData SetTopLeftCornerRadius(this RectGPUData gpuData, float topLeftCornerRadius, VertexNumber vertexNumber) + public static ShapeGpuData SetTopLeftCornerRadius(this ShapeGpuData gpuData, float topLeftCornerRadius, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -280,9 +280,9 @@ public static RectGPUData SetTopLeftCornerRadius(this RectGPUData gpuData, float _ => throw new ArgumentOutOfRangeException(nameof(vertexNumber), "The vertex number is invalid.") }; - var newVertexData = new RectVertexData( + var newVertexData = new ShapeVertexData( oldVertex.VertexPos, - oldVertex.Rectangle, + oldVertex.BoundingBox, oldVertex.Color, oldVertex.IsSolid, oldVertex.BorderThickness, @@ -294,21 +294,21 @@ public static RectGPUData SetTopLeftCornerRadius(this RectGPUData gpuData, float #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new RectGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new RectGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new ShapeGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new ShapeGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the setting for all of the vertex data in the given . + /// Updates the setting for all of the vertex data in the given . /// /// The GPU data to update. /// The setting to apply to all vertex data. /// The updated GPU data. - public static RectGPUData SetTopLeftCornerRadius(this RectGPUData gpuData, float topLeftCornerRadius) + public static ShapeGpuData SetTopLeftCornerRadius(this ShapeGpuData gpuData, float topLeftCornerRadius) { gpuData = gpuData.SetTopLeftCornerRadius(topLeftCornerRadius, VertexNumber.One); gpuData = gpuData.SetTopLeftCornerRadius(topLeftCornerRadius, VertexNumber.Two); @@ -319,14 +319,14 @@ public static RectGPUData SetTopLeftCornerRadius(this RectGPUData gpuData, float } /// - /// Updates the setting of a vertex using the given + /// Updates the setting of a vertex using the given /// for the given . /// /// The GPU data to update. /// The bottom left corner radius to apply to a vertex. /// The vertex to update. /// The updated GPU data. - public static RectGPUData SetBottomLeftCornerRadius(this RectGPUData gpuData, float bottomLeftCornerRadius, VertexNumber vertexNumber) + public static ShapeGpuData SetBottomLeftCornerRadius(this ShapeGpuData gpuData, float bottomLeftCornerRadius, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -337,9 +337,9 @@ public static RectGPUData SetBottomLeftCornerRadius(this RectGPUData gpuData, fl _ => throw new ArgumentOutOfRangeException(nameof(vertexNumber), "The vertex number is invalid.") }; - var newVertexData = new RectVertexData( + var newVertexData = new ShapeVertexData( oldVertex.VertexPos, - oldVertex.Rectangle, + oldVertex.BoundingBox, oldVertex.Color, oldVertex.IsSolid, oldVertex.BorderThickness, @@ -351,21 +351,21 @@ public static RectGPUData SetBottomLeftCornerRadius(this RectGPUData gpuData, fl #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new RectGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new RectGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new ShapeGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new ShapeGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the setting for all of the vertex data in the given . + /// Updates the setting for all of the vertex data in the given . /// /// The GPU data to update. /// The setting to apply to all vertex data. /// The updated GPU data. - public static RectGPUData SetBottomLeftCornerRadius(this RectGPUData gpuData, float bottomLeftCornerRadius) + public static ShapeGpuData SetBottomLeftCornerRadius(this ShapeGpuData gpuData, float bottomLeftCornerRadius) { gpuData = gpuData.SetBottomLeftCornerRadius(bottomLeftCornerRadius, VertexNumber.One); gpuData = gpuData.SetBottomLeftCornerRadius(bottomLeftCornerRadius, VertexNumber.Two); @@ -376,14 +376,14 @@ public static RectGPUData SetBottomLeftCornerRadius(this RectGPUData gpuData, fl } /// - /// Updates the setting of a vertex using the given + /// Updates the setting of a vertex using the given /// for the given . /// /// The GPU data to update. /// The bottom right corner radius to apply to a vertex. /// The vertex to update. /// The updated GPU data. - public static RectGPUData SetBottomRightCornerRadius(this RectGPUData gpuData, float bottomRightCornerRadius, VertexNumber vertexNumber) + public static ShapeGpuData SetBottomRightCornerRadius(this ShapeGpuData gpuData, float bottomRightCornerRadius, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -394,9 +394,9 @@ public static RectGPUData SetBottomRightCornerRadius(this RectGPUData gpuData, f _ => throw new ArgumentOutOfRangeException(nameof(vertexNumber), "The vertex number is invalid.") }; - var newVertexData = new RectVertexData( + var newVertexData = new ShapeVertexData( oldVertex.VertexPos, - oldVertex.Rectangle, + oldVertex.BoundingBox, oldVertex.Color, oldVertex.IsSolid, oldVertex.BorderThickness, @@ -408,21 +408,21 @@ public static RectGPUData SetBottomRightCornerRadius(this RectGPUData gpuData, f #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new RectGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new RectGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new ShapeGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new ShapeGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the setting for all of the vertex data in the given . + /// Updates the setting for all of the vertex data in the given . /// /// The GPU data to update. /// The setting to apply to all vertex data. /// The updated GPU data. - public static RectGPUData SetBottomRightCornerRadius(this RectGPUData gpuData, float bottomRightCornerRadius) + public static ShapeGpuData SetBottomRightCornerRadius(this ShapeGpuData gpuData, float bottomRightCornerRadius) { gpuData = gpuData.SetBottomRightCornerRadius(bottomRightCornerRadius, VertexNumber.One); gpuData = gpuData.SetBottomRightCornerRadius(bottomRightCornerRadius, VertexNumber.Two); @@ -433,14 +433,14 @@ public static RectGPUData SetBottomRightCornerRadius(this RectGPUData gpuData, f } /// - /// Updates the setting of a vertex using the given + /// Updates the setting of a vertex using the given /// for the given . /// /// The GPU data to update. /// The top right corner radius to apply to a vertex. /// The vertex to update. /// The updated GPU data. - public static RectGPUData SetTopRightCornerRadius(this RectGPUData gpuData, float topRightCornerRadius, VertexNumber vertexNumber) + public static ShapeGpuData SetTopRightCornerRadius(this ShapeGpuData gpuData, float topRightCornerRadius, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -451,9 +451,9 @@ public static RectGPUData SetTopRightCornerRadius(this RectGPUData gpuData, floa _ => throw new ArgumentOutOfRangeException(nameof(vertexNumber), "The vertex number is invalid.") }; - var newVertexData = new RectVertexData( + var newVertexData = new ShapeVertexData( oldVertex.VertexPos, - oldVertex.Rectangle, + oldVertex.BoundingBox, oldVertex.Color, oldVertex.IsSolid, oldVertex.BorderThickness, @@ -465,21 +465,21 @@ public static RectGPUData SetTopRightCornerRadius(this RectGPUData gpuData, floa #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new RectGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new RectGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new ShapeGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new ShapeGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the setting for all of the vertex data in the given . + /// Updates the setting for all of the vertex data in the given . /// /// The GPU data to update. /// The setting to apply to all vertex data. /// The updated GPU data. - public static RectGPUData SetTopRightCornerRadius(this RectGPUData gpuData, float topRightCornerRadius) + public static ShapeGpuData SetTopRightCornerRadius(this ShapeGpuData gpuData, float topRightCornerRadius) { gpuData = gpuData.SetTopRightCornerRadius(topRightCornerRadius, VertexNumber.One); gpuData = gpuData.SetTopRightCornerRadius(topRightCornerRadius, VertexNumber.Two); @@ -490,14 +490,14 @@ public static RectGPUData SetTopRightCornerRadius(this RectGPUData gpuData, floa } /// - /// Updates the of a vertex using the given + /// Updates the of a vertex using the given /// for the given . /// /// The GPU data to update. /// The color to set the vertex. /// The vertex to update. /// The updated GPU data. - public static RectGPUData SetColor(this RectGPUData gpuData, Color color, VertexNumber vertexNumber) + public static ShapeGpuData SetColor(this ShapeGpuData gpuData, Color color, VertexNumber vertexNumber) { var oldVertex = vertexNumber switch { @@ -508,9 +508,9 @@ public static RectGPUData SetColor(this RectGPUData gpuData, Color color, Vertex _ => throw new ArgumentOutOfRangeException(nameof(vertexNumber), "The vertex number is invalid.") }; - var newVertexData = new RectVertexData( + var newVertexData = new ShapeVertexData( oldVertex.VertexPos, - oldVertex.Rectangle, + oldVertex.BoundingBox, color, oldVertex.IsSolid, oldVertex.BorderThickness, @@ -522,21 +522,21 @@ public static RectGPUData SetColor(this RectGPUData gpuData, Color color, Vertex #pragma warning disable CS8524 return vertexNumber switch { - VertexNumber.One => new RectGPUData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Two => new RectGPUData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), - VertexNumber.Three => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), - VertexNumber.Four => new RectGPUData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), + VertexNumber.One => new ShapeGpuData(newVertexData, gpuData.Vertex2, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Two => new ShapeGpuData(gpuData.Vertex1, newVertexData, gpuData.Vertex3, gpuData.Vertex4), + VertexNumber.Three => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, newVertexData, gpuData.Vertex4), + VertexNumber.Four => new ShapeGpuData(gpuData.Vertex1, gpuData.Vertex2, gpuData.Vertex3, newVertexData), }; #pragma warning restore CS8524 } /// - /// Updates the for all of the vertex data in the given . + /// Updates the for all of the vertex data in the given . /// /// The GPU data to update. /// The color to apply to all vertex data. /// The updated GPU data. - public static RectGPUData SetColor(this RectGPUData gpuData, Color color) + public static ShapeGpuData SetColor(this ShapeGpuData gpuData, Color color) { gpuData = gpuData.SetColor(color, VertexNumber.One); gpuData = gpuData.SetColor(color, VertexNumber.Two); @@ -547,18 +547,18 @@ public static RectGPUData SetColor(this RectGPUData gpuData, Color color) } /// - /// Sets the color of the to the given . + /// Sets the color of the to the given . /// /// The line GPU data. /// The color to set. - /// The with the new color applied. - public static LineGPUData SetColor(this LineGPUData gpuData, Color color) + /// The with the new color applied. + public static LineGpuData SetColor(this LineGpuData gpuData, Color color) { var newVertex1 = new LineVertexData(gpuData.Vertex1.VertexPos, color); var newVertex2 = new LineVertexData(gpuData.Vertex2.VertexPos, color); var newVertex3 = new LineVertexData(gpuData.Vertex3.VertexPos, color); var newVertex4 = new LineVertexData(gpuData.Vertex4.VertexPos, color); - return new LineGPUData(newVertex1, newVertex2, newVertex3, newVertex4); + return new LineGpuData(newVertex1, newVertex2, newVertex3, newVertex4); } } diff --git a/Velaptor/Factories/IReactableFactory.cs b/Velaptor/Factories/IReactableFactory.cs index bee5be647..a732d2ac9 100644 --- a/Velaptor/Factories/IReactableFactory.cs +++ b/Velaptor/Factories/IReactableFactory.cs @@ -84,10 +84,10 @@ internal interface IReactableFactory IBatchPullReactable CreateFontPullBatchReactable(); /// - /// Creates a reactable for pulling rectangle batch data. + /// Creates a reactable for pulling shape batch data. /// /// The reactable. - IBatchPullReactable CreateRectPullBatchReactable(); + IBatchPullReactable CreateShapePullBatchReactable(); /// /// Creates a reactable for pulling line batch data. @@ -108,10 +108,10 @@ internal interface IReactableFactory IRenderBatchReactable CreateRenderFontReactable(); /// - /// Creates a reactable for pushing rect batch data to the rect renderer. + /// Creates a reactable for pushing shape batch data to the shape renderer. /// /// The reactable. - IRenderBatchReactable CreateRenderRectReactable(); + IRenderBatchReactable CreateRenderShapeReactable(); /// /// Creates a reactable for pushing line batch data to the line renderer. diff --git a/Velaptor/Factories/IShaderFactory.cs b/Velaptor/Factories/IShaderFactory.cs index 2679b0ce6..130c5b9c2 100644 --- a/Velaptor/Factories/IShaderFactory.cs +++ b/Velaptor/Factories/IShaderFactory.cs @@ -27,7 +27,7 @@ internal interface IShaderFactory /// Creates a shader for rendering rectangles. /// /// The shader program. - IShaderProgram CreateRectShader(); + IShaderProgram CreateShapeShader(); /// /// Creates a shader for rendering lines. diff --git a/Velaptor/Factories/ReactableFactory.cs b/Velaptor/Factories/ReactableFactory.cs index 67b768253..5066f70ed 100644 --- a/Velaptor/Factories/ReactableFactory.cs +++ b/Velaptor/Factories/ReactableFactory.cs @@ -55,7 +55,7 @@ public IBatchPullReactable CreateFontPullBatchReactable() => IoC.Container.GetInstance>(); /// - public IBatchPullReactable CreateRectPullBatchReactable() => + public IBatchPullReactable CreateShapePullBatchReactable() => IoC.Container.GetInstance>(); /// @@ -71,7 +71,7 @@ public IRenderBatchReactable CreateRenderFontReactable() => IoC.Container.GetInstance>(); /// - public IRenderBatchReactable CreateRenderRectReactable() => + public IRenderBatchReactable CreateRenderShapeReactable() => IoC.Container.GetInstance>(); /// diff --git a/Velaptor/Factories/RendererFactory.cs b/Velaptor/Factories/RendererFactory.cs index 4dd9bbb4b..0eff375a6 100644 --- a/Velaptor/Factories/RendererFactory.cs +++ b/Velaptor/Factories/RendererFactory.cs @@ -7,120 +7,23 @@ namespace Velaptor.Factories; using System.Diagnostics.CodeAnalysis; using Batching; using Graphics.Renderers; -using NativeInterop.OpenGL; -using OpenGL.Batching; -using OpenGL.Buffers; /// [ExcludeFromCodeCoverage(Justification = "Cannot unit test due direct interaction with IoC container.")] public sealed class RendererFactory : IRendererFactory { - private static ITextureRenderer? textureRenderer; - private static IFontRenderer? fontRenderer; - private static IShapeRenderer? shapeRenderer; - private static ILineRenderer? lineRenderer; - /// - public ITextureRenderer CreateTextureRenderer() - { - if (textureRenderer is not null) - { - return textureRenderer; - } - - var glInvoker = IoC.Container.GetInstance(); - var reactableFactory = IoC.Container.GetInstance(); - var openGLService = IoC.Container.GetInstance(); - var buffer = IoC.Container.GetInstance>(); - var shader = IoC.Container.GetInstance().CreateTextureShader(); - var batchManager = IoC.Container.GetInstance(); - - textureRenderer = new TextureRenderer( - glInvoker, - reactableFactory, - openGLService, - buffer, - shader, - batchManager); - - return textureRenderer; - } + public ITextureRenderer CreateTextureRenderer() => IoC.Container.GetInstance(); /// - public IFontRenderer CreateFontRenderer() - { - if (fontRenderer is not null) - { - return fontRenderer; - } - - var glInvoker = IoC.Container.GetInstance(); - var reactableFactory = IoC.Container.GetInstance(); - var openGLService = IoC.Container.GetInstance(); - var buffer = IoC.Container.GetInstance>(); - var shader = IoC.Container.GetInstance().CreateFontShader(); - var batchManager = IoC.Container.GetInstance(); - - fontRenderer = new FontRenderer( - glInvoker, - reactableFactory, - openGLService, - buffer, - shader, - batchManager); - - return fontRenderer; - } + public IFontRenderer CreateFontRenderer() => IoC.Container.GetInstance(); /// - public IShapeRenderer CreateShapeRenderer() - { - if (shapeRenderer is not null) - { - return shapeRenderer; - } - - var glInvoker = IoC.Container.GetInstance(); - var reactableFactory = IoC.Container.GetInstance(); - var openGLService = IoC.Container.GetInstance(); - var buffer = IoC.Container.GetInstance>(); - var shader = IoC.Container.GetInstance().CreateRectShader(); - var batchManager = IoC.Container.GetInstance(); - - shapeRenderer = new ShapeRenderer( - glInvoker, - reactableFactory, - openGLService, - buffer, - shader, - batchManager); - - return shapeRenderer; - } + public IShapeRenderer CreateShapeRenderer() => IoC.Container.GetInstance(); /// - public ILineRenderer CreateLineRenderer() - { - if (lineRenderer is not null) - { - return lineRenderer; - } + public ILineRenderer CreateLineRenderer() => IoC.Container.GetInstance(); - var glInvoker = IoC.Container.GetInstance(); - var reactableFactory = IoC.Container.GetInstance(); - var openGLService = IoC.Container.GetInstance(); - var buffer = IoC.Container.GetInstance>(); - var shader = IoC.Container.GetInstance().CreateLineShader(); - var batchManager = IoC.Container.GetInstance(); - - lineRenderer = new LineRenderer( - glInvoker, - reactableFactory, - openGLService, - buffer, - shader, - batchManager); - - return lineRenderer; - } + /// + public IBatcher CreateBatcher() => IoC.Container.GetInstance(); } diff --git a/Velaptor/Factories/ShaderFactory.cs b/Velaptor/Factories/ShaderFactory.cs index 912fd44cf..4d71e7714 100644 --- a/Velaptor/Factories/ShaderFactory.cs +++ b/Velaptor/Factories/ShaderFactory.cs @@ -17,7 +17,7 @@ internal sealed class ShaderFactory : IShaderFactory { private readonly IShaderProgram textureShader; private readonly IShaderProgram fontShader; - private readonly IShaderProgram rectShader; + private readonly IShaderProgram shapeShader; private readonly IShaderProgram lineShader; /// @@ -42,7 +42,7 @@ public ShaderFactory() shaderLoaderService, reactableFactory); - this.rectShader = new RectangleShader( + this.shapeShader = new ShapeShader( glInvoker, glInvokerExtensions, shaderLoaderService, @@ -62,7 +62,7 @@ public ShaderFactory() public IShaderProgram CreateFontShader() => this.fontShader; /// - public IShaderProgram CreateRectShader() => this.rectShader; + public IShaderProgram CreateShapeShader() => this.shapeShader; /// public IShaderProgram CreateLineShader() => this.lineShader; diff --git a/Velaptor/Graphics/RenderMediator.cs b/Velaptor/Graphics/RenderMediator.cs index 1ab60bd6f..343348f10 100644 --- a/Velaptor/Graphics/RenderMediator.cs +++ b/Velaptor/Graphics/RenderMediator.cs @@ -18,15 +18,15 @@ internal sealed class RenderMediator : IRenderMediator private readonly IPushReactable pushReactable; private readonly IBatchPullReactable texturePullReactable; private readonly IBatchPullReactable fontPullReactable; - private readonly IBatchPullReactable rectPullReactable; + private readonly IBatchPullReactable shapePullReactable; private readonly IBatchPullReactable linePullReactable; private readonly IRenderBatchReactable textureRenderBatchReactable; private readonly IRenderBatchReactable fontRenderBatchReactable; - private readonly IRenderBatchReactable rectRenderBatchReactable; + private readonly IRenderBatchReactable shapeRenderBatchReactable; private readonly IRenderBatchReactable lineRenderBatchReactable; private readonly IComparer> textureItemComparer; private readonly IComparer> fontItemComparer; - private readonly IComparer> rectItemComparer; + private readonly IComparer> shapeItemComparer; private readonly IComparer> lineItemComparer; private readonly IDisposable endBatchUnsubscriber; private readonly IDisposable shutDownUnsubscriber; @@ -40,19 +40,19 @@ internal sealed class RenderMediator : IRenderMediator /// Creates reactables for sending and receiving notifications with or without data. /// Compares two texture batch items for the purpose of sorting. /// Compares two font batch items for the purpose of sorting. - /// Compares two rect batch items for the purpose of sorting. + /// Compares two shape batch items for the purpose of sorting. /// Compares two line batch items for the purpose of sorting. public RenderMediator( IReactableFactory reactableFactory, IComparer> textureItemComparer, IComparer> fontItemComparer, - IComparer> rectItemComparer, + IComparer> shapeItemComparer, IComparer> lineItemComparer) { EnsureThat.ParamIsNotNull(reactableFactory); EnsureThat.ParamIsNotNull(textureItemComparer); EnsureThat.ParamIsNotNull(fontItemComparer); - EnsureThat.ParamIsNotNull(rectItemComparer); + EnsureThat.ParamIsNotNull(shapeItemComparer); EnsureThat.ParamIsNotNull(lineItemComparer); this.pushReactable = reactableFactory.CreateNoDataPushReactable(); @@ -71,17 +71,17 @@ public RenderMediator( this.texturePullReactable = reactableFactory.CreateTexturePullBatchReactable(); this.fontPullReactable = reactableFactory.CreateFontPullBatchReactable(); - this.rectPullReactable = reactableFactory.CreateRectPullBatchReactable(); + this.shapePullReactable = reactableFactory.CreateShapePullBatchReactable(); this.linePullReactable = reactableFactory.CreateLinePullBatchReactable(); this.textureRenderBatchReactable = reactableFactory.CreateRenderTextureReactable(); this.fontRenderBatchReactable = reactableFactory.CreateRenderFontReactable(); - this.rectRenderBatchReactable = reactableFactory.CreateRenderRectReactable(); + this.shapeRenderBatchReactable = reactableFactory.CreateRenderShapeReactable(); this.lineRenderBatchReactable = reactableFactory.CreateRenderLineReactable(); this.textureItemComparer = textureItemComparer; this.fontItemComparer = fontItemComparer; - this.rectItemComparer = rectItemComparer; + this.shapeItemComparer = shapeItemComparer; this.lineItemComparer = lineItemComparer; // Sets all of the layers to a default value of the max value of int @@ -98,12 +98,12 @@ private void CoordinateRenders() { var textureItems = this.texturePullReactable.Pull(PullResponses.GetTextureItemsId); var fontItems = this.fontPullReactable.Pull(PullResponses.GetFontItemsId); - var rectItems = this.rectPullReactable.Pull(PullResponses.GetRectItemsId); + var shapeItems = this.shapePullReactable.Pull(PullResponses.GetShapeItemsId); var lineItems = this.linePullReactable.Pull(PullResponses.GetLineItemsId); textureItems.Span.Sort(this.textureItemComparer); fontItems.Span.Sort(this.fontItemComparer); - rectItems.Span.Sort(this.rectItemComparer); + shapeItems.Span.Sort(this.shapeItemComparer); lineItems.Span.Sort(this.lineItemComparer); var layerIndex = 0; @@ -132,15 +132,15 @@ private void CoordinateRenders() layerIndex++; } - for (var i = 0; i < rectItems.Length; i++) + for (var i = 0; i < shapeItems.Length; i++) { - var rectLayer = rectItems.Span[i].Layer; - if (this.allLayers.Span.Contains(rectLayer)) + var shapeLayer = shapeItems.Span[i].Layer; + if (this.allLayers.Span.Contains(shapeLayer)) { continue; } - this.allLayers.Span[layerIndex] = rectLayer; + this.allLayers.Span[layerIndex] = shapeLayer; layerIndex++; } @@ -170,7 +170,7 @@ private void CoordinateRenders() var totalTexturesOnCurrentLayer = textureItems.TotalOnLayer(currentLayer); var totalFontOnCurrentLayer = fontItems.TotalOnLayer(currentLayer); - var totalRectsOnCurrentLayer = rectItems.TotalOnLayer(currentLayer); + var totalShapesOnCurrentLayer = shapeItems.TotalOnLayer(currentLayer); var totalLinesOnCurrentLayer = lineItems.TotalOnLayer(currentLayer); if (totalTexturesOnCurrentLayer > 0) @@ -191,13 +191,13 @@ private void CoordinateRenders() PushNotifications.RenderFontsId); } - if (totalRectsOnCurrentLayer > 0) + if (totalShapesOnCurrentLayer > 0) { - var rectLayerStart = rectItems.FirstLayerIndex(currentLayer); + var shapeLayerStart = shapeItems.FirstLayerIndex(currentLayer); - this.rectRenderBatchReactable.Push( - rectItems.Slice(rectLayerStart, totalRectsOnCurrentLayer), - PushNotifications.RenderRectsId); + this.shapeRenderBatchReactable.Push( + shapeItems.Slice(shapeLayerStart, totalShapesOnCurrentLayer), + PushNotifications.RenderShapesId); } if (totalLinesOnCurrentLayer > 0) diff --git a/Velaptor/Graphics/Renderers/FontRenderer.cs b/Velaptor/Graphics/Renderers/FontRenderer.cs index b0762fb28..165941038 100644 --- a/Velaptor/Graphics/Renderers/FontRenderer.cs +++ b/Velaptor/Graphics/Renderers/FontRenderer.cs @@ -29,7 +29,7 @@ internal sealed class FontRenderer : RendererBase, IFontRenderer { private readonly IBatchingManager batchManager; private readonly IOpenGLService openGLService; - private readonly IGPUBuffer buffer; + private readonly IGpuBuffer buffer; private readonly IShaderProgram shader; private readonly IDisposable renderUnsubscriber; private readonly IDisposable renderBatchBegunUnsubscriber; @@ -48,7 +48,7 @@ public FontRenderer( IGLInvoker gl, IReactableFactory reactableFactory, IOpenGLService openGLService, - IGPUBuffer buffer, + IGpuBuffer buffer, IShaderProgram shader, IBatchingManager batchManager) : base(gl, reactableFactory) @@ -133,7 +133,7 @@ public void Render(IFont font, Span<(GlyphMetrics metrics, Color clr)> glyphs, i if (this.hasBegun is false) { - throw new InvalidOperationException($"The '{nameof(IRenderer.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); + throw new InvalidOperationException($"The '{nameof(IBatcher.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); } var normalizedSize = renderSize - 1f; @@ -342,7 +342,7 @@ private static IEnumerable ToFontBatchItems( /// This takes new line characters into account to render multiple lines of text. /// Thrown if the font object is null. /// - /// Thrown if the method has not been called before rendering. + /// Thrown if the method has not been called before rendering. /// private void RenderBase(IFont font, string text, int x, int y, float renderSize, float angle, Color color, int layer = 0) { @@ -360,7 +360,7 @@ private void RenderBase(IFont font, string text, int x, int y, float renderSize, if (this.hasBegun is false) { - throw new InvalidOperationException($"The '{nameof(IRenderer.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); + throw new InvalidOperationException($"The '{nameof(IBatcher.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); } var normalizedSize = renderSize - 1f; diff --git a/Velaptor/Graphics/Renderers/IFontRenderer.cs b/Velaptor/Graphics/Renderers/IFontRenderer.cs index 0d2e07848..cbe5fee16 100644 --- a/Velaptor/Graphics/Renderers/IFontRenderer.cs +++ b/Velaptor/Graphics/Renderers/IFontRenderer.cs @@ -7,6 +7,7 @@ namespace Velaptor.Graphics.Renderers; using System; using System.Drawing; using System.Numerics; +using Batching; using Content.Fonts; /// @@ -23,7 +24,7 @@ public interface IFontRenderer /// The X coordinate location to render the text. /// The Y coordinate location to render the text. /// The layer to render the text. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position is based on the center of the text. @@ -66,7 +67,7 @@ public interface IFontRenderer /// The text to render. /// The position to render the text. /// The layer to render the text. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The is based on the center of the text. @@ -112,7 +113,7 @@ public interface IFontRenderer /// The size of the text. /// The angle of the text in degrees. /// The layer to render the text. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position is based on the center of the text. @@ -161,7 +162,7 @@ public interface IFontRenderer /// The size of the text. /// The angle of the text in degrees. /// The layer to render the text. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The is based on the center of the text. @@ -211,7 +212,7 @@ public interface IFontRenderer /// The Y coordinate location to render the text. /// The color of the text. /// The layer to render the text. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position is based on the center of the text. @@ -259,7 +260,7 @@ public interface IFontRenderer /// The position to render the text. /// The color of the text. /// The layer to render the text. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The is based on the center of the text. @@ -304,7 +305,7 @@ public interface IFontRenderer /// The angle of the text in degrees. /// The color of the text. /// The layer to render the text. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The is based on the center of the text. @@ -398,7 +399,7 @@ public interface IFontRenderer /// The angle of the text in degrees. /// The color to apply to the rendering. /// The layer to render the text. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position is based on the center of the text. @@ -449,7 +450,7 @@ public interface IFontRenderer /// The size of the text. /// The angle of the text in degrees. /// The layer to render the text. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position is based on the center of the text. diff --git a/Velaptor/Graphics/Renderers/ILineRenderer.cs b/Velaptor/Graphics/Renderers/ILineRenderer.cs index 13d336149..d2fff49f7 100644 --- a/Velaptor/Graphics/Renderers/ILineRenderer.cs +++ b/Velaptor/Graphics/Renderers/ILineRenderer.cs @@ -7,6 +7,7 @@ namespace Velaptor.Graphics.Renderers; using System; using System.Drawing; using System.Numerics; +using Batching; /// /// Renders lines to the screen. @@ -18,7 +19,7 @@ public interface ILineRenderer /// /// The line to render. /// The layer to render the line. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// Lower values will render before higher values. @@ -55,7 +56,7 @@ public interface ILineRenderer /// The start of the line. /// The end of the line. /// The layer to render the line. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// Lower values will render before higher values. @@ -94,7 +95,7 @@ public interface ILineRenderer /// The end of the line. /// The color of the line. /// The layer to render the line. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// Lower values will render before higher values. @@ -133,7 +134,7 @@ public interface ILineRenderer /// The end of the line. /// The thickness of the line. /// The layer to render the line. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// Lower values will render before higher values. @@ -173,7 +174,7 @@ public interface ILineRenderer /// The color of the line. /// The thickness of the line. /// The layer to render the line. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// Lower values will render before higher values. diff --git a/Velaptor/Graphics/Renderers/IRenderer.cs b/Velaptor/Graphics/Renderers/IRenderer.cs deleted file mode 100644 index de9254cb6..000000000 --- a/Velaptor/Graphics/Renderers/IRenderer.cs +++ /dev/null @@ -1,185 +0,0 @@ -// -// Copyright (c) KinsonDigital. All rights reserved. -// - -namespace Velaptor.Graphics.Renderers; - -using System; -using System.Drawing; -using Carbonate.NonDirectional; -using Carbonate.UniDirectional; -using Exceptions; -using NativeInterop.OpenGL; -using OpenGL; -using ReactableData; - -/// -/// Provides basic rendering functionality. -/// -public interface IRenderer -{ - /// - /// true if initialization has been executed. - /// - private static bool isInitialized; - - /// - /// The batch size. - /// - private const uint InitialBatchSize = 1000; - - /// - /// The OpenGL invoker. - /// - private static readonly IGLInvoker GLInvoker; - - /// - /// A push reactable to push messages without data. - /// - private static readonly IPushReactable PushReactable; - - /// - /// The unsubscriber for OpenGL the initialization event. - /// - private static readonly IDisposable? GLInitUnsubscriber; - - /// - /// Caches the color used to clear the screen during the rendering process. - /// - private static CachedValue? cachedClearColor; - - /// - /// Initializes static members of the class. - /// - static IRenderer() - { - GLInvoker = IoC.Container.GetInstance(); - PushReactable = IoC.Container.GetInstance(); - var batchSizeReactable = IoC.Container.GetInstance>(); - - const string glInitName = $"{nameof(IRenderer)}.Ctor - {nameof(PushNotifications.GLInitializedId)}"; - GLInitUnsubscriber = PushReactable.Subscribe(new ReceiveReactor( - eventId: PushNotifications.GLInitializedId, - name: glInitName, - onReceive: () => - { - if (isInitialized) - { - return; - } - - GLInvoker.Enable(GLEnableCap.Blend); - GLInvoker.BlendFunc(GLBlendingFactor.SrcAlpha, GLBlendingFactor.OneMinusSrcAlpha); - - foreach (var batchType in Enum.GetValues()) - { - batchSizeReactable.Push( - new BatchSizeData { BatchSize = InitialBatchSize, TypeOfBatch = batchType }, - PushNotifications.BatchSizeChangedId); - } - - PushReactable.Unsubscribe(PushNotifications.BatchSizeChangedId); - - if (cachedClearColor is not null) - { - cachedClearColor.IsCaching = false; - } - - isInitialized = true; - }, - onUnsubscribe: () => GLInitUnsubscriber?.Dispose())); - - SetupCaches(); - } - - /// - /// Gets or sets the color of the back buffer when cleared. - /// - static Color ClearColor - { - get => cachedClearColor?.GetValue() ?? Color.Empty; - set => cachedClearColor?.SetValue(value); - } - - /// - /// Initializes the renderer. This kicks off the static ctor which in turn pushes init notifications - /// across the application. - /// - internal static void Init() - { - // Left empty on purpose. This is to invoke the static ctor. - } - - /// - /// Starts the batch rendering process. Must be called before invoking any render methods. - /// - static void Begin() - { - if (!isInitialized) - { - throw new RendererException($"The '{nameof(IRenderer)}' is not initialized."); - } - - PushReactable.Push(PushNotifications.BatchHasBegunId); - } - - /// - /// Clears the buffers. - /// - /// - /// It is best to clear the buffer before rendering all of the textures. - /// This is to make sure smearing does not occur during texture - /// movement or animation. - /// - static void Clear() - { - if (!isInitialized) - { - throw new RendererException($"The '{nameof(IRenderer)}' is not initialized."); - } - - GLInvoker.Clear(GLClearBufferMask.ColorBufferBit); - } - - /// - /// Ends the batch process. Calling this will render any textures - /// still in the batch. - /// - static void End() - { - if (!isInitialized) - { - throw new RendererException($"The '{nameof(IRenderer)}' is not initialized."); - } - - PushReactable.Push(PushNotifications.BatchHasEndedId); - } - - /// - /// Setup all of the caching for the properties that need caching. - /// - private static void SetupCaches() => - cachedClearColor = new CachedValue( - Color.FromArgb(255, 16, 29, 36), - () => - { - var colorValues = new float[4]; - GLInvoker.GetFloat(GLGetPName.ColorClearValue, colorValues); - - var red = colorValues[0].MapValue(0, 1, 0, 255); - var green = colorValues[1].MapValue(0, 1, 0, 255); - var blue = colorValues[2].MapValue(0, 1, 0, 255); - var alpha = colorValues[3].MapValue(0, 1, 0, 255); - - return Color.FromArgb((byte)alpha, (byte)red, (byte)green, (byte)blue); - }, - value => - { - var red = value.R.MapValue(0f, 255f, 0f, 1f); - var green = value.G.MapValue(0f, 255f, 0f, 1f); - var blue = value.B.MapValue(0f, 255f, 0f, 1f); - var alpha = value.A.MapValue(0f, 255f, 0f, 1f); - - GLInvoker.ClearColor(red, green, blue, alpha); - }); -} diff --git a/Velaptor/Graphics/Renderers/IRendererFactory.cs b/Velaptor/Graphics/Renderers/IRendererFactory.cs index daa5f26a9..062ce5a74 100644 --- a/Velaptor/Graphics/Renderers/IRendererFactory.cs +++ b/Velaptor/Graphics/Renderers/IRendererFactory.cs @@ -4,6 +4,8 @@ namespace Velaptor.Graphics.Renderers; +using Batching; + /// /// Creates renderer instances. /// @@ -36,4 +38,10 @@ public interface IRendererFactory /// The line renderer. /// NOTE: the renderer is a singleton. ILineRenderer CreateLineRenderer(); + + /// + /// Creates an instance of to start and stop batching. + /// + /// The batcher instance. + IBatcher CreateBatcher(); } diff --git a/Velaptor/Graphics/Renderers/IShapeRenderer.cs b/Velaptor/Graphics/Renderers/IShapeRenderer.cs index 8994875de..def14f4e5 100644 --- a/Velaptor/Graphics/Renderers/IShapeRenderer.cs +++ b/Velaptor/Graphics/Renderers/IShapeRenderer.cs @@ -5,6 +5,7 @@ namespace Velaptor.Graphics.Renderers; using System; +using Batching; /// /// Renders rectangles to the screen. @@ -16,7 +17,7 @@ public interface IShapeRenderer /// /// The rectangle to render. /// The layer to render the rectangle. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// Lower values will render before higher values. @@ -52,7 +53,7 @@ public interface IShapeRenderer /// /// The circle to render. /// The layer to render the circle. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// Lower values will render before higher values. diff --git a/Velaptor/Graphics/Renderers/ITextureRenderer.cs b/Velaptor/Graphics/Renderers/ITextureRenderer.cs index 11b7d88cc..4dd8fbd2a 100644 --- a/Velaptor/Graphics/Renderers/ITextureRenderer.cs +++ b/Velaptor/Graphics/Renderers/ITextureRenderer.cs @@ -7,6 +7,7 @@ namespace Velaptor.Graphics.Renderers; using System; using System.Drawing; using System.Numerics; +using Batching; using Content; /// @@ -21,7 +22,7 @@ public interface ITextureRenderer /// The X location of the texture. /// The Y location of the texture. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position are based on the center of the texture. @@ -63,7 +64,7 @@ public interface ITextureRenderer /// The Y location of the texture. /// The angle of rotation in degrees of the rendering. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position are based on the center of the texture. @@ -105,7 +106,7 @@ public interface ITextureRenderer /// The Y location of the texture. /// The rendering effects to apply to the texture when rendering. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position is based on the center of the texture. @@ -147,7 +148,7 @@ public interface ITextureRenderer /// The Y location of the texture. /// The color to apply to the texture. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position is based on the center of the texture. @@ -190,7 +191,7 @@ public interface ITextureRenderer /// The color to apply to the texture. /// The rendering effects to apply to the texture when rendering. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The and position is based on the center of the texture. @@ -230,7 +231,7 @@ public interface ITextureRenderer /// The texture to render. /// The location of the texture. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The position are based on the center of the texture. @@ -271,7 +272,7 @@ public interface ITextureRenderer /// The location of the texture. /// The angle of rotation in degrees of the rendering. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The position are based on the center of the texture. @@ -312,7 +313,7 @@ public interface ITextureRenderer /// The location of the texture. /// The rendering effects to apply to the texture when rendering. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The position are based on the center of the texture. @@ -353,7 +354,7 @@ public interface ITextureRenderer /// The location of the texture. /// The color to apply to the texture. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The position are based on the center of the texture. @@ -395,7 +396,7 @@ public interface ITextureRenderer /// The color to apply to the texture. /// The rendering effects to apply to the texture when rendering. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The position are based on the center of the texture. @@ -440,7 +441,7 @@ public interface ITextureRenderer /// The color to apply to the rendering. /// The rendering effects to apply to the texture when rendering. /// The layer to render the texture. - /// Thrown if the method has not been called. + /// Thrown if the method has not been called. /// /// /// The position in the is based on the center of the texture. diff --git a/Velaptor/Graphics/Renderers/LineRenderer.cs b/Velaptor/Graphics/Renderers/LineRenderer.cs index de34c6d2d..e302fa555 100644 --- a/Velaptor/Graphics/Renderers/LineRenderer.cs +++ b/Velaptor/Graphics/Renderers/LineRenderer.cs @@ -23,7 +23,7 @@ internal sealed class LineRenderer : RendererBase, ILineRenderer { private readonly IBatchingManager batchManager; private readonly IOpenGLService openGLService; - private readonly IGPUBuffer buffer; + private readonly IGpuBuffer buffer; private readonly IShaderProgram shader; private readonly IDisposable renderUnsubscriber; private readonly IDisposable renderBatchBegunUnsubscriber; @@ -42,7 +42,7 @@ public LineRenderer( IGLInvoker gl, IReactableFactory reactableFactory, IOpenGLService openGLService, - IGPUBuffer buffer, + IGpuBuffer buffer, IShaderProgram shader, IBatchingManager batchManager) : base(gl, reactableFactory) @@ -122,7 +122,7 @@ private void RenderBase(Vector2 start, Vector2 end, Color color, uint thickness, { if (this.hasBegun is false) { - throw new InvalidOperationException($"The '{nameof(IRenderer.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); + throw new InvalidOperationException($"The '{nameof(IBatcher.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); } var batchItem = new LineBatchItem( diff --git a/Velaptor/Graphics/Renderers/RendererBase.cs b/Velaptor/Graphics/Renderers/RendererBase.cs index 37f7ddbbd..566507270 100644 --- a/Velaptor/Graphics/Renderers/RendererBase.cs +++ b/Velaptor/Graphics/Renderers/RendererBase.cs @@ -10,8 +10,10 @@ namespace Velaptor.Graphics.Renderers; using Guards; using NativeInterop.OpenGL; -/// -internal abstract class RendererBase : IRenderer +/// +/// Provides base functionality for a renderer. +/// +internal abstract class RendererBase { private readonly IDisposable shutDownUnsubscriber; diff --git a/Velaptor/Graphics/Renderers/ShapeRenderer.cs b/Velaptor/Graphics/Renderers/ShapeRenderer.cs index b3faaba1e..5dde9d6cc 100644 --- a/Velaptor/Graphics/Renderers/ShapeRenderer.cs +++ b/Velaptor/Graphics/Renderers/ShapeRenderer.cs @@ -21,7 +21,7 @@ internal sealed class ShapeRenderer : RendererBase, IShapeRenderer { private readonly IBatchingManager batchManager; private readonly IOpenGLService openGLService; - private readonly IGPUBuffer buffer; + private readonly IGpuBuffer buffer; private readonly IShaderProgram shader; private readonly IDisposable renderUnsubscriber; private readonly IDisposable renderBatchBegunUnsubscriber; @@ -40,7 +40,7 @@ public ShapeRenderer( IGLInvoker gl, IReactableFactory reactableFactory, IOpenGLService openGLService, - IGPUBuffer buffer, + IGpuBuffer buffer, IShaderProgram shader, IBatchingManager batchManager) : base(gl, reactableFactory) @@ -63,11 +63,11 @@ public ShapeRenderer( name: renderStateName, onReceive: () => this.hasBegun = true)); - var rectRenderBatchReactable = reactableFactory.CreateRenderRectReactable(); + var shapeRenderBatchReactable = reactableFactory.CreateRenderShapeReactable(); - var renderReactorName = this.GetExecutionMemberName(nameof(PushNotifications.RenderRectsId)); - this.renderUnsubscriber = rectRenderBatchReactable.Subscribe(new ReceiveReactor>>( - eventId: PushNotifications.RenderRectsId, + var renderReactorName = this.GetExecutionMemberName(nameof(PushNotifications.RenderShapesId)); + this.renderUnsubscriber = shapeRenderBatchReactable.Subscribe(new ReceiveReactor>>( + eventId: PushNotifications.RenderShapesId, name: renderReactorName, onReceiveData: RenderBatch)); } @@ -100,32 +100,32 @@ protected override void ShutDown() /// The batch item to render. /// The layer to render the item. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// private void RenderBase(ShapeBatchItem batchItem, int layer) { if (this.hasBegun is false) { - throw new InvalidOperationException($"The '{nameof(IRenderer.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); + throw new InvalidOperationException($"The '{nameof(IBatcher.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); } - this.batchManager.AddRectItem(batchItem, layer, DateTime.Now); + this.batchManager.AddShapeItem(batchItem, layer, DateTime.Now); } /// - /// Invoked every time a batch of rectangles is ready to be rendered. + /// Invoked every time a batch of shapes are ready to be rendered. /// private void RenderBatch(Memory> itemsToRender) { if (itemsToRender.Length <= 0) { - this.openGLService.BeginGroup("Render Rectangle Process - Nothing To Render"); + this.openGLService.BeginGroup("Render Shape Process - Nothing To Render"); this.openGLService.EndGroup(); return; } - this.openGLService.BeginGroup($"Render Rectangle Process With {this.shader.Name} Shader"); + this.openGLService.BeginGroup($"Render Shape Process With {this.shader.Name} Shader"); this.shader.Use(); @@ -140,14 +140,14 @@ private void RenderBatch(Memory> itemsToRender) gpuDataIndex++; totalItemsToRender++; - this.openGLService.BeginGroup($"Update Rectangle Data - BatchItem({i})"); + this.openGLService.BeginGroup($"Update Shape Data - BatchItem({i})"); this.buffer.UploadData(batchItem, (uint)gpuDataIndex); this.openGLService.EndGroup(); } var totalElements = 6u * totalItemsToRender; - this.openGLService.BeginGroup($"Render {totalElements} Rectangle Elements"); + this.openGLService.BeginGroup($"Render {totalElements} Shape Elements"); GL.DrawElements(GLPrimitiveType.Triangles, totalElements, GLDrawElementsType.UnsignedInt, nint.Zero); this.openGLService.EndGroup(); diff --git a/Velaptor/Graphics/Renderers/TextureRenderer.cs b/Velaptor/Graphics/Renderers/TextureRenderer.cs index 5d00350bb..bcfa5abef 100644 --- a/Velaptor/Graphics/Renderers/TextureRenderer.cs +++ b/Velaptor/Graphics/Renderers/TextureRenderer.cs @@ -26,7 +26,7 @@ internal sealed class TextureRenderer : RendererBase, ITextureRenderer { private readonly IBatchingManager batchManager; private readonly IOpenGLService openGLService; - private readonly IGPUBuffer buffer; + private readonly IGpuBuffer buffer; private readonly IShaderProgram shader; private readonly IDisposable renderBatchBegunUnsubscriber; private readonly IDisposable renderUnsubscriber; @@ -45,7 +45,7 @@ public TextureRenderer( IGLInvoker gl, IReactableFactory reactableFactory, IOpenGLService openGLService, - IGPUBuffer buffer, + IGpuBuffer buffer, IShaderProgram shader, IBatchingManager batchManager) : base(gl, reactableFactory) @@ -62,10 +62,10 @@ public TextureRenderer( var pushReactable = reactableFactory.CreateNoDataPushReactable(); - const string renderStateName = $"{nameof(TextureRenderer)}.Ctor - {nameof(PushNotifications.BatchHasBegunId)}"; + const string batchStateName = $"{nameof(TextureRenderer)}.Ctor - {nameof(PushNotifications.BatchHasBegunId)}"; this.renderBatchBegunUnsubscriber = pushReactable.Subscribe(new ReceiveReactor( eventId: PushNotifications.BatchHasBegunId, - name: renderStateName, + name: batchStateName, onReceive: () => this.hasBegun = true)); var textureRenderBatchReactable = reactableFactory.CreateRenderTextureReactable(); @@ -80,7 +80,7 @@ public TextureRenderer( /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, int x, int y, int layer = 0) => Render(texture, x, y, Color.White, RenderEffects.None, layer); @@ -88,7 +88,7 @@ public void Render(ITexture texture, int x, int y, int layer = 0) => /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, int x, int y, float angle, int layer = 0) { @@ -109,7 +109,7 @@ public void Render(ITexture texture, int x, int y, float angle, int layer = 0) /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, int x, int y, RenderEffects effects, int layer = 0) => Render(texture, x, y, Color.White, effects, layer); @@ -117,7 +117,7 @@ public void Render(ITexture texture, int x, int y, RenderEffects effects, int la /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, int x, int y, Color color, int layer = 0) => Render(texture, x, y, color, RenderEffects.None, layer); @@ -125,7 +125,7 @@ public void Render(ITexture texture, int x, int y, Color color, int layer = 0) = /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, int x, int y, Color color, RenderEffects effects, int layer = 0) { @@ -146,7 +146,7 @@ public void Render(ITexture texture, int x, int y, Color color, RenderEffects ef /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, Vector2 pos, int layer = 0) => Render(texture, (int)pos.X, (int)pos.Y, Color.White, RenderEffects.None, layer); @@ -154,7 +154,7 @@ public void Render(ITexture texture, Vector2 pos, int layer = 0) => /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, Vector2 pos, float angle, int layer = 0) { @@ -175,7 +175,7 @@ public void Render(ITexture texture, Vector2 pos, float angle, int layer = 0) /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, Vector2 pos, RenderEffects effects, int layer = 0) => Render(texture, (int)pos.X, (int)pos.Y, Color.White, effects, layer); @@ -183,7 +183,7 @@ public void Render(ITexture texture, Vector2 pos, RenderEffects effects, int lay /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, Vector2 pos, Color color, int layer = 0) => Render(texture, (int)pos.X, (int)pos.Y, color, RenderEffects.None, layer); @@ -191,7 +191,7 @@ public void Render(ITexture texture, Vector2 pos, Color color, int layer = 0) => /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// public void Render(ITexture texture, Vector2 pos, Color color, RenderEffects effects, int layer = 0) { @@ -212,7 +212,7 @@ public void Render(ITexture texture, Vector2 pos, Color color, RenderEffects eff /// /// Thrown if the is null. /// - /// Thrown if the has not been invoked before rendering. + /// Thrown if the has not been invoked before rendering. /// /// /// Thrown if the source rectangle width or height is less than or equal to 0. @@ -254,7 +254,7 @@ protected override void ShutDown() /// /// Thrown if the is null. /// - /// Thrown if the method has not been called before rendering. + /// Thrown if the method has not been called before rendering. /// /// /// Thrown if the source rectangle width or height is less than or equal to 0. @@ -275,7 +275,7 @@ private void RenderBase( if (this.hasBegun is false) { - throw new InvalidOperationException($"The '{nameof(IRenderer.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); + throw new InvalidOperationException($"The '{nameof(IBatcher.Begin)}()' method must be invoked first before any '{nameof(Render)}()' methods."); } (Rectangle srcRect, Rectangle destRect) = rects; diff --git a/Velaptor/IoC.cs b/Velaptor/IoC.cs index 44f3acaf6..15ee112e7 100644 --- a/Velaptor/IoC.cs +++ b/Velaptor/IoC.cs @@ -67,6 +67,8 @@ private static void SetupContainer() SetupBuffers(); + SetupRendering(); + SetupCaching(); SetupFactories(); @@ -83,6 +85,7 @@ private static void SetupContainer() IoCContainer.Register>, RenderItemComparer>(Lifestyle.Singleton); IoCContainer.Register>, RenderItemComparer>(Lifestyle.Singleton); + IoCContainer.Register(Lifestyle.Singleton); IoCContainer.Register(Lifestyle.Singleton); IoCContainer.Register, Keyboard>(Lifestyle.Singleton); IoCContainer.Register, Mouse>(Lifestyle.Singleton); @@ -92,6 +95,88 @@ private static void SetupContainer() isInitialized = true; } + /// + /// Sets up the various renderers. + /// + private static void SetupRendering() + { + IoCContainer.Register( + () => + { + var glInvoker = IoCContainer.GetInstance(); + var reactableFactory = IoCContainer.GetInstance(); + var openGLService = IoCContainer.GetInstance(); + var buffer = IoCContainer.GetInstance>(); + var shader = IoCContainer.GetInstance().CreateFontShader(); + var batchManager = IoCContainer.GetInstance(); + + return new FontRenderer( + glInvoker, + reactableFactory, + openGLService, + buffer, + shader, + batchManager); + }, Lifestyle.Singleton); + + IoCContainer.Register( + () => + { + var glInvoker = IoCContainer.GetInstance(); + var reactableFactory = IoCContainer.GetInstance(); + var openGLService = IoCContainer.GetInstance(); + var buffer = IoCContainer.GetInstance>(); + var shader = IoCContainer.GetInstance().CreateTextureShader(); + var batchManager = IoCContainer.GetInstance(); + + return new TextureRenderer( + glInvoker, + reactableFactory, + openGLService, + buffer, + shader, + batchManager); + }, Lifestyle.Singleton); + + IoCContainer.Register( + () => + { + var glInvoker = IoCContainer.GetInstance(); + var reactableFactory = IoCContainer.GetInstance(); + var openGLService = IoCContainer.GetInstance(); + var buffer = IoCContainer.GetInstance>(); + var shader = IoCContainer.GetInstance().CreateLineShader(); + var batchManager = IoCContainer.GetInstance(); + + return new LineRenderer( + glInvoker, + reactableFactory, + openGLService, + buffer, + shader, + batchManager); + }, Lifestyle.Singleton); + + IoCContainer.Register( + () => + { + var glInvoker = IoCContainer.GetInstance(); + var reactableFactory = IoCContainer.GetInstance(); + var openGLService = IoCContainer.GetInstance(); + var buffer = IoCContainer.GetInstance>(); + var shader = IoCContainer.GetInstance().CreateShapeShader(); + var batchManager = IoCContainer.GetInstance(); + + return new ShapeRenderer( + glInvoker, + reactableFactory, + openGLService, + buffer, + shader, + batchManager); + }, Lifestyle.Singleton); + } + /// /// Sets up the container registration related to OpenGL. /// @@ -117,10 +202,10 @@ private static void SetupNativeInterop() /// private static void SetupBuffers() { - IoCContainer.Register, TextureGPUBuffer>(Lifestyle.Singleton); - IoCContainer.Register, FontGPUBuffer>(Lifestyle.Singleton); - IoCContainer.Register, ShapeGPUBuffer>(Lifestyle.Singleton); - IoCContainer.Register, LineGPUBuffer>(Lifestyle.Singleton); + IoCContainer.Register, TextureGpuBuffer>(Lifestyle.Singleton); + IoCContainer.Register, FontGpuBuffer>(Lifestyle.Singleton); + IoCContainer.Register, ShapeGpuBuffer>(Lifestyle.Singleton); + IoCContainer.Register, LineGpuBuffer>(Lifestyle.Singleton); } /// diff --git a/Velaptor/OpenGL/Buffers/FontGPUBuffer.cs b/Velaptor/OpenGL/Buffers/FontGpuBuffer.cs similarity index 94% rename from Velaptor/OpenGL/Buffers/FontGPUBuffer.cs rename to Velaptor/OpenGL/Buffers/FontGpuBuffer.cs index 750bce6bc..0ffff4050 100644 --- a/Velaptor/OpenGL/Buffers/FontGPUBuffer.cs +++ b/Velaptor/OpenGL/Buffers/FontGpuBuffer.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -13,21 +13,21 @@ namespace Velaptor.OpenGL.Buffers; using Carbonate.UniDirectional; using Exceptions; using Factories; -using GPUData; +using GpuData; using NativeInterop.OpenGL; using ReactableData; /// /// Updates font data in the GPU buffer. /// -[GPUBufferName("Font")] -internal sealed class FontGPUBuffer : GPUBufferBase +[GpuBufferName("Font")] +internal sealed class FontGpuBuffer : GpuBufferBase { private const string BufferNotInitMsg = "The font buffer has not been initialized."; private readonly IDisposable unsubscriber; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Invokes OpenGL functions. /// Provides OpenGL related helper methods. @@ -35,7 +35,7 @@ internal sealed class FontGPUBuffer : GPUBufferBase /// /// Invoked when any of the parameters are null. /// - public FontGPUBuffer( + public FontGpuBuffer( IGLInvoker gl, IOpenGLService openGLService, IReactableFactory reactableFactory) @@ -71,11 +71,11 @@ protected internal override float[] GenerateData() throw new BufferNotInitializedException(BufferNotInitMsg); } - var result = new List(); + var result = new List(); for (var i = 0u; i < BatchSize; i++) { - result.AddRange(new TextureGPUData[] { new (default, default, default, default) }); + result.AddRange(new TextureGpuData[] { new (default, default, default, default) }); } return OpenGLExtensionMethods.ToArray(result); @@ -205,13 +205,13 @@ protected internal override void UploadVertexData(FontGlyphBatchItem textureQuad textureBottomRight = textureBottomRight.ToNDCTextureCoords(textureWidth, textureHeight); // Convert the texture quad vertex positions to NDC values - var quadDataItem = new TextureGPUData( + var quadDataItem = new TextureGpuData( new TextureVertexData(vertex1, textureTopLeft, textureQuad.TintColor), new TextureVertexData(vertex2, textureBottomLeft, textureQuad.TintColor), new TextureVertexData(vertex3, textureTopRight, textureQuad.TintColor), new TextureVertexData(vertex4, textureBottomRight, textureQuad.TintColor)); - var totalBytes = TextureGPUData.GetTotalBytes(); + var totalBytes = TextureGpuData.GetTotalBytes(); var data = quadDataItem.ToArray(); var offset = totalBytes * batchIndex; diff --git a/Velaptor/OpenGL/Buffers/GPUBufferBase.cs b/Velaptor/OpenGL/Buffers/GpuBufferBase.cs similarity index 93% rename from Velaptor/OpenGL/Buffers/GPUBufferBase.cs rename to Velaptor/OpenGL/Buffers/GpuBufferBase.cs index 1dccdac5a..7ba28e114 100644 --- a/Velaptor/OpenGL/Buffers/GPUBufferBase.cs +++ b/Velaptor/OpenGL/Buffers/GpuBufferBase.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -18,7 +18,7 @@ namespace Velaptor.OpenGL.Buffers; /// Base functionality for managing buffer data in the GPU. /// /// The type of data in the GPU buffer. -internal abstract class GPUBufferBase : IGPUBuffer +internal abstract class GpuBufferBase : IGpuBuffer where TData : struct { private readonly IDisposable shutDownUnsubscriber; @@ -28,7 +28,7 @@ internal abstract class GPUBufferBase : IGPUBuffer private uint[] indices = Array.Empty(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Invokes OpenGL functions. /// Provides OpenGL related helper methods. @@ -36,7 +36,7 @@ internal abstract class GPUBufferBase : IGPUBuffer /// /// Invoked when any of the parameters are null. /// - internal GPUBufferBase( + internal GpuBufferBase( IGLInvoker gl, IOpenGLService openGLService, IReactableFactory reactableFactory) @@ -77,10 +77,10 @@ internal GPUBufferBase( } /// - /// Finalizes an instance of the class. + /// Finalizes an instance of the class. /// [ExcludeFromCodeCoverage(Justification = "De-constructors cannot be unit tested.")] - ~GPUBufferBase() + ~GpuBufferBase() { if (UnitTestDetector.IsRunningFromUnitTest) { @@ -270,21 +270,21 @@ private void ProcessCustomAttributes() Attribute[]? attributes = null; var currentType = GetType(); - if (currentType == typeof(TextureGPUBuffer)) + if (currentType == typeof(TextureGpuBuffer)) { - attributes = Attribute.GetCustomAttributes(typeof(TextureGPUBuffer)); + attributes = Attribute.GetCustomAttributes(typeof(TextureGpuBuffer)); } - else if (currentType == typeof(FontGPUBuffer)) + else if (currentType == typeof(FontGpuBuffer)) { - attributes = Attribute.GetCustomAttributes(typeof(FontGPUBuffer)); + attributes = Attribute.GetCustomAttributes(typeof(FontGpuBuffer)); } - else if (currentType == typeof(ShapeGPUBuffer)) + else if (currentType == typeof(ShapeGpuBuffer)) { - attributes = Attribute.GetCustomAttributes(typeof(ShapeGPUBuffer)); + attributes = Attribute.GetCustomAttributes(typeof(ShapeGpuBuffer)); } - else if (currentType == typeof(LineGPUBuffer)) + else if (currentType == typeof(LineGpuBuffer)) { - attributes = Attribute.GetCustomAttributes(typeof(LineGPUBuffer)); + attributes = Attribute.GetCustomAttributes(typeof(LineGpuBuffer)); } else { @@ -298,7 +298,7 @@ private void ProcessCustomAttributes() foreach (var attribute in attributes) { - if (attribute is GPUBufferNameAttribute nameAttribute) + if (attribute is GpuBufferNameAttribute nameAttribute) { Name = nameAttribute.Name; } diff --git a/Velaptor/OpenGL/Buffers/IGPUBuffer.cs b/Velaptor/OpenGL/Buffers/IGpuBuffer.cs similarity index 90% rename from Velaptor/OpenGL/Buffers/IGPUBuffer.cs rename to Velaptor/OpenGL/Buffers/IGpuBuffer.cs index fc7cea5b0..02e155b85 100644 --- a/Velaptor/OpenGL/Buffers/IGPUBuffer.cs +++ b/Velaptor/OpenGL/Buffers/IGpuBuffer.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -8,7 +8,7 @@ namespace Velaptor.OpenGL.Buffers; /// Manages buffer data in the GPU. /// /// The type of data in the buffer. -internal interface IGPUBuffer +internal interface IGpuBuffer where TData : struct { /// diff --git a/Velaptor/OpenGL/Buffers/LineGPUBuffer.cs b/Velaptor/OpenGL/Buffers/LineGpuBuffer.cs similarity index 92% rename from Velaptor/OpenGL/Buffers/LineGPUBuffer.cs rename to Velaptor/OpenGL/Buffers/LineGpuBuffer.cs index 5a9a8f521..76074d75e 100644 --- a/Velaptor/OpenGL/Buffers/LineGPUBuffer.cs +++ b/Velaptor/OpenGL/Buffers/LineGpuBuffer.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -12,21 +12,21 @@ namespace Velaptor.OpenGL.Buffers; using Exceptions; using ExtensionMethods; using Factories; -using GPUData; +using GpuData; using NativeInterop.OpenGL; using ReactableData; /// /// Updates data in the line GPU buffer. /// -[GPUBufferName("Line")] -internal sealed class LineGPUBuffer : GPUBufferBase +[GpuBufferName("Line")] +internal sealed class LineGpuBuffer : GpuBufferBase { private const string BufferNotInitMsg = "The line buffer has not been initialized."; private readonly IDisposable unsubscriber; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Invokes OpenGL functions. /// Provides OpenGL related helper methods. @@ -34,7 +34,7 @@ internal sealed class LineGPUBuffer : GPUBufferBase /// /// Invoked when any of the parameters are null. /// - public LineGPUBuffer( + public LineGpuBuffer( IGLInvoker gl, IOpenGLService openGLService, IReactableFactory reactableFactory) @@ -72,7 +72,7 @@ protected internal override void UploadVertexData(LineBatchItem lineData, uint b OpenGLService.BeginGroup($"Update Line - BatchItem({batchIndex})"); - var data = default(LineGPUData); + var data = default(LineGpuData); var lineRectPoints = lineData.CreateRectFromLine().ToArray(); @@ -88,7 +88,7 @@ protected internal override void UploadVertexData(LineBatchItem lineData, uint b data = data.SetColor(lineData.Color); - var totalBytes = LineGPUData.GetTotalBytes(); + var totalBytes = LineGpuData.GetTotalBytes(); var rawData = data.ToArray(); var offset = totalBytes * batchIndex; @@ -119,7 +119,7 @@ protected internal override float[] GenerateData() for (var i = 0; i < BatchSize; i++) { - result.AddRange(new LineGPUData(default, default, default, default).ToArray()); + result.AddRange(new LineGpuData(default, default, default, default).ToArray()); } return result.ToArray(); diff --git a/Velaptor/OpenGL/Buffers/ShapeGPUBuffer.cs b/Velaptor/OpenGL/Buffers/ShapeGpuBuffer.cs similarity index 62% rename from Velaptor/OpenGL/Buffers/ShapeGPUBuffer.cs rename to Velaptor/OpenGL/Buffers/ShapeGpuBuffer.cs index d40cf8c20..75cd1bfec 100644 --- a/Velaptor/OpenGL/Buffers/ShapeGPUBuffer.cs +++ b/Velaptor/OpenGL/Buffers/ShapeGpuBuffer.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -14,23 +14,23 @@ namespace Velaptor.OpenGL.Buffers; using Exceptions; using ExtensionMethods; using Factories; -using GPUData; +using GpuData; using Graphics; using NativeInterop.OpenGL; using ReactableData; /// -/// Updates data in the rectangle GPU buffer. +/// Updates data in the shape GPU buffer. /// -[GPUBufferName("Rectangle")] +[GpuBufferName("Shape")] [SuppressMessage("csharpsquid", "S101", Justification = "GPU is an acceptable acronym.")] -internal sealed class ShapeGPUBuffer : GPUBufferBase +internal sealed class ShapeGpuBuffer : GpuBufferBase { - private const string BufferNotInitMsg = "The rectangle buffer has not been initialized."; + private const string BufferNotInitMsg = "The shape buffer has not been initialized."; private readonly IDisposable unsubscriber; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Invokes OpenGL functions. /// Provides OpenGL related helper methods. @@ -38,7 +38,7 @@ internal sealed class ShapeGPUBuffer : GPUBufferBase /// /// Invoked when any of the parameters are null. /// - public ShapeGPUBuffer( + public ShapeGpuBuffer( IGLInvoker gl, IOpenGLService openGLService, IReactableFactory reactableFactory) @@ -67,9 +67,9 @@ public ShapeGPUBuffer( } /// - protected internal override void UploadVertexData(ShapeBatchItem rectShape, uint batchIndex) + protected internal override void UploadVertexData(ShapeBatchItem shape, uint batchIndex) { - OpenGLService.BeginGroup($"Update Rectangle - BatchItem({batchIndex})"); + OpenGLService.BeginGroup($"Update Shape - BatchItem({batchIndex})"); /* * Always have the smallest value between the width and height (divided by 2) @@ -78,15 +78,15 @@ protected internal override void UploadVertexData(ShapeBatchItem rectShape, uint * the width and height, it would produce unintended rendering artifacts. */ - rectShape = ProcessBorderThicknessLimit(rectShape); - rectShape = ProcessCornerRadiusLimits(rectShape); + shape = ProcessBorderThicknessLimit(shape); + shape = ProcessCornerRadiusLimits(shape); - var data = RectGPUData.Empty(); + var data = ShapeGpuData.Empty(); - var left = rectShape.Position.X - rectShape.HalfWidth; - var bottom = rectShape.Position.Y + rectShape.HalfHeight; - var right = rectShape.Position.X + rectShape.HalfWidth; - var top = rectShape.Position.Y - rectShape.HalfHeight; + var left = shape.Position.X - shape.HalfWidth; + var bottom = shape.Position.Y + shape.HalfHeight; + var right = shape.Position.X + shape.HalfWidth; + var top = shape.Position.Y - shape.HalfHeight; var topLeft = new Vector2(left, top).ToNDC(ViewPortSize.Width, ViewPortSize.Height); var bottomLeft = new Vector2(left, bottom).ToNDC(ViewPortSize.Width, ViewPortSize.Height); @@ -98,19 +98,19 @@ protected internal override void UploadVertexData(ShapeBatchItem rectShape, uint data = data.SetVertexPos(topRight, VertexNumber.Three); data = data.SetVertexPos(bottomRight, VertexNumber.Four); - data = data.SetRectangle(new Vector4(rectShape.Position.X, rectShape.Position.Y, rectShape.Width, rectShape.Height)); + data = data.SetRectangle(new Vector4(shape.Position.X, shape.Position.Y, shape.Width, shape.Height)); - data = ApplyColor(data, rectShape); + data = ApplyColor(data, shape); - data = data.SetAsSolid(rectShape.IsSolid); + data = data.SetAsSolid(shape.IsSolid); - data = data.SetBorderThickness(rectShape.BorderThickness); - data = data.SetTopLeftCornerRadius(rectShape.CornerRadius.TopLeft); - data = data.SetBottomLeftCornerRadius(rectShape.CornerRadius.BottomLeft); - data = data.SetBottomRightCornerRadius(rectShape.CornerRadius.BottomRight); - data = data.SetTopRightCornerRadius(rectShape.CornerRadius.TopRight); + data = data.SetBorderThickness(shape.BorderThickness); + data = data.SetTopLeftCornerRadius(shape.CornerRadius.TopLeft); + data = data.SetBottomLeftCornerRadius(shape.CornerRadius.BottomLeft); + data = data.SetBottomRightCornerRadius(shape.CornerRadius.BottomRight); + data = data.SetTopRightCornerRadius(shape.CornerRadius.TopRight); - var totalBytes = RectGPUData.GetTotalBytes(); + var totalBytes = ShapeGpuData.GetTotalBytes(); var rawData = data.ToArray(); var offset = totalBytes * batchIndex; @@ -142,7 +142,7 @@ protected internal override float[] GenerateData() for (var i = 0u; i < BatchSize; i++) { var vertexData = GenerateVertexData(); - result.AddRange(new RectGPUData(vertexData[0], vertexData[1], vertexData[2], vertexData[3]).ToArray()); + result.AddRange(new ShapeGpuData(vertexData[0], vertexData[1], vertexData[2], vertexData[3]).ToArray()); } return result.ToArray(); @@ -151,7 +151,7 @@ protected internal override float[] GenerateData() /// protected internal override void SetupVAO() { - var stride = RectVertexData.GetStride(); + var stride = ShapeVertexData.GetStride(); var attrComponentSizes = new[] { @@ -218,49 +218,49 @@ protected override void ShutDown() } /// - /// Generates default for all four vertices that make - /// up a rectangle rendering area. + /// Generates default for all four vertices that make + /// up a rectangular rendering area. /// /// The four vertex data items. - private static RectVertexData[] GenerateVertexData() => new[] + private static ShapeVertexData[] GenerateVertexData() => new[] { - RectVertexData.New(-1.0f, 1.0f), - RectVertexData.New(-1.0f, -1.0f), - RectVertexData.New(1.0f, 1.0f), - RectVertexData.New(1.0f, 1.0f), + ShapeVertexData.New(-1.0f, 1.0f), + ShapeVertexData.New(-1.0f, -1.0f), + ShapeVertexData.New(1.0f, 1.0f), + ShapeVertexData.New(1.0f, 1.0f), }; /// - /// Applies the color of the given shape to the rectangle + /// Applies the color of the given shape to the shape /// data being sent to the GPU. /// /// The data to apply the color to. - /// The rect that holds the color to apply to the data. + /// The shape that holds the color to apply to the data. /// The original GPU with the color applied. /// - /// Thrown if the of the given + /// Thrown if the of the given /// is an invalid value. /// - private static RectGPUData ApplyColor(RectGPUData data, ShapeBatchItem rect) + private static ShapeGpuData ApplyColor(ShapeGpuData data, ShapeBatchItem shape) { - switch (rect.GradientType) + switch (shape.GradientType) { case ColorGradient.None: - return data.SetColor(rect.Color); + return data.SetColor(shape.Color); case ColorGradient.Horizontal: - data = data.SetColor(rect.GradientStart, VertexNumber.One); // BOTTOM LEFT - data = data.SetColor(rect.GradientStart, VertexNumber.Two); // BOTTOM RIGHT - data = data.SetColor(rect.GradientStop, VertexNumber.Three); // TOP RIGHT - data = data.SetColor(rect.GradientStop, VertexNumber.Four); // BOTTOM RIGHT + data = data.SetColor(shape.GradientStart, VertexNumber.One); // BOTTOM LEFT + data = data.SetColor(shape.GradientStart, VertexNumber.Two); // BOTTOM RIGHT + data = data.SetColor(shape.GradientStop, VertexNumber.Three); // TOP RIGHT + data = data.SetColor(shape.GradientStop, VertexNumber.Four); // BOTTOM RIGHT break; case ColorGradient.Vertical: - data = data.SetColor(rect.GradientStart, VertexNumber.One); // BOTTOM LEFT - data = data.SetColor(rect.GradientStop, VertexNumber.Two); // BOTTOM RIGHT - data = data.SetColor(rect.GradientStart, VertexNumber.Three); // TOP RIGHT - data = data.SetColor(rect.GradientStop, VertexNumber.Four); // BOTTOM RIGHT + data = data.SetColor(shape.GradientStart, VertexNumber.One); // BOTTOM LEFT + data = data.SetColor(shape.GradientStop, VertexNumber.Two); // BOTTOM RIGHT + data = data.SetColor(shape.GradientStart, VertexNumber.Three); // TOP RIGHT + data = data.SetColor(shape.GradientStop, VertexNumber.Four); // BOTTOM RIGHT break; default: - throw new ArgumentOutOfRangeException(nameof(rect.GradientType), "The gradient type is invalid."); + throw new ArgumentOutOfRangeException(nameof(shape.GradientType), "The gradient type is invalid."); } return data; @@ -270,44 +270,44 @@ private static RectGPUData ApplyColor(RectGPUData data, ShapeBatchItem rect) /// Process the border thickness by checking that the value is within limits. /// If it is not within limits, it will force the value to be within limits. /// - /// The rectangle containing the border thickness to set within a limit. + /// The shape containing the border thickness to set within a limit. /// /// This is done to prevent any undesired rendering artifacts from occuring. /// - private static ShapeBatchItem ProcessBorderThicknessLimit(ShapeBatchItem rect) + private static ShapeBatchItem ProcessBorderThicknessLimit(ShapeBatchItem shape) { - var largestValueAllowed = (rect.Width <= rect.Height ? rect.Width : rect.Height) / 2f; + var largestValueAllowed = (shape.Width <= shape.Height ? shape.Width : shape.Height) / 2f; - var newBorderThickness = rect.BorderThickness > largestValueAllowed + var newBorderThickness = shape.BorderThickness > largestValueAllowed ? largestValueAllowed - : rect.BorderThickness; + : shape.BorderThickness; newBorderThickness = newBorderThickness < 1f ? 1f : newBorderThickness; - rect = new ShapeBatchItem( - rect.Position, - rect.Width, - rect.Height, - rect.Color, - rect.IsSolid, + shape = new ShapeBatchItem( + shape.Position, + shape.Width, + shape.Height, + shape.Color, + shape.IsSolid, newBorderThickness, - rect.CornerRadius, - rect.GradientType, - rect.GradientStart, - rect.GradientStop); + shape.CornerRadius, + shape.GradientType, + shape.GradientStart, + shape.GradientStop); - return rect; + return shape; } /// /// Processes the corner radius by checking each corner radius value and making sure they /// are within limits. If it is not within limits, it will force the values to be within limits. /// - /// The rectangle containing the radius values to process. - /// The rect with the corner radius values set within limits. + /// The shape containing the radius values to process. + /// The shape with the corner radius values set within limits. /// /// This is done to prevent any undesired rendering artifacts from occuring. /// - private static ShapeBatchItem ProcessCornerRadiusLimits(ShapeBatchItem rect) + private static ShapeBatchItem ProcessCornerRadiusLimits(ShapeBatchItem shape) { /* * Always have the smallest value between the width and height (divided by 2) @@ -315,22 +315,22 @@ private static ShapeBatchItem ProcessCornerRadiusLimits(ShapeBatchItem rect) * If the value was allowed to be larger than the smallest value between * the width and height, it would produce unintended rendering artifacts. */ - var largestValueAllowed = (rect.Width <= rect.Height ? rect.Width : rect.Height) / 2f; + var largestValueAllowed = (shape.Width <= shape.Height ? shape.Width : shape.Height) / 2f; - var clampedCornerRadius = rect.CornerRadius.Clamp(0, largestValueAllowed); + var clampedCornerRadius = shape.CornerRadius.Clamp(0, largestValueAllowed); - rect = new ShapeBatchItem( - rect.Position, - rect.Width, - rect.Height, - rect.Color, - rect.IsSolid, - rect.BorderThickness, + shape = new ShapeBatchItem( + shape.Position, + shape.Width, + shape.Height, + shape.Color, + shape.IsSolid, + shape.BorderThickness, clampedCornerRadius, - rect.GradientType, - rect.GradientStart, - rect.GradientStop); + shape.GradientType, + shape.GradientStart, + shape.GradientStop); - return rect; + return shape; } } diff --git a/Velaptor/OpenGL/Buffers/TextureGPUBuffer.cs b/Velaptor/OpenGL/Buffers/TextureGpuBuffer.cs similarity index 95% rename from Velaptor/OpenGL/Buffers/TextureGPUBuffer.cs rename to Velaptor/OpenGL/Buffers/TextureGpuBuffer.cs index fe52d8b30..ba1126b4a 100644 --- a/Velaptor/OpenGL/Buffers/TextureGPUBuffer.cs +++ b/Velaptor/OpenGL/Buffers/TextureGpuBuffer.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -12,7 +12,7 @@ namespace Velaptor.OpenGL.Buffers; using Carbonate.UniDirectional; using Exceptions; using Factories; -using GPUData; +using GpuData; using Graphics; using NativeInterop.OpenGL; using ReactableData; @@ -22,14 +22,14 @@ namespace Velaptor.OpenGL.Buffers; /// /// Updates texture data in the GPU buffer. /// -[GPUBufferName("Texture")] -internal sealed class TextureGPUBuffer : GPUBufferBase +[GpuBufferName("Texture")] +internal sealed class TextureGpuBuffer : GpuBufferBase { private const string BufferNotInitMsg = "The texture buffer has not been initialized."; private readonly IDisposable unsubscriber; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Invokes OpenGL functions. /// Provides OpenGL related helper methods. @@ -37,7 +37,7 @@ internal sealed class TextureGPUBuffer : GPUBufferBase /// /// Invoked when any of the parameters are null. /// - public TextureGPUBuffer( + public TextureGpuBuffer( IGLInvoker gl, IOpenGLService openGLService, IReactableFactory reactableFactory) @@ -150,13 +150,13 @@ protected internal override void UploadVertexData(TextureBatchItem textureQuad, textureBottomRight = textureBottomRight.ToNDCTextureCoords(textureWidth, textureHeight); // Convert the texture quad vertex positions to NDC values - var quadDataItem = new TextureGPUData( + var quadDataItem = new TextureGpuData( new TextureVertexData(vertex1, textureTopLeft, textureQuad.TintColor), new TextureVertexData(vertex2, textureBottomLeft, textureQuad.TintColor), new TextureVertexData(vertex3, textureTopRight, textureQuad.TintColor), new TextureVertexData(vertex4, textureBottomRight, textureQuad.TintColor)); - var totalBytes = TextureGPUData.GetTotalBytes(); + var totalBytes = TextureGpuData.GetTotalBytes(); var data = quadDataItem.ToArray(); var offset = totalBytes * batchIndex; @@ -188,11 +188,11 @@ protected internal override float[] GenerateData() throw new BufferNotInitializedException(BufferNotInitMsg); } - var result = new List(); + var result = new List(); for (var i = 0u; i < BatchSize; i++) { - result.AddRange(new TextureGPUData[] { new (default, default, default, default) }); + result.AddRange(new TextureGpuData[] { new (default, default, default, default) }); } return OpenGLExtensionMethods.ToArray(result); diff --git a/Velaptor/OpenGL/GLWindow.cs b/Velaptor/OpenGL/GLWindow.cs index 3c760081a..bbff47e7e 100644 --- a/Velaptor/OpenGL/GLWindow.cs +++ b/Velaptor/OpenGL/GLWindow.cs @@ -202,6 +202,18 @@ public VelaptorWindowBorder TypeOfBorder /// public ISceneManager SceneManager { get; } + /// + public bool AutoSceneLoading { get; set; } = true; + + /// + public bool AutoSceneUnloading { get; set; } = true; + + /// + public bool AutoSceneUpdating { get; set; } = true; + + /// + public bool AutoSceneRendering { get; set; } = true; + /// public int UpdateFrequency { @@ -291,6 +303,9 @@ await this.taskService.ContinueWith( /// private static void GL_GLError(object? sender, GLErrorEventArgs e) => throw new Exception(e.ErrorMessage); + /// + /// Runs the OpenGL window. + /// private void RunGLWindow() { this.glWindow.Run(); diff --git a/Velaptor/OpenGL/GPUBufferNameAttribute.cs b/Velaptor/OpenGL/GpuBufferNameAttribute.cs similarity index 70% rename from Velaptor/OpenGL/GPUBufferNameAttribute.cs rename to Velaptor/OpenGL/GpuBufferNameAttribute.cs index 4bbcd01c7..fab2f2217 100644 --- a/Velaptor/OpenGL/GPUBufferNameAttribute.cs +++ b/Velaptor/OpenGL/GpuBufferNameAttribute.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -11,13 +11,13 @@ namespace Velaptor.OpenGL; /// Represents the name of a buffer. /// [AttributeUsage(AttributeTargets.Class)] -internal sealed class GPUBufferNameAttribute : Attribute +internal sealed class GpuBufferNameAttribute : Attribute { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The name to give a buffer. - public GPUBufferNameAttribute(string name) + public GpuBufferNameAttribute(string name) { EnsureThat.StringParamIsNotNullOrEmpty(name); Name = name; diff --git a/Velaptor/OpenGL/GPUData/LineGPUData.cs b/Velaptor/OpenGL/GpuData/LineGpuData.cs similarity index 87% rename from Velaptor/OpenGL/GPUData/LineGPUData.cs rename to Velaptor/OpenGL/GpuData/LineGpuData.cs index 0ee6c4b96..328d3fc7b 100644 --- a/Velaptor/OpenGL/GPUData/LineGPUData.cs +++ b/Velaptor/OpenGL/GpuData/LineGpuData.cs @@ -1,32 +1,32 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // -namespace Velaptor.OpenGL.GPUData; +namespace Velaptor.OpenGL.GpuData; using System.Collections.Generic; /// /// Holds all the necessary data for a line to send to the GPU for rendering. /// -internal readonly struct LineGPUData +internal readonly struct LineGpuData { private const uint TotalVertexItems = 4u; private static readonly uint Stride; /// - /// Initializes static members of the struct. + /// Initializes static members of the struct. /// - static LineGPUData() => Stride = LineVertexData.GetStride() * TotalVertexItems; + static LineGpuData() => Stride = LineVertexData.GetStride() * TotalVertexItems; /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The first vertex of the line. /// The second vertex of the line. /// The third vertex of the line. /// The fourth vertex of the line. - public LineGPUData(LineVertexData vertex1, LineVertexData vertex2, LineVertexData vertex3, LineVertexData vertex4) + public LineGpuData(LineVertexData vertex1, LineVertexData vertex2, LineVertexData vertex3, LineVertexData vertex4) { Vertex1 = vertex1; Vertex2 = vertex2; @@ -77,7 +77,7 @@ public LineGPUData(LineVertexData vertex1, LineVertexData vertex2, LineVertexDat public LineVertexData Vertex4 { get; } /// - /// The total number of bytes that the data contains. + /// The total number of bytes that the data contains. /// /// The total number of bytes. public static uint GetTotalBytes() => Stride; diff --git a/Velaptor/OpenGL/GPUData/LineVertexData.cs b/Velaptor/OpenGL/GpuData/LineVertexData.cs similarity index 95% rename from Velaptor/OpenGL/GPUData/LineVertexData.cs rename to Velaptor/OpenGL/GpuData/LineVertexData.cs index 7d87f7c05..a5000a429 100644 --- a/Velaptor/OpenGL/GPUData/LineVertexData.cs +++ b/Velaptor/OpenGL/GpuData/LineVertexData.cs @@ -2,14 +2,14 @@ // Copyright (c) KinsonDigital. All rights reserved. // -namespace Velaptor.OpenGL.GPUData; +namespace Velaptor.OpenGL.GpuData; using System.Collections.Generic; using System.Drawing; using System.Numerics; /// -/// Represents a single vertex of the sent to the GPU. +/// Represents a single vertex of the sent to the GPU. /// internal readonly struct LineVertexData { diff --git a/Velaptor/OpenGL/GPUData/RectGPUData.cs b/Velaptor/OpenGL/GpuData/ShapeGpuData.cs similarity index 51% rename from Velaptor/OpenGL/GPUData/RectGPUData.cs rename to Velaptor/OpenGL/GpuData/ShapeGpuData.cs index ffbc76fd6..d4b2a6491 100644 --- a/Velaptor/OpenGL/GPUData/RectGPUData.cs +++ b/Velaptor/OpenGL/GpuData/ShapeGpuData.cs @@ -1,32 +1,32 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // -namespace Velaptor.OpenGL.GPUData; +namespace Velaptor.OpenGL.GpuData; using System.Collections.Generic; /// -/// Holds all the necessary data for a rectangle to send to the GPU for rendering. +/// Holds all the necessary data for a shape to send to the GPU for rendering. /// -internal readonly struct RectGPUData +internal readonly struct ShapeGpuData { private const uint TotalVertexItems = 4u; private static readonly uint TotalBytes; /// - /// Initializes static members of the struct. + /// Initializes static members of the struct. /// - static RectGPUData() => TotalBytes = RectVertexData.GetStride() * TotalVertexItems; + static ShapeGpuData() => TotalBytes = ShapeVertexData.GetStride() * TotalVertexItems; /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// - /// The first vertex of the rectangle. - /// The second vertex of the rectangle. - /// The third vertex of the rectangle. - /// The fourth vertex of the rectangle. - public RectGPUData(RectVertexData vertex1, RectVertexData vertex2, RectVertexData vertex3, RectVertexData vertex4) + /// The first vertex of the shape. + /// The second vertex of the shape. + /// The third vertex of the shape. + /// The fourth vertex of the shape. + public ShapeGpuData(ShapeVertexData vertex1, ShapeVertexData vertex2, ShapeVertexData vertex3, ShapeVertexData vertex4) { Vertex1 = vertex1; Vertex2 = vertex2; @@ -35,55 +35,55 @@ public RectGPUData(RectVertexData vertex1, RectVertexData vertex2, RectVertexDat } /// - /// Gets the vertex data for the top left vertex of a rectangle. + /// Gets the vertex data for the top left vertex of a bounding box. /// /// - /// This is first vertex of the top left triangle that makes up the rectangle. + /// This is first vertex of the top left triangle that makes up the bounding box. /// - public RectVertexData Vertex1 { get; } + public ShapeVertexData Vertex1 { get; } /// - /// Gets the vertex data for the bottom left vertex of a rectangle. + /// Gets the vertex data for the bottom left vertex of a bounding box. /// /// /// - /// This is second vertex of the bottom left triangle that makes up the rectangle. + /// This is second vertex of the bottom left triangle that makes up the bounding box. /// /// - /// This vertex is shared with the second vertex of the bottom right triangle of the rectangle. + /// This vertex is shared with the second vertex of the bottom right triangle of the bounding box. /// /// - public RectVertexData Vertex2 { get; } + public ShapeVertexData Vertex2 { get; } /// - /// Gets the vertex data for the top right vertex of a rectangle. + /// Gets the vertex data for the top right vertex of a bounding box. /// /// /// - /// This is third vertex of the top left triangle that makes up the rectangle. + /// This is third vertex of the top left triangle that makes up the bounding box. /// /// - /// This vertex is shared with the first vertex of the bottom right triangle of the rectangle. + /// This vertex is shared with the first vertex of the bottom right triangle of the bounding box. /// /// - public RectVertexData Vertex3 { get; } + public ShapeVertexData Vertex3 { get; } /// - /// Gets the vertex data for the bottom right vertex of a rectangle. + /// Gets the vertex data for the bottom right vertex of a bounding box. /// /// - /// This is the third vertex of the bottom right triangle of the rectangle. + /// This is the third vertex of the bottom right triangle of the bounding box. /// - public RectVertexData Vertex4 { get; } + public ShapeVertexData Vertex4 { get; } /// - /// Creates an empty instance of . + /// Creates an empty instance of . /// /// An empty instance. - public static RectGPUData Empty() => new (RectVertexData.Empty(), RectVertexData.Empty(), RectVertexData.Empty(), RectVertexData.Empty()); + public static ShapeGpuData Empty() => new (ShapeVertexData.Empty(), ShapeVertexData.Empty(), ShapeVertexData.Empty(), ShapeVertexData.Empty()); /// - /// The total number of bytes that the data contains. + /// The total number of bytes that the data contains. /// /// The total number of bytes. public static uint GetTotalBytes() => TotalBytes; diff --git a/Velaptor/OpenGL/GPUData/RectVertexData.cs b/Velaptor/OpenGL/GpuData/ShapeVertexData.cs similarity index 64% rename from Velaptor/OpenGL/GPUData/RectVertexData.cs rename to Velaptor/OpenGL/GpuData/ShapeVertexData.cs index 314414862..7ad7db366 100644 --- a/Velaptor/OpenGL/GPUData/RectVertexData.cs +++ b/Velaptor/OpenGL/GpuData/ShapeVertexData.cs @@ -1,41 +1,41 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // -namespace Velaptor.OpenGL.GPUData; +namespace Velaptor.OpenGL.GpuData; using System.Collections.Generic; using System.Drawing; using System.Numerics; /// -/// Represents a single vertex of the sent to the GPU. +/// Represents a single vertex of the sent to the GPU. /// -internal readonly struct RectVertexData +internal readonly struct ShapeVertexData { private const uint TotalElements = 16u; private static readonly uint Stride; /// - /// Initializes static members of the struct. + /// Initializes static members of the struct. /// - static RectVertexData() => Stride = TotalElements * sizeof(float); + static ShapeVertexData() => Stride = TotalElements * sizeof(float); /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The position of the vertex. - /// The rectangle components. + /// The corner vectors of the bounding box that contain the shape. /// The fill or border color. - /// True if the rectangle is a solid color. + /// True if the shape is a solid color. /// The thickness of the border. /// The top left corner radius. /// The bottom left corner radius. /// The bottom right corner radius. /// The top right corner radius. - public RectVertexData( + public ShapeVertexData( Vector2 vertexPos, - Vector4 rectangle, + Vector4 boundingBox, Color color, bool isSolid, float borderThickness, @@ -45,7 +45,7 @@ public RectVertexData( float topRightCornerRadius) { VertexPos = vertexPos; - Rectangle = rectangle; + BoundingBox = boundingBox; Color = color; IsSolid = isSolid; BorderThickness = borderThickness; @@ -56,68 +56,68 @@ public RectVertexData( } /// - /// Gets the position of a single rectangle vertex. + /// Gets the position of a single shape vertex. /// public Vector2 VertexPos { get; } /// - /// Gets the components that make up the rectangle. + /// Gets the components that make up the bounding box. /// /// - /// The components below represent the rectangle: + /// The components below represent the bounding box: /// - /// X: The position of the center of the rectangle on the X axis. - /// Y: The position of the center of the rectangle on the Y axis. - /// Z: The width of the rectangle. - /// W: The height of the rectangle. + /// X: The position of the center of the bounding box on the X axis. + /// Y: The position of the center of the bounding box on the Y axis. + /// Z: The width of the bound box. + /// W: The height of the bound box. /// /// - public Vector4 Rectangle { get; } + public Vector4 BoundingBox { get; } /// - /// Gets the color of the rectangle. + /// Gets the color of the shape. /// /// - /// This is the solid color if the entire rectangle is set to true - /// and is the solid color of the rectangle border if is set to false. + /// This is the solid color if the entire shape is set to true + /// and is the solid color of the shape border if is set to false. /// public Color Color { get; } /// - /// Gets a value indicating whether or not the rectangle will be rendered as a solid rectangle. + /// Gets a value indicating whether or not the shape will be rendered as a solid shape. /// public bool IsSolid { get; } /// - /// Gets the thickness of the rectangle border if the is set to false. + /// Gets the thickness of the shape border if the is set to false. /// public float BorderThickness { get; } /// - /// Gets the radius of the top left corner of the rectangle. + /// Gets the radius of the top left corner of the bound box. /// public float TopLeftCornerRadius { get; } /// - /// Gets the radius of the bottom left corner of the rectangle. + /// Gets the radius of the bottom left corner of the bound box. /// public float BottomLeftCornerRadius { get; } /// - /// Gets the radius of the bottom right corner of the rectangle. + /// Gets the radius of the bottom right corner of the bound box. /// public float BottomRightCornerRadius { get; } /// - /// Gets the radius of the top right corner of the rectangle. + /// Gets the radius of the top right corner of the bound box. /// public float TopRightCornerRadius { get; } /// - /// Returns an empty instance. + /// Returns an empty instance. /// /// The empty instance. - public static RectVertexData Empty() => + public static ShapeVertexData Empty() => new ( Vector2.Zero, Vector4.Zero, @@ -136,12 +136,12 @@ public static RectVertexData Empty() => public static uint GetStride() => Stride; /// - /// Creates a new instance of a struct with the given and components.. + /// Creates a new instance of a struct with the given and components. /// /// The X component of the position. /// The Y component of the position. /// The new instance. - public static RectVertexData New(float x, float y) => + public static ShapeVertexData New(float x, float y) => new (new Vector2(x, y), Vector4.Zero, Color.Empty, @@ -167,7 +167,7 @@ has to match the layout told to OpenGL. var result = new List(); result.AddRange(VertexPos.ToArray()); - result.AddRange(Rectangle.ToArray()); + result.AddRange(BoundingBox.ToArray()); result.AddRange(Color.ToArray()); result.Add(IsSolid ? 1f : 0f); diff --git a/Velaptor/OpenGL/GPUData/TextureGPUData.cs b/Velaptor/OpenGL/GpuData/TextureGpuData.cs similarity index 83% rename from Velaptor/OpenGL/GPUData/TextureGPUData.cs rename to Velaptor/OpenGL/GpuData/TextureGpuData.cs index 60d00d13b..d09baf16e 100644 --- a/Velaptor/OpenGL/GPUData/TextureGPUData.cs +++ b/Velaptor/OpenGL/GpuData/TextureGpuData.cs @@ -1,8 +1,8 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // -namespace Velaptor.OpenGL.GPUData; +namespace Velaptor.OpenGL.GpuData; using System; using System.Diagnostics.CodeAnalysis; @@ -10,16 +10,16 @@ namespace Velaptor.OpenGL.GPUData; /// /// Holds data for a single quad in the GPU vertex buffer. /// -internal readonly struct TextureGPUData : IEquatable +internal readonly struct TextureGpuData : IEquatable { /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The top left corner vertex of the quad. /// The top right corner vertex of the quad. /// The bottom right corner vertex of the quad. /// The bottom left corner vertex of the quad. - public TextureGPUData(in TextureVertexData vertex1, TextureVertexData vertex2, TextureVertexData vertex3, TextureVertexData vertex4) + public TextureGpuData(in TextureVertexData vertex1, TextureVertexData vertex2, TextureVertexData vertex3, TextureVertexData vertex4) { Vertex1 = vertex1; Vertex2 = vertex2; @@ -54,7 +54,7 @@ public TextureGPUData(in TextureVertexData vertex1, TextureVertexData vertex2, T /// The left operand. /// The right operand. /// true if the two operands are equal. - public static bool operator ==(TextureGPUData left, TextureGPUData right) => left.Equals(right); + public static bool operator ==(TextureGpuData left, TextureGpuData right) => left.Equals(right); /// /// Returns a value indicating whether or not the operand is not equal to the operand. @@ -63,7 +63,7 @@ public TextureGPUData(in TextureVertexData vertex1, TextureVertexData vertex2, T /// The left operand. /// The right operand. /// true if the two operands are equal. - public static bool operator !=(TextureGPUData left, TextureGPUData right) => !(left == right); + public static bool operator !=(TextureGpuData left, TextureGpuData right) => !(left == right); /// /// Returns the total number of bytes for this struct. @@ -74,7 +74,7 @@ public TextureGPUData(in TextureVertexData vertex1, TextureVertexData vertex2, T /// public override bool Equals(object? obj) { - if (obj is not TextureGPUData data) + if (obj is not TextureGpuData data) { return false; } @@ -83,7 +83,7 @@ public override bool Equals(object? obj) } /// - public bool Equals(TextureGPUData other) + public bool Equals(TextureGpuData other) => Vertex1 == other.Vertex1 && Vertex2 == other.Vertex2 && Vertex3 == other.Vertex3 && diff --git a/Velaptor/OpenGL/GPUData/TextureVertexData.cs b/Velaptor/OpenGL/GpuData/TextureVertexData.cs similarity index 97% rename from Velaptor/OpenGL/GPUData/TextureVertexData.cs rename to Velaptor/OpenGL/GpuData/TextureVertexData.cs index ccc784544..b12a95510 100644 --- a/Velaptor/OpenGL/GPUData/TextureVertexData.cs +++ b/Velaptor/OpenGL/GpuData/TextureVertexData.cs @@ -2,7 +2,7 @@ // Copyright (c) KinsonDigital. All rights reserved. // -namespace Velaptor.OpenGL.GPUData; +namespace Velaptor.OpenGL.GpuData; using System; using System.Diagnostics.CodeAnalysis; @@ -10,7 +10,7 @@ namespace Velaptor.OpenGL.GPUData; using System.Numerics; /// -/// Represents a single vertex of the sent to the GPU. +/// Represents a single vertex of the sent to the GPU. /// internal readonly struct TextureVertexData : IEquatable { diff --git a/Velaptor/OpenGL/OpenGLExtensionMethods.cs b/Velaptor/OpenGL/OpenGLExtensionMethods.cs index 64aab21af..3e73ad70b 100644 --- a/Velaptor/OpenGL/OpenGLExtensionMethods.cs +++ b/Velaptor/OpenGL/OpenGLExtensionMethods.cs @@ -7,7 +7,7 @@ namespace Velaptor.OpenGL; using System.Collections.Generic; using System.Drawing; using System.Numerics; -using GPUData; +using GpuData; /// /// Provides various helper methods for OpenGL related operations. @@ -152,7 +152,7 @@ public static float[] ToArray(this TextureVertexData vertexData) /// /// The quad to convert. /// An array of float values. - public static float[] ToArray(this TextureGPUData data) + public static float[] ToArray(this TextureGpuData data) { var result = new List(); @@ -169,7 +169,7 @@ public static float[] ToArray(this TextureGPUData data) /// /// The quads to convert. /// An array of float values. - public static float[] ToArray(this IEnumerable data) + public static float[] ToArray(this IEnumerable data) { var result = new List(); diff --git a/Velaptor/OpenGL/ShaderCode/rectangle.frag b/Velaptor/OpenGL/ShaderCode/shape.frag similarity index 100% rename from Velaptor/OpenGL/ShaderCode/rectangle.frag rename to Velaptor/OpenGL/ShaderCode/shape.frag diff --git a/Velaptor/OpenGL/ShaderCode/rectangle.vert b/Velaptor/OpenGL/ShaderCode/shape.vert similarity index 100% rename from Velaptor/OpenGL/ShaderCode/rectangle.vert rename to Velaptor/OpenGL/ShaderCode/shape.vert diff --git a/Velaptor/OpenGL/Shaders/ShaderEnums.cs b/Velaptor/OpenGL/Shaders/ShaderEnums.cs index bd75fe856..dc33858a4 100644 --- a/Velaptor/OpenGL/Shaders/ShaderEnums.cs +++ b/Velaptor/OpenGL/Shaders/ShaderEnums.cs @@ -20,9 +20,9 @@ internal enum ShaderType Font = 2, /// - /// A rectangle shape shader. + /// A shape shader. /// - Rectangle = 3, + Shape = 3, /// /// A line shader. diff --git a/Velaptor/OpenGL/Shaders/ShaderProgram.cs b/Velaptor/OpenGL/Shaders/ShaderProgram.cs index f205dfa80..dccebd3c6 100644 --- a/Velaptor/OpenGL/Shaders/ShaderProgram.cs +++ b/Velaptor/OpenGL/Shaders/ShaderProgram.cs @@ -286,9 +286,9 @@ private void ProcessCustomAttributes() { attributes = Attribute.GetCustomAttributes(typeof(FontShader)); } - else if (currentType == typeof(RectangleShader)) + else if (currentType == typeof(ShapeShader)) { - attributes = Attribute.GetCustomAttributes(typeof(RectangleShader)); + attributes = Attribute.GetCustomAttributes(typeof(ShapeShader)); } else if (currentType == typeof(LineShader)) { diff --git a/Velaptor/OpenGL/Shaders/RectangleShader.cs b/Velaptor/OpenGL/Shaders/ShapeShader.cs similarity index 85% rename from Velaptor/OpenGL/Shaders/RectangleShader.cs rename to Velaptor/OpenGL/Shaders/ShapeShader.cs index 733c53eb1..a97391145 100644 --- a/Velaptor/OpenGL/Shaders/RectangleShader.cs +++ b/Velaptor/OpenGL/Shaders/ShapeShader.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) KinsonDigital. All rights reserved. // @@ -13,15 +13,15 @@ namespace Velaptor.OpenGL.Shaders; using Services; /// -/// A rectangle shader used to render 2D rectangles. +/// A shader used to render 2D shapes. /// -[ShaderName("Rectangle")] -internal sealed class RectangleShader : ShaderProgram +[ShaderName("Shape")] +internal sealed class ShapeShader : ShaderProgram { private readonly IDisposable unsubscriber; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Invokes OpenGL functions. /// Provides OpenGL related helper methods. @@ -30,7 +30,7 @@ internal sealed class RectangleShader : ShaderProgram /// /// Invoked when any of the parameters are null. /// - public RectangleShader( + public ShapeShader( IGLInvoker gl, IOpenGLService openGLService, IShaderLoaderService shaderLoaderService, diff --git a/Velaptor/PullResponses.cs b/Velaptor/PullResponses.cs index 41f7340f3..d122fac3b 100644 --- a/Velaptor/PullResponses.cs +++ b/Velaptor/PullResponses.cs @@ -24,7 +24,7 @@ internal static class PullResponses /// /// Gets the unique for request notifications for returning rect batch items. /// - public static Guid GetRectItemsId { get; } = new ("bb5b2b6e-05f0-4404-acf2-7d19fca83fa1"); + public static Guid GetShapeItemsId { get; } = new ("bb5b2b6e-05f0-4404-acf2-7d19fca83fa1"); /// /// Gets the unique for request notifications for returning line batch items. diff --git a/Velaptor/PushNotifications.cs b/Velaptor/PushNotifications.cs index 210c02e43..784f43cdb 100644 --- a/Velaptor/PushNotifications.cs +++ b/Velaptor/PushNotifications.cs @@ -89,10 +89,10 @@ internal static class PushNotifications /// /// Gets the unique for push notifications for when the rectangles need to be rendered. /// - public static Guid RenderRectsId { get; } = new ("27c20138-52d3-4b5d-936d-3b62e3b7db4d"); + public static Guid RenderShapesId { get; } = new ("27c20138-52d3-4b5d-936d-3b62e3b7db4d"); /// - /// Gets the unique for push notifications for when the lines need to be rendered. + /// Gets the unique for push notifications when the lines need to be rendered. /// public static Guid RenderLinesId { get; } = new ("3fb13cdb-db24-4d28-b117-b9604722277f"); } diff --git a/Velaptor/Scene/IScene.cs b/Velaptor/Scene/IScene.cs index 01f90a2e2..f1aaaf832 100644 --- a/Velaptor/Scene/IScene.cs +++ b/Velaptor/Scene/IScene.cs @@ -5,6 +5,7 @@ namespace Velaptor.Scene; using System; +using System.Diagnostics.CodeAnalysis; using System.Drawing; using Content; using Velaptor; @@ -28,21 +29,25 @@ public interface IScene : IUpdatable, IDrawable, IDisposable /// /// Gets a value indicating whether or not the scene has been loaded. /// + [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Public API")] bool IsLoaded { get; } /// /// Gets the size of the window. /// + [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Public API")] SizeU WindowSize { get; } /// /// Gets the center of the window. /// + [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Public API")] Point WindowCenter { get; } /// /// Gets the content loader. /// + [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Public API")] IContentLoader ContentLoader { get; } /// @@ -54,12 +59,14 @@ public interface IScene : IUpdatable, IDrawable, IDisposable /// Adds a control to the scene to be updated and rendered. /// /// The control to add to the scene. + [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Public API")] void AddControl(IControl control); /// /// Removes the given from the scene. /// /// The control to remove. + [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Public API")] void RemoveControl(IControl control); /// diff --git a/Velaptor/Scene/ISceneManager.cs b/Velaptor/Scene/ISceneManager.cs index d86d76eab..a5de1a8b1 100644 --- a/Velaptor/Scene/ISceneManager.cs +++ b/Velaptor/Scene/ISceneManager.cs @@ -16,7 +16,7 @@ public interface ISceneManager : IUpdatable, IDrawable, IDisposable /// /// Gets the current scene. /// - public IScene? CurrentScene { get; } + IScene? CurrentScene { get; } /// /// Gets a list of all the 's for the scenes that are inactive. @@ -25,12 +25,18 @@ public interface ISceneManager : IUpdatable, IDrawable, IDisposable [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Used by library users.")] IReadOnlyCollection InActiveScenes { get; } + /// + /// Gets a value indicating whether or not the scene manager has been loaded. + /// + /// This does not mean that the content in the individual scenes have been loaded. + bool IsLoaded { get; } + /// /// Adds the given scene. /// /// The scene to add. /// The scene will not be activated when added using this method. - public void AddScene(IScene scene); + void AddScene(IScene scene); /// /// Adds the given scene and sets it as active or inactive. @@ -40,24 +46,24 @@ public interface ISceneManager : IUpdatable, IDrawable, IDisposable /// When set to true, the scene being added will be set to active and /// all other scenes will bet set to inactive. /// - public void AddScene(IScene scene, bool setToActive); + void AddScene(IScene scene, bool setToActive); /// /// Removes the scene that matches the given . /// /// The ID of the scene to remove. [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Used for library users.")] - public void RemoveScene(Guid sceneId); + void RemoveScene(Guid sceneId); /// /// Moves to the next scene. /// - public void NextScene(); + void NextScene(); /// /// Moves to the previous scene. /// - public void PreviousScene(); + void PreviousScene(); /// /// Sets a scene that matches the given to be the active scene. @@ -72,12 +78,12 @@ public interface ISceneManager : IUpdatable, IDrawable, IDisposable /// /// Loads the content for the manager and the current scene. /// - public void LoadContent(); + void LoadContent(); /// /// Unloads the scene manager content and added scenes. /// - public void UnloadContent(); + void UnloadContent(); /// /// Returns a value indicating whether or not a scene exists that matches the given . diff --git a/Velaptor/Scene/SceneBase.cs b/Velaptor/Scene/SceneBase.cs index 6cd47faea..578fd6a1c 100644 --- a/Velaptor/Scene/SceneBase.cs +++ b/Velaptor/Scene/SceneBase.cs @@ -167,6 +167,9 @@ protected virtual void Dispose(bool disposing) IsDisposed = true; } + /// + /// Unloads all of the controls. + /// private void UnloadAllControls() { foreach (var control in this.controls) diff --git a/Velaptor/Scene/SceneManager.cs b/Velaptor/Scene/SceneManager.cs index 695c5210d..37c68c888 100644 --- a/Velaptor/Scene/SceneManager.cs +++ b/Velaptor/Scene/SceneManager.cs @@ -17,16 +17,18 @@ internal sealed class SceneManager : ISceneManager { private readonly List<(IScene? scene, bool isActive)> scenes = new (); private bool isDisposed; - private bool isLoaded; /// - public IScene? CurrentScene => this.scenes.FirstOrDefault(s => s.isActive).scene; + public IScene? CurrentScene => this.scenes.Find(s => s.isActive).scene; /// public IReadOnlyCollection InActiveScenes => this.scenes.Where(s => s.scene is not null && s.isActive is false) .Select(s => s.scene?.Id ?? Guid.Empty).ToArray().AsReadOnly(); + /// + public bool IsLoaded { get; private set; } + /// public void AddScene(IScene scene) => AddScene(scene, false); @@ -70,7 +72,7 @@ public void RemoveScene(Guid sceneId) return; } - var sceneToRemove = this.scenes.FirstOrDefault(s => s.scene?.Id == sceneId); + var sceneToRemove = this.scenes.Find(s => s.scene?.Id == sceneId); if (sceneToRemove.scene is null) { @@ -164,20 +166,20 @@ public void LoadContent() throw new ObjectDisposedException(nameof(SceneManager), "Cannot load a scene manager that has been disposed."); } - if (this.isLoaded) + if (IsLoaded) { return; } CurrentScene?.LoadContent(); - this.isLoaded = true; + IsLoaded = true; } /// public void UnloadContent() { - if (!this.isLoaded || this.isDisposed) + if (IsLoaded is false || this.isDisposed) { return; } @@ -196,7 +198,7 @@ public void UnloadContent() /// /// The ID of the scene to check for. /// True if the scene exists. - public bool SceneExists(Guid id) => this.scenes.Any(s => s.scene?.Id == id); + public bool SceneExists(Guid id) => this.scenes.Exists(s => s.scene?.Id == id); /// public void Dispose() diff --git a/Velaptor/Services/AppService.cs b/Velaptor/Services/AppService.cs index 86678e7be..98090b146 100644 --- a/Velaptor/Services/AppService.cs +++ b/Velaptor/Services/AppService.cs @@ -5,7 +5,6 @@ namespace Velaptor.Services; using System.Diagnostics.CodeAnalysis; -using Graphics.Renderers; /// [ExcludeFromCodeCoverage(Justification = "No implementation to test")] @@ -21,7 +20,6 @@ public void Init() return; } - IRenderer.Init(); this.alreadyInitialized = true; } } diff --git a/Velaptor/UI/IWindow.cs b/Velaptor/UI/IWindow.cs index 96f5a6d9e..1761fdf04 100644 --- a/Velaptor/UI/IWindow.cs +++ b/Velaptor/UI/IWindow.cs @@ -7,8 +7,8 @@ namespace Velaptor.UI; using System; using System.Numerics; using System.Threading.Tasks; +using Batching; using Content; -using Graphics.Renderers; using Scene; /// @@ -74,16 +74,16 @@ public interface IWindow : IDisposable /// /// /// - /// If this is set to true, this means you do not have to - /// use or invoke the () method. + /// If this is set to true, it means you do not have to + /// use or invoke the () method. /// /// - /// Set to the value of false if you want more control over when + /// Set to the value of false if you want more control when /// the back buffers will be cleared. /// /// - /// WARNING!! - To prevent performance issues, do not have the clear - /// the buffers with the () method + /// WARNING!! - To prevent performance issues, do not manually clear the + /// buffer with the () method /// and set this property to true. That would be a waste of resources. /// /// @@ -119,6 +119,26 @@ public interface IWindow : IDisposable /// ISceneManager SceneManager { get; } + /// + /// Gets or sets a value indicating whether or not the scenes should be automatically loaded. + /// + bool AutoSceneLoading { get; set; } + + /// + /// Gets or sets a value indicating whether or not the scenes should be automatically unloaded. + /// + public bool AutoSceneUnloading { get; set; } + + /// + /// Gets or sets a value indicating whether or not the scenes should be automatically updated. + /// + public bool AutoSceneUpdating { get; set; } + + /// + /// Gets or sets a value indicating whether or not the scenes should be automatically rendered. + /// + public bool AutoSceneRendering { get; set; } + /// /// Shows the window. /// diff --git a/Velaptor/UI/Window.cs b/Velaptor/UI/Window.cs index 21f0dcb32..2607a00f3 100644 --- a/Velaptor/UI/Window.cs +++ b/Velaptor/UI/Window.cs @@ -8,6 +8,7 @@ namespace Velaptor.UI; using System.Diagnostics.CodeAnalysis; using System.Numerics; using System.Threading.Tasks; +using Batching; using Content; using Factories; using Guards; @@ -19,6 +20,7 @@ namespace Velaptor.UI; public abstract class Window : IWindow { private readonly IWindow nativeWindow; + private readonly IBatcher batcher; private bool isDisposed; /// @@ -29,6 +31,8 @@ protected Window() { this.nativeWindow = WindowFactory.CreateWindow(); SceneManager = IoC.Container.GetInstance(); + this.batcher = IoC.Container.GetInstance(); + Init(); } @@ -37,13 +41,16 @@ protected Window() /// /// The window implementation that contains the window functionality. /// Manages scenes. - private protected Window(IWindow window, ISceneManager sceneManager) + /// Controls the batching start and end process. + private protected Window(IWindow window, ISceneManager sceneManager, IBatcher batcher) { EnsureThat.ParamIsNotNull(window); EnsureThat.ParamIsNotNull(sceneManager); + EnsureThat.ParamIsNotNull(batcher); this.nativeWindow = window; SceneManager = sceneManager; + this.batcher = batcher; Init(); } @@ -155,6 +162,22 @@ public IContentLoader ContentLoader /// public ISceneManager SceneManager { get; } + /// + public bool AutoSceneLoading { get; set; } = true; + + /// + public bool AutoSceneUnloading { get; set; } = true; + + /// + public bool AutoSceneUpdating { get; set; } = true; + + /// + /// + /// If this is set to false, using and + /// will be required to render the scene. + /// + public bool AutoSceneRendering { get; set; } = true; + /// public bool Initialized => this.nativeWindow.Initialized; @@ -193,6 +216,12 @@ public void Dispose() [ExcludeFromCodeCoverage(Justification = "Not originally intended to have a method body.")] protected virtual void OnLoad() { + if (AutoSceneLoading is false) + { + return; + } + + SceneManager.LoadContent(); } /// @@ -202,6 +231,12 @@ protected virtual void OnLoad() [ExcludeFromCodeCoverage(Justification = "Not originally intended to have a method body.")] protected virtual void OnUpdate(FrameTime frameTime) { + if (AutoSceneUpdating is false) + { + return; + } + + SceneManager.Update(frameTime); } /// @@ -211,6 +246,17 @@ protected virtual void OnUpdate(FrameTime frameTime) [ExcludeFromCodeCoverage(Justification = "Not originally intended to have a method body.")] protected virtual void OnDraw(FrameTime frameTime) { + if (AutoSceneRendering is false) + { + return; + } + + this.batcher.Clear(); + this.batcher.Begin(); + + SceneManager.Render(); + + this.batcher.End(); } /// @@ -219,6 +265,12 @@ protected virtual void OnDraw(FrameTime frameTime) [ExcludeFromCodeCoverage(Justification = "Not originally intended to have a method body.")] protected virtual void OnUnload() { + if (AutoSceneUnloading is false) + { + return; + } + + SceneManager.UnloadContent(); } /// @@ -231,27 +283,15 @@ protected virtual void OnResize(SizeU size) { } - /// - /// Initializes the window. - /// - private void Init() - { - this.nativeWindow.Initialize = OnLoad; - this.nativeWindow.Update = OnUpdate; - this.nativeWindow.Draw = OnDraw; - this.nativeWindow.WinResize = OnResize; - this.nativeWindow.Uninitialize = OnUnload; - - // Set the update frequency to default value of 60 - // just in case the IWindow implementation is not - this.nativeWindow.UpdateFrequency = 60; - } - /// /// /// /// Disposes managed resources when true. - private void Dispose(bool disposing) + [SuppressMessage( + "ReSharper", + "VirtualMemberNeverOverridden.Global", + Justification = "Left for library users to override if needed.")] + protected virtual void Dispose(bool disposing) { if (this.isDisposed) { @@ -265,4 +305,20 @@ private void Dispose(bool disposing) this.isDisposed = true; } + + /// + /// Initializes the window. + /// + private void Init() + { + this.nativeWindow.Initialize = OnLoad; + this.nativeWindow.Update = OnUpdate; + this.nativeWindow.Draw = OnDraw; + this.nativeWindow.WinResize = OnResize; + this.nativeWindow.Uninitialize = OnUnload; + + // Set the update frequency to default value of 60 + // just in case the IWindow implementation is not + this.nativeWindow.UpdateFrequency = 60; + } } diff --git a/Velaptor/Velaptor.csproj b/Velaptor/Velaptor.csproj index e2009133a..d46428cea 100644 --- a/Velaptor/Velaptor.csproj +++ b/Velaptor/Velaptor.csproj @@ -60,45 +60,23 @@ - - - - - - - - Never - - - Never - - - - + + + + + + - - - - - - - - - - - - -