Skip to content

Commit

Permalink
RenderManager no longer acts as an interface just as a storage manager
Browse files Browse the repository at this point in the history
for the different renderers
  • Loading branch information
Zang3th committed Jul 4, 2024
1 parent d18701c commit 9f101a9
Show file tree
Hide file tree
Showing 28 changed files with 216 additions and 376 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Checks: "*,
-google-*,
-llvm*,
-cppcoreguidelines-*,
-perfomance-*,
-readability-identifier-length,
-hicpp-uppercase-literal-suffix,
-readability-uppercase-literal-suffix,
Expand Down
13 changes: 8 additions & 5 deletions Apps/CellSim/CellSimApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ namespace CS
LoadResources();

//Create application specific renderers
_sceneRenderer = Engine::RenderManager::AddSceneRenderer();
_sceneRenderer = new Engine::SceneRenderer();
_sceneRenderer->SetModelShader("ModelShader");
Engine::RenderManager::Submit(_sceneRenderer);

_cellRenderer = new Engine::CellRenderer("CellShader", glm::vec3(-30.0f, 0.5f, -30.0f));
Engine::RenderManager::Submit(_cellRenderer);

//Create cell manager and add cell renderer
_cellManager = Engine::MakeScope<Engine::CellManager>();
_cellManager->AddCellRenderer("CellShader", glm::vec3(-30.0f, 0.5f, -30.0f));
_cellManager = Engine::MakeScope<Engine::CellManager>(_cellRenderer);

//Create UI
_interface = Engine::MakeScope<CellSimInterface>();
Expand Down Expand Up @@ -239,13 +242,13 @@ namespace CS
{
Engine::PROFILE_SCOPE("Render scene");

Engine::RenderManager::RenderScene();
_sceneRenderer->Flush(nullptr);
}

{
Engine::PROFILE_SCOPE("Render cells");

Engine::RenderManager::RenderCells();
_cellRenderer->Flush((Engine::Renderer*)_sceneRenderer);
}

{
Expand Down
1 change: 1 addition & 0 deletions Apps/CellSim/CellSimApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace CS
Engine::uint8 _tickCounter = 0;
bool _calcPhysicsThisTurn = true;
Engine::SceneRenderer* _sceneRenderer = nullptr;
Engine::CellRenderer* _cellRenderer = nullptr;
Engine::Scope<Engine::CellManager> _cellManager;
Engine::Scope<CellSimInterface> _interface;

Expand Down
30 changes: 20 additions & 10 deletions Apps/GreenWorld/GreenWorldApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,23 @@ namespace GW
LoadResources();

//Create application specific renderers
_sceneRenderer = Engine::RenderManager::AddSceneRenderer();
_sceneRenderer = new Engine::SceneRenderer();
_sceneRenderer->SetTerrainShader("TerrainShader");
_sceneRenderer->SetModelShader("ModelShader");
_sceneRenderer->SetWaterShader("WaterShader");
_shadowRenderer = Engine::RenderManager::AddShadowRenderer(8192, glm::ortho(-90.0f, 90.0f, -90.0f, 90.0f, 110.0f, 210.0f), "ShadowCreateShader");
_waterRenderer = Engine::RenderManager::AddWaterRenderer();
_spriteRenderer = Engine::RenderManager::AddSpriteRenderer();
Engine::RenderManager::AddParticleRenderer
Engine::RenderManager::Submit(_sceneRenderer);

_shadowRenderer = new Engine::ShadowRenderer(8192, 8192, glm::ortho(-90.0f, 90.0f, -90.0f, 90.0f, 110.0f, 210.0f), "ShadowCreateShader");
_sceneRenderer->AddLightProjection(_shadowRenderer->GetLightProjection());
Engine::RenderManager::Submit(_shadowRenderer);

_waterRenderer = new Engine::WaterRenderer();
Engine::RenderManager::Submit(_waterRenderer);

_spriteRenderer = new Engine::SpriteRenderer();
Engine::RenderManager::Submit(_spriteRenderer);

_particleRenderer = new Engine::ParticleRenderer
(
200,
5.0f,
Expand All @@ -67,6 +76,7 @@ namespace GW
"ParticleShader",
glm::vec3(87.0f, 34.0f, 92.5f)
);
Engine::RenderManager::Submit(_particleRenderer);

//Create UI
_interface = Engine::MakeScope<GreenWorldInterface>();
Expand Down Expand Up @@ -234,24 +244,24 @@ namespace GW
{
Engine::PROFILE_SCOPE("Render shadows");

Engine::RenderManager::RenderShadows();
_shadowRenderer->Flush((Engine::Renderer*)_sceneRenderer);
}

{
Engine::PROFILE_SCOPE("Render water");

Engine::RenderManager::RenderWater();
_waterRenderer->Flush((Engine::Renderer*)_sceneRenderer);
}

{
Engine::PROFILE_SCOPE("Render scene");

Engine::RenderManager::RenderScene();
Engine::RenderManager::RenderParticles();
_sceneRenderer->Flush(nullptr);
_particleRenderer->Flush((Engine::Renderer*)_sceneRenderer);

if(Engine::UIParams::debugSprites)
{
Engine::RenderManager::RenderSprites();
_spriteRenderer->Flush(nullptr);
}
}

Expand Down
9 changes: 5 additions & 4 deletions Apps/GreenWorld/GreenWorldApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ namespace GW
class GreenWorldApp final : public Engine::App
{
private:
Engine::SceneRenderer* _sceneRenderer = nullptr;
Engine::ShadowRenderer* _shadowRenderer = nullptr;
Engine::WaterRenderer* _waterRenderer = nullptr;
Engine::SpriteRenderer* _spriteRenderer = nullptr;
Engine::SceneRenderer* _sceneRenderer = nullptr;
Engine::ShadowRenderer* _shadowRenderer = nullptr;
Engine::WaterRenderer* _waterRenderer = nullptr;
Engine::ParticleRenderer* _particleRenderer = nullptr;
Engine::SpriteRenderer* _spriteRenderer = nullptr;
Engine::Scope<GreenWorldInterface> _interface;
Engine::Scope<Engine::Audio> _audio;

Expand Down
3 changes: 2 additions & 1 deletion Apps/Liquefied/LiquefiedApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ namespace Liq
LoadResources();

//Create grid renderer
_gridRenderer = Engine::RenderManager::AddGridRenderer
_gridRenderer = new Engine::GridRenderer
(
Engine::LiquiefiedParams::SIMULATION_WIDTH,
Engine::LiquiefiedParams::SIMULATION_HEIGHT,
10,
"GridShader"
);
Engine::RenderManager::Submit(_gridRenderer);

//Create UI
_interface = Engine::MakeScope<LiquefiedInterface>();
Expand Down
3 changes: 2 additions & 1 deletion Engine/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
#include "SpriteRenderer.hpp"
#include "WaterRenderer.hpp"
#include "ParticleRenderer.hpp"
#include "GridRenderer.hpp"

// ----- Physics -----
#include "CellManager.hpp"
#include "FluidSimulator.hpp"
#include "FluidSimulator.hpp"
17 changes: 3 additions & 14 deletions Engine/Physics/CellularAutomata/CellManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,12 @@ namespace Engine

// ----- Public -----

CellManager::CellManager()
CellManager::CellManager(CellRenderer* cellRenderer)
: _cellRenderer(cellRenderer)
{
_cellSpawnerStorage.reserve(5);
}

void CellManager::AddCellRenderer(const std::string& shader, const glm::vec3& worldSpawnPos)
{
if(RenderManager::GetInitStatus())
{
_cellRenderer = Engine::RenderManager::AddCellRenderer(shader, worldSpawnPos);
}
else
{
Logger::Error("Failed", "CellRenderer", "RenderManager wasn't initialized!");
}
}

void CellManager::AddCell(const CellParams& cellParams)
{
uint32 cellCount = CellSimParams::cellsAlive;
Expand Down Expand Up @@ -318,4 +307,4 @@ namespace Engine
Logger::Print("Cells alive: " + std::to_string(CellSimParams::cellsAlive));
Logger::Print("Excessive cell counter: " + std::to_string(_excessiveCells));
}
}
}
7 changes: 4 additions & 3 deletions Engine/Physics/CellularAutomata/CellManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include "CellStorage.hpp"
#include "Types.hpp"
#include "GlobalParams.hpp"
#include "RenderManager.hpp"
#include "CellRenderer.hpp"
#include "Random.hpp"

namespace Engine
{
Expand All @@ -22,7 +23,7 @@ namespace Engine
void HandleWaterCell(uint32 index, const glm::u32vec3& cellPos);

public:
CellManager();
explicit CellManager(CellRenderer* cellRenderer);
void AddCellRenderer(const std::string& shader, const glm::vec3& worldSpawnPos);
void AddCell(const CellParams& cellParams);
void AddCellWithoutRender(const CellParams& cellParams);
Expand All @@ -35,4 +36,4 @@ namespace Engine
void CreateCellWorld();
void PrintDebug();
};
}
}
18 changes: 9 additions & 9 deletions Engine/Rendering/Renderer/CellRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ namespace Engine
{
// ----- Private -----

CellRenderer::CellRenderer(Shader* shader, const glm::vec3& worldSpawnPos)
: _verticeCount(36), _shader(shader), _worldSpawnPos(worldSpawnPos), _positionStorage{glm::vec3(0.0f)},
_colorStorage{glm::vec3(1.0f)}
{
Logger::Info("Created", "Renderer", __func__);
InitGpuStorage();
}

void CellRenderer::InitGpuStorage()
{
//Create and bind vao
Expand Down Expand Up @@ -52,6 +44,14 @@ namespace Engine

// ----- Public -----

CellRenderer::CellRenderer(const std::string& shader, const glm::vec3& worldSpawnPos)
: _verticeCount(36), _shader(ResourceManager::GetShader(shader)), _worldSpawnPos(worldSpawnPos), _positionStorage{glm::vec3(0.0f)},
_colorStorage{glm::vec3(1.0f)}
{
Logger::Info("Created", "Renderer", __func__);
InitGpuStorage();
}

void CellRenderer::Flush(Renderer* sceneRenderer)
{
uint32 cellCount = CellSimParams::cellsAlive;
Expand Down Expand Up @@ -102,4 +102,4 @@ namespace Engine
_positionStorage.at(index) = _worldSpawnPos + glm::vec3(cellPos);
_colorStorage.at(index) = cellColor;
}
}
}
12 changes: 5 additions & 7 deletions Engine/Rendering/Renderer/CellRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace Engine
{
class CellRenderer final : public Renderer
{
friend class RenderManager;

private:
Scope<VertexArray> _vao;
Scope<VertexBuffer> _vboVert, _vboPos, _vboColor;
Expand All @@ -28,14 +26,14 @@ namespace Engine
std::array<glm::vec3, CellSimParams::MAX_CELL_AMOUNT> _positionStorage;
std::array<glm::vec3, CellSimParams::MAX_CELL_AMOUNT> _colorStorage;

CellRenderer(Shader* shader, const glm::vec3& worldSpawnPos);
~CellRenderer() override = default;

void InitGpuStorage();
void UploadGPUStorage();

public:
void Flush(Renderer* renderer) override;
CellRenderer(const std::string& shader, const glm::vec3& worldSpawnPos);
~CellRenderer() override = default;

void Flush(Renderer* sceneRenderer) override;
void UpdateGPUStorage(uint32 index, const glm::u32vec3& cellPos, const glm::vec3& cellColor);
};
}
}
36 changes: 18 additions & 18 deletions Engine/Rendering/Renderer/GridRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ namespace Engine
{
// ----- Private -----

GridRenderer::GridRenderer
(
const uint32 width,
const uint32 height,
const uint32 quadSize,
const std::string& shader
)
: _gridWidth(width), _gridHeight(height), _quadSize(quadSize), _quadAmountTotal(_gridWidth * _gridHeight),
_defaultColor(glm::vec3(0.1f, 0.1f, 0.1f)), _defaultGradientFactor(0.000025f), _shader(ResourceManager::GetShader(shader)),
_orthoProj(glm::ortho(0.0f, (float)WindowParams::WIDTH, 0.0f, (float)WindowParams::HEIGHT, -1.0f, 1.0f)),
_model(glm::scale(glm::mat4(1.0f), glm::vec3(glm::vec2((float)_quadSize), 0.0f)))
{
Logger::Info("Created", "Renderer", __func__);
_colorStorage.reserve(_quadAmountTotal);
InitGpuStorage();
}

void GridRenderer::InitGpuStorage()
{
//Create vertice data
Expand Down Expand Up @@ -62,6 +45,23 @@ namespace Engine

// ----- Public -----

GridRenderer::GridRenderer
(
const uint32 width,
const uint32 height,
const uint32 quadSize,
const std::string& shader
)
: _gridWidth(width), _gridHeight(height), _quadSize(quadSize), _quadAmountTotal(_gridWidth * _gridHeight),
_defaultColor(glm::vec3(0.1f, 0.1f, 0.1f)), _defaultGradientFactor(0.000025f), _shader(ResourceManager::GetShader(shader)),
_orthoProj(glm::ortho(0.0f, (float)WindowParams::WIDTH, 0.0f, (float)WindowParams::HEIGHT, -1.0f, 1.0f)),
_model(glm::scale(glm::mat4(1.0f), glm::vec3(glm::vec2((float)_quadSize), 0.0f)))
{
Logger::Info("Created", "Renderer", __func__);
_colorStorage.reserve(_quadAmountTotal);
InitGpuStorage();
}

void GridRenderer::Flush(Renderer* renderer)
{
//Check for Wireframe-Mode
Expand Down Expand Up @@ -131,4 +131,4 @@ namespace Engine
_vboColor->Update(&_backupStorage[0], _backupStorage.size() * 4 * sizeof(float));
_vboColor->Unbind();
}
}
}
Loading

0 comments on commit 9f101a9

Please sign in to comment.