From fa5b2ed730fca2f2ba445959edc22fbbd89e275d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 3 Jun 2020 00:46:52 +0900 Subject: [PATCH] shaderir: Change the param order --- internal/shaderir/glsl.go | 6 +++--- internal/shaderir/ir_test.go | 12 ++++++------ internal/shaderir/program.go | 8 ++++---- internal/testing/shader.go | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/shaderir/glsl.go b/internal/shaderir/glsl.go index 4b0d41c07..5168ba42d 100644 --- a/internal/shaderir/glsl.go +++ b/internal/shaderir/glsl.go @@ -249,10 +249,10 @@ func (p *Program) glslBlock(b *Block, level int, localVarIndex int) []string { switch { case idx < na: return fmt.Sprintf("A%d", idx) - case idx < na+nv: - return fmt.Sprintf("V%d", idx-na) - case idx == na+nv: + case idx == na: return "gl_Position" + case idx < na+nv+1: + return fmt.Sprintf("V%d", idx-na-1) default: return fmt.Sprintf("l%d", idx-(na+nv+1)) } diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index fdaf983e5..9e318f169 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -646,15 +646,15 @@ varying vec3 V0;`, Block: block( nil, assignStmt( - localVariableExpr(5), + localVariableExpr(3), localVariableExpr(0), ), assignStmt( - localVariableExpr(3), + localVariableExpr(4), localVariableExpr(1), ), assignStmt( - localVariableExpr(4), + localVariableExpr(5), localVariableExpr(2), ), ), @@ -695,15 +695,15 @@ varying vec2 V1;`, Block: block( nil, assignStmt( - localVariableExpr(5), + localVariableExpr(3), localVariableExpr(0), ), assignStmt( - localVariableExpr(3), + localVariableExpr(4), localVariableExpr(1), ), assignStmt( - localVariableExpr(4), + localVariableExpr(5), localVariableExpr(2), ), ), diff --git a/internal/shaderir/program.go b/internal/shaderir/program.go index 3b1177eee..007a9845f 100644 --- a/internal/shaderir/program.go +++ b/internal/shaderir/program.go @@ -37,10 +37,10 @@ type Func struct { } // VertexFunc takes pseudo params, and the number if len(attributes) + len(varyings) + 1. -// If 0 <= index < len(attributes), the params are in-params and treated as attribute variables. -// If len(attributes) <= index < len(attributes) + len(varyings), the params are out-params and treated as varying -// variables. -// The last param represents the position in vec4 (gl_Position in GLSL). +// If 0 <= index < len(attributes), the params are in-params and represent attribute variables. +// If index == len(attributes), the param is an out-param and repesents the position in vec4 (gl_Position in GLSL) +// If len(attributes) + 1 <= index < len(attributes) + len(varyings) + 1, the params are out-params and represent +// varying variables. type VertexFunc struct { Block Block } diff --git a/internal/testing/shader.go b/internal/testing/shader.go index c8294acdb..f8f67fb6f 100644 --- a/internal/testing/shader.go +++ b/internal/testing/shader.go @@ -159,7 +159,7 @@ var ( Exprs: []shaderir.Expr{ { Type: shaderir.LocalVariable, - Index: 4, // the varying variable + Index: 5, // the varying variable }, { Type: shaderir.LocalVariable, @@ -172,7 +172,7 @@ var ( Exprs: []shaderir.Expr{ { Type: shaderir.LocalVariable, - Index: 5, // gl_Position in GLSL + Index: 4, // gl_Position in GLSL }, { Type: shaderir.Binary,