Hi OpenGL community. I’m face to a problem using Buffer Objects and would like your opinion on this. I have a code like this:
Texture object constructor:
glBindTexture(GL_TEXTURE_2D, m_textureName);
glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_width, m_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
Texture object update():
glBindTexture(GL_TEXTURE_2D, m_textureName);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, GL_BGRA, GL_UNSIGNED_BYTE, m_pTexture); // As you guess, m_pTexture is a pointer to the pixels
The texture pixels need some CPU modifications (It’s a N64 HLE emulator) so some (most) of them are updated almost once per frame so I often have lags.
Trying to improve the situation as much as possible, I’ve tried to modify my code to use Buffer Objects, like this:
Texture object constructor:
glBindTexture(GL_TEXTURE_2D, m_textureName);
glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_width, m_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pixelBuffer);
glBufferData(GL_PIXEL_UNPACK_BUFFER, m_width * m_height * GetPixelSize(), NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, NULL);
Texture object update():
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pixelBuffer);
glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, m_width * m_height * GetPixelSize(), m_pTexture);
glBindTexture(GL_TEXTURE_2D, m_textureName);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, NULL);
It work but performances are very bad, I was surprised (Intel 965GM, MESA 8.0.1, Linux Mint 13 Maya aka Ubuntu 12.04).
So I have multiple question:
- Am I doing things badly?
- Is there any interest to use Buffer Objects here?
- What could be “the good way” to deal with my case? (maybe there is some other OpenGL features more appropriates). I would like to stay on OpenGL 2.1 but using the more modern approach with it.
- Would I have better performance using glMapBuffer/glUnmapBuffer with a memcopy() between them?
A big thanks in advance all!