-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SampleType, Added BlendState, Added GraphicsHelper, Worked on S…
…priteBatch
- Loading branch information
Showing
5 changed files
with
131 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Bliss.CSharp.Logging; | ||
using Veldrid; | ||
|
||
namespace Bliss.CSharp.Graphics; | ||
|
||
public class BlendState { | ||
|
||
private static Dictionary<BlendStateDescription, BlendState> _cachedBlendStates = new(); | ||
|
||
public static BlendState Disabled => FromDescription(BlendStateDescription.SingleDisabled); | ||
public static BlendState AdditiveBlend => FromDescription(BlendStateDescription.SingleAdditiveBlend); | ||
public static BlendState AlphaBlend => FromDescription(BlendStateDescription.SingleAlphaBlend); | ||
public static BlendState OverrideBlend => FromDescription(BlendStateDescription.SingleOverrideBlend); | ||
|
||
public readonly BlendStateDescription Description; | ||
|
||
/// <summary> | ||
/// Represents a state for blending operations in graphics rendering. It provides predefined blend states such as | ||
/// Empty, Disabled, AdditiveBlend, AlphaBlend, and OverrideBlend. This class allows for the creation or retrieval | ||
/// of blend states based on a given description. | ||
/// </summary> | ||
private BlendState(BlendStateDescription description) { | ||
this.Description = description; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new or retrieves an existing <see cref="BlendState"/> instance based on the provided | ||
/// <see cref="BlendStateDescription"/>. | ||
/// </summary> | ||
/// <param name="description">The description of the blend state to create or retrieve.</param> | ||
/// <returns>The <see cref="BlendState"/> instance corresponding to the provided description.</returns> | ||
public static BlendState FromDescription(BlendStateDescription description) { | ||
if (!_cachedBlendStates.TryGetValue(description, out BlendState? state)) { | ||
Logger.Info("Create a new BlendState."); | ||
BlendState blendState = new BlendState(description); | ||
|
||
_cachedBlendStates.Add(description, blendState); | ||
return blendState; | ||
} | ||
|
||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Veldrid; | ||
|
||
namespace Bliss.CSharp.Graphics; | ||
|
||
public static class GraphicsHelper { | ||
/// <summary> | ||
/// Retrieves a Sampler object based on the provided SamplerType. | ||
/// </summary> | ||
/// <param name="graphicsDevice">The graphics device used to create the sampler.</param> | ||
/// <param name="samplerType">The type of sampler to retrieve.</param> | ||
/// <returns>A Sampler object corresponding to the specified SamplerType.</returns> | ||
/// <exception cref="ArgumentException">Thrown when an unsupported sampler type is provided.</exception> | ||
public static Sampler GetSampler(GraphicsDevice graphicsDevice, SamplerType samplerType) { | ||
return samplerType switch { | ||
SamplerType.Point => graphicsDevice.PointSampler, | ||
SamplerType.Linear => graphicsDevice.LinearSampler, | ||
SamplerType.Aniso4X => graphicsDevice.Aniso4xSampler, | ||
_ => throw new ArgumentException($"Unsupported sampler type: {samplerType}", nameof(samplerType)) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Bliss.CSharp.Graphics; | ||
|
||
public enum SamplerType { | ||
Point, | ||
Linear, | ||
Aniso4X | ||
} |