Skip to content

Commit 279d2f9

Browse files
committed
Update dep, minor code improvement and changes
1 parent 9caa675 commit 279d2f9

24 files changed

Lines changed: 131 additions & 157 deletions

Common/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" )
1212
INCLUDE(libcxxopts)
1313

1414
ADD_LIBRARY(glCommon SHARED ${SOURCE_OPENGL_COMMON_FILES} ${HEADER_OPENGL_COMMON_FILES})
15-
TARGET_LINK_LIBRARIES(glCommon PUBLIC fragcore nekomimi-window fragcore-rgl fragcore-shader-compiler cxxopts fragcore-geometry-util fragcore-window-sdl fragcore-imageloader glew fragcore-scheduler-tasksch ${OPENGL_LIBRARIES} ${SDL2_LINK_LIBRARIES} assimp)
15+
TARGET_LINK_LIBRARIES(glCommon PUBLIC fragcore nekomimi-window fragcore-rgl fragcore-shader-compiler cxxopts fragcore-geometry-util fragcore-window-sdl2 fragcore-imageloader glew fragcore-scheduler-tasksch ${OPENGL_LIBRARIES} ${SDL2_LINK_LIBRARIES} assimp)
1616

1717
IF(JEMALLOC_LIBRARIES)
1818
TARGET_LINK_LIBRARIES(glCommon PUBLIC ${JEMALLOC_LIBRARIES})
1919
ENDIF()
2020

2121
# OpenGL dependies headers.
2222
TARGET_INCLUDE_DIRECTORIES(glCommon PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_SOURCE_DIR}/extern )
23-
ADD_DEPENDENCIES(glCommon fragcore nekomimi-window fragcore-rgl fragcore-shader-compiler fragcore-geometry-util fragcore-window-sdl cxxopts fragcore-imageloader fragcore-scheduler-tasksch glew)
23+
ADD_DEPENDENCIES(glCommon fragcore nekomimi-window fragcore-rgl fragcore-shader-compiler fragcore-geometry-util fragcore-window-sdl2 cxxopts fragcore-imageloader fragcore-scheduler-tasksch glew)
2424

2525
TARGET_COMPILE_DEFINITIONS(glCommon PRIVATE FLYTHROUGH_CAMERA_IMPLEMENTATION=1)
2626

@@ -34,6 +34,5 @@ IF(OpenMP_FOUND AND OpenMP_CXX_FOUND)
3434
ENDIF()
3535

3636
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Importer)
37-
#ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/Scene)
3837

39-
INSTALL(TARGETS glCommon fragcore nekomimi-window fragcore-rgl fragcore-shader-compiler cxxopts fragcore-geometry-util fragcore-window-sdl fragcore-imageloader glew fragcore-scheduler-tasksch DESTINATION lib)
38+
INSTALL(TARGETS glCommon fragcore nekomimi-window fragcore-rgl fragcore-shader-compiler cxxopts fragcore-geometry-util fragcore-window-sdl2 fragcore-imageloader glew fragcore-scheduler-tasksch DESTINATION lib)

Common/GLDataStructure.h

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2025 Valdemar Lindberg
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*/
116
#pragma once
217
#include "Math3D/LinAlg.h"
318
#include "RenderDesc.h"
4-
#include "SampleHelper.h"
5-
#include "Scene/CameraController.h"
19+
#include "Scene/Camera.h"
620
#include "Scene/RenderQueue.h"
721
#include <glm/fwd.hpp>
822
#include <glm/matrix.hpp>
@@ -46,13 +60,13 @@ namespace glsample {
4660
using GraphicShaderSettings = struct graphic_shader_settings_t { // Property Maybe ?
4761
fragcore::BlendEqu blend_equ = fragcore::BlendEqu::NoEqu; /* */
4862
fragcore::BlendFunc blend_color_func = fragcore::BlendFunc::One; /* */
49-
CullingMode cullingMode = CullingMode::Back;
50-
DepthFunc DepthFunc = DepthFunc::Less;
63+
fragcore::CullingMode cullingMode = fragcore::CullingMode::Back;
64+
fragcore::DepthFunc DepthFunc = fragcore::DepthFunc::Less;
5165
bool DepthWrite{};
5266
RenderQueue queue;
53-
Primitive primitiveMode;
67+
fragcore::Primitive primitiveMode;
5468

55-
FillMode fillMode;
69+
fragcore::FillMode fillMode;
5670

5771
float clipping = 1;
5872
};
@@ -133,28 +147,6 @@ namespace glsample {
133147
return *this;
134148
}
135149

136-
camera_instance_data_t &operator=(CameraController &camera) {
137-
//*this = camera.as<Camera<float>>();
138-
139-
// TODO: reuse function above
140-
this->near = camera.getNear();
141-
this->far = camera.getFar();
142-
this->proj = camera.getProjectionMatrix();
143-
this->view = camera.getViewMatrix();
144-
145-
this->inverseProj = glm::inverse(this->proj);
146-
this->position = glm::vec4(camera.getPosition(), 0);
147-
148-
this->viewDir = glm::vec4(camera.getLookDirection(), 0);
149-
150-
this->viewInv = glm::inverse(this->view);
151-
152-
this->viewRot = camera.getRotationMatrix();
153-
this->viewProj = this->proj * this->view;
154-
this->viewProjInv = glm::inverse(this->viewProj);
155-
return *this;
156-
}
157-
158150
/* */
159151
float near = 0.15;
160152
float far = 1000;

Common/GLSampleBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "cxxopts.hpp"
2222
#include <string>
2323

24-
24+
/* */
2525
class FVDECLSPEC GLSampleBase : public nekomimi::MIMIWindow {
2626
public:
2727
GLSampleBase();

Common/GLUIComponent.cpp

Lines changed: 0 additions & 35 deletions
This file was deleted.

Common/Importer/ImportHelper.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ void ImportHelper::loadModelBuffer(ModelImporter &modelLoader, std::vector<MeshO
126126
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tmp_ibo);
127127
glBindBuffer(GL_ARRAY_BUFFER, tmp_vbo);
128128

129-
// TODO: based on conditions
130129
/* Vertex. */
131130
glEnableVertexAttribArrayARB(AttributeMapping::Vertex);
132131
glVertexAttribPointerARB(0, 3, GL_FLOAT, GL_FALSE, vertexStride,
@@ -258,7 +257,6 @@ void ImportHelper::loadTextures(ModelImporter &modelLoader, std::vector<TextureA
258257
/* Convert BumpMap to NormalMap*/
259258
if (!materials.empty() && materials[0]->heightbumpIndex == texture_index) {
260259

261-
// TODO: use gpu to convert image.
262260
image = std::move(ImageUtil::convert2NormalMap(image, 3.5f));
263261
materials[0]->heightbumpIndex = -1;
264262
materials[0]->normalIndex = texture_index;
@@ -309,7 +307,7 @@ void ImportHelper::loadTextures(ModelImporter &modelLoader, std::vector<TextureA
309307
}
310308

311309
std::cout << "Start Transfering ImageData to GPU" << std::endl;
312-
310+
313311
#pragma omp master
314312
for (size_t texture_index = 0; texture_index < images.size(); texture_index++) {
315313

Common/Importer/ModelImporter.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,6 @@ void ModelImporter::initScene(const aiScene *scene) {
285285
}
286286
});
287287

288-
/* */
289-
nodePool.resize(4096);
290-
291-
process_textures_thread.join();
292-
process_light_camera_thread.join();
293-
294-
for (size_t i = 0; i < model_threads.size(); i++) {
295-
model_threads[i].join();
296-
}
297-
298288
std::thread process_material_thread([&]() {
299289
/* Require Texture Data has been loaded. */
300290
if (scene->HasMaterials()) {
@@ -305,8 +295,29 @@ void ModelImporter::initScene(const aiScene *scene) {
305295
}
306296
});
307297

298+
size_t nrNodes = 0;
299+
std::function<size_t(aiNode *)> calculateNumNodes;
308300
/* */
309-
this->nodeReferences.reserve(2048); // TODO: calculate.
301+
calculateNumNodes = [&nrNodes, &calculateNumNodes](aiNode *currentNode) {
302+
nrNodes++;
303+
for (size_t i = 0; i < currentNode->mNumChildren; i++) {
304+
calculateNumNodes(currentNode->mChildren[i]);
305+
}
306+
return nrNodes;
307+
};
308+
calculateNumNodes(scene->mRootNode);
309+
310+
process_textures_thread.join();
311+
process_light_camera_thread.join();
312+
process_material_thread.join();
313+
314+
for (size_t i = 0; i < model_threads.size(); i++) {
315+
model_threads[i].join();
316+
}
317+
318+
/* */
319+
nodePool.resize(nrNodes);
320+
this->nodeReferences.reserve(nrNodes);
310321
this->initNodeRoot(scene->mRootNode, nullptr);
311322

312323
/* */
@@ -323,7 +334,6 @@ void ModelImporter::initScene(const aiScene *scene) {
323334
}
324335
});
325336

326-
process_material_thread.join();
327337
process_bone_animation_thread.join();
328338
}
329339

@@ -343,9 +353,8 @@ void ModelImporter::initNodeRoot(const aiNode *ai_node, NodeObject *parent) {
343353
aiVector3f position, scale;
344354
aiQuaternion rotation;
345355

346-
// TODO: fix pool for classes.
347-
NodeObject *pobject = new NodeObject(); // nodePool.obtain();
348-
//*pobject = NodeObject();
356+
/* Fetch node from pool. */
357+
NodeObject *pobject = &nodePool[nrNodesInPool++];
349358

350359
/* Assigned parent. */
351360
if (parent) {

Common/Importer/ModelImporter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ class FVDECLSPEC ModelImporter {
391391

392392
/* Nodes. */
393393
std::vector<NodeObject> nodePool;
394+
size_t nrNodesInPool = 0;
394395
std::vector<NodeObject *> nodeReferences;
395396
std::map<std::string, NodeObject *> nodeByName;
396397

Common/Scene/Node.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,9 @@ glm::mat4 Node::getLocalViewMatrix() const noexcept {
118118
return localView;
119119
}
120120

121-
glm::mat4 Node::getRotationMatrix() const noexcept {
122-
// glm::quat rotation = glm::quatLookAt(glm::normalize(this->forward()), glm::normalize(this->up()));
123-
return glm::toMat4(this->getRotation());
124-
}
121+
glm::mat4 Node::getRotationMatrix() const noexcept { return glm::toMat4(this->getRotation()); }
125122

126-
glm::mat4 Node::getLocalRotationMatrix() const noexcept {
127-
// glm::quat rotation = glm::quatLookAt(glm::normalize(this->forward()), glm::normalize(this->up()));
128-
return glm::toMat4(this->getLocalRotation());
129-
}
123+
glm::mat4 Node::getLocalRotationMatrix() const noexcept { return glm::toMat4(this->getLocalRotation()); }
130124

131125
glm::mat4 Node::getViewTranslationMatrix() const noexcept { return glm::translate(glm::mat4(1), -this->getPosition()); }
132126

@@ -176,9 +170,9 @@ glm::vec3 Node::getLocalScale() const noexcept {
176170
}
177171
return this->getScale();
178172
}
173+
179174
glm::quat Node::getLocalRotation() const noexcept {
180175
Node *parent = this->parent();
181-
// TODO: fix and verify.
182176
if (parent) {
183177
return parent->getRotation() * glm::inverse(getRotation());
184178
}

Common/Scene/Scene.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ namespace glsample {
515515
}
516516
}
517517

518-
/* */
519-
#pragma omp single
518+
/* */
519+
#pragma omp single
520520
for (size_t i = 0; i < objects.size(); i++) {
521521
this->visableNodes.insert(this->visableNodes.end(), objects[i].begin(), objects[i].end());
522522
}
@@ -566,6 +566,9 @@ namespace glsample {
566566

567567
this->getRenderingSettings().skybox.render(*camera);
568568

569+
glActiveTexture(GL_TEXTURE0 + TextureTypeBinding::Reflection);
570+
glBindTexture(GL_TEXTURE_2D, this->getRenderingSettings().skybox.getTexture());
571+
569572
/* */
570573
this->render();
571574

@@ -897,11 +900,6 @@ namespace glsample {
897900
this->bindTexture(*material, TextureTypeBinding::Specular_Roughness);
898901
this->bindTexture(*material, TextureTypeBinding::Metal);
899902
// this->bindTexture(material, TextureType::Irradiance); //TODO: enable once material has been binded
900-
// with irradiance texture
901-
// this->bindTexture(*material, TextureTypeBinding::Reflection);
902-
903-
// glActiveTexture(GL_TEXTURE0 + TextureTypeBinding::Reflection);
904-
// glBindTexture(GL_TEXTURE_2D, this->getRenderingSettings().skybox.getTexture()); // TODO: relocate
905903

906904
this->bindTexture(*material, TextureTypeBinding::DepthBuffer);
907905
}

Common/ShaderLoader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace glsample {
3232
const std::vector<uint32_t> *geometry = nullptr,
3333
const std::vector<uint32_t> *tesselationc = nullptr,
3434
const std::vector<uint32_t> *tesselatione = nullptr);
35-
3635
static int loadGraphicProgram(const std::vector<char> *vertex, const std::vector<char> *fragment,
3736
const std::vector<char> *geometry = nullptr,
3837
const std::vector<char> *tesselationc = nullptr,

0 commit comments

Comments
 (0)