示例#1
0
            protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext)
            {
                var convertParameters = new TextureHelper.ImportParameters(AssetParameters)
                {
                    OutputUrl = Url
                };

                using (var texTool = new TextureTool())
                    using (var texImage = texTool.Load(AssetParameters.SourcePathFromDisk, convertParameters.IsSRgb))
                    {
                        var importResult = TextureHelper.ImportTextureImage(texTool, texImage, convertParameters, CancellationToken, commandContext.Logger);

                        return(Task.FromResult(importResult));
                    }
            }
示例#2
0
        public static ResultStatus ImportStreamableTextureImage(ContentManager assetManager, TextureTool textureTool, TexImage texImage, TextureHelper.ImportParameters convertParameters, CancellationToken cancellationToken, ICommandContext commandContext)
        {
            // Perform normal texture importing (but don't save it to file now)
            var importResult = TextureHelper.ImportTextureImageRaw(textureTool, texImage, convertParameters, cancellationToken, commandContext.Logger);

            if (importResult != ResultStatus.Successful)
            {
                return(importResult);
            }

            // Make sure we don't compress mips data
            var dataUrl = convertParameters.OutputUrl + "_Data";

            commandContext.AddTag(new ObjectUrl(UrlType.Content, dataUrl), Builder.DoNotCompressTag);

            using (var outputImage = textureTool.ConvertToXenkoImage(texImage))
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(ResultStatus.Cancelled);
                }

                // Create texture mips data containers (storage all array slices for every mip in separate chunks)
                var           desc     = outputImage.Description;
                List <byte[]> mipsData = new List <byte[]>(desc.MipLevels);
                for (int mipIndex = 0; mipIndex < desc.MipLevels; mipIndex++)
                {
                    int totalSize = 0;
                    for (int arrayIndex = 0; arrayIndex < desc.ArraySize; arrayIndex++)
                    {
                        var pixelBuffer = outputImage.GetPixelBuffer(arrayIndex, 0, mipIndex);
                        totalSize += pixelBuffer.BufferStride;
                    }

                    var buf        = new byte[totalSize];
                    int startIndex = 0;
                    for (int arrayIndex = 0; arrayIndex < desc.ArraySize; arrayIndex++)
                    {
                        var pixelBuffer = outputImage.GetPixelBuffer(arrayIndex, 0, mipIndex);
                        int size        = pixelBuffer.BufferStride;

                        Marshal.Copy(pixelBuffer.DataPointer, buf, startIndex, size);
                        startIndex += size;
                    }
                    mipsData.Add(buf);
                }

                // Pack mip maps to the storage container
                ContentStorageHeader storageHeader;
                ContentStorage.Create(dataUrl, mipsData, out storageHeader);

                if (cancellationToken.IsCancellationRequested)
                {
                    return(ResultStatus.Cancelled);
                }

                // Serialize texture to file
                var outputTexture = new TextureSerializationData(outputImage, true, storageHeader);
                assetManager.Save(convertParameters.OutputUrl, outputTexture.ToSerializableVersion(), typeof(Texture));

                commandContext.Logger.Verbose($"Compression successful [{dataUrl}] to ({outputImage.Description.Width}x{outputImage.Description.Height},{outputImage.Description.Format})");
            }

            return(ResultStatus.Successful);
        }
示例#3
0
            private ResultStatus Import(ICommandContext commandContext, TextureTool textureTool, TexImage texImage, TextureHelper.ImportParameters convertParameters)
            {
                var assetManager             = new ContentManager();
                var useSeparateDataContainer = TextureHelper.ShouldUseDataContainer(Parameters.IsStreamable, texImage.Dimension);

                // Note: for streamable textures we want to store mip maps in a separate storage container and read them on request instead of whole asset deserialization (at once)

                return(useSeparateDataContainer
                    ? TextureHelper.ImportStreamableTextureImage(assetManager, textureTool, texImage, convertParameters, CancellationToken, commandContext)
                    : TextureHelper.ImportTextureImage(assetManager, textureTool, texImage, convertParameters, CancellationToken, commandContext.Logger));
            }