title: Uploading texture to GPU by PBO not working (OpenGL version 4.1)
body: <p>I have read the famous tutorial <a href="http://www.songho.ca/opengl/gl_pbo.html" rel="nofollow noreferrer">OpenGL Pixel Buffer Object (PBO)</a>. I tested the sample code on my computer and it works (although with PBO on, its performance didn't improve but at least it's rendering correctly).</p>
  
  <p>The problem is in the sample code the OpenGL context version is quite old (<code>Version: 2.1 INTEL-10.22.29</code>), and the OpenGL context version for my project is <code>version: 4.1 INTEL-10.22.29</code> which doesn't support extension <code>GL_ARB_pixel_buffer_object</code> any more.</p>
  
  <p>I have read this <a href="https://gamedev.stackexchange.com/questions/35486/map-and-fill-texture-using-pbo-opengl-3-3">Map and fill texture using PBO (OpenGL 3.3)</a>, so I change my code to:</p>
  
  <pre><code>// generating buffers and textures
  glGenVertexArrays(1, &amp;_vertex_array);
  glBindVertexArray(_vertex_array);
  
  glGenBuffers(1, &amp;_vertex_buffer);
  glBindBuffer(GL_ARRAY_BUFFER, _vertex_buffer);
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertexs_data), vertexs_data, GL_STATIC_DRAW);
  glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
  
  glGenBuffers(1, &amp;_uv_buffer);
  glBindBuffer(GL_ARRAY_BUFFER, _uv_buffer);
  glBufferData(GL_ARRAY_BUFFER, sizeof(uvs_data), uvs_data, GL_STATIC_DRAW);
  glEnableVertexAttribArray(1);
  glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
  
  glGenBuffers(1, &amp;_pixel_buffer);
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _pixel_buffer);
  glBufferData(GL_PIXEL_UNPACK_BUFFER, DATA_SIZE, 0, GL_STREAM_DRAW);
  
  glGenTextures(1, &amp;_texture);
  glBindTexture(GL_TEXTURE_2D, _texture);
  </code></pre>
  
  <p>and render loop:</p>
  
  <pre><code>glBindTexture(GL_TEXTURE_2D, _texture);
  // ======== start process PBO =========
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _pixel_buffer);
  glBufferData(GL_PIXEL_UNPACK_BUFFER, DATA_SIZE, 0, GL_STREAM_DRAW);
  GLubyte *ptr = (GLubyte*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
  if( ptr != nullptr )
  {
      cout&lt;&lt;"map pixel buffer success"&lt;&lt;endl;
      memcpy(ptr, DATA_SIZE, data );
      glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);   
  }
  // ========= end process PBO ==========
  
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
               _window_width, _window_height,
               0, GL_RGB,
               GL_UNSIGNED_BYTE, data
  );
  glGenerateMipmap(GL_TEXTURE_2D);
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
  // draw commands goes here
  </code></pre>
  
  <p>My code is simply rendering a single color texture, if I comment the block from <code>======== start process PBO =========</code> to <code>========= end process PBO ==========</code> then everything goes well, but with this block, it just failed and all I get is a black screen. I already checked that the <code>glMapBuffer</code> works correctly and I successfully write the texture data to memory pointed by <code>ptr</code>( checking by print out its value ), but I can't figure out why I didn't get my expected result.</p>
  
  <p>Thanks in advance.</p>
  
  <p>My Environment:</p>
  
  <pre><code>OS: macOS sierra 10.12.3 (16D32)
  Graphics: Intel Iris Graphics 6100 1536 MB
  </code></pre>