Skip to content

Commit

Permalink
Renderer as abstract class and chidlren classes
Browse files Browse the repository at this point in the history
  • Loading branch information
AEspinosaDev committed Oct 8, 2024
1 parent aa1e66e commit c54546c
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 227 deletions.
24 changes: 17 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ file(GLOB LIB_SOURCES
"src/core/*.cpp"
"src/core/scene/*.cpp"
"src/core/materials/*.cpp"
"src/core/renderers/*.cpp"
"src/utilities/*.cpp"
"src/graphics/*.cpp"
"src/graphics/renderpasses/*.cpp")

file(GLOB LIB_HEADERS
"include/VkFW/*.h"
"include/VkFW/core/*.h"
"include/VkFW/core/scene/*.h"
"include/VkFW/core/materials/*.h"
"include/VkFW/utilities/*.h"
"include/VkFW/graphics/*.h"
"include/VkFW/graphics/renderpasses/*.h")
"include/engine/*.h"
"include/engine/core/*.h"
"include/engine/core/scene/*.h"
"include/engine/core/renderers/*.h"
"include/engine/core/materials/*.h"
"include/engine/utilities/*.h"
"include/engine/graphics/*.h"
"include/engine/graphics/renderpasses/*.h")

add_library(VkFW STATIC ${LIB_SOURCES} ${LIB_HEADERS})

Expand Down Expand Up @@ -96,6 +98,9 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
file(GLOB materials_h
${CMAKE_CURRENT_SOURCE_DIR}/include/VkFW/core/materials/*.h
)
file(GLOB rend_h
${CMAKE_CURRENT_SOURCE_DIR}/include/VkFW/core/renderers/*.h
)
file(GLOB utilities_h
${CMAKE_CURRENT_SOURCE_DIR}/include/VkFW/utilities/*.h
)
Expand All @@ -112,6 +117,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
source_group("Header Files\\Core" FILES ${core_h})
source_group("Header Files\\Core\\Scene Objects" FILES ${scene_objects_h})
source_group("Header Files\\Core\\Materials" FILES ${materials_h})
source_group("Header Files\\Core\\Renderers" FILES ${rend_h})
source_group("Header Files\\Graphics" FILES ${backend_h})
source_group("Header Files\\Graphics\\RenderPasses" FILES ${rpass_h})

Expand All @@ -121,6 +127,9 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
file(GLOB materials_cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/core/materials/*.cpp
)
file(GLOB rend_cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/core/renderers/*.cpp
)
file(GLOB utilities_cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/utilities/*.cpp
)
Expand All @@ -138,6 +147,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
source_group("Source Files\\Core" FILES ${core_cpp})
source_group("Source Files\\Core\\Scene Objects" FILES ${scene_objects_cpp})
source_group("Source Files\\Core\\Materials" FILES ${materials_cpp})
source_group("Source Files\\Core\\Renderers" FILES ${rend_cpp})
source_group("Source Files\\Graphics" FILES ${backend_cpp})
source_group("Source Files\\Graphics\\RenderPasses" FILES ${rpass_cpp})

Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-test/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void VulkanRenderer::init(RendererSettings settings)
std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4));

m_renderer = new Renderer(m_window, settings);
m_renderer = new ForwardRenderer(m_window, settings);

setup();

Expand Down
5 changes: 2 additions & 3 deletions examples/lighting-test/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

#include <chrono>

#include <engine/core/renderer.h>
#include <engine/core/texture.h>
#include <engine/core.h>

#include <engine/utilities/controller.h>
#include <engine/utilities/gui.h>
#include <engine/utilities/renderer_widget.h>

#include <engine/core/materials/physically_based.h>


/**
* Example app
Expand Down
8 changes: 2 additions & 6 deletions examples/renderer-app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void VulkanRenderer::init(RendererSettings settings)
std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4));

m_renderer = new Renderer(m_window, settings);
m_renderer = settings.renderingType == TFORWARD ? new ForwardRenderer(m_window, settings) : nullptr;

setup();

Expand Down Expand Up @@ -289,10 +289,6 @@ void VulkanRenderer::setup()
// hair->set_scale(0.1f);
// m_scene->add(hair);





Mesh *lanternMesh = new Mesh();
lanternMesh->load_file(MESH_PATH + "lantern.obj", true);
auto lanternMat = new PhysicallyBasedMaterial();
Expand Down Expand Up @@ -336,7 +332,7 @@ void VulkanRenderer::setup()
stoneMat->set_roughness(0.9f);
m_scene->add(stoneMesh);

m_scene->set_ambient_color({0.2,0.25,0.61});
m_scene->set_ambient_color({0.2, 0.25, 0.61});

m_controller = new Controller(camera);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rotating-kabuto/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main()
settings.clearColor = Vec4(0.0, 0.0, 0.0, 1.0);
settings.renderingType = TFORWARD;

Renderer* renderer = new Renderer(window, settings);
Renderer* renderer = new ForwardRenderer(window, settings);

Camera* camera = new Camera();
camera->set_position(Vec3(0.0f, 0.15f, -1.0f));
Expand Down
2 changes: 2 additions & 0 deletions include/engine/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
#include <engine/core/scene/mesh.h>
#include <engine/core/scene/scene.h>

#include <engine/core/renderers/forward.h>

127 changes: 33 additions & 94 deletions include/engine/core/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Implementation of this class is fragmentated in three submodules:
* vk_renderer.cpp
* vk_renderer_vk_mgr.cpp
* vk_renderer_data_mgr.cpp
////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -51,7 +50,7 @@ Renderer Global Settings Data
*/
struct RendererSettings
{
RendererType renderingType{TDEFERRED};
RendererType renderingType{TFORWARD};

AntialiasingType AAtype{MSAA_x4};
BufferingType bufferingType{_DOUBLE};
Expand All @@ -60,6 +59,7 @@ struct RendererSettings
DepthFormatType depthFormat{D32F};

ShadowResolution shadowResolution{LOW};
bool updateShadows{false};

AmbientOcclusionType occlusionType{SSAO};

Expand Down Expand Up @@ -92,33 +92,31 @@ struct RenderPipeline
};

/**
* Renders a given scene data to a given window. Fully parametrizable. Main class of the library. It can be inherited for achieving a higher end application.
* Virtual class. Renders a given scene data to a given window. Fully parametrizable. It has to be inherited for achieving a higher end application.
*/
class Renderer
{
#pragma region Properties
protected:
RendererSettings m_settings{};

Context m_context{};
Window *m_window;

RenderPipeline m_renderPipeline;

utils::DeletionQueue m_deletionQueue;

Mesh *m_vignette{nullptr};

uint32_t m_currentFrame{0};
bool m_initialized{false};
bool m_updateShadowQuality{false};
bool m_updateContext{false};
bool m_updateFramebuffers{false};

GUIOverlay *m_gui{nullptr};

#pragma endregion
public:
Renderer(Window *window) : m_window(window) { on_awake(); }
Renderer(Window *window, RendererSettings settings) : m_window(window), m_settings(settings) { on_awake(); }
Renderer(Window *window) : m_window(window) { on_instance(); }
Renderer(Window *window, RendererSettings settings) : m_window(window), m_settings(settings) { on_instance(); }

#pragma region Getters & Setters

Expand All @@ -127,84 +125,25 @@ class Renderer
inline RendererSettings get_settings() { return m_settings; }
inline void set_settings(RendererSettings settings) { m_settings = settings; }

inline void set_clearcolor(Vec4 c)
{
m_settings.clearColor = c;
}
inline void set_antialiasing(AntialiasingType msaa)
{
m_settings.AAtype = msaa;
if (m_initialized)
{
m_updateContext = true;
}
}
inline void set_shadow_quality(ShadowResolution quality)
{
m_settings.shadowResolution = quality;
if (m_initialized)
m_updateShadowQuality = true;
}
inline void set_color_format(ColorFormatType color)
{
m_settings.colorFormat = color;
if (m_initialized)
m_updateContext = true;
}
inline void set_depth_format(DepthFormatType d)
{
m_settings.depthFormat = d;
if (m_initialized)
m_updateContext = true;
}
inline void set_sync_type(SyncType sync)
{
m_settings.screenSync = sync;
if (m_initialized)
m_updateFramebuffers = true;
}

inline void enable_gui_overlay(bool op) { m_settings.enableUI; }

inline void set_gui_overlay(GUIOverlay *gui)
{
m_gui = gui;
}

inline GUIOverlay *get_gui_overlay()
{
return m_gui;
}
inline void set_hardware_depth_bias(bool op) { m_settings.enableHardwareDepthBias = op; };
inline void set_clearcolor(Vec4 c) { m_settings.clearColor = c; }
inline void set_antialiasing(AntialiasingType msaa) { m_settings.AAtype = msaa; }
inline void set_color_format(ColorFormatType color) { m_settings.colorFormat = color; }
inline void set_depth_format(DepthFormatType d) { m_settings.depthFormat = d; }
inline void set_gui_overlay(GUIOverlay *gui) { m_gui = gui; }

inline GUIOverlay *get_gui_overlay() { return m_gui; }
inline RenderPipeline get_render_pipeline() const { return m_renderPipeline; }

inline void set_rendering_method(RendererType type)
{
m_settings.renderingType = type;
if (m_initialized)
m_updateContext = true;
}
inline void set_deferred_output_type(int op)
{
// if (m_initialized)
// static_cast<CompositionPass *>(m_renderPipeline.renderpasses[COMPOSITION])->set_output_type(op);
}
inline int get_deferred_output_type() const
{
// return static_cast<CompositionPass *>(m_renderPipeline.renderpasses[COMPOSITION])->get_output_type();
return 0;
}
inline AmbientOcclusionType get_ssao_type() const { return m_settings.occlusionType; }
inline void set_ssao_type(AmbientOcclusionType ao)
inline void enable_gui_overlay(bool op) { m_settings.enableUI; }
inline void set_sync_type(SyncType sync)
{
m_settings.occlusionType = ao;
m_settings.screenSync = sync;
if (m_initialized)
m_updateFramebuffers = true;
}

#pragma endregion
#pragma region Core Functions
#pragma region Public Functions

/**
* Inits the renderer.
Expand All @@ -224,11 +163,13 @@ class Renderer
*/
void shutdown(Scene *const scene);

#pragma endregion
#pragma region Core Functions
protected:
/*
What to do when instancing the renderer
*/
virtual void on_awake() {}
virtual void on_instance() {}
/*
What to do when initiating the renderer
*/
Expand All @@ -248,7 +189,7 @@ class Renderer
/*
Init renderpasses and create framebuffers and image resources attached to them
*/
virtual void setup_renderpasses(); // Should be zero
virtual void setup_renderpasses() = 0;
/*
Link images of previous passes to current pass
*/
Expand All @@ -257,15 +198,7 @@ class Renderer
Clean and recreates swapchain and framebuffers in the renderer. Useful to use when resizing context
*/
void update_renderpasses();
/*
Resource like samplers, base textures and misc creation
*/
virtual void init_resources();
/*
Clean all resources used
*/
virtual void clean_Resources();


#pragma endregion
/*
////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -275,20 +208,26 @@ class Renderer
////////////////////////////////////////////////////////////////////////////////////
*/
#pragma region Data Management
/*
Resource like samplers, base textures and misc creation
*/
virtual void init_resources();
/*
Clean all resources used
*/
virtual void clean_Resources();
/*
Object descriptor layouts uniforms buffer upload to GPU
*/
void upload_object_data(Scene *const scene);
virtual void upload_object_data(Scene *const scene);
/*
Global descriptor layouts uniforms buffer upload to GPU
*/
void upload_global_data(Scene *const scene);

virtual void upload_global_data(Scene *const scene);
/*
Initialize and setup textures and uniforms in given material
*/
void setup_material(Material *const mat);

virtual void setup_material(Material *const mat);
/*
Upload geometry vertex buffers to the GPU
*/
Expand Down
Loading

0 comments on commit c54546c

Please sign in to comment.