176 lines
6.3 KiB
C#
176 lines
6.3 KiB
C#
using System.Numerics;
|
|
|
|
namespace DaggerFramework.Rendering
|
|
{
|
|
/// <summary>
|
|
/// An abstract class representing the graphics renderer.
|
|
/// </summary>
|
|
public abstract class Renderer
|
|
{
|
|
// INIT
|
|
/// <summary>
|
|
/// Creates the renderer window and initializes internal resources.
|
|
/// </summary>
|
|
/// <param name="windowSettings">Settings for the rendering window.</param>
|
|
/// <param name="renderSettings">Rendering settings.</param>
|
|
public abstract void CreateAndInitialize(WindowSettings windowSettings, RendererSettings renderSettings);
|
|
/// <summary>
|
|
/// Initializes internal resources. Should be called before other methods.
|
|
/// </summary>
|
|
/// <param name="settings">Rendering settings.</param>
|
|
public abstract void Initialize(RendererSettings settings);
|
|
|
|
// UTIL
|
|
/// <summary>
|
|
/// Indicates if the renderer will render the next frame.
|
|
/// </summary>
|
|
public abstract bool ShouldRun { get; }
|
|
/// <summary>
|
|
/// Target frames per second for rendering.
|
|
/// </summary>
|
|
public abstract int TargetFps { get; set; }
|
|
public abstract bool VSync { get; set; }
|
|
public double FrameTime => GetFrameTime();
|
|
|
|
// WINDOW
|
|
/// <summary>
|
|
/// The size of the render window.
|
|
/// </summary>
|
|
public abstract Vector2 WindowSize { get; }
|
|
|
|
public abstract string WindowTitle { get; set; }
|
|
|
|
/// <summary>
|
|
/// Active monitor's size.
|
|
/// </summary>
|
|
public abstract Vector2 MonitorSize { get; }
|
|
|
|
/// <summary>
|
|
/// Creates a window.
|
|
/// </summary>
|
|
/// <param name="windowSettings">Window settings to use to create the window.</param>
|
|
public abstract void CreateWindow(WindowSettings windowSettings);
|
|
protected abstract void SetWindowTitle(string title);
|
|
protected abstract void SetWindowVSync(bool value);
|
|
protected abstract void SetTargetFps(int fps);
|
|
protected abstract double GetFrameTime();
|
|
protected abstract int GetMonitorWidth(int monitorId);
|
|
protected abstract int GetMonitorHeight(int monitorId);
|
|
protected abstract int GetCurrentMonitor();
|
|
protected abstract bool WindowShouldClose();
|
|
public abstract void Shutdown();
|
|
|
|
// DRAWING
|
|
/// <summary>
|
|
/// Prepares the renderer for drawing the next frame.
|
|
/// </summary>
|
|
public abstract void BeginFrame();
|
|
/// <summary>
|
|
/// Ends rendering of the frame.
|
|
/// </summary>
|
|
public abstract void EndFrame();
|
|
|
|
public abstract void BeginCamera2d(Vector2 offset, Vector2 target, float rotation, float zoom);
|
|
public abstract void EndCamera2d();
|
|
|
|
/// <summary>
|
|
/// Clears the render canvas and sets a background color.
|
|
/// </summary>
|
|
/// <param name="color">Background color.</param>
|
|
public abstract void ClearBackground(Color color);
|
|
|
|
/// <summary>
|
|
/// Loads the texture onto the GPU for later use in DrawTexture or other Texture related methods.
|
|
/// </summary>
|
|
/// <param name="texture">Texture to load.</param>
|
|
/// <returns>A texture handler on the GPU.</returns>
|
|
public abstract int LoadTexture(Texture2d texture);
|
|
|
|
public abstract int LoadFont(Font font);
|
|
|
|
/// <summary>
|
|
/// Sets transforms for the next draw operation.
|
|
/// </summary>
|
|
/// <param name="position">Global transform position.</param>
|
|
/// <param name="offset">Local offset point around which shapes will rotate.</param>
|
|
/// <param name="rotation">Rotation.</param>
|
|
public abstract void SetTransform(Vector2 position, Vector2 offset, float rotation = 0.0f);
|
|
/// <summary>
|
|
/// Sets the transform for the next draw operation.
|
|
/// </summary>
|
|
/// <param name="transform">Transform matrix.</param>
|
|
public abstract void SetTransform(Matrix4x4 transform);
|
|
/// <summary>
|
|
/// Draws a filled circle.
|
|
/// </summary>
|
|
/// <param name="radius">Radius of a circle.</param>
|
|
/// <param name="color">Fill color.</param>
|
|
public abstract void DrawCircle(float radius, Color color);
|
|
/// <summary>
|
|
/// Draws a filled rectangle.
|
|
/// </summary>
|
|
/// <param name="size">Rectangle size.</param>
|
|
/// <param name="color">Fill color.</param>
|
|
public abstract void DrawRectangle(Vector2 size, Color color);
|
|
/// <summary>
|
|
/// Draws a debug text with a default font.
|
|
/// </summary>
|
|
/// <param name="position"></param>
|
|
/// <param name="text"></param>
|
|
/// <param name="fontSize"></param>
|
|
/// <param name="color"></param>
|
|
public abstract void DrawDebugText(string text, int fontSize, Color color);
|
|
/// <summary>
|
|
/// Draws text using a signed distance field font atlas.
|
|
/// </summary>
|
|
/// <param name="text">Text to draw.</param>
|
|
/// <param name="fontSize">Size of the font.</param>
|
|
/// <param name="color">Color of the text.</param>
|
|
public abstract void DrawSdfText(string text, int fontSize, Color color);
|
|
|
|
public abstract void DrawText(int fontId, string text, int fontSize, Color color);
|
|
|
|
/// <summary>
|
|
/// Draws the texture.
|
|
/// </summary>
|
|
/// <param name="id">Texture handle.</param>
|
|
/// <param name="tint">Texture tint.</param>
|
|
public abstract void DrawTexture(int id, Color tint);
|
|
}
|
|
|
|
public enum Msaa
|
|
{
|
|
None,
|
|
Msaa2x,
|
|
Msaa4x,
|
|
Msaa8x
|
|
}
|
|
public struct RendererSettings
|
|
{
|
|
public Msaa Msaa;
|
|
public bool UseVSync;
|
|
public bool Fullscreen;
|
|
public int TargetFps = 60;
|
|
|
|
public RendererSettings() { }
|
|
|
|
public static RendererSettings Default => new RendererSettings()
|
|
{
|
|
UseVSync = true,
|
|
TargetFps = 60
|
|
};
|
|
}
|
|
|
|
public struct WindowSettings
|
|
{
|
|
public string Title;
|
|
public Vector2 Size = new Vector2(640, 480);
|
|
public bool Resizable { get; set; }
|
|
|
|
public WindowSettings(string title, Vector2 size)
|
|
{
|
|
Title = title;
|
|
Size = size;
|
|
}
|
|
}
|
|
} |