Example #1
0
        RenderTextureBackup takeRenderTexture()
        {
            int index = rtex.Count - 1;
            RenderTextureBackup rt = rtex [index];

            rtex.RemoveAt(index);
            return(rt);
        }
Example #2
0
        public void ApplyTo(ImageData id)
        {
            bool fromRT = (tex2D.Count == 0) || ((rtex.Count > 0) && (tex2D [tex2D.Count - 1].order < rtex [rtex.Count - 1].order));

            bool toRT = id.destination == TexTarget.RenderTexture;

            int toClear = id.recordedStrokes_forUndoRedo.Count;

            if (toRT)
            {
                otherDirection.backupRenderTexture(int.MaxValue, id);
            }
            else
            {
                otherDirection.backupTexture2D(int.MaxValue, id);
            }


            RenderTextureBackup rtBackup  = fromRT ? takeRenderTexture() : null;
            Texture2DBackup     pixBackup = fromRT ? null : takeTexture2D();
            TextureBackup       backup    = fromRT ? (TextureBackup)rtBackup : (TextureBackup)pixBackup;



            if (!isUndo)
            {
                id.recordedStrokes.AddRange(backup.strokeRecord);
            }
            else
            {
                id.recordedStrokes.RemoveLast(toClear);
            }

            id.recordedStrokes_forUndoRedo = backup.strokeRecord;

            /*  if (isUndo) {
             *
             *
             * } else {
             *    id.recordedStrokes.AddRange(backup.strokeRecord);
             *    id.recordedStrokes_forUndoRedo.AddRange(backup.strokeRecord);
             * }*/


            if (!fromRT)
            {
                id.Pixels = (Color[])pixBackup.pixels;//.Clone();
                id.SetAndApply(true);
            }

            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);

                bool converted = false;

                if ((PainterCamera.Inst.isLinearColorSpace) && (!rtBackup.exclusive))
                {
                    converted = true;
                    id.PixelsToGamma();
                }
                //else
                //   id.pixelsToLinear();
                // if (!RenderTexturePainter.inst.isLinearColorSpace)
                //{
                //  Debug.Log("Pixels to lnear");

                //   id.pixelsToLinear();
                //}

                // In Linear dont turn to gamma if saved from Exclusive Render Texture
                if (converted)
                {
                    id.SetAndApply(true);
                }
                else
                {
                    id.texture2D.Apply(true);
                }
            }

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