/// <summary> /// Creates a texture array. /// </summary> /// <param name="array">The array.</param> /// <param name="request">The request.</param> private void Create(TexImage array, ArrayCreationRequest request) { array.Width = request.TextureList[0].Width; array.Height = request.TextureList[0].Height; array.Depth = request.TextureList[0].Depth; array.RowPitch = request.TextureList[0].RowPitch; array.SlicePitch = request.TextureList[0].SlicePitch; array.Format = request.TextureList[0].Format; array.FaceCount = request.TextureList[0].FaceCount; array.MipmapCount = request.TextureList[0].MipmapCount; array.DisposingLibrary = this; array.Name = request.TextureList[0].Name + "_array"; array.ArraySize = request.TextureList.Count; array.SubImageArray = new TexImage.SubImage[request.TextureList.Count * request.TextureList[0].SubImageArray.Length]; array.DataSize = 0; array.DataSize = request.TextureList[0].DataSize * array.ArraySize; array.Data = Marshal.AllocHGlobal(array.DataSize); int offset1, offset2; long arrayData = array.Data.ToInt64(); long currentData; IntPtr buffer; TexImage current; offset1 = 0; for (int i = 0; i < request.TextureList.Count; ++i) { current = request.TextureList[i]; buffer = new IntPtr(arrayData + offset1); offset1 += current.DataSize; Utilities.CopyMemory(buffer, current.Data, current.DataSize); offset2 = 0; currentData = buffer.ToInt64(); for (int j = 0; j < current.SubImageArray.Length; ++j) { array.SubImageArray[i * current.SubImageArray.Length + j] = current.SubImageArray[j]; array.SubImageArray[i * current.SubImageArray.Length + j].Data = new IntPtr(currentData + offset2); offset2 += current.SubImageArray[j].DataSize; } } }
/// <summary> /// Creates a texture array with the given TexImage. /// </summary> /// <param name="textureList">The texture list.</param> /// <returns>An instance of <see cref="TexImage"/> corresponding containing the texture array.</returns> /// <exception cref="TextureToolsException"> /// No available library could create the array. /// or /// The textures must all have the same size and format to be in a texture array. /// </exception> public TexImage CreateTextureArray(List<TexImage> textureList) { var array = new TexImage(); var request = new ArrayCreationRequest(textureList); ITexLibrary library = FindLibrary(array, request); if (library == null) { Log.Error("No available library could create the array."); throw new TextureToolsException("No available library could create the array."); } int width = textureList[0].Width; int height = textureList[0].Height; int depth = textureList[0].Depth; array.Format = textureList[0].Format; foreach (var texture in textureList) { texture.Update(); if (texture.Width != width || texture.Height != height || texture.Depth != depth || texture.Format != array.Format) { Log.Error("The textures must all have the same size and format to be in a texture array."); throw new TextureToolsException("The textures must all have the same size and format to be in a texture array."); } } ExecuteRequest(array, request); return array; }
/// <summary> /// Creates a texture array. /// </summary> /// <param name="array">The array.</param> /// <param name="request">The request.</param> private void CreateArray(TexImage array, ArrayCreationRequest request) { Log.Info("Creating texture array ..."); Create(array, request); }