Exemple #1
0
        public RenderContext(SVGSVGElement drawing)
        {
            Drawing = drawing;

            // Create the tex too:
            Filter = new Loonim.SurfaceTexture();

            // Create the draw surface:
            DrawInfo = new Loonim.DrawInfo();
        }
 /// <summary>Sets a filter to apply. This is what rasterising elements is all for!</summary>
 public void SetFilter(Loonim.SurfaceTexture tex)
 {
     if (Renderer == null)
     {
         // We've now got a filter waiting for the renderer:
         PendingFilter = tex;
     }
     else
     {
         // Setting the filter will typically trigger an imagechange event.
         // That then updates the material image.
         Renderer.Filter = tex;
     }
 }
        /// <summary>Connects a filter to the camera's output.
        /// Fires an imagechange event too as this updates Texture to the filtered version.</summary>
        private void ConnectFilter()
        {
            if (Filter_ != null)
            {
                if (FilterDrawInfo == null)
                {
                    FilterDrawInfo = new Loonim.DrawInfo();
                }

                // Update draw info:
                FilterDrawInfo.SetSize(pixelWidth, pixelHeight);

                // Update source:
                Filter_.Set("source0", SourceCamera.targetTexture);

                // Reallocate the filter:
                Filter_.PreAllocate(FilterDrawInfo);

                // Grab the main output (always a RT):
                Texture = Filter_.Texture as RenderTexture;

                if (Texture == null)
                {
                    // This isn't a valid filter!
                    // It either had no nodes or e.g. e.g. a solid colour.
                    Debug.Log("Invalid filter was set to a FlatWorldUI - removed it.");
                    Filter_ = null;
                }
            }

            if (Filter_ == null)
            {
                // Clear draw info:
                FilterDrawInfo = null;

                // Revert to the camera's output:
                Texture = SourceCamera.targetTexture;
            }

            // Fire an imagechange event into the window:
            Dom.Event e = new Dom.Event("imagechange");
            e.SetTrusted(false);
            document.window.dispatchEvent(e);
        }
        /// <summary>Sets a filter to apply. This is what rasterising elements is all for!</summary>
        public void SetFilter(Loonim.SurfaceTexture tex)
        {
            Filter = tex;

            if (tex == null)
            {
                if (FilterDrawInfo != null)
                {
                    // Tidy it up:
                    tex.Clear();

                    FilterDrawInfo = null;
                }

                if (Renderer != null)
                {
                    // Update it now:
                    Output = Renderer.Texture;

                    if (Material != null)
                    {
                        // Hook up the output:
                        Material.SetTexture("_MainTex", Output);
                    }
                }
            }
            else
            {
                // Create the draw info (for GPU mode):
                FilterDrawInfo = new Loonim.DrawInfo();

                if (Renderer != null)
                {
                    // Update it now:
                    Filter.Set("source0", Renderer.Texture);

                    // Note that the next draw will update Output for us.
                }
            }
        }
        internal override void Layout(LayoutBox box, Renderman renderer)
        {
            // Dimensions:
            float width  = box.Width;
            float height = box.Height;

            if (Renderer == null)
            {
                // Create the FWUI now:
                Renderer = new FlatWorldUI("#Internal-PowerUI-Raster-" + RasterID, (int)width, (int)height);
                Renderer.Renderer.AllowLayout = false;
                RasterID++;

                // Add the listener:
                Renderer.document.window.addEventListener("imagechange", delegate(Dom.Event ev){
                    ChangedOutputEvent(ev);
                });

                if (PendingFilter != null)
                {
                    // Setting the filter will cause an imagechange event anyway:
                    Renderer.Filter = PendingFilter;
                    PendingFilter   = null;
                }
                else
                {
                    // Invoke our change event now:
                    Dom.Event e = new Dom.Event("imagechange");
                    e.SetTrusted(false);
                    ChangedOutputEvent(e);
                }
            }

            // Does the given renderer belong to the worldUI?
            if (renderer == Renderer.Renderer)
            {
                // Yes! We're actually drawing the element.
                return;
            }

            // Next we'll draw the rastered image.
            // It's essentially just the output from the renderer.

            // Get the top left inner corner (inside margin and border):
            float top  = box.Y;
            float left = box.X;

            // Update the FlatWorldUI next:
            UpdateRenderer(box, width, height);

            // Always isolated:
            Isolate();

            // Make sure the renderer stalls and doesn't draw anything else of this element or its kids.
            renderer.StallStatus = 2;

            // Setup boundary:
            BoxRegion boundary = new BoxRegion(left, top, width, height);

            if (!boundary.Overlaps(renderer.ClippingBoundary))
            {
                if (Visible)
                {
                    SetVisibility(false);
                }

                return;
            }
            else if (!Visible)
            {
                // ImageLocation will allocate here if it's needed.
                SetVisibility(true);
            }

            // Texture time - get its location on that atlas:
            if (LocatedAt == null)
            {
                LocatedAt = new AtlasLocation(width, height);
            }
            else
            {
                // Dimensions changed?
                int w = (int)width;
                int h = (int)height;

                if (LocatedAt.Width != w || LocatedAt.Height != h)
                {
                    // Update it:
                    LocatedAt.UpdateFixed(width, height);
                }
            }

            boundary.ClipBy(renderer.ClippingBoundary);

            // Ensure we have a batch:
            renderer.SetupBatch(this, null, null);

            if (Material == null)
            {
                // Create the material now using the isolated shader:
                Material = new Material(renderer.CurrentShaderSet.Isolated);

                // Hook up the output:
                Material.SetTexture("_MainTex", Output);
            }

            // Allocate the block:
            MeshBlock block = Add(renderer);

            // Set current material:
            SetBatchMaterial(renderer, Material);

            // Set the (overlay) colour:
            block.SetColour(renderer.ColorOverlay);
            block.TextUV = null;

            // Z-index (same as a background-image):
            float zIndex = (RenderData.computedStyle.ZIndex - 0.003f);

            BoxRegion screenRegion = new BoxRegion();

            screenRegion.Set(left, top, width, height);

            // Setup the block:
            block.ImageUV = block.SetClipped(boundary, screenRegion, renderer, zIndex, LocatedAt, block.ImageUV);

            // Flush it:
            block.Done(renderer.Transform);
        }