2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali/internal/graphics/gles-impl/egl-graphics-controller.h>
21 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/gl-abstraction.h>
24 #include <dali/integration-api/gl-defines.h>
25 #include <dali/integration-api/graphics-sync-abstraction.h>
26 #include <dali/internal/graphics/gles-impl/egl-sync-object.h>
27 #include <dali/internal/graphics/gles-impl/gles-graphics-command-buffer.h>
28 #include <dali/internal/graphics/gles-impl/gles-graphics-pipeline.h>
29 #include <dali/internal/graphics/gles-impl/gles-graphics-program.h>
30 #include <dali/internal/graphics/gles-impl/gles-graphics-render-pass.h>
31 #include <dali/internal/graphics/gles-impl/gles-graphics-render-target.h>
32 #include <dali/internal/graphics/gles-impl/gles-graphics-shader.h>
33 #include <dali/internal/graphics/gles-impl/gles-graphics-texture.h>
34 #include <dali/internal/graphics/gles-impl/gles-graphics-types.h>
35 #include <dali/internal/graphics/gles-impl/gles-sync-object.h>
36 #include <dali/internal/graphics/gles-impl/gles3-graphics-memory.h>
37 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
38 #include <dali/public-api/common/dali-common.h>
40 // Uncomment the following define to turn on frame dumping
41 //#define ENABLE_COMMAND_BUFFER_FRAME_DUMP 1
42 #include <dali/internal/graphics/gles-impl/egl-graphics-controller-debug.h>
45 namespace Dali::Graphics
50 * @brief Custom deleter for all Graphics objects created
51 * with use of the Controller.
53 * When Graphics object dies the unique pointer (Graphics::UniquePtr)
54 * doesn't destroy it directly but passes the ownership back
55 * to the Controller. The GLESDeleter is responsible for passing
56 * the object to the discard queue (by calling Resource::DiscardResource()).
61 GLESDeleter() = default;
63 void operator()(T* object)
65 // Discard resource (add it to discard queue)
66 object->DiscardResource();
71 * @brief Helper function allocating graphics object
73 * @param[in] info Create info structure
74 * @param[in] controller Controller object
75 * @param[out] out Unique pointer to the return object
77 template<class GLESType, class GfxCreateInfo, class T>
78 auto NewObject(const GfxCreateInfo& info, EglGraphicsController& controller, T&& oldObject)
81 using Type = typename T::element_type;
82 using UPtr = Graphics::UniquePtr<Type>;
83 if(info.allocationCallbacks)
85 auto* memory = info.allocationCallbacks->allocCallback(
88 info.allocationCallbacks->userData);
89 return UPtr(new(memory) GLESType(info, controller), GLESDeleter<GLESType>());
91 else // Use standard allocator
93 return UPtr(new GLESType(info, controller), GLESDeleter<GLESType>());
97 template<class T0, class T1>
98 T0* CastObject(T1* apiObject)
100 return static_cast<T0*>(apiObject);
103 // Maximum size of texture upload buffer.
104 const uint32_t TEXTURE_UPLOAD_MAX_BUFER_SIZE_MB = 1;
108 EglGraphicsController::~EglGraphicsController() = default;
110 void EglGraphicsController::InitializeGLES(Integration::GlAbstraction& glAbstraction)
112 DALI_LOG_RELEASE_INFO("Initializing New Graphics Controller #1\n");
113 mGlAbstraction = &glAbstraction;
114 mContext = std::make_unique<GLES::Context>(*this);
115 mCurrentContext = mContext.get();
118 void EglGraphicsController::Initialize(Integration::GraphicsSyncAbstraction& syncImplementation,
119 Integration::GlContextHelperAbstraction& glContextHelperAbstraction,
120 Internal::Adaptor::GraphicsInterface& graphicsInterface)
122 DALI_LOG_RELEASE_INFO("Initializing New Graphics Controller #2\n");
123 auto* syncImplPtr = static_cast<Internal::Adaptor::EglSyncImplementation*>(&syncImplementation);
125 mEglSyncImplementation = syncImplPtr;
126 mGlContextHelperAbstraction = &glContextHelperAbstraction;
127 mGraphics = &graphicsInterface;
130 void EglGraphicsController::SubmitCommandBuffers(const SubmitInfo& submitInfo)
132 for(auto& cmdbuf : submitInfo.cmdBuffer)
134 // Push command buffers
135 mCommandQueue.push(static_cast<GLES::CommandBuffer*>(cmdbuf));
138 // If flush bit set, flush all pending tasks
139 if(submitInfo.flags & (0 | SubmitFlagBits::FLUSH))
145 void EglGraphicsController::PresentRenderTarget(RenderTarget* renderTarget)
147 GLES::CommandBuffer* presentCommandBuffer{nullptr};
148 if(mPresentationCommandBuffers.empty())
150 CommandBufferCreateInfo info;
151 info.SetLevel(CommandBufferLevel::PRIMARY);
152 info.fixedCapacity = 1; // only one command
153 presentCommandBuffer = new GLES::CommandBuffer(info, *this);
157 presentCommandBuffer = const_cast<GLES::CommandBuffer*>(mPresentationCommandBuffers.front());
158 presentCommandBuffer->Reset();
159 mPresentationCommandBuffers.pop();
161 presentCommandBuffer->PresentRenderTarget(static_cast<GLES::RenderTarget*>(renderTarget));
162 SubmitInfo submitInfo;
163 submitInfo.cmdBuffer = {presentCommandBuffer};
164 submitInfo.flags = 0 | SubmitFlagBits::FLUSH;
165 SubmitCommandBuffers(submitInfo);
168 void EglGraphicsController::ResolvePresentRenderTarget(GLES::RenderTarget* renderTarget)
170 mCurrentContext->InvalidateDepthStencilBuffers();
172 auto* rt = static_cast<GLES::RenderTarget*>(renderTarget);
173 if(rt->GetCreateInfo().surface)
175 auto* surfaceInterface = reinterpret_cast<Dali::RenderSurfaceInterface*>(rt->GetCreateInfo().surface);
176 surfaceInterface->MakeContextCurrent();
177 surfaceInterface->PostRender();
181 Integration::GlAbstraction& EglGraphicsController::GetGlAbstraction()
183 DALI_ASSERT_DEBUG(mGlAbstraction && "Graphics controller not initialized");
184 return *mGlAbstraction;
187 Integration::GlContextHelperAbstraction& EglGraphicsController::GetGlContextHelperAbstraction()
189 DALI_ASSERT_DEBUG(mGlContextHelperAbstraction && "Graphics controller not initialized");
190 return *mGlContextHelperAbstraction;
193 Internal::Adaptor::EglSyncImplementation& EglGraphicsController::GetEglSyncImplementation()
195 DALI_ASSERT_DEBUG(mEglSyncImplementation && "Sync implementation not initialized");
196 return *mEglSyncImplementation;
199 Graphics::UniquePtr<CommandBuffer> EglGraphicsController::CreateCommandBuffer(
200 const CommandBufferCreateInfo& commandBufferCreateInfo,
201 Graphics::UniquePtr<CommandBuffer>&& oldCommandBuffer)
203 return NewObject<GLES::CommandBuffer>(commandBufferCreateInfo, *this, std::move(oldCommandBuffer));
206 Graphics::UniquePtr<RenderPass> EglGraphicsController::CreateRenderPass(const RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<RenderPass>&& oldRenderPass)
208 return NewObject<GLES::RenderPass>(renderPassCreateInfo, *this, std::move(oldRenderPass));
211 Graphics::UniquePtr<Texture>
212 EglGraphicsController::CreateTexture(const TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Texture>&& oldTexture)
214 return NewObject<GLES::Texture>(textureCreateInfo, *this, std::move(oldTexture));
217 Graphics::UniquePtr<Buffer> EglGraphicsController::CreateBuffer(
218 const BufferCreateInfo& bufferCreateInfo, Graphics::UniquePtr<Buffer>&& oldBuffer)
220 return NewObject<GLES::Buffer>(bufferCreateInfo, *this, std::move(oldBuffer));
223 Graphics::UniquePtr<Framebuffer> EglGraphicsController::CreateFramebuffer(
224 const FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr<Framebuffer>&& oldFramebuffer)
226 return NewObject<GLES::Framebuffer>(framebufferCreateInfo, *this, std::move(oldFramebuffer));
229 Graphics::UniquePtr<Pipeline> EglGraphicsController::CreatePipeline(
230 const PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline)
232 // Create pipeline cache if needed
235 mPipelineCache = std::make_unique<GLES::PipelineCache>(*this);
238 return mPipelineCache->GetPipeline(pipelineCreateInfo, std::move(oldPipeline));
241 Graphics::UniquePtr<Program> EglGraphicsController::CreateProgram(
242 const ProgramCreateInfo& programCreateInfo, UniquePtr<Program>&& oldProgram)
244 // Create program cache if needed
247 mPipelineCache = std::make_unique<GLES::PipelineCache>(*this);
250 return mPipelineCache->GetProgram(programCreateInfo, std::move(oldProgram));
253 Graphics::UniquePtr<Shader> EglGraphicsController::CreateShader(const ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Shader>&& oldShader)
255 return NewObject<GLES::Shader>(shaderCreateInfo, *this, std::move(oldShader));
258 Graphics::UniquePtr<Sampler> EglGraphicsController::CreateSampler(const SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Sampler>&& oldSampler)
260 return NewObject<GLES::Sampler>(samplerCreateInfo, *this, std::move(oldSampler));
263 Graphics::UniquePtr<RenderTarget> EglGraphicsController::CreateRenderTarget(const RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<RenderTarget>&& oldRenderTarget)
265 return NewObject<GLES::RenderTarget>(renderTargetCreateInfo, *this, std::move(oldRenderTarget));
268 Graphics::UniquePtr<SyncObject> EglGraphicsController::CreateSyncObject(const SyncObjectCreateInfo& syncObjectCreateInfo,
269 UniquePtr<SyncObject>&& oldSyncObject)
271 if(GetGLESVersion() < GLES::GLESVersion::GLES_30)
273 return NewObject<EGL::SyncObject>(syncObjectCreateInfo, *this, std::move(oldSyncObject));
277 return NewObject<GLES::SyncObject>(syncObjectCreateInfo, *this, std::move(oldSyncObject));
281 const Graphics::Reflection& EglGraphicsController::GetProgramReflection(const Graphics::Program& program)
283 return static_cast<const Graphics::GLES::Program*>(&program)->GetReflection();
286 void EglGraphicsController::CreateSurfaceContext(Dali::RenderSurfaceInterface* surface)
288 std::unique_ptr<GLES::Context> context = std::make_unique<GLES::Context>(*this);
289 mSurfaceContexts.push_back(std::move(std::make_pair(surface, std::move(context))));
292 void EglGraphicsController::DeleteSurfaceContext(Dali::RenderSurfaceInterface* surface)
294 mSurfaceContexts.erase(std::remove_if(
295 mSurfaceContexts.begin(), mSurfaceContexts.end(), [surface](SurfaceContextPair& iter) { return surface == iter.first; }),
296 mSurfaceContexts.end());
299 void EglGraphicsController::ActivateResourceContext()
301 mCurrentContext = mContext.get();
302 mCurrentContext->GlContextCreated();
305 void EglGraphicsController::ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface)
307 if(surface && mGraphics->IsResourceContextSupported())
309 auto iter = std::find_if(mSurfaceContexts.begin(), mSurfaceContexts.end(), [surface](SurfaceContextPair& iter) {
310 return (iter.first == surface);
313 if(iter != mSurfaceContexts.end())
315 mCurrentContext = iter->second.get();
316 mCurrentContext->GlContextCreated();
321 void EglGraphicsController::AddTexture(GLES::Texture& texture)
323 // Assuming we are on the correct context
324 mCreateTextureQueue.push(&texture);
327 void EglGraphicsController::AddBuffer(GLES::Buffer& buffer)
329 // Assuming we are on the correct context
330 mCreateBufferQueue.push(&buffer);
333 void EglGraphicsController::AddFramebuffer(GLES::Framebuffer& framebuffer)
335 // Assuming we are on the correct context
336 mCreateFramebufferQueue.push(&framebuffer);
339 void EglGraphicsController::ProcessDiscardQueues()
342 ProcessDiscardQueue<GLES::Texture>(mDiscardTextureQueue);
345 ProcessDiscardQueue<GLES::Buffer>(mDiscardBufferQueue);
347 // Process Framebuffers
348 ProcessDiscardQueue<GLES::Framebuffer>(mDiscardFramebufferQueue);
350 // Process RenderPass
351 ProcessDiscardQueue<GLES::RenderPass>(mDiscardRenderPassQueue);
353 // Process RenderTarget
354 ProcessDiscardQueue<GLES::RenderTarget>(mDiscardRenderTargetQueue);
357 ProcessDiscardQueue(mDiscardPipelineQueue);
360 ProcessDiscardQueue<GLES::Program>(mDiscardProgramQueue);
363 ProcessDiscardQueue<GLES::Shader>(mDiscardShaderQueue);
366 ProcessDiscardQueue<GLES::Sampler>(mDiscardSamplerQueue);
368 // Process command buffers
369 ProcessDiscardQueue<GLES::CommandBuffer>(mDiscardCommandBufferQueue);
372 void EglGraphicsController::ProcessCreateQueues()
375 ProcessCreateQueue(mCreateTextureQueue);
378 ProcessCreateQueue(mCreateBufferQueue);
380 // Process framebuffers
381 ProcessCreateQueue(mCreateFramebufferQueue);
384 void EglGraphicsController::ProcessCommandBuffer(const GLES::CommandBuffer& commandBuffer)
387 const auto commands = commandBuffer.GetCommands(count);
388 for(auto i = 0u; i < count; ++i)
390 auto& cmd = commands[i];
394 case GLES::CommandType::FLUSH:
396 // Nothing to do here
399 case GLES::CommandType::BIND_TEXTURES:
401 mCurrentContext->BindTextures(cmd.bindTextures.textureBindings.Ptr(), cmd.bindTextures.textureBindingsCount);
404 case GLES::CommandType::BIND_VERTEX_BUFFERS:
406 auto bindings = cmd.bindVertexBuffers.vertexBufferBindings.Ptr();
407 mCurrentContext->BindVertexBuffers(bindings, cmd.bindVertexBuffers.vertexBufferBindingsCount);
410 case GLES::CommandType::BIND_UNIFORM_BUFFER:
412 auto& bindings = cmd.bindUniformBuffers;
413 mCurrentContext->BindUniformBuffers(bindings.uniformBufferBindingsCount ? bindings.uniformBufferBindings.Ptr() : nullptr, bindings.uniformBufferBindingsCount, bindings.standaloneUniformsBufferBinding);
416 case GLES::CommandType::BIND_INDEX_BUFFER:
418 mCurrentContext->BindIndexBuffer(cmd.bindIndexBuffer);
421 case GLES::CommandType::BIND_SAMPLERS:
425 case GLES::CommandType::BIND_PIPELINE:
427 auto pipeline = static_cast<const GLES::Pipeline*>(cmd.bindPipeline.pipeline);
428 mCurrentContext->BindPipeline(pipeline);
431 case GLES::CommandType::DRAW:
433 mCurrentContext->Flush(false, cmd.draw);
436 case GLES::CommandType::DRAW_INDEXED:
438 mCurrentContext->Flush(false, cmd.draw);
441 case GLES::CommandType::DRAW_INDEXED_INDIRECT:
443 mCurrentContext->Flush(false, cmd.draw);
446 case GLES::CommandType::SET_SCISSOR: // @todo Consider correcting for orientation here?
448 mGlAbstraction->Scissor(cmd.scissor.region.x, cmd.scissor.region.y, cmd.scissor.region.width, cmd.scissor.region.height);
451 case GLES::CommandType::SET_SCISSOR_TEST:
453 mCurrentContext->SetScissorTestEnabled(cmd.scissorTest.enable);
456 case GLES::CommandType::SET_VIEWPORT: // @todo Consider correcting for orientation here?
458 mGlAbstraction->Viewport(cmd.viewport.region.x, cmd.viewport.region.y, cmd.viewport.region.width, cmd.viewport.region.height);
462 case GLES::CommandType::SET_COLOR_MASK:
464 mCurrentContext->ColorMask(cmd.colorMask.enabled);
467 case GLES::CommandType::CLEAR_STENCIL_BUFFER:
469 mCurrentContext->ClearStencilBuffer();
472 case GLES::CommandType::CLEAR_DEPTH_BUFFER:
474 mCurrentContext->ClearDepthBuffer();
478 case GLES::CommandType::SET_STENCIL_TEST_ENABLE:
480 mCurrentContext->SetStencilTestEnable(cmd.stencilTest.enabled);
484 case GLES::CommandType::SET_STENCIL_FUNC:
486 mCurrentContext->StencilFunc(cmd.stencilFunc.compareOp,
487 cmd.stencilFunc.reference,
488 cmd.stencilFunc.compareMask);
492 case GLES::CommandType::SET_STENCIL_WRITE_MASK:
494 mCurrentContext->StencilMask(cmd.stencilWriteMask.mask);
498 case GLES::CommandType::SET_STENCIL_OP:
500 mCurrentContext->StencilOp(cmd.stencilOp.failOp,
501 cmd.stencilOp.depthFailOp,
502 cmd.stencilOp.passOp);
506 case GLES::CommandType::SET_DEPTH_COMPARE_OP:
508 mCurrentContext->SetDepthCompareOp(cmd.depth.compareOp);
511 case GLES::CommandType::SET_DEPTH_TEST_ENABLE:
513 mCurrentContext->SetDepthTestEnable(cmd.depth.testEnabled);
516 case GLES::CommandType::SET_DEPTH_WRITE_ENABLE:
518 mCurrentContext->SetDepthWriteEnable(cmd.depth.writeEnabled);
522 case GLES::CommandType::BEGIN_RENDERPASS:
524 auto& renderTarget = *cmd.beginRenderPass.renderTarget;
525 const auto& targetInfo = renderTarget.GetCreateInfo();
527 if(targetInfo.surface)
529 // switch to surface context
530 mGraphics->ActivateSurfaceContext(static_cast<Dali::RenderSurfaceInterface*>(targetInfo.surface));
532 else if(targetInfo.framebuffer)
534 // switch to resource context
535 mGraphics->ActivateResourceContext();
538 mCurrentContext->BeginRenderPass(cmd.beginRenderPass);
541 case GLES::CommandType::END_RENDERPASS:
543 mCurrentContext->EndRenderPass();
545 auto syncObject = const_cast<GLES::SyncObject*>(static_cast<const GLES::SyncObject*>(cmd.endRenderPass.syncObject));
548 syncObject->InitializeResource();
552 case GLES::CommandType::PRESENT_RENDER_TARGET:
554 ResolvePresentRenderTarget(cmd.presentRenderTarget.targetToPresent);
556 // The command buffer will be pushed into the queue of presentation command buffers
557 // for further reuse.
558 if(commandBuffer.GetCreateInfo().fixedCapacity == 1)
560 mPresentationCommandBuffers.push(&commandBuffer);
564 case GLES::CommandType::EXECUTE_COMMAND_BUFFERS:
566 // Process secondary command buffers
567 // todo: check validity of the secondaries
568 // there are operations which are illigal to be done
569 // within secondaries.
570 auto buffers = cmd.executeCommandBuffers.buffers.Ptr();
571 for(auto j = 0u; j < cmd.executeCommandBuffers.buffersCount; ++j)
573 auto& buf = buffers[j];
574 ProcessCommandBuffer(*static_cast<const GLES::CommandBuffer*>(buf));
582 void EglGraphicsController::ProcessCommandQueues()
586 while(!mCommandQueue.empty())
588 auto cmdBuf = mCommandQueue.front();
590 DUMP_FRAME_COMMAND_BUFFER(cmdBuf);
591 ProcessCommandBuffer(*cmdBuf);
597 void EglGraphicsController::ProcessTextureUpdateQueue()
599 while(!mTextureUpdateRequests.empty())
601 TextureUpdateRequest& request = mTextureUpdateRequests.front();
603 auto& info = request.first;
604 auto& source = request.second;
606 if(source.sourceType == Graphics::TextureUpdateSourceInfo::Type::MEMORY)
608 // GPU memory must be already allocated.
610 // Check if it needs conversion
611 auto* texture = static_cast<GLES::Texture*>(info.dstTexture);
612 const auto& createInfo = texture->GetCreateInfo();
613 auto srcFormat = GLES::GLTextureFormatType(info.srcFormat).format;
614 auto srcType = GLES::GLTextureFormatType(info.srcFormat).type;
615 auto destInternalFormat = GLES::GLTextureFormatType(createInfo.format).internalFormat;
616 auto destFormat = GLES::GLTextureFormatType(createInfo.format).format;
618 // From render-texture.cpp
619 const bool isSubImage(info.dstOffset2D.x != 0 || info.dstOffset2D.y != 0 ||
620 info.srcExtent2D.width != (createInfo.size.width / (1 << info.level)) ||
621 info.srcExtent2D.height != (createInfo.size.height / (1 << info.level)));
623 auto* sourceBuffer = reinterpret_cast<uint8_t*>(source.memorySource.memory);
624 std::vector<uint8_t> tempBuffer;
625 if(mGlAbstraction->TextureRequiresConverting(srcFormat, destFormat, isSubImage))
627 // Convert RGB to RGBA if necessary.
628 texture->TryConvertPixelData(source.memorySource.memory, info.srcFormat, createInfo.format, info.srcSize, info.srcExtent2D.width, info.srcExtent2D.height, tempBuffer);
629 sourceBuffer = &tempBuffer[0];
630 srcFormat = destFormat;
631 srcType = GLES::GLTextureFormatType(createInfo.format).type;
634 // Calculate the maximum mipmap level for the texture
635 texture->SetMaxMipMapLevel(std::max(texture->GetMaxMipMapLevel(), info.level));
637 GLenum bindTarget{GL_TEXTURE_2D};
638 GLenum target{GL_TEXTURE_2D};
640 if(createInfo.textureType == Graphics::TextureType::TEXTURE_CUBEMAP)
642 bindTarget = GL_TEXTURE_CUBE_MAP;
643 target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + info.layer;
646 mGlAbstraction->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
647 mCurrentContext->BindTexture(bindTarget, texture->GetTextureTypeId(), texture->GetGLTexture());
651 if(!texture->IsCompressed())
653 mGlAbstraction->TexImage2D(target,
656 info.srcExtent2D.width,
657 info.srcExtent2D.height,
665 mGlAbstraction->CompressedTexImage2D(target,
668 info.srcExtent2D.width,
669 info.srcExtent2D.height,
677 if(!texture->IsCompressed())
679 mGlAbstraction->TexSubImage2D(target,
683 info.srcExtent2D.width,
684 info.srcExtent2D.height,
691 mGlAbstraction->CompressedTexSubImage2D(target,
695 info.srcExtent2D.width,
696 info.srcExtent2D.height,
702 // free staging memory
703 free(source.memorySource.memory);
707 // TODO: other sources
710 mTextureUpdateRequests.pop();
714 void EglGraphicsController::UpdateTextures(const std::vector<TextureUpdateInfo>& updateInfoList,
715 const std::vector<TextureUpdateSourceInfo>& sourceList)
718 for(auto& info : updateInfoList)
720 mTextureUpdateRequests.push(std::make_pair(info, sourceList[info.srcReference]));
721 auto& pair = mTextureUpdateRequests.back();
722 switch(pair.second.sourceType)
724 case Graphics::TextureUpdateSourceInfo::Type::MEMORY:
726 auto& info = pair.first;
727 auto& source = pair.second;
729 // allocate staging memory and copy the data
730 // TODO: using PBO with GLES3, this is just naive
733 char* stagingBuffer = reinterpret_cast<char*>(malloc(info.srcSize));
734 std::copy(&reinterpret_cast<char*>(source.memorySource.memory)[info.srcOffset],
735 reinterpret_cast<char*>(source.memorySource.memory) + info.srcSize,
738 mTextureUploadTotalCPUMemoryUsed += info.srcSize;
740 // store staging buffer
741 source.memorySource.memory = stagingBuffer;
744 case Graphics::TextureUpdateSourceInfo::Type::BUFFER:
746 // TODO, with PBO support
749 case Graphics::TextureUpdateSourceInfo::Type::TEXTURE:
751 // TODO texture 2 texture in-GPU copy
757 // If upload buffer exceeds maximum size, flush.
758 if(mTextureUploadTotalCPUMemoryUsed > TEXTURE_UPLOAD_MAX_BUFER_SIZE_MB * 1024)
761 mTextureUploadTotalCPUMemoryUsed = 0;
765 void EglGraphicsController::ProcessTextureMipmapGenerationQueue()
767 while(!mTextureMipmapGenerationRequests.empty())
769 auto* texture = mTextureMipmapGenerationRequests.front();
771 mCurrentContext->BindTexture(texture->GetGlTarget(), texture->GetTextureTypeId(), texture->GetGLTexture());
772 mCurrentContext->GenerateMipmap(texture->GetGlTarget());
774 mTextureMipmapGenerationRequests.pop();
778 void EglGraphicsController::GenerateTextureMipmaps(const Graphics::Texture& texture)
780 mTextureMipmapGenerationRequests.push(static_cast<const GLES::Texture*>(&texture));
783 Graphics::UniquePtr<Memory> EglGraphicsController::MapBufferRange(const MapBufferInfo& mapInfo)
785 mGraphics->ActivateResourceContext();
787 // Mapping buffer requires the object to be created NOW
788 // Workaround - flush now, otherwise there will be given a staging buffer
789 // in case when the buffer is not there yet
790 ProcessCreateQueues();
792 if(GetGLESVersion() < GLES::GLESVersion::GLES_30)
794 return Graphics::UniquePtr<Memory>(new GLES::Memory2(mapInfo, *this));
798 return Graphics::UniquePtr<Memory>(new GLES::Memory3(mapInfo, *this));
802 bool EglGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData)
804 return static_cast<GLES::Program*>(&program)->GetImplementation()->GetParameter(parameterId, outData);
807 GLES::PipelineCache& EglGraphicsController::GetPipelineCache() const
809 return *mPipelineCache;
812 } // namespace Dali::Graphics