public LargePreview(PreviewRender.PreviewBuilder preview, ShaderDiagram.Document doc) { _preview = preview; _document = doc; InitializeComponent(); SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true); SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true); }
public LargePreview(PreviewRender.PreviewBuilder preview, ShaderDiagram.Document doc) { _preview = preview; _document = doc; InitializeComponent(); SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true); SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true); }
public override void Render(Graphics graphics, SizeF minimumSize, PointF location) { if (Node.Tag is ShaderFragmentNodeTag) { SizeF size = Measure(graphics); if (!graphics.IsVisible(new Rectangle() {X = (int)location.X, Y = (int)location.Y, Width = (int)size.Width, Height = (int)size.Height })) return; if (_builder == null) { var nodeGraph = ModelConversion.ToShaderPatcherLayer(_graphControl); var shader = ShaderPatcherLayer.NodeGraph.GeneratePreviewShader(nodeGraph, ((ShaderFragmentNodeTag)Node.Tag).Id); _builder = PreviewRender.Manager.Instance.CreatePreview(shader); } // (assuming no rotation on this transformation -- scale is easy to find) Size idealSize = new Size((int)(graphics.Transform.Elements[0] * size.Width), (int)(graphics.Transform.Elements[3] * size.Height)); if (_builder != null && _builder.Bitmap != null) { // compare the current bitmap size to the size we'd like Size bitmapSize = _builder.Bitmap.Size; float difference = System.Math.Max(System.Math.Abs(1.0f - bitmapSize.Width / (float)(idealSize.Width)), System.Math.Abs(1.0f - bitmapSize.Height / (float)(idealSize.Height))); if (difference > 0.1f) { _builder.Invalidate(); } } if (_builder.Bitmap==null) { _builder.Update(_document, idealSize); } if (_builder.Bitmap!=null) { graphics.DrawImage(_builder.Bitmap, new RectangleF() { X = location.X, Y = location.Y, Width = size.Width, Height = size.Height }); } } }
public void InvalidateShaderStructure() { _builder = null; }
public void InvalidateAttachedConstants() { _builder = null; /* required complete rebuild of shader */ }
public ShaderFragmentPreviewItem(HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc) { _graphControl = graphControl; _document = doc; _builder = null; }