OpenGL ES2 IOS 8.x无法渲染纹理工作

时间:2015-03-13 14:31:54

标签: ios opengl-es opengl-es-2.0 render-to-texture

我设法将渲染工作渲染到屏幕外缓冲区,而不是尝试渲染到纹理时运气。渲染命令不做任何事情,我得到的只是黑色纹理。

我使用offscreen方法完成了相同的渲染,纹理按预期更新。

我已经关注了Apple文档并尝试了stackoverflow解决方法,仍然无法使其工作。

ogl没有错误报告。

任何?

由于

RenderTexture* RenderTextureCreate(int width, int height, bool hasDepth){


//frame buffer
GLuint frameBuffer = 0, depthBuffer = 0, renderTexture = 0;

glGenFramebuffers ( 1, &frameBuffer );
glBindFramebuffer ( GL_FRAMEBUFFER, frameBuffer );

glGenTextures(1, &renderTexture);
glBindTexture(GL_TEXTURE_2D, renderTexture);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

GLenum glErr = glGetError();
if ( glErr != GL_NO_ERROR){
    printf("RenderTextureCreate() error: %x\n", (int)glErr );
}

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glErr = glGetError();
if ( glErr != GL_NO_ERROR){
    printf("RenderTextureCreate() error: %x\n", (int)glErr );
}

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderTexture, 0);

glErr = glGetError();
if ( glErr != GL_NO_ERROR){
    printf("RenderTextureCreate() error: %x\n", (int)glErr );
}

// depth buffer
if(hasDepth){
    glGenRenderbuffers(1, &depthBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, width, height);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
}

glErr = glGetError();
if ( glErr != GL_NO_ERROR){
    printf("RenderTextureCreate() error: %x\n", (int)glErr );
}

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderTexture, 0);

// check for errors
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE){
    printf("---- RenderTextureCreate() status: %X\n", (int)status);
}else{
    printf("---- RenderTextureCreate() buffer ok status: %X\n", (int)status);
}


// create object
RenderTexture *rt = calloc(1, sizeof(RenderTexture));

if(rt){
    rt->frameBuffer = frameBuffer;
    rt->depthBuffer = depthBuffer;
    rt->texture = renderTexture;

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

return rt;
}

0 个答案:

没有答案