From f3c2a606497f7ff55edbd5f8e011b8bec9ff0d78 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sat, 16 Jan 2021 16:48:33 +0100 Subject: [PATCH] Cloud asset icon cutout --- Sources/arm/Layers.hx | 14 ++++++++++++++ Sources/arm/ui/UIFiles.hx | 13 +++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Sources/arm/Layers.hx b/Sources/arm/Layers.hx index 31efc57c..5cdc38e5 100644 --- a/Sources/arm/Layers.hx +++ b/Sources/arm/Layers.hx @@ -31,6 +31,7 @@ class Layers { public static var pipeCopy8: PipelineState; public static var pipeCopy128: PipelineState; public static var pipeCopyBGRA: PipelineState; + public static var pipeCopyRGB: PipelineState = null; public static var pipeInvert8: PipelineState; public static var pipeMask: PipelineState; public static var tex0: TextureUnit; @@ -218,6 +219,19 @@ class Layers { texaMask = pipeMask.getTextureUnit("texa"); } + public static function makePipeCopyRGB() { + pipeCopyRGB = new PipelineState(); + pipeCopyRGB.vertexShader = kha.Shaders.getVertex("layer_view.vert"); + pipeCopyRGB.fragmentShader = kha.Shaders.getFragment("layer_copy.frag"); + var vs = new VertexStructure(); + vs.add("pos", VertexData.Float3); + vs.add("tex", VertexData.Float2); + vs.add("col", VertexData.Float4); + pipeCopyRGB.inputLayout = [vs]; + pipeCopyRGB.colorWriteMasksAlpha = [false]; + pipeCopyRGB.compile(); + } + public static function makeCursorPipe() { pipeCursor = new PipelineState(); pipeCursor.vertexShader = kha.Shaders.getVertex("cursor.vert"); diff --git a/Sources/arm/ui/UIFiles.hx b/Sources/arm/ui/UIFiles.hx index 4d9db970..5886863e 100644 --- a/Sources/arm/ui/UIFiles.hx +++ b/Sources/arm/ui/UIFiles.hx @@ -143,8 +143,17 @@ class UIFiles { var abs = File.cacheCloud(handle.text + Path.sep + iconFile); if (abs != null) { iron.data.Data.getImage(abs, function(image: kha.Image) { - icon = image; - iconMap.set(handle.text + Path.sep + f, icon); + iron.App.notifyOnInit(function() { + if (Layers.pipeCopyRGB == null) Layers.makePipeCopyRGB(); + icon = kha.Image.createRenderTarget(image.width, image.height); + icon.g2.begin(false); + icon.g2.drawImage(Project.materials[0].image, 0, 0); // Used for alpha cutout + icon.g2.pipeline = Layers.pipeCopyRGB; + icon.g2.drawImage(image, 0, 0); + icon.g2.pipeline = null; + icon.g2.end(); + iconMap.set(handle.text + Path.sep + f, icon); + }); }); } }