I am trying something tricky under OpenGL on a multiplatform game. I would like to:
a) Extract a smallish rectangle (192x192) from a large texture (2048x2048). The colour data received will be used to create “debris”.
b) Then immediately destroy parts of the same large texture (filling them with alpha=0). The modified texture will then be used to continue in the game.
All is well and fast under linux in various computers I have tried. Windows 10 works but gets choppy, maybe 100ms delay every time an explosion occurs. I try doing only a) and not b), and there is no choppiness, same with b) and not a).
This is how I read the pixels from the texture:
glBindFramebuffer(GL_READ_FRAMEBUFFER, my_fb);
glFramebufferTexture(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, world_tex, 0);
glReadPixels(x, y, 192, 192, GL_BGRA, GL_UNSIGNED_BYTE, my_buffer);
I also tried glGetTextureSubImage and glCopyImageSubData and get the same choppiness under Windows (fine under Linux). But they are not supported on some legacy hardware.
My code to destroy parts of the terrain:
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, world_tex, 0);
glBufferData(GL_ARRAY_BUFFER, buffer_size, buffer_data, GL_STREAM_DRAW);
glDrawArrays(GL_POINTS, 0, num_points);
I am interested if there is a better way to do this, or a reason why Windows is slow.
Steve