graphics: Bug fix: Need to reset viewport size after resizing (#232)

This commit is contained in:
Hajime Hoshi 2016-06-18 06:25:40 +09:00
parent 5eb77d2fb5
commit 98fccb563e
6 changed files with 36 additions and 12 deletions

View File

@ -52,6 +52,7 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight, screenScale int) er
c.screen.Clear() c.screen.Clear()
c.offscreen = offscreen c.offscreen = offscreen
c.screenScale = screenScale c.screenScale = screenScale
ui.GLContext().ResetViewportSize()
return nil return nil
} }

View File

@ -54,10 +54,10 @@ func newFramebufferFromTexture(context *opengl.Context, texture *texture) (*fram
const viewportSize = 4096 const viewportSize = 4096
func (f *framebuffer) setAsViewport(c *opengl.Context) error { func (f *framebuffer) setAsViewport(context *opengl.Context) error {
width := viewportSize width := viewportSize
height := viewportSize height := viewportSize
return c.SetViewport(f.native, width, height) return context.SetViewport(f.native, width, height)
} }
func (f *framebuffer) projectionMatrix() *[4][4]float64 { func (f *framebuffer) projectionMatrix() *[4][4]float64 {

View File

@ -51,3 +51,8 @@ func (c *Context) bindFramebuffer(f Framebuffer) {
func (c *Context) ScreenFramebuffer() Framebuffer { func (c *Context) ScreenFramebuffer() Framebuffer {
return c.screenFramebuffer return c.screenFramebuffer
} }
func (c *Context) ResetViewportSize() {
c.lastViewportWidth = 0
c.lastViewportHeight = 0
}

View File

@ -104,23 +104,39 @@ func (c *Context) Init() error {
return err return err
} }
c.BlendFunc(CompositeModeSourceOver) c.BlendFunc(CompositeModeSourceOver)
f := int32(0) if err := c.RunOnContextThread(func() error {
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f) f := int32(0)
c.screenFramebuffer = Framebuffer(f) gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
c.screenFramebuffer = Framebuffer(f)
return nil
}); err != nil {
return err
}
return nil return nil
} }
func (c *Context) Resume() { func (c *Context) Resume() error {
c.locationCache = newLocationCache() c.locationCache = newLocationCache()
c.lastFramebuffer = invalidFramebuffer c.lastFramebuffer = invalidFramebuffer
c.lastViewportWidth = 0 c.lastViewportWidth = 0
c.lastViewportHeight = 0 c.lastViewportHeight = 0
c.lastCompositeMode = CompositeModeUnknown c.lastCompositeMode = CompositeModeUnknown
gl.Enable(gl.BLEND) if err := c.RunOnContextThread(func() error {
gl.Enable(gl.BLEND)
return nil
}); err != nil {
return err
}
c.BlendFunc(CompositeModeSourceOver) c.BlendFunc(CompositeModeSourceOver)
f := int32(0) if err := c.RunOnContextThread(func() error {
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f) f := int32(0)
c.screenFramebuffer = Framebuffer(f) gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
c.screenFramebuffer = Framebuffer(f)
return nil
}); err != nil {
return err
}
return nil
} }
func (c *Context) BlendFunc(mode CompositeMode) { func (c *Context) BlendFunc(mode CompositeMode) {

View File

@ -122,7 +122,7 @@ func (c *Context) init() {
c.screenFramebuffer = Framebuffer{f} c.screenFramebuffer = Framebuffer{f}
} }
func (c *Context) Resume() { func (c *Context) Resume() error {
c.locationCache = newLocationCache() c.locationCache = newLocationCache()
c.lastFramebuffer = invalidFramebuffer c.lastFramebuffer = invalidFramebuffer
c.lastViewportWidth = 0 c.lastViewportWidth = 0
@ -133,6 +133,7 @@ func (c *Context) Resume() {
c.BlendFunc(CompositeModeSourceOver) c.BlendFunc(CompositeModeSourceOver)
f := gl.GetParameter(gl.FRAMEBUFFER_BINDING) f := gl.GetParameter(gl.FRAMEBUFFER_BINDING)
c.screenFramebuffer = Framebuffer{f} c.screenFramebuffer = Framebuffer{f}
return nil
} }
func (c *Context) BlendFunc(mode CompositeMode) { func (c *Context) BlendFunc(mode CompositeMode) {

View File

@ -84,7 +84,7 @@ func NewContext() (*Context, error) {
return c, nil return c, nil
} }
func (c *Context) Resume() { func (c *Context) Resume() error {
c.locationCache = newLocationCache() c.locationCache = newLocationCache()
c.lastFramebuffer = invalidFramebuffer c.lastFramebuffer = invalidFramebuffer
c.lastViewportWidth = 0 c.lastViewportWidth = 0
@ -94,6 +94,7 @@ func (c *Context) Resume() {
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)})
return nil
} }
func (c *Context) WaitUntilInitializingDone() { func (c *Context) WaitUntilInitializingDone() {