2023-04-21 15:52:49 +02:00
|
|
|
// 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 ignore
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-19 17:52:03 +01:00
|
|
|
"bufio"
|
2023-04-21 15:52:49 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := run(); err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func run() error {
|
|
|
|
f, err := os.Create("debug.go")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
2023-12-19 17:52:03 +01:00
|
|
|
out := bufio.NewWriter(f)
|
|
|
|
|
|
|
|
if _, err := fmt.Fprintf(out, `// Copyright 2023 The Ebitengine Authors
|
2023-04-21 15:52:49 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2023-10-01 17:20:44 +02:00
|
|
|
// Code generated by genkeys.go using 'go generate'. DO NOT EDIT.
|
|
|
|
|
2023-12-19 17:52:03 +01:00
|
|
|
%s
|
|
|
|
|
2023-04-21 15:52:49 +02:00
|
|
|
package gl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DebugContext struct {
|
|
|
|
Context Context
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Context = (*DebugContext)(nil)
|
2023-12-19 17:52:03 +01:00
|
|
|
`, "//go:build !playstation5"); err != nil {
|
2023-04-21 15:52:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t := reflect.TypeOf((*gl.Context)(nil)).Elem()
|
|
|
|
for i := 0; i < t.NumMethod(); i++ {
|
|
|
|
m := t.Method(i)
|
|
|
|
name := m.Name
|
|
|
|
|
|
|
|
var argNames []string
|
|
|
|
var argNamesAndTypes []string
|
|
|
|
for j := 0; j < m.Type.NumIn(); j++ {
|
|
|
|
n := fmt.Sprintf("arg%d", j)
|
|
|
|
argNames = append(argNames, n)
|
|
|
|
argNamesAndTypes = append(argNamesAndTypes, n+" "+typeName(m.Type.In(j)))
|
|
|
|
}
|
|
|
|
|
|
|
|
var outTypes []string
|
|
|
|
var outNames []string
|
|
|
|
for j := 0; j < m.Type.NumOut(); j++ {
|
|
|
|
outTypes = append(outTypes, typeName(m.Type.Out(j)))
|
|
|
|
outNames = append(outNames, fmt.Sprintf("out%d", j))
|
|
|
|
}
|
|
|
|
|
2023-12-19 17:52:03 +01:00
|
|
|
if _, err := fmt.Fprintf(out, "\nfunc (d *DebugContext) %s(%s) (%s) {\n", name, strings.Join(argNamesAndTypes, ", "), strings.Join(outTypes, ",")); err != nil {
|
2023-04-21 15:52:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(outTypes) > 0 {
|
2023-12-19 17:52:03 +01:00
|
|
|
if _, err := fmt.Fprintf(out, "\t%s := ", strings.Join(outNames, ", ")); err != nil {
|
2023-04-21 15:52:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2023-12-19 17:52:03 +01:00
|
|
|
if _, err := fmt.Fprintf(out, "\t"); err != nil {
|
2023-04-21 15:52:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2023-12-19 17:52:03 +01:00
|
|
|
if _, err := fmt.Fprintf(out, "d.Context.%s(%s)\n", name, strings.Join(argNames, ", ")); err != nil {
|
2023-04-21 15:52:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print logs.
|
|
|
|
if name != "LoadFunctions" && name != "IsES" {
|
2023-12-19 17:52:03 +01:00
|
|
|
if _, err := fmt.Fprintf(out, "\tfmt.Fprintln(os.Stderr, %q)\n", name); err != nil {
|
2023-04-21 15:52:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check errors.
|
|
|
|
if name != "LoadFunctions" && name != "IsES" && name != "GetError" {
|
2023-12-19 17:52:03 +01:00
|
|
|
if _, err := fmt.Fprintf(out, ` if e := d.Context.GetError(); e != NO_ERROR {
|
2023-04-21 15:52:49 +02:00
|
|
|
panic(fmt.Sprintf("gl: GetError() returned %%d at %s", e))
|
|
|
|
}
|
|
|
|
`, name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(outTypes) > 0 {
|
2023-12-19 17:52:03 +01:00
|
|
|
if _, err := fmt.Fprintf(out, "\treturn %s\n", strings.Join(outNames, ", ")); err != nil {
|
2023-04-21 15:52:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2023-12-19 17:52:03 +01:00
|
|
|
if _, err := fmt.Fprintf(out, "}\n"); err != nil {
|
2023-04-21 15:52:49 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-19 17:52:03 +01:00
|
|
|
if err := out.Flush(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-04-21 15:52:49 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func typeName(t reflect.Type) string {
|
|
|
|
if t.Kind() == reflect.Slice {
|
|
|
|
return "[]" + typeName(t.Elem())
|
|
|
|
}
|
|
|
|
return t.Name()
|
|
|
|
}
|