Two questions, regarding biltscaled and clipping

Hello, and apologies beforehand for the bother. If anyone has the time, please could you clarify these doubts?

  1. Clipping, in general. While working with a tile map, I started doing the routine for correctly sizing the tile sub rectangle to copy so that it would not over-lap the edges or corners of the target surface, if the tile was not perfectly aligned with said edge or corner. It used to be important, once upon a time, and is not a big deal to create the function. But; then I (re)read this properly, on the SDL_BlitSurface documentation…

This is the public blit function, and it performs rectangle validation and clipping before passing it to SDL_LowerBlit().

I conclude that, therefore, clipping is not necessary if we use SDL_BlitSurface. So, clipping does remain an important consideration under certain circumstances. Which brings me to the following;

Does the same apply when rendering onto target textures? It is not clear in the documentation if the functions for SDL_RenderDrawLine, SDL_RenderDrawRect and SDL_RenderFillRect (and their “cousins”), and indeed SDL_RenderCopy, perform clipping automatically, too.

For safety, I have been making a larger than necessary texture, with a fringe, that can accommodate forays “off the edge”, when working with the renderer. I then grab the rectangle of interest excluding the fringe, for final presentation. However, I also tested extending a draw line right off the target texture, to no apparent ill effects. I assume, therefore, that clipping is done prior to any form of texture drawing or texture copying. But I might be getting myself into some trouble.

Could you please confirm that clipping is done on texture draw functions?

  1. An issue with SDL_BlitScaled that took two sessions to finally corner, and cost a couple of fistfuls of hair in the process. I have been using 8 bit indexed pixel format, paletted surfaces for the tile source, for a tiled map experiment, which has slew and zoom functions. However, when invoking the zoom, the 8 bit tiles refuse to scale up or down (they just do not blit). SDL_GetError says that the operation is not supported. It does work fine with a 32 bit tile source, however.

Again, there was no mention in the docs, as far as I have read, that 8 bit images are not supported by SDL_BlitScaled. I am assuming it is deliberate, and just not documented, or otherwise, should SDL_BlitScaled support 8 bit rectangle scaling, too?

Apologies again for the nitpicking. Just want to be clear.

All the best, and thanks in advance.

When drawing with the GPU (which is what SDL_Renderer and its drawing functions use), the GPU will clip to whatever your destination is (in this case, your target texture), unless you manually specify a smaller clip rectangle.

(yes, oversimplifications ahoy, but the result is that rendering a polygon, line, etc., that goes off the edge of the target texture won’t have any negative effects)

1 Like

@sjr Thank you, I did not know that! It has directed me to some more reading, but more importantly, knowing this saves me some extra routines that I was prepared to do and that would have been simply “bloat code”.

That said, I have still done the preliminary clipping (suppression, to be more specific) of drawing that is completely off the target. It was the drawing on the transition that was bothering me. As “automatic” clipping had been mentioned elsewhere (on the surface blitting functions), I was naturally hesitant of doing double work and using processor time unnecessarily if it was also applicable to textures.

Thanks again!