| 59 | // once |
| 60 | |
| 61 | static inline uint32_t MipCoordFromBase(const uint32_t coord, const uint32_t mip, const uint32_t dim) |
| 62 | { |
| 63 | const uint32_t mipDim = (dim >> mip) > 0 ? (dim >> mip) : 1; |
| 64 | |
| 65 | // for mip levels where we more than half (e.g. 15x15 to 7x7) the coord can't be shifted by the |
| 66 | // mip. |
| 67 | // e.g. if the top level is 960x540 an x coordinate of 950 would be shifted by 7 down to 7, but |
| 68 | // mip 7 is 7x4 so the max x co-ordinate is 6. Instead we need to get the float value on the top |
| 69 | // mip, multiply by the mip dimension, and floor it |
| 70 | |
| 71 | const float coordf = float(coord) / float(dim); |
| 72 | |
| 73 | // we add 1e-6 to account for float errors, where we might not get back coord after rounding down |
| 74 | // in the coordf calculation even when mipDim == dim. This will not affect the rounding for any |
| 75 | // realistic texture sizes - even for a dim of 16383 and coord of 16382 |
| 76 | return uint32_t(mipDim * (coordf + 1e-6f)); |
| 77 | } |
| 78 | |
| 79 | static inline uint32_t BaseCoordFromMip(uint32_t coord, const uint32_t mip, const uint32_t dim) |
| 80 | { |
no outgoing calls
no test coverage detected