69 lines
1.9 KiB
C++
69 lines
1.9 KiB
C++
/* /\ +--------------------------------------------------------------+
|
|
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
|
|
\ / / | copy, modify and sell without restriction |
|
|
+--\ ^__^ /--+ | |
|
|
| ~/ \~ | | - originally created at [http://nugget.fun] |
|
|
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
|
|
| SPACE ~~~~~ | /
|
|
| ~~~~~~~ BOX |/
|
|
+--------------+
|
|
|
|
[VBO.hpp]
|
|
|
|
This class can be used to allocate space for vertex attributes on the GPU and transfer their
|
|
values into the allocated space.
|
|
|
|
First allocate space by passing a size in bytes to the allocate member function. This size
|
|
can be calculated by adding together the sizes of every Attributes object that is intended to
|
|
be added to the VBO. After allocating, pass each Attributes object to the add function one at
|
|
a time to fill the buffer.
|
|
|
|
This class doesn't support updating the attribute values once they've been added. To do that,
|
|
either reallocate the entire buffer and re-add the attribute values or keep track of the offset
|
|
returned by the add function and use glBufferSubData independently.
|
|
|
|
*/
|
|
|
|
#ifndef SB_VBO_H_
|
|
#define SB_VBO_H_
|
|
|
|
/* include Open GL */
|
|
#if defined(__EMSCRIPTEN__)
|
|
#include <GL/glew.h>
|
|
#else
|
|
#include "glew/glew.h"
|
|
#endif
|
|
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include "GLObject.hpp"
|
|
#include "Attributes.hpp"
|
|
#include "Log.hpp"
|
|
|
|
namespace sb
|
|
{
|
|
|
|
class VBO;
|
|
|
|
std::ostream& operator<<(std::ostream&, const VBO&);
|
|
|
|
class VBO : public Buffer
|
|
{
|
|
|
|
private:
|
|
|
|
GLintptr offset = 0;
|
|
|
|
public:
|
|
|
|
VBO();
|
|
void allocate(GLsizeiptr, GLenum);
|
|
GLintptr add(sb::Attributes&);
|
|
friend std::ostream& operator<<(std::ostream&, const VBO&);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|