c++ - 在 OpenGL4.0 中使用交错属性数组提高性能

标签 c++ performance opengl opengl-4

我使用 OpenGL4.X。最近我阅读了 this Apple OpenGLES2 文档,其中指出使用交错属性数组可以提高 IOS 移动设备上的性能,并且是推荐的方法(而不是使用属性 block )。

对于那些不明白我意思的人,这里有一个例子:

单个属性数组中的属性 block :

 float vertices[]{
 //Triangle vertices:

  v0x , v0y , v0z ,
  v1x , v1y , v1z ,
  v2x , v2y , v2z ,

  //Triangle UVs:

  uv0s , uv0t ,
  uv1s , uv1t ,
  uv2s , uv2t ,

  //Triangle Normals:
  n0x , n0y , n0z ,
  n1x , n1y , n1z ,
  n2x , n2y , n2z 

}

交错属性数组:

 float vertices[]{


  v0x , v0y , v0z ,
  uv0s , uv0t ,          ////vertex 1 attributes
  n0x , n0y , n0z ,

  v1x , v1y , v1z ,
  uv1s , uv1t ,         ///vertex 2 attributes
  n1x , n1y , n1z ,

  v2x , v2y , v2z ,
  uv2s , uv2t ,         ///vertex 3 attributes
  n2x , n2y , n2z 

}

所以我的问题是:在桌面 GPU 上运行的 OpenGL 是否也是如此?如果是,那么理论上性能增益有多大?

最佳答案

Is it also true for OpenGL running on desktop GPUs ?

来自 Vertex specification wiki page :

As a general rule, you should use interleaved attributes wherever possible. Obviously if you need to change certain attributes and not others, then interleaving the ones that change with those that don't is not a good idea.


how big the performance gain can theoretically be ?

我真的无法回答这个问题,但我不希望有很大的改进。唯一确定的方法是测量。

关于c++ - 在 OpenGL4.0 中使用交错属性数组提高性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14874914/

相关文章:

c++ - 如何初始化数组 vector

java - 在基于 3d 网格的环境中对电线进行编程的最有效方法是什么?

opengl - 法线贴图光照根据方向不同

c++ - 纹理图像未正确映射

c++ - 使用帧缓冲区进行高斯模糊 2 pass

c++ - ffmpeg:如何将 h264 原始数据保存为 mp4 文件

c++ - Lua 函数什么都不做

sql-server - WHERE 子句中的列顺序重要吗?

performance - HTTP 代理使用的协议(protocol)是否减少了客户端协商的连接数?

c++ - 为什么 QFileDialog::getOpenFileName 不起作用?