Texture SamplingI implemented a texture sampling memory adapter class over the last few days. It is capable of point sampling and bilinear sampling, with mip maps and potentially some form of anisotropic sampling to be used at some point in the future. They may come some time down the road, but for now I'll stick with the bilinear sampling due to time constraints.
InterpolationThe use of texture coordinates and texture sampling requires interpolation of the coordinates as well as colors (in the case of bilinear sampling). Typically texture coords and colors can be represented with a 4-tuple of whatever precision variables you are working with. In my case it happens to be a 32-bit floating point variable for each element. A *operator overload gets defined for multiplying by a scalar element, and you can perform interpolation on your 4-tuple object.
If you are using a class to represent your colors as mentioned above, everything is just fine. However, if you are using a built in type things aren't quite as easy. If using an unsigned int for each pixel color in the frame buffer (which is fairly common since the most common desktop color mode is 24 bit) then you can't use simple interpolation like this. You have to mask out each channel, interpolate it, then put it back together. If you don't, it ends up with a funny looking wash of colors anywhere that the texture transitions colors.
This is a pain, and is not very clean to work with either.
The alternatives are to try to use some form of variable casting to access each element as needed (in this example, casting the pixel color to a char, then accessing each element as if it were a 0-255 value) or you can wrap the unsigned int into a 4-tuple type of class. I ended up wrapping it in its own class, which actually helped my overall design quite a bit. The concept behind the engine is to have template classes serve as the memory 'adapters' for various resources. By wrapping the color variable, I can make use of custom template operations - as long as all of the classes that will instantiate the template support a member function, then I can use them in the adapter classes without any trouble.
For example, my sampler adapter can be instantiated to sample a 2D array of ColorRGB objects (my unsigned int wrapper) or CVector4f objects (4-tuple of floats) or whatever other combination I need. This effectively lets me support any format of image surface (in D3D lingo) without even writing new code. It is much more work to implement the templates, but it is so worth it when its all finished up.