Skip to content

Commit

Permalink
Fixed #81: Lambda's with ignored args render ok
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Sep 24, 2023
1 parent db4d5eb commit 7536aef
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class CreateShaderAST[Q <: Quotes](using val qq: Q) extends ShaderMacroUtils:
case ValDef(name, _, Some(Ident(_))) if name.contains("$proxy") =>
true

case ValDef(name, _, Some(_)) =>
name.contains("$proxy") || name.matches("""_\$[0-9]+""")

case _ =>
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,61 @@ class GLSLExternalTests extends munit.FunSuite {

}

test("Inlined external def function with ignored argument") {
inline def modifyColorNamed: vec4 => Shader[Unit, vec4] =
inputColor =>
Shader[Unit, vec4] { env =>
vec4(2.0)
}

inline def fragmentNamed =
Shader {
modifyColorNamed(vec4(1.0)).run(())
}

val actualNamed =
fragmentNamed.toGLSL[WebGL2].toOutput.code

// DebugAST.toAST(fragment)
// println(actual)

assertEquals(
actualNamed,
s"""
|vec4 inputColor=vec4(1.0);
|vec4(2.0);
|""".stripMargin.trim
)

inline def modifyColorAnon: vec4 => Shader[Unit, vec4] =
_ =>
Shader[Unit, vec4] { env =>
vec4(2.0)
}

inline def fragmentAnon =
Shader {
modifyColorAnon(vec4(1.0)).run(())
}

val actualAnon =
fragmentAnon.toGLSL[WebGL2].toOutput.code

// DebugAST.toAST(fragment)
// println(actual)

assertEquals(
actualAnon,
s"""
|vec4 def0(){
| return vec4(2.0);
|}
|def0();
|""".stripMargin.trim
)

}

}

object TileAndStretch:
Expand Down

0 comments on commit 7536aef

Please sign in to comment.