1#!/usr/bin/python3 2# Copyright 2016 The ANGLE Project Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5# 6# gen_copy_conversion_table.py: 7# Code generation for ES3 valid copy conversions table format map. 8# NOTE: don't run this script directly. Run scripts/run_code_generation.py. 9 10import sys 11 12sys.path.append('renderer') 13import angle_format 14 15template_cpp = """// GENERATED FILE - DO NOT EDIT. 16// Generated by {script_name} using data from {data_source_name}. 17// 18// Copyright 2016 The ANGLE Project Authors. All rights reserved. 19// Use of this source code is governed by a BSD-style license that can be 20// found in the LICENSE file. 21// 22// format_map: 23// Determining the sized internal format from a (format,type) pair. 24// Also check es3 format combinations for validity. 25 26#include "angle_gl.h" 27#include "common/debug.h" 28 29namespace gl 30{{ 31 32bool ValidES3CopyConversion(GLenum textureFormat, GLenum framebufferFormat) 33{{ 34 switch (textureFormat) 35 {{ 36{texture_format_cases} default: 37 break; 38 }} 39 40 return false; 41}} 42 43}} // namespace gl 44""" 45 46template_format_case = """ case {texture_format}: 47 switch (framebufferFormat) 48 {{ 49{framebuffer_format_cases} return true; 50 default: 51 break; 52 }} 53 break; 54 55""" 56 57template_simple_case = """ case {key}: 58""" 59 60 61def parse_texture_format_case(texture_format, framebuffer_formats): 62 framebuffer_format_cases = "" 63 for framebuffer_format in sorted(framebuffer_formats): 64 framebuffer_format_cases += template_simple_case.format(key=framebuffer_format) 65 return template_format_case.format( 66 texture_format=texture_format, framebuffer_format_cases=framebuffer_format_cases) 67 68 69def main(): 70 71 data_source_name = 'es3_copy_conversion_formats.json' 72 out_file_name = 'es3_copy_conversion_table_autogen.cpp' 73 74 # auto_script parameters. 75 if len(sys.argv) > 1: 76 inputs = ['renderer/angle_format.py', data_source_name] 77 outputs = [out_file_name] 78 79 if sys.argv[1] == 'inputs': 80 print(','.join(inputs)) 81 elif sys.argv[1] == 'outputs': 82 print(','.join(outputs)) 83 else: 84 print('Invalid script parameters') 85 return 1 86 return 0 87 88 json_data = angle_format.load_json(data_source_name) 89 90 format_map = {} 91 92 for description, data in sorted(json_data.items()): 93 for texture_format, framebuffer_format in data: 94 if texture_format not in format_map: 95 format_map[texture_format] = [] 96 format_map[texture_format] += [framebuffer_format] 97 98 texture_format_cases = "" 99 100 for texture_format, framebuffer_formats in sorted(format_map.items()): 101 texture_format_cases += parse_texture_format_case(texture_format, framebuffer_formats) 102 103 with open(out_file_name, 'wt') as out_file: 104 output_cpp = template_cpp.format( 105 script_name=sys.argv[0], 106 data_source_name=data_source_name, 107 texture_format_cases=texture_format_cases) 108 out_file.write(output_cpp) 109 out_file.close() 110 return 0 111 112 113if __name__ == '__main__': 114 sys.exit(main()) 115