2014-12-09 15:16:04 +01:00
|
|
|
/*
|
|
|
|
Copyright 2014 Hajime Hoshi
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
package ebiten
|
2014-12-08 17:08:47 +01:00
|
|
|
|
2014-12-14 13:04:26 +01:00
|
|
|
type syncer interface {
|
|
|
|
Sync(f func())
|
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
type syncGraphicsContext struct {
|
2014-12-14 13:04:26 +01:00
|
|
|
syncer syncer
|
|
|
|
innerGraphicsContext GraphicsContext
|
2014-12-08 17:08:47 +01:00
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
var _ GraphicsContext = new(syncGraphicsContext)
|
2014-12-08 17:08:47 +01:00
|
|
|
|
2014-12-14 13:38:54 +01:00
|
|
|
func (c *syncGraphicsContext) Clear() (err error) {
|
2014-12-14 13:04:26 +01:00
|
|
|
c.syncer.Sync(func() {
|
2014-12-14 13:38:54 +01:00
|
|
|
err = c.innerGraphicsContext.Clear()
|
2014-12-08 17:08:47 +01:00
|
|
|
})
|
2014-12-14 13:38:54 +01:00
|
|
|
return
|
2014-12-08 17:08:47 +01:00
|
|
|
}
|
|
|
|
|
2014-12-14 13:38:54 +01:00
|
|
|
func (c *syncGraphicsContext) Fill(r, g, b uint8) (err error) {
|
2014-12-14 13:04:26 +01:00
|
|
|
c.syncer.Sync(func() {
|
2014-12-14 13:38:54 +01:00
|
|
|
err = c.innerGraphicsContext.Fill(r, g, b)
|
2014-12-08 17:08:47 +01:00
|
|
|
})
|
2014-12-14 13:38:54 +01:00
|
|
|
return
|
2014-12-08 17:08:47 +01:00
|
|
|
}
|
|
|
|
|
2014-12-18 14:24:27 +01:00
|
|
|
func (c *syncGraphicsContext) DrawTexture(texture *Texture, parts []TexturePart, geo GeometryMatrix, color ColorMatrix) (err error) {
|
2014-12-14 13:04:26 +01:00
|
|
|
c.syncer.Sync(func() {
|
2014-12-18 14:24:27 +01:00
|
|
|
err = c.innerGraphicsContext.DrawTexture(texture, parts, geo, color)
|
2014-12-08 17:08:47 +01:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
func (c *syncGraphicsContext) PopRenderTarget() {
|
2014-12-14 13:04:26 +01:00
|
|
|
c.syncer.Sync(func() {
|
|
|
|
c.innerGraphicsContext.PopRenderTarget()
|
2014-12-08 17:08:47 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-17 14:04:33 +01:00
|
|
|
func (c *syncGraphicsContext) PushRenderTarget(renderTarget *RenderTarget) {
|
2014-12-14 13:04:26 +01:00
|
|
|
c.syncer.Sync(func() {
|
2014-12-17 14:04:33 +01:00
|
|
|
c.innerGraphicsContext.PushRenderTarget(renderTarget)
|
2014-12-08 17:08:47 +01:00
|
|
|
})
|
|
|
|
}
|