winzik/tools/gl-stubs.php
David Nurdin 7ce84c932f OpenGL + OpenAL: PHP-OpenGL / PHP-OpenAL (Ponup) in every runtime
- docker/ext/php-opengl.patch: framebuffers, glGetIntegerv/Floatv, uniforms,
  binary strings, non-fatal shader errors, glDelete*, WebGL guards
- desktop, desktop-async and the WebAssembly engine build both extensions
  (WebGL 1 / Web Audio in the browser)
- engine: OpenGl (raw gl* in SDL's context, begin/end, resources), WebGl
  rewritten on top of it (jumphp-gl.js removed), Audio3d (positional sound)
- headless test/shot run GL games on Xvfb (jumphp-xvfb), JUMPHP_GL
- stubs for phpstan (tools/gl-stubs.php)
- hello-webgl: RawGlScene (raw gl* + 3D beep); jumpball: mediump-safe post
- docs: AGENTS.md, api-web, build, READMEs

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 16:44:36 +01:00

25 lines
1.3 KiB
PHP

<?php
// Writes engine/stubs/opengl.stub.php and openal.stub.php from the loaded extensions (reflection), for phpstan
// and IDEs. Run in the desktop image: bin/jumphp php . tools/gl-stubs.php
foreach (['OpenGL' => 'opengl', 'openal' => 'openal'] as $ext => $file) {
$r = new ReflectionExtension($ext);
$out = "<?php\n// Generated by tools/gl-stubs.php from the $ext extension (" . ($ext === 'OpenGL'
? 'Ponup/php-opengl + docker/ext/php-opengl.patch' : 'Ponup/php-openal') . "): signatures for phpstan / IDEs.\n\n";
foreach ($r->getConstants() as $name => $value) {
$out .= "const $name = " . var_export($value, true) . ";\n";
}
$out .= "\n";
$functions = $r->getFunctions();
ksort($functions);
foreach ($functions as $f) {
$params = [];
foreach ($f->getParameters() as $p) {
$params[] = ($p->isPassedByReference() ? '&' : '') . ($p->isVariadic() ? '...' : '') . '$' . $p->getName()
. ($p->isOptional() && !$p->isVariadic() ? ' = null' : '');
}
$out .= "/** @return mixed */\nfunction {$f->getName()}(" . implode(', ', $params) . ") {}\n";
}
file_put_contents(__DIR__ . "/../engine/stubs/$file.stub.php", $out);
echo "$file: " . count($functions) . " functions, " . count($r->getConstants()) . " constants\n";
}