Botcraft 1.21.4
Loading...
Searching...
No Matches
BlockRenderable.cpp
Go to the documentation of this file.
1#include <glad/glad.h>
2
4
5namespace Botcraft
6{
7 namespace Renderer
8 {
18
23
25 {
26
27 }
28
30 {
31 std::lock_guard<std::mutex> lock_faces(mutex_faces);
32 faces.clear();
34 {
36 }
37 }
38
39 const unsigned int BlockRenderable::GetNumFace() const
40 {
41 return face_number;
42 }
43
45 {
46 glBindVertexArray(faces_VAO);
47 glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, face_number);
48 }
49
51 {
52 glGenVertexArrays(1, &faces_VAO);
53 glGenBuffers(1, &faces_VBO);
54
55 //Buffer for the base face (x,y,z)
56 glBindVertexArray(faces_VAO);
57 glBindBuffer(GL_ARRAY_BUFFER, faces_VBO);
58 glBufferData(GL_ARRAY_BUFFER, Face::base_face.size() * sizeof(float), Face::base_face.data(), GL_STATIC_DRAW);
59
60 //(x, y, z) for base face
61 glEnableVertexAttribArray(0);
62 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
63
64 glGenBuffers(1, &data_VBO);
65 glBindBuffer(GL_ARRAY_BUFFER, data_VBO);
66 glBufferData(GL_ARRAY_BUFFER, sizeof(Face) * face_number, 0, GL_DYNAMIC_DRAW);
67
68 //(matrix4x4) model matrix of the face
69 //Actually passed as 4 columns
70 glEnableVertexAttribArray(1);
71 glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Face), (void*)0);
72 //Specify that only one instance of this must be sent to one index
73 glVertexAttribDivisor(1, 1);
74
75 glEnableVertexAttribArray(2);
76 glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Face), (void*)(4 * sizeof(float)));
77 //Specify that only one instance of this must be sent to one index
78 glVertexAttribDivisor(2, 1);
79
80 glEnableVertexAttribArray(3);
81 glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Face), (void*)(8 * sizeof(float)));
82 //Specify that only one instance of this must be sent to one index
83 glVertexAttribDivisor(3, 1);
84
85 glEnableVertexAttribArray(4);
86 glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Face), (void*)(12 * sizeof(float)));
87 //Specify that only one instance of this must be sent to one index
88 glVertexAttribDivisor(4, 1);
89
90 glEnableVertexAttribArray(5);
91 //tex_coords(u0, v0, u1, v1) for one face
92 glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Face), (void*)(16 * sizeof(float)));
93 //Specify that only one instance of this must be sent to one index
94 glVertexAttribDivisor(5, 1);
95
96 glEnableVertexAttribArray(6);
97 //tex_coords_overlay(u0, v0, u1, v1) for one face
98 glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(Face), (void*)(20 * sizeof(float)));
99 //Specify that only one instance of this must be sent to one index
100 glVertexAttribDivisor(6, 1);
101
102 glEnableVertexAttribArray(7);
103 //(texture_data) for one face
104 glVertexAttribIPointer(7, 1, GL_UNSIGNED_INT, sizeof(Face), (void*)(24 * sizeof(float)));
105 //Specify that only one instance of this must be sent to one index
106 glVertexAttribDivisor(7, 1);
107
108 glEnableVertexAttribArray(8);
109 //(texture_multiplier, texture_multiplier_overlay) for one face
110 glVertexAttribIPointer(8, 2, GL_UNSIGNED_INT, sizeof(Face), (void*)(25 * sizeof(float)));
111 //Specify that only one instance of this must be sent to one index
112 glVertexAttribDivisor(8, 1);
113
114 glBindBuffer(GL_ARRAY_BUFFER, 0);
115 glBindVertexArray(0);
116 }
117
119 {
120 if (faces_VBO)
121 {
122 glDeleteBuffers(1, &faces_VBO);
123 }
124 if (data_VBO)
125 {
126 glDeleteBuffers(1, &data_VBO);
127 }
128 if (faces_VAO)
129 {
130 glDeleteVertexArrays(1, &faces_VAO);
131 }
132 }
133 } // Renderer
134} // Botcraft
const unsigned int GetNumFace() const
static const std::vector< float > base_face
Definition Face.hpp:48