Sounds like I probably should see if I should do it via modulo vs keeping things as is. ...
Or use the &-trick if your size is a power of two, i.e. i%j = i&(j-1) if j is
a power of two.
... (Is there theoretically a way to extend the renderer juuuuuuuuuuuust wide enough to have it always get you valid graphics data on screen?) ...
Yes.
Out of my head...
Guess you have an effect resp. mapping which will distort the screen. When
going over the output screen (a subset of the range of said mapping) while
using the inverse mapping of the given one, then you will find for each pixel
(x,y) on the screen the corresponding pixel in the domain of the mapping, i.e.
in your undistorted image, which, unter said mapping, gets distorted to the
(x,y) position you're currently at.
Nothing new so far.
But now imagine you inverse-map all the boundary points of the screen, then,
given that the inverse mapping is sound in the first place, you will find a
bounded set in the domain. Computing the bounding box of this set of points
will give you the maximal extent you need to render to cover each point of the
screen under the given mapping/distortion.
So for example. Say you already have an image of your rendering of a given
size and you want to have a lens (a faked one, 2d) rolling over said image.
Such a lens only does some radial scaling, basically. However, if the scaling
is large enough, then the inverse mapping will address points outside of your
rendered image with you having to set these pixels black (whatever). But now
the lens has some finite extent on your rendered image. It's a circle, usually.
If you re-project this circle, you will find the extent you need to render
your image at, to address every pixel reached by the lens (by the inverse
mapping).
Edit:
I think we should switch over to the indie thread on this.
Edit II:
Regarding the lens, the inverse mapping of the lens' boundary (depending on
the scaling/magnification factor) may actually turn out to be a pretty huge
region in the domain of the mapping, leading to a huge render target degrading
performance. Hence, either a limit needs to be set for the maximum render
target or the lens' scaling/magnification factor needs to be limited if you
won't have a lens displaying black pixel inside of it. What I wanna say is;
the approach described above won't work without any bounds. However, it all
depends on the mapping.