mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/graphicsdriver/opengl: refactoring
This commit is contained in:
parent
42566c6c9a
commit
8c49c88b08
@ -19,26 +19,9 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
// NewGraphics creates an implementation of graphicsdriver.Graphics for OpenGL.
|
||||
// The returned graphics value is nil iff the error is not nil.
|
||||
//
|
||||
// context is an additional information to initialize the underlying context.
|
||||
// context type depends on environments.
|
||||
func NewGraphics(context any) (graphicsdriver.Graphics, error) {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return nil, fmt.Errorf("opengl: OpenGL is not supported on Xbox")
|
||||
}
|
||||
g := &Graphics{}
|
||||
if err := g.init(context); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return g, nil
|
||||
}
|
||||
|
||||
type activatedTexture struct {
|
||||
textureNative textureNative
|
||||
index int
|
||||
|
@ -17,9 +17,22 @@
|
||||
package opengl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
||||
)
|
||||
|
||||
func (g *Graphics) init(context any) error {
|
||||
return gl.Init()
|
||||
// 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) {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return nil, fmt.Errorf("opengl: OpenGL is not supported on Xbox")
|
||||
}
|
||||
g := &Graphics{}
|
||||
if err := gl.Init(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return g, nil
|
||||
}
|
||||
|
@ -20,7 +20,10 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
|
||||
)
|
||||
|
||||
func (g *Graphics) init(context any) error {
|
||||
// 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) {
|
||||
g := &Graphics{}
|
||||
g.context.ctx = gl.DefaultContext{}
|
||||
return nil
|
||||
return g, nil
|
||||
}
|
||||
|
@ -18,7 +18,10 @@ import (
|
||||
"syscall/js"
|
||||
)
|
||||
|
||||
func (g *Graphics) init(canvas any) error {
|
||||
g.context.canvas = canvas.(js.Value)
|
||||
return nil
|
||||
// NewGraphics creates an implementation of graphicsdriver.Graphics for OpenGL.
|
||||
// The returned graphics value is nil iff the error is not nil.
|
||||
func NewGraphics(canvas js.Value) (graphicsdriver.Graphics, error) {
|
||||
g := &Graphics{}
|
||||
g.context.canvas = canvas
|
||||
return g, nil
|
||||
}
|
||||
|
@ -22,11 +22,14 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
|
||||
)
|
||||
|
||||
func (g *Graphics) init(context any) error {
|
||||
// NewGraphics creates an implementation of graphicsdriver.Graphics for OpenGL.
|
||||
// The returned graphics value is nil iff the error is not nil.
|
||||
func NewGraphics(context mgl.Context) (graphicsdriver.Graphics, error) {
|
||||
g := &Graphics{}
|
||||
if context != nil {
|
||||
g.context.ctx = gl.NewGomobileContext(context.(mgl.Context))
|
||||
} else {
|
||||
g.context.ctx = gl.DefaultContext{}
|
||||
}
|
||||
return nil
|
||||
return g, nil
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, Graphics
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
return opengl.NewGraphics(nil)
|
||||
return opengl.NewGraphics()
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
|
||||
|
@ -40,7 +40,7 @@ func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, Graphics
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
return opengl.NewGraphics(nil)
|
||||
return opengl.NewGraphics()
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
|
||||
|
@ -47,7 +47,7 @@ func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, Graphics
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
return opengl.NewGraphics(nil)
|
||||
return opengl.NewGraphics()
|
||||
}
|
||||
|
||||
func (g *graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
|
||||
|
@ -32,7 +32,7 @@ func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, Graphics
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||
return opengl.NewGraphics(nil)
|
||||
return opengl.NewGraphics()
|
||||
}
|
||||
|
||||
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user