Ejemplo n.º 1
0
        public void Render(CommandList cl, IDrawStageModel stage, GpuSurface surface, ICameraModel2D camera)
        {
            if (cl == null || stage == null || surface == null || camera == null)
            {
                _frameworkMessenger.Report("Warning: you are feeding DrawStage Renderer null inputs, aborting");
                return;
            }

            cl.SetFramebuffer(surface.Framebuffer);
            _viewportManager.ConfigureViewportForActiveFramebuffer(cl);
            cl.SetVertexBuffer(0, stage.Buffers.VertexBuffer);
            cl.SetIndexBuffer(stage.Buffers.IndexBuffer, IndexFormat.UInt32); //Extract format and type
            cl.SetPipeline(_pipelineFactory.ReturnDrawingPipeline(stage.BlendState));
            cl.SetGraphicsResourceSet(0, camera.ResourceSet);

            //When drawing commands are queued need to check and ensure the same texture is not used for both tex inputs
            //We also need to trigger the sort somewhere earlier than this and ensure if already sorted into batches dont do it
            var batcher = stage.Batcher;

            for (var b = 0; b < batcher.NumberOfBatches; b++)
            {
                var batch = batcher.Pool[b];

                ResourceSet t0;
                if (batch.Texture0 == 0UL)
                {
                    t0 = _surfaceManager.SingleWhitePixel.ResourceSet_TexWrap;
                }
                else
                {
                    var retrieved = _surfaceManager.RetrieveSurface(batch.Texture0, new GpuSurfaceType[] { GpuSurfaceType.SwapChainOutput, GpuSurfaceType.Internal });

                    if (retrieved == surface)
                    {
                        _frameworkMessenger.Report("Warning: A draw stage is attempting to draw a surface onto itself. Aborting");
                        return;
                    }

                    t0 = retrieved == null ? _surfaceManager.SingleWhitePixel.ResourceSet_TexWrap :
                         batch.TextureMode0 == TextureCoordinateMode.Mirror ?
                         retrieved.ResourceSet_TexMirror : retrieved.ResourceSet_TexWrap;
                }
                cl.SetGraphicsResourceSet(1, t0);

                ResourceSet t1;
                if (batch.Texture1 == 0UL)
                {
                    t1 = _surfaceManager.SingleWhitePixel.ResourceSet_TexWrap;
                }
                else
                {
                    var retrieved = _surfaceManager.RetrieveSurface(batch.Texture1, new GpuSurfaceType[] { GpuSurfaceType.SwapChainOutput, GpuSurfaceType.Internal });

                    t1 = retrieved == null ? _surfaceManager.SingleWhitePixel.ResourceSet_TexWrap :
                         batch.TextureMode1 == TextureCoordinateMode.Mirror ?
                         retrieved.ResourceSet_TexMirror : retrieved.ResourceSet_TexWrap;

                    if (retrieved == surface)
                    {
                        _frameworkMessenger.Report("Warning: A draw stage is attempting to draw a surface onto itself. Aborting");
                        return;
                    }
                }
                cl.SetGraphicsResourceSet(2, t1);

                cl.DrawIndexed((uint)batch.NumIndices, 1, (uint)batch.StartIndex, 0, 0);
            }
        }