diff --git a/internal/graphicsdriver/opengl/context.go b/internal/graphicsdriver/opengl/context.go index 947b6a781..ea766afc3 100644 --- a/internal/graphicsdriver/opengl/context.go +++ b/internal/graphicsdriver/opengl/context.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !playstation5 + package opengl import ( diff --git a/internal/graphicsdriver/opengl/gl/debug.go b/internal/graphicsdriver/opengl/gl/debug.go index a978f8ee2..5ab601d64 100644 --- a/internal/graphicsdriver/opengl/gl/debug.go +++ b/internal/graphicsdriver/opengl/gl/debug.go @@ -14,6 +14,8 @@ // Code generated by genkeys.go using 'go generate'. DO NOT EDIT. +//go:build !playstation5 + package gl import ( diff --git a/internal/graphicsdriver/opengl/gl/default_cgo.go b/internal/graphicsdriver/opengl/gl/default_cgo.go index d0484e7bf..4f6c77207 100644 --- a/internal/graphicsdriver/opengl/gl/default_cgo.go +++ b/internal/graphicsdriver/opengl/gl/default_cgo.go @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: 2014 Eric Woroshow // SPDX-FileCopyrightText: 2022 The Ebitengine Authors -//go:build !darwin && !js && !windows +//go:build !darwin && !js && !windows && !playstation5 package gl diff --git a/internal/graphicsdriver/opengl/gl/gen.go b/internal/graphicsdriver/opengl/gl/gen.go index 75e128475..0adf5a3ab 100644 --- a/internal/graphicsdriver/opengl/gl/gen.go +++ b/internal/graphicsdriver/opengl/gl/gen.go @@ -17,6 +17,7 @@ package main import ( + "bufio" "fmt" "os" "reflect" @@ -39,7 +40,9 @@ func run() error { } defer f.Close() - if _, err := f.WriteString(`// Copyright 2023 The Ebitengine Authors + out := bufio.NewWriter(f) + + if _, err := fmt.Fprintf(out, `// Copyright 2023 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. @@ -55,6 +58,8 @@ func run() error { // Code generated by genkeys.go using 'go generate'. DO NOT EDIT. +%s + package gl import ( @@ -67,7 +72,7 @@ type DebugContext struct { } var _ Context = (*DebugContext)(nil) -`); err != nil { +`, "//go:build !playstation5"); err != nil { return err } @@ -91,32 +96,32 @@ var _ Context = (*DebugContext)(nil) outNames = append(outNames, fmt.Sprintf("out%d", j)) } - if _, err := fmt.Fprintf(f, "\nfunc (d *DebugContext) %s(%s) (%s) {\n", name, strings.Join(argNamesAndTypes, ", "), strings.Join(outTypes, ",")); err != nil { + if _, err := fmt.Fprintf(out, "\nfunc (d *DebugContext) %s(%s) (%s) {\n", name, strings.Join(argNamesAndTypes, ", "), strings.Join(outTypes, ",")); err != nil { return err } if len(outTypes) > 0 { - if _, err := fmt.Fprintf(f, "\t%s := ", strings.Join(outNames, ", ")); err != nil { + if _, err := fmt.Fprintf(out, "\t%s := ", strings.Join(outNames, ", ")); err != nil { return err } } else { - if _, err := fmt.Fprintf(f, "\t"); err != nil { + if _, err := fmt.Fprintf(out, "\t"); err != nil { return err } } - if _, err := fmt.Fprintf(f, "d.Context.%s(%s)\n", name, strings.Join(argNames, ", ")); err != nil { + if _, err := fmt.Fprintf(out, "d.Context.%s(%s)\n", name, strings.Join(argNames, ", ")); err != nil { return err } // Print logs. if name != "LoadFunctions" && name != "IsES" { - if _, err := fmt.Fprintf(f, "\tfmt.Fprintln(os.Stderr, %q)\n", name); err != nil { + if _, err := fmt.Fprintf(out, "\tfmt.Fprintln(os.Stderr, %q)\n", name); err != nil { return err } } // Check errors. if name != "LoadFunctions" && name != "IsES" && name != "GetError" { - if _, err := fmt.Fprintf(f, ` if e := d.Context.GetError(); e != NO_ERROR { + if _, err := fmt.Fprintf(out, ` if e := d.Context.GetError(); e != NO_ERROR { panic(fmt.Sprintf("gl: GetError() returned %%d at %s", e)) } `, name); err != nil { @@ -125,15 +130,19 @@ var _ Context = (*DebugContext)(nil) } if len(outTypes) > 0 { - if _, err := fmt.Fprintf(f, "\treturn %s\n", strings.Join(outNames, ", ")); err != nil { + if _, err := fmt.Fprintf(out, "\treturn %s\n", strings.Join(outNames, ", ")); err != nil { return err } } - if _, err := fmt.Fprintf(f, "}\n"); err != nil { + if _, err := fmt.Fprintf(out, "}\n"); err != nil { return err } } + if err := out.Flush(); err != nil { + return err + } + return nil } diff --git a/internal/graphicsdriver/opengl/gl/interface.go b/internal/graphicsdriver/opengl/gl/interface.go index 471908b16..7b01fc186 100644 --- a/internal/graphicsdriver/opengl/gl/interface.go +++ b/internal/graphicsdriver/opengl/gl/interface.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !playstation5 + package gl //go:generate go run gen.go diff --git a/internal/graphicsdriver/opengl/gl/procaddr.go b/internal/graphicsdriver/opengl/gl/procaddr.go index 2b562b845..94966a78d 100644 --- a/internal/graphicsdriver/opengl/gl/procaddr.go +++ b/internal/graphicsdriver/opengl/gl/procaddr.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !js +//go:build !js && !playstation5 package gl diff --git a/internal/graphicsdriver/opengl/gl/procaddr_null.go b/internal/graphicsdriver/opengl/gl/procaddr_null.go deleted file mode 100644 index 0ba018d6f..000000000 --- a/internal/graphicsdriver/opengl/gl/procaddr_null.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2023 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 playstation5 - -package gl - -import ( - "errors" -) - -func (c *defaultContext) init() error { - return errors.New("gl: defaultContext is not implemented") -} - -func (c *defaultContext) getProcAddress(name string) (uintptr, error) { - return 0, errors.New("gl: defaultContext is not implemented") -} diff --git a/internal/graphicsdriver/opengl/graphics.go b/internal/graphicsdriver/opengl/graphics.go index bf177e7d5..1b07f7597 100644 --- a/internal/graphicsdriver/opengl/graphics.go +++ b/internal/graphicsdriver/opengl/graphics.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !playstation5 + package opengl import ( diff --git a/internal/graphicsdriver/opengl/graphics_default.go b/internal/graphicsdriver/opengl/graphics_default.go deleted file mode 100644 index fdc694cd0..000000000 --- a/internal/graphicsdriver/opengl/graphics_default.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2022 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 !android && !ios && !js && !nintendosdk - -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" -) - -// 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") - } - - ctx, err := gl.NewDefaultContext() - if err != nil { - return nil, err - } - - return newGraphics(ctx), nil -} - -func (g *Graphics) makeContextCurrent() { - // TODO: Implement this (#2714). -} - -func (g *Graphics) swapBuffers() { - // TODO: Implement this (#2714). -} diff --git a/internal/graphicsdriver/opengl/graphics_glfw.go b/internal/graphicsdriver/opengl/graphics_glfw.go index 876ddfd46..dcf2f1814 100644 --- a/internal/graphicsdriver/opengl/graphics_glfw.go +++ b/internal/graphicsdriver/opengl/graphics_glfw.go @@ -17,11 +17,38 @@ package opengl import ( + "fmt" "runtime" "github.com/hajimehoshi/ebiten/v2/internal/glfw" + "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" + "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl" + "github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk" ) +// 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") + } + + ctx, err := gl.NewDefaultContext() + if err != nil { + return nil, err + } + + return newGraphics(ctx), nil +} + +func (g *Graphics) makeContextCurrent() { + // TODO: Implement this (#2714). +} + +func (g *Graphics) swapBuffers() { + // TODO: Implement this (#2714). +} + func (g *Graphics) SetGLFWClientAPI() error { if g.context.ctx.IsES() { if err := glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLESAPI); err != nil { diff --git a/internal/graphicsdriver/opengl/graphics_mobile.go b/internal/graphicsdriver/opengl/graphics_mobile.go index 0b212eae1..82c98774f 100644 --- a/internal/graphicsdriver/opengl/graphics_mobile.go +++ b/internal/graphicsdriver/opengl/graphics_mobile.go @@ -41,9 +41,7 @@ func NewGraphics(context mgl.Context) (graphicsdriver.Graphics, error) { } func (g *Graphics) makeContextCurrent() { - // TODO: Implement this (#2714). } func (g *Graphics) swapBuffers() { - // TODO: Implement this (#2714). } diff --git a/internal/graphicsdriver/opengl/image.go b/internal/graphicsdriver/opengl/image.go index 3b24f98c8..a46081bed 100644 --- a/internal/graphicsdriver/opengl/image.go +++ b/internal/graphicsdriver/opengl/image.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !playstation5 + package opengl import ( diff --git a/internal/graphicsdriver/opengl/locationcache.go b/internal/graphicsdriver/opengl/locationcache.go index 6a82581b9..7a13d79ce 100644 --- a/internal/graphicsdriver/opengl/locationcache.go +++ b/internal/graphicsdriver/opengl/locationcache.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !playstation5 + package opengl type locationCache struct { diff --git a/internal/graphicsdriver/opengl/program.go b/internal/graphicsdriver/opengl/program.go index bdd378c42..cfe8bf8d4 100644 --- a/internal/graphicsdriver/opengl/program.go +++ b/internal/graphicsdriver/opengl/program.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !playstation5 + package opengl import ( diff --git a/internal/graphicsdriver/opengl/shader.go b/internal/graphicsdriver/opengl/shader.go index 06336e269..8f8890f59 100644 --- a/internal/graphicsdriver/opengl/shader.go +++ b/internal/graphicsdriver/opengl/shader.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !playstation5 + package opengl import (