Skip to content

cgeffect/CGMetal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CGMetal

截屏2021-11-27 上午12 10 19

CGMetal 是一个适用于 iOS 的GPU加速Metal处理库

SDK 的 Github 地址:https://github.com/cgeffect/CGMetal

image

image

工程结构

CGMetal: iOS动态framework
CGMetalMac: Mac动态framework
MetaliOS: 集成CGMetal动态framework的iOS工程
MetalMac: 集成CGMetalMac动态framework的Mac工程

输入源

  1. CGMetalImageInput(图片)
  2. CGMetalPixelBufferInput(CVPixelBufferRef)
    support: NV12/32BGRA
  3. CGMetalRawDataInput(二进制数据)
    support: NV12/NV12/BGRA/RGBA/I420
  4. CGMetalTextureInput(纹理输入, Metal纹理)
  5. CGMetalVideoInput(本地视频输入, 重编码)
  6. CGMetalCameraInput(相机输入)
  7. CGMetalPlayerInput(视频输入, 播放)

输出源

  1. CGMetalImageOutput(图片)
  2. CGMetalPixelBufferOutput(CVPxielBufferRef)
  3. CGMetalRawDataOutput(二进制数据)
  4. CGMetalTextureOutput(纹理输入, Metal纹理)
  5. CGMetalVideoOutput(视频)
  6. CGMetalNSViewOutput(Mac渲染)
  7. CGMetalUIViewOutput(iOS渲染)
  8. CGMetalCALayerOutput(iOS/Mac渲染)
  9. CGMetalPixelBufferSurfaceOutput(CVPxielBufferRef)

代码示例

UIImage *sourceImage = [UIImage imageNamed:@"rgba"];
CGMetalImageInput *inputSource = [[CGMetalImageInput alloc] initWithImage:sourceImage];
CGMetalBasic *basic = [[CGMetalBasic alloc] init];
CGMetalViewOutput * metalView = [[CGMetalViewOutput alloc] initWithFrame:frame];

[inputSource addTarget:basic];
[basic addTarget:metalView];
[inputSource requestRender];

Effect效果

CGMetalGlitch 毛刺
CGMetalColour 着色
CGMetalGray 灰度
CGMetalShake 色彩偏移
CGMetalSoul 灵魂出窍

Transform效果

CGMetalCrop 裁剪
CGMetalFlipX X轴反转
CGMetalFlipY Y轴反转
CGMetalProjection 透视
CGMetalRotate Z轴旋转
CGMetalTranslation XY平移
CGMetalZoom 缩放
CGMetalWobble 晃动
continue...

注意

模拟器不支持fast texture upload, 使用真机运行 iOS10以上, Xcode 13及其以上

官方文档

Metal Using Metal to Draw a View’s Contents
Processing a Texture in a Compute Function
Synchronizing CPU and GPU Work
Performing Calculations on a GPU

About

CGMetal 是用于 iOS/macOS 的GPU加速Metal渲染库

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published