Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
Simon Lübeß
2022-01-05 15:42:57 +01:00
15 changed files with 289 additions and 32 deletions
@@ -0,0 +1,93 @@
using GlitchyEngine.Core;
namespace GlitchyEngine.Renderer
{
/// The stencil operations that can be performed during depth-stencil testing.
public enum StencilOperation : uint32
{
/// Keep the existing stencil data.
Keep = 1,
/// Set the stencil data to 0.
Zero= 2,
/// Set the stencil data to the reference value set by calling ID3D11DeviceContext::OMSetDepthStencilState.
Replace = 3,
/// Increment the stencil value by 1, and clamp the result.
IncrementAndClamp = 4,
/// Decrement the stencil value by 1, and clamp the result.
DecrementAndClamp = 5,
/// Invert the stencil data.
Invert = 6,
/// Increment the stencil value by 1, and wrap the result if necessary.
Increment = 7,
/// Decrement the stencil value by 1, and wrap the result if necessary.
Decrement = 8
}
public struct DepthStencilOperationDescription
{
/// The stencil operation to perform when stencil testing fails.
public StencilOperation StencilFailOperation = .Keep;
/// The stencil operation to perform when stencil testing passes and depth testing fails.
public StencilOperation StencilDepthFailOperation = .Keep;
/// The stencil operation to perform when stencil testing and depth testing both pass.
public StencilOperation StencilPassOperation = .Keep;
/// A function that compares stencil data against existing stencil data.
public ComparisonFunction StencilFunction = .Always;
public this(StencilOperation stencilFailOperation = .Keep, StencilOperation stencilDepthFailOperation = .Keep,
StencilOperation stencilPassOperation = .Keep, ComparisonFunction stencilFunction = .Always)
{
StencilFunction = stencilFunction;
}
public const Self Default = Self();
}
public struct DepthStencilStateDescription
{
/// True if depth testing is enabled.
public bool DepthEnabled = true;
/// If true writing to the depth-stencil buffer is enabled.
public bool WriteDepth = true;
/// The function that is used to compare depth data against the existing depth data.
public ComparisonFunction DepthFunction = .Less;
/// True if stencil testing is enabled.
public bool StencilEnabled = false;
public uint8 StencilReadMask = 255;
public uint8 StencilWriteMask = 255;
public DepthStencilOperationDescription FrontFace = .();
public DepthStencilOperationDescription BackFace = .();
public this(bool depthEnabled = true, bool writeDepth = true, ComparisonFunction depthFunction = .Less,
bool stencilEnabled = false, uint8 stencilReadMask = 255, uint8 stencilWriteMask = 255,
DepthStencilOperationDescription frontFace = .(),
DepthStencilOperationDescription backFace = .())
{
DepthEnabled = depthEnabled;
WriteDepth = writeDepth;
DepthFunction = depthFunction;
StencilEnabled = stencilEnabled;
StencilReadMask = stencilReadMask;
StencilWriteMask = stencilWriteMask;
FrontFace = frontFace;
BackFace = backFace;
}
public const DepthStencilStateDescription Default = Self();
}
class DepthStencilState : RefCounter
{
public DepthStencilStateDescription _description;
public extern this(DepthStencilStateDescription description);
}
}
+2 -4
View File
@@ -19,11 +19,9 @@ namespace GlitchyEngine.Renderer
}
}
public static void DisposeComponent(void* component)
public void Dispose() mut
{
Self* self = (Self*)component;
ReleaseRefAndNullify!(self._mesh);
ReleaseRefAndNullify!(_mesh);
}
}
}
@@ -75,6 +75,11 @@ namespace GlitchyEngine.Renderer
{
_rendererAPI.SetBlendState(blendState, blendFactor);
}
public static void SetDepthStencilState(DepthStencilState depthStencilState, uint8 stencilReference = 0)
{
_rendererAPI.SetDepthStencilState(depthStencilState, stencilReference);
}
[Inline]
public static void DrawIndexed(GeometryBinding geometry)
+14
View File
@@ -597,6 +597,20 @@ namespace GlitchyEngine.Renderer
}
}
public static void DrawQuad(Matrix transform, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1))
{
#if DEBUG
Log.EngineLogger.AssertDebug(s_sceneRunning, "Missing call of BeginScene.");
#endif
QueueQuadInstance(transform, color, texture, transform.Translation.Z, uvTransform);
if(s_drawOrder == .Immediate)
{
DrawDeferred();
}
}
public static void DrawQuadPivotCorner(Vector3 position, Vector2 size, float rotation, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1))
{
DrawQuad(position + Vector3(size.X / 2, size.Y / -2, 0), size, rotation, texture, color, uvTransform);
@@ -42,6 +42,8 @@ namespace GlitchyEngine.Renderer
public extern void SetBlendState(BlendState blendState, ColorRGBA blendFactor);
public extern void SetDepthStencilState(DepthStencilState depthStencilState, uint8 stencilReference);
public extern void DrawIndexed(GeometryBinding geometry);
public extern void DrawInstanced(GeometryBinding geometry);