Nvidia旧驱动程序,glDrawArrays异常访问冲突

时间:2015-10-14 09:15:31

标签: opengl exception vertex-buffer vertex-attributes vertex-array-object

我们的应用程序崩溃了旧的Nvidia驱动程序..

调试代码为here

环顾四周,here他们说这通常是由于顶点属性设置不正确

这就是我设置vbo和vao的方式:

        /**
         * 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的步幅,但结果相同..

1 个答案:

答案 0 :(得分:1)

我无法相信。

问题在其他地方撒谎,我正在初始化我的采样器

public static void init(GL3 gl3) {

    pool = new int[Id.size.ordinal()];

    gl3.glGenSamplers(Id.size.ordinal(), pool, 0);

    gl3.glSamplerParameteri(pool[Id.clampToEdge_nearest_0maxAn.ordinal()],
            GL3.GL_TEXTURE_WRAP_S, GL3.GL_CLAMP_TO_EDGE);
    gl3.glSamplerParameteri(pool[Id.clampToEdge_nearest_0maxAn.ordinal()],
            GL3.GL_TEXTURE_WRAP_T, GL3.GL_CLAMP_TO_EDGE);
    gl3.glSamplerParameteri(pool[Id.clampToEdge_nearest_0maxAn.ordinal()],
            GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_NEAREST);
    gl3.glSamplerParameteri(pool[Id.clampToEdge_nearest_0maxAn.ordinal()],
            GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_NEAREST);
    gl3.glSamplerParameteri(pool[Id.clampToEdge_nearest_0maxAn.ordinal()],
            GL3.GL_TEXTURE_MAX_ANISOTROPY_EXT, 0);
}

崩溃是由于将最大各向异性设置为0 ... 1解决了崩溃...

Ps:glSamplerParameterf代替glSamplerParameteri,因为它是一个浮点值..

无论如何,这很奇怪,因为代码是因为很长一段时间以来从未触发过违规行为..我不知道......也许后来的代码修改是以Nvidia驱动程序无法进行的方式进行的。 ; t不再检测问题并自行修复,谁知道..