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-08 17:08:47 +01:00
|
|
|
package glfw
|
|
|
|
|
|
|
|
import (
|
2014-12-09 14:09:22 +01:00
|
|
|
"github.com/hajimehoshi/ebiten"
|
2014-12-08 17:08:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type context struct {
|
|
|
|
canvas *canvas
|
|
|
|
}
|
|
|
|
|
2014-12-09 14:09:22 +01:00
|
|
|
var _ ebiten.GraphicsContext = new(context)
|
2014-12-08 17:08:47 +01:00
|
|
|
|
|
|
|
func (c *context) Clear() {
|
|
|
|
c.canvas.use(func() {
|
|
|
|
c.canvas.context.Clear()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *context) Fill(r, g, b uint8) {
|
|
|
|
c.canvas.use(func() {
|
|
|
|
c.canvas.context.Fill(r, g, b)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-09 14:09:22 +01:00
|
|
|
func (c *context) Texture(id ebiten.TextureID) (d ebiten.Drawer) {
|
2014-12-08 17:08:47 +01:00
|
|
|
c.canvas.use(func() {
|
|
|
|
d = &drawer{
|
|
|
|
canvas: c.canvas,
|
|
|
|
innerDrawer: c.canvas.context.Texture(id),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-09 14:09:22 +01:00
|
|
|
func (c *context) RenderTarget(id ebiten.RenderTargetID) (d ebiten.Drawer) {
|
2014-12-08 17:08:47 +01:00
|
|
|
c.canvas.use(func() {
|
|
|
|
d = &drawer{
|
|
|
|
canvas: c.canvas,
|
|
|
|
innerDrawer: c.canvas.context.RenderTarget(id),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *context) ResetOffscreen() {
|
|
|
|
c.canvas.use(func() {
|
|
|
|
c.canvas.context.ResetOffscreen()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-09 14:09:22 +01:00
|
|
|
func (c *context) SetOffscreen(id ebiten.RenderTargetID) {
|
2014-12-08 17:08:47 +01:00
|
|
|
c.canvas.use(func() {
|
|
|
|
c.canvas.context.SetOffscreen(id)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type drawer struct {
|
|
|
|
canvas *canvas
|
2014-12-09 14:09:22 +01:00
|
|
|
innerDrawer ebiten.Drawer
|
2014-12-08 17:08:47 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 14:09:22 +01:00
|
|
|
var _ ebiten.Drawer = new(drawer)
|
2014-12-08 17:08:47 +01:00
|
|
|
|
2014-12-09 14:09:22 +01:00
|
|
|
func (d *drawer) Draw(parts []ebiten.TexturePart, geo ebiten.GeometryMatrix, color ebiten.ColorMatrix) {
|
2014-12-08 17:08:47 +01:00
|
|
|
d.canvas.use(func() {
|
|
|
|
d.innerDrawer.Draw(parts, geo, color)
|
|
|
|
})
|
|
|
|
}
|