我从OpenGL学习了方法glMultiDrawArraysIndirect(),我想用JOGL调用这个方法。在示例代码中,使用C ++结构,并使用glMapBufferRange()将该结构中的数据存储在缓冲区中。我想知道JOGL是如何失败的?如果有任何例子,那就太棒了。
以下是使用OpenGL的示例代码:
struct DrawArraysIndirectCommand
{
GLuint count;
GLuint primCount;
GLuint first;
GLuint baseInstance;
};
load_shaders();
object.load("media/objects/asteroids.sbm");
glGenBuffers(1, &indirect_draw_buffer);
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indirect_draw_buffer);
glBufferData(GL_DRAW_INDIRECT_BUFFER,
NUM_DRAWS * sizeof(DrawArraysIndirectCommand),
NULL,
GL_STATIC_DRAW);
DrawArraysIndirectCommand * cmd = (DrawArraysIndirectCommand *)
glMapBufferRange(GL_DRAW_INDIRECT_BUFFER,
0,
NUM_DRAWS * sizeof(DrawArraysIndirectCommand),
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
for (i = 0; i < NUM_DRAWS; i++)
{
object.get_sub_object_info(i % object.get_sub_object_count(),
cmd[i].first,
cmd[i].count);
cmd[i].primCount = 1;
cmd[i].baseInstance = i;
}
glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER);
答案 0 :(得分:1)
你可以看到结构只是一个接一个4个胶合,你需要模仿:
ByteBuffer cmd = gl.glMapBufferRange(GL_DRAW_INDIRECT_BUFFER,
0,
NUM_DRAWS * 4 * 4,
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
for (int i = 0; i < NUM_DRAWS; i++)
{
int first = object.get_sub_object_info_first(i % object.get_sub_object_count());
int count = object.get_sub_object_info_count(i % object.get_sub_object_count());
int primCount = 1;
int baseInstance = i;
cmd.putInt(count);
cmd.putInt(primCount);
cmd.putInt(first);
cmd.putInt(basInstance);
}