I'm currently using glCopyImageSubData to copy from texture to texture. It works fine, but I'm trying to replace it with the following code. It doesn't work, failing on the copy back to the GPU.
glCopyImageSubData(glowmap_tex, GL_TEXTURE_2D, 0, 0, 0, 0,
last_frame_glowmap_tex, GL_TEXTURE_2D, 0, 0, 0, 0,
win_x, win_y, 1);
…
vector<float> output_pixels(win_x* win_y * 4, 1.0f);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, glowmap_tex);
glBindImageTexture(GL_TEXTURE4, glowmap_tex, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, &output_pixels[0]);
vector<float> last_frame_output_pixels(win_x* win_y * 4, 1.0f);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, last_frame_glowmap_tex);
glBindImageTexture(GL_TEXTURE4, last_frame_glowmap_tex, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, &last_frame_output_pixels[0]);
vector<float> combined_output_pixels(win_x* win_y * 4, 1.0f);
for (int x = 0; x < win_x; x++)
{
for (int y = 0; y < win_y; y++)
{
size_t index = 4 * ((y * win_x) + x);
combined_output_pixels[index + 0] = output_pixels[index + 0];// +last_frame_output_pixels[imgIdx + 0];
combined_output_pixels[index + 1] = output_pixels[index + 1];// +last_frame_output_pixels[imgIdx + 1];
combined_output_pixels[index + 2] = output_pixels[index + 2];// +last_frame_output_pixels[imgIdx + 2];
combined_output_pixels[index + 3] = output_pixels[index + 3];// +last_frame_output_pixels[imgIdx + 3];
}
}
// The following doesn't work, and I don't know why
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, last_frame_glowmap_tex);
glBindImageTexture(4, last_frame_glowmap_tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, win_x, win_y, 0, GL_RGBA, GL_FLOAT, &combined_output_pixels[0]);
Any ideas?