%============================================================================================              
% Filename: listcode.tex
% Author: Daniel Mueller [d.mueller@qut.edu.au]
%--------------------------------------------------------------------------------------------
% Description: 
% Encapulates commands to list source code using the listings package.
% Also loads the [Shading]OpenGL language.
%--------------------------------------------------------------------------------------------
% Notes:
% - The listings package does not integrate well with the memoir class...
%	It may be necessary to delete the *.lol (local listing file) if an error
%   occurs during compilation.
%============================================================================================              
 
%--------------------------------------------------------------------------------------------
% Define the used colours
\definecolor{listcomment}{rgb}{0.0,0.5,0.0}
\definecolor{listkeyword}{rgb}{0.0,0.0,0.5}
\definecolor{listbackground}{gray}{0.965}

%--------------------------------------------------------------------------------------------
% Define a new command for listing source code 
% arg[0]: eg. language = [Shading]OpenGL
% arg[1]: eg. floatplacement = !htb
% arg[2]: eg. caption = Texture shader (OpenGL Shading Language)
% arg[3]: eg. label = lst:Shader
\newcommand{\listcode}[4]{%
%\singlespacing
\lstset{%
        frame = tb,
        framerule = 0.5pt,
        float,
        fontadjust,
        backgroundcolor={\color{listbackground}},
        basicstyle = {\ttfamily\footnotesize},
        keywordstyle = {\ttfamily\color{listkeyword}\textbf},
        identifierstyle = {\ttfamily},
        commentstyle = {\ttfamily\color{listcomment}\textit},
        stringstyle = {\ttfamily},
        showstringspaces = false,
        showtabs = false,
        numbers = left,
        captionpos = b,
        tabsize = 2,
        #1,
        #2,
        #3,
        #4}	
}

%--------------------------------------------------------------------------------------------
% Define the OpenGL Shading language keywords, comments, etc...
\lstdefinelanguage[Shading]{OpenGL}%
{%
    morekeywords=   {%
                    attribute,%
                    const,%
                    uniform,%
                    varying,%
                    break,%
                    continue,%
                    do,%
                    for,%
                    while,%
                    if,%
                    else,%
                    in,%
                    out,%
                    inout,%
                    true,%
                    false,%
                    discard,%
                    return,%
                    float,%
                    int,%
                    void,%
                    bool,%
                    mat2,%
                    mat3,%
                    mat4,%
                    vec2,
                    vec3,%
                    vec4,%
                    ivec2,%
                    ivec3,%
                    ivec4,%
                    bvec2,%
                    bvec3,%
                    bvec4,%
                    sampler1D,%
                    sampler2D,%
                    sampler3D,%
                    samplerCube,%
                    sampler1DShadow,%
                    sampler2DShadow,%
                    struct,%
                    radians,%
                    degrees,%
                    sin,%
                    cos,%
                    tan,%
                    asin,%
                    acos,%
                    atan,%
                    pow,%
                    exp2,%
                    log2,%
                    sqrt,%
                    inversesqrt,%
                    abs,%
                    sign,%
                    floor,%
                    ceil,%
                    fract,%
                    mod,%
                    min,%
                    max,%
                    clamp,%
                    mix,%
                    step,%
                    smoothstep,%
                    length,%
                    distance,%
                    dot,%
                    cross,%
                    normalize,%
                    transform,%
                    faceforward,%
                    reflect,%
                    matrixCompMult,%
                    lessThan,%
                    lessThanEqual,%
                    greaterThan,%
                    greaterThanEqual,%
                    equal,%
                    notEqual,%
                    any,%
                    all,%
                    not,%
                    texture1D,%
                    texture1DProj,%
                    texture1DProjLod,%
                    texture2D,%
                    texture2DProj,%
                    texture2DProjLod,%
                    texture3D,%
                    texture3DProj,%
                    texture3DProjLod,%
                    textureCube,%
                    textureCubeLod,%
                    shadow1D,%
                    shadow1DProj,%
                    shadow1DLod,%
                    shadow1DProjLod,%
                    shadow2D,%
                    shadow2DProj,%
                    shadow2DLod,%
                    shadow2DProjLod,%
                    dFdx,%
                    dFdy,%
                    fwidth,%
                    noise1,%
                    noise2,%
                    noise3,%
                    noise4},%
    morekeywords={%
                    gl_Position,%
                    gl_PointSize,%
                    gl_ClipVertex,%
                    gl_FragCoord,%
                    gl_FrontFacing,%
                    gl_FragColor,%
                    gl_FragDepth,%
                    gl_Color,%
                    gl_SecondaryColor,%
                    gl_Normal,%
                    gl_Vertex,%
                    gl_MultiTexCoord0,%
                    gl_MultiTexCoord1,%
                    gl_MultiTexCoord2,%
                    gl_MultiTexCoord3,%
                    gl_MultiTexCoord4,%
                    gl_MultiTexCoord5,%
                    gl_MultiTexCoord6,%
                    gl_MultiTexCoord7,%
                    gl_FogCoord,%
                    gl_MaxLights,%
                    gl_MaxClipPlanes,%
                    gl_MaxTextureUnits,%
                    gl_MaxTextureCoordsARB,%
                    gl_MaxVertexAttributesGL2,%
                    gl_MaxVertexUniformFloatsGL2,%
                    gl_MaxVaryingFloatsGL2,%
                    gl_MaxVertexTextureUnitsGL2,%
                    gl_MaxFragmentTextureUnitsGL2,%
                    gl_MaxFragmentUniformFloatsGL2,%
                    gl_ModelViewMatrix,%
                    gl_ProjectionMatrix,%
                    gl_ModelViewProjectionMatrix,%
                    gl_NormalMatrix,%
                    gl_TextureMatrix,%
                    gl_NormalScale,%
                    gl_DepthRange,%
                    gl_ClipPlane,%
                    gl_Point,%
                    gl_FrontMaterial,%
                    gl_BackMaterial,%
                    gl_LightSource,%
                    gl_LightModel,%
                    gl_FrontLightModelProduct,%
                    gl_BackLightModelProduct,%
                    gl_FrontLightProduct,%
                    gl_LightProducts,%
                    gl_TextureEnvColor,%
                    gl_EyePlaneS,%
                    gl_EyePlaneT,%
                    gl_EyePlaneR,%
                    gl_EyePlaneQ,%
                    gl_ObjectPlaneS,%
                    gl_ObjectPlaneT,%
                    gl_ObjectPlaneR,%
                    gl_ObjectPlaneQ,%
                    gl_Fog,%
                    gl_FrontColor,%
                    gl_BackColor,%
                    gl_FrontSecondaryColor,%
                    gl_BackSecondaryColor,%
                    gl_TexCoord,%
                    gl_FogFragCoord,%
                    gl_Color,%
                    gl_SecondaryColor,%
                    gl_TexCoord,%
                    gl_FogFragCoord},%                   
    sensitive,%
    morecomment=[s]{/*}{*/},%
    morecomment=[l]//,%
    morestring=[b]"
    }[keywords,comments,strings]%

%--------------------------------------------------------------------------------------------
% Load [Shading]OpenGL for use with the listings package 
\lstloadlanguages{[Shading]OpenGL}
