From e96fe00359857ee376e5e18880f9dee0a356a9b1 Mon Sep 17 00:00:00 2001 From: dotslashinit-sh Date: Tue, 29 Apr 2025 15:10:54 +0530 Subject: [PATCH 1/7] Added CMake for windows --- .gitignore | 2 ++ demonstration/CMakeLists.txt | 21 +++++++++++++++++++++ demonstration/src/main.cxx | 1 - 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 demonstration/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 7d939a3..bd55861 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ blends/** *3d-game-shaders-for-beginners* !blends/* !blends/mill-scene/mill-scene-low-poly-backup.blend +demonstration/build/* +*.exe \ No newline at end of file diff --git a/demonstration/CMakeLists.txt b/demonstration/CMakeLists.txt new file mode 100644 index 0000000..8211b28 --- /dev/null +++ b/demonstration/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.10) +project(3DGameShadersForBeginners LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED true) + +add_executable(3d-game-shaders src/main.cxx) +find_package(Python3 REQUIRED) +set(PandaPath "C:\\Panda3D-1.10.15-x64" CACHE STRING "Path to the root of panda sdk") +list(APPEND LIBRARIES + libp3framework + libpanda + libpandafx + libpandaexpress + libpandaphysics + libp3dtoolconfig + libp3dtool +) +target_link_directories(3d-game-shaders PRIVATE "${PandaPath}/lib") +target_include_directories(3d-game-shaders PRIVATE "${PandaPath}/include") +target_link_libraries(3d-game-shaders PRIVATE ${LIBRARIES}) \ No newline at end of file diff --git a/demonstration/src/main.cxx b/demonstration/src/main.cxx index 0cf10fa..e82f98d 100644 --- a/demonstration/src/main.cxx +++ b/demonstration/src/main.cxx @@ -4,7 +4,6 @@ */ #include -#include #include #include #include From b38b1eeaeb08dcb90459fbaa4ae222aa092545ef Mon Sep 17 00:00:00 2001 From: dotslashinit-sh Date: Tue, 29 Apr 2025 15:40:15 +0530 Subject: [PATCH 2/7] Added VSCode tasks --- demonstration/.vscode/launch.json | 16 ++++++++++++++ demonstration/.vscode/tasks.json | 36 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 demonstration/.vscode/launch.json create mode 100644 demonstration/.vscode/tasks.json diff --git a/demonstration/.vscode/launch.json b/demonstration/.vscode/launch.json new file mode 100644 index 0000000..d50bc14 --- /dev/null +++ b/demonstration/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Run Shaders", + "type": "cppvsdbg", + "request": "launch", + "program": "${workspaceRoot}/build/Release/3d-game-shaders.exe", + "cwd": "${workspaceRoot}", + "preLaunchTask": "Build" + } + ] +} \ No newline at end of file diff --git a/demonstration/.vscode/tasks.json b/demonstration/.vscode/tasks.json new file mode 100644 index 0000000..c01c899 --- /dev/null +++ b/demonstration/.vscode/tasks.json @@ -0,0 +1,36 @@ +{ + "tasks": [ + { + "label": "Build", + "dependsOrder": "parallel", + "dependsOn": ["Build executable", "Copy shaders"] + }, + { + "label": "Build executable", + "type": "shell", + "command": "cmake", + "args": ["--build", ".", "--config", "Release"], + "options": { + "cwd": "${workspaceFolder}/build", + }, + "dependsOn": ["Configure CMake"] + }, + { + "label": "Configure CMake", + "type": "shell", + "command": "cmake ./build", + "options": { + "cwd": "${workspaceFolder}" + } + }, + { + "label": "Copy shaders", + "type": "shell", + "command": "cp -Recurse -Force ./shaders ./build/Release/", + "options": { + "cwd": "${workspaceFolder}" + } + } + ], + "version": "2.0.0" +} \ No newline at end of file From b05d73aec2e0286d2d28e45dcea69e3903821d48 Mon Sep 17 00:00:00 2001 From: dotslashinit-sh Date: Tue, 29 Apr 2025 15:41:37 +0530 Subject: [PATCH 3/7] Remove comment --- demonstration/.vscode/launch.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/demonstration/.vscode/launch.json b/demonstration/.vscode/launch.json index d50bc14..0ff3b0c 100644 --- a/demonstration/.vscode/launch.json +++ b/demonstration/.vscode/launch.json @@ -1,7 +1,4 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { From 50be87e563c55a2a109312de563996d9de66deb9 Mon Sep 17 00:00:00 2001 From: dotslashinit-sh Date: Tue, 29 Apr 2025 15:58:56 +0530 Subject: [PATCH 4/7] Added Powershell script to build files / Fixed VSCode build task --- demonstration/.vscode/tasks.json | 6 +++--- demonstration/CMakeLists.txt | 3 ++- demonstration/build-for-windows.ps1 | 8 ++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 demonstration/build-for-windows.ps1 diff --git a/demonstration/.vscode/tasks.json b/demonstration/.vscode/tasks.json index c01c899..0a9c407 100644 --- a/demonstration/.vscode/tasks.json +++ b/demonstration/.vscode/tasks.json @@ -2,7 +2,7 @@ "tasks": [ { "label": "Build", - "dependsOrder": "parallel", + "dependsOrder": "sequence", "dependsOn": ["Build executable", "Copy shaders"] }, { @@ -18,9 +18,9 @@ { "label": "Configure CMake", "type": "shell", - "command": "cmake ./build", + "command": "cmake .", "options": { - "cwd": "${workspaceFolder}" + "cwd": "${workspaceFolder}/build" } }, { diff --git a/demonstration/CMakeLists.txt b/demonstration/CMakeLists.txt index 8211b28..12fdd71 100644 --- a/demonstration/CMakeLists.txt +++ b/demonstration/CMakeLists.txt @@ -18,4 +18,5 @@ list(APPEND LIBRARIES ) target_link_directories(3d-game-shaders PRIVATE "${PandaPath}/lib") target_include_directories(3d-game-shaders PRIVATE "${PandaPath}/include") -target_link_libraries(3d-game-shaders PRIVATE ${LIBRARIES}) \ No newline at end of file +target_link_libraries(3d-game-shaders PRIVATE ${LIBRARIES}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/demonstration/build-for-windows.ps1 b/demonstration/build-for-windows.ps1 new file mode 100644 index 0000000..9c85bba --- /dev/null +++ b/demonstration/build-for-windows.ps1 @@ -0,0 +1,8 @@ +# Create a build directory +if(-not(Test-Path ./build)) { + mkdir ./build +} + +# Configure CMake +cmake . -B build +cmake --build build --config Release \ No newline at end of file From b52ac7fa60b132975b5cd9fb1dd4f9bcba0819ff Mon Sep 17 00:00:00 2001 From: dotslashinit-sh Date: Tue, 29 Apr 2025 16:31:19 +0530 Subject: [PATCH 5/7] Updated build-for-windows.ps1 / Make VSCode use powershell script --- demonstration/.vscode/launch.json | 2 +- demonstration/.vscode/tasks.json | 26 ++++------------------ demonstration/build-for-windows.ps1 | 34 +++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/demonstration/.vscode/launch.json b/demonstration/.vscode/launch.json index 0ff3b0c..5b74676 100644 --- a/demonstration/.vscode/launch.json +++ b/demonstration/.vscode/launch.json @@ -5,7 +5,7 @@ "name": "Run Shaders", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceRoot}/build/Release/3d-game-shaders.exe", + "program": "${workspaceRoot}/3d-game-shaders.exe", "cwd": "${workspaceRoot}", "preLaunchTask": "Build" } diff --git a/demonstration/.vscode/tasks.json b/demonstration/.vscode/tasks.json index 0a9c407..1a4b7a5 100644 --- a/demonstration/.vscode/tasks.json +++ b/demonstration/.vscode/tasks.json @@ -2,33 +2,15 @@ "tasks": [ { "label": "Build", - "dependsOrder": "sequence", - "dependsOn": ["Build executable", "Copy shaders"] + "dependsOn": ["Build executable"] }, { "label": "Build executable", "type": "shell", - "command": "cmake", - "args": ["--build", ".", "--config", "Release"], + "command": "pwsh", + "args": ["build-for-windows.ps1"], "options": { - "cwd": "${workspaceFolder}/build", - }, - "dependsOn": ["Configure CMake"] - }, - { - "label": "Configure CMake", - "type": "shell", - "command": "cmake .", - "options": { - "cwd": "${workspaceFolder}/build" - } - }, - { - "label": "Copy shaders", - "type": "shell", - "command": "cp -Recurse -Force ./shaders ./build/Release/", - "options": { - "cwd": "${workspaceFolder}" + "cwd": "${workspaceFolder}", } } ], diff --git a/demonstration/build-for-windows.ps1 b/demonstration/build-for-windows.ps1 index 9c85bba..f3f11cd 100644 --- a/demonstration/build-for-windows.ps1 +++ b/demonstration/build-for-windows.ps1 @@ -1,8 +1,34 @@ +function buildExe() { + # Configure CMake + cmake . -B build + # Build the file in release mode + $result = (cmake --build build --config Release ) + Write-Output $result + if($result -eq 0) { + Write-Error "An error occurred when building the project file! Check logs for more details." + } + return $result +} + +function copyExe() { + # Copies the exe file to the workspace root + Copy-Item ./build/Release/3d-game-shaders.exe ./ +} + +$firstTime = 1 + # Create a build directory if(-not(Test-Path ./build)) { - mkdir ./build + mkdir ./build > $null + $firstTime = 1 } -# Configure CMake -cmake . -B build -cmake --build build --config Release \ No newline at end of file +# If CMakeLists.txt or main.cxx is changed, rebuild the executable and copy it to the root directory +if($firstTime -or -not(git diff --quiet CMakeLists.txt src/main.cxx)) { + Write-Output "Building exe file..." + if(buildExe -eq 0) { + Write-Output "Copying exe file..." + copyExe + } + Write-Output "Build completed successfully!" +} \ No newline at end of file From 7d54c91e825f266dbcad31020fff5b0cc8235191 Mon Sep 17 00:00:00 2001 From: dotslashinit-sh Date: Wed, 30 Apr 2025 12:54:15 +0530 Subject: [PATCH 6/7] Add checks to compile only if file was changed --- demonstration/build-for-windows.ps1 | 43 +++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/demonstration/build-for-windows.ps1 b/demonstration/build-for-windows.ps1 index f3f11cd..d4d04c8 100644 --- a/demonstration/build-for-windows.ps1 +++ b/demonstration/build-for-windows.ps1 @@ -1,4 +1,4 @@ -function buildExe() { +function BuildExe() { # Configure CMake cmake . -B build # Build the file in release mode @@ -10,12 +10,42 @@ function buildExe() { return $result } -function copyExe() { +function CopyExe() { # Copies the exe file to the workspace root - Copy-Item ./build/Release/3d-game-shaders.exe ./ + Copy-Item "./build/Release/3d-game-shaders.exe" "./" } -$firstTime = 1 +$changeCache = (Test-Path "build/cache.json") ? (Get-Content "build/cache.json" | ConvertFrom-Json -AsHashTable) : @{} + +function GetFileHash { + param( + $file + ) + return (Get-FileHash "$file" -Algorithm SHA256).Hash +} + +function SetFileHash { + param ( + $file + ) + $changeCache["$file"] = GetFileHash($file) +} + +function CheckDiff { + param ($file) + return ((GetFileHash($file)) -eq ($changeCache["$file"])) +} + +function MakeCache { + if(Test-Path "build/cache.json") { + Clear-Content "build/cache.json" + } + SetFileHash("CMakeLists.txt") + SetFileHash("src/main.cxx") + Set-Content -Path "build/cache.json" -Value ($changeCache | ConvertTo-Json) +} + +$firstTime = 0 # Create a build directory if(-not(Test-Path ./build)) { @@ -24,11 +54,12 @@ if(-not(Test-Path ./build)) { } # If CMakeLists.txt or main.cxx is changed, rebuild the executable and copy it to the root directory -if($firstTime -or -not(git diff --quiet CMakeLists.txt src/main.cxx)) { +if($firstTime -or -not(CheckDiff("src/main.cxx") -and CheckDiff("CMakeLists.txt"))) { Write-Output "Building exe file..." if(buildExe -eq 0) { Write-Output "Copying exe file..." copyExe + MakeCache } - Write-Output "Build completed successfully!" + Write-Output "Build script finished executing!" } \ No newline at end of file From c6ce3e5f55f41f43a3bdb48d9a62a29ece9af845 Mon Sep 17 00:00:00 2001 From: dotslashinit-sh Date: Tue, 29 Jul 2025 18:14:23 +0530 Subject: [PATCH 7/7] Remove .vscode --- demonstration/.vscode/launch.json | 13 ------------- demonstration/.vscode/tasks.json | 18 ------------------ 2 files changed, 31 deletions(-) delete mode 100644 demonstration/.vscode/launch.json delete mode 100644 demonstration/.vscode/tasks.json diff --git a/demonstration/.vscode/launch.json b/demonstration/.vscode/launch.json deleted file mode 100644 index 5b74676..0000000 --- a/demonstration/.vscode/launch.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Run Shaders", - "type": "cppvsdbg", - "request": "launch", - "program": "${workspaceRoot}/3d-game-shaders.exe", - "cwd": "${workspaceRoot}", - "preLaunchTask": "Build" - } - ] -} \ No newline at end of file diff --git a/demonstration/.vscode/tasks.json b/demonstration/.vscode/tasks.json deleted file mode 100644 index 1a4b7a5..0000000 --- a/demonstration/.vscode/tasks.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "tasks": [ - { - "label": "Build", - "dependsOn": ["Build executable"] - }, - { - "label": "Build executable", - "type": "shell", - "command": "pwsh", - "args": ["build-for-windows.ps1"], - "options": { - "cwd": "${workspaceFolder}", - } - } - ], - "version": "2.0.0" -} \ No newline at end of file