├── .clang-format ├── .github └── workflows │ ├── clang-format.sh │ ├── clang-format.yml │ ├── macos.yml │ └── ubuntu.yml ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── assets ├── README.md ├── matcap │ ├── ceramic_dark.png │ ├── ceramic_lightbulb.png │ ├── clay_studio.png │ └── jade.png ├── spot.obj ├── spot_texture.png └── teapot.obj ├── docs └── screen_shot.png ├── examples ├── cubes │ └── main.cpp ├── matcaps │ └── main.cpp ├── mesh │ └── main.cpp └── minimal │ └── main.cpp ├── include └── bigger │ ├── app.hpp │ ├── camera.hpp │ ├── material.hpp │ ├── materials │ ├── blinnphong-material.hpp │ └── matcap-material.hpp │ ├── primitive.hpp │ ├── primitives │ ├── cube-primitive.hpp │ ├── dynamic-mesh-primitive.hpp │ ├── mesh-primitive.hpp │ ├── plane-primitive.hpp │ └── sphere-primitive.hpp │ ├── scene-object.hpp │ ├── screen-shot-callback.hpp │ └── utils.hpp ├── shaders ├── blinnphong │ ├── fs_blinnphong.sc │ ├── varying.def.sc │ └── vs_blinnphong.sc └── matcap │ ├── fs_matcap.sc │ ├── varying.def.sc │ └── vs_matcap.sc └── src ├── app.cpp ├── camera.cpp ├── dynamic-mesh-primitive.cpp ├── mesh-primitive.cpp └── utils.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | Language: Cpp 2 | AccessModifierOffset: -4 3 | AlignAfterOpenBracket: Align 4 | AlignConsecutiveAssignments: true 5 | AlignConsecutiveDeclarations: true 6 | AlignEscapedNewlines: Right 7 | AlignOperands: true 8 | AlignTrailingComments: true 9 | AllowAllArgumentsOnNextLine: false 10 | AllowAllParametersOfDeclarationOnNextLine: false 11 | AllowShortBlocksOnASingleLine: false 12 | AllowShortCaseLabelsOnASingleLine: true 13 | AllowShortFunctionsOnASingleLine: All 14 | AllowShortIfStatementsOnASingleLine: false 15 | AllowShortLoopsOnASingleLine: false 16 | AlwaysBreakAfterDefinitionReturnType: None 17 | AlwaysBreakAfterReturnType: None 18 | AlwaysBreakBeforeMultilineStrings: false 19 | AlwaysBreakTemplateDeclarations: MultiLine 20 | BinPackArguments: false 21 | BinPackParameters: false 22 | BraceWrapping: 23 | AfterClass: false 24 | AfterControlStatement: false 25 | AfterEnum: false 26 | AfterFunction: false 27 | AfterNamespace: false 28 | AfterObjCDeclaration: false 29 | AfterStruct: false 30 | AfterUnion: false 31 | AfterExternBlock: false 32 | BeforeCatch: false 33 | BeforeElse: false 34 | IndentBraces: false 35 | SplitEmptyFunction: true 36 | SplitEmptyRecord: true 37 | SplitEmptyNamespace: true 38 | BreakBeforeBinaryOperators: None 39 | BreakBeforeBraces: Allman 40 | BreakBeforeInheritanceComma: false 41 | BreakInheritanceList: BeforeColon 42 | BreakBeforeTernaryOperators: true 43 | BreakConstructorInitializersBeforeComma: false 44 | BreakConstructorInitializers: BeforeColon 45 | BreakAfterJavaFieldAnnotations: false 46 | BreakStringLiterals: true 47 | ColumnLimit: 120 48 | CommentPragmas: '^ IWYU pragma:' 49 | CompactNamespaces: false 50 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 51 | ConstructorInitializerIndentWidth: 4 52 | ContinuationIndentWidth: 4 53 | Cpp11BracedListStyle: true 54 | DerivePointerAlignment: false 55 | DisableFormat: false 56 | ExperimentalAutoDetectBinPacking: false 57 | FixNamespaceComments: true 58 | ForEachMacros: 59 | - foreach 60 | - Q_FOREACH 61 | - BOOST_FOREACH 62 | IncludeBlocks: Merge 63 | IncludeCategories: 64 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 65 | Priority: 2 66 | - Regex: '^(<|"(gtest|gmock|isl|json)/)' 67 | Priority: 3 68 | - Regex: '.*' 69 | Priority: 1 70 | IncludeIsMainRegex: '(Test)?$' 71 | IndentCaseLabels: false 72 | IndentPPDirectives: None 73 | IndentWidth: 4 74 | IndentWrappedFunctionNames: false 75 | JavaScriptQuotes: Leave 76 | JavaScriptWrapImports: true 77 | KeepEmptyLinesAtTheStartOfBlocks: true 78 | MacroBlockBegin: '' 79 | MacroBlockEnd: '' 80 | MaxEmptyLinesToKeep: 1 81 | NamespaceIndentation: All 82 | ObjCBinPackProtocolList: Auto 83 | ObjCBlockIndentWidth: 2 84 | ObjCSpaceAfterProperty: false 85 | ObjCSpaceBeforeProtocolList: true 86 | PenaltyBreakAssignment: 2 87 | PenaltyBreakBeforeFirstCallParameter: 19 88 | PenaltyBreakComment: 300 89 | PenaltyBreakFirstLessLess: 120 90 | PenaltyBreakString: 1000 91 | PenaltyBreakTemplateDeclaration: 10 92 | PenaltyExcessCharacter: 1000000 93 | PenaltyReturnTypeOnItsOwnLine: 60 94 | PointerAlignment: Left 95 | ReflowComments: true 96 | SortIncludes: true 97 | SortUsingDeclarations: true 98 | SpaceAfterCStyleCast: true 99 | SpaceAfterTemplateKeyword: true 100 | SpaceBeforeAssignmentOperators: true 101 | SpaceBeforeCpp11BracedList: false 102 | SpaceBeforeCtorInitializerColon: true 103 | SpaceBeforeInheritanceColon: true 104 | SpaceBeforeParens: ControlStatements 105 | SpaceBeforeRangeBasedForLoopColon: true 106 | SpaceInEmptyParentheses: false 107 | SpacesBeforeTrailingComments: 1 108 | SpacesInAngles: false 109 | SpacesInContainerLiterals: true 110 | SpacesInCStyleCastParentheses: false 111 | SpacesInParentheses: false 112 | SpacesInSquareBrackets: false 113 | Standard: Cpp11 114 | StatementMacros: 115 | - Q_UNUSED 116 | - QT_REQUIRE_VERSION 117 | TabWidth: 4 118 | UseTab: Never 119 | -------------------------------------------------------------------------------- /.github/workflows/clang-format.sh: -------------------------------------------------------------------------------- 1 | clang-format src/*.cpp include/**/*.hpp examples/**/*.*pp --output-replacements-xml | grep -c "/dev/null 2 | if [ $? -ne 1 ]; then echo "Ill-styled code detected" && exit 1; fi 3 | -------------------------------------------------------------------------------- /.github/workflows/clang-format.yml: -------------------------------------------------------------------------------- 1 | name: Format Test 2 | 3 | on: [push] 4 | 5 | jobs: 6 | format-test: 7 | runs-on: macos-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v1 11 | - name: install-clang-format 12 | run: brew install clang-format 13 | - name: clang-format 14 | run: | 15 | sh ./.github/workflows/clang-format.sh 16 | -------------------------------------------------------------------------------- /.github/workflows/macos.yml: -------------------------------------------------------------------------------- 1 | name: macOS 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build-test: 7 | runs-on: macos-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v1 11 | - name: install-build-dependencies 12 | run: echo "No build dependencies" 13 | - name: submodule 14 | run: git submodule update --init --recursive 15 | - name: cmake -DBIGGER_EXAMPLES=ON 16 | run: cmake . 17 | - name: make 18 | run: make 19 | -------------------------------------------------------------------------------- /.github/workflows/ubuntu.yml: -------------------------------------------------------------------------------- 1 | name: Ubuntu 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build-test: 7 | runs-on: ${{ matrix.os }} 8 | 9 | strategy: 10 | matrix: 11 | os: [ubuntu-18.04, ubuntu-20.04, ubuntu-22.04] 12 | 13 | steps: 14 | - uses: actions/checkout@v1 15 | - name: install-build-dependencies 16 | run: sudo apt-get -y install libglu1-mesa-dev xorg-dev 17 | - name: submodule 18 | run: git submodule update --init --recursive 19 | - name: cmake -DBIGGER_EXAMPLES=ON 20 | run: cmake . 21 | - name: make 22 | run: make 23 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/bigg"] 2 | path = external/bigg 3 | url = https://github.com/Josh4428/bigg.git 4 | [submodule "external/tinyobjloader"] 5 | path = external/tinyobjloader 6 | url = https://github.com/tinyobjloader/tinyobjloader.git 7 | [submodule "external/rand-util"] 8 | path = external/rand-util 9 | url = https://github.com/yuki-koyama/rand-util.git 10 | [submodule "external/string-util"] 11 | path = external/string-util 12 | url = https://github.com/yuki-koyama/string-util.git 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | 3 | project(bigger CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(BGFX_AMALGAMATED OFF CACHE INTERNAL "" FORCE) 10 | set(BGFX_CONFIG_DEBUG OFF CACHE INTERNAL "" FORCE) 11 | set(BGFX_INSTALL OFF CACHE INTERNAL "" FORCE) 12 | set(BGFX_INSTALL_EXAMPLES OFF CACHE INTERNAL "" FORCE) 13 | set(BGFX_USE_DEBUG_SUFFIX OFF CACHE INTERNAL "" FORCE) 14 | set(BGFX_USE_OVR OFF CACHE INTERNAL "" FORCE) 15 | set(BIGG_ASSET_GEN OFF CACHE INTERNAL "" FORCE) 16 | set(BIGG_EXAMPLES OFF CACHE INTERNAL "" FORCE) 17 | set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE) 18 | set(BX_AMALGAMATED OFF CACHE INTERNAL "" FORCE) 19 | set(GLFW_DOCUMENT_INTERNALS OFF CACHE INTERNAL "" FORCE) 20 | set(GLFW_USE_CHDIR ON CACHE INTERNAL "" FORCE) 21 | set(GLFW_USE_MENUBAR ON CACHE INTERNAL "" FORCE) 22 | set(GLFW_USE_RETINA ON CACHE INTERNAL "" FORCE) 23 | set(GLFW_USE_OSMESA OFF CACHE INTERNAL "" FORCE) 24 | set(GLFW_VULKAN_STATIC OFF CACHE INTERNAL "" FORCE) 25 | set(LIB_SUFFIX "" CACHE INTERNAL "" FORCE) 26 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/bigg) 27 | 28 | # Note: This was necessary to avoid a run-time error on macOS/OpenGL. Without 29 | # this option, the NSOpenGLViewContext's setView method was called from a 30 | # wrong (?) thread during bgfx::init and then the app crashes. This needs to be 31 | # investigated further. 32 | target_compile_definitions(bgfx PUBLIC BGFX_CONFIG_MULTITHREADED=0) 33 | 34 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/rand-util) 35 | 36 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/string-util) 37 | 38 | set(TINYOBJLOADER_BUILD_OBJ_STICHER OFF CACHE INTERNAL "" FORCE) 39 | set(TINYOBJLOADER_BUILD_TEST_LOADER OFF CACHE INTERNAL "" FORCE) 40 | set(TINYOBJLOADER_USE_DOUBLE OFF CACHE INTERNAL "" FORCE) 41 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/tinyobjloader) 42 | 43 | set(headers 44 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/app.hpp 45 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/camera.hpp 46 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/material.hpp 47 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/primitive.hpp 48 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/scene-object.hpp 49 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/screen-shot-callback.hpp 50 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/utils.hpp 51 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/materials/blinnphong-material.hpp 52 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/materials/matcap-material.hpp 53 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/primitives/cube-primitive.hpp 54 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/primitives/dynamic-mesh-primitive.hpp 55 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/primitives/mesh-primitive.hpp 56 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/primitives/plane-primitive.hpp 57 | ${CMAKE_CURRENT_SOURCE_DIR}/include/bigger/primitives/sphere-primitive.hpp 58 | ) 59 | set(sources 60 | ${CMAKE_CURRENT_SOURCE_DIR}/src/app.cpp 61 | ${CMAKE_CURRENT_SOURCE_DIR}/src/camera.cpp 62 | ${CMAKE_CURRENT_SOURCE_DIR}/src/dynamic-mesh-primitive.cpp 63 | ${CMAKE_CURRENT_SOURCE_DIR}/src/mesh-primitive.cpp 64 | ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cpp 65 | ) 66 | set(shaders 67 | ${CMAKE_CURRENT_SOURCE_DIR}/shaders/blinnphong/vs_blinnphong.sc 68 | ${CMAKE_CURRENT_SOURCE_DIR}/shaders/blinnphong/fs_blinnphong.sc 69 | ${CMAKE_CURRENT_SOURCE_DIR}/shaders/blinnphong/varying.def.sc 70 | ${CMAKE_CURRENT_SOURCE_DIR}/shaders/matcap/vs_matcap.sc 71 | ${CMAKE_CURRENT_SOURCE_DIR}/shaders/matcap/fs_matcap.sc 72 | ${CMAKE_CURRENT_SOURCE_DIR}/shaders/matcap/varying.def.sc 73 | ) 74 | 75 | add_library(bigger STATIC ${headers} ${sources} ${shaders}) 76 | target_link_libraries(bigger PUBLIC bigg rand-util string-util tinyobjloader) 77 | target_include_directories(bigger PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) 78 | 79 | set(BIGGER_SHADER_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/shaders CACHE STRING "") 80 | 81 | add_shader(${CMAKE_CURRENT_SOURCE_DIR}/shaders/blinnphong/vs_blinnphong.sc VERTEX OUTPUT ${BIGGER_SHADER_OUTPUT_DIR} DX11_MODEL 5_0 GLSL 130) 82 | add_shader(${CMAKE_CURRENT_SOURCE_DIR}/shaders/blinnphong/fs_blinnphong.sc FRAGMENT OUTPUT ${BIGGER_SHADER_OUTPUT_DIR} DX11_MODEL 5_0 GLSL 130) 83 | add_shader(${CMAKE_CURRENT_SOURCE_DIR}/shaders/matcap/vs_matcap.sc VERTEX OUTPUT ${BIGGER_SHADER_OUTPUT_DIR} DX11_MODEL 5_0 GLSL 130) 84 | add_shader(${CMAKE_CURRENT_SOURCE_DIR}/shaders/matcap/fs_matcap.sc FRAGMENT OUTPUT ${BIGGER_SHADER_OUTPUT_DIR} DX11_MODEL 5_0 GLSL 130) 85 | 86 | option(BIGGER_EXAMPLES ON "") 87 | if(BIGGER_EXAMPLES) 88 | add_executable(minimal ${CMAKE_CURRENT_SOURCE_DIR}/examples/minimal/main.cpp) 89 | target_link_libraries(minimal bigger) 90 | 91 | add_executable(cubes ${CMAKE_CURRENT_SOURCE_DIR}/examples/cubes/main.cpp) 92 | target_link_libraries(cubes bigger) 93 | add_custom_command(TARGET cubes POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${BIGGER_SHADER_OUTPUT_DIR} $/shaders) 94 | 95 | add_executable(mesh ${CMAKE_CURRENT_SOURCE_DIR}/examples/mesh/main.cpp) 96 | target_link_libraries(mesh bigger) 97 | add_custom_command(TARGET mesh POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${BIGGER_SHADER_OUTPUT_DIR} $/shaders) 98 | add_custom_command(TARGET mesh POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets $/assets) 99 | 100 | add_executable(matcaps ${CMAKE_CURRENT_SOURCE_DIR}/examples/matcaps/main.cpp) 101 | target_link_libraries(matcaps bigger) 102 | add_custom_command(TARGET matcaps POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${BIGGER_SHADER_OUTPUT_DIR} $/shaders) 103 | add_custom_command(TARGET matcaps POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets $/assets) 104 | endif() 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Yuki Koyama 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bigger 2 | 3 | ![macOS](https://github.com/yuki-koyama/bigger/workflows/macOS/badge.svg) 4 | ![Ubuntu](https://github.com/yuki-koyama/bigger/workflows/Ubuntu/badge.svg) 5 | [![GitHub license](https://img.shields.io/github/license/yuki-koyama/bigger)](https://github.com/yuki-koyama/bigger/blob/master/LICENSE) 6 | 7 | bigg (bgfx + imgui + glfw + glm) + utils 8 | 9 | This library, named `bigger`, is a prototype-oriented middleware library for 3D interactive applications. Based on a library named `bigg`, which stands for `bgfx` + `imgui` + `glfw` + `glm`, this library adds some higher-level utilities (such as renderable primitive classes) to make the prototyping of lightweight and cross-platform apps even easier. 10 | 11 | ![](./docs/screen_shot.png) 12 | 13 | ## Languages 14 | 15 | - C++17 16 | - GLSL 1.30 17 | 18 | ## Dependencies 19 | 20 | - bigg [Unlicense] 21 | - bgfx.cmake [CC0 1.0 Universal] 22 | - bgfx [BSD 2-Clause] 23 | - bimg [BSD 2-Clause] 24 | - bx [BSD 2-Clause] 25 | - Dear ImGui [MIT] 26 | - GLFW [Zlib] 27 | - GLM [MIT] 28 | - random-util [MIT] 29 | - string-util [MIT] 30 | - tinyobjloader [MIT] 31 | 32 | ## Main Classes 33 | 34 | - App __(needs to be overridden)__ 35 | - Camera 36 | - Primitives 37 | - Cube primitive 38 | - Dynamic mesh primitive 39 | - Mesh primitive 40 | - Plane primitive 41 | - Sphere primitive 42 | - Materials 43 | - Blinn-Phong material 44 | - MatCap material 45 | 46 | ## App Event Cycle 47 | 48 | - `bigger::App::runApp()` 49 | - `bigg::Application::run()` 50 | - `glfw` initialization 51 | - `bgfx` initialization 52 | - `imgui` initialization 53 | - Reset 54 | - `bigger::App::initialize()` __(needs to be overridden)__ 55 | - Main loop 56 | - `glfw` event polling 57 | - `imgui` event polling 58 | - `bigger::App::update()` 59 | - `bigger::App::updateApp()` __(needs to be overridden)__ 60 | - Update scene objects (`bigger::SceneObject::update()`) 61 | - Render scene objects (`bigger::SceneObject::draw()`) 62 | - `imgui` render 63 | - `bgfx` submit 64 | - `bigger::App::shutdown()` 65 | - Release scene objects 66 | - `bigger::App::releaseSharedResources()` __(needs to be overridden)__ 67 | - `imgui` shutdown 68 | - `bgfx` shutdown 69 | - `glfw` shutdown 70 | 71 | ## App Design 72 | 73 | - Always two directional lights 74 | - Other types of lights or more than two directional lights are not supported 75 | - Intensive use of smart pointers 76 | - Primitives and materials need to be dynamically instantiated and managed by smart pointers (i.e., either `std::shared_ptr` or `std::unique_ptr`) 77 | 78 | ## Usage 79 | 80 | ### Minimal Example 81 | 82 | This is a minimal example of using `bigger::App`. This app just shows a blank window and do nothing. 83 | 84 | ```cpp 85 | #include 86 | 87 | class MinimalApp final : public bigger::App 88 | { 89 | public: 90 | 91 | MinimalApp() {} 92 | 93 | void initialize(int argc, char** argv) override {} 94 | void updateApp() override {} 95 | void releaseSharedResources() override {} 96 | }; 97 | 98 | int main(int argc, char** argv) 99 | { 100 | MinimalApp app; 101 | return app.runApp(argc, argv); 102 | } 103 | ``` 104 | 105 | ### Override App Class 106 | 107 | The following three methods need to be overridden by the new app class: 108 | 109 | - `bigger::App::initialize()`: Initializing the app and instantiating necessary objects living through the app life. 110 | - `bigger::App::updateApp()`: Writing frame-wise update rules and calling `imgui` draw calls. 111 | - `bigger::App::releaseSharedResources()`: Releasing shared resources maintained by the app class (such as vertex buffers). 112 | 113 | ### (TODO) 114 | 115 | ### Additional Notes: Screen Capture 116 | 117 | `bgfx` provides screen capture functionalities, which of course can be directly called (see the official documentation and examples). For easier use, in `bigger` by default, just inserting the following one-line code into `update()` can capture the screen: 118 | 119 | ``` 120 | bgfx::requestScreenShot(BGFX_INVALID_HANDLE, "/path/to/output"); 121 | ``` 122 | 123 | Note: On macOS, using the Metal backend somehow fails to capture the screen (not sure why; probably related to [this issue](https://github.com/bkaradzic/bgfx/issues/1833)). A possible quick fix is to use OpenGL. 124 | 125 | ## License 126 | 127 | MIT License 128 | 129 | ## Contribution 130 | 131 | Issue reports & pull requests are highly welcomed. 132 | -------------------------------------------------------------------------------- /assets/README.md: -------------------------------------------------------------------------------- 1 | # teapot.obj 2 | 3 | Originally provided by Martin Newell, downloaded from , edited by Yuki Koyama, licensed under CC0. 4 | 5 | # spot.obj / spot_texture.png 6 | 7 | Originally provided by Keenan Crane, downloaded from , edited by Yuki Koyama, released into the public domain. 8 | 9 | # MatCap 10 | 11 | ## jade.png / clay_studio.png / ceramic_lightbulb.png / ceramic_dark.png 12 | 13 | Originally provided by the Blender community, downloaded from , edited by Yuki Koyama, released under CC0. 14 | -------------------------------------------------------------------------------- /assets/matcap/ceramic_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuki-koyama/bigger/35102fc1b3a3f8dc5c1c00ae9b41660bf9cdbb96/assets/matcap/ceramic_dark.png -------------------------------------------------------------------------------- /assets/matcap/ceramic_lightbulb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuki-koyama/bigger/35102fc1b3a3f8dc5c1c00ae9b41660bf9cdbb96/assets/matcap/ceramic_lightbulb.png -------------------------------------------------------------------------------- /assets/matcap/clay_studio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuki-koyama/bigger/35102fc1b3a3f8dc5c1c00ae9b41660bf9cdbb96/assets/matcap/clay_studio.png -------------------------------------------------------------------------------- /assets/matcap/jade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuki-koyama/bigger/35102fc1b3a3f8dc5c1c00ae9b41660bf9cdbb96/assets/matcap/jade.png -------------------------------------------------------------------------------- /assets/spot_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuki-koyama/bigger/35102fc1b3a3f8dc5c1c00ae9b41660bf9cdbb96/assets/spot_texture.png -------------------------------------------------------------------------------- /docs/screen_shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuki-koyama/bigger/35102fc1b3a3f8dc5c1c00ae9b41660bf9cdbb96/docs/screen_shot.png -------------------------------------------------------------------------------- /examples/cubes/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class CubeObject; 11 | 12 | class CubesApp final : public bigger::App 13 | { 14 | public: 15 | CubesApp(); 16 | 17 | void initialize(int argc, char** argv) override; 18 | void onReset() override; 19 | 20 | void updateApp() override; 21 | void releaseSharedResources() override; 22 | 23 | // State variables 24 | int m_massive_level; 25 | 26 | // Const values 27 | const int m_max_massive_level = 8; 28 | 29 | private: 30 | // Shared resources 31 | std::shared_ptr m_cube_material; 32 | std::shared_ptr m_cube_primitive; 33 | }; 34 | 35 | class CubeObject final : public bigger::SceneObject 36 | { 37 | public: 38 | CubeObject(const CubesApp* app, 39 | const int x, 40 | const int y, 41 | std::shared_ptr material, 42 | std::shared_ptr cube) 43 | : bigger::SceneObject(material), m_x(x), m_y(y), m_app(app), m_cube(cube) 44 | { 45 | assert(app != nullptr); 46 | assert(material != nullptr); 47 | assert(cube != nullptr); 48 | } 49 | 50 | void update() override 51 | { 52 | // Update transform 53 | const float t = m_app->m_time; 54 | m_rotate_matrix = glm::rotate(glm::mat4(1.0), t, glm::vec3(m_x, m_y, 1.0f)); 55 | 56 | // Update visibility 57 | m_is_visible = std::max(std::abs(m_x), std::abs(m_y)) <= m_app->m_massive_level; 58 | } 59 | 60 | void draw(const glm::mat4& parent_transform_matrix = glm::mat4(1.0f)) override 61 | { 62 | const glm::mat4 transform_matrix = parent_transform_matrix * getTransform(); 63 | bgfx::setTransform(glm::value_ptr(transform_matrix)); 64 | 65 | m_material->submitUniforms(); 66 | m_cube->submitPrimitive(m_material->m_program); 67 | } 68 | 69 | const int m_x; 70 | const int m_y; 71 | 72 | private: 73 | // Pointer to the app 74 | const CubesApp* m_app; 75 | 76 | // Assigned resources 77 | std::shared_ptr m_cube; 78 | }; 79 | 80 | CubesApp::CubesApp() 81 | { 82 | getCamera().m_position = glm::vec3(0.0f, 0.0f, -5.0f); 83 | 84 | m_massive_level = 2; 85 | } 86 | 87 | void CubesApp::initialize(int argc, char** argv) 88 | { 89 | // Register and apply BGFX configuration settings 90 | reset(BGFX_RESET_VSYNC | BGFX_RESET_MSAA_X8); 91 | 92 | // Instantiate shared resources 93 | m_cube_material = std::make_shared(); 94 | m_cube_primitive = std::make_shared(); 95 | 96 | // Instantiate scene objects 97 | for (int x = -m_max_massive_level; x <= m_max_massive_level; ++x) 98 | { 99 | for (int y = -m_max_massive_level; y <= m_max_massive_level; ++y) 100 | { 101 | auto cube_object = std::make_shared(this, x, y, m_cube_material, m_cube_primitive); 102 | 103 | cube_object->m_translate_matrix = glm::translate(glm::mat4(1.0), glm::vec3(x, y, 0.0f)); 104 | cube_object->m_scale_matrix = glm::scale(glm::mat4(1.0), glm::vec3(std::pow(3.0f, -0.5f))); 105 | 106 | addSceneObject(cube_object); 107 | } 108 | } 109 | } 110 | 111 | void CubesApp::onReset() 112 | { 113 | constexpr uint32_t bg_color = 0x303030ff; 114 | 115 | bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, bg_color, 1.0f, 0); 116 | } 117 | 118 | void CubesApp::updateApp() 119 | { 120 | // Display ImGui components 121 | ImGui::Begin("Config"); 122 | { 123 | ImGui::Text("frame: %d", m_frame); 124 | ImGui::Text("time: %.2f", m_time); 125 | ImGui::Text("fps: %.2f", 1.0f / m_last_dt); 126 | ImGui::Separator(); 127 | getCamera().drawImgui(); 128 | ImGui::Separator(); 129 | m_cube_material->drawImgui(); 130 | ImGui::Separator(); 131 | ImGui::SliderInt("massive_level", &m_massive_level, 1, m_max_massive_level); 132 | } 133 | ImGui::End(); 134 | } 135 | 136 | void CubesApp::releaseSharedResources() 137 | { 138 | // Release shared resources 139 | m_cube_material = nullptr; 140 | m_cube_primitive = nullptr; 141 | } 142 | 143 | int main(int argc, char** argv) 144 | { 145 | CubesApp app; 146 | return app.runApp(argc, argv); 147 | } 148 | -------------------------------------------------------------------------------- /examples/matcaps/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class MeshObject; 12 | 13 | class MatcapApp final : public bigger::App 14 | { 15 | public: 16 | MatcapApp() { getCamera().m_target = glm::vec3(0.0f, 0.1f, 0.0f); } 17 | 18 | void initialize(int argc, char** argv) override; 19 | void onReset() override; 20 | 21 | void updateApp() override; 22 | void releaseSharedResources() override; 23 | 24 | private: 25 | // Shared resources 26 | std::shared_ptr m_mesh_material; 27 | std::shared_ptr m_mesh_primitive; 28 | std::array m_tex_matcaps; 29 | 30 | // Current state 31 | int m_matcap_index = 1; 32 | 33 | // Static resources 34 | static constexpr std::array k_matcap_paths = { 35 | "assets/matcap/ceramic_dark.png", 36 | "assets/matcap/ceramic_lightbulb.png", 37 | "assets/matcap/clay_studio.png", 38 | "assets/matcap/jade.png", 39 | }; 40 | static constexpr std::array k_matcap_names = { 41 | "Ceramic Dark", 42 | "Ceramic Lightbulb", 43 | "Clay Studio", 44 | "Jade", 45 | }; 46 | }; 47 | 48 | class MeshObject final : public bigger::SceneObject 49 | { 50 | public: 51 | MeshObject(const MatcapApp* app, 52 | std::shared_ptr material, 53 | std::shared_ptr mesh) 54 | : bigger::SceneObject(material), m_app(app), m_primitive(mesh) 55 | { 56 | assert(app != nullptr); 57 | assert(material != nullptr); 58 | assert(mesh != nullptr); 59 | } 60 | 61 | void update() override 62 | { 63 | // Update transform 64 | const float t = m_app->m_time; 65 | m_rotate_matrix = glm::rotate(glm::mat4(1.0f), t, glm::vec3(0.0f, 1.0f, 0.0f)); 66 | } 67 | 68 | void draw(const glm::mat4& parent_transform_matrix = glm::mat4(1.0f)) override 69 | { 70 | const glm::mat4 transform_matrix = parent_transform_matrix * getTransform(); 71 | bgfx::setTransform(glm::value_ptr(transform_matrix)); 72 | 73 | m_material->submitUniforms(); 74 | m_primitive->submitPrimitive(m_material->m_program); 75 | } 76 | 77 | private: 78 | // Pointer to the app 79 | const MatcapApp* m_app; 80 | 81 | // Assigned resources 82 | std::shared_ptr m_primitive; 83 | }; 84 | 85 | void MatcapApp::initialize(int argc, char** argv) 86 | { 87 | assert(std::size(m_tex_matcaps) == std::size(k_matcap_paths)); 88 | assert(std::size(m_tex_matcaps) == std::size(k_matcap_names)); 89 | 90 | // Register and apply BGFX configuration settings 91 | reset(BGFX_RESET_VSYNC | BGFX_RESET_MSAA_X8); 92 | 93 | // Instantiate shared resources (matcap textures) 94 | for (int i = 0; i < std::size(m_tex_matcaps); ++i) 95 | { 96 | m_tex_matcaps[i] = bigger::loadTexture(k_matcap_paths[i]); 97 | } 98 | 99 | // Instantiate shared resources (matcap material) 100 | m_mesh_material = std::make_shared(); 101 | 102 | m_mesh_material->setTexMatcap(&(m_tex_matcaps[m_matcap_index])); 103 | 104 | // Instantiate shared resources (mesh) 105 | const std::string obj_path = "assets/spot.obj"; 106 | 107 | m_mesh_primitive = std::make_shared(obj_path); 108 | 109 | // Instantiate scene objects 110 | auto mesh_object = std::make_shared(this, m_mesh_material, m_mesh_primitive); 111 | 112 | addSceneObject(mesh_object); 113 | } 114 | 115 | void MatcapApp::onReset() 116 | { 117 | constexpr uint32_t bg_color = 0x303030ff; 118 | 119 | bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, bg_color, 1.0f, 0); 120 | } 121 | 122 | void MatcapApp::updateApp() 123 | { 124 | // Display ImGui components 125 | ImGui::Begin("Config"); 126 | { 127 | ImGui::Text("frame: %d", m_frame); 128 | ImGui::Text("time: %.2f", m_time); 129 | ImGui::Text("fps: %.2f", 1.0f / m_last_dt); 130 | ImGui::Separator(); 131 | getCamera().drawImgui(); 132 | ImGui::Separator(); 133 | m_mesh_material->drawImgui(); 134 | ImGui::Separator(); 135 | ImGui::Text("App Setting"); 136 | if (ImGui::Combo("MatCap", &m_matcap_index, k_matcap_names.data(), std::size(k_matcap_names))) 137 | { 138 | assert(m_matcap_index < std::size(m_tex_matcaps)); 139 | 140 | // Update the MatCap texture 141 | m_mesh_material->setTexMatcap(&(m_tex_matcaps[m_matcap_index])); 142 | } 143 | } 144 | ImGui::End(); 145 | } 146 | 147 | void MatcapApp::releaseSharedResources() 148 | { 149 | // Release shared resources 150 | m_mesh_material = nullptr; 151 | m_mesh_primitive = nullptr; 152 | 153 | for (int i = 0; i < std::size(m_tex_matcaps); ++i) 154 | { 155 | bgfx::destroy(m_tex_matcaps[i]); 156 | } 157 | } 158 | 159 | int main(int argc, char** argv) 160 | { 161 | MatcapApp app; 162 | return app.runApp(argc, argv); 163 | } 164 | -------------------------------------------------------------------------------- /examples/mesh/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class MeshObject; 12 | 13 | class MeshApp final : public bigger::App 14 | { 15 | public: 16 | MeshApp() { getCamera().m_target = glm::vec3(0.0f, 0.3f, 0.0f); } 17 | 18 | void initialize(int argc, char** argv) override; 19 | void onReset() override; 20 | 21 | void updateApp() override; 22 | void releaseSharedResources() override; 23 | 24 | private: 25 | // Shared resources 26 | std::shared_ptr m_mesh_material; 27 | std::shared_ptr m_mesh_primitive; 28 | 29 | bgfx::TextureHandle m_tex_diffuse = BGFX_INVALID_HANDLE; 30 | }; 31 | 32 | class MeshObject final : public bigger::SceneObject 33 | { 34 | public: 35 | MeshObject(const MeshApp* app, 36 | std::shared_ptr material, 37 | std::shared_ptr mesh) 38 | : bigger::SceneObject(material), m_app(app), m_primitive(mesh) 39 | { 40 | assert(app != nullptr); 41 | assert(material != nullptr); 42 | assert(mesh != nullptr); 43 | } 44 | 45 | void update() override 46 | { 47 | // Update transform 48 | const float t = m_app->m_time; 49 | m_rotate_matrix = glm::rotate(glm::mat4(1.0f), t, glm::vec3(0.0f, 1.0f, 0.0f)); 50 | } 51 | 52 | void draw(const glm::mat4& parent_transform_matrix = glm::mat4(1.0f)) override 53 | { 54 | const glm::mat4 transform_matrix = parent_transform_matrix * getTransform(); 55 | bgfx::setTransform(glm::value_ptr(transform_matrix)); 56 | 57 | m_material->submitUniforms(); 58 | m_primitive->submitPrimitive(m_material->m_program); 59 | } 60 | 61 | private: 62 | // Pointer to the app 63 | const MeshApp* m_app; 64 | 65 | // Assigned resources 66 | std::shared_ptr m_primitive; 67 | }; 68 | 69 | void MeshApp::initialize(int argc, char** argv) 70 | { 71 | // Register and apply BGFX configuration settings 72 | reset(BGFX_RESET_VSYNC | BGFX_RESET_MSAA_X8); 73 | 74 | // Instantiate shared resources 75 | #if false 76 | const std::string obj_path = "assets/spot.obj"; 77 | const std::string tex_path = "assets/spot_texture.png"; 78 | 79 | m_tex_diffuse = bigger::loadTexture(tex_path.c_str()); 80 | 81 | m_mesh_material = std::make_shared(); 82 | m_mesh_material->setTexDiffuse(&m_tex_diffuse); 83 | #else 84 | const std::string obj_path = "assets/teapot.obj"; 85 | 86 | m_mesh_material = std::make_shared(); 87 | #endif 88 | 89 | m_mesh_primitive = std::make_shared(obj_path); 90 | 91 | // Instantiate scene objects 92 | auto mesh_object = std::make_shared(this, m_mesh_material, m_mesh_primitive); 93 | 94 | addSceneObject(mesh_object); 95 | } 96 | 97 | void MeshApp::onReset() 98 | { 99 | constexpr uint32_t bg_color = 0x303030ff; 100 | 101 | bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, bg_color, 1.0f, 0); 102 | } 103 | 104 | void MeshApp::updateApp() 105 | { 106 | // Display ImGui components 107 | ImGui::Begin("Config"); 108 | { 109 | ImGui::Text("frame: %d", m_frame); 110 | ImGui::Text("time: %.2f", m_time); 111 | ImGui::Text("fps: %.2f", 1.0f / m_last_dt); 112 | ImGui::Separator(); 113 | getCamera().drawImgui(); 114 | ImGui::Separator(); 115 | m_mesh_material->drawImgui(); 116 | } 117 | ImGui::End(); 118 | } 119 | 120 | void MeshApp::releaseSharedResources() 121 | { 122 | // Release shared resources 123 | m_mesh_material = nullptr; 124 | m_mesh_primitive = nullptr; 125 | 126 | if (isValid(m_tex_diffuse)) 127 | { 128 | bgfx::destroy(m_tex_diffuse); 129 | } 130 | } 131 | 132 | int main(int argc, char** argv) 133 | { 134 | MeshApp app; 135 | return app.runApp(argc, argv); 136 | } 137 | -------------------------------------------------------------------------------- /examples/minimal/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class MinimalApp final : public bigger::App 4 | { 5 | public: 6 | MinimalApp() {} 7 | 8 | void initialize(int argc, char** argv) override {} 9 | void updateApp() override {} 10 | void releaseSharedResources() override {} 11 | }; 12 | 13 | int main(int argc, char** argv) 14 | { 15 | MinimalApp app; 16 | return app.runApp(argc, argv); 17 | } 18 | -------------------------------------------------------------------------------- /include/bigger/app.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_APP_HPP 2 | #define BIGGER_APP_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace bigger 11 | { 12 | class SceneObject; 13 | 14 | class App : public bigg::Application 15 | { 16 | public: 17 | App(const unsigned int width = 1280, const unsigned int height = 720) : bigg::Application("", width, height) 18 | { 19 | m_camera.m_position = {1.0f, 1.0f, -2.0f}; 20 | m_camera.m_target = {0.0f, 0.0f, 0.0f}; 21 | m_camera.m_up = {0.0f, 1.0f, 0.0f}; 22 | 23 | m_time = 0.0f; 24 | m_frame = 0; 25 | } 26 | 27 | int runApp(int argc, char** argv, bgfx::RendererType::Enum type = bgfx::RendererType::Count); 28 | 29 | // Events to be overridden 30 | virtual void updateApp() = 0; 31 | virtual void releaseSharedResources() = 0; 32 | 33 | // Events to be overridden, provided by bigg::Application 34 | virtual void initialize(int argc, char** argv) override = 0; 35 | virtual void onReset() override {} 36 | 37 | void setRect() { bgfx::setViewRect(0, 0, 0, uint16_t(getWidth()), uint16_t(getHeight())); } 38 | 39 | void setViewProj() 40 | { 41 | const glm::mat4 view_matrix = m_camera.getViewMatrix(); 42 | const glm::mat4 proj_matrix = 43 | glm::perspective(glm::radians(m_camera.m_fov), getAspect(), m_camera.m_near_clip, m_camera.m_far_clip); 44 | 45 | bgfx::setViewTransform(0, glm::value_ptr(view_matrix), glm::value_ptr(proj_matrix)); 46 | } 47 | 48 | float getAspect() const { return float(getWidth()) / float(getHeight()); } 49 | 50 | const Camera& getCamera() const { return m_camera; } 51 | Camera& getCamera() { return m_camera; } 52 | 53 | unsigned int m_frame; 54 | float m_time; 55 | float m_last_dt; 56 | std::unordered_map> m_scene_objects; 57 | 58 | void addSceneObject(std::shared_ptr scene_object, const std::string& name = ""); 59 | 60 | private: 61 | // Events provided by bigg::Application 62 | void update(float dt) override; 63 | int shutdown() override; 64 | 65 | Camera m_camera; 66 | }; 67 | } // namespace bigger 68 | 69 | #endif // BIGGER_APP_HPP 70 | -------------------------------------------------------------------------------- /include/bigger/camera.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_CAMERA_HPP 2 | #define BIGGER_CAMERA_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace bigger 8 | { 9 | class Camera 10 | { 11 | public: 12 | glm::vec3 m_position = glm::vec3(1.0f, 1.0f, -2.0f); 13 | glm::vec3 m_target = glm::vec3(0.0f, 0.0f, 0.0f); 14 | glm::vec3 m_up = glm::vec3(0.0f, 1.0f, 0.0f); 15 | 16 | float m_fov = 60.0f; 17 | float m_near_clip = 0.1f; 18 | float m_far_clip = 100.0f; 19 | 20 | glm::mat4 getViewMatrix() const { return glm::lookAt(m_position, m_target, m_up); } 21 | 22 | void drawImgui(); 23 | }; 24 | } // namespace bigger 25 | 26 | #endif // BIGGER_CAMERA_HPP 27 | -------------------------------------------------------------------------------- /include/bigger/material.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_MATERIAL_HPP 2 | #define BIGGER_MATERIAL_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace bigger 9 | { 10 | class Material 11 | { 12 | public: 13 | Material(const std::string& shader_name) 14 | { 15 | const std::string shader_dir_path = getShaderDirectoryPath(bgfx::getRendererType()); 16 | const std::string vs_path = shader_dir_path + "/" + "vs_" + shader_name + ".bin"; 17 | const std::string fs_path = shader_dir_path + "/" + "fs_" + shader_name + ".bin"; 18 | 19 | m_program = bigg::loadProgram(vs_path.c_str(), fs_path.c_str()); 20 | } 21 | 22 | ~Material() { bgfx::destroy(m_program); } 23 | 24 | virtual void submitUniforms() {} 25 | virtual void drawImgui() {} 26 | 27 | bgfx::ProgramHandle m_program; 28 | }; 29 | } // namespace bigger 30 | 31 | #endif // BIGGER_MATERIAL_HPP 32 | -------------------------------------------------------------------------------- /include/bigger/materials/blinnphong-material.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_BLINNPHONG_MATERIAL_HPP 2 | #define BIGGER_BLINNPHONG_MATERIAL_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace bigger 11 | { 12 | class BlinnPhongMaterial final : public Material 13 | { 14 | public: 15 | static constexpr unsigned int num_vec4_uniforms = 6; 16 | 17 | struct DirLight 18 | { 19 | glm::vec3 dir; 20 | glm::vec3 color; 21 | }; 22 | 23 | BlinnPhongMaterial() : bigger::Material("blinnphong") 24 | { 25 | u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4, num_vec4_uniforms); 26 | u_tex_transform = bgfx::createUniform("u_tex_transform", bgfx::UniformType::Mat3); 27 | s_tex_diffuse = bgfx::createUniform("s_tex_diffuse", bgfx::UniformType::Sampler); 28 | 29 | constexpr bgfx::TextureFormat::Enum format = bgfx::TextureFormat::RGBA32F; 30 | constexpr uint64_t flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE; 31 | 32 | m_tex_diffuse_alt = bgfx::createTexture2D(1, 1, false, 1, format, flags, nullptr); 33 | 34 | #if BX_PLATFORM_OSX 35 | // This is an ad-hoc hotfix to avoid the Metal API Validation assertion; see 36 | // https://github.com/yuki-koyama/bigger/issues/13 37 | bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler); 38 | #endif 39 | } 40 | 41 | ~BlinnPhongMaterial() 42 | { 43 | bgfx::destroy(u_params); 44 | bgfx::destroy(u_tex_transform); 45 | bgfx::destroy(s_tex_diffuse); 46 | 47 | bgfx::destroy(m_tex_diffuse_alt); 48 | } 49 | 50 | void setTexDiffuse(bgfx::TextureHandle* tex_diffuse) 51 | { 52 | assert(isValid(*tex_diffuse)); 53 | 54 | m_tex_diffuse = tex_diffuse; 55 | m_is_textured = true; 56 | } 57 | 58 | void submitUniforms() override 59 | { 60 | // Set uniform parameters (in a packed way) 61 | constexpr float dummy = 0.0f; 62 | 63 | const std::array buffer = {{ 64 | {m_specular, dummy}, 65 | {m_ambient, m_shininess}, 66 | {m_dir_lights[0].dir, dummy}, 67 | {m_dir_lights[0].color, dummy}, 68 | {m_dir_lights[1].dir, dummy}, 69 | {m_dir_lights[1].color, dummy}, 70 | }}; 71 | bgfx::setUniform(u_params, buffer.data(), num_vec4_uniforms); 72 | 73 | // Set the transform matrix for texture coordinates 74 | #if false 75 | constexpr float texture_transform[] = 76 | {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; // Do nothing 77 | #else 78 | constexpr float texture_transform[] = 79 | {1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f}; // Flip vertically 80 | #endif 81 | bgfx::setUniform(u_tex_transform, texture_transform); 82 | 83 | // Set the diffuse color 84 | if (m_is_textured) 85 | { 86 | bgfx::setTexture(0, s_tex_diffuse, *m_tex_diffuse); 87 | } 88 | else 89 | { 90 | // Create and set a 1x1 small diffuse color texture 91 | m_buffer_tex_diffuse_alt[0] = m_diffuse.r; 92 | m_buffer_tex_diffuse_alt[1] = m_diffuse.g; 93 | m_buffer_tex_diffuse_alt[2] = m_diffuse.b; 94 | m_buffer_tex_diffuse_alt[3] = 1.0; 95 | 96 | const bgfx::Memory* mem = bgfx::makeRef(std::data(m_buffer_tex_diffuse_alt), sizeof(float) * 4); 97 | 98 | // Update the texture with the current color 99 | bgfx::updateTexture2D(m_tex_diffuse_alt, 0, 0, 0, 0, 1, 1, mem); 100 | bgfx::setTexture(0, s_tex_diffuse, m_tex_diffuse_alt); 101 | } 102 | } 103 | 104 | void drawImgui() override 105 | { 106 | ImGui::Text("Material Setting"); 107 | if (m_is_textured) 108 | { 109 | ImGui::Text("diffuse (textured)"); 110 | } 111 | else 112 | { 113 | ImGui::ColorEdit3("diffuse", glm::value_ptr(m_diffuse)); 114 | } 115 | ImGui::ColorEdit3("specular", glm::value_ptr(m_specular)); 116 | ImGui::ColorEdit3("ambient", glm::value_ptr(m_ambient)); 117 | ImGui::SliderFloat("shininess", &m_shininess, 0.5f, 256.0f); 118 | ImGui::SliderFloat3("dir_light_0_dir", glm::value_ptr(m_dir_lights[0].dir), -1.0f, 1.0f); 119 | ImGui::ColorEdit3("dir_light_0_color", glm::value_ptr(m_dir_lights[0].color)); 120 | ImGui::SliderFloat3("dir_light_1_dir", glm::value_ptr(m_dir_lights[1].dir), -1.0f, 1.0f); 121 | ImGui::ColorEdit3("dir_light_1_color", glm::value_ptr(m_dir_lights[1].color)); 122 | } 123 | 124 | glm::vec3 m_diffuse = glm::vec3(0.78f, 0.71f, 0.85f); 125 | glm::vec3 m_specular = glm::vec3(1.00f, 1.00f, 1.00f); 126 | glm::vec3 m_ambient = glm::vec3(0.00f, 0.00f, 0.00f); 127 | float m_shininess = 128.0f; 128 | 129 | std::array m_dir_lights = {{ 130 | DirLight{{+0.5, +0.5, +1.0}, {1.0, 0.9, 0.9}}, 131 | DirLight{{-1.0, +0.0, +0.0}, {0.2, 0.2, 0.5}}, 132 | }}; 133 | 134 | private: 135 | /// \brief Boolean indicating whether a diffuse texture is set by another class or not. 136 | bool m_is_textured = false; 137 | 138 | /// \brief Buffer for internal use. 139 | std::array m_buffer_tex_diffuse_alt; 140 | 141 | // ------------------------------------------------------------------------------------------------------------- 142 | // Handles managed by this class. 143 | // ------------------------------------------------------------------------------------------------------------- 144 | 145 | bgfx::UniformHandle u_params; 146 | bgfx::UniformHandle u_tex_transform; 147 | bgfx::UniformHandle s_tex_diffuse; 148 | 149 | /// \brief Texture handle that will be used when no diffuse texture is set. 150 | bgfx::TextureHandle m_tex_diffuse_alt = BGFX_INVALID_HANDLE; 151 | 152 | // ------------------------------------------------------------------------------------------------------------- 153 | // Handles not managed by this class. 154 | // ------------------------------------------------------------------------------------------------------------- 155 | 156 | /// \brief Texture handle for diffuse color, which should be set and managed by another class. 157 | bgfx::TextureHandle* m_tex_diffuse = nullptr; 158 | }; 159 | } // namespace bigger 160 | 161 | #endif // BIGGER_BLINNPHONG_MATERIAL_HPP 162 | -------------------------------------------------------------------------------- /include/bigger/materials/matcap-material.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_MATCAP_MATERIAL_HPP 2 | #define BIGGER_MATCAP_MATERIAL_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace bigger 11 | { 12 | class MatcapMaterial final : public Material 13 | { 14 | public: 15 | MatcapMaterial() : bigger::Material("matcap") 16 | { 17 | s_tex_matcap = bgfx::createUniform("s_tex_matcap", bgfx::UniformType::Sampler); 18 | 19 | constexpr bgfx::TextureFormat::Enum format = bgfx::TextureFormat::RGBA32F; 20 | constexpr uint64_t flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE; 21 | 22 | m_tex_matcap_alt = bgfx::createTexture2D(1, 1, false, 1, format, flags, nullptr); 23 | 24 | #if BX_PLATFORM_OSX 25 | // This is an ad-hoc hotfix to avoid the Metal API Validation assertion; see 26 | // https://github.com/yuki-koyama/bigger/issues/13 27 | bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler); 28 | #endif 29 | } 30 | 31 | ~MatcapMaterial() 32 | { 33 | bgfx::destroy(s_tex_matcap); 34 | bgfx::destroy(m_tex_matcap_alt); 35 | } 36 | 37 | void setTexMatcap(bgfx::TextureHandle* tex_diffuse) 38 | { 39 | assert(isValid(*tex_diffuse)); 40 | 41 | m_tex_matcap = tex_diffuse; 42 | m_is_textured = true; 43 | } 44 | 45 | void submitUniforms() override 46 | { 47 | // Set the diffuse color 48 | if (m_is_textured) 49 | { 50 | bgfx::setTexture(0, s_tex_matcap, *m_tex_matcap); 51 | } 52 | else 53 | { 54 | // Create and set a 1x1 small diffuse color texture 55 | static float color[4] = {1.0f, 0.0f, 1.0f, 1.0f}; 56 | const bgfx::Memory* mem = bgfx::makeRef(color, sizeof(float) * 4); 57 | 58 | // Update the texture with the current color 59 | bgfx::updateTexture2D(m_tex_matcap_alt, 0, 0, 0, 0, 1, 1, mem); 60 | bgfx::setTexture(0, s_tex_matcap, m_tex_matcap_alt); 61 | } 62 | } 63 | 64 | void drawImgui() override { ImGui::Text("Material Setting"); } 65 | 66 | private: 67 | /// \brief Boolean indicating whether a diffuse texture is set by another class or not. 68 | bool m_is_textured = false; 69 | 70 | // ------------------------------------------------------------------------------------------------------------- 71 | // Handles managed by this class. 72 | // ------------------------------------------------------------------------------------------------------------- 73 | 74 | bgfx::UniformHandle s_tex_matcap; 75 | 76 | /// \brief Texture handle that will be used when no diffuse texture is set. 77 | bgfx::TextureHandle m_tex_matcap_alt = BGFX_INVALID_HANDLE; 78 | 79 | // ------------------------------------------------------------------------------------------------------------- 80 | // Handles not managed by this class. 81 | // ------------------------------------------------------------------------------------------------------------- 82 | 83 | /// \brief Texture handle for diffuse color, which should be set and managed by another class. 84 | bgfx::TextureHandle* m_tex_matcap = nullptr; 85 | }; 86 | } // namespace bigger 87 | 88 | #endif // BIGGER_MATCAP_MATERIAL_HPP 89 | -------------------------------------------------------------------------------- /include/bigger/primitive.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_PRIMITIVE_HPP 2 | #define BIGGER_PRIMITIVE_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace bigger 10 | { 11 | struct PositionNormalUvVertex 12 | { 13 | glm::vec3 position; 14 | glm::vec3 normal; 15 | glm::vec2 uv; 16 | 17 | static bgfx::VertexLayout getVertexLayout() 18 | { 19 | bgfx::VertexLayout vertex_layout; 20 | vertex_layout.begin() 21 | .add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float) 22 | .add(bgfx::Attrib::Normal, 3, bgfx::AttribType::Float) 23 | .add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float) 24 | .end(); 25 | return vertex_layout; 26 | } 27 | }; 28 | 29 | class Primitive 30 | { 31 | public: 32 | Primitive() : m_is_initialized(false) {} 33 | virtual ~Primitive() { destroyPrimitive(); } 34 | 35 | virtual void submitPrimitive(bgfx::ProgramHandle program, bool preserve_state = false) const 36 | { 37 | assert(m_is_initialized); 38 | 39 | bgfx::setVertexBuffer(0, m_vertex_buffer_handle); 40 | bgfx::setIndexBuffer(m_index_buffer_handle); 41 | 42 | bgfx::submit(0, program, bgfx::ViewMode::Default, preserve_state); 43 | } 44 | 45 | protected: 46 | std::vector m_vertices; 47 | std::vector m_triangle_list; 48 | 49 | bool m_is_initialized; 50 | 51 | bgfx::VertexBufferHandle m_vertex_buffer_handle; 52 | bgfx::IndexBufferHandle m_index_buffer_handle; 53 | 54 | virtual void initializePrimitive() 55 | { 56 | assert(!m_vertices.empty()); 57 | assert(!m_triangle_list.empty()); 58 | 59 | const bgfx::VertexLayout vertex_layout = PositionNormalUvVertex::getVertexLayout(); 60 | 61 | m_vertex_buffer_handle = bgfx::createVertexBuffer( 62 | bgfx::makeRef(m_vertices.data(), sizeof(PositionNormalUvVertex) * m_vertices.size()), 63 | vertex_layout); 64 | m_index_buffer_handle = bgfx::createIndexBuffer( 65 | bgfx::makeRef(m_triangle_list.data(), sizeof(uint16_t) * m_triangle_list.size())); 66 | 67 | m_is_initialized = true; 68 | } 69 | 70 | private: 71 | virtual void destroyPrimitive() 72 | { 73 | assert(m_is_initialized); 74 | 75 | bgfx::destroy(m_vertex_buffer_handle); 76 | bgfx::destroy(m_index_buffer_handle); 77 | } 78 | }; 79 | } // namespace bigger 80 | 81 | #endif // BIGGER_PRIMITIVE_HPP 82 | -------------------------------------------------------------------------------- /include/bigger/primitives/cube-primitive.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_CUBE_PRIMITIVE_HPP 2 | #define BIGGER_CUBE_PRIMITIVE_HPP 3 | 4 | #include 5 | 6 | namespace bigger 7 | { 8 | class CubePrimitive : public Primitive 9 | { 10 | public: 11 | CubePrimitive() 12 | { 13 | m_vertices = { 14 | {{+0.5f, +0.5f, +0.5f}, {0.0f, 0.0f, +1.0f}}, // 15 | {{-0.5f, +0.5f, +0.5f}, {0.0f, 0.0f, +1.0f}}, // 16 | {{-0.5f, -0.5f, +0.5f}, {0.0f, 0.0f, +1.0f}}, // 17 | {{+0.5f, +0.5f, +0.5f}, {0.0f, 0.0f, +1.0f}}, // 18 | {{-0.5f, -0.5f, +0.5f}, {0.0f, 0.0f, +1.0f}}, // 19 | {{+0.5f, -0.5f, +0.5f}, {0.0f, 0.0f, +1.0f}}, // 20 | 21 | {{+0.5f, +0.5f, -0.5f}, {+1.0f, 0.0f, 0.0f}}, // 22 | {{+0.5f, +0.5f, +0.5f}, {+1.0f, 0.0f, 0.0f}}, // 23 | {{+0.5f, -0.5f, +0.5f}, {+1.0f, 0.0f, 0.0f}}, // 24 | {{+0.5f, +0.5f, -0.5f}, {+1.0f, 0.0f, 0.0f}}, // 25 | {{+0.5f, -0.5f, +0.5f}, {+1.0f, 0.0f, 0.0f}}, // 26 | {{+0.5f, -0.5f, -0.5f}, {+1.0f, 0.0f, 0.0f}}, // 27 | 28 | {{-0.5f, +0.5f, -0.5f}, {0.0f, 0.0f, -1.0f}}, // 29 | {{+0.5f, +0.5f, -0.5f}, {0.0f, 0.0f, -1.0f}}, // 30 | {{+0.5f, -0.5f, -0.5f}, {0.0f, 0.0f, -1.0f}}, // 31 | {{-0.5f, +0.5f, -0.5f}, {0.0f, 0.0f, -1.0f}}, // 32 | {{+0.5f, -0.5f, -0.5f}, {0.0f, 0.0f, -1.0f}}, // 33 | {{-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f, -1.0f}}, // 34 | 35 | {{-0.5f, +0.5f, +0.5f}, {-1.0f, 0.0f, 0.0f}}, // 36 | {{-0.5f, +0.5f, -0.5f}, {-1.0f, 0.0f, 0.0f}}, // 37 | {{-0.5f, -0.5f, -0.5f}, {-1.0f, 0.0f, 0.0f}}, // 38 | {{-0.5f, +0.5f, +0.5f}, {-1.0f, 0.0f, 0.0f}}, // 39 | {{-0.5f, -0.5f, -0.5f}, {-1.0f, 0.0f, 0.0f}}, // 40 | {{-0.5f, -0.5f, +0.5f}, {-1.0f, 0.0f, 0.0f}}, // 41 | 42 | {{+0.5f, +0.5f, -0.5f}, {0.0f, +1.0f, 0.0f}}, // 43 | {{-0.5f, +0.5f, -0.5f}, {0.0f, +1.0f, 0.0f}}, // 44 | {{-0.5f, +0.5f, +0.5f}, {0.0f, +1.0f, 0.0f}}, // 45 | {{+0.5f, +0.5f, -0.5f}, {0.0f, +1.0f, 0.0f}}, // 46 | {{-0.5f, +0.5f, +0.5f}, {0.0f, +1.0f, 0.0f}}, // 47 | {{+0.5f, +0.5f, +0.5f}, {0.0f, +1.0f, 0.0f}}, // 48 | 49 | {{-0.5f, -0.5f, +0.5f}, {0.0f, -1.0f, 0.0f}}, // 50 | {{-0.5f, -0.5f, -0.5f}, {0.0f, -1.0f, 0.0f}}, // 51 | {{+0.5f, -0.5f, -0.5f}, {0.0f, -1.0f, 0.0f}}, // 52 | {{-0.5f, -0.5f, +0.5f}, {0.0f, -1.0f, 0.0f}}, // 53 | {{+0.5f, -0.5f, -0.5f}, {0.0f, -1.0f, 0.0f}}, // 54 | {{+0.5f, -0.5f, +0.5f}, {0.0f, -1.0f, 0.0f}}, // 55 | }; 56 | 57 | m_triangle_list = { 58 | 0, 1, 2, 3, 4, 5, // 59 | 6, 7, 8, 9, 10, 11, // 60 | 12, 13, 14, 15, 16, 17, // 61 | 18, 19, 20, 21, 22, 23, // 62 | 24, 25, 26, 27, 28, 29, // 63 | 30, 31, 32, 33, 34, 35, // 64 | }; 65 | 66 | Primitive::initializePrimitive(); 67 | } 68 | }; 69 | } // namespace bigger 70 | 71 | #endif // BIGGER_CUBE_PRIMITIVE_HPP 72 | -------------------------------------------------------------------------------- /include/bigger/primitives/dynamic-mesh-primitive.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_DYNAMIC_MESH_PRIMITIVE_HPP 2 | #define BIGGER_DYNAMIC_MESH_PRIMITIVE_HPP 3 | 4 | #include 5 | 6 | namespace bigger 7 | { 8 | class DynamicMeshPrimitive : public Primitive 9 | { 10 | public: 11 | DynamicMeshPrimitive(const std::vector& vertex_data, 12 | const std::vector& triangle_list); 13 | 14 | virtual void initializePrimitive(); 15 | virtual void submitPrimitive(bgfx::ProgramHandle program, bool preserve_state = false) const; 16 | virtual void destroyPrimitive(); 17 | 18 | void updateVertexData(const std::vector& vertex_data); 19 | 20 | private: 21 | bgfx::DynamicVertexBufferHandle m_dynamic_vertex_buffer_handle; 22 | }; 23 | } // namespace bigger 24 | 25 | #endif // BIGGER_DYNAMIC_MESH_PRIMITIVE_HPP 26 | -------------------------------------------------------------------------------- /include/bigger/primitives/mesh-primitive.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_MESH_PRIMITIVE_HPP 2 | #define BIGGER_MESH_PRIMITIVE_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace bigger 8 | { 9 | class MeshPrimitive : public Primitive 10 | { 11 | public: 12 | MeshPrimitive(const std::string& obj_path); 13 | }; 14 | } // namespace bigger 15 | 16 | #endif // BIGGER_MESH_PRIMITIVE_HPP 17 | -------------------------------------------------------------------------------- /include/bigger/primitives/plane-primitive.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_PLANE_PRIMITIVE_HPP 2 | #define BIGGER_PLANE_PRIMITIVE_HPP 3 | 4 | #include 5 | 6 | namespace bigger 7 | { 8 | class PlanePrimitive : public Primitive 9 | { 10 | public: 11 | PlanePrimitive() 12 | { 13 | m_vertices = { 14 | {{+0.5f, +0.0f, -0.5f}, {0.0f, +1.0f, 0.0f}}, 15 | {{-0.5f, +0.0f, -0.5f}, {0.0f, +1.0f, 0.0f}}, 16 | {{-0.5f, +0.0f, +0.5f}, {0.0f, +1.0f, 0.0f}}, 17 | {{+0.5f, +0.0f, +0.5f}, {0.0f, +1.0f, 0.0f}}, 18 | }; 19 | 20 | m_triangle_list = { 21 | 0, 22 | 1, 23 | 2, // 24 | 25 | 0, 26 | 2, 27 | 3, // 28 | }; 29 | 30 | Primitive::initializePrimitive(); 31 | } 32 | }; 33 | } // namespace bigger 34 | 35 | #endif // BIGGER_PLANE_PRIMITIVE_HPP 36 | -------------------------------------------------------------------------------- /include/bigger/primitives/sphere-primitive.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_SPHERE_PRIMITIVE_HPP 2 | #define BIGGER_SPHERE_PRIMITIVE_HPP 3 | 4 | #include 5 | 6 | namespace bigger 7 | { 8 | class SpherePrimitive : public Primitive 9 | { 10 | public: 11 | SpherePrimitive() 12 | { 13 | constexpr float pi = glm::pi(); 14 | constexpr int latitude_resolution = 20; 15 | constexpr int longitude_resolution = 30; 16 | 17 | m_vertices.resize(latitude_resolution * longitude_resolution * 6); 18 | m_triangle_list.resize(latitude_resolution * longitude_resolution * 6); 19 | 20 | for (int i = 0; i < longitude_resolution; ++i) 21 | { 22 | const float theta_xy_1 = 23 | 2.0 * static_cast(i + 0) * pi / static_cast(longitude_resolution); 24 | const float theta_xy_2 = 25 | 2.0 * static_cast(i + 1) * pi / static_cast(longitude_resolution); 26 | const float x_1 = std::cos(theta_xy_1); 27 | const float x_2 = std::cos(theta_xy_2); 28 | const float y_1 = std::sin(theta_xy_1); 29 | const float y_2 = std::sin(theta_xy_2); 30 | 31 | for (int j = 0; j < latitude_resolution; ++j) 32 | { 33 | const float theta_z_1 = static_cast(j + 0) * pi / static_cast(latitude_resolution); 34 | const float theta_z_2 = static_cast(j + 1) * pi / static_cast(latitude_resolution); 35 | const float cos_1 = std::cos(theta_z_1); 36 | const float cos_2 = std::cos(theta_z_2); 37 | const float sin_1 = std::sin(theta_z_1); 38 | const float sin_2 = std::sin(theta_z_2); 39 | 40 | const int offset = i * latitude_resolution * 6 + j * 6; 41 | 42 | const glm::vec3 vertex_0 = {sin_2 * x_1, sin_2 * y_1, cos_2}; 43 | const glm::vec3 vertex_1 = {sin_2 * x_2, sin_2 * y_2, cos_2}; 44 | const glm::vec3 vertex_2 = {sin_1 * x_2, sin_1 * y_2, cos_1}; 45 | const glm::vec3 vertex_3 = {sin_2 * x_1, sin_2 * y_1, cos_2}; 46 | const glm::vec3 vertex_4 = {sin_1 * x_2, sin_1 * y_2, cos_1}; 47 | const glm::vec3 vertex_5 = {sin_1 * x_1, sin_1 * y_1, cos_1}; 48 | 49 | m_vertices[offset + 0] = {vertex_0, vertex_0}; 50 | m_vertices[offset + 1] = {vertex_1, vertex_1}; 51 | m_vertices[offset + 2] = {vertex_2, vertex_2}; 52 | m_vertices[offset + 3] = {vertex_3, vertex_3}; 53 | m_vertices[offset + 4] = {vertex_4, vertex_4}; 54 | m_vertices[offset + 5] = {vertex_5, vertex_5}; 55 | } 56 | } 57 | 58 | for (int i = 0; i < m_triangle_list.size(); ++i) 59 | { 60 | m_triangle_list[i] = static_cast(i); 61 | } 62 | 63 | Primitive::initializePrimitive(); 64 | } 65 | }; 66 | } // namespace bigger 67 | 68 | #endif // BIGGER_SPHERE_PRIMITIVE_HPP 69 | -------------------------------------------------------------------------------- /include/bigger/scene-object.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_SCENE_OBJECT_HPP 2 | #define BIGGER_SCENE_OBJECT_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace bigger 8 | { 9 | class Material; 10 | 11 | class SceneObject 12 | { 13 | public: 14 | SceneObject(std::shared_ptr material = nullptr) : m_material(material) {} 15 | 16 | virtual void update() {} 17 | virtual void draw(const glm::mat4& parent_transform_matrix = glm::mat4(1.0f)) {} 18 | 19 | glm::mat4 m_rotate_matrix = glm::mat4(1.0f); 20 | glm::mat4 m_scale_matrix = glm::mat4(1.0f); 21 | glm::mat4 m_translate_matrix = glm::mat4(1.0f); 22 | 23 | glm::mat4 getTransform() const { return m_translate_matrix * m_rotate_matrix * m_scale_matrix; } 24 | 25 | bool m_is_active = true; 26 | bool m_is_visible = true; 27 | 28 | std::shared_ptr m_material; 29 | }; 30 | } // namespace bigger 31 | 32 | #endif // BIGGER_SCENE_OBJECT_HPP 33 | -------------------------------------------------------------------------------- /include/bigger/screen-shot-callback.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_SCREEN_SHOT_CALLBACK_HPP 2 | #define BIGGER_SCREEN_SHOT_CALLBACK_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace bigger 10 | { 11 | struct ScreenShotCallback : public bgfx::CallbackI 12 | { 13 | enum class ImageType 14 | { 15 | Png, 16 | Tga 17 | }; 18 | 19 | virtual ~ScreenShotCallback() {} 20 | virtual void fatal(const char*, uint16_t, bgfx::Fatal::Enum, const char*) override {} 21 | virtual void traceVargs(const char*, uint16_t, const char*, va_list) override {} 22 | virtual void profilerBegin(const char*, uint32_t, const char*, uint16_t) override {} 23 | virtual void profilerBeginLiteral(const char*, uint32_t, const char*, uint16_t) override {} 24 | virtual void profilerEnd() override {} 25 | virtual uint32_t cacheReadSize(uint64_t) override { return 0; } 26 | virtual bool cacheRead(uint64_t, void*, uint32_t) override { return false; } 27 | virtual void cacheWrite(uint64_t, const void*, uint32_t) override {} 28 | virtual void captureBegin(uint32_t, uint32_t, uint32_t, bgfx::TextureFormat::Enum, bool) override {} 29 | virtual void captureEnd() override {} 30 | virtual void captureFrame(const void*, uint32_t) override {} 31 | 32 | virtual void screenShot(const char* _filePath, 33 | uint32_t _width, 34 | uint32_t _height, 35 | uint32_t _pitch, 36 | const void* _data, 37 | uint32_t _size, 38 | bool _yflip) override 39 | { 40 | const std::string full_path = std::string(_filePath) + ((image_type == ImageType::Png) ? ".png" : ".tga"); 41 | 42 | bx::FileWriter writer; 43 | if (bx::open(&writer, full_path.c_str())) 44 | { 45 | if (image_type == ImageType::Png) 46 | { 47 | bimg::imageWritePng(&writer, 48 | _width, 49 | _height, 50 | _pitch, 51 | _data, 52 | bimg::TextureFormat::BGRA8, 53 | _yflip, 54 | nullptr); 55 | } 56 | else 57 | { 58 | bimg::imageWriteTga(&writer, _width, _height, _pitch, _data, false, _yflip); 59 | } 60 | 61 | bx::close(&writer); 62 | } 63 | else 64 | { 65 | throw std::runtime_error(""); 66 | } 67 | } 68 | 69 | ImageType image_type = ImageType::Tga; 70 | }; 71 | } // namespace bigger 72 | 73 | #endif // BIGGER_SCREEN_SHOT_CALLBACK_HPP 74 | -------------------------------------------------------------------------------- /include/bigger/utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BIGGER_UTILS_HPP 2 | #define BIGGER_UTILS_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace bigger 8 | { 9 | std::string getShaderDirectoryPath(const bgfx::RendererType::Enum renderer_type); 10 | 11 | /// \brief Load texture data from a texture image file. 12 | /// \details This is a wrapper function for using utility functions in bgfx's examples. 13 | /// \param file_path A file path to the texture image data. 14 | bgfx::TextureHandle loadTexture(const char* file_path); 15 | } // namespace bigger 16 | 17 | #endif // BIGGER_UTILS_HPP 18 | -------------------------------------------------------------------------------- /shaders/blinnphong/fs_blinnphong.sc: -------------------------------------------------------------------------------- 1 | $input v_pos, v_view, v_normal, v_texcoord0 2 | 3 | #include 4 | 5 | SAMPLER2D(s_tex_diffuse, 0); 6 | 7 | struct DirLight 8 | { 9 | vec3 dir; 10 | vec3 intensity; 11 | }; 12 | 13 | struct Material 14 | { 15 | vec3 diffuse; 16 | vec3 specular; 17 | vec3 ambient; 18 | float shininess; 19 | }; 20 | 21 | uniform vec4 u_params[6]; 22 | #define u_specular u_params[0].xyz 23 | #define u_ambient u_params[1].xyz 24 | #define u_shininess u_params[1].w 25 | #define u_dir_light_0_dir u_params[2].xyz 26 | #define u_dir_light_0_color u_params[3].xyz 27 | #define u_dir_light_1_dir u_params[4].xyz 28 | #define u_dir_light_1_color u_params[5].xyz 29 | 30 | const float gamma = 2.2; 31 | 32 | vec3 calculateLambertDiffuse(vec3 normal, vec3 light_dir, vec3 diffuse_color) 33 | { 34 | return max(dot(normal, light_dir), 0.0) * diffuse_color; 35 | } 36 | 37 | vec3 calculateBlinnSpecular(vec3 normal, vec3 view_dir, vec3 light_dir, vec3 specular_color, float shininess) 38 | { 39 | vec3 half_dir = normalize(light_dir + view_dir); 40 | float angle = max(dot(half_dir, normal), 0.0); 41 | float strength = pow(angle, shininess); 42 | return strength * specular_color; 43 | } 44 | 45 | vec3 calculateSingleLightShading(DirLight dir_light, Material material, vec3 normal, vec3 view_dir) 46 | { 47 | vec3 light_dir = normalize(dir_light.dir); 48 | 49 | vec3 diffuse = dir_light.intensity * calculateLambertDiffuse(normal, light_dir, material.diffuse); 50 | vec3 specular = dir_light.intensity * calculateBlinnSpecular(normal, view_dir, light_dir, material.specular, material.shininess); 51 | 52 | return diffuse + specular; 53 | } 54 | 55 | vec3 convertToLinear(vec3 gamma_color) 56 | { 57 | return pow(gamma_color, vec3_splat(gamma)); 58 | } 59 | 60 | vec3 convertToGamma(vec3 linear_color) 61 | { 62 | return pow(linear_color, vec3_splat(1.0 / gamma)); 63 | } 64 | 65 | void main() 66 | { 67 | vec3 linear_color = vec3(0.0, 0.0, 0.0); 68 | 69 | // Retrieve the diffuse color from sampler 70 | vec3 diffuse_color = convertToLinear(texture2D(s_tex_diffuse, v_texcoord0).xyz); 71 | 72 | // Assemble the material property 73 | Material material; 74 | material.diffuse = diffuse_color; 75 | material.specular = u_specular; 76 | material.ambient = u_ambient; 77 | material.shininess = u_shininess; 78 | 79 | // Note: When the triangle is back-facing, the normal direction will be flipped 80 | vec3 view_dir = normalize(- v_view); 81 | vec3 normal = dot(v_normal, view_dir) > 0.0 ? normalize(v_normal) : normalize(- v_normal); 82 | 83 | DirLight dir_light_0, dir_light_1; 84 | dir_light_0.dir = u_dir_light_0_dir; 85 | dir_light_0.intensity = u_dir_light_0_color; 86 | dir_light_1.dir = u_dir_light_1_dir; 87 | dir_light_1.intensity = u_dir_light_1_color; 88 | 89 | linear_color += calculateSingleLightShading(dir_light_0, material, normal, view_dir); 90 | linear_color += calculateSingleLightShading(dir_light_1, material, normal, view_dir); 91 | 92 | linear_color += material.ambient; 93 | 94 | vec3 corrected_color = convertToGamma(linear_color); 95 | 96 | gl_FragColor.xyz = corrected_color; 97 | gl_FragColor.w = 1.0; 98 | } 99 | -------------------------------------------------------------------------------- /shaders/blinnphong/varying.def.sc: -------------------------------------------------------------------------------- 1 | vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0); 2 | vec3 v_normal : NORMAL = vec3(0.0, 0.0, 1.0); 3 | vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0); 4 | vec3 v_pos : TEXCOORD1 = vec3(0.0, 0.0, 0.0); 5 | vec3 v_view : TEXCOORD2 = vec3(0.0, 0.0, 0.0); 6 | 7 | vec3 a_position : POSITION; 8 | vec4 a_color0 : COLOR0; 9 | vec2 a_texcoord0 : TEXCOORD0; 10 | vec3 a_normal : NORMAL; 11 | -------------------------------------------------------------------------------- /shaders/blinnphong/vs_blinnphong.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_normal, a_texcoord0 2 | $output v_pos, v_view, v_normal, v_texcoord0 3 | 4 | #include 5 | 6 | uniform mat3 u_tex_transform; 7 | 8 | void main() 9 | { 10 | vec3 pos = a_position; 11 | 12 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); 13 | v_pos = gl_Position.xyz; 14 | 15 | v_view = mul(u_modelView, vec4(a_position, 1.0)).xyz; 16 | v_normal = mul(u_modelView, vec4(a_normal, 0.0)).xyz; 17 | 18 | v_texcoord0 = mul(u_tex_transform, vec3(a_texcoord0, 1.0)).xy; 19 | } 20 | -------------------------------------------------------------------------------- /shaders/matcap/fs_matcap.sc: -------------------------------------------------------------------------------- 1 | $input v_normal 2 | 3 | #include 4 | 5 | SAMPLER2D(s_tex_matcap, 0); 6 | 7 | void main() 8 | { 9 | vec2 coords = 0.5 * (normalize(v_normal).xy + 1.0); 10 | 11 | gl_FragColor.xyz = texture2D(s_tex_matcap, vec2(coords.x, 1.0 - coords.y)).xyz; 12 | gl_FragColor.w = 1.0; 13 | } 14 | -------------------------------------------------------------------------------- /shaders/matcap/varying.def.sc: -------------------------------------------------------------------------------- 1 | vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0); 2 | vec3 v_normal : NORMAL = vec3(0.0, 0.0, 1.0); 3 | vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0); 4 | vec3 v_pos : TEXCOORD1 = vec3(0.0, 0.0, 0.0); 5 | vec3 v_view : TEXCOORD2 = vec3(0.0, 0.0, 0.0); 6 | 7 | vec3 a_position : POSITION; 8 | vec4 a_color0 : COLOR0; 9 | vec2 a_texcoord0 : TEXCOORD0; 10 | vec3 a_normal : NORMAL; 11 | -------------------------------------------------------------------------------- /shaders/matcap/vs_matcap.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_normal 2 | $output v_normal 3 | 4 | #include 5 | 6 | void main() 7 | { 8 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); 9 | 10 | v_normal = mul(u_modelView, vec4(a_normal, 0.0)).xyz; 11 | } 12 | -------------------------------------------------------------------------------- /src/app.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int bigger::App::runApp(int argc, char** argv, bgfx::RendererType::Enum type) 9 | { 10 | static ScreenShotCallback callback; 11 | return run(argc, argv, type, BGFX_PCI_ID_NONE, 0, &callback); 12 | } 13 | 14 | void bigger::App::addSceneObject(std::shared_ptr scene_object, const std::string& name) 15 | { 16 | if (name.empty()) 17 | { 18 | const std::string random_name = randutil::GenRandomString(); 19 | m_scene_objects[random_name] = scene_object; 20 | } 21 | else 22 | { 23 | const bool has_the_same_name_object = m_scene_objects.find(name) != m_scene_objects.end(); 24 | if (has_the_same_name_object) 25 | { 26 | throw std::runtime_error(""); 27 | } 28 | 29 | m_scene_objects[name] = scene_object; 30 | } 31 | } 32 | 33 | void bigger::App::update(float dt) 34 | { 35 | // Update state variables 36 | m_last_dt = dt; 37 | m_time += dt; 38 | ++m_frame; 39 | 40 | // Call the application-specific update method 41 | updateApp(); 42 | 43 | // Update scene objects 44 | for (auto key_value : m_scene_objects) 45 | { 46 | if (key_value.second->m_is_active) 47 | { 48 | key_value.second->update(); 49 | } 50 | } 51 | 52 | // Prepare drawing 53 | setViewProj(); 54 | setRect(); 55 | bgfx::touch(0); 56 | 57 | // Draw scene objects 58 | for (auto key_value : m_scene_objects) 59 | { 60 | if (key_value.second->m_is_active && key_value.second->m_is_visible) 61 | { 62 | key_value.second->draw(); 63 | } 64 | } 65 | } 66 | 67 | int bigger::App::shutdown() 68 | { 69 | // Release the scene objects 70 | m_scene_objects.clear(); 71 | 72 | // Release the application-specific shared resources 73 | releaseSharedResources(); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /src/camera.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void bigger::Camera::drawImgui() 5 | { 6 | ImGui::Text("Camera Setting"); 7 | ImGui::SliderFloat3("Position", glm::value_ptr(m_position), -5.0f, 5.0f); 8 | ImGui::SliderFloat3("Target", glm::value_ptr(m_target), -2.0f, 2.0f); 9 | ImGui::SliderFloat("FoV (Degree)", &m_fov, 10.0f, 120.0f); 10 | } 11 | -------------------------------------------------------------------------------- /src/dynamic-mesh-primitive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bigger::DynamicMeshPrimitive::DynamicMeshPrimitive(const std::vector& vertex_data, 4 | const std::vector& triangle_list) 5 | { 6 | m_vertices = vertex_data; 7 | m_triangle_list = triangle_list; 8 | 9 | initializePrimitive(); 10 | } 11 | 12 | void bigger::DynamicMeshPrimitive::initializePrimitive() 13 | { 14 | assert(!m_vertices.empty()); 15 | assert(!m_triangle_list.empty()); 16 | 17 | const bgfx::VertexLayout vertex_layout = PositionNormalUvVertex::getVertexLayout(); 18 | 19 | m_dynamic_vertex_buffer_handle = bgfx::createDynamicVertexBuffer( 20 | bgfx::makeRef(m_vertices.data(), sizeof(PositionNormalUvVertex) * m_vertices.size()), 21 | vertex_layout); 22 | m_index_buffer_handle = 23 | bgfx::createIndexBuffer(bgfx::makeRef(m_triangle_list.data(), sizeof(uint16_t) * m_triangle_list.size())); 24 | 25 | m_is_initialized = true; 26 | } 27 | 28 | void bigger::DynamicMeshPrimitive::submitPrimitive(bgfx::ProgramHandle program, bool preserve_state) const 29 | { 30 | assert(m_is_initialized); 31 | assert(!m_vertices.empty()); 32 | assert(!m_triangle_list.empty()); 33 | 34 | bgfx::update(m_dynamic_vertex_buffer_handle, 35 | 0, 36 | bgfx::makeRef(m_vertices.data(), sizeof(PositionNormalUvVertex) * m_vertices.size())); 37 | 38 | bgfx::setVertexBuffer(0, m_dynamic_vertex_buffer_handle); 39 | bgfx::setIndexBuffer(m_index_buffer_handle); 40 | 41 | bgfx::submit(0, program, bgfx::ViewMode::Default, preserve_state); 42 | } 43 | 44 | void bigger::DynamicMeshPrimitive::destroyPrimitive() 45 | { 46 | assert(m_is_initialized); 47 | assert(!m_vertices.empty()); 48 | assert(!m_triangle_list.empty()); 49 | 50 | bgfx::destroy(m_dynamic_vertex_buffer_handle); 51 | bgfx::destroy(m_index_buffer_handle); 52 | } 53 | 54 | void bigger::DynamicMeshPrimitive::updateVertexData(const std::vector& vertex_data) 55 | { 56 | assert(m_vertices.size() == vertex_data.size()); 57 | 58 | m_vertices = vertex_data; 59 | } 60 | -------------------------------------------------------------------------------- /src/mesh-primitive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define TINYOBJLOADER_IMPLEMENTATION 6 | #include 7 | 8 | bigger::MeshPrimitive::MeshPrimitive(const std::string& obj_path) 9 | { 10 | tinyobj::attrib_t attrib; 11 | std::vector shapes; 12 | std::vector materials; 13 | 14 | std::string warn; 15 | std::string err; 16 | const bool return_value = tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, obj_path.c_str()); 17 | 18 | if (!warn.empty()) 19 | { 20 | std::cerr << warn << std::endl; 21 | } 22 | if (!err.empty()) 23 | { 24 | std::cerr << err << std::endl; 25 | } 26 | if (!return_value) 27 | { 28 | throw std::runtime_error(""); 29 | } 30 | 31 | if (attrib.vertices.empty() || attrib.normals.empty()) 32 | { 33 | throw std::runtime_error(""); 34 | } 35 | 36 | for (const auto& shape : shapes) 37 | { 38 | for (const auto& index : shape.mesh.indices) 39 | { 40 | m_vertices.push_back({{ 41 | attrib.vertices[3 * index.vertex_index + 0], 42 | attrib.vertices[3 * index.vertex_index + 1], 43 | attrib.vertices[3 * index.vertex_index + 2], 44 | }, 45 | { 46 | attrib.normals[3 * index.normal_index + 0], 47 | attrib.normals[3 * index.normal_index + 1], 48 | attrib.normals[3 * index.normal_index + 2], 49 | }, 50 | { 51 | attrib.texcoords[2 * index.texcoord_index + 0], 52 | attrib.texcoords[2 * index.texcoord_index + 1], 53 | }}); 54 | m_triangle_list.push_back(uint16_t(m_triangle_list.size())); 55 | } 56 | } 57 | 58 | Primitive::initializePrimitive(); 59 | } 60 | -------------------------------------------------------------------------------- /src/utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // The following functions in the "bgfx_utils" namespace were originally distributed in the bgfx repository (in the 7 | // examples directory) under the BSD 2-clause license. Yuki Koyama modified them slightly and redistribute them under 8 | // the MIT license here. 9 | namespace bgfx_utils 10 | { 11 | /* 12 | * Copyright 2011-2020 Branimir Karadzic. All rights reserved. 13 | * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause 14 | */ 15 | 16 | bx::AllocatorI* getAllocator() 17 | { 18 | static bx::DefaultAllocator s_allocator; 19 | return &s_allocator; 20 | } 21 | 22 | bx::FileReaderI* getFileReader() 23 | { 24 | static bx::FileReader s_file_reader; 25 | return &s_file_reader; 26 | } 27 | 28 | void* load(bx::FileReaderI* _reader, bx::AllocatorI* _allocator, const char* _filePath, uint32_t* _size) 29 | { 30 | if (bx::open(_reader, _filePath)) 31 | { 32 | uint32_t size = (uint32_t) bx::getSize(_reader); 33 | void* data = BX_ALLOC(_allocator, size); 34 | bx::read(_reader, data, size); 35 | bx::close(_reader); 36 | if (NULL != _size) 37 | { 38 | *_size = size; 39 | } 40 | return data; 41 | } 42 | else 43 | { 44 | printf("Failed to open: %s.\n", _filePath); 45 | } 46 | 47 | if (NULL != _size) 48 | { 49 | *_size = 0; 50 | } 51 | 52 | return NULL; 53 | } 54 | 55 | void* load(const char* _filePath, uint32_t* _size) 56 | { 57 | return load(getFileReader(), getAllocator(), _filePath, _size); 58 | } 59 | 60 | void unload(void* _ptr) { BX_FREE(getAllocator(), _ptr); } 61 | 62 | static void imageReleaseCb(void* _ptr, void* _userData) 63 | { 64 | BX_UNUSED(_ptr); 65 | bimg::ImageContainer* imageContainer = (bimg::ImageContainer*) _userData; 66 | bimg::imageFree(imageContainer); 67 | } 68 | 69 | bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, 70 | const char* _filePath, 71 | uint64_t _flags, 72 | uint8_t _skip, 73 | bgfx::TextureInfo* _info, 74 | bimg::Orientation::Enum* _orientation) 75 | { 76 | BX_UNUSED(_skip); 77 | bgfx::TextureHandle handle = BGFX_INVALID_HANDLE; 78 | 79 | uint32_t size; 80 | void* data = load(_reader, getAllocator(), _filePath, &size); 81 | if (NULL != data) 82 | { 83 | bimg::ImageContainer* imageContainer = bimg::imageParse(getAllocator(), data, size); 84 | 85 | if (NULL != imageContainer) 86 | { 87 | if (NULL != _orientation) 88 | { 89 | *_orientation = imageContainer->m_orientation; 90 | } 91 | 92 | const bgfx::Memory* mem = 93 | bgfx::makeRef(imageContainer->m_data, imageContainer->m_size, imageReleaseCb, imageContainer); 94 | unload(data); 95 | 96 | if (imageContainer->m_cubeMap) 97 | { 98 | handle = bgfx::createTextureCube(uint16_t(imageContainer->m_width), 99 | 1 < imageContainer->m_numMips, 100 | imageContainer->m_numLayers, 101 | bgfx::TextureFormat::Enum(imageContainer->m_format), 102 | _flags, 103 | mem); 104 | } 105 | else if (1 < imageContainer->m_depth) 106 | { 107 | handle = bgfx::createTexture3D(uint16_t(imageContainer->m_width), 108 | uint16_t(imageContainer->m_height), 109 | uint16_t(imageContainer->m_depth), 110 | 1 < imageContainer->m_numMips, 111 | bgfx::TextureFormat::Enum(imageContainer->m_format), 112 | _flags, 113 | mem); 114 | } 115 | else if (bgfx::isTextureValid(0, 116 | false, 117 | imageContainer->m_numLayers, 118 | bgfx::TextureFormat::Enum(imageContainer->m_format), 119 | _flags)) 120 | { 121 | handle = bgfx::createTexture2D(uint16_t(imageContainer->m_width), 122 | uint16_t(imageContainer->m_height), 123 | 1 < imageContainer->m_numMips, 124 | imageContainer->m_numLayers, 125 | bgfx::TextureFormat::Enum(imageContainer->m_format), 126 | _flags, 127 | mem); 128 | } 129 | 130 | if (bgfx::isValid(handle)) 131 | { 132 | bgfx::setName(handle, _filePath); 133 | } 134 | 135 | if (NULL != _info) 136 | { 137 | bgfx::calcTextureSize(*_info, 138 | uint16_t(imageContainer->m_width), 139 | uint16_t(imageContainer->m_height), 140 | uint16_t(imageContainer->m_depth), 141 | imageContainer->m_cubeMap, 142 | 1 < imageContainer->m_numMips, 143 | imageContainer->m_numLayers, 144 | bgfx::TextureFormat::Enum(imageContainer->m_format)); 145 | } 146 | } 147 | } 148 | 149 | return handle; 150 | } 151 | 152 | } // namespace bgfx_utils 153 | 154 | std::string bigger::getShaderDirectoryPath(const bgfx::RendererType::Enum renderer_type) 155 | { 156 | switch (renderer_type) 157 | { 158 | case bgfx::RendererType::Direct3D9: return "shaders/dx9"; 159 | case bgfx::RendererType::Direct3D11: 160 | case bgfx::RendererType::Direct3D12: return "shaders/dx11"; 161 | case bgfx::RendererType::Metal: return "shaders/metal"; 162 | case bgfx::RendererType::OpenGL: return "shaders/glsl"; 163 | case bgfx::RendererType::OpenGLES: return "shaders/essl"; 164 | case bgfx::RendererType::Nvn: 165 | case bgfx::RendererType::Gnm: 166 | case bgfx::RendererType::Noop: 167 | case bgfx::RendererType::Vulkan: 168 | case bgfx::RendererType::Count: break; 169 | } 170 | throw std::runtime_error("Renderer type not supported."); 171 | } 172 | 173 | bgfx::TextureHandle bigger::loadTexture(const char* file_path) 174 | { 175 | return bgfx_utils::loadTexture(bgfx_utils::getFileReader(), 176 | file_path, 177 | BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE, 178 | 0, 179 | nullptr, 180 | nullptr); 181 | } 182 | --------------------------------------------------------------------------------