Dawn/src/dawnopengl/display/RenderManager.cpp
2023-05-26 10:44:17 -07:00

83 lines
2.3 KiB
C++

// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "dawnopengl.hpp"
#include "game/DawnGame.hpp"
#include "display/RenderManager.hpp"
using namespace Dawn;
RenderManager::RenderManager(DawnGame *game) :
IRenderManager(game),
backBuffer(*this),
renderPipeline(this)
{
}
void RenderManager::init() {
// Lock the common shaders
this->lockSimpleTextured = this->shaderManager.lockShader<SimpleTexturedShader>();
this->simpleTexturedShader = this->shaderManager.getShader<SimpleTexturedShader>(this->lockSimpleTextured);
this->lockUIShaderProgram = this->shaderManager.lockShader<SimpleTexturedShader>();
this->uiShader = this->shaderManager.getShader<SimpleTexturedShader>(this->lockUIShaderProgram);
this->lockFontShader = this->shaderManager.lockShader<FontShader>();
this->fontShader = this->shaderManager.getShader<FontShader>(this->lockFontShader);
this->renderPipeline.init();
this->fontManager.init();
// Prepare the initial values
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
this->defaultFont.init();
}
RenderTarget * RenderManager::getBackBuffer() {
return &this->backBuffer;
}
RenderPipeline * RenderManager::getRenderPipeline() {
return &this->renderPipeline;
}
ShaderManager * RenderManager::getShaderManager() {
return &this->shaderManager;
}
FontManager * RenderManager::getFontManager() {
return &this->fontManager;
}
void RenderManager::setRenderFlags(renderflag_t flags) {
this->renderFlags = flags;
if((flags & RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST) == 0) {
glDisable(GL_DEPTH_TEST);
} else {
glEnable(GL_DEPTH_TEST);
}
if((flags & RENDER_MANAGER_RENDER_FLAG_BLEND) == 0) {
glDisable(GL_BLEND);
} else {
glEnable(GL_BLEND);
}
}
void RenderManager::update() {
this->getRenderPipeline()->render();
}
RenderManager::~RenderManager() {
this->shaderManager.releaseShader<SimpleTexturedShader>(this->lockSimpleTextured);
this->shaderManager.releaseShader<SimpleTexturedShader>(this->lockUIShaderProgram);
this->shaderManager.releaseShader<FontShader>(this->lockFontShader);
}