4 This script will regenerate and update GLConsts.h.
7 Download the last gl.xml, egl.xml, glx.xml and wgl.xml from
8 http://www.opengl.org/registry/#specfiles into some XML_DIR:
9 wget https://www.khronos.org/registry/OpenGL/xml/gl.xml
10 wget https://www.khronos.org/registry/OpenGL/xml/glx.xml
11 wget https://www.khronos.org/registry/OpenGL/xml/wgl.xml
12 wget https://www.khronos.org/registry/EGL/api/egl.xml
15 `py ./GLConsts.py <XML_DIR>`
18 Do not add the downloaded XML in the patch
25 from typing
import List
# mypy!
29 import xml
.etree
.ElementTree
33 (_
, XML_DIR_STR
) = sys
.argv
34 XML_DIR
= pathlib
.Path(XML_DIR_STR
)
39 /* This Source Code Form is subject to the terms of the Mozilla Public
40 * License, v. 2.0. If a copy of the MPL was not distributed with this
41 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
49 * GENERATED FILE, DO NOT MODIFY DIRECTLY.
50 * This is a file generated directly from the official OpenGL registry
51 * xml available http://www.opengl.org/registry/#specfiles.
53 * To generate this file, see tutorial in \'GLConsts.py\'.
70 def format_lib_constant(lib
, name
, value
):
71 # lib would be 'GL', 'EGL', 'GLX' or 'WGL'
72 # name is the name of the const (example: MAX_TEXTURE_SIZE)
73 # value is the value of the const (example: 0xABCD)
75 define
= "#define LOCAL_" + lib
+ "_" + name
76 whitespace
= 60 - len(define
)
78 whitespace
= whitespace
% 8
80 return define
+ " " * whitespace
+ " " + value
84 def __init__(self
, lib
, name
, value
, type):
92 LIBS
= ["GL", "EGL", "GLX", "WGL"]
96 self
.libs
= set(GLDatabase
.LIBS
)
97 self
.vendors
= set(["EXT", "ATI"])
98 # there is no vendor="EXT" and vendor="ATI" in gl.xml,
99 # so we manualy declare them
101 def load_xml(self
, xml_path
):
102 tree
= xml
.etree
.ElementTree
.parse(xml_path
)
103 root
= tree
.getroot()
105 for enums
in root
.iter("enums"):
106 vendor
= enums
.get("vendor")
108 # there some standart enums that do have the vendor attribute,
109 # so we fake them as ARB's enums
112 if vendor
not in self
.vendors
:
113 # we map this new vendor in the vendors set.
114 self
.vendors
.add(vendor
)
116 namespaceType
= enums
.get("type")
119 if enum
.tag
!= "enum":
120 # this is not an enum => we skip it
123 lib
= enum
.get("name").split("_")[0]
125 if lib
not in self
.libs
:
126 # unknown library => we skip it
129 name
= enum
.get("name")[len(lib
) + 1 :]
130 value
= enum
.get("value")
131 type = enum
.get("type")
134 # if no type specified, we get the namespace's default type
137 self
.consts
[lib
+ "_" + name
] = GLConst(lib
, name
, value
, type)
143 db
.load_xml(XML_DIR
/ "gl.xml")
144 db
.load_xml(XML_DIR
/ "glx.xml")
145 db
.load_xml(XML_DIR
/ "wgl.xml")
146 db
.load_xml(XML_DIR
/ "egl.xml")
150 lines
: List
[str] = [] # noqa: E999 (bug 1573737)
152 keys
= sorted(db
.consts
.keys())
155 lines
.append("// " + lib
)
163 const_str
= format_lib_constant(lib
, const
.name
, const
.value
)
164 lines
.append(const_str
)
170 b_lines
: List
[bytes
] = [HEADER
] + [x
.encode() for x
in lines
] + [FOOTER
]
171 b_data
: bytes
= b
"\n".join(b_lines
)
173 dest
= pathlib
.Path("GLConsts.h")
174 dest
.write_bytes(b_data
)
176 print(f
"Wrote {len(b_data)} bytes.") # Some indication that we're successful.