diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-20 20:55:05 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-18 15:21:46 +0100 |
commit | ca92d8c90f7103db6d7cae4cef49b278d804b474 (patch) | |
tree | baf44e42fcc1cf7e871a7b2f1d3d92f680f3a845 | |
parent | 3d7f123c0fc0af4b8df3ad791b264d22268bd423 (diff) |
Create shader using c++ code
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | LICENSE | 7 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | compile_commands.json | 92 | ||||
-rw-r--r-- | include/DataView.hpp | 26 | ||||
-rw-r--r-- | include/RenderBackend/OpenGL/CommonShader.hpp | 33 | ||||
-rw-r--r-- | include/RenderBackend/OpenGL/DeviceMemory.hpp | 27 | ||||
-rw-r--r-- | include/RenderBackend/OpenGL/PixelShader.hpp | 71 | ||||
-rw-r--r-- | include/RenderBackend/OpenGL/ShaderVec.hpp | 81 | ||||
-rw-r--r-- | include/RenderBackend/OpenGL/VertexShader.hpp | 70 | ||||
-rw-r--r-- | include/RenderBackend/OpenGL/opengl.hpp | 5 | ||||
-rw-r--r-- | include/types.hpp | 22 | ||||
-rwxr-xr-x | include/utils.hpp | 6 | ||||
-rw-r--r-- | project.conf | 9 | ||||
-rw-r--r-- | src/RenderBackend/OpenGL/DeviceMemory.cpp | 31 | ||||
-rw-r--r-- | src/RenderBackend/OpenGL/PixelShader.cpp | 114 | ||||
-rw-r--r-- | src/RenderBackend/OpenGL/ShaderVec.cpp | 23 | ||||
-rw-r--r-- | src/RenderBackend/OpenGL/VertexShader.cpp | 110 | ||||
-rw-r--r-- | src/main.cpp | 88 |
19 files changed, 820 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9b6c2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +sibs-build +.kdev4 +amalgine.kdev4 @@ -0,0 +1,7 @@ +Copyright (c) 2017 dec05eba + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -1 +1,2 @@ - +## Prerequisite +Install glfw3 and glew diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 0000000..c409aa1 --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,92 @@ +[ + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/entity/Entity.cpp \"-o\" 'amalgine@exe/src/entity/Entity.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/entity/Entity.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/entity/Entity.cpp", + "output": "amalgine@exe/src/entity/Entity.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/entity/MeshInstance.cpp \"-o\" 'amalgine@exe/src/entity/MeshInstance.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/entity/MeshInstance.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/entity/MeshInstance.cpp", + "output": "amalgine@exe/src/entity/MeshInstance.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/Image.cpp \"-o\" 'amalgine@exe/src/Image.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/Image.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/Image.cpp", + "output": "amalgine@exe/src/Image.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/ShaderFrame.cpp \"-o\" 'amalgine@exe/src/RenderBackend/OpenGL/ShaderFrame.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/RenderBackend/OpenGL/ShaderFrame.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/ShaderFrame.cpp", + "output": "amalgine@exe/src/RenderBackend/OpenGL/ShaderFrame.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/ShaderProgram.cpp \"-o\" 'amalgine@exe/src/RenderBackend/OpenGL/ShaderProgram.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/RenderBackend/OpenGL/ShaderProgram.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/ShaderProgram.cpp", + "output": "amalgine@exe/src/RenderBackend/OpenGL/ShaderProgram.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/Uniform.cpp \"-o\" 'amalgine@exe/src/RenderBackend/OpenGL/Uniform.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/RenderBackend/OpenGL/Uniform.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/Uniform.cpp", + "output": "amalgine@exe/src/RenderBackend/OpenGL/Uniform.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/DeviceMemory.cpp \"-o\" 'amalgine@exe/src/RenderBackend/OpenGL/DeviceMemory.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/RenderBackend/OpenGL/DeviceMemory.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/DeviceMemory.cpp", + "output": "amalgine@exe/src/RenderBackend/OpenGL/DeviceMemory.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/Texture2D.cpp \"-o\" 'amalgine@exe/src/RenderBackend/OpenGL/Texture2D.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/RenderBackend/OpenGL/Texture2D.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/Texture2D.cpp", + "output": "amalgine@exe/src/RenderBackend/OpenGL/Texture2D.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/Shader.cpp \"-o\" 'amalgine@exe/src/RenderBackend/OpenGL/Shader.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/RenderBackend/OpenGL/Shader.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/RenderBackend/OpenGL/Shader.cpp", + "output": "amalgine@exe/src/RenderBackend/OpenGL/Shader.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/File.cpp \"-o\" 'amalgine@exe/src/File.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/File.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/File.cpp", + "output": "amalgine@exe/src/File.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/model_loader/ObjModelLoader.cpp \"-o\" 'amalgine@exe/src/model_loader/ObjModelLoader.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/model_loader/ObjModelLoader.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/model_loader/ObjModelLoader.cpp", + "output": "amalgine@exe/src/model_loader/ObjModelLoader.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/main.cpp \"-o\" 'amalgine@exe/src/main.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/main.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/main.cpp", + "output": "amalgine@exe/src/main.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/ModelLoader.cpp \"-o\" 'amalgine@exe/src/ModelLoader.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/ModelLoader.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/ModelLoader.cpp", + "output": "amalgine@exe/src/ModelLoader.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/ThirdPersonCamera.cpp \"-o\" 'amalgine@exe/src/ThirdPersonCamera.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/ThirdPersonCamera.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/ThirdPersonCamera.cpp", + "output": "amalgine@exe/src/ThirdPersonCamera.cpp.o" + }, + { + "directory": "/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/release", + "command": "ccache c++ \"-c\" -fPIE -fPIC /home/dec05eba/git/amalgine/src/Physics/Physics.cpp \"-o\" 'amalgine@exe/src/Physics/Physics.cpp.o' -fdiagnostics-show-option -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Winvalid-pch -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE -fstack-protector -MMD -MF 'amalgine@exe/src/Physics/Physics.cpp.o'.d -I/usr/local/include '-I/usr/local/include/libsurvive/libsurvive' '-I/usr/local/include/libsurvive/redist/' '-I/home/dec05eba/.cache/sibs/lib/linux_x86_64/soil/1.16.0/inc' '-I/home/dec05eba/git/amalgine/sibs-build/linux_x86_64/generated-headers' -I/usr/include/bullet -I/usr/include/hidapi \"-Wall\" \"-Wextra\" \"-Werror=return-type\" -O3 -g0 -DNDEBUG -flto \"-fexceptions\" \"-Wnon-virtual-dtor\" \"-std=c++14\" \"-pedantic\"", + "file": "/home/dec05eba/git/amalgine/src/Physics/Physics.cpp", + "output": "amalgine@exe/src/Physics/Physics.cpp.o" + } +] diff --git a/include/DataView.hpp b/include/DataView.hpp new file mode 100644 index 0000000..c9e25e7 --- /dev/null +++ b/include/DataView.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "types.hpp" + +namespace amalgine +{ + template <typename T> + class DataView + { + public: + DataView() : data(nullptr), size(0) {} + + DataView(T *_data, usize _size) : data(_data), size(_size) + { + + } + + usize getByteSize() const + { + return size * sizeof(T); + } + + T *data; + usize size; + }; +} diff --git a/include/RenderBackend/OpenGL/CommonShader.hpp b/include/RenderBackend/OpenGL/CommonShader.hpp new file mode 100644 index 0000000..a67aa68 --- /dev/null +++ b/include/RenderBackend/OpenGL/CommonShader.hpp @@ -0,0 +1,33 @@ +#pragma once + +namespace amalgine +{ + static bool isAlpha(char c) + { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); + } + + static bool isDigit(char c) + { + return c >= '0' && c <= '9'; + } + + static bool isShaderVariableNameValid(const char *variableName) + { + const char *p = &variableName[0]; + if(isAlpha(*p) || *p == '_') + { + ++p; + while(true) + { + char c = *p; + if(c == '\0') + return true; + else if(isAlpha(c) || isDigit(c) || c == '_') + ++p; + } + } + + return false; + } +} diff --git a/include/RenderBackend/OpenGL/DeviceMemory.hpp b/include/RenderBackend/OpenGL/DeviceMemory.hpp new file mode 100644 index 0000000..706529e --- /dev/null +++ b/include/RenderBackend/OpenGL/DeviceMemory.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "../../DataView.hpp" +#include "../../utils.hpp" + +namespace amalgine +{ + class DeviceMemory + { + DISABLE_COPY(DeviceMemory) + public: + DeviceMemory(); + + // Uploaded once, drawn many times + void copyStatic(const DataView<f32> &data); + + // Created once, changed from time to time but drawn many times more than that + void copyDynamic(const DataView<f32> &data); + + // Uploaded once, drawn once (for example data that is changed every frame) + void copyStream(const DataView<f32> &data); + private: + void copy(const DataView<f32> &data, i32 storageType); + private: + u32 vertexBufferObjectId; + }; +} diff --git a/include/RenderBackend/OpenGL/PixelShader.hpp b/include/RenderBackend/OpenGL/PixelShader.hpp new file mode 100644 index 0000000..3d33155 --- /dev/null +++ b/include/RenderBackend/OpenGL/PixelShader.hpp @@ -0,0 +1,71 @@ +#pragma once + +#include "../../DataView.hpp" +#include "ShaderVec.hpp" +#include <string> +#include <unordered_map> +#include <vector> +#include <stdexcept> +#include <functional> + +namespace amalgine +{ + class PixelShaderTooManyAttributes : public std::runtime_error + { + public: + PixelShaderTooManyAttributes(i32 maxPixelAttributes); + }; + + class PixelShaderAttributeAlreadyDefined : public std::runtime_error + { + public: + PixelShaderAttributeAlreadyDefined(const std::string &attributeName); + }; + + class PixelShaderInvalidAttributeName : public std::runtime_error + { + public: + PixelShaderInvalidAttributeName(const std::string &attributeName); + }; + + class PixelShaderFunctionAlreadyDefined : public std::runtime_error + { + public: + PixelShaderFunctionAlreadyDefined(const std::string &funcName); + }; + + using PixelShaderMainFunc = std::function<void()>; + + /* + * Using the same PixelShader instance in multiple threads to define data is not thread safe. + * All get*** functions are thread safe. + */ + class PixelShader + { + public: + PixelShader(); + + const std::string& getOutputAttributeName(i32 attributeIndex); + ShaderOutputVec4 defineOutputVec4(const std::string &name); + void defineMain(PixelShaderMainFunc mainFunc); + void assign(const ShaderOutputVec4 &lhsVariable, const ShaderVec4 &rhsVariable); + std::string build(); + private: + void writeHeader(const std::string &code); + void writeBody(const std::string &code); + + /* + * Throws PixelShaderTooManyAttributes if too many pixel attributes are defined for the platform. + * Throws PixelShaderAttributeAlreadyDefined if a pixel attribute with the same name has already been defined. + */ + i32 defineOutputVariable(const std::string &variableName, const char *typeName); + private: + std::string header; + std::string body; + int locationCounter; + i32 maxPixelAttribs; // Could make this static + std::unordered_map<std::string, i32> pixelAttributes; + std::vector<std::string> pixelAttributeNames; + bool mainFuncDefined; + }; +} diff --git a/include/RenderBackend/OpenGL/ShaderVec.hpp b/include/RenderBackend/OpenGL/ShaderVec.hpp new file mode 100644 index 0000000..10e628c --- /dev/null +++ b/include/RenderBackend/OpenGL/ShaderVec.hpp @@ -0,0 +1,81 @@ +#pragma once + +#include "../../types.hpp" +#include <string> + +namespace amalgine +{ + class VertexShader; + class PixelShader; + + class ShaderInputVec2 + { + friend class VertexShader; + public: + const std::string& getName() const; + private: + ShaderInputVec2(VertexShader *_vertexShader, i32 _attributeIndex) : + vertexShader(_vertexShader), + attributeIndex(_attributeIndex) + { + + } + private: + VertexShader *vertexShader; + i32 attributeIndex; + }; + + class ShaderVec4 + { + public: + ShaderVec4(f32 x = 0.0f, f32 y = 0.0f, f32 z = 0.0f, f32 w = 0.0f) + { + result = "vec4("; + result += std::to_string(x); + result += ", "; + result += std::to_string(y); + result += ", "; + result += std::to_string(z); + result += ", "; + result += std::to_string(w); + result += ")"; + } + + ShaderVec4(const ShaderInputVec2 &vec2, f32 z = 0.0f, f32 w = 0.0f) + { + result = "vec4("; + result += vec2.getName(); + result += ", "; + result += std::to_string(z); + result += ", "; + result += std::to_string(w); + result += ")"; + } + + const std::string& getOutput() const + { + return result; + } + private: + std::string result; + }; + + class ShaderOutputVec4 + { + friend class PixelShader; + public: + const std::string& getName() const; + + void operator=(const ShaderVec4 &shaderVec4); + private: + ShaderOutputVec4(PixelShader *_pixelShader, i32 _attributeIndex) : + pixelShader(_pixelShader), + attributeIndex(_attributeIndex) + { + + } + private: + PixelShader *pixelShader; + i32 attributeIndex; + }; +} diff --git a/include/RenderBackend/OpenGL/VertexShader.hpp b/include/RenderBackend/OpenGL/VertexShader.hpp new file mode 100644 index 0000000..ec8be22 --- /dev/null +++ b/include/RenderBackend/OpenGL/VertexShader.hpp @@ -0,0 +1,70 @@ +#pragma once + +#include "../../DataView.hpp" +#include "ShaderVec.hpp" +#include <string> +#include <unordered_map> +#include <vector> +#include <stdexcept> +#include <functional> + +namespace amalgine +{ + class VertexShaderTooManyAttributes : public std::runtime_error + { + public: + VertexShaderTooManyAttributes(i32 maxVertexAttributes); + }; + + class VertexShaderAttributeAlreadyDefined : public std::runtime_error + { + public: + VertexShaderAttributeAlreadyDefined(const std::string &attributeName); + }; + + class VertexShaderInvalidAttributeName : public std::runtime_error + { + public: + VertexShaderInvalidAttributeName(const std::string &attributeName); + }; + + class VertexShaderFunctionAlreadyDefined : public std::runtime_error + { + public: + VertexShaderFunctionAlreadyDefined(const std::string &funcName); + }; + + using VertexShaderMainFunc = std::function<ShaderVec4()>; + + /* + * Using the same VertexShader instance in multiple threads to define data is not thread safe. + * All get*** functions are thread safe. + */ + class VertexShader + { + public: + VertexShader(); + + const std::string& getInputAttributeName(i32 attributeIndex); + ShaderInputVec2 defineInputVec2(const std::string &name); + void defineMain(VertexShaderMainFunc mainFunc); + std::string build(); + private: + void writeHeader(const std::string &code); + void writeBody(const std::string &code); + + /* + * Throws VertexShaderTooManyInputAttributes if too many vertex attributes are defined for the platform. + * Throws VertexShaderAttributeAlreadyDefined if a vertex attribute with the same name has already been defined. + */ + i32 defineInputVariable(const std::string &variableName, const char *typeName); + private: + std::string header; + std::string body; + int locationCounter; + i32 maxVertexAttribs; // Could make this static + std::unordered_map<std::string, i32> vertexAttributes; + std::vector<std::string> vertexAttributeNames; + bool mainFuncDefined; + }; +} diff --git a/include/RenderBackend/OpenGL/opengl.hpp b/include/RenderBackend/OpenGL/opengl.hpp new file mode 100644 index 0000000..6ea8fcb --- /dev/null +++ b/include/RenderBackend/OpenGL/opengl.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include <GL/glew.h> +#include <GLFW/glfw3.h> +#include <glm/glm.hpp> diff --git a/include/types.hpp b/include/types.hpp new file mode 100644 index 0000000..4f95730 --- /dev/null +++ b/include/types.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include <cstdint> + +namespace amalgine +{ + typedef int8_t i8; + typedef int16_t i16; + typedef int32_t i32; + typedef int64_t i64; + + typedef uint8_t u8; + typedef uint16_t u16; + typedef uint32_t u32; + typedef uint64_t u64; + + typedef intptr_t isize; + typedef uintptr_t usize; + + typedef float f32; + typedef double f64; +} diff --git a/include/utils.hpp b/include/utils.hpp new file mode 100755 index 0000000..01e478d --- /dev/null +++ b/include/utils.hpp @@ -0,0 +1,6 @@ +#pragma once + +// Disable copying for a class or struct +#define DISABLE_COPY(ClassName) \ + ClassName(ClassName&) = delete; \ + ClassName& operator = (ClassName&) = delete; diff --git a/project.conf b/project.conf new file mode 100644 index 0000000..977aee7 --- /dev/null +++ b/project.conf @@ -0,0 +1,9 @@ +[package] +name = "amalgine" +type = "executable" +version = "0.1.0" + +[dependencies] +glfw3 = "3.2.1" +glew = "2.1.0" +glm = "0.9.8"
\ No newline at end of file diff --git a/src/RenderBackend/OpenGL/DeviceMemory.cpp b/src/RenderBackend/OpenGL/DeviceMemory.cpp new file mode 100644 index 0000000..f166666 --- /dev/null +++ b/src/RenderBackend/OpenGL/DeviceMemory.cpp @@ -0,0 +1,31 @@ +#include "../../../include/RenderBackend/OpenGL/DeviceMemory.hpp" +#include "../../../include/RenderBackend/OpenGL/opengl.hpp" + +namespace amalgine +{ + DeviceMemory::DeviceMemory() + { + glGenBuffers(1, &vertexBufferObjectId); + } + + void DeviceMemory::copyStatic(const DataView<f32> &data) + { + copy(data, GL_STATIC_DRAW); + } + + void DeviceMemory::copyDynamic(const DataView<f32> &data) + { + copy(data, GL_DYNAMIC_DRAW); + } + + void DeviceMemory::copyStream(const DataView<f32> &data) + { + copy(data, GL_STREAM_DRAW); + } + + void DeviceMemory::copy(const DataView<f32> &data, i32 storageType) + { + glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId); + glBufferData(GL_ARRAY_BUFFER, data.getByteSize(), data.data, storageType); + } +} diff --git a/src/RenderBackend/OpenGL/PixelShader.cpp b/src/RenderBackend/OpenGL/PixelShader.cpp new file mode 100644 index 0000000..cbdc842 --- /dev/null +++ b/src/RenderBackend/OpenGL/PixelShader.cpp @@ -0,0 +1,114 @@ +#include "../../../include/RenderBackend/OpenGL/PixelShader.hpp" +#include "../../../include/RenderBackend/OpenGL/CommonShader.hpp" +#include "../../../include/RenderBackend/OpenGL/opengl.hpp" +#include <cassert> + +using namespace std; + +namespace amalgine +{ + PixelShaderTooManyAttributes::PixelShaderTooManyAttributes(i32 maxPixelAttributes) : + runtime_error(string("Attempting to define more than ") + to_string(maxPixelAttributes) + " pixel attributes") + { + + } + + PixelShaderAttributeAlreadyDefined::PixelShaderAttributeAlreadyDefined(const std::string &attributeName) : + runtime_error(string("A pixel attribute with the name ") + attributeName + " has already been defined") + { + + } + + PixelShaderInvalidAttributeName::PixelShaderInvalidAttributeName(const std::string &attributeName) : + runtime_error(string("Pixel attribute name ") + attributeName + " is invalid") + { + + } + + PixelShaderFunctionAlreadyDefined::PixelShaderFunctionAlreadyDefined(const std::string &funcName) : + runtime_error(string("Pixel shader function already defined: ") + funcName) + { + + } + + PixelShader::PixelShader() : locationCounter(0), mainFuncDefined(false) + { + glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxPixelAttribs); + writeHeader("#version 330 core\n\n"); + } + + const string& PixelShader::getOutputAttributeName(i32 attributeIndex) + { + assert(attributeIndex < pixelAttributeNames.size()); + return pixelAttributeNames[attributeIndex]; + } + + ShaderOutputVec4 PixelShader::defineOutputVec4(const std::string &name) + { + i32 attributeIndex = defineOutputVariable(name, "vec4"); + return ShaderOutputVec4(this, attributeIndex); + } + + void PixelShader::defineMain(PixelShaderMainFunc mainFunc) + { + if(mainFuncDefined) + throw PixelShaderFunctionAlreadyDefined("main"); + + writeBody("void main() {\n"); + mainFunc(); + mainFuncDefined = true; + writeBody("}\n\n"); + } + + void PixelShader::assign(const ShaderOutputVec4 &lhsVariable, const ShaderVec4 &rhsVariable) + { + writeBody(lhsVariable.getName()); + writeBody(" = "); + writeBody(rhsVariable.getOutput()); + writeBody(";\n"); + } + + i32 PixelShader::defineOutputVariable(const string &variableName, const char *typeName) + { + if(!isShaderVariableNameValid(variableName.c_str())) + throw PixelShaderInvalidAttributeName(variableName); + + if(locationCounter + 1 > maxPixelAttribs) + throw PixelShaderTooManyAttributes(maxPixelAttribs); + + if(pixelAttributes.find(variableName) != pixelAttributes.end()) + throw PixelShaderAttributeAlreadyDefined(variableName); + + i32 attributeIndex = locationCounter; + pixelAttributes[variableName] = locationCounter; + pixelAttributeNames.push_back(variableName); + + ++locationCounter; + writeHeader("out "); + writeHeader(typeName); + writeHeader(" "); + writeHeader(variableName); + writeHeader(";\n"); + return attributeIndex; + } + + string PixelShader::build() + { + std::string result; + result.reserve(header.size() + 2 + body.size()); + result += header; + result += "\n"; + result += body; + return result; + } + + void PixelShader::writeHeader(const string &code) + { + header += code; + } + + void PixelShader::writeBody(const string &code) + { + body += code; + } +} diff --git a/src/RenderBackend/OpenGL/ShaderVec.cpp b/src/RenderBackend/OpenGL/ShaderVec.cpp new file mode 100644 index 0000000..0dfb4c6 --- /dev/null +++ b/src/RenderBackend/OpenGL/ShaderVec.cpp @@ -0,0 +1,23 @@ +#include "../../../include/RenderBackend/OpenGL/ShaderVec.hpp" +#include "../../../include/RenderBackend/OpenGL/VertexShader.hpp" +#include "../../../include/RenderBackend/OpenGL/PixelShader.hpp" + +using namespace std; + +namespace amalgine +{ + const string& ShaderInputVec2::getName() const + { + return vertexShader->getInputAttributeName(attributeIndex); + } + + const string& ShaderOutputVec4::getName() const + { + return pixelShader->getOutputAttributeName(attributeIndex); + } + + void ShaderOutputVec4::operator=(const ShaderVec4 &shaderVec4) + { + pixelShader->assign(*this, shaderVec4); + } +} diff --git a/src/RenderBackend/OpenGL/VertexShader.cpp b/src/RenderBackend/OpenGL/VertexShader.cpp new file mode 100644 index 0000000..b869624 --- /dev/null +++ b/src/RenderBackend/OpenGL/VertexShader.cpp @@ -0,0 +1,110 @@ +#include "../../../include/RenderBackend/OpenGL/VertexShader.hpp" +#include "../../../include/RenderBackend/OpenGL/CommonShader.hpp" +#include "../../../include/RenderBackend/OpenGL/opengl.hpp" +#include <cassert> + +using namespace std; + +namespace amalgine +{ + VertexShaderTooManyAttributes::VertexShaderTooManyAttributes(i32 maxVertexAttributes) : + runtime_error(string("Attempting to define more than ") + to_string(maxVertexAttributes) + " vertex attributes") + { + + } + + VertexShaderAttributeAlreadyDefined::VertexShaderAttributeAlreadyDefined(const std::string &attributeName) : + runtime_error(string("A vertex attribute with the name ") + attributeName + " has already been defined") + { + + } + + VertexShaderInvalidAttributeName::VertexShaderInvalidAttributeName(const std::string &attributeName) : + runtime_error(string("Vertex attribute name ") + attributeName + " is invalid") + { + + } + + VertexShaderFunctionAlreadyDefined::VertexShaderFunctionAlreadyDefined(const std::string &funcName) : + runtime_error(string("Vertex shader function already defined: ") + funcName) + { + + } + + VertexShader::VertexShader() : locationCounter(0), mainFuncDefined(false) + { + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); + writeHeader("#version 330 core\n\n"); + } + + const string& VertexShader::getInputAttributeName(i32 attributeIndex) + { + assert(attributeIndex < vertexAttributeNames.size()); + return vertexAttributeNames[attributeIndex]; + } + + ShaderInputVec2 VertexShader::defineInputVec2(const std::string &name) + { + i32 attributeIndex = defineInputVariable(name, "vec2"); + return ShaderInputVec2(this, attributeIndex); + } + + void VertexShader::defineMain(VertexShaderMainFunc mainFunc) + { + if(mainFuncDefined) + throw VertexShaderFunctionAlreadyDefined("main"); + + writeBody("void main() {\n"); + ShaderVec4 glPosition = mainFunc(); + mainFuncDefined = true; + writeBody("gl_Position = "); + writeBody(glPosition.getOutput()); + writeBody(";\n}\n\n"); + } + + i32 VertexShader::defineInputVariable(const string &variableName, const char *typeName) + { + if(!isShaderVariableNameValid(variableName.c_str())) + throw VertexShaderInvalidAttributeName(variableName); + + if(locationCounter + 1 > maxVertexAttribs) + throw VertexShaderTooManyAttributes(maxVertexAttribs); + + if(vertexAttributes.find(variableName) != vertexAttributes.end()) + throw VertexShaderAttributeAlreadyDefined(variableName); + + i32 attributeIndex = locationCounter; + vertexAttributes[variableName] = locationCounter; + vertexAttributeNames.push_back(variableName); + + writeHeader("layout(location = "); + writeHeader(to_string(locationCounter)); + ++locationCounter; + writeHeader(") in "); + writeHeader(typeName); + writeHeader(" "); + writeHeader(variableName); + writeHeader(";\n"); + return attributeIndex; + } + + string VertexShader::build() + { + std::string result; + result.reserve(header.size() + 2 + body.size()); + result += header; + result += "\n"; + result += body; + return result; + } + + void VertexShader::writeHeader(const string &code) + { + header += code; + } + + void VertexShader::writeBody(const string &code) + { + body += code; + } +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..fe48ddf --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,88 @@ +#include <cstdio> +#include <GL/glew.h> +#include <GLFW/glfw3.h> +#include <glm/glm.hpp> +#include "../include/RenderBackend/OpenGL/VertexShader.hpp" +#include "../include/RenderBackend/OpenGL/PixelShader.hpp" +#include "../include/RenderBackend/OpenGL/DeviceMemory.hpp" + +using namespace amalgine; +using namespace std; + +int main() +{ + if(!glfwInit()) + { + fprintf(stderr, "Failed to initialize GLFW\n"); + return -1; + } + + glfwWindowHint(GLFW_SAMPLES, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); + + GLFWwindow *window = glfwCreateWindow(1920, 1080, "Amalgine", nullptr, nullptr); + if(!window) + { + fprintf(stderr, "Failed to open GLFW window\n"); + glfwTerminate(); + return -1; + } + + glfwMakeContextCurrent(window); + glewExperimental = true; + if(glewInit() != GLEW_OK) + { + fprintf(stderr, "Failed to initialize GLEW\n"); + glfwTerminate(); + return -1; + } + + glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); + + + f32 verticesRaw[] = + { + 0.0f, 0.5f, + 0.5f, -0.5f, + -0.5f, -0.5f + }; + DataView<f32> vertices(verticesRaw, 6); + DeviceMemory triangle; + triangle.copyStatic(vertices); + + VertexShader vertexShader; + ShaderInputVec2 inputPosition = vertexShader.defineInputVec2("position"); + + vertexShader.defineMain([&inputPosition]() + { + return ShaderVec4(inputPosition, 0.0f, 1.0f); + }); + + PixelShader pixelShader; + ShaderOutputVec4 outColor = pixelShader.defineOutputVec4("outColor"); + + pixelShader.defineMain([&outColor]() + { + outColor = ShaderVec4(1.0f, 1.0f, 1.0f, 1.0f); + }); + + string vertexShaderSource = vertexShader.build(); + printf("Vertex shader source:\n%s", vertexShaderSource.c_str()); + string pixelShaderSource = pixelShader.build(); + printf("Pixel shader source:\n%s", pixelShaderSource.c_str()); + + while(!glfwWindowShouldClose(window)) + { + if(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS) + glfwSetWindowShouldClose(window, GL_TRUE); + + glfwSwapBuffers(window); + glfwPollEvents(); + } + + return 0; +} |