My Project
Loading...
Searching...
No Matches
buffers.hh
Go to the documentation of this file.
1#pragma once
2
3#include <GL/glew.h>
4#include <glm/glm.hpp>
5#include <vector>
6#include <iostream>
7#include <assert.h>
8
9struct Vertex {
10 glm::vec3 position;
11 glm::vec2 tex_coord;
12 glm::vec3 normal;
13};
14
16private:
17 unsigned int vb_render_id;
18
19public:
20 VertexBuffer(const std::vector<Vertex> &data);
22
23 void bind() const;
24 void unbind() const;
25};
26
28private:
29 unsigned int ib_render_id;
30 unsigned int ib_count;
31
32public:
33 IndexBuffer(const std::vector<unsigned int> data);
35
36 void bind() const;
37 void unbind() const;
38
39 inline unsigned int
40 get_count() const {
41 return ib_count;
42 }
43};
44
46 unsigned int type;
47 unsigned int count;
48 unsigned int normalize;
49
50 static unsigned int
51 get_size_of_type(unsigned int type) {
52 switch (type) {
53 case GL_FLOAT:
54 return 4;
55 case GL_UNSIGNED_INT:
56 return 4;
57 case GL_UNSIGNED_BYTE:
58 return 1;
59 }
60 std::cout << "[ERROR] GL type " << type << "not found" << std::endl;
61 return 0;
62 }
63};
64
66private:
67 std::vector<VertexBufferElements> vbl_elements;
68 unsigned int vbl_stride;
69
70public:
72
73 template <typename T> void push(unsigned int count);
74
75 inline const std::vector<VertexBufferElements> &
76 get_elements() const {
77 return vbl_elements;
78 };
79 inline unsigned int
80 get_stride() const {
81 return vbl_stride;
82 };
83};
84
86private:
87 unsigned int va_render_id;
88
89public:
92
93 void add_buffer(const VertexBuffer &vb, const VertexBufferLayout &layout);
94 void bind() const;
95 void unbind() const;
96};
Definition buffers.hh:27
unsigned int ib_count
Definition buffers.hh:30
void unbind() const
Definition buffers.cpp:46
~IndexBuffer()
Definition buffers.cpp:37
unsigned int ib_render_id
Definition buffers.hh:29
unsigned int get_count() const
Definition buffers.hh:40
void bind() const
Definition buffers.cpp:40
Definition buffers.hh:85
void bind() const
Definition buffers.cpp:56
~VertexArray()
Definition buffers.cpp:53
void unbind() const
Definition buffers.cpp:62
VertexArray()
Definition buffers.cpp:51
unsigned int va_render_id
Definition buffers.hh:87
void add_buffer(const VertexBuffer &vb, const VertexBufferLayout &layout)
Definition buffers.cpp:68
Definition buffers.hh:65
VertexBufferLayout()
Definition buffers.hh:71
unsigned int get_stride() const
Definition buffers.hh:80
std::vector< VertexBufferElements > vbl_elements
Definition buffers.hh:67
unsigned int vbl_stride
Definition buffers.hh:68
void push(unsigned int count)
const std::vector< VertexBufferElements > & get_elements() const
Definition buffers.hh:76
Definition buffers.hh:15
~VertexBuffer()
Definition buffers.cpp:14
void unbind() const
Definition buffers.cpp:23
unsigned int vb_render_id
Definition buffers.hh:17
void bind() const
Definition buffers.cpp:17
Definition buffers.hh:45
unsigned int count
Definition buffers.hh:47
unsigned int normalize
Definition buffers.hh:48
unsigned int type
Definition buffers.hh:46
static unsigned int get_size_of_type(unsigned int type)
Definition buffers.hh:51
Definition buffers.hh:9
glm::vec3 position
Definition buffers.hh:10
glm::vec3 normal
Definition buffers.hh:12
glm::vec2 tex_coord
Definition buffers.hh:11