示例#1
0
        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
                );
        }
示例#2
0
        /// <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();
                            }
                        }
            }
        }