X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Fcommon%2Frender-manager.cpp;h=8db070bd05d79bf99a6d8ca086eb51eb526f63e2;hb=73d9eb4329d780832541e1d1df3d97e992666cc7;hp=188ed7e9b78533e6f6ea7f36f5174256cc65ef5f;hpb=81e9db18900720bafcfb10171baab55fa5950001;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/common/render-manager.cpp b/dali/internal/render/common/render-manager.cpp index 188ed7e..8db070b 100644 --- a/dali/internal/render/common/render-manager.cpp +++ b/dali/internal/render/common/render-manager.cpp @@ -24,11 +24,11 @@ // INTERNAL INCLUDES #include #include -#include #include #include +#include #include #include @@ -36,12 +36,16 @@ #include #include #include +#include #include #include #include #include +#include #include +#include + namespace Dali { namespace Internal @@ -55,6 +59,43 @@ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_REN } // unnamed namespace #endif +namespace +{ +inline Graphics::Rect2D RecalculateScissorArea(Graphics::Rect2D scissorArea, int orientation, Rect viewportRect) +{ + Graphics::Rect2D newScissorArea; + + if(orientation == 90) + { + newScissorArea.x = viewportRect.height - (scissorArea.y + scissorArea.height); + newScissorArea.y = scissorArea.x; + newScissorArea.width = scissorArea.height; + newScissorArea.height = scissorArea.width; + } + else if(orientation == 180) + { + newScissorArea.x = viewportRect.width - (scissorArea.x + scissorArea.width); + newScissorArea.y = viewportRect.height - (scissorArea.y + scissorArea.height); + newScissorArea.width = scissorArea.width; + newScissorArea.height = scissorArea.height; + } + else if(orientation == 270) + { + newScissorArea.x = scissorArea.y; + newScissorArea.y = viewportRect.width - (scissorArea.x + scissorArea.width); + newScissorArea.width = scissorArea.height; + newScissorArea.height = scissorArea.width; + } + else + { + newScissorArea.x = scissorArea.x; + newScissorArea.y = scissorArea.y; + newScissorArea.width = scissorArea.width; + newScissorArea.height = scissorArea.height; + } + return newScissorArea; +} +} // namespace /** * Structure to contain internal data */ @@ -64,9 +105,7 @@ struct RenderManager::Impl Integration::DepthBufferAvailable depthBufferAvailableParam, Integration::StencilBufferAvailable stencilBufferAvailableParam, Integration::PartialUpdateAvailable partialUpdateAvailableParam) - : context(graphicsController.GetGlAbstraction(), &sceneContextContainer), - currentContext(&context), - graphicsController(graphicsController), + : graphicsController(graphicsController), renderQueue(), renderAlgorithms(graphicsController), frameCount(0u), @@ -83,10 +122,11 @@ struct RenderManager::Impl partialUpdateAvailable(partialUpdateAvailableParam) { // Create thread pool with just one thread ( there may be a need to create more threads in the future ). - threadPool = std::unique_ptr(new Dali::ThreadPool()); + threadPool = std::make_unique(); threadPool->Initialize(1u); - uniformBufferManager.reset(new Render::UniformBufferManager(&graphicsController)); + uniformBufferManager = std::make_unique(&graphicsController); + pipelineCache = std::make_unique(graphicsController); } ~Impl() @@ -96,7 +136,7 @@ struct RenderManager::Impl void AddRenderTracker(Render::RenderTracker* renderTracker) { - DALI_ASSERT_DEBUG(renderTracker != NULL); + DALI_ASSERT_DEBUG(renderTracker != nullptr); mRenderTrackers.PushBack(renderTracker); } @@ -105,33 +145,6 @@ struct RenderManager::Impl mRenderTrackers.EraseObject(renderTracker); } - Context* CreateSceneContext() - { - Context* context = new Context(graphicsController.GetGlAbstraction()); - sceneContextContainer.PushBack(context); - return context; - } - - void DestroySceneContext(Context* sceneContext) - { - auto iter = std::find(sceneContextContainer.Begin(), sceneContextContainer.End(), sceneContext); - if(iter != sceneContextContainer.End()) - { - (*iter)->GlContextDestroyed(); - sceneContextContainer.Erase(iter); - } - } - - Context* ReplaceSceneContext(Context* oldSceneContext) - { - Context* newContext = new Context(graphicsController.GetGlAbstraction()); - - oldSceneContext->GlContextDestroyed(); - - std::replace(sceneContextContainer.begin(), sceneContextContainer.end(), oldSceneContext, newContext); - return newContext; - } - void UpdateTrackers() { for(auto&& iter : mRenderTrackers) @@ -141,12 +154,8 @@ struct RenderManager::Impl } // the order is important for destruction, - // programs are owned by context at the moment. - Context context; ///< Holds the GL state of the share resource context - Context* currentContext; ///< Holds the GL state of the current context for rendering - OwnerContainer sceneContextContainer; ///< List of owned contexts holding the GL state per scene - Graphics::Controller& graphicsController; - RenderQueue renderQueue; ///< A message queue for receiving messages from the update-thread. + Graphics::Controller& graphicsController; + RenderQueue renderQueue; ///< A message queue for receiving messages from the update-thread. std::vector sceneContainer; ///< List of pointers to the scene graph objects of the scenes @@ -166,10 +175,11 @@ struct RenderManager::Impl OwnerContainer mRenderTrackers; ///< List of render trackers - ProgramController programController; ///< Owner of the GL programs + ProgramController programController; ///< Owner of the programs Render::ShaderCache shaderCache; ///< The cache for the graphics shaders std::unique_ptr uniformBufferManager; ///< The uniform buffer manager + std::unique_ptr pipelineCache; Integration::DepthBufferAvailable depthBufferAvailable; ///< Whether the depth buffer is available Integration::StencilBufferAvailable stencilBufferAvailable; ///< Whether the stencil buffer is available @@ -185,8 +195,8 @@ RenderManager* RenderManager::New(Graphics::Controller& graphicsCo Integration::StencilBufferAvailable stencilBufferAvailable, Integration::PartialUpdateAvailable partialUpdateAvailable) { - RenderManager* manager = new RenderManager; - manager->mImpl = new Impl(graphicsController, + auto* manager = new RenderManager; + manager->mImpl = new Impl(graphicsController, depthBufferAvailable, stencilBufferAvailable, partialUpdateAvailable); @@ -208,48 +218,14 @@ RenderQueue& RenderManager::GetRenderQueue() return mImpl->renderQueue; } -void RenderManager::ContextCreated() -{ - mImpl->context.GlContextCreated(); - mImpl->programController.GlContextCreated(); - - // renderers, textures and gpu buffers cannot reinitialize themselves - // so they rely on someone reloading the data for them -} - -void RenderManager::ContextDestroyed() -{ - mImpl->context.GlContextDestroyed(); - mImpl->programController.GlContextDestroyed(); - - //Inform textures - for(auto&& texture : mImpl->textureContainer) - { - texture->Destroy(); - } - - //Inform framebuffers - for(auto&& framebuffer : mImpl->frameBufferContainer) - { - framebuffer->Destroy(); - } - - // inform context - for(auto&& context : mImpl->sceneContextContainer) - { - context->GlContextDestroyed(); - } -} - void RenderManager::SetShaderSaver(ShaderSaver& upstream) { - mImpl->programController.SetShaderSaver(upstream); } void RenderManager::AddRenderer(OwnerPointer& renderer) { // Initialize the renderer as we are now in render thread - renderer->Initialize(mImpl->graphicsController, mImpl->programController, mImpl->shaderCache, *(mImpl->uniformBufferManager.get())); + renderer->Initialize(mImpl->graphicsController, mImpl->programController, mImpl->shaderCache, *(mImpl->uniformBufferManager.get()), *(mImpl->pipelineCache.get())); mImpl->rendererContainer.PushBack(renderer.Release()); } @@ -324,7 +300,7 @@ void RenderManager::AddFrameBuffer(OwnerPointer& frameBuffe void RenderManager::RemoveFrameBuffer(Render::FrameBuffer* frameBuffer) { - DALI_ASSERT_DEBUG(NULL != frameBuffer); + DALI_ASSERT_DEBUG(nullptr != frameBuffer); // Find the sampler, use reference so we can safely do the erase for(auto&& iter : mImpl->frameBufferContainer) @@ -341,14 +317,12 @@ void RenderManager::RemoveFrameBuffer(Render::FrameBuffer* frameBuffer) void RenderManager::InitializeScene(SceneGraph::Scene* scene) { - scene->Initialize(*mImpl->CreateSceneContext(), mImpl->graphicsController, mImpl->depthBufferAvailable, mImpl->stencilBufferAvailable); + scene->Initialize(mImpl->graphicsController, mImpl->depthBufferAvailable, mImpl->stencilBufferAvailable); mImpl->sceneContainer.push_back(scene); } void RenderManager::UninitializeScene(SceneGraph::Scene* scene) { - mImpl->DestroySceneContext(scene->GetContext()); - auto iter = std::find(mImpl->sceneContainer.begin(), mImpl->sceneContainer.end(), scene); if(iter != mImpl->sceneContainer.end()) { @@ -358,8 +332,7 @@ void RenderManager::UninitializeScene(SceneGraph::Scene* scene) void RenderManager::SurfaceReplaced(SceneGraph::Scene* scene) { - Context* newContext = mImpl->ReplaceSceneContext(scene->GetContext()); - scene->Initialize(*newContext, mImpl->graphicsController, mImpl->depthBufferAvailable, mImpl->stencilBufferAvailable); + scene->Initialize(mImpl->graphicsController, mImpl->depthBufferAvailable, mImpl->stencilBufferAvailable); } void RenderManager::AttachColorTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer) @@ -409,12 +382,19 @@ void RenderManager::AddGeometry(OwnerPointer& geometry) void RenderManager::RemoveGeometry(Render::Geometry* geometry) { - mImpl->geometryContainer.EraseObject(geometry); + auto it = std::find_if(mImpl->geometryContainer.begin(), mImpl->geometryContainer.end(), [geometry](auto& item) { + return geometry == item; + }); + + if(it != mImpl->geometryContainer.end()) + { + mImpl->geometryContainer.Erase(it); + } } void RenderManager::AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer) { - DALI_ASSERT_DEBUG(NULL != geometry); + DALI_ASSERT_DEBUG(nullptr != geometry); // Find the geometry for(auto&& iter : mImpl->geometryContainer) @@ -429,7 +409,7 @@ void RenderManager::AttachVertexBuffer(Render::Geometry* geometry, Render::Verte void RenderManager::RemoveVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer) { - DALI_ASSERT_DEBUG(NULL != geometry); + DALI_ASSERT_DEBUG(nullptr != geometry); // Find the geometry for(auto&& iter : mImpl->geometryContainer) @@ -457,17 +437,12 @@ void RenderManager::RemoveRenderTracker(Render::RenderTracker* renderTracker) mImpl->RemoveRenderTracker(renderTracker); } -ProgramCache* RenderManager::GetProgramCache() -{ - return &(mImpl->programController); -} - void RenderManager::PreRender(Integration::RenderStatus& status, bool forceClear, bool uploadOnly) { DALI_PRINT_RENDER_START(mImpl->renderBufferIndex); - // Core::Render documents that GL context must be current before calling Render - DALI_ASSERT_DEBUG(mImpl->context.IsGlContextCreated()); + // Rollback + mImpl->uniformBufferManager->GetUniformBufferViewPool(mImpl->renderBufferIndex)->Rollback(); // Increment the frame count at the beginning of each frame ++mImpl->frameCount; @@ -476,9 +451,9 @@ void RenderManager::PreRender(Integration::RenderStatus& status, bool forceClear mImpl->renderQueue.ProcessMessages(mImpl->renderBufferIndex); uint32_t count = 0u; - for(uint32_t i = 0; i < mImpl->sceneContainer.size(); ++i) + for(auto& i : mImpl->sceneContainer) { - count += mImpl->sceneContainer[i]->GetRenderInstructions().Count(mImpl->renderBufferIndex); + count += i->GetRenderInstructions().Count(mImpl->renderBufferIndex); } const bool haveInstructions = count > 0u; @@ -490,53 +465,10 @@ void RenderManager::PreRender(Integration::RenderStatus& status, bool forceClear { DALI_LOG_INFO(gLogFilter, Debug::General, "Render: Processing\n"); - // Switch to the shared context - if(mImpl->currentContext != &mImpl->context) - { - mImpl->currentContext = &mImpl->context; - - // Clear the current cached program when the context is switched - mImpl->programController.ClearCurrentProgram(); - } - // Upload the geometries - for(uint32_t i = 0; i < mImpl->sceneContainer.size(); ++i) + for(auto&& geom : mImpl->geometryContainer) { - RenderInstructionContainer& instructions = mImpl->sceneContainer[i]->GetRenderInstructions(); - for(uint32_t j = 0; j < instructions.Count(mImpl->renderBufferIndex); ++j) - { - RenderInstruction& instruction = instructions.At(mImpl->renderBufferIndex, j); - - const Matrix* viewMatrix = instruction.GetViewMatrix(mImpl->renderBufferIndex); - const Matrix* projectionMatrix = instruction.GetProjectionMatrix(mImpl->renderBufferIndex); - - DALI_ASSERT_DEBUG(viewMatrix); - DALI_ASSERT_DEBUG(projectionMatrix); - - if(viewMatrix && projectionMatrix) - { - const RenderListContainer::SizeType renderListCount = instruction.RenderListCount(); - - // Iterate through each render list. - for(RenderListContainer::SizeType index = 0; index < renderListCount; ++index) - { - const RenderList* renderList = instruction.GetRenderList(index); - - if(renderList && !renderList->IsEmpty()) - { - const std::size_t itemCount = renderList->Count(); - for(uint32_t itemIndex = 0u; itemIndex < itemCount; ++itemIndex) - { - const RenderItem& item = renderList->GetItem(itemIndex); - if(DALI_LIKELY(item.mRenderer)) - { - item.mRenderer->Upload(); - } - } - } - } - } - } + geom->Upload(mImpl->graphicsController); } } } @@ -560,8 +492,9 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector>& class DamagedRectsCleaner { public: - DamagedRectsCleaner(std::vector>& damagedRects) + explicit DamagedRectsCleaner(std::vector>& damagedRects, Rect& surfaceRect) : mDamagedRects(damagedRects), + mSurfaceRect(surfaceRect), mCleanOnReturn(true) { } @@ -576,18 +509,20 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector>& if(mCleanOnReturn) { mDamagedRects.clear(); + mDamagedRects.push_back(mSurfaceRect); } } private: std::vector>& mDamagedRects; + Rect mSurfaceRect; bool mCleanOnReturn; }; Rect surfaceRect = sceneObject->GetSurfaceRect(); // Clean collected dirty/damaged rects on exit if 3d layer or 3d node or other conditions. - DamagedRectsCleaner damagedRectCleaner(damagedRects); + DamagedRectsCleaner damagedRectCleaner(damagedRects, surfaceRect); // Mark previous dirty rects in the sorted array. The array is already sorted by node and renderer, frame number. // so you don't need to sort: std::stable_sort(itemsDirtyRects.begin(), itemsDirtyRects.end()); @@ -597,8 +532,8 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector>& dirtyRect.visited = false; } - uint32_t count = sceneObject->GetRenderInstructions().Count(mImpl->renderBufferIndex); - for(uint32_t i = 0; i < count; ++i) + uint32_t instructionCount = sceneObject->GetRenderInstructions().Count(mImpl->renderBufferIndex); + for(uint32_t i = 0; i < instructionCount; ++i) { RenderInstruction& instruction = sceneObject->GetRenderInstructions().At(mImpl->renderBufferIndex, i); @@ -662,10 +597,10 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector>& const RenderList* renderList = instruction.GetRenderList(index); if(renderList && !renderList->IsEmpty()) { - const std::size_t count = renderList->Count(); - for(uint32_t index = 0u; index < count; ++index) + const std::size_t listCount = renderList->Count(); + for(uint32_t listIndex = 0u; listIndex < listCount; ++listIndex) { - RenderItem& item = renderList->GetItem(index); + RenderItem& item = renderList->GetItem(listIndex); // If the item does 3D transformation, do early exit and clean the damaged rect array if(item.mUpdateSize == Vector3::ZERO) { @@ -680,9 +615,8 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector>& (item.mNode->Updated() || (item.mRenderer && item.mRenderer->Updated(mImpl->renderBufferIndex, item.mNode))))) { item.mIsUpdated = false; - item.mNode->SetUpdated(false); - rect = item.CalculateViewportSpaceAABB(item.mUpdateSize, viewportRect.width, viewportRect.height); + rect = RenderItem::CalculateViewportSpaceAABB(item.mModelViewMatrix, item.mUpdateSize, viewportRect.width, viewportRect.height); if(rect.IsValid() && rect.Intersect(viewportRect) && !rect.IsEmpty()) { const int left = rect.x; @@ -743,6 +677,9 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector>& } } } + + // Reset updated flag from the root + renderList->GetSourceLayer()->SetUpdatedTree(false); } } } @@ -776,6 +713,12 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect& clippingRect) { + if(mImpl->partialUpdateAvailable == Integration::PartialUpdateAvailable::TRUE && !renderToFbo && clippingRect.IsEmpty()) + { + // ClippingRect is empty. Skip rendering + return; + } + // Reset main algorithms command buffer mImpl->renderAlgorithms.ResetCommandBuffer(); @@ -788,6 +731,15 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: std::vector targetstoPresent; + Rect surfaceRect = sceneObject->GetSurfaceRect(); + if(clippingRect == surfaceRect) + { + // Full rendering case + // Make clippingRect empty because we're doing full rendering now if the clippingRect is empty. + // To reduce side effects, keep this logic now. + clippingRect = Rect(); + } + for(uint32_t i = 0; i < count; ++i) { RenderInstruction& instruction = sceneObject->GetRenderInstructions().At(mImpl->renderBufferIndex, i); @@ -801,19 +753,8 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: status.SetNeedsPostRender(true); Rect viewportRect; - Vector4 clearColor; - if(instruction.mIsClearColorSet) - { - clearColor = instruction.mClearColor; - } - else - { - clearColor = Dali::RenderTask::DEFAULT_CLEAR_COLOR; - } - - Rect surfaceRect = sceneObject->GetSurfaceRect(); - int32_t surfaceOrientation = sceneObject->GetSurfaceOrientation(); + int32_t surfaceOrientation = sceneObject->GetSurfaceOrientation(); // @todo Should these be part of scene? Integration::DepthBufferAvailable depthBufferAvailable = mImpl->depthBufferAvailable; @@ -825,7 +766,7 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: if(instruction.mFrameBuffer) { - // Ensure graphics framebuffer is created, bind atachments and create render passes + // Ensure graphics framebuffer is created, bind attachments and create render passes // Only happens once per framebuffer. If the create fails, e.g. no attachments yet, // then don't render to this framebuffer. if(!instruction.mFrameBuffer->GetGraphicsObject()) @@ -840,7 +781,7 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: auto& clearValues = instruction.mFrameBuffer->GetGraphicsRenderPassClearValues(); // Set the clear color for first color attachment - if(instruction.mIsClearColorSet && clearValues.size() > 0) + if(instruction.mIsClearColorSet && !clearValues.empty()) { clearValues[0].color = { instruction.mClearColor.r, @@ -856,30 +797,9 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: // offscreen buffer currentRenderTarget = instruction.mFrameBuffer->GetGraphicsRenderTarget(); currentRenderPass = instruction.mFrameBuffer->GetGraphicsRenderPass(loadOp, Graphics::AttachmentStoreOp::STORE); - - if(mImpl->currentContext != &mImpl->context) - { - // Switch to shared context for off-screen buffer - mImpl->currentContext = &mImpl->context; - - // Clear the current cached program when the context is switched - mImpl->programController.ClearCurrentProgram(); - } } else // no framebuffer { - if(mImpl->currentContext->IsSurfacelessContextSupported()) - { - if(mImpl->currentContext != sceneObject->GetContext()) - { - // Switch the correct context if rendering to a surface - mImpl->currentContext = sceneObject->GetContext(); - - // Clear the current cached program when the context is switched - mImpl->programController.ClearCurrentProgram(); - } - } - // surface auto& clearValues = sceneObject->GetGraphicsRenderPassClearValues(); @@ -913,9 +833,6 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: targetstoPresent.emplace_back(currentRenderTarget); - // Make sure that GL context must be created - mImpl->currentContext->GlContextCreated(); - // reset the program matrices for all programs once per frame // this ensures we will set view and projection matrix once per program per camera mImpl->programController.ResetProgramMatrices(); @@ -934,7 +851,7 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: // Offscreen buffer rendering if(instruction.mIsViewportSet) { - // For glViewport the lower-left corner is (0,0) + // For Viewport the lower-left corner is (0,0) const int32_t y = (instruction.mFrameBuffer->GetHeight() - instruction.mViewport.height) - instruction.mViewport.y; viewportRect.Set(instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height); } @@ -949,7 +866,7 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: // Check whether a viewport is specified, otherwise the full surface size is used if(instruction.mIsViewportSet) { - // For glViewport the lower-left corner is (0,0) + // For Viewport the lower-left corner is (0,0) const int32_t y = (surfaceRect.height - instruction.mViewport.height) - instruction.mViewport.y; viewportRect.Set(instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height); } @@ -960,20 +877,16 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: } // Set surface orientation - mImpl->currentContext->SetSurfaceOrientation(surfaceOrientation); + // @todo Inform graphics impl by another route. + // was: mImpl->currentContext->SetSurfaceOrientation(surfaceOrientation); /*** Clear region of framebuffer or surface before drawing ***/ - - bool clearFullFrameRect = true; + bool clearFullFrameRect = (surfaceRect == viewportRect); if(instruction.mFrameBuffer != nullptr) { Viewport frameRect(0, 0, instruction.mFrameBuffer->GetWidth(), instruction.mFrameBuffer->GetHeight()); clearFullFrameRect = (frameRect == viewportRect); } - else - { - clearFullFrameRect = (surfaceRect == viewportRect); - } if(!clippingRect.IsEmpty()) { @@ -997,6 +910,11 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: } } + // Scissor's value should be set based on the default system coordinates. + // When the surface is rotated, the input values already were set with the rotated angle. + // So, re-calculation is needed. + scissorArea = RecalculateScissorArea(scissorArea, surfaceOrientation, viewportRect); + // Begin render pass mainCommandBuffer->BeginRenderPass( currentRenderPass, @@ -1022,70 +940,16 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: clippingRect, surfaceOrientation); - // Synchronise the FBO/Texture access when there are multiple contexts - if(mImpl->currentContext->IsSurfacelessContextSupported()) - { - // Check whether any bound texture is in the dependency list - bool textureFound = false; - - if(mImpl->boundTextures.Count() > 0u && mImpl->textureDependencyList.Count() > 0u) - { - for(auto texture : mImpl->textureDependencyList) - { - textureFound = std::find_if(mImpl->boundTextures.Begin(), mImpl->boundTextures.End(), [texture](Graphics::Texture* graphicsTexture) { - return texture == graphicsTexture; - }) != mImpl->boundTextures.End(); - } - } - - if(textureFound) - { - if(instruction.mFrameBuffer) - { - // For off-screen buffer - - // Clear the dependency list - mImpl->textureDependencyList.Clear(); - } - else - { - // Worker thread lambda function - auto& glContextHelperAbstraction = mImpl->graphicsController.GetGlContextHelperAbstraction(); - auto workerFunction = [&glContextHelperAbstraction](int workerThread) { - // Switch to the shared context in the worker thread - glContextHelperAbstraction.MakeSurfacelessContextCurrent(); - - // Wait until all rendering calls for the shared context are executed - glContextHelperAbstraction.WaitClient(); - - // Must clear the context in the worker thread - // Otherwise the shared context cannot be switched to from the render thread - glContextHelperAbstraction.MakeContextNull(); - }; - - auto future = mImpl->threadPool->SubmitTask(0u, workerFunction); - if(future) - { - mImpl->threadPool->Wait(); - - // Clear the dependency list - mImpl->textureDependencyList.Clear(); - } - } - } - } - + Graphics::SyncObject* syncObject{nullptr}; + // If the render instruction has an associated render tracker (owned separately) + // and framebuffer, create a one shot sync object, and use it to determine when + // the render pass has finished executing on GPU. if(instruction.mRenderTracker && instruction.mFrameBuffer) { - // This will create a sync object every frame this render tracker - // is alive (though it should be now be created only for - // render-once render tasks) - instruction.mRenderTracker->CreateSyncObject(mImpl->graphicsController.GetGlSyncAbstraction()); - instruction.mRenderTracker = nullptr; // Only create once. + syncObject = instruction.mRenderTracker->CreateSyncObject(mImpl->graphicsController); + instruction.mRenderTracker = nullptr; } - - // End render pass - mainCommandBuffer->EndRenderPass(); + mainCommandBuffer->EndRenderPass(syncObject); } mImpl->renderAlgorithms.SubmitCommandBuffer(); @@ -1113,9 +977,9 @@ void RenderManager::PostRender(bool uploadOnly) mImpl->UpdateTrackers(); uint32_t count = 0u; - for(uint32_t i = 0; i < mImpl->sceneContainer.size(); ++i) + for(auto& scene : mImpl->sceneContainer) { - count += mImpl->sceneContainer[i]->GetRenderInstructions().Count(mImpl->renderBufferIndex); + count += scene->GetRenderInstructions().Count(mImpl->renderBufferIndex); } const bool haveInstructions = count > 0u;