Skip to content

Instantly share code, notes, and snippets.

@nikolas
Created March 2, 2019 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikolas/f2200376e28183b5efb8384277e36ac1 to your computer and use it in GitHub Desktop.
Save nikolas/f2200376e28183b5efb8384277e36ac1 to your computer and use it in GitHub Desktop.
static void DrawSurfaceToScreen()
{
int n = _num_dirty_rects;
if (n == 0) return;
_num_dirty_rects = 0;
if (n > MAX_DIRTY_RECTS) {
SDL_CALL SDL_UpdateTexture(
_sdl_texture, NULL, _sdl_surface->pixels, _sdl_surface->pitch);
SDL_CALL SDL_RenderClear(_sdl_renderer);
SDL_CALL SDL_RenderCopy(_sdl_renderer, _sdl_texture, NULL, NULL);
} else {
void *pixels;
int pitch;
SDL_CALL SDL_LockTexture(_sdl_texture, NULL, &pixels, &pitch);
memcpy(
pixels, _sdl_surface->pixels,
pitch * _sdl_surface->h);
SDL_CALL SDL_UnlockTexture(_sdl_texture);
for (int i = 0; i < n; i++) {
SDL_CALL SDL_RenderCopy(
_sdl_renderer, _sdl_texture, &_dirty_rects[i], &_dirty_rects[i]);
}
}
SDL_CALL SDL_RenderPresent(_sdl_renderer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment