diff --git a/src/Buffer.cpp b/src/Buffer.cpp new file mode 100644 index 000000000..5c238c729 --- /dev/null +++ b/src/Buffer.cpp @@ -0,0 +1,26 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Buffer.h" + +namespace Magnum { + +void Buffer::copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { + read->bind(Target::CopyRead); + write->bind(Target::CopyWrite); + glCopyBufferSubData(static_cast(Target::CopyRead), static_cast(Target::CopyWrite), readOffset, writeOffset, size); +} + +} diff --git a/src/Buffer.h b/src/Buffer.h index caca1706d..ca2c46a4c 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -25,6 +25,8 @@ #include "Magnum.h" +#include "magnumVisibility.h" + namespace Magnum { /** @@ -56,10 +58,9 @@ std::vector data; buffer.setData(data, Buffer::Usage::StaticDraw); @endcode -@todo Support for buffer copying (OpenGL 3.1, @extension{ARB,copy_buffer}) @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) */ -class Buffer { +class MAGNUM_EXPORT Buffer { Buffer(const Buffer& other) = delete; Buffer(Buffer&& other) = delete; Buffer& operator=(const Buffer& other) = delete; @@ -87,14 +88,14 @@ class Buffer { #endif /** - * Source for copies. + * Source for copies. See copy(). * @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gles30 (no extension providing this functionality) */ CopyRead = GL_COPY_READ_BUFFER, /** - * Target for copies. + * Target for copies. See copy(). * @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gles30 (no extension providing this functionality) */ @@ -237,6 +238,22 @@ class Buffer { glBindBuffer(static_cast(target), 0); } + /** + * @brief Copy one buffer to another + * @param read %Buffer from which to read + * @param write %Buffer to which to copy + * @param readOffset Offset in the read buffer + * @param writeOffset Offset in the write buffer + * @param size Data size + * + * Read buffer is bound to `Target::CopyRead`, write buffer to + * `Target::CopyWrite` and the copy is performed. + * @requires_gl31 Extension @extension{ARB,copy_buffer} + * @requires_gles30 (no extension providing this functionality) + * @see @fn_gl{CopyBufferSubData} + */ + static void copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + /** * @brief Constructor * @param defaultTarget Default target (used when calling bind() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1cf6c5361..e2e867e56 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ set(Magnum_SRCS AbstractImage.cpp AbstractTexture.cpp AbstractShaderProgram.cpp + Buffer.cpp BufferedImage.cpp BufferedTexture.cpp Context.cpp