//public void DrawIndexed(int indexCount, uint instanceCount, uint indexStart, int vertexOffset, uint instanceStart) //{ // Issue a Draw command for a single instance with 4 indices. //veldridCommandList.DrawIndexed(Convert.ToUInt32(indexCount), instanceCount, indexStart, vertexOffset, instanceStart); //} #endregion #region Internal API /// <summary> /// Initialises the GraphicsDevice /// </summary> /// <param name="graphicsAPI"></param> internal void Initialise(VesselWindow window, ApplicationConfig config) { GraphicsAPI = config.GraphicsAPI; GraphicsDeviceOptions options = new GraphicsDeviceOptions { PreferStandardClipSpaceYDirection = true, PreferDepthRangeZeroToOne = true, SyncToVerticalBlank = config.VSync, Debug = config.DebugMode, }; DefaultGraphicsAPI = (GraphicsAPI)VeldridStartup.GetPlatformDefaultBackend(); if (config.GraphicsAPI == GraphicsAPI.Default) { veldridGraphicsDevice = VeldridStartup.CreateGraphicsDevice(window.WindowInternal, options, (GraphicsBackend)DefaultGraphicsAPI); } else { veldridGraphicsDevice = VeldridStartup.CreateGraphicsDevice(window.WindowInternal, options, (GraphicsBackend)config.GraphicsAPI); } //Create the Graphics Resources ResourceFactory factory = veldridGraphicsDevice.ResourceFactory; //TODO: Replace with ResourceFactory.Load("ShaderTest0"); //shader = new ShaderTechnique(this, //System.IO.File.ReadAllBytes(@"E:\Data\Projects\Vessel\VesselSharp\VesselSharp\ShaderTests\ShaderTest0.vert.spv"), //System.IO.File.ReadAllBytes(@"E:\Data\Projects\Vessel\VesselSharp\VesselSharp\ShaderTests\ShaderTest0.frag.spv"), //"ShaderTest0"); // TODO: Move pipeline to Shader class // TODO: Shader => ShaderTechnique; ComputeShader // TODO: Assets can be compiled (i.e. banks) or directories (i.e. folder of compiled assets (eg shader.shd), assets aren't packaged into an archive though) - for use during dev cuz packaging archives will probably be time consuming as f**k and decimate workflows // Create pipeline /* * pipelineDescription = new GraphicsPipelineDescription(); * pipelineDescription.BlendState = BlendStateDescription.SingleOverrideBlend; * pipelineDescription.DepthStencilState = new DepthStencilStateDescription( * depthTestEnabled: true, * depthWriteEnabled: true, * comparisonKind: ComparisonKind.LessEqual); * * pipelineDescription.RasterizerState = new RasterizerStateDescription( * cullMode: FaceCullMode.Back, * fillMode: PolygonFillMode.Solid, * frontFace: FrontFace.Clockwise, * depthClipEnabled: true, * scissorTestEnabled: false); * * pipelineDescription.PrimitiveTopology = PrimitiveTopology.TriangleStrip; * pipelineDescription.ResourceLayouts = System.Array.Empty<ResourceLayout>(); * pipelineDescription.ShaderSet = new ShaderSetDescription( * vertexLayouts: new VertexLayoutDescription[] * { * VertexPositionColor.VertexLayout, * }, * shaders: shader.Programs); * pipelineDescription.Outputs = veldridGraphicsDevice.SwapchainFramebuffer.OutputDescription; * * veldridPipeline = factory.CreateGraphicsPipeline(pipelineDescription); */ veldridCommandList = factory.CreateCommandList(); }
/// <summary> /// Setups the engine and initialises the window /// </summary> internal void MainLoop() { VesselLogger.Logger.Info("Initialising Vessel..."); //Setup the window VesselWindow window; window = new VesselWindow(GraphicsDevice, config.Name, config.Width, config.Height); Window = window; // Initialise RenderDoc if (config.RenderDoc) { RenderDoc.Initialise(); } //Initialise the Graphics Device GraphicsDevice.Initialise(window, config); Window.Invalidate(); //Callback for the engine Initialise(); VesselLogger.Logger.Info($"Started Vessel using {GraphicsDevice.GraphicsAPI}!"); //Deltatime variables long previousFrameTicks = 0; Stopwatch sw = new Stopwatch(); sw.Start(); //Main Loop while (Window.Exists) { Window.ProcessEvents(); //Calculate delta-time long currentFrameTicks = sw.ElapsedTicks; double deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; //Wait till next frame if we are locking the target framerate while (LimitFrameRate && deltaSeconds < TargetFrameTime) { currentFrameTicks = sw.ElapsedTicks; deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; } DeltaTime = (float)deltaSeconds; previousFrameTicks = currentFrameTicks; //Update method Update(); //Only Draw if the window is still open if (!Window.Exists) { break; } GraphicsDevice.OnFrameBegin(); // Draw the scene GraphicsDevice.Debug.PushGroup("Draw Scene"); Draw(); GraphicsDevice.Debug.PopGroup(); // Draw layers + post processing GraphicsDevice.Debug.PushGroup("Draw Layers"); RenderLayers.Draw(); GraphicsDevice.Debug.PopGroup(); GraphicsDevice.OnFrameEnd(); } // Cleanup VesselLogger.Logger.Info("Shutting down Vessel..."); Exiting(); }