Wrapper.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef WRAPPER_H
  2. #define WRAPPER_H
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5. #include <iostream>
  6. #include "client/engine/shader/ShaderProgram.h"
  7. #include "client/math/Vector3D.h"
  8. #include "client/math/Matrix3D.h"
  9. #include "client/engine/shader/WorldShader.h"
  10. #include "client/engine/shader/SSAOShader.h"
  11. #include "client/engine/shader/SSAOBlurShader.h"
  12. #include "client/engine/shader/FramebufferRectangle.h"
  13. #include "client/engine/shader/WorldPostShader.h"
  14. #include "client/engine/shader/OverlayShader.h"
  15. #include "client/engine/Mesh.h"
  16. #include "client/engine/Shader.h"
  17. using namespace std;
  18. class IClient
  19. {
  20. public:
  21. virtual ~IClient() = default;
  22. virtual void tick() = 0;
  23. virtual void render3DTick(float lag) = 0;
  24. virtual void render2DTick(float lag) = 0;
  25. virtual void onKeyEvent(int key, int scancode, int action, int mods) = 0;
  26. virtual void onMouseMove(double x, double y) = 0;
  27. virtual void onMouseClick(int button, int action, int mods) = 0;
  28. };
  29. class DummyClient : public IClient
  30. {
  31. public:
  32. static DummyClient dummy;
  33. void tick() override { cout << "Dummy tick" << endl; };
  34. void render3DTick(float lag) override { cout << "Dummy render3DTick" << endl; };
  35. void render2DTick(float lag) override { cout << "Dummy render3DTick" << endl; };
  36. void onKeyEvent(int key, int scancode, int action, int mods) override { cout << "Dummy onKeyEvent" << endl; };
  37. void onMouseMove(double x, double y) override { cout << "Dummy onMouseMove" << endl; };
  38. void onMouseClick(int button, int action, int mods) override { cout << "Dummy onMouseClick" << endl; };
  39. private:
  40. DummyClient() {};
  41. };
  42. class Engine
  43. {
  44. public:
  45. static bool init(int width, int height, const char* name);
  46. static void start(IClient* client);
  47. static void stop();
  48. static void printError();
  49. static int getScale();
  50. static int getWidth();
  51. static int getHeight();
  52. static float getScaledWidth();
  53. static float getScaledHeight();
  54. static float getFieldOfView();
  55. static float getNearClip();
  56. static float getFarClip();
  57. static void setMouseTrapped(bool mode);
  58. static void setMixMode();
  59. static void setColorMode();
  60. static void setTextureMode();
  61. private:
  62. friend void Shader::updateModelMatrix();
  63. static const uint64_t NANOS_PER_FRAME = 1000000000 / 60;
  64. static const uint64_t NANOS_PER_TICK = 50000000;
  65. static const int MAX_TICKS_PER_FRAME = 1;
  66. static void sleep(uint64_t nanos);
  67. static bool initOverlayShader();
  68. static void onRenderTick(float lag);
  69. static void onKeyEvent(GLFWwindow* w, int key, int scancode, int action, int mods);
  70. static void onMouseMove(GLFWwindow* w, double x, double y);
  71. static void onMouseClick(GLFWwindow* w, int button, int action, int mods);
  72. static void onWindowResize(GLFWwindow* w, int width, int height);
  73. static void setViewMatrix(const float* data);
  74. static void setModelMatrix(const float* data);
  75. static void updateScale();
  76. static IClient* client;
  77. // window data
  78. static GLFWwindow* window;
  79. static int scale;
  80. static int width;
  81. static int height;
  82. static int resizeTicks;
  83. // projection data
  84. static float fovY;
  85. static float nearClip;
  86. static float farClip;
  87. static Matrix3D projMatrix;
  88. // rectangle for framebuffer drawing
  89. static FramebufferRectangle rectangle;
  90. static int stage;
  91. // shader stage 1 - world
  92. static WorldShader worldShader;
  93. // shader stage 2 - world ssao
  94. static SSAOShader ssaoShader;
  95. // shader stage 3 - world ssao blur
  96. static SSAOBlurShader ssaoBlurShader;
  97. // shader stage 4 - world post
  98. static WorldPostShader worldPostShader;
  99. // shader stage 5 - 2D overlay
  100. static OverlayShader overlayShader;
  101. };
  102. #endif