示例#1
0
        protected override void Executing(ISceneSnapshot snapshot)
        {
            var emanager = ContextState.GetEntityManager();
            var ticks    = (float)snapshot.FrameRateTime.TotalMilliseconds;

            Synchronize();
            var registrator = new RenderTechniqueRegistrator <ToolkitRenderProperties>(nested);

            try {
                using (var frame = graphics.FrameBegin()) {
                    foreach (var entity in emanager.GetEntities().OrderBy(x => x.GetOrderIndex <RenderSystem>()))
                    {
                        if (entity.Contains(typeof(RenderableComponent), typeof(TransformComponent)))
                        {
                            registrator.Register(entity);
                        }
                    }

                    if (!registrator.HasAny)
                    {
                        return;
                    }

                    prevCameraState = snapshot.Camera;
                    var lights   = snapshot.Lights.Select(x => LightStructBuffer.From(x)).ToArray();
                    var gamebuff = GameStructBuffer.FromCameraState(prevCameraState, snapshot.Surface.Size);

                    frame.Graphics.UpdateDynamicBuffer(ref gamebuff, gameDataBuffer);
                    frame.Graphics.UpdateDynamicBuffer(lights, lightDataBuffer);

                    foreach (var str in registrator.Techniques)
                    {
                        if (str is IGraphicSystemContextDependent dependent)
                        {
                            dependent.ContextState = ContextState;
                        }
                        str.Render(frame.Graphics, new ToolkitRenderProperties(gameDataBuffer, lightDataBuffer, prevCameraState));
                    }
                }
            } catch (SharpDX.CompilationException cex) {
                ContextState.Logger.Error(cex);
            } catch (SharpDX.SharpDXException shex) {
                ContextState.Logger.Error(shex);
                throw shex;
            } catch (Exception ex) {
                ContextState.Logger.Error(ex.Message);
                throw ex;
            } finally {
                registrator.Cleanup();
                Pass = registrator.Techniques.SelectMany(x => x.GetPass()).ToArray();
            }
        }
示例#2
0
        protected override void Executing(ISceneSnapshot snapshot)
        {
            var emanager = ContextState.GetEntityManager();
            var ticks    = (float)snapshot.FrameRateTime.TotalMilliseconds;

            Synchronize();
            var registrator = new RenderTechniqueRegistrator <CustomRenderProperties>(nested);

            try {
                using (var frame = graphics.Device.FrameBegin()) {
                    foreach (var entity in emanager.GetEntities().OrderBy(x => x.GetOrderIndex <RenderSystem>()))
                    {
                        var renders = entity.GetComponents <IRenderableComponent>();
                        if (renders.Any() && renders.All(x => x.CanRender))
                        {
                            if (!entity.Has <IGeometryComponent>() || !entity.Has <TransformComponent>())
                            {
                                throw new Exception("There are not all necessary components in entity to render.");
                            }
                            registrator.Register(entity);
                        }
                    }

                    prevCameraState = snapshot.Camera;
                    var lights   = snapshot.Lights.Select(x => LightStructBuffer.From(x)).ToArray();
                    var gamebuff = GameStructBuffer.FromCameraState(prevCameraState);

                    frame.Graphics.UpdateSubresource(ref gamebuff, gameDataBuffer, GameStructBuffer.RegisterResourceSlot);
                    frame.Graphics.UpdateDynamicBuffer(lights, lightDataBuffer, LightStructBuffer.RegisterResourceSlot);

                    foreach (var str in registrator.Techniques)
                    {
                        str.Render(frame.Graphics, new CustomRenderProperties(gameDataBuffer, lightDataBuffer, prevCameraState));
                    }
                }
            } catch (SharpDX.CompilationException cex) {
                System.Diagnostics.Trace.WriteLine($"CompilationException[\n{cex.Message.Trim()}]");
            } catch (SharpDX.SharpDXException shex) {
                //var reason = frame.Graphics.D3DDevice.DeviceRemovedReason;
                System.Diagnostics.Trace.WriteLine(shex.Message);
                throw shex;
            } catch (Exception ex) {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                throw ex;
            } finally {
                registrator.Cleanup();
                Pass = registrator.Techniques.Select(x => x.GetPass()).ToArray();
            }
        }