# Chapter 15 Create Heap with Cube Map

**URL:** <https://forums.kodeco.com/t/chapter-15-create-heap-with-cube-map/137463>\
**Category:** Metal by Tutorials\
**Created:** [April 11, 2021, 4:40pm UTC](https://forums.kodeco.com/t/chapter-15-create-heap-with-cube-map/137463 "2021-04-11T16:40:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hougoul](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hougoul/32/110937_2.png) [@hougoul](https://forums.kodeco.com/u/hougoul)\
**Post date:** [April 11, 2021, 4:40pm UTC](https://forums.kodeco.com/t/chapter-15-create-heap-with-cube-map/137463/1 "2021-04-11T16:40:35Z")

</div>

I’m trying to move the sky box texture in the MTL heap too.

To achieved it I had to a change the code:

```swift
zip(textures, heapTextures).forEach { (texture, heapTexture) in
            var region = MTLRegionMake2D(0, 0, texture.width,
                                         texture.height)
            
            for level in 0..<texture.mipmapLevelCount {
                for slice in 0..<texture.arrayLength {
                    blitEncoder.copy(from: texture,
                                     sourceSlice: slice,
                                     sourceLevel: level,
                                     sourceOrigin: region.origin,
                                     sourceSize: region.size,
                                     to: heapTexture,
                                     destinationSlice: slice,
                                     destinationLevel: level,
                                     destinationOrigin: region.origin)
                }
                
                region.size.width /= 2
                region.size.height /= 2
                if(region.size.width == 0) {region.size.width = 1}
                if(region.size.height == 0) {region.size.height = 1}
            }
        }
}

```

To

```swift
  zip(textures, heapTextures).forEach { (texture, heapTexture) in
            var region = MTLRegionMake2D(0, 0, texture.width,
                                         texture.height)
            let sliceCount = (texture.textureType == .typeCube) ? 6 : texture.arrayLength
            
            for level in 0..<texture.mipmapLevelCount {
                for slice in 0..<sliceCount {
                    blitEncoder.copy(from: texture,
                                     sourceSlice: slice,
                                     sourceLevel: level,
                                     sourceOrigin: region.origin,
                                     sourceSize: region.size,
                                     to: heapTexture,
                                     destinationSlice: slice,
                                     destinationLevel: level,
                                     destinationOrigin: region.origin)
                }
                
                region.size.width /= 2
                region.size.height /= 2
                if(region.size.width == 0) {region.size.width = 1}
                if(region.size.height == 0) {region.size.height = 1}
            }
        }

```

do you know if there is other textureType needing this type of adaptation.

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [April 12, 2021, 12:25am UTC](https://forums.kodeco.com/t/chapter-15-create-heap-with-cube-map/137463/2 "2021-04-12T00:25:16Z")

</div>

Hi @hougoul and welcome to the forums 😃

That’s a good change to make. The documentation for `MTLTextureType` provides a bewildering array of types to cater for:

[https://developer.apple.com/documentation/metal/mtltexturetype](https://developer.apple.com/documentation/metal/mtltexturetype)

For example, `typeCubeArray` holds an array of cube images, which would need catering for if you use that type.
