Opengl顶点属性stride [英] Opengl Vertex attribute stride

查看:713
本文介绍了Opengl顶点属性stride的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿。
我最新的OpenGL ES,但我有我的经验与正常的OpenGL。
我被告知,使用隔行数组的顶点缓冲区是快得多,因为优化避免缓存缺失。

我开发了一个顶点格式,我会使用它像这样

 
struct SVertex
{
float x,y,z;
float nx,ny,nz;
float tx,ty,tz;
float bx,by,bz;
float tu1,tv1;
float tu2,tv2;
};然后我使用了glVertexAttribPointer(index,3,GL_FLOAT,GL_FALSE,stride,v);b。指向顶点数组。索引是我想使用的属性之一,除了步幅,一切都是确定。它的工作之前,我决定将这添加到方程。我通过了stride两个作为sizeof(SVertex)和像13 * 4,但没有一个似乎工作。

如果它有任何重要性,我画这样的原始像

 glDrawElements(GL_TRIANGLES ,surface-> GetIndexCount()/ 3,GL_UNSIGNED_INT,surface-> IndPtr()); 


在OpenGL规范中写道,stride应该是以字节为单位的大小属性(在这种情况下为z)到同一类型的下一个属性(在这种情况下为x)。所以通过我的计算,这应该是13(nx,ny,nz,tx,ty .... tuv2,tv2)乘以4(浮动大小)。

哦,还有一件事是,显示为空。

任何人都可以帮我解决这个问题吗?

非常感谢。

解决方案

如果你有这样的结构,那么 stride 只是 sizeof SVertex 每个属性相同。这里没有什么复杂的。



如果这不起作用,请在其他地方寻找您的错误。



例如:



surface-> GetIndexCount()/ 3



这个参数应该是顶点数,而不是原始数 被发送的数量 - 因此我会说这个除以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顶点属性stride的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆