问题描述
嘿.我是 OpenGL ES 的新手,但我对普通的 OpenGL 有一些经验.有人告诉我,由于避免缓存未命中的优化,对顶点缓冲区使用交错数组要快得多.
我开发了一种我将使用的顶点格式,如下所示
然后我使用glVertexAttribPointer(index,3,GL_FLOAT,GL_FALSE,stride,v);"指向顶点数组.索引是我想要使用的属性之一,除了步幅之外,其他一切都很好.在我决定将其添加到等式之前,它起作用了.我以 sizeof(SVertex) 和 13*4 的形式通过了跨步,但它们似乎都不起作用.
如果它有任何重要性,我会绘制这样的图元
glDrawElements(GL_TRIANGLES,surface->GetIndexCount()/3,GL_UNSIGNED_INT,surface->IndPtr());
在 OpenGL 规范中写到,步幅应该是从属性末尾(在本例中为 z)到下一个同类属性(在本例中为 x)的大小(以字节为单位).所以根据我的计算,这应该是 13(nx,ny,nz,tx,ty....tuv2,tv2) 乘以 4(浮点数的大小).
哦,还有一件事是显示器只是空的.
有人可以帮我解决这个问题吗?
非常感谢.
如果你有这样的结构,那么 stride
就是 sizeof SVertex
并且对于每个属性.这里没有什么复杂的.
如果这不起作用,请在其他地方查找您的错误.
例如这里:
surface->GetIndexCount()/3
这个参数应该是要发送的顶点数,而不是基元数 - 因此我会说这个除以三是错误的.保留为:
surface->GetIndexCount()
Hey.
I new to OpenGL ES but I've had my share of experience with normal OpenGL.
I've been told that using interlaced arrays for the vertex buffers is a lot faster due to the optimisation for avoiding cache misses.
I've developed a vertex format that I will use that looks like this
struct SVertex { float x,y,z; float nx,ny,nz; float tx,ty,tz; float bx,by,bz; float tu1,tv1; float tu2,tv2; };
Then I used "glVertexAttribPointer(index,3,GL_FLOAT,GL_FALSE,stride,v);" to point to the vertex array. The index is the one of the attribute I want to use and everything else is ok except the stride. It worked before I decided to add this into the equation. I passed the stride both as sizeof(SVertex) and like 13*4 but none of them seem to work.
If it has any importance I draw the primitives like this
glDrawElements(GL_TRIANGLES,surface->GetIndexCount()/3,GL_UNSIGNED_INT,surface->IndPtr());
In the OpenGL specs it's written that the stride should be the size in bytes from the end of the attribute( in this case z) to the next attribute of the same kind(in this case x). So by my calculations this should be 13(nx,ny,nz,tx,ty....tuv2,tv2) times 4 (the size of a float).
Oh and one more thing is that the display is just empty.
Could anyone please help me with this?
Thanks a lot.
If you have a structure like this, then stride
is just sizeof SVertex
and it's the same for every attribute. There's nothing complicated here.
If this didn't work, look for your error somewhere else.
For example here:
surface->GetIndexCount()/3
This parameter should be the number of vertices, not primitives to be sent - hence I'd say that this division by three is wrong. Leave it as:
surface->GetIndexCount()
这篇关于Opengl顶点属性步幅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!