| 167 | } |
| 168 | |
| 169 | void sample_engine_performance::on_draw() |
| 170 | { |
| 171 | glfwMakeContextCurrent(window); |
| 172 | |
| 173 | int width, height; |
| 174 | glfwGetWindowSize(window, &width, &height); |
| 175 | |
| 176 | imgui->begin_frame(); |
| 177 | |
| 178 | const uint32_t viewIndex = 0; |
| 179 | const float4x4 projectionMatrix = cam.get_projection_matrix(float(width) / float(height)); |
| 180 | const float4x4 viewMatrix = cam.get_view_matrix(); |
| 181 | const float4x4 viewProjectionMatrix = projectionMatrix * viewMatrix; |
| 182 | const frustum camera_frustum(viewProjectionMatrix); |
| 183 | |
| 184 | glEnable(GL_BLEND); |
| 185 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 186 | |
| 187 | payload.views.clear(); |
| 188 | payload.views.emplace_back(view_data(viewIndex, cam.pose, projectionMatrix)); |
| 189 | |
| 190 | payload.render_components.clear(); |
| 191 | |
| 192 | { |
| 193 | simple_cpu_timer t; |
| 194 | t.start(); |
| 195 | const std::vector<entity> visible_entity_list = scene.get_collision_system()->get_visible_entities(camera_frustum); |
| 196 | t.stop(); |
| 197 | |
| 198 | ImGui::Text("Frustum Cull Took %f ms", (float)t.elapsed_ms()); |
| 199 | ImGui::Text("Visible Entities %i", visible_entity_list.size()); |
| 200 | |
| 201 | auto assemble_render_component = [](base_object & t) |
| 202 | { |
| 203 | render_component r; |
| 204 | r.material = t.get_component<material_component>(); |
| 205 | r.mesh = t.get_component<mesh_component>(); |
| 206 | r.world_matrix = t.get_component<transform_component>()->get_world_transform().matrix(); |
| 207 | r.render_sort_order = 0; |
| 208 | return r; |
| 209 | }; |
| 210 | |
| 211 | // Render everything |
| 212 | for (auto & t : scene.get_graph().graph_objects) |
| 213 | { |
| 214 | render_component r = assemble_render_component(t.second); |
| 215 | payload.render_components.emplace_back(r); |
| 216 | }; |
| 217 | |
| 218 | for (size_t i = 0; i < visible_entity_list.size(); ++i) |
| 219 | { |
| 220 | const entity e = visible_entity_list[i]; |
| 221 | base_object & obj = scene.get_graph().get_object(e); |
| 222 | render_component r = assemble_render_component(obj); |
| 223 | payload.render_components.emplace_back(r); |
| 224 | } |
| 225 | |
| 226 | } |
nothing calls this directly
no test coverage detected