Exemplo n.º 1
0
        public void StartLoad(EntityManager man, Entity e, ref Image2D image, ref Image2DSTB imgSTB, ref Image2DLoadFromFile fspec, ref Image2DSTBLoading loading)
        {
            // if there are async still loading, but set to new file stop job
            if (loading.internalId != 0)
            {
                ImageIOSTBNativeCalls.AbortLoad(loading.internalId);
            }

            image.status           = ImageStatus.Loading;
            image.hasAlpha         = false;
            image.imagePixelSize.x = 0;
            image.imagePixelSize.y = 0;

            var fnImage = man.GetBufferAsString <Image2DLoadFromFileImageFile>(e);

            if (man.HasComponent <Image2DLoadFromFileImageFile>(e) && fnImage.Length <= 0)
            {
                Debug.LogFormat("The file one entity {1} contains an empty Image2DLoadFromFileImageFile string.", e);
            }
            var fnMask = man.GetBufferAsString <Image2DLoadFromFileMaskFile>(e);

            if (man.HasComponent <Image2DLoadFromFileMaskFile>(e) && fnMask.Length <= 0)
            {
                Debug.LogFormat("The file one entity {1} contains an empty Image2DLoadFromFileMaskFile string.", e);
            }

            loading.internalId = ImageIOSTBNativeCalls.StartLoad(fnImage, fnMask);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void StartLoad(EntityManager man, Entity e, ref Image2D image, ref Image2DSTB imgSTB, ref Image2DLoadFromFile fspec, ref Image2DSTBLoading loading)
        {
            // if there are async still loading, but set to new file stop job
            if (loading.internalId != 0)
            {
                ImageIOSTBNativeCalls.AbortLoad(loading.internalId);
            }

            image.status           = ImageStatus.Loading;
            image.imagePixelHeight = 0;
            image.imagePixelWidth  = 0;

            string fnImage = "", fnMask = "";

            if (man.HasComponent <Image2DLoadFromFileGuids>(e))
            {
                var guids = man.GetComponentData <Image2DLoadFromFileGuids>(e);
                // TODO -- call an asset service to actually get some kind of stream from a guid
                if (!guids.imageAsset.Equals(Guid.Empty))
                {
                    fnImage = "Data/" + guids.imageAsset.ToString("N");
                }
                if (!guids.maskAsset.Equals(Guid.Empty))
                {
                    fnMask = "Data/" + guids.maskAsset.ToString("N");
                }
            }
            else
            {
                fnImage = man.GetBufferAsString <Image2DLoadFromFileImageFile>(e);
                if (man.HasComponent <Image2DLoadFromFileImageFile>(e) && fnImage.Length <= 0)
                {
                    Debug.LogFormat("The file one entity {1} contains an empty Image2DLoadFromFileImageFile string.", e);
                }
                fnMask = man.GetBufferAsString <Image2DLoadFromFileMaskFile>(e);
                if (man.HasComponent <Image2DLoadFromFileMaskFile>(e) && fnMask.Length <= 0)
                {
                    Debug.LogFormat("The file one entity {1} contains an empty Image2DLoadFromFileMaskFile string.", e);
                }
            }

            loading.internalId = ImageIOSTBNativeCalls.StartLoad(fnImage, fnMask);
        }
Exemplo n.º 5
0
        public void FreeNative(EntityManager man, Entity e, ref Image2DSTB imgSTB)
        {
#if ENABLE_DOTSRUNTIME_PROFILER
            int w = 0, h = 0;
            unsafe
            {
                ImageIOSTBNativeCalls.GetImageFromHandle(imgSTB.imageHandle, ref w, ref h);
            }
            if (w != 0 && h != 0)
            {
                ProfilerStats.AccumStats.memTextureCount.Accumulate(-1);

                long bytes = -w * h * 4;

                ProfilerStats.AccumStats.memTexture.Accumulate(bytes);
                ProfilerStats.AccumStats.memReservedGFX.Accumulate(bytes);
                ProfilerStats.AccumStats.memUsedGFX.Accumulate(bytes);
            }
#endif
            ImageIOSTBNativeCalls.FreeNative(imgSTB.imageHandle);
        }
Exemplo n.º 6
0
 public void FinishLoading(EntityManager man, Entity e, ref Image2D img, ref Image2DSTB imgSTB, ref Image2DSTBLoading loading)
 {
     ImageIOSTBNativeCalls.FinishLoading();
 }
Exemplo n.º 7
0
 public void FreeNative(EntityManager man, Entity e, ref Image2DSTB imgSTB)
 {
     ImageIOSTBNativeCalls.FreeNative(imgSTB.imageHandle);
 }