2014-02-25 101 views

回答

3

你会想为此使用FBO(帧缓冲对象)。帧缓冲区对象使用当前的OpenGL上下文,但绘制到附加到其上的纹理或其他类型的缓冲区,而不是绘制到屏幕上。苹果有一些不错的documentation on getting it working here

一旦您绘制了纹理,就可以将它从FBO中分离出来并像其他任何纹理一样使用它,例如将其应用到正在绘制到屏幕上的对象。

0

一般来说,下面是你如何做一个FBO。这不是合成。

//Creation of FBO 
glGenFramebuffers(NUM_FBO, fboId); 
//fbo texture 
glGenTextures(NUM_FBO, fboTextureId); 
//Regular first texture 
glGenTextures(1, &regularTextureId); 
//Bind offscreen texture 
GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0)); 
GL_CHECK(glBindTexture(GL_TEXTURE_2D, fboTextureId[i])); 
GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, inTextureWidth, inTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL)); 
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fboId[i])); 
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTextureId[i], 0)); 
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 
{ 
    goto err; 
} 
//Bind regular texture 
GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0)); 
GL_CHECK(glBindTexture(GL_TEXTURE_2D, regularTextureId)); 
add_texture(inTextureWidth, inTextureHeight, textureData, inPixelFormat); 
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 
//Draw with regular draw calls to FBO 
GL_CHECK(_test17(1)); 
//Now get back display framebuffer and unbind the FBO 
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0)); 
GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0)); 
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 
{ 
    goto err; 
} 
//bind to texture 
GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0)); 
GL_CHECK(glBindTexture(GL_TEXTURE_2D, fboTextureId[i])); 
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 
//draw other 3D objects with regular vertex/texure coordinates, use the above texture and then call swapbuffers 
draw_regular(); 

一个完整的工作版本可通过在线教程,包括https://github.com/prabindh/sgxperf/blob/master/sgxperf_test17矿的数量被发现。