renderer.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include "rendering/shader.h"
  3. #include <vector>
  4. #include "rendering/camera.h"
  5. #include "rendering/skyBoxRenderer.h"
  6. #include <gl2d/gl2d.h>
  7. struct BlocksLoader;
  8. struct ChunkSystem;
  9. struct Renderer
  10. {
  11. Shader defaultShader;
  12. GLint u_viewProjection = -1;
  13. GLint u_typesCount = -1;
  14. GLint u_positionInt = -1;
  15. GLint u_positionFloat = -1;
  16. GLint u_texture = -1;
  17. GLint u_time = -1;
  18. GLuint u_vertexData = GL_INVALID_INDEX;
  19. GLuint u_vertexUV = GL_INVALID_INDEX;
  20. GLuint u_textureSamplerers = GL_INVALID_INDEX;
  21. void create(BlocksLoader &blocksLoader);
  22. void updateDynamicBlocks();
  23. void render(std::vector<int> &data, Camera &c, gl2d::Texture &texture);
  24. void renderFromBakedData(ChunkSystem &chunkSystem, Camera &c, gl2d::Texture &texture);
  25. SkyBoxRenderer skyBoxRenderer;
  26. GLuint vao = 0;
  27. GLuint vertexBuffer = 0;
  28. GLuint vertexDataBuffer = 0;
  29. GLuint vertexUVBuffer = 0;
  30. GLuint textureSamplerersBuffer = 0;
  31. };
  32. struct GyzmosRenderer
  33. {
  34. struct CubeData
  35. {
  36. int x=0, y=0, z=0;
  37. };
  38. void create();
  39. Shader gyzmosCubeShader;
  40. GLint u_viewProjection = -1;
  41. GLint u_positionInt = -1;
  42. GLint u_positionFloat = -1;
  43. GLuint vao = 0;
  44. GLuint vertexDataBuffer = 0;
  45. GLuint blockPositionBuffer = 0;
  46. GLuint cubeIndices = 0;
  47. std::vector<CubeData> cubes;
  48. void drawCube(int x, int y, int z) { cubes.push_back({x, y, z}); };
  49. void drawCube(glm::ivec3 pos) { drawCube(pos.x, pos.y, pos.z); };
  50. void render(Camera &c, glm::ivec3 posInt, glm::vec3 posFloat);
  51. };
  52. struct PointDebugRenderer
  53. {
  54. void create();
  55. Shader pointDebugShader;
  56. GLint u_viewProjection = -1;
  57. GLint u_positionInt = -1;
  58. GLint u_positionFloat = -1;
  59. GLint u_blockPositionInt = -1;
  60. GLint u_blockPositionFloat = -1;
  61. void renderPoint(Camera &c, glm::dvec3 point);
  62. void renderCubePoint(Camera &c, glm::dvec3 point);
  63. };
  64. constexpr int mergeShorts(short a, short b)
  65. {
  66. int rez = 0;
  67. ((short*)&rez)[0] = a;
  68. ((short*)&rez)[1] = b;
  69. return rez;
  70. }