83 lines
2.4 KiB
C++
83 lines
2.4 KiB
C++
#pragma once
|
|
#ifndef _NB_DRAW
|
|
#define _NB_DRAW
|
|
|
|
#include <exception>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <glad/glad.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include "Buffers.h"
|
|
#include "Shader.h"
|
|
|
|
namespace NB{
|
|
|
|
class DrawWarning : public std::runtime_error {
|
|
public:
|
|
DrawWarning(const std::string&);
|
|
};
|
|
|
|
uint8_t GLSLTypeSize(GLenum);
|
|
|
|
uint8_t GLSLPrimitiveVertexSize(GLenum, unsigned int num_prims=1);
|
|
|
|
template<typename T>
|
|
std::vector<unsigned char> rawDataVector(const std::vector<T>& vec) {
|
|
unsigned int num_bytes = vec.size() * sizeof(T);
|
|
std::vector<unsigned char> ret(num_bytes);
|
|
memcpy(ret.data(), vec.data(), num_bytes);
|
|
|
|
return ret;
|
|
}
|
|
|
|
struct VertexAttributePointer {
|
|
int32_t offset;
|
|
GLsizei stride = -1;
|
|
};
|
|
|
|
struct VertexAttribute {
|
|
const GLint GLSLSize;
|
|
const GLenum GLSLType;
|
|
const GLboolean GLSLNormalization;
|
|
VertexAttributePointer ptr;
|
|
};
|
|
|
|
class DrawBuffer {
|
|
public:
|
|
DrawBuffer(std::vector<VertexAttribute>, const Shader&);
|
|
//DrawBuffer(std::initializer_list<VertexAttribute>, std::initializer_list<VertexAttributePointer>);
|
|
|
|
unsigned int vertSize() const;
|
|
std::vector<VertexAttributePointer> getLayout() const;
|
|
const Shader shader() const;
|
|
bool keepLocalElement() const;
|
|
bool keepLocalVertex() const;
|
|
unsigned int elementBufferID() const;
|
|
unsigned int vertexBufferID() const;
|
|
virtual void draw() const;
|
|
|
|
bool keepLocalElement(bool);
|
|
bool keepLocalVertex(bool);
|
|
const Shader shader(const Shader&);
|
|
virtual std::vector<VertexAttributePointer> setLayout();
|
|
virtual std::vector<VertexAttributePointer> setLayout(std::vector<VertexAttributePointer>);
|
|
virtual void generateElementBuffer(std::vector<unsigned int>, GLenum gl_primitive_type=GL_TRIANGLES);
|
|
virtual void generateElementBuffer(unsigned int, GLenum gl_primitive_type=GL_TRIANGLES);
|
|
virtual void generateVertexBuffer(std::vector<unsigned char>);
|
|
virtual void generateVertexBuffer(unsigned int);
|
|
virtual void loadElementBuffer(const std::vector<unsigned int>&, unsigned int offset=0, GLenum gl_primitive_type=GL_TRIANGLES);
|
|
virtual void loadVertexBuffer(const std::vector<unsigned char>&, unsigned int offset=0);
|
|
|
|
protected:
|
|
std::vector<VertexAttribute> _vertex_attributes;
|
|
BufferManager<unsigned char> _vert_data;
|
|
BufferManager<unsigned int> _elmt_data;
|
|
Shader _shader;
|
|
unsigned int _num_verts, _num_prims, _VAO;
|
|
GLenum _gl_primitive_type;
|
|
};
|
|
|
|
}
|
|
#endif |