所以我正在组合一个高度图渲染器,它将在顶点着色器中完成大部分工作,但首先我当然会生成一个要渲染的网格,目前我正在使用 openGL 和 C++ 的上限来查看我可以渲染的网格有多密集(所以我后来在 LoD 网格划分方面有一些事情要做)
反正!切入问题;
我在测试 32、64 和 128 的 meshResolution 后注意到的问题我遇到了运行时崩溃,我使用自制的类“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);
}