From 8cb1584a00b41d5b35f75e1f38f0f8c7ec8ee95a Mon Sep 17 00:00:00 2001 From: NaifBanana Date: Tue, 11 Feb 2025 01:18:26 -0600 Subject: [PATCH] Cleaning? Still trying to do preproc work --- .vscode/settings.json | 95 ------------------------------------------- .vscode/tasks.json | 28 ------------- CMakeLists.txt | 44 -------------------- include/shader.h | 8 ++++ shader.cpp | 65 ++++++++++++++++++++--------- 5 files changed, 53 insertions(+), 187 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 .vscode/tasks.json delete mode 100644 CMakeLists.txt diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index a4969c2..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "files.associations": { - "iostream": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "compare": "cpp", - "concepts": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp", - "charconv": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "format": "cpp", - "ios": "cpp", - "locale": "cpp", - "mutex": "cpp", - "queue": "cpp", - "ranges": "cpp", - "ratio": "cpp", - "span": "cpp", - "stop_token": "cpp", - "thread": "cpp", - "xfacet": "cpp", - "xiosbase": "cpp", - "xlocale": "cpp", - "xlocbuf": "cpp", - "xlocinfo": "cpp", - "xlocmes": "cpp", - "xlocmon": "cpp", - "xlocnum": "cpp", - "xloctime": "cpp", - "xmemory": "cpp", - "xstring": "cpp", - "xtr1common": "cpp", - "xutility": "cpp", - "chrono": "cpp", - "condition_variable": "cpp", - "iomanip": "cpp", - "semaphore": "cpp", - "variant": "cpp", - "forward_list": "cpp", - "map": "cpp", - "xstddef": "cpp", - "xtree": "cpp" - }, - "cmake.generator": "Ninja", - "cmake.configureSettings": { - "CMAKE_MAKE_PROGRAM": "C:/Users/naifa/Documents/Projects/ninja/ninja.exe", - "CMAKE_C_COMPILER": "path_to_mingw/bin/gcc.exe", - "CMAKE_CXX_COMPILER": "path_to_mingw/bin/g++.exe", - "CMAKE_EXPORT_COMPILE_COMMANDS": true - }, - "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 7b0448d..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "tasks": [ - { - "type": "cppbuild", - "label": "C/C++: g++.exe build active file", - "command": "C:\\msys64\\ucrt64\\bin\\g++.exe", - "args": [ - "-fdiagnostics-color=always", - "-g", - "${file}", - "-o", - "${fileDirname}\\${fileBasenameNoExtension}.exe" - ], - "options": { - "cwd": "${fileDirname}" - }, - "problemMatcher": [ - "$gcc" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "detail": "Task generated by Debugger." - } - ], - "version": "2.0.0" -} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 737cea7..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -cmake_minimum_required(VERSION 3.5.0) -project(GraphicsTest VERSION 0.1.0 LANGUAGES C CXX) - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -include(CTest) -enable_testing() - -# set(CPACK_PROJECT_NAME ${PROJECT_NAME}) -# set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) -# include(CPack) - -include_directories( - ../libs/NBEngine/include - ../libs/glfw/include - ../libs/glad/include - ../libs/glm-0.9.9.8/glm - ./deps - ./include -) - -find_package(OpenGL) -add_subdirectory(../libs/glfw ./deps) - -if (CMAKE_BUILD_TYPE STREQUAL "Release") - link_directories(../libs/NBEngine/build/lib) -endif() -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - link_directories(../libs/NBEngine/build/debug/lib) -endif() - -#add_library(NBDrawing Draw.cpp Shader.cpp ../libs/glad/src/glad.c) -#target_link_libraries(NBDrawing glfw3) - -set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) -set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) -set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) -set(NBGL_BUILD_TEST ON) - -add_executable(GraphicsTest main.cpp funcs.cpp Draw.cpp Shader.cpp Buffers.cpp Camera.cpp ../libs/glad/src/glad.c) -target_link_libraries(GraphicsTest NBWindow glfw OpenGL::GL) - diff --git a/include/shader.h b/include/shader.h index 66e422d..f3cd721 100644 --- a/include/shader.h +++ b/include/shader.h @@ -47,6 +47,14 @@ protected: std::string formatString(const std::string&, const char* shad=nullptr, const std::string& file="", int line=-1); }; +class ShaderUnit { + std::string rawSource; + std::string preprocSource; + std::map defines; + std::map includes; + uint8_t vMajor=0, vMinor=0; +}; + class ShaderPreprocessor { public: typedef ShaderPreprocessorError::Codes Codes; diff --git a/shader.cpp b/shader.cpp index ae791ab..df43d4c 100644 --- a/shader.cpp +++ b/shader.cpp @@ -359,36 +359,61 @@ std::stringstream ShaderPreprocessor::process(std::stringstream& code) const { std::string line; const std::vector preprocKeys = { "#include", - "//", - "/*", - "*/" + "#define", + "#ifdef", + "#ifndef", + "#endif" }; - const size_t keysListSize = preprocKeys.size(); enum Context : uint8_t { Code, - LineComment, - BlockComment + BlockComment, + FalseBranch }; Context currcontext = Code; - bool blockcomment = false; + const size_t keysListSize = preprocKeys.size(); std::vector keysIdx(keysListSize); + size_t linecom, blockstart, blockend; // Use linked list to count char len of each line while(std::getline(code, line)) { - if (!blockcomment) { - for (int i = 0; i < keysListSize; ++i) { - keysIdx[i] = line.find(preprocKeys[i]); + switch (currcontext) { + case Code: + if (linecom != std::string::npos) { + size_t preprocIdx; + for (int i = 0; i < keysListSize; ++i) { + preprocIdx = line.find(preprocKeys[i]); + keysIdx[i] = (preprocIdx < linecom) ? preprocIdx: std::string::npos; + } + } else if (blockstart != std::string::npos) { + size_t preprocIdx; + for (int i = 0; i < keysListSize; ++i) { + preprocIdx = line.find(preprocKeys[i]); + keysIdx[i] = (preprocIdx < blockstart) ? preprocIdx: std::string::npos; + } + } else { + for (int i = 0; i < keysListSize; ++i) { + keysIdx[i] = line.find(preprocKeys[i]); + } } - } else if (keysIdx[2] == std::string::npos) { + + if (keysIdx) + break; + case BlockComment: + if (blockend == std::string::npos) { + ret << line; + } else { + size_t newpos = code.tellg() - line.size() + blockend; + line.resize(blockend); + ret << line; + code.seekg(newpos); + continue; + } + break; + case FalseBranch: ret << line; - } else { - - } - } - if (keysIdx[0] != std::string::npos) { - if (keysIdx[1] != std::string::npos) { - if ( (keysIdx[0] > keysIdx[1]) ) { - - } + break; + default: + ret << line; + break; } } }