1
0
Fork 0
Univerxel/src/client/render/gl/buffer/ShortIndexed.hpp

58 lines
1.7 KiB
C++

#pragma once
#include <GL/gl3w.h>
#include <glm/glm.hpp>
#include <vector>
#include <fstream>
#include "Abstract.hpp"
#include "VertexData.hpp"
namespace buffer {
/// OpenGL VertexBuffer with IndexBuffer
class ShortIndexed: public Abstract {
public:
/// Preindexed buffer data
struct Data {
std::vector<GLushort> indices;
std::vector<PackedVertexData> vertices;
Data() { }
Data(const std::vector<PackedVertexData> &vertices, const std::vector<GLushort> &indices);
Data(const std::vector<PackedVertexData> &vertices) { index(vertices); }
Data(std::ifstream &in);
void index(const std::vector<PackedVertexData> &vertices);
bool empty() const {
return indices.empty();
}
void clear() {
indices.clear();
vertices.clear();
}
void serialize(std::ofstream &out);
};
ShortIndexed(GLenum shape, const typename std::vector<PackedVertexData> &vertices);
ShortIndexed(GLenum shape, const typename std::vector<PackedVertexData> &vertices, const typename std::vector<GLushort> &indices);
ShortIndexed(GLenum shape, const typename ShortIndexed::Data &data);
virtual ~ShortIndexed();
uint draw(params params) override;
protected:
void enableVertexAttrib();
void enableAllAttribs();
void disableAllAttribs();
void enableIndex();
GLushort IndexSize = 0;
private:
GLuint IndexBufferID;
void setData(const ShortIndexed::Data &data);
void setIndicies(const unsigned long size, const void *data);
};
}