Question about implementation of SDL_UpdateWindowSurfaceRects()

Hello. I want to update part of the screen and so I use SDL_UpdateWindowSurfaceRects(win, rects, count); in my loop. This works well on macos and linux. But on windows entire screen is updated (even though I pass good rects). I did some research in SDL source code and found out that the function SDL_UpdateWindowSurfaceRects uses on windows is:

int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
{
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    BitBlt(data->hdc, 0, 0, window->w, window->h, data->mdc, 0, 0, SRCCOPY);
    return 0;
}

As you can see this function calls BitBlt on entire screen, even though it accepts the rects. Rects variable is not even used in this function at all. Now my question is why is that the case? In SDL 1.2 it used to be (I will write just part of code)

for ( i=0; i<numrects; ++i ) {
	BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h,
				mdc, rects[i].x, rects[i].y, SRCCOPY);
}

Thanks in advance.

This is likely a bug, since very few things use SDL_UpdateWindowSurfaceRects. I have opened a bug report here so we remember to fix it:

https://bugzilla.libsdl.org/show_bug.cgi?id=5113

…but I would also encourage you not to use this function, but rather wrap your 2D rendering in the SDL render API, which will move the work to the GPU and get you free scaling, etc. This is often worthwhile (and faster!) even if you’re just uploading a block of pixels you rendered yourself on the CPU every frame.

1 Like