├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .gitmodules
├── .idea
├── .gitignore
├── .name
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── deployment.xml
├── fileTemplates
│ ├── includes
│ │ └── C File Header.h
│ └── internal
│ │ └── C Header File.h
├── misc.xml
├── modules.xml
├── real-engine.iml
└── vcs.xml
├── .vscode
└── settings.json
├── CMakeLists.txt
├── CMakePresets.json
├── CMakeSettings.json
├── LICENSE
├── README.md
├── building.md
├── cmake
├── assets.cmake
├── build.cmake
├── compilerOptions.cmake
├── coverage.cmake
├── rdoc.cmake
├── sanitizers.cmake
└── shaders.cmake
├── engine
├── CMakeLists.txt
├── include
│ └── real
│ │ ├── api
│ │ └── gl
│ │ │ ├── gl_array_vertex.hpp
│ │ │ ├── gl_buffer_index.hpp
│ │ │ ├── gl_buffer_vertex.hpp
│ │ │ ├── gl_conversions.hpp
│ │ │ ├── gl_headers.hpp
│ │ │ ├── gl_renderer_api.hpp
│ │ │ ├── gl_rendering_context.hpp
│ │ │ ├── gl_shader.hpp
│ │ │ └── gl_texture.hpp
│ │ ├── application.hpp
│ │ ├── assert.hpp
│ │ ├── core.hpp
│ │ ├── event.hpp
│ │ ├── event
│ │ ├── base_event.hpp
│ │ ├── key_event.hpp
│ │ ├── mouse_event.hpp
│ │ └── window_event.hpp
│ │ ├── input.hpp
│ │ ├── input
│ │ └── base_input.hpp
│ │ ├── keycode.hpp
│ │ ├── layer.hpp
│ │ ├── layer
│ │ ├── base_layer.hpp
│ │ └── imgui_layer.hpp
│ │ ├── layer_stack.hpp
│ │ ├── logger.hpp
│ │ ├── pch.hpp
│ │ ├── platform
│ │ └── windows
│ │ │ ├── windows_input.hpp
│ │ │ ├── windows_time.hpp
│ │ │ └── windows_window.hpp
│ │ ├── real.hpp
│ │ ├── renderer.hpp
│ │ ├── renderer
│ │ ├── array_vertex.hpp
│ │ ├── base_renderer.hpp
│ │ ├── base_rendering_context.hpp
│ │ ├── base_shader.hpp
│ │ ├── base_texture.hpp
│ │ ├── buffer_index.hpp
│ │ ├── buffer_layout.hpp
│ │ ├── buffer_vertex.hpp
│ │ ├── camera.hpp
│ │ ├── common.hpp
│ │ ├── light.hpp
│ │ ├── material.hpp
│ │ ├── render_command.hpp
│ │ ├── renderer_api.hpp
│ │ └── shaders
│ │ │ ├── base.glsl
│ │ │ ├── material.glsl
│ │ │ └── tex.glsl
│ │ ├── time.hpp
│ │ ├── time
│ │ └── timestep.hpp
│ │ ├── transform.hpp
│ │ ├── util
│ │ └── singleton.hpp
│ │ ├── window.hpp
│ │ └── window
│ │ └── base_window.hpp
└── src
│ ├── api
│ └── gl
│ │ ├── gl_array_vertex.cpp
│ │ ├── gl_buffer_index.cpp
│ │ ├── gl_buffer_vertex.cpp
│ │ ├── gl_renderer_api.cpp
│ │ ├── gl_rendering_context.cpp
│ │ ├── gl_shader.cpp
│ │ ├── gl_texture.cpp
│ │ └── imgui_build.cpp
│ ├── application.cpp
│ ├── base_input.cpp
│ ├── base_layer.cpp
│ ├── base_window.cpp
│ ├── layer
│ └── imgui_layer.cpp
│ ├── layer_stack.cpp
│ ├── logger.cpp
│ ├── platform
│ └── windows
│ │ ├── windows_input.cpp
│ │ ├── windows_time.cpp
│ │ └── windows_window.cpp
│ ├── renderer
│ ├── array_vertex.cpp
│ ├── base_renderer.cpp
│ ├── base_rendering_context.cpp
│ ├── base_shader.cpp
│ ├── base_texture.cpp
│ ├── buffer_index.cpp
│ ├── buffer_layout.cpp
│ ├── buffer_vertex.cpp
│ ├── camera.cpp
│ └── renderer_api.cpp
│ └── stb.cpp
├── examples
├── CMakeLists.txt
└── cube
│ └── main.cpp
├── plan.md
├── rdoc
└── settings.cap
└── vendor
├── CMakeLists.txt
└── stb
├── CMakeLists.txt
└── include
└── stb
└── image.h
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 | run-name: building main library
3 | on: [push]
4 | jobs:
5 | build:
6 | runs-on: windows-latest
7 | steps:
8 | - name: Checkout
9 | uses: actions/checkout@v3
10 | with:
11 | submodules: recursive
12 | - name: Build with CMake
13 | uses: lukka/run-cmake@v10.6
14 | with:
15 | configurePreset: base-win
16 | buildPreset: base-win
17 |
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### macOS template
3 | # General
4 | .DS_Store
5 | .AppleDouble
6 | .LSOverride
7 |
8 | # Icon must end with two \r
9 | Icon
10 |
11 | # Thumbnails
12 | ._*
13 |
14 | # Files that might appear in the root of a volume
15 | .DocumentRevisions-V100
16 | .fseventsd
17 | .Spotlight-V100
18 | .TemporaryItems
19 | .Trashes
20 | .VolumeIcon.icns
21 | .com.apple.timemachine.donotpresent
22 |
23 | # Directories potentially created on remote AFP share
24 | .AppleDB
25 | .AppleDesktop
26 | Network Trash Folder
27 | Temporary Items
28 | .apdisk
29 |
30 | ### C++ template
31 | # Prerequisites
32 | *.d
33 |
34 | # Compiled Object files
35 | *.slo
36 | *.lo
37 | *.o
38 | *.obj
39 |
40 | # Precompiled Headers
41 | *.gch
42 | *.pch
43 |
44 | # Compiled Dynamic libraries
45 | *.so
46 | *.dylib
47 | *.dll
48 |
49 | # Fortran module files
50 | *.mod
51 | *.smod
52 |
53 | # Compiled Static libraries
54 | *.lai
55 | *.la
56 | *.a
57 | *.lib
58 |
59 | # Executables
60 | *.exe
61 | *.out
62 | *.app
63 |
64 | ### C template
65 | # Prerequisites
66 | *.d
67 |
68 | # Object files
69 | *.o
70 | *.ko
71 | *.obj
72 | *.elf
73 |
74 | # Linker output
75 | *.ilk
76 | *.map
77 | *.exp
78 |
79 | # Precompiled Headers
80 | *.gch
81 | *.pch
82 |
83 | # Libraries
84 | *.lib
85 | *.a
86 | *.la
87 | *.lo
88 |
89 | # Shared objects (inc. Windows DLLs)
90 | *.dll
91 | *.so
92 | *.so.*
93 | *.dylib
94 |
95 | # Executables
96 | *.exe
97 | *.out
98 | *.app
99 | *.i*86
100 | *.x86_64
101 | *.hex
102 |
103 | # Debug files
104 | *.dSYM/
105 | *.su
106 | *.idb
107 | *.pdb
108 |
109 | # Kernel Module Compile Results
110 | *.mod*
111 | *.cmd
112 | .tmp_versions/
113 | modules.order
114 | Module.symvers
115 | Mkfile.old
116 | dkms.conf
117 |
118 | ### Windows template
119 | # Windows thumbnail cache files
120 | Thumbs.db
121 | Thumbs.db:encryptable
122 | ehthumbs.db
123 | ehthumbs_vista.db
124 |
125 | # Dump file
126 | *.stackdump
127 |
128 | # Folder config file
129 | [Dd]esktop.ini
130 |
131 | # Recycle Bin used on file shares
132 | $RECYCLE.BIN/
133 |
134 | # Windows Installer files
135 | *.cab
136 | *.msi
137 | *.msix
138 | *.msm
139 | *.msp
140 |
141 | # Windows shortcuts
142 | *.lnk
143 |
144 | ### JetBrains template
145 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
146 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
147 |
148 | # User-specific stuff
149 | .idea/**/workspace.xml
150 | .idea/**/tasks.xml
151 | .idea/**/usage.statistics.xml
152 | .idea/**/dictionaries
153 | .idea/**/shelf
154 |
155 | # Generated files
156 | .idea/**/contentModel.xml
157 |
158 | # Sensitive or high-churn files
159 | .idea/**/dataSources/
160 | .idea/**/dataSources.ids
161 | .idea/**/dataSources.local.xml
162 | .idea/**/sqlDataSources.xml
163 | .idea/**/dynamic.xml
164 | .idea/**/uiDesigner.xml
165 | .idea/**/dbnavigator.xml
166 |
167 | # Gradle
168 | .idea/**/gradle.xml
169 | .idea/**/libraries
170 |
171 | # Gradle and Maven with auto-import
172 | # When using Gradle or Maven with auto-import, you should exclude module files,
173 | # since they will be recreated, and may cause churn. Uncomment if using
174 | # auto-import.
175 | # .idea/artifacts
176 | # .idea/compiler.xml
177 | # .idea/jarRepositories.xml
178 | # .idea/modules.xml
179 | # .idea/*.iml
180 | # .idea/modules
181 | # *.iml
182 | # *.ipr
183 |
184 | # CMake
185 | cmake-build-*/
186 | build/
187 |
188 | # Mongo Explorer plugin
189 | .idea/**/mongoSettings.xml
190 |
191 | # File-based project format
192 | *.iws
193 |
194 | # IntelliJ
195 | out/
196 |
197 | # mpeltonen/sbt-idea plugin
198 | .idea_modules/
199 |
200 | # JIRA plugin
201 | atlassian-ide-plugin.xml
202 |
203 | # Cursive Clojure plugin
204 | .idea/replstate.xml
205 |
206 | # Crashlytics plugin (for Android Studio and IntelliJ)
207 | com_crashlytics_export_strings.xml
208 | crashlytics.properties
209 | crashlytics-build.properties
210 | fabric.properties
211 |
212 | # Editor-based Rest Client
213 | .idea/httpRequests
214 |
215 | # Android studio 3.1+ serialized cache file
216 | .idea/caches/build_file_checksums.ser
217 |
218 | ### Python template
219 | # Byte-compiled / optimized / DLL files
220 | __pycache__/
221 | *.py[cod]
222 | *$py.class
223 |
224 | # C extensions
225 | *.so
226 |
227 | # Distribution / packaging
228 | .Python
229 | build/
230 | develop-eggs/
231 | dist/
232 | downloads/
233 | eggs/
234 | .eggs/
235 | lib/
236 | lib64/
237 | parts/
238 | sdist/
239 | var/
240 | wheels/
241 | share/python-wheels/
242 | *.egg-info/
243 | .installed.cfg
244 | *.egg
245 | MANIFEST
246 |
247 | # PyInstaller
248 | # Usually these files are written by a python script from a template
249 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
250 | *.manifest
251 | *.spec
252 |
253 | # Installer logs
254 | pip-log.txt
255 | pip-delete-this-directory.txt
256 |
257 | # Unit test / coverage reports
258 | htmlcov/
259 | .tox/
260 | .nox/
261 | .coverage
262 | .coverage.*
263 | .cache
264 | nosetests.xml
265 | coverage.xml
266 | *.cover
267 | *.py,cover
268 | .hypothesis/
269 | .pytest_cache/
270 | cover/
271 |
272 | # Translations
273 | *.mo
274 | *.pot
275 |
276 | # Django stuff:
277 | *.log
278 | local_settings.py
279 | db.sqlite3
280 | db.sqlite3-journal
281 |
282 | # Flask stuff:
283 | instance/
284 | .webassets-cache
285 |
286 | # Scrapy stuff:
287 | .scrapy
288 |
289 | # Sphinx documentation
290 | docs/_build/
291 |
292 | # PyBuilder
293 | .pybuilder/
294 | target/
295 |
296 | # Jupyter Notebook
297 | .ipynb_checkpoints
298 |
299 | # IPython
300 | profile_default/
301 | ipython_config.py
302 |
303 | # pyenv
304 | # For a library or package, you might want to ignore these files since the code is
305 | # intended to run in multiple environments; otherwise, check them in:
306 | # .python-version
307 |
308 | # pipenv
309 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
310 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
311 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
312 | # install all needed dependencies.
313 | #Pipfile.lock
314 |
315 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
316 | __pypackages__/
317 |
318 | # Celery stuff
319 | celerybeat-schedule
320 | celerybeat.pid
321 |
322 | # SageMath parsed files
323 | *.sage.py
324 |
325 | # Environments
326 | .env
327 | .venv
328 | env/
329 | venv/
330 | ENV/
331 | env.bak/
332 | venv.bak/
333 |
334 | # Spyder project settings
335 | .spyderproject
336 | .spyproject
337 |
338 | # Rope project settings
339 | .ropeproject
340 |
341 | # mkdocs documentation
342 | /site
343 |
344 | # mypy
345 | .mypy_cache/
346 | .dmypy.json
347 | dmypy.json
348 |
349 | # Pyre type checker
350 | .pyre/
351 |
352 | # pytype static type analyzer
353 | .pytype/
354 |
355 | # Cython debug symbols
356 | cython_debug/
357 |
358 | ### VisualStudioCode template
359 | .vscode/*
360 | !.vscode/settings.json
361 | !.vscode/tasks.json
362 | !.vscode/launch.json
363 | !.vscode/extensions.json
364 | *.code-workspace
365 |
366 | # Local History for Visual Studio Code
367 | .history/
368 |
369 | ### CMake template
370 | CMakeLists.txt.user
371 | CMakeCache.txt
372 | CMakeFiles
373 | CMakeScripts
374 | Testing
375 | Makefile
376 | cmake_install.cmake
377 | install_manifest.txt
378 | compile_commands.json
379 | CTestTestfile.cmake
380 | _deps
381 |
382 | /.vs/
383 | .vscode/settings.json
384 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "vendor/spdlog"]
2 | path = vendor/spdlog
3 | url = https://github.com/gabime/spdlog.git
4 | [submodule "vendor/glfw"]
5 | path = vendor/glfw
6 | url = https://github.com/glfw/glfw.git
7 | [submodule "vendor/glad"]
8 | path = vendor/glad
9 | url = https://github.com/Dav1dde/glad.git
10 | [submodule "vendor/imgui"]
11 | path = vendor/imgui
12 | url = https://github.com/udv-code/version-imgui.git
13 | [submodule "vendor/glm"]
14 | path = vendor/glm
15 | url = https://github.com/g-truc/glm.git
16 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | real-engine
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/deployment.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/includes/C File Header.h:
--------------------------------------------------------------------------------
1 | #if ($HEADER_COMMENTS)
2 | // Copyright (c) $YEAR ${USER_NAME}#if (!$USER_NAME.endsWith(".")).#end All rights reserved.
3 | #if ($ORGANIZATION_NAME && $ORGANIZATION_NAME != "")
4 | // Copyright (c) $YEAR ${ORGANIZATION_NAME}#if (!$ORGANIZATION_NAME.endsWith(".")).#end All rights reserved.
5 | #end
6 | #end
7 |
8 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/C Header File.h:
--------------------------------------------------------------------------------
1 | #parse("C File Header.h")
2 | #[[#ifndef]]# ${INCLUDE_GUARD}
3 | #[[#define]]# ${INCLUDE_GUARD}
4 |
5 | #[[#include]]# "real/core.hpp"
6 |
7 | namespace real {
8 |
9 | }
10 |
11 | #[[#endif]]# //${INCLUDE_GUARD}
12 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/real-engine.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
3 |
4 | // Cmake
5 | "cmake.buildDirectory": "${workspaceFolder}/build/laptop/vscode/",
6 | "cmake.generator": "MinGW Makefiles",
7 |
8 | "cmake.configureSettings": {
9 | "OPTION_REAL_BUILD_EXAMPLES": "ON"
10 | },
11 | }
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | ### CMake setup
2 |
3 | # Version
4 | cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
5 | # Policies
6 | cmake_policy(SET CMP0077 NEW) # option honors normal variables
7 |
8 | ### Meta info
9 |
10 | # Names
11 | set(META_REAL_PROJECT_NAME "real")
12 | string(TOUPPER "real" META_REAL_PROJECT_NAME_PREFIX)
13 | string(TOUPPER ${META_REAL_PROJECT_NAME} META_REAL_PROJECT_NAME_UPPER)
14 | set(META_REAL_PROJECT_FULL_NAME "${META_REAL_PROJECT_NAME}-engine")
15 | set(META_REAL_PROJECT_DESCRIPTION "The Real 3D Rendering Engine")
16 | set(META_REAL_AUTHOR "udvsharp")
17 | set(META_REAL_AUTHOR_DOMAIN "https://github.com/${META_REAL_AUTHOR}/${META_REAL_PROJECT_NAME}")
18 |
19 | # Version
20 | set(META_REAL_VERSION_MAJOR "1")
21 | set(META_REAL_VERSION_MINOR "0")
22 | set(META_REAL_VERSION_PATCH "0")
23 | set(META_REAL_VERSION_TWEAK "0")
24 | set(META_REAL_VERSION "${META_REAL_VERSION_MAJOR}.${META_REAL_VERSION_MINOR}.${META_REAL_VERSION_PATCH}.${META_REAL_VERSION_TWEAK}")
25 | set(META_REAL_NAME_VERSION "${META_REAL_PROJECT_FULL_NAME} v${META_REAL_VERSION_MAJOR}.${META_REAL_VERSION_MINOR}.${META_REAL_VERSION_PATCH}.${META_REAL_VERSION_TWEAK}")
26 |
27 | # Targets
28 | set(REAL_LIBRARY_TARGET_NAME "${META_REAL_PROJECT_NAME}")
29 |
30 | ### Project config options
31 |
32 | option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
33 | # Examples
34 | option(OPTION_REAL_BUILD_EXAMPLES "Build examples" OFF)
35 | # Detail examples
36 | option(OPTION_REAL_EXAMPLES_CUBE "Build rotating cube example" ON)
37 | # Analysis tools
38 | option(OPTION_REAL_ENABLE_COVERAGE "Enable code coverage" OFF)
39 | option(OPTION_REAL_ENABLE_SANITIZE "Enable sanitizers" OFF)
40 | # Tools
41 | option(OPTION_REAL_DEBUG_CMAKE "Enable CMake debugging information" OFF)
42 |
43 | # Configs
44 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
45 | set_property(GLOBAL PROPERTY USE_FOLDERS ON)
46 |
47 | ### Project
48 | project(${META_REAL_PROJECT_FULL_NAME}
49 | VERSION ${META_REAL_VERSION}
50 | DESCRIPTION ${META_REAL_PROJECT_DESCRIPTION}
51 | HOMEPAGE_URL ${META_REAL_AUTHOR_DOMAIN}
52 | LANGUAGES C CXX ASM)
53 |
54 | ### Language Options
55 | # C
56 | set(C_STANDARD_DEFAULT 11)
57 | set(CMAKE_C_STANDARD ${C_STANDARD_DEFAULT})
58 | set(CMAKE_C_STANDARD_REQUIRED ON)
59 | set(CMAKE_C_EXTENSIONS OFF)
60 | # C++
61 | set(CXX_STANDARD_DEFAULT 20)
62 | set(CMAKE_CXX_STANDARD ${CXX_STANDARD_DEFAULT})
63 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
64 | set(CMAKE_CXX_EXTENSIONS OFF)
65 | # TODO: ASM
66 |
67 | ### Modules
68 | # Standard
69 | # include(WriteCompilerDetectionHeader) # Consider using https://nemequ.github.io/hedley/ instead
70 | include(GenerateExportHeader)
71 |
72 | # Own
73 | include(build)
74 |
75 | include(rdoc)
76 | include(assets)
77 | include(shaders)
78 |
79 | # TODO: get rid of dependencies
80 | ### Submodules
81 | add_subdirectory(vendor)
82 |
83 | ### Packages
84 | find_package(OpenGL REQUIRED)
85 |
86 | ### Code analysis
87 | # Coverage
88 | if (OPTION_REAL_ENABLE_COVERAGE)
89 | include(coverage)
90 | append_coverage_compiler_flags()
91 | endif ()
92 |
93 | # Sanitizers
94 | if (OPTION_REAL_ENABLE_SANITIZE)
95 | include(sanitizers)
96 | # TODO: append_sanitizer_compiler_flags()
97 | endif ()
98 |
99 | ### Engine
100 | add_subdirectory(engine)
101 |
102 | target_link_libraries(
103 | ${REAL_LIBRARY_TARGET_NAME}
104 | PUBLIC
105 | imgui
106 | glfw
107 | glad
108 | spdlog::spdlog
109 | OpenGL::GL
110 | glm::glm
111 |
112 | stb
113 | )
114 |
115 | ### Examples
116 | if (OPTION_REAL_BUILD_EXAMPLES)
117 | add_subdirectory(examples)
118 | endif ()
--------------------------------------------------------------------------------
/CMakePresets.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 6,
3 | "cmakeMinimumRequired": {
4 | "major": 3,
5 | "minor": 23,
6 | "patch": 0
7 | },
8 | "configurePresets": [
9 | {
10 | "name": "base",
11 | "displayName": "Default Config",
12 | "description": "Default build preset",
13 | "binaryDir": "${sourceDir}/build/base",
14 | "cacheVariables": {
15 | "BUILD_SHARED_LIBS": false,
16 | "OPTION_REAL_BUILD_EXAMPLES": true,
17 | "OPTION_REAL_ENABLE_COVERAGE": true,
18 | "OPTION_REAL_ENABLE_SANITIZE": false,
19 | "OPTION_REAL_DEBUG_CMAKE": false
20 | },
21 | "environment": {
22 | },
23 | "vendor": {
24 | }
25 | },
26 | {
27 | "name": "base-win",
28 | "inherits": [
29 | "base"
30 | ],
31 | "description": "Base windows build preset",
32 | "binaryDir": "${sourceDir}/build/base",
33 | "generator": "Visual Studio 17 2022"
34 | }
35 | ],
36 | "buildPresets": [
37 | {
38 | "name": "default",
39 | "configurePreset": "base-win"
40 | },
41 | {
42 | "name": "base-win",
43 | "configurePreset": "base-win"
44 | }
45 | ],
46 | "testPresets": [
47 | ],
48 | "packagePresets": [
49 | ],
50 | "workflowPresets": [
51 | {
52 | "name": "default",
53 | "steps": [
54 | {
55 | "type": "configure",
56 | "name": "base-win"
57 | },
58 | {
59 | "type": "build",
60 | "name": "base-win"
61 | }
62 | ]
63 | }
64 | ]
65 | }
--------------------------------------------------------------------------------
/CMakeSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "configurations": [
3 | {
4 | "name": "x64-Debug",
5 | "generator": "Visual Studio 16 2019",
6 | "configurationType": "Debug",
7 | "inheritEnvironments": [ "msvc_x64_x64" ],
8 | "buildRoot": "${projectDir}\\build\\vs\\${name}",
9 | "installRoot": "${projectDir}\\out\\install\\${name}",
10 | "cmakeCommandArgs": "-DOPTION_REAL_BUILD_EXAMPLES=ON",
11 | "buildCommandArgs": "",
12 | "ctestCommandArgs": "",
13 | "variables": [
14 | {
15 | "name": "CMAKE_BUILD_TYPE",
16 | "value": "Debug",
17 | "type": "STRING"
18 | }
19 | ],
20 | "intelliSenseMode": "android-clang-arm64"
21 | },
22 | {
23 | "name": "x64-Release",
24 | "generator": "Ninja",
25 | "configurationType": "Release",
26 | "buildRoot": "${projectDir}\\build\\vs\\${name}",
27 | "installRoot": "${projectDir}\\out\\install\\${name}",
28 | "cmakeCommandArgs": "",
29 | "buildCommandArgs": "",
30 | "ctestCommandArgs": "",
31 | "inheritEnvironments": [ "msvc_x64_x64" ],
32 | "variables": []
33 | }
34 | ]
35 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Dmitry udv-code Vasyliev
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # The Real Engine
2 | [//]: # (TODO: add logo)
3 |
4 | **The Real Engine** is a cross-platform 3D rendering engine.
5 | **Currently Real Engine is not fully-implemented**.
6 |
7 | ## Getting started
8 | You can clone the repository to a local destination using git:
9 |
10 | - `git clone --recursive https://github.com/udv-code/real`
11 |
12 | You may do a `--recursive` clone to fetch all of the submodules.
13 |
14 | ## Instructions
15 | You can find build instructions [here](building.md)
16 |
17 | ## The Plan
18 | The plan is to create a 3D cross-platform rendering engine
19 | and learn "the best practices" of game engine development.
20 |
21 | That's the matter for development to be very slow and precise.
22 |
23 | You can view plans, issues, TODOs and more [here](plan.md).
24 |
25 | ### Mentions
26 | Inspired by [TheCherno's](https://github.com/TheCherno) [Hazel](https://github.com/TheCherno/Hazel) videos.
27 |
--------------------------------------------------------------------------------
/building.md:
--------------------------------------------------------------------------------
1 | ### Requirements
2 | - CMake 3.17+
3 | ### Instructions
4 | 1. Clone project from github: `git clone https://github.com/udv-code/real --recursive`
5 | 2. Create build directory: `mkdir build && cd build`.
6 | 3. Configure CMake project: `cmake ..` or with specific generator(for example, VS 2019) : `cmake -G "Visual Studio 16 2019" ..`
7 | - If you want to build sandbox project, you need to add `-DOPTION_REAL_BUILD_EXAMPLES=ON` to the end of your `cmake` command.
8 |
9 | Then you need to build generated project.
10 |
11 | ### OR
12 | Use CLion!
13 |
14 | ### MSVC
15 | Generate project files with `"Visual Studio 16 2019"` generator, open generated `.sln` file in Visual Studio and run build.
16 |
17 | ### Other
18 | Other build types are not tested for now so you can learn how to build CMake projects by yourself(example: [here](https://cliutils.gitlab.io/modern-cmake/chapters/intro/running.html)).
19 |
--------------------------------------------------------------------------------
/cmake/assets.cmake:
--------------------------------------------------------------------------------
1 | macro (add_assets_dir DIRNAME)
2 | file(COPY "${DIRNAME}" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
3 | endmacro ()
--------------------------------------------------------------------------------
/cmake/build.cmake:
--------------------------------------------------------------------------------
1 | function(build_log MSG SEVERITY)
2 | # Severity: ALWAYS, ...
3 | if (OPTION_REAL_DEBUG_CMAKE OR SEVERITY STREQUAL "ALWAYS")
4 | message(STATUS "${MSG}")
5 | endif ()
6 | endfunction()
7 |
8 | ### Multi-config generator detection
9 | get_property(REAL_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
10 | if (REAL_GENERATOR_IS_MULTI_CONFIG)
11 | message(STATUS "Current CMake generator is multi-config generator(${CMAKE_GENERATOR})")
12 | message(STATUS "CMAKE_BUILD_TYPE variable is ignored!")
13 | else ()
14 | message(STATUS "Current CMake generator is single-config generator(${CMAKE_GENERATOR})")
15 | endif ()
16 |
17 | ### Updating Build types
18 | message(STATUS "Updating Build types...")
19 | set(CUSTOM_BUILD_TYPES "Debug;Release;RelWithDebInfo")
20 | if (REAL_GENERATOR_IS_MULTI_CONFIG)
21 | foreach (BUILD_TYPE IN LISTS CUSTOM_BUILD_TYPES)
22 | if (NOT "${BUILD_TYPE}" IN_LIST CMAKE_CONFIGURATION_TYPES)
23 | set(CMAKE_CONFIGURATION_TYPES ${CUSTOM_BUILD_TYPES} CACHE STRING "" FORCE)
24 | endif ()
25 | endforeach ()
26 | else ()
27 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
28 | STRINGS "${CUSTOM_BUILD_TYPES}")
29 |
30 | if (NOT CMAKE_BUILD_TYPE)
31 | set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
32 | elseif (NOT CMAKE_BUILD_TYPE IN_LIST CUSTOM_BUILD_TYPES)
33 | message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE} (Supported: ${CUSTOM_BUILD_TYPES})")
34 | endif ()
35 | endif ()
36 |
37 | ### Build Directories
38 | message(STATUS "Updating build directories...")
39 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
40 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/int")
41 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
42 |
43 | if (REAL_GENERATOR_IS_MULTI_CONFIG)
44 | foreach (OUTPUT_CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES)
45 | string(TOUPPER "${OUTPUT_CONFIG}" OUTPUT_CONFIG_UPPER)
46 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUT_CONFIG_UPPER} "${CMAKE_BINARY_DIR}/lib")
47 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUT_CONFIG_UPPER} "${CMAKE_BINARY_DIR}/int")
48 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUT_CONFIG_UPPER} "${CMAKE_BINARY_DIR}/bin")
49 | endforeach ()
50 | endif ()
51 |
52 | include(compilerOptions)
53 |
54 | foreach (BUILD_TYPE IN LISTS CUSTOM_BUILD_TYPES)
55 | string(TOUPPER "${BUILD_TYPE}" BUILD_TYPE_UPPERCASE)
56 | # set(CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE_UPPERCASE} ${DEFAULT_LINKER_OPTIONS})
57 | # set(CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE_UPPERCASE} ${DEFAULT_LINKER_OPTIONS})
58 | # set(CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE_UPPERCASE} ${DEFAULT_LINKER_OPTIONS})
59 | endforeach ()
--------------------------------------------------------------------------------
/cmake/compilerOptions.cmake:
--------------------------------------------------------------------------------
1 | ### Architecture setup
2 |
3 | # Determine architecture (32/64 bit)
4 | set(X64 OFF)
5 | if (CMAKE_SIZEOF_VOID_P EQUAL 8)
6 | set(X64 ON)
7 | endif ()
8 |
9 | set(DEFAULT_COMPILE_DEFINITIONS)
10 | set(DEFAULT_COMPILE_OPTIONS)
11 | set(DEFAULT_LINKER_OPTIONS)
12 |
13 | ### MSVC TODO: modify options
14 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
15 | set(DEFAULT_COMPILE_DEFINITIONS ${DEFAULT_COMPILE_DEFINITIONS}
16 | _SCL_SECURE_NO_WARNINGS # Calling any one of the potentially unsafe methods in the Standard C++ Library
17 | _CRT_SECURE_NO_WARNINGS # Calling any one of the potentially unsafe methods in the CRT Library
18 | )
19 |
20 | set(DEFAULT_COMPILE_OPTIONS ${DEFAULT_COMPILE_OPTIONS}
21 | PRIVATE
22 | /MP # -> build with multiple processes
23 | /W4 # -> warning level 4
24 | # /WX # -> treat warnings as errors
25 |
26 | /wd4251 # -> disable warning: 'identifier': class 'type' needs to have dll-interface to be used by clients of class 'type2'
27 | /wd4592 # -> disable warning: 'identifier': symbol will be dynamically initialized (implementation limitation)
28 | # /wd4201 # -> disable warning: nonstandard extension used: nameless struct/union (caused by GLM)
29 | # /wd4127 # -> disable warning: conditional expression is constant (caused by Qt)
30 |
31 | PUBLIC
32 | $<$>:
33 | /Zi
34 | >
35 |
36 | $<$:
37 | /Gw # -> whole program global optimization
38 | /GS- # -> buffer security check: no
39 | /GL # -> whole program optimization: enable link-time code generation (disables Zi)
40 | /GF # -> enable string pooling
41 | >
42 | )
43 |
44 | set(DEFAULT_LINKER_OPTIONS ${DEFAULT_LINKER_OPTIONS}
45 | PRIVATE
46 |
47 | PUBLIC
48 | $<$>:
49 | /DEBUG
50 | >
51 |
52 | /INCREMENTAL
53 | )
54 | endif ()
55 |
56 | ### GCC and Clang compiler options TODO: modify options
57 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
58 | set(DEFAULT_COMPILE_DEFINITIONS ${DEFAULT_COMPILE_DEFINITIONS})
59 |
60 | set(DEFAULT_COMPILE_OPTIONS ${DEFAULT_COMPILE_OPTIONS}
61 | PRIVATE
62 | -Wall
63 | -Wextra
64 | -Wunused
65 |
66 | -Wreorder
67 | -Wignored-qualifiers
68 | -Wmissing-braces
69 | -Wreturn-type
70 | -Wswitch
71 | -Wswitch-default
72 | -Wuninitialized
73 | -Wmissing-field-initializers
74 |
75 | $<$:
76 | -Wmaybe-uninitialized
77 |
78 | $<$,4.8>:
79 | -Wpedantic
80 |
81 | -Wreturn-local-addr
82 | >
83 | >
84 |
85 | $<$:
86 | -Wpedantic
87 |
88 | # -Wreturn-stack-address # gives false positives
89 | >
90 |
91 | $<$:
92 | -fprofile-arcs
93 | -ftest-coverage
94 | >
95 |
96 | PUBLIC
97 |
98 | $<$:
99 | -pthread
100 | >
101 |
102 | # Required for CMake < 3.1; should be removed if minimum required CMake version is raised.
103 | $<$:
104 | -std=c++11
105 | >
106 | )
107 |
108 | set(DEFAULT_LINKER_OPTIONS ${DEFAULT_LINKER_OPTIONS})
109 | endif ()
110 |
111 | # Use pthreads on mingw and linux
112 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
113 | set(DEFAULT_LINKER_OPTIONS
114 | ${DEFAULT_LINKER_OPTIONS}
115 | -pthread
116 | )
117 |
118 | if (${OPTION_REAL_ENABLE_COVERAGE})
119 | set(DEFAULT_LINKER_OPTIONS
120 | ${DEFAULT_LINKER_OPTIONS}
121 | -fprofile-arcs
122 | -ftest-coverage
123 | )
124 | endif ()
125 | endif ()
--------------------------------------------------------------------------------
/cmake/coverage.cmake:
--------------------------------------------------------------------------------
1 | find_program(GCOV_PATH gcov)
2 | # find_program(LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl)
3 | # find_program(GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
4 | # find_program(CPPFILT_PATH NAMES c++filt)
5 |
6 | include(CMakeParseArguments)
7 |
8 | if (NOT GCOV_PATH)
9 | message(FATAL_ERROR "gcov not found! Aborting...")
10 | else ()
11 | message(STATUS "Found gcov: ${GCOV_PATH}")
12 | endif ()
13 |
14 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
15 | if ("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
16 | message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
17 | endif ()
18 | elseif (NOT CMAKE_COMPILER_IS_GNUCXX)
19 | # Do something
20 | message(STATUS "Compiler is not GNUCXX")
21 | endif ()
22 |
23 | set(COVERAGE_COMPILER_FLAGS "-g -fprofile-arcs -ftest-coverage"
24 | CACHE INTERNAL "")
25 |
26 | set(CMAKE_CXX_FLAGS_COVERAGE
27 | ${COVERAGE_COMPILER_FLAGS}
28 | CACHE STRING "Flags used by the C++ compiler during coverage builds."
29 | FORCE)
30 | set(CMAKE_C_FLAGS_COVERAGE
31 | ${COVERAGE_COMPILER_FLAGS}
32 | CACHE STRING "Flags used by the C compiler during coverage builds."
33 | FORCE)
34 | set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
35 | ""
36 | CACHE STRING "Flags used for linking binaries during coverage builds."
37 | FORCE)
38 | set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
39 | ""
40 | CACHE STRING "Flags used by the shared libraries linker during coverage builds."
41 | FORCE)
42 | mark_as_advanced(
43 | CMAKE_CXX_FLAGS_COVERAGE
44 | CMAKE_C_FLAGS_COVERAGE
45 | CMAKE_EXE_LINKER_FLAGS_COVERAGE
46 | CMAKE_SHARED_LINKER_FLAGS_COVERAGE
47 | )
48 |
49 | if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT REAL_GENERATOR_IS_MULTI_CONFIG)
50 | message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
51 | endif ()
52 |
53 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
54 | link_libraries(gcov)
55 | endif ()
56 |
57 | function (append_coverage_compiler_flags)
58 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_COVERAGE}" PARENT_SCOPE)
59 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_COVERAGE}" PARENT_SCOPE)
60 | message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
61 | endfunction ()
--------------------------------------------------------------------------------
/cmake/rdoc.cmake:
--------------------------------------------------------------------------------
1 | ### Functions
2 |
3 | # Generates renderdoc settings file from given template
4 | function(generate_rdoc_settings_from TEMPLATE_FILENAME TARGET_NAME RDOC_CONFIG_OUTFOLDER)
5 | message(STATUS "Generating RenderDoc Settings for ${TARGET_NAME}")
6 |
7 | ## RenderDoc
8 | set(RDOC_WORKING_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
9 | set(RDOC_TARGET_FILE "$")
10 |
11 | set(RDOC_CONFIG_OUTFILE "${RDOC_CONFIG_OUTFOLDER}/rdoc/settings.cap")
12 |
13 | configure_file("${CMAKE_SOURCE_DIR}/rdoc/settings.cap" "${RDOC_CONFIG_OUTFILE}")
14 |
15 | if (REAL_GENERATOR_IS_MULTI_CONFIG)
16 | file(
17 | GENERATE
18 | OUTPUT "${RDOC_CONFIG_OUTFILE}.$"
19 | INPUT "${RDOC_CONFIG_OUTFILE}"
20 | )
21 | else ()
22 | file(
23 | GENERATE
24 | OUTPUT "${RDOC_CONFIG_OUTFILE}"
25 | INPUT "${RDOC_CONFIG_OUTFILE}"
26 | )
27 | endif ()
28 |
29 | endfunction()
--------------------------------------------------------------------------------
/cmake/sanitizers.cmake:
--------------------------------------------------------------------------------
1 | set(WANTED_SANITIZE_THREAD ${SANITIZE_THREAD})
2 | set(WANTED_SANITIZE_UNDEFINED ${SANITIZE_UNDEFINED})
3 | set(WANTED_SANITIZE_MEMORY ${SANITIZE_MEMORY})
4 | set(WANTED_SANITIZE_ADDRESS ${SANITIZE_ADDRESS})
5 |
6 | function (check_sanitizer NAME PREFIX)
7 | if (${WANTED_SANITIZE_${NAME}})
8 | if ("${${PREFIX}_${CMAKE_C_COMPILER_ID}_FLAGS}" STREQUAL "")
9 | message(FATAL_ERROR ${NAME} " sanitizer is NOT available")
10 | else ()
11 | message(STATUS ${NAME} " sanitizer is available")
12 | endif ()
13 | endif ()
14 | endfunction ()
15 |
16 | check_sanitizer(THREAD TSan)
17 | check_sanitizer(UNDEFINED UBSan)
18 | check_sanitizer(MEMORY MSan)
19 | check_sanitizer(ADDRESS ASan)
20 |
21 | # TODO: figure out what to do with sanitizers!
22 |
--------------------------------------------------------------------------------
/cmake/shaders.cmake:
--------------------------------------------------------------------------------
1 | function (add_shaders TARGET_NAME)
2 | set(GENERATE_SHADERS_TARGET_NAME "${TARGET_NAME}-generate-shaders")
3 | set(SHADERS)
4 | set(SHADERS_OUTDIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/shaders")
5 |
6 | add_custom_command(
7 | OUTPUT "${SHADERS_OUTDIR}"
8 | COMMAND ${CMAKE_COMMAND} -E make_directory "${SHADERS_OUTDIR}"
9 | COMMENT "Creating shaders directory in ${SHADERS_OUTDIR}"
10 |
11 | VERBATIM
12 | )
13 |
14 | foreach (SHADER_SOURCE IN LISTS ARGN)
15 | get_filename_component(SHADER_NAME "${SHADER_SOURCE}" NAME)
16 | set(SHADER_OUTFILE "${SHADERS_OUTDIR}/${SHADER_NAME}")
17 |
18 | message(STATUS "Adding shaders ${SHADER_SOURCE} to ${TARGET_NAME}")
19 | list(APPEND SHADERS "${SHADER_OUTFILE}")
20 |
21 | add_custom_command(
22 | OUTPUT "${SHADER_OUTFILE}"
23 | DEPENDS ${SHADERS_OUTDIR} ${SHADER_SOURCE}
24 | COMMAND ${CMAKE_COMMAND} -E copy ${SHADER_SOURCE} ${SHADERS_OUTDIR}
25 |
26 |
27 | COMMENT "Moving ${SHADER_SOURCE} to runtime directory..."
28 |
29 | VERBATIM
30 | )
31 | endforeach ()
32 |
33 | add_custom_target(
34 | ${GENERATE_SHADERS_TARGET_NAME} ALL
35 | DEPENDS ${SHADERS}
36 | )
37 | add_dependencies(${TARGET_NAME} ${GENERATE_SHADERS_TARGET_NAME})
38 | endfunction ()
39 |
--------------------------------------------------------------------------------
/engine/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | message(STATUS "Configuring ${META_REAL_NAME_VERSION}")
2 |
3 | # Target
4 | add_library(
5 | ${REAL_LIBRARY_TARGET_NAME}
6 | STATIC # It is necessary
7 |
8 | ### Headers
9 | # util
10 | include/real/util/singleton.hpp
11 | # Core
12 | include/real/real.hpp
13 | include/real/pch.hpp
14 | include/real/assert.hpp
15 | include/real/core.hpp
16 | include/real/application.hpp
17 | include/real/logger.hpp
18 | include/real/layer.hpp
19 | include/real/layer_stack.hpp
20 | include/real/input.hpp
21 | include/real/window.hpp
22 | include/real/event.hpp
23 | include/real/time.hpp
24 | include/real/transform.hpp
25 | # Layers
26 | include/real/layer/base_layer.hpp
27 | include/real/layer/imgui_layer.hpp
28 | # Window
29 | include/real/window/base_window.hpp
30 | # Input
31 | include/real/keycode.hpp
32 | include/real/input/base_input.hpp
33 | # Events
34 | include/real/event/base_event.hpp
35 | include/real/event/key_event.hpp
36 | include/real/event/mouse_event.hpp
37 | include/real/event/window_event.hpp
38 | # Renderer
39 | include/real/renderer.hpp
40 | include/real/renderer/base_rendering_context.hpp
41 | include/real/renderer/base_renderer.hpp
42 | include/real/renderer/render_command.hpp
43 | include/real/renderer/renderer_api.hpp
44 | include/real/renderer/base_shader.hpp
45 | include/real/renderer/base_texture.hpp
46 | include/real/renderer/buffer_layout.hpp
47 | include/real/renderer/buffer_vertex.hpp
48 | include/real/renderer/buffer_index.hpp
49 | include/real/renderer/array_vertex.hpp
50 | include/real/renderer/camera.hpp
51 | include/real/renderer/light.hpp
52 | include/real/renderer/material.hpp
53 | include/real/renderer/common.hpp
54 | # Time
55 | include/real/time/timestep.hpp
56 | ## Api
57 | ## GL
58 | include/real/api/gl/gl_rendering_context.hpp
59 | include/real/api/gl/gl_renderer_api.hpp
60 | include/real/api/gl/gl_buffer_vertex.hpp
61 | include/real/api/gl/gl_buffer_index.hpp
62 | include/real/api/gl/gl_array_vertex.hpp
63 | include/real/api/gl/gl_conversions.hpp
64 | include/real/api/gl/gl_shader.hpp
65 | include/real/api/gl/gl_texture.hpp
66 |
67 | ### Sources
68 | # Core
69 | src/application.cpp
70 | src/base_window.cpp
71 | src/layer_stack.cpp
72 | src/logger.cpp
73 | # Layers
74 | src/base_layer.cpp
75 | src/layer/imgui_layer.cpp
76 | # Input
77 | src/base_input.cpp
78 | # Renderer
79 | src/renderer/base_rendering_context.cpp
80 | src/renderer/base_renderer.cpp
81 | src/renderer/renderer_api.cpp
82 | src/renderer/buffer_vertex.cpp
83 | src/renderer/buffer_index.cpp
84 | src/renderer/buffer_layout.cpp
85 | src/renderer/array_vertex.cpp
86 | src/renderer/base_shader.cpp
87 | src/renderer/base_texture.cpp
88 | src/renderer/camera.cpp
89 | ## Api
90 | ## GL
91 | # Imgui
92 | src/api/gl/imgui_build.cpp
93 | # Renderer
94 | src/api/gl/gl_rendering_context.cpp
95 | src/api/gl/gl_renderer_api.cpp
96 | src/api/gl/gl_shader.cpp
97 | src/api/gl/gl_texture.cpp
98 | src/api/gl/gl_buffer_vertex.cpp
99 | src/api/gl/gl_buffer_index.cpp
100 | src/api/gl/gl_array_vertex.cpp
101 | ## Other
102 | src/stb.cpp
103 | )
104 |
105 | target_precompile_headers(
106 | ${REAL_LIBRARY_TARGET_NAME}
107 | PRIVATE
108 | "include/real/pch.hpp"
109 | )
110 |
111 |
112 | # Platform-dependent sources
113 | if (WIN32)
114 | target_sources(
115 | ${REAL_LIBRARY_TARGET_NAME}
116 | PUBLIC
117 | # Window
118 | include/real/platform/windows/windows_window.hpp
119 | # Input
120 | include/real/platform/windows/windows_input.hpp
121 | # Time
122 | include/real/platform/windows/windows_time.hpp
123 | PRIVATE
124 | # Window
125 | src/platform/windows/windows_window.cpp
126 | # Input
127 | src/platform/windows/windows_input.cpp
128 | # Time
129 | src/platform/windows/windows_time.cpp
130 | )
131 |
132 | target_precompile_headers(
133 | ${REAL_LIBRARY_TARGET_NAME}
134 | PRIVATE
135 |
136 | # Platform-dependent headers
137 |
138 | )
139 | endif ()
140 |
141 | # Shaders
142 | add_shaders(
143 | ${REAL_LIBRARY_TARGET_NAME}
144 | "${CMAKE_CURRENT_SOURCE_DIR}/include/real/renderer/shaders/base.glsl"
145 | "${CMAKE_CURRENT_SOURCE_DIR}/include/real/renderer/shaders/material.glsl"
146 | "${CMAKE_CURRENT_SOURCE_DIR}/include/real/renderer/shaders/tex.glsl"
147 | )
148 |
149 | # Properties
150 | target_include_directories(
151 | ${REAL_LIBRARY_TARGET_NAME}
152 | PUBLIC
153 | "include"
154 | "${CMAKE_CURRENT_BINARY_DIR}"
155 | PRIVATE
156 | "src"
157 | )
158 |
159 | set_target_properties(
160 | ${REAL_LIBRARY_TARGET_NAME} PROPERTIES
161 |
162 | # Folder
163 | FOLDER ${META_REAL_PROJECT_FULL_NAME}/engine
164 |
165 | # Version
166 | VERSION ${META_REAL_VERSION}
167 | SOVERSION ${META_REAL_VERSION_MAJOR}
168 |
169 | # C++
170 | CXX_STANDARD ${CXX_STANDARD_DEFAULT}
171 | CXX_STANDARD_REQUIRED ON
172 | CXX_EXTENSIONS OFF
173 |
174 | # C
175 | C_STANDARD ${C_STANDARD_DEFAULT}
176 | C_STANDARD_REQUIRED ON
177 | C_EXTENSIONS OFF
178 |
179 | # Other
180 | VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
181 | )
182 |
183 | target_compile_definitions(
184 | ${REAL_LIBRARY_TARGET_NAME}
185 | PRIVATE
186 |
187 | PUBLIC
188 | # Build type macros
189 | $<$:REAL_DEBUG>
190 | $<$:REAL_RELEASE>
191 | $<$:REAL_PROFILE>
192 | # Platform macros
193 | $<$:REAL_PLATFORM_WINDOWS>
194 | INTERFACE
195 | REAL_CLIENT
196 | )
197 |
198 | target_compile_options(
199 | ${REAL_LIBRARY_TARGET_NAME}
200 | PUBLIC
201 | ${DEFAULT_COMPILE_OPTIONS}
202 | )
203 |
204 | target_link_options(
205 | ${REAL_LIBRARY_TARGET_NAME}
206 | PUBLIC
207 | # ${DEFAULT_LINKER_OPTIONS}
208 | )
209 |
210 | set_target_properties(
211 | ${REAL_LIBRARY_TARGET_NAME} PROPERTIES
212 |
213 | VISIBILITY_INLINES_HIDDEN YES
214 | CXX_VISIBILITY_PRESET hidden
215 | C_VISIBILITY_PRESET hidden
216 | ASM_VISIBILITY_PRESET hidden
217 | )
218 |
219 | # Utility
220 | # Generated Files
221 | # write_compiler_detection_header(
222 | # FILE "${META_REAL_PROJECT_NAME}/core-compiler.hpp"
223 | # PREFIX ${META_REAL_PROJECT_NAME_PREFIX}
224 | # COMPILERS Clang GNU MSVC
225 | # FEATURES cxx_override
226 | # )
227 |
228 | generate_export_header(
229 | ${REAL_LIBRARY_TARGET_NAME}
230 | BASE_NAME "${META_REAL_PROJECT_NAME_PREFIX}"
231 | PREFIX_NAME "${META_REAL_PROJECT_NAME_PREFIX}_"
232 | INCLUDE_GUARD_NAME "${META_REAL_PROJECT_NAME_PREFIX}_CORE_COMPILER"
233 | EXPORT_MACRO_NAME "API"
234 | EXPORT_FILE_NAME "${META_REAL_PROJECT_NAME}/core-export.hpp"
235 | NO_EXPORT_MACRO_NAME "NO_EXPORT"
236 | DEPRECATED_MACRO_NAME "DEPRECATED"
237 | INCLUDE_GUARD_NAME "${META_REAL_PROJECT_NAME_PREFIX}_CORE_API"
238 | STATIC_DEFINE "STATIC"
239 | NO_DEPRECATED_MACRO_NAME "NO_DEPRECATED"
240 |
241 | # DEFINE_NO_DEPRECATED
242 | )
243 |
244 | # Custom commands
245 | set(LOGS_DIR "${CMAKE_CURRENT_BINARY_DIR}/logs")
246 | set(LOG_EXPORTS_FILE "${LOGS_DIR}/exports.txt")
247 |
248 | file(MAKE_DIRECTORY "${LOGS_DIR}")
249 |
250 | # TODO: add support for other platforms
251 | if (WIN32 AND MSVC)
252 | # Save DLL exports
253 | add_custom_command(
254 | TARGET ${REAL_LIBRARY_TARGET_NAME} POST_BUILD
255 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
256 | COMMENT "Saving DLL file exports"
257 | BYPRODUCTS "${LOG_EXPORTS_FILE}"
258 |
259 | COMMAND dumpbin /exports $ > "${LOG_EXPORTS_FILE}"
260 |
261 | VERBATIM
262 | )
263 | endif ()
--------------------------------------------------------------------------------
/engine/include/real/api/gl/gl_array_vertex.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_GL_ARRAY_VERTEX
4 | #define REAL_GL_ARRAY_VERTEX
5 |
6 | #include "real/core.hpp"
7 | #include "real/renderer/array_vertex.hpp"
8 |
9 | namespace Real
10 | {
11 | class REAL_API GLVertexArray : public VertexArray
12 | {
13 | public:
14 | GLVertexArray();
15 | ~GLVertexArray() override;
16 |
17 | [[nodiscard]] virtual const std::vector>& VertexBuffers() const override
18 | { return vertexBuffers; };
19 | [[nodiscard]] virtual const std::vector>& IndexBuffers() const override
20 | { return indexBuffers; };
21 |
22 | virtual void AddVertexBuffer(
23 | const Real::Reference& buffer) override;
24 | virtual void AddIndexBuffer(
25 | const Real::Reference& buffer) override;
26 |
27 | virtual int32_t Count() const override;
28 |
29 | virtual void Bind() const override;
30 | virtual void Unbind() const override;
31 | private:
32 | renderer_id_t rendererId;
33 | uint32_t count;
34 |
35 | std::vector> vertexBuffers;
36 | std::vector> indexBuffers;
37 | };
38 | }
39 |
40 | #endif //REAL_GL_ARRAY_VERTEX
41 |
--------------------------------------------------------------------------------
/engine/include/real/api/gl/gl_buffer_index.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_GL_BUFFER_INDEX
4 | #define REAL_GL_BUFFER_INDEX
5 |
6 | #include "real/core.hpp"
7 | #include "real/renderer/buffer_index.hpp"
8 |
9 | namespace Real {
10 | class REAL_API GLIndexBuffer : public IndexBuffer {
11 | public:
12 | GLIndexBuffer(uint32_t *data, uint32_t size);
13 | ~GLIndexBuffer() override;
14 |
15 | void Bind() const override;
16 | void Unbind() const override;
17 |
18 | [[nodiscard]] uint32_t Count() const override;
19 | private:
20 | renderer_id_t rendererId;
21 | uint32_t count;
22 | };
23 | }
24 |
25 | #endif //REAL_GL_BUFFER_INDEX
26 |
--------------------------------------------------------------------------------
/engine/include/real/api/gl/gl_buffer_vertex.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_GL_BUFFER_VERTEX
4 | #define REAL_GL_BUFFER_VERTEX
5 |
6 | #include
7 |
8 | #include "real/core.hpp"
9 | #include "real/renderer/buffer_vertex.hpp"
10 |
11 | namespace Real
12 | {
13 | class REAL_API GLVertexBuffer : public VertexBuffer
14 | {
15 | public:
16 | GLVertexBuffer(float* data, uint32_t size);
17 | ~GLVertexBuffer() override;
18 |
19 | [[nodiscard]] const BufferLayout& Layout() const override
20 | { return bufferLayout; };
21 |
22 | void Layout(std::initializer_list attributes) override;
23 |
24 | void Bind() const override;
25 | void Unbind() const override;
26 | private:
27 | renderer_id_t rendererId;
28 | BufferLayout bufferLayout;
29 | };
30 | }
31 |
32 | #endif //REAL_GL_BUFFER_VERTEX
33 |
--------------------------------------------------------------------------------
/engine/include/real/api/gl/gl_conversions.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_GL_CONVERSIONS
4 | #define REAL_GL_CONVERSIONS
5 |
6 | #include "real/core.hpp"
7 | #include "real/renderer/common.hpp"
8 | #include "real/api/gl/gl_headers.hpp"
9 | #include "real/logger.hpp"
10 |
11 | namespace Real
12 | {
13 | constexpr GLuint GLTypeFrom(shader_data_t type) noexcept
14 | {
15 | // @formatter:off
16 | switch (type) {
17 | case shader_data_t::vec : return GL_FLOAT;
18 | case shader_data_t::vec2 : return GL_FLOAT;
19 | case shader_data_t::vec3 : return GL_FLOAT;
20 | case shader_data_t::vec4 : return GL_FLOAT;
21 | case shader_data_t::mat3 : return GL_FLOAT;
22 | case shader_data_t::mat4 : return GL_FLOAT;
23 | case shader_data_t::ivec : return GL_INT;
24 | case shader_data_t::ivec2 : return GL_INT;
25 | case shader_data_t::ivec3 : return GL_INT;
26 | case shader_data_t::ivec4 : return GL_INT;
27 | case shader_data_t::bvec : return GL_BOOL;
28 | case shader_data_t::bvec2 : return GL_BOOL;
29 | case shader_data_t::bvec3 : return GL_BOOL;
30 | case shader_data_t::bvec4 : return GL_BOOL;
31 |
32 | default:
33 | case shader_data_t::none: REAL_CORE_ERROR("Unsupported data type: {}!", static_cast(type));
34 | return 0;
35 | }
36 | // @formatter:on
37 | }
38 |
39 | inline GLenum GLShaderTypeFrom(std::string_view type) noexcept
40 | {
41 | if (type == "vertex")
42 | {
43 | return GL_VERTEX_SHADER;
44 | }
45 |
46 | if (type == "fragment")
47 | {
48 | return GL_FRAGMENT_SHADER;
49 | }
50 |
51 | REAL_CORE_ERROR("Unknown shader type {0}", type);
52 | return 0;
53 | }
54 | }
55 |
56 | #endif //REAL_GL_CONVERSIONS
57 |
--------------------------------------------------------------------------------
/engine/include/real/api/gl/gl_headers.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_GL_HEADERS
4 | #define REAL_GL_HEADERS
5 |
6 | #include
7 | #include
8 |
9 | #endif //REAL_GL_HEADERS
10 |
--------------------------------------------------------------------------------
/engine/include/real/api/gl/gl_renderer_api.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_GL_RENDERER_API
4 | #define REAL_GL_RENDERER_API
5 |
6 | #include "real/core.hpp"
7 | #include "real/renderer/renderer_api.hpp"
8 | #include "real/renderer/array_vertex.hpp"
9 |
10 | namespace Real
11 | {
12 | class REAL_API GLRendererApi : public RendererAPI
13 | {
14 | public:
15 | virtual void Init() override;
16 | void ClearColor(glm::fvec4 color) override;
17 | void Clear(int32_t bits) override;
18 | void DrawIndexed(const Real::Reference& vao) override;
19 | [[nodiscard]] API Value() const override;
20 | private:
21 | [[nodiscard]] int32_t DefaultClearBits() const noexcept override;
22 | };
23 | }
24 |
25 | #endif //REAL_GL_RENDERER_API
26 |
--------------------------------------------------------------------------------
/engine/include/real/api/gl/gl_rendering_context.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_GL_RENDERING_CONTEXT
4 | #define REAL_GL_RENDERING_CONTEXT
5 |
6 | #include "real/renderer/base_rendering_context.hpp"
7 |
8 | // Avoid including glfw
9 | struct GLFWwindow;
10 |
11 | namespace Real
12 | {
13 | class REAL_API GLRenderingContext : public RenderingContext
14 | {
15 | public:
16 | explicit GLRenderingContext(GLFWwindow* windowHandle);
17 | virtual ~GLRenderingContext();
18 |
19 | void Init() override;
20 | void SwapBuffers() override;
21 | void VSync(bool enabled) override;
22 | private:
23 | GLFWwindow* glfwWindowHandle;
24 | };
25 | }
26 |
27 | #endif //REAL_GL_RENDERING_CONTEXT
28 |
--------------------------------------------------------------------------------
/engine/include/real/api/gl/gl_shader.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_GL_SHADER
4 | #define REAL_GL_SHADER
5 |
6 | #include
7 |
8 | #include "real/core.hpp"
9 | #include "real/renderer/base_shader.hpp"
10 | #include "real/api/gl/gl_headers.hpp"
11 |
12 | #define GL_SHADERS_MAX_COUNT SHADERS_MAX_COUNT
13 | #define GL_SHADERS_AVG_COUNT SHADERS_AVG_COUNT
14 |
15 | namespace Real
16 | {
17 | class REAL_API GLShader : public Real::Shader
18 | {
19 | public:
20 | GLShader(const std::string& filename);
21 | ~GLShader() override;
22 |
23 | // region Uniforms
24 | // Floats
25 | void UniformFloat(const std::string& name, glm::f32 value) override;
26 | void UniformFloat(const std::string& name, const glm::fvec2& value) override;
27 | void UniformFloat(const std::string& name, const glm::fvec3& value) override;
28 | void UniformFloat(const std::string& name, const glm::fvec4& value) override;
29 |
30 | // Matrices
31 | void UniformMatrix(const std::string& name, const glm::fmat3& matrix) override;
32 | void UniformMatrix(const std::string& name, const glm::fmat4& matrix) override;
33 |
34 | // Ints
35 | void UniformInt(const std::string& name, glm::int32 value) override;
36 | void UniformInt(const std::string& name, const glm::ivec2& value) override;
37 | void UniformInt(const std::string& name, const glm::ivec3& value) override;
38 | void UniformInt(const std::string& name, const glm::ivec4& value) override;
39 | // endregion
40 |
41 | const std::string& Name() const override
42 | { return this->shaderName; }
43 | void Name(std::string string) override
44 | { this->shaderName = string; }
45 |
46 | void Bind() const override;
47 | void Unbind() const override;
48 | private:
49 | //region Helpers
50 | static std::string ReadFile(const std::string& filepath);
51 |
52 | void Preprocess(std::string& source) const;
53 | std::unordered_map Split(const std::string& source) const;
54 | void Compile(const std::unordered_map& shader_srcs);
55 | void Link() const;
56 |
57 | static void CheckHandleProgramError(GLuint id, GLenum action);
58 | static void CheckHandleShaderError(GLuint id, GLenum action);
59 | //endregion
60 |
61 | inline GLint LocationOf(const std::string& name) const;
62 | private:
63 | GLuint programId;
64 | std::string shaderName;
65 |
66 | size_t count = 0;
67 | std::array shaders;
68 |
69 | mutable std::unordered_map uniformLocationsCache;
70 | };
71 | }
72 |
73 | #endif //REAL_GL_SHADER
74 |
--------------------------------------------------------------------------------
/engine/include/real/api/gl/gl_texture.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_GL_TEXTURE
4 | #define REAL_GL_TEXTURE
5 |
6 | #include "real/core.hpp"
7 | #include "real/renderer/base_texture.hpp"
8 |
9 | namespace Real
10 | {
11 |
12 | class REAL_API GLTexture2D : public Real::Texture2D
13 | {
14 | public:
15 | GLTexture2D(const std::string& path);
16 | ~GLTexture2D();
17 |
18 | virtual void Init() override;
19 |
20 | virtual texture_dimension_t Width() const override
21 | { return width; };
22 | virtual texture_dimension_t Height() const override
23 | { return height; };
24 |
25 | virtual void Bind(uint32_t slot = 0) const override;
26 | private:
27 | std::string path;
28 |
29 | texture_dimension_t width;
30 | texture_dimension_t height;
31 |
32 | renderer_id_t rendererId;
33 | };
34 | }
35 |
36 | #endif //REAL_GL_TEXTURE
37 |
--------------------------------------------------------------------------------
/engine/include/real/application.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_APPLICATION
4 | #define REAL_APPLICATION
5 |
6 | #include
7 |
8 | #include "real/event.hpp"
9 | #include "real/core.hpp"
10 | #include "real/window.hpp"
11 | #include "real/input.hpp"
12 | #include "real/layer_stack.hpp"
13 | #include "real/renderer.hpp"
14 | #include "real/time.hpp"
15 | #include "real/util/singleton.hpp"
16 |
17 | namespace Real
18 | {
19 | class REAL_API SINGLETON(Application)
20 | {
21 | public:
22 | explicit Application(std::string name = REAL_APPLICATION_DEFAULT_NAME);
23 | virtual ~Application();
24 |
25 | [[nodiscard]] LayerStack& Layers() noexcept
26 | { return this->layerStack; }
27 | [[nodiscard]] Window& Window() const noexcept
28 | { return *(this->window); }
29 |
30 | double Time() const;
31 | void Init();
32 | void Run();
33 |
34 | void PushLayer(Layer* layer);
35 | void PushOverlay(Layer* layer);
36 | protected:
37 | virtual void Update(Timestep ts);
38 | virtual void OnEvent(Event& e);
39 | private:
40 | void OnWindowClose(WindowClosedEvent& event);
41 | private:
42 | ImGUILayer* imGUILayer;
43 |
44 | std::string name;
45 |
46 | Real::Scope window;
47 | Real::Scope input;
48 |
49 | LayerStack layerStack;
50 |
51 | bool isRunning { true };
52 |
53 | float frametime = 0.0f;
54 | };
55 |
56 | // To be defined in client
57 | extern Real::Scope Make();
58 | }
59 |
60 | #endif //REAL_APPLICATION
61 |
--------------------------------------------------------------------------------
/engine/include/real/assert.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_ASSERT
4 | #define REAL_ASSERT
5 |
6 | #include "real/logger.hpp"
7 |
8 | #define REAL_EXPAND_MACRO(x) x
9 | #define REAL_STRINGIFY_MACRO(x) #x
10 |
11 | //region real_dbg_assert and real_debugbreak()
12 | // Thanks https://github.com/nemequ/portable-snippets/tree/master/debug-trap for knowledge
13 | #if defined(__has_builtin) && !defined(__ibmxl__)
14 | # if __has_builtin(__builtin_debugtrap)
15 | # define real_debugbreak() __builtin_debugtrap()
16 | # elif __has_builtin(__debugbreak)
17 | # define real_debugbreak() __debugbreak()
18 | # endif
19 | #endif
20 | #if !defined(real_debugbreak)
21 | # if defined(_MSC_VER) || defined(__INTEL_COMPILER)
22 | # define real_debugbreak() __debugbreak()
23 | # elif defined(__ARMCC_VERSION)
24 | # define real_debugbreak() __breakpoint(42)
25 | # elif defined(__ibmxl__) || defined(__xlC__)
26 | # include
27 | # define real_debugbreak() __trap(42)
28 | # elif defined(__DMC__) && defined(_M_IX86)
29 | static inline void real_debugbreak(void) { __asm int 3h; }
30 | # elif defined(__i386__) || defined(__x86_64__)
31 | static inline void real_debugbreak(void) { __asm__ __volatile__("int3"); }
32 | # elif defined(__thumb__)
33 | static inline void real_debugbreak(void) { __asm__ __volatile__(".inst 0xde01"); }
34 | # elif defined(__aarch64__)
35 | static inline void real_debugbreak(void) { __asm__ __volatile__(".inst 0xd4200000"); }
36 | # elif defined(__arm__)
37 | static inline void real_debugbreak(void) { __asm__ __volatile__(".inst 0xe7f001f0"); }
38 | # elif defined (__alpha__) && !defined(__osf__)
39 | static inline void real_debugbreak(void) { __asm__ __volatile__("bpt"); }
40 | # elif defined(_54_)
41 | static inline void real_debugbreak(void) { __asm__ __volatile__("ESTOP"); }
42 | # elif defined(_55_)
43 | static inline void real_debugbreak(void) { __asm__ __volatile__(";\n .if (.MNEMONIC)\n ESTOP_1\n .else\n ESTOP_1()\n .endif\n NOP"); }
44 | # elif defined(_64P_)
45 | static inline void real_debugbreak(void) { __asm__ __volatile__("SWBP 0"); }
46 | # elif defined(_6x_)
47 | static inline void real_debugbreak(void) { __asm__ __volatile__("NOP\n .word 0x10000000"); }
48 | # elif defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) && defined(__GNUC__)
49 | # define real_debugbreak() __builtin_trap()
50 | # else
51 | # include
52 | # if defined(SIGTRAP)
53 | # define real_debugbreak() raise(SIGTRAP)
54 | # else
55 | # define real_debugbreak() raise(SIGABRT)
56 | # endif
57 | # endif
58 | #endif
59 |
60 | #if defined(HEDLEY_LIKELY)
61 | # define REAL_DBG_LIKELY(expr) HEDLEY_LIKELY(expr)
62 | #elif defined(__GNUC__) && (__GNUC__ >= 3)
63 | # define REAL_DBG_LIKELY(expr) __builtin_expect(!!(expr), 1)
64 | #else
65 | # define REAL_DBG_LIKELY(expr) (!!(expr))
66 | #endif
67 |
68 | #if defined(REAL_DEBUG)
69 | # define real_dbg_assert(expr) do { \
70 | if (!REAL_DBG_LIKELY(expr)) { \
71 | real_debugbreak(); \
72 | } \
73 | } while (0)
74 | # define real_msg_assert(expr, ...) do { \
75 | if (!REAL_DBG_LIKELY(expr)) { \
76 | REAL_EXPAND_MACRO(REAL_CORE_ERROR)(__VA_ARGS__); \
77 | real_debugbreak(); \
78 | } \
79 | } while (0)
80 | #else
81 | # define real_dbg_assert(expr)
82 | # define real_msg_assert(expr, ...)
83 | #endif
84 |
85 | //endregion
86 |
87 | #endif //REAL_ASSERT
88 |
--------------------------------------------------------------------------------
/engine/include/real/core.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_CORE
4 | #define REAL_CORE
5 |
6 | // region Configured By CMake
7 | // Export Macros
8 | #include "real/core-export.hpp"
9 | // Compilers
10 | // #include "real/core-compiler.hpp"
11 | // endregion
12 |
13 | #define REAL_APPLICATION_DEFAULT_NAME "Real Engine"
14 | #define REAL_DEFAULT_WINDOW_HEIGHT 720
15 | #define REAL_DEFAULT_WINDOW_WIDTH 1280
16 | #define REAL_DEFAULT_WINDOW_TITLE "Real Engine"
17 | #define REAL_DEFAULT_WINDOW_V_SYNC false
18 |
19 | #include "real/pch.hpp"
20 | #include "real/assert.hpp"
21 |
22 | namespace Real
23 | {
24 | // region types
25 | // Input
26 | using keycode_t = int32_t;
27 | using mouse_btn_t = int32_t;
28 | using mouse_position_t = int32_t;
29 |
30 | // Window
31 | using window_dimension_t = int32_t;
32 | using window_position_t = int32_t;
33 |
34 | // Renderer
35 | using renderer_id_t = uint32_t;
36 | //// Textures
37 | using texture_dimension_t = uint32_t;
38 | // endregion
39 | //region util
40 | constexpr uint16_t bit(uint16_t x)
41 | {
42 | return static_cast(1u << x);
43 | }
44 | // endregion
45 | // region Pointers
46 | // TODO: make own pointers
47 | template
48 | using Reference = std::shared_ptr;
49 |
50 | template
51 | constexpr Reference MakeReference(Args&& ... args)
52 | {
53 | return std::make_shared(std::forward(args)...);
54 | }
55 |
56 | template
57 | using Scope = std::unique_ptr;
58 |
59 | template
60 | constexpr Scope MakeScope(Args&& ... args)
61 | {
62 | return std::make_unique(std::forward(args)...);
63 | }
64 | // endregion
65 | }
66 |
67 | #endif //REAL_CORE
--------------------------------------------------------------------------------
/engine/include/real/event.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_EVENT
4 | #define REAL_EVENT
5 |
6 | #include "real/event/base_event.hpp"
7 | #include "real/event/window_event.hpp"
8 | #include "real/event/key_event.hpp"
9 | #include "real/event/mouse_event.hpp"
10 |
11 | #endif //REAL_EVENT
12 |
13 |
--------------------------------------------------------------------------------
/engine/include/real/event/base_event.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_EVENT_BASE
4 | #define REAL_EVENT_BASE
5 |
6 | #include
7 | #include
8 |
9 | #include
10 |
11 | #include "real/core.hpp"
12 |
13 | namespace Real
14 | {
15 |
16 | using ev_type_t = int32_t;
17 | using ev_category_t = int32_t;
18 |
19 | enum class EventType : ev_type_t
20 | {
21 | None = 0,
22 |
23 | // category_window types
24 | WindowClose, WindowResize, WindowFocus, WindowUnfocus, WindowMove,
25 |
26 | // key types
27 | KeyPressed, KeyReleased, KeyTyped,
28 |
29 | // category_mouse types
30 | MouseBtnPress, MouseBtnRelease, MouseMove, MouseScroll,
31 | };
32 |
33 | enum class EventCategory : ev_category_t
34 | {
35 | None = 0,
36 | Window = bit(1u),
37 | Input = bit(2u),
38 | Mouse = bit(3u),
39 | MouseBtn = bit(4u),
40 | };
41 |
42 | class Event
43 | {
44 | friend class EventDispatcher;
45 |
46 | friend std::ostream& operator<<(std::ostream& os, const Event& ev);
47 | public:
48 | [[nodiscard]] virtual ev_category_t Categories() const = 0;
49 | [[nodiscard]] virtual EventType Type() const = 0;
50 |
51 | [[nodiscard]] bool IsHandled() const
52 | { return handled; }
53 |
54 | #ifdef REAL_DEBUG
55 | [[nodiscard]] virtual std::string Name() const = 0;
56 | [[nodiscard]] virtual std::string ToString() const
57 | { return Name(); }
58 | #else
59 | [[nodiscard]] virtual std::string ToString() const { return "event"; }
60 | #endif
61 |
62 | [[nodiscard]] bool HasCategory(EventCategory c) const
63 | {
64 | return static_cast(static_cast(c) & Categories());
65 | }
66 | protected:
67 | bool handled = false;
68 | };
69 |
70 | template
71 | struct IsEvent
72 | {
73 | #pragma clang diagnostic push
74 | #pragma ide diagnostic ignored "NotImplementedFunctions"
75 | static int Detect(...);
76 |
77 | template
78 | static decltype(U::StaticType()) Detect(const U&);
79 |
80 | static constexpr bool value = std::is_same<
81 | EventType,
82 | decltype(
83 | Detect(std::declval<
84 | typename std::enable_if::value, T>::type
85 | >()))
86 | >::value;
87 | #pragma clang diagnostic pop
88 | };
89 |
90 | class EventDispatcher
91 | {
92 | template
93 | using ev_function_t = std::function;
94 | public:
95 |
96 | explicit EventDispatcher(Event* ev)
97 | :event(ev)
98 | {}
99 |
100 | template
101 | bool Dispatch(
102 | ev_function_t<
103 | typename std::enable_if::value, T>::type
104 | > function
105 | ) noexcept
106 | {
107 | if (event->Type() == T::StaticType())
108 | {
109 | event->handled = function(*((T*)event));
110 | return true;
111 | }
112 | return false;
113 | }
114 |
115 | private:
116 | Event* event;
117 | };
118 |
119 | inline std::ostream& operator<<(std::ostream& os, const Event& event)
120 | {
121 | os << event.ToString() << ", handled: " << event.handled;
122 | return os;
123 | }
124 | }
125 |
126 | #endif //REAL_EVENT_BASE
--------------------------------------------------------------------------------
/engine/include/real/event/key_event.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_EVENT_KEY
4 | #define REAL_EVENT_KEY
5 |
6 | #include "real/event/base_event.hpp"
7 |
8 | namespace Real
9 | {
10 | class KeyEvent : public Event
11 | {
12 | public:
13 | [[nodiscard]] ev_category_t Categories() const override
14 | {
15 | return static_cast(EventCategory::Input);
16 | }
17 |
18 | [[nodiscard]] EventType Type() const override
19 | {
20 | return EventType::None;
21 | }
22 |
23 | [[nodiscard]] static EventType StaticType()
24 | {
25 | return EventType::None;
26 | };
27 | };
28 |
29 | class KeyPressedEvent : public KeyEvent
30 | {
31 | private:
32 | keycode_t btnKeycode;
33 | public:
34 | explicit KeyPressedEvent(keycode_t btn)
35 | :btnKeycode(btn)
36 | {};
37 |
38 | [[nodiscard]] mouse_btn_t KeyCode() const
39 | { return btnKeycode; }
40 |
41 | [[nodiscard]] EventType Type() const override
42 | {
43 | return EventType::KeyPressed;
44 | }
45 |
46 | [[nodiscard]] static EventType StaticType()
47 | {
48 | return EventType::KeyPressed;
49 | };
50 | #ifdef REAL_DEBUG
51 | [[nodiscard]] std::string Name() const override
52 | {
53 | return "key_press_ev";
54 | }
55 | #endif
56 | [[nodiscard]] std::string ToString() const override
57 | {
58 | std::stringstream ss;
59 | ss << "key_press_ev: (";
60 | ss << btnKeycode;
61 | ss << ")";
62 | return ss.str();
63 | }
64 |
65 | };
66 |
67 | class KeyReleasedEvent : public KeyEvent
68 | {
69 | private:
70 | keycode_t btnKeycode;
71 | public:
72 | explicit KeyReleasedEvent(keycode_t btn)
73 | :btnKeycode(btn)
74 | {};
75 |
76 | [[nodiscard]] mouse_btn_t KeyCode() const
77 | { return btnKeycode; }
78 |
79 | [[nodiscard]] EventType Type() const override
80 | {
81 | return EventType::KeyReleased;
82 | }
83 |
84 | [[nodiscard]] static EventType StaticType()
85 | {
86 | return EventType::KeyReleased;
87 | };
88 |
89 | #ifdef REAL_DEBUG
90 | [[nodiscard]] std::string Name() const override
91 | {
92 | return "key_release_ev";
93 | }
94 | #endif
95 | [[nodiscard]] std::string ToString() const override
96 | {
97 | std::stringstream ss;
98 | ss << "key_release_ev: (";
99 | ss << btnKeycode;
100 | ss << ")";
101 | return ss.str();
102 | }
103 |
104 | };
105 |
106 | class KeyTypedEvent : public KeyEvent
107 | {
108 | private:
109 | keycode_t keycode;
110 | keycode_t repeatCount = 0;
111 | public:
112 | explicit KeyTypedEvent(keycode_t btn)
113 | :keycode(btn)
114 | {};
115 |
116 | [[nodiscard]] mouse_btn_t KeyCode() const
117 | { return keycode; }
118 | [[nodiscard]] mouse_btn_t Repeats() const
119 | { return repeatCount; }
120 |
121 | [[nodiscard]] EventType Type() const override
122 | {
123 | return EventType::KeyTyped;
124 | }
125 |
126 | [[nodiscard]] static EventType StaticType()
127 | {
128 | return EventType::KeyTyped;
129 | };
130 |
131 | #ifdef REAL_DEBUG
132 | [[nodiscard]] std::string Name() const override
133 | {
134 | return "key_typed_ev";
135 | }
136 | #endif
137 | [[nodiscard]] std::string ToString() const override
138 | {
139 | std::stringstream ss;
140 | ss << "key_typed_ev: (";
141 | ss << keycode << ", " << repeatCount;
142 | ss << ")";
143 | return ss.str();
144 | }
145 |
146 | };
147 | }
148 |
149 | #endif //REAL_EVENT_KEY
150 |
--------------------------------------------------------------------------------
/engine/include/real/event/mouse_event.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_EVENT_MOUSE
4 | #define REAL_EVENT_MOUSE
5 |
6 | #include "real/event/base_event.hpp"
7 |
8 | namespace Real
9 | {
10 |
11 | class MouseEvent : public Event
12 | {
13 | public:
14 | [[nodiscard]] ev_category_t Categories() const override
15 | {
16 | return static_cast(EventCategory::Mouse);
17 | }
18 |
19 | [[nodiscard]] EventType Type() const override
20 | {
21 | return EventType::None;
22 | }
23 |
24 | [[nodiscard]] static EventType StaticType()
25 | {
26 | return EventType::None;
27 | };
28 | };
29 |
30 | class MouseBtnPressedEvent : public MouseEvent
31 | {
32 | private:
33 | mouse_btn_t mouseBtn;
34 | public:
35 | explicit MouseBtnPressedEvent(mouse_btn_t btn)
36 | :mouseBtn(btn)
37 | {};
38 |
39 | [[nodiscard]] mouse_btn_t Button() const
40 | { return mouseBtn; }
41 |
42 | [[nodiscard]] EventType Type() const override
43 | {
44 | return EventType::MouseBtnPress;
45 | }
46 |
47 | [[nodiscard]] static EventType StaticType()
48 | {
49 | return EventType::MouseBtnPress;
50 | };
51 |
52 | #ifdef REAL_DEBUG
53 | [[nodiscard]] std::string Name() const override
54 | {
55 | return "mouse_btn_press_ev";
56 | }
57 | #endif
58 | [[nodiscard]] std::string ToString() const override
59 | {
60 | std::stringstream ss;
61 | ss << "mouse_btn_press_ev: (";
62 | ss << mouseBtn;
63 | ss << ")";
64 | return ss.str();
65 | }
66 |
67 | };
68 |
69 | class MouseBtnReleasedEvent : public MouseEvent
70 | {
71 | private:
72 | mouse_btn_t mouseBtn;
73 | public:
74 | explicit MouseBtnReleasedEvent(mouse_btn_t btn)
75 | :mouseBtn(btn)
76 | {};
77 |
78 | [[nodiscard]] mouse_btn_t Button() const
79 | { return mouseBtn; }
80 |
81 | [[nodiscard]] EventType Type() const override
82 | {
83 | return EventType::MouseBtnRelease;
84 | }
85 |
86 | [[nodiscard]] static EventType StaticType()
87 | {
88 | return EventType::MouseBtnRelease;
89 | };
90 |
91 | #ifdef REAL_DEBUG
92 | [[nodiscard]] std::string Name() const override
93 | {
94 | return "mouse_btn_release_ev";
95 | }
96 | #endif
97 | [[nodiscard]] std::string ToString() const override
98 | {
99 | std::stringstream ss;
100 | ss << "mouse_btn_release_ev: (";
101 | ss << mouseBtn;
102 | ss << ")";
103 | return ss.str();
104 | }
105 |
106 | };
107 |
108 | class MouseMovedEvent : public MouseEvent
109 | {
110 | private:
111 | mouse_position_t xPos, yPos;
112 | public:
113 | MouseMovedEvent(mouse_position_t x, mouse_position_t y)
114 | :xPos(x), yPos(y)
115 | {}
116 |
117 | [[nodiscard]] mouse_position_t X() const
118 | { return xPos; }
119 | [[nodiscard]] mouse_position_t Y() const
120 | { return yPos; }
121 |
122 | [[nodiscard]] EventType Type() const override
123 | {
124 | return EventType::MouseMove;
125 | }
126 |
127 | [[nodiscard]] static EventType StaticType()
128 | {
129 | return EventType::MouseMove;
130 | };
131 |
132 | #ifdef REAL_DEBUG
133 | [[nodiscard]] std::string Name() const override
134 | {
135 | return "mouse_move_ev";
136 | }
137 | #endif
138 | [[nodiscard]] std::string ToString() const override
139 | {
140 | std::stringstream ss;
141 | ss << "mouse_move_ev: (";
142 | ss << xPos << ", " << yPos;
143 | ss << ")";
144 | return ss.str();
145 | }
146 |
147 | };
148 |
149 | class MouseScrolledEvent : public MouseEvent
150 | {
151 | public:
152 | MouseScrolledEvent(mouse_position_t x_offset, mouse_position_t y_offset)
153 | :xOffset(x_offset),
154 | yOffset(y_offset)
155 | {}
156 |
157 | [[nodiscard]] mouse_position_t XOffset() const
158 | { return xOffset; }
159 | [[nodiscard]] mouse_position_t YOffset() const
160 | { return yOffset; }
161 |
162 | [[nodiscard]] EventType Type() const override
163 | {
164 | return EventType::MouseScroll;
165 | }
166 |
167 | [[nodiscard]] static EventType StaticType()
168 | {
169 | return EventType::MouseScroll;
170 | };
171 |
172 | #ifdef REAL_DEBUG
173 | [[nodiscard]] std::string Name() const override
174 | {
175 | return "mouse_scroll_ev";
176 | }
177 | #endif
178 |
179 | [[nodiscard]] std::string ToString() const override
180 | {
181 | std::stringstream ss;
182 | ss << "mouse_btn_press_ev: (";
183 | ss << xOffset << ", " << yOffset;
184 | ss << ")";
185 | return ss.str();
186 | }
187 | private:
188 | mouse_position_t xOffset;
189 | mouse_position_t yOffset;
190 | };
191 | }
192 |
193 | #endif //REAL_EVENT_MOUSE
194 |
--------------------------------------------------------------------------------
/engine/include/real/event/window_event.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_EVENT_WINDOW
4 | #define REAL_EVENT_WINDOW
5 |
6 | #include
7 |
8 | #include "real/event/base_event.hpp"
9 |
10 | namespace Real
11 | {
12 |
13 | class WindowEvent : public Event
14 | {
15 | public:
16 | [[nodiscard]] ev_category_t Categories() const override
17 | {
18 | return static_cast(EventCategory::Window);
19 | }
20 |
21 | [[nodiscard]] EventType Type() const override
22 | {
23 | return EventType::None;
24 | }
25 |
26 | [[nodiscard]] static EventType StaticType()
27 | {
28 | return EventType::None;
29 | };
30 | };
31 |
32 | class WindowClosedEvent : public WindowEvent
33 | {
34 | public:
35 | WindowClosedEvent() = default;
36 |
37 | [[nodiscard]] EventType Type() const override
38 | {
39 | return EventType::WindowClose;
40 | }
41 |
42 | [[nodiscard]] static EventType StaticType()
43 | {
44 | return EventType::WindowClose;
45 | };
46 |
47 | #ifdef REAL_DEBUG
48 | [[nodiscard]] std::string Name() const override
49 | {
50 | return "window_close_ev";
51 | }
52 | #endif
53 | [[nodiscard]] std::string ToString() const override
54 | {
55 | return "window_close_ev";
56 | }
57 |
58 | };
59 |
60 | class WindowResizedEvent : public WindowEvent
61 | {
62 | private:
63 | window_dimension_t width, heigth;
64 | public:
65 | WindowResizedEvent(window_dimension_t w, window_dimension_t h)
66 | :width(w), heigth(h)
67 | {}
68 |
69 | [[nodiscard]] mouse_btn_t Width() const
70 | { return width; }
71 | [[nodiscard]] mouse_btn_t Height() const
72 | { return heigth; }
73 |
74 | [[nodiscard]] EventType Type() const override
75 | {
76 | return EventType::WindowResize;
77 | }
78 |
79 | [[nodiscard]] static EventType StaticType()
80 | {
81 | return EventType::WindowResize;
82 | };
83 |
84 | #ifdef REAL_DEBUG
85 | [[nodiscard]] std::string Name() const override
86 | {
87 | return "window_resize_ev";
88 | }
89 | #endif
90 | [[nodiscard]] std::string ToString() const override
91 | {
92 | std::stringstream ss;
93 | ss << "window_resize_ev: (";
94 | ss << width << ", " << heigth;
95 | ss << ")";
96 | return ss.str();
97 | }
98 |
99 | };
100 |
101 | class WindowMovedEvent : public WindowEvent
102 | {
103 | private:
104 | window_position_t xPos, yPos;
105 | public:
106 | WindowMovedEvent(window_position_t x, window_position_t y)
107 | :xPos(x), yPos(y)
108 | {}
109 |
110 | [[nodiscard]] mouse_btn_t X() const
111 | { return xPos; }
112 | [[nodiscard]] mouse_btn_t Y() const
113 | { return yPos; }
114 |
115 | [[nodiscard]] EventType Type() const override
116 | {
117 | return EventType::WindowMove;
118 | }
119 |
120 | [[nodiscard]] static EventType StaticType()
121 | {
122 | return EventType::WindowMove;
123 | };
124 |
125 | #ifdef REAL_DEBUG
126 | [[nodiscard]] std::string Name() const override
127 | {
128 | return "window_move_ev";
129 | }
130 | #endif
131 |
132 | [[nodiscard]] std::string ToString() const override
133 | {
134 | std::stringstream ss;
135 | ss << "window_move_ev: (";
136 | ss << xPos << ", " << yPos;
137 | ss << ")";
138 | return ss.str();
139 | }
140 |
141 | };
142 |
143 | class WindowFocusedEvent : public WindowEvent
144 | {
145 | public:
146 | WindowFocusedEvent() = default;
147 |
148 | [[nodiscard]] EventType Type() const override
149 | {
150 | return EventType::WindowFocus;
151 | }
152 |
153 | [[nodiscard]] static EventType StaticType()
154 | {
155 | return EventType::WindowFocus;
156 | };
157 |
158 | #ifdef REAL_DEBUG
159 | [[nodiscard]] std::string Name() const override
160 | {
161 | return "window_focus_ev";
162 | }
163 | #endif
164 |
165 | [[nodiscard]] std::string ToString() const override
166 | {
167 | std::stringstream ss;
168 | ss << "window_resize_ev";
169 | return ss.str();
170 | }
171 |
172 | };
173 |
174 | class WindowUnfocusedEvent : public WindowEvent
175 | {
176 | public:
177 | WindowUnfocusedEvent() = default;
178 |
179 | [[nodiscard]] EventType Type() const override
180 | {
181 | return EventType::WindowUnfocus;
182 | }
183 |
184 | [[nodiscard]] static EventType StaticType()
185 | {
186 | return EventType::WindowUnfocus;
187 | };
188 |
189 | #ifdef REAL_DEBUG
190 | [[nodiscard]] std::string Name() const override
191 | {
192 | return "window_unfocus_ev";
193 | }
194 | #endif
195 |
196 | [[nodiscard]] std::string ToString() const override
197 | {
198 | std::stringstream ss;
199 | ss << "window_resize_ev";
200 | return ss.str();
201 | }
202 |
203 | };
204 | }
205 |
206 | #endif //REAL_EVENT_WINDOW
207 |
--------------------------------------------------------------------------------
/engine/include/real/input.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_INPUT
4 | #define REAL_INPUT
5 |
6 | #include "real/core.hpp"
7 | #include "real/keycode.hpp"
8 | #include "real/input/base_input.hpp"
9 |
10 | #ifdef REAL_PLATFORM_WINDOWS
11 | #include "real/platform/windows/windows_input.hpp"
12 | #else
13 | #error Unsupported platform!
14 | #endif
15 |
16 | #endif //REAL_INPUT
17 |
--------------------------------------------------------------------------------
/engine/include/real/input/base_input.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_INPUT_BASE
4 | #define REAL_INPUT_BASE
5 |
6 | #include "real/core.hpp"
7 | #include "real/keycode.hpp"
8 | #include "real/util/singleton.hpp"
9 |
10 | namespace Real
11 | {
12 | class REAL_API SINGLETON(Input)
13 | {
14 | public:
15 | virtual ~Input() = default;
16 |
17 | virtual bool IsKeyPressed(KeyCode keycode) = 0;
18 | virtual bool IsMouseBtnPressed(mouse_btn_t mouseBtn) = 0;
19 |
20 | virtual std::pair MousePosition() = 0;
21 | virtual mouse_position_t MouseX() = 0;
22 | virtual mouse_position_t MouseY() = 0;
23 |
24 | static Real::Scope Make();
25 | };
26 | }
27 |
28 | #endif //REAL_INPUT_BASE
29 |
--------------------------------------------------------------------------------
/engine/include/real/keycode.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_KEYCODE
4 | #define REAL_KEYCODE
5 |
6 | #include
7 |
8 | #include "real/core.hpp"
9 |
10 | namespace Real {
11 | enum class KeyCode : keycode_t {
12 | // @formatter:off
13 | // From glfw3.h
14 | Space = 32,
15 | Apostrophe = 39, /* ' */
16 | Comma = 44, /* , */
17 | Minus = 45, /* - */
18 | Period = 46, /* . */
19 | Slash = 47, /* / */
20 |
21 | D0 = 48, /* 0 */
22 | D1 = 49, /* 1 */
23 | D2 = 50, /* 2 */
24 | D3 = 51, /* 3 */
25 | D4 = 52, /* 4 */
26 | D5 = 53, /* 5 */
27 | D6 = 54, /* 6 */
28 | D7 = 55, /* 7 */
29 | D8 = 56, /* 8 */
30 | D9 = 57, /* 9 */
31 |
32 | Semicolon = 59, /* ; */
33 | Equal = 61, /* = */
34 |
35 | A = 65,
36 | B = 66,
37 | C = 67,
38 | D = 68,
39 | E = 69,
40 | F = 70,
41 | G = 71,
42 | H = 72,
43 | I = 73,
44 | J = 74,
45 | K = 75,
46 | L = 76,
47 | M = 77,
48 | N = 78,
49 | O = 79,
50 | P = 80,
51 | Q = 81,
52 | R = 82,
53 | S = 83,
54 | T = 84,
55 | U = 85,
56 | V = 86,
57 | W = 87,
58 | X = 88,
59 | Y = 89,
60 | Z = 90,
61 |
62 | LeftBracket = 91, /* [ */
63 | Backslash = 92, /* \ */
64 | RightBracket = 93, /* ] */
65 | GraveAccent = 96, /* ` */
66 |
67 | World1 = 161, /* non-US #1 */
68 | World2 = 162, /* non-US #2 */
69 |
70 | /* Function keys */
71 | Escape = 256,
72 | Enter = 257,
73 | Tab = 258,
74 | Backspace = 259,
75 | Insert = 260,
76 | Delete = 261,
77 | Right = 262,
78 | Left = 263,
79 | Down = 264,
80 | Up = 265,
81 | PageUp = 266,
82 | PageDown = 267,
83 | Home = 268,
84 | End = 269,
85 | CapsLock = 280,
86 | ScrollLock = 281,
87 | NumLock = 282,
88 | PrintScreen = 283,
89 | Pause = 284,
90 | F1 = 290,
91 | F2 = 291,
92 | F3 = 292,
93 | F4 = 293,
94 | F5 = 294,
95 | F6 = 295,
96 | F7 = 296,
97 | F8 = 297,
98 | F9 = 298,
99 | F10 = 299,
100 | F11 = 300,
101 | F12 = 301,
102 | F13 = 302,
103 | F14 = 303,
104 | F15 = 304,
105 | F16 = 305,
106 | F17 = 306,
107 | F18 = 307,
108 | F19 = 308,
109 | F20 = 309,
110 | F21 = 310,
111 | F22 = 311,
112 | F23 = 312,
113 | F24 = 313,
114 | F25 = 314,
115 |
116 | /* Keypad */
117 | KP0 = 320,
118 | KP1 = 321,
119 | KP2 = 322,
120 | KP3 = 323,
121 | KP4 = 324,
122 | KP5 = 325,
123 | KP6 = 326,
124 | KP7 = 327,
125 | KP8 = 328,
126 | KP9 = 329,
127 | KPDecimal = 330,
128 | KPDivide = 331,
129 | KPMultiply = 332,
130 | KPSubtract = 333,
131 | KPAdd = 334,
132 | KPEnter = 335,
133 | KPEqual = 336,
134 |
135 | LeftShift = 340,
136 | LeftControl = 341,
137 | LeftAlt = 342,
138 | LeftSuper = 343,
139 | RightShift = 344,
140 | RightControl = 345,
141 | RightAlt = 346,
142 | RightSuper = 347,
143 | Menu = 348,
144 | // @formatter:on
145 | };
146 |
147 | inline std::ostream &operator<<(std::ostream &os, KeyCode keyCode) {
148 | os << static_cast(keyCode);
149 | return os;
150 | }
151 | }
152 |
153 | // @formatter:off
154 | #define REAL_KEY_SPACE ::Real::KeyCode::Space
155 | #define REAL_KEY_APOSTROPHE ::real::KeyCode::Apostrophe /* ' */
156 | #define REAL_KEY_COMMA ::real::KeyCode::Comma /* , */
157 | #define REAL_KEY_MINUS ::real::KeyCode::Minus /* - */
158 | #define REAL_KEY_PERIOD ::real::KeyCode::Period /* . */
159 | #define REAL_KEY_SLASH ::real::KeyCode::Slash /* / */
160 | #define REAL_KEY_0 ::real::KeyCode::D0
161 | #define REAL_KEY_1 ::real::KeyCode::D1
162 | #define REAL_KEY_2 ::real::KeyCode::D2
163 | #define REAL_KEY_3 ::real::KeyCode::D3
164 | #define REAL_KEY_4 ::real::KeyCode::D4
165 | #define REAL_KEY_5 ::real::KeyCode::D5
166 | #define REAL_KEY_6 ::real::KeyCode::D6
167 | #define REAL_KEY_7 ::real::KeyCode::D7
168 | #define REAL_KEY_8 ::real::KeyCode::D8
169 | #define REAL_KEY_9 ::real::KeyCode::D9
170 | #define REAL_KEY_SEMICOLON ::real::KeyCode::Semicolon /* ; */
171 | #define REAL_KEY_EQUAL ::real::KeyCode::Equal /* = */
172 | #define REAL_KEY_A ::Real::KeyCode::A
173 | #define REAL_KEY_B ::real::KeyCode::B
174 | #define REAL_KEY_C ::Real::KeyCode::C
175 | #define REAL_KEY_D ::real::KeyCode::D
176 | #define REAL_KEY_E ::real::KeyCode::E
177 | #define REAL_KEY_F ::real::KeyCode::F
178 | #define REAL_KEY_G ::real::KeyCode::G
179 | #define REAL_KEY_H ::real::KeyCode::H
180 | #define REAL_KEY_I ::real::KeyCode::I
181 | #define REAL_KEY_J ::real::KeyCode::J
182 | #define REAL_KEY_K ::real::KeyCode::K
183 | #define REAL_KEY_L ::real::KeyCode::L
184 | #define REAL_KEY_M ::real::KeyCode::M
185 | #define REAL_KEY_N ::real::KeyCode::N
186 | #define REAL_KEY_O ::real::KeyCode::O
187 | #define REAL_KEY_P ::real::KeyCode::P
188 | #define REAL_KEY_Q ::real::KeyCode::Q
189 | #define REAL_KEY_R ::real::KeyCode::R
190 | #define REAL_KEY_S ::real::KeyCode::S
191 | #define REAL_KEY_T ::real::KeyCode::T
192 | #define REAL_KEY_U ::real::KeyCode::U
193 | #define REAL_KEY_V ::Real::KeyCode::V
194 | #define REAL_KEY_W ::real::KeyCode::W
195 | #define REAL_KEY_X ::Real::KeyCode::X
196 | #define REAL_KEY_Y ::Real::KeyCode::Y
197 | #define REAL_KEY_Z ::Real::KeyCode::Z
198 | #define REAL_KEY_LEFT_BRACKET ::real::KeyCode::LeftBracket /* [ */
199 | #define REAL_KEY_BACKSLASH ::real::KeyCode::Backslash /* \ */
200 | #define REAL_KEY_RIGHT_BRACKET ::real::KeyCode::RightBracket /* ] */
201 | #define REAL_KEY_GRAVE_ACCENT ::real::KeyCode::GraveAccent /* ` */
202 | #define REAL_KEY_WORLD_1 ::real::KeyCode::World1 /* non-US #1 */
203 | #define REAL_KEY_WORLD_2 ::real::KeyCode::World2 /* non-US #2 */
204 |
205 | /* Function keys */
206 | #define REAL_KEY_ESCAPE ::Real::KeyCode::Escape
207 | #define REAL_KEY_ENTER ::Real::KeyCode::Enter
208 | #define REAL_KEY_TAB ::Real::KeyCode::Tab
209 | #define REAL_KEY_BACKSPACE ::Real::KeyCode::Backspace
210 | #define REAL_KEY_INSERT ::Real::KeyCode::Insert
211 | #define REAL_KEY_DELETE ::Real::KeyCode::Delete
212 | #define REAL_KEY_RIGHT ::Real::KeyCode::Right
213 | #define REAL_KEY_LEFT ::Real::KeyCode::Left
214 | #define REAL_KEY_DOWN ::Real::KeyCode::Down
215 | #define REAL_KEY_UP ::Real::KeyCode::Up
216 | #define REAL_KEY_PAGE_UP ::Real::KeyCode::PageUp
217 | #define REAL_KEY_PAGE_DOWN ::Real::KeyCode::PageDown
218 | #define REAL_KEY_HOME ::Real::KeyCode::Home
219 | #define REAL_KEY_END ::Real::KeyCode::End
220 | #define REAL_KEY_CAPS_LOCK ::real::KeyCode::CapsLock
221 | #define REAL_KEY_SCROLL_LOCK ::real::KeyCode::ScrollLock
222 | #define REAL_KEY_NUM_LOCK ::real::KeyCode::NumLock
223 | #define REAL_KEY_PRINT_SCREEN ::real::KeyCode::PrintScreen
224 | #define REAL_KEY_PAUSE ::real::KeyCode::Pause
225 | #define REAL_KEY_F1 ::real::KeyCode::F1
226 | #define REAL_KEY_F2 ::real::KeyCode::F2
227 | #define REAL_KEY_F3 ::real::KeyCode::F3
228 | #define REAL_KEY_F4 ::real::KeyCode::F4
229 | #define REAL_KEY_F5 ::real::KeyCode::F5
230 | #define REAL_KEY_F6 ::real::KeyCode::F6
231 | #define REAL_KEY_F7 ::real::KeyCode::F7
232 | #define REAL_KEY_F8 ::real::KeyCode::F8
233 | #define REAL_KEY_F9 ::real::KeyCode::F9
234 | #define REAL_KEY_F10 ::real::KeyCode::F10
235 | #define REAL_KEY_F11 ::real::KeyCode::F11
236 | #define REAL_KEY_F12 ::real::KeyCode::F12
237 | #define REAL_KEY_F13 ::real::KeyCode::F13
238 | #define REAL_KEY_F14 ::real::KeyCode::F14
239 | #define REAL_KEY_F15 ::real::KeyCode::F15
240 | #define REAL_KEY_F16 ::real::KeyCode::F16
241 | #define REAL_KEY_F17 ::real::KeyCode::F17
242 | #define REAL_KEY_F18 ::real::KeyCode::F18
243 | #define REAL_KEY_F19 ::real::KeyCode::F19
244 | #define REAL_KEY_F20 ::real::KeyCode::F20
245 | #define REAL_KEY_F21 ::real::KeyCode::F21
246 | #define REAL_KEY_F22 ::real::KeyCode::F22
247 | #define REAL_KEY_F23 ::real::KeyCode::F23
248 | #define REAL_KEY_F24 ::real::KeyCode::F24
249 | #define REAL_KEY_F25 ::real::KeyCode::F25
250 |
251 | /* Keypad */
252 | #define REAL_KEY_KP_0 ::real::KeyCode::KP0
253 | #define REAL_KEY_KP_1 ::real::KeyCode::KP1
254 | #define REAL_KEY_KP_2 ::real::KeyCode::KP2
255 | #define REAL_KEY_KP_3 ::real::KeyCode::KP3
256 | #define REAL_KEY_KP_4 ::real::KeyCode::KP4
257 | #define REAL_KEY_KP_5 ::real::KeyCode::KP5
258 | #define REAL_KEY_KP_6 ::real::KeyCode::KP6
259 | #define REAL_KEY_KP_7 ::real::KeyCode::KP7
260 | #define REAL_KEY_KP_8 ::real::KeyCode::KP8
261 | #define REAL_KEY_KP_9 ::real::KeyCode::KP9
262 | #define REAL_KEY_KP_DECIMAL ::real::KeyCode::KPDecimal
263 | #define REAL_KEY_KP_DIVIDE ::real::KeyCode::KPDivide
264 | #define REAL_KEY_KP_MULTIPLY ::real::KeyCode::KPMultiply
265 | #define REAL_KEY_KP_SUBTRACT ::real::KeyCode::KPSubtract
266 | #define REAL_KEY_KP_ADD ::real::KeyCode::KPAdd
267 | #define REAL_KEY_KP_ENTER ::Real::KeyCode::KPEnter
268 | #define REAL_KEY_KP_EQUAL ::real::KeyCode::KPEqual
269 |
270 | #define REAL_KEY_LEFT_SHIFT ::Real::KeyCode::LeftShift
271 | #define REAL_KEY_LEFT_CONTROL ::Real::KeyCode::LeftControl
272 | #define REAL_KEY_LEFT_ALT ::Real::KeyCode::LeftAlt
273 | #define REAL_KEY_LEFT_SUPER ::Real::KeyCode::LeftSuper
274 | #define REAL_KEY_RIGHT_SHIFT ::Real::KeyCode::RightShift
275 | #define REAL_KEY_RIGHT_CONTROL ::Real::KeyCode::RightControl
276 | #define REAL_KEY_RIGHT_ALT ::Real::KeyCode::RightAlt
277 | #define REAL_KEY_RIGHT_SUPER ::Real::KeyCode::RightSuper
278 | #define REAL_KEY_MENU ::real::KeyCode::Menu
279 | // @formatter:on
280 |
281 | #endif //REAL_KEYCODE
282 |
--------------------------------------------------------------------------------
/engine/include/real/layer.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_LAYER
4 | #define REAL_LAYER
5 |
6 | #include "real/layer/base_layer.hpp"
7 | #include "real/layer/imgui_layer.hpp"
8 |
9 | #endif //REAL_BASE_LAYER
10 |
--------------------------------------------------------------------------------
/engine/include/real/layer/base_layer.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_LAYER_BASE
4 | #define REAL_LAYER_BASE
5 |
6 | #include "real/time/timestep.hpp"
7 |
8 | #include "real/core.hpp"
9 | #include "real/event.hpp"
10 |
11 | namespace Real
12 | {
13 | class REAL_API Layer
14 | {
15 | public:
16 | Layer() = default;
17 | virtual void OnImGUIRender();
18 |
19 | virtual void Attach();
20 | virtual void Detach();
21 | virtual void Update(Timestep ts);
22 | virtual void HandleEvent(Event& e);
23 | };
24 | }
25 |
26 | #endif //REAL_LAYER_BASE
27 |
--------------------------------------------------------------------------------
/engine/include/real/layer/imgui_layer.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_LAYER_IMGUI
4 | #define REAL_LAYER_IMGUI
5 |
6 | #include "real/core.hpp"
7 | #include "real/layer/base_layer.hpp"
8 |
9 | namespace Real {
10 | class REAL_API ImGUILayer : public Layer {
11 | public:
12 | ImGUILayer();
13 | ~ImGUILayer();
14 |
15 | void Begin();
16 | void End();
17 |
18 | void Attach() override;
19 | void Detach() override;
20 | void HandleEvent(Event &ev) override;
21 | };
22 | }
23 |
24 | #endif //REAL_LAYER_IMGUI
25 |
--------------------------------------------------------------------------------
/engine/include/real/layer_stack.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_LAYER_STACK
4 | #define REAL_LAYER_STACK
5 |
6 | #include "real/core.hpp"
7 | #include "real/layer.hpp"
8 |
9 | namespace Real
10 | {
11 | class REAL_API LayerStack
12 | {
13 | using container = std::vector;
14 | using iterator = container::iterator;
15 | using const_iterator = container::const_iterator;
16 | private:
17 | // TODO: own vector
18 | container stack;
19 | typename container::size_type layerInsert;
20 | public:
21 | LayerStack();
22 | ~LayerStack();
23 |
24 | //region Iterators
25 | iterator begin() noexcept
26 | { return stack.begin(); };
27 | const_iterator cbegin() const noexcept
28 | { return stack.begin(); };
29 | const_iterator begin() const noexcept
30 | { return stack.begin(); };
31 |
32 | iterator end() noexcept
33 | { return stack.end(); };
34 | const_iterator end() const noexcept
35 | { return stack.end(); };
36 | const_iterator cend() const noexcept
37 | { return stack.end(); };
38 | //endregion
39 |
40 | void PushLayer(Layer* layer);
41 | void PopLayer(Layer* layer);
42 |
43 | void PushOverlay(Layer* overlay);
44 | void PopOverlay(Layer* overlay);
45 | };
46 | }
47 |
48 | #endif //REAL_LAYER_STACK
49 |
--------------------------------------------------------------------------------
/engine/include/real/logger.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_LOGGER
4 | #define REAL_LOGGER
5 |
6 | #include
7 |
8 | #include
9 | #include
10 |
11 | #include "real/core.hpp"
12 |
13 | // TODO: new logging!
14 | namespace Real
15 | {
16 | class REAL_API Logger
17 | {
18 | public:
19 | static void Init();
20 |
21 | static std::shared_ptr& Core()
22 | { return coreLogger; }
23 | static std::shared_ptr& Client()
24 | { return clientLogger; }
25 | private:
26 | static std::shared_ptr coreLogger;
27 | static std::shared_ptr clientLogger;
28 | };
29 | }
30 |
31 | // @formatter:off
32 | // Core log macros
33 | #define REAL_CORE_TRACE(...) ::Real::Logger::Core()->trace(__VA_ARGS__)
34 | #define REAL_CORE_INFO(...) ::Real::Logger::Core()->info(__VA_ARGS__)
35 | #define REAL_CORE_WARN(...) ::real::Logger::Core()->warn(__VA_ARGS__)
36 | #define REAL_CORE_ERROR(...) ::Real::Logger::Core()->error(__VA_ARGS__)
37 | #define REAL_CORE_CRITICAL(...) ::real::Logger::Core()->critical(__VA_ARGS__)
38 |
39 | // Client log macros
40 | #define REAL_TRACE(...) ::Real::Logger::Client()->trace(__VA_ARGS__)
41 | #define REAL_INFO(...) ::real::Logger::Client()->info(__VA_ARGS__)
42 | #define REAL_WARN(...) ::real::Logger::Client()->warn(__VA_ARGS__)
43 | #define REAL_ERROR(...) ::real::Logger::Client()->error(__VA_ARGS__)
44 | #define REAL_CRITICAL(...) ::real::Logger::Client()->critical(__VA_ARGS__)
45 | // @formatter:on
46 |
47 |
48 | #endif //REAL_LOGGER
49 |
--------------------------------------------------------------------------------
/engine/include/real/pch.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 udv. All rights reserved.
2 |
3 | #ifndef REAL_PCH
4 | #define REAL_PCH
5 |
6 | // Defines
7 | #include
8 | // Util
9 | #include
10 | #include
11 | #include
12 | // IO
13 | #include
14 | #include
15 | // Structures
16 | #include
17 | #include
18 | #include
19 | #include