1#!python 2# Copyright 2017 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_proc_table.py: 7# Code generation for entry point loading tables. 8# NOTE: don't run this script directly. Run scripts/run_code_generation.py. 9 10import sys 11from datetime import date 12import registry_xml 13 14out_file_name_gles = "../src/libGLESv2/proc_table_egl_autogen.cpp" 15out_file_name_gl = "../src/libGL/proc_table_wgl_autogen.cpp" 16 17# The EGL_ANGLE_explicit_context extension is generated differently from other extensions. 18# Toggle generation here. 19# Only for GLES 20support_egl_ANGLE_explicit_context = True 21 22strip_suffixes = ["ANGLE", "EXT", "KHR", "OES", "CHROMIUM", "OVR"] 23 24template_cpp = """// GENERATED FILE - DO NOT EDIT. 25// Generated by {script_name} using data from {data_source_name}. 26// 27// Copyright {copyright_year} The ANGLE Project Authors. All rights reserved. 28// Use of this source code is governed by a BSD-style license that can be 29// found in the LICENSE file. 30// 31// getProcAddress loader table: 32// Mapping from a string entry point name to function address. 33// 34 35{includes} 36#define P(FUNC) reinterpret_cast<{cast}>(FUNC) 37 38namespace {namespace} 39{{ 40ProcEntry g_procTable[] = {{ 41{proc_data} 42}}; 43 44size_t g_numProcs = {num_procs}; 45}} // namespace {namespace} 46""" 47 48includes_gles = """#include "libGLESv2/proc_table_egl.h" 49 50#include "libGLESv2/entry_points_egl.h" 51#include "libGLESv2/entry_points_egl_ext.h" 52#include "libGLESv2/entry_points_gles_1_0_autogen.h" 53#include "libGLESv2/entry_points_gles_2_0_autogen.h" 54#include "libGLESv2/entry_points_gles_3_0_autogen.h" 55#include "libGLESv2/entry_points_gles_3_1_autogen.h" 56#include "libGLESv2/entry_points_gles_ext_autogen.h" 57#include "platform/Platform.h" 58""" 59 60includes_gl = """#include "libGL/proc_table_wgl.h" 61 62#include "libGL/entry_points_wgl.h" 63#include "libGL/entry_points_gl_1_0_autogen.h" 64#include "libGL/entry_points_gl_1_1_autogen.h" 65#include "libGL/entry_points_gl_1_2_autogen.h" 66#include "libGL/entry_points_gl_1_3_autogen.h" 67#include "libGL/entry_points_gl_1_4_autogen.h" 68#include "libGL/entry_points_gl_1_5_autogen.h" 69#include "libGL/entry_points_gl_2_0_autogen.h" 70#include "libGL/entry_points_gl_2_1_autogen.h" 71#include "libGL/entry_points_gl_3_0_autogen.h" 72#include "libGL/entry_points_gl_3_1_autogen.h" 73#include "libGL/entry_points_gl_3_2_autogen.h" 74#include "libGL/entry_points_gl_3_3_autogen.h" 75#include "libGL/entry_points_gl_4_0_autogen.h" 76#include "libGL/entry_points_gl_4_1_autogen.h" 77#include "libGL/entry_points_gl_4_2_autogen.h" 78#include "libGL/entry_points_gl_4_3_autogen.h" 79#include "libGL/entry_points_gl_4_4_autogen.h" 80#include "libGL/entry_points_gl_4_5_autogen.h" 81#include "libGL/entry_points_gl_4_6_autogen.h" 82#include "platform/Platform.h" 83""" 84 85sys.path.append('../src/libANGLE/renderer') 86import angle_format 87 88 89def main(): 90 91 # auto_script parameters. 92 if len(sys.argv) > 1: 93 inputs = [source for source in registry_xml.xml_inputs] 94 outputs = [out_file_name_gles, out_file_name_gl] 95 if sys.argv[1] == 'inputs': 96 print ','.join(inputs) 97 elif sys.argv[1] == 'outputs': 98 print ','.join(outputs) 99 else: 100 print('Invalid script parameters') 101 return 1 102 return 0 103 104 glesxml = registry_xml.RegistryXML('gl.xml', 'gl_angle_ext.xml') 105 106 for annotation in ["2_0", "3_0", "3_1", "1_0"]: 107 108 name_prefix = "GL_ES_VERSION_" 109 if annotation[0] == '1': 110 name_prefix = "GL_VERSION_ES_CM_" 111 feature_name = "{}{}".format(name_prefix, annotation) 112 glesxml.AddCommands(feature_name, annotation) 113 114 glesxml.AddExtensionCommands(registry_xml.supported_extensions, ['gles2', 'gles1']) 115 116 # Also don't add GLES extension commands to libGL proc table 117 extension_commands = [] 118 for extension_name, ext_cmd_names in sorted(glesxml.ext_data.iteritems()): 119 extension_commands.extend(glesxml.ext_data[extension_name]) 120 for name in extension_commands: 121 name_no_suffix = name 122 for suffix in strip_suffixes: 123 if name_no_suffix.endswith(suffix): 124 name_no_suffix = name_no_suffix[0:-len(suffix)] 125 126 gles_data = glesxml.all_cmd_names.get_all_commands() 127 128 eglxml = registry_xml.RegistryXML('egl.xml', 'egl_angle_ext.xml') 129 130 for annotation in ["1_0", "1_1", "1_2", "1_3", "1_4", "1_5"]: 131 132 name_prefix = "EGL_VERSION_" 133 feature_name = "{}{}".format(name_prefix, annotation) 134 eglxml.AddCommands(feature_name, annotation) 135 136 eglxml.AddExtensionCommands(registry_xml.supported_egl_extensions, ['gles2', 'gles1']) 137 138 gles_data.extend(eglxml.all_cmd_names.get_all_commands()) 139 140 gles_data.append("ANGLEGetDisplayPlatform") 141 gles_data.append("ANGLEResetDisplayPlatform") 142 143 all_functions = {} 144 145 for function in gles_data: 146 if function.startswith("gl"): 147 all_functions[function] = "gl::" + function[2:] 148 # Special handling for EGL_ANGLE_explicit_context extension 149 if support_egl_ANGLE_explicit_context: 150 all_functions[function + "ContextANGLE"] = "gl::" + function[2:] + "ContextANGLE" 151 elif function.startswith("egl"): 152 all_functions[function] = "EGL_" + function[3:] 153 else: 154 all_functions[function] = function 155 156 proc_data = [(' {"%s", P(%s)}' % (func, angle_func)) 157 for func, angle_func in sorted(all_functions.iteritems())] 158 159 with open(out_file_name_gles, 'w') as out_file: 160 output_cpp = template_cpp.format( 161 script_name=sys.argv[0], 162 data_source_name="gl.xml, gl_angle_ext.xml, egl.xml, egl_angle_ext.xml", 163 copyright_year=date.today().year, 164 includes=includes_gles, 165 cast="__eglMustCastToProperFunctionPointerType", 166 namespace="egl", 167 proc_data=",\n".join(proc_data), 168 num_procs=len(proc_data)) 169 out_file.write(output_cpp) 170 out_file.close() 171 172 # libGL proc table 173 glxml = registry_xml.RegistryXML('gl.xml') 174 175 for annotation in [ 176 "1_0", "1_1", "1_2", "1_3", "1_4", "1_5", "2_0", "2_1", "3_0", "3_1", "3_2", "3_3", 177 "4_0", "4_1", "4_2", "4_3", "4_4", "4_5", "4_6" 178 ]: 179 180 name_prefix = "GL_VERSION_" 181 feature_name = "{}{}".format(name_prefix, annotation) 182 glxml.AddCommands(feature_name, annotation) 183 184 gl_data = [cmd for cmd in glxml.all_cmd_names.get_all_commands()] 185 186 wglxml = registry_xml.RegistryXML('wgl.xml') 187 188 for annotation in ["1_0"]: 189 190 name_prefix = "WGL_VERSION_" 191 feature_name = "{}{}".format(name_prefix, annotation) 192 wglxml.AddCommands(feature_name, annotation) 193 194 gl_commands = wglxml.all_cmd_names.get_all_commands() 195 gl_data.extend([cmd if cmd[:3] == 'wgl' else 'wgl' + cmd for cmd in gl_commands]) 196 197 all_functions = {} 198 199 for function in gl_data: 200 if function.startswith("gl"): 201 all_functions[function] = "gl::" + function[2:] 202 else: 203 all_functions[function] = function 204 205 proc_data = [(' {"%s", P(%s)}' % (func, angle_func)) 206 for func, angle_func in sorted(all_functions.iteritems())] 207 208 with open(out_file_name_gl, 'w') as out_file: 209 output_cpp = template_cpp.format( 210 script_name=sys.argv[0], 211 data_source_name="gl.xml, wgl.xml", 212 copyright_year=date.today().year, 213 includes=includes_gl, 214 cast="PROC", 215 namespace="wgl", 216 proc_data=",\n".join(proc_data), 217 num_procs=len(proc_data)) 218 out_file.write(output_cpp) 219 out_file.close() 220 return 0 221 222 223if __name__ == '__main__': 224 sys.exit(main()) 225