mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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/opengl"
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
|
||||
func newGraphicsContext(f func(*Image) error) *graphicsContext {
|
||||
@ -131,8 +130,8 @@ func (c *graphicsContext) drawToDefaultRenderTarget(context *opengl.Context) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *graphicsContext) UpdateAndDraw(updateCount int) error {
|
||||
if err := c.initializeIfNeeded(ui.GLContext()); err != nil {
|
||||
func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int) error {
|
||||
if err := c.initializeIfNeeded(context); err != nil {
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
if err := c.drawToDefaultRenderTarget(ui.GLContext()); err != nil {
|
||||
if err := c.drawToDefaultRenderTarget(context); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := theImages.savePixels(ui.GLContext()); err != nil {
|
||||
if err := theImages.savePixels(context); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *graphicsContext) Draw() error {
|
||||
if err := c.initializeIfNeeded(ui.GLContext()); err != nil {
|
||||
func (c *graphicsContext) Draw(context *opengl.Context) error {
|
||||
if err := c.initializeIfNeeded(context); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.drawToDefaultRenderTarget(ui.GLContext()); err != nil {
|
||||
if err := c.drawToDefaultRenderTarget(context); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
|
||||
@ -79,8 +80,8 @@ func (c *runContext) updateFPS(fps float64) {
|
||||
|
||||
type GraphicsContext interface {
|
||||
SetSize(width, height int, scale float64) error
|
||||
UpdateAndDraw(updateCount int) error
|
||||
Draw() error
|
||||
UpdateAndDraw(context *opengl.Context, updateCount int) error
|
||||
Draw(context *opengl.Context) 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
|
||||
}
|
||||
if 1 <= tt {
|
||||
if err := g.UpdateAndDraw(tt); err != nil {
|
||||
if err := g.UpdateAndDraw(ui.GLContext(), tt); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := g.Draw(); err != nil {
|
||||
if err := g.Draw(ui.GLContext()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user