예제 #1
0
 public void Upload(GpuTexture Owner, IRenderEngine Engine)
 {
     Handle = Engine.Create_Texture(Data.Span, Owner.Size, Format);
     if (!GpuTexture.PERSIST_IMAGE_DATA)
     {
         // Clear the pixel data from memory to minimize RAM usage
         Data = null;
     }
 }
예제 #2
0
        /// <summary>
        /// Creates a new GPU texture by decoding the given image data
        /// </summary>
        public static async Task <GpuTexture> fromData(ReadOnlyMemory <byte> imgData)
        {
#if ENABLE_HEADLESS
            return(new GpuTexture(Rect2i.Zero));
#else
            var image   = Image.Load <Rgba32>(imgData.ToArray());
            var Size    = new Rect2i(image.Width, image.Height);
            var Texture = new GpuTexture(Size);

            if (image.Frames.Count > 1)
            {
                var frames     = image.Frames;
                int frameCount = frames.Count;

                for (int f = 0; f < frameCount; f++)
                {
                    var frame = frames[f];
                    // Get the delay for this frame from the gif
                    int delay = 0;
                    try
                    {
                        GifFrameMetaData meta = frame.MetaData.GetFormatMetaData(GifFormat.Instance);
                        delay = meta.FrameDelay;// Time is in 1/100th of a second
                    }
                    finally
                    {
                        Span <byte> rgbaBytes = MemoryMarshal.AsBytes(frame.GetPixelSpan()).ToArray();
                        var         size      = new Rect2i(frame.Width, frame.Height);
                        var         duration  = delay / 1000.0f;
                        Texture.Push_Frame(rgbaBytes, size, EPixelFormat.RGBA, duration);
                    }
                }
            }
            else
            {
                Span <byte> rgbaBytes = MemoryMarshal.AsBytes(image.GetPixelSpan()).ToArray();
                var         size      = new Rect2i(image.Width, image.Height);
                Texture.Push_Frame(rgbaBytes, size, EPixelFormat.RGBA);
            }
            return(Texture);
#endif
        }
예제 #3
0
 /// <summary>
 /// Destroy a texture, ensuring it cannot be used again unless recreated.
 /// </summary>
 public abstract bool Destroy_Texture(GpuTexture texture);
예제 #4
0
 /// <summary>
 /// Sets the current texture for whatever system is doing the rendering, be it DirectX, OpenGL, Vulkan, D3D, etc.
 /// </summary>
 public abstract void Set_Texture(GpuTexture tex);