mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2026-04-23 00:07:15 +08:00
b78d867e7a
Create a new internal/colormshader package that owns the color matrix shader generation, fully independent of internal/builtinshader. It has its own shader template with ColorM logic baked in, its own Filter/Address types, and a go:generate pipeline producing defs.go. This removes the useColorM dimension from internal/builtinshader, reducing it from 18 shader variants to 9. The colorm package now imports only colormshader (not builtinshader) for shader sources, preparing for the v2/v3 split where v2's colorm cannot access v3's builtinshader. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
99 lines
2.7 KiB
Go
99 lines
2.7 KiB
Go
// 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 ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
|
|
)
|
|
|
|
func main() {
|
|
if err := xmain(); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
const license = `// 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.
|
|
`
|
|
|
|
const note = `// This file is intended for precompiled shaders that will be introduced in the future.
|
|
// All constant names are underscores and not actually used,
|
|
// so they do not affect the binary file size.
|
|
`
|
|
|
|
func xmain() error {
|
|
f, err := os.Create("defs.go")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
|
|
w := bufio.NewWriter(f)
|
|
|
|
if _, err := w.WriteString("// Code generated by gen.go using 'go generate'. DO NOT EDIT.\n\n"); err != nil {
|
|
return err
|
|
}
|
|
if _, err := w.WriteString(license); err != nil {
|
|
return err
|
|
}
|
|
if _, err := w.WriteString("\n"); err != nil {
|
|
return err
|
|
}
|
|
if _, err := w.WriteString(note); err != nil {
|
|
return err
|
|
}
|
|
if _, err := w.WriteString("\npackage builtinshader\n"); err != nil {
|
|
return err
|
|
}
|
|
|
|
for filter := builtinshader.Filter(0); filter < builtinshader.FilterCount; filter++ {
|
|
for address := builtinshader.Address(0); address < builtinshader.AddressCount; address++ {
|
|
s := builtinshader.ShaderSource(filter, address)
|
|
if _, err := w.WriteString("\n"); err != nil {
|
|
return err
|
|
}
|
|
if _, err := w.WriteString("//ebitengine:shadersource\n"); err != nil {
|
|
return err
|
|
}
|
|
if _, err := fmt.Fprintf(w, "const _ = %q\n", s); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
if err := w.Flush(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|