Browse Source

Fixed exporting

flabbet 10 months ago
parent
commit
cf71d3173d

+ 7 - 9
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CreateImageNode.cs

@@ -2,6 +2,7 @@
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Surfaces;
 using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
 using PixiEditor.Numerics;
 
@@ -10,14 +11,12 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 [NodeInfo("CreateImage")]
 public class CreateImageNode : Node
 {
-    private Paint _paint = new();
-    
     public OutputProperty<Texture> Output { get; }
 
     public InputProperty<VecI> Size { get; }
-    
+
     public InputProperty<Color> Fill { get; }
-    
+
     public RenderInputProperty Content { get; }
 
     public CreateImageNode()
@@ -34,16 +33,15 @@ public class CreateImageNode : Node
         {
             return;
         }
+        
+        var surface = RequestTexture(0, Size.Value, false);
 
-        var surface = RequestTexture(0, Size.Value); 
-
-        _paint.Color = Fill.Value;
-        surface.DrawingSurface.Canvas.DrawPaint(_paint);
+        surface.DrawingSurface.Canvas.Clear(Fill.Value);
 
         Content.Value?.Paint(context, surface.DrawingSurface);
 
         Output.Value = surface;
     }
- 
+
     public override Node CreateCopy() => new CreateImageNode();
 }

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageLeftNode.cs

@@ -56,7 +56,7 @@ public class ModifyImageLeftNode : Node, IPairNode, IPreviewRenderable
             return false;
         }
 
-        RenderContext renderContext = new(renderOn, frame, ChunkResolution.Full, VecI.Zero);
+        using RenderContext renderContext = new(renderOn, frame, ChunkResolution.Full, VecI.Zero);
         renderOn.Canvas.DrawSurface(Image.Value.DrawingSurface, 0, 0); 
         return true;
     }

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageRightNode.cs

@@ -102,7 +102,7 @@ public class ModifyImageRightNode : RenderNode, IPairNode, ICustomShaderNode
             drawingPaint.Shader = drawingPaint.Shader.WithUpdatedUniforms(builder.Uniforms);
         }
 
-        surface.DrawingSurface.Canvas.DrawPaint(drawingPaint);
+        surface.DrawingSurface.Canvas.DrawRect(0, 0, size.X, size.Y, drawingPaint);
 
         targetSurface.Canvas.DrawSurface(surface.DrawingSurface, 0, 0);
         builder.Dispose();

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs

@@ -198,8 +198,8 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
             renderSurface.DrawingSurface.Canvas.DrawRect(new RectD(chunkPos * chunkSize, new VecD(chunkSize)),
                 clearPaint);
         }
-
-        renderSurface.DrawingSurface.Flush();
+        
+        renderSurface?.DrawingSurface.Flush(true, true);
     }
 
     protected void ApplyRasterClip(DrawingSurface toClip, DrawingSurface clipSource)

+ 1 - 0
src/PixiEditor.DrawingApi.Core/Bridge/Operations/ISurfaceImplementation.cs

@@ -22,5 +22,6 @@ public interface ISurfaceImplementation
     public RectI GetDeviceClipBounds(DrawingSurface surface);
     public RectD GetLocalClipBounds(DrawingSurface surface);
     public void Unmanage(DrawingSurface surface);
+    public void Flush(DrawingSurface drawingSurface, bool submit, bool synchronous);
 }
 

+ 1 - 1
src/PixiEditor.DrawingApi.Core/Shaders/Generation/ShaderBuilder.cs

@@ -70,7 +70,7 @@ public class ShaderBuilder
         }
 
         string name = $"texture_{GetUniqueNameNumber()}";
-        using var snapshot = surface.Snapshot(surface.DeviceClipBounds);
+        using var snapshot = surface.Snapshot();
         Uniforms[name] = new Uniform(name, snapshot.ToShader());
         var newSampler = new SurfaceSampler(name);
         _samplers[surface] = newSampler;

+ 5 - 0
src/PixiEditor.DrawingApi.Core/Surfaces/DrawingSurface.cs

@@ -92,6 +92,11 @@ namespace PixiEditor.DrawingApi.Core.Surfaces
             DrawingBackendApi.Current.SurfaceImplementation.Flush(this);
         }
 
+        public void Flush(bool submit, bool synchronous)
+        {
+            DrawingBackendApi.Current.SurfaceImplementation.Flush(this, submit, synchronous);
+        }
+
         public static DrawingSurface FromNative(object native)
         {
             return DrawingBackendApi.Current.SurfaceImplementation.FromNative(native);

+ 5 - 0
src/PixiEditor.DrawingApi.Skia/Implementations/SkiaSurfaceImplementation.cs

@@ -156,6 +156,11 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
         {
             ManagedInstances[drawingSurface.ObjectPointer].Flush(true, true);
         }
+        
+        public void Flush(DrawingSurface surface, bool submit, bool synchronous)
+        {
+            ManagedInstances[surface.ObjectPointer].Flush(submit, synchronous);
+        }
 
         public DrawingSurface FromNative(object native)
         {

+ 6 - 2
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -519,10 +519,14 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
     {
         try
         {
-            Surface finalSurface = new Surface(SizeBindable);
+            Surface finalSurface = null; 
             DrawingBackendApi.Current.RenderingDispatcher.Invoke(() =>
             {
-                Renderer.RenderDocument(finalSurface.DrawingSurface, frameTime);
+                using Texture texture = new Texture(SizeBindable);
+                Renderer.RenderDocument(texture.DrawingSurface, frameTime);
+                
+                finalSurface = new Surface(SizeBindable);
+                finalSurface.DrawingSurface.Canvas.DrawImage(texture.DrawingSurface.Snapshot(), 0, 0);
             });
 
             return finalSurface;