Skip to content

Commit bf32c82

Browse files
committed
Minor cleanup, changes and improvements
1 parent 634704d commit bf32c82

32 files changed

Lines changed: 243 additions & 1540 deletions

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Irradiance)
160160

161161
############## Work In Progress ####################
162162
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/InfiniteWorld)
163-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/RayTracing)
164-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/Sort)
165-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/CirclePacking)
166-
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/SubGroup)
167163

168164
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Samples/WindCoeff)
169165

@@ -251,3 +247,6 @@ ADD_CUSTOM_COMMAND(
251247
# All shader files.
252248
FILE(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/Shaders ${CMAKE_CURRENT_BINARY_DIR}/Shaders SYMBOLIC)
253249
FILE(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/asset ${CMAKE_CURRENT_BINARY_DIR}/asset SYMBOLIC)
250+
251+
# Install Shaders.
252+
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Shaders DESTINATION bin)

Common/GLSampleWindow.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ class SampleSettingComponent : public GLUIComponent<GLSampleWindow> {
212212
ImGui::EndDisabled();
213213

214214
/* List all builtin post processing. */
215+
bool usePostProcessing = this->getRefSample().getIsPostProcessingEnabled();
216+
if (ImGui::Checkbox("Use Post Processing", &usePostProcessing)) {
217+
this->getRefSample().setPostProcessingEnabled(usePostProcessing);
218+
}
219+
215220
if (this->getRefSample().getPostProcessingManager() && ImGui::CollapsingHeader("Post Processing")) {
216221

217222
ImGui::BeginGroup();
@@ -459,7 +464,7 @@ void GLSampleWindow::renderUI() {
459464

460465
/* Make sure all commands are flush before resizing. */
461466
if (this->preWidth != this->width() || this->preHeight != this->height()) {
462-
467+
463468
/* Finish all commands before starting resizing buffers and etc. */
464469
glFinish();
465470

@@ -528,7 +533,7 @@ void GLSampleWindow::renderUI() {
528533
}
529534

530535
/* */
531-
if (this->postprocessingManager) {
536+
if (this->postprocessingManager && this->postProcessingEnabled) {
532537

533538
const std::string postStage = "Post Processing";
534539
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 1, postStage.size(), postStage.data());

Common/GLSampleWindow.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class FVDECLSPEC GLSampleWindow : public nekomimi::MIMIWindow {
139139
unsigned int getDefaultFramebuffer() const noexcept;
140140
glsample::FrameBuffer *getDefaultFrameBufferObj() { return this->defaultFramebuffer.get(); }
141141
const glsample::FrameBuffer *getDefaultFrameBufferObj() const noexcept { return this->defaultFramebuffer.get(); }
142+
143+
bool getIsPostProcessingEnabled() const noexcept { return this->postProcessingEnabled; }
144+
void setPostProcessingEnabled(bool enabled) noexcept { this->postProcessingEnabled = enabled; }
142145
glsample::PostProcessingManager *getPostProcessingManager() const noexcept {
143146
return this->postprocessingManager.get();
144147
}
@@ -152,8 +155,9 @@ class FVDECLSPEC GLSampleWindow : public nekomimi::MIMIWindow {
152155
}
153156

154157
// TODO: relocate
155-
static void blitFrameBufferAttacments(const glsample::FrameBuffer* targetFrameBuffer, const glsample::FrameBuffer *framebufferAttachments, const unsigned int width, const int height,
156-
glm::vec4 rectNormalized, int mode = 0) {
158+
static void blitFrameBufferAttacments(const glsample::FrameBuffer *targetFrameBuffer,
159+
const glsample::FrameBuffer *framebufferAttachments, const unsigned int width,
160+
const int height, glm::vec4 rectNormalized, int mode = 0) {
157161

158162
/* Blit image targets to screen. */
159163
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFrameBuffer->framebuffer);
@@ -224,6 +228,7 @@ class FVDECLSPEC GLSampleWindow : public nekomimi::MIMIWindow {
224228

225229
std::shared_ptr<fragcore::IFileSystem> filesystem; /* */
226230

231+
bool postProcessingEnabled = true;
227232
std::shared_ptr<glsample::PostProcessingManager> postprocessingManager = nullptr;
228233
std::shared_ptr<glsample::ColorSpaceConverter> colorSpace;
229234

Common/Importer/ImageImport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ unsigned int TextureImporter::loadImage2DRaw(const Image &image, const ColorSpac
4747

4848
/* */
4949
const size_t power_of_2 = std::floor(std::log(Math::max(image.width(), image.height())) / std::log(2));
50-
const size_t max_mipmap = Math::clamp<size_t>(power_of_2 - 4, 0, std::numeric_limits<size_t>::max());
50+
const size_t max_mipmap = Math::clamp<size_t>(power_of_2 - 2, 0, std::numeric_limits<size_t>::max());
5151

5252
/* */
5353
GLuint currentPBO = this->pbos[current_pbo++];

Common/Importer/ModelImporter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ void ModelImporter::initNodeRoot(const aiNode *ai_node, NodeObject *parent) {
318318

319319
if (parent) {
320320
pobject->parent = parent;
321+
// parent->childrens.addChild(ITree<node_object_t *> *pchild)
321322
} else {
322323
pobject->parent = nullptr;
323324
}

Common/Importer/ModelImporter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* all copies or substantial portions of the Software.
1515
*/
1616
#pragma once
17-
#include "DataStructure/PoolAllocator.h"
17+
#include "DataStructure/ITree.h"
1818
#include "DataStructure/StackAllactor.h"
1919
#include "FragDef.h"
2020
#include "Math3D/LinAlg.h"
@@ -135,6 +135,7 @@ using MaterialObject = struct material_object_t : public AssetObject {
135135
};
136136

137137
using NodeObject = struct node_object_t : public AssetObject {
138+
138139
/* */
139140
glm::vec3 localPosition;
140141
glm::quat localRotation;
@@ -151,6 +152,7 @@ using NodeObject = struct node_object_t : public AssetObject {
151152
std::vector<unsigned int> materialIndex;
152153

153154
struct node_object_t *parent = nullptr;
155+
fragcore::ITree<struct node_object_t *> childrens;
154156
};
155157

156158
using MeshData = struct mesh_data_t : public AssetObject {
@@ -228,6 +230,7 @@ using TextureAssetObject = struct alignas(32) texture_asset_object_t {
228230
char *data = nullptr;
229231
};
230232

233+
// TOOD: relocate.
231234
using KeyFrame = struct alignas(16) key_frame_t {
232235
float time; /* */
233236
float value; /* */

Common/PostProcessing/PostProcessingManager.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
namespace glsample {
2222

2323
class PostProcessing;
24-
/**
25-
* @brief
26-
*
24+
/*
2725
*/
2826
class FVDECLSPEC PostProcessingManager : public fragcore::Object {
2927
public:
@@ -41,6 +39,7 @@ namespace glsample {
4139
void render(glsample::FrameBuffer *framebuffer,
4240
const std::initializer_list<std::tuple<const GBuffer, unsigned int>> &render_targets);
4341

42+
4443
void populateCommonData() {}
4544
void swapPostProcessing(int a, int b);
4645

Common/Scene/Node.cpp

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
#include "Node.h"
2+
#include <glm/ext/quaternion_common.hpp>
3+
#include <glm/fwd.hpp>
4+
#include <glm/gtx/quaternion.hpp>
25

36
using namespace glsample;
47

5-
void Node::setPosition(const glm::vec3 &position) noexcept {}
6-
glm::vec3 Node::getPosition() noexcept { return {}; }
8+
void Node::setPosition(const glm::vec3 &position) noexcept {
9+
const glm::vec3 position_offset = position - this->getPosition();
10+
for (int x = 0; x < this->getNumChildren(); x++) {
11+
12+
Node *node = dynamic_cast<Node *>(this->getChild(x));
13+
node->setPosition(node->getPosition() + position);
14+
}
15+
TransformGLM::setPosition(position);
16+
}
17+
glm::vec3 Node::getPosition() noexcept { return TransformGLM::getPosition(); }
718
const glm::vec3 &Node::getPosition() const noexcept { return TransformGLM::getPosition(); }
819

9-
void Node::setScale(const glm::vec3 &scale) noexcept {}
10-
glm::vec3 Node::getScale() const noexcept { return {}; }
20+
void Node::setScale(const glm::vec3 &scale) noexcept { TransformGLM::setPosition(scale); }
21+
glm::vec3 Node::getScale() const noexcept { return TransformGLM::getScale(); }
1122

1223
const glm::quat &Node::getRotation() const noexcept { return TransformGLM::getRotation(); }
13-
void Node::setRotation(const glm::quat &quat) noexcept {}
24+
void Node::setRotation(const glm::quat &quat) noexcept { TransformGLM::setRotation(quat); }
25+
26+
Node *Node::parent() const noexcept { return dynamic_cast<Node *>(this->getParent()); }
1427

1528
glm::mat4 Node::getViewMatrix() const noexcept { return glm::translate(glm::mat4(1), -this->getPosition()); }
1629
glm::mat4 Node::getRotationMatrix() const noexcept {
@@ -19,6 +32,39 @@ glm::mat4 Node::getRotationMatrix() const noexcept {
1932
}
2033
glm::mat4 Node::getViewTranslationMatrix() const noexcept { return glm::translate(glm::mat4(1), -this->getPosition()); }
2134

22-
glm::vec3 Node::getLocalPosition() const noexcept { return {}; }
23-
glm::vec3 Node::getLocalScale() const noexcept { return {}; }
24-
glm::quat Node::getLocalRotation() const noexcept { return {}; }
35+
void Node::setLocalPosition(const glm::vec3 &localPosition) noexcept {
36+
Node *parent = this->parent();
37+
38+
const glm::vec3 global_position = parent ? parent->getPosition() : glm::vec3(0);
39+
this->setPosition(global_position + localPosition);
40+
}
41+
void Node::setLocalScale(const glm::vec3 &localScale) noexcept {
42+
Node *parent = this->parent();
43+
44+
const glm::vec3 global_scale = parent ? parent->getScale() : glm::vec3(0);
45+
this->setScale(global_scale + localScale);
46+
}
47+
void Node::setLocalRotation(const glm::quat &localRotation) noexcept {
48+
Node *parent = this->parent();
49+
50+
const glm::quat global_rotation = parent ? parent->getRotation() : glm::quat();
51+
this->setRotation(global_rotation * localRotation);
52+
}
53+
54+
glm::vec3 Node::getLocalPosition() const noexcept {
55+
Node *parent = this->parent();
56+
glm::vec3 parent_position = parent ? parent->getPosition() : glm::vec3(0);
57+
return parent_position - this->getPosition();
58+
}
59+
glm::vec3 Node::getLocalScale() const noexcept {
60+
Node *parent = this->parent();
61+
glm::vec3 parent_position = parent ? parent->getScale() : glm::vec3(0);
62+
return parent_position - this->getScale();
63+
}
64+
glm::quat Node::getLocalRotation() const noexcept {
65+
Node *parent = this->parent();
66+
glm::quat parent_rotation = parent ? parent->getRotation() : glm::quat();
67+
68+
// TODO: fix
69+
return parent_rotation * glm::inverse(getRotation());
70+
}

Common/Scene/Node.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,19 @@
1717

1818
#include "Core/Object.h"
1919
#include "DataStructure/ITree.h"
20-
#include "Importer/ModelImporter.h"
2120
#include "Transform.h"
2221

2322
namespace glsample {
2423

24+
enum class NodeType { Node, Frustum, Camera, Renderer, Light, MaxNodeTypes };
25+
2526
/**
2627
* @brief
2728
*
2829
*/
29-
class FVDECLSPEC Node : public glsample::TransformGLM,
30-
public fragcore::ITree<Node>,
31-
public fragcore::Object {
30+
class FVDECLSPEC Node : public glsample::TransformGLM, public fragcore::ITree<Node>, public fragcore::Object {
3231
public:
3332
Node() = default;
34-
Node(const NodeObject *node);
3533
~Node() override = default;
3634

3735
public:
@@ -46,11 +44,16 @@ namespace glsample {
4644
void setRotation(const glm::quat &quat) noexcept;
4745

4846
/* */
47+
Node *parent() const noexcept;
4948

5049
glm::vec3 getLocalPosition() const noexcept;
5150
glm::vec3 getLocalScale() const noexcept;
5251
glm::quat getLocalRotation() const noexcept;
5352

53+
void setLocalPosition(const glm::vec3 &localPosition) noexcept;
54+
void setLocalScale(const glm::vec3 &localScale) noexcept;
55+
void setLocalRotation(const glm::quat &localRotation) noexcept;
56+
5457
glm::mat4 getViewMatrix() const noexcept;
5558
glm::mat4 getRotationMatrix() const noexcept;
5659
glm::mat4 getViewTranslationMatrix() const noexcept;
@@ -64,8 +67,8 @@ namespace glsample {
6467
std::vector<unsigned int> materialIndex;
6568

6669
/* */
67-
glm::mat4 modelGlobalTransform;
68-
glm::mat4 modelLocalTransform;
70+
glm::mat4 modelGlobalTransform{};
71+
glm::mat4 modelLocalTransform{};
6972
};
7073

7174
} // namespace glsample

Common/Scene/Renderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
namespace glsample {
2020
class Renderer : public Node {
2121
public:
22+
/* */
23+
fragcore::Bound bound{};
2224
/* Geometry and material. */
2325
std::vector<unsigned int> geometryObjectIndex;
2426
std::vector<unsigned int> materialIndex;

0 commit comments

Comments
 (0)