2020-07-10 17:49:16 +00:00
|
|
|
#include "Renderer.hpp"
|
|
|
|
|
|
|
|
#include "../world/materials.hpp"
|
|
|
|
#include "../control/Camera.hpp"
|
|
|
|
|
|
|
|
Renderer::Renderer(const Renderer::options& options) {
|
|
|
|
glGenVertexArrays(1, &VertexArrayID);
|
|
|
|
glBindVertexArray(VertexArrayID);
|
|
|
|
|
|
|
|
MainPass = new MainProgram(options.main);
|
2020-07-13 16:45:08 +00:00
|
|
|
SkyPass = new SkyProgram();
|
|
|
|
SkyEnable = options.skybox;
|
2020-07-10 17:49:16 +00:00
|
|
|
|
2020-07-12 13:46:51 +00:00
|
|
|
FogColor = glm::vec3(options.clear_color.x, options.clear_color.y, options.clear_color.z);
|
2020-07-10 17:49:16 +00:00
|
|
|
loadTextures(options.textures, options.mipMapLOD);
|
|
|
|
}
|
|
|
|
|
|
|
|
Renderer::~Renderer() {
|
|
|
|
unloadTextures();
|
|
|
|
delete MainPass;
|
2020-07-13 16:45:08 +00:00
|
|
|
delete SkyPass;
|
2020-07-10 17:49:16 +00:00
|
|
|
glDeleteVertexArrays(1, &VertexArrayID);
|
|
|
|
}
|
|
|
|
|
|
|
|
PassContext Renderer::getPass() {
|
2020-07-13 16:45:08 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2020-07-10 17:49:16 +00:00
|
|
|
return PassContext(this, MainPass);
|
|
|
|
}
|
2020-07-13 16:45:08 +00:00
|
|
|
void Renderer::postProcess() {
|
|
|
|
if(SkyEnable) {
|
|
|
|
SkyPass->draw(this);
|
|
|
|
}
|
|
|
|
}
|
2020-07-10 17:49:16 +00:00
|
|
|
|
|
|
|
void Renderer::reloadShaders(const MainProgram::options& options) {
|
|
|
|
delete MainPass;
|
|
|
|
MainPass = new MainProgram(options);
|
|
|
|
}
|
|
|
|
void Renderer::reloadTextures(const std::string& texturePath, float mipMapLOD) {
|
|
|
|
unloadTextures();
|
|
|
|
loadTextures(texturePath, mipMapLOD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::unloadTextures() {
|
|
|
|
glDeleteTextures(1, &HOSAtlas);
|
|
|
|
glDeleteTextures(1, &NormalAtlas);
|
|
|
|
glDeleteTextures(1, &TextureAtlas);
|
|
|
|
}
|
|
|
|
void Renderer::loadTextures(const std::string& texturePath, float mipMapLOD) {
|
2020-07-13 16:45:08 +00:00
|
|
|
std::vector<std::string> terrainTextures;
|
2020-07-10 17:49:16 +00:00
|
|
|
for(const auto texture: materials::textures) {
|
2020-07-13 16:45:08 +00:00
|
|
|
terrainTextures.push_back(texturePath + "/terrain/" + texture);
|
2020-07-10 17:49:16 +00:00
|
|
|
}
|
2020-07-13 16:45:08 +00:00
|
|
|
TextureAtlas = Program::loadTextureArray(terrainTextures, "", mipMapLOD);
|
|
|
|
NormalAtlas = Program::loadTextureArray(terrainTextures, ".nrm", mipMapLOD);
|
|
|
|
HOSAtlas = Program::loadTextureArray(terrainTextures, ".hos", mipMapLOD);
|
|
|
|
|
|
|
|
Skybox = Program::loadTextureCube(texturePath + "/sky/Space_tray");
|
2020-07-10 17:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::lookFrom(const Camera& camera) {
|
|
|
|
ProjectionMatrix = camera.getProjectionMatrix();
|
|
|
|
ViewMatrix = camera.getViewMatrix();
|
2020-07-10 19:37:49 +00:00
|
|
|
FogDepth = camera.getDepth();
|
2020-07-10 17:49:16 +00:00
|
|
|
}
|