Esempio n. 1
0
	void Collider::setMaterial(const std::string &material)
	{
		SCOPE_profile_cpu_function("Physic");

		assert(collider != nullptr && "Invalid Collider");
		collider->setMaterial(material);
	}
Esempio n. 2
0
	void Collider::setFilterGroup(Physics::FilterGroup group)
	{
		SCOPE_profile_cpu_function("Physic");

		assert(collider != nullptr && "Invalid Collider");
		collider->setFilterGroup(group);
	}
Esempio n. 3
0
	void BFCLinkTracker::reset()
	{
		SCOPE_profile_cpu_function("BFC");
		{
			SCOPE_profile_cpu_i("BFC", "ResetLinks");
			for (auto &e : _links)
			{
				// beurk
				if (e != nullptr)
				{
					e->resetBFCTrackerIndex();
					for (auto &cullable : e->_cullables)
					{
						auto &item = e->_bfcBlockFactory->getItem(cullable.getItemId());
						item.setPosition(cullable.getPtr()->setBFCTransform(e->_globalTransformation));
					}
					e = nullptr;
				}
			}
			_links.clear();
		}
		{
			SCOPE_profile_cpu_i("BFC", "ResetFree");
			//beurk
			while (!_free.empty())
				_free.pop();
		}
	}
	void DRBLightElementManager::removeSpotLight(BFCCullableHandle &handle)
	{
		SCOPE_profile_cpu_function("DRB");

		_spotLightPool.destroy(handle.getPtr());
		_bfcBlockManager->deleteItem(handle);
	}
Esempio n. 5
0
	void Collider::setAsTrigger(bool mustBeATrigger)
	{
		SCOPE_profile_cpu_function("Physic");

		assert(collider != nullptr && "Invalid Collider");
		collider->setAsTrigger(mustBeATrigger);
	}
Esempio n. 6
0
	void Collider::setFilterGroup(const std::string &filterName)
	{
		SCOPE_profile_cpu_function("Physic");

		assert(collider != nullptr && "Invalid Collider");
		collider->setFilterGroup(collider->getWorld()->getFilterGroupForFilterName(filterName));
	}
Esempio n. 7
0
	void TextureBuffer::set(GLvoid const *data, GLsizeiptr count)
	{
		SCOPE_profile_cpu_function("TextureBuffer");
		AGE_ASSERT(count <= _count);
		bindBuffer();
		glBufferSubData(GL_TEXTURE_BUFFER, 0, _size * count, data);
	}
Esempio n. 8
0
	void BFCLinkTracker::removeLink(std::size_t index)
	{
		SCOPE_profile_cpu_function("BFC");

		AGE_ASSERT(index != -1 && index < _links.size());
		_links[index] = nullptr;
		_free.push(index);
	}
Esempio n. 9
0
	BufferPrograms & BufferPrograms::clear()
	{
		SCOPE_profile_cpu_function("RenderTimer");
		for (auto &buffer : _buffers) {
			buffer->clear();
		}
		_indices_buffer.clear();
		return (*this);
	}
Esempio n. 10
0
	// Methods
	void Collider::init(Physics::ColliderType colliderType, const std::string &mesh)
	{
		SCOPE_profile_cpu_function("Physic");

		assert(collider == nullptr && "Collider already initialized");
		collider = entity->getScene()->getInstance<Physics::PhysicsInterface>()->getWorld()->createCollider(colliderType, mesh, entity->addComponent<Private::PhysicsData>(entity)->getData());
		collider->collider = this;
		scale(entity->getLink().getScale());
	}
	BFCCullableHandle DRBLightElementManager::addSpotLight()
	{
		SCOPE_profile_cpu_function("DRB");

		auto *drbSpotLight = _spotLightPool.create();

		BFCCullableHandle result = _bfcBlockManager->createItem(drbSpotLight);

		return result;
	}
Esempio n. 12
0
	bool            SceneManager::updateScenes(float time)
	{
		SCOPE_profile_cpu_function("Main thread");

		for (auto &e : _actives)
		{
			if (!e.second->userUpdateBegin(time))
				return false;
			e.second->update(time);
			if (!e.second->userUpdateEnd(time))
				return false;
		}
		return true;
	}
Esempio n. 13
0
	bool MainThread::update()
	{
		SCOPE_profile_cpu_function("Main thread");
		std::chrono::system_clock::time_point waitStart;
		std::chrono::system_clock::time_point waitEnd;
		std::chrono::system_clock::time_point workStart;
		std::chrono::system_clock::time_point workEnd;
		std::size_t workCount = 0;
		std::size_t waitCount = 0;

		workStart = std::chrono::high_resolution_clock::now();

		if (_frameCounter - GetRenderThread()->getCurrentFrameCount() > 2)
		{
			_isRenderFrame = false;
		}
		else
		{
			_isRenderFrame = true;
		}

		if (!_engine->update())
		{
			return false;
		}

		{
			SCOPE_profile_cpu_i("MainThread", "Execute tasks");
			{
				TMQ::MessageBase *task = nullptr;
				while (TMQ::TaskManager::MainThreadGetTask(task))
				{
					SCOPE_profile_cpu_i("MainThread", "Execute task");
					auto result = execute(task);
					assert(result); // we receive a task that we cannot handle
				}
			}
		}

		workEnd = std::chrono::high_resolution_clock::now();
		workCount = std::chrono::duration_cast<std::chrono::microseconds>(workEnd - workStart).count();
		workCount -= waitCount;

		if (_isRenderFrame)
		{
			++_frameCounter;
		}

		return true;
	}
Esempio n. 14
0
	// Inherited Methods
	void Collider::reset(void)
	{
		SCOPE_profile_cpu_function("Physic");

		if (collider != nullptr)
		{
			entity->getScene()->getInstance<Physics::PhysicsInterface>()->getWorld()->destroyCollider(collider);
			collider = nullptr;
		}
		if (!entity->haveComponent<RigidBody>())
		{
			entity->removeComponent<Private::PhysicsData>();
		}
	}
Esempio n. 15
0
	bool TextureBuffer::init(GLsizeiptr count, GLenum internal_format /*GL_R32F */, GLsizeiptr size, GLenum usage /* GL_STATIC_DRAW ...*/)
	{
		SCOPE_profile_cpu_function("TextureBuffer");
		AGE_ASSERT(_bufferHandle == -1 && _textureHandle == -1 && _count == 0 && _size == 0 && _buffer == nullptr);
		_count = count;
		_size = size;

		glGenBuffers(1, &_bufferHandle);
		bindBuffer();
		glBufferData(GL_TEXTURE_BUFFER, size * count, nullptr, usage);
		glGenTextures(1, &_textureHandle);
		bind();
		glTexBuffer(GL_TEXTURE_BUFFER, internal_format, _bufferHandle);
		_buffer = (char*)AGE_MALLOC(size * count);
		return true;
	}
Esempio n. 16
0
	bool BufferPrograms::insert(Vertices &vertices)
	{
		SCOPE_profile_cpu_function("RenderTimer");
		if (vertices.nbr_buffer() != _types.size()) {
			return (false);
		}
		for (auto index = 0ull; index < vertices.nbr_buffer(); ++index) {
			if (_types[index] != vertices.get_type(index)) {
				return (false);
			}
		}
		for (auto &buffer_targeted : _buffers) {
			vertices.set_block_memory(buffer_targeted->push_back(vertices.transfer_data(buffer_targeted->name())), buffer_targeted->name());
		}
		vertices.set_indices_block_memory(_indices_buffer.push_back(vertices.transfer_indices_data()));
		return (true);
	}
Esempio n. 17
0
void GraphicElementManager::removeMesh(BFCCullableHandleGroup &handle)
{
    SCOPE_profile_cpu_function("DRB");

    for (auto &m : handle.getHandles())
    {
        if (m.getPtr<DRBMesh>()->getDatas()->hadRenderMode(RenderModes::AGE_SKINNED))
        {
            _skinnedMeshPool.destroy(m.getPtr());
        }
        else
        {
            _meshPool.destroy(m.getPtr());
        }
        _bfcBlockManager->deleteItem(m);
    }
    handle.getHandles().clear();
}
Esempio n. 18
0
	std::size_t BFCLinkTracker::addLink(BFCLink *link)
	{
		SCOPE_profile_cpu_function("BFC");

		std::size_t result = -1;

		if (_free.empty() == false)
		{
			result = _free.front();
			_links[result] = link;
			_free.pop();
		}
		else
		{
			result = _links.size();
			_links.push_back(link);
		}
		return result;
	}
Esempio n. 19
0
	void Imgui::startUpdate()
	{
		SCOPE_profile_cpu_function("Main thread");

#ifdef AGE_ENABLE_IMGUI
		ImGuiIO& io = ImGui::GetIO();

		auto input = this->_engine->getInstance<AGE::Input>();

		// Setup timestep
		static Timer timer;
		timer.update();
		float elapsedTime = timer.getElapsed();

		io.DeltaTime = elapsedTime == 0.0 ? 0.000000001f : elapsedTime;
		io.MouseDown[0] = _lastMouseState.mouseState[0];
		io.MouseDown[1] = _lastMouseState.mouseState[1];
		io.MouseDown[2] = _lastMouseState.mouseState[2];
		io.MousePos = ImVec2((float)_lastMouseState.mousePosition.x, (float)_lastMouseState.mousePosition.y);
		io.MouseWheel = _lastMouseState.mouseWheel;
		// Start the frame
		ImGui::NewFrame();
#endif
	}
Esempio n. 20
0
BFCCullableHandleGroup GraphicElementManager::addMesh(std::shared_ptr<MeshInstance> mesh, std::shared_ptr<MaterialSetInstance> materialInstance)
{
    SCOPE_profile_cpu_function("DRB");

    BFCCullableHandleGroup result;

    for (auto &submesh : mesh->subMeshs)
    {
        DRBMesh *drbMesh = nullptr;

        if (submesh.isSkinned)
        {
            auto drbMeshSkeleton = _skinnedMeshPool.create();
            drbMesh = drbMeshSkeleton;
        }
        else
        {
            drbMesh = _meshPool.create();
        }


        drbMesh->datas->setVerticesKey(submesh.vertices);
        drbMesh->datas->setPainterKey(submesh.painter);
        drbMesh->datas->setAABB(submesh.boundingBox);

        std::size_t materialIndex = submesh.defaultMaterialIndex < materialInstance->datas.size() ? submesh.defaultMaterialIndex : 0;
        auto &material = materialInstance->datas[materialIndex];

        // we set the material unique id
        drbMesh->material = &material;

        BFCCullableHandle resultMesh = _bfcBlockManager->createItem(drbMesh);
        result.getHandles().push_back(resultMesh);
    }
    return result;
}
Esempio n. 21
0
	void occlusionCulling(std::list<std::shared_ptr<DRBData>> &list, bool drawDebugLines)
	{
		SCOPE_profile_cpu_function("Camera system");

		auto depthMap = GetRenderThread()->getDepthMapManager().getReadableMap();
		//for (auto &e : cameraList->meshs)
		//{
		//	readableDepthMap->testBox()
		//}

		if (depthMap.isValid() == false)
		{
			return;
		}

		auto j = list.begin();
		while (j != std::end(list))
		{
			auto &d = *j;
			auto mesh = std::static_pointer_cast<DRBMeshData>(d);
			if (mesh->hadRenderMode(AGE_OCCLUDER))
			{
				++j;
				continue;
			}
			auto BB = mesh->getAABB();


			glm::vec2 minPoint = glm::vec2(1);
			glm::vec2 maxPoint = glm::vec2(-1);

			float minZ = std::numeric_limits<float>::max();

			for (std::size_t i = 0; i < 8; ++i)
			{
				auto point = depthMap->getMV() * d->getTransformation() * glm::vec4(BB.getCornerPoint(i), 1.0f);
				point /= point.w;

				if (point.x < -1)
				{
					point.x = -1;
				}
				if (point.y < -1)
				{
					point.y = -1;
				}
				if (point.x > 1)
				{
					point.x = 1;
				}
				if (point.y > 1)
				{
					point.y = 1;
				}

				minPoint.x = std::min(minPoint.x, point.x);
				minPoint.y = std::min(minPoint.y, point.y);
				maxPoint.x = std::max(maxPoint.x, point.x);
				maxPoint.y = std::max(maxPoint.y, point.y);

				point.z = (point.z + 1.0f) * 0.5f;
				minZ = std::min(minZ, point.z);
			}

			glm::uvec2 screenMin(((minPoint + glm::vec2(1)) / glm::vec2(2)) * glm::vec2(depthMap->getMipmapWidth(), depthMap->getMipmapHeight()));
			glm::uvec2 screenMax(((maxPoint + glm::vec2(1)) / glm::vec2(2)) * glm::vec2(depthMap->getMipmapWidth(), depthMap->getMipmapHeight()));

			if (minZ < 0)
			{
				minZ = 0;
			}

			if (depthMap->testBox((uint32_t)(minZ * (1 << 24)), screenMin, screenMax) == false)
			{
				list.erase(j++);
				continue;
			}
			if (drawDebugLines)
			{
				GetRenderThread()->getQueue()->emplaceTask<AGE::Commands::ToRender::Draw2DQuad>(glm::vec2(minPoint.x, minPoint.y), glm::vec2(minPoint.x, maxPoint.y), glm::vec2(maxPoint.x, maxPoint.y), glm::vec2(maxPoint.x, minPoint.y), glm::vec3(0, 1, 0));
			}
			++j;
		}
	}
Esempio n. 22
0
	BufferPrograms & BufferPrograms::unbind()
	{
		SCOPE_profile_cpu_function("RenderTimer");
		_vertex_array.unbind();
		return (*this);
	}
Esempio n. 23
0
	void Imgui::renderThreadRenderFn(std::vector<Age_ImDrawList> const &cmd_lists)
	{
		SCOPE_profile_cpu_function("RenderTimer");
		SCOPE_profile_gpu_i("Render IMGUI");
		if (cmd_lists.empty())
			return;
		OpenGLState::glEnable(GL_BLEND);
		OpenGLState::glBlendEquation(GL_FUNC_ADD);
		OpenGLState::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		OpenGLState::glDisable(GL_CULL_FACE);
		OpenGLState::glDisable(GL_DEPTH_TEST);
		OpenGLState::glEnable(GL_SCISSOR_TEST);
		glActiveTexture(GL_TEXTURE0);

		// Setup orthographic projection matrix
		const float width = ImGui::GetIO().DisplaySize.x;
		const float height = ImGui::GetIO().DisplaySize.y;
		const float ortho_projection[4][4] =
		{
			{ 2.0f / width, 0.0f, 0.0f, 0.0f },
			{ 0.0f, 2.0f / -height, 0.0f, 0.0f },
			{ 0.0f, 0.0f, -1.0f, 0.0f },
			{ -1.0f, 1.0f, 0.0f, 1.0f },
		};

		glUseProgram(shader_handle);
		glUniform1i(texture_location, 0);
		glUniformMatrix4fv(ortho_location, 1, GL_FALSE, &ortho_projection[0][0]);
		glBindVertexArray(vao_handle);

		for (int n = 0; n < cmd_lists.size(); n++)
		{
			const Age_ImDrawList& cmd_list = cmd_lists[n];
			const ImDrawIdx* idx_buffer = cmd_list.idx_buffer.data();

			glBindBuffer(GL_ARRAY_BUFFER, vbo_handle);
			size_t needed_vtx_size = cmd_list.vtx_buffer.size() * sizeof(ImDrawVert);
			if (vbo_size < needed_vtx_size)
			{
				// Grow our buffer if needed
				vbo_size = needed_vtx_size + 2000 * sizeof(ImDrawVert);
				glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)vbo_size, NULL, GL_STREAM_DRAW);
			}
			unsigned char* vtx_data = (unsigned char*)glMapBufferRange(GL_ARRAY_BUFFER, 0, needed_vtx_size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
			if (!vtx_data)
				continue;
			memcpy(vtx_data, &cmd_list.vtx_buffer[0], cmd_list.vtx_buffer.size() * sizeof(ImDrawVert));
			glUnmapBuffer(GL_ARRAY_BUFFER);

			for (auto pcmd = cmd_list.commands.begin(); pcmd != cmd_list.commands.end(); pcmd++)
			{
				glBindTexture(GL_TEXTURE_2D, fontTex);
				glScissor((int)pcmd->ClipRect.x, (int)(height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
				glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer);
				idx_buffer += pcmd->ElemCount;
			}
		}

		// Restore modified state
		glBindVertexArray(0);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glUseProgram(0);
		OpenGLState::glDisable(GL_SCISSOR_TEST);
		glBindTexture(GL_TEXTURE_2D, 0);
	}
Esempio n. 24
0
	void TextureBuffer::sendBuffer()
	{
		SCOPE_profile_cpu_function("TextureBuffer");
		bindBuffer();
		glBufferSubData(GL_TEXTURE_BUFFER, 0, _offset * _size, _buffer);
	}
Esempio n. 25
0
void SdlContext::refreshInputs()
{
    SCOPE_profile_cpu_function("RenderTimer");

    SDL_Event events;
    auto input = _dependencyManager->getInstance<Input>();

    input->frameUpdate();
    if (_firstCall)
    {
        _initJoysticks(*input);
        _firstCall = false;
    }
    while (SDL_PollEvent(&events))
    {
        switch (events.type)
        {
        case SDL_KEYDOWN:
            input->keyInputPressed(findAgeMappedKey(events.key.keysym.sym), findAgePhysicalKey(events.key.keysym.scancode));
            break;
        case SDL_KEYUP:
            input->keyInputReleased(findAgeMappedKey(events.key.keysym.sym), findAgePhysicalKey(events.key.keysym.scancode));
            break;
        case SDL_MOUSEBUTTONDOWN:
            input->mouseButtonPressed(findAgeMouseButton(events.button.button));
            break;
        case SDL_MOUSEBUTTONUP:
            input->mouseButtonReleased(findAgeMouseButton(events.button.button));
            break;
        case SDL_MOUSEWHEEL:
            input->setMouseWheel(glm::ivec2(events.wheel.x, events.wheel.y));
            break;
        case SDL_MOUSEMOTION:
            input->setMousePosition(glm::ivec2(events.motion.x, events.motion.y), glm::ivec2(events.motion.xrel, events.motion.yrel));
            break;
        case SDL_JOYDEVICEADDED:
            _addJoystick(*input, events.jdevice.which);
            break;
        case SDL_JOYDEVICEREMOVED:
            _removeJoystick(*input, events.jdevice.which);
            break;
        case SDL_JOYAXISMOTION:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jaxis.which);
            AgeJoystickAxis joyAxis = findAgeJoystickAxis(events.jaxis.axis);
            float value = (float)events.jaxis.value / 32768.0f;
            input->setJoystickAxis(joyId, joyAxis, value);
        }
        break;
        case SDL_JOYBUTTONDOWN:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jbutton.which);
            AgeJoystickButtons joyButton = findAgeJoystickButton(events.jbutton.button);
            input->joystickButtonPressed(joyId, joyButton);
        }
        break;
        case SDL_JOYBUTTONUP:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jbutton.which);
            AgeJoystickButtons joyButton = findAgeJoystickButton(events.jbutton.button);
            input->joystickButtonReleased(joyId, joyButton);
        }
        break;
        case SDL_JOYBALLMOTION:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jball.which);
            input->setJoystickTrackBall(joyId, events.jball.ball, glm::ivec2(events.jball.xrel, events.jball.yrel));
        }
        break;
        case SDL_JOYHATMOTION:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jhat.which);
            AgeJoystickHatDirections joyHatDir = findAgeJoystickHatDirection(events.jhat.value);
            input->setJoystickHat(joyId, events.jhat.hat, joyHatDir);
        }
        break;
        case SDL_WINDOWEVENT:
            input->addWindowInput(findAgeWindowInput(events.window.event));
            break;
        default:
            input->addWindowInput(findAgeWindowInput(events.type));
            break;
        }
    }
    input->sendMouseStateToIMGUI();
}
Esempio n. 26
0
	void RenderCameraSystem::mainUpdate(float time)
	{
		SCOPE_profile_cpu_function("Camera system");
		_scene->getBfcLinkTracker()->reset();

		// check if the render thread does not already have stuff to draw
		if (GetMainThread()->isRenderFrame() == false)
		{
			return;
		}

		std::list<std::shared_ptr<DRBSpotLightDrawableList>> spotLightList;
		std::list<std::shared_ptr<DRBData>> pointLightList;


		for (auto &spotEntity : _spotLights.getCollection())
		{
			auto spot = spotEntity->getComponent<SpotLightComponent>();
			auto spotDrawableList = std::make_shared<DRBSpotLightDrawableList>();
			spotDrawableList->spotLight = spot->getCullableHandle().getPtr()->getDatas();

			auto spotData = std::static_pointer_cast<DRBSpotLightData>(spotDrawableList->spotLight);

			glm::mat4 spotViewProj = spot->updateShadowMatrix();

			Frustum spotlightFrustum;
			spotlightFrustum.setMatrix(spotViewProj);

			// Draw spotlight frustum debug:
			glm::vec4 worldPos = glm::inverse(spotViewProj) * glm::vec4(-1, -1, -1, 1.0f);
			glm::vec3 aNear = glm::vec3(worldPos / worldPos.w);
			worldPos = glm::inverse(spotViewProj) * glm::vec4(-1, 1, -1, 1.0f);
			glm::vec3 bNear = glm::vec3(worldPos / worldPos.w);
			worldPos = glm::inverse(spotViewProj) * glm::vec4(1, 1, -1, 1.0f);
			glm::vec3 cNear = glm::vec3(worldPos / worldPos.w);
			worldPos = glm::inverse(spotViewProj) * glm::vec4(1, -1, -1, 1.0f);
			glm::vec3 dNear = glm::vec3(worldPos / worldPos.w);
			worldPos = glm::inverse(spotViewProj) * glm::vec4(-1, -1, 1, 1.0f);
			glm::vec3 aFar = glm::vec3(worldPos / worldPos.w);
			worldPos = glm::inverse(spotViewProj) * glm::vec4(-1, 1, 1, 1.0f);
			glm::vec3 bFar = glm::vec3(worldPos / worldPos.w);
			worldPos = glm::inverse(spotViewProj) * glm::vec4(1, 1, 1, 1.0f);
			glm::vec3 cFar = glm::vec3(worldPos / worldPos.w);
			worldPos = glm::inverse(spotViewProj) * glm::vec4(1, -1, 1, 1.0f);
			glm::vec3 dFar = glm::vec3(worldPos / worldPos.w);

			glm::vec3 color = glm::vec3(1, 0, 0);
			bool activateDepth = true;

			if (_drawDebugLines)
			{
				AGE::GetRenderThread()->getQueue()->emplaceTask<Commands::ToRender::Draw3DQuad>(aNear, bNear, cNear, dNear, color, activateDepth);
				AGE::GetRenderThread()->getQueue()->emplaceTask<Commands::ToRender::Draw3DQuad>(aFar, bFar, cFar, dFar, color, activateDepth);
				AGE::GetRenderThread()->getQueue()->emplaceTask<Commands::ToRender::Draw3DLine>(aNear, aFar, color, activateDepth);
				AGE::GetRenderThread()->getQueue()->emplaceTask<Commands::ToRender::Draw3DLine>(bNear, bFar, color, activateDepth);
				AGE::GetRenderThread()->getQueue()->emplaceTask<Commands::ToRender::Draw3DLine>(cNear, cFar, color, activateDepth);
				AGE::GetRenderThread()->getQueue()->emplaceTask<Commands::ToRender::Draw3DLine>(dNear, dFar, color, activateDepth);
			}

			std::atomic_size_t counter = 0;

			LFList<BFCItem> meshInLightList;
			std::size_t meshBlocksToCullNumber = _scene->getBfcBlockManagerFactory()->getBlockNumberToCull(BFCCullableType::CullableMesh);

			for (std::size_t i = 0; i < meshBlocksToCullNumber; ++i)
			{
				BFCBlockManagerFactory *bf = _scene->getBfcBlockManagerFactory();
				EmplaceTask<Tasks::Basic::VoidFunction>([bf, i, &spotlightFrustum, &counter, &meshInLightList](){
					bf->cullOnBlock(BFCCullableType::CullableMesh, meshInLightList, spotlightFrustum, i);
					counter.fetch_add(1);
				});
			}

			{
				SCOPE_profile_cpu_i("Camera system", "Cull for spots");
				while (counter < meshBlocksToCullNumber )
				{
				}
				//GetMainThread()->computeTasksWhile(std::function<bool()>([&counter, meshBlocksToCullNumber]() {
				//	return counter >= meshBlocksToCullNumber;
				//}));
			}

			while (meshInLightList.getSize() > 0)
			{
				spotDrawableList->meshs.push_back(meshInLightList.pop()->getDrawable()->getDatas());
			}

			spotLightList.push_back(spotDrawableList);
		}
		for (auto &pointLightEntity : _pointLights.getCollection())
		{
			auto point = pointLightEntity->getComponent<PointLightComponent>();
			
			pointLightList.push_back(point->getCullableHandle().getPtr()->getDatas());
		}

		for (auto &cameraEntity : _cameras.getCollection())
		{
			Frustum cameraFrustum;
			auto camera = cameraEntity->getComponent<CameraComponent>();

			std::atomic_size_t counter = 0;

			auto cameraList = std::make_shared<DRBCameraDrawableList>();
			cameraList->cameraInfos.data = camera->getData();
			cameraList->cameraInfos.view = glm::inverse(cameraEntity->getLink().getGlobalTransform());

			cameraFrustum.setMatrix(camera->getProjection() * cameraList->cameraInfos.view);

			LFList<BFCItem> meshList;
			LFList<BFCItem> pointLightListToCull;
			std::size_t meshBlocksToCullNumber = _scene->getBfcBlockManagerFactory()->getBlockNumberToCull(BFCCullableType::CullableMesh);
			std::size_t pointLightBlocksToCullNumber = _scene->getBfcBlockManagerFactory()->getBlockNumberToCull(BFCCullableType::CullablePointLight);
			std::size_t totalToCullNumber = meshBlocksToCullNumber + pointLightBlocksToCullNumber;
			
			for (std::size_t i = 0; i < meshBlocksToCullNumber; ++i)
			{
				BFCBlockManagerFactory *bf = _scene->getBfcBlockManagerFactory();
				EmplaceTask<Tasks::Basic::VoidFunction>([bf, i, &cameraFrustum, &counter, &meshList](){
					bf->cullOnBlock(BFCCullableType::CullableMesh, meshList, cameraFrustum, i);
					counter.fetch_add(1);
				});
			}

			for (std::size_t i = 0; i < pointLightBlocksToCullNumber; ++i)
			{
				BFCBlockManagerFactory *bf = _scene->getBfcBlockManagerFactory();
				EmplaceTask<Tasks::Basic::VoidFunction>([bf, i, &cameraFrustum, &counter, &pointLightListToCull](){
					bf->cullOnBlock(BFCCullableType::CullablePointLight, pointLightListToCull, cameraFrustum, i);
					counter.fetch_add(1);
				});
			}

			{
				SCOPE_profile_cpu_i("Camera system", "Cull for cam");
				while (counter < totalToCullNumber)
				{ }
				//GetMainThread()->computeTasksWhile(std::function<bool()>([&counter, totalToCullNumber]() {
				//	return counter >= totalToCullNumber;
				//}));
			}

			{
				SCOPE_profile_cpu_i("Camera system", "Copy LFList to std");
				while (meshList.getSize() > 0)
				{
					cameraList->meshs.push_back(meshList.pop()->getDrawable()->getDatas());
				}

				while (pointLightListToCull.getSize() > 0)
				{
					cameraList->pointLights.push_back(pointLightListToCull.pop()->getDrawable()->getDatas());
				}
			}
			if (OcclusionConfig::g_Occlusion_is_enabled)
			{
				occlusionCulling(cameraList->meshs, _drawDebugLines);
			}

			cameraList->spotLights = spotLightList;
			cameraList->pointLights = pointLightList;
			AGE::GetRenderThread()->getQueue()->emplaceTask<AGE::DRBCameraDrawableListCommand>(cameraList);
		}
	}