mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-14 23:17:27 +01:00
parent
38e4f4c110
commit
c3ea539cdb
@ -21,14 +21,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
class_NSInvocation = objc.GetClass("NSInvocation")
|
|
||||||
class_NSMethodSignature = objc.GetClass("NSMethodSignature")
|
|
||||||
class_NSAutoreleasePool = objc.GetClass("NSAutoreleasePool")
|
class_NSAutoreleasePool = objc.GetClass("NSAutoreleasePool")
|
||||||
class_NSString = objc.GetClass("NSString")
|
class_NSString = objc.GetClass("NSString")
|
||||||
class_NSProcessInfo = objc.GetClass("NSProcessInfo")
|
class_NSProcessInfo = objc.GetClass("NSProcessInfo")
|
||||||
class_NSColor = objc.GetClass("NSColor")
|
class_NSColor = objc.GetClass("NSColor")
|
||||||
class_NSWindow = objc.GetClass("NSWindow")
|
|
||||||
class_NSView = objc.GetClass("NSView")
|
|
||||||
class_NSScreen = objc.GetClass("NSScreen")
|
class_NSScreen = objc.GetClass("NSScreen")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,15 +32,6 @@ var (
|
|||||||
sel_alloc = objc.RegisterName("alloc")
|
sel_alloc = objc.RegisterName("alloc")
|
||||||
sel_new = objc.RegisterName("new")
|
sel_new = objc.RegisterName("new")
|
||||||
sel_release = objc.RegisterName("release")
|
sel_release = objc.RegisterName("release")
|
||||||
sel_invocationWithMethodSignature = objc.RegisterName("invocationWithMethodSignature:")
|
|
||||||
sel_setSelector = objc.RegisterName("setSelector:")
|
|
||||||
sel_setTarget = objc.RegisterName("setTarget:")
|
|
||||||
sel_setArgumentAtIndex = objc.RegisterName("setArgument:atIndex:")
|
|
||||||
sel_getReturnValue = objc.RegisterName("getReturnValue:")
|
|
||||||
sel_invoke = objc.RegisterName("invoke")
|
|
||||||
sel_invokeWithTarget = objc.RegisterName("invokeWithTarget:")
|
|
||||||
sel_instanceMethodSignatureForSelector = objc.RegisterName("instanceMethodSignatureForSelector:")
|
|
||||||
sel_signatureWithObjCTypes = objc.RegisterName("signatureWithObjCTypes:")
|
|
||||||
sel_initWithUTF8String = objc.RegisterName("initWithUTF8String:")
|
sel_initWithUTF8String = objc.RegisterName("initWithUTF8String:")
|
||||||
sel_UTF8String = objc.RegisterName("UTF8String")
|
sel_UTF8String = objc.RegisterName("UTF8String")
|
||||||
sel_length = objc.RegisterName("length")
|
sel_length = objc.RegisterName("length")
|
||||||
@ -176,52 +163,6 @@ func (v NSView) SetWantsLayer(wantsLayer bool) {
|
|||||||
v.Send(sel_setWantsLayer, wantsLayer)
|
v.Send(sel_setWantsLayer, wantsLayer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSInvocation is being used to call functions that can't be called directly with purego.SyscallN.
|
|
||||||
// See the downsides of that function for what it cannot do.
|
|
||||||
type NSInvocation struct {
|
|
||||||
objc.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
func NSInvocation_invocationWithMethodSignature(sig NSMethodSignature) NSInvocation {
|
|
||||||
return NSInvocation{objc.ID(class_NSInvocation).Send(sel_invocationWithMethodSignature, sig.ID)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i NSInvocation) SetSelector(cmd objc.SEL) {
|
|
||||||
i.Send(sel_setSelector, cmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i NSInvocation) SetTarget(target objc.ID) {
|
|
||||||
i.Send(sel_setTarget, target)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i NSInvocation) SetArgumentAtIndex(arg unsafe.Pointer, idx int) {
|
|
||||||
i.Send(sel_setArgumentAtIndex, arg, idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i NSInvocation) GetReturnValue(ret unsafe.Pointer) {
|
|
||||||
i.Send(sel_getReturnValue, ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i NSInvocation) Invoke() {
|
|
||||||
i.Send(sel_invoke)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i NSInvocation) InvokeWithTarget(target objc.ID) {
|
|
||||||
i.Send(sel_invokeWithTarget, target)
|
|
||||||
}
|
|
||||||
|
|
||||||
type NSMethodSignature struct {
|
|
||||||
objc.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
// NSMethodSignature_signatureWithObjCTypes takes a string that represents the type signature of a method.
|
|
||||||
// It follows the encoding specified in the Apple Docs.
|
|
||||||
//
|
|
||||||
// [Apple Docs]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html#//apple_ref/doc/uid/TP40008048-CH100
|
|
||||||
func NSMethodSignature_signatureWithObjCTypes(types string) NSMethodSignature {
|
|
||||||
return NSMethodSignature{objc.ID(class_NSMethodSignature).Send(sel_signatureWithObjCTypes, types)}
|
|
||||||
}
|
|
||||||
|
|
||||||
type NSAutoreleasePool struct {
|
type NSAutoreleasePool struct {
|
||||||
objc.ID
|
objc.ID
|
||||||
}
|
}
|
||||||
|
@ -913,11 +913,7 @@ func (rce RenderCommandEncoder) SetViewport(viewport Viewport) {
|
|||||||
//
|
//
|
||||||
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515583-setscissorrect?language=objc.
|
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515583-setscissorrect?language=objc.
|
||||||
func (rce RenderCommandEncoder) SetScissorRect(scissorRect ScissorRect) {
|
func (rce RenderCommandEncoder) SetScissorRect(scissorRect ScissorRect) {
|
||||||
inv := cocoa.NSInvocation_invocationWithMethodSignature(cocoa.NSMethodSignature_signatureWithObjCTypes("v@:{MTLScissorRect=qqqq}"))
|
rce.commandEncoder.Send(sel_setScissorRect, scissorRect)
|
||||||
inv.SetTarget(rce.commandEncoder)
|
|
||||||
inv.SetSelector(sel_setScissorRect)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&scissorRect), 2)
|
|
||||||
inv.Invoke()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVertexBuffer sets a buffer for the vertex shader function at an index
|
// SetVertexBuffer sets a buffer for the vertex shader function at an index
|
||||||
@ -1007,19 +1003,10 @@ func (bce BlitCommandEncoder) SynchronizeTexture(texture Texture, slice int, lev
|
|||||||
//
|
//
|
||||||
// Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400754-copyfromtexture?language=objc.
|
// Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400754-copyfromtexture?language=objc.
|
||||||
func (bce BlitCommandEncoder) CopyFromTexture(sourceTexture Texture, sourceSlice int, sourceLevel int, sourceOrigin Origin, sourceSize Size, destinationTexture Texture, destinationSlice int, destinationLevel int, destinationOrigin Origin) {
|
func (bce BlitCommandEncoder) CopyFromTexture(sourceTexture Texture, sourceSlice int, sourceLevel int, sourceOrigin Origin, sourceSize Size, destinationTexture Texture, destinationSlice int, destinationLevel int, destinationOrigin Origin) {
|
||||||
inv := cocoa.NSInvocation_invocationWithMethodSignature(cocoa.NSMethodSignature_signatureWithObjCTypes("v@:@QQ{MTLOrigin=qqq}{MTLSize=qqq}@QQ{MTLOrigin=qqq}"))
|
sel := sel_copyFromTexture_sourceSlice_sourceLevel_sourceOrigin_sourceSize_toTexture_destinationSlice_destinationLevel_destinationOrigin
|
||||||
inv.SetTarget(bce.commandEncoder)
|
bce.commandEncoder.Send(sel,
|
||||||
inv.SetSelector(sel_copyFromTexture_sourceSlice_sourceLevel_sourceOrigin_sourceSize_toTexture_destinationSlice_destinationLevel_destinationOrigin)
|
sourceTexture.texture, sourceSlice, sourceLevel, sourceOrigin, sourceSize,
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&sourceTexture), 2)
|
destinationTexture.texture, destinationSlice, destinationLevel, destinationOrigin)
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&sourceSlice), 3)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&sourceLevel), 4)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&sourceOrigin), 5)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&sourceSize), 6)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&destinationTexture), 7)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&destinationSlice), 8)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&destinationLevel), 9)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&destinationOrigin), 10)
|
|
||||||
inv.Invoke()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Library is a collection of compiled graphics or compute functions.
|
// Library is a collection of compiled graphics or compute functions.
|
||||||
@ -1073,28 +1060,14 @@ func (t Texture) Release() {
|
|||||||
//
|
//
|
||||||
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515751-getbytes?language=objc.
|
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515751-getbytes?language=objc.
|
||||||
func (t Texture) GetBytes(pixelBytes *byte, bytesPerRow uintptr, region Region, level int) {
|
func (t Texture) GetBytes(pixelBytes *byte, bytesPerRow uintptr, region Region, level int) {
|
||||||
inv := cocoa.NSInvocation_invocationWithMethodSignature(cocoa.NSMethodSignature_signatureWithObjCTypes("v@:^vQ{MTLRegion={MTLOrigin=qqq}{MTLSize=qqq}}Q"))
|
t.texture.Send(sel_getBytes_bytesPerRow_fromRegion_mipmapLevel, pixelBytes, bytesPerRow, region, level)
|
||||||
inv.SetTarget(t.texture)
|
|
||||||
inv.SetSelector(sel_getBytes_bytesPerRow_fromRegion_mipmapLevel)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&pixelBytes), 2)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&bytesPerRow), 3)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(®ion), 4)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&level), 5)
|
|
||||||
inv.Invoke()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplaceRegion copies a block of pixels from the caller's pointer into the storage allocation for slice 0 of a texture.
|
// ReplaceRegion copies a block of pixels from the caller's pointer into the storage allocation for slice 0 of a texture.
|
||||||
//
|
//
|
||||||
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515464-replaceregion?language=objc.
|
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515464-replaceregion?language=objc.
|
||||||
func (t Texture) ReplaceRegion(region Region, level int, pixelBytes unsafe.Pointer, bytesPerRow int) {
|
func (t Texture) ReplaceRegion(region Region, level int, pixelBytes unsafe.Pointer, bytesPerRow int) {
|
||||||
inv := cocoa.NSInvocation_invocationWithMethodSignature(cocoa.NSMethodSignature_signatureWithObjCTypes("v@:{MTLRegion={MTLOrigin=qqq}{MTLSize=qqq}}Q^vQ"))
|
t.texture.Send(sel_replaceRegion_mipmapLevel_withBytes_bytesPerRow, region, level, pixelBytes, bytesPerRow)
|
||||||
inv.SetTarget(t.texture)
|
|
||||||
inv.SetSelector(sel_replaceRegion_mipmapLevel_withBytes_bytesPerRow)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(®ion), 2)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&level), 3)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&pixelBytes), 4)
|
|
||||||
inv.SetArgumentAtIndex(unsafe.Pointer(&bytesPerRow), 5)
|
|
||||||
inv.Invoke()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Width is the width of the texture image for the base level mipmap, in pixels.
|
// Width is the width of the texture image for the base level mipmap, in pixels.
|
||||||
|
Loading…
Reference in New Issue
Block a user