#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); SkyPass = new SkyProgram(); SkyEnable = options.skybox; FogColor = glm::vec3(options.clear_color.x, options.clear_color.y, options.clear_color.z); loadTextures(options.textures, options.mipMapLOD); } Renderer::~Renderer() { unloadTextures(); delete MainPass; delete SkyPass; glDeleteVertexArrays(1, &VertexArrayID); } PassContext Renderer::getPass() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); return PassContext(this, MainPass); } void Renderer::postProcess() { if(SkyEnable) { SkyPass->draw(this); } } 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) { std::vector terrainTextures; for(const auto texture: materials::textures) { terrainTextures.push_back(texturePath + "/terrain/" + texture); } TextureAtlas = Program::loadTextureArray(terrainTextures, "", mipMapLOD); NormalAtlas = Program::loadTextureArray(terrainTextures, ".nrm", mipMapLOD); HOSAtlas = Program::loadTextureArray(terrainTextures, ".hos", mipMapLOD); Skybox = Program::loadTextureCube(texturePath + "/sky/Space_tray"); } void Renderer::lookFrom(const Camera& camera) { ProjectionMatrix = camera.getProjectionMatrix(); ViewMatrix = camera.getViewMatrix(); FogDepth = camera.getDepth(); }