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; } // WINDOW /// /// The size of the render window. /// public abstract Vector2 WindowSize { get; } /// /// Creates the window with a given title and size. /// /// Title of the window. /// Vector2 representing size. public abstract void CreateWindow(string title, Vector2 size); public void CreateWindow(WindowSettings windowSettings) { CreateWindow(windowSettings.Title, windowSettings.Size); } // TODO: use properties for these. public abstract void SetWindowTitle(string title); public abstract void SetWindowVSync(bool value); public abstract void SetTargetFps(int fps); public 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); public abstract double GetFrameTime(); /// /// 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); public abstract int LoadFont(Font font); /// /// Sets transforms for the next draw operation. /// /// Global transform position. /// Rotation. public abstract void SetTransform(Vector2 position, 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(int fontId, string text, int fontSize, 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 static RendererSettings Default => new RendererSettings() { UseVSync = true, }; } public struct WindowSettings { public string Title; public Vector2 Size = new Vector2(640, 480); public WindowSettings(string title, Vector2 size) { Title = title; Size = size; } } }