mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 09:22:01 +01:00
parent
fef487e09d
commit
bff760af01
@ -102,7 +102,7 @@ func compileShader(program *shaderir.Program) (vsh, psh *_ID3DBlob, ferr error)
|
||||
return vsh, psh, nil
|
||||
}
|
||||
|
||||
vs, ps := hlsl.Compile(program)
|
||||
vs, ps, _ := hlsl.Compile(program)
|
||||
var flag uint32 = uint32(_D3DCOMPILE_OPTIMIZATION_LEVEL3)
|
||||
|
||||
var wg errgroup.Group
|
||||
|
@ -41,8 +41,8 @@ func glslFragmentNormalize(str string) string {
|
||||
return strings.TrimSpace(str)
|
||||
}
|
||||
|
||||
func hlslNormalize(str string) string {
|
||||
str = strings.TrimPrefix(str, hlsl.Prelude)
|
||||
func hlslNormalize(str string, prelude string) string {
|
||||
str = strings.TrimPrefix(str, prelude)
|
||||
return strings.TrimSpace(str)
|
||||
}
|
||||
|
||||
@ -180,8 +180,8 @@ func TestCompile(t *testing.T) {
|
||||
}
|
||||
|
||||
if tc.HLSL != nil {
|
||||
vs, _ := hlsl.Compile(s)
|
||||
if got, want := hlslNormalize(vs), hlslNormalize(string(tc.HLSL)); got != want {
|
||||
vs, _, prelude := hlsl.Compile(s)
|
||||
if got, want := hlslNormalize(vs, prelude), hlslNormalize(string(tc.HLSL), prelude); got != want {
|
||||
compare(t, "HLSL", got, want)
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ cbuffer Uniforms : register(b0) {
|
||||
float2 U0 : packoffset(c0);
|
||||
}
|
||||
|
||||
Varyings VSMain(float2 A0 : POSITION, float2 A1 : TEXCOORD, float4 A2 : COLOR) {
|
||||
Varyings VSMain(float2 A0 : POSITION, float2 A1 : TEXCOORD, float4 A2 : COLOR0) {
|
||||
Varyings varyings;
|
||||
float4x4 l0 = 0.0;
|
||||
varyings.Position = 0.0;
|
||||
|
@ -52,7 +52,7 @@ func (c *compileContext) structName(p *shaderir.Program, t *shaderir.Type) strin
|
||||
return n
|
||||
}
|
||||
|
||||
const Prelude = `float mod(float x, float y) {
|
||||
const utilFuncs = `float mod(float x, float y) {
|
||||
return x - y * floor(x/y);
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ float4x4 float4x4FromScalar(float x) {
|
||||
return float4x4(x, 0, 0, 0, 0, x, 0, 0, 0, 0, x, 0, 0, 0, 0, x);
|
||||
}`
|
||||
|
||||
func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
||||
func Compile(p *shaderir.Program) (vertexShader, pixelShader, prelude string) {
|
||||
offsets := CalcUniformMemoryOffsets(p)
|
||||
|
||||
c := &compileContext{
|
||||
@ -88,7 +88,7 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
||||
}
|
||||
|
||||
var lines []string
|
||||
lines = append(lines, strings.Split(Prelude, "\n")...)
|
||||
lines = append(lines, strings.Split(utilFuncs, "\n")...)
|
||||
|
||||
lines = append(lines, "", "struct Varyings {")
|
||||
lines = append(lines, "\tfloat4 Position : SV_POSITION;")
|
||||
@ -96,7 +96,7 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
||||
for i, v := range p.Varyings {
|
||||
switch i {
|
||||
case 0:
|
||||
lines = append(lines, fmt.Sprintf("\tfloat2 M%d : TEXCOORD0;", i))
|
||||
lines = append(lines, fmt.Sprintf("\tfloat2 M%d : TEXCOORD;", i))
|
||||
case 1:
|
||||
lines = append(lines, fmt.Sprintf("\tfloat4 M%d : COLOR0;", i))
|
||||
default:
|
||||
@ -110,6 +110,8 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
||||
}
|
||||
}
|
||||
lines = append(lines, "};")
|
||||
prelude = strings.Join(lines, "\n")
|
||||
|
||||
lines = append(lines, "", "{{.Structs}}")
|
||||
|
||||
if len(p.Uniforms) > 0 {
|
||||
@ -177,7 +179,7 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string) {
|
||||
case 0:
|
||||
args = append(args, fmt.Sprintf("float2 A%d : POSITION", i))
|
||||
case 1:
|
||||
args = append(args, fmt.Sprintf("float2 A%d : TEXCOORD0", i))
|
||||
args = append(args, fmt.Sprintf("float2 A%d : TEXCOORD", i))
|
||||
case 2:
|
||||
args = append(args, fmt.Sprintf("float4 A%d : COLOR0", i))
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user