Ejemplo n.º 1
0
        /// <summary>
        /// Uses the specified <see cref="DrawDevice"/> to collect renderer drawcalls in the specified <see cref="Scene"/>.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="drawDevice"></param>
        /// <param name="pickingMap"></param>
        protected void CollectRendererDrawcalls(Scene scene, DrawDevice drawDevice)
        {
            //Profile.TimeCollectDrawcalls.BeginMeasure();
            try
            {
                // If no visibility groups are met, don't bother looking for renderers.
                // This is important to allow efficient drawcall injection with additional
                // "dummy" renderpasses. CamViewStates render their overlays by temporarily
                // adding 3 - 4 of these passes. Iterating over all objects again would be
                // devastating for performance and at the same time pointless.
                if ((drawDevice.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
                {
                    return;
                }

                // Query renderers
                IRendererVisibilityStrategy visibilityStrategy = scene.VisibilityStrategy;
                if (visibilityStrategy == null)
                {
                    return;
                }

                //Profile.TimeQueryVisibleRenderers.BeginMeasure();

                if (this.collectRendererBuffer == null)
                {
                    this.collectRendererBuffer = new RawList <ICmpRenderer>();
                }
                this.collectRendererBuffer.Clear();

                visibilityStrategy.QueryVisibleRenderers(drawDevice, this.collectRendererBuffer);
                if (this.rendererFilter.Count > 0)
                {
                    this.collectRendererBuffer.RemoveAll(r =>
                    {
                        for (int i = 0; i < this.rendererFilter.Count; i++)
                        {
                            if (!this.rendererFilter[i](r))
                            {
                                return(true);
                            }
                        }
                        return(false);
                    });
                }

                //Profile.TimeQueryVisibleRenderers.EndMeasure();

                this.OnCollectRendererDrawcalls(drawDevice, this.collectRendererBuffer, visibilityStrategy.IsRendererQuerySorted);
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error while {0} was collecting renderer drawcalls: {1}", this, /*LogFormat.Exception(*/ e /*)*/);
            }
            //Profile.TimeCollectDrawcalls.EndMeasure();
        }
Ejemplo n.º 2
0
        private void CollectDrawcalls()
        {
            // If no visibility groups are met, don't bother looking for renderers
            if ((this.drawDevice.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
            {
                return;
            }

            // Query renderers
            IRendererVisibilityStrategy visibilityStrategy = Scene.Current.VisibilityStrategy;

            if (visibilityStrategy == null)
            {
                return;
            }
            IEnumerable <ICmpRenderer> rendererQuery = visibilityStrategy.QueryVisibleRenderers(this.drawDevice);

            if (this.editorRenderFilter.Count > 0)
            {
                rendererQuery = rendererQuery.Where(r =>
                {
                    for (int i = 0; i < this.editorRenderFilter.Count; i++)
                    {
                        if (!this.editorRenderFilter[i](r))
                        {
                            return(false);
                        }
                    }
                    return(true);
                });
            }

            // Collect drawcalls
            if (this.drawDevice.IsPicking)
            {
                this.pickingMap = new List <ICmpRenderer>(rendererQuery);
                foreach (ICmpRenderer r in this.pickingMap)
                {
                    r.Draw(this.drawDevice);
                    this.drawDevice.PickingIndex++;
                }
            }
            else
            {
                Profile.TimeCollectDrawcalls.BeginMeasure();

                foreach (ICmpRenderer r in rendererQuery)
                {
                    r.Draw(this.drawDevice);
                }

                Profile.TimeCollectDrawcalls.EndMeasure();
            }
        }
Ejemplo n.º 3
0
        private void CollectDrawcalls()
        {
            // If no visibility groups are met, don't bother looking for renderers.
            // This is important to allow efficient drawcall injection with additional
            // "dummy" renderpasses. CamViewStates render their overlays by temporarily
            // adding 3 - 4 of these passes. Iterating over all objects again would be
            // devastating for performance and at the same time pointless.
            if ((this.drawDevice.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
            {
                return;
            }

            // Query renderers
            IRendererVisibilityStrategy visibilityStrategy = Scene.Current.VisibilityStrategy;
            RawList <ICmpRenderer>      visibleRenderers;

            {
                if (visibilityStrategy == null)
                {
                    return;
                }
                Profile.TimeQueryVisibleRenderers.BeginMeasure();

                visibleRenderers = new RawList <ICmpRenderer>();
                visibilityStrategy.QueryVisibleRenderers(this.drawDevice, visibleRenderers);
                if (this.editorRenderFilter.Count > 0)
                {
                    visibleRenderers.RemoveAll(r =>
                    {
                        for (int i = 0; i < this.editorRenderFilter.Count; i++)
                        {
                            if (!this.editorRenderFilter[i](r))
                            {
                                return(true);
                            }
                        }
                        return(false);
                    });
                }

                Profile.TimeQueryVisibleRenderers.EndMeasure();
            }

            // Collect drawcalls
            if (this.drawDevice.IsPicking)
            {
                this.pickingMap.AddRange(visibleRenderers);
                foreach (ICmpRenderer r in visibleRenderers)
                {
                    r.Draw(this.drawDevice);
                    this.drawDevice.PickingIndex++;
                }
            }
            else
            {
                bool profilePerType = visibilityStrategy.IsRendererQuerySorted;
                Profile.TimeCollectDrawcalls.BeginMeasure();

                Type           lastRendererType = null;
                Type           rendererType     = null;
                TimeCounter    activeProfiler   = null;
                ICmpRenderer[] data             = visibleRenderers.Data;
                for (int i = 0; i < data.Length; i++)
                {
                    if (i >= visibleRenderers.Count)
                    {
                        break;
                    }

                    // Manage profilers per Component type
                    if (profilePerType)
                    {
                        rendererType = data[i].GetType();
                        if (rendererType != lastRendererType)
                        {
                            if (activeProfiler != null)
                            {
                                activeProfiler.EndMeasure();
                            }
                            activeProfiler = Profile.RequestCounter <TimeCounter>(Profile.TimeCollectDrawcalls.FullName + @"\" + rendererType.Name);
                            activeProfiler.BeginMeasure();
                            lastRendererType = rendererType;
                        }
                    }

                    // Collect Drawcalls from this Component
                    data[i].Draw(this.drawDevice);
                }

                if (activeProfiler != null)
                {
                    activeProfiler.EndMeasure();
                }

                Profile.TimeCollectDrawcalls.EndMeasure();
            }
        }
Ejemplo n.º 4
0
        private void CollectDrawcalls()
        {
            // If no visibility groups are met, don't bother looking for renderers
            if ((this.drawDevice.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
            {
                return;
            }

            // Query renderers
            IRendererVisibilityStrategy visibilityStrategy = Scene.Current.VisibilityStrategy;
            RawList <ICmpRenderer>      visibleRenderers;

            {
                if (visibilityStrategy == null)
                {
                    return;
                }
                Profile.TimeQueryVisibleRenderers.BeginMeasure();

                visibleRenderers = new RawList <ICmpRenderer>();
                visibilityStrategy.QueryVisibleRenderers(this.drawDevice, visibleRenderers);
                if (this.editorRenderFilter.Count > 0)
                {
                    visibleRenderers.RemoveAll(r =>
                    {
                        for (int i = 0; i < this.editorRenderFilter.Count; i++)
                        {
                            if (!this.editorRenderFilter[i](r))
                            {
                                return(true);
                            }
                        }
                        return(false);
                    });
                }

                Profile.TimeQueryVisibleRenderers.EndMeasure();
            }

            // Collect drawcalls
            if (this.drawDevice.IsPicking)
            {
                this.pickingMap.AddRange(visibleRenderers);
                foreach (ICmpRenderer r in visibleRenderers)
                {
                    r.Draw(this.drawDevice);
                    this.drawDevice.PickingIndex++;
                }
            }
            else
            {
                bool profilePerType = visibilityStrategy.IsRendererQuerySorted;
                Profile.TimeCollectDrawcalls.BeginMeasure();

                Type           lastRendererType = null;
                Type           rendererType     = null;
                TimeCounter    activeProfiler   = null;
                ICmpRenderer[] data             = visibleRenderers.Data;
                for (int i = 0; i < data.Length; i++)
                {
                    if (i >= visibleRenderers.Count)
                    {
                        break;
                    }

                    // Manage profilers per Component type
                    if (profilePerType)
                    {
                        rendererType = data[i].GetType();
                        if (rendererType != lastRendererType)
                        {
                            if (activeProfiler != null)
                            {
                                activeProfiler.EndMeasure();
                            }
                            activeProfiler = Profile.RequestCounter <TimeCounter>(Profile.TimeCollectDrawcalls.FullName + @"\" + rendererType.Name);
                            activeProfiler.BeginMeasure();
                            lastRendererType = rendererType;
                        }
                    }

                    // Collect Drawcalls from this Component
                    data[i].Draw(this.drawDevice);
                }

                if (activeProfiler != null)
                {
                    activeProfiler.EndMeasure();
                }

                Profile.TimeCollectDrawcalls.EndMeasure();
            }
        }