public LoadResult CheckLoading(IntPtr cppwrapper, EntityManager man, Entity e, ref Image2D image, ref Image2DSTB imgSTB, ref Image2DLoadFromFile unused, ref Image2DSTBLoading loading) { int newHandle = 0; int r = ImageIOSTBNativeCalls.CheckLoading(loading.internalId, ref newHandle); if (r == 0) { return(LoadResult.stillWorking); } FreeNative(man, e, ref imgSTB); imgSTB.imageHandle = newHandle; var fnLog = string.Empty; fnLog += man.GetBufferAsString <Image2DLoadFromFileImageFile>(e); if (man.HasComponent <Image2DLoadFromFileGuids>(e)) { fnLog += man.GetComponentData <Image2DLoadFromFileGuids>(e).imageAsset; } if (man.HasComponent <Image2DLoadFromFileMaskFile>(e)) { fnLog += " alpha="; fnLog += man.GetBufferAsString <Image2DLoadFromFileMaskFile>(e); } if (r == 2) { image.status = ImageStatus.LoadError; image.imagePixelHeight = 0; image.imagePixelWidth = 0; Debug.LogFormat("Failed to load {0}", fnLog); return(LoadResult.failed); } Assert.IsTrue(newHandle > 0); int w = 0, h = 0; unsafe { ImageIOSTBNativeCalls.GetImageFromHandle(imgSTB.imageHandle, ref w, ref h); Assert.IsTrue(w > 0 && h > 0); image.imagePixelWidth = w; image.imagePixelHeight = h; } #if IO_ENABLE_TRACE Debug.LogFormat("Loaded image: {0} Handle {4} Size: {1},{2}", fnLog, w, h, imgSTB.imageHandle); #endif #if ENABLE_DOTSRUNTIME_PROFILER ProfilerStats.AccumStats.memTextureCount.Accumulate(1); long bytes = image.imagePixelWidth * image.imagePixelHeight * 4; ProfilerStats.AccumStats.memTexture.Accumulate(bytes); ProfilerStats.AccumStats.memReservedGFX.Accumulate(bytes); ProfilerStats.AccumStats.memUsedGFX.Accumulate(bytes); #endif image.status = ImageStatus.Loaded; return(LoadResult.success); }
public LoadResult CheckLoading(IntPtr cppwrapper, EntityManager man, Entity e, ref Image2D image, ref Image2DSTB imgSTB, ref Image2DLoadFromFile unused, ref Image2DSTBLoading loading) { int newHandle = 0; int r = ImageIOSTBNativeCalls.CheckLoading(loading.internalId, ref newHandle); if (r == 0) { return(LoadResult.stillWorking); } FreeNative(man, e, ref imgSTB); Assert.IsTrue(newHandle > 0); imgSTB.imageHandle = newHandle; var fnLog = string.Empty; fnLog += man.GetBufferAsString <Image2DLoadFromFileImageFile>(e); if (man.HasComponent <Image2DLoadFromFileMaskFile>(e)) { fnLog += " alpha="; fnLog += man.GetBufferAsString <Image2DLoadFromFileMaskFile>(e); } if (r == 2) { image.status = ImageStatus.LoadError; image.imagePixelSize.xy = 0; Debug.LogFormat("Failed to load {0}", fnLog); return(LoadResult.failed); } int hasAlpha = 0; int w = 0, h = 0; unsafe { ImageIOSTBNativeCalls.GetImageFromHandle(imgSTB.imageHandle, ref hasAlpha, ref w, ref h); Assert.IsTrue(w > 0 && h > 0); image.hasAlpha = hasAlpha != 0; image.imagePixelSize.x = (float)w; image.imagePixelSize.y = (float)h; } Debug.LogFormatAlways("Loaded image: {0} Handle {4} Size: {1},{2} Alpha: {3}", fnLog, w, h, image.hasAlpha?"yes":"no", imgSTB.imageHandle); // We finished loading the image and retrieve its pixel size, lets init the mask data also if (man.HasComponent <Image2DAlphaMask>(e)) { DynamicBuffer <Image2DAlphaMaskData> maskData = man.GetBuffer <Image2DAlphaMaskData>(e); maskData.ResizeUninitialized(w * h); unsafe { ImageIOSTBNativeCalls.InitImage2DMask(imgSTB.imageHandle, (byte *)(maskData.GetUnsafePtr())); Debug.LogAlways(" Created alpha mask for image."); } } image.status = ImageStatus.Loaded; return(LoadResult.success); }