void AbstractFramebuffer::read(const Range2Di& rectangle, Image2D& image) {
    bindInternal(FramebufferTarget::Read);
    const std::size_t dataSize = image.dataSize(rectangle.size());
    char* const data = new char[dataSize];
    (Context::current()->state().framebuffer->readImplementation)(rectangle, image.format(), image.type(), dataSize, data);
    image.setData(image.format(), image.type(), rectangle.size(), data);
}
void AbstractFramebuffer::read(const Range2Di& rectangle, BufferImage2D& image, BufferUsage usage) {
    bindInternal(FramebufferTarget::Read);
    /* If the buffer doesn't have sufficient size, resize it */
    /** @todo Explicitly reset also when buffer usage changes */
    if(image.size() != rectangle.size())
        image.setData(image.format(), image.type(), rectangle.size(), nullptr, usage);

    image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
    (Context::current()->state().framebuffer->readImplementation)(rectangle, image.format(), image.type(), image.dataSize(rectangle.size()), nullptr);
}
void AbstractFramebuffer::read(const Range2Di& rectangle, BufferImage2D& image, BufferUsage usage) {
    bindInternal(FramebufferTarget::Read);

    /* Reallocate only if needed */
    const std::size_t dataSize = Implementation::imageDataSizeFor(image, rectangle.size());
    if(image.dataSize() < dataSize)
        image.setData(image.storage(), image.format(), image.type(), rectangle.size(), {nullptr, dataSize}, usage);
    else
        image.setData(image.storage(), image.format(), image.type(), rectangle.size(), nullptr, usage);

    image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
    image.storage().applyPack();
    (Context::current().state().framebuffer->readImplementation)(rectangle, image.format(), image.type(), dataSize, nullptr);
}
void AbstractFramebuffer::read(const Range2Di& rectangle, Image2D& image) {
    bindInternal(FramebufferTarget::Read);

    /* Reallocate only if needed */
    const std::size_t dataSize = Implementation::imageDataSizeFor(image, rectangle.size());
    Containers::Array<char> data{image.release()};
    if(data.size() < dataSize)
        data = Containers::Array<char>{dataSize};

    #ifndef MAGNUM_TARGET_GLES2
    Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
    #endif
    image.storage().applyPack();
    (Context::current().state().framebuffer->readImplementation)(rectangle, image.format(), image.type(), data.size(), data
        #ifdef MAGNUM_TARGET_GLES2
        + Implementation::pixelStorageSkipOffsetFor(image, rectangle.size())
        #endif
        );
    image.setData(image.storage(), image.format(), image.type(), rectangle.size(), std::move(data));
}
Exemple #5
0
void RangeTest::size() {
    const Range1Di line(34, 47);
    const Range2Di rect({34, 23}, {47, 30});
    const Range3Di cube({34, 23, -17}, {47, 30, 12});

    CORRADE_COMPARE(line.size(), 13);
    CORRADE_COMPARE(rect.size(), Vector2i(13, 7));
    CORRADE_COMPARE(cube.size(), Vector3i(13, 7, 29));

    CORRADE_COMPARE(rect.sizeX(), 13);
    CORRADE_COMPARE(rect.sizeY(), 7);

    CORRADE_COMPARE(cube.sizeX(), 13);
    CORRADE_COMPARE(cube.sizeY(), 7);
    CORRADE_COMPARE(cube.sizeZ(), 29);
}