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
27 import xml
.etree
.ElementTree
28 from typing
import List
# mypy!
32 (_
, XML_DIR_STR
) = sys
.argv
33 XML_DIR
= pathlib
.Path(XML_DIR_STR
)
38 /* This Source Code Form is subject to the terms of the Mozilla Public
39 * License, v. 2.0. If a copy of the MPL was not distributed with this
40 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
48 * GENERATED FILE, DO NOT MODIFY DIRECTLY.
49 * This is a file generated directly from the official OpenGL registry
50 * xml available http://www.opengl.org/registry/#specfiles.
52 * To generate this file, see tutorial in \'GLConsts.py\'.
69 def format_lib_constant(lib
, name
, value
):
70 # lib would be 'GL', 'EGL', 'GLX' or 'WGL'
71 # name is the name of the const (example: MAX_TEXTURE_SIZE)
72 # value is the value of the const (example: 0xABCD)
74 define
= "#define LOCAL_" + lib
+ "_" + name
75 whitespace
= 60 - len(define
)
77 whitespace
= whitespace
% 8
79 return define
+ " " * whitespace
+ " " + value
83 def __init__(self
, lib
, name
, value
, type):
91 LIBS
= ["GL", "EGL", "GLX", "WGL"]
95 self
.libs
= set(GLDatabase
.LIBS
)
96 self
.vendors
= set(["EXT", "ATI"])
97 # there is no vendor="EXT" and vendor="ATI" in gl.xml,
98 # so we manualy declare them
100 def load_xml(self
, xml_path
):
101 tree
= xml
.etree
.ElementTree
.parse(xml_path
)
102 root
= tree
.getroot()
104 for enums
in root
.iter("enums"):
105 vendor
= enums
.get("vendor")
107 # there some standart enums that do have the vendor attribute,
108 # so we fake them as ARB's enums
111 if vendor
not in self
.vendors
:
112 # we map this new vendor in the vendors set.
113 self
.vendors
.add(vendor
)
115 namespaceType
= enums
.get("type")
118 if enum
.tag
!= "enum":
119 # this is not an enum => we skip it
122 lib
= enum
.get("name").split("_")[0]
124 if lib
not in self
.libs
:
125 # unknown library => we skip it
128 name
= enum
.get("name")[len(lib
) + 1 :]
129 value
= enum
.get("value")
130 type = enum
.get("type")
133 # if no type specified, we get the namespace's default type
136 self
.consts
[lib
+ "_" + name
] = GLConst(lib
, name
, value
, type)
142 db
.load_xml(XML_DIR
/ "gl.xml")
143 db
.load_xml(XML_DIR
/ "glx.xml")
144 db
.load_xml(XML_DIR
/ "wgl.xml")
145 db
.load_xml(XML_DIR
/ "egl.xml")
149 lines
: List
[str] = [] # noqa: E999 (bug 1573737)
151 keys
= sorted(db
.consts
.keys())
154 lines
.append("// " + lib
)
162 const_str
= format_lib_constant(lib
, const
.name
, const
.value
)
163 lines
.append(const_str
)
169 b_lines
: List
[bytes
] = [HEADER
] + [x
.encode() for x
in lines
] + [FOOTER
]
170 b_data
: bytes
= b
"\n".join(b_lines
)
172 dest
= pathlib
.Path("GLConsts.h")
173 dest
.write_bytes(b_data
)
175 print(f
"Wrote {len(b_data)} bytes.") # Some indication that we're successful.