How to use UniformBuffer better

Hi, everyone, I am now studying the use of UniformBuffer. I know that ubo can update values ​​for multiple pipelines at the same time. What I am designing now is that all uniforms in each pipeline should be designed as one ubo, but this requires every Dynamically update the binding-point of ubo every frame, because I can’t see if the ubo-binding-points in different pipelines conflict, I don’t know if this is the right way to use it, or there is a better way to use it?
The complete code is here:

// init
		xUniformBuffer::xUniformBuffer(uint32_t size, uint32_t binding)
			: m_ContextID(0), m_Binding(binding), m_Size(size)
		{
			glGenBuffers(1, &m_ContextID);
			glBindBuffer(GL_UNIFORM_BUFFER, m_ContextID);
			glBufferData(GL_UNIFORM_BUFFER, m_Size, NULL, GL_DYNAMIC_DRAW);
			glBindBuffer(GL_UNIFORM_BUFFER, 0);
		}

// pre update
		void xUniformBuffer::UpdateData(const char* data) const
		{
			glBindBuffer(GL_UNIFORM_BUFFER, m_ContextID);
			glBufferSubData(GL_UNIFORM_BUFFER, 0, m_Size, data);
			glBindBuffer(GL_UNIFORM_BUFFER, 0);
		}

// update
void xRenderer::BindDescriptorSetLayout(const xDescriptorSetLayout& desc_layout) const
		{
			for (const xDescriptorHandle* desc : desc_layout.Datas())
			{
				if (desc->Type() == xDescriptorType::Uniform)
				{
					glBindBufferBase(GL_UNIFORM_BUFFER, desc->Binding(), desc->ContextID());
				}
				else if (desc->Type() == xDescriptorType::Texture)
				{
					glActiveTexture(GL_TEXTURE0 + desc->Binding());
					glBindTexture(GL_TEXTURE_2D, desc->ContextID());
				}
				else if (desc->Type() == xDescriptorType::TextureCube)
				{
					glActiveTexture(GL_TEXTURE0 + desc->Binding());
					glBindTexture(GL_TEXTURE_CUBE_MAP, desc->ContextID());
				}
			}

		}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.