You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chunkrenderer.cpp 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * =====================================================================================
  3. *
  4. * Filename: chunkrenderer.cpp
  5. *
  6. * Description:
  7. *
  8. * Version: 1.0
  9. * Created: 04/04/2014 11:34:53 PM
  10. * Revision: none
  11. * Compiler: gcc
  12. *
  13. * Author: YOUR NAME (),
  14. * Organization:
  15. *
  16. * =====================================================================================
  17. */
  18. #include "chunkrenderer.h"
  19. #include "chunk.h"
  20. #include "world.h"
  21. #include <GL/glew.h>
  22. #include <GL/gl.h>
  23. #include <iostream>
  24. namespace vtk {
  25. void ChunkRenderer::init() {
  26. hasGeometryChanged = false;
  27. hasTexturesChanged = false;
  28. hasLightingChanged = false;
  29. updatingGeometry = false;
  30. chunkSize = 16;
  31. lightingMethod = 0;
  32. voxelSize = 1.0f;
  33. //generate VBOs
  34. for (auto& i : vertexBuffers) {
  35. for(auto& j : i) {
  36. glGenBuffers(1, &j);
  37. }
  38. }
  39. //generate VAOs
  40. for (auto& i : vertexArrays) {
  41. glGenVertexArrays(1, &i);
  42. }
  43. //bind VAOs
  44. for (int i = 0; i < 6; i++) {
  45. glBindVertexArray(vertexArrays[i]);
  46. glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[i][0]);
  47. glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
  48. glEnableVertexAttribArray(0);
  49. glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[i][1]);
  50. glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
  51. glEnableVertexAttribArray(1);
  52. glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[i][2]);
  53. glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL);
  54. glEnableVertexAttribArray(2);
  55. }
  56. }
  57. void ChunkRenderer::drawChunk() {
  58. for (int i = 0; i < 6; i++) {
  59. glBindVertexArray(vertexArrays[i]);
  60. glDrawArrays(GL_TRIANGLES, 0, vertexCounts[i]);
  61. }
  62. }
  63. void ChunkRenderer::setChunkPosition(const int&x, const int& y, const int&z) {
  64. chunkPos = std::make_tuple(x, y, z);
  65. }
  66. void ChunkRenderer::updateGeometry() {
  67. updatingGeometry = true;
  68. for (auto& i : geometryVertices)
  69. i.clear();
  70. for (auto& i : faceCounts)
  71. i = 0;
  72. for (unsigned i = 0; i < chunkSize; i++) {
  73. for (unsigned j = 0; j < chunkSize; j++) {
  74. for (unsigned k = 0; k < chunkSize; k++) {
  75. if (linkedChunk->isVoxelSolid(i,j,k)) {
  76. if (!linkedChunk->isVoxelSolid(i+1,j,k)) {
  77. //right face
  78. //top left
  79. addVertex(geometryVertices[0], i * voxelSize + voxelSize, j * voxelSize + voxelSize, k * voxelSize + voxelSize);
  80. //top right
  81. addVertex(geometryVertices[0], i * voxelSize + voxelSize, j * voxelSize + voxelSize, k * voxelSize);
  82. //bottom left
  83. addVertex(geometryVertices[0], i * voxelSize + voxelSize, j * voxelSize, k * voxelSize + voxelSize);
  84. //bottom right
  85. addVertex(geometryVertices[0], i * voxelSize + voxelSize, j * voxelSize, k * voxelSize);
  86. //bottom left
  87. addVertex(geometryVertices[0], i * voxelSize + voxelSize, j * voxelSize, k * voxelSize + voxelSize);
  88. //top right
  89. addVertex(geometryVertices[0], i * voxelSize + voxelSize, j * voxelSize + voxelSize, k * voxelSize);
  90. faceCounts[0]++;
  91. }
  92. if (!linkedChunk->isVoxelSolid(i-1,j,k)) {
  93. //left face
  94. //top left
  95. addVertex(geometryVertices[1], i * voxelSize, j * voxelSize + voxelSize, k * voxelSize);
  96. //top right
  97. addVertex(geometryVertices[1], i * voxelSize, j * voxelSize + voxelSize, k * voxelSize + voxelSize);
  98. //bottom left
  99. addVertex(geometryVertices[1], i * voxelSize, j * voxelSize, k * voxelSize);
  100. //bottom right
  101. addVertex(geometryVertices[1], i * voxelSize, j * voxelSize, k * voxelSize + voxelSize);
  102. //bottom left
  103. addVertex(geometryVertices[1], i * voxelSize, j * voxelSize, k * voxelSize);
  104. //top right
  105. addVertex(geometryVertices[1], i * voxelSize, j * voxelSize + voxelSize, k * voxelSize + voxelSize);
  106. faceCounts[1]++;
  107. }
  108. if (!linkedChunk->isVoxelSolid(i,j+1,k)) {
  109. //top face
  110. //bottom left
  111. addVertex(geometryVertices[2], i * voxelSize, j * voxelSize + voxelSize, k * voxelSize + voxelSize);
  112. //top left
  113. addVertex(geometryVertices[2], i * voxelSize, j * voxelSize + voxelSize, k * voxelSize);
  114. //bottom right
  115. addVertex(geometryVertices[2], i * voxelSize + voxelSize, j * voxelSize + voxelSize, k * voxelSize + voxelSize);
  116. //top right
  117. addVertex(geometryVertices[2], i * voxelSize + voxelSize, j * voxelSize + voxelSize, k * voxelSize);
  118. //bottom right
  119. addVertex(geometryVertices[2], i * voxelSize + voxelSize, j * voxelSize + voxelSize, k * voxelSize + voxelSize);
  120. //top left
  121. addVertex(geometryVertices[2], i * voxelSize, j * voxelSize + voxelSize, k * voxelSize);
  122. faceCounts[2]++;
  123. }
  124. if (!linkedChunk->isVoxelSolid(i,j-1,k)) {
  125. //bottom face
  126. //top right
  127. addVertex(geometryVertices[3], i * voxelSize + voxelSize, j * voxelSize, k * voxelSize + voxelSize);
  128. //bottom right
  129. addVertex(geometryVertices[3], i * voxelSize + voxelSize, j * voxelSize, k * voxelSize);
  130. //top left
  131. addVertex(geometryVertices[3], i * voxelSize, j * voxelSize, k * voxelSize + voxelSize);
  132. //bottom left
  133. addVertex(geometryVertices[3], i * voxelSize, j * voxelSize, k * voxelSize);
  134. //top left
  135. addVertex(geometryVertices[3], i * voxelSize, j * voxelSize, k * voxelSize + voxelSize);
  136. //bottom right
  137. addVertex(geometryVertices[3], i * voxelSize + voxelSize, j * voxelSize, k * voxelSize);
  138. faceCounts[3]++;
  139. }
  140. if (!linkedChunk->isVoxelSolid(i,j,k-1)) {
  141. //back face
  142. //top left
  143. addVertex(geometryVertices[4], i * voxelSize + voxelSize, j * voxelSize + voxelSize, k * voxelSize);
  144. //top right
  145. addVertex(geometryVertices[4], i * voxelSize, j * voxelSize + voxelSize, k * voxelSize);
  146. //bottom left
  147. addVertex(geometryVertices[4], i * voxelSize + voxelSize, j * voxelSize, k * voxelSize);
  148. //bottom right
  149. addVertex(geometryVertices[4], i * voxelSize, j * voxelSize, k * voxelSize);
  150. //bottom left
  151. addVertex(geometryVertices[4], i * voxelSize + voxelSize, j * voxelSize, k * voxelSize);
  152. //top right
  153. addVertex(geometryVertices[4], i * voxelSize, j * voxelSize + voxelSize, k * voxelSize);
  154. faceCounts[4]++;
  155. }
  156. if (!linkedChunk->isVoxelSolid(i,j,k+1)) {
  157. //front face
  158. //bottom right
  159. addVertex(geometryVertices[5], i * voxelSize + voxelSize, j * voxelSize, k * voxelSize + voxelSize);
  160. //bottom left
  161. addVertex(geometryVertices[5], i * voxelSize, j * voxelSize, k * voxelSize + voxelSize);
  162. //top right
  163. addVertex(geometryVertices[5], i * voxelSize + voxelSize, j * voxelSize + voxelSize, k * voxelSize + voxelSize);
  164. //top left
  165. addVertex(geometryVertices[5], i * voxelSize, j * voxelSize + voxelSize, k * voxelSize + voxelSize);
  166. //top right
  167. addVertex(geometryVertices[5], i * voxelSize + voxelSize, j * voxelSize + voxelSize, k * voxelSize + voxelSize);
  168. //bottom left
  169. addVertex(geometryVertices[5], i * voxelSize, j * voxelSize, k * voxelSize + voxelSize);
  170. faceCounts[5]++;
  171. }
  172. }
  173. }
  174. }
  175. }
  176. hasGeometryChanged = true;
  177. updateTexCoords();
  178. updateLighting();
  179. updatingGeometry = false;
  180. }
  181. void ChunkRenderer::updateTexCoords() {
  182. auto linkedWorld = linkedChunk->getWorld();
  183. for (auto& i : textureCoords)
  184. i.clear();
  185. for (unsigned i = 0; i < chunkSize; i++) {
  186. for (unsigned j = 0; j < chunkSize; j++) {
  187. for (unsigned k = 0; k < chunkSize; k++) {
  188. if (linkedChunk->isVoxelSolid(i,j,k)) {
  189. if (!linkedChunk->isVoxelSolid(i+1,j,k)) {
  190. //right face
  191. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[0], linkedChunk->getWorldCoords(i,j,k), Face3D::RIGHT, Corner2D::TOPLEFT);
  192. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[0], linkedChunk->getWorldCoords(i,j,k), Face3D::RIGHT, Corner2D::TOPRIGHT);
  193. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[0], linkedChunk->getWorldCoords(i,j,k), Face3D::RIGHT, Corner2D::BOTTOMLEFT);
  194. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[0], linkedChunk->getWorldCoords(i,j,k), Face3D::RIGHT, Corner2D::BOTTOMRIGHT);
  195. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[0], linkedChunk->getWorldCoords(i,j,k), Face3D::RIGHT, Corner2D::BOTTOMLEFT);
  196. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[0], linkedChunk->getWorldCoords(i,j,k), Face3D::RIGHT, Corner2D::TOPRIGHT);
  197. }
  198. if (!linkedChunk->isVoxelSolid(i-1,j,k)) {
  199. //left face
  200. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[1], linkedChunk->getWorldCoords(i,j,k), Face3D::LEFT, Corner2D::TOPLEFT);
  201. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[1], linkedChunk->getWorldCoords(i,j,k), Face3D::LEFT, Corner2D::TOPRIGHT);
  202. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[1], linkedChunk->getWorldCoords(i,j,k), Face3D::LEFT, Corner2D::BOTTOMLEFT);
  203. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[1], linkedChunk->getWorldCoords(i,j,k), Face3D::LEFT, Corner2D::BOTTOMRIGHT);
  204. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[1], linkedChunk->getWorldCoords(i,j,k), Face3D::LEFT, Corner2D::BOTTOMLEFT);
  205. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[1], linkedChunk->getWorldCoords(i,j,k), Face3D::LEFT, Corner2D::TOPRIGHT);
  206. }
  207. if (!linkedChunk->isVoxelSolid(i,j+1,k)) {
  208. //top face
  209. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[2], linkedChunk->getWorldCoords(i,j,k), Face3D::TOP, Corner2D::BOTTOMLEFT);
  210. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[2], linkedChunk->getWorldCoords(i,j,k), Face3D::TOP, Corner2D::TOPLEFT);
  211. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[2], linkedChunk->getWorldCoords(i,j,k), Face3D::TOP, Corner2D::BOTTOMRIGHT);
  212. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[2], linkedChunk->getWorldCoords(i,j,k), Face3D::TOP, Corner2D::TOPRIGHT);
  213. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[2], linkedChunk->getWorldCoords(i,j,k), Face3D::TOP, Corner2D::BOTTOMRIGHT);
  214. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[2], linkedChunk->getWorldCoords(i,j,k), Face3D::TOP, Corner2D::TOPLEFT);
  215. }
  216. if (!linkedChunk->isVoxelSolid(i,j-1,k)) {
  217. //bottom face
  218. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[3], linkedChunk->getWorldCoords(i,j,k), Face3D::BOTTOM, Corner2D::TOPRIGHT);
  219. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[3], linkedChunk->getWorldCoords(i,j,k), Face3D::BOTTOM, Corner2D::BOTTOMRIGHT);
  220. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[3], linkedChunk->getWorldCoords(i,j,k), Face3D::BOTTOM, Corner2D::TOPLEFT);
  221. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[3], linkedChunk->getWorldCoords(i,j,k), Face3D::BOTTOM, Corner2D::BOTTOMLEFT);
  222. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[3], linkedChunk->getWorldCoords(i,j,k), Face3D::BOTTOM, Corner2D::TOPLEFT);
  223. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[3], linkedChunk->getWorldCoords(i,j,k), Face3D::BOTTOM, Corner2D::BOTTOMRIGHT);
  224. }
  225. if (!linkedChunk->isVoxelSolid(i,j,k-1)) {
  226. //back face
  227. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[4], linkedChunk->getWorldCoords(i,j,k), Face3D::BACK, Corner2D::TOPLEFT);
  228. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[4], linkedChunk->getWorldCoords(i,j,k), Face3D::BACK, Corner2D::TOPRIGHT);
  229. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[4], linkedChunk->getWorldCoords(i,j,k), Face3D::BACK, Corner2D::BOTTOMLEFT);
  230. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[4], linkedChunk->getWorldCoords(i,j,k), Face3D::BACK, Corner2D::BOTTOMRIGHT);
  231. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[4], linkedChunk->getWorldCoords(i,j,k), Face3D::BACK, Corner2D::BOTTOMLEFT);
  232. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[4], linkedChunk->getWorldCoords(i,j,k), Face3D::BACK, Corner2D::TOPRIGHT);
  233. }
  234. if (!linkedChunk->isVoxelSolid(i,j,k+1)) {
  235. //front face
  236. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[5], linkedChunk->getWorldCoords(i,j,k), Face3D::FRONT, Corner2D::BOTTOMRIGHT);
  237. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[5], linkedChunk->getWorldCoords(i,j,k), Face3D::FRONT, Corner2D::BOTTOMLEFT);
  238. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[5], linkedChunk->getWorldCoords(i,j,k), Face3D::FRONT, Corner2D::TOPRIGHT);
  239. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[5], linkedChunk->getWorldCoords(i,j,k), Face3D::FRONT, Corner2D::TOPLEFT);
  240. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[5], linkedChunk->getWorldCoords(i,j,k), Face3D::FRONT, Corner2D::TOPRIGHT);
  241. linkedWorld.voxelInfo.pushTexCoordFromWorldCoords(textureCoords[5], linkedChunk->getWorldCoords(i,j,k), Face3D::FRONT, Corner2D::BOTTOMLEFT);
  242. }
  243. }
  244. }
  245. }
  246. }
  247. hasTexturesChanged = true;
  248. }
  249. void ChunkRenderer::updateLighting() {
  250. for (auto& i : lightingData)
  251. i.clear();
  252. for (unsigned i = 0; i < chunkSize; i++) {
  253. for (unsigned j = 0; j < chunkSize; j++) {
  254. for (unsigned k = 0; k < chunkSize; k++) {
  255. if (linkedChunk->isVoxelSolid(i,j,k)) {
  256. if (lightingMethod == 0) { //fullbright lighting
  257. //face U , V , I
  258. //right face
  259. if (!linkedChunk->isVoxelSolid(i+1,j,k)) {
  260. addVertex(lightingData[0], 0.8f, 0.8f, 0.8f); //TL
  261. addVertex(lightingData[0], 0.8f, 0.8f, 0.8f); //TR
  262. addVertex(lightingData[0], 0.8f, 0.8f, 0.8f); //BL
  263. addVertex(lightingData[0], 0.8f, 0.8f, 0.8f); //BR
  264. addVertex(lightingData[0], 0.8f, 0.8f, 0.8f); //BL
  265. addVertex(lightingData[0], 0.8f, 0.8f, 0.8f); //TR
  266. }
  267. if (!linkedChunk->isVoxelSolid(i-1,j,k)) {
  268. //left face
  269. addVertex(lightingData[1], 0.8f, 0.8f, 0.8f); //TL
  270. addVertex(lightingData[1], 0.8f, 0.8f, 0.8f); //TR
  271. addVertex(lightingData[1], 0.8f, 0.8f, 0.8f); //BL
  272. addVertex(lightingData[1], 0.8f, 0.8f, 0.8f); //BR
  273. addVertex(lightingData[1], 0.8f, 0.8f, 0.8f); //BL
  274. addVertex(lightingData[1], 0.8f, 0.8f, 0.8f); //TR
  275. }
  276. if (!linkedChunk->isVoxelSolid(i,j+1,k)) {
  277. //top face
  278. addVertex(lightingData[2], 1.0f, 1.0f, 1.0f); //TL
  279. addVertex(lightingData[2], 1.0f, 1.0f, 1.0f); //TR
  280. addVertex(lightingData[2], 1.0f, 1.0f, 1.0f); //BL
  281. addVertex(lightingData[2], 1.0f, 1.0f, 1.0f); //BR
  282. addVertex(lightingData[2], 1.0f, 1.0f, 1.0f); //BL
  283. addVertex(lightingData[2], 1.0f, 1.0f, 1.0f); //TR
  284. }
  285. if (!linkedChunk->isVoxelSolid(i,j-1,k)) {
  286. //bottom face
  287. addVertex(lightingData[3], 0.5f, 0.5f, 0.5f); //TL
  288. addVertex(lightingData[3], 0.5f, 0.5f, 0.5f); //TR
  289. addVertex(lightingData[3], 0.5f, 0.5f, 0.5f); //BL
  290. addVertex(lightingData[3], 0.5f, 0.5f, 0.5f); //BR
  291. addVertex(lightingData[3], 0.5f, 0.5f, 0.5f); //BL
  292. addVertex(lightingData[3], 0.5f, 0.5f, 0.5f); //TR
  293. }
  294. if (!linkedChunk->isVoxelSolid(i,j,k-1)) {
  295. //back face
  296. addVertex(lightingData[4], 0.7f, 0.7f, 0.7f); //TL
  297. addVertex(lightingData[4], 0.7f, 0.7f, 0.7f); //TR
  298. addVertex(lightingData[4], 0.7f, 0.7f, 0.7f); //BL
  299. addVertex(lightingData[4], 0.7f, 0.7f, 0.7f); //BR
  300. addVertex(lightingData[4], 0.7f, 0.7f, 0.7f); //BL
  301. addVertex(lightingData[4], 0.7f, 0.7f, 0.7f); //TR
  302. }
  303. if (!linkedChunk->isVoxelSolid(i,j,k+1)) {
  304. //front face
  305. addVertex(lightingData[5], 0.9f, 0.9f, 0.9f); //TL
  306. addVertex(lightingData[5], 0.9f, 0.9f, 0.9f); //TR
  307. addVertex(lightingData[5], 0.9f, 0.9f, 0.9f); //BL
  308. addVertex(lightingData[5], 0.9f, 0.9f, 0.9f); //BR
  309. addVertex(lightingData[5], 0.9f, 0.9f, 0.9f); //BL
  310. addVertex(lightingData[5], 0.9f, 0.9f, 0.9f); //TR
  311. }
  312. } else if (lightingMethod == 1) { //blocky lighting (Need to implement!)
  313. } else if (lightingMethod == 2) { //smooth lighting (Need to implement!)
  314. }
  315. }
  316. }
  317. }
  318. }
  319. hasLightingChanged = true;
  320. }
  321. void ChunkRenderer::updateVertexData() {
  322. if (!updatingGeometry) {
  323. //std::cout << "testing";
  324. for (unsigned i = 0; i < 6; i++) {
  325. if (hasGeometryChanged) {
  326. glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[i][0]);
  327. glBufferData(GL_ARRAY_BUFFER, sizeof(float) * geometryVertices[i].size(), geometryVertices[i].data(), GL_STATIC_DRAW);
  328. //hasGeometryChanged = false;
  329. }
  330. if (hasTexturesChanged) {
  331. glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[i][1]);
  332. glBufferData(GL_ARRAY_BUFFER, sizeof(float) * textureCoords[i].size(), textureCoords[i].data(), GL_STATIC_DRAW);
  333. //hasTexturesChanged = false;
  334. }
  335. if (hasLightingChanged) {
  336. glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[i][2]);
  337. glBufferData(GL_ARRAY_BUFFER, sizeof(float) * lightingData[i].size(), lightingData[i].data(), GL_STATIC_DRAW);
  338. //hasLightingChanged = false;
  339. }
  340. }
  341. if (hasGeometryChanged) hasGeometryChanged = false;
  342. if (hasTexturesChanged) hasTexturesChanged = false;
  343. if (hasLightingChanged) hasLightingChanged = false;
  344. for (int i = 0; i < 6; i++) {
  345. vertexCounts[i] = faceCounts[i] * 6;
  346. }
  347. }
  348. }
  349. void ChunkRenderer::addVertex(std::vector<float>& data, const float& x, const float& y, const float& z) {
  350. data.push_back(x);
  351. data.push_back(y);
  352. data.push_back(z);
  353. }
  354. }