Framebuffer Access

Framebuffer objects can be saved directly to files, just as we did previously with rprFrameBufferSaveToFile().

However, framebuffer objects have many other uses. For instance, they can be read directly to memory. Here we read a framebuffer into memory, create an image texture and then use that texture for a subsequent render.

// Access framebuffer data
size_t size = 0;
CHECK(rprFrameBufferGetInfo(frame_buffer_resolved, RPR_FRAMEBUFFER_DATA, 0, NULL, &size));
float* buffer = new float[size / sizeof(float)];
CHECK(rprFrameBufferGetInfo(frame_buffer_resolved, RPR_FRAMEBUFFER_DATA, size, buffer, 0));

// Apply this data as a texture material to the plane

rpr_material_node diffuse1=nullptr;
rpr_material_node tex=nullptr;
rpr_image img1=nullptr;
{
    // Create the image from the data of the previous framebuffer
    rpr_image_format format;
    format.num_components = 4;
    format.type = RPR_COMPONENT_TYPE_FLOAT32;
    rpr_image_desc desc2;
    desc2.image_width = desc.fb_width;
    desc2.image_height = desc.fb_height;
    desc2.image_row_pitch = 0;
    desc2.image_slice_pitch = 0;
    desc2.image_depth = 0;
    CHECK(rprContextCreateImage(context, format, &desc2, buffer, &img1));

    // Create the image sampler material
    CHECK(rprMaterialSystemCreateNode(matsys, RPR_MATERIAL_NODE_IMAGE_TEXTURE, &tex));

    // Set image data
    CHECK(rprMaterialNodeSetInputImageDataByKey(tex, RPR_MATERIAL_INPUT_DATA, img1));
    
    // Create a simple diffuse material
    CHECK(rprMaterialSystemCreateNode(matsys, RPR_MATERIAL_NODE_DIFFUSE, &diffuse1));

    // Apply the built texture as color
    CHECK(rprMaterialNodeSetInputNByKey(diffuse1, RPR_MATERIAL_INPUT_COLOR, tex));

    // Plane now uses this diffuse as material
    CHECK(rprShapeSetMaterial(plane, diffuse1));
}

See full code