Browse Source

Buffer: support for copying.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
5283b3b9cd
  1. 26
      src/Buffer.cpp
  2. 25
      src/Buffer.h
  3. 1
      src/CMakeLists.txt

26
src/Buffer.cpp

@ -0,0 +1,26 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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<GLenum>(Target::CopyRead), static_cast<GLenum>(Target::CopyWrite), readOffset, writeOffset, size);
}
}

25
src/Buffer.h

@ -25,6 +25,8 @@
#include "Magnum.h"
#include "magnumVisibility.h"
namespace Magnum {
/**
@ -56,10 +58,9 @@ std::vector<Vector3> 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<GLenum>(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()

1
src/CMakeLists.txt

@ -21,6 +21,7 @@ set(Magnum_SRCS
AbstractImage.cpp
AbstractTexture.cpp
AbstractShaderProgram.cpp
Buffer.cpp
BufferedImage.cpp
BufferedTexture.cpp
Context.cpp

Loading…
Cancel
Save