Skip to content

Commit

Permalink
Improved and simplified Renderer API, Implemed Render Target logic
Browse files Browse the repository at this point in the history
- Reduced redundant static RenderCommand class
- Renderer now isn't static and exist in Application class
- All render commands submited directly by Renderer class
- Imgui library is being built along with other vendor libs
- Rendering is now consists of Three Render passes:
1. Render to multisampled render target (if MSAA is enabled)
2. Render from multisampled to intermidiate
3. Render to framebuffer to draw on screen
  • Loading branch information
denyskryvytskyi committed Apr 22, 2024
1 parent caf1c86 commit daedb66
Show file tree
Hide file tree
Showing 86 changed files with 799 additions and 361 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ option(BUILD_SANDBOX "build sandbox projects" ON)
option(BUILD_GAMES "build games" ON)
option(EDITOR_MODE "Enable ImGUI editor overlay" ON)
option(PROFILE_MODE "Enable functions profiling" ON)
option(ASSIMP_MODE "Enable 3D module with Assimp support" ON)
option(THREE_D_MODE "Enable 3D module with Assimp support" ON)

if(WIN32)
add_compile_definitions(
Expand All @@ -33,8 +33,8 @@ if (PROFILE_MODE)
add_compile_definitions(PROFILE_MODE)
endif()

if (ASSIMP_MODE)
add_compile_definitions(ASSIMP_MODE)
if (THREE_D_MODE)
add_compile_definitions(THREE_D_MODE)
endif()

add_subdirectory(Engine)
Expand All @@ -43,7 +43,7 @@ set(ElvenEngine_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})


if (BUILD_SANDBOX)
if (ASSIMP_MODE)
if (THREE_D_MODE)
add_subdirectory(Sandbox3D)
set(STARTUP_PROJECT_NAME "Sandbox3D")
else()
Expand Down
56 changes: 28 additions & 28 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ set(ENGINE_HEADERS
"src/Events/TextureEvent.h"
"src/Events/PhysicsEvent.h"
"src/Events/MeshEvent.h"
"src/Renderer/Buffer.h"
"src/Renderer/GraphicsContext.h"
"src/Renderer/RHI/Buffer.h"
"src/Renderer/RHI/GraphicsContext.h"
"src/Renderer/RHI/RendererAPI.h"
"src/Renderer/RHI/Shader.h"
"src/Renderer/RHI/VertexArray.h"
"src/Renderer/RHI/Texture.h"
"src/Renderer/RHI/RenderTarget.h"
"src/Renderer/Camera.h"
"src/Renderer/CameraController.h"
"src/Renderer/OrthographicCameraController.h"
"src/Renderer/EditorCameraController.h"
"src/Renderer/RenderCommand.h"
"src/Renderer/Renderer2D.h"
"src/Renderer/Renderer.h"
"src/Renderer/RendererAPI.h"
"src/Renderer/Shader.h"
"src/Renderer/VertexArray.h"
"src/Renderer/Texture2D.h"
"src/Renderer/TextRenderer.h"
"src/Renderer/Material.h"
"src/Renderer/Mesh.h"
Expand All @@ -49,7 +49,8 @@ set(ENGINE_HEADERS
"src/Platform/OpenGL/OpenGLRendererAPI.h"
"src/Platform/OpenGL/OpenGLShader.h"
"src/Platform/OpenGL/OpenGLVertexArray.h"
"src/Platform/OpenGL/OpenGLTexture2D.h"
"src/Platform/OpenGL/OpenGLTexture.h"
"src/Platform/OpenGL/OpenGLRenderTarget.h"
"src/Scene/Entity.h"
"src/Scene/Component.h"
"src/Scene/Behavior.h"
Expand Down Expand Up @@ -96,18 +97,18 @@ set(ENGINE_SOURCES
"src/Core/SettingsConfig.cpp"
"src/Core/Profiler.cpp"
"src/Events/EventManager.cpp"
"src/Renderer/Buffer.cpp"
"src/Renderer/GraphicsContext.cpp"
"src/Renderer/RHI/Buffer.cpp"
"src/Renderer/RHI/GraphicsContext.cpp"
"src/Renderer/RHI/RendererAPI.cpp"
"src/Renderer/RHI/Shader.cpp"
"src/Renderer/RHI/VertexArray.cpp"
"src/Renderer/RHI/RenderTarget.cpp"
"src/Renderer/Camera.cpp"
"src/Renderer/CameraController.cpp"
"src/Renderer/OrthographicCameraController.cpp"
"src/Renderer/EditorCameraController.cpp"
"src/Renderer/RenderCommand.cpp"
"src/Renderer/Renderer2D.cpp"
"src/Renderer/Renderer.cpp"
"src/Renderer/RendererAPI.cpp"
"src/Renderer/Shader.cpp"
"src/Renderer/VertexArray.cpp"
"src/Renderer/TextRenderer.cpp"
"src/Renderer/Mesh.cpp"
"src/Renderer/Material.cpp"
Expand All @@ -116,7 +117,8 @@ set(ENGINE_SOURCES
"src/Platform/OpenGL/OpenGLRendererAPI.cpp"
"src/Platform/OpenGL/OpenGLShader.cpp"
"src/Platform/OpenGL/OpenGLVertexArray.cpp"
"src/Platform/OpenGL/OpenGLTexture2D.cpp"
"src/Platform/OpenGL/OpenGLTexture.cpp"
"src/Platform/OpenGL/OpenGLRenderTarget.cpp"
"src/Platform/Windows/WindowsInput.cpp"
"src/Platform/Windows/WindowsWindow.cpp"
"src/Scene/Behavior.cpp"
Expand Down Expand Up @@ -193,17 +195,6 @@ target_include_directories(${LIBRARY_NAME}
PUBLIC ${ENGINE_INCLUDE_DIRS}
)

if (EDITOR_MODE)
add_subdirectory(${VENDOR_PATH}/imgui)
set_target_properties(imgui PROPERTIES FOLDER "Libs")
endif()

if (EDITOR_MODE)
set(STATIC_THIRD_PARTY_LIBRARIES
imgui
)
endif()

set(VENDOR_PATH_DEBUG ${PROJECT_SOURCE_DIR}/build_vendor/lib/Debug/)
set(VENDOR_PATH_RELEASE ${PROJECT_SOURCE_DIR}/build_vendor/lib/Release/)

Expand All @@ -214,6 +205,7 @@ find_library(lia_d NAMES lia PATHS ${VENDOR_PATH_DEBUG})
find_library(stb_d NAMES stb PATHS ${VENDOR_PATH_DEBUG})
find_library(freetype_d NAMES freetyped PATHS ${VENDOR_PATH_DEBUG})
find_library(fmt_d NAMES fmtd PATHS ${VENDOR_PATH_DEBUG})
find_library(imgui_d NAMES imguid PATHS ${VENDOR_PATH_DEBUG})
find_library(assimp_d NAMES assimp-vc143-mtd PATHS ${VENDOR_PATH_DEBUG})
find_library(zlib_d NAMES zlibstaticd PATHS ${VENDOR_PATH_DEBUG})

Expand All @@ -224,6 +216,7 @@ find_library(lia NAMES lia PATHS ${VENDOR_PATH_RELEASE})
find_library(stb NAMES stb PATHS ${VENDOR_PATH_RELEASE})
find_library(freetype NAMES freetype PATHS ${VENDOR_PATH_RELEASE})
find_library(fmt NAMES fmt PATHS ${VENDOR_PATH_RELEASE})
find_library(imgui NAMES imgui PATHS ${VENDOR_PATH_RELEASE})
find_library(irrklang NAMES irrKlang.lib PATHS ${VENDOR_PATH}/irrklang/lib)
find_library(assimp NAMES assimp-vc143-mt PATHS ${VENDOR_PATH_RELEASE})
find_library(zlib NAMES zlibstatic PATHS ${VENDOR_PATH_RELEASE})
Expand All @@ -239,15 +232,22 @@ debug ${irrklang} optimized ${irrklang}
debug ${fmt_d} optimized ${fmt}
)

if (ASSIMP_MODE)
if (EDITOR_MODE)
set(VENDOR
${VENDOR}
debug ${imgui_d} optimized ${imgui}
)
endif()

if (THREE_D_MODE)
set(VENDOR
${VENDOR}
debug ${assimp_d} optimized ${assimp}
debug ${zlib_d} optimized ${zlib}
)
endif()

target_link_libraries(${LIBRARY_NAME} ${STATIC_THIRD_PARTY_LIBRARIES} ${VENDOR})
target_link_libraries(${LIBRARY_NAME} ${VENDOR})

# pch header file path
set(ENGINE_PRECOMPILED_HEADERS
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Fragment shader for the mesh
#version 450 core

struct Material {
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions Engine/assets/shaders/quad.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 450 core

uniform sampler2D u_screenTexture;

in vec2 v_uv;

out vec4 color;

void main()
{
vec3 col = texture(u_screenTexture, v_uv).rgb;
color = vec4(col, 1.0);
}
11 changes: 11 additions & 0 deletions Engine/assets/shaders/quad.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 450 core
layout (location = 0) in vec2 pos;
layout (location = 1) in vec2 uv;

out vec2 v_uv;

void main()
{
v_uv = uv;
gl_Position = vec4(pos, 0.0, 1.0);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 7 additions & 10 deletions Engine/src/Core/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ Application::Application()

EL_CORE_INFO("Executable path: {0}", fileSystem::GetCurrentPath());

// Init global engine settings
gEngineSettings.LoadSettings();

m_window = Window::Create({ "ElvenEngine", gEngineSettings.windowWidth, gEngineSettings.windowHeight, gEngineSettings.enableFullscreen, gEngineSettings.enableVSync });
RenderCommand::SetViewport(0, 0, m_window->GetWidth(), m_window->GetHeight());

gTextureManager.Init();
gMeshLibrary.Init();
Renderer::Init();
Renderer2D::Init();
TextRenderer::Init();
m_renderer.Init(m_window->GetWidth(), m_window->GetHeight());
Renderer2D::Init(&m_renderer);
TextRenderer::Init(m_renderer);
gAudioManager.Init();
gSceneManager.Init();

Expand Down Expand Up @@ -93,7 +91,7 @@ Application::~Application()
gMeshLibrary.Shutdown();
gSceneManager.Shutdown();
gTextureManager.Shutdown();
Renderer::Shutdown();
m_renderer.Shutdown();
Renderer2D::Shutdown();
}

Expand Down Expand Up @@ -149,11 +147,10 @@ void Application::Run()
// ============== Rendering Step ==============
{
PROFILE_SCOPE("Render in: ");
RenderCommand::SetClearColor(Renderer::GetClearColor());
RenderCommand::Clear();

m_renderer.BeginScene(m_cameraController);
gSceneManager.Render(elapsedTime);
OnRender(elapsedTime);
m_renderer.EndScene();
}

#if EDITOR_MODE
Expand Down Expand Up @@ -187,7 +184,7 @@ void Application::OnWindowResize(const events::WindowResizeEvent& e)
}
m_isPaused = false;

Renderer::OnWindowResize(e.width, e.height);
m_renderer.OnWindowResize(e.width, e.height);

if (!OrthographicCameraController::IsCustomCameraController()) {
auto& cameraComponent = GetScene().GetComponent<CameraComponent>(m_orthoCameraEntity);
Expand Down
4 changes: 4 additions & 0 deletions Engine/src/Core/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "Events/ApplicationEvent.h"
#include "Events/EventHandler.h"
#include "Renderer/Renderer.h"
#include "Scene/Entity.h"

#if EDITOR_MODE
Expand Down Expand Up @@ -40,6 +41,8 @@ class Application {

SharedPtr<CameraController> GetCameraController() const { return m_cameraController; }

Renderer& GetRenderer() { return m_renderer; }

protected:
virtual void OnCreate() {};
virtual void OnUpdate(float dt) {};
Expand All @@ -63,6 +66,7 @@ class Application {
bool m_running { false };

SharedPtr<CameraController> m_cameraController { nullptr };
Renderer m_renderer;

private:
static Application* s_instance;
Expand Down
27 changes: 15 additions & 12 deletions Engine/src/Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
#include "Core/Application.h"
#include "Core/SettingsConfig.h"
#include "Core/Window.h"
#include "Renderer/RenderCommand.h"
#include "Renderer/Renderer.h"

#include <imgui.h>

namespace elv::editor {
void Editor::OnInit()
{
m_isVSync = Application::Get().GetWindow()->IsVSync();
m_isFullScreen = Application::Get().GetWindow()->IsFullScreen();

if (gEngineSettings.enableSceneGraph) {
m_sceneHierarchyPanel.OnInit();
} else {
Expand All @@ -31,28 +27,35 @@ void Editor::OnImGuiRender()
ImGui::ShowDemoWindow(&showDemo);
}

auto& window = Application::Get().GetWindow();
auto& renderer = Application::Get().GetRenderer();

bool isVSync = window->IsVSync();
bool isFullScreen = window->IsFullScreen();
bool isMSAAEnabled = renderer.IsMSAAEnabled();

// ============ Settings panel ============
ImGui::Begin("Settings");
ImGui::SetWindowSize(ImVec2(300.0f, 200.0f));

if (ImGui::Checkbox("V-Sync", &m_isVSync)) {
Application::Get().GetWindow()->SetVSync(m_isVSync);
if (ImGui::Checkbox("V-Sync", &isVSync)) {
window->SetVSync(isVSync);
}

if (ImGui::Checkbox("Fullsreen mode", &m_isFullScreen)) {
Application::Get().GetWindow()->SetFullScreen(m_isFullScreen);
if (ImGui::Checkbox("Fullsreen mode", &isFullScreen)) {
window->SetFullScreen(isFullScreen);
}

if (ImGui::Checkbox("MSAA", &m_isMSAAEnabled)) {
RenderCommand::EnableMSAA(m_isMSAAEnabled);
if (ImGui::Checkbox("MSAA", &isMSAAEnabled)) {
renderer.EnableMSAA(isMSAAEnabled);
}
ImGui::End();

// ============ Environment ============
ImGui::Begin("Environment");
auto clearColor = Renderer::GetClearColor();
auto clearColor = renderer.GetClearColor();
if (DrawRGBAColorControl("Clear color", clearColor)) {
Renderer::SetClearColor(clearColor);
renderer.SetClearColor(clearColor);
}
ImGui::End();

Expand Down
5 changes: 0 additions & 5 deletions Engine/src/Editor/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ class Editor {
// panels
SceneHierarchyPanel m_sceneHierarchyPanel;
ProfileTelemetryPanel m_profileTelemetry;

// settings
bool m_isVSync { false };
bool m_isFullScreen { false };
bool m_isMSAAEnabled { true };
};

} // namespace elv::editor
1 change: 0 additions & 1 deletion Engine/src/Editor/ImGuiOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "Core/Application.h"
#include "Core/Window.h"
#include "Renderer/RenderCommand.h"
#include "Renderer/Renderer2D.h"

namespace elv {
Expand Down
7 changes: 3 additions & 4 deletions Engine/src/Elven.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
#include "Renderer/CameraController.h"
#include "Renderer/EditorCameraController.h"
#include "Renderer/OrthographicCameraController.h"
#include "Renderer/RenderCommand.h"
#include "Renderer/Renderer.h"
#include "Renderer/Renderer2D.h"

#include "Renderer/Buffer.h"
#include "Renderer/Material.h"
#include "Renderer/Shader.h"
#include "Renderer/VertexArray.h"
#include "Renderer/RHI/Buffer.h"
#include "Renderer/RHI/Shader.h"
#include "Renderer/RHI/VertexArray.h"

#include "Resources/TextureManager.h"

Expand Down
2 changes: 1 addition & 1 deletion Engine/src/Platform/OpenGL/OpenGLBuffer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "Renderer/Buffer.h"
#include "Renderer/RHI/Buffer.h"

namespace elv {

Expand Down
2 changes: 1 addition & 1 deletion Engine/src/Platform/OpenGL/OpenGLContext.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "Renderer/GraphicsContext.h"
#include "Renderer/RHI/GraphicsContext.h"

struct GLFWwindow;

Expand Down
Loading

0 comments on commit daedb66

Please sign in to comment.