Beispiel #1
0
            public void ApplyTo(TextureMeta id)
            {
                var fromRt = (tex2D.Count == 0) ||
                             ((rTex.Count > 0) && (tex2D[tex2D.Count - 1].order < rTex[rTex.Count - 1].order));

                var toRt = id.target == TexTarget.RenderTexture;

                if (toRt)
                {
                    otherDirection.BackupRenderTexture(int.MaxValue, id);
                }
                else
                {
                    otherDirection.BackupTexture2D(int.MaxValue, id);
                }

                var rtBackup  = fromRt ? TakeRenderTexture() : null;
                var pixBackup = fromRt ? null : TakeTexture2D();
                var backup    = fromRt ? rtBackup : (TextureBackup)pixBackup;

                if (isUndo)
                {
                    foreach (var module in id.Modules)
                    {
                        module.OnUndo(backup);
                    }
                }
                else
                {
                    foreach (var module in id.Modules)
                    {
                        module.OnRedo(backup);
                    }
                }

                if (!fromRt)
                {
                    id.Pixels = pixBackup.pixels;
                    id.SetAndApply();
                }

                if (toRt)
                {
                    if (fromRt)
                    {
                        Rtp.Render(rtBackup.rt, id);
                    }
                    else
                    {
                        Rtp.Render(id.texture2D, id);
                    }
                }
                else if (fromRt)
                {
                    id.texture2D.CopyFrom(rtBackup.rt);
                    id.PixelsFromTexture2D(id.texture2D);

                    var converted = false;

                    if ((PainterCamera.Inst.IsLinearColorSpace) && !rtBackup.exclusive)
                    {
                        converted = true;
                        id.PixelsToGamma();
                    }

                    if (converted)
                    {
                        id.SetAndApply();
                    }
                    else
                    {
                        id.texture2D.Apply(true);
                    }
                }

                if (fromRt)
                {
                    rtBackup.DestroyRtex();
                }
            }