12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #ifndef WRAPPER_H
- #define WRAPPER_H
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <iostream>
- using namespace std;
- class IClient
- {
- public:
- virtual void tick() = 0;
- virtual void renderTick(float lag) = 0;
- virtual void onKeyEvent(int key, int scancode, int action, int mods) = 0;
- virtual void onMouseClick(int button, int action, int mods) = 0;
- };
- class DummyClient : public IClient
- {
- public:
- static DummyClient dummy;
-
- void tick() override { cout << "Dummy tick" << endl; };
- void renderTick(float lag) override { cout << "Dummy renderTick" << endl; };
- void onKeyEvent(int key, int scancode, int action, int mods) override { cout << "Dummy onKeyEvent" << endl; };
- void onMouseClick(int button, int action, int mods) override { cout << "Dummy onMouseClick" << endl; };
- private:
- DummyClient() {};
- };
- class Engine
- {
- public:
- static bool init(int width, int height, const char* name);
- static void start(IClient* client);
- static void stop();
-
- static void printError();
-
- static int getScale();
- static int getWidth();
- static int getHeight();
-
- static GLint getUniformLocation(const GLchar* name);
- static void setMatrix(GLint location, const GLfloat* m);
- static void setInt(GLint location, GLint i);
- static void setFloat(GLint location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4);
- private:
- static const uint64_t NANOS_PER_TICK = 50000000;
- static const int MAX_TICKS_PER_FRAME = 5;
-
- static void generateFramebuffer();
- static void generatePostData();
- static void destroyPostData();
-
- static GLchar* readFile(const char* name);
- static bool checkShaderErrors(const char* name, GLuint shader);
- static GLuint compileProgram(GLuint& vShader, GLuint& fShader, const GLchar* v, const GLchar* f);
- static GLuint createProgram(const char* v, const char* f, GLuint& vShader, GLuint& fShader);
-
- static void onKeyEvent(GLFWwindow* w, int key, int scancode, int action, int mods);
- static void onMouseClick(GLFWwindow* w, int button, int action, int mods);
- static void onWindowResize(GLFWwindow* w, int width, int height);
-
- static void updateScale();
-
- static IClient* client;
- static GLFWwindow* window;
-
- static GLuint vShader;
- static GLuint fShader;
- static GLuint program;
-
- static GLuint postVba;
- static GLuint postVbo;
- static GLuint postVShader;
- static GLuint postFShader;
- static GLuint postProgram;
-
- static GLuint frameBuffer;
- static GLuint frameTexture;
- static GLuint renderBuffer;
- static int scale;
- static int width;
- static int height;
- };
- #endif
|