Example #1
0
def write_shader_param():
    header = CodeWriter(os.path.join(get_base_path(), 'shaderparam.h'))
    code = CodeWriter(os.path.join(get_base_path(), 'shaderparam.cpp'))

    parameters = []
    for shader in SHADERS:
        for param in shader.uniforms:
            parameters.append(param[0])
        if shader.tex_param:
            parameters.append(shader.tex_param)
    parameters = list(set(parameters))

    hash_data = get_hash_function('hash_shader_parameter', parameters,
                                  False)

    code.putln(hash_data.code.replace('inline ', ''))

    header.start_guard('CHOWDREN_SHADERPARAM_H')
    header.putln('unsigned int hash_shader_parameter(const char * str, '
                                                    'unsigned int len);')
    header.putln('')

    for k, v in hash_data.strings.iteritems():
        name = 'SHADER_PARAM_%s' % get_method_name(k).upper()
        header.putdefine(name, v)

    header.close_guard('CHOWDREN_SHADERPARAM_H')

    header.close()
    code.close()
Example #2
0
def translate_name(name, out_dir, profile):
    makedirs(out_dir)
    shader_path = os.path.join(get_base_path(), 'shaders')
    vert_path = os.path.join(shader_path, '%s.vert' % name)
    frag_path = os.path.join(shader_path, '%s.frag' % name)
    new_vert_path = os.path.join(out_dir, '%s.vert' % name)
    new_frag_path = os.path.join(out_dir, '%s.frag' % name)
    translate_shader_path(vert_path, 'vertex', new_vert_path, profile)
    translate_shader_path(frag_path, 'fragment', new_frag_path, profile)
    return new_vert_path, new_frag_path
Example #3
0
def translate_name(name, out_dir, profile):
    makedirs(out_dir)
    shader_path = os.path.join(get_base_path(), 'shaders')
    vert_path = os.path.join(shader_path, '%s.vert' % name)
    frag_path = os.path.join(shader_path, '%s.frag' % name)
    new_vert_path = os.path.join(out_dir, '%s.vert' % name)
    new_frag_path = os.path.join(out_dir, '%s.frag' % name)
    translate_shader_path(vert_path, 'vertex', new_vert_path, profile)
    translate_shader_path(frag_path, 'fragment', new_frag_path, profile)
    return new_vert_path, new_frag_path
Example #4
0
def convert_shaders():
    base_path = get_base_path()
    shader_path = os.path.join(base_path, 'shaders')

    for shader in get_shader_programs():
        vert_path = os.path.join(shader_path, '%s.vert' % shader)
        frag_path = os.path.join(shader_path, '%s.frag' % shader)

        with open(vert_path, 'rb') as fp:
            vert = fp.read()
        with open(frag_path, 'rb') as fp:
            frag = fp.read()

        convert(vert, frag, SHADERS_DIR, 'hlsl', shader)
Example #5
0
def convert_shaders():
    base_path = get_base_path()
    shader_path = os.path.join(base_path, 'shaders')

    for shader in get_shader_programs():
        vert_path = os.path.join(shader_path, '%s.vert' % shader)
        frag_path = os.path.join(shader_path, '%s.frag' % shader)

        with open(vert_path, 'rb') as fp:
            vert = fp.read()
        with open(frag_path, 'rb') as fp:
            frag = fp.read()

        convert(vert, frag, SHADERS_DIR, 'hlsl', shader)
Example #6
0
def get_shader_programs():
    shaders = set()
    for path in os.listdir(os.path.join(get_base_path(), 'shaders')):
        shaders.add(os.path.splitext(os.path.basename(path))[0])
    return shaders
Example #7
0
def main():
    # generate key definition files
    import sys
    sys.path.append('..')
    from chowdren.codewriter import CodeWriter
    from chowdren.common import get_base_path
    from chowdren.stringhash import get_string_int_map
    import os

    writer = CodeWriter(os.path.join(get_base_path(), 'keyconv.cpp'))

    # write keys file
    writer.putln('#include <string>')
    writer.putln('#include "keydef.h"')
    writer.putln('#include "stringcommon.h"')
    writer.putln('')

    writer.putmeth('int translate_vk_to_key', 'int vk')
    writer.putln('switch (vk) {')
    writer.indent()
    for vk, name in VK_TO_SDL.iteritems():
        writer.putln('case %s: return %s;' % (vk, name[0]))
    writer.end_brace()
    writer.putln('return -1;')
    writer.end_brace()
    writer.putln('')

    string_map = {}
    for vk, name in VK_TO_SDL.iteritems():
        string_name = VK_TO_NAME.get(vk, None)
        if string_name is None:
            continue
        string_map[string_name] = name[0]

    writer.putln(
        get_string_int_map('translate_string_to_key', 'get_key_string_hash',
                           string_map, False))

    writer.putmeth('std::string translate_vk_to_string', 'int vk')
    writer.putln('switch (vk) {')
    writer.indent()
    for vk, name in VK_TO_SDL.iteritems():
        string_name = VK_TO_NAME.get(vk, None)
        if string_name is None:
            continue
        writer.putlnc('case %s: return %r;', vk, string_name)
    writer.end_brace()
    writer.putln('return "";')
    writer.end_brace()
    writer.putln('')

    writer.putmeth('std::string translate_key_to_string', 'int key')
    writer.putln('switch (key) {')
    writer.indent()
    for name, string_name in KEY_TO_NAME.iteritems():
        writer.putlnc('case %s: return %r;', name, string_name)
    writer.end_brace()
    writer.putln('return "";')
    writer.end_brace()

    # keys = {}
    # for name, value in SDL_KEYS.iteritems():
    #     if isinstance(value, str):
    #         value = ord(value)
    #     keys[value] = name

    # writer.putmeth('int translate_key_to_index', 'int key')
    # writer.putln('switch (key) {')
    # writer.indent()
    # for index, value in enumerate(sorted(keys)):
    #     name = keys[value]
    #     writer.putlnc('case %s: return %r;', name, index)
    # writer.end_brace()
    # writer.putln('return -1;')
    # writer.end_brace()

    writer.close()
Example #8
0
def write_shaders():
    code = CodeWriter(os.path.join(get_base_path(), 'shaders.cpp'))

    for shader in SHADERS:
        shader_name = '%sShader' % shader.name
        code.putlnc('class %s : public BaseShader', shader_name)
        code.start_brace()
        code.put_access('public')

        for uniform in shader.uniforms:
            code.putlnc('static int %s;', uniform[0])

        if shader.uniforms:
            code.putln('')

        asset_name = 'SHADER_%s' % shader.asset_name.upper()
        args = [asset_name]
        options = []
        if shader.has_back:
            options.append('SHADER_HAS_BACK')
        if shader.has_tex_size:
            options.append('SHADER_HAS_TEX_SIZE')
        if not options:
            if shader.tex_param:
                args.append('0')
        else:
            args.append(' | '.join(options))
        if shader.tex_param:
            args.append('"%s"' % shader.tex_param)

        code.putlnc('%s()', shader_name)
        code.putlnc(': BaseShader(%s)', ', '.join(args))
        code.start_brace()
        code.end_brace()

        code.putln('')

        code.putmeth('void initialize_parameters')
        for uniform in shader.uniforms:
            code.putlnc('%s = get_uniform(%r);', uniform[0], uniform[0],
                        cpp=False)
        code.end_brace()
        code.putln('')

        code.putmeth('static void set_parameters', 'FrameObject * instance')

        for uniform in shader.uniforms:
            param = 'SHADER_PARAM_%s' % uniform[0].upper()
            code.putlnc('BaseShader::set_%s(instance, %s, %s);', uniform[1],
                        param, uniform[0])
        if shader.tex_param:
            param = 'SHADER_PARAM_%s' % shader.tex_param.upper()
            code.putlnc('BaseShader::set_image(instance, %s);', param)
        code.end_brace()

        code.end_brace(True)

        for uniform in shader.uniforms:
            code.putlnc('int %s::%s;', shader_name, uniform[0])

        code.putln('')

    # write static init code
    for shader in SHADERS:
        shader_type = '%sShader' % shader.name
        shader_name = '%s_shader' % shader.name.lower()
        code.putlnc('%s %s;', shader_type, shader_name)

    code.close()
Example #9
0
def get_shader_programs():
    shaders = set()
    for path in os.listdir(os.path.join(get_base_path(), 'shaders')):
        shaders.add(os.path.splitext(os.path.basename(path))[0])
    return shaders
Example #10
0
def main():
    # generate key definition files
    import sys
    sys.path.append('..')
    from chowdren.codewriter import CodeWriter
    from chowdren.common import get_base_path
    from chowdren.stringhash import get_string_int_map
    import os

    writer = CodeWriter(os.path.join(get_base_path(), 'keyconv.cpp'))

    # write keys file
    writer.putln('#include "chowstring.h"')
    writer.putln('#include "keydef.h"')
    writer.putln('#include "stringcommon.h"')
    writer.putln('')

    writer.putmeth('int translate_vk_to_key', 'int vk')
    writer.putln('switch (vk) {')
    writer.indent()
    for vk, name in VK_TO_SDL.iteritems():
        writer.putln('case %s: return %s;' % (vk, name[0]))
    writer.end_brace()
    writer.putln('return -1;')
    writer.end_brace()
    writer.putln('')

    string_map = {}
    for vk, name in VK_TO_SDL.iteritems():
        string_name = VK_TO_NAME.get(vk, None)
        if string_name is None:
            continue
        string_map[string_name] = name[0]

    writer.putln(get_string_int_map('translate_string_to_key',
                                    'get_key_string_hash',
                                    string_map, False))

    writer.putmeth('chowstring translate_vk_to_string',
                   'int vk')
    writer.putln('switch (vk) {')
    writer.indent()
    for vk, name in VK_TO_SDL.iteritems():
        string_name = VK_TO_NAME.get(vk, None)
        if string_name is None:
            continue
        writer.putlnc('case %s: return %r;', vk, string_name)
    writer.end_brace()
    writer.putln('return "";')
    writer.end_brace()
    writer.putln('')

    writer.putmeth('chowstring translate_key_to_string',
                   'int key')
    writer.putln('switch (key) {')
    writer.indent()
    for name, string_name in KEY_TO_NAME.iteritems():
        writer.putlnc('case %s: return %r;', name, string_name)
    writer.end_brace()
    writer.putln('return "";')
    writer.end_brace()

    # keys = {}
    # for name, value in SDL_KEYS.iteritems():
    #     if isinstance(value, str):
    #         value = ord(value)
    #     keys[value] = name

    # writer.putmeth('int translate_key_to_index', 'int key')
    # writer.putln('switch (key) {')
    # writer.indent()
    # for index, value in enumerate(sorted(keys)):
    #     name = keys[value]
    #     writer.putlnc('case %s: return %r;', name, index)
    # writer.end_brace()
    # writer.putln('return -1;')
    # writer.end_brace()

    writer.close()
Example #11
0
def main():
    # generate key definition files
    from chowdren.codewriter import CodeWriter
    from chowdren.common import get_base_path
    import os

    writer = CodeWriter(os.path.join(get_base_path(), 'keyconv.cpp'))

    # write keys file
    writer.putln('#include <string>')
    writer.putln('#include "keydef.h"')
    writer.putln('#include "stringcommon.h"')
    writer.putln('')

    writer.putmeth('int translate_vk_to_key', 'int vk')
    writer.putln('switch (vk) {')
    writer.indent()
    for vk, name in VK_TO_SDL.iteritems():
        writer.putln('case %s: return %s;' % (vk, name[0]))
    writer.end_brace()
    writer.putln('return -1;')
    writer.end_brace()
    writer.putln('')

    writer.putmeth('int translate_string_to_key',
                   'const std::string & in_name')
    writer.putln('std::string name = in_name;')
    writer.putln('to_lower(name);')
    for vk, name in VK_TO_SDL.iteritems():
        string_name = VK_TO_NAME.get(vk, None)
        if string_name is None:
            continue
        string_name = string_name.lower()
        writer.putlnc('if (name.compare(0, %s, %r) == 0) return %s;',
                      len(string_name), string_name, name[0], cpp=False)
    writer.putln('return -1;')
    writer.end_brace()
    writer.putln('')

    writer.putmeth('std::string translate_vk_to_string',
                   'int vk')
    writer.putln('switch (vk) {')
    writer.indent()
    for vk, name in VK_TO_SDL.iteritems():
        string_name = VK_TO_NAME.get(vk, None)
        if string_name is None:
            continue
        writer.putlnc('case %s: return %r;', vk, string_name)
    writer.end_brace()
    writer.putln('return "";')
    writer.end_brace()
    writer.putln('')

    writer.putmeth('std::string translate_key_to_string',
                   'int key')
    writer.putln('switch (key) {')
    writer.indent()
    for name, string_name in KEY_TO_NAME.iteritems():
        writer.putlnc('case %s: return %r;', name, string_name)
    writer.end_brace()
    writer.putln('return "";')
    writer.end_brace()

    writer.close()