osg3.6(准确版本没有考证)开始引入了间接绘制。对应的opengl接口为:glMultiDrawElementsIndirect() ;
在例子Examples osgsimpleMDI中有对应的代码。
接口原形:
void glMultiDrawElementsIndirect(GLenum mode, GLenum type, const void* indirect, GLsizei drawcount, GLsizei stride);
相较于glDrawElements(),普通的绘制命令,间接绘制只需要提交一次drawcall,减少cpu的消耗,从而达到提高效率的效果。
osg的间接绘制也需要绘制单元:
struct DrawCmd
{
GLuint count;
GLuint instanceCount;
GLuint firstIndex;
GLint baseVertex;
GLuint baseInstance;
};
一个DrawCmd代表一个绘制单元,
count:索引个数
instanceCount:实例总数(一般情况下为1)
firstIndex:该单元的第一索引位置(单元的索引偏移量)
baseVertex:单元顶点总数
baseInstance:实例化的偏移量