graphics-toolkit/bin/generate-glext.php
2021-12-17 23:34:28 +01:00

40 lines
No EOL
1.1 KiB
PHP

<?php
if ( ! file_exists(__DIR__ . "/../resources/gl.xml")) {
copy("https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/gl.xml", __DIR__ . "/../resources/gl.xml");
}
$xml = new DOMDocument();
$xml->loadXML(file_get_contents(__DIR__ . "/../resources/gl.xml"));
$commands = $xml->getElementsByTagName("commands")->item(0);
$data = file_get_contents(__DIR__ . "/../headers/gl.h");
$data .= "// GENERATED DATA START\n\n";
/** @var DOMNode $node */
foreach ($commands->childNodes as $node) {
if ($node->nodeName !== "command") {
continue;
}
/** @var DOMElement $node */
$proto = $node->getElementsByTagName("proto")->item(0);
/** @var DOMElement $name */
$name = $proto->getElementsByTagName("name")[0];
$name->remove();
$returnType = trim($proto->textContent);
$functionName = trim($name->textContent);
$args = [];
foreach ($node->getElementsByTagName("param") as $param) {
$args[] = trim($param->textContent);
}
$data .= "typedef $returnType (* FUNC_$functionName) (" . implode(", ", $args) . ");\n";
}
file_put_contents(__DIR__ . "/../headers/gl_generated.h", $data);