glTexSubImage2D在windows7中上传nv12格式非常慢

时间:2017-09-20 07:15:13

标签: opengl

问题:

我现在正在努力使用opengl渲染4K(4096 * 2048),30FPS视频。 我发现glTexSubImage2D在windows7中的工作速度非常慢,需要120ms 画一帧。 但它在Windows 10中运行良好,只需要16ms即可绘制一帧。

谁能告诉我原因?以下是我的源代码。

来源:

void Draw()
{
  glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  glClearDepth(1.0f);
  glClear(GL_COLOR_BUFFER_BIT);
  glShadeModel(GL_SMOOTH);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glUseProgram(g_program);

  //Y planner
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, g_texture[0]);
  DWORD startCount = GetTickCount();//Get start count
  if (flag)
  {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, frameWidth, frameHeight, 0, GL_RED, GL_UNSIGNED_BYTE, picture->data[0]);
  }
  else
  {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frameWidth, frameHeight,GL_RED, GL_UNSIGNED_BYTE, picture->data[0]);
  }
  glUniform1i(y, 0);

  //UV planner
  glActiveTexture(GL_TEXTURE1);
  glBindTexture(GL_TEXTURE_2D, g_texture[1]);
  if (flag)
  {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, frameWidth / 2, frameHeight / 2, 0, GL_RG, GL_UNSIGNED_BYTE, picture->data[1]);
  }
  else
  {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frameWidth / 2, frameHeight / 2, GL_RG, GL_UNSIGNED_BYTE, picture->data[1]);
  }
  DWORD endCount = GetTickCount();//Get end count
  printf("upload take time is:%s\n", endCount - startCount);//display upload time
  flag = false;
  glUniform1i(uv, 1);

  DrawHorizontal();

  glBindVertexArray(0);
  glUseProgram(0);
  glBindTexture(GL_TEXTURE_2D, 0);
}

0 个答案:

没有答案