Browse Source

Method chaining in Buffer.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
932b9f4377
  1. 45
      src/Buffer.h

45
src/Buffer.h

@ -489,6 +489,7 @@ class MAGNUM_EXPORT Buffer {
/**
* @brief Set target hint
* @return Pointer to self (for method chaining)
*
* If @extension{EXT,direct_state_access} is not available, the buffer
* must be internally bound to some target before any operation. You
@ -501,7 +502,10 @@ class MAGNUM_EXPORT Buffer {
* http://www.opengl.org/wiki/Vertex_Specification#Index_buffers
* ... damned GL state
*/
inline void setTargetHint(Target hint) { _targetHint = hint; }
inline Buffer* setTargetHint(Target hint) {
_targetHint = hint;
return this;
}
/**
* @brief Bind buffer
@ -520,6 +524,7 @@ class MAGNUM_EXPORT Buffer {
* @param size Data size
* @param data Pointer to data
* @param usage %Buffer usage
* @return Pointer to self (for method chaining)
*
* If @extension{EXT,direct_state_access} is not available and the
* buffer is not already bound somewhere, it is bound to hinted target
@ -527,30 +532,35 @@ class MAGNUM_EXPORT Buffer {
* @see setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{BufferData} or
* @fn_gl_extension{NamedBufferData,EXT,direct_state_access}
*/
inline void setData(GLsizeiptr size, const GLvoid* data, Usage usage) {
inline Buffer* setData(GLsizeiptr size, const GLvoid* data, Usage usage) {
(this->*setDataImplementation)(size, data, usage);
return this;
}
/**
* @brief Set buffer data
* @param data Fixed-size array with data
* @param usage %Buffer usage
* @return Pointer to self (for method chaining)
*
* @see setData(GLsizeiptr, const GLvoid*, Usage).
*/
template<std::size_t size, class T> inline void setData(const T(&data)[size], Usage usage) {
template<std::size_t size, class T> inline Buffer* setData(const T(&data)[size], Usage usage) {
setData(size*sizeof(T), data, usage);
return this;
}
/**
* @brief Set buffer data
* @param data Vector with data
* @param usage %Buffer usage
* @return Pointer to self (for method chaining)
*
* @see setData(GLsizeiptr, const GLvoid*, Usage)
*/
template<class T> inline void setData(const std::vector<T>& data, Usage usage) {
template<class T> inline Buffer* setData(const std::vector<T>& data, Usage usage) {
setData(data.size()*sizeof(T), data.data(), usage);
return this;
}
/** @overload */
@ -563,6 +573,7 @@ class MAGNUM_EXPORT Buffer {
* @param offset Offset in the buffer
* @param size Data size
* @param data Pointer to data
* @return Pointer to self (for method chaining)
*
* If @extension{EXT,direct_state_access} is not available and the
* buffer is not already bound somewhere, it is bound to hinted target
@ -570,60 +581,70 @@ class MAGNUM_EXPORT Buffer {
* @see setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{BufferSubData}
* or @fn_gl_extension{NamedBufferSubData,EXT,direct_state_access}
*/
inline void setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) {
inline Buffer* setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) {
(this->*setSubDataImplementation)(offset, size, data);
return this;
}
/**
* @brief Set buffer subdata
* @param offset Offset in the buffer
* @param data Fixed-size array with data
* @return Pointer to self (for method chaining)
*
* @see setSubData(GLintptr, GLsizeiptr, const GLvoid*)
*/
template<std::size_t size, class T> inline void setSubData(GLintptr offset, const T(&data)[size]) {
template<std::size_t size, class T> inline Buffer* setSubData(GLintptr offset, const T(&data)[size]) {
setSubData(offset, size*sizeof(T), data);
return this;
}
/**
* @brief Set buffer subdata
* @param offset Offset in the buffer
* @param data Vector with data
* @return Pointer to self (for method chaining)
*
* @see setSubData(GLintptr, GLsizeiptr, const GLvoid*)
*/
template<class T> inline void setSubData(GLintptr offset, const std::vector<T>& data) {
template<class T> inline Buffer* setSubData(GLintptr offset, const std::vector<T>& data) {
setSubData(offset, data.size()*sizeof(T), data.data());
return this;
}
/** @overload */
template<std::size_t size, class T> inline void setSubData(GLintptr offset, const std::array<T, size>& data) {
template<std::size_t size, class T> inline Buffer* setSubData(GLintptr offset, const std::array<T, size>& data) {
setSubData(offset, data.size()*sizeof(T), data.data());
return this;
}
#ifndef MAGNUM_TARGET_GLES
/**
* @brief Invalidate buffer data
* @return Pointer to self (for method chaining)
*
* If running on OpenGL ES or extension @extension{ARB,invalidate_subdata}
* is not available, this function does nothing.
* @see @ref MapFlag "MapFlag::InvalidateBuffer", @fn_gl{InvalidateBufferData}
*/
inline void invalidateData() {
inline Buffer* invalidateData() {
(this->*invalidateImplementation)();
return this;
}
/**
* @brief Invalidate buffer subdata
* @param offset Offset into the buffer
* @param length Length of the invalidated range
* @return Pointer to self (for method chaining)
*
* If running on OpenGL ES or extension @extension{ARB,invalidate_subdata}
* is not available, this function does nothing.
* @see @ref MapFlag "MapFlag::InvalidateRange", @fn_gl{InvalidateBufferData}
*/
inline void invalidateSubData(GLintptr offset, GLsizeiptr length) {
inline Buffer* invalidateSubData(GLintptr offset, GLsizeiptr length) {
(this->*invalidateSubImplementation)(offset, length);
return this;
}
#endif
@ -673,6 +694,7 @@ class MAGNUM_EXPORT Buffer {
* @brief Flush mapped range
* @param offset Offset relative to start of mapped range
* @param length Length of the flushed memory
* @return Pointer to self (for method chaining)
*
* Flushes specified subsection of mapped range. Use only if you called
* map() with @ref MapFlag "MapFlag::FlushExplicit" flag. See
@ -686,8 +708,9 @@ class MAGNUM_EXPORT Buffer {
* @requires_gl30 %Extension @extension{ARB,map_buffer_range}
* @requires_gles30 %Extension @es_extension{EXT,map_buffer_range}
*/
inline void flushMappedRange(GLintptr offset, GLsizeiptr length) {
inline Buffer* flushMappedRange(GLintptr offset, GLsizeiptr length) {
(this->*flushMappedRangeImplementation)(offset, length);
return this;
}
/**

Loading…
Cancel
Save