2010-06-18 35 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繪製)與內容(粒子等)合併在一起以將最終場景合成爲屏幕。