mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
opengl: Consider framebuffer size on iOS
This commit is contained in:
parent
98fccb563e
commit
83ab4352f8
@ -44,6 +44,8 @@ type context struct {
|
|||||||
gl mgl.Context
|
gl mgl.Context
|
||||||
worker mgl.Worker
|
worker mgl.Worker
|
||||||
initialized chan struct{}
|
initialized chan struct{}
|
||||||
|
screenFramebufferWidth int
|
||||||
|
screenFramebufferHeight int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContext() (*Context, error) {
|
func NewContext() (*Context, error) {
|
||||||
@ -79,11 +81,22 @@ func NewContext() (*Context, error) {
|
|||||||
c.BlendFunc(CompositeModeSourceOver)
|
c.BlendFunc(CompositeModeSourceOver)
|
||||||
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
|
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
|
||||||
c.screenFramebuffer = Framebuffer(mgl.Framebuffer{uint32(f)})
|
c.screenFramebuffer = Framebuffer(mgl.Framebuffer{uint32(f)})
|
||||||
|
// It is invalid to get the size of the deafult framebuffer.
|
||||||
|
if c.screenFramebuffer.Value != 0 {
|
||||||
|
width := c.gl.GetRenderbufferParameteri(mgl.RENDERBUFFER, mgl.RENDERBUFFER_WIDTH)
|
||||||
|
height := c.gl.GetRenderbufferParameteri(mgl.RENDERBUFFER, mgl.RENDERBUFFER_HEIGHT)
|
||||||
|
c.screenFramebufferWidth = width
|
||||||
|
c.screenFramebufferHeight = height
|
||||||
|
}
|
||||||
close(c.initialized)
|
close(c.initialized)
|
||||||
}()
|
}()
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) ScreenFramebufferSize() (int, int) {
|
||||||
|
return c.screenFramebufferWidth, c.screenFramebufferHeight
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) Resume() error {
|
func (c *Context) Resume() error {
|
||||||
c.locationCache = newLocationCache()
|
c.locationCache = newLocationCache()
|
||||||
c.lastFramebuffer = invalidFramebuffer
|
c.lastFramebuffer = invalidFramebuffer
|
||||||
@ -94,12 +107,12 @@ func (c *Context) Resume() error {
|
|||||||
c.BlendFunc(CompositeModeSourceOver)
|
c.BlendFunc(CompositeModeSourceOver)
|
||||||
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
|
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
|
||||||
c.screenFramebuffer = Framebuffer(mgl.Framebuffer{uint32(f)})
|
c.screenFramebuffer = Framebuffer(mgl.Framebuffer{uint32(f)})
|
||||||
|
// TODO: Need to update screenFramebufferWidth/Height?
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) WaitUntilInitializingDone() {
|
func (c *Context) InitializedCh() <-chan struct{} {
|
||||||
// TODO: Call this function at an approriate place
|
return c.initialized
|
||||||
<-c.initialized
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Worker() mgl.Worker {
|
func (c *Context) Worker() mgl.Worker {
|
||||||
|
@ -36,6 +36,13 @@ func Render(chError <-chan error) error {
|
|||||||
return errors.New("ui: chError must not be nil")
|
return errors.New("ui: chError must not be nil")
|
||||||
}
|
}
|
||||||
// TODO: Check this is called on the rendering thread
|
// TODO: Check this is called on the rendering thread
|
||||||
|
if chGLInitialized != nil {
|
||||||
|
if err := doGLWorks(chError, glContext.InitializedCh()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
close(chGLInitialized)
|
||||||
|
<-chGLInitializedEnd
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case chRender <- struct{}{}:
|
case chRender <- struct{}{}:
|
||||||
return doGLWorks(chError, chRenderEnd)
|
return doGLWorks(chError, chRenderEnd)
|
||||||
@ -70,12 +77,15 @@ type userInterface struct {
|
|||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
scale int
|
scale int
|
||||||
|
framebufferScale int
|
||||||
sizeChanged bool
|
sizeChanged bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
chRender = make(chan struct{})
|
chRender = make(chan struct{})
|
||||||
chRenderEnd = make(chan struct{})
|
chRenderEnd = make(chan struct{})
|
||||||
|
chGLInitialized = make(chan struct{})
|
||||||
|
chGLInitializedEnd = make(chan struct{})
|
||||||
currentUI = &userInterface{
|
currentUI = &userInterface{
|
||||||
sizeChanged: true,
|
sizeChanged: true,
|
||||||
}
|
}
|
||||||
@ -99,6 +109,11 @@ func (u *userInterface) Terminate() error {
|
|||||||
|
|
||||||
func (u *userInterface) Update() (interface{}, error) {
|
func (u *userInterface) Update() (interface{}, error) {
|
||||||
// TODO: Need lock?
|
// TODO: Need lock?
|
||||||
|
if chGLInitialized != nil {
|
||||||
|
<-chGLInitialized
|
||||||
|
chGLInitialized = nil
|
||||||
|
close(chGLInitializedEnd)
|
||||||
|
}
|
||||||
if u.sizeChanged {
|
if u.sizeChanged {
|
||||||
u.sizeChanged = false
|
u.sizeChanged = false
|
||||||
e := ScreenSizeEvent{
|
e := ScreenSizeEvent{
|
||||||
@ -132,7 +147,17 @@ func (u *userInterface) ScreenScale() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) actualScreenScale() int {
|
func (u *userInterface) actualScreenScale() int {
|
||||||
return u.scale
|
if u.framebufferScale == 0 {
|
||||||
|
width, _ := glContext.ScreenFramebufferSize()
|
||||||
|
if width == 0 {
|
||||||
|
// Android
|
||||||
|
u.framebufferScale = 1
|
||||||
|
} else {
|
||||||
|
// iOS
|
||||||
|
u.framebufferScale = width / u.width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return u.scale * u.framebufferScale
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateTouches(touches []Touch) {
|
func UpdateTouches(touches []Touch) {
|
||||||
|
Loading…
Reference in New Issue
Block a user