From 9f4985943c72e97adf8720bc90968c4495b6f291 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 16 May 2020 03:40:33 +0900 Subject: [PATCH] shaderir: Allow integer literals --- internal/shaderir/glsl.go | 6 ++++-- internal/shaderir/ir_test.go | 8 ++++---- internal/shaderir/program.go | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/shaderir/glsl.go b/internal/shaderir/glsl.go index afaff4033..a426f99e7 100644 --- a/internal/shaderir/glsl.go +++ b/internal/shaderir/glsl.go @@ -119,8 +119,10 @@ func (p *Program) glslBlock(b *Block, f *Func, level int, localVarIndex int) []s var glslExpr func(e *Expr) string glslExpr = func(e *Expr) string { switch e.Type { - case Numeric: - return fmt.Sprintf("%.9e", e.Num) + case IntExpr: + return fmt.Sprintf("%d", e.Int) + case FloatExpr: + return fmt.Sprintf("%.9e", e.Float) case VarName: switch e.Variable.Type { case Uniform: diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index cdbc3973f..efb586682 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -59,10 +59,10 @@ func forStmt(init, end, delta int, block Block) Stmt { } } -func numericExpr(value float64) Expr { +func floatExpr(value float32) Expr { return Expr{ - Type: Numeric, - Num: value, + Type: FloatExpr, + Float: value, } } @@ -291,7 +291,7 @@ varying vec3 V0;`, binaryExpr( Eq, varNameExpr(Local, 0), - numericExpr(0), + floatExpr(0), ), block( nil, diff --git a/internal/shaderir/program.go b/internal/shaderir/program.go index e20bd0064..688b01947 100644 --- a/internal/shaderir/program.go +++ b/internal/shaderir/program.go @@ -66,7 +66,8 @@ type Expr struct { Type ExprType Exprs []Expr Variable Variable - Num float64 + Int int32 + Float float32 Ident string Op Op } @@ -74,7 +75,8 @@ type Expr struct { type ExprType int const ( - Numeric ExprType = iota + IntExpr ExprType = iota + FloatExpr VarName Ident Unary