简体   繁体   English

IBO的三倍序列如何运作?

[英]How are tripled sequence in IBO working?

I'm analyzing an obfuscated OpenGL application. 我正在分析一个混淆的OpenGL应用程序。 I want to generate a .obj file that describes the multi-polygon model which is displayed in the application. 我想生成一个.obj文件,该文件描述了应用程序中显示的多边形模型。

So I froze the app and dig out the values set in VBO and IBO. 所以我冻结了应用程序并挖掘出VBO和IBO中设置的值。 But the values set in IBO was far more mysterious than what I've expected. 但是,IBO中设定的价值远比我预期的要神秘得多。 The value was 价值是

0, 0, 1, 2, 3, 4, 5, 6, 7, 7, 5, 8, 3, 3, 9, 9, 10, 11, 12, 12, 10, 13, 14, 14, 10, 15, 16, 16, 17, 17, 7, 8, 8, 18, 18, 19, 20, 21, 21, 22, 22, 23, 24, 25, 25, 26, 26, 27, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 36, 37, 38, 38, 36, 39, 34, 34, 40, 40, 40, 41, 42, 43, 44, 44, 45, 45, 46, 47, 48, 49, 49, 50, 50, 51, 52, 52, 53, 53, 54, 55, 55, 56, 56, 57, 58, 58, 59, 59, 60, 61, 62, 62, 63, 63, 63, 64, 65, 66, 67, 64, 68, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 76, 77, 77, 78, 79, 80, 81, 82, 82, 80, 83, 83, 84, 84, 85, 86, 87, 88, 88, 89, 89, 90, 91, 91, 92, 92, 92, 93, 94, 95, 96, 96, 97, 97, 97, 98, 99, 100, 101, 102, 102, 100, 103, 103, 104, 104, 105, 106, 107, 107, 108, 108, 108, 109, 110, 111, 112, 112, 100, 100, 101, 113, 114, 114, ... (length=10495) 0,0,1,2,3,4,5,6,7,7,5,8,3,3,9,9,10,11,12,12,10,13,14,14,10, 15,16,16,17,17,7,8,8,18,18,19,20,21,21,22,22,23,24,25,25,26,26,27,28,29, 29,30,30,31,32,32,33,33,34,35,36,37,38,38,36,39,34,34,40,40,40,41,42,43,44, 44,45,45,46,47,48,49,49,50,50,51,52,52,53,53,54,55,55,56,56,57,58,58,59,59, 60,61,62,62,63,63,63,64,65,66,67,64,68,68,69,69,70,71,72,73,74,75,76,76,77, 77,78,79,80,81,82,82,80,83,83,84,84,85,86,87,88,88,89,89,90,91,91,92,92,92, 93,94,95,96,96,97,97,97,98,99,100,101,102,102,103,103,104,104,105,106,107,107,108,108, 108,109,110,111,112,112,100,100,101,113,114,114,......(长度= 10495)

As you can see indices like 40 , 63 , 92 and 108 are tripled, so setting neither GL_TRIANGLES , GL_TRIANGLE_STRIP , GL_TRIANGLE_FAN , GL_QUADS , GL_QUAD_STRIP nor GL_POLYGON to glDrawElements won't work correctly. 正如你可以看到像指数406392108的两倍,所以设置既不GL_TRIANGLESGL_TRIANGLE_STRIPGL_TRIANGLE_FANGL_QUADSGL_QUAD_STRIP也不GL_POLYGONglDrawElements将无法正常工作。

Are there some kind of advanced techniques to use triple sequenced indices in IBO? 是否有某种先进技术在IBO中使用三重序列指数? What does it mean? 这是什么意思? For what reason is it used for? 它用于什么原因?

Repeated indices like that are indicative of aggressive optimization of triangle strips. 像这样的重复指数表示三角形条带的积极优化。 A repeated index creates degenerate triangles: triangles with zero area. 重复索引创建退化三角形:零区域的三角形。 Since they have no visible area, they are not rendered. 由于它们没有可见区域,因此它们不会被渲染。 They exist so that you can jump from one triangle strip to the next without having to issue another draw command. 它们的存在使您可以从一个三角形条跳到下一个三角形条而不必发出另一个绘制命令。

So a double-index is often used to stitch two strips together. 因此,经常使用双指数将两个条带缝合在一起。 The two triangles it generates will not be rendered. 它生成的两个三角形将不会被渲染。

However, because of the way strips work with the winding order , the facing for the triangles can work out incorrectly. 但是,由于条带处理缠绕顺序的方式 ,三角形的面对可能会错误地解决。 That is, if you stitched two strips together with a double-index, the second strip would start out with the reverse winding order than it desires. 也就是说,如果你用双索引缝合两个条带,第二个条带将以反向缠绕顺序开始,而不是它想要的。

That's where triple indices come in. The third index fixes the winding order for the triangles in the destination strip. 这就是三重索引的来源。第三个索引修正了目标条带中三角形的缠绕顺序。 The three extra triangles it generates will not be rendered. 它生成的三个额外三角形将不会被渲染。

The more modern way to handle multiple strips in the same draw call is to use primitive restart indices . 在同一个绘图调用中处理多个条带的更现代的方法是使用原始重启索引 But the index list as it currently stands is adequate for use with GL_TRIANGLE_STRIP . 但目前的索引列表足以与GL_TRIANGLE_STRIP一起使用。

You can read this strip list and process it into a series of separate triangles (as appropriate for GL_TRIANGLES ) easily enough. 您可以轻松阅读此条带列表并将其处理为一系列单独的三角形(适用于GL_TRIANGLES )。 Simply look at each sequence of 3 vertices, and output that to your triangle buffer, so long as it is not a degenerate triangle. 只需查看3个顶点的每个序列,并将其输出到三角形缓冲区,只要它不是简并三角形即可。 And you'll have to reverse the order of two of the indices for every odd-numbered triangle. 而且你必须颠倒每个奇数三角形的两个指数的顺序。 The code would look something like this: 代码看起来像这样:

const int num_faces = indices.size() - 2;
faces.reserve(num_faces);

for(auto i = 0; i < num_faces; ++i)
{
  Face f(indices[i], indices[i + 1], indices[i + 2]);

  //Don't add any degenerate faces.
  if(!(f[0] == f[1] || f[0] == f[2] || f[1] == f[2]))
  {
    if(i % 2 == 1) //Every odd-numbered face.
      std::swap(f[1], f[2]);

    faces.push_back(f);
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM