2014-02-10 06:43:20 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef _GEOMETRYBUFFER_HPP_
|
|
|
|
#define _GEOMETRYBUFFER_HPP_
|
2016-04-07 02:13:46 +02:00
|
|
|
#include <gl/gl_core_3_3.h>
|
2014-02-10 06:43:20 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enum used to determine which shader input an attribute maps to
|
|
|
|
*/
|
|
|
|
enum AttributeSemantic {
|
|
|
|
ATRS_Position,
|
|
|
|
ATRS_Normal,
|
|
|
|
ATRS_Colour,
|
|
|
|
ATRS_TexCoord
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores Vertex Attribute data
|
|
|
|
*/
|
|
|
|
struct AttributeIndex {
|
|
|
|
AttributeSemantic sem;
|
|
|
|
GLsizei size;
|
|
|
|
GLsizei stride;
|
|
|
|
GLsizei offset;
|
2014-08-04 23:21:01 +02:00
|
|
|
GLenum type;
|
|
|
|
|
|
|
|
AttributeIndex(AttributeSemantic s,
|
|
|
|
GLsizei sz,
|
|
|
|
GLsizei strd,
|
|
|
|
GLsizei offs,
|
|
|
|
GLenum type = GL_FLOAT)
|
|
|
|
: sem(s), size(sz), stride(strd), offset(offs), type(type)
|
|
|
|
{}
|
2014-02-10 06:43:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<AttributeIndex> AttributeList;
|
|
|
|
|
2014-02-13 11:55:11 +01:00
|
|
|
/**
|
|
|
|
* GeometryBuffer stores a set of vertex attribute data
|
|
|
|
*/
|
2014-02-10 06:43:20 +01:00
|
|
|
class GeometryBuffer {
|
|
|
|
GLuint vbo;
|
|
|
|
GLsizei num;
|
|
|
|
|
|
|
|
AttributeList attributes;
|
|
|
|
public:
|
|
|
|
|
|
|
|
GeometryBuffer();
|
2014-07-28 03:27:55 +02:00
|
|
|
template<class T> GeometryBuffer(const std::vector<T>& data)
|
|
|
|
: vbo(0), num(0)
|
|
|
|
{
|
|
|
|
uploadVertices(data);
|
|
|
|
}
|
|
|
|
|
2014-02-10 06:43:20 +01:00
|
|
|
~GeometryBuffer();
|
|
|
|
|
|
|
|
GLuint getVBOName() const
|
|
|
|
{ return vbo; }
|
|
|
|
|
2015-01-23 18:18:16 +01:00
|
|
|
GLsizei getCount() const
|
|
|
|
{ return num; }
|
|
|
|
|
2014-02-10 06:43:20 +01:00
|
|
|
/**
|
|
|
|
* Uploads Vertex Buffer data from an STL vector
|
2014-02-13 11:55:11 +01:00
|
|
|
*
|
|
|
|
* vertex_attributes() is assumed to exist so that vertex types
|
|
|
|
* can implicitly declare the strides and offsets for their data.
|
2014-02-10 06:43:20 +01:00
|
|
|
*/
|
|
|
|
template<class T> void uploadVertices(const std::vector<T>& data) {
|
|
|
|
uploadVertices(data.size(), data.size()*sizeof(T), data.data());
|
|
|
|
// Assume T has a static method for attributes;
|
|
|
|
attributes = T::vertex_attributes();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uploads raw memory into the buffer.
|
|
|
|
*/
|
|
|
|
void uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem);
|
|
|
|
|
|
|
|
const AttributeList& getDataAttributes() const
|
|
|
|
{ return attributes; }
|
2015-03-28 14:42:29 +01:00
|
|
|
AttributeList& getDataAttributes()
|
|
|
|
{ return attributes; }
|
2014-02-10 06:43:20 +01:00
|
|
|
};
|
|
|
|
|
2014-07-28 03:27:55 +02:00
|
|
|
#endif
|