Example #1
0
def compile_shader_program(shader_dir, shader_name):
    print('Compiling shader "' + shader_name + '" ...')
    vert_shader = cherry.join_path(shader_dir, 'shaders/vs_' + shader_name + '.sc')
    frag_shader = cherry.join_path(shader_dir, 'shaders/fs_' + shader_name + '.sc')
    vert_out    = cherry.join_path(shader_dir, '%s/vs_' + shader_name + '.bin')
    frag_out    = cherry.join_path(shader_dir, '%s/fs_' + shader_name + '.bin')
    include_dirs= [cherry.bgfx_src_path, cherry.shader_path]

    shader_out_dir = 'assets/shaders'

    compile_info = []
    if cherry.is_windows_system():
        compile_info += [
            ['windows', ['vs_3_0', 'ps_3_0'], 3, 'dx9'],
            ['windows', ['vs_5_0', 'ps_5_0'], 3, 'dx11']
        ]
    compile_info += [
        ['nacl',    [None,    None   ], None, 'essl'],
        ['android', [None,    None   ], None, 'essl_a'],
        ['linux',   ['120',   '120'  ], None, 'glsl'],
        ['osx',     ['metal', 'metal'], None, 'metal'],
#       ['orbis',   ['pssl',  'pssl' ], None, 'pssl'],
        ['linux',   ['spirv', 'spirv'], None, 'spirv']
    ]

    for info_arr in compile_info:
        platform, profile, opt_level, shader_id = info_arr
        folder    = cherry.join_path(shader_out_dir, shader_id)
        cherry.compile_shader(vert_shader, vert_out % folder, platform, 'vertex',   include_dirs, profile[0], opt_level)
        cherry.compile_shader(frag_shader, frag_out % folder, platform, 'fragment', include_dirs, profile[1], opt_level)
Example #2
0
def generate_embedded_shader_header(shader_dir):
    embedded_shader_dir = cherry.join_path(shader_dir, 'embedded_shaders')
    file_list = cherry.get_file_list_from_wildcard(cherry.join_path(embedded_shader_dir, '*.bin.h'))
    shader_src = ' '.join(list(map(cherry.get_file_name, file_list)))
    p = re.compile('fs_([A-Za-z0-9_]*)\.bin.h')
    shader_names = p.findall(shader_src)
    shader_names.sort()
    header_file = open(cherry.join_path(shader_dir, 'embedded_shaders.h'), 'w')
    header_file.write('#ifndef _CHERRYSODA_EMBEDDED_SHADERS_H_\n') 
    header_file.write('#define _CHERRYSODA_EMBEDDED_SHADERS_H_\n') 
    header_file.write('\n')
    for shader in shader_names:
        header_file.write('#include "embedded_shaders/vs_%s.bin.h"\n' % (shader,))
        header_file.write('#include "embedded_shaders/fs_%s.bin.h"\n' % (shader,))
    header_file.write('#ifdef _WIN32\n') 
    for shader in shader_names:
        header_file.write('#include "embedded_shaders/vs_%s.dx.bin.h"\n' % (shader,))
        header_file.write('#include "embedded_shaders/fs_%s.dx.bin.h"\n' % (shader,))
    header_file.write('#endif // _WIN32\n') 
    header_file.write('\n')
    header_file.write('static const bgfx::EmbeddedShader s_embeddedShaders[] =\n{\n')
    for shader in shader_names:
        header_file.write('\tBGFX_EMBEDDED_SHADER(vs_%s),\n' % (shader,))
        header_file.write('\tBGFX_EMBEDDED_SHADER(fs_%s),\n' % (shader,))
    header_file.write('\n\tBGFX_EMBEDDED_SHADER_END()\n};\n')
    header_file.write('\n')
    header_file.write('static const cherrysoda::STL::Vector<cherrysoda::String> s_embeddedShaderNameList =\n{\n')
    for shader in shader_names[:-1]:
        header_file.write('\t"%s",\n' % (shader,))
    if shader_names:
        header_file.write('\t"%s"\n' % (shader_names[-1],))
    header_file.write('};\n')
    header_file.write('\n')
    header_file.write('#endif // _CHERRYSODA_EMBEDDED_SHADERS_H_\n') 
    header_file.close()
def main():
    if not cherry.is_windows_system():
        print('This script is for X86/Windows.')
        print('On Linux, please use package manager to install libSDL2.')
        return
    if cherry.exists(cherry.sdl2_path):
        print('"%s" already exists!' % (cherry.sdl2_path, ))
        return
    sdl2_zip_filename = cherry.join_path(
        cherry.tool_path,
        'res\\SDL2\\SDL2-devel-' + cherry.sdl2_version + '-VC.zip')
    cherry.extract_zip_to(sdl2_zip_filename, cherry.external_path)
    sdl2_dir = cherry.sdl2_path
    cherry.copy(
        cherry.join_path(cherry.tool_path, 'res\\SDL2\\sdl2-config.cmake'),
        sdl2_dir)
def create_project(path, name):
    template_path = cherry.join_path(cherry.tool_path, 'res/CherrySoda/ProjectTemplate')
    project_path = cherry.join_path('.', name)
    if cherry.exists(project_path):
        print('"%s" already exists in current directory!' % (name))
        return 
    cherry.copytree(template_path, project_path)
    file_list = cherry.get_file_list_of_path(project_path)
    processed_name = name
    processed_name = processed_name.replace('-', '_')
    if processed_name[0].islower():
        processed_name = processed_name[0].upper() + processed_name[1:]
    elif processed_name[0] in '0123456789':
        processed_name = 'C_' + processed_name
    replace_list = [['CherrySodaOriginal', name],
                    ['CherrySodaTemplate', processed_name],
                    ['cherrysodatemplate', processed_name.lower()],
                    ['CHERRYSODATEMPLATE', processed_name.upper()]]
    for f in file_list:
        cherry.replace_file_str(f, replace_list)
        cherry.replace_file_name(f, replace_list)
Example #5
0
def create_scene(path, name):
    template_path = cherry.join_path(cherry.tool_path,
                                     'res/CherrySoda/SceneTemplate/*.*')
    project_path = path
    if cherry.exists(cherry.join_path(project_path, 'src')):
        project_path = cherry.join_path(project_path, 'src')
    if cherry.exists(cherry.join_path(project_path, 'Scenes')):
        project_path = cherry.join_path(project_path, 'Scenes')
    cherry.copy(template_path, project_path)
    file_list = [
        cherry.join_path(project_path, cherry.get_file_name(f))
        for f in cherry.get_file_list_from_wildcard(template_path)
    ]
    replace_list = [['CherrySodaSceneTemplate', name],
                    ['cherrysodascenetemplate',
                     name.lower()], ['CHERRYSODASCENETEMPLATE',
                                     name.upper()]]
    for f in file_list:
        cherry.replace_file_str(f, replace_list)
        cherry.replace_file_name(f, replace_list)
def main():
    local_projects_path = cherry.abspath(
        cherry.join_path(cherry.project_path, '..'))
    local_bgfx_path = cherry.join_path(local_projects_path, 'bgfx')
    local_bimg_path = cherry.join_path(local_projects_path, 'bimg')
    local_bx_path = cherry.join_path(local_projects_path, 'bx')

    engine_bgfx_path = cherry.join_path(cherry.external_path, 'bgfx/bgfx')
    engine_bimg_path = cherry.join_path(cherry.external_path, 'bgfx/bimg')
    engine_bx_path = cherry.join_path(cherry.external_path, 'bgfx/bx')

    cherry.rmtree(engine_bgfx_path)
    cherry.rmtree(engine_bimg_path)
    cherry.rmtree(engine_bx_path)

    cherry.copytree(local_bgfx_path, engine_bgfx_path)
    cherry.copytree(local_bimg_path, engine_bimg_path)
    cherry.copytree(local_bx_path, engine_bx_path)

    cherry.rmtree(cherry.join_path(engine_bgfx_path, 'bindings'))
    cherry.rmtree(cherry.join_path(engine_bgfx_path, 'examples'))
    cherry.rmtree(cherry.join_path(engine_bimg_path, 'tools'))
    cherry.rmtree(cherry.join_path(engine_bx_path, 'tests'))

    cherry.rmtree(cherry.join_path(engine_bgfx_path, '.build'))
    cherry.rmtree(cherry.join_path(engine_bgfx_path, '.github'))
    cherry.rmtree(cherry.join_path(engine_bgfx_path, '.git'))
    cherry.rmtree(cherry.join_path(engine_bimg_path, '.git'))
    cherry.rmtree(cherry.join_path(engine_bx_path, '.git'))
Example #7
0
def compile_embedded_shader_program(shader_dir, shader_name):
    print('Compiling embedded shader "' + shader_name + '" ...')
    vert_shader = cherry.join_path(shader_dir, 'shaders/vs_' + shader_name + '.sc')
    frag_shader = cherry.join_path(shader_dir, 'shaders/fs_' + shader_name + '.sc')
    vert_out    = cherry.join_path(shader_dir, 'embedded_shaders/vs_' + shader_name + '.bin.h')
    frag_out    = cherry.join_path(shader_dir, 'embedded_shaders/fs_' + shader_name + '.bin.h')
    dx_vert_out = cherry.join_path(shader_dir, 'embedded_shaders/vs_' + shader_name + '.dx.bin.h')
    dx_frag_out = cherry.join_path(shader_dir, 'embedded_shaders/fs_' + shader_name + '.dx.bin.h')
    include_dirs= [cherry.bgfx_src_path, cherry.shader_path]
    shader_tmp  = cherry.join_path(cherry.tmp_path, 'shader.tmp')

    compile_info = [
        {
            'platform': 'linux',
            'suffix': 'glsl'
        },
        {
            'platform': 'linux',
            'profile': ['spirv', 'spirv'],
            'suffix': 'spv'
        },
        {
            'platform': 'ios',
            'profile': ['metal', 'metal'],
            'opt_level': 3,
            'suffix': 'mtl'
        }
    ]
    cherry.make_sure_folder_exist(vert_out)
    vs_file = open(vert_out, 'w')
    fs_file = open(frag_out, 'w')
    for info_dict in compile_info:
        platform  = info_dict.get('platform')
        profile   = info_dict.get('profile', [None, None])
        opt_level = info_dict.get('opt_level')
        suffix    = info_dict.get('suffix', '')
        cherry.compile_shader(vert_shader, shader_tmp, platform, 'vertex',   include_dirs, profile[0], opt_level, 'vs_' + shader_name + '_' + suffix)
        vs_file.write(cherry.read_file(shader_tmp))
        cherry.compile_shader(frag_shader, shader_tmp, platform, 'fragment', include_dirs, profile[1], opt_level, 'fs_' + shader_name + '_' + suffix)
        fs_file.write(cherry.read_file(shader_tmp))
    vs_file.write('extern const uint8_t* vs_' + shader_name + '_pssl;\n')
    vs_file.write('extern const uint32_t vs_' + shader_name + '_pssl_size;\n')
    fs_file.write('extern const uint8_t* fs_' + shader_name + '_pssl;\n')
    fs_file.write('extern const uint32_t fs_' + shader_name + '_pssl_size;\n')
    vs_file.close()
    fs_file.close()
    if cherry.is_windows_system():
        compile_info = [
            {
                'platform': 'windows',
                'profile': ['vs_3_0', 'ps_3_0'],
                'opt_level': 3,
                'suffix': 'dx9'
            },
            {
                'platform': 'windows',
                'profile': ['vs_4_0', 'ps_4_0'],
                'opt_level': 3,
                'suffix': 'dx11'
            }
        ]
        vs_file = open(dx_vert_out, 'w')
        fs_file = open(dx_frag_out, 'w')
        for info_dict in compile_info:
            platform  = info_dict.get('platform')
            profile   = info_dict.get('profile', [None, None])
            opt_level = info_dict.get('opt_level')
            suffix    = info_dict.get('suffix', '')
            cherry.compile_shader(vert_shader, shader_tmp, platform, 'vertex',   include_dirs, profile[0], opt_level, 'vs_' + shader_name + '_' + suffix)
            vs_file.write(cherry.read_file(shader_tmp))
            cherry.compile_shader(frag_shader, shader_tmp, platform, 'fragment', include_dirs, profile[1], opt_level, 'fs_' + shader_name + '_' + suffix)
            fs_file.write(cherry.read_file(shader_tmp))
        vs_file.close()
        fs_file.close()