Render one frame using the current state of every object in the world */
| 76 | Render one frame using the current state of every object in the world |
| 77 | */ |
| 78 | void RenderEngine::Draw(){ |
| 79 | //get the active camera |
| 80 | auto worldOwning = Ref<World>(world); |
| 81 | auto components = worldOwning->Components(); |
| 82 | auto allcams = components.GetAllComponentsOfType<CameraComponent>(); |
| 83 | |
| 84 | //set the view transform - all entities drawn will use this matrix |
| 85 | for (auto& cam : allcams) { |
| 86 | auto owning = Ref<CameraComponent>(cam); |
| 87 | if (owning->isActive()) { |
| 88 | //TODO: set projection |
| 89 | auto size = surface->GetDrawableArea(); |
| 90 | owning->SetTargetSize(size.width, size.height); |
| 91 | MaterialManager::SetProjectionMatrix(cam->GenerateProjectionMatrix()); |
| 92 | MaterialManager::SetViewMatrix(cam->GenerateViewMatrix()); |
| 93 | break; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | //apply transforms for only entities that need to be rendered |
| 98 | auto toDraw = components.GetAllComponentsOfSubclass<RenderableComponent>(); |
| 99 | |
| 100 | // Begin recording commands |
| 101 | commands->Begin(); |
| 102 | |
| 103 | // Clear buffers |
| 104 | commands->Clear(LLGL::ClearFlags::Color | LLGL::ClearFlags::Depth); |
| 105 | |
| 106 | // Set the render context as the initial render target |
| 107 | commands->BeginRenderPass(*surface->GetContext()); |
| 108 | |
| 109 | // Set viewport and scissor rectangle |
| 110 | commands->SetViewport(surface->GetContext()->GetResolution()); |
| 111 | |
| 112 | //iterate through renderables and call Draw |
| 113 | for (auto& e : toDraw) { |
| 114 | e->Draw(commands); |
| 115 | } |
| 116 | |
| 117 | commands->EndRenderPass(); |
| 118 | |
| 119 | commands->End(); |
| 120 | queue->Submit(*commands); |
| 121 | // Present the result on the screen |
| 122 | surface->GetContext()->Present(); |
| 123 | |
| 124 | //iterate through materials to draw each one |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | @return the name of the current rendering API |
nothing calls this directly
no test coverage detected