私は何かが欠けています。UBO バッファーのセットアップに成功しました。データをバッファにmemcpyした後、すべてが問題なく機能します。コードをクリーンアップするために、memcpy とバッファリングを行う関数を作成しようとしています。私の関数は次のようになります。
void bufferUBOData(const GLuint uboIndex)
{
auto uboSize = sizeRegistry.find(uboIndex)->second;
auto buffer = bufferRegistry.find(uboIndex)->second;
glBufferData(GL_UNIFORM_BUFFER, uboSize, buffer, GL_DYNAMIC_DRAW);
}
template<typename T, typename... Args>
void bufferUBOData(const GLuint uboIndex, T data, Args... args)
{
auto buffer = bufferRegistry.find(uboIndex)->second;
auto size = std::get<1>(dataRegistry.find(uboIndex)->second);
auto offset = std::get<2>(dataRegistry.find(uboIndex)->second);
auto type = std::get<3>(dataRegistry.find(uboIndex)->second);
const int index = sizeof...(args);
memcpy(buffer + offset[index], &data, size[index] * TypeSize(type[index]));
bufferUBOData(uboIndex, args...);
}
コードを実装するには、次のことを行いました。
//memcpy(buffer + offset[Scale], &scale, size[Scale] * TypeSize(type[Scale]));
//memcpy(buffer + offset[Translation], &translation, size[Translation] * TypeSize(type[Translation]));
//memcpy(buffer + offset[Rotation], &rotation, size[Rotation] * TypeSize(type[Rotation]));
//memcpy(buffer + offset[Enabled], &enabled, size[Enabled] * TypeSize(type[Enabled]));
//glBufferData(GL_UNIFORM_BUFFER, uboSize, buffer, GL_DYNAMIC_DRAW);
bufferUBOData(uboIndex, enabled, rotation, translation, scale);
すべてがコンパイルされます。上記のコード セクションで、memcpy および glBufferData 呼び出しのコメントを外し、bufferUBOData 呼び出しをコメント アウトすると、すべてが機能します。ただし、示されている例では、空白の画面 (ジオメトリなし) がレンダリングされます。
注: bufferUBOData 関数を使用するときは、引数を逆の順序で配置します。
編集: 役に立たない while ループを削除 --> sizeof...() に関するヒントをくれた DyP に感謝