Opengl 第一个索引参数在给定给glmultidraurementsindirect的命令结构中意味着什么?
我不明白这个命令结构是如何工作的。除了firstIndex之外,所有这些似乎都有意义(在文档中;我还没有实际调用该函数)。事实上,在我看来,文档中似乎有输入错误 以下是我在查找相关文档的每个地方看到的文本: 间接法处理的参数被封装到一个结构中,该结构采用以下形式(在C中): 假设不对以下对象生成错误,则对GLMultiDrawerElementsInDirect的单个调用是等效的:Opengl 第一个索引参数在给定给glmultidraurementsindirect的命令结构中意味着什么?,opengl,Opengl,我不明白这个命令结构是如何工作的。除了firstIndex之外,所有这些似乎都有意义(在文档中;我还没有实际调用该函数)。事实上,在我看来,文档中似乎有输入错误 以下是我在查找相关文档的每个地方看到的文本: 间接法处理的参数被封装到一个结构中,该结构采用以下形式(在C中): 假设不对以下对象生成错误,则对GLMultiDrawerElementsInDirect的单个调用是等效的: GLsizei n; for (n = 0; n < drawcount; n++) { const
GLsizei n;
for (n = 0; n < drawcount; n++) {
const DrawElementsIndirectCommand *cmd;
if (stride != 0) {
cmd = (const DrawElementsIndirectCommand *)((uintptr)indirect + n * stride);
} else {
cmd = (const DrawElementsIndirectCommand *)indirect + n;
}
glDrawElementsInstancedBaseVertexBaseInstance(mode,
cmd->count,
type,
cmd->firstIndex + size-of-type,
cmd->instanceCount,
cmd->baseVertex,
cmd->baseInstance);
}
glsizein;
对于(n=0;ncount,
类型,
cmd->firstIndex+类型大小,
cmd->instanceCount,
cmd->baseVertex,
cmd->baseInstance);
}
但这些页面并没有说明“类型大小”的含义,也没有说明为什么它被添加到firstIndex,而不是说,乘以它。似乎GlDrawerElementsInstancedBaseVertexBaseInstance在那里有一个字节偏移量,所以我认为firstIndex是顶点索引的GL_元素数组缓冲区数组中的索引——索引的索引——类型的大小是顶点索引(比如4)的字节大小,需要在那里进行转换将“索引到索引数组”转换为该数组的字节偏移量
但是…这种转换可以表示为乘法,他们说+不是*:(
我说得对吗?firstIndex是顶点索引数组中一个条目的索引,键入的大小是顶点索引的字节大小,还有+a输入错误吗?如果不是,我缺少什么?这只是中的一个输入错误。虽然手册页在官方网站上,但它们不是官方文档。它们经常包含错误或OMISI奥斯 官方文档是规范文档。它确实有一个乘法而不是加法。OpenGL 4.5规范第353/354页: 命令 相当于 因此,
firstIndex
与您已经猜到的差不多。它是索引缓冲区(又称元素数组缓冲区)中的偏移量,非常类似于glpaurements()
的最后一个元素。唯一的细微之处是,在这种情况下,偏移量是以索引为单位测量的,而对于glpaurements()
它是以字节为单位测量的。这就是类型的大小的乘法
例如,假设您有一个元素数组缓冲区,其中包含类型为
GL\u UNSIGNED\u SHORT
的索引。您希望draw命令从第50个索引开始使用此缓冲区中的索引。对于glpaurements()
,您将为最后一个参数传入100,因为偏移量以字节为单位,每个索引为两个字节,您将使用50,因为它是在索引中测量的。与规范中类型的大小相乘(在本例中为2)说明了这一差异,即如果将firstIndex
设置为50,字节偏移量将为100,因此匹配用于gldrawerelements()的偏移量
我正在查看规范,但没有看到firstIndex和类型大小的实际含义……好吧,我想我会打电话看看会发生什么。@mjwach:如果有GL\u UNSIGNED\u INT
索引,类型大小将是4;如果有GL\u UNSIGNED\u SHORT
索引,类型大小将是2;如果有GL\u UNSIGNED\u BYTE
I,类型大小将是1ndices(提示:不要这样做,硬件不喜欢8位顶点索引)。@mjwach我补充了一些关于该值含义的解释。听起来你已经找到了该部分。
GLsizei n;
for (n = 0; n < drawcount; n++) {
const DrawElementsIndirectCommand *cmd;
if (stride != 0) {
cmd = (const DrawElementsIndirectCommand *)((uintptr)indirect + n * stride);
} else {
cmd = (const DrawElementsIndirectCommand *)indirect + n;
}
glDrawElementsInstancedBaseVertexBaseInstance(mode,
cmd->count,
type,
cmd->firstIndex + size-of-type,
cmd->instanceCount,
cmd->baseVertex,
cmd->baseInstance);
}
void DrawElementsIndirect( enum mode, enum type, const void *indirect );
typedef struct {
uint count;
uint instanceCount;
uint firstIndex;
int baseVertex;
uint baseInstance;
} DrawElementsIndirectCommand;
if (no element array buffer is bound) {
generate appropriate error
} else {
DrawElementsIndirectCommand *cmd =
(DrawElementsIndirectCommand *)indirect;
DrawElementsInstancedBaseVertexBaseInstance(mode,
cmd->count, type,
cmd->firstIndex * size-of-type,
cmd->instanceCount, cmd->baseVertex,
cmd->baseInstance);
}