mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +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) {
|
||||
game.rectTextureID = tf.NewRenderTarget(rectTextureWidth, rectTextureHeight)
|
||||
game.offscreenID = tf.NewRenderTarget(offscreenWidth, offscreenHeight)
|
||||
var err error
|
||||
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) {
|
||||
|
@ -35,7 +35,7 @@ type Context interface {
|
||||
}
|
||||
|
||||
type TextureFactory interface {
|
||||
NewRenderTarget(width, height int) RenderTargetID
|
||||
NewRenderTarget(width, height int) (RenderTargetID, error)
|
||||
NewTextureFromImage(img image.Image) (TextureID, error)
|
||||
}
|
||||
|
||||
|
@ -51,8 +51,12 @@ func (context *Context) Init() {
|
||||
|
||||
initializeShaders()
|
||||
|
||||
context.screenId = context.NewRenderTarget(
|
||||
var err error
|
||||
context.screenId, err = context.NewRenderTarget(
|
||||
context.screenWidth, context.screenHeight)
|
||||
if err != nil {
|
||||
panic("initializing the offscreen failed: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (context *Context) ToTexture(renderTargetID graphics.RenderTargetID) graphics.TextureID {
|
||||
@ -262,8 +266,12 @@ func (context *Context) setShaderProgram(
|
||||
return
|
||||
}
|
||||
|
||||
func (context *Context) NewRenderTarget(width, height int) graphics.RenderTargetID {
|
||||
renderTarget := newRenderTarget(width, height)
|
||||
func (context *Context) NewRenderTarget(width, height int) (
|
||||
graphics.RenderTargetID, error) {
|
||||
renderTarget, err := newRenderTarget(width, height)
|
||||
if err != nil {
|
||||
return 0, nil
|
||||
}
|
||||
renderTargetId := graphics.RenderTargetID(<-newId)
|
||||
textureId := graphics.TextureID(<-newId)
|
||||
context.renderTargets[renderTargetId] = renderTarget
|
||||
@ -274,7 +282,7 @@ func (context *Context) NewRenderTarget(width, height int) graphics.RenderTarget
|
||||
context.Clear()
|
||||
context.setMainFramebufferOffscreen()
|
||||
|
||||
return renderTargetId
|
||||
return renderTargetId, nil
|
||||
}
|
||||
|
||||
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()
|
||||
width, height := size.X, size.Y
|
||||
|
||||
@ -93,20 +102,7 @@ func createTextureFromImage(img image.Image) *Texture {
|
||||
textureWidth: textureWidth,
|
||||
textureHeight: textureHeight,
|
||||
native: nativeTexture,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newRenderTargetWithFramebuffer(width, height int,
|
||||
|
Loading…
Reference in New Issue
Block a user