Exemplo n.º 1
0
            void Init()
            {
                texture               = ComponentUtility.CreateComponent <Component_Image>(null, true, false);
                texture.CreateType    = Component_Image.TypeEnum._2D;
                texture.CreateSize    = imageSizeRender;             // new Vector2I( imageSizeRender, imageSizeRender );
                texture.CreateMipmaps = false;
                texture.CreateFormat  = imageFormat;
                texture.CreateUsage   = Component_Image.Usages.RenderTarget;
                texture.CreateFSAA    = 0;
                texture.Enabled       = true;

                var renderTexture = texture.Result.GetRenderTarget(0, 0);

                viewport = renderTexture.AddViewport(false, true);
                viewport.AllowRenderScreenLabels = false;

                //viewport.UpdateBegin += Viewport_UpdateBegin;

                textureRead               = ComponentUtility.CreateComponent <Component_Image>(null, true, false);
                textureRead.CreateType    = Component_Image.TypeEnum._2D;
                textureRead.CreateSize    = texture.CreateSize;
                textureRead.CreateMipmaps = false;
                textureRead.CreateFormat  = texture.CreateFormat;
                textureRead.CreateUsage   = Component_Image.Usages.ReadBack | Component_Image.Usages.BlitDestination;
                textureRead.CreateFSAA    = 0;
                textureRead.Enabled       = true;
                //!!!!
                textureRead.Result.PrepareNativeObject();

                var imageDataBytes = PixelFormatUtility.GetNumElemBytes(imageFormat) * imageSizeRender.X * imageSizeRender.Y;

                imageData = NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Utility, imageDataBytes);
            }
Exemplo n.º 2
0
        public unsafe T[] ToArray()
        {
            var result = new T[Count];

            fixed(T *pResult = result)
            NativeUtility.CopyMemory(pResult, Data, Count * sizeof(T));

            return(result);
        }
Exemplo n.º 3
0
        public static MemoryBlock AllocateAutoReleaseMemoryBlock(IntPtr data, int size)
        {
            var buffer = NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Renderer, size);

            NativeUtility.CopyMemory(buffer, data, size);

            var memory = MemoryBlock.MakeRef(buffer, size, buffer, ReleaseHandleCallback);

            return(memory);
        }
Exemplo n.º 4
0
 public unsafe void Dispose()
 {
     Clear();
     if (Data != null)
     {
         NativeUtility.Free(Data);
         Data       = null;
         DataLength = 0;
     }
 }
Exemplo n.º 5
0
        public unsafe static MemoryBlock AllocateAutoReleaseMemoryBlock <T>(ArraySegment <T> data) where T : unmanaged
        {
            var size = data.Count * sizeof(T);

            var buffer = NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Renderer, size);

            fixed(T *p = data.Array)
            NativeUtility.CopyMemory(buffer, (IntPtr)(p + data.Offset), size);

            var memory = MemoryBlock.MakeRef(buffer, size, buffer, ReleaseHandleCallback);

            return(memory);
        }
Exemplo n.º 6
0
            //private void Viewport_UpdateBegin( Viewport viewport )
            //{
            //	//generator?.PerformUpdate();
            //}

            void Shutdown()
            {
                if (imageData != IntPtr.Zero)
                {
                    NativeUtility.Free(imageData);
                    imageData = IntPtr.Zero;
                }

                texture?.Dispose();
                texture  = null;
                viewport = null;
                textureRead?.Dispose();
                textureRead = null;
            }
Exemplo n.º 7
0
            public Image2D(PixelFormat format, Vector2I size, IntPtr data)
            {
                this.format = format;
                this.size   = size;

                this.data = new byte[SizeInBytes];
                if (data != IntPtr.Zero)
                {
                    unsafe
                    {
                        fixed(byte *pData = this.data)
                        NativeUtility.CopyMemory((IntPtr)pData, data, SizeInBytes);
                    }
                }
            }
Exemplo n.º 8
0
        public unsafe void Add(ref T item)
        {
            if (Count == DataLength)
            {
                T * oldData   = Data;
                int oldLength = DataLength;

                DataLength = oldLength != 0 ? oldLength * 2 : 4;
                Data       = (T *)NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Utility, DataLength * sizeof(T));
                NativeUtility.CopyMemory(Data, oldData, Count * sizeof(T));

                NativeUtility.Free(oldData);
            }
            Data[Count++] = item;
        }
Exemplo n.º 9
0
        public void Write(IntPtr vertices, int vertexCount)
        {
            if (!(Flags.HasFlag(GpuBufferFlags.Dynamic) || (realObject == null && !Flags.HasFlag(GpuBufferFlags.Dynamic) && !Flags.HasFlag(GpuBufferFlags.ComputeWrite))))
            {
                Log.Fatal("GpuVertexBuffer: Write: The buffer must be dynamic or must be still not be created on GPU.");
            }
            if (vertexCount > this.vertexCount)
            {
                Log.Fatal("GpuIndexBuffer: Write: vertexCount > this.vertexCount.");
            }
            ////change type to dynamic
            //if( !dynamic && realObject != null )
            //	dynamic = true;

            unsafe
            {
                fixed(byte *pVertices = this.vertices)
                NativeUtility.CopyMemory((IntPtr)pVertices, vertices, vertexCount * vertexSize);
            }
            vertexCountActual        = vertexCount;
            dynamic_needUpdateNative = true;
        }
        unsafe GetObjectsInSpaceItem.ResultItem[] GetObjectsInSpace_FromOctree_GetResult(GetObjectsInSpaceItem item, int *array, int outputCount)
        {
            var toAdd = NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Utility, outputCount * 4);

            NativeUtility.ZeroMemory(toAdd, outputCount * 4);
            var toAdd2 = (int *)toAdd;

            try
            {
                int length = 0;
                for (int n = 0; n < outputCount; n++)
                {
                    var obj = octreeObjects[array[n]];

                    if (item.VisibleOnly && !obj.VisibleInHierarchy)
                    {
                        continue;
                    }
                    if (item.SelectedTypeOnly != null && !item.SelectedTypeOnly.IsAssignableFrom(obj.BaseType))
                    {
                        continue;
                    }

                    toAdd2[n] = 1;
                    length++;

                    if (item.CastType == GetObjectsInSpaceItem.CastTypeEnum.One)
                    {
                        break;
                    }
                }

                if (length != 0)
                {
                    var result  = new GetObjectsInSpaceItem.ResultItem[length];
                    int current = 0;

                    for (int n = 0; n < outputCount; n++)
                    {
                        var obj = octreeObjects[array[n]];

                        if (toAdd2[n] == 0)
                        {
                            continue;
                        }

                        ref var resultItem = ref result[current];
                        resultItem.Object = obj;
                        current++;

                        if (item.CastType == GetObjectsInSpaceItem.CastTypeEnum.One)
                        {
                            break;
                        }
                    }

                    if (length != current)
                    {
                        Log.Fatal("Component_Scene: GetObjectsInSpace_FromOctree_GetResult: length != current.");
                    }

                    return(result);
                }
                else
                {
                    return(Array.Empty <GetObjectsInSpaceItem.ResultItem>());
                }
            }
Exemplo n.º 11
0
        public void Set(string name, ParameterType type, int elementCount, IntPtr value, int checkTotalSizeInBytes)
        {
            if (NamedParameters == null)
            {
                NamedParameters = new Dictionary <string, NamedParameter>(32);
            }

            if (string.IsNullOrEmpty(name))
            {
                Log.Fatal("ParameterContainer: Set: Name can't be empty.");
            }
            if (!ParameterTypeUtility.CanConvertToByteArray(type))
            {
                Log.Fatal("ParameterContainer: Set: !ParameterTypeUtils.CanConvertToByteArray( type )");
            }

            //ParameterItem parameter = null;

            ////use current parameter or new depending format
            //{
            //	ParameterItem currentItem;
            //	if( parameters.TryGetValue( name, out currentItem ) )
            //	{
            //		if( type == currentItem.type && elementCount == currentItem.elementCount )
            //		{
            //			//!!!!!так?
            //			parameter = currentItem;
            //		}
            //		else
            //			Remove( name );
            //	}
            //}

            ////create parameter
            //if( parameter == null )
            //{
            //	parameter = new ParameterItem();
            //	parameter.container = this;
            //	parameter.name = name;
            //	parameter.type = type;
            //	parameter.elementCount = elementCount;
            //	parameters[ name ] = parameter;
            //}

            var parameter = new NamedParameter();

            parameter.Type         = type;
            parameter.ElementCount = elementCount;

            if (parameter.GetTotalSizeInBytes() != checkTotalSizeInBytes)
            {
                Log.Fatal("ParameterContainer: Set: parameter.GetValueSizeInBytes() != checkTotalSizeInBytes.");
            }

            //prepare data array
            //if( parameter.valueDataPosition == -1 )
            {
                int needSize = dataUsedBytes + parameter.GetTotalSizeInBytes();

                if (data == null)
                {
                    data = new byte[256];
                }

                if (needSize > data.Length)
                {
                    int newSize = data.Length * 2;
                    while (newSize < needSize)
                    {
                        newSize *= 2;
                    }
                    byte[] newData = new byte[newSize];
                    Buffer.BlockCopy(data, 0, newData, 0, dataUsedBytes);
                    data = newData;
                }

                parameter.ValueDataPosition = dataUsedBytes;
                dataUsedBytes += parameter.GetTotalSizeInBytes();
            }

            //copy value
            unsafe
            {
                fixed(byte *pData = data)
                NativeUtility.CopyMemory((IntPtr)(pData + parameter.ValueDataPosition), (IntPtr)value, parameter.GetTotalSizeInBytes());
            }

            if (NamedParameters == null)
            {
                NamedParameters = new Dictionary <string, NamedParameter>(32);
            }
            NamedParameters[name] = parameter;

            unchecked
            {
                version++;
            }

            //return parameter;
        }
Exemplo n.º 12
0
 static void ReleaseHandle(IntPtr usedRef)
 {
     NativeUtility.Free(usedRef);
 }
Exemplo n.º 13
0
        public override string[] GetNativeModuleNames()
        {
            //copy from WindowsPlatformFunctionality

            string[] result;

            unsafe
            {
                try
                {
                    uint needBytes;
                    if (EnumProcessModules(Process.GetCurrentProcess().Handle,
                                           null, 0, &needBytes))
                    {
                        int     count = (int)needBytes / (int)sizeof(IntPtr);
                        IntPtr *array = (IntPtr *)NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Utility, (int)needBytes).ToPointer();

                        uint needBytes2;
                        if (EnumProcessModules(Process.GetCurrentProcess().Handle,
                                               array, needBytes, &needBytes2))
                        {
                            if (needBytes2 < needBytes)
                            {
                                count = (int)needBytes2 / (int)sizeof(IntPtr);
                            }

                            result = new string[count];

                            StringBuilder stringBuilder = new StringBuilder(2048);

                            for (int n = 0; n < count; n++)
                            {
                                stringBuilder.Length = 0;
                                GetModuleFileNameEx(Process.GetCurrentProcess().Handle,
                                                    array[n], stringBuilder, (uint)stringBuilder.Capacity);

                                result[n] = stringBuilder.ToString();
                            }
                        }
                        else
                        {
                            result = new string[0];
                        }

                        NativeUtility.Free((IntPtr)array);
                    }
                    else
                    {
                        result = new string[0];
                    }
                }
                catch
                {
                    result = new string[0];
                }
            }

            return(result);


            //// it seems it works, but it's cross-platform?
            //var wp = new WindowsPlatformFunctionality();
            //return wp.GetNativeModuleNames();
        }
Exemplo n.º 14
0
 public unsafe OpenListNative(int capacity)
 {
     DataLength = capacity;
     Data       = (T *)NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Utility, DataLength * sizeof(T));
 }