55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using System.Runtime.InteropServices;
|
|
using Engine.Renderer.Pixel;
|
|
using Engine.Renderer.Shader;
|
|
using OpenTK.Graphics.OpenGL;
|
|
using Serilog;
|
|
using Serilog.Events;
|
|
|
|
namespace Engine.Renderer;
|
|
|
|
public class Renderer
|
|
{
|
|
internal Texture.Texture TextureInternal => _framebuffer.TextureInternal;
|
|
|
|
private readonly Framebuffer.Framebuffer _framebuffer;
|
|
private readonly Queue<Action<Renderer>> _renderActions = new();
|
|
|
|
public Renderer(int width, int height)
|
|
{
|
|
InitializeOpenGl();
|
|
|
|
_framebuffer = Framebuffer.Framebuffer.Create<Rgb8>(width, height);
|
|
}
|
|
|
|
private void InitializeOpenGl()
|
|
{
|
|
#if DEBUG
|
|
Debug.Setup();
|
|
#endif
|
|
|
|
GL.Enable(EnableCap.DepthTest);
|
|
|
|
GL.Enable(EnableCap.FramebufferSrgb);
|
|
|
|
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
|
GL.Enable(EnableCap.Blend);
|
|
}
|
|
|
|
internal void Commit(Action<Renderer> renderAction)
|
|
{
|
|
_renderActions.Enqueue(renderAction);
|
|
}
|
|
|
|
internal void Render()
|
|
{
|
|
_framebuffer.Bind();
|
|
while (_renderActions.TryDequeue(out var renderAction))
|
|
renderAction(this);
|
|
_framebuffer.Unbind();
|
|
}
|
|
|
|
internal void Resize(int width, int height)
|
|
{
|
|
_framebuffer.Resize(width, height);
|
|
}
|
|
} |