Created
April 3, 2014 15:11
-
-
Save SimonDanisch/9956214 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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