.. _program_listing_file_PrismEngine_src_renderSystem.cpp: Program Listing for File renderSystem.cpp ========================================= |exhale_lsh| :ref:`Return to documentation for file ` (``PrismEngine/src/renderSystem.cpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #include "renderSystem.h" #include "cameraComponent.h" #include "transformComponent.h" #include "meshComponent.h" #include "materialComponent.h" #include "lightsComponent.h" void prism::scene::RenderSystem::update() { if (renderer->isRenderingActive()) { renderer->beginFrame(); auto cameras = scene->getEntitiesWithAll(); for (auto camera : cameras) { CameraComponent* cameraComponent = scene->getComponent(camera); if (cameraComponent->isActive) { TransformComponent* transformComponent = scene->getComponent(camera); renderer->updateCamera(transformComponent, cameraComponent); } } auto forRenderingEntites = scene->getEntitiesWithAll(); std::vector renderData; std::map> instances; MaterialComponent defaultTexture = { INVALID_TEXTURE_ID }; for (auto entity : forRenderingEntites) { MaterialComponent* texture; if (scene->getComponent(entity) != nullptr) { texture = scene->getComponent(entity); } else { texture = &defaultTexture; } instances[scene->getComponent(entity)->mesh].push_back({ scene->getComponent(entity), texture }); } for (auto instance : instances) { for (auto renData : instance.second) { renderData.push_back(renData); } } prism::render::LightData lightData; auto pointsLightEntitys = scene->getEntitiesWith(); for (auto pointLightEntity : pointsLightEntitys) { PointLightComponent pointsLight = *scene->getComponent(pointLightEntity); if (auto transform = scene->getComponent(pointLightEntity)) { pointsLight.pos += transform->pos; } lightData.pointLights.push_back(pointsLight); } auto directionalLightEntitys = scene->getEntitiesWith(); for (auto directionalLightEntity : directionalLightEntitys) { DirectionalLightComponents dirLight = *scene->getComponent(directionalLightEntity); lightData.directionalLights.push_back(dirLight); } renderer->updateInstances(renderData); renderer->updateLights(&lightData); renderer->beginRender(); renderer->bindDefault(); renderer->bindObjectsData(); uint32_t instanceOffset = 0; for (auto instance : instances) { renderer->drawMesh(instance.first, instance.second.size(), instanceOffset); instanceOffset+=instance.second.size(); } renderer->endRender(); renderer->endFrame(); } }