private void OnPostRender(GPUContext context, RenderContext renderContext) { if (renderContext.View.Mode != ViewMode.Default) { var task = renderContext.Task; // Render editor primitives, gizmo and debug shapes in debug view modes // Note: can use Output buffer as both input and output because EditorPrimitives is using a intermediate buffers if (EditorPrimitives && EditorPrimitives.CanRender) { EditorPrimitives.Render(context, ref renderContext, task.Output, task.Output); } // Render editor sprites if (_spritesRenderer && _spritesRenderer.CanRender) { _spritesRenderer.Render(context, ref renderContext, task.Output, task.Output); } // Render selection outline if (SelectionOutline && SelectionOutline.CanRender) { // Use temporary intermediate buffer var desc = task.Output.Description; var temp = RenderTargetPool.Get(ref desc); SelectionOutline.Render(context, ref renderContext, task.Output, temp); // Copy the results back to the output context.CopyTexture(task.Output, 0, 0, 0, 0, temp, 0); RenderTargetPool.Release(temp); } } }
private void OnPostRender(GPUContext context, RenderContext renderContext) { if (renderContext.View.Mode != ViewMode.Default) { var task = renderContext.Task; // Render editor sprites if (_spritesRenderer && _spritesRenderer.CanRender) { _spritesRenderer.Render(context, ref renderContext, task.Output, task.Output); } // Render selection outline if (SelectionOutline && SelectionOutline.CanRender) { // Use temporary intermediate buffer var desc = task.Output.Description; var temp = RenderTargetPool.Get(ref desc); SelectionOutline.Render(context, ref renderContext, task.Output, temp); // Copy the results back to the output context.CopyTexture(task.Output, 0, 0, 0, 0, temp, 0); RenderTargetPool.Release(temp); } } }
public override void RenderFrame(GPUContext context, ref StagingTexture frame, RenderOptions options, GPUTexture output) { // Copy texture back to the staging texture context.CopyTexture(frame.Texture, 0, 0, 0, 0, output, 0); }
private void OnEnd(RenderTask task, GPUContext context) { // Pick the atlas or create a new one int atlasIndex = -1; for (int i = 0; i < _atlases.Count; i++) { if (!_atlases[i].IsFull) { atlasIndex = i; break; } } if (atlasIndex == -1) { // Setup configuration var atlasSize = 1024; var atlasFormat = PixelFormat.R8G8B8A8_UNorm; var width = (float)Width; var height = (float)Height; var countX = Mathf.FloorToInt(atlasSize / width); var countY = Mathf.FloorToInt(atlasSize / height); var count = countX * countY; // Create sprite atlas texture var spriteAtlas = FlaxEngine.Content.CreateVirtualAsset <SpriteAtlas>(); var data = new byte[atlasSize * atlasSize * PixelFormatExtensions.SizeInBytes(atlasFormat)]; var initData = new TextureBase.InitData { Width = atlasSize, Height = atlasSize, ArraySize = 1, Format = atlasFormat, Mips = new[] { new TextureBase.InitData.MipData { Data = data, RowPitch = data.Length / atlasSize, SlicePitch = data.Length }, }, }; spriteAtlas.Init(ref initData); // Setup sprite atlas slots (each per thumbnail) var thumbnailSizeUV = new Vector2(width / atlasSize, height / atlasSize); for (int i = 0; i < count; i++) { var x = i % countX; var y = i / countX; var s = new Sprite { Name = string.Empty, Area = new Rectangle(new Vector2(x, y) * thumbnailSizeUV, thumbnailSizeUV), }; spriteAtlas.AddSprite(s); } // Add atlas to the cached ones atlasIndex = _atlases.Count; _atlases.Add(new Atlas { Texture = spriteAtlas, SlotsUsage = new BitArray(count, false), Count = 0, }); } // Skip ending if the atlas is not loaded yet (streaming backend uploads texture to GPU or sth) var atlas = _atlases[atlasIndex]; if (atlas.Texture.ResidentMipLevels == 0) { return; } // Pick the sprite slot from the atlas var spriteIndex = -1; for (int i = 0; i < atlas.SlotsUsage.Count; i++) { if (atlas.SlotsUsage[i] == false) { atlas.SlotsUsage[i] = true; spriteIndex = i; break; } } if (spriteIndex == -1) { throw new FlaxException(); } atlas.Count++; _atlases[atlasIndex] = atlas; var sprite = new SpriteHandle(atlas.Texture, spriteIndex); // Copy output frame to the sprite atlas slot var spriteLocation = sprite.Location; context.CopyTexture(atlas.Texture.Texture, 0, (uint)spriteLocation.X, (uint)spriteLocation.Y, 0, _output, 0); // Link sprite to the UI var req = _queue[0]; req.Media.OnThumbnailRenderingEnd((SceneRenderTask)task, context, ref req, ref sprite); // End _queue.RemoveAt(0); task.Enabled = false; }