diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2009-04-28 02:44:36 +0100 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2009-04-28 02:48:19 +0100 |
commit | e89328b8af2e9edf518961ea6ead3d367f6695c5 (patch) | |
tree | b664b2fcdd453157a58ad1da1808626f214050bd /scripts | |
parent | fd859199bd1d6421a56b27c1eef02a40696e1c44 (diff) | |
download | clutter-gst-e89328b8af2e9edf518961ea6ead3d367f6695c5.tar.gz |
[videosink] Add a I420 to RGBA fragment program
Things are a bit convoluted:
* we want to keep GLSL shaders (eg OpenGL ES 2.0 does not have
the GL_ARB_fragment_program extension)
* we want to default to assembly fragment programs as they will support
as broader range of hardware
Now, those fragment programs are written in Cg, compiled with the Cg
compiler and its arbfp1 profile and then turned into a header file
thanks to a small python script. Sounds fun isn't it?
As people may not want to install the Cg compiler, let's commit the
actual fragment program. The configure script will detect if you have
cgc and add targets to build the pso file accordingly.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Makefile.am | 1 | ||||
-rwxr-xr-x | scripts/pso2h.py | 126 |
2 files changed, 127 insertions, 0 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am new file mode 100644 index 0000000..0648085 --- /dev/null +++ b/scripts/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = pso2h.py diff --git a/scripts/pso2h.py b/scripts/pso2h.py new file mode 100755 index 0000000..0ce063f --- /dev/null +++ b/scripts/pso2h.py @@ -0,0 +1,126 @@ +#!/usr/bin/python +"""pso2h + +A small python script to generated header files from compiled ARBfp1.0 shaders + +Usage: ./pso2h-runtime [options] file.pso + +Options: + -o, --output header file name + -n, --name name of the shader + -h, --help display this help + -v, --verbose verbose output + + file.pso compiled shader""" + +import sys, os, string, getopt + +__author__ = "Damien Lespiau <damien.lespiau@intel.com>" +__version__ = "0.1" +__date__ = "20090426" +__copyright__ = "Copyright (c) 2009 Intel Corporation" +__license__ = "GPL v2" + +_verbose = 0 + +_template = """/* + * This file was generated by pso2h. + */ + +#ifndef %s +#define %s + +/* + * This define is the size of the shader in bytes. More precisely it's the + * sum of strlen() of every string in the array. + */ +#define %s %d + +static const char *%s[] = +{ +%s}; + +#endif +""" + +def define(format, filename): + path, file = os.path.split(filename) + return format % string.upper(file.replace('.', '_').capitalize()) + +class PSO: + def __init__(self, filename=None, name=None): + self.filename = filename + self.name = name + + def write_header(self, filename): + file = open(self.filename) + header = open(filename, "w") + __HEADER__ = define("__%s__", filename) + SIZE = define("%s_SZ", self.name) + body = "" + size = 0; + + for line in file: + # skip comments + if line.startswith('#'): + continue + line = string.strip(line) + line += '\\n' + size += len(line) - 1; + body += " \"%s\",\n" % line + + header.write(_template % (__HEADER__, + __HEADER__, + SIZE, + size, + self.name, + body)) + +def usage(): + print __doc__ + +def main(argv): + opt_shader = None + opt_header = None + opt_name = None + try: + opts, args = getopt.getopt(argv, "hvo:n:", \ + ["help", "verbose", "--ouput=", "--name="]) + except getopt.GetoptError: + usage() + sys.exit(1) + for opt, arg in opts: + if opt in ("-h", "--help"): + usage() + sys.exit() + elif opt in ("-v", "--verbose"): + global _verbose + _verbose = 1 + elif opt in ("-o", "-output"): + opt_header = arg + elif opt in ("-n", "-name"): + opt_name = arg + if args: + opt_shader = "".join(args) + + #input validation + if not opt_shader: + print "error: you must supply a shader file.\n" + usage() + sys.exit(1) + if not os.access(opt_shader, os.F_OK): + print opt_shader + ": file not found" + sys.exit(1) + file, ext = os.path.splitext(opt_shader) + if not opt_header: + opt_header = file + ".h" + if not opt_name: + path, file = os.path.split(file) + opt_name = file + + pso = PSO(opt_shader, opt_name) + pso.write_header(opt_header) + +if __name__ == "__main__": + main(sys.argv[1:]) + |