Copy texture from one ofFbo to another

What’s the simplest, most efficient method for copying a texture from one ofFbo to another? Is it just calling the .copyTo() function?

edit:

at the minute I’m doing:

    ofTexture tempTexture = localMeasures.fbos[0].getTexture(data1);
    graphShader.fbos[0].attachTexture(tempTexture, GL_RGBA32F_ARB, 0);
    tempTexture.clear();

just want to be sure that this is the most efficient method
S

1 Like

Ok so I don’t think the above is correct, as it creates a feedback loop - the texture in the first ofFbo seems to be affected when I run shaders on the second ofFbo. Is this a thing?

Instead I’m now trying the following, but it seems really longwinded to me.

        ofTexture temp_Texture;
        ofBufferObject temp_Buff;
        temp_Buff.allocate(width * height * 4, GL_STATIC_DRAW);
        temp_Texture.allocate(width, height, GL_RGBA32F_ARB);
        
        //select the correct data set from the first fbo
        localMeasures.fbos[0].getTexture(0).copyTo(temp_Buff);
        
       //send the data set to the second fbo
        temp_Texture.loadData(temp_Buff, GL_RGBA32F_ARB, GL_UNSIGNED_BYTE);
        graphShader.fbos[0].attachTexture(temp_Texture, GL_RGBA32F_ARB, 0);
        
        temp_Texture.clear();

eurgh, the above doesn’t seem to load the texture into the second ofFbo correctly, I just get a load of naans and infs

I’m really a bit stuck on this, can anyone help?

All I want to do is have a 2D texture that is shared between shader programs, so that I can write information to particular coordinates within it as vec4s in one shader, and read and use that information in another. I thought it would be simple but I’ve not got anywhere in hours.

I’m currently trying to allocate the texture and it send to the shaders as follows:

    ofPixels data_Graph;
    ofTexture tex_Graph;
    ofBufferObject buffer_Graph;

    data_Graph.allocate(width, height,OF_PIXELS_RGBA);
    for (int y = 0; y < height; y++){
        for (int x = 0; x < width; x++){
            data_Graph.setColor(x,y,ofColor(0,0,0,0));
        }}
    
    //data_Graph is space for the graph info to pass
    buffer_Graph.allocate();
    buffer_Graph.bind(GL_SAMPLER_2D_RECT);
    buffer_Graph.setData(data_Graph,GL_DYNAMIC_DRAW);
    tex_Graph.allocateAsBufferTexture(buffer_Graph,GL_RGBA32F);
    
    graphShader.updateShader.begin();
    graphShader.drawShader.setUniformTexture("tex_Graph",tex_Graph,1);
    graphShader.updateShader.end();

//repeat set uniform for all shaders sharing the texture, with location number varying a bit

And then in the shaders, to write the information:

uniform sampler2DRect tex_Graph;
//location varies as there are other textures involved
layout(location = 7) out vec4 graph_Out;

//and at the end of void main
graph_Out = vec4(value.xyz,0);

And then to read the information in the next shader:

uniform sampler2DRect tex_Graph;
//in void main
vec4 graphInfo = texture(tex_Graph, texCoordVarying.st);
//use to make fragColor out

But all I’m getting is zero values through, judging by the colour output.
Any pointers or suggestions would be really helpful, I’m totally stumped.
S

Did you have some luck on the subject? I’m trying resize fbos in a pingpongbuffer struct object and came across your subject. (I haven’t tested whether this works but I’ll let you know if it does!) The pingpongbuffer struct is included in openframeworks examples. (link below)
https://github.com/openframeworks/openFrameworks/blob/patch-release/examples/gl/gpuParticleSystemExample/src/ofApp.h

in the struct, the example uses std::swap to swap the src buffer with dst fbo. So, maybe if we use something like,

std::swap(A,B);

where A is the desired destination of the copying, and the other is the source, perhaps the fbo will be copied(swapped)?

If you’re going fbo to fbo you can use blitting

theres more info here just do a find for blit https://learnopengl.com/Advanced-OpenGL/Anti-Aliasing