OpenGL和QtQuick纹理问题(重访)

时间:2015-10-30 06:00:55

标签: c++ opengl-es textures qt-quick

根据这篇文章OpenGL and QtQuick Texture Problems,确保解除绑定与活动纹理关联的纹理ID解决了我的初始问题。其中,调用glActiveTexture等正在破坏我在QML中定义的Text个对象。因此下面的代码可以使用。

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
}

但是,如果我将代码更改为:

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
}

不正确呈现的QML Text对象的问题返回。我所做的就是改变哪个纹理是活动的并且根据set the texture for by glUniform1i我确保更新对glUniform1i的调用。还有什么可能导致QML标签被错误地渲染?这个问题的图片会有用吗?

0 个答案:

没有答案