Wrapper.h 3.4 KB

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