mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
231 lines
4.1 KiB
Go
231 lines
4.1 KiB
Go
// Copyright 2020 The Ebiten 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.
|
|
|
|
package testing
|
|
|
|
import (
|
|
"github.com/hajimehoshi/ebiten/internal/shaderir"
|
|
)
|
|
|
|
func ShaderProgramFill(r, g, b, a byte) shaderir.Program {
|
|
mat := shaderir.Expr{
|
|
Type: shaderir.Call,
|
|
Exprs: []shaderir.Expr{
|
|
{
|
|
Type: shaderir.BuiltinFuncExpr,
|
|
BuiltinFunc: shaderir.Mat4F,
|
|
},
|
|
{
|
|
Type: shaderir.Binary,
|
|
Op: shaderir.Div,
|
|
Exprs: []shaderir.Expr{
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 2,
|
|
},
|
|
{
|
|
Type: shaderir.FieldSelector,
|
|
Exprs: []shaderir.Expr{
|
|
{
|
|
Type: shaderir.UniformVariable,
|
|
Index: 0,
|
|
},
|
|
{
|
|
Type: shaderir.SwizzlingExpr,
|
|
Swizzling: "x",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.Binary,
|
|
Op: shaderir.Div,
|
|
Exprs: []shaderir.Expr{
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 2,
|
|
},
|
|
{
|
|
Type: shaderir.FieldSelector,
|
|
Exprs: []shaderir.Expr{
|
|
{
|
|
Type: shaderir.UniformVariable,
|
|
Index: 0,
|
|
},
|
|
{
|
|
Type: shaderir.SwizzlingExpr,
|
|
Swizzling: "y",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 1,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: -1,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: -1,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 1,
|
|
},
|
|
},
|
|
}
|
|
pos := shaderir.Expr{
|
|
Type: shaderir.Call,
|
|
Exprs: []shaderir.Expr{
|
|
{
|
|
Type: shaderir.BuiltinFuncExpr,
|
|
BuiltinFunc: shaderir.Vec4F,
|
|
},
|
|
{
|
|
Type: shaderir.LocalVariable,
|
|
Index: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 0,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: 1,
|
|
},
|
|
},
|
|
}
|
|
clr := shaderir.Expr{
|
|
Type: shaderir.Call,
|
|
Exprs: []shaderir.Expr{
|
|
{
|
|
Type: shaderir.BuiltinFuncExpr,
|
|
BuiltinFunc: shaderir.Vec4F,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: float32(r) / 0xff,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: float32(g) / 0xff,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: float32(b) / 0xff,
|
|
},
|
|
{
|
|
Type: shaderir.FloatExpr,
|
|
Float: float32(a) / 0xff,
|
|
},
|
|
},
|
|
}
|
|
|
|
return shaderir.Program{
|
|
Uniforms: []shaderir.Type{
|
|
{Main: shaderir.Vec2},
|
|
},
|
|
Attributes: []shaderir.Type{
|
|
{Main: shaderir.Vec2},
|
|
{Main: shaderir.Vec2},
|
|
{Main: shaderir.Vec4},
|
|
{Main: shaderir.Vec4},
|
|
},
|
|
VertexFunc: shaderir.VertexFunc{
|
|
Block: shaderir.Block{
|
|
Stmts: []shaderir.Stmt{
|
|
{
|
|
Type: shaderir.Assign,
|
|
Exprs: []shaderir.Expr{
|
|
{
|
|
Type: shaderir.LocalVariable,
|
|
Index: 4,
|
|
},
|
|
{
|
|
Type: shaderir.Binary,
|
|
Op: shaderir.Mul,
|
|
Exprs: []shaderir.Expr{
|
|
mat,
|
|
pos,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
FragmentFunc: shaderir.FragmentFunc{
|
|
Block: shaderir.Block{
|
|
Stmts: []shaderir.Stmt{
|
|
{
|
|
Type: shaderir.Assign,
|
|
Exprs: []shaderir.Expr{
|
|
{
|
|
Type: shaderir.LocalVariable,
|
|
Index: 1,
|
|
},
|
|
clr,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|