ebiten/graphics/opengl/offscreen/offscreen.go

63 lines
1.6 KiB
Go
Raw Normal View History

2013-11-26 17:46:07 +01:00
package offscreen
import (
"github.com/hajimehoshi/go-ebiten/graphics"
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
)
2014-01-10 13:28:50 +01:00
type Texture interface {
Draw(projectionMatrix [4][4]float64,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color)
DrawParts(parts []graphics.TexturePart, projectionMatrix [4][4]float64,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color)
2013-11-26 17:46:07 +01:00
}
2014-01-10 13:28:50 +01:00
type RenderTarget interface {
SetAsViewport()
ProjectionMatrix() [4][4]float64
2014-01-11 00:20:05 +01:00
Clear()
Fill(r, g, b uint8)
2014-01-10 13:28:50 +01:00
}
2013-11-26 17:46:07 +01:00
2014-01-10 13:28:50 +01:00
type Offscreen struct {
currentRenderTarget RenderTarget
mainFramebuffer RenderTarget
}
2013-11-26 17:46:07 +01:00
2014-01-10 13:28:50 +01:00
func New(mainFramebuffer RenderTarget) *Offscreen {
return &Offscreen{
mainFramebuffer: mainFramebuffer,
}
2013-11-26 17:46:07 +01:00
}
2014-01-10 13:28:50 +01:00
func (o *Offscreen) Set(rt RenderTarget) {
2014-01-08 08:38:03 +01:00
o.currentRenderTarget = rt
2013-11-26 17:46:07 +01:00
}
func (o *Offscreen) SetMainFramebuffer() {
2014-01-10 13:28:50 +01:00
o.Set(o.mainFramebuffer)
2013-11-26 17:46:07 +01:00
}
2014-01-10 13:28:50 +01:00
func (o *Offscreen) DrawTexture(texture Texture,
2013-11-26 17:46:07 +01:00
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
2014-01-11 00:20:05 +01:00
o.currentRenderTarget.SetAsViewport()
2014-01-10 13:28:50 +01:00
projectionMatrix := o.currentRenderTarget.ProjectionMatrix()
texture.Draw(projectionMatrix, geometryMatrix, colorMatrix)
2013-11-26 17:46:07 +01:00
}
2014-01-10 13:28:50 +01:00
func (o *Offscreen) DrawTextureParts(texture Texture,
2013-11-26 17:46:07 +01:00
parts []graphics.TexturePart,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
2014-01-11 00:20:05 +01:00
o.currentRenderTarget.SetAsViewport()
2014-01-10 13:28:50 +01:00
projectionMatrix := o.currentRenderTarget.ProjectionMatrix()
2014-01-08 10:03:21 +01:00
texture.DrawParts(parts, projectionMatrix, geometryMatrix, colorMatrix)
2013-11-26 17:46:07 +01:00
}
2014-01-11 00:20:05 +01:00
func (o *Offscreen) Clear() {
o.currentRenderTarget.Clear()
}
func (o *Offscreen) Fill(r, g, b uint8) {
o.currentRenderTarget.Fill(r, g, b)
}