123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #ifndef WRAPPER_H
- #define WRAPPER_H
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include "ShaderProgram.h"
- #include "../math/Vector3D.h"
- #include "../math/Matrix3D.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);
-
- static void setLineMode(bool mode);
-
- static float testX;
- static float testY;
- static float testZ;
- static Matrix3D testMat;
- private:
- static const uint64_t NANOS_PER_TICK = 50000000;
- static const int MAX_TICKS_PER_FRAME = 5;
-
- static bool onProgramInit();
-
- static void onInit();
- static void onRenderTick(float lag);
- static void onTerm();
-
- 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;
-
- // active program
- static GLuint activeProgram;
-
- // world data
- static ShaderProgram worldShader;
- static GLuint worldFrameBuffer;
- static GLuint worldPositionTexture;
- static GLuint worldNormalTexture;
- static GLuint worldColorTexture;
- static GLuint worldDepthTexture;
-
- // ssao shader
- static ShaderProgram ssaoShader;
- static GLuint ssaoFrameBuffer;
- static GLuint ssaoTexture;
-
- // post shader
- static GLuint postVba;
- static GLuint postVbo;
- static ShaderProgram postShader;
- static int scale;
- static int width;
- static int height;
-
- static bool lineMode;
-
- // ssao kernel data
- static constexpr int ssaoKernelAmount = 64;
- static Vector3D ssaoKernel[ssaoKernelAmount];
- static GLuint noiseTexture;
- };
- #endif
|