4.13. glslangparams — Extracting OpenGL 2 shader parameters

This module can be used to extract the parameters of an OpenGL 2 shader from the shader source file.

cgkit.glslangparams.glslangparams(shader=None, cpp=None, cpperrstream=sys.stderr)

Extracts the shader parameters from an OpenGL 2 shader source file.

The argument shader is either the name of the shader source file or a file-like object that provides the shader sources. cpp determines how the shader source is preprocessed. It can either be a string containing the name of an external preprocessor tool (such as cpp) that must take the file name as parameter and dump the preprocessed output to stdout or it can be a callable that takes shader and cpperrstream as input and returns the preprocessed sources as a string. If the external preprocessor does not produce any data a PreprocessorNotFound exception is thrown. The error stream of the preprocessor is written to the object that is specified by cpperrstream which must have a write() method. If cpperrstream is None, the error stream is ignored.

If cpp is None a simple internal preprocessor based on the simplecpp module is used.

The function returns three lists (uniform, attribute, varying) that contain the variables with the corresponding qualifier.

A uniform variable is a 5-tuple (type, identifier, arraysize, structname, struct). arraysize is a string containing the expression for the length of the array (i.e. the value between the square brackets). If the variable is no array, arraysize is None. When the variable is a struct, type has the value 'struct'. In this case, the struct is given in struct (which is itself a list of variables as 5-tuples). If the struct has a name, this name is given in structname, otherwise structname is None.

An attribute variable is a 2-tuple (type, identifier) and a varying variable is a 3-tuple (type, identifier, arraysize) where arraysize is defined as in the uniform case.

The module defines the following exception class:

exception cgkit.glslangparams.GLSLangParseError

This exception is thrown when an error occurs during parsing the shader source file.

Previous topic

4.12. glslangtokenize — Tokenizer for the OpenGL 2 shading language

Next topic

4.14. spacedevice — Wrapper around the 3Dconnexion Developer’s Kits

This Page