| 162 | } |
| 163 | |
| 164 | void BufferValues::draw(const mat4& projection, const mat4& view_inv) { |
| 165 | const auto stage = game_object_ref().get_stage(); |
| 166 | if (!stage.has_value()) { |
| 167 | return; |
| 168 | } |
| 169 | const auto cam_obj = stage->get().get_game_object("camera"); |
| 170 | if (!cam_obj.has_value()) { |
| 171 | return; |
| 172 | } |
| 173 | const auto camera_opt = |
| 174 | cam_obj->get().get_component<Camera>("camera_component"); |
| 175 | if (!camera_opt.has_value()) { |
| 176 | return; |
| 177 | } |
| 178 | const auto& camera = camera_opt->get(); |
| 179 | |
| 180 | if (const auto zoom = camera.compute_zoom(); |
| 181 | zoom > BufferConstants::ZOOM_BORDER_THRESHOLD) { |
| 182 | const auto buffer_pose = game_object_ref().get_pose(); |
| 183 | |
| 184 | const auto buffer_component_opt = |
| 185 | game_object_ref().get_component<Buffer>("buffer_component"); |
| 186 | if (!buffer_component_opt.has_value()) { |
| 187 | return; |
| 188 | } |
| 189 | const auto& buffer_component = buffer_component_opt->get(); |
| 190 | const auto buffer_width_f = buffer_component.buffer_width_f; |
| 191 | const auto buffer_height_f = buffer_component.buffer_height_f; |
| 192 | const auto channels = buffer_component.channels; |
| 193 | const auto channels_f = static_cast<float>(channels); |
| 194 | |
| 195 | const auto tl_ndc = vec4{-1.0f, 1.0f, 0.0f, 1.0f}; |
| 196 | const auto br_ndc = vec4{1.0f, -1.0f, 0.0f, 1.0f}; |
| 197 | const auto vp_inv = (projection * view_inv * buffer_pose).inv(); |
| 198 | auto tl = vp_inv * tl_ndc; |
| 199 | auto br = vp_inv * br_ndc; |
| 200 | |
| 201 | // Since the clip ROI may be rotated, we need to re-compute TL and BR |
| 202 | // from their Xs and Ys |
| 203 | const auto tl_x = (std::min)(tl.x(), br.x()); |
| 204 | const auto tl_y = (std::min)(tl.y(), br.y()); |
| 205 | const auto br_x = (std::max)(tl.x(), br.x()); |
| 206 | const auto br_y = (std::max)(tl.y(), br.y()); |
| 207 | tl.x() = tl_x; |
| 208 | tl.y() = tl_y; |
| 209 | br.x() = br_x; |
| 210 | br.y() = br_y; |
| 211 | |
| 212 | const auto lower_x = |
| 213 | static_cast<int>(std::clamp(truncf(tl.x()) - 1.0f, |
| 214 | -buffer_width_f / 2.0f, |
| 215 | buffer_width_f / 2.0f - 1.0f)); |
| 216 | const auto upper_x = |
| 217 | static_cast<int>(std::clamp(ceilf(br.x()) + 1.0f, |
| 218 | -(buffer_width_f + 1.0f) / 2.0f + 1.0f, |
| 219 | (buffer_width_f + 1.0f) / 2.0f)); |
| 220 | |
| 221 | const auto lower_y = |
nothing calls this directly
no test coverage detected