Cleaning? Still trying to do preproc work
This commit is contained in:
parent
2cb665cf19
commit
8cb1584a00
95
.vscode/settings.json
vendored
95
.vscode/settings.json
vendored
@ -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"
|
|
||||||
}
|
|
||||||
28
.vscode/tasks.json
vendored
28
.vscode/tasks.json
vendored
@ -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"
|
|
||||||
}
|
|
||||||
@ -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)
|
|
||||||
|
|
||||||
@ -47,6 +47,14 @@ protected:
|
|||||||
std::string formatString(const std::string&, const char* shad=nullptr, const std::string& file="", int line=-1);
|
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<std::string, std::string> defines;
|
||||||
|
std::map<uint8_t, ShaderUnit*> includes;
|
||||||
|
uint8_t vMajor=0, vMinor=0;
|
||||||
|
};
|
||||||
|
|
||||||
class ShaderPreprocessor {
|
class ShaderPreprocessor {
|
||||||
public:
|
public:
|
||||||
typedef ShaderPreprocessorError::Codes Codes;
|
typedef ShaderPreprocessorError::Codes Codes;
|
||||||
|
|||||||
65
shader.cpp
65
shader.cpp
@ -359,36 +359,61 @@ std::stringstream ShaderPreprocessor::process(std::stringstream& code) const {
|
|||||||
std::string line;
|
std::string line;
|
||||||
const std::vector<std::string> preprocKeys = {
|
const std::vector<std::string> preprocKeys = {
|
||||||
"#include",
|
"#include",
|
||||||
"//",
|
"#define",
|
||||||
"/*",
|
"#ifdef",
|
||||||
"*/"
|
"#ifndef",
|
||||||
|
"#endif"
|
||||||
};
|
};
|
||||||
const size_t keysListSize = preprocKeys.size();
|
|
||||||
enum Context : uint8_t {
|
enum Context : uint8_t {
|
||||||
Code,
|
Code,
|
||||||
LineComment,
|
BlockComment,
|
||||||
BlockComment
|
FalseBranch
|
||||||
};
|
};
|
||||||
Context currcontext = Code;
|
Context currcontext = Code;
|
||||||
bool blockcomment = false;
|
const size_t keysListSize = preprocKeys.size();
|
||||||
std::vector<size_t> keysIdx(keysListSize);
|
std::vector<size_t> keysIdx(keysListSize);
|
||||||
|
size_t linecom, blockstart, blockend;
|
||||||
// Use linked list to count char len of each line
|
// Use linked list to count char len of each line
|
||||||
while(std::getline(code, line)) {
|
while(std::getline(code, line)) {
|
||||||
if (!blockcomment) {
|
switch (currcontext) {
|
||||||
for (int i = 0; i < keysListSize; ++i) {
|
case Code:
|
||||||
keysIdx[i] = line.find(preprocKeys[i]);
|
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;
|
ret << line;
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
}
|
ret << line;
|
||||||
}
|
break;
|
||||||
if (keysIdx[0] != std::string::npos) {
|
|
||||||
if (keysIdx[1] != std::string::npos) {
|
|
||||||
if ( (keysIdx[0] > keysIdx[1]) ) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user