Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧Add render overloads #1028

Merged
merged 9 commits into from
Sep 3, 2024
36 changes: 21 additions & 15 deletions Testing/VelaptorTesting/Scenes/AnimatedGraphicsScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,28 @@ namespace VelaptorTesting.Scenes;
public class AnimatedGraphicsScene : SceneBase
{
private const int WindowPadding = 10;
private readonly ITextureRenderer textureRenderer;
private readonly BackgroundManager backgroundManager;
private readonly ILoader<IAtlasData> atlasLoader;
private IAtlasData? mainAtlas;
private ITextureRenderer? textureRenderer;
private AtlasSubTextureData[]? frames;
private BackgroundManager? backgroundManager;
private ILoader<IAtlasData>? atlasLoader;
private IControlGroup? grpInstructions;
private IControlGroup? grpAnimation;
private int elapsedTime;
private int currentFrame;
private float animSpeed = 32;
private bool runningForward = true;

/// <summary>
/// Initializes a new instance of the <see cref="AnimatedGraphicsScene"/> class.
/// </summary>
public AnimatedGraphicsScene()
{
this.backgroundManager = new BackgroundManager();
this.textureRenderer = RendererFactory.CreateTextureRenderer();
this.atlasLoader = ContentLoaderFactory.CreateAtlasLoader();
}

/// <inheritdoc cref="IScene.LoadContent"/>
public override void LoadContent()
{
Expand All @@ -42,12 +52,8 @@ public override void LoadContent()
return;
}

this.backgroundManager = new BackgroundManager();
this.backgroundManager.Load(new Vector2(WindowCenter.X, WindowCenter.Y));

this.textureRenderer = RendererFactory.CreateTextureRenderer();

this.atlasLoader = ContentLoaderFactory.CreateAtlasLoader();
this.mainAtlas = this.atlasLoader.Load("Main-Atlas");
this.frames = this.mainAtlas.GetFrames("samus");

Expand Down Expand Up @@ -115,7 +121,7 @@ public override void UnloadContent()
return;
}

this.backgroundManager?.Unload();
this.backgroundManager.Unload();
this.atlasLoader.Unload(this.mainAtlas);
this.grpInstructions.Dispose();
this.grpInstructions = null;
Expand Down Expand Up @@ -156,15 +162,15 @@ public override void Update(FrameTime frameTime)
/// <inheritdoc cref="IDrawable.Render"/>
public override void Render()
{
this.backgroundManager?.Render();
this.backgroundManager.Render();

this.textureRenderer.Render(
this.mainAtlas.Texture,
this.frames[this.currentFrame].Bounds,
new Rectangle(WindowCenter.X, WindowCenter.Y, (int)this.mainAtlas.Width, (int)this.mainAtlas.Height),
this.mainAtlas,
"samus",
new Vector2(WindowCenter.X, WindowCenter.Y),
0,
3f,
0f,
Color.White,
RenderEffects.None);
this.currentFrame);

this.grpInstructions.Render();
this.grpAnimation.Render();
Expand Down
62 changes: 19 additions & 43 deletions Testing/VelaptorTesting/Scenes/LayeredTextureRenderingScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ public class LayeredTextureRenderingScene : SceneBase
private const RenderLayer OrangeLayer = RenderLayer.Two;
private const RenderLayer BlueLayer = RenderLayer.Four;
private readonly IAppInput<KeyboardState> keyboard;
private ITextureRenderer? textureRenderer;
private readonly ITextureRenderer textureRenderer;
private readonly BackgroundManager backgroundManager;
private readonly ILoader<IAtlasData> atlasLoader;
private IAtlasData? atlas;
private AtlasSubTextureData whiteBoxData;
private Vector2 whiteBoxPos;
private Vector2 orangeBoxPos;
private Vector2 blueBoxPos;
private KeyboardState currentKeyState;
private KeyboardState prevKeyState;
private AtlasSubTextureData whiteBoxData;
private AtlasSubTextureData orangeBoxData;
private AtlasSubTextureData blueBoxData;
private BackgroundManager? backgroundManager;
private ILoader<IAtlasData>? atlasLoader;
private IControlGroup? grpInstructions;
private IControlGroup? grpTextureState;
private RenderLayer whiteLayer = RenderLayer.One;
Expand All @@ -50,7 +49,13 @@ public class LayeredTextureRenderingScene : SceneBase
/// <summary>
/// Initializes a new instance of the <see cref="LayeredTextureRenderingScene"/> class.
/// </summary>
public LayeredTextureRenderingScene() => this.keyboard = HardwareFactory.GetKeyboard();
public LayeredTextureRenderingScene()
{
this.keyboard = HardwareFactory.GetKeyboard();
this.backgroundManager = new BackgroundManager();
this.textureRenderer = RendererFactory.CreateTextureRenderer();
this.atlasLoader = ContentLoaderFactory.CreateAtlasLoader();
}

/// <inheritdoc cref="IScene.LoadContent"/>
public override void LoadContent()
Expand All @@ -61,17 +66,12 @@ public override void LoadContent()
}

this.isFirstRender = true;
this.backgroundManager = new BackgroundManager();
this.backgroundManager.Load(new Vector2(WindowCenter.X, WindowCenter.Y));

this.textureRenderer = RendererFactory.CreateTextureRenderer();

this.atlasLoader = ContentLoaderFactory.CreateAtlasLoader();
this.atlas = this.atlasLoader.Load("layered-rendering-atlas");

this.whiteBoxData = this.atlas.GetFrames("white-box")[0];
this.orangeBoxData = this.atlas.GetFrames("orange-box")[0];
this.blueBoxData = this.atlas.GetFrames("blue-box")[0];

// Set the default white box position
this.orangeBoxPos.X = WindowCenter.X - 100;
Expand Down Expand Up @@ -137,40 +137,16 @@ public override void Update(FrameTime frameTime)
/// <inheritdoc cref="IDrawable.Render"/>
public override void Render()
{
this.backgroundManager.Render();

// BLUE
this.textureRenderer.Render(
this.atlas.Texture,
this.blueBoxData.Bounds,
new Rectangle((int)this.blueBoxPos.X, (int)this.blueBoxPos.Y, (int)this.atlas.Width, (int)this.atlas.Height),
1f,
0f,
Color.White,
RenderEffects.None,
(int)BlueLayer);
this.textureRenderer.Render(this.atlas, "blue-box", this.blueBoxPos, 0, (int)BlueLayer);

// ORANGE
this.textureRenderer.Render(
this.atlas.Texture,
this.orangeBoxData.Bounds,
new Rectangle((int)this.orangeBoxPos.X, (int)this.orangeBoxPos.Y, (int)this.atlas.Width, (int)this.atlas.Height),
1f,
0f,
Color.White,
RenderEffects.None,
(int)OrangeLayer); // Neutral layer

this.backgroundManager.Render();
this.textureRenderer.Render(this.atlas, "orange-box", this.orangeBoxPos, 0, (int)OrangeLayer);

// WHITE
this.textureRenderer.Render(
this.atlas.Texture,
this.whiteBoxData.Bounds,
new Rectangle((int)this.whiteBoxPos.X, (int)this.whiteBoxPos.Y, (int)this.atlas.Width, (int)this.atlas.Height),
1f,
0f,
Color.White,
RenderEffects.None,
(int)this.whiteLayer);
this.textureRenderer.Render(this.atlas, "white-box", this.whiteBoxPos, 0, (int)this.whiteLayer);

this.grpInstructions.Render();
this.grpTextureState.Render();
Expand Down Expand Up @@ -224,9 +200,9 @@ private void UpdateBoxStateText()
// Render the current enabled box text
var textLines = new[]
{
$"2. White Box Layer: {this.whiteLayer}",
$"3. Orange Box Layer: {OrangeLayer}",
$"4. Blue Box Layer: {BlueLayer}",
$"1. White Box Layer: {this.whiteLayer}",
$"2. Orange Box Layer: {OrangeLayer}",
$"3. Blue Box Layer: {BlueLayer}",
};

var lblBoxStateCtrl = this.grpTextureState.GetControl<ILabel>(this.lblBoxStateName);
Expand Down
12 changes: 5 additions & 7 deletions Testing/VelaptorTesting/Scenes/NonAnimatedGraphicsScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ public class NonAnimatedGraphicsScene : SceneBase
{
private const int WindowPadding = 10;
private readonly IAppInput<KeyboardState> keyboard;
private readonly ITextureRenderer? textureRenderer;
private readonly ITextureRenderer textureRenderer;
private readonly ILoader<IAtlasData> atlasLoader;
private IAtlasData? mainAtlas;
private IControlGroup? grpControls;
private AtlasSubTextureData octagonData;
private KeyboardState prevKeyState;
private BackgroundManager? backgroundManager;
private RenderEffects renderEffects = RenderEffects.None;
Expand Down Expand Up @@ -81,7 +80,6 @@ public override void LoadContent()
this.grpControls.Add(lblInstructions);

this.mainAtlas = this.atlasLoader.Load("Main-Atlas");
this.octagonData = this.mainAtlas.GetFrames("octagon-flip")[0];

base.LoadContent();
}
Expand Down Expand Up @@ -159,11 +157,11 @@ public override void Render()
this.backgroundManager?.Render();

this.textureRenderer.Render(
this.mainAtlas.Texture,
this.octagonData.Bounds,
new Rectangle(WindowCenter.X, WindowCenter.Y, (int)this.mainAtlas.Width, (int)this.mainAtlas.Height),
this.mainAtlas,
"octagon-flip",
new Vector2(WindowCenter.X, WindowCenter.Y),
0F,
1f,
0f,
Color.White,
this.renderEffects);

Expand Down
1 change: 0 additions & 1 deletion Testing/VelaptorTests/Content/AudioLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace VelaptorTests.Content;
using System;
using System.IO;
using System.IO.Abstractions;
using System.Runtime.InteropServices;
using FluentAssertions;
using NSubstitute;
using Velaptor.Content;
Expand Down
Loading
Loading