Wrapper.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #ifndef WRAPPER_H
  2. #define WRAPPER_H
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5. #include "ShaderProgram.h"
  6. #include "../math/Vector3D.h"
  7. #include "../math/Matrix3D.h"
  8. #include <iostream>
  9. using namespace std;
  10. class IClient
  11. {
  12. public:
  13. virtual void tick() = 0;
  14. virtual void renderTick(float lag) = 0;
  15. virtual void onKeyEvent(int key, int scancode, int action, int mods) = 0;
  16. virtual void onMouseClick(int button, int action, int mods) = 0;
  17. };
  18. class DummyClient : public IClient
  19. {
  20. public:
  21. static DummyClient dummy;
  22. void tick() override { cout << "Dummy tick" << endl; };
  23. void renderTick(float lag) override { cout << "Dummy renderTick" << endl; };
  24. void onKeyEvent(int key, int scancode, int action, int mods) override { cout << "Dummy onKeyEvent" << endl; };
  25. void onMouseClick(int button, int action, int mods) override { cout << "Dummy onMouseClick" << endl; };
  26. private:
  27. DummyClient() {};
  28. };
  29. class Engine
  30. {
  31. public:
  32. static bool init(int width, int height, const char* name);
  33. static void start(IClient* client);
  34. static void stop();
  35. static void printError();
  36. static int getScale();
  37. static int getWidth();
  38. static int getHeight();
  39. static GLint getUniformLocation(const GLchar* name);
  40. static void setMatrix(GLint location, const GLfloat* m);
  41. static void setInt(GLint location, GLint i);
  42. static void setFloat(GLint location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4);
  43. static void setLineMode(bool mode);
  44. static float testX;
  45. static float testY;
  46. static float testZ;
  47. static Matrix3D testMat;
  48. private:
  49. static const uint64_t NANOS_PER_TICK = 50000000;
  50. static const int MAX_TICKS_PER_FRAME = 5;
  51. static bool onProgramInit();
  52. static void onInit();
  53. static void onRenderTick(float lag);
  54. static void onTerm();
  55. static GLchar* readFile(const char* name);
  56. static bool checkShaderErrors(const char* name, GLuint shader);
  57. static GLuint compileProgram(GLuint& vShader, GLuint& fShader, const GLchar* v, const GLchar* f);
  58. static GLuint createProgram(const char* v, const char* f, GLuint& vShader, GLuint& fShader);
  59. static void onKeyEvent(GLFWwindow* w, int key, int scancode, int action, int mods);
  60. static void onMouseClick(GLFWwindow* w, int button, int action, int mods);
  61. static void onWindowResize(GLFWwindow* w, int width, int height);
  62. static void updateScale();
  63. static IClient* client;
  64. static GLFWwindow* window;
  65. // active program
  66. static GLuint activeProgram;
  67. // world data
  68. static ShaderProgram worldShader;
  69. static GLuint worldFrameBuffer;
  70. static GLuint worldPositionTexture;
  71. static GLuint worldNormalTexture;
  72. static GLuint worldColorTexture;
  73. static GLuint worldDepthTexture;
  74. // ssao shader
  75. static ShaderProgram ssaoShader;
  76. static GLuint ssaoFrameBuffer;
  77. static GLuint ssaoTexture;
  78. // post shader
  79. static GLuint postVba;
  80. static GLuint postVbo;
  81. static ShaderProgram postShader;
  82. static int scale;
  83. static int width;
  84. static int height;
  85. static bool lineMode;
  86. // ssao kernel data
  87. static constexpr int ssaoKernelAmount = 64;
  88. static Vector3D ssaoKernel[ssaoKernelAmount];
  89. static GLuint noiseTexture;
  90. };
  91. #endif