OpenGL: glVertexAttribPointer() fails with “Invalid value” for stride bigger than 2048 on new NVIDIA drivers

纵饮孤独 提交于 2020-01-07 05:45:08

问题


Did anyone else recognize that it is not possible any more to call glVertexAttribPointer() with a stride bigger then 2048 with new NVIDIA drivers (from 331.58 WHQL and above)? The call creates the OpenGL error Invalid value (1281).

For example the following minimal GLUT example will generate the OpenGL error 1281 after testStride(2049); is called when using driver 331.58 WHQL:

#include <iostream>
#include <GL/glut.h>
#include <windows.h>

using namespace std;

PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer = 0;

void testStride(const GLsizei stride)
{
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride, 0);
    GLenum code = glGetError();
    if (code != GL_NO_ERROR)
         std::cerr << "glVertexAttribPointer() with a stride of " << stride << " failed with code " << code << std::endl;
    else std::cout << "glVertexAttribPointer() with a stride of " << stride << " succeeded" << std::endl;
}

void render(void)
{
    testStride(2048); // Works well with driver version 311.06 and 331.58
    testStride(2049); // Does not work with driver version 331.58 but works well with driver version 311.06
}

int main(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    glutCreateWindow("Window");
    glutDisplayFunc(render);

    glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) wglGetProcAddress("glVertexAttribPointer");

    glutMainLoop();
    return 0;
}

What is your opinion? Am I doing anything wrong?

@Christian Rau: Thank you very much for the hint. I immediately replaced the glVertexPointer() call with the glVertexAttribPointer() and still get the same result.


回答1:


OpenGL 4.4 added GL_MAX_VERTEX_ATTRIB_STRIDE, which is exactly what it sounds like: a hard, implementation-defined limit on the maximum stride you're allowed to use. It applies equally to separate attribute formats and old-style glVertexAttribPointer.



来源:https://stackoverflow.com/questions/20564469/opengl-glvertexattribpointer-fails-with-invalid-value-for-stride-bigger-tha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!