OpenGL GLKit : rendering different size vertices objects together. ios opengl draw call exceeded array buffer bounds

StackOverflow https://stackoverflow.com/questions/23177366

  •  06-07-2023
  •  | 
  •  

Question

I very much doubt anyone can help me on this but hey ho.

I have a 3D framework I have been working on where most things in the world are cubes (36 vertices).

I followed this great tutorial about bringing blender objects in to OpenGL : http://www.raywenderlich.com/48293/how-to-export-blender-models-to-opengl-es-part-1

I brought the cube in and all was good, I then tried to bring a sphere in, cube, cylinder etc and it blows up with ios opengl draw call exceeded array buffer bounds

I know the objects are fine as they work with the demo app but that only renders 1 object and has no binding of arrays and vertex's etc

Anyway

I am sure this code is junk but I have tried everything

- (void)setupSphere;
{

    glGenVertexArraysOES(1, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);
//////
    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(&sphereVertices), &sphereVertices, GL_STATIC_DRAW);
////
    glGenBuffers(1, &_position);
    glBindBuffer(GL_ARRAY_BUFFER, _position);
    glBufferData(GL_ARRAY_BUFFER, sizeof(spherePositions),spherePositions, GL_STATIC_DRAW);
////
    glGenBuffers(1, &_texture);
    glBindBuffer(GL_ARRAY_BUFFER, _texture);
    glBufferData(GL_ARRAY_BUFFER, sizeof(sphereTexels),sphereTexels, GL_STATIC_DRAW);
////
    glGenBuffers(1, &_normal);
    glBindBuffer(GL_ARRAY_BUFFER, _normal);
    glBufferData(GL_ARRAY_BUFFER, sizeof(sphereNormals),sphereNormals, GL_STATIC_DRAW);
//////
//    glBindVertexArrayOES(0);

    // Positions
    //glBindBuffer(GL_ARRAY_BUFFER, _position);
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 0, spherePositions);

    // Texels
    //glBindBuffer(GL_ARRAY_BUFFER, _texture);
    glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
    glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, sphereTexels);

    // Normals
    //glBindBuffer(GL_ARRAY_BUFFER, _normal);
    glEnableVertexAttribArray(GLKVertexAttribNormal);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 0, sphereNormals);

    //glBindVertexArrayOES(_vertexArray);

    glBindVertexArrayOES(0);
}

- (void)drawSphere:(float)eyeOffset
{
    // Calculate the per-eye model view matrix:
    GLKMatrix4 temp = GLKMatrix4MakeTranslation(eyeOffset, 0.0f, 0.0f);
    GLKMatrix4 eyeBaseModelViewMatrix = GLKMatrix4Multiply(temp, self.baseModelViewMatrix);

    if (self.isTransparant)
    {
        glEnable (GL_BLEND);
        glDisable(GL_CULL_FACE);
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    if (self.textureInfo)
    {
        glBindTexture(self.textureInfo.target, self.textureInfo.name);
    }


    glBindVertexArrayOES(_vertexArray);

    glUseProgram(_program);

    self.modelViewMatrix = GLKMatrix4MakeTranslation(self.position.x,self.position.y, self.position.z );//(float)x, (float)y, -1.5f)
    self.modelViewMatrix = GLKMatrix4Scale(self.modelViewMatrix, self.scale.x, self.scale.y, self.scale.z);

    //rotation +=0.01;
    self.modelViewMatrix = GLKMatrix4Rotate(self.modelViewMatrix,rotation, 0.0 ,0.0 ,1.0);
    self.modelViewMatrix = GLKMatrix4Multiply(eyeBaseModelViewMatrix, self.modelViewMatrix);

    GLKMatrix3 normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(self.modelViewMatrix), NULL);
    GLKMatrix4 modelViewProjectionMatrix = GLKMatrix4Multiply(self.projectionMatrix, self.modelViewMatrix);

    glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, modelViewProjectionMatrix.m);
    glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, normalMatrix.m);

    _colorSlot = glGetUniformLocation(_program, "color");
    GLfloat color[] = {
        self.color.x, self.color.y, self.color.z, self.color.a};
    glUniform4fv(_colorSlot, 1, color);

    glDrawArrays(GL_TRIANGLES, 0, sphereVertices);

    if (self.isTransparant)
    {
        glEnable(GL_CULL_FACE);
        //glEnable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
    }
}
Was it helpful?

Solution

You're trying to use a VAO with client vertex arrays. This is not supported. Quoting from the extension spec:

  • Should a vertex array object be allowed to encapsulate client vertex arrays?

    RESOLVED: No. The OpenGL ES working group agreed that compatibility with OpenGL and the ability to to guide developers to more performant drawing by enforcing VBO usage were more important than the possibility of hurting adoption of VAOs.

If you want to use a VAO, you will need to enable the VBO code that seems mostly present in your code, but currently commented out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top