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); }
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); }
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); }
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; }
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>()); } }
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(); }
public unsafe OpenListNative(int capacity) { DataLength = capacity; Data = (T *)NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Utility, DataLength * sizeof(T)); }