internal/graphicsdriver/opengl, internal/graphicsdriver/opengl/gl: refactoring

This commit is contained in:
Hajime Hoshi 2023-12-20 01:52:03 +09:00
parent 6fd18150d8
commit 12ae411d15
15 changed files with 64 additions and 91 deletions

View File

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !playstation5
package opengl
import (

View File

@ -14,6 +14,8 @@
// Code generated by genkeys.go using 'go generate'. DO NOT EDIT.
//go:build !playstation5
package gl
import (

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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")
}

View File

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !playstation5
package opengl
import (

View File

@ -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).
}

View File

@ -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 {

View File

@ -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).
}

View File

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !playstation5
package opengl
import (

View File

@ -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 {

View File

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !playstation5
package opengl
import (

View File

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !playstation5
package opengl
import (