mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-14 23:17:27 +01:00
internal/graphicsdriver/opengl: refactoring: separate graphcis_*.go for macOS
Updates #2714
This commit is contained in:
parent
5245537e21
commit
87e412cd39
86
internal/graphicsdriver/opengl/graphics_darwin.go
Normal file
86
internal/graphicsdriver/opengl/graphics_darwin.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
// Copyright 2024 The Ebitengine Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
//go:build !ios
|
||||||
|
|
||||||
|
package opengl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
|
||||||
|
)
|
||||||
|
|
||||||
|
type graphicsPlatform struct {
|
||||||
|
window *glfw.Window
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGraphics creates an implementation of graphicsdriver.Graphics for OpenGL.
|
||||||
|
// The returned graphics value is nil iff the error is not nil.
|
||||||
|
func NewGraphics() (graphicsdriver.Graphics, error) {
|
||||||
|
ctx, err := gl.NewDefaultContext()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLAPI); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := glfw.WindowHint(glfw.ContextVersionMajor, 3); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := glfw.WindowHint(glfw.ContextVersionMinor, 2); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// macOS requires forward-compatible and a core profile.
|
||||||
|
if err := glfw.WindowHint(glfw.OpenGLForwardCompat, glfw.True); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return newGraphics(ctx), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) SetGLFWWindow(window *glfw.Window) {
|
||||||
|
g.window = window
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) makeContextCurrent() error {
|
||||||
|
return g.window.MakeContextCurrent()
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := g.window.SwapBuffers(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -12,13 +12,12 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//go:build !android && !ios && !js && !nintendosdk && !playstation5
|
//go:build !android && !darwin && !js && !nintendosdk && !playstation5
|
||||||
|
|
||||||
package opengl
|
package opengl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
@ -75,15 +74,6 @@ func setGLFWClientAPI(isES bool) error {
|
|||||||
if err := glfw.WindowHint(glfw.ContextVersionMinor, 2); err != nil {
|
if err := glfw.WindowHint(glfw.ContextVersionMinor, 2); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// macOS requires forward-compatible and a core profile.
|
|
||||||
if runtime.GOOS == "darwin" {
|
|
||||||
if err := glfw.WindowHint(glfw.OpenGLForwardCompat, glfw.True); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user