diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index 3920ac5d..bedcbdea 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -39,8 +39,8 @@ namespace MobileGL::MG_Backend::DirectGLES { return; } - MGLOG_D("Syncing buffer object with ID: %u to backend for state: %s", m_backendBufferId, - stateBufferObject.get()); + MGLOG_D("Syncing buffer object with backend ID %u to backend for state ID %u", m_backendBufferId, + stateBufferObject->GetExternalIndex()); Bool needsRegeneration = !m_isInitialized || bufferSize > m_prevBufferSize || bufferSize < m_prevBufferSize / 2; @@ -154,7 +154,8 @@ namespace MobileGL::MG_Backend::DirectGLES { return; } - MGLOG_D("Syncing VAO object with ID: %u to backend for state: %p", m_backendVAOId, stateVAOObject.get()); + MGLOG_D("Syncing VAO with backend ID %u to backend for state ID %u", m_backendVAOId, + stateVAOObject->GetExternalIndex()); BufferImpl::BackendBufferBindingProtector backendBufferBindingProtector(BufferImpl::TempBufferTarget); BackendVertexArrayBindingProtector backendVAOBindingProtector; @@ -242,8 +243,8 @@ namespace MobileGL::MG_Backend::DirectGLES { return; } - MGLOG_D("Syncing texture object with ID: %u to backend for state: %p", m_backendTextureId, - stateTextureObject.get()); + MGLOG_D("Syncing texture with backend ID %u to backend for state ID %u", m_backendTextureId, + stateTextureObject->GetExternalIndex()); GLenum target = MG_Util::ConvertTextureTargetToGLEnum(stateTextureObject->GetTarget()); @@ -384,14 +385,15 @@ namespace MobileGL::MG_Backend::DirectGLES { MG_External::GLES::glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_backendFBOId); } - void BackendFramebufferObject::SyncToBackend(SharedPtr& stateFBOObject, FramebufferTarget asTarget) { + void BackendFramebufferObject::SyncToBackend(SharedPtr& stateFBOObject, + FramebufferTarget asTarget) { if (!stateFBOObject) { MGLOG_E("State FBO object is null, cannot sync to backend."); return; } - MGLOG_D("Syncing FBO object with ID: %u to backend for state: %p, as %s FBO", m_backendFBOId, stateFBOObject.get(), - (asTarget == FramebufferTarget::Draw ? "DRAW" : "READ")); + MGLOG_D("Syncing FBO with backend ID %u to backend for state ID %u, as %s FBO", m_backendFBOId, + stateFBOObject->GetExternalIndex(), (asTarget == FramebufferTarget::Draw ? "DRAW" : "READ")); GLenum glFBOTarget = MG_Util::ConvertFramebufferTargetToGLEnum(asTarget); BackendFramebufferBindingProtector backendFBOBindingProtector(glFBOTarget); @@ -403,28 +405,24 @@ namespace MobileGL::MG_Backend::DirectGLES { // Attach attachment to FBO, realize `glDrawBuffers` if (stateFBOObject->DrawBuffersIsDirty()) { std::fill(m_frontendBuffers, - m_frontendBuffers + MG_State::GLState::FramebufferObject::MAX_DRAW_BUFFERS, - GL_NONE); + m_frontendBuffers + MG_State::GLState::FramebufferObject::MAX_DRAW_BUFFERS, GL_NONE); std::fill(m_backendBuffers, - m_backendBuffers + MG_State::GLState::FramebufferObject::MAX_DRAW_BUFFERS, - GL_NONE); - auto &stateDrawBuffers = stateFBOObject->GetDrawBuffers(); + m_backendBuffers + MG_State::GLState::FramebufferObject::MAX_DRAW_BUFFERS, GL_NONE); + auto& stateDrawBuffers = stateFBOObject->GetDrawBuffers(); for (GLint i = 0; i < stateDrawBuffers.size(); ++i) { - m_frontendBuffers[i] = - MG_Util::ConvertFramebufferAttachmentTypeToGLEnum(stateDrawBuffers[i]); + m_frontendBuffers[i] = MG_Util::ConvertFramebufferAttachmentTypeToGLEnum(stateDrawBuffers[i]); } MGLOG_D("%s: mapping draw buffers gl -> es:", __func__); - for (int i = 0; - i < MG_State::GLState::FramebufferObject::MAX_DRAW_BUFFERS; ++i) { + for (int i = 0; i < MG_State::GLState::FramebufferObject::MAX_DRAW_BUFFERS; ++i) { if (m_frontendBuffers[i] == GL_NONE) { MGLOG_D("(m_frontendBuffers[%d] = GL_NONE), skipped", i); continue; } m_backendBuffers[nBuffers] = GL_COLOR_ATTACHMENT0 + nBuffers; m_compactedFrontendBuffers[nBuffers] = m_frontendBuffers[i]; - MGLOG_D("(m_frontendBuffers[%d] = %s) -> %s", - i, MG_Util::ConvertGLEnumToString(m_frontendBuffers[i]).c_str(), + MGLOG_D("(m_frontendBuffers[%d] = %s) -> %s", i, + MG_Util::ConvertGLEnumToString(m_frontendBuffers[i]).c_str(), MG_Util::ConvertGLEnumToString(m_backendBuffers[nBuffers]).c_str()); nBuffers++; } @@ -438,7 +436,7 @@ namespace MobileGL::MG_Backend::DirectGLES { const auto& attachments = stateFBOObject->GetAllAttachments(); for (SizeT i = 0; i < nBuffers; ++i) { FramebufferAttachmentType frontendAttachmentType = - MG_Util::ConvertGLEnumToFramebufferAttachmentType(m_compactedFrontendBuffers[i]); + MG_Util::ConvertGLEnumToFramebufferAttachmentType(m_compactedFrontendBuffers[i]); GLenum glBackendAttachmentType = m_backendBuffers[i]; const auto& attachment = attachments[(SizeT)frontendAttachmentType]; @@ -456,9 +454,9 @@ namespace MobileGL::MG_Backend::DirectGLES { const auto& backendTextureObject = backendTextureIt->second; auto glTextureTarget = MG_Util::ConvertTextureTargetToGLEnum(textureObject->GetTarget()); backendTextureObject->Bind(glTextureTarget); - MG_External::GLES::glFramebufferTexture2D( - glFBOTarget, glBackendAttachmentType, glTextureTarget, - backendTextureObject->GetBackendTextureId(), static_cast(attachment.GetTextureLevel())); + MG_External::GLES::glFramebufferTexture2D(glFBOTarget, glBackendAttachmentType, glTextureTarget, + backendTextureObject->GetBackendTextureId(), + static_cast(attachment.GetTextureLevel())); } else if (attachment.IsRenderbuffer()) { // TODO } @@ -470,8 +468,7 @@ namespace MobileGL::MG_Backend::DirectGLES { GLenum backendAtt = GL_NONE; // Attach attachment to FBO, fast path for (SizeT i = 0; i < MG_State::GLState::FramebufferObject::MAX_DRAW_BUFFERS; ++i) { - if (m_compactedFrontendBuffers[i] == frontendAtt) - backendAtt = m_backendBuffers[i]; + if (m_compactedFrontendBuffers[i] == frontendAtt) backendAtt = m_backendBuffers[i]; } if (backendAtt != GL_NONE) { MG_External::GLES::glReadBuffer(backendAtt); @@ -479,28 +476,25 @@ namespace MobileGL::MG_Backend::DirectGLES { // Maybe we should properly do `glFramebufferTexture2D` here // don't need remap / virtualization MG_External::GLES::glReadBuffer(frontendAtt); - const auto &attachments = stateFBOObject->GetAllAttachments(); - const auto &attachment = attachments[(SizeT) frontendAtt]; + const auto& attachments = stateFBOObject->GetAllAttachments(); + const auto& attachment = attachments[(SizeT)frontendAtt]; if (!attachment.IsComplete()) { return; } if (attachment.IsTexture()) { - const auto &textureObject = attachment.GetTexture(); - const auto &backendTextureIt = - TextureImpl::g_backendTextureObjects.find(textureObject); + const auto& textureObject = attachment.GetTexture(); + const auto& backendTextureIt = TextureImpl::g_backendTextureObjects.find(textureObject); if (backendTextureIt == TextureImpl::g_backendTextureObjects.end()) { MGLOG_E("No backend texture found for FBO attachment, cannot bind texture."); return; } - const auto &backendTextureObject = backendTextureIt->second; - auto glTextureTarget = MG_Util::ConvertTextureTargetToGLEnum( - textureObject->GetTarget()); + const auto& backendTextureObject = backendTextureIt->second; + auto glTextureTarget = MG_Util::ConvertTextureTargetToGLEnum(textureObject->GetTarget()); backendTextureObject->Bind(glTextureTarget); - MG_External::GLES::glFramebufferTexture2D( - glFBOTarget, frontendAtt, glTextureTarget, - backendTextureObject->GetBackendTextureId(), - static_cast(attachment.GetTextureLevel())); + MG_External::GLES::glFramebufferTexture2D(glFBOTarget, frontendAtt, glTextureTarget, + backendTextureObject->GetBackendTextureId(), + static_cast(attachment.GetTextureLevel())); } else if (attachment.IsRenderbuffer()) { // TODO } @@ -569,9 +563,10 @@ namespace MobileGL::MG_Backend::DirectGLES { // Attach current shaders auto& attachedShaders = stateProgramObject->GetAttachedShaders(); MGLOG_D("Attaching %zu shaders to program %u", attachedShaders.size(), m_backendProgramId); - for (auto& shader: attachedShaders) { + for (auto& shader : attachedShaders) { const auto& src = shader->GetShaderSource(); - const auto& stage = MG_Util::ConvertGLEnumToString(MG_Util::ConvertShaderStageToGLEnum(shader->GetShaderStage())); + const auto& stage = + MG_Util::ConvertGLEnumToString(MG_Util::ConvertShaderStageToGLEnum(shader->GetShaderStage())); MGLOG_D("Original src @ %s: \n%s", stage.c_str(), src.c_str()); } auto& shaderSpirvs = stateProgramObject->GetGeneratedSpirv(); @@ -589,14 +584,15 @@ namespace MobileGL::MG_Backend::DirectGLES { auto& spirvCode = shaderSpirvs[index]; MG_Util::ShaderTranspiler::SpvcSession spvcSession(spirvCode); -// if (glShaderType == GL_VERTEX_SHADER) { -// if (stateProgramObject->GetAttribLocationMap().empty()) -// MGLOG_D("%s: no explicitly set vertex in location", __func__); -// for (auto& [name, loc]: stateProgramObject->GetAttribLocationMap()) { -// MGLOG_D("%s: got explicitly set - layout(location = %d) %s;", __func__, loc, name.c_str()); -// } -//// spvcSession.SetVertexAttribLocation(stateProgramObject->GetAttribLocationMap()); -// } + // if (glShaderType == GL_VERTEX_SHADER) { + // if (stateProgramObject->GetAttribLocationMap().empty()) + // MGLOG_D("%s: no explicitly set vertex in location", __func__); + // for (auto& [name, loc]: stateProgramObject->GetAttribLocationMap()) { + // MGLOG_D("%s: got explicitly set - layout(location = %d) %s;", __func__, loc, + // name.c_str()); + // } + //// spvcSession.SetVertexAttribLocation(stateProgramObject->GetAttribLocationMap()); + // } spvc_compiler_options options; spvcSession.CreateOptions(&options); @@ -672,7 +668,7 @@ namespace MobileGL::MG_Backend::DirectGLES { MG_External::GLES::glBindBuffer(GL_UNIFORM_BUFFER, 0); m_isInitialized = true; - MGLOG_D("Program sync completed. Backend ID: %u", m_backendProgramId); + MGLOG_D("Program sync completed. backend ID %u", m_backendProgramId); } void BackendProgramObjectImpl::Use() {