title: How do I blit an image with transparency over another image in Metal?
body: <p>Whenever I try to blit an image that has transparent parts in Metal, the transparent parts are replaced with black.</p>
  
  <p>To be clear, my images do not contain any semi-transparent pixels. They're  either solid color or completely transparent.</p>
  
  <p>I have a simple ViewController that sets up Metal and tries to blit 2 images. But the transparent parts of the second image are black and don't reveal the first image below.</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
  
      id &lt;MTLDevice&gt; device = MTLCreateSystemDefaultDevice();
      self.commandQueue = [device newCommandQueue];
      MTKTextureLoader *textureLoader = [[MTKTextureLoader alloc] initWithDevice:device];
      self.texture = [textureLoader newTextureWithCGImage:[UIImage imageNamed:@"image1"].CGImage options:nil error:nil];
      self.texture2 = [textureLoader newTextureWithCGImage:[UIImage imageNamed:@"image2"].CGImage options:nil error:nil];
  
      self.metalView = [[MTKView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) device:device];
      self.metalView.framebufferOnly = NO;
      self.metalView.delegate = self;
      self.metalView.colorPixelFormat = MTLPixelFormatBGRA8Unorm_sRGB;
      [self.view addSubview:self.metalView];
  }
  
  - (void)drawInMTKView:(MTKView *)view
  {
      id&lt;MTLCommandBuffer&gt; commandBuffer = [self.commandQueue commandBuffer];
      id&lt;MTLBlitCommandEncoder&gt; blitEncoder = [commandBuffer blitCommandEncoder];
  
      [blitEncoder copyFromTexture:self.texture sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(0, 0, 0) sourceSize:MTLSizeMake(self.texture.width, self.texture.height, self.texture.depth) toTexture:self.metalView.currentDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)];
      [blitEncoder copyFromTexture:self.texture2 sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(0, 0, 0) sourceSize:MTLSizeMake(self.texture2.width, self.texture2.height, self.texture2.depth) toTexture:self.metalView.currentDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(20, 20, 0)];
      [blitEncoder endEncoding];
  
      [commandBuffer presentDrawable:self.metalView.currentDrawable];
      [commandBuffer commit];
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>