我正在处理一个金属支持的绘画应用程序,其中我将笔触的绘制分为两个步骤:第一步将笔触的前缘绘制到屏幕上并捕获整个通过:
到mtltexturemetalTextureComposite = self.currentDrawable!.texture
第二步绘制了前进性中风的更新前缘,并在质感的多边形上绘制了最后保存的金属TextureCompostosite。
这种方法使我能够在不牺牲性能的情况下无限长的笔触,因为这两个步骤在绘图周期的每个帧中都重复。
我遇到的问题是,使用所需的源复合模式(请参见下面的代码),我只看到正在屏幕上绘制中风的前缘。这告诉我,我要么没有充分从当前可抽证中捕获金属TextureCompomposite,要么我对使用的混合模式做出了错误的假设,偶然地如下:
renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
如果我使用不同的混合模式,我确实会看到全部绘制的中风,但不一定是我追求的外观。以下是我在MTKView的draw()方法中都包含的代码的一部分。
func metalRenderStampArray() {
// first encode uber-stamp with previous loop's metalTextureComposite in a background polygon
// note metalTexture= metalTextureComposite contains previous loop's drawable contents
metalCommandEncode(renderCommandEncoder: renderCommandEncoder, stampLayer: stampLayerMode.stampLayerBG, vertexArrayStamps: vertexArrayStampsBG, metalTexture: metalTextureComposite) // background uber-stamp
// empty out uber-stamp in preparation for the next cycle
initializeStampArrays(stampLayer: stampLayerMode.stampLayerBG)
// next, encode current subCurve chunk polygons in foreground
// note metalTexture=brushTexture.texture is a round brush texture with alpha
metalCommandEncode(renderCommandEncoder: renderCommandEncoder, stampLayer: stampLayerMode.stampLayerFG, vertexArrayStamps: vertexArrayStampsFG, metalTexture: brushTexture.texture) // foreground sub-curve chunk
renderCommandEncoder?.endEncoding() // finalize renderEncoder set up
// now present bg + fg composite which is where I see the problem
commandBuffer?.present(self.currentDrawable!)
// 7b. Render to pipeline
commandBuffer?.commit() // commit and send task to gpu
metalTextureComposite = nil // empty out before re-populating
metalTextureComposite = self.currentDrawable!.texture // set up bg texture for next iteration
metalStampComputeComposite() // compute coordinates for the background composite stamp for the next iteration
} // end of func metalRenderStampArray()
我是否应该以不同的方式处理金属Xturexturecompomposite(因为它以1/fps的形式写入),如果是,我应该如何处理?目的是将单个混合模式用于背景多边形和领先的中风多边形。任何帮助将不胜感激。
您似乎正在存储对Drawable纹理的引用,然后在下一个帧中使用它。
我可以看到两个可能的问题: - 在下一个帧拉动周期中,图形处理器可能尚未绘制上一个帧的纹理 - 系统和应用程序的代码可以同时使用Drawable的纹理
我建议尝试复制可绘制的纹理,以供您在commandBuffer?.addCompletedHandler { }