Skip to content

Commit 6cf818f

Browse files
committed
- Dev: changing classic pointers by shared_ptr (part 1)
1 parent bd5a008 commit 6cf818f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+466
-460
lines changed

examples/raytracing/application.cpp

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,17 @@
22
#include <filesystem>
33

44
void Application::init(Systems::RendererSettings settings) {
5-
m_window = new WindowGLFW("Raytracing Example", 1280, 1024);
5+
m_window = std::make_shared<WindowGLFW>("Raytracing", 1280, 1024);
66

77
m_window->init();
88
m_window->set_window_icon(EXAMPLES_RESOURCES_PATH "textures/ico.png");
99

10-
m_window->set_window_size_callback(
11-
std::bind(&Application::window_resize_callback, this, std::placeholders::_1, std::placeholders::_2));
12-
m_window->set_mouse_callback(
13-
std::bind(&Application::mouse_callback, this, std::placeholders::_1, std::placeholders::_2));
14-
m_window->set_key_callback(std::bind(&Application::keyboard_callback,
15-
this,
16-
std::placeholders::_1,
17-
std::placeholders::_2,
18-
std::placeholders::_3,
19-
std::placeholders::_4));
20-
21-
Systems::DeferredRenderer* rndr = new Systems::DeferredRenderer(m_window, settings);
22-
// SSAOSettings ao = {};
23-
// ao.type = AOType::RTAO;
24-
// ao.samples = 4;
25-
// rndr->set_SSAO_settings(ao);
26-
m_renderer = rndr;
10+
m_window->set_window_size_callback(std::bind(&Application::window_resize_callback, this, std::placeholders::_1, std::placeholders::_2));
11+
m_window->set_mouse_callback(std::bind(&Application::mouse_callback, this, std::placeholders::_1, std::placeholders::_2));
12+
m_window->set_key_callback(
13+
std::bind(&Application::keyboard_callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
14+
15+
m_renderer = std::make_shared<Systems::DeferredRenderer>(m_window, settings);
2716

2817
setup();
2918
setup_gui();
@@ -87,15 +76,15 @@ void Application::setup() {
8776
Mesh* toriiMesh = new Mesh();
8877
auto toriiMat = new PhysicalMaterial();
8978

90-
Texture* toriiT = new Texture();
79+
TextureLDR* toriiT = new TextureLDR();
9180
Tools::Loaders::load_texture(toriiT, TEXTURE_PATH + "torii_color.png");
9281
toriiMat->set_albedo_texture(toriiT);
9382

94-
Texture* toriiN = new Texture();
83+
TextureLDR* toriiN = new TextureLDR();
9584
Tools::Loaders::load_texture(toriiN, TEXTURE_PATH + "torii_normal.png", TEXTURE_FORMAT_UNORM);
9685
toriiMat->set_normal_texture(toriiN);
9786

98-
Texture* toriiM = new Texture();
87+
TextureLDR* toriiM = new TextureLDR();
9988
// Tools::Loaders::load_texture(toriiM, TEXTURE_PATH + "torii_mask.png");
10089
// toriiMat->set_mask_texture(toriiM, UNREAL_ENGINE);
10190
toriiMat->set_metalness(0.05);
@@ -113,11 +102,11 @@ void Application::setup() {
113102
// Tools::Loaders::load_3D_file(plane, MESH_PATH + "torii.obj", false);
114103
plane->push_geometry(Geometry::create_quad());
115104
auto terrainMat = new PhysicalMaterial();
116-
Texture* floorText = new Texture();
105+
TextureLDR* floorText = new TextureLDR();
117106
Tools::Loaders::load_texture(floorText, TEXTURE_PATH + "floor_diffuse.jpg");
118-
Texture* floorNormalText = new Texture();
107+
TextureLDR* floorNormalText = new TextureLDR();
119108
Tools::Loaders::load_texture(floorNormalText, TEXTURE_PATH + "floor_normal.jpg", TEXTURE_FORMAT_UNORM);
120-
Texture* floorRoughText = new Texture();
109+
TextureLDR* floorRoughText = new TextureLDR();
121110
Tools::Loaders::load_texture(floorRoughText, TEXTURE_PATH + "floor_roughness.jpg");
122111
terrainMat->set_albedo({0.43f, 0.28f, 0.23f});
123112
terrainMat->set_albedo_texture(floorText);
@@ -135,10 +124,10 @@ void Application::setup() {
135124
Mesh* stoneMesh = new Mesh();
136125
Tools::Loaders::load_3D_file(stoneMesh, MESH_PATH + "moisturizer.obj");
137126
auto stoneMat = new PhysicalMaterial();
138-
Texture* stonelanternT = new Texture();
127+
TextureLDR* stonelanternT = new TextureLDR();
139128
Tools::Loaders::load_texture(stonelanternT, TEXTURE_PATH + "moisturizer_color.png");
140129
stoneMat->set_albedo_texture(stonelanternT);
141-
Texture* stonelanternN = new Texture();
130+
TextureLDR* stonelanternN = new TextureLDR();
142131
Tools::Loaders::load_texture(stonelanternN, TEXTURE_PATH + "moisturizer_normal.png", TEXTURE_FORMAT_UNORM);
143132
stoneMat->set_normal_texture(stonelanternN);
144133
stoneMesh->push_material(stoneMat);
@@ -153,13 +142,13 @@ void Application::setup() {
153142
Mesh* droidMesh = new Mesh();
154143
Tools::Loaders::load_3D_file(droidMesh, MESH_PATH + "droid.obj");
155144
auto droidMat = new PhysicalMaterial();
156-
Texture* droidText0 = new Texture();
145+
TextureLDR* droidText0 = new TextureLDR();
157146
Tools::Loaders::load_texture(droidText0, TEXTURE_PATH + "DROID_Body_BaseColor.jpg");
158147
droidMat->set_albedo_texture(droidText0);
159-
Texture* droidText1 = new Texture();
148+
TextureLDR* droidText1 = new TextureLDR();
160149
Tools::Loaders::load_texture(droidText1, TEXTURE_PATH + "DROID_Body_Emissive.jpg");
161150
droidMat->set_emissive_texture(droidText1);
162-
Texture* droidText2 = new Texture();
151+
TextureLDR* droidText2 = new TextureLDR();
163152
Tools::Loaders::load_texture(droidText2, TEXTURE_PATH + "DROID_Body_Normal.jpg", TEXTURE_FORMAT_UNORM);
164153
droidMat->set_normal_texture(droidText2);
165154
droidMesh->push_material(droidMat);
@@ -180,13 +169,13 @@ void Application::setup() {
180169
Mesh* stormtrooper = new Mesh();
181170
Tools::Loaders::load_3D_file(stormtrooper, MESH_PATH + "stormtrooper.obj");
182171
auto stormtrooperMat = new PhysicalMaterial();
183-
Texture* stormtrooperText = new Texture();
172+
TextureLDR* stormtrooperText = new TextureLDR();
184173
Tools::Loaders::load_texture(stormtrooperText, TEXTURE_PATH + "stormtrooper_color.png");
185174
stormtrooperMat->set_albedo_texture(stormtrooperText);
186-
Texture* stormtrooperText1 = new Texture();
175+
TextureLDR* stormtrooperText1 = new TextureLDR();
187176
Tools::Loaders::load_texture(stormtrooperText1, TEXTURE_PATH + "stormtrooper_normal.png", TEXTURE_FORMAT_UNORM);
188177
stormtrooperMat->set_normal_texture(stormtrooperText1);
189-
Texture* stormtrooperText2 = new Texture();
178+
TextureLDR* stormtrooperText2 = new TextureLDR();
190179
Tools::Loaders::load_texture(stormtrooperText2, TEXTURE_PATH + "stormtrooper_mask.png", TEXTURE_FORMAT_UNORM);
191180
stormtrooperMat->set_mask_texture(stormtrooperText2, MaskType::UNREAL_ENGINE);
192181
stormtrooper->push_material(stormtrooperMat);
@@ -197,14 +186,13 @@ void Application::setup() {
197186
Mesh* stormtrooperHead = new Mesh();
198187
Tools::Loaders::load_3D_file(stormtrooperHead, MESH_PATH + "stormtrooper_helm.obj", false);
199188
auto stormtrooperMat1 = new PhysicalMaterial();
200-
Texture* stormtrooperText11 = new Texture();
189+
TextureLDR* stormtrooperText11 = new TextureLDR();
201190
Tools::Loaders::load_texture(stormtrooperText11, TEXTURE_PATH + "stormtrooper_head_color.png");
202191
stormtrooperMat1->set_albedo_texture(stormtrooperText11);
203-
Texture* stormtrooperText12 = new Texture();
204-
Tools::Loaders::load_texture(
205-
stormtrooperText12, TEXTURE_PATH + "stormtrooper_head_normal.png", TEXTURE_FORMAT_UNORM);
192+
TextureLDR* stormtrooperText12 = new TextureLDR();
193+
Tools::Loaders::load_texture(stormtrooperText12, TEXTURE_PATH + "stormtrooper_head_normal.png", TEXTURE_FORMAT_UNORM);
206194
stormtrooperMat1->set_normal_texture(stormtrooperText12);
207-
Texture* stormtrooperText13 = new Texture();
195+
TextureLDR* stormtrooperText13 = new TextureLDR();
208196
Tools::Loaders::load_texture(stormtrooperText13, TEXTURE_PATH + "stormtrooper_head_mask.png", TEXTURE_FORMAT_UNORM);
209197
stormtrooperMat1->set_mask_texture(stormtrooperText13, MaskType::UNREAL_ENGINE);
210198
stormtrooperHead->push_material(stormtrooperMat1);
@@ -261,15 +249,13 @@ void Application::setup() {
261249
sky->set_color_intensity(0.25f);
262250
m_scene->set_skybox(sky);
263251

264-
m_controller = new Tools::Controller(camera, m_window, ControllerMovementType::ORBITAL);
252+
m_controller = new Tools::Controller(camera, m_window.get(), ControllerMovementType::ORBITAL);
265253
}
266254

267255
void Application::setup_gui() {
268-
m_interface.overlay = new Tools::GUIOverlay(
269-
(float)m_window->get_extent().width, (float)m_window->get_extent().height, GuiColorProfileType::DARK);
256+
m_interface.overlay = new Tools::GUIOverlay((float)m_window->get_extent().width, (float)m_window->get_extent().height, GuiColorProfileType::DARK);
270257

271-
Tools::Panel* tutorialPanel =
272-
new Tools::Panel("TUTORIAL", 0, 0.8f, 0.2f, 0.2f, PanelWidgetFlags::NoMove, false, true);
258+
Tools::Panel* tutorialPanel = new Tools::Panel("TUTORIAL", 0, 0.8f, 0.2f, 0.2f, PanelWidgetFlags::NoMove, false, true);
273259

274260
tutorialPanel->add_child(new Tools::Space());
275261
tutorialPanel->add_child(new Tools::Separator("CONTROLS"));
@@ -288,10 +274,10 @@ void Application::setup_gui() {
288274
m_interface.tutorial = tutorialPanel;
289275

290276
Tools::Panel* explorerPanel = new Tools::Panel("EXPLORER", 0, 0, 0.2f, 0.7f, PanelWidgetFlags::NoMove, false);
291-
m_interface.scene = new Tools::ExplorerWidget(m_scene, m_renderer);
277+
m_interface.scene = new Tools::ExplorerWidget(m_scene, m_renderer.get());
292278
explorerPanel->add_child(m_interface.scene);
293279
explorerPanel->add_child(new Tools::Space());
294-
explorerPanel->add_child(new Tools::DeferredRendererWidget(static_cast<Systems::DeferredRenderer*>(m_renderer)));
280+
explorerPanel->add_child(new Tools::DeferredRendererWidget(static_cast<Systems::DeferredRenderer*>(m_renderer.get())));
295281
explorerPanel->add_child(new Tools::ControllerWidget(m_controller));
296282
explorerPanel->add_child(new Tools::Separator());
297283
explorerPanel->add_child(new Tools::TextLine(" Application average"));
@@ -301,9 +287,8 @@ void Application::setup_gui() {
301287
m_interface.overlay->add_panel(explorerPanel);
302288
m_interface.explorer = explorerPanel;
303289

304-
Tools::Panel* propertiesPanel =
305-
new Tools::Panel("OBJECT PROPERTIES", 0.75f, 0, 0.25f, 0.8f, PanelWidgetFlags::NoMove, true);
306-
m_interface.object = new Tools::ObjectExplorerWidget();
290+
Tools::Panel* propertiesPanel = new Tools::Panel("OBJECT PROPERTIES", 0.75f, 0, 0.25f, 0.8f, PanelWidgetFlags::NoMove, true);
291+
m_interface.object = new Tools::ObjectExplorerWidget();
307292
propertiesPanel->add_child(m_interface.object);
308293

309294
m_interface.overlay->add_panel(propertiesPanel);
@@ -321,8 +306,8 @@ void Application::update() {
321306
if (animateLight)
322307
{
323308
float rotationAngle = glm::radians(10.0f * m_time.delta);
324-
float _x = light->get_position().x * cos(rotationAngle) - light->get_position().z * sin(rotationAngle);
325-
float _z = light->get_position().x * sin(rotationAngle) + light->get_position().z * cos(rotationAngle);
309+
float _x = light->get_position().x * cos(rotationAngle) - light->get_position().z * sin(rotationAngle);
310+
float _z = light->get_position().x * sin(rotationAngle) + light->get_position().z * cos(rotationAngle);
326311

327312
light->set_position({_x, light->get_position().y, _z});
328313
}

examples/raytracing/application.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Application
3131
};
3232
UserInterface m_interface{};
3333

34-
IWindow *m_window;
35-
Systems::BaseRenderer *m_renderer;
34+
ptr<IWindow> m_window;
35+
ptr<Systems::BaseRenderer> m_renderer;
3636
Scene *m_scene;
3737
Camera *camera;
3838
Tools::Controller *m_controller;

examples/renderer-app/application.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <filesystem>
33

44
void Application::init(Systems::RendererSettings settings) {
5-
m_window = new WindowGLFW("VK Engine", 1280, 1024);
5+
m_window = std::make_shared<WindowGLFW>("VK Engine", 1280, 1024);
66

77
m_window->init();
88
m_window->set_window_icon(EXAMPLES_RESOURCES_PATH "textures/ico.png");
@@ -12,7 +12,8 @@ void Application::init(Systems::RendererSettings settings) {
1212
m_window->set_key_callback(
1313
std::bind(&Application::keyboard_callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
1414

15-
m_renderer = new Systems::ForwardRenderer(m_window, settings);
15+
// m_renderer = new Systems::ForwardRenderer(m_window, settings);
16+
m_renderer = std::make_shared<Systems::ForwardRenderer>(m_window, settings);
1617

1718
setup();
1819

@@ -159,11 +160,11 @@ void Application::setup() {
159160

160161
Mesh* toriiMesh = new Mesh();
161162
auto toriiMat = new PhysicalMaterial();
162-
Texture* toriiT = new Texture();
163+
TextureLDR* toriiT = new TextureLDR();
163164
Tools::Loaders::load_texture(toriiT, TEXTURE_PATH + "torii_color.png");
164-
Texture* toriiN = new Texture();
165+
TextureLDR* toriiN = new TextureLDR();
165166
Tools::Loaders::load_texture(toriiN, TEXTURE_PATH + "torii_normal.png", TEXTURE_FORMAT_UNORM);
166-
Texture* toriiM = new Texture();
167+
TextureLDR* toriiM = new TextureLDR();
167168
Tools::Loaders::load_texture(toriiM, TEXTURE_PATH + "torii_mask.png");
168169
toriiMat->set_albedo_texture(toriiT);
169170
toriiMat->set_normal_texture(toriiN);
@@ -182,12 +183,12 @@ void Application::setup() {
182183
terrainMesh->set_scale(10.0);
183184
terrainMesh->set_position({0.0, -4.0, 0.0});
184185
Tools::Loaders::load_3D_file(terrainMesh, MESH_PATH + "terrain.obj");
185-
Texture* floorText = new Texture();
186+
TextureLDR* floorText = new TextureLDR();
186187
Tools::Loaders::load_texture(floorText, TEXTURE_PATH + "floor_diffuse.jpg");
187188

188-
Texture* floorNormalText = new Texture();
189+
TextureLDR* floorNormalText = new TextureLDR();
189190
Tools::Loaders::load_texture(floorNormalText, TEXTURE_PATH + "floor_normal.jpg", TEXTURE_FORMAT_UNORM);
190-
Texture* floorRoughText = new Texture();
191+
TextureLDR* floorRoughText = new TextureLDR();
191192
Tools::Loaders::load_texture(floorRoughText, TEXTURE_PATH + "floor_roughness.jpg");
192193
auto terrainMat = new PhysicalMaterial();
193194
terrainMat->set_albedo({0.43f, 0.28f, 0.23f});
@@ -212,7 +213,7 @@ void Application::setup() {
212213
Tools::Loaders::load_3D_file(kabutoMesh, MESH_PATH + "kabuto.obj");
213214
kabutoMesh->set_rotation(glm::vec3(0.0, 180, 0.0));
214215
auto kabutoMat = new PhysicalMaterial();
215-
Texture* kabutoText = new Texture();
216+
TextureLDR* kabutoText = new TextureLDR();
216217
Tools::Loaders::load_texture(kabutoText, TEXTURE_PATH + "kabuto_color.png");
217218
kabutoMat->set_albedo_texture(kabutoText);
218219
kabutoMat->set_albedo({0.0, 1.0, 0.0});
@@ -227,11 +228,11 @@ void Application::setup() {
227228
Tools::Loaders::load_3D_file(templeMesh, MESH_PATH + "temple.obj");
228229
templeMesh->set_rotation(glm::vec3(0.0, 180, 0.0));
229230
auto templeMat = new PhysicalMaterial();
230-
Texture* templeText = new Texture();
231+
TextureLDR* templeText = new TextureLDR();
231232
Tools::Loaders::load_texture(templeText, TEXTURE_PATH + "temple_diffuse.png");
232-
Texture* templeRText = new Texture();
233+
TextureLDR* templeRText = new TextureLDR();
233234
Tools::Loaders::load_texture(templeRText, TEXTURE_PATH + "temple_rough.png");
234-
Texture* templeMText = new Texture();
235+
TextureLDR* templeMText = new TextureLDR();
235236
Tools::Loaders::load_texture(templeMText, TEXTURE_PATH + "temple_metal.png");
236237
templeMat->set_albedo_texture(templeText);
237238
templeMat->set_metallic_texture(templeMText);
@@ -250,11 +251,11 @@ void Application::setup() {
250251
Tools::Loaders::load_3D_file(templeMesh2, MESH_PATH + "shrine.obj");
251252
templeMesh2->set_rotation(glm::vec3(0.0, 180, 0.0));
252253
auto templeMat2 = new PhysicalMaterial();
253-
Texture* templeText2 = new Texture();
254+
TextureLDR* templeText2 = new TextureLDR();
254255
Tools::Loaders::load_texture(templeText2, TEXTURE_PATH + "shrine_diffuse.png");
255-
Texture* templeRText2 = new Texture();
256+
TextureLDR* templeRText2 = new TextureLDR();
256257
Tools::Loaders::load_texture(templeRText2, TEXTURE_PATH + "shrine_rough.png");
257-
Texture* templeMText2 = new Texture();
258+
TextureLDR* templeMText2 = new TextureLDR();
258259
Tools::Loaders::load_texture(templeMText2, TEXTURE_PATH + "shrine_metal.png");
259260
templeMat2->set_albedo_texture(templeText2);
260261
templeMat2->set_metallic_texture(templeMText2);
@@ -269,7 +270,7 @@ void Application::setup() {
269270
Mesh* lanternMesh = new Mesh();
270271
Tools::Loaders::load_3D_file(lanternMesh, MESH_PATH + "lantern.obj", false);
271272
auto lanternMat = new PhysicalMaterial();
272-
Texture* lanternT = new Texture();
273+
TextureLDR* lanternT = new TextureLDR();
273274
Tools::Loaders::load_texture(lanternT, TEXTURE_PATH + "lantern_diffuse.png");
274275
lanternMat->set_albedo_texture(lanternT);
275276
lanternMesh->push_material(lanternMat);
@@ -298,7 +299,7 @@ void Application::setup() {
298299
Mesh* stoneMesh = new Mesh();
299300
Tools::Loaders::load_3D_file(stoneMesh, MESH_PATH + "stone_lantern.obj", false);
300301
auto stoneMat = new PhysicalMaterial();
301-
Texture* stonelanternT = new Texture();
302+
TextureLDR* stonelanternT = new TextureLDR();
302303
Tools::Loaders::load_texture(stonelanternT, TEXTURE_PATH + "stone_diffuse.png");
303304
stoneMat->set_albedo_texture(stonelanternT);
304305
stoneMesh->push_material(stoneMat);
@@ -317,7 +318,7 @@ void Application::setup() {
317318
sky->set_color_intensity(0.25f);
318319
m_scene->set_skybox(sky);
319320

320-
m_controller = new Tools::Controller(camera, m_window);
321+
m_controller = new Tools::Controller(camera, m_window.get());
321322
}
322323

323324
void Application::setup_gui() {
@@ -342,10 +343,10 @@ void Application::setup_gui() {
342343
m_interface.tutorial = tutorialPanel;
343344

344345
Tools::Panel* explorerPanel = new Tools::Panel("EXPLORER", 0, 0, 0.2f, 0.7f, PanelWidgetFlags::NoMove, false);
345-
m_interface.scene = new Tools::ExplorerWidget(m_scene, m_renderer);
346+
m_interface.scene = new Tools::ExplorerWidget(m_scene, m_renderer.get());
346347
explorerPanel->add_child(m_interface.scene);
347348
explorerPanel->add_child(new Tools::Space());
348-
explorerPanel->add_child(new Tools::ForwardRendererWidget(static_cast<Systems::ForwardRenderer*>(m_renderer)));
349+
explorerPanel->add_child(new Tools::ForwardRendererWidget(static_cast<Systems::ForwardRenderer*>(m_renderer.get())));
349350
explorerPanel->add_child(new Tools::Separator());
350351
explorerPanel->add_child(new Tools::TextLine(" Application average"));
351352
explorerPanel->add_child(new Tools::Profiler());

examples/renderer-app/application.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Application
3131
};
3232
UserInterface m_interface{};
3333

34-
IWindow *m_window;
35-
Systems::BaseRenderer *m_renderer;
34+
ptr<IWindow> m_window;
35+
ptr<Systems::BaseRenderer> m_renderer;
3636
Scene *m_scene;
3737
Camera *camera;
3838
Tools::Controller *m_controller;

examples/rotating-kabuto/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ int main() {
2727
float delta;
2828
float last{0};
2929

30-
Core::IWindow* window = new Core::WindowGLFW("Kabuto", 800, 600);
30+
ptr<Core::IWindow> window = std::make_shared<Core::WindowGLFW>("Kabuto", 800, 600);
3131

3232
window->init();
3333

3434
Systems::RendererSettings settings{};
35-
settings.samplesMSAA = MSAASamples::x4;
35+
settings.samplesMSAA = MSAASamples::x1;
36+
settings.softwareAA = SoftwareAA::FXAA;
3637
settings.clearColor = Vec4(0.0, 0.0, 0.0, 1.0);
3738

38-
Systems::BaseRenderer* renderer = new Systems::ForwardRenderer(window, settings);
39+
ptr<Systems::BaseRenderer> renderer = std::make_shared<Systems::ForwardRenderer>(window, settings);
3940

4041
Core::Camera* camera = new Core::Camera();
4142
camera->set_position(Vec3(0.0f, 0.15f, -1.0f));

0 commit comments

Comments
 (0)