C++OpenGL大型网格缺少三角形
C++ OpenGL Large Mesh is missing triangles
所以我正在组装一个高度贴图渲染器,它将在顶点着色器中完成大部分工作,但首先我当然会生成一个要渲染的网格,现在我正在玩openGL和C++的上限,看看我能渲染多密集的网格(所以我以后在LoD网格划分方面有一些参考)
无论如何切入问题;
在测试32、64的meshResolution后,我注意到了一个问题,在128时,我遇到了运行时崩溃,我通过使用自制的类"indexFace"来阻止它们,该类包含6个索引以降低数组长度,问题是在128分辨率时,只有三分之一的网格实际显示,我想知道openGL使用一组BufferObjects可以呈现或保存的索引数量是否有限制,或者这是否是我处理C++方面的问题。
我通过以下方式生成网格:
void HeightMapMesh::GenerateMesh(GLfloat meshScale, GLushort meshResolution)
{
GLushort vertexCount = (meshResolution + 1) * (meshResolution + 1);
Vertex_Texture* vertexData = new Vertex_Texture[vertexCount];
GLushort indexCount = (meshResolution * meshResolution) * 6;
//indexFace holds 6 GLushort's in an attempt to overcome the array size limit
indexFace* indexData = new indexFace[meshResolution * meshResolution];
GLfloat scalar = meshScale / ((GLfloat)meshResolution);
GLfloat posX = 0;
GLfloat posY = 0;
for (int x = 0; x <= meshResolution; x++)
{
posX = ((GLfloat)x) * scalar;
for (int y = 0; y <= meshResolution; y++)
{
posY = ((GLfloat)y) * scalar;
vertexData[y + (x * (meshResolution + 1))] = Vertex_Texture(posX, posY, 0.0f, x, y);
}
}
GLint indexPosition;
GLint TL, TR, BL, BR;
for (int x = 0; x < meshResolution; x++)
{
for (int y = 0; y < meshResolution; y++)
{
indexPosition = (y + (x * (meshResolution)));
BL = y + (x * (meshResolution + 1));
TL = y + 1 + (x * (meshResolution + 1));
BR = y + ((x + 1) * (meshResolution + 1));
TR = y + 1 + ((x + 1) * (meshResolution + 1));
indexData[indexPosition] = indexFace(
BL, TR, TL,
BL, BR, TR
);
}
}
mesh.Fill(vertexData, vertexCount, (void *)indexData, indexCount, GL_STATIC_DRAW, GL_STATIC_DRAW);
delete [] vertexData;
delete [] indexData;
}
//This is for mesh.Fill()
void Fill(T* vertData, GLushort vertCount, void* indData, GLushort indCount, GLenum vertUsage, GLenum indUsage)
{
indexCount = indCount;
vertexCount = vertCount;
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObjectID);
glBufferData(GL_ARRAY_BUFFER, sizeof(T) * vertexCount, vertData, vertUsage);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indexCount, indData, indUsage);
}
这是因为你做空了指数。
例如:对于meshResolution
,GLushort indexCount = (meshResolution * meshResolution) * 6;
正在以105的值命中USHRT_MAX。(105*105*6=66150>65535)
使用int作为索引。因此,将各处的索引更改为无符号整数,并进行最后的绘图调用,如下所示:
glDrawElements( GL_QUADS, indCount, GL_UNSIGNED_INT, indices); //do this
//glDrawElements( GL_QUADS, indCount, GL_UNSIGNED_SHORT, indices); //instead of this
//also GL_QUADS is deprecated but it seems your data is in that format so I left it that way
如果你画GL_TRIANGLE_STRIP
s,你可以保存一堆索引,或者更好地在GPU上进行镶嵌,因为这是它的完美用例。
相关文章:
- 使用对象文件读取三角形数据网格
- 如何从 3D 曲面网格中删除自相交三角形?
- 如何计算具有三角形面的网格的质心?
- 在开放网格中计算三角形的面积
- 三角形网格上的CGAL插值被卡住
- 使用 #CGAL 的 2D 网格的三角形角度
- 重建三角形网格中的所有边
- 如何累积三维三角形网格的边?用c语言计算网格边的算法
- 3D模型文件并从中创建三角形网格
- PhysX地形-Heightfield vs三角形网格
- 如何在现代 OpenGl 中选择网格的顶点或三角形(上面的 3.3)
- 变换反馈丢失了三角形网格的顺序
- 网格三角形上的复杂OpenMP并行化
- 从三角形网格中查找面
- Tetgen:从曲面的给定三角形开始,在不改变曲面连接性的情况下创建新网格
- C++OpenGL大型网格缺少三角形
- 尝试渲染三角形网格(c++)时崩溃
- 三角形网格和粒子的八叉树实现
- 计算三角形网格中的法线
- 使用 kinect 从点云生成三角形网格的算法