繁体   English   中英

存在未初始化的颜色附件问题

[英]Present of uninitialized color attachment issue

当我运行OpenGL应用程序时,出现以下错误:

在此处输入图片说明

我用Google搜索,但无法获得任何有用的信息。

这是一段源代码:

- (void)render:(CADisplayLink*)displayLink {
    [self.canvas clear];
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    NSInteger mLength = mParticles.count;
    NSInteger drawCount = 0;
    NSInteger drawIndex = 0;
    WQParticle* drawParticle;
    CGFloat drawX,drawY,drawScale,drawAngle;
    GLKMatrix4 changeColorMatrix;
    if (mLength > 0){
        glBindFramebuffer(GL_FRAMEBUFFER, FBO);
        glViewport(0,0,width,height);
        drawCount = 0;
        drawIndex = -1;
        while ( drawCount < mLength){
            drawParticle = mParticles[drawCount];

            if(!(drawParticle.flg && random > 0.5)){

                if (drawIndex != drawParticle.texIndex) {
                    glActiveTexture(GL_TEXTURE0);
                    glBindTexture(GL_TEXTURE_2D, (GLuint)(texture[drawParticle.texIndex]));
                    glUniform1i((GLint)uniLocation[1], 0);
                    drawIndex = drawParticle.texIndex;
                }

                if(drawParticle.flg){
                    drawX = drawParticle.posX + (random * 1 - 0.5) * drawParticle.scale * 0.06;
                    drawY = drawParticle.posY + (random * 1 - 0.5) * drawParticle.scale * 0.06;
                    drawScale = drawParticle.scale * (random * 0.4 + 0.8);
                    changeColorMatrix = [self setChangeColorWithDp:drawParticle n:random];
                    drawX = drawX / drawScale;
                    drawY = drawY / drawScale;
                }else{
                    drawX = drawParticle.posX / drawParticle.scale;
                    drawY = drawParticle.posY / drawParticle.scale;
                    drawScale = drawParticle.scale;
                    changeColorMatrix = [self setChangeColorWithDp:drawParticle n:1];
                }
                glUniformMatrix4fv((GLint)uniLocation[2], 1, 0, changeColorMatrix.m);
                drawAngle = drawParticle.angle;
                CGFloat drawR = sqrt(drawX * drawX + drawY * drawY);
                CGFloat oa = 2 * M_PI - acos(drawX / drawR);
                drawX = cos(oa - drawAngle) * drawR;
                drawY = sin(oa - drawAngle) * drawR;

                mMatrix = GLKMatrix4Identity;
                mMatrix = GLKMatrix4Rotate(mMatrix, drawAngle, 0, 0, 1);
                mMatrix = GLKMatrix4Scale(mMatrix, drawScale, drawScale, drawScale);
                mMatrix = GLKMatrix4Translate(mMatrix, drawX, drawY, 0);
                mvpMatrix = GLKMatrix4Multiply(f_tmpMatrix, mMatrix);

                glUniform1i((GLint)uniLocation[3], YES);
                glUniformMatrix4fv((GLint)uniLocation[0], 1, 0, mvpMatrix.m);
                glDrawElements(GL_TRIANGLES, sizeof(indices), GL_UNSIGNED_BYTE, 0);
            }

            if (drawParticle.life > 0) {
                [mVF getForceFromPosWithPx:drawParticle.posX Py:drawParticle.posY];
                [drawParticle setVFupdateWithOutX:mVF.outX OutY:mVF.outY];
                drawCount++;
                continue;
            }
            [mParticles removeObjectAtIndex:drawCount];
            mLength = mLength - 1;
        }
        glBindFramebuffer(GL_FRAMEBUFFER,0);
    }

    glBindTexture(GL_TEXTURE_2D, FBOTexture);
    mMatrix = GLKMatrix4Identity;
    mvpMatrix = GLKMatrix4Multiply(tmpMatrix, mMatrix);
    glUniformMatrix4fv((GLint)uniLocation[0], 1, 0, mvpMatrix.m);
    glUniform1i((GLint)uniLocation[3], NO);
    glDrawElements(GL_TRIANGLES, sizeof(indices), GL_UNSIGNED_BYTE, 0);
    [self.canvas.glContext presentRenderbuffer:GL_RENDERBUFFER];
}

我该如何解决?

检查glViewport()是否设置了要渲染的renderpass的大小,并且glScissor()也设置为该大小,或者是否通过glDisable()禁用了剪刀测试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM