corjan
Posts: 3
Joined: Fri Sep 25, 2015 7:04 am

Back buffer gets cleared?

Fri Sep 25, 2015 7:12 am

Hi,

Currently I am porting a bit of openGL code to the raspberry.
To reduce the number of redraws, it won't redraw parts that haven't changed.

Here I have trouble with the raspberry somehow. It seems it is clearing the back buffer with every frame. So stuff I draw one frame is thrown away the next. When I let the openGL code draw everything every frame, all is fine (expect the performance :) ).

I created a small code snipplet to demonstrate this:

Code: Select all

#include "lib_instrument.h"

#include <stdio.h>

int main(int argc, char* argv[])
{
	int i;

	int w = 1920;
	int h = 1080;
	int x = SDL_WINDOWPOS_CENTERED;
	int y = SDL_WINDOWPOS_CENTERED;

	SDL_Window* window = NULL;

	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		log_error("Main", "Unable to initialize SDL Video:  %s", SDL_GetError());
		return 1;
	}

	window = SDL_CreateWindow("Air Panel", x, y, w, h, SDL_WINDOW_OPENGL);

	SDL_GL_CreateContext(window);

        printf("Drawing red\n");
	glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
        // Screen will indeed become red, all is still fine

        for(int i=0; i < 10; i++) {
	    printf("Swap\n");
	    SDL_GL_SwapWindow(window);

            // Here the screen is black
            // I expect it to be black->red->black->red->black etc. here
        }

	return 0;
}
Any help is appreciated,

Kind regards,
Corjan

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: Back buffer gets cleared?

Fri Sep 25, 2015 9:22 am

In my experience it is performing as expected, but then I've not tried to do what you are trying !

I've not used SDL either, so I don't know what "SDL_GL_SwapWindow(window);" actually does but the manual page for eglSwapBuffers here https://www.khronos.org/registry/egl/sd ... fers.xhtml suggests that
eglSurfaceAttrib https://www.khronos.org/registry/egl/sd ... trib.xhtml can be used to change the swap behaviour. I can't try it out at the moment (no access to a Pi).

PeterO
Last edited by PeterO on Fri Sep 25, 2015 9:23 am, edited 1 time in total.
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dave j
Posts: 123
Joined: Mon Mar 05, 2012 2:19 pm

Re: Back buffer gets cleared?

Fri Sep 25, 2015 9:23 am

Tile based GPUs don't preserve the back buffer by default because it reduces performance.

You can control it using EGL_SWAP_BEHAVIOUR (see here).

You should also read Performance Tuning for Tile Based Architectures which has a good explanation of why you should avoid it if possible and other performance hints for tile based GPUs.

User avatar
PeterO
Posts: 5829
Joined: Sun Jul 22, 2012 4:14 pm

Re: Back buffer gets cleared?

Fri Sep 25, 2015 9:24 am

SNAP ! :D
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dattrax
Posts: 52
Joined: Sat Dec 24, 2011 5:09 pm

Re: Back buffer gets cleared?

Wed Dec 16, 2015 7:09 pm

It's not really anything to do with tiled or immediate mode renderers, but more what the EGL speciation says when eglSwapbuffers is called.

From the specification -
The contents of ancillary buffers are always undefined after calling eglSwap-
Buffers. The contents of the color buffer are undefined if the value of the EGL_SWAP_BEHAVIOR attribute of surface is not EGL_BUFFER_PRESERVED. The value of EGL_SWAP_BEHAVIOR can be set for some surfaces using eglSurfaceAttrib, as described in section 3.5.619

Undefined can mean anything. In a immediate mode renderer it can be the frame from three swaps ago, in tiled it could be a default color, just you can't ever rely on it.

Return to “OpenGLES”