Пример #1
0
        public static RenderTarget2D GetTarget(GraphicsDevice device, RenderTargetInfo info, string name = null)
        {
            RenderTargetInfo mapped;
            bool             wasMapped = infoMappings.TryGetValue(info, out mapped);

            if (!wasMapped)
            {
                mapped = info;
            }

            var stack = GetPool(mapped);

            if (stack.Count > 0)
            {
                var t = stack.Pop();
                t.Tag = name;
#if DEBUG
                active.Add(t.Tag as string);
#endif
                return(t);
            }

            var target = new RenderTarget2D(device, mapped.Width, mapped.Height, mapped.MipMap, mapped.SurfaceFormat, mapped.DepthFormat, mapped.MultiSampleCount, mapped.Usage);
            target.Tag = name;

            if (!wasMapped)
            {
                var targetInfo = RenderTargetInfo.FromRenderTarget(target);
                infoMappings[info] = targetInfo;
            }

#if PROFILE
            numRenderTargets.Value++;

            var   resolution = target.Width * target.Height;
            float size       = resolution * target.Format.FormatSize();
            if (target.MultiSampleCount > 0)
            {
                size *= target.MultiSampleCount;
            }
            if (info.MipMap)
            {
                size *= 1.33f;
            }
            size += resolution * target.DepthStencilFormat.FormatSize();
            renderTargetMemory.Value += size / (1024 * 1024);
#endif

#if DEBUG
            active.Add(target.Tag as string);
#endif

            return(target);
        }
Пример #2
0
        public static void RecycleTarget(RenderTarget2D target)
        {
            var info = RenderTargetInfo.FromRenderTarget(target);

#if DEBUG
            if (GetPool(info).Contains(target))
            {
                throw new InvalidOperationException("Render target has already been freed.");
            }

            active.Remove(target.Tag as string);
#endif

            GetPool(info).Push(target);
            target.Tag = null;
        }