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.
68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
/** @noinspection PhpUnused */
|
|
|
|
namespace Cijber\GraphicsToolkit;
|
|
|
|
use Cijber\GraphicsToolkit\Consts\GLConsts;
|
|
use FFI;
|
|
use FFI\CData;
|
|
use RuntimeException;
|
|
|
|
|
|
class GL extends GLConsts {
|
|
public static string $lastCall;
|
|
public static FFI $ffi;
|
|
|
|
/**
|
|
* @var array|callable[]
|
|
*/
|
|
public static array $calls;
|
|
|
|
/**
|
|
* @GLIgnore
|
|
*/
|
|
public static function init() {
|
|
static::$ffi = FFI::load(__DIR__ . "/../headers/gl_generated.h");
|
|
include_once __DIR__ . "/gl_functions.php";
|
|
}
|
|
|
|
/**
|
|
* @GLIgnore
|
|
*/
|
|
public static function getProcAddress($name): CData {
|
|
$funcname = 'gl' . ucfirst($name);
|
|
$typename = 'FUNC_' . $funcname;
|
|
|
|
$funcstring = static::$ffi->new(FFI::arrayType(static::$ffi->type('GLubyte'), [strlen($funcname) + 1]));
|
|
FFI::memcpy($funcstring, $funcname, strlen($funcname));
|
|
$funcstring[strlen($funcname)] = "\0";
|
|
|
|
/** @var CData $proc */
|
|
/** @noinspection PhpUndefinedMethodInspection */
|
|
$proc = static::$ffi->glXGetProcAddress(
|
|
static::$ffi->cast("GLubyte*", $funcstring)
|
|
);
|
|
|
|
/** @noinspection PhpUndefinedMethodInspection */
|
|
if ($proc === null || FFI::isNull($proc)) {
|
|
throw new RuntimeException("GL function $name doesn't exist");
|
|
}
|
|
|
|
return static::$ffi->cast($typename, $proc);
|
|
}
|
|
|
|
public static function shaderSource(int $shader, array $sources) {
|
|
$lens = [];
|
|
$strings = [];
|
|
foreach ($sources as $source) {
|
|
$strings[] = Utils::string($source, false);
|
|
$lens[] = strlen($source);
|
|
}
|
|
|
|
$arrays = Utils::arrayOf('char*', $strings);
|
|
$lengths = Utils::arrayOf('int32_t', $lens);
|
|
|
|
glShaderSource($shader, count($sources), $arrays, $lengths);
|
|
}
|
|
}
|