我們的應用程序崩潰..Nvidia的老司機,調用glDrawArrays異常訪問衝突舊的Nvidia驅動程序
調試代碼here
放眼望去,here他們說,這往往是由於不正確的頂點屬性設置
這是怎麼設置我的VBO和維羅:
/**
* Init Vbo/vao.
*/
float[] vertexData = new float[]{
0, 0,
1, 0,
1, 1};
debugVbo = new int[1];
gl3.glGenBuffers(1, debugVbo, 0);
gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, debugVbo[0]);
{
FloatBuffer buffer = GLBuffers.newDirectFloatBuffer(vertexData);
gl3.glBufferData(GL3.GL_ARRAY_BUFFER, vertexData.length * Float.BYTES, buffer, GL3.GL_STATIC_DRAW);
}
gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
debugVao = new int[1];
gl3.glGenVertexArrays(1, debugVao, 0);
gl3.glBindVertexArray(debugVao[0]);
{
gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, debugVbo[0]);
{
gl3.glEnableVertexAttribArray(0);
{
gl3.glVertexAttribPointer(0, 2, GL3.GL_FLOAT, false, 0, 0);
}
}
gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
}
gl3.glBindVertexArray(0);
}
這就是我的呈現方式:
public static void render(GL3 gl3) {
gl3.glClear(GL3.GL_DEPTH_BUFFER_BIT | GL3.GL_COLOR_BUFFER_BIT);
gl3.glUseProgram(textureProgram);
{
gl3.glBindVertexArray(debugVao[0]);
{
gl3.glActiveTexture(GL3.GL_TEXTURE0);
gl3.glBindTexture(GL3.GL_TEXTURE_2D, texture[0]);
gl3.glBindSampler(0, EC_Samplers.pool[EC_Samplers.Id.clampToEdge_nearest_0maxAn.ordinal()]);
{
gl3.glDrawArrays(GL3.GL_TRIANGLES, 0, 3);
}
gl3.glBindTexture(GL3.GL_TEXTURE_2D, 0);
gl3.glBindSampler(0, 0);
}
gl3.glBindVertexArray(0);
}
gl3.glUseProgram(0);
}
這是我的VS:
#version 330
layout (location = 0) in vec2 position;
uniform mat4 modelToCameraMatrix;
uniform mat4 cameraToClipMatrix;
out vec2 fragmentUV;
void main()
{
gl_Position = cameraToClipMatrix * modelToCameraMatrix * vec4(position, 0, 1);
fragmentUV = position;
}
我的FS:
#version 330
in vec2 fragmentUV;
out vec4 outputColor;
uniform sampler2D textureNode;
void main()
{
outputColor = texture(textureNode, fragmentUV);
}
我讀和重讀,因爲現在2天相同的代碼,我無法找到任何東西錯誤。 我也試着定義一個2 * 4 = 8的步幅,但是結果相同..
到目前爲止,您的代碼看起來正確,但我建議您使用glGetError調用(每個常規OpenGL調用後調用它)看看它究竟在哪裏失敗。有些奇怪的事情正在發生。另外對於快速測試,我建議你在* drawing *代碼中設置一個完整的頂點attrib指針,而不是依賴於VAO;如果這樣的話,你知道VAO正在發生什麼。 – datenwolf
嘗試完整的頂點attrib指針設置。我會嘗試glGetError噴塗,謝謝 – elect
誰-1ed,你介意解釋嗎? – elect