/// <summary>
        /// Adds the image to the Graphic Device as a texture.
        /// Then returns the pointer of the added texture. It also
        /// cache the image internally rather than creating a new texture on every call,
        /// so this function can be called multiple times per image (per FPS).
        /// </summary>
        /// <param name="filePath">
        /// Path to the image on disk. If the image is loaded in the memory
        /// save it on the disk before sending to this function. Reason for this
        /// is to cache the Image Texture using filePath as the key.
        /// </param>
        /// <returns>
        /// A pointer to the Texture in the Graphic Device.
        /// </returns>
        public IntPtr AddOrGetImagePointer(string filePath)
        {
            if (!loadedImages.TryGetValue(filePath, out Texture texture))
            {
                ImageSharpTexture imgSharpTexture = new ImageSharpTexture(filePath);
                texture = imgSharpTexture.CreateDeviceTexture(graphicsDevice, graphicsDevice.ResourceFactory);
                loadedImages.Add(filePath, texture);
            }

            return imController.GetOrCreateImGuiBinding(graphicsDevice.ResourceFactory, texture);
        }
示例#2
0
        /// <summary>
        /// Adds the image to the Graphic Device as a texture.
        /// Then returns the pointer of the added texture. It also
        /// cache the image internally rather than creating a new texture on every call,
        /// so this function can be called multiple times per frame.
        /// </summary>
        /// <param name="filePath">
        /// Path to the image on disk. If the image is loaded in the memory
        /// save it on the disk before sending to this function. Reason for this
        /// is to cache the Image Texture using filePath as the key.
        /// </param>
        /// <param name="handle">output pointer to the image in the graphic device.</param>
        /// <param name="width">width of the loaded image.</param>
        /// <param name="height">height of the loaded image.</param>
        public void AddOrGetImagePointer(
            string filePath,
            out IntPtr handle,
            out uint width,
            out uint height)
        {
            if (!loadedImages.TryGetValue(filePath, out Texture texture))
            {
                ImageSharpTexture imgSharpTexture = new ImageSharpTexture(filePath);
                texture = imgSharpTexture.CreateDeviceTexture(graphicsDevice, graphicsDevice.ResourceFactory);
                loadedImages.Add(filePath, texture);
            }

            width  = texture.Width;
            height = texture.Height;
            handle = imController.GetOrCreateImGuiBinding(graphicsDevice.ResourceFactory, texture);
        }