Skip to content

Commit

Permalink
Start of cell rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Zang3th committed Jan 23, 2023
1 parent 683ac85 commit 29836cf
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 83 deletions.
16 changes: 10 additions & 6 deletions Apps/CellSim/src/CellSimApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ namespace CS
Engine::RenderManager::Init();

//Configure some application settings
Engine::APP_SETTINGS.planeSize = 1;
Engine::AppSettings::planeSize = 1;

//Load up shaders and textures
LoadResources();

//Create application specific renderers
_sceneRenderer = Engine::RenderManager::AddScene(_nearPlane, _farPlane, _lightPos, _lightCol);
_cellRenderer = new Engine::CellRenderer(glm::vec3(512.0f, 0.5f, 512.0f), 1.0f, _nearPlane, _farPlane);
_shadowRenderer = Engine::RenderManager::AddShadows(8192, _lightPos, _lightTarget,
glm::ortho(-60.0f, 60.0f, -60.0f, 60.0f, 77.0f, 240.0f),
"ShadowCreateShader");
Expand All @@ -46,8 +47,8 @@ namespace CS
//Ground plane
_sceneRenderer->AddPlane
(
Engine::APP_SETTINGS.planeSize, //Length in x direction
Engine::APP_SETTINGS.planeSize, //Length in z direction
Engine::AppSettings::planeSize, //Length in x direction
Engine::AppSettings::planeSize, //Length in z direction
1024.0f, //Tile size
glm::vec3(0.0f), //Position
_shadowRenderer->GetDepthTexture(), //Depth texture
Expand All @@ -66,15 +67,15 @@ namespace CS
);

//Cube
_sceneRenderer->AddObject
/*_sceneRenderer->AddObject
(
0.5f, //Size
glm::vec3(0.0f), //Rotation
glm::vec3(500.0f, 10.0f, 524.0f), //Position
_shadowRenderer->GetDepthTexture(), //Depth texture
"Cube", //Name
"../Res/Assets/Models/CellSim/Cube" //Path to obj file
);
);*/
}

void CellSimApp::AddSprites()
Expand Down Expand Up @@ -102,6 +103,8 @@ namespace CS
{
Engine::ResourceManager::CleanUp();
Engine::RenderManager::CleanUp();

delete _cellRenderer; //TODO: Move into RenderManager after prototyping
}

void CellSimApp::Update()
Expand Down Expand Up @@ -132,8 +135,9 @@ namespace CS
Engine::PROFILE_SCOPE("Render scene");

Engine::RenderManager::RenderScene();
_cellRenderer->Flush(nullptr);

if(Engine::APP_SETTINGS.debugSprites)
if(Engine::AppSettings::debugSprites)
Engine::RenderManager::RenderSprites();
}

Expand Down
1 change: 1 addition & 0 deletions Apps/CellSim/src/CellSimApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace CS
Engine::SceneRenderer* _sceneRenderer = nullptr;
Engine::ShadowRenderer* _shadowRenderer = nullptr;
Engine::SpriteRenderer* _spriteRenderer = nullptr;
Engine::CellRenderer* _cellRenderer = nullptr;
Engine::Scope<CellSimInterface> _interface;

void LoadResources() final;
Expand Down
14 changes: 7 additions & 7 deletions Apps/CellSim/src/CellSimInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace CS
{
const ImGuiViewport* viewport = ImGui::GetMainViewport();
const ImVec2 workPos = viewport->WorkPos;
const auto windowWidth = (float)Engine::APP_SETTINGS.WINDOW_WIDTH;
const auto windowHeight = (float)Engine::APP_SETTINGS.WINDOW_HEIGHT;
const auto windowWidth = (float)Engine::AppSettings::WINDOW_WIDTH;
const auto windowHeight = (float)Engine::AppSettings::WINDOW_HEIGHT;
const float menuBarHeight = 25.0f;
const float sidebarWidth = 415.0f;

Expand Down Expand Up @@ -50,13 +50,13 @@ namespace CS
if(ImGui::BeginMenu("Settings"))
{
ImGui::MenuItem("Show overlay", "", &_showOverlay);
ImGui::MenuItem("Show debug sprites", "", &Engine::APP_SETTINGS.debugSprites);
ImGui::MenuItem("Show debug sprites", "", &Engine::AppSettings::debugSprites);
ImGui::EndMenu();
}

if(ImGui::BeginMenu("Rendering"))
{
ImGui::MenuItem("Wireframe-Mode", "", &Engine::APP_SETTINGS.wireframeRendering);
ImGui::MenuItem("Wireframe-Mode", "", &Engine::AppSettings::wireframeRendering);
ImGui::EndMenu();
}
}
Expand All @@ -82,13 +82,13 @@ namespace CS
//Render stats
ImGui::NewLine();
ImGui::Separator();
ImGui::Text("DrawCalls: %d", Engine::APP_SETTINGS.renderStats.drawCalls);
ImGui::Text("DrawnVertices: %d", Engine::APP_SETTINGS.renderStats.drawnVertices);
ImGui::Text("DrawCalls: %d", Engine::AppSettings::renderStats.drawCalls);
ImGui::Text("DrawnVertices: %d", Engine::AppSettings::renderStats.drawnVertices);
ImGui::Separator();

ImGui::NewLine();
ImGui::Separator();
ImGui::Text("Model passes: %d", Engine::APP_SETTINGS.renderStats.modelPasses);
ImGui::Text("Model passes: %d", Engine::AppSettings::renderStats.modelPasses);
ImGui::Separator();

//Camera stats
Expand Down
14 changes: 7 additions & 7 deletions Apps/GreenWorld/src/GreenWorldApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace GW
Engine::RenderManager::Init();

//Configure some application settings
Engine::APP_SETTINGS.planeSize = 128;
Engine::APP_SETTINGS.gravity = -20.0f;
Engine::AppSettings::planeSize = 128;
Engine::AppSettings::gravity = -20.0f;

//Load up shaders and textures
LoadResources();
Expand Down Expand Up @@ -91,8 +91,8 @@ namespace GW
//Terrain
_sceneRenderer->AddTerrain
(
Engine::APP_SETTINGS.planeSize, //Length in x direction
Engine::APP_SETTINGS.planeSize, //Length in z direction
Engine::AppSettings::planeSize, //Length in x direction
Engine::AppSettings::planeSize, //Length in z direction
1.0f, //Tile size
glm::vec3(0.0f, -2.7f, 0.0f), //Position
_shadowRenderer->GetDepthTexture(), //Depth texture
Expand All @@ -104,8 +104,8 @@ namespace GW
//Water
_sceneRenderer->AddWater
(
Engine::APP_SETTINGS.planeSize - 112, //Length in x direction
Engine::APP_SETTINGS.planeSize, //Length in z direction
Engine::AppSettings::planeSize - 112, //Length in x direction
Engine::AppSettings::planeSize, //Length in z direction
1.0f, //Tile size
glm::vec3(30.5f, 0.0f, 0.0f), //Position
0.025f, //Wave speed
Expand Down Expand Up @@ -241,7 +241,7 @@ namespace GW
Engine::RenderManager::RenderScene();
Engine::RenderManager::RenderParticles();

if(Engine::APP_SETTINGS.debugSprites)
if(Engine::AppSettings::debugSprites)
Engine::RenderManager::RenderSprites();
}

Expand Down
24 changes: 12 additions & 12 deletions Apps/GreenWorld/src/GreenWorldInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace GW
{
const ImGuiViewport* viewport = ImGui::GetMainViewport();
const ImVec2 workPos = viewport->WorkPos;
const auto windowWidth = (float)Engine::APP_SETTINGS.WINDOW_WIDTH;
const auto windowHeight = (float)Engine::APP_SETTINGS.WINDOW_HEIGHT;
const auto windowWidth = (float)Engine::AppSettings::WINDOW_WIDTH;
const auto windowHeight = (float)Engine::AppSettings::WINDOW_HEIGHT;
const float menuBarHeight = 25.0f;
const float sidebarWidth = 415.0f;
const float shaderTexBarWidth = 210.0f;
Expand Down Expand Up @@ -55,13 +55,13 @@ namespace GW
if(ImGui::BeginMenu("Settings"))
{
ImGui::MenuItem("Show overlay", "", &_showOverlay);
ImGui::MenuItem("Show debug sprites", "", &Engine::APP_SETTINGS.debugSprites);
ImGui::MenuItem("Show debug sprites", "", &Engine::AppSettings::debugSprites);
ImGui::EndMenu();
}

if(ImGui::BeginMenu("Rendering"))
{
ImGui::MenuItem("Wireframe-Mode", "", &Engine::APP_SETTINGS.wireframeRendering);
ImGui::MenuItem("Wireframe-Mode", "", &Engine::AppSettings::wireframeRendering);
ImGui::EndMenu();
}
}
Expand All @@ -87,18 +87,18 @@ namespace GW
//Render stats
ImGui::NewLine();
ImGui::Separator();
ImGui::Text("DrawCalls: %d", Engine::APP_SETTINGS.renderStats.drawCalls);
ImGui::Text("DrawnVertices: %d", Engine::APP_SETTINGS.renderStats.drawnVertices);
ImGui::Text("DrawCalls: %d", Engine::AppSettings::renderStats.drawCalls);
ImGui::Text("DrawnVertices: %d", Engine::AppSettings::renderStats.drawnVertices);
ImGui::Separator();

ImGui::NewLine();
ImGui::Separator();
ImGui::Text("Model passes: %d", Engine::APP_SETTINGS.renderStats.modelPasses);
ImGui::Text("Terrain passes: %d", Engine::APP_SETTINGS.renderStats.terrainPasses);
ImGui::Text("Water passes: %d", Engine::APP_SETTINGS.renderStats.waterPasses);
ImGui::Text("Particle passes: %d", Engine::APP_SETTINGS.renderStats.particlePasses);
ImGui::Text("Sprite passes: %d", Engine::APP_SETTINGS.renderStats.spritePasses);
ImGui::Text("Cubemap passes: %d", Engine::APP_SETTINGS.renderStats.cubemapPasses);
ImGui::Text("Model passes: %d", Engine::AppSettings::renderStats.modelPasses);
ImGui::Text("Terrain passes: %d", Engine::AppSettings::renderStats.terrainPasses);
ImGui::Text("Water passes: %d", Engine::AppSettings::renderStats.waterPasses);
ImGui::Text("Particle passes: %d", Engine::AppSettings::renderStats.particlePasses);
ImGui::Text("Sprite passes: %d", Engine::AppSettings::renderStats.spritePasses);
ImGui::Text("Cubemap passes: %d", Engine::AppSettings::renderStats.cubemapPasses);
ImGui::Separator();

//Camera stats
Expand Down
2 changes: 0 additions & 2 deletions Engine/Application/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Engine
{
AppSettings APP_SETTINGS;

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

App::~App() = default;
Expand Down
19 changes: 10 additions & 9 deletions Engine/Core/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ namespace Engine
// --- Application settings
struct AppSettings
{
const int32 WINDOW_WIDTH = 1920;
const int32 WINDOW_HEIGHT = 1080;
uint32 planeSize = 64;
float gravity = 10.0f;
bool wireframeRendering = false;
bool debugSprites = false;
RenderStats renderStats;
};
inline static constexpr int32 WINDOW_WIDTH = 1920;
inline static constexpr int32 WINDOW_HEIGHT = 1080;
inline static constexpr uint32 CELL_CUBE_SIZE = 512;
inline static uint32 planeSize = 64;
inline static float gravity = 10.0f;
inline static bool wireframeRendering = false;
inline static bool debugSprites = false;
inline static RenderStats renderStats;

extern struct AppSettings APP_SETTINGS;
AppSettings() = delete;
};
}
6 changes: 3 additions & 3 deletions Engine/Core/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Engine
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);

_windowName = title;
_window = glfwCreateWindow(APP_SETTINGS.WINDOW_WIDTH, APP_SETTINGS.WINDOW_HEIGHT, _windowName.c_str(), nullptr, nullptr);
_window = glfwCreateWindow(AppSettings::WINDOW_WIDTH, AppSettings::WINDOW_HEIGHT, _windowName.c_str(), nullptr, nullptr);

if(!_window)
Logger::Error("Failed", "GLFW-Window", std::to_string(glfwGetError(nullptr)));
Expand All @@ -40,7 +40,7 @@ namespace Engine
Logger::Info("Loaded", "OpenGL", glInfo);
}

GLRenderSettings::SetViewport(APP_SETTINGS.WINDOW_WIDTH, APP_SETTINGS.WINDOW_HEIGHT);
GLRenderSettings::SetViewport(AppSettings::WINDOW_WIDTH, AppSettings::WINDOW_HEIGHT);
GLRenderSettings::EnableDebugging();

//Start application
Expand Down Expand Up @@ -119,6 +119,6 @@ namespace Engine

float Window::GetAspectRatio()
{
return (float)APP_SETTINGS.WINDOW_WIDTH/(float)APP_SETTINGS.WINDOW_HEIGHT;
return (float)AppSettings::WINDOW_WIDTH/(float)AppSettings::WINDOW_HEIGHT;
}
}
3 changes: 2 additions & 1 deletion Engine/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
#include "ShadowRenderer.hpp"
#include "SpriteRenderer.hpp"
#include "WaterRenderer.hpp"
#include "ParticleRenderer.hpp"
#include "ParticleRenderer.hpp"
#include "CellRenderer.hpp"
2 changes: 1 addition & 1 deletion Engine/Rendering/Buffers/FrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Engine
void FrameBuffer::Unbind() const
{
GLCall(glBindFramebuffer(GL_FRAMEBUFFER, 0));
GLRenderSettings::SetViewport(APP_SETTINGS.WINDOW_WIDTH, APP_SETTINGS.WINDOW_HEIGHT);
GLRenderSettings::SetViewport(AppSettings::WINDOW_WIDTH, AppSettings::WINDOW_HEIGHT);
}

void FrameBuffer::SetColorAttachment0()
Expand Down
11 changes: 11 additions & 0 deletions Engine/Rendering/Renderables/Cell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Cell.hpp"

namespace Engine
{
// ----- Public -----

Cell::Cell()
{

}
}
10 changes: 10 additions & 0 deletions Engine/Rendering/Renderables/Cell.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

namespace Engine
{
class Cell
{
public:
Cell();
};
}
20 changes: 10 additions & 10 deletions Engine/Rendering/Renderables/Heightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace Engine
stbi_set_flip_vertically_on_load(false);

//Reserve space
_heightmap.reserve(APP_SETTINGS.planeSize * APP_SETTINGS.planeSize * sizeof(float));
_heightmap.reserve(AppSettings::planeSize * AppSettings::planeSize * sizeof(float));

if(localBuffer)
{
if(width < (int)APP_SETTINGS.planeSize || height < (int)APP_SETTINGS.planeSize)
if(width < (int)AppSettings::planeSize || height < (int)AppSettings::planeSize)
{
std::string texInfo = "Texture too small: " + filepath;
Logger::Error("Failed", "Heightmap", texInfo);
Expand Down Expand Up @@ -59,17 +59,17 @@ namespace Engine
{
//Return value at given position with some special treatment for the edges

if(x < APP_SETTINGS.planeSize && z < APP_SETTINGS.planeSize)
return _heightmap.at(APP_SETTINGS.planeSize * x + z);
if(x < AppSettings::planeSize && z < AppSettings::planeSize)
return _heightmap.at(AppSettings::planeSize * x + z);

else if(x-1 < APP_SETTINGS.planeSize && z < APP_SETTINGS.planeSize)
return _heightmap.at(APP_SETTINGS.planeSize * (x-1) + z);
else if(x-1 < AppSettings::planeSize && z < AppSettings::planeSize)
return _heightmap.at(AppSettings::planeSize * (x-1) + z);

else if(x < APP_SETTINGS.planeSize && z-1 < APP_SETTINGS.planeSize)
return _heightmap.at(APP_SETTINGS.planeSize * x + (z-1));
else if(x < AppSettings::planeSize && z-1 < AppSettings::planeSize)
return _heightmap.at(AppSettings::planeSize * x + (z-1));

else if(x-1 < APP_SETTINGS.planeSize && z-1 < APP_SETTINGS.planeSize)
return _heightmap.at(APP_SETTINGS.planeSize * (x-1) + (z-1));
else if(x-1 < AppSettings::planeSize && z-1 < AppSettings::planeSize)
return _heightmap.at(AppSettings::planeSize * (x-1) + (z-1));

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/Rendering/Renderables/Particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Engine

bool Particle::Update(float dt)
{
_velocity.y += APP_SETTINGS.gravity * _gravityFactor * dt;
_velocity.y += AppSettings::gravity * _gravityFactor * dt;
_position += _velocity * dt;
_elapsedTime += dt;

Expand Down
Loading

0 comments on commit 29836cf

Please sign in to comment.