protected override void CollectCore(RenderContext context) { base.CollectCore(context); using (context.PushTagAndRestore(CameraComponentRendererExtensions.Current, Camera)) { var oldRenderView = context.RenderView; context.RenderSystem.Views.Add(RenderView); context.RenderView = RenderView; OutputSize = context.ViewportState.Viewport0.Size; Viewport = new Viewport((context.ViewportState.Viewport0.Width - ViewportSize) * ViewportPosition.X, (context.ViewportState.Viewport0.Height - ViewportSize) * ViewportPosition.Y, ViewportSize, ViewportSize); using (context.SaveViewportAndRestore()) { context.ViewportState = new ViewportState { Viewport0 = Viewport }; SceneCameraRenderer.UpdateCameraToRenderView(context, RenderView, Camera); Content.Collect(context); } context.RenderView = oldRenderView; } }
protected override void CollectCore(RenderContext context) { base.CollectCore(context); Camera = previewService.selectedEntity?.Components.Get <CameraComponent>(); // Enable camera incrust only if we have an active camera and IsActive is true // Also disabled when previewing game graphics compositor IsIncrustEnabled = previewService.isActive && !previewService.Rendering.RenderMode.PreviewGameGraphicsCompositor && Camera != null; if (IsIncrustEnabled) { var width = context.ViewportState.Viewport0.Width * 0.3f; var height = context.ViewportState.Viewport0.Height * 0.2f; var aspectRatio = width / height; if (Camera.UseCustomAspectRatio) { // Make sure to respect aspect ratio aspectRatio = Camera.AspectRatio; } else if (GameSettingsAccessor != null) { var renderingSettings = GameSettingsAccessor.GetConfiguration <RenderingSettings>(); if (renderingSettings != null) { aspectRatio = (float)renderingSettings.DefaultBackBufferWidth / (float)renderingSettings.DefaultBackBufferHeight; } } if (width > height * aspectRatio) { width = height * aspectRatio; } else { height = width / aspectRatio; } if (width < 32.0f || height < 32.0f) { // Do not display incrust if too small IsIncrustEnabled = false; } context.RenderSystem.Views.Add(RenderView); context.RenderView = RenderView; // Setup viewport Viewport = new Viewport(0, 0, (int)width, (int)height); using (context.SaveViewportAndRestore()) { context.ViewportState = new ViewportState { Viewport0 = Viewport }; SceneCameraRenderer.UpdateCameraToRenderView(context, RenderView, Camera); using (context.PushRenderViewAndRestore(RenderView)) using (context.PushTagAndRestore(CameraComponentRendererExtensions.Current, Camera)) { Content.Collect(context); } } } }