public void PrepareTexture(ITexture texture, IRendererContext context) { var veldridTexture = (IVeldridTexture)texture; var gd = ((VeldridRendererContext)context).GraphicsDevice; lock (_syncRoot) { if (_cache.ContainsKey(texture)) { if (!texture.IsDirty) { return; } _cache[texture].Dispose(); } } var deviceTexture = veldridTexture.CreateDeviceTexture(gd, gd.ResourceFactory, TextureUsage.Sampled); var textureView = gd.ResourceFactory.CreateTextureView(deviceTexture); textureView.Name = "TV_" + texture.Name; CoreTrace.Log.CreatedDeviceTexture(textureView.Name, texture.Width, texture.Height, texture.ArrayLayers); lock (_syncRoot) { _cache[texture] = new CacheEntry(deviceTexture, textureView); } }
public IEnumerable <IRenderable> UpdatePerFrameResources(IRendererContext context, IEnumerable <IRenderable> renderables) { var c = (VeldridRendererContext)context; var gd = c.GraphicsDevice; if (!(renderables.FirstOrDefault() is SkyboxRenderable skybox)) { yield break; } ITextureManager textureManager = Resolve <ITextureManager>(); IDeviceObjectManager objectManager = Resolve <IDeviceObjectManager>(); textureManager?.PrepareTexture(skybox.Texture, context); TextureView textureView = (TextureView)textureManager?.GetTexture(skybox.Texture); var resourceSet = objectManager.Get <ResourceSet>((skybox, textureView)); if (resourceSet == null) { resourceSet = gd.ResourceFactory.CreateResourceSet(new ResourceSetDescription( _resourceLayout, gd.PointSampler, textureView, _uniformBuffer)); resourceSet.Name = $"RS_Sky:{skybox.Texture.Name}"; PerfTracker.IncrementFrameCounter("Create ResourceSet"); objectManager.Set((skybox, textureView), resourceSet); } yield return(skybox); }
public void Render(IRendererContext context, RenderPasses renderPass, IRenderable renderable) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (renderable == null) { throw new ArgumentNullException(nameof(renderable)); } var c = (VeldridRendererContext)context; var cl = c.CommandList; var dom = Resolve <IDeviceObjectManager>(); var overlay = (InfoOverlay)renderable; cl.PushDebugGroup(overlay.Name); var resourceSet = dom.GetDeviceObject <ResourceSet>((overlay, overlay, "ResourceSet")); cl.SetPipeline(_pipeline); cl.SetGraphicsResourceSet(0, resourceSet); cl.SetGraphicsResourceSet(1, c.SceneContext.CommonResourceSet); cl.SetVertexBuffer(0, _vertexBuffer); cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16); cl.DrawIndexed((uint)Indices.Length); cl.PopDebugGroup(); }
public void CreateDeviceObjects(IRendererContext context) { var c = (VeldridRendererContext)context; var cl = c.CommandList; var gd = c.GraphicsDevice; var sc = c.SceneContext; ResourceFactory factory = gd.ResourceFactory; _vb = factory.CreateBuffer(new BufferDescription(Vertices.SizeInBytes(), BufferUsage.VertexBuffer)); _ib = factory.CreateBuffer(new BufferDescription(Indices.SizeInBytes(), BufferUsage.IndexBuffer)); _miscUniformBuffer = factory.CreateBuffer(new BufferDescription(MiscUniformData.SizeInBytes, BufferUsage.UniformBuffer)); _vb.Name = "TileMapVertexBuffer"; _ib.Name = "TileMapIndexBuffer"; _miscUniformBuffer.Name = "TileMapMiscBuffer"; cl.UpdateBuffer(_vb, 0, Vertices); cl.UpdateBuffer(_ib, 0, Indices); var shaderCache = Resolve <IShaderCache>(); _shaders = shaderCache.GetShaderPair(gd.ResourceFactory, VertexShaderName, FragmentShaderName, shaderCache.GetGlsl(VertexShaderName), shaderCache.GetGlsl(FragmentShaderName)); var shaderSet = new ShaderSetDescription(new[] { VertexLayout, InstanceLayout }, _shaders); _layout = factory.CreateResourceLayout(PerSpriteLayoutDescription); _textureSampler = gd.ResourceFactory.CreateSampler(new SamplerDescription( SamplerAddressMode.Clamp, SamplerAddressMode.Clamp, SamplerAddressMode.Clamp, SamplerFilter.MinPoint_MagPoint_MipPoint, null, 1, 0, 0, 0, SamplerBorderColor.TransparentBlack )); var depthStencilMode = gd.IsDepthRangeZeroToOne ? DepthStencilStateDescription.DepthOnlyLessEqual : DepthStencilStateDescription.DepthOnlyGreaterEqual; var rasterizerMode = new RasterizerStateDescription( FaceCullMode.Front, PolygonFillMode.Solid, FrontFace.Clockwise, true, true); var pd = new GraphicsPipelineDescription( BlendStateDescription.SingleAlphaBlend, depthStencilMode, rasterizerMode, PrimitiveTopology.TriangleList, new ShaderSetDescription(new[] { VertexLayout, InstanceLayout }, shaderSet.Shaders, ShaderHelper.GetSpecializations(gd)), new[] { _layout, sc.CommonResourceLayout }, sc.MainSceneFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); _pipeline.Name = "P_TileMapRenderer"; _disposeCollector.Add(_vb, _ib, _layout, _textureSampler, _pipeline); }
public void Render(IRendererContext context, RenderPasses renderPass, IRenderable renderable) { var c = (VeldridRendererContext)context; var cl = c.CommandList; var sc = c.SceneContext; ITextureManager textureManager = Resolve <ITextureManager>(); IDeviceObjectManager dom = Resolve <IDeviceObjectManager>(); EngineFlags engineFlags = Resolve <IEngineSettings>().Flags; // float depth = gd.IsDepthRangeZeroToOne ? 0 : 1; var sprite = (MultiSprite)renderable; var shaderKey = new SpriteShaderKey(sprite, engineFlags); sprite.PipelineId = shaderKey.GetHashCode(); //if (!shaderKey.UseArrayTexture) // return; cl.PushDebugGroup(sprite.Name); if (sc.PaletteView == null) { return; } TextureView textureView = (TextureView)textureManager?.GetTexture(sprite.Key.Texture); var resourceSet = dom.Get <ResourceSet>((sprite, textureView)); var instanceBuffer = dom.Get <DeviceBuffer>((sprite, sprite)); var uniformInfo = new SpriteUniformInfo { Flags = sprite.Key.Flags, TextureWidth = textureView?.Target.Width ?? 1, TextureHeight = textureView?.Target.Height ?? 1 }; if (sprite.Key.ScissorRegion.HasValue) { IWindowManager wm = Resolve <IWindowManager>(); var screenCoordinates = wm.UiToPixel(sprite.Key.ScissorRegion.Value); cl.SetScissorRect(0, (uint)screenCoordinates.X, (uint)screenCoordinates.Y, (uint)screenCoordinates.Width, (uint)screenCoordinates.Height); } cl.UpdateBuffer(_uniformBuffer, 0, uniformInfo); cl.SetPipeline(_pipelines[shaderKey]); cl.SetGraphicsResourceSet(0, resourceSet); cl.SetGraphicsResourceSet(1, sc.CommonResourceSet); cl.SetVertexBuffer(0, _vertexBuffer); cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16); cl.SetVertexBuffer(1, instanceBuffer); //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, depth, depth)); cl.DrawIndexed((uint)Indices.Length, (uint)sprite.ActiveInstances, 0, 0, 0); //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, 0, 1)); if (sprite.Key.ScissorRegion.HasValue) { cl.SetFullScissorRect(0); } cl.PopDebugGroup(); }
public IDisposable CreateRenderDebugGroup(IRendererContext context, string name) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return(new RenderDebugGroup(((VeldridRendererContext)context).CommandList, name)); }
public void Render(IRendererContext context, RenderPasses renderPass, IRenderable r) { var c = (VeldridRendererContext)context; ApiUtil.Assert(renderPass == RenderPasses.Standard); _imguiRenderer.Render(c.GraphicsDevice, c.CommandList); c.CommandList.SetFullScissorRects(); }
protected override Size OnMeasure(Size size, IRendererContext context) { var panelSize = Margin.GetAbsoluteSize() + Padding.GetAbsoluteSize() + Border.AsSpacer().GetAbsoluteSize(); Inner?.Measure((size - panelSize).Union(Size.Empty), context); return((Inner?.DesiredSize ?? Size.Empty) + panelSize); }
public void Render(IRendererContext context, RenderPasses renderPass, IRenderable renderable) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (renderable == null) { throw new ArgumentNullException(nameof(renderable)); } var c = (VeldridRendererContext)context; var cl = c.CommandList; var dom = Resolve <IDeviceObjectManager>(); var engineFlags = Resolve <IEngineSettings>().Flags; var textureManager = Resolve <ITextureManager>(); var sprite = (MultiSprite)renderable; var shaderKey = new SpriteShaderKey(sprite, engineFlags); sprite.PipelineId = shaderKey.GetHashCode(); //if (!shaderKey.UseArrayTexture) // return; cl.PushDebugGroup(sprite.Name); if (c.SceneContext.PaletteView == null) { return; } TextureView textureView = (TextureView)textureManager?.GetTexture(sprite.Key.Texture); var resourceSet = dom.GetDeviceObject <ResourceSet>((sprite, textureView, "ResourceSet")); var instanceBuffer = dom.GetDeviceObject <DeviceBuffer>((sprite, sprite, "InstanceBuffer")); if (sprite.Key.ScissorRegion.HasValue) { IWindowManager wm = Resolve <IWindowManager>(); var screenCoordinates = wm.UiToPixel(sprite.Key.ScissorRegion.Value); cl.SetScissorRect(0, (uint)screenCoordinates.X, (uint)screenCoordinates.Y, (uint)screenCoordinates.Width, (uint)screenCoordinates.Height); } cl.SetPipeline(_pipelines[shaderKey]); cl.SetGraphicsResourceSet(0, resourceSet); cl.SetGraphicsResourceSet(1, c.SceneContext.CommonResourceSet); cl.SetVertexBuffer(0, _vertexBuffer); cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16); cl.SetVertexBuffer(1, instanceBuffer); cl.DrawIndexed((uint)Indices.Length, (uint)sprite.ActiveInstances, 0, 0, 0); if (sprite.Key.ScissorRegion.HasValue) { cl.SetFullScissorRect(0); } cl.PopDebugGroup(); }
private static IEnumerable <TextBlockMeasure> ToBlockMeasure(IRendererContext context, IEnumerable <TextBlock> textBlocks) { foreach (var block in textBlocks.SelectMany(b => b.Normalize())) { var text = block.Text; var size = context.MeasureText(text, block.Metadata.Font); var space = block.IsLineBreak ? 0f : context.GetSpaceWidth(block.Metadata.Font); yield return(new TextBlockMeasure(block, size, space)); } }
public void CreateDeviceObjects(IRendererContext context) { var c = (VeldridRendererContext)context; var cl = c.CommandList; var gd = c.GraphicsDevice; var sc = c.SceneContext; DisposeCollectorResourceFactory factory = new DisposeCollectorResourceFactory(gd.ResourceFactory); _disposeCollector = factory.DisposeCollector; ResourceLayout resourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment))); var shaderCache = Resolve <IShaderCache>(); _shaders = shaderCache.GetShaderPair(gd.ResourceFactory, VertexShaderName, FragmentShaderName, shaderCache.GetGlsl(VertexShaderName), shaderCache.GetGlsl(FragmentShaderName)); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( new BlendStateDescription( RgbaFloat.Black, BlendAttachmentDescription.OverrideBlend, BlendAttachmentDescription.OverrideBlend), gd.IsDepthRangeZeroToOne ? DepthStencilStateDescription.DepthOnlyGreaterEqual : DepthStencilStateDescription.DepthOnlyLessEqual, RasterizerStateDescription.Default, PrimitiveTopology.TriangleList, new ShaderSetDescription( new[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("TexCoords", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2)) }, _shaders, ShaderHelper.GetSpecializations(gd)), new[] { resourceLayout }, sc.DuplicatorFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); _pipeline.Name = "P_ScreenDuplicator"; float[] verts = CoreUtil.GetFullScreenQuadVerts(gd.IsClipSpaceYInverted); _vb = factory.CreateBuffer(new BufferDescription(verts.SizeInBytes() * sizeof(float), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, verts); _ib = factory.CreateBuffer( new BufferDescription((uint)QuadIndices.Length * sizeof(ushort), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, QuadIndices); }
public void Render(IRendererContext context, RenderPasses renderPass, IRenderable renderable) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (renderable == null) { throw new ArgumentNullException(nameof(renderable)); } var c = (VeldridRendererContext)context; var cl = c.CommandList; var gd = c.GraphicsDevice; var sc = c.SceneContext; ITextureManager textureManager = Resolve <ITextureManager>(); if (!(renderable is TileMapWindow window)) { return; } var tilemap = window.TileMap; cl.PushDebugGroup($"Tiles3D:{tilemap.Name}:{tilemap.RenderOrder}"); TextureView floors = (TextureView)textureManager.GetTexture(tilemap.Floors); TextureView walls = (TextureView)textureManager.GetTexture(tilemap.Walls); var miscUniformData = new MiscUniformData { TileSize = tilemap.TileSize, Unused1 = 0 }; cl.UpdateBuffer(_miscUniformBuffer, 0, miscUniformData); var resourceSet = gd.ResourceFactory.CreateResourceSet(new ResourceSetDescription(_layout, _miscUniformBuffer, gd.PointSampler, _textureSampler, floors, walls)); resourceSet.Name = $"RS_TileMap:{tilemap.Name}"; _resourceSets.Add(resourceSet); cl.SetPipeline(_pipeline); cl.SetGraphicsResourceSet(0, resourceSet); cl.SetGraphicsResourceSet(1, sc.CommonResourceSet); cl.SetVertexBuffer(0, _vb); cl.SetVertexBuffer(1, _instanceBuffers[window.InstanceBufferId]); cl.SetIndexBuffer(_ib, IndexFormat.UInt16); cl.DrawIndexed((uint)Indices.Length, (uint)window.Length, 0, 0, 0); cl.PopDebugGroup(); }
protected override Size OnMeasure(Size size, IRendererContext context) { if (Inner == null) { return(Size.Empty); } var marginSize = ClipMargin.GetAbsoluteSize(); Inner.Measure(size.Add(marginSize), context); return(Inner.DesiredSize.Subtract(marginSize)); }
public void Render(IRendererContext context, RenderPasses renderPass, IRenderable r) { var c = (VeldridRendererContext)context; var cl = c.CommandList; var sc = c.SceneContext; cl.SetPipeline(_pipeline); cl.SetGraphicsResourceSet(0, sc.DuplicatorTargetSet0); cl.SetVertexBuffer(0, _vb); cl.SetIndexBuffer(_ib, IndexFormat.UInt16); cl.DrawIndexed(6, 1, 0, 0, 0); }
public void Render(IRendererContext context, RenderPasses renderPass, IRenderable renderable) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (renderable == null) { throw new ArgumentNullException(nameof(renderable)); } var c = (VeldridRendererContext)context; var cl = c.CommandList; var sc = c.SceneContext; ITextureManager textureManager = Resolve <ITextureManager>(); IDeviceObjectManager dom = Resolve <IDeviceObjectManager>(); var config = Resolve <CoreConfig>().Visual.Skybox; if (!(Resolve <ICamera>() is PerspectiveCamera camera)) { return; } var skybox = (SkyboxRenderable)renderable; cl.PushDebugGroup(skybox.Name); var uniformInfo = new SkyboxUniformInfo { uYaw = camera.Yaw, uPitch = camera.Pitch, uVisibleProportion = config.VisibleProportion }; cl.UpdateBuffer(_uniformBuffer, 0, uniformInfo); if (sc.PaletteView == null) { return; } TextureView textureView = (TextureView)textureManager?.GetTexture(skybox.Texture); var resourceSet = dom.GetDeviceObject <ResourceSet>((skybox, textureView, null)); cl.SetPipeline(_pipeline); cl.SetGraphicsResourceSet(0, resourceSet); cl.SetGraphicsResourceSet(1, sc.CommonResourceSet); cl.SetVertexBuffer(0, _vertexBuffer); cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16); cl.DrawIndexed((uint)Indices.Length, 1, 0, 0, 0); cl.PopDebugGroup(); }
protected override Size OnMeasure(Size size, IRendererContext context) { var result = Size.Empty; foreach (var component in GetChildren()) { component.Measure(size, context); result.Width = Math.Max(result.Width, component.DesiredSize.Width); result.Height = Math.Max(result.Height, component.DesiredSize.Height); } return(result); }
public IEnumerable <IRenderable> UpdatePerFrameResources(IRendererContext context, IEnumerable <IRenderable> renderables) { var c = (VeldridRendererContext)context; var cl = c.CommandList; var gd = c.GraphicsDevice; ITextureManager textureManager = Resolve <ITextureManager>(); foreach (var buffer in _instanceBuffers) { buffer.Dispose(); } _instanceBuffers.Clear(); foreach (var resourceSet in _resourceSets) { resourceSet.Dispose(); } _resourceSets.Clear(); void UpdateTilemapWindow(TileMapWindow window) { var tilemap = window.TileMap; window.InstanceBufferId = _instanceBuffers.Count; var buffer = gd.ResourceFactory.CreateBuffer(new BufferDescription((uint)window.Length * TileMap.Tile.StructSize, BufferUsage.VertexBuffer)); buffer.Name = $"B_Tile3DInst{_instanceBuffers.Count}"; cl.UpdateBuffer(buffer, 0, ref tilemap.Tiles[window.Offset], TileMap.Tile.StructSize * (uint)window.Length); _instanceBuffers.Add(buffer); textureManager.PrepareTexture(tilemap.Floors, context); textureManager.PrepareTexture(tilemap.Walls, context); } foreach (var renderable in renderables) { if (renderable is TileMap tilemap) { var dummyWindow = new TileMapWindow(tilemap, 0, tilemap.Tiles.Length); UpdateTilemapWindow(dummyWindow); yield return(dummyWindow); } else if (renderable is TileMapWindow window) { UpdateTilemapWindow(window); yield return(window); } } }
public void CreateDeviceObjects(IRendererContext context) { var c = (VeldridRendererContext)context; if (_imguiRenderer == null) { var window = Resolve <IWindowManager>(); _imguiRenderer = new ImGuiRenderer(c.GraphicsDevice, c.SceneContext.MainSceneFramebuffer.OutputDescription, window.PixelWidth, window.PixelHeight, ColorSpaceHandling.Linear); } else { _imguiRenderer.CreateDeviceResources(c.GraphicsDevice, c.SceneContext.MainSceneFramebuffer.OutputDescription, ColorSpaceHandling.Linear); } }
public void UpdatePerFrameResources(IRendererContext context, IEnumerable <IRenderable> renderables, IList <IRenderable> results) { if (renderables == null) { throw new ArgumentNullException(nameof(renderables)); } if (results == null) { throw new ArgumentNullException(nameof(results)); } foreach (var r in renderables) { results.Add(r); } }
public void Render(IRendererContext context, RenderPasses renderPass, IRenderable r) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (r == null) { throw new ArgumentNullException(nameof(r)); } var c = (VeldridRendererContext)context; ApiUtil.Assert(renderPass == RenderPasses.Standard); _imguiRenderer.Render(c.GraphicsDevice, c.CommandList); c.CommandList.SetFullScissorRects(); }
public void CreateDeviceObjects(IRendererContext context) { var c = (VeldridRendererContext)context; var cl = c.CommandList; var gd = c.GraphicsDevice; var factory = new DisposeCollectorResourceFactory(gd.ResourceFactory); _disposeCollector = factory.DisposeCollector; var layout = factory.CreateResourceLayout(new ResourceLayoutDescription( ResourceLayoutHelper.Texture("SourceTexture"), ResourceLayoutHelper.Sampler("SourceSampler"))); var shaderCache = Resolve <IShaderCache>(); _shaders = shaderCache.GetShaderPair(gd.ResourceFactory, VertexShaderName, FragmentShaderName, shaderCache.GetGlsl(VertexShaderName), shaderCache.GetGlsl(FragmentShaderName)); var rasterizerState = new RasterizerStateDescription( FaceCullMode.Back, PolygonFillMode.Solid, FrontFace.Clockwise, true, false); var pd = new GraphicsPipelineDescription( new BlendStateDescription(RgbaFloat.Black, BlendAttachmentDescription.OverrideBlend), DepthStencilStateDescription.Disabled, rasterizerState, PrimitiveTopology.TriangleList, new ShaderSetDescription(new[] { VertexLayoutHelper.Vertex2DTextured }, _shaders, ShaderHelper.GetSpecializations(gd)), new[] { layout }, gd.SwapchainFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); _pipeline.Name = "P_FullScreenQuad"; float[] verts = CoreUtil.GetFullScreenQuadVerts(gd.IsClipSpaceYInverted); _vb = factory.CreateBuffer(new BufferDescription(verts.SizeInBytes() * sizeof(float), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, verts); _ib = factory.CreateBuffer(new BufferDescription(QuadIndices.SizeInBytes(), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, QuadIndices); }
public void CreateDeviceObjects(IRendererContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var c = (VeldridRendererContext)context; if (_imguiRenderer == null) { var window = Resolve <IWindowManager>(); _imguiRenderer = new ImGuiRenderer(c.GraphicsDevice, c.GraphicsDevice.SwapchainFramebuffer.OutputDescription, window.PixelWidth, window.PixelHeight, ColorSpaceHandling.Linear); } else { _imguiRenderer.CreateDeviceResources(c.GraphicsDevice, c.GraphicsDevice.SwapchainFramebuffer.OutputDescription, ColorSpaceHandling.Linear); } }
public void CreateDeviceObjects(IRendererContext context) { var c = (VeldridRendererContext)context; ResourceFactory factory = c.GraphicsDevice.ResourceFactory; _vertexBuffer = factory.CreateBuffer(new BufferDescription(Vertices.SizeInBytes(), BufferUsage.VertexBuffer)); _indexBuffer = factory.CreateBuffer(new BufferDescription(Indices.SizeInBytes(), BufferUsage.IndexBuffer)); _uniformBuffer = factory.CreateBuffer(new BufferDescription((uint)Unsafe.SizeOf <SkyboxUniformInfo>(), BufferUsage.UniformBuffer)); _vertexBuffer.Name = "SpriteVertexBuffer"; _indexBuffer.Name = "SpriteIndexBuffer"; _uniformBuffer.Name = "SpriteUniformBuffer"; c.CommandList.UpdateBuffer(_vertexBuffer, 0, Vertices); c.CommandList.UpdateBuffer(_indexBuffer, 0, Indices); _resourceLayout = factory.CreateResourceLayout(ResourceLayoutDescription); _disposeCollector.Add(_vertexBuffer, _indexBuffer, _uniformBuffer, _resourceLayout); _pipeline = BuildPipeline(c.GraphicsDevice, c.SceneContext); }
protected override Size OnMeasure(Size size, IRendererContext context) { var result = Size.Empty; foreach (var child in GetChildren()) { child.Measure(size, context); var desiredSize = child.DesiredSize; result.Width += desiredSize.Width; result.Height = Math.Max(result.Height, desiredSize.Height); size.Width -= desiredSize.Width; if (size.Width < 0) { size.Width = 0; } } return(result); }
public TextMeasure Measure(IRendererContext context, int maxWidth, IEnumerable <TextBlock> blocks) { var results = new List <TextLineMeasure>(); var line = new List <TextBlockMeasure>(); float max = 0; float totalLength = 0; foreach (var area in ToBlockMeasure(context, blocks)) { var space = line.Any() ? area.SpacePadding : 0; if (area.Block.IsLineBreak || (totalLength + space + area.Measure.Width > maxWidth && totalLength > 0)) { max = Math.Max(max, totalLength); var size = new SizeF(totalLength, GetHeight(line, area)); results.Add(new TextLineMeasure(size, line)); totalLength = 0; space = 0; line = new List <TextBlockMeasure>(); } if (!area.Block.IsLineBreak) { line.Add(area); totalLength += area.Measure.Width + space; } } if (line.Any()) { max = Math.Max(max, totalLength); var size = new SizeF(totalLength, GetHeight(line, line[0])); results.Add(new TextLineMeasure(size, line)); } var measureWidth = (int)Math.Ceiling(max); var measureHeight = (int)Math.Ceiling(results.Aggregate(0f, (c, x) => c + x.Measure.Height)); return(new TextMeasure(new Size(measureWidth, measureHeight), results)); }
public void CreateDeviceObjects(IRendererContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var c = (VeldridRendererContext)context; var cl = c.CommandList; var gd = c.GraphicsDevice; var factory = gd.ResourceFactory; _vertexBuffer = factory.CreateBuffer(new BufferDescription(Vertices.SizeInBytes(), BufferUsage.VertexBuffer)); _indexBuffer = factory.CreateBuffer(new BufferDescription(Indices.SizeInBytes(), BufferUsage.IndexBuffer)); _vertexBuffer.Name = "SpriteVertexBuffer"; _indexBuffer.Name = "SpriteIndexBuffer"; cl.UpdateBuffer(_vertexBuffer, 0, Vertices); cl.UpdateBuffer(_indexBuffer, 0, Indices); _perSpriteResourceLayout = factory.CreateResourceLayout(PerSpriteLayoutDescription); _disposeCollector.Add(_vertexBuffer, _indexBuffer, _perSpriteResourceLayout); }
public IEnumerable <IRenderable> UpdatePerFrameResources(IRendererContext context, IEnumerable <IRenderable> renderables) => renderables;
public static String RenderCanonicalElfAsPublicText(this String canonical, IRendererContext ctx) { var script = (Script)new ElfAstBuilder(canonical).BuildAstAllowLoopholes(); return script.RenderPublicText(ctx); }
public static String RenderLightElfAsPublicText(this String light, IRendererContext ctx) { return RenderCanonicalElfAsPublicText(light.ToCanonicalElf(), ctx); }
public static String RenderPublicText(this Script script, IRendererContext ctx) { var body = script.Classes.Single().Funcs.Single().Body; var lines = body.Children.Cast<ExpressionStatement>().Select(es => es.Expression).ToArray(); ; return lines.Select(l => l.RenderPublicText(ctx)).StringJoin(Environment.NewLine); }
public static String RenderPublicText(this Expression target, IRendererContext ctx) { return ctx.CreateRenderer(target).RenderPublicText(); }
public IEnumerable <IRenderable> UpdatePerFrameResources(IRendererContext context, IEnumerable <IRenderable> renderables) { var c = (VeldridRendererContext)context; var cl = c.CommandList; var gd = c.GraphicsDevice; var sc = c.SceneContext; ITextureManager textureManager = Resolve <ITextureManager>(); IDeviceObjectManager objectManager = Resolve <IDeviceObjectManager>(); EngineFlags engineFlags = Resolve <IEngineSettings>().Flags; foreach (var renderable in renderables) { var sprite = (MultiSprite)renderable; if (sprite.ActiveInstances == 0) { continue; } var shaderKey = new SpriteShaderKey(sprite, engineFlags); if (!_pipelines.ContainsKey(shaderKey)) { _pipelines.Add(shaderKey, BuildPipeline(gd, sc, shaderKey)); } uint bufferSize = (uint)sprite.Instances.Length * SpriteInstanceData.StructSize; var buffer = objectManager.Get <DeviceBuffer>((sprite, sprite)); if (buffer?.SizeInBytes != bufferSize) { buffer = gd.ResourceFactory.CreateBuffer(new BufferDescription(bufferSize, BufferUsage.VertexBuffer)); buffer.Name = $"B_SpriteInst:{sprite.Name}"; PerfTracker.IncrementFrameCounter("Create InstanceBuffer"); objectManager.Set((sprite, sprite), buffer); } if (sprite.InstancesDirty) { cl.UpdateBuffer(buffer, 0, sprite.Instances); PerfTracker.IncrementFrameCounter("Update InstanceBuffers"); } textureManager?.PrepareTexture(sprite.Key.Texture, context); TextureView textureView = (TextureView)textureManager?.GetTexture(sprite.Key.Texture); var resourceSet = objectManager.Get <ResourceSet>((sprite, textureView)); if (resourceSet == null) { resourceSet = gd.ResourceFactory.CreateResourceSet(new ResourceSetDescription( _perSpriteResourceLayout, gd.PointSampler, textureView, _uniformBuffer)); resourceSet.Name = $"RS_Sprite:{sprite.Key.Texture.Name}"; PerfTracker.IncrementFrameCounter("Create ResourceSet"); objectManager.Set((sprite, textureView), resourceSet); } sprite.InstancesDirty = false; yield return(sprite); } Resolve <ISpriteManager>().Cleanup(); }
protected override Size OnMeasure(Size size, IRendererContext context) => _desiredSize;
protected override Size OnMeasure(Size size, IRendererContext context) => OnMeasureCallback(size);