diff --git a/.github/workflows/clang_build_win.yml b/.github/workflows/clang_build_win.yml
index 4e37ed5c..9da8914f 100644
--- a/.github/workflows/clang_build_win.yml
+++ b/.github/workflows/clang_build_win.yml
@@ -8,6 +8,7 @@ on:
env:
BUILD_TYPE: Release
+ BUILD_DIR: build
jobs:
build:
@@ -17,7 +18,7 @@ jobs:
- name: Install Vulkan SDK
uses: jakoch/install-vulkan-sdk-action@v1.0.0
with:
- vulkan_version: 1.3.231.1
+ vulkan_version: 1.3.296.0
optional_components: com.lunarg.vulkan.vma
install_runtime: true
cache: true
@@ -33,7 +34,10 @@ jobs:
generator: Ninja
c-compiler: clang
cxx-compiler: clang++
- build-dir: build
+ build-dir: ${{env.BUILD_DIR}}
- name: Build
- run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
+ run: cmake --build ${{github.workspace}}/${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}}
+
+ - name: Run Core Unit Tests
+ run: cmake --build ${{github.workspace}}/${{env.BUILD_DIR}} --target run_core_tests
\ No newline at end of file
diff --git a/.github/workflows/gcc_build_ubuntu.yml b/.github/workflows/gcc_build_ubuntu.yml
new file mode 100644
index 00000000..65c1f03e
--- /dev/null
+++ b/.github/workflows/gcc_build_ubuntu.yml
@@ -0,0 +1,45 @@
+name: Ubuntu GCC Build
+
+on:
+ push:
+ branches: [ "master", "dev" ]
+ pull_request:
+ branches: [ "master", "dev" ]
+
+env:
+ BUILD_TYPE: Release
+ BUILD_DIR: build
+ CMAKE_C_COMPILER: gcc-13
+ CMAKE_CPP_COMPILER: g++-13
+
+jobs:
+ build:
+ runs-on: ubuntu-24.04
+
+ steps:
+ - uses: actions/checkout@v1
+ with:
+ submodules: recursive
+
+ - name: Install Vulkan SDK
+ uses: jakoch/install-vulkan-sdk-action@v1.0.0
+ with:
+ optional_components: com.lunarg.vulkan.vma
+ install_runtime: true
+ cache: true
+ stripdown: true
+
+ - name: Install GCC 13
+ run: sudo apt-get update && sudo apt-get -y install g++-13
+
+ - name: Install Ninja
+ run: sudo apt install ninja-build
+
+ - name: Configure CMake
+ run: cmake -B ${{env.BUILD_DIR}} -D CMAKE_C_COMPILER=/usr/bin/gcc-13 -D CMAKE_CXX_COMPILER=/usr/bin/g++-13 -G Ninja
+
+ - name: Build
+ run: cmake --build ${{github.workspace}}/${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}}
+
+ - name: Run Core Unit Tests
+ run: cmake --build ${{github.workspace}}/${{env.BUILD_DIR}} --target run_core_tests
\ No newline at end of file
diff --git a/.github/workflows/mingw_gcc_build_win.yml b/.github/workflows/mingw_gcc_build_win.yml
index ca536c74..d03e7f15 100644
--- a/.github/workflows/mingw_gcc_build_win.yml
+++ b/.github/workflows/mingw_gcc_build_win.yml
@@ -8,6 +8,7 @@ on:
env:
BUILD_TYPE: Release
+ BUILD_DIR: build
jobs:
build:
@@ -17,7 +18,7 @@ jobs:
- name: Install Vulkan SDK
uses: jakoch/install-vulkan-sdk-action@v1.0.0
with:
- vulkan_version: 1.3.231.1
+ vulkan_version: 1.3.296.0
optional_components: com.lunarg.vulkan.vma
install_runtime: true
cache: true
@@ -33,7 +34,10 @@ jobs:
generator: Ninja
c-compiler: gcc
cxx-compiler: g++
- build-dir: build
+ build-dir: ${{env.BUILD_DIR}}
- name: Build
- run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
+ run: cmake --build ${{github.workspace}}/${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}}
+
+ - name: Run Core Unit Tests
+ run: cmake --build ${{github.workspace}}/${{env.BUILD_DIR}} --target run_core_tests
\ No newline at end of file
diff --git a/.github/workflows/ubuntu-latest.yml b/.github/workflows/ubuntu-latest.yml
deleted file mode 100644
index f4829642..00000000
--- a/.github/workflows/ubuntu-latest.yml
+++ /dev/null
@@ -1,45 +0,0 @@
-name: Ubuntu Build
-
-on:
- push:
- branches: [ "master", "dev" ]
- pull_request:
- branches: [ "master", "dev" ]
-
-env:
- BUILD_TYPE: Release
-
-jobs:
- build:
- runs-on: ubuntu-latest
-
- steps:
- - uses: actions/checkout@v1
- with:
- submodules: recursive
-
- - name: Install prerequisites
- run: sudo apt-get update && sudo apt-get install libxrandr-dev xorg-dev
-
- - name: Install Vulkan 0
- run: wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo tee /etc/apt/trusted.gpg.d/lunarg.asc
-
- - name: Install Vulkan 1
- run: sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list http://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
-
- - name: Install Vulkan 2
- run: sudo apt update
-
- - name: Install Vulkan 3
- run: sudo apt install vulkan-sdk
-
- - name: Configure CMake
- uses: threeal/cmake-action@v1.3.0
- with:
- generator: Ninja
- c-compiler: gcc
- cxx-compiler: g++
- build-dir: build
-
- - name: Build
- run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
diff --git a/.gitignore b/.gitignore
index 8c557ffc..c58c2f65 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,6 @@ build
/.idea/
make.bat
test.bat
-imgui.ini
\ No newline at end of file
+imgui.ini
+.vs
+./out
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
index d556ed06..abd1d5e6 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,19 +4,16 @@
[submodule "3dparty/glad"]
path = 3dparty/glad
url = https://github.com/Maksasj/glad
-[submodule "3dparty/Vulkan-Headers"]
- path = 3dparty/Vulkan-Headers
- url = https://github.com/Maksasj/Vulkan-Headers.git
-[submodule "3dparty/omni_types"]
- path = 3dparty/omni_types
- url = https://github.com/Maksasj/omni_types
-
[submodule "3dparty/stb"]
path = 3dparty/stb
url = https://github.com/Maksasj/stb
-[submodule "3dparty/imgui"]
- path = 3dparty/imgui
- url = https://github.com/Maksasj/imgui
[submodule "3dparty/glslang"]
path = 3dparty/glslang
url = https://github.com/Maksasj/glslang
+[submodule "3dparty/miniaudio"]
+ path = 3dparty/miniaudio
+ url = https://github.com/Maksasj/miniaudio
+[submodule "3dparty/google-test"]
+ path = 3dparty/google-test
+ url = https://github.com/Soskar1/googletest.git
+ branch = v1.14.x
diff --git a/3dparty/CMakeLists.txt b/3dparty/CMakeLists.txt
index f6bbbd30..2d5ab77e 100644
--- a/3dparty/CMakeLists.txt
+++ b/3dparty/CMakeLists.txt
@@ -1,9 +1,5 @@
add_subdirectory(glad)
-set(OMNI_GLAD_INTEGRATION ON)
-include_directories("glad/include")
-add_subdirectory(omni_types)
-
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
@@ -15,8 +11,8 @@ set(SHADERC_SKIP_EXAMPLES ON)
set(SHADERC_SKIP_COPYRIGHT_CHECK ON)
add_subdirectory(glslang)
-add_subdirectory("Vulkan-Headers")
-
add_subdirectory(stb)
+add_subdirectory(miniaudio)
-add_subdirectory(imgui)
+add_subdirectory(google-test)
+include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
\ No newline at end of file
diff --git a/3dparty/Vulkan-Headers b/3dparty/Vulkan-Headers
deleted file mode 160000
index a3b68365..00000000
--- a/3dparty/Vulkan-Headers
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit a3b683653e6a498514ef8a1865594810e91c594c
diff --git a/3dparty/glslang b/3dparty/glslang
index 0015dc93..7c4d91e7 160000
--- a/3dparty/glslang
+++ b/3dparty/glslang
@@ -1 +1 @@
-Subproject commit 0015dc9345ff9572af60801948c82b7ebce5ddb3
+Subproject commit 7c4d91e7819a1d27213aa3499953d54ae1a00e8f
diff --git a/3dparty/google-test b/3dparty/google-test
new file mode 160000
index 00000000..f8d7d77c
--- /dev/null
+++ b/3dparty/google-test
@@ -0,0 +1 @@
+Subproject commit f8d7d77c06936315286eb55f8de22cd23c188571
diff --git a/3dparty/imgui b/3dparty/imgui
deleted file mode 160000
index 5f40784f..00000000
--- a/3dparty/imgui
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 5f40784f4794d7fd6a4f330f277e0f10f7b96f77
diff --git a/3dparty/miniaudio b/3dparty/miniaudio
new file mode 160000
index 00000000..b487e015
--- /dev/null
+++ b/3dparty/miniaudio
@@ -0,0 +1 @@
+Subproject commit b487e015d220570f648347cadef05dca18212127
diff --git a/3dparty/omni_types b/3dparty/omni_types
deleted file mode 160000
index 6fa7d38f..00000000
--- a/3dparty/omni_types
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 6fa7d38f621aa7ff80e2643579b9b08becbf2564
diff --git a/3dparty/stb b/3dparty/stb
index 0763cb3b..ae3bde09 160000
--- a/3dparty/stb
+++ b/3dparty/stb
@@ -1 +1 @@
-Subproject commit 0763cb3b70c8475f8d351f35a93adf8f3ad97baf
+Subproject commit ae3bde090e8e317b7dbaa76c84ed78507b52d0c9
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f23a7704..df453ae0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,10 +3,10 @@ project(Bebone)
# Bebone versions
set(BEBONE_VERSION_MAJOR 0 CACHE STRING "Bebone major version")
-set(BEBONE_VERSION_MINOR 1 CACHE STRING "Bebone minor version")
-set(BEBONE_VERSION_PATCH 1 CACHE STRING "Bebone patch version")
+set(BEBONE_VERSION_MINOR 2 CACHE STRING "Bebone minor version")
+set(BEBONE_VERSION_PATCH 0 CACHE STRING "Bebone patch version")
-set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT CMAKE_BUILD_TYPE)
@@ -22,9 +22,9 @@ if(CMAKE_BUILD_TYPE MATCHES Release)
endif()
if(MSVC)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
else()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++2b")
endif()
# Bebone build options
@@ -34,9 +34,10 @@ option(BEBONE_TESTS "Bebone build all tests" ON)
option(BEBONE_BUILD_CORE "Bebone build core module" ON)
option(BEBONE_BUILD_ASSETS "Bebone build assets module" ON)
option(BEBONE_BUILD_GFX "Bebone build gfx module" ON)
+option(BEBONE_BUILD_RENDERER "Bebone build renderer module" ON)
+option(BEBONE_BUILD_SOUND "Bebone build sound module" ON)
add_subdirectory(3dparty)
-
add_subdirectory(src)
if(BEBONE_EXAMPLES)
@@ -45,4 +46,4 @@ endif()
if(BEBONE_TESTS)
add_subdirectory(tests)
-endif()
+endif()
\ No newline at end of file
diff --git a/LICENSE.md b/LICENSE.md
index 828dfe8a..7dc91c9a 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,21 +1,201 @@
-MIT License
-
-Copyright (c) 2023 Maksim Jaroslavcevas, Oskaras Vištorskis, Vadim Elkin
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2024 [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/README.md b/README.md
index 0df65664..93b401e2 100644
--- a/README.md
+++ b/README.md
@@ -1,110 +1,129 @@
-# Bebone
-Bebone - Is a framework/engine aimed for flexible and comfortable game development, written in C++.
-In other words Bebone is a set of useful game development libraries, written and integrated
-in Bebone framework ecosystem.
+# bebone 💀
-> Bebone is not a new javascript framework btw. It is a game development one!
+Modular game development framework/engine written with **C++**. **Bebone** implements **high-level** abstractions, as well as provides access to **low-level** internal abstractions for **flexible** and **highly customizable** game development
+
+- **Modular code base**, every **bebone** module is a self contained library with **minimal** dependency on **third-party** libraries. All **bebone** abstractions inherit same **interfaces**, for better integration with user defined abstractions
+- **Designed with real-world use in mind** for small hobby projects, as well as professional/enterprise projects.
+- **User-Friendly** for **all experience levels**. Designed to be intuitive and easy to use for **beginners**, as well as experienced professionals
+
+> **Bebone** is not a new javascript framework btw. It is a game development one!
Cool looking widgets
-
-
-
-
-## Features
-* Core module
- * Arena allocator & container
- * Logger
- * Types library
- * Event submodule
- * Listener system (Java style)
- * Action delegate (C# style)
- * Input system
- * Meta programming module
-* Graphics module
- * OpenGL abstraction layer
- * Vulkan abstraction layer (in development)
- * Shaders
- * Window
- * Begui (Dear ImGui abstraction layer)
-## Build
-For now there is two methods how you can use bebone is your project(build locally).
-1. **Build manually**
- First of all requirements:
- - Cmake (At least version 3.21)
- - Ninja (At least version 1.11.1)
- - C++ compiler (Have test with Clang 15.0.5 and GCC 12.2.0)
- - *Vulkan SDK (if you want to build gfx module)*
-
- Firstly lets clone bebone locally(note that you also need to clone all bebone git submodules).
-
- Secondly lets configure our Cmake configuration with
- ```bash
- cmake -B build -G Ninja
- ```
-
- Finally you can simply build project with cmake
- ```bash
- cmake --build build
- ```
-
-2. **Using docker**
- Currently the docker image is not available, but we are planning to release it towards bebone 0.2v.
-
-Note that bebone is only a **set** of useful libraries/modules, some modules can be used separately.
-
-## Testing
-The testing process is similar to the **Building**. After a successful build, all you have to do is run CTest from ```build\tests\unit``` directory.
-
-## Dependencies
-For convenience, we try to reduce the use of third-party libraries, as it complicates code management and readability.
-At the moment, bebone is only dependent on these libraries:
- - [Glad](https://github.com/Maksasj/glad/tree/all-extensions) *(opengl function header)*
- - [Vulkan-Headers](https://github.com/Maksasj/Vulkan-Headers/tree/main) *(vulkan function header)*
- - [GLFW](https://github.com/Maksasj/glfw/tree/master) *(window management library)*
+
+
+
+
+
+### Links
+1. Source code available at [github.com/Maksasj/bebone](https://github.com/Maksasj/bebone)
+2. Community Discord [discord.gg/bebone](https://discord.gg/v4mcTmuDTb)
+3. **Bebone** documentation available at [github.com/Maksasj/bebone](github.com/Maksasj/bebone/docs/DOCUMENTATION.md)
+
+## Architecture ⚙️
+
+**Bebone** provides multi layer APIs where each level build on top of previous:
+
+- **[Abstraction]()** - basic abstraction layer. Abstracts most basic things, such as OpenGL or Vulkan
+- **[System]()** - advance abstraction layer. Implements generalized systems on top of abstraction layer, such as Renderer
+- **[App]()** - complete application layer. Combines multiple systems into self-contained application
+
+## Features ✨
+
+For now **bebone** has several modules:
+
+* [Core module](). Core **bebone** module implements most important abstractions which are widely used across all other modules. Implements **Memory, Debug, Types, Event, Input** abstractions
+* [Graphics module (GFX module)](). **Abstraction layer** module, implements basic abstractions on top of **Graphical APIs** such as **OpenGL** and **Vulkan**. **GFX module**
+ depends on **Core**, **Assets** modules
+* [Assets module](). Module designed for loading and managing different **assets** such as **images**, **models**, **materals**. **Assets module** depends on **Core module** only
+* [Renderer module]() **System layer** module, provides high-level generalized graphical functionality. It abstracts all low-level **OpenGL** or **Vulkan** under one convenient interface. This module is build on top of **GFX module**
+* [Sound module]() *Todo*
+
+### Planned modules
+* [Physics module]()
+* [Entity component system module (ECS module)]()
+* [App module]()
+
+## Build 🛠
+
+First of all requirements
+ - [CMake](https://cmake.org/) (At least version 3.21)
+ - [Ninja](https://github.com/ninja-build/ninja) (At least version 1.11.1)
+ - C++ compiler (Have test with Clang 15.0.5 and GCC 12.2.0)
+ - *[Vulkan SDK](https://www.lunarg.com/vulkan-sdk/) (if you want to build [GFX module]())*
+
+ Firstly lets clone **bebone** locally *(note that you also need to clone all bebone git submodules with `--recursive` flag)*
+
+ ```bash
+ git clone --recursive git@github.com:Maksasj/bebone.git
+ ```
+
+ Secondly lets configure our **CMake** configuration with
+ ```bash
+ cmake -B build -G Ninja
+ ```
+
+ Finally you can simply build project with cmake
+ ```bash
+ cmake --build build
+ ```
+
+## Testing 💊
+### Unit testing
+The testing process is similar to the **Building**. After a successful build, all you have to do is run [CTest](https://cmake.org/cmake/help/book/mastering-cmake/chapter/Testing%20With%20CMake%20and%20CTest.html) from ```build\tests\unit``` directory
+
+### Integration testing
+As for integration tests we use our examples, so see **[Examples]()** section
+
+## Dependencies 🗃
+For convenience, we tried to reduce the use of third-party libraries, as it complicates code management and readability.
+At the moment, bebone is only dependent on these third-party libraries:
+ - [Glad](https://github.com/Maksasj/glad/tree/all-extensions) *(OpenGL function header)*
+ - [Vulkan-Headers](https://github.com/Maksasj/Vulkan-Headers/tree/main) *(Vulkan function header)*
+ - [GLFW](https://github.com/Maksasj/glfw/tree/master) *(Window management library)*
- [Glslang](https://github.com/KhronosGroup/glslang/tree/main) *(SPIR-V shader compiler library)*
- - [imgui](https://github.com/Maksasj/imgui/tree/master) *(Debug gui library)*
- - [omni_types](https://github.com/Maksasj/omni_types/tree/master) *(Type library)*
+ - [imgui](https://github.com/Maksasj/imgui/tree/master) *(Debug GUI library)*
- [stb](https://github.com/Maksasj/stb/tree/master) *(Image management library and others)*
+ - [miniaudio](https://github.com/Maksasj/miniaudio/tree/master) *(Sound and Music library)*
-## Examples
-Bebone hello world example:
+## Examples 🤡
+You can find examples in [examples](https://github.com/Maksasj/bebone/tree/master/examples) directory.
+
+### Minimal example
```c++
#include "bebone/bebone.h"
+using namespace bebone::renderer;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
int main() {
- GLFWContext::init();
-
- auto window = WindowFactory::create_window("Example", 800, 600, GfxAPI::OPENGL);
-
- GLContext::load_opengl();
- GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
-
- while (!window->closing()) {
- GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
- GLContext::clear(GL_COLOR_BUFFER_BIT);
+ auto window = WindowFactory::create_window("Example", 800, 600);
+ auto renderer = RendererFactory::create_renderer(window);
- // Your game code
+ auto sprite = renderer->load_sprite("sprite.png");
- GLFWContext::swap_buffers(*window);
- GLFWContext::poll_events();
- window->execute_input_actions();
+ while(!window->closing()) {
+ renderer->render(sprite, { .position = Vec3f::zero });
+ renderer->present();
}
- GLFWContext::terminate();
return 0;
}
-
```
-You can find other examples in [examples](https://github.com/Maksasj/bebone/tree/master/examples) directory.
+## Documentation 📑
+ - [Core module](https://github.com/Maksasj/bebone/blob/master/docs/core/CORE.md)
+ - [Assets module](https://github.com/Maksasj/bebone/blob/master/docs/assets/ASSETS.md)
+ - [GFX module](https://github.com/Maksasj/bebone/blob/master/docs/gfx/GFX.md)
+ - [Renderer module](https://github.com/Maksasj/bebone/blob/master/docs/renderer/RENDERER.md)
+ - [Sound module](https://github.com/Maksasj/bebone/blob/master/docs/sound/SOUND.md)
+
+For full documentation see [DOCUMENTATION.md](https://github.com/Maksasj/bebone/blob/master/docs/DOCUMENTATION.md) file
+
+## Contribution 🫶
+Since for now no one cares about **bebone** we do not have any instructions or pull request templates, so just open [issue](https://github.com/Maksasj/bebone/issues).
-## Documentation
- - [Core module](https://github.com/Maksasj/bebone/blob/master/docs/Core.md)
- - [GFX module](https://github.com/Maksasj/bebone/blob/master/docs/Gfx.md)
+## License 🛡
+**Bebone** is free and open source game development framework. All code in this repository is licensed under
+- Apache-2.0 license ([LICENSE.md](https://github.com/Maksasj/bebone/blob/master/LICENSE.md) or http://www.apache.org/licenses/LICENSE-2.0)
-## License
-Bebone is free, open source game development framework. All code in this repository FOR NOW is licensed under
-- MIT License ([LICENSE.md](https://github.com/Maksasj/bebone/blob/master/LICENSE.md) or https://opensource.org/license/mit/)
+*Copyright 2023 © Maksim Jaroslavcevas, Oskaras Vištorskis*
\ No newline at end of file
diff --git a/docs/DOCUMENTATION.md b/docs/DOCUMENTATION.md
new file mode 100644
index 00000000..2809866a
--- /dev/null
+++ b/docs/DOCUMENTATION.md
@@ -0,0 +1,9 @@
+# bebone documentation
+
+### Sections
+- [Core]()
+ - [Events]()
+ - [Input]()
+- [Gfx]()
+ - [OpenGL]()
+ - [Vulkan]()
\ No newline at end of file
diff --git a/docs/core/CORE.md b/docs/core/CORE.md
new file mode 100644
index 00000000..5eea07b1
--- /dev/null
+++ b/docs/core/CORE.md
@@ -0,0 +1,5 @@
+# Core module
+
+### Articles
+- [Events]()
+- [Input]()
\ No newline at end of file
diff --git a/docs/Core.md b/docs/core/EVENTS.md
similarity index 89%
rename from docs/Core.md
rename to docs/core/EVENTS.md
index 68bbaf96..59c3eb50 100644
--- a/docs/Core.md
+++ b/docs/core/EVENTS.md
@@ -1,4 +1,4 @@
-# Core module
+# Events
## Action delegate(C# style)
Action delegate is a function object container which can subscribe to the specific functions or unsubscribe from them. Also, it can execute all functions to which action is subscribed. Action delegate can subscribe only to those functions who have void return type and some arguments (or without arguments) Action delegate is similar to the C# Action.
@@ -121,14 +121,15 @@ In Bebone you can use event-based input system to add some actions to your keys.
Input system works with ```Action<>``` delegate. Because of this feature, you will subscribe/unsubscribe your keyboard keys and mouse buttons to the 'in-game actions' (such as jumping, running, etc.). You can do this with these two methods:
```c++
-void register_key_action(const KeyCode& keyCode, std::function& action, const InputType& inputType = InputType::PRESS);
-void remove_key_action(const KeyCode& keyCode, std::function& action, const InputType& inputType = InputType::PRESS);
+void register_key_action(const KeyCode& key_code, std::function& action, const InputType& input_type = InputType::Press);
+void remove_key_action(const KeyCode& key_code, std::function& action, const InputType& input_type = InputType::Press);
```
* KeyCode — enum, which specifies the key to which you can subscribe an action
* action — 'in-game action'
-* inputType — enum, which specifies in which case the action will be executed (by default it is set to PRESS)
+* input_type — enum, which specifies in which case the action will be executed (by default it is set to Press)
+
+Add this command line inside the window loop to allow the framework to handle all the user input:
-All that is left to do is to add one command line inside the window loop to allow the framework to handle all the user input (maybe we will change it later):
```c++
window->execute_input_actions();
```
@@ -141,12 +142,11 @@ const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
int main() {
glfwInit();
- auto window = WindowFactory::create_window("0. Input example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("0. Input example", SCR_WIDTH, SCR_HEIGHT, OpenGL);
GLContext::load_opengl();
GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
@@ -173,4 +173,4 @@ int main() {
glfwTerminate();
return 0;
}
-```
\ No newline at end of file
+```
diff --git a/docs/core/INPUT.md b/docs/core/INPUT.md
new file mode 100644
index 00000000..bd8f0c3c
--- /dev/null
+++ b/docs/core/INPUT.md
@@ -0,0 +1,60 @@
+# Input
+
+## Input System
+In Bebone you can use event-based input system to add some actions to your keys. Input class — is a singleton class, so you can get it's instance anywhere in your codebase.
+
+Input system works with ```Action<>``` delegate. Because of this feature, you will subscribe/unsubscribe your keyboard keys and mouse buttons to the 'in-game actions' (such as jumping, running, etc.). You can do this with these two methods:
+```c++
+void register_key_action(const KeyCode& key_code, std::function& action, const InputType& input_type = InputType::Press);
+void remove_key_action(const KeyCode& key_code, std::function& action, const InputType& input_type = InputType::Press);
+```
+* KeyCode — enum, which specifies the key to which you can subscribe an action
+* action — 'in-game action'
+* input_type — enum, which specifies in which case the action will be executed (by default it is set to Press)
+
+All that is left to do is to add one command line inside the window loop to allow the framework to handle all the user input (maybe we will change it later):
+```c++
+window->execute_input_actions();
+```
+
+Example usage:
+```с++
+#include "bebone/bebone.h"
+
+const unsigned int SCR_WIDTH = 800;
+const unsigned int SCR_HEIGHT = 600;
+
+using namespace bebone::gfx;
+using namespace bebone::gfx::opengl;
+
+int main() {
+ glfwInit();
+
+ auto window = WindowFactory::create_window("0. Input example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OpenGL);
+
+ GLContext::load_opengl();
+ GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
+
+ // in-game action
+ std::function keyPress = []() {
+ std::cout << "key press\n";
+ };
+
+ // registering the key
+ Input::get_instance().register_key_action(KeyCode::A, keyPress);
+
+ while (!window->closing()) {
+ GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
+ GLContext::clear(GL_COLOR_BUFFER_BIT);
+
+ // without this your input will not work!
+ window->execute_input_actions();
+
+ glfwSwapBuffers(window->get_backend());
+ glfwPollEvents();
+ }
+
+ glfwTerminate();
+ return 0;
+}
+```
\ No newline at end of file
diff --git a/docs/gfx/GFX.md b/docs/gfx/GFX.md
new file mode 100644
index 00000000..90f7bc1d
--- /dev/null
+++ b/docs/gfx/GFX.md
@@ -0,0 +1,5 @@
+# GFX module
+
+### Articles
+- [OpenGL]()
+- [Vulkan]()
\ No newline at end of file
diff --git a/docs/Gfx.md b/docs/gfx/OPENGL.md
similarity index 94%
rename from docs/Gfx.md
rename to docs/gfx/OPENGL.md
index 96ea64f4..612bf56f 100644
--- a/docs/Gfx.md
+++ b/docs/gfx/OPENGL.md
@@ -19,12 +19,11 @@ const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
int main() {
glfwInit();
- auto window = WindowFactory::create_window("0. OpenGL window example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("0. OpenGL window example", SCR_WIDTH, SCR_HEIGHT, OpenGL);
GLContext::load_opengl();
GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
@@ -117,14 +116,14 @@ To use shaders in OpenGL Bebone you will need to use the GLShaderFactory, GLShad
### GLShaderFactory
GLShaderFactory creates shader objects (GLShader) which later need to be assigned to the shader program (GLShaderProgram). GLShaderFactory has only one public method for shader creation:
```c++
-static GLShader create_shader(const std::string& path, const ShaderType& shaderType, const GLShaderProperties& properties = NONE);
+static GLShader create_shader(const std::string& path, const ShaderType& shaderType, const GLShaderProperties& properties = None);
```
You need to specify the path to the glsl shader, it's type (vertex/fragment shader) and other properties (enable uniforms or not)
Simple example usage:
```c++
-GLShader vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
-GLShader fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
+GLShader vertexShader = GLShaderFactory::create_shader("vertex.glsl", VertexShader);
+GLShader fragmentShader = GLShaderFactory::create_shader("fragment.glsl", FragmentShader);
```
### GLShader
@@ -132,14 +131,14 @@ In OpenGL, a Shader is a user-defined program designed to run on some stage of a
Firstly lets create our shader. The easiest and simplest way to create a shader is to use GLShaderFactory, like this:
```c++
-auto vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
-auto fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
+auto vertexShader = GLShaderFactory::create_shader("vertex.glsl", VertexShader);
+auto fragmentShader = GLShaderFactory::create_shader("fragment.glsl", FragmentShader);
```
As you see you need only to specify path to shader source code and shader type, after this you can use your shader for creating your shader program.
Second way is using GLShader constructor:
```c++
-GLShader(const ShaderCode& code, const ShaderType& shaderType, const GLShaderProperties& properties = NONE);
+GLShader(const ShaderCode& code, const ShaderType& shaderType, const GLShaderProperties& properties = None);
```
As you see there you have a bit more controll on creating your opengl shader. You can compile your opengl shader code manually using ShaderCompiler and then use shader code as input for GLShader constructor.
@@ -168,7 +167,6 @@ const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
const std::vector vertices = {
{-0.5f, -0.5f, 0.0f},
@@ -183,13 +181,13 @@ const std::vector indices = {
int main() {
GLFWContext::init();
- auto window = WindowFactory::create_window("1. OpenGL hello triangle example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("1. OpenGL hello triangle example", SCR_WIDTH, SCR_HEIGHT, OpenGL);
GLContext::load_opengl();
GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
- GLShader vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
- GLShader fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
+ GLShader vertexShader = GLShaderFactory::create_shader("vertex.glsl", VertexShader);
+ GLShader fragmentShader = GLShaderFactory::create_shader("fragment.glsl", FragmentShader);
GLShaderProgram shaderProgram(vertexShader, fragmentShader);
vertexShader.destroy();
@@ -253,7 +251,6 @@ const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
struct Vertex {
Vec3f pos;
@@ -276,13 +273,13 @@ const std::vector indices {
int main() {
GLFWContext::init();
- auto window = WindowFactory::create_window("2. OpenGL texture example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("2. OpenGL texture example", SCR_WIDTH, SCR_HEIGHT, OpenGL);
GLContext::load_opengl();
GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
- auto vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
- auto fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
+ auto vertexShader = GLShaderFactory::create_shader("vertex.glsl", VertexShader);
+ auto fragmentShader = GLShaderFactory::create_shader("fragment.glsl", FragmentShader);
GLShaderProgram shaderProgram(vertexShader, fragmentShader);
vertexShader.destroy();
diff --git a/docs/gfx/VULKAN.md b/docs/gfx/VULKAN.md
new file mode 100644
index 00000000..e69de29b
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 3a0b578a..47338be2 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,15 +1,8 @@
cmake_minimum_required(VERSION 3.21)
project(BeboneExamples)
-include_directories("./")
-include_directories("../src")
-include_directories("../3dparty/glad/include")
-include_directories("../3dparty/glfw/include")
-include_directories("../3dparty/Vulkan-Headers/include")
-include_directories("../3dparty/omni_types/src")
-include_directories("../3dparty/stb")
-include_directories("../3dparty/imgui")
-
-add_subdirectory(gfx)
add_subdirectory(assets)
add_subdirectory(core)
+add_subdirectory(gfx)
+add_subdirectory(renderer)
+add_subdirectory(sound)
diff --git a/examples/assets/0_assets_image_basic/CMakeLists.txt b/examples/assets/0_assets_image_basic/CMakeLists.txt
index dda6bb40..3c36a2f4 100644
--- a/examples/assets/0_assets_image_basic/CMakeLists.txt
+++ b/examples/assets/0_assets_image_basic/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_ASSETS_0_IMAGE_BASIC *.cpp)
-include_directories("../../src")
include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Assets_0_Image_Basic ${BEBONE_EXAMPLE_ASSETS_0_IMAGE_BASIC})
target_link_libraries(Bebone_Example_Assets_0_Image_Basic bebone)
\ No newline at end of file
diff --git a/examples/assets/0_assets_image_basic/main.cpp b/examples/assets/0_assets_image_basic/main.cpp
index e74f395d..61f7391a 100644
--- a/examples/assets/0_assets_image_basic/main.cpp
+++ b/examples/assets/0_assets_image_basic/main.cpp
@@ -2,16 +2,15 @@
#include
-const unsigned int SCR_WIDTH = 512;
-const unsigned int SCR_HEIGHT = 512;
+const unsigned int screen_width = 512;
+const unsigned int screen_height = 512;
using namespace bebone::assets;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
struct Vertex {
Vec3f pos;
- Vec2f texCord;
+ Vec2f tex_coords;
};
const std::vector vertices {
@@ -27,20 +26,18 @@ const std::vector indices {
};
int main() {
- GLFWContext::init();
-
- auto window = WindowFactory::create_window("0. Image example basic", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("0. Image example basic", screen_width, screen_height, OpenGL);
GLContext::load_opengl();
- GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
+ GLContext::set_viewport(0, 0, screen_width, screen_height);
- auto vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
- auto fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
- GLShaderProgram shaderProgram(vertexShader, fragmentShader);
- shaderProgram.set_uniform("ourTexture", 0);
+ auto vertex_shader = GLShaderFactory::create_shader("vertex.glsl", ShaderType::VertexShader);
+ auto fragment_shader = GLShaderFactory::create_shader("fragment.glsl", ShaderType::FragmentShader);
+ GLShaderProgram shader_program(vertex_shader, fragment_shader);
+ shader_program.set_uniform("ourTexture", 0);
- vertexShader.destroy();
- fragmentShader.destroy();
+ vertex_shader.destroy();
+ fragment_shader.destroy();
GLVertexArrayObject vao;
vao.bind();
@@ -49,7 +46,7 @@ int main() {
GLElementBufferObject ebo(indices.data(), indices.size() * sizeof(u32));
vao.link_attributes(vbo, 0, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, pos));
- vao.link_attributes(vbo, 1, 2, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, texCord));
+ vao.link_attributes(vbo, 1, 2, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, tex_coords));
vao.unbind();
vbo.unbind();
@@ -64,14 +61,14 @@ int main() {
auto texture = make_shared(image);
window->add_listener([&](InputMouseButtonEvent& event) {
- double xPos, yPos;
- glfwGetCursorPos(window->get_backend(), &xPos, &yPos);
+ double x_pos, y_pos;
+ glfwGetCursorPos(window->get_backend(), &x_pos, &y_pos);
if(event.button == GLFW_MOUSE_BUTTON_LEFT) {
- painter.paint_circle(xPos, yPos, 20, ColorRGBA::RED);
+ painter.paint_circle(x_pos, y_pos, 20, ColorRGBA::RED);
texture = make_shared(image);
} else if(event.button == GLFW_MOUSE_BUTTON_RIGHT) {
- painter.paint_square(xPos, yPos, 5, 5, ColorRGBA::BLUE);
+ painter.paint_square(x_pos, y_pos, 5, 5, ColorRGBA::BLUE);
texture = make_shared(image);
}
});
@@ -82,15 +79,11 @@ int main() {
}
});
- GLContext::enable(GL_CULL_FACE);
- GLContext::cull_face(GL_BACK);
- GLContext::front_face(GL_CW);
-
while (!window->closing()) {
GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
GLContext::clear(GL_COLOR_BUFFER_BIT);
- shaderProgram.enable();
+ shader_program.enable();
texture->bind();
vao.bind();
@@ -98,10 +91,8 @@ int main() {
GLContext::draw_elements(GL_TRIANGLES, static_cast(indices.size()), GL_UNSIGNED_INT, nullptr);
glfwSwapBuffers(window->get_backend());
- GLFWContext::poll_events();
+ window->pull_events();
}
- GLFWContext::terminate();
-
return 0;
}
diff --git a/examples/assets/1_assets_image_advance/CMakeLists.txt b/examples/assets/1_assets_image_advance/CMakeLists.txt
index 410b9a80..9e6e1585 100644
--- a/examples/assets/1_assets_image_advance/CMakeLists.txt
+++ b/examples/assets/1_assets_image_advance/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_ASSETS_1_IMAGE_ADVANCE *.cpp)
-include_directories("../../src")
include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Assets_1_Image_Advance ${BEBONE_EXAMPLE_ASSETS_1_IMAGE_ADVANCE})
target_link_libraries(Bebone_Example_Assets_1_Image_Advance bebone)
\ No newline at end of file
diff --git a/examples/assets/1_assets_image_advance/main.cpp b/examples/assets/1_assets_image_advance/main.cpp
index e88d84bb..fde6d276 100644
--- a/examples/assets/1_assets_image_advance/main.cpp
+++ b/examples/assets/1_assets_image_advance/main.cpp
@@ -7,11 +7,10 @@ const unsigned int SCR_HEIGHT = 512;
using namespace bebone::assets;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
struct Vertex {
Vec3f pos;
- Vec2f texCord;
+ Vec2f tex_coords;
};
const std::vector vertices {
@@ -27,20 +26,18 @@ const std::vector indices {
};
int main() {
- GLFWContext::init();
-
- auto window = WindowFactory::create_window("1. Image example advance", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("1. Image example advance", SCR_WIDTH, SCR_HEIGHT, OpenGL);
GLContext::load_opengl();
GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
- auto vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
- auto fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
- GLShaderProgram shaderProgram(vertexShader, fragmentShader);
- shaderProgram.set_uniform("ourTexture", 0);
+ auto vertex_shader = GLShaderFactory::create_shader("vertex.glsl", ShaderType::VertexShader);
+ auto fragment_shader = GLShaderFactory::create_shader("fragment.glsl", ShaderType::FragmentShader);
+ GLShaderProgram shader_program(vertex_shader, fragment_shader);
+ shader_program.set_uniform("ourTexture", 0);
- vertexShader.destroy();
- fragmentShader.destroy();
+ vertex_shader.destroy();
+ fragment_shader.destroy();
GLVertexArrayObject vao;
vao.bind();
@@ -49,7 +46,7 @@ int main() {
GLElementBufferObject ebo(indices.data(), indices.size() * sizeof(u32));
vao.link_attributes(vbo, 0, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, pos));
- vao.link_attributes(vbo, 1, 2, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, texCord));
+ vao.link_attributes(vbo, 1, 2, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, tex_coords));
vao.unbind();
vbo.unbind();
@@ -65,15 +62,11 @@ int main() {
auto texture = make_shared(image);
- GLContext::enable(GL_CULL_FACE);
- GLContext::cull_face(GL_BACK);
- GLContext::front_face(GL_CW);
-
while (!window->closing()) {
GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
GLContext::clear(GL_COLOR_BUFFER_BIT);
- shaderProgram.enable();
+ shader_program.enable();
texture->bind();
vao.bind();
@@ -81,10 +74,8 @@ int main() {
GLContext::draw_elements(GL_TRIANGLES, static_cast(indices.size()), GL_UNSIGNED_INT, nullptr);
glfwSwapBuffers(window->get_backend());
- GLFWContext::poll_events();
+ window->pull_events();
}
- GLFWContext::terminate();
-
return 0;
}
diff --git a/examples/core/events/0_events_event_listeners/CMakeLists.txt b/examples/core/events/0_events_event_listeners/CMakeLists.txt
index c5178e23..e80aa1fe 100644
--- a/examples/core/events/0_events_event_listeners/CMakeLists.txt
+++ b/examples/core/events/0_events_event_listeners/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_EVENTS_0_EVENT_LISTENERS *.cpp)
-include_directories("../../src")
-include_directories(".")
+include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Events_0_Event_Listeners ${BEBONE_EXAMPLE_EVENTS_0_EVENT_LISTENERS})
target_link_libraries(Bebone_Example_Events_0_Event_Listeners bebone)
\ No newline at end of file
diff --git a/examples/core/events/0_events_event_listeners/main.cpp b/examples/core/events/0_events_event_listeners/main.cpp
index b2c21659..3ce034c9 100644
--- a/examples/core/events/0_events_event_listeners/main.cpp
+++ b/examples/core/events/0_events_event_listeners/main.cpp
@@ -1,10 +1,9 @@
#include "bebone/bebone.h"
-const unsigned int SCR_WIDTH = 800;
-const unsigned int SCR_HEIGHT = 600;
+const unsigned int screen_width = 800;
+const unsigned int screen_height = 600;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
void window_resize_event_listener(WindowSizeEvent&) {
std::cout << "Window resize event !\n";
@@ -19,7 +18,7 @@ struct WindowPosEventListener : EventListener {
int main() {
glfwInit();
- auto window = WindowFactory::create_window("0. OpenGL window example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("0. OpenGL window example", screen_width, screen_height, OpenGL);
WindowPosEventListener listener;
window->add_listener(listener);
@@ -33,7 +32,7 @@ int main() {
window->fire(WindowPosEvent(0, 0));
GLContext::load_opengl();
- GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
+ GLContext::set_viewport(0, 0, screen_width, screen_height);
while (!window->closing()) {
GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
diff --git a/examples/core/events/1_events_action_delegate/CMakeLists.txt b/examples/core/events/1_events_action_delegate/CMakeLists.txt
index c87a9de4..b7d1b493 100644
--- a/examples/core/events/1_events_action_delegate/CMakeLists.txt
+++ b/examples/core/events/1_events_action_delegate/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_EVENTS_1_ACTION_DELEGATE *.cpp)
-include_directories("../../src")
-include_directories(".")
+include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Events_1_Action_Delegate ${BEBONE_EXAMPLE_EVENTS_1_ACTION_DELEGATE})
target_link_libraries(Bebone_Example_Events_1_Action_Delegate bebone)
\ No newline at end of file
diff --git a/examples/core/input/0_input_keyboard/CMakeLists.txt b/examples/core/input/0_input_keyboard/CMakeLists.txt
index 5a13e227..e2b8d36e 100644
--- a/examples/core/input/0_input_keyboard/CMakeLists.txt
+++ b/examples/core/input/0_input_keyboard/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_INPUT_0_KEYBOARD *.cpp)
-include_directories("../../src")
-include_directories(".")
+include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Input_0_Keyboard ${BEBONE_EXAMPLE_INPUT_0_KEYBOARD})
target_link_libraries(Bebone_Example_Input_0_Keyboard bebone)
\ No newline at end of file
diff --git a/examples/core/input/0_input_keyboard/main.cpp b/examples/core/input/0_input_keyboard/main.cpp
index 1b906c2a..03b84450 100644
--- a/examples/core/input/0_input_keyboard/main.cpp
+++ b/examples/core/input/0_input_keyboard/main.cpp
@@ -1,30 +1,38 @@
#include "bebone/bebone.h"
-const unsigned int SCR_WIDTH = 800;
-const unsigned int SCR_HEIGHT = 600;
+const unsigned int screen_width = 800;
+const unsigned int screen_height = 600;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
int main() {
glfwInit();
- auto window = WindowFactory::create_window("0. Input example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("0. Input example", screen_width, screen_height, OpenGL);
GLContext::load_opengl();
- GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
+ GLContext::set_viewport(0, 0, screen_width, screen_height);
- std::function keyPress = []() {
+ std::function key_press = []() {
std::cout << "key press\n";
};
- Input::get_instance().register_key_action(KeyCode::A, keyPress);
+ auto input = std::make_shared();
+ auto input_executor = std::make_shared(input);
+
+ KeyListener key_listener(input_executor);
+ MouseListener mouse_listener(input_executor);
+
+ window->add_listener(key_listener);
+ window->add_listener(mouse_listener);
+
+ input->register_key_action(KeyCode::A, key_press);
while (!window->closing()) {
GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
GLContext::clear(GL_COLOR_BUFFER_BIT);
- window->execute_input_actions();
+ input_executor->execute_input_actions();
glfwSwapBuffers(window->get_backend());
glfwPollEvents();
diff --git a/examples/core/input/1_input_utility_functions/CMakeLists.txt b/examples/core/input/1_input_utility_functions/CMakeLists.txt
new file mode 100644
index 00000000..ff6c4337
--- /dev/null
+++ b/examples/core/input/1_input_utility_functions/CMakeLists.txt
@@ -0,0 +1,7 @@
+file(GLOB_RECURSE BEBONE_EXAMPLE_INPUT_1_UTILITY_FUNCTIONS *.cpp)
+
+include_directories("./")
+include_directories(${BEBONE_INCLUDES})
+
+add_executable(Bebone_Example_Input_1_Utility_Functions ${BEBONE_EXAMPLE_INPUT_1_UTILITY_FUNCTIONS})
+target_link_libraries(Bebone_Example_Input_1_Utility_Functions bebone)
\ No newline at end of file
diff --git a/examples/core/input/1_input_utility_functions/main.cpp b/examples/core/input/1_input_utility_functions/main.cpp
new file mode 100644
index 00000000..c4a2f3af
--- /dev/null
+++ b/examples/core/input/1_input_utility_functions/main.cpp
@@ -0,0 +1,50 @@
+#include "bebone/bebone.h"
+
+const unsigned int screen_width = 800;
+const unsigned int screen_height = 600;
+
+using namespace bebone::gfx;
+
+int main() {
+ glfwInit();
+
+ auto window = WindowFactory::create_window("1. Input utility functions example", screen_width, screen_height, OpenGL);
+
+ GLContext::load_opengl();
+ GLContext::set_viewport(0, 0, screen_width, screen_height);
+
+ auto input = std::make_shared();
+ auto input_executor = std::make_shared(input);
+
+ KeyListener key_listener(input_executor);
+ window->add_listener(key_listener);
+
+ while (!window->closing()) {
+ GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
+ GLContext::clear(GL_COLOR_BUFFER_BIT);
+
+ if (input_executor->is_key_down(KeyCode::A)) {
+ std::cout << "key A is down\n";
+ }
+
+ if (input_executor->is_key_up(KeyCode::A)) {
+ std::cout << "key A is up\n";
+ }
+
+ if (input_executor->is_key_pressed(KeyCode::A)) {
+ std::cout << "Key A is pressed\n";
+ }
+
+ if (input_executor->is_key_released(KeyCode::A)) {
+ std::cout << "Key A is released\n";
+ }
+
+ input_executor->execute_input_actions();
+
+ glfwSwapBuffers(window->get_backend());
+ glfwPollEvents();
+ }
+
+ glfwTerminate();
+ return 0;
+}
diff --git a/examples/core/input/CMakeLists.txt b/examples/core/input/CMakeLists.txt
index 1c4de317..391e9c63 100644
--- a/examples/core/input/CMakeLists.txt
+++ b/examples/core/input/CMakeLists.txt
@@ -1 +1,2 @@
-add_subdirectory(0_input_keyboard)
\ No newline at end of file
+add_subdirectory(0_input_keyboard)
+add_subdirectory(1_input_utility_functions)
\ No newline at end of file
diff --git a/examples/gfx/CMakeLists.txt b/examples/gfx/CMakeLists.txt
index fb0ee40e..3d486edc 100644
--- a/examples/gfx/CMakeLists.txt
+++ b/examples/gfx/CMakeLists.txt
@@ -1,3 +1,2 @@
add_subdirectory(vulkan)
add_subdirectory(opengl)
-add_subdirectory(begui)
diff --git a/examples/gfx/begui/0_begui_node_graph/CMakeLists.txt b/examples/gfx/begui/0_begui_node_graph/CMakeLists.txt
deleted file mode 100644
index 3dd60360..00000000
--- a/examples/gfx/begui/0_begui_node_graph/CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-file(GLOB_RECURSE BEBONE_EXAMPLE_BEGUI_0_NODE_GRAPH *.cpp)
-
-include_directories("../../src")
-include_directories(".")
-
-add_executable(Bebone_Example_Begui_0_Node_Graph ${BEBONE_EXAMPLE_BEGUI_0_NODE_GRAPH})
-target_link_libraries(Bebone_Example_Begui_0_Node_Graph bebone)
\ No newline at end of file
diff --git a/examples/gfx/begui/0_begui_node_graph/fragment.glsl b/examples/gfx/begui/0_begui_node_graph/fragment.glsl
deleted file mode 100644
index a1b650a9..00000000
--- a/examples/gfx/begui/0_begui_node_graph/fragment.glsl
+++ /dev/null
@@ -1,9 +0,0 @@
-#version 450 core
-
-layout (location = 0) out vec4 FragColor;
-
-layout (location = 0) in vec3 outColor;
-
-void main() {
- FragColor = vec4(outColor, 1.0f);
-}
\ No newline at end of file
diff --git a/examples/gfx/begui/0_begui_node_graph/imgui_node_graph_test.h b/examples/gfx/begui/0_begui_node_graph/imgui_node_graph_test.h
deleted file mode 100644
index 544546fb..00000000
--- a/examples/gfx/begui/0_begui_node_graph/imgui_node_graph_test.h
+++ /dev/null
@@ -1,220 +0,0 @@
-#include
-
-#define OMNI_TYPES_MATRIX_COLLUM_MAJOR_ORDER
-#define OMNI_TYPES_MATRIX4X4_PROJECTION_MATRIX_INVERSE_Y_AXIS
-#include "bebone/bebone.h"
-
-static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x + rhs.x, lhs.y + rhs.y); }
-static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x - rhs.x, lhs.y - rhs.y); }
-
-void ShowExampleAppCustomNodeGraph(bool* opened) {
- ImGui::SetNextWindowSize(ImVec2(700, 600), ImGuiCond_FirstUseEver);
- if (!ImGui::Begin("Example: Custom Node Graph", opened)) {
- ImGui::End();
- return;
- }
-
- struct Node {
- int ID;
- std::string Name;
- ImVec2 Pos, Size;
- float Value;
- ImVec4 Color;
- int InputsCount, OutputsCount;
-
- Node(int id, std::string name, const ImVec2& pos, float value, const ImVec4& color, int inputs_count, int outputs_count) {
- ID = id;
- Name = name;
- Pos = pos;
- Value = value;
- Color = color;
- InputsCount = inputs_count;
- OutputsCount = outputs_count;
- }
-
- ImVec2 GetInputSlotPos(int slot_no) const { return ImVec2(Pos.x, Pos.y + Size.y * ((float)slot_no + 1) / ((float)InputsCount + 1)); }
- ImVec2 GetOutputSlotPos(int slot_no) const { return ImVec2(Pos.x + Size.x, Pos.y + Size.y * ((float)slot_no + 1) / ((float)OutputsCount + 1)); }
- };
- struct NodeLink {
- int InputIdx;
- int InputSlot;
- int OutputIdx;
- int OutputSlot;
-
- NodeLink(int input_idx, int input_slot, int output_idx, int output_slot) { InputIdx = input_idx; InputSlot = input_slot; OutputIdx = output_idx; OutputSlot = output_slot; }
- };
-
- static ImVector nodes;
- static ImVector links;
- static ImVec2 scrolling = ImVec2(0.0f, 0.0f);
- static bool inited = false;
- static bool show_grid = true;
- static int node_selected = -1;
-
- // Initialization
- ImGuiIO& io = ImGui::GetIO();
- if (!inited) {
- nodes.push_back(Node(0, "MainTex", ImVec2(40, 50), 0.5f, ImColor(255, 100, 100), 1, 1));
- nodes.push_back(Node(1, "BumpMap", ImVec2(40, 150), 0.42f, ImColor(200, 100, 200), 1, 1));
- nodes.push_back(Node(2, "Combine", ImVec2(270, 80), 1.0f, ImColor(0, 200, 100), 2, 2));
- links.push_back(NodeLink(0, 0, 2, 0));
- links.push_back(NodeLink(1, 0, 2, 1));
- inited = true;
- }
-
- // Draw a list of nodes on the left side
- bool open_context_menu = false;
- int node_hovered_in_list = -1;
- int node_hovered_in_scene = -1;
- ImGui::BeginChild("node_list", ImVec2(100, 0));
- ImGui::Text("Nodes");
- ImGui::Separator();
- for (int node_idx = 0; node_idx < nodes.Size; node_idx++) {
- Node* node = &nodes[node_idx];
- ImGui::PushID(node->ID);
- if (ImGui::Selectable(node->Name.c_str(), node->ID == node_selected))
- node_selected = node->ID;
- if (ImGui::IsItemHovered()) {
- node_hovered_in_list = node->ID;
- open_context_menu |= ImGui::IsMouseClicked(1);
- }
- ImGui::PopID();
- }
- ImGui::EndChild();
-
- ImGui::SameLine();
- ImGui::BeginGroup();
-
- const float NODE_SLOT_RADIUS = 4.0f;
- const ImVec2 NODE_WINDOW_PADDING(8.0f, 8.0f);
-
- // Create our child canvas
- ImGui::Text("Hold middle mouse button to scroll (%.2f,%.2f)", scrolling.x, scrolling.y);
- ImGui::SameLine(ImGui::GetWindowWidth() - 100);
- ImGui::Checkbox("Show grid", &show_grid);
- ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(1, 1));
- ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
- ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(60, 60, 70, 200));
- ImGui::BeginChild("scrolling_region", ImVec2(0, 0), true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove);
- ImGui::PopStyleVar(); // WindowPadding
- ImGui::PushItemWidth(120.0f);
-
- const ImVec2 offset = ImGui::GetCursorScreenPos() + scrolling;
- ImDrawList* draw_list = ImGui::GetWindowDrawList();
-
- if (show_grid) {
- ImU32 GRID_COLOR = IM_COL32(200, 200, 200, 40);
- float GRID_SZ = 64.0f;
- ImVec2 win_pos = ImGui::GetCursorScreenPos();
- ImVec2 canvas_sz = ImGui::GetWindowSize();
- for (float x = fmodf(scrolling.x, GRID_SZ); x < canvas_sz.x; x += GRID_SZ)
- draw_list->AddLine(ImVec2(x, 0.0f) + win_pos, ImVec2(x, canvas_sz.y) + win_pos, GRID_COLOR);
- for (float y = fmodf(scrolling.y, GRID_SZ); y < canvas_sz.y; y += GRID_SZ)
- draw_list->AddLine(ImVec2(0.0f, y) + win_pos, ImVec2(canvas_sz.x, y) + win_pos, GRID_COLOR);
- }
-
- draw_list->ChannelsSplit(2);
- draw_list->ChannelsSetCurrent(0); // Background
- for (int link_idx = 0; link_idx < links.Size; link_idx++) {
- NodeLink* link = &links[link_idx];
- Node* node_inp = &nodes[link->InputIdx];
- Node* node_out = &nodes[link->OutputIdx];
- ImVec2 p1 = offset + node_inp->GetOutputSlotPos(link->InputSlot);
- ImVec2 p2 = offset + node_out->GetInputSlotPos(link->OutputSlot);
-
- draw_list->AddBezierCubic(p1, p1 + ImVec2(+50, 0), p2 + ImVec2(-50, 0), p2, IM_COL32(200, 200, 100, 255), 3.0f);
- // draw_list->AddLine(p1, p2, IM_COL32(200, 200, 100, 255), 3.0f);
- }
-
- for (int node_idx = 0; node_idx < nodes.Size; node_idx++) {
- Node* node = &nodes[node_idx];
- ImGui::PushID(node->ID);
- ImVec2 node_rect_min = offset + node->Pos;
-
- // Display node contents first
- draw_list->ChannelsSetCurrent(1); // Foreground
- bool old_any_active = ImGui::IsAnyItemActive();
- ImGui::SetCursorScreenPos(node_rect_min + NODE_WINDOW_PADDING);
- ImGui::BeginGroup(); // Lock horizontal position
- ImGui::Text("%s", node->Name.c_str());
- ImGui::SliderFloat("##value", &node->Value, 0.0f, 1.0f, "Alpha %.2f");
- ImGui::ColorEdit3("##color", &node->Color.x);
- ImGui::EndGroup();
-
- // Save the size of what we have emitted and whether any of the widgets are being used
- bool node_widgets_active = (!old_any_active && ImGui::IsAnyItemActive());
- node->Size = ImGui::GetItemRectSize() + NODE_WINDOW_PADDING + NODE_WINDOW_PADDING;
- ImVec2 node_rect_max = node_rect_min + node->Size;
-
- // Display node box
- draw_list->ChannelsSetCurrent(0); // Background
- ImGui::SetCursorScreenPos(node_rect_min);
- ImGui::InvisibleButton("node", node->Size);
- if (ImGui::IsItemHovered()) {
- node_hovered_in_scene = node->ID;
- open_context_menu |= ImGui::IsMouseClicked(1);
- }
- bool node_moving_active = ImGui::IsItemActive();
- if (node_widgets_active || node_moving_active)
- node_selected = node->ID;
- if (node_moving_active && ImGui::IsMouseDragging(ImGuiMouseButton_Left))
- node->Pos = node->Pos + io.MouseDelta;
-
- ImU32 node_bg_color = (node_hovered_in_list == node->ID || node_hovered_in_scene == node->ID || (node_hovered_in_list == -1 && node_selected == node->ID)) ? IM_COL32(75, 75, 75, 255) : IM_COL32(60, 60, 60, 255);
- draw_list->AddRectFilled(node_rect_min, node_rect_max, node_bg_color, 4.0f);
- draw_list->AddRect(node_rect_min, node_rect_max, IM_COL32(100, 100, 100, 255), 4.0f);
- for (int slot_idx = 0; slot_idx < node->InputsCount; slot_idx++)
- draw_list->AddCircleFilled(offset + node->GetInputSlotPos(slot_idx), NODE_SLOT_RADIUS, IM_COL32(150, 150, 150, 150));
- for (int slot_idx = 0; slot_idx < node->OutputsCount; slot_idx++)
- draw_list->AddCircleFilled(offset + node->GetOutputSlotPos(slot_idx), NODE_SLOT_RADIUS, IM_COL32(150, 150, 150, 150));
-
- ImGui::PopID();
- }
- draw_list->ChannelsMerge();
-
- // Open context menu
- if (ImGui::IsMouseReleased(ImGuiMouseButton_Right))
- if (ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) || !ImGui::IsAnyItemHovered()) {
- node_selected = node_hovered_in_list = node_hovered_in_scene = -1;
- open_context_menu = true;
- }
- if (open_context_menu) {
- ImGui::OpenPopup("context_menu");
- if (node_hovered_in_list != -1)
- node_selected = node_hovered_in_list;
- if (node_hovered_in_scene != -1)
- node_selected = node_hovered_in_scene;
- }
-
- // Draw context menu
- ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8, 8));
- if (ImGui::BeginPopup("context_menu"))
- {
- Node* node = node_selected != -1 ? &nodes[node_selected] : NULL;
- ImVec2 scene_pos = ImGui::GetMousePosOnOpeningCurrentPopup() - offset;
-
- if (node) {
- ImGui::Text("Node '%s'", node->Name.c_str());
- ImGui::Separator();
- if (ImGui::MenuItem("Rename..", NULL, false, false)) {}
- if (ImGui::MenuItem("Delete", NULL, false, false)) {}
- if (ImGui::MenuItem("Copy", NULL, false, false)) {}
- } else {
- if (ImGui::MenuItem("Add")) { nodes.push_back(Node(nodes.Size, "New node", scene_pos, 0.5f, ImColor(100, 100, 200), 2, 2)); }
- if (ImGui::MenuItem("Paste", NULL, false, false)) {}
- }
- ImGui::EndPopup();
- }
- ImGui::PopStyleVar();
-
- if (ImGui::IsWindowHovered() && !ImGui::IsAnyItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Middle, 0.0f))
- scrolling = scrolling + io.MouseDelta;
-
- ImGui::PopItemWidth();
- ImGui::EndChild();
- ImGui::PopStyleColor();
- ImGui::PopStyleVar();
- ImGui::EndGroup();
-
- ImGui::End();
-}
diff --git a/examples/gfx/begui/0_begui_node_graph/main.cpp b/examples/gfx/begui/0_begui_node_graph/main.cpp
deleted file mode 100644
index a3a58fac..00000000
--- a/examples/gfx/begui/0_begui_node_graph/main.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-#include "imgui_node_graph_test.h"
-
-const unsigned int SCR_WIDTH = 800;
-const unsigned int SCR_HEIGHT = 600;
-
-using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
-
-int main() {
- BEBONE_PROFILE_RECORD(MAIN)
-
- GLFWContext::init();
-
- auto window = WindowFactory::create_window("0. Begui Node graph example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
-
- window->add_listener([&](InputKeyEvent& event) {
- if(event.key == GLFW_KEY_ENTER && event.action == GLFW_RELEASE) {
- BEBONE_PROFILE_RECORD(EVENT)
-
- std::cout << "Called event !\n";
-
- BEBONE_PROFILE_STOP(EVENT)
- }
- });
-
- GLContext::load_opengl();
- GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
- glfwSwapInterval(0);
-
- auto vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
- auto fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
- GLShaderProgram shaderProgram(vertexShader, fragmentShader);
-
- vertexShader.destroy();
- fragmentShader.destroy();
-
- GLContext::enable(GL_DEPTH_TEST);
-
- BeGUI::init(window);
-
- while (!window->closing()) {
- BEBONE_PROFILE_RECORD(LOOP)
-
- BEBONE_PROFILE_RECORD(CLEAR)
- GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
- GLContext::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- BEBONE_PROFILE_STOP(CLEAR)
-
- BEBONE_PROFILE_RECORD(BEGUI)
- BeGUI::begin();
- ShowExampleAppCustomNodeGraph(nullptr);
- ImGui::ShowDemoWindow();
- BeGUI::show_profiler();
- BeGUI::end();
- BEBONE_PROFILE_STOP(BEGUI)
-
- GLFWContext::swap_buffers(*window); // Todo make this not a reference
- GLFWContext::poll_events();
-
- BEBONE_PROFILE_STOP(LOOP)
- }
-
- shaderProgram.destroy();
-
- GLFWContext::terminate();
-
- BEBONE_PROFILE_STOP(MAIN)
- std::cout << BEBONE_PROFILER_SUM_UP() << "\n";
-
- return 0;
-}
diff --git a/examples/gfx/begui/0_begui_node_graph/vertex.glsl b/examples/gfx/begui/0_begui_node_graph/vertex.glsl
deleted file mode 100644
index e94b6d3a..00000000
--- a/examples/gfx/begui/0_begui_node_graph/vertex.glsl
+++ /dev/null
@@ -1,22 +0,0 @@
-#version 450 core
-
-layout (location = 0) in vec3 aPos;
-layout (location = 1) in vec3 aColor;
-
-layout (location = 0) out vec3 outColor;
-
-layout(binding = 0) uniform Transform {
- mat4 translation;
- mat4 scale;
- mat4 rotation;
-};
-
-layout(binding = 1) uniform Camera {
- mat4 proj;
- mat4 view;
-};
-
-void main() {
- gl_Position = proj * view * translation * rotation * scale * vec4(aPos, 1.0);
- outColor = aColor;
-}
\ No newline at end of file
diff --git a/examples/gfx/begui/CMakeLists.txt b/examples/gfx/begui/CMakeLists.txt
deleted file mode 100644
index 9fc74fcd..00000000
--- a/examples/gfx/begui/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-add_subdirectory(0_begui_node_graph)
\ No newline at end of file
diff --git a/examples/gfx/opengl/0_opengl_window/CMakeLists.txt b/examples/gfx/opengl/0_opengl_window/CMakeLists.txt
index 25521bd8..df0f2e6d 100644
--- a/examples/gfx/opengl/0_opengl_window/CMakeLists.txt
+++ b/examples/gfx/opengl/0_opengl_window/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_GFX_OPENGL_0_OPENGL_WINDOW *.cpp)
-include_directories("../../src")
include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Gfx_0_Opengl_Window ${BEBONE_EXAMPLE_GFX_OPENGL_0_OPENGL_WINDOW})
target_link_libraries(Bebone_Example_Gfx_0_Opengl_Window bebone)
\ No newline at end of file
diff --git a/examples/gfx/opengl/0_opengl_window/main.cpp b/examples/gfx/opengl/0_opengl_window/main.cpp
index 2185161a..07bef287 100644
--- a/examples/gfx/opengl/0_opengl_window/main.cpp
+++ b/examples/gfx/opengl/0_opengl_window/main.cpp
@@ -1,27 +1,30 @@
#include "bebone/bebone.h"
-const unsigned int SCR_WIDTH = 800;
-const unsigned int SCR_HEIGHT = 600;
+const unsigned int screen_width = 800;
+const unsigned int screen_height = 600;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
int main() {
- GLFWContext::init();
-
- auto window = WindowFactory::create_window("0. OpenGL window example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ LOG_TRACE("Test message");
+ LOG_DEBUG("Test message");
+ LOG_INFORMATION("Test message");
+ LOG_WARNING("Test message");
+ LOG_ERROR("Test message");
+ LOG_CRITICAL("Test message");
+
+ auto window = WindowFactory::create_window("0. OpenGL window example", screen_width, screen_height, OpenGL);
GLContext::load_opengl();
- GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
+ GLContext::set_viewport(0, 0, screen_width, screen_height);
while (!window->closing()) {
GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
GLContext::clear(GL_COLOR_BUFFER_BIT);
GLFWContext::swap_buffers(*window);
- GLFWContext::poll_events();
+ window->pull_events();
}
- GLFWContext::terminate();
return 0;
}
diff --git a/examples/gfx/opengl/1_opengl_hello_triangle/CMakeLists.txt b/examples/gfx/opengl/1_opengl_hello_triangle/CMakeLists.txt
index 199ffbb4..68c2f69f 100644
--- a/examples/gfx/opengl/1_opengl_hello_triangle/CMakeLists.txt
+++ b/examples/gfx/opengl/1_opengl_hello_triangle/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_GFX_OPENGL_1_OPENGL_HELLO_TRIANGLE *.cpp)
-include_directories("../../src")
include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Gfx_1_Opengl_Hello_Triangle ${BEBONE_EXAMPLE_GFX_OPENGL_1_OPENGL_HELLO_TRIANGLE})
target_link_libraries(Bebone_Example_Gfx_1_Opengl_Hello_Triangle bebone)
\ No newline at end of file
diff --git a/examples/gfx/opengl/1_opengl_hello_triangle/fragment.glsl b/examples/gfx/opengl/1_opengl_hello_triangle/fragment.glsl
index 119963d8..8904deb8 100644
--- a/examples/gfx/opengl/1_opengl_hello_triangle/fragment.glsl
+++ b/examples/gfx/opengl/1_opengl_hello_triangle/fragment.glsl
@@ -1,7 +1,7 @@
#version 450 core
-layout (location = 0) out vec4 FragColor;
+layout (location = 0) out vec4 out_color;
void main() {
- FragColor = vec4(0.6f, 0.9f, 0.6f, 1.0f);
+ out_color = vec4(0.6f, 0.9f, 0.6f, 1.0f);
}
diff --git a/examples/gfx/opengl/1_opengl_hello_triangle/main.cpp b/examples/gfx/opengl/1_opengl_hello_triangle/main.cpp
index cbe7de52..31382600 100644
--- a/examples/gfx/opengl/1_opengl_hello_triangle/main.cpp
+++ b/examples/gfx/opengl/1_opengl_hello_triangle/main.cpp
@@ -2,36 +2,26 @@
#include "bebone/bebone.h"
-const unsigned int SCR_WIDTH = 800;
-const unsigned int SCR_HEIGHT = 600;
+const unsigned int screen_width = 800;
+const unsigned int screen_height = 600;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
-const std::vector vertices = {
- {-0.5f, -0.5f, 0.0f},
- {0.5f, -0.5f, 0.0f},
- {0.0f, 0.5f, 0.0f}
-};
-
-const std::vector indices = {
- 0, 1, 2,
-};
+const std::vector vertices = { {-0.5f, -0.5f, 0.0f}, {0.5f, -0.5f, 0.0f}, {0.0f, 0.5f, 0.0f} };
+const std::vector indices = { 0, 1, 2, };
int main() {
- GLFWContext::init();
-
- auto window = WindowFactory::create_window("1. OpenGL hello triangle example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("1. OpenGL hello triangle example", screen_width, screen_height, OpenGL);
GLContext::load_opengl();
- GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
+ GLContext::set_viewport(0, 0, screen_width, screen_height);
- GLShader vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
- GLShader fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
- GLShaderProgram shaderProgram(vertexShader, fragmentShader);
+ GLShader vertex_shader = GLShaderFactory::create_shader("vertex.glsl", ShaderType::VertexShader);
+ GLShader fragment_shader = GLShaderFactory::create_shader("fragment.glsl", ShaderType::FragmentShader);
+ GLShaderProgram shader_program(vertex_shader, fragment_shader);
- vertexShader.destroy();
- fragmentShader.destroy();
+ vertex_shader.destroy();
+ fragment_shader.destroy();
GLVertexArrayObject vao;
vao.bind();
@@ -45,24 +35,25 @@ int main() {
vbo.unbind();
ebo.unbind();
+ GLContext::disable(GL_DEPTH_TEST);
+
while(!window->closing()) {
GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
GLContext::clear(GL_COLOR_BUFFER_BIT);
- shaderProgram.enable();
+ shader_program.enable();
vao.bind();
GLContext::draw_arrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window->get_backend());
- GLFWContext::poll_events();
+ window->pull_events();
}
vao.destroy();
vbo.destroy();
ebo.destroy();
- shaderProgram.destroy();
+ shader_program.destroy();
- GLFWContext::terminate();
return 0;
}
diff --git a/examples/gfx/opengl/2_opengl_texture/CMakeLists.txt b/examples/gfx/opengl/2_opengl_texture/CMakeLists.txt
index d407252e..ec321f73 100644
--- a/examples/gfx/opengl/2_opengl_texture/CMakeLists.txt
+++ b/examples/gfx/opengl/2_opengl_texture/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_GFX_OPENGL_2_OPENGL_TEXTURE *.cpp)
-include_directories("../../src")
include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Gfx_2_Opengl_Texture ${BEBONE_EXAMPLE_GFX_OPENGL_2_OPENGL_TEXTURE})
target_link_libraries(Bebone_Example_Gfx_2_Opengl_Texture bebone)
\ No newline at end of file
diff --git a/examples/gfx/opengl/2_opengl_texture/fragment.glsl b/examples/gfx/opengl/2_opengl_texture/fragment.glsl
index 84667cb0..469169d5 100644
--- a/examples/gfx/opengl/2_opengl_texture/fragment.glsl
+++ b/examples/gfx/opengl/2_opengl_texture/fragment.glsl
@@ -2,7 +2,6 @@
layout (location = 0) out vec4 FragColor;
-layout (location = 0) in vec3 ourColor;
layout (location = 1) in vec2 TexCoord;
layout (binding = 0) uniform sampler2D ourTexture;
diff --git a/examples/gfx/opengl/2_opengl_texture/main.cpp b/examples/gfx/opengl/2_opengl_texture/main.cpp
index db14ee38..428b903b 100644
--- a/examples/gfx/opengl/2_opengl_texture/main.cpp
+++ b/examples/gfx/opengl/2_opengl_texture/main.cpp
@@ -2,44 +2,37 @@
#include
-const unsigned int SCR_WIDTH = 800;
-const unsigned int SCR_HEIGHT = 600;
+const unsigned int screen_width = 800;
+const unsigned int screen_height = 600;
using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
struct Vertex {
Vec3f pos;
- Vec3f color;
- Vec2f texCord;
+ Vec2f tex_coords;
};
const std::vector vertices {
- {{0.5f, 0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {1.0f, 1.0f}},
- {{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
- {{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
- {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}}
+ {{0.5f, 0.5f, 0.0f}, {1.0f, 1.0f}},
+ {{0.5f, -0.5f, 0.0f}, {1.0f, 0.0f}},
+ {{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f}},
+ {{-0.5f, 0.5f, 0.0f}, {0.0f, 1.0f}}
};
-const std::vector indices {
- 0, 1, 3,
- 1, 2, 3
-};
+const std::vector indices { 0, 3, 1, 3, 2, 1 };
int main() {
- GLFWContext::init();
-
- auto window = WindowFactory::create_window("2. OpenGL texture example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
+ auto window = WindowFactory::create_window("2. OpenGL texture example", screen_width, screen_height, OpenGL);
GLContext::load_opengl();
- GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
+ GLContext::set_viewport(0, 0, screen_width, screen_height);
- auto vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
- auto fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
- GLShaderProgram shaderProgram(vertexShader, fragmentShader);
+ auto vertex_shader = GLShaderFactory::create_shader("vertex.glsl", ShaderType::VertexShader);
+ auto fragment_shader = GLShaderFactory::create_shader("fragment.glsl", ShaderType::FragmentShader);
+ GLShaderProgram shader_program(vertex_shader, fragment_shader);
- vertexShader.destroy();
- fragmentShader.destroy();
+ vertex_shader.destroy();
+ fragment_shader.destroy();
GLVertexArrayObject vao;
vao.bind();
@@ -48,26 +41,22 @@ int main() {
GLElementBufferObject ebo(indices.data(), indices.size() * sizeof(u32));
vao.link_attributes(vbo, 0, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, pos));
- vao.link_attributes(vbo, 1, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, color));
- vao.link_attributes(vbo, 2, 2, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, texCord));
+ vao.link_attributes(vbo, 1, 2, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, tex_coords));
vao.unbind();
vbo.unbind();
ebo.unbind();
GLTexture2D texture("image.png");
+ shader_program.set_uniform("ourTexture", 0);
- shaderProgram.set_uniform("ourTexture", 0);
-
- GLContext::enable(GL_CULL_FACE);
- GLContext::cull_face(GL_BACK);
- GLContext::front_face(GL_CW);
+ GLContext::disable(GL_DEPTH_TEST);
while (!window->closing()) {
GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
GLContext::clear(GL_COLOR_BUFFER_BIT);
- shaderProgram.enable();
+ shader_program.enable();
texture.bind();
vao.bind();
@@ -75,10 +64,8 @@ int main() {
GLContext::draw_elements(GL_TRIANGLES, static_cast(indices.size()), GL_UNSIGNED_INT, nullptr);
glfwSwapBuffers(window->get_backend());
- GLFWContext::poll_events();
+ window->pull_events();
}
- GLFWContext::terminate();
-
return 0;
}
diff --git a/examples/gfx/opengl/2_opengl_texture/vertex.glsl b/examples/gfx/opengl/2_opengl_texture/vertex.glsl
index 35f0ac1b..d49b9afe 100644
--- a/examples/gfx/opengl/2_opengl_texture/vertex.glsl
+++ b/examples/gfx/opengl/2_opengl_texture/vertex.glsl
@@ -1,14 +1,11 @@
#version 450 core
layout (location = 0) in vec3 aPos;
-layout (location = 1) in vec3 aColor;
-layout (location = 2) in vec2 aTexCoord;
+layout (location = 1) in vec2 aTexCoord;
-layout (location = 0) out vec3 ourColor;
layout (location = 1) out vec2 TexCoord;
void main() {
gl_Position = vec4(aPos, 1.0);
- ourColor = aColor;
TexCoord = aTexCoord;
}
\ No newline at end of file
diff --git a/examples/gfx/opengl/3_opengl_3d_cube/CMakeLists.txt b/examples/gfx/opengl/3_opengl_3d_cube/CMakeLists.txt
index 88373d09..2721dfff 100644
--- a/examples/gfx/opengl/3_opengl_3d_cube/CMakeLists.txt
+++ b/examples/gfx/opengl/3_opengl_3d_cube/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_GFX_OPENGL_3_OPENGL_3D_CUBE *.cpp)
-include_directories("../../src")
include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Gfx_3_Opengl_3D_Cube ${BEBONE_EXAMPLE_GFX_OPENGL_3_OPENGL_3D_CUBE})
target_link_libraries(Bebone_Example_Gfx_3_Opengl_3D_Cube bebone)
\ No newline at end of file
diff --git a/examples/gfx/opengl/3_opengl_3d_cube/main.cpp b/examples/gfx/opengl/3_opengl_3d_cube/main.cpp
index f7a5aa8f..ef23fffc 100644
--- a/examples/gfx/opengl/3_opengl_3d_cube/main.cpp
+++ b/examples/gfx/opengl/3_opengl_3d_cube/main.cpp
@@ -1,126 +1,111 @@
-#include
-
-#define OMNI_TYPES_MATRIX_COLLUM_MAJOR_ORDER
-#define OMNI_TYPES_MATRIX4X4_PROJECTION_MATRIX_INVERSE_Y_AXIS
-#include "bebone/bebone.h"
-
-const unsigned int SCR_WIDTH = 800;
-const unsigned int SCR_HEIGHT = 600;
-
-using namespace bebone::gfx;
-using namespace bebone::gfx::opengl;
-
-struct Vertex {
- Vec3f pos;
- ColorRGBA color;
-};
-
-const std::vector vertices {
- {{-1.0, -1.0, 1.0}, ColorRGBA::WHITE },
- {{ 1.0, -1.0, 1.0}, ColorRGBA::YELLOW },
- {{ 1.0, 1.0, 1.0}, ColorRGBA::MAGENTA},
- {{-1.0, 1.0, 1.0}, ColorRGBA::RED },
- {{-1.0, -1.0, -1.0}, ColorRGBA::CYAN },
- {{ 1.0, -1.0, -1.0}, ColorRGBA::GREEN },
- {{ 1.0, 1.0, -1.0}, ColorRGBA::BLUE },
- {{-1.0, 1.0, -1.0}, ColorRGBA::BLACK }
-};
-
-const std::vector indices {
- 0, 1, 2, 2, 3, 0,
- 1, 5, 6, 6, 2, 1,
- 7, 6, 5, 5, 4, 7,
- 4, 0, 3, 3, 7, 4,
- 4, 5, 1, 1, 0, 4,
- 3, 2, 6, 6, 7, 3
-};
-
-struct Transform {
- Mat4f translation;
- Mat4f scale;
- Mat4f rotation;
-};
-
-struct Camera {
- Mat4f proj;
- Mat4f view;
-};
-
-int main() {
- glfwInit();
-
- auto window = WindowFactory::create_window("3. OpenGL 3D cube example", SCR_WIDTH, SCR_HEIGHT, GfxAPI::OPENGL);
-
- GLContext::load_opengl();
- GLContext::set_viewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
-
- auto vertexShader = GLShaderFactory::create_shader("vertex.glsl", ShaderTypes::VERTEX_SHADER);
- auto fragmentShader = GLShaderFactory::create_shader("fragment.glsl", ShaderTypes::FRAGMENT_SHADER);
- GLShaderProgram shaderProgram(vertexShader, fragmentShader);
-
- vertexShader.destroy();
- fragmentShader.destroy();
-
- GLVertexArrayObject vao;
- vao.bind();
-
- GLVertexBufferObject vbo(vertices.data(), vertices.size() * sizeof(Vertex));
- GLElementBufferObject ebo(indices.data(), indices.size() * sizeof(u32));
-
- vao.link_attributes(vbo, 0, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, pos));
- vao.link_attributes(vbo, 1, 4, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, color));
-
- vao.unbind();
- vbo.unbind();
- ebo.unbind();
-
- GLUniformBufferObject transformUbo(sizeof(Transform));
- GLUniformBufferObject cameraUbo(sizeof(Camera));
-
- transformUbo.bind();
- shaderProgram.bind_buffer("Transform", 0, transformUbo);
- auto transformPtr = static_cast(transformUbo.map());
- transformPtr->translation = Mat4f::translation(Vec3f::zero);
- transformPtr->scale = Mat4f::identity();
-
- cameraUbo.bind();
- shaderProgram.bind_buffer("Camera", 1, cameraUbo);
- auto cameraPtr = static_cast(cameraUbo.map());
- cameraPtr->proj = Mat4f::perspective(1, window->get_aspect(), 0.1f, 100.0f);
- cameraPtr->view = Mat4f::translation(Vec3f(0, 0, 5));
- cameraUbo.unmap();
- cameraUbo.unbind();
-
- GLContext::enable(GL_DEPTH_TEST);
-
- f32 t = 0.0f;
- while (!window->closing()) {
- ++t;
-
- GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
- GLContext::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- transformPtr->rotation = trait_bryan_angle_yxz(Vec3f(t * 0.01f, t * 0.01f, 0.0f));
-
- shaderProgram.enable();
-
- vao.bind();
-
- GLContext::draw_elements(GL_TRIANGLES, static_cast(indices.size()), GL_UNSIGNED_INT, nullptr);
-
- GLFWContext::swap_buffers(*window);
- GLFWContext::poll_events();
- }
-
- transformUbo.unmap();
- transformUbo.unbind();
-
- vao.destroy();
- vbo.destroy();
- ebo.destroy();
- shaderProgram.destroy();
-
- GLFWContext::terminate();
-
- return 0;
-}
+#include
+#include "bebone/bebone.h"
+
+const unsigned int screen_width = 800;
+const unsigned int screen_height = 600;
+
+using namespace bebone::gfx;
+
+struct Vertex {
+ Vec3f pos;
+ ColorRGBA color;
+};
+
+const vector vertices {
+ {{ -1.0, -1.0, 1.0 }, ColorRGBA::WHITE },
+ {{ 1.0, -1.0, 1.0 }, ColorRGBA::YELLOW },
+ {{ 1.0, 1.0, 1.0 }, ColorRGBA::MAGENTA},
+ {{ -1.0, 1.0, 1.0 }, ColorRGBA::RED },
+ {{ -1.0, -1.0, -1.0 }, ColorRGBA::CYAN },
+ {{ 1.0, -1.0, -1.0 }, ColorRGBA::GREEN },
+ {{ 1.0, 1.0, -1.0 }, ColorRGBA::BLUE },
+ {{ -1.0, 1.0, -1.0 }, ColorRGBA::BLACK }
+};
+
+const vector indices {
+ 0, 1, 2, 2, 3, 0, 1, 5, 6, 6, 2, 1, 7, 6, 5, 5, 4, 7, 4, 0, 3, 3, 7, 4, 4, 5, 1, 1, 0, 4, 3, 2, 6, 6, 7, 3
+};
+
+struct Transform {
+ Mat4f translation;
+ Mat4f rotation;
+};
+
+int main() {
+ glfwInit();
+
+ auto window = WindowFactory::create_window("3. OpenGL 3D cube example", screen_width, screen_height, OpenGL);
+
+ GLContext::load_opengl();
+ GLContext::set_viewport(0, 0, screen_width, screen_height);
+
+ auto vertex_shader = GLShaderFactory::create_shader("vertex.glsl", ShaderType::VertexShader);
+ auto fragment_shader = GLShaderFactory::create_shader("fragment.glsl", ShaderType::FragmentShader);
+ GLShaderProgram shader_program(vertex_shader, fragment_shader);
+
+ vertex_shader.destroy();
+ fragment_shader.destroy();
+
+ GLVertexArrayObject vao;
+ vao.bind();
+
+ GLVertexBufferObject vbo(vertices.data(), vertices.size() * sizeof(Vertex));
+ GLElementBufferObject ebo(indices.data(), indices.size() * sizeof(u32));
+
+ vao.link_attributes(vbo, 0, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, pos));
+ vao.link_attributes(vbo, 1, 4, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, color));
+
+ vao.unbind();
+ vbo.unbind();
+ ebo.unbind();
+
+ GLUniformBufferObject transform_ubo(sizeof(Mat4f));
+ GLUniformBufferObject camera_ubo(sizeof(Mat4f));
+
+ auto transform = Transform {};
+ transform.translation = Mat4f::translation(Vec3f(0.0f, 0.0f, 10.0f));
+ transform.rotation = Mat4f::identity();
+
+ transform_ubo.bind();
+ shader_program.bind_buffer("Transform", 0, transform_ubo);
+ auto transform_ptr = static_cast(transform_ubo.map());
+ *transform_ptr = transform.translation * transform.rotation;
+
+ camera_ubo.bind();
+ shader_program.bind_buffer("Camera", 1, camera_ubo);
+ auto camera_ptr = static_cast(camera_ubo.map());
+ *camera_ptr = Mat4f::perspective(1, window->get_aspect(), 0.1f, 100.0f) * Mat4f::look_at(Vec3f(0, 0, -10.0f), Vec3f(0.0f, 0.0f, 0.0f), Vec3f::up);
+ camera_ubo.unmap();
+ camera_ubo.unbind();
+
+ while (!window->closing()) {
+ GLContext::clear_color(0.2f, 0.2f, 0.2f, 1.0f);
+ GLContext::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ const auto t = static_cast(Time::get_seconds_elapsed());
+ transform.rotation = trait_bryan_angle_yxz(Vec3f(t, t, 0.0f));
+ *transform_ptr = transform.translation * transform.rotation;
+
+ auto time = Time::get_seconds_elapsed();
+ auto pos = Vec3f((sin(time)) * 5.0f, 0.0f, (sin(time)) * 5.0f);
+ transform.translation = Mat4f::translation(pos);
+
+ shader_program.enable();
+ vao.bind();
+
+ GLContext::draw_elements(GL_TRIANGLES, static_cast(indices.size()), GL_UNSIGNED_INT, nullptr);
+
+ GLFWContext::swap_buffers(*window);
+ window->pull_events();
+ }
+
+ transform_ubo.unmap();
+ transform_ubo.unbind();
+
+ vao.destroy();
+ vbo.destroy();
+ ebo.destroy();
+ shader_program.destroy();
+
+ return 0;
+}
diff --git a/examples/gfx/opengl/3_opengl_3d_cube/vertex.glsl b/examples/gfx/opengl/3_opengl_3d_cube/vertex.glsl
index dabbf589..906ceec1 100644
--- a/examples/gfx/opengl/3_opengl_3d_cube/vertex.glsl
+++ b/examples/gfx/opengl/3_opengl_3d_cube/vertex.glsl
@@ -5,18 +5,10 @@ layout (location = 1) in vec4 aColor;
layout (location = 0) out vec4 outColor;
-layout(binding = 0) uniform Transform {
- mat4 translation;
- mat4 scale;
- mat4 rotation;
-};
-
-layout(binding = 1) uniform Camera {
- mat4 proj;
- mat4 view;
-};
+layout(binding = 0) uniform Transform { mat4 transform; };
+layout(binding = 1) uniform Camera { mat4 cam; };
void main() {
- gl_Position = proj * view * translation * rotation * scale * vec4(aPos, 1.0);
+ gl_Position = cam * transform * vec4(aPos, 1.0);
outColor = aColor;
}
\ No newline at end of file
diff --git a/examples/gfx/opengl/4_opengl_bexel/CMakeLists.txt b/examples/gfx/opengl/4_opengl_bexel/CMakeLists.txt
index 76254437..f2b1f605 100644
--- a/examples/gfx/opengl/4_opengl_bexel/CMakeLists.txt
+++ b/examples/gfx/opengl/4_opengl_bexel/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_GFX_OPENGL_4_OPENGL_BEXEL *.cpp)
-include_directories("../../src")
include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Gfx_4_Opengl_Bexel ${BEBONE_EXAMPLE_GFX_OPENGL_4_OPENGL_BEXEL})
target_link_libraries(Bebone_Example_Gfx_4_Opengl_Bexel bebone)
diff --git a/examples/gfx/opengl/4_opengl_bexel/bebone.h b/examples/gfx/opengl/4_opengl_bexel/bebone.h
deleted file mode 100644
index a7f83546..00000000
--- a/examples/gfx/opengl/4_opengl_bexel/bebone.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef BEBONE_H
-#define BEBONE_H
-
-#define OMNI_TYPES_MATRIX_COLLUM_MAJOR_ORDER
-// #define OMNI_TYPES_MATRIX4X4_PROJECTION_MATRIX_INVERSE_Y_AXIS
-#include "bebone/bebone.h"
-
-#endif
diff --git a/examples/gfx/opengl/4_opengl_bexel/bexel.cpp b/examples/gfx/opengl/4_opengl_bexel/bexel.cpp
index cb165eb0..6aec6c29 100644
--- a/examples/gfx/opengl/4_opengl_bexel/bexel.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/bexel.cpp
@@ -1,85 +1,60 @@
#include "bexel.h"
namespace bexel {
- Bexel::Bexel() : m_window(nullptr), m_shader(nullptr), m_world(nullptr) {
+ Bexel::Bexel() : window(nullptr), shader(nullptr), world(nullptr) {
}
void Bexel::init() {
- BEBONE_PROFILE_RECORD(BEXEL_INIT)
-
- GLFWContext::init();
-
- m_window = WindowFactory::create_window("4. Opengl Bexel example", GAME_WIDTH, GAME_HEIGHT, GfxAPI::OPENGL, {
- .enableResize = true
+ window = WindowFactory::create_window("4. Opengl Bexel example", game_width, game_height, OpenGL, {
+ .enable_resize = true
});
GLContext::load_opengl();
glfwSwapInterval(0);
-
- BEBONE_PROFILE_STOP(BEXEL_INIT)
}
void Bexel::load() {
- BEBONE_PROFILE_RECORD(BEXEL_LOAD)
+ const auto shader_flags = EnableUniforms;
- const auto shaderFlags = ENABLE_UNIFORMS;
+ auto vertex_shader = GLShaderFactory::create_shader("assets/vertex.glsl", ShaderType::VertexShader, shader_flags);
+ auto fragment_shader = GLShaderFactory::create_shader("assets/fragment.glsl", ShaderType::FragmentShader, shader_flags);
- auto vertexShader = GLShaderFactory::create_shader("assets/vertex.glsl", ShaderTypes::VERTEX_SHADER, shaderFlags);
- auto fragmentShader = GLShaderFactory::create_shader("assets/fragment.glsl", ShaderTypes::FRAGMENT_SHADER, shaderFlags);
+ shader = make_unique(vertex_shader, fragment_shader);
- m_shader = make_unique(vertexShader, fragmentShader);
+ camera = make_unique(Vec3f(0.0, -24.0f, 0.0f), 12);
+ world = make_unique();
- m_camera = make_unique(Vec3f(0.0, -24.0f, 0.0f), 12);
- m_world = make_unique();
-
- m_texture = make_unique("assets/texture.png");
-
- BEBONE_PROFILE_STOP(BEXEL_LOAD)
+ texture = make_unique("assets/texture.png");
}
void Bexel::run() {
- BEBONE_PROFILE_RECORD(BEXEL_RUN)
-
- GLContext::enable(GL_DEPTH_TEST);
- GLContext::enable(GL_CULL_FACE);
- GLContext::cull_face(GL_BACK);
- GLContext::front_face(GL_CW);
+ shader->set_uniform("inTexture", 0);
- m_shader->set_uniform("inTexture", 0);
-
- while (!m_window->closing()) {
- BEBONE_PROFILE_RECORD(BEXEL_UPDATE_LOOP)
-
- GLContext::set_viewport(0, 0, m_window->get_width(), m_window->get_height());
+ while (!window->closing()) {
+ GLContext::set_viewport(0, 0, window->get_width(), window->get_height());
GLContext::clear_color(0.47f, 0.65f, 1.0f, 1.0f);
GLContext::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- m_camera->update(m_window);
- m_world->update(m_camera);
-
- m_shader->enable();
+ camera->update(window);
+ world->update(camera);
- m_texture->bind();
+ shader->enable();
- m_camera->bind(m_shader);
- m_world->render(m_shader);
+ texture->bind();
- GLFWContext::swap_buffers(*m_window);
- GLFWContext::poll_events();
+ camera->bind(shader);
+ world->render(shader);
- BEBONE_PROFILE_STOP(BEXEL_UPDATE_LOOP)
+ GLFWContext::swap_buffers(*window);
+ window->pull_events();
}
-
- BEBONE_PROFILE_STOP(BEXEL_RUN)
}
void Bexel::unload() {
- m_camera = nullptr;
- m_world = nullptr;
-
- m_shader->destroy();
+ camera = nullptr;
+ world = nullptr;
- GLFWContext::terminate();
+ shader->destroy();
}
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/bexel.h b/examples/gfx/opengl/4_opengl_bexel/bexel.h
index cdf25ba8..1cf5a445 100644
--- a/examples/gfx/opengl/4_opengl_bexel/bexel.h
+++ b/examples/gfx/opengl/4_opengl_bexel/bexel.h
@@ -1,22 +1,22 @@
#ifndef BEXEL_BEXEL_H
#define BEXEL_BEXEL_H
-#include "gfx/opengl/4_opengl_bexel/world/world.h"
+#include "world/world.h"
#include "camera.h"
namespace bexel {
- static const u64 GAME_WIDTH = 800;
- static const u64 GAME_HEIGHT = 600;
+ static const u64 game_width = 800;
+ static const u64 game_height = 600;
class Bexel {
private:
- shared_ptr m_window;
+ shared_ptr window;
- unique_ptr m_shader;
- unique_ptr m_texture;
+ unique_ptr shader;
+ unique_ptr texture;
- unique_ptr m_camera;
- unique_ptr m_world;
+ unique_ptr camera;
+ unique_ptr world;
public:
Bexel();
diff --git a/examples/gfx/opengl/4_opengl_bexel/camera.cpp b/examples/gfx/opengl/4_opengl_bexel/camera.cpp
index 33f21b24..174ee37c 100644
--- a/examples/gfx/opengl/4_opengl_bexel/camera.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/camera.cpp
@@ -1,114 +1,86 @@
#include "camera.h"
namespace bexel {
- Camera::Camera(const Vec3f& position, const i32& renderDistance) {
- m_renderDistance = renderDistance;
+ Camera::Camera(const Vec3f& position, const i32& render_distance) {
+ this->render_distance = render_distance;
- m_position = position;
- m_rotation = Vec3f::zero;
- m_direction = Vec3f::zero;
+ this->position = position;
+ rotation = Vec3f::zero;
+ direction = Vec3f::zero;
- m_mouseLocked = true;
+ mouse_locked = true;
- m_viewMatrix = Mat4f::identity();
- m_projMatrix = Mat4f::identity();
- }
-
- Mat4f Camera::calculate_view_matrix() const {
- const static auto upVector = Vec3f::down;
-
- const auto w = m_direction.normalize();
- const auto u = w.cross(upVector).normalize();
- const auto v = w.cross(u);
-
- Mat4f viewMatrix = Mat4f::identity();
- viewMatrix[0 * 4 + 0] = u.x;
- viewMatrix[1 * 4 + 0] = u.y;
- viewMatrix[2 * 4 + 0] = u.z;
- viewMatrix[0 * 4 + 1] = v.x;
- viewMatrix[1 * 4 + 1] = v.y;
- viewMatrix[2 * 4 + 1] = v.z;
- viewMatrix[0 * 4 + 2] = w.x;
- viewMatrix[1 * 4 + 2] = w.y;
- viewMatrix[2 * 4 + 2] = w.z;
- viewMatrix[3 * 4 + 0] = -1.0f * (u).dot(m_position);
- viewMatrix[3 * 4 + 1] = -1.0f * (v).dot(m_position);
- viewMatrix[3 * 4 + 2] = -1.0f * (w).dot(m_position);
-
- return viewMatrix;
+ view_matrix = Mat4f::identity();
+ proj_matrix = Mat4f::identity();
}
void Camera::update(shared_ptr& window) {
- BEBONE_PROFILE_RECORD(BEXEL_CAMERA_UPDATE)
-
const f32 speed = 0.5f;
if (glfwGetKey(window->get_backend(), 'W') == GLFW_PRESS)
- m_position += Vec3f(1.0f, 0.0f, 1.0f) * m_direction.normalize() * speed;
+ position += Vec3f(1.0f, 0.0f, 1.0f) * direction.normalize() * speed;
if (glfwGetKey(window->get_backend(), 'S') == GLFW_PRESS)
- m_position -= Vec3f(1.0f, 0.0f, 1.0f) * m_direction.normalize() * speed;
+ position -= Vec3f(1.0f, 0.0f, 1.0f) * direction.normalize() * speed;
if (glfwGetKey(window->get_backend(), 'A') == GLFW_PRESS)
- m_position -= Vec3f(m_direction.z, 0.0f, -m_direction.x).normalize() * speed;
+ position -= Vec3f(direction.z, 0.0f, -direction.x).normalize() * speed;
if (glfwGetKey(window->get_backend(), 'D') == GLFW_PRESS)
- m_position += Vec3f(m_direction.z, 0.0f, -m_direction.x).normalize() * speed;
+ position += Vec3f(direction.z, 0.0f, -direction.x).normalize() * speed;
if (glfwGetKey(window->get_backend(), GLFW_KEY_SPACE) == GLFW_PRESS)
- m_position.y += speed;
+ position.y += speed;
if (glfwGetKey(window->get_backend(), GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
- m_position.y -= speed;
+ position.y -= speed;
- bool oldMouseLockState = m_mouseLocked;
- static auto buttonPressed = false;
- const auto isDebugButtonPressed = (glfwGetKey(window->get_backend(), GLFW_KEY_ENTER) == GLFW_RELEASE);
- m_mouseLocked = (isDebugButtonPressed && !buttonPressed) ? !m_mouseLocked : m_mouseLocked;
- buttonPressed = isDebugButtonPressed;
+ bool old_mouse_lock_state = mouse_locked;
+ static auto button_pressed = false;
+ const auto is_debug_button_pressed = (glfwGetKey(window->get_backend(), GLFW_KEY_ENTER) == GLFW_RELEASE);
+ mouse_locked = (is_debug_button_pressed && !button_pressed) ? !mouse_locked : mouse_locked;
+ button_pressed = is_debug_button_pressed;
- if(oldMouseLockState != m_mouseLocked)
+ if(old_mouse_lock_state != mouse_locked)
glfwSetCursorPos(window->get_backend(), window->get_width() / 2.0f, window->get_height() / 2.0f);
- if(m_mouseLocked) {
+ if(mouse_locked) {
glfwSetInputMode(window->get_backend(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
- const f64 centerXPos = window->get_width() / 2.0f;
- const f64 centerYPos = window->get_height() / 2.0f;
+ const f64 center_x_pos = window->get_width() / 2.0f;
+ const f64 center_y_pos = window->get_height() / 2.0f;
- f64 xPos, yPos;
- glfwGetCursorPos(window->get_backend(), &xPos, &yPos);
+ f64 x_pos, y_pos;
+ glfwGetCursorPos(window->get_backend(), &x_pos, &y_pos);
- const f32 deltaX = floor(centerXPos) - xPos;
- const f32 deltaY = floor(centerYPos) - yPos;
+ const f32 delta_x = floor(center_x_pos) - x_pos;
+ const f32 delta_y = floor(center_y_pos) - y_pos;
- m_rotation.x += deltaY * 0.005f;
- m_rotation.y += deltaX * 0.005f; // If this is confusing just think that we rotate Y axis cause of movement mouse a long X axis, actual this make sense
+ rotation.x += delta_y * 0.005f;
+ rotation.y += delta_x * 0.005f; // If this is confusing just think that we rotate Y axis cause of movement mouse a long X axis, actual this make sense
- glfwSetCursorPos(window->get_backend(), centerXPos, centerYPos);
+ glfwSetCursorPos(window->get_backend(), center_x_pos, center_y_pos);
} else
glfwSetInputMode(window->get_backend(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
- m_direction.x = cos(m_rotation.y) * cos(m_rotation.x);
- m_direction.y = sin(m_rotation.x);
- m_direction.z = sin(m_rotation.y) * cos(m_rotation.x);
-
- m_viewMatrix = calculate_view_matrix();
- m_projMatrix = Mat4f::perspective(1.0472, window->get_aspect(), 0.1f, 2000.0f);
+ direction.x = cos(rotation.y) * cos(rotation.x);
+ direction.y = sin(rotation.x);
+ direction.z = sin(rotation.y) * cos(rotation.x);
- BEBONE_PROFILE_STOP(BEXEL_CAMERA_UPDATE)
+ view_matrix = Mat4f::view(position, direction);
+ proj_matrix = Mat4f::perspective(1.0472, window->get_aspect(), 0.1f, 2000.0f);
}
void Camera::bind(unique_ptr& shader) {
- shader->set_uniform("proj", m_projMatrix);
- shader->set_uniform("view", m_viewMatrix);
+ shader->set_uniform("proj", proj_matrix);
+ shader->set_uniform("view", view_matrix);
}
const Vec3f& Camera::get_position() const {
- return m_position;
+ return position;
}
const i32& Camera::get_render_distance() const {
- return m_renderDistance;
+ return render_distance;
}
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/camera.h b/examples/gfx/opengl/4_opengl_bexel/camera.h
index e627cd93..42911c4e 100644
--- a/examples/gfx/opengl/4_opengl_bexel/camera.h
+++ b/examples/gfx/opengl/4_opengl_bexel/camera.h
@@ -1,26 +1,26 @@
#ifndef BEXEL_CAMERA_H
#define BEXEL_CAMERA_H
-#include "gfx/opengl/4_opengl_bexel/mesh/vertex.h"
+#include "mesh/vertex.h"
namespace bexel {
+ using namespace bebone;
+
class Camera : private core::NonCopyable {
private:
- i32 m_renderDistance;
-
- Vec3f m_position;
- Vec3f m_rotation;
- Vec3f m_direction;
+ i32 render_distance;
- bool m_mouseLocked;
+ Vec3f position;
+ Vec3f rotation;
+ Vec3f direction;
- Mat4f m_viewMatrix;
- Mat4f m_projMatrix;
+ bool mouse_locked;
- Mat4f calculate_view_matrix() const;
+ Mat4f view_matrix;
+ Mat4f proj_matrix;
public:
- Camera(const Vec3f& position, const i32& renderDistance);
+ Camera(const Vec3f& position, const i32& render_distance);
void update(shared_ptr& window);
void bind(unique_ptr& shader);
diff --git a/examples/gfx/opengl/4_opengl_bexel/direction.h b/examples/gfx/opengl/4_opengl_bexel/direction.h
index 1666849f..38de5a9d 100644
--- a/examples/gfx/opengl/4_opengl_bexel/direction.h
+++ b/examples/gfx/opengl/4_opengl_bexel/direction.h
@@ -3,12 +3,12 @@
namespace bexel {
enum Direction {
- UP,
- DOWN,
- LEFT,
- RIGHT,
- FORWARD,
- BACK
+ Up,
+ Down,
+ Left,
+ Right,
+ Forward,
+ Back
};
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/main.cpp b/examples/gfx/opengl/4_opengl_bexel/main.cpp
index b1efd0ce..853d05ca 100644
--- a/examples/gfx/opengl/4_opengl_bexel/main.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/main.cpp
@@ -5,8 +5,6 @@
using namespace bexel;
int main() {
- BEBONE_PROFILE_RECORD(BEXEL_MAIN)
-
Bexel bexel;
bexel.init();
@@ -14,9 +12,5 @@ int main() {
bexel.run();
bexel.unload();
- BEBONE_PROFILE_STOP(BEXEL_MAIN)
-
- bebone::core::Profiler::get_instance().result();
-
return 0;
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/mesh/mesh.cpp b/examples/gfx/opengl/4_opengl_bexel/mesh/mesh.cpp
index 428e050f..3238deaa 100644
--- a/examples/gfx/opengl/4_opengl_bexel/mesh/mesh.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/mesh/mesh.cpp
@@ -1,24 +1,24 @@
#include "mesh.h"
namespace bexel {
- Mesh::Mesh(const vector& vertices, const vector& indices) : m_vertices(vertices), m_indices(indices) {
- m_vao = make_unique();
- m_vao->bind();
+ Mesh::Mesh(const vector& vertices, const vector& indices) : vertices(vertices), indices(indices) {
+ vao = make_unique();
+ vao->bind();
- m_vbo = make_unique(m_vertices.data(), m_vertices.size() * sizeof(Vertex));
- m_ebo = make_unique(m_indices.data(), m_indices.size() * sizeof(u32));
+ vbo = make_unique(vertices.data(), vertices.size() * sizeof(Vertex));
+ ebo = make_unique(indices.data(), indices.size() * sizeof(u32));
- m_vao->link_attributes(*m_vbo, 0, 3, GL_FLOAT, sizeof(Vertex), (void*) offsetof(Vertex, pos));
- m_vao->link_attributes(*m_vbo, 1, 2, GL_FLOAT, sizeof(Vertex), (void*) offsetof(Vertex, tex));
+ vao->link_attributes(*vbo, 0, 3, GL_FLOAT, sizeof(Vertex), (void*) offsetof(Vertex, pos));
+ vao->link_attributes(*vbo, 1, 2, GL_FLOAT, sizeof(Vertex), (void*) offsetof(Vertex, tex));
- m_vao->unbind();
- m_vbo->unbind();
- m_ebo->unbind();
+ vao->unbind();
+ vbo->unbind();
+ ebo->unbind();
}
void Mesh::render() const {
- m_vao->bind();
+ vao->bind();
- GLContext::draw_elements(GL_TRIANGLES, static_cast(m_indices.size()), GL_UNSIGNED_INT, nullptr);
+ GLContext::draw_elements(GL_TRIANGLES, static_cast(indices.size()), GL_UNSIGNED_INT, nullptr);
}
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/mesh/mesh.h b/examples/gfx/opengl/4_opengl_bexel/mesh/mesh.h
index bffae034..02c7869b 100644
--- a/examples/gfx/opengl/4_opengl_bexel/mesh/mesh.h
+++ b/examples/gfx/opengl/4_opengl_bexel/mesh/mesh.h
@@ -7,14 +7,16 @@
#include "vertex.h"
namespace bexel {
+ using namespace bebone;
+
class Mesh final : private core::NonCopyable {
private:
- vector m_vertices;
- vector m_indices;
+ vector vertices;
+ vector indices;
- unique_ptr m_vao;
- unique_ptr m_vbo;
- unique_ptr m_ebo;
+ unique_ptr vao;
+ unique_ptr vbo;
+ unique_ptr ebo;
public:
Mesh(const vector& vertices, const vector& indices);
diff --git a/examples/gfx/opengl/4_opengl_bexel/mesh/mesh_builder.cpp b/examples/gfx/opengl/4_opengl_bexel/mesh/mesh_builder.cpp
index 8335d60f..0d7e541b 100644
--- a/examples/gfx/opengl/4_opengl_bexel/mesh/mesh_builder.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/mesh/mesh_builder.cpp
@@ -1,11 +1,11 @@
#include "mesh_builder.h"
namespace bexel {
- MeshBuilder::MeshBuilder() : m_indexOffset(0) {
+ MeshBuilder::MeshBuilder() : index_offset(0) {
}
unique_ptr MeshBuilder::build() {
- return make_unique(m_vertices, m_indices);
+ return make_unique(vertices, indices);
}
}
\ No newline at end of file
diff --git a/examples/gfx/opengl/4_opengl_bexel/mesh/mesh_builder.h b/examples/gfx/opengl/4_opengl_bexel/mesh/mesh_builder.h
index e50d6edb..602e5f83 100644
--- a/examples/gfx/opengl/4_opengl_bexel/mesh/mesh_builder.h
+++ b/examples/gfx/opengl/4_opengl_bexel/mesh/mesh_builder.h
@@ -11,63 +11,63 @@
namespace bexel {
class MeshBuilder {
private:
- vector m_vertices;
- vector m_indices;
+ vector vertices;
+ vector indices;
- u32 m_indexOffset;
+ u32 index_offset;
public:
MeshBuilder();
- template
- MeshBuilder& append(const _MeshData& meshData, const Transform& transform) {
- for(auto vertex : meshData.get_vertices()) {
+ template
+ MeshBuilder& append(const MeshData& mesh_data, const Transform& transform) {
+ for(auto vertex : mesh_data.get_vertices()) {
vertex.rotate(transform.rotation);
vertex.translate(transform.translation);
vertex.scale(transform.scale);
- m_vertices.push_back(vertex);
+ vertices.push_back(vertex);
}
- u32 maxIndex = 0;
- for(const auto& index : meshData.get_indices()) {
- m_indices.push_back(index + m_indexOffset);
+ u32 max_index = 0;
+ for(const auto& index : mesh_data.get_indices()) {
+ indices.push_back(index + index_offset);
- if(index > maxIndex)
- maxIndex = index;
+ if(index > max_index)
+ max_index = index;
}
- m_indexOffset += maxIndex + 1;
+ index_offset += max_index + 1;
return *this;
}
- template
- MeshBuilder& append(const _MeshData& meshData, const vector& textureCoords, const Transform& transform) {
- const auto size = meshData.get_vertices().size();
- const auto& vertices = meshData.get_vertices();
+ template
+ MeshBuilder& append(const MeshData& mesh_data, const vector& texture_coords, const Transform& transform) {
+ const auto size = mesh_data.get_vertices().size();
+ const auto& mesh_vertices = mesh_data.get_vertices();
for(size_t i = 0; i < size; ++i) {
- auto vertex = vertices[i];
+ auto vertex = mesh_vertices[i];
vertex.rotate(transform.rotation);
vertex.translate(transform.translation);
vertex.scale(transform.scale);
- vertex.tex = textureCoords[i];
+ vertex.tex = texture_coords[i];
- m_vertices.push_back(vertex);
+ vertices.push_back(vertex);
}
- u32 maxIndex = 0;
- for(const auto& index : meshData.get_indices()) {
- m_indices.push_back(index + m_indexOffset);
+ u32 max_index = 0;
+ for(const auto& index : mesh_data.get_indices()) {
+ indices.push_back(index + index_offset);
- if(index > maxIndex)
- maxIndex = index;
+ if(index > max_index)
+ max_index = index;
}
- m_indexOffset += maxIndex + 1;
+ index_offset += max_index + 1;
return *this;
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/mesh/vertex.h b/examples/gfx/opengl/4_opengl_bexel/mesh/vertex.h
index 89cdb967..901d62f4 100644
--- a/examples/gfx/opengl/4_opengl_bexel/mesh/vertex.h
+++ b/examples/gfx/opengl/4_opengl_bexel/mesh/vertex.h
@@ -1,14 +1,12 @@
#ifndef BEXEL_VERTEX_H
#define BEXEL_VERTEX_H
-#include "bebone.h"
+#include "bebone/bebone.h"
namespace bexel {
- using namespace bebone::core;
- using namespace bebone;
using namespace std;
+ using namespace bebone::core;
using namespace bebone::gfx;
- using namespace bebone::gfx::opengl;
struct Vertex {
Vec3f pos;
@@ -23,18 +21,18 @@ namespace bexel {
}
void rotate(const Mat4f& matrix) {
- f32 resultX = pos.x * matrix.e[0 * 4 + 0] + pos.y * matrix.e[1 * 4 + 0] + pos.z * matrix.e[2 * 4 + 0] + 1.0f * matrix.e[3 * 4 + 0];
- f32 resultY = pos.x * matrix.e[0 * 4 + 1] + pos.y * matrix.e[1 * 4 + 1] + pos.z * matrix.e[2 * 4 + 1] + 1.0f * matrix.e[3 * 4 + 1];
- f32 resultZ = pos.x * matrix.e[0 * 4 + 2] + pos.y * matrix.e[1 * 4 + 2] + pos.z * matrix.e[2 * 4 + 2] + 1.0f * matrix.e[3 * 4 + 2];
- const f32 resultW = pos.x * matrix.e[0 * 4 + 3] + pos.y * matrix.e[1 * 4 + 3] + pos.z * matrix.e[2 * 4 + 3] + 1.0f * matrix.e[3 * 4 + 3];
-
- if (resultW != 0.0f) {
- resultX /= resultW;
- resultY /= resultW;
- resultZ /= resultW;
+ f32 result_x = Vec3f::dot(pos, (Vec3f)matrix[0]) + matrix(3, 0);
+ f32 result_y = Vec3f::dot(pos, (Vec3f)matrix[1]) + matrix(3, 1);
+ f32 result_z = Vec3f::dot(pos, (Vec3f)matrix[2]) + matrix(3, 2);
+ const f32 result_w = Vec3f::dot(pos, (Vec3f)matrix[3]) + matrix(3, 3);
+
+ if (result_w != 0.0f) {
+ result_x /= result_w;
+ result_y /= result_w;
+ result_z /= result_w;
}
- pos = Vec3f(resultX, resultY, resultZ);
+ pos = Vec3f(result_x, result_y, result_z);
}
};
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/mesh/wall_mesh.h b/examples/gfx/opengl/4_opengl_bexel/mesh/wall_mesh.h
index 9df940ba..5a850f92 100644
--- a/examples/gfx/opengl/4_opengl_bexel/mesh/wall_mesh.h
+++ b/examples/gfx/opengl/4_opengl_bexel/mesh/wall_mesh.h
@@ -16,7 +16,7 @@ namespace bexel {
};
template<>
- struct WallMesh {
+ struct WallMesh {
const vector& get_vertices() const {
static const vector vertices = {
{{0.5f, 0.5f, 0.5f}, {1.0f, 1.0f}},
@@ -35,7 +35,7 @@ namespace bexel {
};
template<>
- struct WallMesh {
+ struct WallMesh {
const vector& get_vertices() const {
static const vector vertices = {
{{0.5f, -0.5f, 0.5f}, {1.0f, 1.0f}},
@@ -54,7 +54,7 @@ namespace bexel {
};
template<>
- struct WallMesh {
+ struct WallMesh {
const vector& get_vertices() const {
static const vector vertices = {
{{0.5f, 0.5f, 0.5f}, {1.0f, 1.0f}},
@@ -73,7 +73,7 @@ namespace bexel {
};
template<>
- struct WallMesh {
+ struct WallMesh {
const vector& get_vertices() const {
static const vector vertices = {
{{-0.5f, 0.5f, -0.5f}, {1.0f, 1.0f}},
@@ -92,7 +92,7 @@ namespace bexel {
};
template<>
- struct WallMesh {
+ struct WallMesh {
const vector& get_vertices() const {
static const vector vertices = {
{{-0.5f, 0.5f, 0.5f}, {1.0f, 1.0f}},
@@ -111,7 +111,7 @@ namespace bexel {
};
template<>
- struct WallMesh {
+ struct WallMesh {
const vector& get_vertices() const {
static const vector vertices = {
{{0.5f, 0.5f, -0.5f}, {1.0f, 1.0f}},
diff --git a/examples/gfx/opengl/4_opengl_bexel/renderable.h b/examples/gfx/opengl/4_opengl_bexel/renderable.h
index 3507d52f..290c9ce5 100644
--- a/examples/gfx/opengl/4_opengl_bexel/renderable.h
+++ b/examples/gfx/opengl/4_opengl_bexel/renderable.h
@@ -1,7 +1,7 @@
#ifndef BEXEL_RENDERABLE_H
#define BEXEL_RENDERABLE_H
-#include "gfx/opengl/4_opengl_bexel/mesh/vertex.h"
+#include "mesh/vertex.h"
namespace bexel {
class Renderable {
diff --git a/examples/gfx/opengl/4_opengl_bexel/transform.h b/examples/gfx/opengl/4_opengl_bexel/transform.h
index 481053eb..8770895b 100644
--- a/examples/gfx/opengl/4_opengl_bexel/transform.h
+++ b/examples/gfx/opengl/4_opengl_bexel/transform.h
@@ -1,7 +1,7 @@
#ifndef BEXEL_TRANSFORM_H
#define BEXEL_TRANSFORM_H
-#include "gfx/opengl/4_opengl_bexel/mesh/vertex.h"
+#include "mesh/vertex.h"
namespace bexel {
struct Transform {
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/block_id.h b/examples/gfx/opengl/4_opengl_bexel/world/block_id.h
index 46c8b9d9..790f9399 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/block_id.h
+++ b/examples/gfx/opengl/4_opengl_bexel/world/block_id.h
@@ -3,9 +3,9 @@
namespace bexel {
enum BlockID {
- UNDEFINED,
- AIR,
- SOLID
+ Undefined,
+ Air,
+ Solid
};
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/chunk.cpp b/examples/gfx/opengl/4_opengl_bexel/world/chunk.cpp
index 97912de8..813fddbc 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/chunk.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/world/chunk.cpp
@@ -2,34 +2,30 @@
#include "world.h"
namespace bexel {
- Chunk::Chunk(const Vec3f& pos) : m_mesh(nullptr) {
- m_transform.translation = pos;
- m_transform.rotation = Mat4f::identity();
- m_transform.scale = Vec3f::one;
+ Chunk::Chunk(const Vec3f& pos) : mesh(nullptr) {
+ transform.translation = pos;
+ transform.rotation = Mat4f::identity();
+ transform.scale = Vec3f::one;
}
Chunk::~Chunk() {
for(i32 x = 0; x < CHUNK_SIZE_X; ++x) {
for(i32 z = 0; z < CHUNK_SIZE_Z; ++z) {
for(i32 y = 0; y < CHUNK_SIZE_Y; ++y) {
- delete m_voxels[x][y][z];
+ delete voxels[x][y][z];
}
}
}
}
- void Chunk::generate_chunk(unique_ptr& worldGenerator) {
- BEBONE_PROFILE_RECORD(BEXEL_CHUNK_GENERATE_CHUNK)
-
+ void Chunk::generate_chunk(unique_ptr& world_generator) {
for(i32 x = 0; x < CHUNK_SIZE_X; ++x) {
for(i32 z = 0; z < CHUNK_SIZE_Z; ++z) {
for(i32 y = 0; y < CHUNK_SIZE_Y; ++y) {
- m_voxels[x][y][z] = worldGenerator->create_voxel_at(*this, Vec3i(x, y, z));
+ voxels[x][y][z] = world_generator->create_voxel_at(*this, Vec3i(x, y, z));
}
}
}
-
- BEBONE_PROFILE_STOP(BEXEL_CHUNK_GENERATE_CHUNK)
}
TileBlock* Chunk::get_voxel(const i32& x, const i32& y, const i32& z) {
@@ -37,17 +33,15 @@ namespace bexel {
if(y < 0 || y >= CHUNK_SIZE_Y) return nullptr;
if(z < 0 || z >= CHUNK_SIZE_Z) return nullptr;
- return m_voxels[x][y][z];
+ return voxels[x][y][z];
}
const Vec3f& Chunk::get_pos() const {
- return m_transform.translation;
+ return transform.translation;
}
void Chunk::generate_mesh(World& world) {
- BEBONE_PROFILE_RECORD(BEXEL_CHUNK_GENERATE_MESH)
-
- MeshBuilder meshBuilder;
+ MeshBuilder mesh_builder;
for(i32 x = 0; x < CHUNK_SIZE_X; ++x) {
for(i32 z = 0; z < CHUNK_SIZE_Z; ++z) {
@@ -55,28 +49,22 @@ namespace bexel {
auto voxel = get_voxel(x, y, z);
if(voxel != nullptr)
- voxel->append_mesh(meshBuilder, world, *this);
+ voxel->append_mesh(mesh_builder, world, *this);
}
}
}
- m_mesh = meshBuilder.build();
-
- BEBONE_PROFILE_STOP(BEXEL_CHUNK_GENERATE_MESH)
+ mesh = mesh_builder.build();
}
const Transform& Chunk::get_transform() const {
- return m_transform;
+ return transform;
}
void Chunk::render(unique_ptr& shader) {
- BEBONE_PROFILE_RECORD(BEXEL_CHUNK_RENDER)
-
- shader->set_uniform("transform", m_transform.calc_matrix());
-
- if(m_mesh != nullptr)
- m_mesh->render();
+ shader->set_uniform("transform", transform.calc_matrix());
- BEBONE_PROFILE_STOP(BEXEL_CHUNK_RENDER)
+ if(mesh != nullptr)
+ mesh->render();
}
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/chunk.h b/examples/gfx/opengl/4_opengl_bexel/world/chunk.h
index 8093b941..184df227 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/chunk.h
+++ b/examples/gfx/opengl/4_opengl_bexel/world/chunk.h
@@ -9,7 +9,7 @@
#include "../transform.h"
#include "world_generator.h"
-#include "gfx/opengl/4_opengl_bexel/world/tiles/tile_block.h"
+#include "world/tiles/tile_block.h"
#define CHUNK_SIZE_X 16
#define CHUNK_SIZE_Y 32
@@ -20,16 +20,16 @@ namespace bexel {
class Chunk final : public Renderable, private core::NonCopyable {
private:
- array, CHUNK_SIZE_Y>, CHUNK_SIZE_X> m_voxels;
- Transform m_transform;
+ array, CHUNK_SIZE_Y>, CHUNK_SIZE_X> voxels;
+ Transform transform;
- unique_ptr m_mesh;
+ unique_ptr mesh;
public:
Chunk(const Vec3f& pos);
~Chunk();
- void generate_chunk(unique_ptr& worldGenerator);
+ void generate_chunk(unique_ptr& world_generator);
void generate_mesh(World& world);
TileBlock* get_voxel(const i32& x, const i32& y, const i32& z);
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/tiles/block.cpp b/examples/gfx/opengl/4_opengl_bexel/world/tiles/block.cpp
index c136db41..d925abd3 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/tiles/block.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/world/tiles/block.cpp
@@ -1,61 +1,61 @@
#include "block.h"
-#include "gfx/opengl/4_opengl_bexel/world/chunk.h"
-#include "gfx/opengl/4_opengl_bexel/world/world.h"
+#include "world/chunk.h"
+#include "world/world.h"
namespace bexel {
- Block::Block(const Vec3f& chunkPosition) : TileBlock(false), m_chunkPosition(chunkPosition) {
+ Block::Block(const Vec3f& chunk_position) : TileBlock(false), chunk_position(chunk_position) {
}
- void Block::append_mesh(MeshBuilder& meshBuilder, World& world, Chunk& chunk) {
- const auto chunkPos = chunk.get_pos();
+ void Block::append_mesh(MeshBuilder& mesh_builder, World& world, Chunk& chunk) {
+ const auto chunk_pos = chunk.get_pos();
- const auto& x = m_chunkPosition.x + chunkPos.x;
- const auto& y = m_chunkPosition.y + chunkPos.y;
- const auto& z = m_chunkPosition.z + chunkPos.z;
+ const auto& x = chunk_position.x + chunk_pos.x;
+ const auto& y = chunk_position.y + chunk_pos.y;
+ const auto& z = chunk_position.z + chunk_pos.z;
- auto upBlock = world.get_voxel_at(Vec3f(x, y + 1.0f, z));
- auto downBlock = world.get_voxel_at(Vec3f(x, y - 1.0f, z));
- auto leftBlock = world.get_voxel_at(Vec3f(x + 1.0f, y, z));
- auto rightBlock = world.get_voxel_at(Vec3f(x - 1.0f, y, z));
- auto forwardBlock = world.get_voxel_at(Vec3f(x, y, z + 1.0f));
- auto backBlock = world.get_voxel_at(Vec3f(x, y, z - 1.0f));
+ auto up_block = world.get_voxel_at(Vec3f(x, y + 1.0f, z));
+ auto down_block = world.get_voxel_at(Vec3f(x, y - 1.0f, z));
+ auto left_block = world.get_voxel_at(Vec3f(x + 1.0f, y, z));
+ auto right_block = world.get_voxel_at(Vec3f(x - 1.0f, y, z));
+ auto forward_block = world.get_voxel_at(Vec3f(x, y, z + 1.0f));
+ auto back_block = world.get_voxel_at(Vec3f(x, y, z - 1.0f));
- if(upBlock != SOLID)
- meshBuilder.append(
- WallMesh{},
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one}
+ if(up_block != Solid)
+ mesh_builder.append(
+ WallMesh{},
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one}
);
- if(downBlock != SOLID)
- meshBuilder.append(
- WallMesh{},
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one}
+ if(down_block != Solid)
+ mesh_builder.append(
+ WallMesh{},
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one}
);
- if(leftBlock != SOLID)
- meshBuilder.append(
- WallMesh{},
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one}
+ if(left_block != Solid)
+ mesh_builder.append(
+ WallMesh{},
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one}
);
- if(rightBlock != SOLID)
- meshBuilder.append(
- WallMesh{},
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one}
+ if(right_block != Solid)
+ mesh_builder.append(
+ WallMesh{},
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one}
);
- if(forwardBlock != SOLID)
- meshBuilder.append(
- WallMesh{},
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one}
+ if(forward_block != Solid)
+ mesh_builder.append(
+ WallMesh{},
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one}
);
- if(backBlock != SOLID)
- meshBuilder.append(
- WallMesh{},
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one}
+ if(back_block != Solid)
+ mesh_builder.append(
+ WallMesh{},
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one}
);
}
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/tiles/block.h b/examples/gfx/opengl/4_opengl_bexel/world/tiles/block.h
index fb2fe6b7..dd6171d4 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/tiles/block.h
+++ b/examples/gfx/opengl/4_opengl_bexel/world/tiles/block.h
@@ -8,12 +8,12 @@ namespace bexel {
private:
protected:
- Vec3f m_chunkPosition;
+ Vec3f chunk_position;
public:
- Block(const Vec3f& chunkPosition);
+ Block(const Vec3f& chunk_position);
- void append_mesh(MeshBuilder& meshBuilder, World& world, Chunk& chunk) override;
+ void append_mesh(MeshBuilder& mesh_builder, World& world, Chunk& chunk) override;
};
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/tiles/directional_block.cpp b/examples/gfx/opengl/4_opengl_bexel/world/tiles/directional_block.cpp
index b9639f7f..8a58a020 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/tiles/directional_block.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/world/tiles/directional_block.cpp
@@ -4,69 +4,69 @@
#include "../world.h"
namespace bexel {
- DirectionalBlock::DirectionalBlock(const Vec3f& chunkPosition) : Block(chunkPosition) {
+ DirectionalBlock::DirectionalBlock(const Vec3f& chunk_position) : Block(chunk_position) {
}
- void DirectionalBlock::append_mesh(MeshBuilder& meshBuilder, World& world, Chunk& chunk) {
- const auto chunkPos = chunk.get_pos();
+ void DirectionalBlock::append_mesh(MeshBuilder& mesh_builder, World& world, Chunk& chunk) {
+ const auto chunk_pos = chunk.get_pos();
- const auto& x = m_chunkPosition.x + chunkPos.x;
- const auto& y = m_chunkPosition.y + chunkPos.y;
- const auto& z = m_chunkPosition.z + chunkPos.z;
+ const auto& x = chunk_position.x + chunk_pos.x;
+ const auto& y = chunk_position.y + chunk_pos.y;
+ const auto& z = chunk_position.z + chunk_pos.z;
- auto upBlock = world.get_voxel_at(Vec3f(x, y + 1.0f, z));
- auto downBlock = world.get_voxel_at(Vec3f(x, y - 1.0f, z));
- auto leftBlock = world.get_voxel_at(Vec3f(x + 1.0f, y, z));
- auto rightBlock = world.get_voxel_at(Vec3f(x - 1.0f, y, z));
- auto forwardBlock = world.get_voxel_at(Vec3f(x, y, z + 1.0f));
- auto backBlock = world.get_voxel_at(Vec3f(x, y, z - 1.0f));
+ auto up_block = world.get_voxel_at(Vec3f(x, y + 1.0f, z));
+ auto down_block = world.get_voxel_at(Vec3f(x, y - 1.0f, z));
+ auto left_block = world.get_voxel_at(Vec3f(x + 1.0f, y, z));
+ auto right_block = world.get_voxel_at(Vec3f(x - 1.0f, y, z));
+ auto forward_block = world.get_voxel_at(Vec3f(x, y, z + 1.0f));
+ auto back_block = world.get_voxel_at(Vec3f(x, y, z - 1.0f));
- if(upBlock != SOLID) {
- meshBuilder.append(
- WallMesh{},
+ if(up_block != Solid) {
+ mesh_builder.append(
+ WallMesh{},
get_up_tex_coords(),
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one
});
}
- if(downBlock != SOLID) {
- meshBuilder.append(
- WallMesh{},
+ if(down_block != Solid) {
+ mesh_builder.append(
+ WallMesh{},
get_down_tex_coords(),
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one
});
}
- if(leftBlock != SOLID) {
- meshBuilder.append(
- WallMesh{},
+ if(left_block != Solid) {
+ mesh_builder.append(
+ WallMesh{},
get_left_tex_coords(),
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one
});
}
- if(rightBlock != SOLID) {
- meshBuilder.append(
- WallMesh{},
+ if(right_block != Solid) {
+ mesh_builder.append(
+ WallMesh{},
get_right_tex_coords(),
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one
});
}
- if(forwardBlock != SOLID) {
- meshBuilder.append(
- WallMesh{},
+ if(forward_block != Solid) {
+ mesh_builder.append(
+ WallMesh{},
get_forward_tex_coords(),
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one
});
}
- if(backBlock != SOLID) {
- meshBuilder.append(
- WallMesh{},
+ if(back_block != Solid) {
+ mesh_builder.append(
+ WallMesh{},
get_back_tex_coords(),
- Transform{m_chunkPosition,Mat4f::identity(),Vec3f::one
+ Transform{chunk_position, Mat4f::identity(), Vec3f::one
});
}
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/tiles/directional_block.h b/examples/gfx/opengl/4_opengl_bexel/world/tiles/directional_block.h
index 5383976a..700b47db 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/tiles/directional_block.h
+++ b/examples/gfx/opengl/4_opengl_bexel/world/tiles/directional_block.h
@@ -8,7 +8,7 @@ namespace bexel {
private:
public:
- DirectionalBlock(const Vec3f& chunkPosition);
+ DirectionalBlock(const Vec3f& chunk_position);
virtual const vector& get_up_tex_coords() = 0;
virtual const vector& get_down_tex_coords() = 0;
@@ -17,7 +17,7 @@ namespace bexel {
virtual const vector& get_forward_tex_coords() = 0;
virtual const vector& get_back_tex_coords() = 0;
- void append_mesh(MeshBuilder& meshBuilder, World& world, Chunk& chunk) override;
+ void append_mesh(MeshBuilder& mesh_builder, World& world, Chunk& chunk) override;
};
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/tiles/grass_block.cpp b/examples/gfx/opengl/4_opengl_bexel/world/tiles/grass_block.cpp
index d212f7e5..d01f9692 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/tiles/grass_block.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/world/tiles/grass_block.cpp
@@ -1,7 +1,7 @@
#include "grass_block.h"
namespace bexel {
- GrassBlock::GrassBlock(const Vec3f& chunkPosition) : SideDirectionalBlock(chunkPosition) {
+ GrassBlock::GrassBlock(const Vec3f& chunk_position) : SideDirectionalBlock(chunk_position) {
}
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/tiles/grass_block.h b/examples/gfx/opengl/4_opengl_bexel/world/tiles/grass_block.h
index d2f75537..515358de 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/tiles/grass_block.h
+++ b/examples/gfx/opengl/4_opengl_bexel/world/tiles/grass_block.h
@@ -8,7 +8,7 @@ namespace bexel {
private:
public:
- GrassBlock(const Vec3f &chunkPosition);
+ GrassBlock(const Vec3f &chunk_position);
const vector& get_up_tex_coords() override {
static const vector coordinates = {
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/tiles/side_directional_block.cpp b/examples/gfx/opengl/4_opengl_bexel/world/tiles/side_directional_block.cpp
index 8e7e6f7b..f9ebef6d 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/tiles/side_directional_block.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/world/tiles/side_directional_block.cpp
@@ -1,7 +1,7 @@
#include "side_directional_block.h"
namespace bexel {
- SideDirectionalBlock::SideDirectionalBlock(const Vec3f& chunkPosition) : DirectionalBlock(chunkPosition) {
+ SideDirectionalBlock::SideDirectionalBlock(const Vec3f& chunk_position) : DirectionalBlock(chunk_position) {
}
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/tiles/side_directional_block.h b/examples/gfx/opengl/4_opengl_bexel/world/tiles/side_directional_block.h
index b2c13707..b703dab7 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/tiles/side_directional_block.h
+++ b/examples/gfx/opengl/4_opengl_bexel/world/tiles/side_directional_block.h
@@ -8,7 +8,7 @@ namespace bexel {
private:
public:
- SideDirectionalBlock(const Vec3f& chunkPosition);
+ SideDirectionalBlock(const Vec3f& chunk_position);
const vector& get_left_tex_coords() override {
return get_forward_tex_coords();
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/tiles/tile_block.h b/examples/gfx/opengl/4_opengl_bexel/world/tiles/tile_block.h
index 1ab4bea2..e0f68526 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/tiles/tile_block.h
+++ b/examples/gfx/opengl/4_opengl_bexel/world/tiles/tile_block.h
@@ -1,8 +1,8 @@
#ifndef BEXEL_TILE_BLOCK_H
#define BEXEL_TILE_BLOCK_H
-#include "gfx/opengl/4_opengl_bexel/mesh/vertex.h"
-#include "gfx/opengl/4_opengl_bexel/mesh/mesh_builder.h"
+#include "mesh/vertex.h"
+#include "mesh/mesh_builder.h"
namespace bexel {
class Chunk;
@@ -10,20 +10,20 @@ namespace bexel {
class TileBlock {
private:
- bool m_opaque;
+ bool opaque;
public:
- TileBlock(const bool& opaque) : m_opaque(opaque) {
+ TileBlock(const bool& opaque) : opaque(opaque) {
}
virtual ~TileBlock() = default;
const bool& is_opaque() const {
- return m_opaque;
+ return opaque;
}
- virtual void append_mesh(MeshBuilder& meshBuilder, World& world, Chunk& chunk) = 0;
+ virtual void append_mesh(MeshBuilder& mesh_builder, World& world, Chunk& chunk) = 0;
};
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/world.cpp b/examples/gfx/opengl/4_opengl_bexel/world/world.cpp
index cc116b97..8df8a394 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/world.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/world/world.cpp
@@ -1,64 +1,56 @@
#include "world.h"
namespace bexel {
- World::World() : m_worldGenerator(nullptr) {
- m_worldGenerator = make_unique(123);
+ World::World() : world_generator(nullptr) {
+ world_generator = make_unique(123);
}
- BlockID World::get_voxel_at(const Vec3f& voxelPos) const {
- return m_worldGenerator->get_voxel_at(voxelPos);
+ BlockID World::get_voxel_at(const Vec3f& voxel_pos) const {
+ return world_generator->get_voxel_at(voxel_pos);
}
bool World::chunk_exist(const Vec2i& pos) const {
- return m_chunks.find(pos) != m_chunks.end();
+ return chunks.find(pos) != chunks.end();
}
void World::update(unique_ptr& camera) {
- BEBONE_PROFILE_RECORD(BEXEL_WORLD_UPDATE)
-
const auto pos = camera->get_position();
- const auto camChunkPos = Vec2i(
+ const auto cam_chunk_pos = Vec2i(
static_cast(pos.x) / CHUNK_SIZE_X,
static_cast(pos.z) / CHUNK_SIZE_Z
);
- static auto prevChunkPos = Vec2i(camChunkPos.x + 1, camChunkPos.x);
+ static auto prev_chunk_pos = Vec2i(cam_chunk_pos.x + 1, cam_chunk_pos.x);
- if(prevChunkPos == camChunkPos)
+ if(prev_chunk_pos == cam_chunk_pos)
return;
- const auto renderDistance = camera->get_render_distance();
+ const auto render_distance = camera->get_render_distance();
- for(auto x = -renderDistance; x < renderDistance; ++x) {
- for(auto z = -renderDistance; z < renderDistance; ++z) {
- const auto toCheck = camChunkPos + Vec2i(x, z);
+ for(auto x = -render_distance; x < render_distance; ++x) {
+ for(auto z = -render_distance; z < render_distance; ++z) {
+ const auto to_check = cam_chunk_pos + Vec2i(x, z);
- if(chunk_exist(toCheck))
+ if(chunk_exist(to_check))
continue;
- const auto createChunkPos = Vec3f(
- static_cast(toCheck.x) * CHUNK_SIZE_X,
+ const auto create_chunk_pos = Vec3f(
+ static_cast(to_check.x) * CHUNK_SIZE_X,
0.0f,
- static_cast(toCheck.y) * CHUNK_SIZE_Z
+ static_cast(to_check.y) * CHUNK_SIZE_Z
);
- m_chunks[toCheck] = make_unique(createChunkPos);
- m_chunks[toCheck]->generate_chunk(m_worldGenerator);
- m_chunks[toCheck]->generate_mesh(*this);
+ chunks[to_check] = make_unique(create_chunk_pos);
+ chunks[to_check]->generate_chunk(world_generator);
+ chunks[to_check]->generate_mesh(*this);
}
}
-
- BEBONE_PROFILE_STOP(BEXEL_WORLD_UPDATE)
}
void World::render(unique_ptr& shader) {
- BEBONE_PROFILE_RECORD(BEXEL_WORLD_RENDER)
-
- for_each(m_chunks.begin(), m_chunks.end(), [&](const auto& tuple) {
+ for_each(chunks.begin(), chunks.end(), [&](const auto& tuple) {
const auto& chunk = tuple.second;
chunk->render(shader);
});
-
- BEBONE_PROFILE_STOP(BEXEL_WORLD_RENDER)
};
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/world.h b/examples/gfx/opengl/4_opengl_bexel/world/world.h
index ef6e2da2..faf20e4e 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/world.h
+++ b/examples/gfx/opengl/4_opengl_bexel/world/world.h
@@ -12,15 +12,15 @@
namespace bexel {
class World final : public Renderable, private core::NonCopyable {
private:
- unique_ptr m_worldGenerator;
- unordered_map> m_chunks;
+ unique_ptr world_generator;
+ unordered_map> chunks;
bool chunk_exist(const Vec2i& pos) const;
public:
World();
- BlockID get_voxel_at(const Vec3f& voxelPos) const;
+ BlockID get_voxel_at(const Vec3f& voxel_pos) const;
void update(unique_ptr& camera);
void render(unique_ptr& shader) override;
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/world_generator.cpp b/examples/gfx/opengl/4_opengl_bexel/world/world_generator.cpp
index c8845d9d..d0089253 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/world_generator.cpp
+++ b/examples/gfx/opengl/4_opengl_bexel/world/world_generator.cpp
@@ -2,40 +2,40 @@
#include "chunk.h"
namespace bexel {
- WorldGenerator::WorldGenerator(const i32& seed) : m_seed(seed) {
+ WorldGenerator::WorldGenerator(const i32& seed) : seed(seed) {
}
- BlockID WorldGenerator::get_voxel_at(const Vec3f& voxelPosF) const {
- const auto& x = voxelPosF.x;
- const auto& y = voxelPosF.y;
- const auto& z = voxelPosF.z;
+ BlockID WorldGenerator::get_voxel_at(const Vec3f& voxel_pos_f) const {
+ const auto& x = voxel_pos_f.x;
+ const auto& y = voxel_pos_f.y;
+ const auto& z = voxel_pos_f.z;
- auto v0 = stb_perlin_noise3_seed(x * 0.05f, 0, z * 0.05f,0, 0, 0, m_seed) * 0.5f + 0.5f;
- auto v1 = stb_perlin_noise3_seed(x * 0.01f, 0, z * 0.01f,0, 0, 0, m_seed) * 0.5f + 0.5f;
+ auto v0 = stb_perlin_noise3_seed(x * 0.05f, 0, z * 0.05f,0, 0, 0, seed) * 0.5f + 0.5f;
+ auto v1 = stb_perlin_noise3_seed(x * 0.01f, 0, z * 0.01f,0, 0, 0, seed) * 0.5f + 0.5f;
const auto v = v0 * 8.0f + v1 * 24.0f;
if(y > v)
- return AIR;
+ return Air;
- return SOLID;
+ return Solid;
}
- TileBlock* WorldGenerator::create_voxel_at(const Chunk& chunk, const Vec3i& voxelPosI) const {
- const auto voxelPosF = Vec3f(
- static_cast(voxelPosI.x),
- static_cast(voxelPosI.y),
- static_cast(voxelPosI.z)
+ TileBlock* WorldGenerator::create_voxel_at(const Chunk& chunk, const Vec3i& voxel_pos_i) const {
+ const auto voxel_pos_f = Vec3f(
+ static_cast(voxel_pos_i.x),
+ static_cast(voxel_pos_i.y),
+ static_cast(voxel_pos_i.z)
);
- const auto& chunkPos = chunk.get_pos();
- const auto globalPos = chunkPos + voxelPosF;
+ const auto& chunk_pos = chunk.get_pos();
+ const auto global_pos = chunk_pos + voxel_pos_f;
- const auto blockID = get_voxel_at(globalPos);
+ const auto block_id = get_voxel_at(global_pos);
- switch (blockID) {
- case SOLID: return new GrassBlock(voxelPosF);
+ switch (block_id) {
+ case Solid: return new GrassBlock(voxel_pos_f);
default: return nullptr;
}
}
diff --git a/examples/gfx/opengl/4_opengl_bexel/world/world_generator.h b/examples/gfx/opengl/4_opengl_bexel/world/world_generator.h
index 2721f8a5..99401d71 100644
--- a/examples/gfx/opengl/4_opengl_bexel/world/world_generator.h
+++ b/examples/gfx/opengl/4_opengl_bexel/world/world_generator.h
@@ -11,13 +11,13 @@ namespace bexel {
class WorldGenerator {
private:
- const i32 m_seed;
+ const i32 seed;
public:
WorldGenerator(const i32& seed);
- BlockID get_voxel_at(const Vec3f& voxelPosF) const;
- TileBlock* create_voxel_at(const Chunk& chunk, const Vec3i& voxelPosI) const;
+ BlockID get_voxel_at(const Vec3f& voxel_pos_f) const;
+ TileBlock* create_voxel_at(const Chunk& chunk, const Vec3i& voxel_pos_i) const;
};
}
diff --git a/examples/gfx/opengl/5_opengl_flappy_bird/CMakeLists.txt b/examples/gfx/opengl/5_opengl_flappy_bird/CMakeLists.txt
index 65f503ff..578ed9b0 100644
--- a/examples/gfx/opengl/5_opengl_flappy_bird/CMakeLists.txt
+++ b/examples/gfx/opengl/5_opengl_flappy_bird/CMakeLists.txt
@@ -1,7 +1,7 @@
file(GLOB_RECURSE BEBONE_EXAMPLE_GFX_OPENGL_5_OPENGL_FLAPPY_BIRD *.cpp)
-include_directories("../../src")
include_directories("./")
+include_directories(${BEBONE_INCLUDES})
add_executable(Bebone_Example_Gfx_5_Opengl_Flappy_Bird ${BEBONE_EXAMPLE_GFX_OPENGL_5_OPENGL_FLAPPY_BIRD})
target_link_libraries(Bebone_Example_Gfx_5_Opengl_Flappy_Bird bebone)
diff --git a/examples/gfx/opengl/5_opengl_flappy_bird/assets/vertex.glsl b/examples/gfx/opengl/5_opengl_flappy_bird/assets/vertex.glsl
index b0f997ef..40446c4d 100644
--- a/examples/gfx/opengl/5_opengl_flappy_bird/assets/vertex.glsl
+++ b/examples/gfx/opengl/5_opengl_flappy_bird/assets/vertex.glsl
@@ -7,11 +7,10 @@ layout (location = 2) in float a_TextureUnit;
layout (location = 0) out vec2 v_TexCoords;
layout (location = 1) out flat float v_TextureUnit;
-uniform mat4 u_Model;
uniform mat4 u_Projection;
void main() {
v_TexCoords = a_TexCoords;
v_TextureUnit = a_TextureUnit;
- gl_Position = u_Projection * u_Model * vec4(a_Position, 1.0);
+ gl_Position = u_Projection * vec4(a_Position, 1.0);
}
\ No newline at end of file
diff --git a/examples/gfx/opengl/5_opengl_flappy_bird/core/batch.cpp b/examples/gfx/opengl/5_opengl_flappy_bird/core/batch.cpp
index 0c6b47c4..90713b75 100644
--- a/examples/gfx/opengl/5_opengl_flappy_bird/core/batch.cpp
+++ b/examples/gfx/opengl/5_opengl_flappy_bird/core/batch.cpp
@@ -1,29 +1,29 @@
#include "batch.h"
namespace game::core {
- Batch::Batch(shared_ptr& shaderProgram, shared_ptr& camera, const size_t& quadLimit) :
- camera(camera), shaderProgram(shaderProgram), cachedTextureUnits(map, int>()), texturesToDraw(vector>()), currentTextureUnitIndex(0), indicesSize(0), quadSize(0), quadLimit(quadLimit) {
-
- textureUnitCapacity = min({GLGpuProperties::texture_unit_capacity(), MAX_TEXTURE_UNITS});
+ Batch::Batch(shared_ptr& shader_program, shared_ptr& camera, const size_t& quad_limit) :
+ camera(camera), shader_program(shader_program), cached_texture_units(map, int>()), textures_to_draw(vector>()), current_texture_unit_index(0), indices_size(0), quad_size(0), quad_limit(quad_limit) {
+
+ texture_unit_capacity = min({GLGpuProperties::texture_unit_capacity(), max_texture_units});
- size_t indexLimit = quadLimit * 6;
- size_t vertexLimit = quadLimit * 4;
+ size_t index_limit = quad_limit * 6;
+ size_t vertex_limit = quad_limit * 4;
vao = make_shared();
vao->bind();
- vbo = make_shared(nullptr, vertexLimit * sizeof(ShaderVertex), GL_DYNAMIC_DRAW);
- ebo = make_shared(nullptr, indexLimit * sizeof(u32), GL_DYNAMIC_DRAW);
+ vbo = make_shared(nullptr, vertex_limit * sizeof(ShaderVertex), GL_DYNAMIC_DRAW);
+ ebo = make_shared(nullptr, index_limit * sizeof(u32), GL_DYNAMIC_DRAW);
vao->link_attributes(*vbo, 0, 3, GL_FLOAT, sizeof(ShaderVertex), (void*)offsetof(ShaderVertex, position));
- vao->link_attributes(*vbo, 1, 2, GL_FLOAT, sizeof(ShaderVertex), (void*)offsetof(ShaderVertex, textureCoordinates));
- vao->link_attributes(*vbo, 2, 1, GL_INT, sizeof(ShaderVertex), (void*)offsetof(ShaderVertex, textureUnit));
+ vao->link_attributes(*vbo, 1, 2, GL_FLOAT, sizeof(ShaderVertex), (void*)offsetof(ShaderVertex, texture_coordinates));
+ vao->link_attributes(*vbo, 2, 1, GL_INT, sizeof(ShaderVertex), (void*)offsetof(ShaderVertex, texture_unit));
vao->unbind();
vbo->unbind();
ebo->unbind();
#ifdef BATCH_DEBUG
- drawCalls = 0;
+ draw_calls = 0;
#endif
}
@@ -37,75 +37,69 @@ namespace game::core {
ebo->destroy();
ebo = nullptr;
- shaderProgram->destroy();
- shaderProgram = nullptr;
+ shader_program->destroy();
+ shader_program = nullptr;
}
- void Batch::add(const shared_ptr& gameObject) {
- if (gameObjectsToDraw.find(gameObject) == gameObjectsToDraw.end()) {
- auto renderer = gameObject->get_component();
+ void Batch::add(const shared_ptr& game_object) {
+ if (game_objects_to_draw.find(game_object) == game_objects_to_draw.end()) {
+ auto renderer = game_object->get_component();
if (renderer != nullptr) {
- gameObjectsToDraw[gameObject] = renderer;
+ game_objects_to_draw[game_object] = renderer;
} else {
- cout << gameObject->get_name() << " does not have a SpriteRenderer!";
+ cout << game_object->get_name() << " does not have a SpriteRenderer!";
}
}
}
- void Batch::remove(const shared_ptr& gameObject) {
- gameObjectsToDraw.erase(gameObject);
+ void Batch::remove(const shared_ptr& game_object) {
+ game_objects_to_draw.erase(game_object);
}
void Batch::render() {
- gameObjectsToDrawIterator = gameObjectsToDraw.begin();
+ game_objects_to_draw_iterator = game_objects_to_draw.begin();
#ifdef BATCH_DEBUG
- drawCalls = 0;
+ draw_calls = 0;
#endif
- while (gameObjectsToDrawIterator != gameObjectsToDraw.end()) {
+ while (game_objects_to_draw_iterator != game_objects_to_draw.end()) {
upload_textures();
- shaderProgram->enable();
-
- Mat4f model = Mat4f::identity();
- model = model * model.scale(1.0f);
- model = model * omni::types::trait_bryan_angle_yxz(Vec3f(0.0f, 0.0f, 0.0f));
- model = model * model.translation(Vec3f(0.0f, 0.0f, 0.0f));
+ shader_program->enable();
- for (auto texture : texturesToDraw) {
- texture->bind_texture_unit(cachedTextureUnits[texture]);
+ for (const auto& texture : textures_to_draw) {
+ texture->bind_texture_unit(cached_texture_units[texture]);
}
vao->bind();
- shaderProgram->set_uniform("u_Model", model);
- shaderProgram->set_uniform("u_Projection", camera->get_projection_matrix());
- shaderProgram->set_uniform("u_Textures", textureUnitCapacity, samplers);
- GLContext::draw_elements(GL_TRIANGLES, static_cast(indicesSize), GL_UNSIGNED_INT, nullptr);
+ shader_program->set_uniform("u_Projection", camera->get_projection_matrix());
+ shader_program->set_uniform("u_Textures", texture_unit_capacity, samplers);
+ GLContext::draw_elements(GL_TRIANGLES, static_cast(indices_size), GL_UNSIGNED_INT, nullptr);
vao->unbind();
- quadSize = 0;
- indicesSize = 0;
- currentTextureUnitIndex = 0;
- cachedTextureUnits.clear();
- texturesToDraw.clear();
+ quad_size = 0;
+ indices_size = 0;
+ current_texture_unit_index = 0;
+ cached_texture_units.clear();
+ textures_to_draw.clear();
#ifdef BATCH_DEBUG
- ++drawCalls;
+ ++draw_calls;
#endif
}
}
void Batch::upload_textures() {
- while (gameObjectsToDrawIterator != gameObjectsToDraw.end()) {
- if (quadSize + 1 > quadLimit) {
+ while (game_objects_to_draw_iterator != game_objects_to_draw.end()) {
+ if (quad_size + 1 > quad_limit) {
return;
}
- auto gameObject = gameObjectsToDrawIterator->first;
- auto renderer = gameObjectsToDrawIterator->second;
+ auto game_object = game_objects_to_draw_iterator->first;
+ auto renderer = game_objects_to_draw_iterator->second;
- auto transform = gameObject->get_transform();
+ auto transform = game_object->get_transform();
auto sprite = renderer->get_sprite();
auto texture = sprite->get_texture();
@@ -113,33 +107,33 @@ namespace game::core {
return;
}
- auto quad = create_quad(sprite, transform, cachedTextureUnits[texture]);
- size_t verticesSize = quad.size() * sizeof(ShaderVertex);
+ auto quad = create_quad(sprite, transform, cached_texture_units[texture]);
+ size_t vertices_size = quad.size() * sizeof(ShaderVertex);
- vbo->buffer_sub_data(quadSize * verticesSize, verticesSize, quad.data());
- ++quadSize;
+ vbo->buffer_sub_data(quad_size * vertices_size, vertices_size, quad.data());
+ ++quad_size;
add_indices();
- ++gameObjectsToDrawIterator;
+ ++game_objects_to_draw_iterator;
}
}
bool Batch::try_cache_texture(const shared_ptr& texture) {
- if (currentTextureUnitIndex >= textureUnitCapacity) {
+ if (current_texture_unit_index >= texture_unit_capacity) {
return false;
}
- if (cachedTextureUnits.find(texture) == cachedTextureUnits.end()) {
- cachedTextureUnits[texture] = currentTextureUnitIndex;
- ++currentTextureUnitIndex;
+ if (cached_texture_units.find(texture) == cached_texture_units.end()) {
+ cached_texture_units[texture] = current_texture_unit_index;
+ ++current_texture_unit_index;
- texturesToDraw.push_back(texture);
+ textures_to_draw.push_back(texture);
}
return true;
}
- array Batch::create_quad(const shared_ptr& sprite, const shared_ptr& transform, const int& textureUnit) {
+ array Batch::create_quad(const shared_ptr& sprite, const shared_ptr& transform, const int& texture_unit) {
Vec3f position = transform->get_position();
f32 scale = transform->get_scale();
f32 rotation = transform->get_rotation();
@@ -149,62 +143,62 @@ namespace game::core {
Vec2f tmp;
ShaderVertex v0;
- tmp = rotateVertex( {-width, -height}, rotation);
+ tmp = rotate_vertex({-width, -height}, rotation);
v0.position = Vec3f(position.x + tmp.x, position.y + tmp.y, position.z);
- v0.textureCoordinates = { 0.0f, 0.0f };
- v0.textureUnit = textureUnit;
+ v0.texture_coordinates = {0.0f, 0.0f };
+ v0.texture_unit = texture_unit;
ShaderVertex v1;
- tmp = rotateVertex( {-width, height}, rotation);
+ tmp = rotate_vertex({-width, height}, rotation);
v1.position = Vec3f(position.x + tmp.x, position.y + tmp.y, position.z);
- v1.textureCoordinates = { 0.0f, 1.0f };
- v1.textureUnit = textureUnit;
+ v1.texture_coordinates = {0.0f, 1.0f };
+ v1.texture_unit = texture_unit;
ShaderVertex v2;
- tmp = rotateVertex( {width, height}, rotation);
+ tmp = rotate_vertex({width, height}, rotation);
v2.position = Vec3f(position.x + tmp.x, position.y + tmp.y, position.z);
- v2.textureCoordinates = { 1.0f, 1.0f };
- v2.textureUnit = textureUnit;
+ v2.texture_coordinates = {1.0f, 1.0f };
+ v2.texture_unit = texture_unit;
ShaderVertex v3;
- tmp = rotateVertex( {width, -height}, rotation);
+ tmp = rotate_vertex({width, -height}, rotation);
v3.position = Vec3f(position.x + tmp.x, position.y + tmp.y, position.z);
- v3.textureCoordinates = { 1.0f, 0.0f };
- v3.textureUnit = textureUnit;
+ v3.texture_coordinates = {1.0f, 0.0f };
+ v3.texture_unit = texture_unit;
return { v0, v1, v2, v3 };
}
- Vec2f Batch::rotateVertex(const Vec2f& v, const f32& angle) const {
- Vec2f newV = v;
+ Vec2f Batch::rotate_vertex(const Vec2f& v, const f32& angle) const {
+ Vec2f new_v = v;
double radian = Math::deg_to_rad(angle);
- newV.x = v.x * cos(radian) - v.y * sin(radian);
- newV.y = v.x * sin(radian) + v.y * cos(radian);
- return newV;
+ new_v.x = v.x * cos(radian) - v.y * sin(radian);
+ new_v.y = v.x * sin(radian) + v.y * cos(radian);
+ return new_v;
}
void Batch::add_indices() {
unsigned int indices[6];
- size_t totalVerticesSize = quadSize * 4;
+ size_t total_vertices_size = quad_size * 4;
- indices[0] = totalVerticesSize - 4;
- indices[1] = totalVerticesSize - 3;
- indices[2] = totalVerticesSize - 1;
+ indices[0] = total_vertices_size - 4;
+ indices[1] = total_vertices_size - 3;
+ indices[2] = total_vertices_size - 1;
- indices[3] = totalVerticesSize - 3;
- indices[4] = totalVerticesSize - 2;
- indices[5] = totalVerticesSize - 1;
+ indices[3] = total_vertices_size - 3;
+ indices[4] = total_vertices_size - 2;
+ indices[5] = total_vertices_size - 1;
- ebo->buffer_sub_data(indicesSize * sizeof(unsigned int), sizeof(indices), indices);
+ ebo->buffer_sub_data(indices_size * sizeof(unsigned int), sizeof(indices), indices);
- indicesSize += 6;
+ indices_size += 6;
}
#pragma region debug
#ifdef BATCH_DEBUG
size_t Batch::get_draw_call_count() const {
- return drawCalls;
+ return draw_calls;
}
#endif
#pragma endregion
diff --git a/examples/gfx/opengl/5_opengl_flappy_bird/core/batch.h b/examples/gfx/opengl/5_opengl_flappy_bird/core/batch.h
index 001df85c..345f5b3a 100644
--- a/examples/gfx/opengl/5_opengl_flappy_bird/core/batch.h
+++ b/examples/gfx/opengl/5_opengl_flappy_bird/core/batch.h
@@ -20,51 +20,51 @@
namespace game::core {
using namespace bebone::core;
using namespace std;
- using namespace bebone::gfx::opengl;
+ using namespace bebone::gfx;
using namespace ecs;
class Batch : private NonCopyable {
private:
shared_ptr camera;
- shared_ptr shaderProgram;
+ shared_ptr shader_program;
shared_ptr vao;
shared_ptr vbo;
shared_ptr ebo;
- const int MAX_TEXTURE_UNITS = 32;
- int textureUnitCapacity;
+ const int max_texture_units = 32;
+ int texture_unit_capacity;
int samplers[32] = {0, 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};
- map, shared_ptr> gameObjectsToDraw;
- map, shared_ptr>::iterator gameObjectsToDrawIterator;
+ map, shared_ptr> game_objects_to_draw;
+ map, shared_ptr>::iterator game_objects_to_draw_iterator;
- map, int> cachedTextureUnits;
- vector> texturesToDraw;
- int currentTextureUnitIndex;
+ map, int> cached_texture_units;
+ vector> textures_to_draw;
+ int current_texture_unit_index;
- size_t indicesSize;
- size_t quadSize;
- size_t quadLimit;
+ size_t indices_size;
+ size_t quad_size;
+ size_t quad_limit;
#pragma region debug
#ifdef BATCH_DEBUG
- size_t drawCalls;
+ size_t draw_calls;
#endif
#pragma endregion
- array create_quad(const shared_ptr& sprite, const shared_ptr& transform, const int& textureUnit);
+ array create_quad(const shared_ptr& sprite, const shared_ptr& transform, const int& texture_unit);
void add_indices();
void upload_textures();
- Vec2f rotateVertex(const Vec2f& v, const f32& angle) const;
+ Vec2f rotate_vertex(const Vec2f& v, const f32& angle) const;
bool try_cache_texture(const shared_ptr& texture);
public:
- Batch(shared_ptr& shaderProgram, shared_ptr& camera, const size_t& quadLimit);
+ Batch(shared_ptr& shader_program, shared_ptr