public static RenderStage GetOrCreateRenderStage(this RenderSystem renderSystem, string name, string effectSlotName, RenderOutputDescription defaultOutput) { var renderStage = renderSystem.RenderStages.FirstOrDefault(x => x.Name == name); if (renderStage != null) return renderStage; renderStage = new RenderStage(name, effectSlotName) { Output = defaultOutput }; renderSystem.RenderStages.Add(renderStage); return renderStage; }
private void CreateDeviceObjects() { var commandList = Game.GraphicsContext.CommandList; var shader = new EffectInstance(EffectSystem.LoadEffect("MultiMeshShader").WaitForResult()); shader.UpdateEffect(GraphicsDevice); streamShader = shader; var outputDesc = new RenderOutputDescription(GraphicsDevice.Presenter.BackBuffer.Format); outputDesc.CaptureState(commandList); var pipeline = new PipelineStateDescription() { /* TODO: do we need all these? */ BlendState = BlendStates.Default, RasterizerState = RasterizerStateDescription.Default, DepthStencilState = DepthStencilStates.None, Output = outputDesc, PrimitiveType = PrimitiveType.TriangleList, InputElements = VertexType.Layout.CreateInputElements(), EffectBytecode = shader.Effect.Bytecode, RootSignature = shader.RootSignature, }; var newPipelineState = PipelineState.New(GraphicsDevice, ref pipeline); pipelineState = newPipelineState; var streamBuffer = Xenko.Graphics.Buffer.New <VertexType>( GraphicsDevice, INITIAL_INSTANCE_COUNT, BufferFlags.VertexBuffer | BufferFlags.StreamOutput ); streamOutBufferBinding = new VertexBufferBinding(streamBuffer, VertexType.Layout, streamBuffer.ElementCount); transformBuffer = Xenko.Graphics.Buffer.Structured.New <Matrix>( GraphicsDevice, INITIAL_INSTANCE_COUNT, isUnorderedAccess: true ); colorBuffer = Xenko.Graphics.Buffer.Structured.New <Color4>( GraphicsDevice, INITIAL_INSTANCE_COUNT, isUnorderedAccess: true ); }
public void Validate(ref RenderOutputDescription renderOutput) { hasChanged = false; if (multisampleCount != renderOutput.MultisampleCount) { hasChanged = true; multisampleCount = renderOutput.MultisampleCount; } if (hasChanged) { // Recalculate shader sources ShaderSource = new ShaderMixinSource(); ShaderSource.Macros.Add(new ShaderMacro("XENKO_MULTISAMPLE_COUNT", (int)multisampleCount)); } renderStage.Output = renderOutput; }
/// <summary> /// Gets a <see cref="RenderOutputDescription"/> that matches current depth stencil and render target formats. /// </summary> /// <returns>The <see cref="RenderOutputDescription"/>.</returns> public unsafe RenderOutputDescription GetRenderOutputDescription() { var result = new RenderOutputDescription { DepthStencilFormat = DepthStencil != null ? DepthStencil.ViewFormat : PixelFormat.None, MultiSampleLevel = DepthStencil != null ? DepthStencil.MultiSampleLevel : MSAALevel.None, }; if (RenderTargets != null) { result.RenderTargetCount = RenderTargets.Length; var renderTargetFormat = &result.RenderTargetFormat0; for (int i = 0; i < RenderTargets.Length; ++i) { *renderTargetFormat++ = RenderTargets[i].ViewFormat; result.MultiSampleLevel = RenderTargets[i].MultiSampleLevel; // multisample should all be equal } } return(result); }
public RenderOutputRestore(RenderContext context) { this.context = context; this.previousValue = context.RenderOutput; }
/// <inheritdoc/> protected override void DrawCore(RenderDrawContext context) { if (Game != null) { // Get or create VisibilityGroup for this RenderSystem + SceneInstance var sceneInstance = SceneInstance.GetCurrent(context.RenderContext); VisibilityGroup visibilityGroup = null; if (sceneInstance != null) { // Find if VisibilityGroup foreach (var currentVisibilityGroup in sceneInstance.VisibilityGroups) { if (currentVisibilityGroup.RenderSystem == RenderSystem) { visibilityGroup = currentVisibilityGroup; break; } } // If first time, let's create and register it if (visibilityGroup == null) { sceneInstance.VisibilityGroups.Add(visibilityGroup = new VisibilityGroup(RenderSystem)); initializedSceneInstances.Add(sceneInstance); } // Reset & cleanup visibilityGroup.Reset(); } using (context.RenderContext.PushTagAndRestore(SceneInstance.CurrentVisibilityGroup, visibilityGroup)) using (context.RenderContext.PushTagAndRestore(SceneInstance.CurrentRenderSystem, RenderSystem)) using (context.RenderContext.PushTagAndRestore(SceneCameraSlotCollection.Current, Cameras)) { // Set render system context.RenderContext.RenderSystem = RenderSystem; context.RenderContext.VisibilityGroup = visibilityGroup; // Set start states for viewports and output (it will be used during the Collect phase) var renderOutputs = new RenderOutputDescription(); renderOutputs.CaptureState(context.CommandList); context.RenderContext.RenderOutput = renderOutputs; var viewports = new ViewportState(); viewports.CaptureState(context.CommandList); context.RenderContext.ViewportState = viewports; try { // Collect in the game graphics compositor: Setup features/stages, enumerate views and populates VisibilityGroup Game.Collect(context.RenderContext); // Collect in render features RenderSystem.Collect(context.RenderContext); // Collect visibile objects from each view (that were not properly collected previously) if (visibilityGroup != null) { foreach (var view in RenderSystem.Views) { visibilityGroup.TryCollect(view); } } // Extract RenderSystem.Extract(context.RenderContext); // Prepare RenderSystem.Prepare(context); // Draw using the game graphics compositor Game.Draw(context); // Flush RenderSystem.Flush(context); } finally { // Reset render context data RenderSystem.Reset(); } } } }
public static RenderStage GetOrCreateRenderStage(this RenderSystem renderSystem, string name, string effectSlotName, RenderOutputDescription defaultOutput) { var renderStage = renderSystem.RenderStages.FirstOrDefault(x => x.Name == name); if (renderStage != null) { return(renderStage); } renderStage = new RenderStage(name, effectSlotName) { Output = defaultOutput }; renderSystem.RenderStages.Add(renderStage); return(renderStage); }
public RenderOutputRestore(RenderContext renderContext) { context = renderContext; previousValue = renderContext.RenderOutput; }