2010-06-18 37 views
0

第一次在这里提问,但一直在看别人的答案。我自己的问题是改善我的计划的表现。OpenGLES - 只渲染一次背景图片而不擦除它

当前我正在擦拭viewFrameBuffer,每遍通过我的程序,然后渲染背景图像,然后是我的场景的其余部分。我想知道如何去渲染一次背景图像,并且只擦除场景的其余部分以便更新/重新渲染。

我试过使用一个单独的缓冲区,但我不知道如何将这个新的缓冲区呈现给渲染缓冲区。

// Set the current EAGLContext and bind to the framebuffer. This will direct all OGL commands to the 
// framebuffer and the associated renderbuffer attachment which is where our scene will be rendered 
[EAGLContext setCurrentContext:context]; 
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); 

// Define the viewport. Changing the settings for the viewport can allow you to scale the viewport 
// as well as the dimensions etc and so I'm setting it for each frame in case we want to change i 
glViewport(0, 0, screenBounds.size.width , screenBounds.size.height); 

// Clear the screen. If we are going to draw a background image then this clear is not necessary 
// as drawing the background image will destroy the previous image 
glClearColor(0.0f, 1.0f, 0.0f, 1.0f); 

glClear(GL_COLOR_BUFFER_BIT); 

// Setup how the images are to be blended when rendered. This could be changed at different points during your 
// render process if you wanted to apply different effects 
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 

switch (currentViewInt) { 
    case 1: 
    { 
     [background render:CGPointMake(240, 0) fromTopLeftBottomRightCenter:@"Bottom"]; 
     // Other Rendering Code 
    }} 

// Bind to the renderbuffer and then present this image to the current context 
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); 
[context presentRenderbuffer:GL_RENDERBUFFER_OES]; 

希望通过解决这个我也将能够实现另一个缓冲区只为渲染的粒子,因为我可以将它们设置为始终使用黑色背景的Alpha源。任何帮助都非常感谢

+0

你试图解决什么性能问题?如果你的背景并不是特别昂贵(也就是说它不是由大量的组合在一起构成的),你可能不会看到这样做会带来任何性能上的提升。 – Pivot 2010-06-19 19:28:48

回答

0

如果你想绘制一个缓冲区到另一个,这意味着第一个缓冲区必须是一个纹理,所以你可以绘制一个纹理映射四个到另一个缓冲区。

如果你有作为纹理的背景(最有可能),那么只需将该纹理以及其他纹理(用FBO绘制)与内容(粒子等)合并在一起以将最终场景合成为屏幕。