dmitri.shuralyov.com/gpu/mtl

add minimal API to support interactive rendering in a window dmitri.shuralyov.com/gpu/mtl#1

Mergeddmitshur opened this change 6 years ago
Patch Set 2: add missing reference links
dmitshur committed 6 years ago commit c6c221649fd918414c5f3561cc3bd6c8280bc77e
Collapse all
Commit Message
FileFile
@@ -1,16 +1,17 @@
11
Parent:     7a718d8 (Add PixelFormatBGRA8UNormSRGB, SetVertexBytes.)
22
Author:     Dmitri Shuralyov <dmitri@shuralyov.com>
33
AuthorDate: Sat Jun 23 01:07:53 2018 -0400
44
Commit:     Dmitri Shuralyov <dmitri@shuralyov.com>
5
CommitDate: Tue Oct 16 22:09:09 2018 -0400
6

7
WIP: Add minimal API to support rendering to a window at 60 FPS.
5
CommitDate: Sat Oct 20 23:15:25 2018 -0400
6

7
WIP: Add minimal API to support interactive rendering in a window.
88

99
The goal of this change is to make it possible to use package mtl
10
to render to a window at 60 FPS. It tries to add the minimum viable
11
API that is needed.
10
to render to a window at interactive framerates (e.g., at 60 FPS,
11
assuming a 60 Hz display with vsync on). It adds the minimal API
12
that is needed.
1213

1314
A new movingtriangle example is added as a demonstration of this
1415
functionality. It renders a triangle that follows the mouse cursor.
1516

1617
TODO: A lot of the newly added API comes from Core Animation, AppKit
mtl.go
FileFile
@@ -55,10 +55,12 @@ func (l Layer) SetDevice(device Device) {
5555
// SetPixelFormat controls the pixel format of textures for rendering layer content.
5656
//
5757
// The pixel format for a Metal layer must be PixelFormatBGRA8UNorm, PixelFormatBGRA8UNormSRGB,
5858
// PixelFormatRGBA16Float, PixelFormatBGRA10XR, or PixelFormatBGRA10XRSRGB.
5959
// SetPixelFormat panics for other values.
60
//
61
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478155-pixelformat.
6062
func (l Layer) SetPixelFormat(pf PixelFormat) {
6163
	e := C.Layer_SetPixelFormat(l.layer, C.uint16_t(pf))
6264
	if e != nil {
6365
		panic(errors.New(C.GoString(e)))
6466
	}
@@ -66,19 +68,23 @@ func (l Layer) SetPixelFormat(pf PixelFormat) {
6668

6769
// SetMaximumDrawableCount controls the number of Metal drawables in the resource pool
6870
// managed by Core Animation.
6971
//
7072
// It can set to 2 or 3 only. SetMaximumDrawableCount panics for other values.
73
//
74
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/2938720-maximumdrawablecount.
7175
func (l Layer) SetMaximumDrawableCount(count int) {
7276
	e := C.Layer_SetMaximumDrawableCount(l.layer, C.uint_t(count))
7377
	if e != nil {
7478
		panic(errors.New(C.GoString(e)))
7579
	}
7680
}
7781

7882
// SetDisplaySyncEnabled controls whether the Metal layer and its drawables
7983
// are synchronized with the display's refresh rate.
84
//
85
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/2887087-displaysyncenabled.
8086
func (l Layer) SetDisplaySyncEnabled(enabled bool) {
8187
	switch enabled {
8288
	case true:
8389
		C.Layer_SetDisplaySyncEnabled(l.layer, 1)
8490
	case false: