ebiten/graphics/opengl/offscreen/offscreen.go

52 lines
1.3 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
}
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
rt.SetAsViewport()
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-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-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
}