first of all many many thanks for all the suggestions. That's much more than I've expected :-).
I currently implemented special functions for power-of-two textures:
Point2D TilePow2(const Point2D& coord) const{ return Point2D(coord.X & ((int)m_width - 1), coord.Y & (m_height - 1));}Point2D MirrorPow2(const Point2D& coord) const{ Point2D result; result.X = coord.X & ((int)m_width - 1); // fast tiling // handle negative coordinates if(coord.X < 0) { int x = -coord.X - 1; // note that negative coords do not start with 0 // even tiles are flipped if(((x / m_width) % 2) == 0) { result.X = m_width - result.X - 1; } // odd tiles simply need to be shifted into positive range else { result.X += m_width; } } // odd tiles are flipped else if(((coord.X / m_width) % 2) != 0) { result.X = m_width - result.X - 1; } result.Y = coord.Y & ((int)m_height - 1); // fast tiling // handle negative coordinates if(coord.Y < 0) { int y = -coord.Y - 1; // note that negative coords do not start with 0 // even tiles are flipped if(((y / m_height) % 2) == 0) { result.Y = m_height - result.Y - 1; } // odd tiles simply need to be shifted into positive range else { result.Y += m_height; } } // odd tiles are flipped else if(((coord.Y / m_height) % 2) != 0) { result.Y = m_height - result.Y - 1; } return result;}
This already gave me some 10% more performance :-). But still, the divides and modulus in the if-statements are the bottlenecks.
@Adam_42 I tried out the code and it gives exeptions. The implementation is as follows:
Point2D MirrorPow2(const Point2D& coord){ Point2D result; result.X = coord.X & ((2 << m_powerWidth) - 1); // fast tiling result.Y = coord.Y & ((2 << m_powerHeight) - 1); // fast tiling // Mirror X const int bMirrorX = (result.X << (31 - m_powerWidth)) >> 31; result.X ^= bMirrorX; result.X += ((2 << m_powerWidth) + 1) & bMirrorX; // Mirror Y const int bMirrorY = (result.Y << (31 - m_powerHeight)) >> 31; result.Y ^= bMirrorY; result.Y += ((2 << m_powerHeight) + 1) & bMirrorY; return result;}
Image size is 128x128, powerWidth/powerHeight is 7, and the input coord is (127/128). The problem is that
result.Y = coord.Y & ((2 << m_powerHeight) - 1);
does not tile. The result still is 128. Any ideas?
Cheers,
data