internal/graphicsdriver/opengl: refactoring: hide SetGLFWClientAPI

Updates #2714
This commit is contained in:
Hajime Hoshi 2023-12-20 02:46:31 +09:00
parent f6f0cf05e6
commit 4ef7b5c166
2 changed files with 30 additions and 32 deletions

View File

@ -38,36 +38,13 @@ func NewGraphics() (graphicsdriver.Graphics, error) {
return nil, err return nil, err
} }
setGLFWClientAPI(ctx.IsES())
return newGraphics(ctx), nil return newGraphics(ctx), nil
} }
func (g *Graphics) makeContextCurrent() { func setGLFWClientAPI(isES bool) error {
// TODO: Implement this (#2714). if isES {
}
func (g *Graphics) swapBuffers() error {
// Call SwapIntervals even though vsync is not changed.
// When toggling to fullscreen, vsync state might be reset unexpectedly (#1787).
// SwapInterval is affected by the current monitor of the window.
// This needs to be called at least after SetMonitor.
// Without SwapInterval after SetMonitor, vsynch doesn't work (#375).
if g.vsync {
if err := glfw.SwapInterval(1); err != nil {
return err
}
} else {
if err := glfw.SwapInterval(0); err != nil {
return err
}
}
// TODO: Implement this (#2714).
return nil
}
func (g *Graphics) SetGLFWClientAPI() error {
if g.context.ctx.IsES() {
if err := glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLESAPI); err != nil { if err := glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLESAPI); err != nil {
return err return err
} }
@ -103,3 +80,28 @@ func (g *Graphics) SetGLFWClientAPI() error {
} }
return nil return nil
} }
func (g *Graphics) makeContextCurrent() {
// TODO: Implement this (#2714).
}
func (g *Graphics) swapBuffers() error {
// Call SwapIntervals even though vsync is not changed.
// When toggling to fullscreen, vsync state might be reset unexpectedly (#1787).
// SwapInterval is affected by the current monitor of the window.
// This needs to be called at least after SetMonitor.
// Without SwapInterval after SetMonitor, vsynch doesn't work (#375).
if g.vsync {
if err := glfw.SwapInterval(1); err != nil {
return err
}
} else {
if err := glfw.SwapInterval(0); err != nil {
return err
}
}
// TODO: Implement this (#2714).
return nil
}

View File

@ -1106,11 +1106,7 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error {
u.setGraphicsLibrary(lib) u.setGraphicsLibrary(lib)
u.graphicsDriver.SetTransparent(options.ScreenTransparent) u.graphicsDriver.SetTransparent(options.ScreenTransparent)
if u.GraphicsLibrary() == GraphicsLibraryOpenGL { if u.GraphicsLibrary() != GraphicsLibraryOpenGL {
if err := u.graphicsDriver.(interface{ SetGLFWClientAPI() error }).SetGLFWClientAPI(); err != nil {
return err
}
} else {
if err := glfw.WindowHint(glfw.ClientAPI, glfw.NoAPI); err != nil { if err := glfw.WindowHint(glfw.ClientAPI, glfw.NoAPI); err != nil {
return err return err
} }