227 lines
8.1 KiB
C#
227 lines
8.1 KiB
C#
using System.Drawing;
|
|
using System.Numerics;
|
|
using System.Text;
|
|
// using Veldrid;
|
|
// using Veldrid.Sdl2;
|
|
// using Veldrid.SPIRV;
|
|
// using Veldrid.StartupUtilities;
|
|
|
|
namespace DaggerFramework.Rendering
|
|
{
|
|
// public class StandardRenderer : Renderer
|
|
// {
|
|
// public override void BeginFrame()
|
|
// {
|
|
// _commandList.Begin();
|
|
// _commandList.SetFramebuffer(_graphicsDevice.SwapchainFramebuffer);
|
|
// }
|
|
|
|
// public override void ClearBackground(Color color)
|
|
// {
|
|
// _commandList.ClearColorTarget(0, SystemColorToRgbaFloat(color));
|
|
// }
|
|
|
|
// public override void CloseWindow()
|
|
// {
|
|
// _window.Close();
|
|
// }
|
|
|
|
// public override void CreateWindow(string title, Vector2 size)
|
|
// {
|
|
// var windowCreateInfo = new WindowCreateInfo()
|
|
// {
|
|
// // TODO: add position property to CreateWindow.
|
|
// X = (int)size.X / 2,
|
|
// Y = (int)size.Y / 2,
|
|
// WindowWidth = (int)size.X,
|
|
// WindowHeight = (int)size.Y,
|
|
// WindowTitle = title,
|
|
|
|
// };
|
|
|
|
// _window = VeldridStartup.CreateWindow(ref windowCreateInfo);
|
|
// }
|
|
|
|
// public override void DrawCircle(float radius, Color color)
|
|
// {
|
|
// throw new NotImplementedException();
|
|
// }
|
|
|
|
// public override void DrawDebugText(Vector2 position, string text, int fontSize, Color color)
|
|
// {
|
|
// throw new NotImplementedException();
|
|
// }
|
|
|
|
// public override void DrawRectangle(Vector2 size, Color color)
|
|
// {
|
|
// _commandList.SetVertexBuffer(0, _vertexBuffer);
|
|
// _commandList.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);
|
|
// _commandList.SetPipeline(_graphicsPipeline);
|
|
// _commandList.SetGraphicsResourceSet(0, _resourceSet);
|
|
// _graphicsDevice.UpdateBuffer(_uniformBuffer, 0, SystemColorToRgbaFloat(color));
|
|
// _commandList.DrawIndexed(indexCount: 4, instanceCount: 1, 0, 0, 0);
|
|
// }
|
|
|
|
// public override void DrawTexture(int id, Color tint)
|
|
// {
|
|
// throw new NotImplementedException();
|
|
// }
|
|
|
|
// public override void EndFrame()
|
|
// {
|
|
// _commandList.End();
|
|
// _graphicsDevice.SubmitCommands(_commandList);
|
|
// _graphicsDevice.SwapBuffers();
|
|
// }
|
|
|
|
// public override double GetFrameTime()
|
|
// {
|
|
// return 0.16f;
|
|
// }
|
|
|
|
// private void CreateResources()
|
|
// {
|
|
// _resourceFactory = _graphicsDevice.ResourceFactory;
|
|
// _commandList = _resourceFactory.CreateCommandList();
|
|
|
|
// _vertexBuffer = _resourceFactory.CreateBuffer(new BufferDescription(4 * 8, BufferUsage.VertexBuffer));
|
|
// _indexBuffer = _resourceFactory.CreateBuffer(new BufferDescription(4 * sizeof(ushort), BufferUsage.IndexBuffer));
|
|
// _uniformBuffer = _resourceFactory.CreateBuffer(new BufferDescription(4 * sizeof(float), BufferUsage.UniformBuffer));
|
|
|
|
|
|
// FillBuffers();
|
|
// var vertexDesc = new ShaderDescription(ShaderStages.Vertex, Encoding.UTF8.GetBytes(_colorRectShader.VertexSource), "main");
|
|
// var fragmentDesc = new ShaderDescription(ShaderStages.Fragment, Encoding.UTF8.GetBytes(_colorRectShader.FragmentSource), "main");
|
|
// _shaders = _resourceFactory.CreateFromSpirv(vertexDesc, fragmentDesc);
|
|
// CreatePipeline();
|
|
// }
|
|
|
|
// private void CreatePipeline()
|
|
// {
|
|
// VertexLayoutDescription vertexLayout = new VertexLayoutDescription(
|
|
// new VertexElementDescription("Position", VertexElementSemantic.Position, VertexElementFormat.Float2));
|
|
|
|
// var pipelineDesc = new GraphicsPipelineDescription();
|
|
// pipelineDesc.BlendState = BlendStateDescription.SingleOverrideBlend;
|
|
|
|
// pipelineDesc.RasterizerState = new RasterizerStateDescription(
|
|
// cullMode: FaceCullMode.Back,
|
|
// fillMode: PolygonFillMode.Solid,
|
|
// frontFace: FrontFace.Clockwise,
|
|
// depthClipEnabled: true,
|
|
// scissorTestEnabled: false);
|
|
|
|
// pipelineDesc.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
|
|
|
|
// var layout = _resourceFactory.CreateResourceLayout(new ResourceLayoutDescription(
|
|
// new ResourceLayoutElementDescription("color", ResourceKind.UniformBuffer, ShaderStages.Fragment)
|
|
// ));
|
|
|
|
// _resourceSet = _resourceFactory.CreateResourceSet(new ResourceSetDescription(layout, _uniformBuffer));
|
|
|
|
// pipelineDesc.ResourceLayouts = new ResourceLayout[] { layout };
|
|
|
|
// pipelineDesc.ShaderSet = new ShaderSetDescription(vertexLayouts: new VertexLayoutDescription[] { vertexLayout }, _shaders);
|
|
|
|
// pipelineDesc.Outputs = _graphicsDevice.SwapchainFramebuffer.OutputDescription;
|
|
|
|
// _graphicsPipeline = _resourceFactory.CreateGraphicsPipeline(pipelineDesc);
|
|
// }
|
|
|
|
// private void FillBuffers()
|
|
// {
|
|
// _graphicsDevice.UpdateBuffer(_vertexBuffer, 0, _quadVertices);
|
|
// _graphicsDevice.UpdateBuffer(_indexBuffer, 0, _quadIndices);
|
|
// }
|
|
// public override void Initialize(RendererSettings settings)
|
|
// {
|
|
// _settings = settings;
|
|
// _graphicsDevice = VeldridStartup.CreateGraphicsDevice(_window, new GraphicsDeviceOptions
|
|
// {
|
|
// PreferStandardClipSpaceYDirection = true,
|
|
// PreferDepthRangeZeroToOne = true
|
|
// });
|
|
|
|
// CreateResources();
|
|
// }
|
|
|
|
// public override int LoadTexture(Texture2d texture)
|
|
// {
|
|
// throw new NotImplementedException();
|
|
// }
|
|
|
|
// public override int LoadTexture(string path)
|
|
// {
|
|
// // throw new NotImplementedException();
|
|
|
|
// return -1;
|
|
// }
|
|
|
|
// public override void SetTargetFps(int fps)
|
|
// {
|
|
// _window.PollIntervalInMs = 1 / fps;
|
|
// }
|
|
|
|
// public override void SetTransform(Vector2 position)
|
|
// {
|
|
// // throw new NotImplementedException();
|
|
// }
|
|
|
|
// public override void SetWindowTitle(string title)
|
|
// {
|
|
// throw new NotImplementedException();
|
|
// }
|
|
|
|
// public override void SetWindowVSync(bool value)
|
|
// {
|
|
// throw new NotImplementedException();
|
|
// }
|
|
|
|
// public override bool WindowShouldClose()
|
|
// {
|
|
// _window.PumpEvents();
|
|
// return !_window.Exists;
|
|
// }
|
|
|
|
// private RgbaFloat SystemColorToRgbaFloat(System.Drawing.Color color)
|
|
// {
|
|
// return new RgbaFloat(color.R, color.G, color.B, color.A);
|
|
// }
|
|
|
|
// public override void SetTransform(Matrix4x4 transform)
|
|
// {
|
|
// _transform = transform;
|
|
// }
|
|
|
|
// // Transform
|
|
// private Matrix4x4 _transform;
|
|
|
|
// // TEMP: quad stuff.
|
|
// private readonly Vector2[] _quadVertices =
|
|
// {
|
|
// new Vector2(-0.5f, 0.5f),
|
|
// new Vector2(0.5f, 0.5f),
|
|
// new Vector2(-0.5f, -0.5f),
|
|
// new Vector2(0.5f, -0.5f)
|
|
// };
|
|
|
|
// private readonly ushort[] _quadIndices = { 0, 1, 2, 3 };
|
|
// private ColorRectShader _colorRectShader = new ColorRectShader();
|
|
|
|
// private Sdl2Window _window;
|
|
// private RendererSettings _settings;
|
|
// private GraphicsDevice _graphicsDevice;
|
|
|
|
// // Resources
|
|
// private ResourceFactory _resourceFactory;
|
|
// private CommandList _commandList;
|
|
// private Pipeline _graphicsPipeline;
|
|
// private Veldrid.Shader[] _shaders;
|
|
|
|
// // Quad resources
|
|
// private DeviceBuffer _vertexBuffer;
|
|
// private DeviceBuffer _indexBuffer;
|
|
// private DeviceBuffer _uniformBuffer;
|
|
// private ResourceSet _resourceSet;
|
|
// }
|
|
} |