glShaderSource
接受一个字符数组的数组,以及这些字符数组的长度数组。
我使用“字符数组”是因为它们绝对不是 D 字符串(又名immutable(char)[]
s,它本身是一个指针和长度的元组),它们也不是 C 字符串(必须以空值结尾;size 参数让你否则做)。
现在,您可以使用 将 D 字符串转换为 C 字符串toStringz
,但这会进行不必要的分配。您可以改为直接传递 D 字符串中的数据:
// Get the pointer to the shader source data, and put it in a 1-sized fixed array
const(char)*[1] shaderStrings = [vertexShaderSource.ptr];
// Same but with shader source length
GLint[1] shaderSizes = [vertexShaderSource.length];
// Pass arrays to glShaderSource
glShaderSource(vertexShaderID, shaderStrings.length, shaderStrings.ptr, shaderSizes.ptr);