using System.Numerics; namespace DaggerFramework.Rendering { /// /// An abstract class representing the graphics renderer. /// public abstract class Renderer { // INIT /// /// Creates the renderer window and initializes internal resources. /// /// Settings for the rendering window. /// Rendering settings. public abstract void CreateAndInitialize(WindowSettings windowSettings, RendererSettings renderSettings); /// /// Initializes internal resources. Should be called before other methods. /// /// Rendering settings. public abstract void Initialize(RendererSettings settings); // UTIL /// /// Indicates if the renderer will render the next frame. /// public abstract bool ShouldRun { get; } /// /// Target frames per second for rendering. /// public abstract int TargetFps { get; set; } public abstract bool VSync { get; set; } public double FrameTime => GetFrameTime(); // WINDOW /// /// The size of the render window. /// public abstract Vector2 WindowSize { get; } public abstract string WindowTitle { get; set; } /// /// Active monitor's size. /// public abstract Vector2 MonitorSize { get; } /// /// Creates a window. /// /// Window settings to use to create the window. 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 /// /// Prepares the renderer for drawing the next frame. /// public abstract void BeginFrame(); /// /// Ends rendering of the frame. /// public abstract void EndFrame(); public abstract void BeginCamera2d(Vector2 offset, Vector2 target, float rotation, float zoom); public abstract void EndCamera2d(); /// /// Clears the render canvas and sets a background color. /// /// Background color. public abstract void ClearBackground(Color color); /// /// Loads the texture onto the GPU for later use in DrawTexture or other Texture related methods. /// /// Texture to load. /// A texture handler on the GPU. public abstract int LoadTexture(Texture2d texture); /// /// Sets transforms for the next draw operation. /// /// Global transform position. /// Local offset point around which shapes will rotate. /// Rotation. public abstract void SetTransform(Vector2 position, Vector2 offset, float rotation = 0.0f); /// /// Sets the transform for the next draw operation. /// /// Transform matrix. public abstract void SetTransform(Matrix4x4 transform); /// /// Draws a filled circle. /// /// Radius of a circle. /// Fill color. public abstract void DrawCircle(float radius, Color color); /// /// Draws a filled rectangle. /// /// Rectangle size. /// Fill color. public abstract void DrawRectangle(Vector2 size, Color color); /// /// Draws a debug text with a default font. /// /// /// /// /// public abstract void DrawDebugText(string text, int fontSize, Color color); /// /// Draws text using a signed distance field font atlas. /// /// Text to draw. /// Size of the font. /// Color of the text. public abstract void DrawSdfText(string text, int fontSize, Color color); public abstract void DrawText(Font font, string text, Color color); /// /// Draws the texture. /// /// Texture handle. /// Texture tint. 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; } } }