Esempio n. 1
0
        /// <summary>
        /// Exports to Xenko <see cref="Image"/>. An instance will be stored in the <see cref="ExportToXenkoRequest"/> instance.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="libraryData">The library data.</param>
        /// <param name="request">The request.</param>
        /// <exception cref="System.InvalidOperationException">
        /// Image size different than expected.
        /// or
        /// Failed to convert texture into Xenko Image.
        /// </exception>
        /// <exception cref="System.NotImplementedException"></exception>
        private void ExportToXenko(TexImage image, XenkoTextureLibraryData libraryData, ExportToXenkoRequest request)
        {
            Log.Debug("Exporting to Xenko Image ...");

            Image xkImage = null;
            switch (image.Dimension)
            {
                case TexImage.TextureDimension.Texture1D:
                    xkImage = Image.New1D(image.Width, image.MipmapCount, image.Format, image.ArraySize); break;
                case TexImage.TextureDimension.Texture2D:
                    xkImage = Image.New2D(image.Width, image.Height, image.MipmapCount, image.Format, image.ArraySize); break;
                case TexImage.TextureDimension.Texture3D:
                    xkImage = Image.New3D(image.Width, image.Height, image.Depth, image.MipmapCount, image.Format); break;
                case TexImage.TextureDimension.TextureCube:
                    xkImage = Image.NewCube(image.Width, image.MipmapCount, image.Format); break;
            }
            if (xkImage == null)
            {
                Log.Error("Image could not be created.");
                throw new InvalidOperationException("Image could not be created.");
            }

            if (xkImage.TotalSizeInBytes != image.DataSize)
            {
                Log.Error("Image size different than expected.");
                throw new InvalidOperationException("Image size different than expected.");
            }

            Utilities.CopyMemory(xkImage.DataPointer, image.Data, image.DataSize);

            request.XkImage = xkImage;
        }
Esempio n. 2
0
        public void ExportToXenkoTest(string file)
        {
            TexImage image = TestTools.Load(library, file);

            ExportToXenkoRequest request = new ExportToXenkoRequest();
            library.Execute(image, request);

            var xk = request.XkImage;

            Assert.IsTrue(xk.TotalSizeInBytes == image.DataSize);
            Assert.IsTrue(xk.Description.MipLevels == image.MipmapCount);
            Assert.IsTrue(xk.Description.Width == image.Width);
            Assert.IsTrue(xk.Description.Height == image.Height);

            image.Dispose();
        }
Esempio n. 3
0
        /// <summary>
        /// Converts to xenko image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>The converted Xenko <see cref="SiliconStudio.Xenko.Graphics.Image"/>.</returns>
        /// <remarks>The user is the owner of the returned image, and has to dispose it after he finishes using it</remarks>
        public SiliconStudio.Xenko.Graphics.Image ConvertToXenkoImage(TexImage image)
        {
            var request = new ExportToXenkoRequest();

            ExecuteRequest(image, request);

            return request.XkImage;
        }