ebiten/internal/shaderir/ir_test.go

136 lines
2.4 KiB
Go
Raw Normal View History

2020-05-11 17:19:42 +02:00
// 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 shaderir_test
import (
"testing"
. "github.com/hajimehoshi/ebiten/internal/shaderir"
)
func TestOutput(t *testing.T) {
tests := []struct {
Name string
Program Program
Glsl string
}{
{
Name: "Empty",
Program: Program{},
Glsl: ``,
},
{
Name: "Uniform",
Program: Program{
Uniforms: []Variable{
{
2020-05-12 16:32:32 +02:00
Name: "U0",
Type: Type{Main: Float},
2020-05-11 17:19:42 +02:00
},
},
},
2020-05-12 16:32:32 +02:00
Glsl: `uniform float U0;`,
2020-05-11 17:19:42 +02:00
},
{
Name: "UniformStruct",
Program: Program{
Uniforms: []Variable{
{
2020-05-12 16:32:32 +02:00
Name: "U0",
2020-05-11 17:19:42 +02:00
Type: Type{
2020-05-12 16:32:32 +02:00
Main: Struct,
Sub: []Type{
{Main: Float},
2020-05-11 17:19:42 +02:00
},
},
},
},
},
Glsl: `struct S0 {
float M0;
};
2020-05-12 16:32:32 +02:00
uniform S0 U0;`,
},
{
Name: "Vars",
Program: Program{
Uniforms: []Variable{
{
Name: "U0",
Type: Type{Main: Float},
},
},
Attributes: []Variable{
{
Name: "A0",
Type: Type{Main: Vec2},
},
},
Varyings: []Variable{
{
Name: "V0",
Type: Type{Main: Vec3},
},
},
},
Glsl: `uniform float U0;
attribute vec2 A0;
varying vec3 V0;`,
},
{
2020-05-13 16:31:17 +02:00
Name: "Func",
2020-05-12 16:32:32 +02:00
Program: Program{
Funcs: []Func{
{
Name: "F0",
},
},
},
Glsl: `void F0(void) {
2020-05-13 16:31:17 +02:00
}`,
},
{
Name: "FuncParams",
Program: Program{
Funcs: []Func{
{
Name: "F0",
InParams: []Type{
{Main: Float},
{Main: Vec2},
{Main: Vec4},
},
InOutParams: []Type{
{Main: Mat2},
},
OutParams: []Type{
{Main: Mat4},
},
},
},
},
Glsl: `void F0(in float l0, in vec2 l1, in vec4 l2, inout mat2 l3, out mat4 l4) {
2020-05-12 16:32:32 +02:00
}`,
2020-05-11 17:19:42 +02:00
},
}
for _, tc := range tests {
got := tc.Program.Glsl()
want := tc.Glsl + "\n"
if got != want {
t.Errorf("%s: got: %s, want: %s", tc.Name, got, want)
}
}
}