mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
graphics: Reduce calls of ui.GLContext()
This commit is contained in:
parent
f29ff4a9e2
commit
fbc1a4238c
@ -19,7 +19,6 @@ import (
|
|||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func newGraphicsContext(f func(*Image) error) *graphicsContext {
|
func newGraphicsContext(f func(*Image) error) *graphicsContext {
|
||||||
@ -131,8 +130,8 @@ func (c *graphicsContext) drawToDefaultRenderTarget(context *opengl.Context) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *graphicsContext) UpdateAndDraw(updateCount int) error {
|
func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int) error {
|
||||||
if err := c.initializeIfNeeded(ui.GLContext()); err != nil {
|
if err := c.initializeIfNeeded(context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := 0; i < updateCount; i++ {
|
for i := 0; i < updateCount; i++ {
|
||||||
@ -150,20 +149,20 @@ func (c *graphicsContext) UpdateAndDraw(updateCount int) error {
|
|||||||
if err := drawWithFittingScale(c.offscreen2, c.offscreen); err != nil {
|
if err := drawWithFittingScale(c.offscreen2, c.offscreen); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.drawToDefaultRenderTarget(ui.GLContext()); err != nil {
|
if err := c.drawToDefaultRenderTarget(context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := theImages.savePixels(ui.GLContext()); err != nil {
|
if err := theImages.savePixels(context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *graphicsContext) Draw() error {
|
func (c *graphicsContext) Draw(context *opengl.Context) error {
|
||||||
if err := c.initializeIfNeeded(ui.GLContext()); err != nil {
|
if err := c.initializeIfNeeded(context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.drawToDefaultRenderTarget(ui.GLContext()); err != nil {
|
if err := c.drawToDefaultRenderTarget(context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -79,8 +80,8 @@ func (c *runContext) updateFPS(fps float64) {
|
|||||||
|
|
||||||
type GraphicsContext interface {
|
type GraphicsContext interface {
|
||||||
SetSize(width, height int, scale float64) error
|
SetSize(width, height int, scale float64) error
|
||||||
UpdateAndDraw(updateCount int) error
|
UpdateAndDraw(context *opengl.Context, updateCount int) error
|
||||||
Draw() error
|
Draw(context *opengl.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run(g GraphicsContext, width, height int, scale float64, title string, fps int) error {
|
func Run(g GraphicsContext, width, height int, scale float64, title string, fps int) error {
|
||||||
@ -155,11 +156,11 @@ func (c *runContext) render(g GraphicsContext) error {
|
|||||||
tt = 1
|
tt = 1
|
||||||
}
|
}
|
||||||
if 1 <= tt {
|
if 1 <= tt {
|
||||||
if err := g.UpdateAndDraw(tt); err != nil {
|
if err := g.UpdateAndDraw(ui.GLContext(), tt); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := g.Draw(); err != nil {
|
if err := g.Draw(ui.GLContext()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user