|
你如果用的PBO,应该要有一个把数据从PBO拷贝到纹理的一个过程吧。- // "index" is used to copy pixels from a PBO to a texture object
- // "nextIndex" is used to update pixels in the other PBO
- index = (index + 1) % 2;
- if(pboMode == 1) // with 1 PBO
- nextIndex = index;
- else if(pboMode == 2) // with 2 PBOs
- nextIndex = (index + 1) % 2;
- // bind the texture and PBO
- glBindTexture(GL_TEXTURE_2D, textureId);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[index]);
- // copy pixels from PBO to texture object
- // Use offset instead of ponter.
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, WIDTH, HEIGHT,
- GL_BGRA, GL_UNSIGNED_BYTE, 0);
- // bind PBO to update texture source
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[nextIndex]);
- // Note that glMapBufferARB() causes sync issue.
- // If GPU is working with this buffer, glMapBufferARB() will wait(stall)
- // until GPU to finish its job. To avoid waiting (idle), you can call
- // first glBufferDataARB() with NULL pointer before glMapBufferARB().
- // If you do that, the previous data in PBO will be discarded and
- // glMapBufferARB() returns a new allocated pointer immediately
- // even if GPU is still working with the previous data.
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, DATA_SIZE, 0, GL_STREAM_DRAW_ARB);
- // map the buffer object into client's memory
- GLubyte* ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB,
- GL_WRITE_ONLY_ARB);
- if(ptr)
- {
- // update data directly on the mapped buffer
- updatePixels(ptr, DATA_SIZE);
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release the mapped buffer
- }
- // it is good idea to release PBOs with ID 0 after use.
- // Once bound with 0, all pixel operations are back to normal ways.
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
复制代码 |
|