mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
Remove Texture/RenderTarget
This commit is contained in:
parent
fd0ba69f0b
commit
db4e3fdc03
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Input struct {
|
type Input struct {
|
||||||
textTexture graphics.Texture
|
textTextureID graphics.TextureID
|
||||||
inputState ebiten.InputState
|
inputState ebiten.InputState
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ func (game *Input) Init(tf graphics.TextureFactory) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if game.textTexture, err = tf.NewTextureFromImage(img); err != nil {
|
if game.textTextureID, err = tf.NewTextureFromImage(img); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,6 +74,6 @@ func (game *Input) drawText(g graphics.Context, text string, x, y int) {
|
|||||||
geometryMatrix := matrix.IdentityGeometry()
|
geometryMatrix := matrix.IdentityGeometry()
|
||||||
geometryMatrix.Translate(float64(x), float64(y))
|
geometryMatrix.Translate(float64(x), float64(y))
|
||||||
colorMatrix := matrix.IdentityColor()
|
colorMatrix := matrix.IdentityColor()
|
||||||
g.DrawTextureParts(game.textTexture.ID(), parts,
|
g.DrawTextureParts(game.textTextureID, parts,
|
||||||
geometryMatrix, colorMatrix)
|
geometryMatrix, colorMatrix)
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Monochrome struct {
|
type Monochrome struct {
|
||||||
ebitenTexture graphics.Texture
|
ebitenTextureID graphics.TextureID
|
||||||
ch chan bool
|
ch chan bool
|
||||||
colorMatrix matrix.Color
|
colorMatrix matrix.Color
|
||||||
geometryMatrix matrix.Geometry
|
geometryMatrix matrix.Geometry
|
||||||
@ -40,7 +40,7 @@ func (game *Monochrome) Init(tf graphics.TextureFactory) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if game.ebitenTexture, err = tf.NewTextureFromImage(img); err != nil {
|
if game.ebitenTextureID, err = tf.NewTextureFromImage(img); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +102,6 @@ func (game *Monochrome) Update(context ebiten.GameContext) {
|
|||||||
func (game *Monochrome) Draw(g graphics.Context) {
|
func (game *Monochrome) Draw(g graphics.Context) {
|
||||||
g.Fill(128, 128, 255)
|
g.Fill(128, 128, 255)
|
||||||
|
|
||||||
g.DrawTexture(game.ebitenTexture.ID(),
|
g.DrawTexture(game.ebitenTextureID,
|
||||||
game.geometryMatrix, game.colorMatrix)
|
game.geometryMatrix, game.colorMatrix)
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Rects struct {
|
type Rects struct {
|
||||||
rectTexture graphics.RenderTarget
|
rectTextureID graphics.RenderTargetID
|
||||||
rectTextureInited bool
|
rectTextureInited bool
|
||||||
offscreen graphics.RenderTarget
|
offscreenID graphics.RenderTargetID
|
||||||
offscreenInited bool
|
offscreenInited bool
|
||||||
rectBounds *graphics.Rect
|
rectBounds *graphics.Rect
|
||||||
rectColor *color.RGBA
|
rectColor *color.RGBA
|
||||||
@ -36,8 +36,8 @@ func New() *Rects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) Init(tf graphics.TextureFactory) {
|
func (game *Rects) Init(tf graphics.TextureFactory) {
|
||||||
game.rectTexture = tf.NewRenderTarget(rectTextureWidth, rectTextureHeight)
|
game.rectTextureID = tf.NewRenderTarget(rectTextureWidth, rectTextureHeight)
|
||||||
game.offscreen = tf.NewRenderTarget(offscreenWidth, offscreenHeight)
|
game.offscreenID = tf.NewRenderTarget(offscreenWidth, offscreenHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) Update(context ebiten.GameContext) {
|
func (game *Rects) Update(context ebiten.GameContext) {
|
||||||
@ -81,22 +81,22 @@ func (game *Rects) rectColorMatrix() matrix.Color {
|
|||||||
|
|
||||||
func (game *Rects) Draw(g graphics.Context) {
|
func (game *Rects) Draw(g graphics.Context) {
|
||||||
if !game.rectTextureInited {
|
if !game.rectTextureInited {
|
||||||
g.SetOffscreen(game.rectTexture.ID())
|
g.SetOffscreen(game.rectTextureID)
|
||||||
g.Fill(255, 255, 255)
|
g.Fill(255, 255, 255)
|
||||||
game.rectTextureInited = true
|
game.rectTextureInited = true
|
||||||
}
|
}
|
||||||
|
|
||||||
g.SetOffscreen(game.offscreen.ID())
|
g.SetOffscreen(game.offscreenID)
|
||||||
if !game.offscreenInited {
|
if !game.offscreenInited {
|
||||||
g.Fill(0, 0, 0)
|
g.Fill(0, 0, 0)
|
||||||
game.offscreenInited = true
|
game.offscreenInited = true
|
||||||
}
|
}
|
||||||
g.DrawTexture(game.rectTexture.Texture().ID(),
|
g.DrawTexture(g.TextureID(game.rectTextureID),
|
||||||
game.rectGeometryMatrix(),
|
game.rectGeometryMatrix(),
|
||||||
game.rectColorMatrix())
|
game.rectColorMatrix())
|
||||||
|
|
||||||
g.ResetOffscreen()
|
g.ResetOffscreen()
|
||||||
g.DrawTexture(game.offscreen.Texture().ID(),
|
g.DrawTexture(g.TextureID(game.offscreenID),
|
||||||
matrix.IdentityGeometry(),
|
matrix.IdentityGeometry(),
|
||||||
matrix.IdentityColor())
|
matrix.IdentityColor())
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Rotating struct {
|
type Rotating struct {
|
||||||
ebitenTexture graphics.Texture
|
ebitenTextureID graphics.TextureID
|
||||||
x int
|
x int
|
||||||
geometryMatrix matrix.Geometry
|
geometryMatrix matrix.Geometry
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ func (game *Rotating) Init(tf graphics.TextureFactory) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if game.ebitenTexture, err = tf.NewTextureFromImage(img); err != nil {
|
if game.ebitenTextureID, err = tf.NewTextureFromImage(img); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func (game *Rotating) Update(context ebiten.GameContext) {
|
|||||||
|
|
||||||
func (game *Rotating) Draw(g graphics.Context) {
|
func (game *Rotating) Draw(g graphics.Context) {
|
||||||
g.Fill(128, 128, 255)
|
g.Fill(128, 128, 255)
|
||||||
g.DrawTexture(game.ebitenTexture.ID(),
|
g.DrawTexture(game.ebitenTextureID,
|
||||||
game.geometryMatrix,
|
game.geometryMatrix,
|
||||||
matrix.IdentityColor())
|
matrix.IdentityColor())
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ func (sprite *Sprite) Update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Sprites struct {
|
type Sprites struct {
|
||||||
ebitenTexture graphics.Texture
|
ebitenTextureID graphics.TextureID
|
||||||
sprites []*Sprite
|
sprites []*Sprite
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ func (game *Sprites) Init(tf graphics.TextureFactory) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if game.ebitenTexture, err = tf.NewTextureFromImage(img); err != nil {
|
if game.ebitenTextureID, err = tf.NewTextureFromImage(img); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +111,6 @@ func (game *Sprites) Draw(g graphics.Context) {
|
|||||||
|
|
||||||
// Draw the sprites
|
// Draw the sprites
|
||||||
locations := make([]graphics.TexturePart, 0, len(game.sprites))
|
locations := make([]graphics.TexturePart, 0, len(game.sprites))
|
||||||
texture := game.ebitenTexture
|
|
||||||
for _, sprite := range game.sprites {
|
for _, sprite := range game.sprites {
|
||||||
location := graphics.TexturePart{
|
location := graphics.TexturePart{
|
||||||
LocationX: sprite.x,
|
LocationX: sprite.x,
|
||||||
@ -123,7 +122,7 @@ func (game *Sprites) Draw(g graphics.Context) {
|
|||||||
locations = append(locations, location)
|
locations = append(locations, location)
|
||||||
}
|
}
|
||||||
geometryMatrix := matrix.IdentityGeometry()
|
geometryMatrix := matrix.IdentityGeometry()
|
||||||
g.DrawTextureParts(texture.ID(), locations,
|
g.DrawTextureParts(game.ebitenTextureID, locations,
|
||||||
geometryMatrix, matrix.IdentityColor())
|
geometryMatrix, matrix.IdentityColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ type TexturePart struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Context interface {
|
type Context interface {
|
||||||
|
TextureID(renderTargetID RenderTargetID) TextureID
|
||||||
|
|
||||||
Clear()
|
Clear()
|
||||||
Fill(r, g, b uint8)
|
Fill(r, g, b uint8)
|
||||||
DrawTexture(textureID TextureID,
|
DrawTexture(textureID TextureID,
|
||||||
@ -33,21 +35,12 @@ type Context interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TextureFactory interface {
|
type TextureFactory interface {
|
||||||
NewRenderTarget(width, height int) RenderTarget
|
NewRenderTarget(width, height int) RenderTargetID
|
||||||
NewTextureFromImage(img image.Image) (Texture, error)
|
NewTextureFromImage(img image.Image) (TextureID, error)
|
||||||
}
|
|
||||||
|
|
||||||
type Texture interface {
|
|
||||||
ID() TextureID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TextureID int
|
type TextureID int
|
||||||
|
|
||||||
// The interface of a render target. This is essentially same as a texture, but
|
// A render target is essentially same as a texture, but it is assumed that the
|
||||||
// it is assumed that the all alpha of a render target is maximum.
|
// all alpha of a render target is maximum.
|
||||||
type RenderTarget interface {
|
|
||||||
Texture() Texture
|
|
||||||
ID() RenderTargetID
|
|
||||||
}
|
|
||||||
|
|
||||||
type RenderTargetID int
|
type RenderTargetID int
|
||||||
|
@ -47,8 +47,13 @@ func (context *Context) Init() {
|
|||||||
|
|
||||||
initializeShaders()
|
initializeShaders()
|
||||||
|
|
||||||
context.screen = context.NewRenderTarget(
|
screenID := context.NewRenderTarget(
|
||||||
context.screenWidth, context.screenHeight).(*RenderTarget)
|
context.screenWidth, context.screenHeight)
|
||||||
|
context.screen = (*RenderTarget)(context.textures[C.GLuint(screenID)])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (context *Context) TextureID(renderTargetID graphics.RenderTargetID) graphics.TextureID {
|
||||||
|
return graphics.TextureID(renderTargetID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) Clear() {
|
func (context *Context) Clear() {
|
||||||
@ -284,7 +289,7 @@ func createFramebuffer(textureID C.GLuint) C.GLuint {
|
|||||||
return framebuffer
|
return framebuffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) NewRenderTarget(width, height int) graphics.RenderTarget {
|
func (context *Context) NewRenderTarget(width, height int) graphics.RenderTargetID {
|
||||||
renderTarget := newRenderTarget(width, height)
|
renderTarget := newRenderTarget(width, height)
|
||||||
context.textures[renderTarget.id] = (*Texture)(renderTarget)
|
context.textures[renderTarget.id] = (*Texture)(renderTarget)
|
||||||
|
|
||||||
@ -292,15 +297,15 @@ func (context *Context) NewRenderTarget(width, height int) graphics.RenderTarget
|
|||||||
context.Clear()
|
context.Clear()
|
||||||
context.resetOffscreen()
|
context.resetOffscreen()
|
||||||
|
|
||||||
return renderTarget
|
return renderTarget.ID()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) NewTextureFromImage(img image.Image) (
|
func (context *Context) NewTextureFromImage(img image.Image) (
|
||||||
graphics.Texture, error) {
|
graphics.TextureID, error) {
|
||||||
texture, err := newTextureFromImage(img)
|
texture, err := newTextureFromImage(img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return 0, err
|
||||||
}
|
}
|
||||||
context.textures[texture.id] = texture
|
context.textures[texture.id] = texture
|
||||||
return texture, nil
|
return texture.ID(), nil
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func (device *Device) Update(draw func(graphics.Context)) {
|
|||||||
{0, scale, 0},
|
{0, scale, 0},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
context.DrawTexture(context.screen.Texture().ID(),
|
context.DrawTexture(context.screen.TextureID(),
|
||||||
geometryMatrix, matrix.IdentityColor())
|
geometryMatrix, matrix.IdentityColor())
|
||||||
context.flush()
|
context.flush()
|
||||||
}
|
}
|
||||||
|
@ -137,8 +137,8 @@ func newRenderTargetWithFramebuffer(width, height int,
|
|||||||
|
|
||||||
type RenderTarget Texture
|
type RenderTarget Texture
|
||||||
|
|
||||||
func (renderTarget *RenderTarget) Texture() graphics.Texture {
|
func (renderTarget *RenderTarget) TextureID() graphics.TextureID {
|
||||||
return (*Texture)(renderTarget)
|
return graphics.TextureID(renderTarget.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderTarget *RenderTarget) ID() graphics.RenderTargetID {
|
func (renderTarget *RenderTarget) ID() graphics.RenderTargetID {
|
||||||
|
Loading…
Reference in New Issue
Block a user