IOS OpenGL gpus_ReturnGuiltyForHardwareRestart错误

时间:2013-12-16 23:57:41

标签: ios opengl-es runtime-error

我遇到的主要问题是libGPUSupportMercury.dylib gpus_ReturnGuiltyForHardwareRestart错误。

目前我正在渲染一个立方体和一条线。如果我只渲染立方体或只是线,则错误在20%的时间内出现。如果我渲染两个我得到错误约90%的时间。

我在网上看到这是ios中的一个错误,没有什么可以做的。但是,像Unity这样的其他OpenGL程序没有这个问题。所以我一定做错了什么

以下是我正在使用的代码的简化版本。

-(void) setUp{
    m_context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease];
    [EAGLContext setCurrentContext:m_context];

    glGenRenderbuffers(1, &m_renderbuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, m_renderbuffer);
    [m_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];

    glGenFramebuffers(1, &m_framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,    m_renderbuffer);
}



-(void) render{
    //[EAGLContext setCurrentContext:m_context];  Error seems to happen more frequent if I uncomment these lines
    // glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);

    glViewport(0, 0, self.bounds.size.width, self.bounds.size.height);

    glClearColor(0.3, 0.3, 0.3, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    [self renderCube];  // VBO
    [self renderLine];  // NON VBO

    [m_context presentRenderbuffer:GL_RENDERBUFFER]; <---- Error Here
}



-(void) renderCube
{
     glUseProgram(m_cubeProgram);

     glBindTexture(GL_TEXTURE_2D, m_textureHandle);

     glUniformMatrix4fv(m_uniformHandles[UNIFORM_PROJECTION_MATRIX], 1, GL_FALSE, m_projectionMatrix.m);
     glUniformMatrix4fv(m_uniformHandles[UNIFORM_MODELVIEW_MATRIX], 1, GL_FALSE, m_modelMatrix.m);

     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_cubeIndexVBO);

     glEnableVertexAttribArray(m_attributeHandles[ATTRIB_POSITION]);
     glEnableVertexAttribArray(m_attributeHandles[ATTRIB_TEXCOORD]);

     glBindBuffer(GL_ARRAY_BUFFER, m_cubeVertexVBO);
     glVertexAttribPointer(m_attributeHandles[ATTRIB_POSITION], 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
     glVertexAttribPointer(m_attributeHandles[ATTRIB_TEXCOORD], 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*) (sizeof(float) * 3));

     glDrawElements( GL_TRIANGLES, m_numberOfIndices, GL_UNSIGNED_SHORT, (void*)0              );

     glDisableVertexAttribArray(m_attributeHandles[ATTRIB_POSITION]);
     glDisableVertexAttribArray(m_attributeHandles[ATTRIB_TEXCOORD]);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);  // Desperate attempt to fix the issue
    glBindBuffer(GL_ARRAY_BUFFER, 0);          // this too
    glBindTexture(GL_TEXTURE_2D, 0);           /// this too
}





-(void) renderLine
{
    glUseProgram(m_lineProgram);

    glUniformMatrix4fv(m_uniformHandles[UNIFORM_LINE_PROJECTION_MATRIX], 1, GL_FALSE, m_projectionMatrix.m);
    glUniformMatrix4fv(m_uniformHandles[UNIFORM_LINE_MODELVIEW_MATRIX], 1, GL_FALSE, m_modelView.m);

    glEnableVertexAttribArray(m_attributeHandles[ATTRIB_LINE_POSITION]);

    float linVertices[]= {...};

    glVertexAttribPointer(m_attributeHandles[ATTRIB_LINE_POSITION], 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, lineVertices);

    glLineWidth(3.0f);
    glDrawArrays(GL_LINE_STRIP, 0, 3);

    glDisableVertexAttribArray(m_attributeHandles[ATTRIB_LINE_POSITION]);
}

0 个答案:

没有答案