Пример #1
0
        internal SinglePassTextureFilter(DrawTargetTexture2D source, DrawTargetTexture2D target)
        {
            if (source == null || target == null)
            {
                throw new ArgumentNullException();
            }
            if (source.SurfaceFormat != target.SurfaceFormat)
            {
                throw new ArgumentException("source.SurfaceFormat != target.SurfaceFormat");
            }
#if XBOX360
            if (source == target && source.Width * source.Height * DrawTarget.FormatSize(source.SurfaceFormat) >
                1000 * 1000 * 10)            //approx 10mb
            {
                throw new ArgumentException("source == target is invalid for larget render targets on Xbox360");
            }
#else
            if (source == target)
            {
                throw new ArgumentException("source == target is invalid on windows");
            }
#endif
            if (source.Width > target.Width ||
                source.Height > target.Height)
            {
                throw new ArgumentException("source is larger than target");
            }

            this.source      = source;
            this.targetClone = target.Clone(false, false, false);

            this.targetClone.ClearBuffer.Enabled = false;

            this.element = new ShaderElement(null, source.Width, source.Height, new Vector2(1, 1), true);
            this.targetClone.Add(element);

            if (target.Width != source.Width ||
                target.Height != source.Height)
            {
                this.targetClone.AddModifier(new Xen.Graphics.Modifier.ScissorModifier(0, 0, Math.Min(1, (source.Width) / target.Width), Math.Min(1, (source.Height) / target.Height)));
                this.element.TextureCrop = new Rectangle(0, 0, Math.Min(this.source.Width, this.targetClone.Width), Math.Min(this.source.Height, this.targetClone.Height));
            }
        }
Пример #2
0
        /// <summary>
        /// Blur the source horizontally to the <paramref name="intermediate"/> target, then blur vertically to <paramref name="target"/>.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="filterFormat">format of the blur filter</param>
        /// <param name="intermediate">draw target to use as a temporary, intermediate target for blurring</param>
        /// <param name="target"></param>
        /// <param name="bellCurveExponent">
        /// <para>A scale value to infulence the bell curve used to generate the filter kernel.</para>
        /// <para>A value of 1.0 generates a standard blur filter kernels. Larger values will produce a tighter curve, and less blur.</para>
        /// <para>Smaller values will produce a wider curve, and a larger blur - but may produce a visible edge as the curve more rapidly ends.</para>
        /// </param>
        public BlurFilter(BlurFilterFormat filterFormat, float bellCurveExponent, DrawTargetTexture2D source, DrawTargetTexture2D intermediate, DrawTargetTexture2D target)
        {
            if (target == null || source == null)
            {
                throw new ArgumentNullException();
            }

            if (intermediate != null && source.SurfaceFormat != intermediate.SurfaceFormat)
            {
                throw new ArgumentException("source.SurfaceFormat != intermediate.SurfaceFormat");
            }
            if (intermediate != null && target.SurfaceFormat != intermediate.SurfaceFormat)
            {
                throw new ArgumentException("target.SurfaceFormat != intermediate.SurfaceFormat");
            }

            this.source = source;

#if XBOX360
            //if the surface will fit into EDRAM then the intermediate can be skipped
            if (source.Width * source.Height * DrawTarget.FormatSize(source.SurfaceFormat) < 1000 * 1000 * 10)  //approx
            {
                this.filterV = new SinglePassTextureFilter(source, target);
                this.filterH = new SinglePassTextureFilter(target, target);
            }
            else
            {
                this.filterV = new SinglePassTextureFilter(source, intermediate);
                this.filterH = new SinglePassTextureFilter(intermediate, source);
            }
#else
            this.filterV = new SinglePassTextureFilter(source, intermediate);
            this.filterH = new SinglePassTextureFilter(intermediate, target);
#endif

            SetFilterFormat(filterFormat, bellCurveExponent);
        }