3b20c53088
- Refactored DirectRendering class to support new IDirectRendering interface and manage textures directly. - Enhanced ImmediateMode to utilize ImmediateVertex struct for immediate rendering calls. - Updated Image class to use IDirectRendering for texture creation. - Modified test application to demonstrate immediate mode rendering with new structures. - Removed obsolete code related to previous rendering abstractions.
69 lines
2.5 KiB
C#
69 lines
2.5 KiB
C#
using System.Data;
|
|
using System.Drawing;
|
|
using System.Numerics;
|
|
using System.Runtime.InteropServices;
|
|
using Dashboard.Layout;
|
|
using Dashboard.Pal;
|
|
|
|
namespace Dashboard.Drawing
|
|
{
|
|
public record struct RectangleDrawInfo(Vector2 Position, ComputedBox Box, Brush Fill, Brush? Border = null);
|
|
|
|
[StructLayout(LayoutKind.Explicit, Size = Size)]
|
|
public struct ImmediateVertex()
|
|
{
|
|
[field: FieldOffset(PosOffset)]
|
|
public Vector3 Position { get; init; }= Vector3.Zero;
|
|
|
|
[field: FieldOffset(TexCoordsOffset)]
|
|
public Vector2 TexCoords { get; init; } = Vector2.Zero;
|
|
|
|
[field: FieldOffset(ColorOffset)]
|
|
public Vector4 Color { get; init; } = Vector4.One;
|
|
|
|
public ImmediateVertex(Vector3 position, Vector2 texCoords, Vector4 color) : this()
|
|
{
|
|
Position = position;
|
|
TexCoords = texCoords;
|
|
Color = color;
|
|
}
|
|
|
|
public ImmediateVertex(Vector3 position, Vector2 texCoords, Color color)
|
|
: this(
|
|
position,
|
|
texCoords,
|
|
new Vector4(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f))
|
|
{
|
|
}
|
|
|
|
public const int Size = 16 * sizeof(float);
|
|
public const int PosOffset = 0 * sizeof(float);
|
|
public const int TexCoordsOffset = 4 * sizeof(float);
|
|
public const int ColorOffset = 8 * sizeof(float);
|
|
}
|
|
|
|
public struct ImmediateDrawCall(MeshPrimitive primitive, ReadOnlyMemory<ImmediateVertex> vertices)
|
|
{
|
|
public MeshPrimitive Primitive { get; init; } = primitive;
|
|
public ReadOnlyMemory<ImmediateVertex> Vertices { get; init; } = vertices;
|
|
public PipelineState PipelineState { get; init; } = new PipelineState();
|
|
public Matrix4x4 Transforms { get; init; } = Matrix4x4.Identity;
|
|
public ITexture? Texture { get; init; } = null;
|
|
}
|
|
|
|
public interface IImmediateMode : IDeviceContextExtension
|
|
{
|
|
/// <summary>
|
|
/// Enqueue a draw with the immediate mode shader pipeline.
|
|
/// </summary>
|
|
/// <param name="call">Information about this draw call.</param>
|
|
void DrawImmediate(ImmediateDrawCall call);
|
|
|
|
// TODO: move these to their own extension?
|
|
void Line(Vector2 a, Vector2 b, float width, float depth, Vector4 color);
|
|
void Rectangle(Box2d rectangle, float depth, Vector4 color);
|
|
void Rectangle(in RectangleDrawInfo rectangle);
|
|
void Image(Box2d rectangle, Box2d uv, float depth, ITexture texture);
|
|
}
|
|
}
|