Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. glPrimitiveRestartIndex doesn't work as it should in Xcode
Forum Update on Monday, May 27th 2025

glPrimitiveRestartIndex doesn't work as it should in Xcode

Scheduled Pinned Locked Moved General and Desktop
opengl
3 Posts 1 Posters 966 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    akilone
    wrote on last edited by akilone
    #1

    Hi,

    I have trouble porting my Qt code from Visual Studio to Xcode. I use glPrimitiveRestartIndex to draw many triangle strips with one draw call, and it works nice in Visual Studio, but doesn't work in Xcode. I wrote little function:

    void drawStrip(QOpenGLShaderProgram* program) {
    vector<QVector3D> vertices;
    vertices.push_back(QVector3D(0,1,0));
    vertices.push_back(QVector3D(0,0,0));
    vertices.push_back(QVector3D(1,1,0));
    vertices.push_back(QVector3D(1,0,0));
    vertices.push_back(QVector3D(0,-1,0));
    vertices.push_back(QVector3D(1,-1,0));

    size_t numVertices = 6;
    size_t numTriangles = 2;
    
    GLushort indices[] = {0,1,2,3, 0xFFFF, 1,4,3,5};
    
    
    size_t numIndices = 8;
    
    arrayBuf.bind();
    arrayBuf.allocate(&vertices[0], numVertices*sizeof(QVector3D));
    
    indexBuf.bind();
    indexBuf.allocate(indices, numIndices*sizeof(GLushort));
    
    quintptr offset = 0;
    
    int vertexLocation = program->attributeLocation("a_position");
    program->enableAttributeArray(vertexLocation);
    program->setAttributeBuffer(vertexLocation, GL_FLOAT, offset, 3, sizeof(QVector3D));
    
    glEnable(GL_PRIMITIVE_RESTART);
    glPrimitiveRestartIndex(0xFFFF);
    
    glDrawElements(GL_TRIANGLE_STRIP, numIndices, GL_UNSIGNED_SHORT, 0);
    

    }

    Which should draw two quads one on top of another. It works in VS, as I said, but in Xcode it gives strange result, like it's not restarting indices correctly , 4th triangle is not even drawn and 3th and 4th triangles are flipped.

    Maybe, it's a version of OpenGL that cause troubles - in windows is 4.3, and on Mac is 4.1. I tried including QtOpenGLFunctions_4_1_core.h in Xcode, but that won't even compile - it's gives few BAD ACCESS errors. When I include just QtOpenGLFunctions.h, the result is what I described above.

    What can be problem here? Why does QtOpenGLFunctions_4_1_core gives that errors in Xcode?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      akilone
      wrote on last edited by akilone
      #2

      Ok, I found that glEnable doesn't even enabled GL_PRIMITIVE_RESTART .

      1 Reply Last reply
      0
      • A Offline
        A Offline
        akilone
        wrote on last edited by
        #3

        Ok, actually I found out that glEnable doesn't work (not just for GL_PRIMITIVE_RESTART, but for all enums). I tried to use glEnable directly in GLWidget class, but it doesn't work. What can be problem?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved