Re: [hatari-devel] use of SDL_RenderClear with SDL2 |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
Hi,
On 02/22/2017 08:09 PM, Nicolas Pomarède wrote:
in the wrapper functions SDL_UpdateRects used only for SDL2, I see :
SDL_UpdateTexture(sdlTexture, NULL, screen->pixels, screen->pitch);
SDL_RenderClear(sdlRenderer);
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
SDL_RenderPresent(sdlRenderer);
Why is there a call to SDL_RenderClear since we copy the texture on
screen anyway just after ?
There's no clear color set anywhere in Hatari sources,
so it's using some (SDL2?) "default" color.
At least, if I comment SDL_RenderClear I still get correct results on
screen. Maybe it's just to clear some parts of the screen near border
and status bar,
With NULL args, RenderCopy() is filling the whole target,
so no.
(Updating whole screen every frame is typical with 3D,
drivers may not even have support for partial updates.)
> but isn't it too much to clear the whole screen on each frame ?
> Or am I missing something ?
It's redundant[1], but overhead from it is only small
percentage of what you'd think.
Such clear doesn't actually write anything to the frame
buffer, just marks some bit(s) in an auxiliary buffer
that is used to indicate which of the (normally 32-bit)
pixels in the frame buffer have been "fast cleared", but
not yet written.
Then, just before the frame is shown on screen, only
pixels that haven't been overwritten yet, will actually
be set with the specified clear color (= driver asks GPU
to "resolve" fast clear). In above case, no writes are
needed at this stage, as copy overwrote the whole buffer.
This is standard performance feature with GPUs and
their 3D drivers.
- Eero
[1] If there is some part of frame buffer that isn't
written during frame, that part is in undefined state.
Previous frame contents are not guaranteed to be copied
to new frame (for obvious performance reasons), especially
when double/triple buffering is used.
That's why 3D programs often start frame with clear.