MetalCanvas

0.0.2

[WIP]このフレームワークは、processingにおけるOpenGLのように、Metalを少ない手続き・インターフェースで使えることを目指しています。
Hideyuki-Machida/MetalCanvas

What's New

Add Swift Package Manager Manifest

2020-08-09T07:25:24Z

MetalCanvas

Swift 5.0 Platforms iOS Xcode 10.2+ Carthage compatible

概要

このフレームワークは、processingの思想に影響を受けています。
processingにおけるOpenGLのように、Metalを少ない手続き・インターフェースで使えることを目指しています。

少ないコードで キャンバスに絵を描くようにコードで絵を描きます。
点や四角などのプリミティブの描画や画像処理。
そういった事を簡単に行なえます。


Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology. There are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning and prototyping.


参考

Metal学習参考

Interface

サンプルコード

  • まず AppDelegate.swift → MCCore.setup で初期化します。
import UIKit
import MetalCanvas

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

	var window: UIWindow?

	func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
		// Override point for customization after application launch.
		do {
			// 初期化
			try MCCore.setup(contextPptions: [
				CIContextOption.workingColorSpace : CGColorSpaceCreateDeviceRGB(),
				CIContextOption.useSoftwareRenderer : NSNumber(value: false)
				])
		} catch {
			
		}
		return true
	}


  • 実際に使う際には下記のサンプルコードの流れで使用します。
    • MTLCommandBufferを生成(MTLCommandBufferについて)
    • MCCanvasを生成
    • キャンバスに描画したいプリミティブをセット
    • MCImageRenderViewを更新(描画)

※ 生成した commandBuffer は MCImageRenderView. updateでcommitされ、MCImageRenderViewに描画されます。
※ MTLCommandBufferは一度 commit されると、無効になります。
※ 動画のフレーム毎の処理のような繰り返し描画を行う場合には、都度 MTLCommandBuffer生成 → commit を繰り返します。
do {
	// MTLCommandBufferを生成
	var commandBuffer: MTLCommandBuffer = MCCore.commandQueue.makeCommandBuffer()!
	
	// キャンバスを生成
	let canvas: MCCanvas = try MCCanvas.init(destination: &destinationTexture, orthoType: .topLeft)
	
	// キャンバスに描画したいプリミティブをセット
	try canvas.draw(commandBuffer: &commandBuffer, objects: [
	
		// キャンバスにポイントを描画
		MCPoint.init(
			psition: MCGeom.Vec3D.init(x: 0, y: 0, z: 0),
			color: MCColor.init(hex: "0xFF0000"), size: 200.0
		),
		MCPoint.init(
			psition: MCGeom.Vec3D.init(x: 300, y: 10, z: 0),
			color: MCColor.init(hex: "0xFFFF00"), size: 300.0
		)
	])
	
	// MCImageRenderViewを更新(描画)
	self.imageRender?.update(
		commandBuffer: commandBuffer,
		texture: destinationTexture,
		renderSize: renderSize,
		queue: nil
	)

} catch {
}

サンプルコード 画像描画

サンプルコード リアルタイム描画

Installation

Carthage

github "Hideyuki-Machida/MetalCanvas"

Coming Soon

  • Noise
  • Filter
  • Morphing
  • Vision

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Wed Apr 17 2024 08:11:18 GMT-0900 (Hawaii-Aleutian Daylight Time)