| 3 | namespace dp |
| 4 | { |
| 5 | std::array<float, 16> MakeProjection(dp::ApiVersion apiVersion, float left, float right, float bottom, float top) |
| 6 | { |
| 7 | std::array<float, 16> result = {}; |
| 8 | |
| 9 | // Projection matrix is calculated for [-1;1] depth-space, in some APIs (e.g. Metal) |
| 10 | // depth-space is [0;1], so we have to remap projection matrix. |
| 11 | float depthScale = 1.0f; |
| 12 | float depthOffset = 0.0f; |
| 13 | if (apiVersion == dp::ApiVersion::Metal) |
| 14 | { |
| 15 | depthScale = 0.5f; |
| 16 | depthOffset = 0.5f; |
| 17 | } |
| 18 | |
| 19 | float const width = right - left; |
| 20 | float const height = top - bottom; |
| 21 | float const depth = kMaxDepth - kMinDepth; |
| 22 | |
| 23 | result[0] = 2.0f / width; |
| 24 | result[3] = -(right + left) / width; |
| 25 | result[5] = 2.0f / height; |
| 26 | result[7] = -(top + bottom) / height; |
| 27 | result[10] = -2.0f * depthScale / depth; |
| 28 | result[11] = depthOffset - (kMaxDepth + kMinDepth) / depth; |
| 29 | result[15] = 1.0; |
| 30 | |
| 31 | return result; |
| 32 | } |
| 33 | } // namespace dp |
no outgoing calls
no test coverage detected