我将代码从 DisplayLists 更改为 VBO/VAO。但是当我运行应用程序时它崩溃了。
它在第一次尝试绘制 VAO 时崩溃。我不使用着色器进行绘制(所以它不会引起问题)。
一个 VAO 中最多有 12 个面(12 * 3 个顶点)以及这些面的纹理坐标。有多达 500 000 个 VAO。
我如何创建一张脸:
tData.add(new float[]{textureX + 0.1249f, textureY+ 0.1249f});
vData.add(new float[]{x, y, z});
tData.add(new float[]{textureX+ 0.1249f, textureY+0.0001f});
vData.add(new float[]{x, y+1, z+1});
tData.add(new float[]{textureX+0.0001f, textureY+0.0001f});
vData.add(new float[]{x+1, y+1, z+1});
创建 VBO/VAO:
if(vData.isEmpty())
return;
int vaoHandle = glGenVertexArrays();
glBindVertexArray(vaoHandle);
int vertexDataSize = vData.size() * 3;
int textureDataSize = tData.size() * 2;
FloatBuffer vertexData = BufferUtils.createFloatBuffer(vData.size() * 3);
FloatBuffer textureData = BufferUtils.createFloatBuffer(tData.size() * 2);
while(!vData.isEmpty())
{
vertexData.put(vData.remove(0));
}
while(!tData.isEmpty())
{
textureData.put(tData.remove(0));
}
vertexData.flip();
textureData.flip();
int vertexHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vertexHandle);
glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
glVertexAttribPointer(0, vertexDataSize, GL_FLOAT, false, 0, 0);
int textureHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, textureHandle);
glBufferData(GL_ARRAY_BUFFER, textureData, GL_STATIC_DRAW);
glVertexAttribPointer(1, textureDataSize, GL_FLOAT, false, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
renderEngine.vaos.add(new VAO(vaoHandle, (int)((float)vertexDataSize / 3f)));
渲染 VBO / VAO:
glUseProgram(0);//TODO:REMOVE
for(VAO vao : vaos)
{
glBindVertexArray(vao.getHandle());
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
System.out.println(vao.getVertices());//correct numeber
glDrawArrays(GL_TRIANGLES, 0, vao.getVertices());//<-- CRASH at first time called
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(0);
}
glBindVertexArray(0);
这是错误:
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000000b3fb610, pid=7736, tid=6224
#
# JRE version: Java(TM) SE Runtime Environment (8.0_20-b26) (build 1.8.0_20-b26)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.20-b23 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [ig75icd64.dll+0x8b610]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Geosearchef\workspaces\workspaceLWJGL\OrangeJuiceVBO\hs_err_pid7736.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
我认为在这里发布整个错误是没有意义的。你知道为什么会这样吗?我找不到有关 VBO 的此错误的任何信息。