GlTexSubImage2D is slower with pixel buffers

I use PBO in opengl es3 on Android, but after using them, the decompression performance has deteriorated. Please help me find a bug in the code. Reference Information. My application consists of a module that generates images at a very high speed. These images are loaded into textures, which are finally drawn on the TextureView. The bottleneck in my application is the time taken to load images into textures. I decided to try PBOs to improve this perfection. Below is my code:

One time initialization

  CheckGLErr( glGenTextures( 1, &texName ) );

  if( usePBO )
  {
     CheckGLErr( glGenBuffers( 1, &pboId ) );
     CheckGLErr( glBindBuffer( GL_PIXEL_UNPACK_BUFFER, pboId ) );
     CheckGLErr( glBufferData( GL_PIXEL_UNPACK_BUFFER, textureSize, 0, GL_STREAM_DRAW ) );
     CheckGLErr( glBindBuffer( GL_PIXEL_UNPACK_BUFFER, 0 ) );
  }

  glBindTexture( GL_TEXTURE_2D, texName );
  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, windowWidth, windowHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );
  glBindTexture( GL_TEXTURE_2D, 0 );

RenderLoop:

 CheckGLErr(glClearColor(0, 1.0f, 0, 1));
 CheckGLErr(glClear(GL_COLOR_BUFFER_BIT));

  glBindTexture( GL_TEXTURE_2D, texName );

  if( usePBO )
  {
     CheckGLErr(glBindBuffer( GL_PIXEL_UNPACK_BUFFER, pboId ));
     void* pBuff = ::glMapBufferRange( GL_PIXEL_UNPACK_BUFFER, 0, textureSize , GL_MAP_WRITE_BIT );
     memcpy( pBuff, buffer.get(), textureSize );
     CheckGLErr(glUnmapBuffer( GL_PIXEL_UNPACK_BUFFER ));
  }

  //std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );

  glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, windowWidth, windowHeight, GL_RGBA, GL_UNSIGNED_BYTE, usePBO ? 0 : buffer.get() );

  // Setup texture properties.
  CheckGLErr(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
  CheckGLErr(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
  CheckGLErr(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
  CheckGLErr(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));

  CheckGLErr( glUseProgram( programObject ) );


  // Enable position vertex attribute. Its size is 3 floats corresponding for co-ordinates in three directions.
  CheckGLErr(glEnableVertexAttribArray(0));
  CheckGLErr(glVertexAttribPointer(0, 3, GL_FLOAT, false, 5 * sizeof(float)/*vertexStride*/, (const GLvoid *)0));

  // Enable UV vertex attribute which starts after position. Hence offset = 3 floats.
  CheckGLErr(glEnableVertexAttribArray(1));
  CheckGLErr(glVertexAttribPointer(1, 2, GL_FLOAT, false, 5 * sizeof(float)/*vertexStride*/, (const GLvoid *)(3*sizeof(float))/*offset worth position*/));

  // Setup ViewPort
  CheckGLErr(glViewport(0, 0, windowWidth, windowHeight));

  if(usePBO )
     CheckGLErr( glBindBuffer( GL_PIXEL_UNPACK_BUFFER, 0 ) );

  CheckGLErr(glDrawElements(GL_TRIANGLE_STRIP, _countof(indices), GL_UNSIGNED_SHORT, (const GLvoid *)0x00000000));
  eglSwapBuffers(eglDisplay, eglWindowSurface);

:
Nexus 7 (4.4.4) Adreno GPU
= 1624 * 1200
   PBO: 17
   PBO: 18 (~ 5 glTexSubImage2D)

Nexus 6 (5.0)
= 2042 * 1440
PBO: 6
PBO: 20

PBOs. glTexSubImage2D (, , < 5ms), VRAM, Nexus 6. std:: this_thread:: sleep_for (std:: chrono:: milliseconds (100)); glUnmapBuffer glTexSubImage2d, , , glTexSubImage2D, .

+4

Source: https://habr.com/ru/post/1610586/


All Articles