Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Created April 3, 2014 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonDanisch/9956214 to your computer and use it in GitHub Desktop.
Save SimonDanisch/9956214 to your computer and use it in GitHub Desktop.
#Example for creating a Vertexshader
glslTypeConversion = [
:Vector2 => "vec2",
:Vector3 => "vec3",
:Vector4 => "vec4",
:Float32 => "float"
]
function toVertShader(vertShader::Dict{String, Any})
globals = ASCIIString[]
main = ASCIIString[]
for elem in vertShader
toVertShader(elem..., globals, main)
end
push!(globals, "void main(){")
return join([globals, main, "}"], '\n')
end
function toVertShader(attribute::String, buffer::GLBuffer, globals::Array{String, 1}, main::Array{String, 1})
push!(globals, "varying " * glslTypeConversion[buffer.elementType] * " " * attribute * ";")
end
function toVertShader(attribute::String, cam::Camera, globals::Array{String, 1}, main::Array{String, 1})
push!(globals, "uniform mat4 " * attribute * ";")
end
function toVertShader(attribute::String, func::(Function, Tuple), globals::Array{String, 1}, main::Array{String, 1})
push!(globals, "varying " * glslTypeConversion[getFuncReturnType(func[1])] * " " * attribute * ";")
push!(main, attribute * " = " * toVertShader(func) * ";")
end
function toVertShader(func::(Function, Tuple))
AST = code_typed(func...)
for elem in AST
toVertShader(elem)
end
end
function toVertShader(expr::Expr)
#... Some nasty AST parsing. Basically convert all the types and recursively inserting all called Julia functions
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment