thread: Rename Run -> Call

This commit is contained in:
Hajime Hoshi 2019-06-06 00:19:12 +09:00
parent 15a5896efd
commit 85dcafe176
4 changed files with 83 additions and 83 deletions

View File

@ -317,7 +317,7 @@ func (d *Driver) SetThread(thread *thread.Thread) {
} }
func (d *Driver) Begin() { func (d *Driver) Begin() {
d.t.Run(func() error { d.t.Call(func() error {
// NSAutoreleasePool is required to release drawable correctly (#847). // NSAutoreleasePool is required to release drawable correctly (#847).
// https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/MTLBestPracticesGuide/Drawables.html // https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/MTLBestPracticesGuide/Drawables.html
d.pool = C.allocAutoreleasePool() d.pool = C.allocAutoreleasePool()
@ -327,7 +327,7 @@ func (d *Driver) Begin() {
func (d *Driver) End() { func (d *Driver) End() {
d.flush(false, true) d.flush(false, true)
d.t.Run(func() error { d.t.Call(func() error {
d.screenDrawable = ca.MetalDrawable{} d.screenDrawable = ca.MetalDrawable{}
C.releaseAutoreleasePool(d.pool) C.releaseAutoreleasePool(d.pool)
d.pool = nil d.pool = nil
@ -336,7 +336,7 @@ func (d *Driver) End() {
} }
func (d *Driver) SetWindow(window uintptr) { func (d *Driver) SetWindow(window uintptr) {
d.t.Run(func() error { d.t.Call(func() error {
// Note that [NSApp mainWindow] returns nil when the window is borderless. // Note that [NSApp mainWindow] returns nil when the window is borderless.
// Then the window is needed to be given. // Then the window is needed to be given.
d.window = window d.window = window
@ -345,7 +345,7 @@ func (d *Driver) SetWindow(window uintptr) {
} }
func (d *Driver) SetVertices(vertices []float32, indices []uint16) { func (d *Driver) SetVertices(vertices []float32, indices []uint16) {
d.t.Run(func() error { d.t.Call(func() error {
if d.vb != (mtl.Buffer{}) { if d.vb != (mtl.Buffer{}) {
d.vb.Release() d.vb.Release()
} }
@ -363,7 +363,7 @@ func (d *Driver) Flush() {
} }
func (d *Driver) flush(wait bool, present bool) { func (d *Driver) flush(wait bool, present bool) {
d.t.Run(func() error { d.t.Call(func() error {
if d.cb == (mtl.CommandBuffer{}) { if d.cb == (mtl.CommandBuffer{}) {
return nil return nil
} }
@ -384,7 +384,7 @@ func (d *Driver) flush(wait bool, present bool) {
func (d *Driver) checkSize(width, height int) { func (d *Driver) checkSize(width, height int) {
m := 0 m := 0
d.t.Run(func() error { d.t.Call(func() error {
if d.maxImageSize == 0 { if d.maxImageSize == 0 {
d.maxImageSize = 4096 d.maxImageSize = 4096
// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf // https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
@ -444,7 +444,7 @@ func (d *Driver) NewImage(width, height int) (driver.Image, error) {
Usage: mtl.TextureUsageShaderRead, Usage: mtl.TextureUsageShaderRead,
} }
var t mtl.Texture var t mtl.Texture
d.t.Run(func() error { d.t.Call(func() error {
t = d.device.MakeTexture(td) t = d.device.MakeTexture(td)
return nil return nil
}) })
@ -457,7 +457,7 @@ func (d *Driver) NewImage(width, height int) (driver.Image, error) {
} }
func (d *Driver) NewScreenFramebufferImage(width, height int) (driver.Image, error) { func (d *Driver) NewScreenFramebufferImage(width, height int) (driver.Image, error) {
d.t.Run(func() error { d.t.Call(func() error {
d.ml.SetDrawableSize(width, height) d.ml.SetDrawableSize(width, height)
return nil return nil
}) })
@ -470,7 +470,7 @@ func (d *Driver) NewScreenFramebufferImage(width, height int) (driver.Image, err
} }
func (d *Driver) Reset() error { func (d *Driver) Reset() error {
if err := d.t.Run(func() error { if err := d.t.Call(func() error {
if d.cq != (mtl.CommandQueue{}) { if d.cq != (mtl.CommandQueue{}) {
d.cq.Release() d.cq.Release()
d.cq = mtl.CommandQueue{} d.cq = mtl.CommandQueue{}
@ -612,7 +612,7 @@ func (d *Driver) Reset() error {
} }
func (d *Driver) Draw(indexLen int, indexOffset int, mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter, address graphics.Address) error { func (d *Driver) Draw(indexLen int, indexOffset int, mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter, address graphics.Address) error {
if err := d.t.Run(func() error { if err := d.t.Call(func() error {
// NSView can be changed anytime (probably). Set this everyframe. // NSView can be changed anytime (probably). Set this everyframe.
setView(d.window, d.ml) setView(d.window, d.ml)
@ -696,7 +696,7 @@ func (d *Driver) Draw(indexLen int, indexOffset int, mode graphics.CompositeMode
} }
func (d *Driver) ResetSource() { func (d *Driver) ResetSource() {
d.t.Run(func() error { d.t.Call(func() error {
d.src = nil d.src = nil
return nil return nil
}) })
@ -738,7 +738,7 @@ func (i *Image) viewportSize() (int, int) {
} }
func (i *Image) Dispose() { func (i *Image) Dispose() {
i.driver.t.Run(func() error { i.driver.t.Call(func() error {
if i.texture != (mtl.Texture{}) { if i.texture != (mtl.Texture{}) {
i.texture.Release() i.texture.Release()
i.texture = mtl.Texture{} i.texture = mtl.Texture{}
@ -755,7 +755,7 @@ func (i *Image) IsInvalidated() bool {
} }
func (i *Image) syncTexture() { func (i *Image) syncTexture() {
i.driver.t.Run(func() error { i.driver.t.Call(func() error {
if i.driver.cb != (mtl.CommandBuffer{}) { if i.driver.cb != (mtl.CommandBuffer{}) {
panic("metal: command buffer must be empty at syncTexture: flush is not called yet?") panic("metal: command buffer must be empty at syncTexture: flush is not called yet?")
} }
@ -775,7 +775,7 @@ func (i *Image) Pixels() ([]byte, error) {
i.syncTexture() i.syncTexture()
b := make([]byte, 4*i.width*i.height) b := make([]byte, 4*i.width*i.height)
i.driver.t.Run(func() error { i.driver.t.Call(func() error {
i.texture.GetBytes(&b[0], uintptr(4*i.width), mtl.Region{ i.texture.GetBytes(&b[0], uintptr(4*i.width), mtl.Region{
Size: mtl.Size{i.width, i.height, 1}, Size: mtl.Size{i.width, i.height, 1},
}, 0) }, 0)
@ -785,14 +785,14 @@ func (i *Image) Pixels() ([]byte, error) {
} }
func (i *Image) SetAsDestination() { func (i *Image) SetAsDestination() {
i.driver.t.Run(func() error { i.driver.t.Call(func() error {
i.driver.dst = i i.driver.dst = i
return nil return nil
}) })
} }
func (i *Image) SetAsSource() { func (i *Image) SetAsSource() {
i.driver.t.Run(func() error { i.driver.t.Call(func() error {
i.driver.src = i i.driver.src = i
return nil return nil
}) })
@ -801,7 +801,7 @@ func (i *Image) SetAsSource() {
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) { func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
i.driver.flush(true, false) i.driver.flush(true, false)
i.driver.t.Run(func() error { i.driver.t.Call(func() error {
i.texture.ReplaceRegion(mtl.Region{ i.texture.ReplaceRegion(mtl.Region{
Origin: mtl.Origin{x, y, 0}, Origin: mtl.Origin{x, y, 0},
Size: mtl.Size{width, height, 1}, Size: mtl.Size{width, height, 1},

View File

@ -75,7 +75,7 @@ type contextImpl struct {
} }
func (c *context) reset() error { func (c *context) reset() error {
if err := c.t.Run(func() error { if err := c.t.Call(func() error {
if c.init { if c.init {
return nil return nil
} }
@ -94,12 +94,12 @@ func (c *context) reset() error {
c.lastViewportWidth = 0 c.lastViewportWidth = 0
c.lastViewportHeight = 0 c.lastViewportHeight = 0
c.lastCompositeMode = graphics.CompositeModeUnknown c.lastCompositeMode = graphics.CompositeModeUnknown
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.Enable(gl.BLEND) gl.Enable(gl.BLEND)
return nil return nil
}) })
c.blendFunc(graphics.CompositeModeSourceOver) c.blendFunc(graphics.CompositeModeSourceOver)
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
f := int32(0) f := int32(0)
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f) gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
c.screenFramebuffer = framebufferNative(f) c.screenFramebuffer = framebufferNative(f)
@ -109,7 +109,7 @@ func (c *context) reset() error {
} }
func (c *context) blendFunc(mode graphics.CompositeMode) { func (c *context) blendFunc(mode graphics.CompositeMode) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
if c.lastCompositeMode == mode { if c.lastCompositeMode == mode {
return nil return nil
} }
@ -123,7 +123,7 @@ func (c *context) blendFunc(mode graphics.CompositeMode) {
func (c *context) newTexture(width, height int) (textureNative, error) { func (c *context) newTexture(width, height int) (textureNative, error) {
var texture textureNative var texture textureNative
if err := c.t.Run(func() error { if err := c.t.Call(func() error {
var t uint32 var t uint32
gl.GenTextures(1, &t) gl.GenTextures(1, &t)
// TODO: Use gl.IsTexture // TODO: Use gl.IsTexture
@ -137,7 +137,7 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
return 0, err return 0, err
} }
c.bindTexture(texture) c.bindTexture(texture)
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
@ -151,7 +151,7 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
} }
func (c *context) bindFramebufferImpl(f framebufferNative) { func (c *context) bindFramebufferImpl(f framebufferNative) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.BindFramebufferEXT(gl.FRAMEBUFFER, uint32(f)) gl.BindFramebufferEXT(gl.FRAMEBUFFER, uint32(f))
return nil return nil
}) })
@ -159,12 +159,12 @@ func (c *context) bindFramebufferImpl(f framebufferNative) {
func (c *context) framebufferPixels(f *framebuffer, width, height int) ([]byte, error) { func (c *context) framebufferPixels(f *framebuffer, width, height int) ([]byte, error) {
var pixels []byte var pixels []byte
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.Flush() gl.Flush()
return nil return nil
}) })
c.bindFramebuffer(f.native) c.bindFramebuffer(f.native)
if err := c.t.Run(func() error { if err := c.t.Call(func() error {
pixels = make([]byte, 4*width*height) pixels = make([]byte, 4*width*height)
gl.ReadPixels(0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(pixels)) gl.ReadPixels(0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(pixels))
return nil return nil
@ -175,14 +175,14 @@ func (c *context) framebufferPixels(f *framebuffer, width, height int) ([]byte,
} }
func (c *context) bindTextureImpl(t textureNative) { func (c *context) bindTextureImpl(t textureNative) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.BindTexture(gl.TEXTURE_2D, uint32(t)) gl.BindTexture(gl.TEXTURE_2D, uint32(t))
return nil return nil
}) })
} }
func (c *context) deleteTexture(t textureNative) { func (c *context) deleteTexture(t textureNative) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
tt := uint32(t) tt := uint32(t)
if !gl.IsTexture(tt) { if !gl.IsTexture(tt) {
return nil return nil
@ -197,7 +197,7 @@ func (c *context) deleteTexture(t textureNative) {
func (c *context) isTexture(t textureNative) bool { func (c *context) isTexture(t textureNative) bool {
r := false r := false
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
r = gl.IsTexture(uint32(t)) r = gl.IsTexture(uint32(t))
return nil return nil
}) })
@ -206,7 +206,7 @@ func (c *context) isTexture(t textureNative) bool {
func (c *context) texSubImage2D(t textureNative, p []byte, x, y, width, height int) { func (c *context) texSubImage2D(t textureNative, p []byte, x, y, width, height int) {
c.bindTexture(t) c.bindTexture(t)
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(x), int32(y), int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p)) gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(x), int32(y), int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p))
return nil return nil
}) })
@ -215,7 +215,7 @@ func (c *context) texSubImage2D(t textureNative, p []byte, x, y, width, height i
func (c *context) newFramebuffer(texture textureNative) (framebufferNative, error) { func (c *context) newFramebuffer(texture textureNative) (framebufferNative, error) {
var framebuffer framebufferNative var framebuffer framebufferNative
var f uint32 var f uint32
if err := c.t.Run(func() error { if err := c.t.Call(func() error {
gl.GenFramebuffersEXT(1, &f) gl.GenFramebuffersEXT(1, &f)
// TODO: Use gl.IsFramebuffer // TODO: Use gl.IsFramebuffer
if f <= 0 { if f <= 0 {
@ -226,7 +226,7 @@ func (c *context) newFramebuffer(texture textureNative) (framebufferNative, erro
return 0, err return 0, err
} }
c.bindFramebuffer(framebufferNative(f)) c.bindFramebuffer(framebufferNative(f))
if err := c.t.Run(func() error { if err := c.t.Call(func() error {
gl.FramebufferTexture2DEXT(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0) gl.FramebufferTexture2DEXT(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0)
s := gl.CheckFramebufferStatusEXT(gl.FRAMEBUFFER) s := gl.CheckFramebufferStatusEXT(gl.FRAMEBUFFER)
if s != gl.FRAMEBUFFER_COMPLETE { if s != gl.FRAMEBUFFER_COMPLETE {
@ -247,14 +247,14 @@ func (c *context) newFramebuffer(texture textureNative) (framebufferNative, erro
} }
func (c *context) setViewportImpl(width, height int) { func (c *context) setViewportImpl(width, height int) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.Viewport(0, 0, int32(width), int32(height)) gl.Viewport(0, 0, int32(width), int32(height))
return nil return nil
}) })
} }
func (c *context) deleteFramebuffer(f framebufferNative) { func (c *context) deleteFramebuffer(f framebufferNative) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
ff := uint32(f) ff := uint32(f)
if !gl.IsFramebufferEXT(ff) { if !gl.IsFramebufferEXT(ff) {
return nil return nil
@ -271,7 +271,7 @@ func (c *context) deleteFramebuffer(f framebufferNative) {
func (c *context) newShader(shaderType shaderType, source string) (shader, error) { func (c *context) newShader(shaderType shaderType, source string) (shader, error) {
var sh shader var sh shader
if err := c.t.Run(func() error { if err := c.t.Call(func() error {
s := gl.CreateShader(uint32(shaderType)) s := gl.CreateShader(uint32(shaderType))
if s == 0 { if s == 0 {
return fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType) return fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
@ -301,7 +301,7 @@ func (c *context) newShader(shaderType shaderType, source string) (shader, error
} }
func (c *context) deleteShader(s shader) { func (c *context) deleteShader(s shader) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.DeleteShader(uint32(s)) gl.DeleteShader(uint32(s))
return nil return nil
}) })
@ -309,7 +309,7 @@ func (c *context) deleteShader(s shader) {
func (c *context) newProgram(shaders []shader, attributes []string) (program, error) { func (c *context) newProgram(shaders []shader, attributes []string) (program, error) {
var pr program var pr program
if err := c.t.Run(func() error { if err := c.t.Call(func() error {
p := gl.CreateProgram() p := gl.CreateProgram()
if p == 0 { if p == 0 {
return errors.New("opengl: glCreateProgram failed") return errors.New("opengl: glCreateProgram failed")
@ -340,14 +340,14 @@ func (c *context) newProgram(shaders []shader, attributes []string) (program, er
} }
func (c *context) useProgram(p program) { func (c *context) useProgram(p program) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.UseProgram(uint32(p)) gl.UseProgram(uint32(p))
return nil return nil
}) })
} }
func (c *context) deleteProgram(p program) { func (c *context) deleteProgram(p program) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
if !gl.IsProgram(uint32(p)) { if !gl.IsProgram(uint32(p)) {
return nil return nil
} }
@ -367,7 +367,7 @@ func (c *context) getUniformLocationImpl(p program, location string) uniformLoca
} }
func (c *context) uniformInt(p program, location string, v int) { func (c *context) uniformInt(p program, location string, v int) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
l := int32(c.locationCache.GetUniformLocation(c, p, location)) l := int32(c.locationCache.GetUniformLocation(c, p, location))
gl.Uniform1i(l, int32(v)) gl.Uniform1i(l, int32(v))
return nil return nil
@ -375,7 +375,7 @@ func (c *context) uniformInt(p program, location string, v int) {
} }
func (c *context) uniformFloat(p program, location string, v float32) { func (c *context) uniformFloat(p program, location string, v float32) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
l := int32(c.locationCache.GetUniformLocation(c, p, location)) l := int32(c.locationCache.GetUniformLocation(c, p, location))
gl.Uniform1f(l, v) gl.Uniform1f(l, v)
return nil return nil
@ -383,7 +383,7 @@ func (c *context) uniformFloat(p program, location string, v float32) {
} }
func (c *context) uniformFloats(p program, location string, v []float32) { func (c *context) uniformFloats(p program, location string, v []float32) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
l := int32(c.locationCache.GetUniformLocation(c, p, location)) l := int32(c.locationCache.GetUniformLocation(c, p, location))
switch len(v) { switch len(v) {
case 2: case 2:
@ -400,21 +400,21 @@ func (c *context) uniformFloats(p program, location string, v []float32) {
} }
func (c *context) vertexAttribPointer(p program, index int, size int, dataType dataType, stride int, offset int) { func (c *context) vertexAttribPointer(p program, index int, size int, dataType dataType, stride int, offset int) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.VertexAttribPointer(uint32(index), int32(size), uint32(dataType), false, int32(stride), gl.PtrOffset(offset)) gl.VertexAttribPointer(uint32(index), int32(size), uint32(dataType), false, int32(stride), gl.PtrOffset(offset))
return nil return nil
}) })
} }
func (c *context) enableVertexAttribArray(p program, index int) { func (c *context) enableVertexAttribArray(p program, index int) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.EnableVertexAttribArray(uint32(index)) gl.EnableVertexAttribArray(uint32(index))
return nil return nil
}) })
} }
func (c *context) disableVertexAttribArray(p program, index int) { func (c *context) disableVertexAttribArray(p program, index int) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.DisableVertexAttribArray(uint32(index)) gl.DisableVertexAttribArray(uint32(index))
return nil return nil
}) })
@ -422,7 +422,7 @@ func (c *context) disableVertexAttribArray(p program, index int) {
func (c *context) newArrayBuffer(size int) buffer { func (c *context) newArrayBuffer(size int) buffer {
var bf buffer var bf buffer
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
var b uint32 var b uint32
gl.GenBuffers(1, &b) gl.GenBuffers(1, &b)
gl.BindBuffer(uint32(arrayBuffer), b) gl.BindBuffer(uint32(arrayBuffer), b)
@ -435,7 +435,7 @@ func (c *context) newArrayBuffer(size int) buffer {
func (c *context) newElementArrayBuffer(size int) buffer { func (c *context) newElementArrayBuffer(size int) buffer {
var bf buffer var bf buffer
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
var b uint32 var b uint32
gl.GenBuffers(1, &b) gl.GenBuffers(1, &b)
gl.BindBuffer(uint32(elementArrayBuffer), b) gl.BindBuffer(uint32(elementArrayBuffer), b)
@ -447,28 +447,28 @@ func (c *context) newElementArrayBuffer(size int) buffer {
} }
func (c *context) bindBuffer(bufferType bufferType, b buffer) { func (c *context) bindBuffer(bufferType bufferType, b buffer) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.BindBuffer(uint32(bufferType), uint32(b)) gl.BindBuffer(uint32(bufferType), uint32(b))
return nil return nil
}) })
} }
func (c *context) arrayBufferSubData(data []float32) { func (c *context) arrayBufferSubData(data []float32) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.BufferSubData(uint32(arrayBuffer), 0, len(data)*4, gl.Ptr(data)) gl.BufferSubData(uint32(arrayBuffer), 0, len(data)*4, gl.Ptr(data))
return nil return nil
}) })
} }
func (c *context) elementArrayBufferSubData(data []uint16) { func (c *context) elementArrayBufferSubData(data []uint16) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.BufferSubData(uint32(elementArrayBuffer), 0, len(data)*2, gl.Ptr(data)) gl.BufferSubData(uint32(elementArrayBuffer), 0, len(data)*2, gl.Ptr(data))
return nil return nil
}) })
} }
func (c *context) deleteBuffer(b buffer) { func (c *context) deleteBuffer(b buffer) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
bb := uint32(b) bb := uint32(b)
gl.DeleteBuffers(1, &bb) gl.DeleteBuffers(1, &bb)
return nil return nil
@ -476,7 +476,7 @@ func (c *context) deleteBuffer(b buffer) {
} }
func (c *context) drawElements(len int, offsetInBytes int) { func (c *context) drawElements(len int, offsetInBytes int) {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.DrawElements(gl.TRIANGLES, int32(len), gl.UNSIGNED_SHORT, gl.PtrOffset(offsetInBytes)) gl.DrawElements(gl.TRIANGLES, int32(len), gl.UNSIGNED_SHORT, gl.PtrOffset(offsetInBytes))
return nil return nil
}) })
@ -484,7 +484,7 @@ func (c *context) drawElements(len int, offsetInBytes int) {
func (c *context) maxTextureSizeImpl() int { func (c *context) maxTextureSizeImpl() int {
size := 0 size := 0
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
s := int32(0) s := int32(0)
gl.GetIntegerv(gl.MAX_TEXTURE_SIZE, &s) gl.GetIntegerv(gl.MAX_TEXTURE_SIZE, &s)
size = int(s) size = int(s)
@ -494,7 +494,7 @@ func (c *context) maxTextureSizeImpl() int {
} }
func (c *context) flush() { func (c *context) flush() {
_ = c.t.Run(func() error { _ = c.t.Call(func() error {
gl.Flush() gl.Flush()
return nil return nil
}) })

View File

@ -49,10 +49,10 @@ func (t *Thread) Loop(ch <-chan error) error {
} }
} }
// Run calls f on the thread. // Call calls f on the thread.
// //
// Do not call this from the same thread. This would block forever. // Do not call this from the same thread. This would block forever.
func (t *Thread) Run(f func() error) error { func (t *Thread) Call(f func() error) error {
if atomic.LoadInt32(&t.started) == 0 { if atomic.LoadInt32(&t.started) == 0 {
panic("thread: the thread loop is not started yet") panic("thread: the thread loop is not started yet")
} }

View File

@ -278,7 +278,7 @@ func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
var v *glfw.VidMode var v *glfw.VidMode
s := 0.0 s := 0.0
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
v = u.currentMonitor().GetVideoMode() v = u.currentMonitor().GetVideoMode()
s = u.glfwScale() s = u.glfwScale()
return nil return nil
@ -290,7 +290,7 @@ func (u *UserInterface) SetScreenSize(width, height int) {
if !u.isRunning() { if !u.isRunning() {
panic("ui: Run is not called yet") panic("ui: Run is not called yet")
} }
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
// TODO: What if the window is maximized? (#320) // TODO: What if the window is maximized? (#320)
u.setScreenSize(width, height, u.scale, u.isFullscreen(), u.vsync) u.setScreenSize(width, height, u.scale, u.isFullscreen(), u.vsync)
return nil return nil
@ -301,7 +301,7 @@ func (u *UserInterface) SetScreenScale(scale float64) {
if !u.isRunning() { if !u.isRunning() {
panic("ui: Run is not called yet") panic("ui: Run is not called yet")
} }
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
// TODO: What if the window is maximized? (#320) // TODO: What if the window is maximized? (#320)
u.setScreenSize(u.width, u.height, scale, u.isFullscreen(), u.vsync) u.setScreenSize(u.width, u.height, scale, u.isFullscreen(), u.vsync)
return nil return nil
@ -313,7 +313,7 @@ func (u *UserInterface) ScreenScale() float64 {
return 0 return 0
} }
s := 0.0 s := 0.0
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
s = u.scale s = u.scale
return nil return nil
}) })
@ -333,7 +333,7 @@ func (u *UserInterface) IsFullscreen() bool {
return u.isInitFullscreen() return u.isInitFullscreen()
} }
b := false b := false
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
b = u.isFullscreen() b = u.isFullscreen()
return nil return nil
}) })
@ -345,7 +345,7 @@ func (u *UserInterface) SetFullscreen(fullscreen bool) {
u.setInitFullscreen(fullscreen) u.setInitFullscreen(fullscreen)
return return
} }
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
u.setScreenSize(u.width, u.height, u.scale, fullscreen, u.vsync) u.setScreenSize(u.width, u.height, u.scale, fullscreen, u.vsync)
return nil return nil
}) })
@ -370,7 +370,7 @@ func (u *UserInterface) SetVsyncEnabled(enabled bool) {
u.m.Unlock() u.m.Unlock()
return return
} }
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
u.setScreenSize(u.width, u.height, u.scale, u.isFullscreen(), enabled) u.setScreenSize(u.width, u.height, u.scale, u.isFullscreen(), enabled)
return nil return nil
}) })
@ -387,7 +387,7 @@ func (u *UserInterface) SetWindowTitle(title string) {
if !u.isRunning() { if !u.isRunning() {
return return
} }
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
u.window.SetTitle(title) u.window.SetTitle(title)
return nil return nil
}) })
@ -398,7 +398,7 @@ func (u *UserInterface) SetWindowIcon(iconImages []image.Image) {
u.setInitIconImages(iconImages) u.setInitIconImages(iconImages)
return return
} }
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
u.window.SetIcon(iconImages) u.window.SetIcon(iconImages)
return nil return nil
}) })
@ -414,7 +414,7 @@ func (u *UserInterface) ScreenPadding() (x0, y0, x1, y1 float64) {
} }
// The window width can be bigger than the game screen width (#444). // The window width can be bigger than the game screen width (#444).
ox := 0.0 ox := 0.0
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
ox = (float64(u.windowWidth)*u.actualScreenScale() - float64(u.width)*u.actualScreenScale()) / 2 ox = (float64(u.windowWidth)*u.actualScreenScale() - float64(u.width)*u.actualScreenScale()) / 2
return nil return nil
}) })
@ -427,7 +427,7 @@ func (u *UserInterface) ScreenPadding() (x0, y0, x1, y1 float64) {
gs := 0.0 gs := 0.0
vw := 0.0 vw := 0.0
vh := 0.0 vh := 0.0
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
m := u.window.GetMonitor() m := u.window.GetMonitor()
d = devicescale.GetAt(m.GetPos()) d = devicescale.GetAt(m.GetPos())
sx = float64(u.width) * u.actualScreenScale() sx = float64(u.width) * u.actualScreenScale()
@ -452,7 +452,7 @@ func (u *UserInterface) adjustPosition(x, y int) (int, int) {
} }
ox, oy, _, _ := u.ScreenPadding() ox, oy, _, _ := u.ScreenPadding()
s := 0.0 s := 0.0
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
s = u.actualScreenScale() s = u.actualScreenScale()
return nil return nil
}) })
@ -464,7 +464,7 @@ func (u *UserInterface) IsCursorVisible() bool {
return u.isInitCursorVisible() return u.isInitCursorVisible()
} }
v := false v := false
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
v = u.window.GetInputMode(glfw.CursorMode) == glfw.CursorNormal v = u.window.GetInputMode(glfw.CursorMode) == glfw.CursorNormal
return nil return nil
}) })
@ -476,7 +476,7 @@ func (u *UserInterface) SetCursorVisible(visible bool) {
u.setInitCursorVisible(visible) u.setInitCursorVisible(visible)
return return
} }
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
c := glfw.CursorNormal c := glfw.CursorNormal
if !visible { if !visible {
c = glfw.CursorHidden c = glfw.CursorHidden
@ -491,7 +491,7 @@ func (u *UserInterface) IsWindowDecorated() bool {
return u.isInitWindowDecorated() return u.isInitWindowDecorated()
} }
v := false v := false
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
v = u.window.GetAttrib(glfw.Decorated) == glfw.True v = u.window.GetAttrib(glfw.Decorated) == glfw.True
return nil return nil
}) })
@ -509,7 +509,7 @@ func (u *UserInterface) SetWindowDecorated(decorated bool) {
// TODO: Now SetAttrib doesn't exist on GLFW 3.2. Revisit later (#556). // TODO: Now SetAttrib doesn't exist on GLFW 3.2. Revisit later (#556).
// If SetAttrib exists, the implementation would be: // If SetAttrib exists, the implementation would be:
// //
// _ = u.t.Run(func() error { // _ = u.t.Call(func() error {
// v := glfw.False // v := glfw.False
// if decorated { // if decorated {
// v = glfw.True // v = glfw.True
@ -524,7 +524,7 @@ func (u *UserInterface) IsWindowResizable() bool {
return u.isInitWindowResizable() return u.isInitWindowResizable()
} }
v := false v := false
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
v = u.window.GetAttrib(glfw.Resizable) == glfw.True v = u.window.GetAttrib(glfw.Resizable) == glfw.True
return nil return nil
}) })
@ -548,7 +548,7 @@ func (u *UserInterface) DeviceScaleFactor() float64 {
return devicescale.GetAt(u.initMonitor.GetPos()) return devicescale.GetAt(u.initMonitor.GetPos())
} }
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
m := u.currentMonitor() m := u.currentMonitor()
f = devicescale.GetAt(m.GetPos()) f = devicescale.GetAt(m.GetPos())
return nil return nil
@ -584,7 +584,7 @@ func (u *UserInterface) RunWithoutMainLoop(width, height int, scale float64, tit
} }
func (u *UserInterface) run(width, height int, scale float64, title string, context driver.UIContext, graphics driver.Graphics) error { func (u *UserInterface) run(width, height int, scale float64, title string, context driver.UIContext, graphics driver.Graphics) error {
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
u.graphics = graphics u.graphics = graphics
u.graphics.SetThread(u.t) u.graphics.SetThread(u.t)
@ -686,7 +686,7 @@ func (u *UserInterface) run(width, height int, scale float64, title string, cont
}) })
var w uintptr var w uintptr
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
w = u.nativeWindow() w = u.nativeWindow()
return nil return nil
}) })
@ -732,7 +732,7 @@ func (u *UserInterface) updateSize(context driver.UIContext) {
actualScale := 0.0 actualScale := 0.0
sizeChanged := false sizeChanged := false
// TODO: Is it possible to reduce 'runOnMainThread' calls? // TODO: Is it possible to reduce 'runOnMainThread' calls?
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
actualScale = u.actualScreenScale() actualScale = u.actualScreenScale()
if u.lastActualScale != actualScale { if u.lastActualScale != actualScale {
u.forceSetScreenSize(u.width, u.height, u.scale, u.isFullscreen(), u.vsync) u.forceSetScreenSize(u.width, u.height, u.scale, u.isFullscreen(), u.vsync)
@ -754,7 +754,7 @@ func (u *UserInterface) updateSize(context driver.UIContext) {
func (u *UserInterface) update(context driver.UIContext) error { func (u *UserInterface) update(context driver.UIContext) error {
shouldClose := false shouldClose := false
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
shouldClose = u.window.ShouldClose() shouldClose = u.window.ShouldClose()
return nil return nil
}) })
@ -762,7 +762,7 @@ func (u *UserInterface) update(context driver.UIContext) error {
return driver.RegularTermination return driver.RegularTermination
} }
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
if u.isInitFullscreen() { if u.isInitFullscreen() {
u.setScreenSize(u.width, u.height, u.scale, true, u.vsync) u.setScreenSize(u.width, u.height, u.scale, true, u.vsync)
u.setInitFullscreen(false) u.setInitFullscreen(false)
@ -773,7 +773,7 @@ func (u *UserInterface) update(context driver.UIContext) error {
// This call is needed for initialization. // This call is needed for initialization.
u.updateSize(context) u.updateSize(context)
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
glfw.PollEvents() glfw.PollEvents()
u.input.update(u.window, u.getScale()*u.glfwScale()) u.input.update(u.window, u.getScale()*u.glfwScale())
@ -799,7 +799,7 @@ func (u *UserInterface) update(context driver.UIContext) error {
} }
// Update the screen size when the window is resizable. // Update the screen size when the window is resizable.
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
w, h := u.reqWidth, u.reqHeight w, h := u.reqWidth, u.reqHeight
if w != 0 || h != 0 { if w != 0 || h != 0 {
u.setScreenSize(w, h, u.scale, u.isFullscreen(), u.vsync) u.setScreenSize(w, h, u.scale, u.isFullscreen(), u.vsync)
@ -813,7 +813,7 @@ func (u *UserInterface) update(context driver.UIContext) error {
func (u *UserInterface) loop(context driver.UIContext) error { func (u *UserInterface) loop(context driver.UIContext) error {
defer func() { defer func() {
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
glfw.Terminate() glfw.Terminate()
return nil return nil
}) })
@ -827,7 +827,7 @@ func (u *UserInterface) loop(context driver.UIContext) error {
vsync := u.vsync vsync := u.vsync
u.m.Unlock() u.m.Unlock()
_ = u.t.Run(func() error { _ = u.t.Call(func() error {
if !vsync { if !vsync {
u.swapBuffers() u.swapBuffers()
return nil return nil