diff --git a/examples/shader/main.go b/examples/shader/main.go index 44c3c7c54..6b713ecb4 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -29,20 +29,19 @@ const ( const shaderSrc = `package main -// __viewportSize is a predefined uniform variable. -// TODO: Hide this by a function. +// viewportSize is a predefined function. func Vertex(position vec2, texCoord vec2, color vec4) vec4 { return mat4( - 2.0/__viewportSize.x, 0, 0, 0, - 0, 2.0/__viewportSize.y, 0, 0, + 2.0/viewportSize().x, 0, 0, 0, + 0, 2.0/viewportSize().y, 0, 0, 0, 0, 1, 0, -1, -1, 0, 1, ) * vec4(position, 0, 1) } func Fragment(position vec4) vec4 { - return vec4(position.x/__viewportSize.x, position.y/__viewportSize.y, 0, 1) + return vec4(position.x/viewportSize().x, position.y/viewportSize().y, 0, 1) }` type Game struct { diff --git a/shader.go b/shader.go index 944d9ac08..cb0c85fed 100644 --- a/shader.go +++ b/shader.go @@ -24,7 +24,11 @@ import ( ) const shaderSuffix = ` -var __viewportSize vec2` +var __viewportSize vec2 + +func viewportSize() vec2 { + return __viewportSize +}` type Shader struct { shader *buffered.Shader