Wrapper.h 3.6 KB

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