|
@@ -3,8 +3,6 @@
|
|
#include "client/rendering/Framebuffers.h"
|
|
#include "client/rendering/Framebuffers.h"
|
|
#include "client/rendering/Mesh.h"
|
|
#include "client/rendering/Mesh.h"
|
|
#include "client/rendering/NoiseTexture.h"
|
|
#include "client/rendering/NoiseTexture.h"
|
|
-#include "client/rendering/Renderer.h"
|
|
|
|
-#include "client/rendering/ShaderMatrix.h"
|
|
|
|
#include "client/rendering/Shaders.h"
|
|
#include "client/rendering/Shaders.h"
|
|
#include "math/Frustum.h"
|
|
#include "math/Frustum.h"
|
|
#include "rendering/Window.h"
|
|
#include "rendering/Window.h"
|
|
@@ -17,7 +15,9 @@ static Framebuffers framebuffers;
|
|
static Size lastSize{0, 0};
|
|
static Size lastSize{0, 0};
|
|
static Frustum frustum{60.0f, 0.1f, 1000.0f, window.getSize()};
|
|
static Frustum frustum{60.0f, 0.1f, 1000.0f, window.getSize()};
|
|
static MatrixStack<16> model;
|
|
static MatrixStack<16> model;
|
|
-static Renderer renderer;
|
|
+Renderer Engine::renderer;
|
|
|
|
+ShaderMatrix Engine::matrix{nullptr, model, nullptr};
|
|
|
|
+float Engine::lag = 0.0f;
|
|
static NoiseTexture ssaoNoise;
|
|
static NoiseTexture ssaoNoise;
|
|
static Mesh rectangle;
|
|
static Mesh rectangle;
|
|
static Matrix worldProj;
|
|
static Matrix worldProj;
|
|
@@ -29,6 +29,7 @@ static bool useSsao = true;
|
|
static bool useShadows = false;
|
|
static bool useShadows = false;
|
|
static float shadowRadius = 0.01f;
|
|
static float shadowRadius = 0.01f;
|
|
static float shadowBias = 0.0002f;
|
|
static float shadowBias = 0.0002f;
|
|
|
|
+static bool running = true;
|
|
|
|
|
|
static bool initRectangle() {
|
|
static bool initRectangle() {
|
|
if(rectangle.init()) {
|
|
if(rectangle.init()) {
|
|
@@ -71,7 +72,7 @@ bool Engine::init() {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-static void renderShadow(float lag) {
|
|
+static void renderShadow() {
|
|
framebuffers.shadow.bindAndClear();
|
|
framebuffers.shadow.bindAndClear();
|
|
GL::enableDepthTesting();
|
|
GL::enableDepthTesting();
|
|
shaders.shadow.use();
|
|
shaders.shadow.use();
|
|
@@ -80,11 +81,11 @@ static void renderShadow(float lag) {
|
|
shaders.shadow.setMatrix("projView", worldShadowProjView.getValues());
|
|
shaders.shadow.setMatrix("projView", worldShadowProjView.getValues());
|
|
model.clear();
|
|
model.clear();
|
|
shaders.shadow.setMatrix("model", model.peek().getValues());
|
|
shaders.shadow.setMatrix("model", model.peek().getValues());
|
|
- ShaderMatrix sm(shaders.shadow, model, worldView);
|
|
+ Engine::matrix = {&shaders.shadow, model, &worldView};
|
|
- Game::game->renderWorld(lag, sm);
|
|
+ Game::renderWorld();
|
|
}
|
|
}
|
|
|
|
|
|
-static void renderWorld(float lag) {
|
|
+static void renderWorld() {
|
|
framebuffers.world.bindAndClear();
|
|
framebuffers.world.bindAndClear();
|
|
GL::enableDepthTesting();
|
|
GL::enableDepthTesting();
|
|
shaders.world.use();
|
|
shaders.world.use();
|
|
@@ -103,8 +104,8 @@ static void renderWorld(float lag) {
|
|
shaders.world.setInt("shadows", useShadows);
|
|
shaders.world.setInt("shadows", useShadows);
|
|
shaders.world.setFloat("radius", shadowRadius);
|
|
shaders.world.setFloat("radius", shadowRadius);
|
|
shaders.world.setFloat("zbias", shadowBias);
|
|
shaders.world.setFloat("zbias", shadowBias);
|
|
- ShaderMatrix sm(shaders.world, model, worldView);
|
|
+ Engine::matrix = {&shaders.world, model, &worldView};
|
|
- Game::game->renderWorld(lag, sm);
|
|
+ Game::renderWorld();
|
|
}
|
|
}
|
|
|
|
|
|
static void renderSSAO() {
|
|
static void renderSSAO() {
|
|
@@ -143,7 +144,7 @@ static void renderPostWorld() {
|
|
rectangle.draw();
|
|
rectangle.draw();
|
|
}
|
|
}
|
|
|
|
|
|
-static void renderOverlay(float lag) {
|
|
+static void renderOverlay() {
|
|
GL::disableDepthTesting();
|
|
GL::disableDepthTesting();
|
|
shaders.overlay.use();
|
|
shaders.overlay.use();
|
|
|
|
|
|
@@ -156,8 +157,8 @@ static void renderOverlay(float lag) {
|
|
shaders.overlay.setMatrix("model", model.peek().getValues());
|
|
shaders.overlay.setMatrix("model", model.peek().getValues());
|
|
|
|
|
|
GL::enableBlending();
|
|
GL::enableBlending();
|
|
- ShaderMatrix sm(shaders.overlay, model, m);
|
|
+ Engine::matrix = {&shaders.overlay, model, &m};
|
|
- Game::game->renderOverlay(lag, sm, renderer);
|
|
+ Game::renderOverlay();
|
|
GL::disableBlending();
|
|
GL::disableBlending();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -192,7 +193,7 @@ static void updateWorldView() {
|
|
worldShadowView.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
|
|
worldShadowView.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
|
|
}
|
|
}
|
|
|
|
|
|
-static void startRender(float lag) {
|
|
+static void startRender() {
|
|
const Size& size = window.getSize();
|
|
const Size& size = window.getSize();
|
|
if(size.width != lastSize.width || size.height != lastSize.height) {
|
|
if(size.width != lastSize.width || size.height != lastSize.height) {
|
|
GL::setViewport(size.width, size.height);
|
|
GL::setViewport(size.width, size.height);
|
|
@@ -205,27 +206,28 @@ static void startRender(float lag) {
|
|
updateWorldView();
|
|
updateWorldView();
|
|
|
|
|
|
if(useShadows) {
|
|
if(useShadows) {
|
|
- renderShadow(lag);
|
|
+ renderShadow();
|
|
}
|
|
}
|
|
- renderWorld(lag);
|
|
+ renderWorld();
|
|
if(useSsao) {
|
|
if(useSsao) {
|
|
renderSSAO();
|
|
renderSSAO();
|
|
}
|
|
}
|
|
renderPostWorld();
|
|
renderPostWorld();
|
|
- renderOverlay(lag);
|
|
+ renderOverlay();
|
|
}
|
|
}
|
|
|
|
|
|
struct Loop final {
|
|
struct Loop final {
|
|
void render(float lag) {
|
|
void render(float lag) {
|
|
- startRender(lag);
|
|
+ Engine::lag = lag;
|
|
|
|
+ startRender();
|
|
}
|
|
}
|
|
|
|
|
|
void tick() {
|
|
void tick() {
|
|
- Game::game->tick();
|
|
+ Game::tick();
|
|
}
|
|
}
|
|
|
|
|
|
bool isRunning() const {
|
|
bool isRunning() const {
|
|
- return Game::game->isRunning();
|
|
+ return running;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -234,6 +236,10 @@ void Engine::run() {
|
|
window.run(loop, 50'000'000);
|
|
window.run(loop, 50'000'000);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void Engine::stop() {
|
|
|
|
+ running = false;
|
|
|
|
+}
|
|
|
|
+
|
|
void Engine::setTextInput(TextInput* input) {
|
|
void Engine::setTextInput(TextInput* input) {
|
|
window.textInput = input;
|
|
window.textInput = input;
|
|
if(input != nullptr) {
|
|
if(input != nullptr) {
|