internal void ExecuteNonDrawMesh(DrawParams drawParams, float pixelsPerPoint, ref Exception immediateException)
        {
            switch (type)
            {
            case CommandType.ImmediateCull:
            {
                RectInt worldRect = RectPointsToPixelsAndFlipYAxis(owner.worldBound, pixelsPerPoint);
                if (!worldRect.Overlaps(Utility.GetActiveViewport()))
                {
                    break;
                }

                // Element isn't culled, follow through the normal immediate callback procedure
                goto case CommandType.Immediate;
            }

            case CommandType.Immediate:
            {
                if (immediateException != null)
                {
                    break;
                }

                Matrix4x4 oldProjection = Utility.GetUnityProjectionMatrix();
                bool      hasScissor    = drawParams.scissor.Count > 1; // We always expect the "unbound" scissor rectangle to exists
                if (hasScissor)
                {
                    Utility.DisableScissor();     // Disable scissor since most IMGUI code assume it's inactive
                }
                Utility.ProfileImmediateRendererBegin();
                try
                {
                    using (new GUIClip.ParentClipScope(owner.worldTransform, owner.worldClip))
                        callback();
                }
                catch (Exception e)
                {
                    immediateException = e;
                }

                GL.modelview = drawParams.view.Peek().transform;
                GL.LoadProjectionMatrix(oldProjection);
                Utility.ProfileImmediateRendererEnd();

                if (hasScissor)
                {
                    Utility.SetScissorRect(RectPointsToPixelsAndFlipYAxis(drawParams.scissor.Peek(), pixelsPerPoint));
                }
                break;
            }

            case CommandType.PushView:
                var vt = new ViewTransform()
                {
                    transform = owner.worldTransform, clipRect = RectToClipSpace(owner.worldClip)
                };
                drawParams.view.Push(vt);
                GL.modelview = vt.transform;
                break;

            case CommandType.PopView:
                drawParams.view.Pop();
                GL.modelview = drawParams.view.Peek().transform;
                break;

            case CommandType.PushScissor:
                Rect elemRect = CombineScissorRects(owner.worldClip, drawParams.scissor.Peek());
                drawParams.scissor.Push(elemRect);
                Utility.SetScissorRect(RectPointsToPixelsAndFlipYAxis(elemRect, pixelsPerPoint));
                break;

            case CommandType.PopScissor:
                drawParams.scissor.Pop();
                Rect prevRect = drawParams.scissor.Peek();
                if (prevRect.x == DrawParams.k_UnlimitedRect.x)
                {
                    Utility.DisableScissor();
                }
                else
                {
                    Utility.SetScissorRect(RectPointsToPixelsAndFlipYAxis(prevRect, pixelsPerPoint));
                }
                break;

            case CommandType.PushRenderTexture:
            {
                RectInt       viewport = Utility.GetActiveViewport();
                RenderTexture rt       = RenderTexture.GetTemporary(viewport.width, viewport.height, 24, RenderTextureFormat.ARGBHalf);
                RenderTexture.active = rt;
                GL.Clear(true, true, new Color(0, 0, 0, 0), UIRUtility.k_ClearZ);
                drawParams.renderTexture.Add(RenderTexture.active);
                break;
            }

            case CommandType.PopRenderTexture:
            {
                int index = drawParams.renderTexture.Count - 1;
                Debug.Assert(index > 0);        //Check that we have something to pop, We should never pop the last(original)one

                // Only supported use case for now is to do a blit befor the pop.
                // This should set the active RenderTexture to index-1 and we should not have this warning.
                Debug.Assert(drawParams.renderTexture[index - 1] == RenderTexture.active, "Content of previous render texture was probably not blitted");

                var rt = drawParams.renderTexture[index];
                if (rt != null)
                {
                    RenderTexture.ReleaseTemporary(rt);
                }
                drawParams.renderTexture.RemoveAt(index);
            }
            break;

            case CommandType.BlitToPreviousRT:
            {
                // Currently the command only blit to the previous RT, but this could be expanded if we use
                // indexCount and indexOffset to point to specific indices in the renderTextureBuffer.
                // The main difficulty is to memorize the current renderTexture depth to get the indices in the RenderChain
                // as we can edit the stack in the middle and that would requires rewriting previous/ subsequent commands

                //Also, there is currently no way to have a permanently assigned rt to be used as cache.

                var source      = drawParams.renderTexture[drawParams.renderTexture.Count - 1];
                var destination = drawParams.renderTexture[drawParams.renderTexture.Count - 2];


                // Note: Graphics.Blit set the arctive RT => RT is not restored and it is expected to be chaged before PopRenderTexture
                //TODO check blit code for other side effect
                Debug.Assert(source == RenderTexture.active, "Unexpected render target change: Current renderTarget is not the one on the top of the stack");

                //The following lines are equivalent to
                //Graphics.Blit(source, destination, state.material);
                //except the vertex are at the specified depth
                var flipped = (indexOffset != 0);
                Blit(source, destination, UIRUtility.k_MeshPosZ, flipped);
            }
            break;

//Logic of both command is entirely in UIRenderDevice as it need access to the local variable defaultMat
            case CommandType.PushDefaultMaterial:
                break;

            case CommandType.PopDefaultMaterial:
                break;
            }
        }
Beispiel #2
0
        internal void ExecuteNonDrawMesh(DrawParams drawParams, float pixelsPerPoint, ref Exception immediateException)
        {
            switch (this.type)
            {
            case CommandType.ImmediateCull:
            {
                bool flag = !RenderChainCommand.RectPointsToPixelsAndFlipYAxis(this.owner.worldBound, pixelsPerPoint).Overlaps(Utility.GetActiveViewport());
                if (flag)
                {
                    return;
                }
                break;
            }

            case CommandType.Immediate:
                break;

            case CommandType.PushView:
            {
                ViewTransform viewTransform = new ViewTransform
                {
                    transform = this.owner.worldTransform,
                    clipRect  = RenderChainCommand.RectToClipSpace(this.owner.worldClip)
                };
                drawParams.view.Push(viewTransform);
                GL.modelview = viewTransform.transform;
                return;
            }

            case CommandType.PopView:
                drawParams.view.Pop();
                GL.modelview = drawParams.view.Peek().transform;
                return;

            case CommandType.PushScissor:
            {
                Rect rect = RenderChainCommand.CombineScissorRects(this.owner.worldClip, drawParams.scissor.Peek());
                drawParams.scissor.Push(rect);
                Utility.SetScissorRect(RenderChainCommand.RectPointsToPixelsAndFlipYAxis(rect, pixelsPerPoint));
                return;
            }

            case CommandType.PopScissor:
            {
                drawParams.scissor.Pop();
                Rect rect2 = drawParams.scissor.Peek();
                bool flag2 = rect2.x == DrawParams.k_UnlimitedRect.x;
                if (flag2)
                {
                    Utility.DisableScissor();
                }
                else
                {
                    Utility.SetScissorRect(RenderChainCommand.RectPointsToPixelsAndFlipYAxis(rect2, pixelsPerPoint));
                }
                return;
            }

            default:
                return;
            }
            bool flag3 = immediateException != null;

            if (!flag3)
            {
                Matrix4x4 unityProjectionMatrix = Utility.GetUnityProjectionMatrix();
                bool      flag4 = drawParams.scissor.Count > 1;
                bool      flag5 = flag4;
                if (flag5)
                {
                    Utility.DisableScissor();
                }
                Utility.ProfileImmediateRendererBegin();
                try
                {
                    using (new GUIClip.ParentClipScope(this.owner.worldTransform, this.owner.worldClip))
                    {
                        this.callback();
                    }
                }
                catch (Exception ex)
                {
                    immediateException = ex;
                }
                GL.modelview = drawParams.view.Peek().transform;
                GL.LoadProjectionMatrix(unityProjectionMatrix);
                Utility.ProfileImmediateRendererEnd();
                bool flag6 = flag4;
                if (flag6)
                {
                    Utility.SetScissorRect(RenderChainCommand.RectPointsToPixelsAndFlipYAxis(drawParams.scissor.Peek(), pixelsPerPoint));
                }
            }
        }
        internal void ExecuteNonDrawMesh(DrawParams drawParams, float pixelsPerPoint, ref Exception immediateException)
        {
            switch (type)
            {
            case CommandType.ImmediateCull:
            {
                if (!owner.worldBound.Overlaps(drawParams.viewport))
                {
                    break;
                }

                // Element isn't culled, follow through the normal immediate callback procedure
                goto case CommandType.Immediate;
            }

            case CommandType.Immediate:
            {
                if (immediateException != null)
                {
                    break;
                }

                Matrix4x4 oldProjection = Utility.GetUnityProjectionMatrix();
                bool      hasScissor    = drawParams.scissor.Count > 1; // We always expect the "unbound" scissor rectangle to exists
                if (hasScissor)
                {
                    Utility.DisableScissor();     // Disable scissor since most IMGUI code assume it's inactive
                }
                Utility.ProfileImmediateRendererBegin();
                try
                {
                    using (new GUIClip.ParentClipScope(owner.worldTransform, owner.worldClip))
                        callback();
                }
                catch (Exception e)
                {
                    immediateException = e;
                }

                GL.modelview = drawParams.view.Peek().transform;
                GL.LoadProjectionMatrix(oldProjection);
                Utility.ProfileImmediateRendererEnd();

                if (hasScissor)
                {
                    Utility.SetScissorRect(RectPointsToPixelsAndFlipYAxis(drawParams.scissor.Peek(), drawParams.viewport, pixelsPerPoint));
                }
                break;
            }

            case CommandType.PushView:
                var vt = new ViewTransform()
                {
                    transform = owner.worldTransform, clipRect = RectToClipSpace(owner.worldClip)
                };
                drawParams.view.Push(vt);
                GL.modelview = vt.transform;
                break;

            case CommandType.PopView:
                drawParams.view.Pop();
                GL.modelview = drawParams.view.Peek().transform;
                break;

            case CommandType.PushScissor:
                Rect elemRect = CombineScissorRects(owner.worldClip, drawParams.scissor.Peek());
                drawParams.scissor.Push(elemRect);
                Utility.SetScissorRect(RectPointsToPixelsAndFlipYAxis(elemRect, drawParams.viewport, pixelsPerPoint));
                break;

            case CommandType.PopScissor:
                drawParams.scissor.Pop();
                Rect prevRect = drawParams.scissor.Peek();
                if (prevRect.x == DrawParams.k_UnlimitedRect.x)
                {
                    Utility.DisableScissor();
                }
                else
                {
                    Utility.SetScissorRect(RectPointsToPixelsAndFlipYAxis(prevRect, drawParams.viewport, pixelsPerPoint));
                }
                break;
            }
        }
        internal void ExecuteNonDrawMesh(DrawParams drawParams, bool straightY, ref Exception immediateException)
        {
            switch (type)
            {
            case CommandType.Immediate:
            {
                if (immediateException != null)
                {
                    break;
                }

                bool hasScissor = drawParams.scissor.Count > 1;     // We always expect the "unbound" scissor rectangle to exists
                if (hasScissor)
                {
                    Utility.DisableScissor();     // Disable scissor since most IMGUI code assume it's inactive
                }
                Utility.ProfileImmediateRendererBegin();
                try
                {
                    using (new GUIClip.ParentClipScope(owner.worldTransform, owner.worldClip))
                        callback();
                }
                catch (Exception e)
                {
                    immediateException = e;
                }

                GL.modelview = drawParams.view.Peek().transform;
                GL.LoadProjectionMatrix(drawParams.projection);
                Utility.ProfileImmediateRendererEnd();

                if (hasScissor)
                {
                    Utility.SetScissorRect(FlipRectYAxis(drawParams.scissor.Peek(), drawParams.viewport));
                }
                break;
            }

            case CommandType.PushView:
                var vt = new ViewTransform()
                {
                    transform = owner.worldTransform, clipRect = RectToScreenSpace(owner.worldClip, drawParams.projection, straightY)
                };
                drawParams.view.Push(vt);
                GL.modelview = vt.transform;
                break;

            case CommandType.PopView:
                drawParams.view.Pop();
                GL.modelview = drawParams.view.Peek().transform;
                break;

            case CommandType.PushScissor:
                Rect elemRect = CombineScissorRects(owner.worldBound, drawParams.scissor.Peek());
                drawParams.scissor.Push(elemRect);
                Utility.SetScissorRect(FlipRectYAxis(elemRect, drawParams.viewport));
                break;

            case CommandType.PopScissor:
                drawParams.scissor.Pop();
                Rect prevRect = drawParams.scissor.Peek();
                if (prevRect.x == DrawParams.k_UnlimitedRect.x)
                {
                    Utility.DisableScissor();
                }
                else
                {
                    Utility.SetScissorRect(FlipRectYAxis(prevRect, drawParams.viewport));
                }
                break;
            }
        }