From 59321fc574686590c9b9f924dccdbd24b4c30fed Mon Sep 17 00:00:00 2001 From: luboslenco Date: Thu, 19 Mar 2020 17:32:30 +0100 Subject: [PATCH] Fix layer copy --- Sources/arm/data/LayerSlot.hx | 22 ++++++++++++++++++++-- Sources/arm/io/ImportArm.hx | 10 ++++++++++ Sources/arm/ui/TabTextures.hx | 3 +++ Sources/arm/ui/UISidebar.hx | 8 ++++++++ Sources/arm/util/RenderUtil.hx | 3 +++ 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Sources/arm/data/LayerSlot.hx b/Sources/arm/data/LayerSlot.hx index d0d569db..0b2386c9 100644 --- a/Sources/arm/data/LayerSlot.hx +++ b/Sources/arm/data/LayerSlot.hx @@ -173,8 +173,12 @@ class LayerSlot { texpaint_mask.g2.begin(); - if (createMaskImage != null) texpaint_mask.g2.drawScaledImage(createMaskImage, 0, 0, texpaint_mask.width, texpaint_mask.height); - else texpaint_mask.g2.clear(createMaskColor); + if (createMaskImage != null) { + texpaint_mask.g2.drawScaledImage(createMaskImage, 0, 0, texpaint_mask.width, texpaint_mask.height); + } + else { + texpaint_mask.g2.clear(createMaskColor); + } texpaint_mask.g2.end(); g.begin(); @@ -249,7 +253,9 @@ class LayerSlot { l.texpaint_pack.g2.end(); l.texpaint_preview.g2.begin(true, 0x00000000); + l.texpaint_preview.g2.pipeline = Layers.pipeCopy; l.texpaint_preview.g2.drawScaledImage(texpaint_preview, 0, 0, texpaint_preview.width, texpaint_preview.height); + l.texpaint_preview.g2.pipeline = null; l.texpaint_preview.g2.end(); if (texpaint_mask != null) { @@ -261,7 +267,9 @@ class LayerSlot { l.texpaint_mask.g2.end(); l.texpaint_mask_preview.g2.begin(true, 0x00000000); + l.texpaint_mask_preview.g2.pipeline = Layers.pipeCopy; l.texpaint_mask_preview.g2.drawScaledImage(texpaint_mask_preview, 0, 0, texpaint_mask_preview.width, texpaint_mask_preview.height); + l.texpaint_mask_preview.g2.pipeline = null; l.texpaint_mask_preview.g2.end(); } @@ -299,16 +307,24 @@ class LayerSlot { this.texpaint_nor = Image.createRenderTarget(res, res, format); this.texpaint_pack = Image.createRenderTarget(res, res, format); + if (Layers.pipeMerge == null) Layers.makePipe(); + this.texpaint.g2.begin(false); + this.texpaint.g2.pipeline = Layers.pipeCopy; this.texpaint.g2.drawScaledImage(texpaint, 0, 0, res, res); + this.texpaint.g2.pipeline = null; this.texpaint.g2.end(); this.texpaint_nor.g2.begin(false); + this.texpaint_nor.g2.pipeline = Layers.pipeCopy; this.texpaint_nor.g2.drawScaledImage(texpaint_nor, 0, 0, res, res); + this.texpaint_nor.g2.pipeline = null; this.texpaint_nor.g2.end(); this.texpaint_pack.g2.begin(false); + this.texpaint_pack.g2.pipeline = Layers.pipeCopy; this.texpaint_pack.g2.drawScaledImage(texpaint_pack, 0, 0, res, res); + this.texpaint_pack.g2.pipeline = null; this.texpaint_pack.g2.end(); iron.App.notifyOnInit(function() { // Out of command list execution @@ -326,7 +342,9 @@ class LayerSlot { this.texpaint_mask = Image.createRenderTarget(res, res, TextureFormat.L8); this.texpaint_mask.g2.begin(false); + this.texpaint_mask.g2.pipeline = Layers.pipeCopy; this.texpaint_mask.g2.drawScaledImage(texpaint_mask, 0, 0, res, res); + this.texpaint_mask.g2.pipeline = null; this.texpaint_mask.g2.end(); iron.App.notifyOnInit(function() { // Out of command list execution diff --git a/Sources/arm/io/ImportArm.hx b/Sources/arm/io/ImportArm.hx index e7a27c09..8b21d554 100644 --- a/Sources/arm/io/ImportArm.hx +++ b/Sources/arm/io/ImportArm.hx @@ -206,20 +206,28 @@ class ImportArm { Project.layers.push(l); if (!isGroup) { + if (Layers.pipeMerge == null) Layers.makePipe(); + // TODO: create render target from bytes var texpaint = Image.fromBytes(Lz4.decode(ld.texpaint, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format); l.texpaint.g2.begin(false); + l.texpaint.g2.pipeline = Layers.pipeCopy; l.texpaint.g2.drawImage(texpaint, 0, 0); + l.texpaint.g2.pipeline = null; l.texpaint.g2.end(); var texpaint_nor = Image.fromBytes(Lz4.decode(ld.texpaint_nor, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format); l.texpaint_nor.g2.begin(false); + l.texpaint_nor.g2.pipeline = Layers.pipeCopy; l.texpaint_nor.g2.drawImage(texpaint_nor, 0, 0); + l.texpaint_nor.g2.pipeline = null; l.texpaint_nor.g2.end(); var texpaint_pack = Image.fromBytes(Lz4.decode(ld.texpaint_pack, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format); l.texpaint_pack.g2.begin(false); + l.texpaint_pack.g2.pipeline = Layers.pipeCopy; l.texpaint_pack.g2.drawImage(texpaint_pack, 0, 0); + l.texpaint_pack.g2.pipeline = null; l.texpaint_pack.g2.end(); var texpaint_mask: kha.Image = null; @@ -227,7 +235,9 @@ class ImportArm { l.createMask(0, false); texpaint_mask = Image.fromBytes(Lz4.decode(ld.texpaint_mask, ld.res * ld.res), ld.res, ld.res, TextureFormat.L8); l.texpaint_mask.g2.begin(false); + l.texpaint_mask.g2.pipeline = Layers.pipeCopy; l.texpaint_mask.g2.drawImage(texpaint_mask, 0, 0); + l.texpaint_mask.g2.pipeline = null; l.texpaint_mask.g2.end(); } diff --git a/Sources/arm/ui/TabTextures.hx b/Sources/arm/ui/TabTextures.hx index b509f263..b4c0ac4e 100644 --- a/Sources/arm/ui/TabTextures.hx +++ b/Sources/arm/ui/TabTextures.hx @@ -87,8 +87,11 @@ class TabTextures { UIFiles.show("png", true, function(path: String) { var target = kha.Image.createRenderTarget(img.width, img.height); function exportTexture(g: kha.graphics4.Graphics) { + if (Layers.pipeMerge == null) Layers.makePipe(); target.g2.begin(false); + target.g2.pipeline = Layers.pipeCopy; target.g2.drawImage(img, 0, 0); + target.g2.pipeline = null; target.g2.end(); var f = UIFiles.filename; if (f == "") f = tr("untitled"); diff --git a/Sources/arm/ui/UISidebar.hx b/Sources/arm/ui/UISidebar.hx index 150e2286..1d7082ce 100644 --- a/Sources/arm/ui/UISidebar.hx +++ b/Sources/arm/ui/UISidebar.hx @@ -777,6 +777,7 @@ class UISidebar { if (Context.layersPreviewDirty) { Context.layersPreviewDirty = false; Context.layerPreviewDirty = false; + if (Layers.pipeMerge == null) Layers.makePipe(); // Update all layer previews for (l in Project.layers) { if (l.getChildren() != null) continue; @@ -784,14 +785,18 @@ class UISidebar { var source = l.texpaint; var g2 = target.g2; g2.begin(true, 0xff000000); + g2.pipeline = Layers.pipeCopy; g2.drawScaledImage(source, 0, 0, target.width, target.height); + g2.pipeline = null; g2.end(); if (l.texpaint_mask != null) { var target = l.texpaint_mask_preview; var source = l.texpaint_mask; var g2 = target.g2; g2.begin(true, 0x00000000); + g2.pipeline = Layers.pipeCopy; g2.drawScaledImage(source, 0, 0, target.width, target.height); + g2.pipeline = null; g2.end(); } } @@ -799,13 +804,16 @@ class UISidebar { } if (Context.layerPreviewDirty && Context.layer.getChildren() == null) { Context.layerPreviewDirty = false; + if (Layers.pipeMerge == null) Layers.makePipe(); // Update layer preview var l = Context.layer; var target = Context.layerIsMask ? l.texpaint_mask_preview : l.texpaint_preview; var source = Context.layerIsMask ? l.texpaint_mask : l.texpaint; var g2 = target.g2; g2.begin(true, 0x00000000); + g2.pipeline = Layers.pipeCopy; g2.drawScaledImage(source, 0, 0, target.width, target.height); + g2.pipeline = null; g2.end(); hwnd.redraws = 2; } diff --git a/Sources/arm/util/RenderUtil.hx b/Sources/arm/util/RenderUtil.hx index 7d7d7639..d9916412 100644 --- a/Sources/arm/util/RenderUtil.hx +++ b/Sources/arm/util/RenderUtil.hx @@ -345,10 +345,13 @@ class RenderUtil { RenderPathPaint.useLiveLayer(false); // Scale layer down to to image preview + if (Layers.pipeMerge == null) Layers.makePipe(); var l = RenderPathPaint.liveLayer; var target = Context.brush.image; target.g2.begin(true, 0x00000000); + target.g2.pipeline = Layers.pipeCopy; target.g2.drawScaledImage(l.texpaint, 0, 0, target.width, target.height); + target.g2.pipeline = null; target.g2.end(); // Scale image preview down to to icon