You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.1 KiB
PHTML

3 years ago
<?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");
}
$types = [
"int" => [
"char",
"unsigned char",
"int",
"unsigned int",
"short",
"unsigned short",
"long",
"unsigned long",
"long long",
"unsigned long long",
"GLsizeiptr",
"GLintptr",
"GLenum",
"GLboolean",
"GLbitfield",
"GLvoid",
"GLbyte",
"GLshort",
"GLint",
"GLubyte",
"GLushort",
"GLuint",
"GLsizei",
"GLchar",
"GLsizeiptr",
"GLintptr",
"GLsync",
"GLeglImageOES",
"GLeglClientBufferEXT",
"GLuint64",
"GLint64",
"GLuint64EXT",
"GLint64EXT",
"GLfixed",
"GLhalfNV",
"GLhandleARB",
"GLcharARB",
"GLintptrARB",
"GLsizeiptrARB",
"GLclampx",
],
"float" => [
'GLfloat',
'GLdouble',
'float',
'double',
],
];
3 years ago
$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";
$php = "<?php\n\nuse Cijber\GraphicsToolkit\GL;\nuse FFI\Cdata;\n\n// generated gl functions\n\n";
3 years ago
/** @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);
3 years ago
$functionName = trim($name->textContent);
$args = [];
$names = [];
$phpArgs = [];
3 years ago
foreach ($node->getElementsByTagName("param") as $param) {
$name = $param->getElementsByTagName('name')->item(0);
$name->remove();
$type = trim($param->textContent);;
if (($type === 'void *' || $type === 'const void *') && $functionName === 'glVertexAttribPointer' || $functionName === 'glDrawElements') {
$type = 'unsigned long long';
}
$phpType = "";
foreach ($types as $foundPhpType => $cTypes) {
if (false !== array_search($type, $cTypes)) {
$phpType = $foundPhpType;
break;
}
}
if ($phpType !== "") {
$phpArgs[] = $phpType . ' $' . $name->textContent;
} else {
$phpArgs[] = '$' . $name->textContent;
}
$names[] = '$' . $name->textContent;
$args[] = $type;
3 years ago
}
$data .= "typedef $returnType (* FUNC_$functionName) (" . implode(", ", $args) . ");\n";
$functionBody = "(" . implode(", ", $phpArgs) . ") {\n static \$proc;\n return (\$proc ??= GL::getProcAddress('" . strtolower($functionName[2]) . substr($functionName, 3) . "'))(" . implode(", ", $names) . ");\n}\n\n";;
$php .= "function $functionName$functionBody";
3 years ago
}
file_put_contents(__DIR__ . "/../headers/gl_generated.h", $data);
file_put_contents(__DIR__ . "/../src/gl_functions.php", $php);