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