mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
Change TextureFactory.NewRenderTarget
This commit is contained in:
parent
ba931902b9
commit
3a383b3078
@ -36,8 +36,15 @@ func New() *Rects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) InitTextures(tf graphics.TextureFactory) {
|
func (game *Rects) InitTextures(tf graphics.TextureFactory) {
|
||||||
game.rectTextureID = tf.NewRenderTarget(rectTextureWidth, rectTextureHeight)
|
var err error
|
||||||
game.offscreenID = tf.NewRenderTarget(offscreenWidth, offscreenHeight)
|
game.rectTextureID, err = tf.NewRenderTarget(rectTextureWidth, rectTextureHeight)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
game.offscreenID, err = tf.NewRenderTarget(offscreenWidth, offscreenHeight)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Rects) Update(context ebiten.GameContext) {
|
func (game *Rects) Update(context ebiten.GameContext) {
|
||||||
|
@ -35,7 +35,7 @@ type Context interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TextureFactory interface {
|
type TextureFactory interface {
|
||||||
NewRenderTarget(width, height int) RenderTargetID
|
NewRenderTarget(width, height int) (RenderTargetID, error)
|
||||||
NewTextureFromImage(img image.Image) (TextureID, error)
|
NewTextureFromImage(img image.Image) (TextureID, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,12 @@ func (context *Context) Init() {
|
|||||||
|
|
||||||
initializeShaders()
|
initializeShaders()
|
||||||
|
|
||||||
context.screenId = context.NewRenderTarget(
|
var err error
|
||||||
|
context.screenId, err = context.NewRenderTarget(
|
||||||
context.screenWidth, context.screenHeight)
|
context.screenWidth, context.screenHeight)
|
||||||
|
if err != nil {
|
||||||
|
panic("initializing the offscreen failed: " + err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) ToTexture(renderTargetID graphics.RenderTargetID) graphics.TextureID {
|
func (context *Context) ToTexture(renderTargetID graphics.RenderTargetID) graphics.TextureID {
|
||||||
@ -262,8 +266,12 @@ func (context *Context) setShaderProgram(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) NewRenderTarget(width, height int) graphics.RenderTargetID {
|
func (context *Context) NewRenderTarget(width, height int) (
|
||||||
renderTarget := newRenderTarget(width, height)
|
graphics.RenderTargetID, error) {
|
||||||
|
renderTarget, err := newRenderTarget(width, height)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
renderTargetId := graphics.RenderTargetID(<-newId)
|
renderTargetId := graphics.RenderTargetID(<-newId)
|
||||||
textureId := graphics.TextureID(<-newId)
|
textureId := graphics.TextureID(<-newId)
|
||||||
context.renderTargets[renderTargetId] = renderTarget
|
context.renderTargets[renderTargetId] = renderTarget
|
||||||
@ -274,7 +282,7 @@ func (context *Context) NewRenderTarget(width, height int) graphics.RenderTarget
|
|||||||
context.Clear()
|
context.Clear()
|
||||||
context.setMainFramebufferOffscreen()
|
context.setMainFramebufferOffscreen()
|
||||||
|
|
||||||
return renderTargetId
|
return renderTargetId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) NewTextureFromImage(img image.Image) (
|
func (context *Context) NewTextureFromImage(img image.Image) (
|
||||||
|
@ -67,7 +67,16 @@ func createTexture(width, height int) *Texture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTextureFromImage(img image.Image) *Texture {
|
func newRenderTarget(width, height int) (*RenderTarget, error) {
|
||||||
|
texture := createTexture(width, height)
|
||||||
|
framebuffer := createFramebuffer(texture.native)
|
||||||
|
return &RenderTarget{
|
||||||
|
texture: texture,
|
||||||
|
framebuffer: framebuffer,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTextureFromImage(img image.Image) (*Texture, error) {
|
||||||
size := img.Bounds().Size()
|
size := img.Bounds().Size()
|
||||||
width, height := size.X, size.Y
|
width, height := size.X, size.Y
|
||||||
|
|
||||||
@ -93,20 +102,7 @@ func createTextureFromImage(img image.Image) *Texture {
|
|||||||
textureWidth: textureWidth,
|
textureWidth: textureWidth,
|
||||||
textureHeight: textureHeight,
|
textureHeight: textureHeight,
|
||||||
native: nativeTexture,
|
native: nativeTexture,
|
||||||
}
|
}, nil
|
||||||
}
|
|
||||||
|
|
||||||
func newRenderTarget(width, height int) *RenderTarget {
|
|
||||||
texture := createTexture(width, height)
|
|
||||||
framebuffer := createFramebuffer(texture.native)
|
|
||||||
return &RenderTarget{
|
|
||||||
texture: texture,
|
|
||||||
framebuffer: framebuffer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newTextureFromImage(img image.Image) (*Texture, error) {
|
|
||||||
return createTextureFromImage(img), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRenderTargetWithFramebuffer(width, height int,
|
func newRenderTargetWithFramebuffer(width, height int,
|
||||||
|
Loading…
Reference in New Issue
Block a user