Wrapper.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 onMouseClick(int button, int action, int mods) = 0;
  25. };
  26. class DummyClient : public IClient
  27. {
  28. public:
  29. static DummyClient dummy;
  30. void tick() override { cout << "Dummy tick" << endl; };
  31. void render3DTick(float lag) override { cout << "Dummy render3DTick" << endl; };
  32. void render2DTick(float lag) override { cout << "Dummy render3DTick" << endl; };
  33. void onKeyEvent(int key, int scancode, int action, int mods) override { cout << "Dummy onKeyEvent" << endl; };
  34. void onMouseClick(int button, int action, int mods) override { cout << "Dummy onMouseClick" << endl; };
  35. private:
  36. DummyClient() {};
  37. };
  38. class Engine
  39. {
  40. public:
  41. static bool init(int width, int height, const char* name);
  42. static void start(IClient* client);
  43. static void stop();
  44. static void printError();
  45. static int getScale();
  46. static int getWidth();
  47. static int getHeight();
  48. static float getFieldOfView();
  49. static float getNearClip();
  50. static float getFarClip();
  51. static void setWorldViewMatrix(const float* data);
  52. static void setWorldModelMatrix(const float* data);
  53. static void setOverlayModelMatrix(const float* data);
  54. private:
  55. static const uint64_t NANOS_PER_FRAME = 1000000000 / 60;
  56. static const uint64_t NANOS_PER_TICK = 50000000;
  57. static const int MAX_TICKS_PER_FRAME = 1;
  58. static void sleep(uint64_t nanos);
  59. static bool initOverlayShader();
  60. static void onRenderTick(float lag);
  61. static void onKeyEvent(GLFWwindow* w, int key, int scancode, int action, int mods);
  62. static void onMouseClick(GLFWwindow* w, int button, int action, int mods);
  63. static void onWindowResize(GLFWwindow* w, int width, int height);
  64. static void updateScale();
  65. static IClient* client;
  66. // window data
  67. static GLFWwindow* window;
  68. static int scale;
  69. static int width;
  70. static int height;
  71. // projection data
  72. static float fovY;
  73. static float nearClip;
  74. static float farClip;
  75. static Matrix3D projMatrix;
  76. // rectangle for framebuffer drawing
  77. static FramebufferRectangle rectangle;
  78. // shader stage 1 - world
  79. static WorldShader worldShader;
  80. // shader stage 2 - world ssao
  81. static SSAOShader ssaoShader;
  82. // shader stage 3 - world ssao blur
  83. static SSAOBlurShader ssaoBlurShader;
  84. // shader stage 4 - world post
  85. static WorldPostShader worldPostShader;
  86. // shader stage 5 - 2D overlay
  87. static OverlayShader overlayShader;
  88. };
  89. #endif