Files
ebiten/internal/colormshader/gen.go
T
Hajime Hoshi b78d867e7a internal/colormshader: extract ColorM shader logic from builtinshader
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>
2026-03-14 15:59:50 +09:00

99 lines
2.7 KiB
Go

// Copyright 2026 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/colormshader"
)
func main() {
if err := xmain(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
const license = `// Copyright 2026 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 colormshader\n"); err != nil {
return err
}
for filter := colormshader.Filter(0); filter < colormshader.FilterCount; filter++ {
for address := colormshader.Address(0); address < colormshader.AddressCount; address++ {
s := colormshader.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
}