150 lines
3.5 KiB
C++
150 lines
3.5 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <algorithm>
|
|
#include <GL/glew.h>
|
|
#include <string>
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include "typedefs.hpp"
|
|
|
|
#include "presets/WeatherPreset.hpp"
|
|
|
|
class Level;
|
|
class Player;
|
|
class Camera;
|
|
class Batch3D;
|
|
class LineBatch;
|
|
class ChunksRenderer;
|
|
class ParticlesRenderer;
|
|
class BlockWrapsRenderer;
|
|
class PrecipitationRenderer;
|
|
class GuidesRenderer;
|
|
class TextsRenderer;
|
|
class Shader;
|
|
class Frustum;
|
|
class Engine;
|
|
class LevelFrontend;
|
|
class Skybox;
|
|
class PostProcessing;
|
|
class DrawContext;
|
|
class ModelBatch;
|
|
class Assets;
|
|
struct EngineSettings;
|
|
|
|
struct Weather {
|
|
WeatherPreset a {};
|
|
WeatherPreset b {};
|
|
std::string nameA;
|
|
std::string nameB;
|
|
float t = 1.0f;
|
|
float speed = 0.0f;
|
|
|
|
void update(float delta) {
|
|
t += delta * speed;
|
|
t = std::min(t, 1.0f);
|
|
b.intensity = t;
|
|
a.intensity = 1.0f - t;
|
|
}
|
|
|
|
void change(WeatherPreset preset, float time, std::string name="") {
|
|
std::swap(a, b);
|
|
std::swap(nameA, nameB);
|
|
b = std::move(preset);
|
|
t = 0.0f;
|
|
speed = 1.0f / glm::max(time, 1.e-5f);
|
|
nameB = std::move(name);
|
|
update(0.0f);
|
|
}
|
|
|
|
float fogOpacity() const {
|
|
return b.fogOpacity * t + a.fogOpacity * (1.0f - t);
|
|
}
|
|
|
|
float fogDencity() const {
|
|
return b.fogDencity * t + a.fogDencity * (1.0f - t);
|
|
}
|
|
|
|
float fogCurve() const {
|
|
return b.fogCurve * t + a.fogCurve * (1.0f - t);
|
|
}
|
|
};
|
|
|
|
class WorldRenderer {
|
|
Engine& engine;
|
|
const Level& level;
|
|
Player& player;
|
|
const Assets& assets;
|
|
std::unique_ptr<Frustum> frustumCulling;
|
|
std::unique_ptr<LineBatch> lineBatch;
|
|
std::unique_ptr<Batch3D> batch3d;
|
|
std::unique_ptr<ChunksRenderer> chunks;
|
|
std::unique_ptr<GuidesRenderer> guides;
|
|
std::unique_ptr<Skybox> skybox;
|
|
std::unique_ptr<ModelBatch> modelBatch;
|
|
|
|
float timer = 0.0f;
|
|
bool debug = false;
|
|
|
|
/// @brief Render block selection lines
|
|
void renderBlockSelection();
|
|
|
|
void renderHands(const Camera& camera, float delta);
|
|
|
|
/// @brief Render lines (selection and debug)
|
|
/// @param camera active camera
|
|
/// @param linesShader shader used
|
|
void renderLines(
|
|
const Camera& camera, Shader& linesShader, const DrawContext& pctx
|
|
);
|
|
|
|
void renderBlockOverlay(const DrawContext& context);
|
|
|
|
void setupWorldShader(
|
|
Shader& shader,
|
|
const Camera& camera,
|
|
const EngineSettings& settings,
|
|
float fogFactor
|
|
);
|
|
public:
|
|
std::unique_ptr<TextsRenderer> texts;
|
|
std::unique_ptr<ParticlesRenderer> particles;
|
|
std::unique_ptr<BlockWrapsRenderer> blockWraps;
|
|
std::unique_ptr<PrecipitationRenderer> precipitation;
|
|
Weather weather {};
|
|
|
|
static bool showChunkBorders;
|
|
static bool showEntitiesDebug;
|
|
|
|
WorldRenderer(Engine& engine, LevelFrontend& frontend, Player& player);
|
|
~WorldRenderer();
|
|
|
|
void draw(
|
|
const DrawContext& context,
|
|
Camera& camera,
|
|
bool hudVisible,
|
|
bool pause,
|
|
float delta,
|
|
PostProcessing* postProcessing
|
|
);
|
|
|
|
/// @brief Render level without diegetic interface
|
|
/// @param context graphics context
|
|
/// @param camera active camera
|
|
/// @param settings engine settings
|
|
void renderLevel(
|
|
const DrawContext& context,
|
|
const Camera& camera,
|
|
const EngineSettings& settings,
|
|
float delta,
|
|
bool pause,
|
|
bool hudVisible
|
|
);
|
|
|
|
void clear();
|
|
|
|
void setDebug(bool flag);
|
|
};
|