示例#1
0
        public void Draw(
            Texture2D texture, Vector2 position,
            Rectangle?sourceRectangle = null, Color?multiplyColor = null, Color addColor = default(Color),
            float rotation            = 0, Vector2?scale  = null, Vector2 origin = default(Vector2),
            bool mirrorX          = false, bool mirrorY   = false, float sortKey = 0,
            int?layer             = null, bool?worldSpace = null,
            BlendState blendState = null, SamplerState samplerState = null
            )
        {
            var drawCall = new BitmapDrawCall(texture, position);

            if (sourceRectangle.HasValue)
            {
                drawCall.TextureRegion = texture.BoundsFromRectangle(sourceRectangle.Value);
            }
            drawCall.MultiplyColor = multiplyColor.GetValueOrDefault(Color.White);
            drawCall.AddColor      = addColor;
            drawCall.Rotation      = rotation;
            drawCall.Scale         = scale.GetValueOrDefault(Vector2.One);
            drawCall.Origin        = origin;
            if (mirrorX || mirrorY)
            {
                drawCall.Mirror(mirrorX, mirrorY);
            }
            drawCall.SortKey = sortKey;

            Draw(ref drawCall, layer: layer, worldSpace: worldSpace, blendState: blendState, samplerState: samplerState);
        }
示例#2
0
        public void Draw(
            Texture2D texture, Rectangle destRectangle,
            Rectangle?sourceRectangle = null, Color?multiplyColor = null, Color addColor = default(Color),
            float rotation            = 0, float originX  = 0, float originY     = 0,
            bool mirrorX          = false, bool mirrorY   = false, float sortKey = 0,
            int?layer             = null, bool?worldSpace = null,
            BlendState blendState = null, SamplerState samplerState = null
            )
        {
            var drawCall = new BitmapDrawCall(texture, new Vector2(destRectangle.X, destRectangle.Y));

            if (sourceRectangle.HasValue)
            {
                var sr = sourceRectangle.Value;
                drawCall.TextureRegion = texture.BoundsFromRectangle(ref sr);
                drawCall.Scale         = new Vector2(destRectangle.Width / (float)sr.Width, destRectangle.Height / (float)sr.Height);
            }
            else
            {
                drawCall.Scale = new Vector2(destRectangle.Width / (float)texture.Width, destRectangle.Height / (float)texture.Height);
            }
            drawCall.MultiplyColor = multiplyColor.GetValueOrDefault(Color.White);
            drawCall.AddColor      = addColor;
            drawCall.Rotation      = rotation;
            drawCall.Origin        = new Vector2(originX, originY);
            if (mirrorX || mirrorY)
            {
                drawCall.Mirror(mirrorX, mirrorY);
            }
            drawCall.SortKey = sortKey;

            Draw(ref drawCall, layer: layer, worldSpace: worldSpace, blendState: blendState, samplerState: samplerState);
        }
示例#3
0
        public void Draw(
            ref BitmapDrawCall drawCall,
            int?layer             = null, bool?worldSpace = null,
            BlendState blendState = null, SamplerState samplerState = null
            )
        {
            if (Container == null)
            {
                throw new InvalidOperationException("You cannot use the argumentless ImperativeRenderer constructor.");
            }
            else if (Container.IsDisposed)
            {
                throw new ObjectDisposedException("The container this ImperativeRenderer is drawing into has been disposed.");
            }

            if (AutoIncrementSortKey)
            {
                drawCall.SortKey = NextSortKey;
                NextSortKey     += 1;
            }

            using (var batch = GetBitmapBatch(
                       layer, worldSpace,
                       blendState, samplerState
                       ))
                batch.Add(ref drawCall);
        }
示例#4
0
        private void RasterizeIntoPrepassComposited(
            ref RasterizePassSet passSet, ref RectF compositeBox, ref BitmapDrawCall dc,
            bool enableCompositor, float effectiveOpacity
            )
        {
            if (MostRecentCompositeData == null)
            {
                MostRecentCompositeData = new CompositionData();
            }
            MostRecentCompositeData.DrawCall = dc;
            MostRecentCompositeData.Box      = compositeBox;
            var subgroup = passSet.Above.MakeSubgroup(
                before: BeforeComposite,
                after: AfterComposite,
                userData: this
                );

            ((BatchGroup)subgroup.Container).SetViewTransform(Appearance.HasTransformMatrix ? ApplyLocalTransformMatrix : null);
            subgroup.BlendState = RenderStates.PorterDuffOver;
            if (enableCompositor)
            {
                Appearance.Compositor.Composite(this, ref subgroup, ref dc, effectiveOpacity);
            }
            else
            {
                subgroup.Draw(ref dc, material: Appearance.CompositeMaterial);
            }
        }
        public override void Draw(Squared.Render.Frame frame)
        {
            const float LightmapScale = 1f;

            LightmapMaterials.ViewportScale    = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, Width,
                Height, 0,
                0, 1
                );

            ClearBatch.AddNew(frame, 0, Game.ScreenMaterials.Clear, clearColor: Color.Black);

            Renderer.RenderLighting(frame, frame, 1);

            using (var bg = BatchGroup.New(frame, 2)) {
                var dc = new BitmapDrawCall(TestImage, new Vector2(0, 550), 0.55f);

                using (var bb = BitmapBatch.New(bg, 0, Renderer.Materials.ScreenSpaceBitmap))
                    bb.Add(ref dc);

                dc.Position.X += 600;
                dc.Textures    = new TextureSet(dc.Texture, RampTexture);

                using (var bb2 = BitmapBatch.New(bg, 1, Renderer.IlluminantMaterials.ScreenSpaceRampBitmap, samplerState2: SamplerState.LinearClamp))
                    bb2.Add(ref dc);
            }

            if (ShowOutlines)
            {
                Renderer.RenderOutlines(frame, 2, true);
            }
        }
示例#6
0
        public override void Draw(Squared.Render.Frame frame)
        {
            const float LightmapScale = 1f;

            LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, Width,
                Height, 0,
                0, 1
            );

            ClearBatch.AddNew(frame, 0, Game.ScreenMaterials.Clear, clearColor: Color.Black);

            Renderer.RenderLighting(frame, frame, 1);

            using (var bg = BatchGroup.New(frame, 2)) {
                var dc = new BitmapDrawCall(TestImage, new Vector2(0, 550), 0.55f);

                using (var bb = BitmapBatch.New(bg, 0, Renderer.Materials.ScreenSpaceBitmap))
                    bb.Add(ref dc);

                dc.Position.X += 600;
                dc.Textures = new TextureSet(dc.Texture, RampTexture);

                using (var bb2 = BitmapBatch.New(bg, 1, Renderer.IlluminantMaterials.ScreenSpaceRampBitmap, samplerState2: SamplerState.LinearClamp))
                    bb2.Add(ref dc);
            }

            if (ShowOutlines)
                Renderer.RenderOutlines(frame, 2, true);
        }
示例#7
0
        public void Draw(
            Texture2D texture, float x, float y,
            Rectangle?sourceRectangle = null, Color?multiplyColor = null, Color addColor = default(Color),
            float rotation            = 0, float scaleX   = 1, float scaleY = 1, float originX = 0, float originY = 0,
            bool mirrorX          = false, bool mirrorY   = false, DrawCallSortKey?sortKey = null,
            int?layer             = null, bool?worldSpace = null,
            BlendState blendState = null, SamplerState samplerState = null,
            Material material     = null
            )
        {
            var drawCall = new BitmapDrawCall(texture, new Vector2(x, y));

            if (sourceRectangle.HasValue)
            {
                drawCall.TextureRegion = texture.BoundsFromRectangle(sourceRectangle.Value);
            }
            drawCall.MultiplyColor = multiplyColor.GetValueOrDefault(Color.White);
            drawCall.AddColor      = addColor;
            drawCall.Rotation      = rotation;
            drawCall.Scale         = new Vector2(scaleX, scaleY);
            drawCall.Origin        = new Vector2(originX, originY);
            if (mirrorX || mirrorY)
            {
                drawCall.Mirror(mirrorX, mirrorY);
            }

            drawCall.SortKey = sortKey.GetValueOrDefault(NextSortKey);
            if (AutoIncrementSortKey)
            {
                NextSortKey.Order += 1;
            }

            Draw(ref drawCall, layer: layer, worldSpace: worldSpace, blendState: blendState, samplerState: samplerState);
        }
示例#8
0
 public void Draw(
     BitmapDrawCall drawCall,
     int?layer             = null, bool?worldSpace = null,
     BlendState blendState = null, SamplerState samplerState = null
     )
 {
     Draw(ref drawCall, layer, worldSpace, blendState, samplerState);
 }
示例#9
0
        /// <summary>
        /// Advances the time position and draws the current frame of the animation.
        /// </summary>
        public void Draw(GameTime gameTime, BitmapBatch batch, Vector2 position, SpriteEffects spriteEffects)
        {
            if (Animation == null)
            {
                throw new NotSupportedException("No animation is currently playing.");
            }

            // Process passing time.
            time += (float)gameTime.ElapsedGameTime.TotalSeconds;
            while (time > Animation.FrameTime)
            {
                time -= Animation.FrameTime;

                // Advance the frame index; looping or clamping as appropriate.
                if (Animation.IsLooping)
                {
                    frameIndex = (frameIndex + 1) % Animation.FrameCount;
                }
                else
                {
                    frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);
                }
            }

            // Calculate the source rectangle of the current frame.
            Rectangle source = new Rectangle(FrameIndex * Animation.Texture.Height, 0, Animation.Texture.Height, Animation.Texture.Height);

            var texScale = new Vector2(1.0f / Animation.Texture.Width, 1.0f / Animation.Texture.Height);

            // Draw the current frame.
            var drawCall = new BitmapDrawCall(
                Animation.Texture, position - Origin,
                new Squared.Game.Bounds(
                    new Vector2(source.X, source.Y) * texScale,
                    new Vector2(source.Right, source.Bottom) * texScale
                    ), Color.White, Vector2.One
                );

            if ((spriteEffects & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally)
            {
                drawCall.Mirror(true, false);
            }
            if ((spriteEffects & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically)
            {
                drawCall.Mirror(false, true);
            }
            batch.Add(drawCall);
            // spriteEffects
        }
        public override void Draw(GameTime gameTime, Frame frame)
        {
            ClearBatch.AddNew(frame, -1, Materials.Clear, clearColor: ClearColor);

            const int width  = 1280;
            const int height = 720;

            var options = new ParallelOptions {
//                MaxDegreeOfParallelism = 1
            };
            int layer   = 0;

            Parallel.For(
                0, height, options,
                // One batch per worker thread
                () =>
                BitmapBatch.New(
                    frame,
                    // Suppress batch combining
                    Interlocked.Increment(ref layer),
                    Materials.ScreenSpaceBitmap
                    ),
                (y, loopState, bb) => {
                var drawCall = new BitmapDrawCall(WhitePixel, new Vector2(0, y));
                float fx     = 0;
                var range    = bb.ReserveSpace(width);
                var array    = range.Array;
                var offset   = range.Offset;

                for (int x = 0; x < width; x++, fx++)
                {
                    drawCall.Texture       = ((x % 2) == 0) ? WhitePixel : GrayPixel;
                    drawCall.Position.X    = fx;
                    drawCall.MultiplyColor = new Color(255, x % 255, y % 255);

                    array[offset + x] = drawCall;
                }

                return(bb);
            },
                (bb) =>
                bb.Dispose()
                );
        }
示例#11
0
        public override void Draw(GameTime gameTime, Frame frame)
        {
            ClearBatch.AddNew(frame, -1, Materials.Clear, clearColor: ClearColor);

            const int width = 1280;
            const int height = 720;

            var options = new ParallelOptions {
            //                MaxDegreeOfParallelism = 1
            };
            int layer = 0;
            Parallel.For(
                0, height, options,
                // One batch per worker thread
                () =>
                    BitmapBatch.New(
                        frame,
                        // Suppress batch combining
                        Interlocked.Increment(ref layer),
                        Materials.ScreenSpaceBitmap
                    ),
                (y, loopState, bb) => {
                    var drawCall = new BitmapDrawCall(WhitePixel, new Vector2(0, y));
                    float fx = 0;
                    var range = bb.ReserveSpace(width);
                    var array = range.Array;
                    var offset = range.Offset;

                    for (int x = 0; x < width; x++, fx++) {
                        drawCall.Texture = ((x % 2) == 0) ? WhitePixel : GrayPixel;
                        drawCall.Position.X = fx;
                        drawCall.MultiplyColor = new Color(255, x % 255, y % 255);

                        array[offset + x] = drawCall;
                    }

                    return bb;
                },
                (bb) =>
                    bb.Dispose()
            );
        }
示例#12
0
        public void Draw(
            ref BitmapDrawCall drawCall,
            int?layer             = null, bool?worldSpace = null,
            BlendState blendState = null, SamplerState samplerState = null,
            Material material     = null
            )
        {
            if (Container == null)
            {
                throw new InvalidOperationException("You cannot use the argumentless ImperativeRenderer constructor.");
            }
            else if (Container.IsReleased)
            {
                throw new ObjectDisposedException("The container this ImperativeRenderer is drawing into has been disposed.");
            }

            using (var batch = GetBitmapBatch(
                       layer, worldSpace,
                       blendState, samplerState, material
                       )) {
                if (LowPriorityMaterialOrdering)
                {
                    if (material != null)
                    {
                        material = Materials.Get(material, RasterizerState, DepthStencilState, blendState ?? BlendState);
                    }
                    else
                    {
                        material = Materials.GetBitmapMaterial(worldSpace ?? WorldSpace, RasterizerState, DepthStencilState, blendState ?? BlendState);
                    }

                    var mmbb = (MultimaterialBitmapBatch)batch;
                    mmbb.Add(ref drawCall, material, samplerState, samplerState);
                }
                else
                {
                    batch.Add(ref drawCall);
                }
            }
        }
示例#13
0
        public override void Draw (Squared.Render.Frame frame) {
            CreateRenderTargets();

            LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, BackgroundLightmap.Width,
                BackgroundLightmap.Height, 0,
                0, 1
            );

            using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) {
                ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 0; i < 1; i++) {
                        var layer = Layers[i];
                        var dc = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) {
                ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 1; i < Layers.Length; i++) {
                        var layer = Layers[i];
                        var dc = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) {
                ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(32, 32, 32, 255), clearZ: 0, clearStencil: 0);
                BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2);
            }

            using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) {
                ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(96, 96, 96, 255), clearZ: 0, clearStencil: 0);
                ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2);
            }

            SetRenderTargetBatch.AddNew(frame, 49, null);
            ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0);

            if (ShowLightmap) {
                using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale);
                    bb.Add(dc);
                }

                ParticleRenderer.Draw(frame, 56);
            } else {
                var dc = new BitmapDrawCall(Background, Vector2.Zero);

                var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend);

                using (var bb = BitmapBatch.New(frame, 55, material)) {
                    dc.Textures = new TextureSet(Background, BackgroundLightmap);
                    dc.SortKey = 0;

                    bb.Add(dc);
                }

                ParticleRenderer.Draw(frame, 56);

                using (var bb = BitmapBatch.New(frame, 57, material)) {
                    dc.Textures = new TextureSet(Foreground, ForegroundLightmap);
                    dc.SortKey = 1;

                    bb.Add(dc);
                }
            }

            if (ShowOutlines || (Dragging != null))
                BackgroundRenderer.RenderOutlines(frame, 59, true);
        }
示例#14
0
        public StringLayout Get()
        {
            if (_Text.IsNull)
            {
                return(new StringLayout());
            }

            if (!_CachedStringLayout.HasValue)
            {
                int length = _Text.Length;

                int capacity = length;
                if (_WordWrap)
                {
                    capacity *= 2;
                }

                ArraySegment <BitmapDrawCall> seg1;
                ArraySegment <BitmapDrawCall>?seg2 = null;

                if ((_Buffer.Array != null) && (_Buffer.Count < capacity))
                {
                    _Buffer = default(ArraySegment <BitmapDrawCall>);
                }

                if (_Buffer.Array == null)
                {
                    var newCapacity = 1 << (int)Math.Ceiling(Math.Log(capacity, 2));
                    var array       = new BitmapDrawCall[newCapacity];
                    _Buffer = new ArraySegment <BitmapDrawCall>(array);
                }

                if (_Buffer.Count < capacity)
                {
                    throw new InvalidOperationException("Buffer too small");
                }

                seg1 = _Buffer;
                // FIXME: Insufficient space?
                if (_WordWrap)
                {
                    seg2 = new ArraySegment <BitmapDrawCall>(
                        _Buffer.Array, _Buffer.Offset + length, length
                        );
                }

                _CachedStringLayout = Font.LayoutString(
                    _Text, seg1,
                    _Position, _Color,
                    _Scale, _SortKey,
                    _CharacterSkipCount, _CharacterLimit,
                    _XOffsetOfFirstLine, _WordWrap ? null : _LineBreakAtX,
                    _AlignToPixels, _KerningAdjustments
                    );

                if (_WordWrap && _LineBreakAtX.HasValue)
                {
                    _CachedStringLayout = _CachedStringLayout.Value.WordWrap(
                        _Text, _LineBreakAtX.Value, seg2, WrapIndentation, characterWrap: CharacterWrap
                        );
                }
            }

            return(_CachedStringLayout.Value);
        }
示例#15
0
        public void Draw(
            Texture2D texture, Rectangle destRectangle,
            Rectangle? sourceRectangle = null, Color? multiplyColor = null, Color addColor = default(Color),
            float rotation = 0, float originX = 0, float originY = 0,
            bool mirrorX = false, bool mirrorY = false, float sortKey = 0,
            int? layer = null, bool? worldSpace = null,
            BlendState blendState = null, SamplerState samplerState = null
        )
        {
            var drawCall = new BitmapDrawCall(texture, new Vector2(destRectangle.X, destRectangle.Y));
            if (sourceRectangle.HasValue) {
                var sr = sourceRectangle.Value;
                drawCall.TextureRegion = texture.BoundsFromRectangle(ref sr);
                drawCall.Scale = new Vector2(destRectangle.Width / (float)sr.Width, destRectangle.Height / (float)sr.Height);
            } else {
                drawCall.Scale = new Vector2(destRectangle.Width / (float)texture.Width, destRectangle.Height / (float)texture.Height);
            }
            drawCall.MultiplyColor = multiplyColor.GetValueOrDefault(Color.White);
            drawCall.AddColor = addColor;
            drawCall.Rotation = rotation;
            drawCall.Origin = new Vector2(originX, originY);
            if (mirrorX || mirrorY)
                drawCall.Mirror(mirrorX, mirrorY);
            drawCall.SortKey = sortKey;

            Draw(ref drawCall, layer: layer, worldSpace: worldSpace, blendState: blendState, samplerState: samplerState);
        }
示例#16
0
        public void Draw(
            Texture2D texture, Vector2 position,
            Rectangle? sourceRectangle = null, Color? multiplyColor = null, Color addColor = default(Color),
            float rotation = 0, Vector2? scale = null, Vector2 origin = default(Vector2),
            bool mirrorX = false, bool mirrorY = false, float sortKey = 0,
            int? layer = null, bool? worldSpace = null, 
            BlendState blendState = null, SamplerState samplerState = null
        )
        {
            var drawCall = new BitmapDrawCall(texture, position);
            if (sourceRectangle.HasValue)
                drawCall.TextureRegion = texture.BoundsFromRectangle(sourceRectangle.Value);
            drawCall.MultiplyColor = multiplyColor.GetValueOrDefault(Color.White);
            drawCall.AddColor = addColor;
            drawCall.Rotation = rotation;
            drawCall.Scale = scale.GetValueOrDefault(Vector2.One);
            drawCall.Origin = origin;
            if (mirrorX || mirrorY)
                drawCall.Mirror(mirrorX, mirrorY);
            drawCall.SortKey = sortKey;

            Draw(ref drawCall, layer: layer, worldSpace: worldSpace, blendState: blendState, samplerState: samplerState);
        }
示例#17
0
        public void Draw(
            ref BitmapDrawCall drawCall, 
            int? layer = null, bool? worldSpace = null,
            BlendState blendState = null, SamplerState samplerState = null
        )
        {
            if (Container == null)
                throw new InvalidOperationException("You cannot use the argumentless ImperativeRenderer constructor.");
            else if (Container.IsDisposed)
                throw new ObjectDisposedException("The container this ImperativeRenderer is drawing into has been disposed.");

            if (AutoIncrementSortKey) {
                drawCall.SortKey = NextSortKey;
                NextSortKey += 1;
            }

            using (var batch = GetBitmapBatch(
                layer, worldSpace,
                blendState, samplerState
            ))
                batch.Add(ref drawCall);
        }
示例#18
0
 public void Draw(
     BitmapDrawCall drawCall, 
     int? layer = null, bool? worldSpace = null,
     BlendState blendState = null, SamplerState samplerState = null
 )
 {
     Draw(ref drawCall, layer, worldSpace, blendState, samplerState);
 }
示例#19
0
        public StringLayout Get()
        {
            if (_Text.IsNull)
            {
                return(new StringLayout());
            }

            if (_CachedStringLayout.HasValue && _CachedGlyphVersion < _GlyphSource.Version)
            {
                _CachedStringLayout = null;
            }

            if (!_CachedStringLayout.HasValue)
            {
                int length = _Text.Length;

                int capacity = length + StringLayoutEngine.DefaultBufferPadding;

                if ((_Buffer.Array != null) && (_Buffer.Count < capacity))
                {
                    _Buffer = default(ArraySegment <BitmapDrawCall>);
                }

                if (_Buffer.Array == null)
                {
                    var newCapacity = 1 << (int)Math.Ceiling(Math.Log(capacity, 2));
                    var array       = new BitmapDrawCall[newCapacity];
                    _Buffer = new ArraySegment <BitmapDrawCall>(array);
                }

                if (_Buffer.Count < capacity)
                {
                    throw new InvalidOperationException("Buffer too small");
                }

                using (
                    var le = new StringLayoutEngine {
                    buffer = _Buffer,
                    position = _Position,
                    color = _Color,
                    scale = _Scale,
                    sortKey = _SortKey,
                    characterSkipCount = _CharacterSkipCount,
                    characterLimit = _CharacterLimit,
                    xOffsetOfFirstLine = _XOffsetOfFirstLine,
                    xOffsetOfWrappedLine = _XOffsetOfNewLine + _WrapIndentation,
                    xOffsetOfNewLine = _XOffsetOfNewLine,
                    lineBreakAtX = _LineBreakAtX,
                    alignToPixels = _AlignToPixels,
                    characterWrap = _CharacterWrap,
                    wordWrap = _WordWrap,
                    wrapCharacter = _WrapCharacter,
                    alignment = (HorizontalAlignment)_Alignment,
                    reverseOrder = _ReverseOrder
                }
                    ) {
                    le.Initialize();
                    le.AppendText(_GlyphSource, _Text, _KerningAdjustments);

                    _CachedGlyphVersion = _GlyphSource.Version;
                    _CachedStringLayout = le.Finish();
                }
            }

            return(_CachedStringLayout.Value);
        }
示例#20
0
        public override void Draw(Squared.Render.Frame frame)
        {
            CreateRenderTargets();

            LightmapMaterials.ViewportScale    = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, BackgroundLightmap.Width,
                BackgroundLightmap.Height, 0,
                0, 1
                );

            using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) {
                ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 0; i < 1; i++)
                    {
                        var layer = Layers[i];
                        var dc    = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) {
                ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 1; i < Layers.Length; i++)
                    {
                        var layer = Layers[i];
                        var dc    = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) {
                ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(32, 32, 32, 255), clearZ: 0, clearStencil: 0);
                BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2);
            }

            using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) {
                ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(96, 96, 96, 255), clearZ: 0, clearStencil: 0);
                ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2);
            }

            SetRenderTargetBatch.AddNew(frame, 49, null);
            ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0);

            if (ShowLightmap)
            {
                using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale);
                    bb.Add(dc);
                }

                ParticleRenderer.Draw(frame, 56);
            }
            else
            {
                var dc = new BitmapDrawCall(Background, Vector2.Zero);

                var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend);

                using (var bb = BitmapBatch.New(frame, 55, material)) {
                    dc.Textures = new TextureSet(Background, BackgroundLightmap);
                    dc.SortKey  = 0;

                    bb.Add(dc);
                }

                ParticleRenderer.Draw(frame, 56);

                using (var bb = BitmapBatch.New(frame, 57, material)) {
                    dc.Textures = new TextureSet(Foreground, ForegroundLightmap);
                    dc.SortKey  = 1;

                    bb.Add(dc);
                }
            }

            if (ShowOutlines || (Dragging != null))
            {
                BackgroundRenderer.RenderOutlines(frame, 59, true);
            }
        }
示例#21
0
        public override void Draw(Squared.Render.Frame frame)
        {
            CreateRenderTargets();

            LightmapMaterials.ViewportScale = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, BackgroundLightmap.Width,
                BackgroundLightmap.Height, 0,
                0, 1
            );

            using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) {
                ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 0; i < 1; i++) {
                        var layer = Layers[i];
                        var dc = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) {
                ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 1; i < Layers.Length; i++) {
                        var layer = Layers[i];
                        var dc = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            if (ShowBrickSpecular)
                using (var bricksLightGroup = BatchGroup.ForRenderTarget(frame, 2, ForegroundLightmap)) {
                    ClearBatch.AddNew(bricksLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(0, 0, 0, 255), clearZ: 0, clearStencil: 0);
                    ForegroundRenderer.RenderLighting(frame, bricksLightGroup, 2);
                }

            if (ShowAOShadow)
                using (var aoShadowFirstPassGroup = BatchGroup.ForRenderTarget(frame, 3, AOShadowScratch)) {
                    ClearBatch.AddNew(aoShadowFirstPassGroup, 1, LightmapMaterials.Clear, clearColor: Color.Transparent);

                    using (var bb = BitmapBatch.New(aoShadowFirstPassGroup, 2, Game.ScreenMaterials.ScreenSpaceHorizontalGaussianBlur5Tap)) {
                        bb.Add(new BitmapDrawCall(Foreground, Vector2.Zero, 1f / LightmapScale));
                    }
                }

            using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) {
                ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(40, 40, 40, 255), clearZ: 0, clearStencil: 0);

                BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2);

                if (ShowBrickSpecular) {
                    using (var foregroundLightBatch = BitmapBatch.New(backgroundLightGroup, 3, MaskedForegroundMaterial)) {
                        var dc = new BitmapDrawCall(
                            ForegroundLightmap, Vector2.Zero
                        );
                        dc.Textures = new TextureSet(dc.Textures.Texture1, BricksLightMask);
                        foregroundLightBatch.Add(dc);
                    }
                } else {
                    ForegroundRenderer.RenderLighting(frame, backgroundLightGroup, 3);
                }

                if (ShowAOShadow)
                    using (var aoShadowBatch = BitmapBatch.New(backgroundLightGroup, 4, AOShadowMaterial)) {
                        var dc = new BitmapDrawCall(
                            AOShadowScratch, new Vector2(0, 4)
                        );
                        dc.MultiplyColor = Color.Black;
                        dc.AddColor = Color.White;

                        aoShadowBatch.Add(dc);
                    }
            }

            using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) {
                ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(127, 127, 127, 255), clearZ: 0, clearStencil: 0);
                ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2);
            }

            SetRenderTargetBatch.AddNew(frame, 49, null);
            ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0);

            if (ShowLightmap) {
                using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale);
                    bb.Add(dc);
                }
            } else {
                var dc = new BitmapDrawCall(Background, Vector2.Zero);

                var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend);

                using (var bb = BitmapBatch.New(frame, 55, material)) {
                    dc.Textures = new TextureSet(Background, BackgroundLightmap);
                    dc.SortKey = 0;

                    bb.Add(dc);
                }

                ParticleRenderer.Draw(frame, 56);

                using (var bb = BitmapBatch.New(frame, 57, material)) {
                    dc.Textures = new TextureSet(Foreground, ForegroundLightmap);
                    dc.SortKey = 1;

                    bb.Add(dc);
                }
            }

            if (ShowOutlines || (Dragging != null))
                BackgroundRenderer.RenderOutlines(frame, 59, true);
        }
示例#22
0
        public override void Draw(GameTime gameTime, Frame frame)
        {
            if (false)
            {
                var stats = RenderManager.GetMemoryStatistics();
                Console.WriteLine(
                    "managed: {0:0000000}kb    vertex: {1:0000000}kb    index: {2:0000000}kb",
                    (stats.ManagedIndexBytes + stats.ManagedVertexBytes) / 1024.0,
                    stats.UnmanagedVertexBytes / 1024.0,
                    stats.UnmanagedIndexBytes / 1024.0
                    );
            }

            ClearBatch.AddNew(frame, -1, Materials.Clear, clearColor: ClearColor);

            const int width  = 1280;
            const int height = 720;

            var options = new ParallelOptions {
//                MaxDegreeOfParallelism = 1
            };
            int layer   = 0;

            Parallel.For(
                0, height, options,
                // One batch per worker thread
                () =>
                BitmapBatch.New(
                    frame,
                    // Suppress batch combining
                    Interlocked.Increment(ref layer),
                    Materials.ScreenSpaceBitmap
                    ),
                (y, loopState, bb) => {
                var drawCall = new BitmapDrawCall(WhitePixel, new Vector2(0, y));
                float fx     = 0;
                var range    = bb.ReserveSpace(width);
                var array    = range.Array;
                var offset   = range.Offset;

                for (int x = 0; x < width; x++, fx++)
                {
                    drawCall.Texture       = ((x % 2) == 0) ? WhitePixel : GrayPixel;
                    drawCall.Position.X    = fx;
                    drawCall.MultiplyColor = new Color(255, x % 255, y % 255);

                    array[offset + x] = drawCall;
                }

                return(bb);
            },
                (bb) =>
                bb.Dispose()
                );

            var ir = new ImperativeRenderer(
                frame, Materials,
                blendState: BlendState.Opaque,
                depthStencilState: DepthStencilState.None,
                rasterizerState: RasterizerState.CullNone,
                worldSpace: false,
                layer: 9999
                );

            DrawPerformanceStats(ref ir);
        }
示例#23
0
        /// <summary>
        /// Advances the time position and draws the current frame of the animation.
        /// </summary>
        public void Draw(GameTime gameTime, BitmapBatch batch, Vector2 position, SpriteEffects spriteEffects)
        {
            if (Animation == null)
                throw new NotSupportedException("No animation is currently playing.");

            // Process passing time.
            time += (float)gameTime.ElapsedGameTime.TotalSeconds;
            while (time > Animation.FrameTime) {
                time -= Animation.FrameTime;

                // Advance the frame index; looping or clamping as appropriate.
                if (Animation.IsLooping) {
                    frameIndex = (frameIndex + 1) % Animation.FrameCount;
                } else {
                    frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);
                }
            }

            // Calculate the source rectangle of the current frame.
            Rectangle source = new Rectangle(FrameIndex * Animation.Texture.Height, 0, Animation.Texture.Height, Animation.Texture.Height);

            var texScale = new Vector2(1.0f / Animation.Texture.Width, 1.0f / Animation.Texture.Height);

            // Draw the current frame.
            var drawCall = new BitmapDrawCall(
                Animation.Texture, position - Origin,
                new Squared.Game.Bounds(
                    new Vector2(source.X, source.Y) * texScale,
                    new Vector2(source.Right, source.Bottom) * texScale
                ), Color.White, Vector2.One
            );
            if ((spriteEffects & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally)
                drawCall.Mirror(true, false);
            if ((spriteEffects & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically)
                drawCall.Mirror(false, true);
            batch.Add(drawCall);
            // spriteEffects
        }
示例#24
0
        public override void Draw(Squared.Render.Frame frame)
        {
            CreateRenderTargets();

            LightmapMaterials.ViewportScale    = new Vector2(1f / LightmapScale);
            LightmapMaterials.ProjectionMatrix = Matrix.CreateOrthographicOffCenter(
                0, BackgroundLightmap.Width,
                BackgroundLightmap.Height, 0,
                0, 1
                );

            using (var backgroundGroup = BatchGroup.ForRenderTarget(frame, 0, Background)) {
                ClearBatch.AddNew(backgroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(backgroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 0; i < 1; i++)
                    {
                        var layer = Layers[i];
                        var dc    = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            using (var foregroundGroup = BatchGroup.ForRenderTarget(frame, 1, Foreground)) {
                ClearBatch.AddNew(foregroundGroup, 1, Game.ScreenMaterials.Clear, clearColor: Color.Transparent);

                using (var bb = BitmapBatch.New(foregroundGroup, 2, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    for (var i = 1; i < Layers.Length; i++)
                    {
                        var layer = Layers[i];
                        var dc    = new BitmapDrawCall(layer, Vector2.Zero);
                        dc.SortKey = i;
                        bb.Add(dc);
                    }
                }
            }

            if (ShowBrickSpecular)
            {
                using (var bricksLightGroup = BatchGroup.ForRenderTarget(frame, 2, ForegroundLightmap)) {
                    ClearBatch.AddNew(bricksLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(0, 0, 0, 255), clearZ: 0, clearStencil: 0);
                    ForegroundRenderer.RenderLighting(frame, bricksLightGroup, 2);
                }
            }

            if (ShowAOShadow)
            {
                using (var aoShadowFirstPassGroup = BatchGroup.ForRenderTarget(frame, 3, AOShadowScratch)) {
                    ClearBatch.AddNew(aoShadowFirstPassGroup, 1, LightmapMaterials.Clear, clearColor: Color.Transparent);

                    using (var bb = BitmapBatch.New(aoShadowFirstPassGroup, 2, Game.ScreenMaterials.ScreenSpaceHorizontalGaussianBlur5Tap)) {
                        bb.Add(new BitmapDrawCall(Foreground, Vector2.Zero, 1f / LightmapScale));
                    }
                }
            }

            using (var backgroundLightGroup = BatchGroup.ForRenderTarget(frame, 4, BackgroundLightmap)) {
                ClearBatch.AddNew(backgroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(40, 40, 40, 255), clearZ: 0, clearStencil: 0);

                BackgroundRenderer.RenderLighting(frame, backgroundLightGroup, 2);

                if (ShowBrickSpecular)
                {
                    using (var foregroundLightBatch = BitmapBatch.New(backgroundLightGroup, 3, MaskedForegroundMaterial)) {
                        var dc = new BitmapDrawCall(
                            ForegroundLightmap, Vector2.Zero
                            );
                        dc.Textures = new TextureSet(dc.Textures.Texture1, BricksLightMask);
                        foregroundLightBatch.Add(dc);
                    }
                }
                else
                {
                    ForegroundRenderer.RenderLighting(frame, backgroundLightGroup, 3);
                }

                if (ShowAOShadow)
                {
                    using (var aoShadowBatch = BitmapBatch.New(backgroundLightGroup, 4, AOShadowMaterial)) {
                        var dc = new BitmapDrawCall(
                            AOShadowScratch, new Vector2(0, 4)
                            );
                        dc.MultiplyColor = Color.Black;
                        dc.AddColor      = Color.White;

                        aoShadowBatch.Add(dc);
                    }
                }
            }

            using (var foregroundLightGroup = BatchGroup.ForRenderTarget(frame, 5, ForegroundLightmap)) {
                ClearBatch.AddNew(foregroundLightGroup, 1, LightmapMaterials.Clear, clearColor: new Color(127, 127, 127, 255), clearZ: 0, clearStencil: 0);
                ForegroundRenderer.RenderLighting(frame, foregroundLightGroup, 2);
            }

            SetRenderTargetBatch.AddNew(frame, 49, null);
            ClearBatch.AddNew(frame, 50, Game.ScreenMaterials.Clear, clearColor: Color.Black, clearZ: 0, clearStencil: 0);

            if (ShowLightmap)
            {
                using (var bb = BitmapBatch.New(frame, 55, Game.ScreenMaterials.WorldSpaceBitmap)) {
                    var dc = new BitmapDrawCall(BackgroundLightmap, Vector2.Zero, LightmapScale);
                    bb.Add(dc);
                }
            }
            else
            {
                var dc = new BitmapDrawCall(Background, Vector2.Zero);

                var material = LightmapMaterials.Get(LightmapMaterials.WorldSpaceLightmappedBitmap, blendState: BlendState.AlphaBlend);

                using (var bb = BitmapBatch.New(frame, 55, material)) {
                    dc.Textures = new TextureSet(Background, BackgroundLightmap);
                    dc.SortKey  = 0;

                    bb.Add(dc);
                }

                ParticleRenderer.Draw(frame, 56);

                using (var bb = BitmapBatch.New(frame, 57, material)) {
                    dc.Textures = new TextureSet(Foreground, ForegroundLightmap);
                    dc.SortKey  = 1;

                    bb.Add(dc);
                }
            }

            if (ShowOutlines || (Dragging != null))
            {
                BackgroundRenderer.RenderOutlines(frame, 59, true);
            }
        }