Ejemplo n.º 1
0
        protected internal override Lime.RenderObject GetRenderObject()
        {
            var blending = GlobalBlending;
            var shader   = GlobalShader;

            if (material == null)
            {
                material = WidgetMaterial.GetInstance(blending, shader, 1);
            }
            var UV1 = new Vector2 {
                X = Size.X / texture.ImageSize.Width * TileRatio.X + TileOffset.X,
                Y = Size.Y / texture.ImageSize.Height * TileRatio.Y + TileOffset.Y
            };

            if (TileRounding)
            {
                UV1.X = (float)Math.Truncate(UV1.X);
                UV1.Y = (float)Math.Truncate(UV1.Y);
            }
            var ro = RenderObjectPool <RenderObject> .Acquire();

            ro.CaptureRenderState(this);
            ro.Texture    = Texture;
            ro.Material   = CustomMaterial ?? material;
            ro.TileOffset = TileOffset;
            ro.UV1        = UV1;
            ro.Color      = GlobalColor;
            ro.Position   = ContentPosition;
            ro.Size       = ContentSize;
            return(ro);
        }
Ejemplo n.º 2
0
        public static void DrawDashedLine(ITexture texture, Vector2 a, Vector2 b, Color4 color, float size = 8)
        {
            var dir = (b - a).Normalized;
            var l   = (b - a).Length;
            var n   = GetVectorNormal(dir) * size / 2;

            Vertex[] vertices =
            {
                new Vertex {
                    Pos   = a - n,
                    UV1   = Vector2.Zero,
                    Color = color,
                },
                new Vertex {
                    Pos   = a + n,
                    UV1   = new Vector2(0, 1),
                    Color = color,
                },
                new Vertex {
                    Pos   = b + n,
                    UV1   = new Vector2(l / size, 1),
                    Color = color,
                },
                new Vertex {
                    Pos   = b - n,
                    UV1   = new Vector2(l / size, 0),
                    Color = color,
                }
            };
            DrawTriangleFan(WidgetMaterial.GetInstance(Blending.None, ShaderId.Diffuse, texture1: texture), vertices, vertices.Length);
        }
Ejemplo n.º 3
0
        public static void DrawSprite(ITexture texture1, Color4 color, Vector2 position, Vector2 size, Vector2 uv0, Vector2 uv1)
        {
            var material = WidgetMaterial.GetInstance(Blending, Shader, CustomShaderProgram, texture1, null);

            texture1?.TransformUVCoordinatesToAtlasSpace(ref uv0);
            texture1?.TransformUVCoordinatesToAtlasSpace(ref uv1);
            DrawSprite(material, color, position, size, uv0, uv1, Vector2.Zero, Vector2.Zero);
        }
Ejemplo n.º 4
0
 public IMaterial GetMaterial(ITexture texture, int tag)
 {
     if (texture != this.texture)
     {
         this.texture = texture;
         material     = WidgetMaterial.GetInstance(blending, shader, null, texture);
     }
     return(material);
 }
Ejemplo n.º 5
0
        protected internal override Lime.RenderObject GetRenderObject()
        {
            if (Parent.AsWidget == null)
            {
                return(null);
            }
            IImageCombinerArg arg1, arg2;

            if (!GetArgs(out arg1, out arg2))
            {
                return(null);
            }
            if (!arg1.GloballyVisible || !arg2.GloballyVisible)
            {
                return(null);
            }
            var texture1 = arg1.GetTexture();
            var texture2 = arg2.GetTexture();

            if (texture1 == null || texture2 == null)
            {
                return(null);
            }
            var ro = RenderObjectPool <RenderObject> .Acquire();

            ro.Arg12CommonMaterial = CustomMaterial;
            ro.Arg1Material        = CustomMaterial;
            if (ro.Arg1Material == null)
            {
                var shader = Shader == ShaderId.Inherited ? Parent.AsWidget.GlobalShader : Shader;
                if (arg2.Shader == ShaderId.Silhuette)
                {
                    shader = ShaderId.Silhuette;
                }
                else if (arg1.Shader == ShaderId.Silhuette)
                {
                    shader = ShaderId.Silhuette;
                    Toolbox.Swap(ref arg1, ref arg2);
                    Toolbox.Swap(ref texture1, ref texture2);
                }
                var blending = Blending == Blending.Inherited ? Parent.AsWidget.GlobalBlending : Blending;
                ro.Arg1Material        = WidgetMaterial.GetInstance(blending, shader, WidgetMaterial.GetNumTextures(texture1, null));
                ro.Arg12CommonMaterial = WidgetMaterial.GetInstance(
                    blending, shader, WidgetMaterial.GetNumTextures(texture1, texture2),
                    Operation == ImageCombinerOperation.Multiply ? TextureBlending.Multiply : TextureBlending.CutOut);
            }
            ro.Arg1Texture           = texture1;
            ro.Arg2Texture           = texture2;
            ro.Operation             = Operation;
            ro.Arg1Transform         = Matrix32.Scaling(arg1.Size) * arg1.CalcLocalToParentTransform();
            ro.Arg2Transform         = Matrix32.Scaling(arg2.Size) * arg2.CalcLocalToParentTransform();
            ro.Arg1UVTransform       = arg1.UVTransform;
            ro.Arg2UVTransform       = arg2.UVTransform;
            ro.LocalToWorldTransform = Parent.AsWidget.LocalToWorldTransform;
            ro.Color = arg1.Color * arg2.Color * Parent.AsWidget.GlobalColor;
            return(ro);
        }
Ejemplo n.º 6
0
 public IMaterial GetMaterial(ITexture texture, int tag)
 {
     if (texture != this.texture)
     {
         this.texture = texture;
         var shaderProg = ShaderPrograms.ColorfulTextShaderProgram.GetShaderProgram(paletteIndex);
         material = WidgetMaterial.GetInstance(
             blending, shaderProg, texture,
             ShaderPrograms.ColorfulTextShaderProgram.GradientRampTexture);
     }
     return(material);
 }
Ejemplo n.º 7
0
 public static WidgetMaterial GetInstance(Blending blending, ShaderId shader, int numTextures, bool premulAlpha = false)
 {
     lock (instanceCache) {
         var            instanceKey = GetInstanceKey(blending, shader, numTextures, premulAlpha);
         WidgetMaterial instance;
         if (!instanceCache.TryGetValue(instanceKey, out instance))
         {
             instance = new WidgetMaterial(blending, shader, numTextures, premulAlpha);
             instanceCache.Add(instanceKey, instance);
         }
         return(instance);
     }
 }
Ejemplo n.º 8
0
        public static void DrawTriangleStrip(ITexture texture1, ITexture texture2, Vertex[] vertices, int numVertices)
        {
            var material = WidgetMaterial.GetInstance(Blending, Shader, CustomShaderProgram, texture1, texture2);
            var batch    = DrawTriangleStripHelper(material, vertices, numVertices);
            var vd       = batch.VertexBuffer.Data;

            for (int i = 0; i < numVertices; i++)
            {
                var t = batch.LastVertex - numVertices + i;
                texture1?.TransformUVCoordinatesToAtlasSpace(ref vd[t].UV1);
                texture2?.TransformUVCoordinatesToAtlasSpace(ref vd[t].UV2);
            }
        }
Ejemplo n.º 9
0
 private IMaterial GetMaterial(Widget widget, PostProcessingComponent component)
 {
     if (component.CustomMaterial != null)
     {
         return(component.CustomMaterial);
     }
     if (material != null && blending == widget.GlobalBlending && shader == widget.GlobalShader)
     {
         return(material);
     }
     blending = widget.GlobalBlending;
     shader   = widget.GlobalShader;
     return(material = WidgetMaterial.GetInstance(blending, shader, 1));
 }
Ejemplo n.º 10
0
        public WidgetMaterial GetInstance(Blending blending, ShaderProgram shaderProgram, ITexture texture1, ITexture texture2, bool premulAlpha)
        {
            foreach (var i in items)
            {
                if (i.Blending == blending && i.ShaderProgram == shaderProgram && i.Texture1 == texture1 && i.Texture2 == texture2)
                {
                    return(i);
                }
            }
            var wm = new WidgetMaterial(blending, shaderProgram, texture1, texture2, premulAlpha);

            Array.Resize(ref items, items.Length + 1);
            items[items.Length - 1] = wm;
            return(wm);
        }
Ejemplo n.º 11
0
        public override void Render()
        {
            var blending = GlobalBlending;
            var shader   = GlobalShader;

            if (material == null)
            {
                material = WidgetMaterial.GetInstance(blending, shader, null, Texture);
            }
            Renderer.Transform1 = LocalToWorldTransform;
            var uv0 = UV0;
            var uv1 = UV1;

            texture.TransformUVCoordinatesToAtlasSpace(ref uv0);
            texture.TransformUVCoordinatesToAtlasSpace(ref uv1);
            Renderer.DrawSprite(material, GlobalColor, ContentPosition, ContentSize, uv0, uv1, Vector2.Zero, Vector2.Zero);
        }
Ejemplo n.º 12
0
            public IMaterial GetMaterial(int tag)
            {
                var styleGradientMapIndex = gradientMapIndices[tag];

                if (material == null || gradientMapIndex != styleGradientMapIndex)
                {
                    gradientMapIndex = styleGradientMapIndex;
                    if (gradientMapIndex < 0)
                    {
                        material = WidgetMaterial.GetInstance(blending, shader, 1);
                    }
                    else
                    {
                        material = ColorfulTextMaterial.GetInstance(blending, gradientMapIndex);
                    }
                }
                return(material);
            }
Ejemplo n.º 13
0
        public override void Render()
        {
            if (Parent.AsWidget == null)
            {
                return;
            }
            IImageCombinerArg arg1, arg2;

            if (!GetArgs(out arg1, out arg2))
            {
                return;
            }
            if (!arg1.GloballyVisible || !arg2.GloballyVisible)
            {
                return;
            }
            var texture1 = arg1.GetTexture();
            var texture2 = arg2.GetTexture();

            if (texture1 == null || texture2 == null)
            {
                return;
            }
            Renderer.Transform1 = Parent.AsWidget.LocalToWorldTransform;
            var blending = Blending == Blending.Inherited ? Parent.AsWidget.GlobalBlending : Blending;
            var shader   = Shader == ShaderId.Inherited ? Parent.AsWidget.GlobalShader : Shader;

            if (arg2.Shader == ShaderId.Silhuette)
            {
                shader = ShaderId.Silhuette;
            }
            else if (arg1.Shader == ShaderId.Silhuette)
            {
                shader = ShaderId.Silhuette;
                Toolbox.Swap(ref arg1, ref arg2);
                Toolbox.Swap(ref texture1, ref texture2);
            }
            var material = WidgetMaterial.GetInstance(blending, shader, CustomShaderProgram, texture1, texture2);

            RenderHelper(arg1, arg2, material, texture1, texture2);
        }
Ejemplo n.º 14
0
        protected internal override Lime.RenderObject GetRenderObject()
        {
            var blending = GlobalBlending;
            var shader   = GlobalShader;

            if (material == null)
            {
                material = WidgetMaterial.GetInstance(blending, shader, 1);
            }
            var ro = RenderObjectPool <RenderObject> .Acquire();

            ro.Texture  = Texture;
            ro.Material = CustomMaterial ?? material;
            ro.UV0      = UV0;
            ro.UV1      = UV1;
            ro.LocalToWorldTransform = LocalToWorldTransform;
            ro.Position = ContentPosition;
            ro.Size     = ContentSize;
            ro.Color    = GlobalColor;
            return(ro);
        }
Ejemplo n.º 15
0
            public IMaterial GetMaterial(ITexture texture, int tag)
            {
                var style = textRenderer.Styles[tag];

                if (texture != this.texture || paletteIndex != style.PaletteIndex)
                {
                    this.texture      = texture;
                    this.paletteIndex = style.PaletteIndex;
                    if (paletteIndex < 0)
                    {
                        material = WidgetMaterial.GetInstance(blending, shader, null, texture);
                    }
                    else
                    {
                        var shaderProg = ShaderPrograms.ColorfulTextShaderProgram.GetShaderProgram(paletteIndex);
                        material = WidgetMaterial.GetInstance(
                            blending, shaderProg, texture,
                            ShaderPrograms.ColorfulTextShaderProgram.GradientRampTexture);
                    }
                }
                return(material);
            }
Ejemplo n.º 16
0
 public void Init(Blending blending, ShaderId shader)
 {
     material = WidgetMaterial.GetInstance(blending, shader, 1);
 }
Ejemplo n.º 17
0
 private static WidgetMaterial GetMaterial(int numTextures)
 {
     return(WidgetMaterial.GetInstance(Blending, Shader, numTextures));
 }