• Advertisement
Sign in to follow this  

Misbehaving function calls?

This topic is 986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was trying out many of the different methods of setting up a VAO in a test program and found something weird.

I checked all code paths and only one path is showing wrong colors (while all others using the same parameters run as they should), but only when its using the HD4400 in my laptop. Everything runs correctly when I set it to use the NV chip instead.

I put glGetError in, but no error returned.

It seems as if glVertexArrayVertexAttribFormatEXT ignores the offset in last parameter (I tried changing the position and that is changing the color, so its reading the wrong part of the VBO), but moving the offset to glVertexArrayBindVertexBufferEXT also does not help and just gets different wrong colors (even though same change would work on NV chip).

I have no more ideas (besides getting some gl debug tool or adding code to use the debug extensions) and searching/reading all kinds of docs did not help. I could just have forgotten something obvious or it could be noone tried this obscure new/old extension combination which does not work?

 

Shortened code:

    static const struct Vertex {
      GLfloat position[3];
      GLubyte color[4];
    } va[] = {
      {
        { 0.f,0.f,0.f },
        { 127,255,127,255 }
      },
      {
        { .5f,0.f,0.f },
        { 127,255,127,255 }
      },
      {
        { 0.f,.5f,0.f },
        { 127,255,127,255 }
      }
    };
    GLuint vao=0;
    GLuint vbo=0;
    {
      glGenVertexArrays(1,&vao);
      glGenBuffers(1,&vbo);
      if(GLAD_GL_EXT_direct_state_access) {
        if(GLAD_GL_ARB_buffer_storage)
          glNamedBufferStorageEXT(vbo,sizeof(va),va,0);
        else
          glNamedBufferDataEXT(vbo,sizeof(va),va,GL_STATIC_DRAW);
        glEnableVertexArrayAttribEXT(vao,0);
        glEnableVertexArrayAttribEXT(vao,1);
        if(GLAD_GL_ARB_vertex_attrib_binding) {
          glVertexArrayVertexAttribFormatEXT(vao,0,3,GL_FLOAT,GL_FALSE,0);
          glVertexArrayBindVertexBufferEXT(vao,0,vbo,0,16);
          // TODO: Fix problem on Intel chip here:
          glVertexArrayVertexAttribFormatEXT(vao,1,4,GL_UNSIGNED_BYTE,GL_TRUE,12);
          glVertexArrayBindVertexBufferEXT(vao,1,vbo,0,16);
        } else {
          glVertexArrayVertexAttribOffsetEXT(vao,vbo,0,3,GL_FLOAT,GL_FALSE,16,0);
          glVertexArrayVertexAttribOffsetEXT(vao,vbo,1,4,GL_UNSIGNED_BYTE,GL_TRUE,16,12);
        }
      } else {
        glBindVertexArray(vao);
        glBindBuffer(GL_ARRAY_BUFFER,vbo);
        if(GLAD_GL_ARB_buffer_storage)
          glBufferStorage(GL_ARRAY_BUFFER,sizeof(va),va,0);
        else
          glBufferData(GL_ARRAY_BUFFER,sizeof(va),va,GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(1);
        if(GLAD_GL_ARB_vertex_attrib_binding) {
          glVertexAttribFormat(0,3,GL_FLOAT,GL_FALSE,0);
          glBindVertexBuffer(0,vbo,0,16);
          glVertexAttribFormat(1,4,GL_UNSIGNED_BYTE,GL_TRUE,12);
          glBindVertexBuffer(1,vbo,0,16);
        } else {
          glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,16,0);
          glVertexAttribPointer(1,4,GL_UNSIGNED_BYTE,GL_TRUE,16,(void*)12);
        }
        glBindBuffer(GL_ARRAY_BUFFER,0);
        glBindVertexArray(0);
      }
    }

    static const char vs[] = {
      "#version 330\n"
      "layout(location=0) in vec3 position;\n"
      "layout(location=1) in vec4 scolor;\n"
      "smooth out vec4 color;\n"
      "void main() {\n"
      "  gl_Position=vec4(position,1);\n"
      "  color=scolor;"
      "}\n"
    };
    static const char fs[] = {
      "#version 330\n"
      "smooth in vec4 color;\n"
      "out vec4 fcolor;\n"
      "void main() {\n"
      "  fcolor=color;\n"
      "}\n"
    };

Share this post


Link to post
Share on other sites
Advertisement


glVertexArrayVertexAttribFormatEXT(vao,1,4,GL_UNSIGNED_BYTE,GL_TRUE,12);

try not using GL_TRUE, I have encountered problems when I rellied on driver to clamp bytes to 0.0-1.0 floats into vertex function, I rather do it manualy by a multiply in the vertex function. Other than that, I have no idea.

Share this post


Link to post
Share on other sites

I tried your suggestion, even though I knew it is not the problem and it makes no difference with glVertexArrayVertexAttribFormatEXT, but works on alternative calls.

The first call only appears to work, as its setting nearly the same values which are already set by default. The 3 is ignored and with the default 4 it picks up garbage in position.w, which made me change the vertex shader already to switch from vec4 to vec 3 and put the 1 in explicitely.

I'm now pretty sure glVertexArrayVertexAttribFormatEXT is broken/ignored in the Intel driver I have installed. I had no luck with upgrading, having newest OEM driver already and generic download from Intel does not want to be installed, even device manager will not accept it without deinstall (which I prefer not trying atm).

Luckily, as glBindVertexArray+glVertexAttribFormat and glVertexArrayVertexAttribOffsetEXT are working, its easy to work around.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement