有人会关心解释VertexBuffer,VertexArray,VertexBufferObject和VertexArrayObject之间的区别吗?我甚至不确定这些是否是针对不同事物的所有术语,但我已经看到它们都出现在OpenGL规范中.
我知道VertexBuffer只包含顶点而没有其他任何东西,一旦绑定,一旦我设置了顶点指针,我就可以使用DrawArrays来绘制它.我已经多次这样做了.
我正在使用我认为的VertexArray,它存储所设置的任何顶点缓冲区的状态,以及任何顶点指针.绑定VertexArray会自动绑定顶点缓冲区并设置顶点指针.我也成功地使用了这个(大部分).
但什么是VertexBufferObject和VertexArrayObject?他们更好吗?VertexArray不能给我我需要的一切吗?
目前正在使用C#开发3D媒体引擎,我遇到了一个小难题.我找到了我的rending循环,我有一个很棒的插件架构和内容管理系统,甚至还有一个计划好的材料管道.然后引擎计划使用DirectX和OpenGL(通过'渲染器'插件),以及两个API的可编程管线.
无论如何,在本周初,我开始研究用于处理顶点的引擎抽象层(我现在已经担心这几周了).正如你们中的一些人所知,图形API之间的顶点处理并不完全相关或相同.好吧有点相关;),但不一样.在OpenGL处理中,顶点非常简单,您可以创建自定义顶点结构,将其发送到GPU,然后让着色器处理其余部分.这对于灵活的图形管线是完美的,OpenGL不需要知道每个顶点包含哪些元素.另一方面,DirectX需要我们为每个顶点结构创建声明,然后将它们发送到GPU.
问题是我不知道传递了什么类型的顶点结构,我肯定希望避免创建抽象层,该抽象层涉及通过枚举和一些抽象的"VertexDeclaration"类声明顶点的每个元素; 这会导致一些问题:
1)获得顶点元素至少可以说是一种痛苦.我可以使用一些'VertexSemantic'并询问顶点'a - z'的位置,但是当处理像骨骼动画这样的顶点时,它会有很多开销.
2)考虑到发动机的主要焦点是"新手",不是非常人性化.我希望用户能够创建自定义顶点和网格缓冲区,而不必声明大量对象,消耗宝贵的开发时间.
3)更多?
现在,我可以使用属性执行某些操作,然后在DirectX渲染器内创建顶点结构的声明.例如,继续创建一些枚举:
// for getting the format layout of the element
public enum ElementFormat
{
Float, Float2, Float3, Byte, etc, etc
}
// for determining the 'usage'
// (here is 'another' where DirectX limits vertex structures ><)
public enum ElementUsage
{
Position, Normal, Color, TextureCoord, etc, etc
}
Run Code Online (Sandbox Code Playgroud)
现在我可以创建一个用户可以应用于顶点结构中每个元素的"字段"的属性:
public class VertexElementAttribute : Attribute
{
#region Properties
/// <summary>
/// Gets the total size (in bytes) of the element.
/// </summary>
public …
Run Code Online (Sandbox Code Playgroud) 我有数据帧
test <- structure(list(
y2002 = c("freshman","freshman","freshman","sophomore","sophomore","senior"),
y2003 = c("freshman","junior","junior","sophomore","sophomore","senior"),
y2004 = c("junior","sophomore","sophomore","senior","senior",NA),
y2005 = c("senior","senior","senior",NA, NA, NA)),
.Names = c("2002","2003","2004","2005"),
row.names = c(c(1:6)),
class = "data.frame")
> test
2002 2003 2004 2005
1 freshman freshman junior senior
2 freshman junior sophomore senior
3 freshman junior sophomore senior
4 sophomore sophomore senior <NA>
5 sophomore sophomore senior <NA>
6 senior senior <NA> <NA>
Run Code Online (Sandbox Code Playgroud)
我需要创建一个顶点/边缘列表(用于igraph),每次学生类别连续几年变化,而忽略没有变化,如
testvertices <- structure(list(
vertex =
c("freshman","junior", "freshman","junior","sophomore","freshman",
"junior","sophomore","sophomore","sophomore"),
edge =
c("junior","senior","junior","sophomore","senior","junior",
"sophomore","senior","senior","senior"),
id =
c("1","1","2","2","2","3","3","3","4","5")),
.Names …
Run Code Online (Sandbox Code Playgroud) 对于每个属性,使用跨步顶点缓冲区与紧密打包缓冲区有什么优缺点?我的意思是例如:
步幅: xyzrgb xyzrgb xyzrgb
紧: xyzxyzxyz rgbrgbrgb
乍一看,您看起来很容易在使用跨步时更改大小,但是当您使用进行重新分配时,顶点缓冲区的内容将被删除glBufferData()
。
对我来说,最好使用紧密模型,因为位置,颜色和texcoords可能来自本地内存中的不同数组,并且因为没有跨步缓冲区数据函数;您必须在上传之前将所有数组复制到交错缓冲区中,或者glBufferSubData()
每个属性每个顶点使用一个(我猜这是一个糟糕的主意)。
似乎通常使用交错缓冲区(步幅)。这是为什么?我在这里想念什么吗?