0

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.

denim
  • 1,329
  • 1
  • 15
  • 24
  • 1
    Which version of OpenGL are you using? Since `glVertexPointer()` has been deprecated since version 3.1 – vallentin Dec 13 '13 at 10:45
  • I am using OpenGL version 2.0. It is deprecated but shouldn't new drivers still be compatible? – denim Dec 13 '13 at 10:47
  • Yes they should, but doesn't have to. – vallentin Dec 13 '13 at 10:56
  • 1
    @Vallentin They *have to* when using a compatibility profile, which is the default when creating your context with GLUT. But it would still be interesting of that also happens for `glVertexAttribPointer`, though it is quite likely given that `glVertexPointer` is nothing but a wrapper for `glVertexAttribPointer`). – Christian Rau Dec 13 '13 at 11:57
  • @ChristianRau Thank you for the hint, I updated my question because I get the same behaviour when I use the `glVertexAttribPointer()`instead of the `glVertexPointer()`. Any ideas? – denim Dec 13 '13 at 12:17
  • 3
    A 2 KiB stride is enormous. That is enough to store 128 `vec4` vertex attributes. Can I inquire why you need such a huge stride? – Andon M. Coleman Dec 13 '13 at 13:19
  • This is common practice to skip a certain amount of vertex attributes (or vertices) and that is what I want to do. Despite that the type of the stride parameter is a **GLsizei** which is type defined as **int** and for this reason a value bigger than 2048 is perfectly valid. – denim Dec 13 '13 at 13:36
  • 1
    @denim *"for this reason a value bigger than 2048 is perfectly valid."* - No, this is alone not a sufficient reason. Just because the variable can hold a number larger as large as 32000 doesn't mean the function is defined reasonably for this domain. You don't have a separate type for each and every possible range of values a function can be defined for. We don't need what this function does with the value internally. – Christian Rau Dec 13 '13 at 15:08
  • @denim *"This is common practice to skip a certain amount of vertex attributes (or vertices) and that is what I want to do."* - Of course it is, *Andon* is not in any way arguing about that practice, just about the individual values used in your specific way of applying this common practice. While there might be use cases where strides larger than 2048 could be needed, it still seems pretty unusual and would be interesting to know the actual nature of your vertex data, even if it doesn't really answer why those strides don't work... – Christian Rau Dec 13 '13 at 15:09
  • @denim ...But in general driver bugs are most likely to encounter in rarely used paths, which strides above 2048 definitely are. – Christian Rau Dec 13 '13 at 15:12

1 Answers1

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.

Community
  • 1
  • 1
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982