Wrapper.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef WRAPPER_H
  2. #define WRAPPER_H
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5. #include <iostream>
  6. using namespace std;
  7. class IClient
  8. {
  9. public:
  10. virtual void tick() = 0;
  11. virtual void renderTick(float lag) = 0;
  12. virtual void onKeyEvent(int key, int scancode, int action, int mods) = 0;
  13. virtual void onMouseClick(int button, int action, int mods) = 0;
  14. };
  15. class DummyClient : public IClient
  16. {
  17. public:
  18. static DummyClient dummy;
  19. void tick() override { cout << "Dummy tick" << endl; };
  20. void renderTick(float lag) override { cout << "Dummy renderTick" << endl; };
  21. void onKeyEvent(int key, int scancode, int action, int mods) override { cout << "Dummy onKeyEvent" << endl; };
  22. void onMouseClick(int button, int action, int mods) override { cout << "Dummy onMouseClick" << endl; };
  23. private:
  24. DummyClient() {};
  25. };
  26. class Engine
  27. {
  28. public:
  29. static bool init(int width, int height, const char* name);
  30. static void start(IClient* client);
  31. static void stop();
  32. static void printError();
  33. static int getScale();
  34. static int getWidth();
  35. static int getHeight();
  36. static GLint getUniformLocation(const GLchar* name);
  37. static void setMatrix(GLint location, const GLfloat* m);
  38. static void setInt(GLint location, GLint i);
  39. static void setFloat(GLint location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4);
  40. private:
  41. static const uint64_t NANOS_PER_TICK = 50000000;
  42. static const int MAX_TICKS_PER_FRAME = 5;
  43. static void generateFramebuffer();
  44. static void generatePostData();
  45. static void destroyPostData();
  46. static GLchar* readFile(const char* name);
  47. static bool checkShaderErrors(const char* name, GLuint shader);
  48. static GLuint compileProgram(GLuint& vShader, GLuint& fShader, const GLchar* v, const GLchar* f);
  49. static GLuint createProgram(const char* v, const char* f, GLuint& vShader, GLuint& fShader);
  50. static void onKeyEvent(GLFWwindow* w, int key, int scancode, int action, int mods);
  51. static void onMouseClick(GLFWwindow* w, int button, int action, int mods);
  52. static void onWindowResize(GLFWwindow* w, int width, int height);
  53. static void updateScale();
  54. static IClient* client;
  55. static GLFWwindow* window;
  56. static GLuint vShader;
  57. static GLuint fShader;
  58. static GLuint program;
  59. static GLuint postVba;
  60. static GLuint postVbo;
  61. static GLuint postVShader;
  62. static GLuint postFShader;
  63. static GLuint postProgram;
  64. static GLuint frameBuffer;
  65. static GLuint frameTexture;
  66. static GLuint depthTexture;
  67. static int scale;
  68. static int width;
  69. static int height;
  70. };
  71. #endif