add documentation to VBO header file
This commit is contained in:
parent
89fbe359f6
commit
b9dd2836f2
|
@ -1,13 +1,12 @@
|
|||
/*!<pre>
|
||||
* /\ +------------------------------------------------------+
|
||||
* ____/ \____ /| - Open source game framework licensed to freely use, |
|
||||
* \ / / | copy, modify and sell without restriction |
|
||||
* +--\ ^__^ /--+ | |
|
||||
* | ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
||||
* | ~~~~~~~~~~~~ | +------------------------------------------------------+
|
||||
* | SPACE ~~~~~ | /
|
||||
* | ~~~~~~~ BOX |/
|
||||
* +--------------+ </pre>*/
|
||||
/* +------------------------------------------------------+
|
||||
____/ \____ /| - Open source game framework licensed to freely use, |
|
||||
\ / / | copy, modify and sell without restriction |
|
||||
+--\ ^__^ /--+ | |
|
||||
| ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
||||
| ~~~~~~~~~~~~ | +------------------------------------------------------+
|
||||
| SPACE ~~~~~ | /
|
||||
| ~~~~~~~ BOX |/
|
||||
+-------------*/
|
||||
|
||||
#include "Attributes.hpp"
|
||||
|
||||
|
|
29
src/VBO.cpp
29
src/VBO.cpp
|
@ -1,27 +1,21 @@
|
|||
/* /\ +--------------------------------------------------------------+
|
||||
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
|
||||
\ / / | copy, modify and sell without restriction |
|
||||
+--\ ^__^ /--+ | |
|
||||
| ~/ \~ | | - originally created at [http://nugget.fun] |
|
||||
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
|
||||
| SPACE ~~~~~ | /
|
||||
| ~~~~~~~ BOX |/
|
||||
+--------------+
|
||||
|
||||
*/
|
||||
/* +------------------------------------------------------+
|
||||
____/ \____ /| - Open source game framework licensed to freely use, |
|
||||
\ / / | copy, modify and sell without restriction |
|
||||
+--\ ^__^ /--+ | |
|
||||
| ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
||||
| ~~~~~~~~~~~~ | +------------------------------------------------------+
|
||||
| SPACE ~~~~~ | /
|
||||
| ~~~~~~~ BOX |/
|
||||
+-------------*/
|
||||
|
||||
#include "VBO.hpp"
|
||||
using namespace sb;
|
||||
|
||||
/* Initialize a Vertex Buffer Object. The base class will be initalized with a target of
|
||||
* GL_ARRAY_BUFFER. */
|
||||
VBO::VBO() : Buffer(GL_ARRAY_BUFFER) {}
|
||||
|
||||
/* Allocate size bytes of vertex attribute memory on the GPU. Usage should be one of GL_STREAM_DRAW,
|
||||
* GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW,
|
||||
* GL_DYNAMIC_READ, or GL_DYNAMIC_COPY. The memory will be uninitialized. */
|
||||
void VBO::allocate(GLsizeiptr size, GLenum usage)
|
||||
{
|
||||
/* Create data store */
|
||||
glBufferData(target(), size, nullptr, usage);
|
||||
|
||||
/* Debug */
|
||||
|
@ -32,7 +26,7 @@ void VBO::allocate(GLsizeiptr size, GLenum usage)
|
|||
|
||||
GLintptr VBO::add(sb::Attributes& attributes)
|
||||
{
|
||||
/* Set memory */
|
||||
/* Set memory and update offset value in attributes object */
|
||||
glBufferSubData(target(), offset, attributes.size(), attributes);
|
||||
attributes.offset(offset);
|
||||
|
||||
|
@ -46,7 +40,6 @@ GLintptr VBO::add(sb::Attributes& attributes)
|
|||
return offset;
|
||||
}
|
||||
|
||||
/* Overload the stream operator to support the VBO string representation. */
|
||||
std::ostream& sb::operator<<(std::ostream& out, const VBO& vbo)
|
||||
{
|
||||
out << "<Vertex Buffer Object (id: " << vbo.id() << ")>";
|
||||
|
|
30
src/VBO.hpp
30
src/VBO.hpp
|
@ -49,11 +49,25 @@ namespace sb
|
|||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Construct a Vertex Buffer Object object. The base GLObject will be constructed with a target of `GL_ARRAY_BUFFER`.
|
||||
*/
|
||||
VBO();
|
||||
void allocate(GLsizeiptr, GLenum);
|
||||
|
||||
/*!
|
||||
* Set memory in the GPU buffer to the values of the attribute data using glBufferSubData. The memory
|
||||
* Allocate size bytes of unintialized vertex buffer memory on the GPU.
|
||||
*
|
||||
* Usage should be one of GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW,
|
||||
* GL_DYNAMIC_READ, or GL_DYNAMIC_COPY. If using `glBufferSubData` directly to change the VBO's data frequently, a value other than the
|
||||
* default GL_STATIC_DRAW can be used.
|
||||
*
|
||||
* @param size number of bytes of GPU memory to allocate to the buffer
|
||||
* @param usage indicator to the GL implementation of how the data will be used, see `glBufferData` for info
|
||||
*/
|
||||
void allocate(GLsizeiptr size, GLenum usage = GL_STATIC_DRAW);
|
||||
|
||||
/*!
|
||||
* Set memory in the GPU buffer to the values of the attribute data using `glBufferSubData`. The memory
|
||||
* is a contiguous area from the object's current byte offset value to the offset plus the size in
|
||||
* bytes of the attributes. After the memory is set, the offset is updated to point to the end of the
|
||||
* area.
|
||||
|
@ -62,12 +76,22 @@ namespace sb
|
|||
* the VAO by passing the offset along when it calls glVertexAttribPointer in its sb::Attributes::bind
|
||||
* method.
|
||||
*
|
||||
* @warning This function is expected to change in the future to allow more control over the offset so
|
||||
* the VBO can be refilled using this class.
|
||||
*
|
||||
* @param attributes vertices to be added to the vertex buffer, wrapped in a sb::Attributes object
|
||||
* @return the new offset that indicates the end of the vertex buffer
|
||||
*/
|
||||
GLintptr add(sb::Attributes&);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&, const VBO&);
|
||||
/*!
|
||||
* Stream a string representation containing the ID# to the output stream.
|
||||
*
|
||||
* @param out output stream
|
||||
* @param vbo this object's string representation will be passed to the stream
|
||||
* @return the edited stream
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& out, const VBO& vbo);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue