Iphone OpenGLES-只渲染一次背景图像,不擦除它

Iphone OpenGLES-只渲染一次背景图像,不擦除它,iphone,objective-c,opengl-es,Iphone,Objective C,Opengl Es,第一次在这里问问题,但观察别人的回答已经有一段时间了。我自己的问题是如何提高我的程序的性能 目前,我正在通过程序的每次过程中擦除viewFrameBuffer,然后首先渲染背景图像,然后渲染场景的其余部分。我想知道如何渲染一次背景图像,而只擦除场景的其余部分以进行更新/重新渲染 我尝试使用一个单独的缓冲区,但我不确定如何将这个新缓冲区呈现给渲染缓冲区 // Set the current EAGLContext and bind to the framebuffer. This will di

第一次在这里问问题,但观察别人的回答已经有一段时间了。我自己的问题是如何提高我的程序的性能

目前,我正在通过程序的每次过程中擦除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源。如果您想将一个缓冲区绘制到另一个缓冲区中,则非常感谢您的帮助,这意味着第一个缓冲区必须是纹理,因此您可以将纹理映射的四边形绘制到另一个缓冲区中

// 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];

如果将背景作为纹理(最有可能),则只需使用该纹理和另一个包含内容(粒子等)的纹理(使用FBO绘制),然后将它们绘制在一起,将最终场景合成到屏幕中。

您试图解决的性能问题是什么?如果你的背景画起来并不特别昂贵(也就是说,它不是由一堆合成在一起的片段组成的),那么你可能看不到这样做的任何性能提升。