Skip to content

Commit 4957f66

Browse files
committed
code cleanup, and minor improvements
1 parent b0b6d4c commit 4957f66

12 files changed

Lines changed: 149 additions & 60 deletions

File tree

CIDI/appimage.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
#
3+
# SCRIPT: Generate AppImage BuilScript
4+
# AUTHOR: Valdemar Lindberg
5+
# DATE:
6+
# REV: 0.1.B
7+
#
8+
# PLATFORM: Linux
9+
#
10+
# PURPOSE: Handle the whole process of generating an AppImage
11+
12+
# set -n
13+
# Uncomment to check script syntax, without execution.
14+
#
15+
# NOTE: Do not forget to put the comment back in or
16+
#
17+
# the shell script will not execute!
18+
# set -x
19+
# Uncomment to debug this shell script
20+
#
21+
22+
BUILD_DIRECTORY=build_app
23+
BUILD_INSTALL_DIR=AppDir
24+
ICON_INTERNAL_FILENAME=opengl-sample-icon
25+
ICON_FILEPATH=../opengl-sample-icon.png
26+
DESKTOP_FILEPATH=../opengl-sample.desktop
27+
BUILD_COMMAND="-DCMAKE_INSTALL_PREFIX=$AppDir/usr -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE -DCMAKE_BUILD_TYPE=Release"
28+
29+
mkdir -p $BUILD_DIRECTORY && cd $BUILD_DIRECTORY
30+
cmake $BUILD_COMMAND ..
31+
cmake --build . --parallel $(nproc --all) --target install
32+
make install DESTDIR=$BUILD_INSTALL_DIR
33+
34+
# Downad the tool requied ot setup
35+
wget -nc https://github.com/linuxdeploy/linuxdeploy/releases/download/1-alpha-20250213-2/linuxdeploy-x86_64.AppImage
36+
chmod +x linuxdeploy-x86_64.AppImage
37+
38+
cp $ICON_FILEPATH $BUILD_INSTALL_DIR/opengl-sample.desktop
39+
40+
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:$(pwd)/$BUILD_INSTALL_DIR/lib/"
41+
# Export variable, since the build tool is still in alpha and has its limitations.
42+
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/lib/x86_64-linux-gnu:$(pwd)/$BUILD_INSTALL_DIR/usr/lib:$(pwd)/$BUILD_INSTALL_DIR/usr/lib/x86_64-linux-gnu"
43+
44+
Version=1.0
45+
46+
./linuxdeploy-x86_64.AppImage --appdir=$BUILD_INSTALL_DIR/ --output appimage --desktop-file=$DESKTOP_FILEPATH --icon-filename $ICON_INTERNAL_FILENAME --icon-file $ICON_FILEPATH

CIDI/entrypoint.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
#
3+
# SCRIPT: EntryPoint for handling multiple executable samples
4+
# AUTHOR: Valdemar Lindberg
5+
# DATE:
6+
# REV: 0.1.B
7+
#
8+
# PLATFORM: Linux
9+
#
10+
# PURPOSE: Handle the whole process of generating an AppImage
11+
12+
# set -n
13+
# Uncomment to check script syntax, without execution.
14+
#
15+
# NOTE: Do not forget to put the comment back in or
16+
#
17+
# the shell script will not execute!
18+
# set -x
19+
# Uncomment to debug this shell script
20+
#
21+
22+
ROOT_PROGRAM=$0
23+
SELECTED_SAMPLE_EXEC=$1
24+
shift 1
25+
SELECTED_SAMPLE_EXEC_ARGS="$@"
26+
27+
echo $SELECTED_SAMPLE_EXEC
28+
echo $SELECTED_SAMPLE_EXEC_ARGS
29+
30+
$SELECTED_SAMPLE_EXEC $SELECTED_SAMPLE_EXEC_ARGS

CIDI/opengl-sample.desktop

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Desktop Entry]
2+
Type=Application
3+
Version=1.0
4+
Name=OpenGLSamples
5+
Exec=entrypoint.sh %U
6+
Icon=opengl-sample-icon
7+
Categories=Utility
8+
GenericName=Debug/Analysis Tool
9+
Keywords=opengl;

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ OPTION(BUILD_WITH_UBSAN "Enable Undefined Behavior Sanitizer." OFF)
1919
OPTION(BUILD_WITH_ASAN "Enable AddressSanitizer." OFF)
2020
OPTION(BUILD_WITH_PEDANTIC "Enable Pedantic Compilation" OFF)
2121

22-
2322
IF(PKG_CONFIG_FOUND)
2423
MESSAGE(STATUS "Found pkg-config: ${PKG_CONFIG_EXECUTABLE} -- version ${PKG_CONFIG_VERSION_STRING}.")
2524
PKG_CHECK_MODULES(SDL2 QUIET sdl2)
@@ -47,7 +46,6 @@ IF(CMAKE_BUILD_TYPE MATCHES Debug)
4746
ADD_DEFINITIONS(-g3 -O0)
4847
ENDIF()
4948

50-
5149
# AVX If supported
5250
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/extern/nekomimi/extern/fragcore/cmake-modules")
5351
FIND_PACKAGE(AVX)
@@ -65,7 +63,6 @@ IF(BUILD_WITH_PEDANTIC)
6563
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PEDANTIC_COMPILE_FLAGS}")
6664
ENDIF()
6765

68-
6966
# ###########################################
7067
# Backend libraries
7168
# ###########################################

Common/GLDataStructure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace glsample {
5050
DepthFunc DepthFunc = DepthFunc::Less;
5151
bool DepthWrite{};
5252
RenderQueue queue;
53+
Primitive primitiveMode;
5354

5455
FillMode fillMode;
5556

Common/Scene/Material.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "GLDataStructure.h"
1919
#include "Importer/ModelImporter.h"
2020
#include "Prerequisites.h"
21-
#include "RenderDesc.h"
2221
#include "SampleHelper.h"
2322
#include "Scene/RenderQueue.h"
2423
#include "ShaderPipeline.h"

Common/Scene/Scene.cpp

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ namespace glsample {
169169
this->UBOStructure.material_align_total_size;
170170

171171
/* */
172-
glGenBuffers(1, &this->UBOStructure.node_and_common_uniform_buffer);
173-
glBindBuffer(GL_UNIFORM_BUFFER, this->UBOStructure.node_and_common_uniform_buffer);
172+
glGenBuffers(1, &this->UBOStructure.shared_uniform_buffer);
173+
glBindBuffer(GL_UNIFORM_BUFFER, this->UBOStructure.shared_uniform_buffer);
174174

175175
if (glBufferStorage) {
176176

@@ -392,7 +392,7 @@ namespace glsample {
392392
}
393393
}
394394

395-
glBindBuffer(GL_UNIFORM_BUFFER, this->UBOStructure.node_and_common_uniform_buffer);
395+
glBindBuffer(GL_UNIFORM_BUFFER, this->UBOStructure.shared_uniform_buffer);
396396

397397
/* */
398398
if (useCoherent) {
@@ -659,12 +659,12 @@ namespace glsample {
659659
const size_t light_offset = this->UBOStructure.light_offsets[this->getRoundRobinIndex()];
660660

661661
glBindBufferRange(GL_UNIFORM_BUFFER, this->UBOStructure.common_buffer_binding,
662-
this->UBOStructure.node_and_common_uniform_buffer, common_offset,
662+
this->UBOStructure.shared_uniform_buffer, common_offset,
663663
this->UBOStructure.common_size_align);
664664

665665
/* */
666666
glBindBufferRange(GL_UNIFORM_BUFFER, this->UBOStructure.light_buffer_binding,
667-
this->UBOStructure.node_and_common_uniform_buffer, light_offset,
667+
this->UBOStructure.shared_uniform_buffer, light_offset,
668668
this->UBOStructure.light_align_total_size);
669669
}
670670

@@ -918,18 +918,20 @@ namespace glsample {
918918
this->UBOStructure.node_prev_offsets[this->getRoundRobinIndex()] +
919919
(node_block_offset_base * this->UBOStructure.max_node_per_binding * sizeof(NodeData));
920920

921+
/* */
921922
glBindBufferRange(GL_UNIFORM_BUFFER, this->UBOStructure.node_buffer_binding,
922-
this->UBOStructure.node_and_common_uniform_buffer, node_total_offset,
923+
this->UBOStructure.shared_uniform_buffer, node_total_offset,
923924
this->UBOStructure.node_size_align);
924925

926+
/* */
925927
glBindBufferRange(GL_UNIFORM_BUFFER, this->UBOStructure.node_prev_buffer_binding,
926-
this->UBOStructure.node_and_common_uniform_buffer, node_prev_total_offset,
928+
this->UBOStructure.shared_uniform_buffer, node_prev_total_offset,
927929
this->UBOStructure.node_size_align);
928930

929931
/* */
930932
const size_t material_offset = this->UBOStructure.mateiral_offsets[this->getRoundRobinIndex()];
931933
glBindBufferRange(GL_UNIFORM_BUFFER, this->UBOStructure.material_buffer_binding,
932-
this->UBOStructure.node_and_common_uniform_buffer, material_offset,
934+
this->UBOStructure.shared_uniform_buffer, material_offset,
933935
this->UBOStructure.material_align_size);
934936
}
935937

@@ -946,25 +948,25 @@ namespace glsample {
946948
const MeshObject &refMesh = this->refGeometry[mesh_index];
947949
glBindVertexArray(refMesh.vao);
948950

949-
/* Material, model matrix. */
951+
/* Material index, model matrix index. */
950952
glVertexAttribI2i(8, material_index, currentNodeIndex % this->UBOStructure.max_node_per_binding);
951953

952954
/* */
955+
const size_t nrInstances = 1;
953956
if (this->getRenderingSettings().enabledTessellation && material.isTessellationEnabled()) {
954957

955958
/* */
956959
glPatchParameteri(GL_PATCH_VERTICES, 3);
957-
glDrawElementsBaseVertex(fragcore::GLHelper::getPrimitive(Primitive::Patchs), refMesh.nrIndicesElements,
958-
GL_UNSIGNED_INT, (void *)(sizeof(unsigned int) * refMesh.indices_offset),
959-
refMesh.vertex_offset);
960+
glDrawElementsInstancedBaseVertex(
961+
fragcore::GLHelper::getPrimitive(Primitive::Patchs), refMesh.nrIndicesElements, GL_UNSIGNED_INT,
962+
(void *)(sizeof(unsigned int) * refMesh.indices_offset), nrInstances, refMesh.vertex_offset);
960963
} else {
961964

962965
/* */
963-
glDrawElementsBaseVertex(
966+
glDrawElementsInstancedBaseVertex(
964967
fragcore::GLHelper::getPrimitive(refMesh.primitiveType), refMesh.nrIndicesElements, GL_UNSIGNED_INT,
965-
(void *)(sizeof(unsigned int) * refMesh.indices_offset), refMesh.vertex_offset);
968+
(void *)(sizeof(unsigned int) * refMesh.indices_offset), nrInstances, refMesh.vertex_offset);
966969
}
967-
// glBindVertexArray(0);
968970
}
969971

970972
/* Update internal states*/
@@ -1006,7 +1008,6 @@ namespace glsample {
10061008

10071009
assert(material);
10081010

1009-
/* */
10101011
/* TODO domain clamping. */
10111012
const RenderQueue domain = material->getRenderQueue();
10121013

@@ -1019,50 +1020,31 @@ namespace glsample {
10191020
}
10201021
}
10211022

1022-
// multi thread.
1023-
//#pragma omp parallel for
1023+
// multi thread.
1024+
// #pragma omp parallel for
10241025
for (size_t domain_index = 0; domain_index < getQueueTypesOrdered().size(); domain_index++) {
10251026
const RenderQueue domain = getQueueTypesOrdered()[domain_index];
10261027

10271028
std::deque<const Node *> queue = this->renderQueueDomainBucket[domain];
10281029

1029-
std::sort(queue.begin(), queue.end(), [&](const Node *a, const Node *b) {
1030-
return getMaterials()[a->materialIndex[0]].getUID() > getMaterials()[b->materialIndex[0]].getUID();
1031-
});
1032-
1033-
this->renderQueue[domain_index] = queue;
1034-
}
1030+
if (this->getRenderingSettings().sortSharedMaterials) {
10351031

1036-
if (this->getRenderingSettings().sortDistance) {
1032+
std::sort(queue.begin(), queue.end(), [&](const Node *a, const Node *b) {
1033+
return getMaterials()[a->materialIndex[0]].getUID() > getMaterials()[b->materialIndex[0]].getUID();
1034+
});
1035+
}
10371036

1037+
this->renderQueue[domain_index] = queue;
10381038
}
10391039

10401040
if (this->getRenderingSettings().mergeInstances) {
1041+
/* Sort based on Shared mesh objects. */
10411042
}
10421043

1043-
/* */
1044-
1045-
/* Sort Based on Distance from Camera, front to back. */
1046-
1047-
/* Sort Transparent Objects. Based on priority. */
1048-
// std::sort(vec.begin(), vec.end(), [this, &index, &edges](const int_iter it1, const int_iter it2) -> bool {
1049-
// index[it1 - int_vec.begin()] < index[it2 - int_vec.begin()];
1050-
// });
1051-
1052-
// int priority = computeMaterialPriority(*material);
1053-
1054-
// renderQueueDomainBucket[RenderQueue::Transparent];
1055-
1056-
/* Sort based on Shared mesh objects. */
1057-
1058-
/* Sort Transparent Objects. Based on distance. */
1059-
}
1060-
1061-
int Scene::computeMaterialPriority(const Material &material) const noexcept {
1062-
const bool use_clipping = material.maskTextureIndex >= 0 && material.maskTextureIndex < refTexture.size();
1063-
const bool useBlending = material.opacity < 1.0f;
1064-
1065-
return (useBlending * 1000) + (use_clipping * 100);
1044+
if (this->getRenderingSettings().sortDistance) {
1045+
/* Sort Opque Objects. Based on distance. */
1046+
/* Sort Transparent Objects. Based on distance. */
1047+
}
10661048
}
10671049

10681050
void Scene::renderUI() { this->settingUI.draw(); }

Common/Scene/Scene.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ namespace glsample {
135135

136136
protected:
137137
virtual void bindTexture(const Material &material, const TextureTypeBinding texture_type);
138-
virtual int computeMaterialPriority(const Material &material) const noexcept;
139138
size_t getRoundRobinIndex() const noexcept { return this->renderPassFrameIndex % BufferRoundRobinSize; }
140139

141140
protected:
@@ -279,8 +278,9 @@ namespace glsample {
279278
PreDepthRenderingSettings preDepthRenderingSettings;
280279
Skybox skybox;
281280
// Render queue settings
282-
bool sortDistance;
283-
bool mergeInstances;
281+
bool sortDistance = true;
282+
bool mergeInstances = true;
283+
bool sortSharedMaterials = true;
284284
};
285285

286286
fragcore::Time timer;
@@ -316,7 +316,7 @@ namespace glsample {
316316

317317
UBOObject uniform_buffer{};
318318

319-
unsigned int node_and_common_uniform_buffer{}; // TODO: removed and replace with uniform_buffer;
319+
unsigned int shared_uniform_buffer{}; // TODO: removed and replace with uniform_buffer;
320320

321321
unsigned int node_base_offset = 0;
322322
std::array<unsigned int, BufferRoundRobinSize> node_offsets{};

Common/Scene/SceneSettingComponentUI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ void SceneSettingsUI::draw() {
8686

8787
ImGui::SeparatorText("Rendering Queue Sorting Settings");
8888

89-
bool distanceSort = false;
89+
bool distanceSort = scene.getRenderingSettings().sortDistance;
9090
if (ImGui::Checkbox("Sort Distance", &distanceSort)) {
9191
}
9292

93-
bool mergeInstance = false;
93+
bool mergeInstance = scene.getRenderingSettings().mergeInstances;
9494
if (ImGui::Checkbox("Merge Instances", &mergeInstance)) {
9595
}
9696

97-
bool bucketMaterial = false;
97+
bool bucketMaterial = scene.getRenderingSettings().sortSharedMaterials;
9898
if (ImGui::Checkbox("Material Bucket Sorting", &bucketMaterial)) {
9999
}
100100

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef _MODELVIEWER_INPUT_
2+
#define _MODELVIEWER_INPUT_ 1
3+
4+
layout(location = 0) in vec3 Vertex;
5+
layout(location = 1) in vec2 TextureCoord;
6+
layout(location = 2) in vec3 Normal;
7+
layout(location = 3) in vec3 Tangent;
8+
layout(location = 4) in uvec4 BoneIDs; /* */
9+
layout(location = 5) in vec4 Weights; /* */
10+
11+
/* */
12+
layout(location = 8) in ivec2 vAssigns;
13+
14+
#endif

0 commit comments

Comments
 (0)