A 2D tile-based sandbox game.
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.

Renderer.h 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <memory>
  3. #include <vector>
  4. #include <stdint.h>
  5. #include <swan-common/constants.h>
  6. #include <swan-common/Vector2.h>
  7. #include "util.h"
  8. namespace Cygnet {
  9. struct RendererState;
  10. struct RenderChunk {
  11. GLuint tex;
  12. };
  13. struct RenderCamera {
  14. SwanCommon::Vec2 pos;
  15. float zoom;
  16. };
  17. class Renderer {
  18. public:
  19. using TileID = uint16_t;
  20. Renderer();
  21. ~Renderer();
  22. void drawChunk(SwanCommon::Vec2 pos, RenderChunk chunk);
  23. void draw(const RenderCamera &cam);
  24. void registerTileTexture(TileID tileId, const void *data, size_t len);
  25. void uploadTileTexture();
  26. RenderChunk createChunk(
  27. TileID tiles[SwanCommon::CHUNK_WIDTH * SwanCommon::CHUNK_HEIGHT]);
  28. void modifyChunk(RenderChunk chunk, SwanCommon::Vec2i pos, TileID id);
  29. void destroyChunk(RenderChunk chunk);
  30. private:
  31. std::unique_ptr<RendererState> state_;
  32. std::vector<std::pair<SwanCommon::Vec2, RenderChunk>> draw_chunks_;
  33. };
  34. inline void Renderer::drawChunk(SwanCommon::Vec2 pos, RenderChunk chunk) {
  35. draw_chunks_.emplace_back(pos, chunk);
  36. }
  37. }