According to this post OpenGL and QtQuick Texture Problems, ensuring that you unbind the texture id associated with an active texture solved my initial problem. Which was, calls to glActiveTexture, etc. were destroying Text
objects I have defined in my QML. Thus the code below works.
void draw()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); GL_CALL
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ebo); GL_CALL
glActiveTexture(GL_TEXTURE0); GL_CALL
glBindTexture(GL_TEXTURE_2D, m_tex[0]); GL_CALL
glUniform1i(glGetUniformLocation(m_handle.shaderProgramId(), "uSampler1"), 0);
GL_CALL
glActiveTexture(GL_TEXTURE1); GL_CALL
glBindTexture(GL_TEXTURE_2D, m_tex[1]); GL_CALL
glUniform1i(glGetUniformLocation(m_handle.shaderProgramId(), "uSampler2"), 1);
GL_CALL
...
glDrawElements(GL_TRIANGLES, m_indices.get_indices_count(), GL_UNSIGNED_INT,
0); GL_CALL
glActiveTexture(GL_TEXTURE1); GL_CALL
glBindTexture(GL_TEXTURE_2D, 0); GL_CALL
glActiveTexture(GL_TEXTURE0); GL_CALL
glBindTexture(GL_TEXTURE_2D, 0); GL_CALL
}
However, if I change the code to look like:
void draw()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); GL_CALL
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ebo); GL_CALL
glActiveTexture(GL_TEXTURE20); GL_CALL
glBindTexture(GL_TEXTURE_2D, m_tex[0]); GL_CALL
glUniform1i(glGetUniformLocation(m_handle.shaderProgramId(), "uSampler1"), 20);
GL_CALL
glActiveTexture(GL_TEXTURE21); GL_CALL
glBindTexture(GL_TEXTURE_2D, m_tex[1]); GL_CALL
glUniform1i(glGetUniformLocation(m_handle.shaderProgramId(), "uSampler2"), 21);
GL_CALL
...
glDrawElements(GL_TRIANGLES, m_indices.get_indices_count(), GL_UNSIGNED_INT,
0); GL_CALL
glActiveTexture(GL_TEXTURE21); GL_CALL
glBindTexture(GL_TEXTURE_2D, 0); GL_CALL
glActiveTexture(GL_TEXTURE20); GL_CALL
glBindTexture(GL_TEXTURE_2D, 0); GL_CALL
}
The issue of improperlly rendered QML Text
objects returns. All I did was change which texture was active and according to set the texture for by glUniform1i I am making sure to update the call to glUniform1i. What else could be causing QML labels to be rendered incorrectly? Would images of the problem be helpful?