<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;

using FeralTic.DX11;
using FeralTic.DX11.Resources;

using VVVV.PluginInterfaces.V2;
using VVVV.PluginInterfaces.V1;
using SlimDX.Direct3D11;


namespace VVVV.DX11.Nodes.Textures
{
    [PluginInfo(Name = "FromSharedTexture", Category = "DX11.Texture", Version = "2d", Author = "vux")]
    public class PointerTextureNode : IPluginEvaluate, IDX11ResourceProvider
    {
        [Input("Pointer", IsSingle=true, AsInt=true)]
        protected IDiffSpread<long> FPointer;

        [Output("Texture")]
        protected Pin<DX11Resource<DX11Texture2D>> FTextureOutput;

        [Output("Is Valid", IsSingle=true)]
        protected ISpread<bool> FValid;

        private bool FInvalidate;

        public void Evaluate(int SpreadMax)
        {
            if (this.FTextureOutput[0] == null)
            {
                this.FTextureOutput[0] = new DX11Resource<DX11Texture2D>();
            }

            this.FValid.SliceCount = 1;


            if (this.FPointer.IsChanged)
            {
                this.FInvalidate = true;
            }
        }

        public void Update(IPluginIO pin, DX11RenderContext context)
        {

            if (this.FInvalidate)
            {
                if (this.FTextureOutput[0].Contains(context))
                {
                    this.FTextureOutput[0].Dispose(context);
                }

                try
                {
                    Texture2D tex = context.Device.OpenSharedResource<Texture2D>(new IntPtr(this.FPointer[0]));
                    ShaderResourceView srv = new ShaderResourceView(context.Device, tex);

                    DX11Texture2D resource = DX11Texture2D.FromTextureAndSRV(context, tex, srv);

                    this.FTextureOutput[0][context] = resource;

                    this.FValid[0] = true;
                }
                catch (Exception ex)
                {
                    this.FValid[0] = false;
                }

                this.FInvalidate = false;
            }           
        }

        public void Destroy(IPluginIO pin, DX11RenderContext context, bool force)
        {
            this.FTextureOutput[0].Dispose(context);
        }
    }
}
<commit_msg>FromPointerTextureNode now fully spreadable<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;

using FeralTic.DX11;
using FeralTic.DX11.Resources;

using VVVV.PluginInterfaces.V2;
using VVVV.PluginInterfaces.V1;
using SlimDX.Direct3D11;


namespace VVVV.DX11.Nodes.Textures
{
    [PluginInfo(Name = "FromSharedTexture", Category = "DX11.Texture", Version = "2d", Author = "velcrome")]
    public class PointerTextureNode : IPluginEvaluate, IDX11ResourceProvider
    {
        [Input("Pointer", AsInt=true)]
        protected IDiffSpread<long> FPointer;

        [Output("Texture")]
        protected Pin<DX11Resource<DX11Texture2D>> FTextureOutput;

        [Output("Is Valid")]
        protected ISpread<bool> FValid;

        protected bool FInvalidate;

        public void Evaluate(int SpreadMax)
        {
            if (this.FPointer.IsChanged)
            {
                this.FInvalidate = true;
            }
            else return;

            SpreadMax = FPointer.SliceCount;

            var oldCount = FTextureOutput.SliceCount;
            if (FTextureOutput[0] == null) oldCount = 0;

            for (int i = SpreadMax; i < oldCount;i++ )
            {
                FTextureOutput[i].Dispose();
            }

            this.FValid.SliceCount = SpreadMax;
            this.FTextureOutput.SliceCount = SpreadMax;

            for (int i = oldCount; i < SpreadMax; i++)
            {
                FTextureOutput[i] = new DX11Resource<DX11Texture2D>();
            }


        }

        public void Update(IPluginIO pin, DX11RenderContext context)
        {

            if (this.FInvalidate)
            {
                for (int i = 0; i < FTextureOutput.SliceCount; i++)
                {
                    if (this.FTextureOutput[i].Contains(context))
                    {
                        this.FTextureOutput[i].Dispose(context);
                    }

                    try
                    {
                        Texture2D tex = context.Device.OpenSharedResource<Texture2D>(new IntPtr(this.FPointer[i]));
                        ShaderResourceView srv = new ShaderResourceView(context.Device, tex);

                        DX11Texture2D resource = DX11Texture2D.FromTextureAndSRV(context, tex, srv);

                        this.FTextureOutput[i][context] = resource;
                        this.FValid[i] = true;
                    }
                    catch (Exception)
                    {
                        this.FValid[i] = false;
                    }
                }
                this.FInvalidate = false;
            }           
        }

        public void Destroy(IPluginIO pin, DX11RenderContext context, bool force)
        {
            for (int i = 0; i < FTextureOutput.SliceCount; i++)
                this.FTextureOutput[i].Dispose(context);
        }
    }
}

{'fraction_non_alphanumeric': 0.09329279878396352, 'fraction_numerical': 0.01710051301539046, 'mean_word_length': 1.6720812182741116, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3402359', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1419, 'n_words': 271}