Dawn/src/dawnopengl/display/RenderManager.cpp

90 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() :
IRenderManager(),
renderPipeline(this)
{
backBuffer = std::make_shared<BackBufferRenderTarget>(*this);
}
void RenderManager::init(std::weak_ptr<DawnGame> game) {
this->game = game;
// Lock the common shaders
lockSimpleTextured = shaderManager.lockShader<SimpleTexturedShader>();
simpleTexturedShader = shaderManager.getShader<SimpleTexturedShader>(
lockSimpleTextured
);
lockUIShaderProgram = shaderManager.lockShader<UIShader>();
uiShader = shaderManager.getShader<UIShader>(lockUIShaderProgram);
lockFontShader = shaderManager.lockShader<FontShader>();
fontShader = shaderManager.getShader<FontShader>(lockFontShader);
renderPipeline.init();
assertNoGLError();
// Prepare the initial values
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
assertNoGLError();
glBlendFuncSeparate(
GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA,
GL_ONE,
GL_ONE_MINUS_SRC_ALPHA
);
assertNoGLError();
glDepthMask(GL_TRUE);
assertNoGLError();
glDepthFunc(GL_LESS);
assertNoGLError();
}
std::shared_ptr<RenderTarget> RenderManager::getBackBuffer() {
return backBuffer;
}
RenderPipeline * RenderManager::getRenderPipeline() {
return &renderPipeline;
}
ShaderManager * RenderManager::getShaderManager() {
return &shaderManager;
}
void RenderManager::setRenderFlags(flag_t flags) {
renderFlags = flags;
if((flags & RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST) == 0) {
glDisable(GL_DEPTH_TEST);
} else {
glEnable(GL_DEPTH_TEST);
}
assertNoGLError();
if((flags & RENDER_MANAGER_RENDER_FLAG_BLEND) == 0) {
glDisable(GL_BLEND);
} else {
glEnable(GL_BLEND);
}
assertNoGLError();
}
void RenderManager::update() {
this->getRenderPipeline()->render();
}
RenderManager::~RenderManager() {
shaderManager.releaseShader<SimpleTexturedShader>(lockSimpleTextured);
shaderManager.releaseShader<UIShader>(lockUIShaderProgram);
shaderManager.releaseShader<FontShader>(lockFontShader);
}