2014-02-25 72 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礦的數量被發現。