I need to render something based on the map. Now SDL_RenderCopy accepts negative value for it's co-ordinate. If I use SDL_RenderCopy with a dstrect={0,-16,32,32}, it would render the bottom half of the rectangle on the Top left of the window. In my case, the map is larger than the window, and scrolling would be used. I can render something that is on map but not on the window using one of the two methods mentioned below. But I am worried about the time required to render then. If I use SDL_RenderCopy with a negative dstrect, would the SDL_RenderCopy function check and adjust the dstrect to render, or the underlying hardware pipeline would do the job? Because if the SDL_RenderCopy does it, it would be faster to check and return in case the rendering can't be done on the window, but if the underlying the protocol detects it, then it would be much later in the scenario that the rectangle can't be drawn, taking longer time to return to do the next possible rendering. Well the time difference may not be that high, probably be done within ms with a reasonable hardware, but when we are talking about a lot of rectangle (say, 10000, though even that number won't be a possible in my case) then I am worried that it may slow down the process.
The mentioned two approaches are below The scrolling is done only in the y axis
- Let the SDL_RenderCopy function do the check
SDL_Rect dstrect={target.x,target.y-Map.y,target.w,target.h};
SDL_RenderCopy(renderer,texture,nullptr,&dstrect);
- Let me do the check
//if within the Map, render
if(target.y<Map.y+Map.h+target.h && target.y>Map.y-target.h)
{
SDL_Rect dstrect={target.x,target.y-Map.y,target.w,target.h);
SDL_RenderCopy(renderer,texture,nullptr,&dstrect);
}