├── .editorconfig ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── assets ├── animations │ └── jump.dae ├── dummy.txt ├── models │ ├── bunny.obj │ ├── mannequin.dae │ └── teapot.obj └── textures │ └── checkerboard.tga ├── init.sh ├── premake5.lua ├── res ├── Info.plist └── readme │ ├── animation.gif │ ├── cube.gif │ ├── model.gif │ ├── postfx.gif │ └── triangle.png └── src ├── Orbit ├── Core │ ├── Application │ │ ├── Application.cpp │ │ ├── Application.h │ │ ├── Bootstrap.cpp │ │ ├── Bootstrap.h │ │ └── EntryPoint.h │ ├── Container │ │ ├── BinarySearchTree.h │ │ └── Pair.h │ ├── Core.h │ ├── Debug │ │ └── Trace.h │ ├── Event │ │ ├── EventDispatcher.h │ │ ├── EventSubscription.cpp │ │ └── EventSubscription.h │ ├── IO │ │ ├── Asset.cpp │ │ ├── Asset.h │ │ ├── IO.h │ │ ├── Log.cpp │ │ ├── Log.h │ │ ├── Parser │ │ │ ├── IParser.cpp │ │ │ ├── IParser.h │ │ │ ├── ITextParser.cpp │ │ │ ├── ITextParser.h │ │ │ ├── TGA │ │ │ │ ├── TGAParser.cpp │ │ │ │ └── TGAParser.h │ │ │ └── XML │ │ │ │ ├── XMLAttribute.h │ │ │ │ ├── XMLElement.cpp │ │ │ │ ├── XMLElement.h │ │ │ │ ├── XMLParser.cpp │ │ │ │ └── XMLParser.h │ │ ├── Pipe.cpp │ │ └── Pipe.h │ ├── Input │ │ ├── Input.cpp │ │ ├── Input.h │ │ ├── Key.cpp │ │ └── Key.h │ ├── Platform │ │ ├── Android │ │ │ ├── AndroidApp.cpp │ │ │ ├── AndroidApp.h │ │ │ ├── AndroidNativeAppGlue.cpp │ │ │ └── AndroidNativeAppGlue.h │ │ ├── Windows │ │ │ ├── ComPtr.h │ │ │ ├── Win32Error.cpp │ │ │ └── Win32Error.h │ │ ├── iOS │ │ │ ├── UIApplicationDelegate.h │ │ │ ├── UIApplicationDelegate.mm │ │ │ ├── UIWindow.h │ │ │ └── UIWindow.mm │ │ └── macOS │ │ │ ├── WindowDelegate.h │ │ │ └── WindowDelegate.mm │ ├── Private │ │ └── WindowDetails.h │ ├── Shape │ │ ├── CubeShape.cpp │ │ ├── CubeShape.h │ │ ├── EquilateralTriangleShape.cpp │ │ ├── EquilateralTriangleShape.h │ │ ├── IShape.h │ │ ├── SphereShape.cpp │ │ └── SphereShape.h │ ├── Time │ │ ├── Clock.cpp │ │ └── Clock.h │ ├── Utility │ │ ├── Bitmask.h │ │ ├── Color.h │ │ ├── HashView.h │ │ ├── PredefinedColors.h │ │ ├── Ref.h │ │ ├── Selector.h │ │ ├── Singleton.h │ │ ├── Span.h │ │ ├── StringConverting.h │ │ ├── StringLiteral.h │ │ └── Utility.h │ └── Widget │ │ ├── Console.cpp │ │ ├── Console.h │ │ ├── Point.cpp │ │ ├── Point.h │ │ ├── Window.cpp │ │ └── Window.h ├── Graphics │ ├── API │ │ └── OpenGL │ │ │ ├── GLSL.cpp │ │ │ ├── GLSL.h │ │ │ ├── OpenGL.cpp │ │ │ ├── OpenGL.h │ │ │ ├── OpenGLEnums.h │ │ │ ├── OpenGLFunctions.h │ │ │ ├── OpenGLVersion.cpp │ │ │ └── OpenGLVersion.h │ ├── Animation │ │ ├── Animation.cpp │ │ ├── Animation.h │ │ ├── Joint.h │ │ └── KeyFrame.h │ ├── Buffer │ │ ├── FrameBuffer.cpp │ │ ├── FrameBuffer.h │ │ ├── IndexBuffer.cpp │ │ ├── IndexBuffer.h │ │ ├── VertexBuffer.cpp │ │ └── VertexBuffer.h │ ├── Context │ │ ├── RenderContext.cpp │ │ └── RenderContext.h │ ├── Debug │ │ ├── DebugManager.cpp │ │ └── DebugManager.h │ ├── Geometry │ │ ├── Face.h │ │ ├── FaceRange.cpp │ │ ├── FaceRange.h │ │ ├── Geometry.cpp │ │ ├── Geometry.h │ │ ├── Mesh.cpp │ │ ├── Mesh.h │ │ ├── MeshFactory.cpp │ │ ├── MeshFactory.h │ │ ├── Model.cpp │ │ ├── Model.h │ │ ├── Vertex.h │ │ ├── VertexLayout.cpp │ │ ├── VertexLayout.h │ │ ├── VertexRange.cpp │ │ └── VertexRange.h │ ├── Graphics.h │ ├── Platform │ │ └── iOS │ │ │ ├── GLKViewDelegate.h │ │ │ └── GLKViewDelegate.mm │ ├── Private │ │ ├── ConstantBufferDetails.h │ │ ├── FrameBufferDetails.h │ │ ├── IndexBufferDetails.h │ │ ├── RenderContextDetails.h │ │ ├── ShaderDetails.h │ │ ├── Texture2DDetails.h │ │ └── VertexBufferDetails.h │ ├── Renderer │ │ ├── BlendEquation.h │ │ ├── DefaultRenderer.cpp │ │ ├── DefaultRenderer.h │ │ ├── IRenderer.cpp │ │ ├── IRenderer.h │ │ └── RenderCommand.h │ ├── Shader │ │ ├── Shader.cpp │ │ ├── Shader.h │ │ └── ShaderConstant.h │ └── Texture │ │ ├── Texture.cpp │ │ ├── Texture.h │ │ ├── Texture2D.cpp │ │ └── Texture2D.h ├── Math │ ├── Geometry │ │ ├── Line.cpp │ │ ├── Line.h │ │ ├── LineSegment.cpp │ │ ├── LineSegment.h │ │ ├── Plane.cpp │ │ ├── Plane.h │ │ ├── Triangle3D.cpp │ │ └── Triangle3D.h │ ├── Literals.h │ ├── Math.h │ ├── Matrix │ │ ├── Matrix4.cpp │ │ └── Matrix4.h │ └── Vector │ │ ├── Vector2.cpp │ │ ├── Vector2.h │ │ ├── Vector3.cpp │ │ ├── Vector3.h │ │ ├── Vector4.cpp │ │ ├── Vector4.h │ │ └── VectorBase.h ├── Orbit.h └── ShaderGen │ ├── Generator │ ├── IShader.cpp │ ├── IShader.h │ ├── MainFunction.h │ ├── ShaderManager.cpp │ └── ShaderManager.h │ ├── ShaderGen.h │ └── Variables │ ├── Attribute.cpp │ ├── Attribute.h │ ├── DataType.h │ ├── Float.cpp │ ├── Float.h │ ├── Mat4.cpp │ ├── Mat4.h │ ├── Sampler.cpp │ ├── Sampler.h │ ├── Swizzle.cpp │ ├── Swizzle.h │ ├── Uniform.cpp │ ├── Uniform.h │ ├── Variable.cpp │ ├── Variable.h │ ├── Varying.cpp │ ├── Varying.h │ ├── Vec2.cpp │ ├── Vec2.h │ ├── Vec3.cpp │ ├── Vec3.h │ ├── Vec4.cpp │ └── Vec4.h └── Samples ├── 00-Framework └── Framework │ ├── Camera.cpp │ ├── Camera.h │ ├── RenderQuad.cpp │ └── RenderQuad.h ├── 01-Triangle ├── Android │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── gaztin │ │ │ └── orbit │ │ │ └── samples │ │ │ └── triangle │ │ │ └── MainActivity.java │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ └── strings.xml ├── TriangleShader.cpp ├── TriangleShader.h └── main.cpp ├── 02-Cube ├── Android │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── gaztin │ │ │ └── orbit │ │ │ └── samples │ │ │ └── cube │ │ │ └── MainActivity.java │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ └── strings.xml ├── CubeShader.cpp ├── CubeShader.h └── main.cpp ├── 03-Model ├── Android │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── gaztin │ │ │ └── orbit │ │ │ └── samples │ │ │ └── model │ │ │ └── MainActivity.java │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ └── strings.xml ├── ModelShader.cpp ├── ModelShader.h └── main.cpp ├── 04-Animation ├── Android │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── gaztin │ │ │ └── orbit │ │ │ └── samples │ │ │ └── animation │ │ │ └── MainActivity.java │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ └── strings.xml ├── AnimationShader.cpp ├── AnimationShader.h └── main.cpp └── 05-PostFX ├── Android ├── AndroidManifest.xml ├── java │ └── com │ │ └── gaztin │ │ └── orbit │ │ └── samples │ │ └── postfx │ │ └── MainActivity.java └── res │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ └── values │ └── strings.xml ├── PostFXShader.cpp ├── PostFXShader.h ├── SceneShader.cpp ├── SceneShader.h └── main.cpp /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .build-*/ 2 | .codelite/ 3 | .externalNativeBuild/ 4 | .gradle/ 5 | .idea/ 6 | .vs/ 7 | build/*/ 8 | !build/android/ 9 | build/android/mobile/build/ 10 | build/android/wear/build/ 11 | 12 | *.gradle 13 | *.iml 14 | *.sln 15 | *.xcworkspace 16 | *.workspace 17 | 18 | gradle/wrapper/gradle-wrapper.jar 19 | gradle/wrapper/gradle-wrapper.properties 20 | gradle.properties 21 | gradlew 22 | gradlew.bat 23 | local.properties 24 | Makefile 25 | premake5.exe 26 | premake5 27 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third_party/premake-android-studio"] 2 | path = third_party/premake-android-studio 3 | url = https://github.com/Gaztin/premake-android-studio.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Sebastian Kylander https://gaztin.com/ 2 | 3 | This software is provided 'as-is', without any express or implied warranty. In no event will 4 | the authors be held liable for any damages arising from the use of this software. 5 | 6 | Permission is granted to anyone to use this software for any purpose, including commercial 7 | applications, and to alter it and redistribute it freely, subject to the following restrictions: 8 | 9 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 10 | original software. If you use this software in a product, an acknowledgment in the product 11 | documentation would be appreciated but is not required. 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 13 | being the original software. 14 | 3. This notice may not be removed or altered from any source distribution. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 💫Orbit 2 | This is a Work-In-Progress game engine using C++17 3 | 4 | # 🔧Building 5 | This project uses [Premake](https://premake.github.io/). It's a project generator configured with Lua scripts. 6 | 7 | The first thing you'll want to do is to run the `init.sh` script. This is a bash script that fetches/builds the premake executable that we'll use to generate our project files. If you are on Windows and don't have any way of running bash scripts, [simply download the latest executable from their website](https://premake.github.io/download.html) and put it in the root directory of the project. 8 | 9 | To generate files for your favorite IDE or build system, simply run the premake executable like so:
10 | `premake5.exe vs2019` (Windows)
11 | `./premake5 codelite` (Unix) 12 | 13 | [Click here for a list of generators.](https://github.com/premake/premake-core/wiki/Using-Premake) 14 | 15 | # 💉Samples 16 | 17 | **Triangle**
18 | ![](res/readme/triangle.png)
19 | Obligatory triangle example (textured) 20 | 21 | **Cube**
22 | ![](res/readme/cube.gif)
23 | This is the first 3D sample.
24 | Introduces a first-person free-flight camera and the usage of constant buffers and matrices. 25 | 26 | **Model**
27 | ![](res/readme/model.gif)
28 | Loads a teapot model from an OBJ file and renders it with a simple directional light. 29 | 30 | **Animation**
31 | ![](res/readme/animation.gif)
32 | Loads a rigged mannequin model and a jump animation from separate COLLADA files and animates the model on a loop. 33 | 34 | **Post Effects**
35 | ![](res/readme/postfx.gif)
36 | Uses two render passes. The first one uses a regular scene shader to render a bunny to a separate framebuffer. The second pass uses another shader to sample on different points on the framebuffer and renders it to a fullscreen quad. The result is a distortion effect. -------------------------------------------------------------------------------- /assets/dummy.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/assets/dummy.txt -------------------------------------------------------------------------------- /assets/textures/checkerboard.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/assets/textures/checkerboard.tga -------------------------------------------------------------------------------- /res/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | Icon.png 13 | CFBundleIdentifier 14 | com.gaztin.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | 28 | -------------------------------------------------------------------------------- /res/readme/animation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/res/readme/animation.gif -------------------------------------------------------------------------------- /res/readme/cube.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/res/readme/cube.gif -------------------------------------------------------------------------------- /res/readme/model.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/res/readme/model.gif -------------------------------------------------------------------------------- /res/readme/postfx.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/res/readme/postfx.gif -------------------------------------------------------------------------------- /res/readme/triangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/res/readme/triangle.png -------------------------------------------------------------------------------- /src/Orbit/Core/Application/Application.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Application.h" 19 | 20 | #include "Orbit/Core/Platform/iOS/UIApplicationDelegate.h" 21 | #include "Orbit/Core/Time/Clock.h" 22 | #include "Orbit/Core/Widget/Console.h" 23 | #include "Orbit/Core/Widget/Window.h" 24 | 25 | #include 26 | 27 | ORB_NAMESPACE_BEGIN 28 | 29 | void ApplicationBase::RunInstance( void ) 30 | { 31 | Console console; 32 | 33 | #if defined( ORB_OS_IOS ) 34 | 35 | @autoreleasepool 36 | { 37 | UIApplicationMain( 0, nil, nil, NSStringFromClass( [ ORB_NAMESPACED_OBJC( UIApplicationDelegate ) class ] ) ); 38 | } 39 | 40 | #else 41 | 42 | if( !Bootstrap::trampoline ) 43 | return; 44 | 45 | // Start the engine clock 46 | Clock::Start(); 47 | 48 | // Initialize application instance and create main window 49 | Window main_window = Window( 800, 600 ); 50 | auto instance = std::static_pointer_cast< ApplicationBase >( Bootstrap::trampoline() ); 51 | 52 | // Show main window 53 | main_window.Show(); 54 | 55 | while( main_window.IsOpen() ) 56 | { 57 | Clock::Update(); 58 | 59 | main_window.PollEvents(); 60 | instance->OnFrame(); 61 | } 62 | 63 | #endif 64 | 65 | } 66 | 67 | ORB_NAMESPACE_END 68 | -------------------------------------------------------------------------------- /src/Orbit/Core/Application/Application.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Application/Bootstrap.h" 20 | 21 | #include 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | class ORB_API_CORE ApplicationBase 27 | { 28 | public: 29 | 30 | ApplicationBase( void ) = default; 31 | virtual ~ApplicationBase( void ) = default; 32 | 33 | public: 34 | 35 | virtual void OnFrame( void ) = 0; 36 | 37 | public: 38 | 39 | static void RunInstance( void ); 40 | 41 | }; 42 | 43 | template< typename Derived > 44 | class Application : private ApplicationBase, private Bootstrapper< Derived > 45 | { 46 | public: 47 | 48 | virtual ~Application( void ) = default; 49 | 50 | }; 51 | 52 | ORB_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /src/Orbit/Core/Application/Bootstrap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Bootstrap.h" 19 | 20 | ORB_NAMESPACE_BEGIN 21 | 22 | Bootstrap::Trampoline Bootstrap::trampoline = nullptr; 23 | 24 | ORB_NAMESPACE_END 25 | -------------------------------------------------------------------------------- /src/Orbit/Core/Application/Bootstrap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | namespace Bootstrap 26 | { 27 | using Trampoline = std::shared_ptr< void >( * )( void ); 28 | 29 | extern ORB_API_CORE Trampoline trampoline; 30 | 31 | template< typename T > 32 | #if defined( ORB_CC_CLANG ) || defined( ORB_CC_GCC ) 33 | __attribute__(( constructor )) 34 | #endif // ORB_CC_CLANG || defined( ORB_CC_GCC ) 35 | auto Load( void ) 36 | { 37 | trampoline = []( void ){ return std::static_pointer_cast< void >( std::make_shared< T >() ); }; 38 | return 0; 39 | } 40 | } 41 | 42 | template< typename T > 43 | class Bootstrapper 44 | { 45 | private: 46 | 47 | #if defined( ORB_CC_MSVC ) 48 | static inline auto bootstrap_eval = Bootstrap::Load< T >(); 49 | #elif defined( ORB_CC_CLANG ) || defined( ORB_CC_GCC ) // ORB_CC_MSVC 50 | using BootstrapDecl = decltype( Bootstrap::Load< T >() ); 51 | #endif // ORB_CC_CLANG || ORB_CC_GCC 52 | 53 | }; 54 | 55 | ORB_NAMESPACE_END 56 | -------------------------------------------------------------------------------- /src/Orbit/Core/Application/EntryPoint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Application/Application.h" 20 | 21 | #if defined( ORB_OS_WINDOWS ) 22 | # include 23 | 24 | INT WINAPI WinMain( HINSTANCE, HINSTANCE, PSTR, INT ) 25 | { 26 | ORB_NAMESPACE ApplicationBase::RunInstance(); 27 | return 0; 28 | } 29 | 30 | #elif defined( ORB_OS_LINUX ) || defined( ORB_OS_MACOS ) || defined( ORB_OS_IOS ) 31 | 32 | int main( int, char*[] ) 33 | { 34 | ORB_NAMESPACE ApplicationBase::RunInstance(); 35 | return 0; 36 | } 37 | 38 | #elif defined( ORB_OS_ANDROID ) 39 | # include "Orbit/Core/Platform/Android/AndroidApp.h" 40 | # include "Orbit/Core/Platform/Android/AndroidNativeAppGlue.h" 41 | 42 | void ORB_NAMESPACE AndroidMain( AndroidApp* app ) 43 | { 44 | ORB_NAMESPACE AndroidOnly::app = app; 45 | ORB_NAMESPACE ApplicationBase::RunInstance(); 46 | } 47 | 48 | extern "C" JNIEXPORT void ANativeActivity_onCreate( ANativeActivity* activity, void* saved_state, size_t saved_state_size ) 49 | { 50 | activity->instance = ORB_NAMESPACE AndroidAppCreate( activity, saved_state, saved_state_size ); 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/Orbit/Core/Core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Orbit.h" 20 | 21 | #if defined( ORB_BUILD_CORE ) 22 | # define ORB_API_CORE ORB_DLL_EXPORT 23 | #else // ORB_BUILD_CORE 24 | # define ORB_API_CORE ORB_DLL_IMPORT 25 | #endif // !ORB_BUILD_CORE 26 | -------------------------------------------------------------------------------- /src/Orbit/Core/Debug/Trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/IO/Log.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | #if defined( NDEBUG ) 24 | #define ORB_TRACE( STR, ... ) 25 | #else // NDEBUG 26 | #define ORB_TRACE( STR, ... ) ORB_NAMESPACE LogDebug( STR, __VA_ARGS__ ) 27 | #endif // !NDEBUG 28 | 29 | ORB_NAMESPACE_END 30 | -------------------------------------------------------------------------------- /src/Orbit/Core/Event/EventSubscription.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #include 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | class ORB_API_CORE EventSubscription 27 | { 28 | public: 29 | 30 | struct Deleter 31 | { 32 | const void* user_data; 33 | void( *functor )( uint64_t id, const void* user_data ); 34 | }; 35 | 36 | public: 37 | 38 | EventSubscription( void ); 39 | EventSubscription( uint64_t id, Deleter deleter ); 40 | EventSubscription( const EventSubscription& other ); 41 | EventSubscription( EventSubscription&& other ); 42 | ~EventSubscription( void ); 43 | 44 | public: 45 | 46 | EventSubscription& operator=( const EventSubscription& other ); 47 | EventSubscription& operator=( EventSubscription&& other ); 48 | 49 | private: 50 | 51 | struct ControlBlock 52 | { 53 | std::atomic_uint64_t ref_count; 54 | }; 55 | 56 | private: 57 | 58 | uint64_t id_; 59 | Deleter deleter_; 60 | ControlBlock* control_block_; 61 | 62 | }; 63 | 64 | ORB_NAMESPACE_END 65 | -------------------------------------------------------------------------------- /src/Orbit/Core/IO/Asset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #include 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | class ORB_API_CORE Asset 27 | { 28 | public: 29 | 30 | explicit Asset( std::string_view path ); 31 | 32 | public: 33 | 34 | const uint8_t* GetData( void ) const { return data_.data(); } 35 | size_t GetSize( void ) const { return data_.size(); } 36 | 37 | private: 38 | 39 | std::vector< uint8_t > data_; 40 | 41 | }; 42 | 43 | ORB_NAMESPACE_END 44 | -------------------------------------------------------------------------------- /src/Orbit/Core/IO/IO.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #if defined( ORB_OS_WINDOWS ) 22 | # include 23 | #endif // ORB_OS_WINDOWS 24 | 25 | ORB_NAMESPACE_BEGIN 26 | 27 | #if defined( ORB_OS_WINDOWS ) 28 | 29 | using NativeFileHandle = HANDLE; 30 | 31 | inline const NativeFileHandle invalid_file_handle = INVALID_HANDLE_VALUE; 32 | 33 | #else // ORB_OS_WINDOWS 34 | 35 | using NativeFileHandle = int; 36 | 37 | constexpr NativeFileHandle invalid_file_handle = -1; 38 | 39 | #endif // !ORB_OS_WINDOWS 40 | 41 | ORB_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /src/Orbit/Core/IO/Parser/IParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "IParser.h" 19 | 20 | #include 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | IParser::IParser( ByteSpan data ) 25 | : data_ { data.Copy() } 26 | , size_ { data.Size() } 27 | , offset_{ 0 } 28 | , good_ { false } 29 | { 30 | } 31 | 32 | void IParser::Skip( size_t size ) 33 | { 34 | if( ( offset_ + size ) < size_ ) offset_ += size; 35 | else offset_ = size_; 36 | } 37 | 38 | void IParser::ReadBytes( void* dst, size_t count ) 39 | { 40 | if( ( offset_ + count ) < size_ ) 41 | { 42 | std::memcpy( dst, &data_[ offset_ ], count ); 43 | offset_ += count; 44 | } 45 | else 46 | { 47 | std::memcpy( dst, &data_[ offset_ ], ( offset_ - size_ ) ); 48 | offset_ = size_; 49 | } 50 | } 51 | 52 | bool IParser::IsEOF( void ) const 53 | { 54 | return ( offset_ == size_ ); 55 | } 56 | 57 | ORB_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /src/Orbit/Core/IO/Parser/IParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Span.h" 20 | 21 | #include 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | class ORB_API_CORE IParser 27 | { 28 | public: 29 | 30 | explicit IParser( ByteSpan data ); 31 | virtual ~IParser( void ) = default; 32 | 33 | public: 34 | 35 | bool IsGood( void ) const { return good_; } 36 | 37 | protected: 38 | 39 | void Skip ( size_t size ); 40 | void ReadBytes( void* dst, size_t count ); 41 | 42 | protected: 43 | 44 | bool IsEOF( void ) const; 45 | 46 | protected: 47 | 48 | std::unique_ptr< uint8_t[] > data_; 49 | 50 | size_t size_; 51 | size_t offset_; 52 | 53 | bool good_; 54 | 55 | }; 56 | 57 | ORB_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /src/Orbit/Core/IO/Parser/ITextParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/IO/Parser/IParser.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class ORB_API_CORE ITextParser : public IParser 24 | { 25 | public: 26 | 27 | explicit ITextParser( ByteSpan data ); 28 | 29 | protected: 30 | 31 | void SkipWhitespace ( void ); 32 | std::string ReadAlphaNumeric( void ); 33 | std::string ReadPrintable ( void ); 34 | std::string ReadLiteral ( void ); 35 | 36 | protected: 37 | 38 | std::string Peek( size_t length ) const; 39 | 40 | protected: 41 | 42 | bool ExpectString( std::string_view str ); 43 | 44 | }; 45 | 46 | ORB_NAMESPACE_END 47 | -------------------------------------------------------------------------------- /src/Orbit/Core/IO/Parser/TGA/TGAParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/IO/Parser/IParser.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | ORB_NAMESPACE_BEGIN 26 | 27 | class ORB_API_CORE TGAParser : public IParser 28 | { 29 | public: 30 | 31 | explicit TGAParser( ByteSpan data ); 32 | 33 | public: 34 | 35 | const uint32_t* ImageData( void ) const { return image_data_.get(); } 36 | uint16_t Width ( void ) const { return width_; } 37 | uint16_t Height ( void ) const { return height_; } 38 | 39 | private: 40 | 41 | uint32_t ReadTrueColor ( void ); 42 | size_t ReadNextRLEPacket( uint32_t* dst ); 43 | 44 | private: 45 | 46 | std::unique_ptr< uint32_t[] > image_data_; 47 | 48 | size_t bytes_per_pixel_; 49 | 50 | uint16_t width_; 51 | uint16_t height_; 52 | 53 | }; 54 | 55 | ORB_NAMESPACE_END 56 | -------------------------------------------------------------------------------- /src/Orbit/Core/IO/Parser/XML/XMLAttribute.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | struct XMLAttribute 26 | { 27 | std::string name; 28 | std::string value; 29 | }; 30 | 31 | ORB_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /src/Orbit/Core/IO/Parser/XML/XMLElement.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/IO/Parser/XML/XMLAttribute.h" 20 | 21 | #include 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | class ORB_API_CORE XMLElement 27 | { 28 | public: 29 | 30 | std::string_view Attribute( std::string_view key ) const; 31 | 32 | public: 33 | 34 | const XMLElement& ChildWithAttribute( std::string_view element, std::string_view attribute, std::string_view value ) const; 35 | size_t CountChildren ( std::string_view element ) const; 36 | bool IsValid ( void ) const; 37 | 38 | public: 39 | 40 | auto begin( void ) const { return children.begin(); } 41 | auto end ( void ) const { return children.end(); } 42 | 43 | public: 44 | 45 | const XMLElement& operator[]( std::string_view key ) const; 46 | 47 | public: 48 | 49 | std::string name; 50 | std::string content; 51 | 52 | std::vector< XMLAttribute > attributes; 53 | std::vector< XMLElement > children; 54 | 55 | }; 56 | 57 | ORB_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /src/Orbit/Core/IO/Parser/XML/XMLParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/IO/Parser/XML/XMLElement.h" 20 | #include "Orbit/Core/IO/Parser/ITextParser.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | class ORB_API_CORE XMLParser : public ITextParser 27 | { 28 | public: 29 | 30 | explicit XMLParser( ByteSpan data ); 31 | ~XMLParser( void ) = default; 32 | 33 | public: 34 | 35 | const XMLElement& GetRootElement( void ) const { return root_element_; } 36 | 37 | private: 38 | 39 | std::string ReadName ( void ); 40 | std::string ReadContent ( void ); 41 | bool ParseElement( XMLElement* parent ); 42 | 43 | private: 44 | 45 | XMLElement root_element_; 46 | 47 | }; 48 | 49 | ORB_NAMESPACE_END 50 | -------------------------------------------------------------------------------- /src/Orbit/Core/Platform/Android/AndroidApp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "AndroidApp.h" 19 | 20 | #if defined( ORB_OS_ANDROID ) 21 | # include "Orbit/Core/Platform/Android/AndroidNativeAppGlue.h" 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | namespace AndroidOnly 26 | { 27 | AndroidApp* app = nullptr; 28 | } 29 | 30 | ORB_NAMESPACE_END 31 | 32 | #endif // ORB_OS_ANDROID 33 | -------------------------------------------------------------------------------- /src/Orbit/Core/Platform/Android/AndroidApp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Platform/Android/AndroidNativeAppGlue.h" 20 | 21 | #if defined( ORB_OS_ANDROID ) 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | namespace AndroidOnly 26 | { 27 | extern ORB_API_CORE AndroidApp* app; 28 | } 29 | 30 | ORB_NAMESPACE_END 31 | 32 | #endif // ORB_OS_ANDROID 33 | -------------------------------------------------------------------------------- /src/Orbit/Core/Platform/Windows/Win32Error.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Win32Error.h" 19 | 20 | #if defined( ORB_OS_WINDOWS ) 21 | # include "Orbit/Core/IO/Log.h" 22 | 23 | # include 24 | 25 | ORB_NAMESPACE_BEGIN 26 | 27 | bool CheckHResult( HRESULT hresult, std::string_view statement, std::string_view file, uint32_t line ) 28 | { 29 | if( FAILED( hresult ) ) 30 | { 31 | LPSTR buffer; 32 | 33 | FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, hresult, 0, reinterpret_cast< LPSTR >( &buffer ), 0, nullptr ); 34 | LogError( "[%s(%d)] { %s } failed with error: %s", file.data(), line, statement.data(), buffer ); 35 | 36 | return false; 37 | } 38 | 39 | return true; 40 | } 41 | 42 | bool CheckSystemError( DWORD error, std::string_view statement, std::string_view file, uint32_t line ) 43 | { 44 | return CheckHResult( HRESULT_FROM_WIN32( error ), statement, file, line ); 45 | } 46 | 47 | ORB_NAMESPACE_END 48 | 49 | #endif // ORB_OS_WINDOWS 50 | -------------------------------------------------------------------------------- /src/Orbit/Core/Platform/Windows/Win32Error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #if defined( ORB_OS_WINDOWS ) 22 | # include 23 | 24 | # include 25 | 26 | ORB_NAMESPACE_BEGIN 27 | 28 | extern ORB_API_CORE bool CheckHResult ( HRESULT hresult, std::string_view statement, std::string_view file, uint32_t line ); 29 | extern ORB_API_CORE bool CheckSystemError( DWORD error, std::string_view statement, std::string_view file, uint32_t line ); 30 | 31 | ORB_NAMESPACE_END 32 | 33 | #define ORB_CHECK_HRESULT( X ) ( ORB_NAMESPACE CheckHResult( ( X ), #X, __FILE__, __LINE__ ) ) 34 | #define ORB_CHECK_SYSTEM_ERROR( X ) ( SetLastError( ERROR_SUCCESS ), ( X ), ORB_NAMESPACE CheckSystemError( GetLastError(), #X, __FILE__, __LINE__ ) ) 35 | 36 | #endif // ORB_OS_WINDOWS 37 | -------------------------------------------------------------------------------- /src/Orbit/Core/Platform/iOS/UIApplicationDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #if defined( ORB_OS_IOS ) 22 | # include "Orbit/Core/Application/Application.h" 23 | # include "Orbit/Core/Widget/Window.h" 24 | 25 | # include 26 | 27 | @interface ORB_NAMESPACED_OBJC( UIApplicationDelegate ) : UIResponder< UIApplicationDelegate > 28 | { 29 | std::shared_ptr< ORB_NAMESPACE ApplicationBase > application_instance; 30 | std::shared_ptr< ORB_NAMESPACE Window > main_window; 31 | } 32 | 33 | -( void )OnFrame:( CADisplayLink* )display_link; 34 | 35 | @end 36 | 37 | #endif // ORB_OS_IOS 38 | -------------------------------------------------------------------------------- /src/Orbit/Core/Platform/iOS/UIWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #if defined( ORB_OS_IOS ) 22 | # include 23 | 24 | @interface ORB_NAMESPACED_OBJC( UIWindow ) : UIWindow 25 | { 26 | } 27 | @end 28 | 29 | #endif // ORB_OS_IOS 30 | 31 | -------------------------------------------------------------------------------- /src/Orbit/Core/Platform/macOS/WindowDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #if defined( ORB_OS_MACOS ) 22 | # include 23 | 24 | @interface ORB_NAMESPACED_OBJC( WindowDelegate ) : NSObject< NSWindowDelegate > 25 | { 26 | } 27 | @end 28 | 29 | #endif // ORB_OS_MACOS 30 | -------------------------------------------------------------------------------- /src/Orbit/Core/Shape/CubeShape.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "CubeShape.h" 19 | 20 | ORB_NAMESPACE_BEGIN 21 | 22 | CubeShape::CubeShape( float half_extent ) 23 | : half_extent( half_extent ) 24 | { 25 | } 26 | 27 | ORB_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /src/Orbit/Core/Shape/CubeShape.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Shape/IShape.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class ORB_API_CORE CubeShape : public IShape 24 | { 25 | public: 26 | 27 | explicit CubeShape( float half_extent ); 28 | 29 | public: 30 | 31 | ShapeType GetType( void ) const override { return ShapeType::Cube; } 32 | 33 | public: 34 | 35 | float half_extent; 36 | 37 | }; 38 | 39 | ORB_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /src/Orbit/Core/Shape/EquilateralTriangleShape.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "EquilateralTriangleShape.h" 19 | 20 | ORB_NAMESPACE_BEGIN 21 | 22 | EquilateralTriangleShape::EquilateralTriangleShape( float scale ) 23 | : scale( scale ) 24 | { 25 | } 26 | 27 | ORB_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /src/Orbit/Core/Shape/EquilateralTriangleShape.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Shape/IShape.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class ORB_API_CORE EquilateralTriangleShape : public IShape 24 | { 25 | public: 26 | 27 | explicit EquilateralTriangleShape( float scale ); 28 | 29 | public: 30 | 31 | ShapeType GetType( void ) const override { return ShapeType::EquilateralTriangle; } 32 | 33 | public: 34 | 35 | float scale; 36 | 37 | }; 38 | 39 | ORB_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /src/Orbit/Core/Shape/IShape.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | enum class ShapeType 24 | { 25 | EquilateralTriangle, 26 | Cube, 27 | Sphere, 28 | }; 29 | 30 | class ORB_API_CORE IShape 31 | { 32 | public: 33 | 34 | IShape( void ) = default; 35 | virtual ~IShape( void ) = default; 36 | 37 | public: 38 | 39 | virtual ShapeType GetType( void ) const = 0; 40 | 41 | }; 42 | 43 | ORB_NAMESPACE_END 44 | -------------------------------------------------------------------------------- /src/Orbit/Core/Shape/SphereShape.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Orbit/Core/Shape/SphereShape.cpp -------------------------------------------------------------------------------- /src/Orbit/Core/Shape/SphereShape.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Shape/IShape.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class ORB_API_CORE SphereShape : public IShape 24 | { 25 | public: 26 | 27 | explicit SphereShape( float radius ); 28 | 29 | public: 30 | 31 | ShapeType GetType( void ) const override { return ShapeType::Sphere; } 32 | 33 | public: 34 | 35 | float radius; 36 | 37 | }; 38 | 39 | ORB_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /src/Orbit/Core/Time/Clock.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Clock.h" 19 | 20 | #include 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | static std::chrono::high_resolution_clock::time_point start; 25 | static std::chrono::high_resolution_clock::time_point then; 26 | static std::chrono::high_resolution_clock::time_point now; 27 | 28 | float Clock::GetLife( void ) 29 | { 30 | auto life_time = std::chrono::duration_cast< std::chrono::duration< float > >( now - start ); 31 | return life_time.count(); 32 | } 33 | 34 | float Clock::GetDelta( void ) 35 | { 36 | auto delta_time = std::chrono::duration_cast< std::chrono::duration< float > >( now - then ); 37 | return delta_time.count(); 38 | } 39 | 40 | void Clock::Start( void ) 41 | { 42 | start = std::chrono::high_resolution_clock::now(); 43 | then = start; 44 | now = start; 45 | } 46 | 47 | void Clock::Update( void ) 48 | { 49 | then = now; 50 | now = std::chrono::high_resolution_clock::now(); 51 | } 52 | 53 | ORB_NAMESPACE_END 54 | -------------------------------------------------------------------------------- /src/Orbit/Core/Time/Clock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | namespace Clock 24 | { 25 | /** Returns the time (in seconds) since the engine was initialized */ 26 | ORB_API_CORE float GetLife( void ); 27 | 28 | /** Returns the time (in seconds) since the last frame */ 29 | ORB_API_CORE float GetDelta( void ); 30 | 31 | /** Starts the internal timer. Initializes Life and Delta to current time. */ 32 | ORB_API_CORE void Start( void ); 33 | 34 | /** Update the internal timer. Increments Life and refreshes Delta. */ 35 | ORB_API_CORE void Update( void ); 36 | }; 37 | 38 | ORB_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /src/Orbit/Core/Utility/Color.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | class Color 26 | { 27 | public: 28 | 29 | constexpr Color( void ) 30 | : r( 0.0f ) 31 | , g( 0.0f ) 32 | , b( 0.0f ) 33 | , a( 1.0f ) 34 | { 35 | } 36 | 37 | constexpr Color( float r, float g, float b, float a = 1.0f ) 38 | : r( r ) 39 | , g( g ) 40 | , b( b ) 41 | , a( a ) 42 | { 43 | } 44 | 45 | public: 46 | 47 | constexpr float& operator[]( size_t i ) { return ( &r )[ i ]; } 48 | constexpr const float& operator[]( size_t i ) const { return ( &r )[ i ]; } 49 | 50 | public: 51 | 52 | static Color Random( void ) 53 | { 54 | Color color; 55 | color.r = rand() / static_cast< float >( RAND_MAX ); 56 | color.g = rand() / static_cast< float >( RAND_MAX ); 57 | color.b = rand() / static_cast< float >( RAND_MAX ); 58 | 59 | return color; 60 | } 61 | 62 | public: 63 | 64 | float r; 65 | float g; 66 | float b; 67 | float a; 68 | 69 | }; 70 | 71 | ORB_NAMESPACE_END 72 | -------------------------------------------------------------------------------- /src/Orbit/Core/Utility/HashView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Utility.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | template< typename ValueType = size_t > 26 | class HashView 27 | { 28 | public: 29 | 30 | constexpr HashView( void ) 31 | : value_{ } 32 | { 33 | } 34 | 35 | constexpr HashView( std::string_view str ) 36 | : value_{ Hash( str ) } 37 | { 38 | } 39 | 40 | constexpr ValueType GetValue( void ) const { return value_; } 41 | 42 | private: 43 | 44 | /* FNV-1a hash function as per http://isthe.com/chongo/tech/comp/fnv/ */ 45 | constexpr ValueType Hash( std::string_view str ) const 46 | { 47 | using HashTraits = HashTraitsFNV< sizeof( ValueType ) >; 48 | 49 | ValueType val = HashTraits::offset_basis; 50 | 51 | for( size_t i = 0; i < str.length(); ++i ) 52 | { 53 | val ^= static_cast< ValueType >( str[ i ] ); 54 | val *= HashTraits::prime; 55 | } 56 | 57 | return val; 58 | } 59 | 60 | private: 61 | 62 | ValueType value_; 63 | 64 | }; 65 | 66 | ORB_NAMESPACE_END 67 | -------------------------------------------------------------------------------- /src/Orbit/Core/Utility/PredefinedColors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Color.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | constexpr Color Black = Color( 0.0f, 0.0f, 0.0f ); 24 | constexpr Color White = Color( 1.0f, 1.0f, 1.0f ); 25 | constexpr Color Red = Color( 1.0f, 0.0f, 0.0f ); 26 | constexpr Color Green = Color( 0.0f, 1.0f, 0.0f ); 27 | constexpr Color Blue = Color( 0.0f, 0.0f, 1.0f ); 28 | constexpr Color Yellow = Color( 1.0f, 1.0f, 0.0f ); 29 | constexpr Color Magenta = Color( 1.0f, 0.0f, 1.0f ); 30 | constexpr Color Turquoise = Color( 0.0f, 1.0f, 1.0f ); 31 | 32 | ORB_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /src/Orbit/Core/Utility/Selector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Container/BinarySearchTree.h" 20 | #include "Orbit/Core/Container/Pair.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | template< typename KeyType, typename ValueType > 27 | class Selector 28 | { 29 | public: 30 | 31 | using PairType = Pair< KeyType, ValueType >; 32 | 33 | public: 34 | 35 | constexpr Selector( std::initializer_list< PairType > pairs ) 36 | { 37 | for( const PairType& pair : pairs ) 38 | tree_.Insert( pair ); 39 | } 40 | 41 | public: 42 | 43 | constexpr ValueType operator[]( const KeyType& key ) const 44 | { 45 | if( const PairType* pair = tree_.Search( PairType( key, { } ) ); pair != nullptr ) 46 | return pair->Value(); 47 | 48 | return { }; 49 | } 50 | 51 | private: 52 | 53 | BinarySearchTree< PairType > tree_; 54 | 55 | }; 56 | 57 | ORB_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /src/Orbit/Core/Utility/Singleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | template< typename Derived > 26 | class ManualSingleton 27 | { 28 | public: 29 | 30 | static Derived& GetInstance( void ) 31 | { 32 | assert( instance_ != nullptr ); 33 | return *instance_; 34 | } 35 | 36 | static Derived* GetInstancePtr( void ) 37 | { 38 | return instance_; 39 | } 40 | 41 | protected: 42 | 43 | ManualSingleton( void ) 44 | { 45 | assert( instance_ == nullptr ); 46 | instance_ = static_cast< Derived* >( this ); 47 | } 48 | 49 | ~ManualSingleton( void ) 50 | { 51 | assert( instance_ == this ); 52 | instance_ = nullptr; 53 | } 54 | 55 | private: 56 | 57 | static Derived* instance_; 58 | 59 | }; 60 | 61 | template< typename Derived > 62 | class Singleton 63 | { 64 | public: 65 | 66 | static Derived& GetInstance( void ) 67 | { 68 | static Derived instance = { }; 69 | return instance; 70 | } 71 | 72 | }; 73 | 74 | template< typename Derived > 75 | Derived* ManualSingleton< Derived >::instance_ = nullptr; 76 | 77 | ORB_NAMESPACE_END 78 | -------------------------------------------------------------------------------- /src/Orbit/Core/Widget/Console.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Console.h" 19 | 20 | #include "Orbit/Core/Platform/Windows/Win32Error.h" 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | Console::Console( void ) 25 | { 26 | 27 | #if defined( ORB_OS_WINDOWS ) 28 | AllocConsole(); 29 | #endif // ORB_OS_WINDOWS 30 | 31 | } 32 | 33 | Console::~Console( void ) 34 | { 35 | 36 | #if defined( ORB_OS_WINDOWS ) 37 | ORB_CHECK_SYSTEM_ERROR( SetStdHandle( STD_OUTPUT_HANDLE, NULL ) ); 38 | FreeConsole(); 39 | #endif // ORB_OS_WINDOWS 40 | 41 | } 42 | 43 | ORB_NAMESPACE_END 44 | -------------------------------------------------------------------------------- /src/Orbit/Core/Widget/Console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Singleton.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class ORB_API_CORE Console : public ManualSingleton< Console > 24 | { 25 | public: 26 | 27 | Console( void ); 28 | ~Console( void ); 29 | 30 | }; 31 | 32 | ORB_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /src/Orbit/Core/Widget/Point.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Point.h" 19 | 20 | #include 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | Point::Point( void ) 25 | : x{ 0 } 26 | , y{ 0 } 27 | { 28 | } 29 | 30 | Point::Point( int x, int y ) 31 | : x{ x } 32 | , y{ y } 33 | { 34 | } 35 | 36 | Point::Point( float fx, float fy ) 37 | : x{ static_cast< int >( std::round( fx ) ) } 38 | , y{ static_cast< int >( std::round( fy ) ) } 39 | { 40 | } 41 | 42 | Point::Point( double dx, double dy ) 43 | : x( static_cast< int >( std::round( dx ) ) ) 44 | , y( static_cast< int >( std::round( dy ) ) ) 45 | { 46 | } 47 | 48 | Point& Point::operator+=( const Point& other ) 49 | { 50 | x += other.x; 51 | y += other.y; 52 | 53 | return *this; 54 | } 55 | 56 | Point& Point::operator-=( const Point& other ) 57 | { 58 | x -= other.x; 59 | y -= other.y; 60 | 61 | return *this; 62 | } 63 | 64 | Point Point::operator+( const Point& other ) const 65 | { 66 | return Point( x + other.x, y + other.y ); 67 | } 68 | 69 | Point Point::operator-( const Point& other ) const 70 | { 71 | return Point( x - other.x, y - other.y ); 72 | } 73 | 74 | ORB_NAMESPACE_END 75 | -------------------------------------------------------------------------------- /src/Orbit/Core/Widget/Point.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Core.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class ORB_API_CORE Point 24 | { 25 | public: 26 | 27 | Point( void ); 28 | Point( int x, int y ); 29 | Point( float fx, float fy ); 30 | Point( double dx, double dy ); 31 | 32 | public: 33 | 34 | Point& operator+=( const Point& other ); 35 | Point& operator-=( const Point& other ); 36 | 37 | public: 38 | 39 | Point operator+( const Point& other ) const; 40 | Point operator-( const Point& other ) const; 41 | 42 | public: 43 | 44 | int x; 45 | int y; 46 | 47 | }; 48 | 49 | ORB_NAMESPACE_END 50 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/API/OpenGL/GLSL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/API/OpenGL/OpenGLVersion.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | namespace GLSL 26 | { 27 | extern ORB_API_GRAPHICS std::string_view GetVersionDirective ( OpenGLVersion version ); 28 | extern ORB_API_GRAPHICS std::string_view GetGLSLDefine ( void ); 29 | extern ORB_API_GRAPHICS std::string_view GetShaderTypeDefine ( ShaderType shader_type ); 30 | extern ORB_API_GRAPHICS std::string_view GetPrecision ( OpenGLVersion version ); 31 | extern ORB_API_GRAPHICS std::string_view GetConstantsMacros ( OpenGLVersion version ); 32 | extern ORB_API_GRAPHICS std::string_view GetVaryingMacro ( OpenGLVersion version, ShaderType shader_type ); 33 | extern ORB_API_GRAPHICS std::string_view GetAttributeMacro ( OpenGLVersion version, ShaderType shader_type ); 34 | extern ORB_API_GRAPHICS std::string_view GetOutColorMacro ( OpenGLVersion version ); 35 | } 36 | 37 | ORB_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/API/OpenGL/OpenGL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Graphics.h" 20 | 21 | #if( ORB_HAS_OPENGL ) 22 | # include "Orbit/Core/Utility/Bitmask.h" 23 | 24 | # include 25 | # include 26 | # include 27 | # include 28 | 29 | ORB_NAMESPACE_BEGIN 30 | 31 | using GLintptr = ptrdiff_t; 32 | using GLsizeiptr = size_t; 33 | using GLdouble = double; 34 | using GLchar = char; 35 | using GLint64 = int64_t; 36 | using GLsync = struct __GLsync*; 37 | 38 | extern ORB_API_GRAPHICS void* GetOpenGLProcAddress( std::string_view name ); 39 | extern ORB_API_GRAPHICS void HandleOpenGLError ( GLenum err, std::string_view func ); 40 | 41 | #define ORB_GL_CLAMP_TO_EDGE 0x812F 42 | #define ORB_GL_DEPTH24_STENCIL8 0x88F0 43 | 44 | ORB_NAMESPACE_END 45 | 46 | #endif // ORB_HAS_OPENGL 47 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Animation/Animation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Span.h" 20 | #include "Orbit/Graphics/Animation/KeyFrame.h" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | ORB_NAMESPACE_BEGIN 27 | 28 | class ORB_API_GRAPHICS Animation 29 | { 30 | public: 31 | 32 | explicit Animation( ByteSpan data ); 33 | 34 | public: 35 | 36 | Matrix4 JointPoseAtTime( std::string_view joint, float time ) const; 37 | 38 | public: 39 | 40 | float GetDuration( void ) const { return duration_; } 41 | 42 | private: 43 | 44 | bool ParseCollada( ByteSpan data ); 45 | 46 | private: 47 | 48 | std::map< std::string, std::vector< KeyFrame > > joint_key_frames_; 49 | 50 | float duration_; 51 | 52 | }; 53 | 54 | ORB_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Animation/Joint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Graphics.h" 20 | #include "Orbit/Math/Matrix/Matrix4.h" 21 | 22 | #include 23 | #include 24 | 25 | ORB_NAMESPACE_BEGIN 26 | 27 | struct Joint 28 | { 29 | std::vector< Joint > children; 30 | 31 | std::string name; 32 | 33 | Matrix4 inverse_bind_transform; 34 | 35 | int id; 36 | }; 37 | 38 | ORB_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Animation/KeyFrame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Graphics.h" 20 | 21 | #include "Orbit/Math/Matrix/Matrix4.h" 22 | 23 | #include 24 | 25 | ORB_NAMESPACE_BEGIN 26 | 27 | struct KeyFrame 28 | { 29 | std::string interpolation_type; 30 | 31 | Matrix4 transform; 32 | 33 | float time; 34 | }; 35 | 36 | ORB_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Buffer/FrameBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Event/EventSubscription.h" 20 | #include "Orbit/Graphics/Private/FrameBufferDetails.h" 21 | #include "Orbit/Graphics/Texture/Texture2D.h" 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | class ORB_API_GRAPHICS FrameBuffer 26 | { 27 | public: 28 | 29 | FrameBuffer( void ); 30 | ~FrameBuffer( void ); 31 | 32 | public: 33 | 34 | void Clear ( void ); 35 | void Bind ( void ); 36 | void Unbind( void ); 37 | 38 | public: 39 | 40 | Texture2D& GetTexture2D( void ) { return texture2d_; } 41 | 42 | private: 43 | 44 | void Resize( uint32_t width, uint32_t height ); 45 | 46 | private: 47 | 48 | Private::FrameBufferDetails framebuffer_details_; 49 | Texture2D texture2d_; 50 | EventSubscription on_resize_; 51 | 52 | }; 53 | 54 | ORB_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Context/RenderContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Singleton.h" 20 | #include "Orbit/Core/Widget/Window.h" 21 | #include "Orbit/Graphics/Private/RenderContextDetails.h" 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | class ORB_API_GRAPHICS RenderContext : public ManualSingleton< RenderContext > 26 | { 27 | public: 28 | 29 | explicit RenderContext( GraphicsAPI api = default_graphics_api ); 30 | ~RenderContext( void ); 31 | 32 | public: 33 | 34 | bool MakeCurrent ( void ); 35 | void Resize ( uint32_t width, uint32_t height ); 36 | void SwapBuffers ( void ); 37 | void Clear ( BufferMask mask ); 38 | void SetClearColor( float r, float g, float b ); 39 | 40 | public: 41 | 42 | Private::RenderContextDetails& GetPrivateDetails( void ) { return details_; } 43 | const Private::RenderContextDetails& GetPrivateDetails( void ) const { return details_; } 44 | 45 | private: 46 | 47 | Private::RenderContextDetails details_; 48 | EventSubscription window_resized_; 49 | EventSubscription window_state_changed_; 50 | 51 | }; 52 | 53 | ORB_NAMESPACE_END 54 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Geometry/Face.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Graphics.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | struct Face 26 | { 27 | std::array< size_t, 3 > indices{ 0, 0, 0 }; 28 | }; 29 | 30 | ORB_NAMESPACE_END 31 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Geometry/FaceRange.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "FaceRange.h" 19 | 20 | #include "Orbit/Graphics/Geometry/Geometry.h" 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | FaceRange::Iterator& FaceRange::Iterator::operator++( void ) 25 | { 26 | ++index; 27 | 28 | return *this; 29 | } 30 | 31 | Face FaceRange::Iterator::operator*( void ) const 32 | { 33 | return range->geometry_->GetFace( index ); 34 | } 35 | 36 | bool FaceRange::Iterator::operator!=( const Iterator& other ) const 37 | { 38 | return ( ( range != other.range ) || ( index != other.index ) ); 39 | } 40 | 41 | FaceRange::FaceRange( const Geometry* geometry ) 42 | : geometry_( geometry ) 43 | { 44 | } 45 | 46 | FaceRange::Iterator FaceRange::begin( void ) const 47 | { 48 | return Iterator{ this, 0 }; 49 | } 50 | 51 | FaceRange::Iterator FaceRange::end( void ) const 52 | { 53 | return Iterator{ this, geometry_->GetFaceCount() }; 54 | } 55 | 56 | ORB_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Geometry/FaceRange.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Geometry/Face.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class Geometry; 24 | 25 | class ORB_API_GRAPHICS FaceRange 26 | { 27 | ORB_DISABLE_COPY( FaceRange ); 28 | 29 | public: 30 | 31 | struct Iterator 32 | { 33 | Iterator& operator++( void ); 34 | Face operator* ( void ) const; 35 | bool operator!=( const Iterator& other ) const; 36 | 37 | const FaceRange* range; 38 | 39 | size_t index; 40 | }; 41 | 42 | public: 43 | 44 | explicit FaceRange( const Geometry* geometry ); 45 | 46 | public: 47 | 48 | Iterator begin( void ) const; 49 | Iterator end ( void ) const; 50 | 51 | private: 52 | 53 | const Geometry* geometry_; 54 | 55 | }; 56 | 57 | ORB_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Geometry/Model.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Span.h" 20 | #include "Orbit/Graphics/Animation/Joint.h" 21 | #include "Orbit/Graphics/Buffer/IndexBuffer.h" 22 | #include "Orbit/Graphics/Buffer/VertexBuffer.h" 23 | #include "Orbit/Graphics/Geometry/Mesh.h" 24 | #include "Orbit/Graphics/Geometry/VertexLayout.h" 25 | #include "Orbit/Graphics/Renderer/RenderCommand.h" 26 | 27 | ORB_NAMESPACE_BEGIN 28 | 29 | class ORB_API_GRAPHICS Model 30 | { 31 | ORB_DISABLE_COPY( Model ); 32 | 33 | public: 34 | 35 | explicit Model( ByteSpan data, const VertexLayout& layout ); 36 | 37 | public: 38 | 39 | bool HasJoints ( void ) const { return root_joint_ != nullptr; } 40 | const Joint& GetRootJoint( void ) const { return *root_joint_; } 41 | 42 | public: 43 | 44 | auto begin( void ) const { return meshes_.begin(); } 45 | auto end ( void ) const { return meshes_.end(); } 46 | 47 | private: 48 | 49 | bool ParseCollada( ByteSpan data, const VertexLayout& layout ); 50 | bool ParseOBJ ( ByteSpan data, const VertexLayout& layout ); 51 | 52 | private: 53 | 54 | std::vector< Mesh > meshes_; 55 | 56 | std::unique_ptr< Joint > root_joint_; 57 | 58 | }; 59 | 60 | ORB_NAMESPACE_END 61 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Geometry/Vertex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Color.h" 20 | #include "Orbit/Graphics/Graphics.h" 21 | #include "Orbit/Math/Vector/Vector2.h" 22 | #include "Orbit/Math/Vector/Vector3.h" 23 | #include "Orbit/Math/Vector/Vector4.h" 24 | 25 | #include 26 | 27 | ORB_NAMESPACE_BEGIN 28 | 29 | struct Vertex 30 | { 31 | Vector4 position { 0.0f, 0.0f, 0.0f, 1.0f }; 32 | Vector3 normal { 0.0f, 0.0f, 1.0f }; 33 | Color color { 1.0f, 1.0f, 1.0f, 1.0f }; 34 | Vector2 tex_coord{ 0.0f, 0.0f }; 35 | std::array< int, 4 > joint_ids{ 0, 0, 0, 0 }; 36 | std::array< float, 4 > weights { 1.0f, 0.0f, 0.0f, 0.0f }; 37 | 38 | }; 39 | 40 | ORB_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Geometry/VertexRange.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "VertexRange.h" 19 | 20 | #include "Orbit/Graphics/Geometry/Geometry.h" 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | VertexRange::Iterator& VertexRange::Iterator::operator++( void ) 25 | { 26 | ++index; 27 | 28 | return *this; 29 | } 30 | 31 | Vertex VertexRange::Iterator::operator*( void ) const 32 | { 33 | return range->geometry_->GetVertex( index ); 34 | } 35 | 36 | bool VertexRange::Iterator::operator!=( const Iterator& other ) const 37 | { 38 | return ( ( range != other.range ) || ( index != other.index ) ); 39 | } 40 | 41 | VertexRange::VertexRange( const Geometry* geometry ) 42 | : geometry_( geometry ) 43 | { 44 | } 45 | 46 | VertexRange::Iterator VertexRange::begin( void ) const 47 | { 48 | return Iterator{ this, 0 }; 49 | } 50 | 51 | VertexRange::Iterator VertexRange::end( void ) const 52 | { 53 | return Iterator{ this, geometry_->GetVertexCount() }; 54 | } 55 | 56 | ORB_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Geometry/VertexRange.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Geometry/Vertex.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class Geometry; 24 | 25 | class ORB_API_GRAPHICS VertexRange 26 | { 27 | ORB_DISABLE_COPY( VertexRange ); 28 | 29 | public: 30 | 31 | struct Iterator 32 | { 33 | Iterator& operator++( void ); 34 | Vertex operator* ( void ) const; 35 | bool operator!=( const Iterator& other ) const; 36 | 37 | const VertexRange* range; 38 | 39 | size_t index; 40 | }; 41 | 42 | public: 43 | 44 | explicit VertexRange( const Geometry* geometry ); 45 | 46 | public: 47 | 48 | Iterator begin( void ) const; 49 | Iterator end ( void ) const; 50 | 51 | private: 52 | 53 | const Geometry* geometry_; 54 | 55 | }; 56 | 57 | ORB_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Platform/iOS/GLKViewDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Graphics.h" 20 | 21 | #if defined( ORB_OS_IOS ) 22 | # include 23 | 24 | @interface ORB_NAMESPACED_OBJC( GLKViewDelegate ) : UIResponder< GLKViewDelegate > 25 | { 26 | } 27 | @end 28 | 29 | #endif // ORB_OS_IOS 30 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Platform/iOS/GLKViewDelegate.mm: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "GLKViewDelegate.h" 19 | 20 | #if defined( ORB_OS_IOS ) 21 | 22 | @implementation ORB_NAMESPACED_OBJC( GLKViewDelegate ) 23 | 24 | -( void )glkView:( nonnull GLKView* )view drawInRect:( CGRect )rect 25 | { 26 | /* Unused parameters */ 27 | ( void )view; 28 | ( void )rect; 29 | } 30 | 31 | @end 32 | 33 | #endif // ORB_OS_IOS 34 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Private/ConstantBufferDetails.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Platform/Windows/ComPtr.h" 20 | #include "Orbit/Graphics/Graphics.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | namespace Private 27 | { 28 | 29 | #if( ORB_HAS_OPENGL ) 30 | 31 | struct _ConstantBufferDetailsOpenGL20 32 | { 33 | }; 34 | 35 | struct _ConstantBufferDetailsOpenGL31 36 | { 37 | GLuint id; 38 | }; 39 | 40 | #endif // ORB_HAS_OPENGL 41 | #if( ORB_HAS_D3D11 ) 42 | 43 | struct _ConstantBufferDetailsD3D11 44 | { 45 | ComPtr< ID3D11Buffer > buffer; 46 | }; 47 | 48 | #endif // ORB_HAS_D3D11 49 | 50 | using ConstantBufferDetails = std::variant< std::monostate 51 | #if( ORB_HAS_OPENGL ) 52 | , _ConstantBufferDetailsOpenGL20 53 | , _ConstantBufferDetailsOpenGL31 54 | #endif // ORB_HAS_OPENGL 55 | #if( ORB_HAS_D3D11 ) 56 | , _ConstantBufferDetailsD3D11 57 | #endif // ORB_HAS_D3D11 58 | >; 59 | } 60 | 61 | ORB_NAMESPACE_END 62 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Private/FrameBufferDetails.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Platform/Windows/ComPtr.h" 20 | #include "Orbit/Graphics/Graphics.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | namespace Private 27 | { 28 | 29 | #if( ORB_HAS_OPENGL ) 30 | 31 | struct _FrameBufferDetailsOpenGL 32 | { 33 | GLuint fbo; 34 | GLuint rbo; 35 | }; 36 | 37 | #endif // ORB_HAS_OPENGL 38 | #if( ORB_HAS_D3D11 ) 39 | 40 | struct _FrameBufferDetailsD3D11 41 | { 42 | ComPtr< ID3D11RenderTargetView > render_target_view; 43 | }; 44 | 45 | #endif // ORB_HAS_D3D11 46 | 47 | using FrameBufferDetails = std::variant< std::monostate 48 | #if( ORB_HAS_OPENGL ) 49 | , _FrameBufferDetailsOpenGL 50 | #endif // ORB_HAS_OPENGL 51 | #if( ORB_HAS_D3D11 ) 52 | , _FrameBufferDetailsD3D11 53 | #endif // ORB_HAS_D3D11 54 | >; 55 | } 56 | 57 | ORB_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Private/IndexBufferDetails.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Platform/Windows/ComPtr.h" 20 | #include "Orbit/Graphics/Graphics.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | namespace Private 27 | { 28 | 29 | #if( ORB_HAS_OPENGL ) 30 | 31 | struct _IndexBufferDetailsOpenGL 32 | { 33 | GLuint id; 34 | }; 35 | 36 | #endif // ORB_HAS_OPENGL 37 | #if( ORB_HAS_D3D11 ) 38 | 39 | struct _IndexBufferDetailsD3D11 40 | { 41 | ComPtr< ID3D11Buffer > buffer; 42 | }; 43 | 44 | #endif // ORB_HAS_D3D11 45 | 46 | using IndexBufferDetails = std::variant< std::monostate 47 | #if( ORB_HAS_OPENGL ) 48 | , _IndexBufferDetailsOpenGL 49 | #endif // ORB_HAS_OPENGL 50 | #if( ORB_HAS_D3D11 ) 51 | , _IndexBufferDetailsD3D11 52 | #endif // ORB_HAS_D3D11 53 | >; 54 | } 55 | 56 | ORB_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Private/Texture2DDetails.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Platform/Windows/ComPtr.h" 20 | #include "Orbit/Graphics/Graphics.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | namespace Private 27 | { 28 | 29 | #if( ORB_HAS_OPENGL ) 30 | 31 | struct _Texture2DDetailsOpenGL 32 | { 33 | GLuint id; 34 | }; 35 | 36 | #endif // ORB_HAS_OPENGL 37 | #if( ORB_HAS_D3D11 ) 38 | 39 | struct _Texture2DDetailsD3D11 40 | { 41 | ComPtr< ID3D11Texture2D > texture2d; 42 | ComPtr< ID3D11ShaderResourceView > shader_resource_view; 43 | }; 44 | 45 | #endif // ORB_HAS_D3D11 46 | 47 | using Texture2DDetails = std::variant< std::monostate 48 | #if( ORB_HAS_OPENGL ) 49 | , _Texture2DDetailsOpenGL 50 | #endif // ORB_HAS_OPENGL 51 | #if( ORB_HAS_D3D11 ) 52 | , _Texture2DDetailsD3D11 53 | #endif // ORB_HAS_D3D11 54 | >; 55 | } 56 | 57 | ORB_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Private/VertexBufferDetails.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Platform/Windows/ComPtr.h" 20 | #include "Orbit/Graphics/Graphics.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | namespace Private 27 | { 28 | 29 | #if( ORB_HAS_OPENGL ) 30 | 31 | struct _VertexBufferDetailsOpenGL 32 | { 33 | GLuint id; 34 | }; 35 | 36 | #endif // ORB_HAS_OPENGL 37 | #if( ORB_HAS_D3D11 ) 38 | 39 | struct _VertexBufferDetailsD3D11 40 | { 41 | ComPtr< ID3D11Buffer > buffer; 42 | }; 43 | 44 | #endif // ORB_HAS_D3D11 45 | 46 | using VertexBufferDetails = std::variant< std::monostate 47 | #if( ORB_HAS_OPENGL ) 48 | , _VertexBufferDetailsOpenGL 49 | #endif // ORB_HAS_OPENGL 50 | #if( ORB_HAS_D3D11 ) 51 | , _VertexBufferDetailsD3D11 52 | #endif // ORB_HAS_D3D11 53 | >; 54 | } 55 | 56 | ORB_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Renderer/DefaultRenderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Singleton.h" 20 | #include "Orbit/Graphics/Renderer/IRenderer.h" 21 | #include "Orbit/Graphics/Renderer/RenderCommand.h" 22 | 23 | #include 24 | 25 | ORB_NAMESPACE_BEGIN 26 | 27 | class ORB_API_GRAPHICS DefaultRenderer : public IRenderer, public Singleton< DefaultRenderer > 28 | { 29 | public: 30 | 31 | void Render( void ) override; 32 | 33 | }; 34 | 35 | ORB_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Renderer/IRenderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Graphics.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | struct RenderCommand; 26 | 27 | class ORB_API_GRAPHICS IRenderer 28 | { 29 | public: 30 | 31 | virtual ~IRenderer( void ) = default; 32 | 33 | public: 34 | 35 | void PushCommand( RenderCommand command ); 36 | void Flush ( void ); 37 | 38 | public: 39 | 40 | virtual void Render( void ) = 0; 41 | 42 | protected: 43 | 44 | void APIDraw( const RenderCommand& command ); 45 | 46 | protected: 47 | 48 | std::vector< RenderCommand > commands_; 49 | 50 | }; 51 | 52 | ORB_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Renderer/RenderCommand.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Ref.h" 20 | #include "Orbit/Graphics/Renderer/BlendEquation.h" 21 | 22 | #include 23 | #include 24 | 25 | ORB_NAMESPACE_BEGIN 26 | 27 | class ConstantBuffer; 28 | class FrameBuffer; 29 | class IndexBuffer; 30 | class Shader; 31 | class Texture2D; 32 | class VertexBuffer; 33 | 34 | struct ORB_API_GRAPHICS RenderCommand 35 | { 36 | std::vector< Ref< Texture2D > > textures; 37 | 38 | Ref< VertexBuffer > vertex_buffer; 39 | Ref< IndexBuffer > index_buffer; 40 | Ref< Shader > shader; 41 | Ref< FrameBuffer > frame_buffer; 42 | 43 | Topology topology = Topology::Triangles; 44 | BlendEquation blend_equation = BlendFactor::SourceAlpha + BlendFactor::InvSourceAlpha; 45 | 46 | bool blend_enabled = true; 47 | }; 48 | 49 | ORB_NAMESPACE_END 50 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Shader/ShaderConstant.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Graphics.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | enum class ShaderConstantType 26 | { 27 | Float, 28 | Vec2, 29 | Vec3, 30 | Vec4, 31 | Mat4, 32 | }; 33 | 34 | struct ORB_API_GRAPHICS ShaderConstant 35 | { 36 | std::string name; 37 | ShaderConstantType type; 38 | }; 39 | 40 | ORB_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Texture/Texture.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Texture.h" 19 | 20 | #include "Orbit/Core/IO/Parser/TGA/TGAParser.h" 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | Texture::Texture( ByteSpan data ) 25 | { 26 | TGAParser tga_parser( data ); 27 | if( tga_parser.IsGood() ) 28 | { 29 | texture2d_.emplace( tga_parser.Width(), tga_parser.Height(), tga_parser.ImageData(), PixelFormat::RGBA ); 30 | return; 31 | } 32 | } 33 | 34 | ORB_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Texture/Texture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Span.h" 20 | #include "Orbit/Graphics/Texture/Texture2D.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | class ORB_API_GRAPHICS Texture 27 | { 28 | public: 29 | 30 | explicit Texture( ByteSpan data ); 31 | 32 | public: 33 | 34 | 35 | Texture2D& GetTexture2D( void ) { return texture2d_.value(); } 36 | 37 | private: 38 | 39 | std::optional< Texture2D > texture2d_; 40 | 41 | }; 42 | 43 | ORB_NAMESPACE_END 44 | -------------------------------------------------------------------------------- /src/Orbit/Graphics/Texture/Texture2D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Private/Texture2DDetails.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class ORB_API_GRAPHICS Texture2D 24 | { 25 | public: 26 | 27 | Texture2D( void ); 28 | Texture2D( uint32_t width, uint32_t height, const void* data, PixelFormat pixel_format ); 29 | ~Texture2D(); 30 | 31 | public: 32 | 33 | void Bind ( uint32_t slot ); 34 | void Unbind( uint32_t slot ); 35 | 36 | public: 37 | 38 | Private::Texture2DDetails& GetPrivateDetails( void ) { return details_; } 39 | const Private::Texture2DDetails& GetPrivateDetails( void ) const { return details_; } 40 | 41 | private: 42 | 43 | Private::Texture2DDetails details_; 44 | 45 | }; 46 | 47 | ORB_NAMESPACE_END 48 | -------------------------------------------------------------------------------- /src/Orbit/Math/Geometry/Line.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Line.h" 19 | 20 | ORB_NAMESPACE_BEGIN 21 | 22 | Line::Line( void ) 23 | : direction ( 0.0f, 0.0f, 1.0f ) 24 | , displacement( 0.0f, 0.0f ) 25 | { 26 | } 27 | 28 | Line::Line( const Vector3& direction, const Vector2& displacement ) 29 | : direction ( direction ) 30 | , displacement( displacement ) 31 | { 32 | } 33 | 34 | ORB_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/Orbit/Math/Geometry/Line.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Math/Vector/Vector2.h" 20 | #include "Orbit/Math/Vector/Vector3.h" 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | class ORB_API_MATH Line 25 | { 26 | public: 27 | 28 | Line( void ); 29 | Line( const Vector3& direction, const Vector2& displacement ); 30 | 31 | public: 32 | 33 | Vector3 direction; 34 | Vector2 displacement; 35 | 36 | }; 37 | 38 | ORB_NAMESPACE_END 39 | -------------------------------------------------------------------------------- /src/Orbit/Math/Geometry/LineSegment.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "LineSegment.h" 19 | 20 | ORB_NAMESPACE_BEGIN 21 | 22 | LineSegment::LineSegment( const Vector3& start, const Vector3& end ) 23 | : start( start ) 24 | , end ( end ) 25 | { 26 | } 27 | 28 | Vector3 LineSegment::PointAt( float fraction ) const 29 | { 30 | return ( start + ( ( end - start ) * fraction ) ); 31 | } 32 | 33 | Vector3 LineSegment::Center( void ) const 34 | { 35 | return PointAt( 0.5f ); 36 | } 37 | 38 | Vector3 LineSegment::Direction( void ) const 39 | { 40 | return ( end - start ).Normalized(); 41 | } 42 | 43 | float LineSegment::Length( void ) const 44 | { 45 | return ( end - start ).Length(); 46 | } 47 | 48 | float LineSegment::LengthSquared( void ) const 49 | { 50 | return ( end - start ).DotProduct(); 51 | } 52 | 53 | ORB_NAMESPACE_END 54 | -------------------------------------------------------------------------------- /src/Orbit/Math/Geometry/LineSegment.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Math/Vector/Vector3.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class ORB_API_MATH LineSegment 24 | { 25 | public: 26 | 27 | LineSegment( void ) = default; 28 | LineSegment( const Vector3& start, const Vector3& end ); 29 | 30 | public: 31 | 32 | Vector3 PointAt ( float fraction ) const; 33 | Vector3 Center ( void ) const; 34 | Vector3 Direction ( void ) const; 35 | float Length ( void ) const; 36 | float LengthSquared( void ) const; 37 | 38 | public: 39 | 40 | Vector3 start; 41 | Vector3 end; 42 | 43 | }; 44 | 45 | ORB_NAMESPACE_END 46 | -------------------------------------------------------------------------------- /src/Orbit/Math/Geometry/Plane.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Math/Geometry/Line.h" 20 | #include "Orbit/Math/Geometry/LineSegment.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | class ORB_API_MATH Plane 27 | { 28 | public: 29 | 30 | using PlaneIntersectionResult = std::variant< Plane, Line >; 31 | using LineIntersectionResult = std::variant< Line, Vector3 >; 32 | using LineSegmentIntersectionResult = std::variant< LineSegment, Vector3 >; 33 | 34 | public: 35 | 36 | Plane( void ); 37 | Plane( const Vector3& normal, float displacement ); 38 | 39 | public: 40 | 41 | Vector3 Center ( void ) const; 42 | PlaneIntersectionResult Intersect( const Plane& other ) const; 43 | LineIntersectionResult Intersect( const Line& line ) const; 44 | LineSegmentIntersectionResult Intersect( const LineSegment& line_segment ) const; 45 | 46 | public: 47 | 48 | Vector3 normal; 49 | 50 | float displacement; 51 | 52 | }; 53 | 54 | ORB_NAMESPACE_END 55 | -------------------------------------------------------------------------------- /src/Orbit/Math/Geometry/Triangle3D.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Triangle3D.h" 19 | 20 | ORB_NAMESPACE_BEGIN 21 | 22 | Triangle3D::Triangle3D( Vector3 a, Vector3 b, Vector3 c ) 23 | : a_( a ) 24 | , b_( b ) 25 | , c_( c ) 26 | { 27 | } 28 | 29 | bool Triangle3D::IsClockwiseAround( Vector3 axis ) const 30 | { 31 | const Vector3 cross = ( b_ - a_ ).CrossProduct( c_ - b_ ); 32 | 33 | return std::signbit( cross.DotProduct( axis ) ); 34 | } 35 | 36 | ORB_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /src/Orbit/Math/Geometry/Triangle3D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Math/Vector/Vector3.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class ORB_API_MATH Triangle3D 24 | { 25 | public: 26 | 27 | Triangle3D( void ) = default; 28 | Triangle3D( Vector3 a, Vector3 b, Vector3 c ); 29 | 30 | public: 31 | 32 | bool IsClockwiseAround( Vector3 axis ) const; 33 | 34 | public: 35 | 36 | Vector3 a_; 37 | Vector3 b_; 38 | Vector3 c_; 39 | 40 | }; 41 | 42 | ORB_NAMESPACE_END 43 | -------------------------------------------------------------------------------- /src/Orbit/Math/Math.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Orbit.h" 20 | 21 | #if defined( ORB_BUILD_MATH ) 22 | # define ORB_API_MATH ORB_DLL_EXPORT 23 | #else // ORB_BUILD_MATH 24 | # define ORB_API_MATH ORB_DLL_IMPORT 25 | #endif // !ORB_BUILD_MATH 26 | 27 | ORB_NAMESPACE_BEGIN 28 | 29 | constexpr float Pi = 3.141592741f; 30 | constexpr float E = 2.718281746f; 31 | constexpr float PythagorasConstant = 1.414213538f; 32 | constexpr float GoldenRatio = 1.618034005f; 33 | 34 | ORB_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/Orbit/Math/Vector/Vector2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Vector2.h" 19 | 20 | #include "Orbit/Math/Vector/Vector3.h" 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | Vector2::Vector2( void ) 25 | : x{ 0.0f } 26 | , y{ 0.0f } 27 | { 28 | } 29 | 30 | Vector2::Vector2( float scalar ) 31 | : x{ scalar } 32 | , y{ scalar } 33 | { 34 | } 35 | 36 | Vector2::Vector2( float x, float y ) 37 | : x{ x } 38 | , y{ y } 39 | { 40 | } 41 | 42 | Vector2::Vector2( const Vector3& vec ) 43 | : x{ vec.x } 44 | , y{ vec.y } 45 | { 46 | } 47 | 48 | ORB_NAMESPACE_END 49 | -------------------------------------------------------------------------------- /src/Orbit/Math/Vector/Vector2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Math/Vector/VectorBase.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class Vector3; 24 | 25 | class ORB_API_MATH Vector2 final : public VectorBase< Vector2, 2 > 26 | { 27 | public: 28 | 29 | Vector2 ( void ); 30 | explicit Vector2( float scalar ); 31 | Vector2 ( float x, float y ); 32 | explicit Vector2( const Vector3& vec ); 33 | 34 | public: 35 | 36 | float x; 37 | float y; 38 | 39 | }; 40 | 41 | ORB_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /src/Orbit/Math/Vector/Vector3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Vector3.h" 19 | 20 | #include "Orbit/Math/Vector/Vector4.h" 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | Vector3::Vector3( void ) 25 | : x{ 0.0f } 26 | , y{ 0.0f } 27 | , z{ 0.0f } 28 | { 29 | } 30 | 31 | Vector3::Vector3( float scalar ) 32 | : x{ scalar } 33 | , y{ scalar } 34 | , z{ scalar } 35 | { 36 | } 37 | 38 | Vector3::Vector3( float x, float y, float z ) 39 | : x{ x } 40 | , y{ y } 41 | , z{ z } 42 | { 43 | } 44 | 45 | Vector3::Vector3( const Vector4& vec ) 46 | : x{ vec.x } 47 | , y{ vec.y } 48 | , z{ vec.z } 49 | { 50 | } 51 | 52 | Vector3 Vector3::CrossProduct( const Vector3& v ) const 53 | { 54 | return Vector3( ( y * v.z ) - ( z * v.y ), 55 | ( z * v.x ) - ( x * v.z ), 56 | ( x * v.y ) - ( y * v.x ) 57 | ); 58 | } 59 | 60 | ORB_NAMESPACE_END 61 | -------------------------------------------------------------------------------- /src/Orbit/Math/Vector/Vector3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Math/Vector/VectorBase.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class Vector4; 24 | 25 | class ORB_API_MATH Vector3 final : public VectorBase< Vector3, 3 > 26 | { 27 | public: 28 | 29 | Vector3 ( void ); 30 | explicit Vector3( float scalar ); 31 | Vector3 ( float x, float y, float z ); 32 | explicit Vector3( const Vector4& vec ); 33 | 34 | public: 35 | 36 | Vector3 CrossProduct( const Vector3& v ) const; 37 | 38 | public: 39 | 40 | float x; 41 | float y; 42 | float z; 43 | 44 | }; 45 | 46 | ORB_NAMESPACE_END 47 | -------------------------------------------------------------------------------- /src/Orbit/Math/Vector/Vector4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Math/Vector/VectorBase.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | class Vector2; 24 | class Vector3; 25 | 26 | class ORB_API_MATH Vector4 final : public VectorBase< Vector4, 4 > 27 | { 28 | public: 29 | 30 | Vector4 ( void ); 31 | explicit Vector4( float scalar ); 32 | Vector4 ( const Vector3& xyz, float w ); 33 | Vector4 ( const Vector2& xy, const Vector2& zw ); 34 | Vector4 ( const Vector2& xy, float z, float w ); 35 | Vector4 ( float x, const Vector3& yzw ); 36 | Vector4 ( float x, const Vector2& yz, float w ); 37 | Vector4 ( float x, float y, const Vector2& zw ); 38 | Vector4 ( float x, float y, float z, float w ); 39 | 40 | public: 41 | 42 | float x; 43 | float y; 44 | float z; 45 | float w; 46 | 47 | }; 48 | 49 | ORB_NAMESPACE_END 50 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Generator/MainFunction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Graphics.h" 20 | 21 | #include 22 | 23 | ORB_NAMESPACE_BEGIN 24 | 25 | namespace ShaderGen 26 | { 27 | class IShader; 28 | 29 | struct MainFunction 30 | { 31 | std::ostringstream code; 32 | 33 | ShaderType shader_type; 34 | ShaderLanguage shader_language; 35 | 36 | uint32_t locals_count = 0; 37 | }; 38 | } 39 | 40 | ORB_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Generator/ShaderManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Core/Utility/Singleton.h" 20 | #include "Orbit/Graphics/Geometry/VertexLayout.h" 21 | #include "Orbit/ShaderGen/Variables/DataType.h" 22 | #include "Orbit/ShaderGen/ShaderGen.h" 23 | 24 | #include 25 | #include 26 | 27 | ORB_NAMESPACE_BEGIN 28 | 29 | namespace ShaderGen 30 | { 31 | class UniformBase; 32 | struct MainFunction; 33 | 34 | class ORB_API_SHADERGEN ShaderManager : public Singleton< ShaderManager > 35 | { 36 | friend class IShader; 37 | 38 | public: 39 | 40 | std::ostringstream& Append ( void ) const; 41 | std::string NewLocal ( DataType type, std::string_view code ) const; 42 | std::string NewAttribute( VertexComponent component ) const; 43 | std::string NewVarying ( VertexComponent component ) const; 44 | std::string NewSampler ( void ) const; 45 | std::string NewUniform ( UniformBase* uniform ) const; 46 | ShaderLanguage GetLanguage ( void ) const; 47 | ShaderType GetType ( void ) const; 48 | 49 | private: 50 | 51 | IShader* current_shader_; 52 | MainFunction* current_main_function_; 53 | 54 | }; 55 | } 56 | 57 | ORB_NAMESPACE_END 58 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/ShaderGen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Orbit.h" 20 | 21 | #if defined( ORB_BUILD_SHADERGEN ) 22 | # define ORB_API_SHADERGEN ORB_DLL_EXPORT 23 | #else // ORB_BUILD_SHADERGEN 24 | # define ORB_API_SHADERGEN ORB_DLL_IMPORT 25 | #endif // !ORB_BUILD_SHADERGEN 26 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Attribute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Attribute.h" 19 | 20 | #include "Orbit/ShaderGen/Generator/IShader.h" 21 | #include "Orbit/ShaderGen/Generator/MainFunction.h" 22 | #include "Orbit/ShaderGen/Generator/ShaderManager.h" 23 | 24 | #include 25 | #include 26 | 27 | ORB_NAMESPACE_BEGIN 28 | 29 | namespace ShaderGen 30 | { 31 | Attribute::Attribute( VertexComponent component ) 32 | : Variable( ShaderManager::GetInstance().NewAttribute( component ), DataTypeFromVertexComponent( component ) ) 33 | { 34 | stored_ = true; 35 | } 36 | 37 | std::string Attribute::GetValueDerived( void ) const 38 | { 39 | if( ShaderManager::GetInstance().GetLanguage() == ShaderLanguage::HLSL ) 40 | { 41 | switch( ShaderManager::GetInstance().GetType() ) 42 | { 43 | case ShaderType::Vertex: { return "input." + value_; } 44 | default: { assert( false ); } break; 45 | } 46 | } 47 | 48 | return value_; 49 | } 50 | } 51 | 52 | ORB_NAMESPACE_END 53 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Attribute.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Geometry/VertexLayout.h" 20 | #include "Orbit/ShaderGen/Variables/Variable.h" 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | namespace ShaderGen 25 | { 26 | template< VertexComponent VC > 27 | class AttributeHelper; 28 | 29 | class ORB_API_SHADERGEN Attribute : public Variable 30 | { 31 | public: 32 | 33 | using Position = AttributeHelper< VertexComponent::Position >; 34 | using Normal = AttributeHelper< VertexComponent::Normal >; 35 | using Color = AttributeHelper< VertexComponent::Color >; 36 | using TexCoord = AttributeHelper< VertexComponent::TexCoord >; 37 | using JointIDs = AttributeHelper< VertexComponent::JointIDs >; 38 | using Weights = AttributeHelper< VertexComponent::Weights >; 39 | using Variable::operator=; 40 | 41 | public: 42 | 43 | Attribute( VertexComponent component ); 44 | 45 | private: 46 | 47 | std::string GetValueDerived( void ) const override; 48 | 49 | }; 50 | 51 | template< VertexComponent VC > 52 | class AttributeHelper : public Attribute 53 | { 54 | public: 55 | 56 | AttributeHelper( void ) 57 | : Attribute( VC ) 58 | { 59 | } 60 | 61 | }; 62 | } 63 | 64 | ORB_NAMESPACE_END 65 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Float.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Float.h" 19 | 20 | #include "Orbit/ShaderGen/Generator/IShader.h" 21 | 22 | #include 23 | 24 | ORB_NAMESPACE_BEGIN 25 | 26 | namespace ShaderGen 27 | { 28 | Float::Float( const Variable& f ) 29 | : Variable( "float( " + f.GetValue() + " )", DataType::Float ) 30 | { 31 | assert( ( f.GetDataType() == DataType::Float ) || ( f.GetDataType() == DataType::Int ) ); 32 | } 33 | 34 | Float::Float( double f ) 35 | : Variable( f ) 36 | { 37 | } 38 | } 39 | 40 | ORB_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Float.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/ShaderGen/Variables/Variable.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | namespace ShaderGen 24 | { 25 | class ORB_API_SHADERGEN Float : public Variable 26 | { 27 | public: 28 | 29 | Float( const Variable& f ); 30 | Float( double f ); 31 | 32 | }; 33 | } 34 | 35 | ORB_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Mat4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Mat4.h" 19 | 20 | #include 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | namespace ShaderGen 25 | { 26 | Mat4::Mat4( const Variable& value ) 27 | : Variable( "mat4( " + value.GetValue() + " )", DataType::Mat4 ) 28 | { 29 | assert( value.GetDataType() == DataType::Mat4 ); 30 | } 31 | } 32 | 33 | ORB_NAMESPACE_END 34 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Mat4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/ShaderGen/Variables/Variable.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | namespace ShaderGen 24 | { 25 | class ORB_API_SHADERGEN Mat4 : public Variable 26 | { 27 | public: 28 | 29 | Mat4( const Variable& value ); 30 | 31 | }; 32 | } 33 | 34 | ORB_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Sampler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Sampler.h" 19 | 20 | #include "Orbit/ShaderGen/Generator/IShader.h" 21 | #include "Orbit/ShaderGen/Generator/ShaderManager.h" 22 | 23 | #include 24 | 25 | ORB_NAMESPACE_BEGIN 26 | 27 | namespace ShaderGen 28 | { 29 | Sampler::Sampler( void ) 30 | : Variable( ShaderManager::GetInstance().NewSampler(), DataType::Unknown ) 31 | { 32 | stored_ = true; 33 | } 34 | } 35 | 36 | ORB_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Sampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/ShaderGen/Variables/Variable.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | namespace ShaderGen 24 | { 25 | class ORB_API_SHADERGEN Sampler : public Variable 26 | { 27 | public: 28 | 29 | Sampler( void ); 30 | 31 | }; 32 | } 33 | 34 | ORB_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Swizzle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Swizzle.h" 19 | 20 | ORB_NAMESPACE_BEGIN 21 | 22 | namespace ShaderGen 23 | { 24 | Variable* variable_to_be_swizzled = nullptr; 25 | } 26 | 27 | ORB_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Uniform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Uniform.h" 19 | 20 | #include "Orbit/ShaderGen/Generator/IShader.h" 21 | #include "Orbit/ShaderGen/Generator/ShaderManager.h" 22 | 23 | #include 24 | #include 25 | 26 | ORB_NAMESPACE_BEGIN 27 | 28 | namespace ShaderGen 29 | { 30 | UniformBase::UniformBase( DataType type ) 31 | : Variable( ShaderManager::GetInstance().NewUniform( this ), type ) 32 | { 33 | stored_ = true; 34 | } 35 | 36 | std::string_view UniformBase::GetName( void ) const 37 | { 38 | // Uniforms are always stored which means @value_ will always contain the variable name 39 | return value_; 40 | } 41 | 42 | UniformArrayBase::UniformArrayBase( DataType element_type ) 43 | : UniformBase ( DataType::Array ) 44 | , element_type_( element_type ) 45 | { 46 | } 47 | 48 | Variable UniformArrayBase::operator[]( const Variable& index ) const 49 | { 50 | assert( index.GetDataType() == DataType::Int ); 51 | 52 | return Variable( GetValue() + "[ " + index.GetValue() + " ]", element_type_ ); 53 | } 54 | } 55 | 56 | ORB_NAMESPACE_END 57 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Varying.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Varying.h" 19 | 20 | #include "Orbit/ShaderGen/Generator/IShader.h" 21 | #include "Orbit/ShaderGen/Generator/MainFunction.h" 22 | #include "Orbit/ShaderGen/Generator/ShaderManager.h" 23 | 24 | #include 25 | #include 26 | 27 | ORB_NAMESPACE_BEGIN 28 | 29 | namespace ShaderGen 30 | { 31 | Varying::Varying( VertexComponent component ) 32 | : Variable( ShaderManager::GetInstance().NewVarying( component ), DataTypeFromVertexComponent( component ) ) 33 | { 34 | stored_ = true; 35 | } 36 | 37 | std::string Varying::GetValueDerived( void ) const 38 | { 39 | if( ShaderManager::GetInstance().GetLanguage() == ShaderLanguage::HLSL ) 40 | { 41 | switch( ShaderManager::GetInstance().GetType() ) 42 | { 43 | case ShaderType::Vertex: { return "output." + value_; } 44 | case ShaderType::Fragment: { return "input." + value_; } 45 | default: { assert( false ); } break; 46 | } 47 | } 48 | 49 | return value_; 50 | } 51 | } 52 | 53 | ORB_NAMESPACE_END 54 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Varying.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/Graphics/Geometry/VertexLayout.h" 20 | #include "Orbit/ShaderGen/Variables/Variable.h" 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | namespace ShaderGen 25 | { 26 | template< VertexComponent VC > 27 | class VaryingHelper; 28 | 29 | class ORB_API_SHADERGEN Varying : public Variable 30 | { 31 | public: 32 | 33 | using Position = VaryingHelper< VertexComponent::Position >; 34 | using Normal = VaryingHelper< VertexComponent::Normal >; 35 | using Color = VaryingHelper< VertexComponent::Color >; 36 | using TexCoord = VaryingHelper< VertexComponent::TexCoord >; 37 | using Variable::operator=; 38 | 39 | public: 40 | 41 | Varying( VertexComponent component ); 42 | 43 | private: 44 | 45 | std::string GetValueDerived( void ) const override; 46 | 47 | }; 48 | 49 | template< VertexComponent VC > 50 | class VaryingHelper : public Varying 51 | { 52 | public: 53 | 54 | using Varying::operator=; 55 | 56 | public: 57 | 58 | VaryingHelper( void ) 59 | : Varying( VC ) 60 | { 61 | } 62 | 63 | }; 64 | } 65 | 66 | ORB_NAMESPACE_END 67 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Vec2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Vec2.h" 19 | 20 | #include 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | namespace ShaderGen 25 | { 26 | Vec2::Vec2( const Variable& a ) 27 | : Variable( "vec2( " + a.GetValue() + " )", DataType::FVec2 ) 28 | { 29 | assert( a.GetDataType() == DataType::FVec2 ); 30 | } 31 | 32 | Vec2::Vec2( const Variable& a, const Variable& b ) 33 | : Variable( "vec2( " + a.GetValue() + ", " + b.GetValue() + " )", DataType::FVec2 ) 34 | { 35 | assert( ( a.GetDataType() == DataType::Float ) && ( b.GetDataType() == DataType::Float ) ); 36 | } 37 | } 38 | 39 | ORB_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Vec2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/ShaderGen/Variables/Variable.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | namespace ShaderGen 24 | { 25 | class ORB_API_SHADERGEN Vec2 : public Variable 26 | { 27 | public: 28 | 29 | Vec2( const Variable& a ); 30 | Vec2( const Variable& a, const Variable& b ); 31 | 32 | }; 33 | } 34 | 35 | ORB_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Vec3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "Vec3.h" 19 | 20 | #include 21 | 22 | ORB_NAMESPACE_BEGIN 23 | 24 | namespace ShaderGen 25 | { 26 | Vec3::Vec3( const Variable& a ) 27 | : Variable( "vec3( " + a.GetValue() + " )", DataType::FVec3 ) 28 | { 29 | assert( a.GetDataType() == DataType::FVec3 ); 30 | } 31 | 32 | Vec3::Vec3( const Variable& a, const Variable& b ) 33 | : Variable( "vec3( " + a.GetValue() + ", " + b.GetValue() + " )", DataType::FVec3 ) 34 | { 35 | assert( ( ( a.GetDataType() == DataType::FVec2 ) && ( b.GetDataType() == DataType::Float ) ) || 36 | ( ( a.GetDataType() == DataType::Float ) && ( b.GetDataType() == DataType::FVec2 ) ) ); 37 | } 38 | 39 | Vec3::Vec3( const Variable& a, const Variable& b, const Variable& c ) 40 | : Variable( "vec3( " + a.GetValue() + ", " + b.GetValue() + ", " + c.GetValue() + " )", DataType::FVec3 ) 41 | { 42 | assert( ( ( a.GetDataType() == DataType::Float ) && ( b.GetDataType() == DataType::Float ) && ( c.GetDataType() == DataType::Float ) ) ); 43 | } 44 | } 45 | 46 | ORB_NAMESPACE_END 47 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Vec3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/ShaderGen/Variables/Variable.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | namespace ShaderGen 24 | { 25 | class ORB_API_SHADERGEN Vec3 : public Variable 26 | { 27 | public: 28 | 29 | Vec3( const Variable& a ); 30 | Vec3( const Variable& a, const Variable& b ); 31 | Vec3( const Variable& a, const Variable& b, const Variable& c ); 32 | 33 | }; 34 | } 35 | 36 | ORB_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /src/Orbit/ShaderGen/Variables/Vec4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include "Orbit/ShaderGen/Variables/Variable.h" 20 | 21 | ORB_NAMESPACE_BEGIN 22 | 23 | namespace ShaderGen 24 | { 25 | class ORB_API_SHADERGEN Vec4 : public Variable 26 | { 27 | public: 28 | 29 | Vec4( const Variable& a ); 30 | Vec4( const Variable& a, const Variable& b ); 31 | Vec4( const Variable& a, const Variable& b, const Variable& c ); 32 | Vec4( const Variable& a, const Variable& b, const Variable& c, const Variable& d ); 33 | 34 | }; 35 | } 36 | 37 | ORB_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /src/Samples/00-Framework/Framework/Camera.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | namespace Orbit { struct WindowResized; } 26 | 27 | class Camera 28 | { 29 | public: 30 | 31 | Camera( void ); 32 | 33 | public: 34 | 35 | void Update( float delta_time ); 36 | 37 | public: 38 | 39 | Orbit::Matrix4 GetViewProjection( void ) const; 40 | 41 | public: 42 | 43 | float fov = 60.0f; 44 | float near_clip = 0.01f; 45 | float far_clip = 1024.0f; 46 | float speed = 4.0f; 47 | 48 | Orbit::Vector3 position; 49 | Orbit::Vector3 rotation; 50 | 51 | private: 52 | 53 | void OnResized ( const Orbit::WindowResized& e ); 54 | void UpdateView( float delta_time ); 55 | 56 | private: 57 | 58 | Orbit::EventSubscription on_resize_; 59 | 60 | uint32_t width_ = 512; 61 | uint32_t height_ = 512; 62 | 63 | }; 64 | -------------------------------------------------------------------------------- /src/Samples/00-Framework/Framework/RenderQuad.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "RenderQuad.h" 19 | 20 | #include 21 | 22 | #include 23 | 24 | static std::initializer_list< Orbit::Vector4 > vertices 25 | { 26 | { -1.0f, -1.0f, 0.0f, 1.0f }, { 1.0f, -1.0f, 0.0f, 1.0f }, 27 | { -1.0f, 1.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 0.0f, 1.0f }, 28 | }; 29 | 30 | static std::initializer_list< uint16_t > indices 31 | { 32 | 0, 2, 1, 33 | 3, 1, 2, 34 | }; 35 | 36 | RenderQuad::RenderQuad( void ) 37 | : vertex_buffer_( vertices ) 38 | , index_buffer_ ( indices ) 39 | { 40 | } 41 | -------------------------------------------------------------------------------- /src/Samples/00-Framework/Framework/RenderQuad.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | 22 | class RenderQuad 23 | { 24 | public: 25 | 26 | RenderQuad( void ); 27 | 28 | public: 29 | 30 | Orbit::VertexBuffer vertex_buffer_; 31 | Orbit::IndexBuffer index_buffer_; 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /src/Samples/01-Triangle/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Samples/01-Triangle/Android/java/com/gaztin/orbit/samples/triangle/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.gaztin.orbit.samples.triangle; 2 | 3 | import android.app.NativeActivity; 4 | 5 | public class MainActivity extends NativeActivity 6 | { 7 | static 8 | { 9 | System.loadLibrary( "01-Triangle" ); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Samples/01-Triangle/Android/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/01-Triangle/Android/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/01-Triangle/Android/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/01-Triangle/Android/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/01-Triangle/Android/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/01-Triangle/Android/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/01-Triangle/Android/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/01-Triangle/Android/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/01-Triangle/Android/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/01-Triangle/Android/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/01-Triangle/Android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Orbit Triangle 3 | 4 | -------------------------------------------------------------------------------- /src/Samples/01-Triangle/TriangleShader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "TriangleShader.h" 19 | 20 | #include 21 | 22 | TriangleShader::Vec4 TriangleShader::VSMain( void ) 23 | { 24 | v_position = a_position; 25 | v_color = a_color; 26 | v_texcoord = a_texcoord; 27 | 28 | return v_position; 29 | } 30 | 31 | TriangleShader::Vec4 TriangleShader::PSMain( void ) 32 | { 33 | Vec4 tex_color = Sample( diffuse_texture, v_texcoord ); 34 | Vec4 out_color = tex_color * v_color; 35 | 36 | return out_color; 37 | } 38 | -------------------------------------------------------------------------------- /src/Samples/01-Triangle/TriangleShader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | class TriangleShader final : public Orbit::ShaderGen::IShader 25 | { 26 | public: 27 | 28 | TriangleShader( void ) = default; 29 | 30 | private: 31 | 32 | Vec4 VSMain( void ) override; 33 | Vec4 PSMain( void ) override; 34 | 35 | private: 36 | 37 | Sampler diffuse_texture; 38 | 39 | Attribute::Position a_position; 40 | Attribute::Color a_color; 41 | Attribute::TexCoord a_texcoord; 42 | 43 | Varying::Position v_position; 44 | Varying::Color v_color; 45 | Varying::TexCoord v_texcoord; 46 | 47 | }; 48 | -------------------------------------------------------------------------------- /src/Samples/02-Cube/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Samples/02-Cube/Android/java/com/gaztin/orbit/samples/cube/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.gaztin.orbit.samples.cube; 2 | 3 | import android.app.NativeActivity; 4 | 5 | public class MainActivity extends NativeActivity 6 | { 7 | static 8 | { 9 | System.loadLibrary( "02-Cube" ); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Samples/02-Cube/Android/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/02-Cube/Android/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/02-Cube/Android/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/02-Cube/Android/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/02-Cube/Android/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/02-Cube/Android/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/02-Cube/Android/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/02-Cube/Android/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/02-Cube/Android/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/02-Cube/Android/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/02-Cube/Android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Orbit Cube 3 | 4 | -------------------------------------------------------------------------------- /src/Samples/02-Cube/CubeShader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "CubeShader.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | CubeShader::Vec4 CubeShader::VSMain( void ) 25 | { 26 | v_position = u_view_projection * u_model * a_position; 27 | v_normal = ( Transpose( u_model_inverse ) * Vec4( a_normal, 0.0 ) )->xyz; 28 | v_texcoord = a_texcoord; 29 | v_color = a_color; 30 | 31 | return v_position; 32 | } 33 | 34 | CubeShader::Vec4 CubeShader::PSMain( void ) 35 | { 36 | Vec3 tex_color = Sample( diffuse_texture, v_texcoord )->rgb; 37 | Vec3 light_dir = Vec3( -0.3, 1.0, -0.8 ); 38 | Float influence = ( Dot( v_normal, light_dir ) * 0.5 + 0.5 ); 39 | 40 | return Vec4( tex_color * influence, 1.0 ); 41 | } 42 | -------------------------------------------------------------------------------- /src/Samples/02-Cube/CubeShader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | class CubeShader final : public Orbit::ShaderGen::IShader 26 | { 27 | public: 28 | 29 | CubeShader( void ) = default; 30 | 31 | private: 32 | 33 | Vec4 VSMain( void ) override; 34 | Vec4 PSMain( void ) override; 35 | 36 | private: 37 | 38 | Sampler diffuse_texture; 39 | 40 | Attribute::Position a_position; 41 | Attribute::Normal a_normal; 42 | Attribute::TexCoord a_texcoord; 43 | Attribute::Color a_color; 44 | 45 | Varying::Position v_position; 46 | Varying::Normal v_normal; 47 | Varying::TexCoord v_texcoord; 48 | Varying::Color v_color; 49 | 50 | public: 51 | 52 | Uniform< Mat4 > u_view_projection; 53 | Uniform< Mat4 > u_model; 54 | Uniform< Mat4 > u_model_inverse; 55 | 56 | }; 57 | -------------------------------------------------------------------------------- /src/Samples/03-Model/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Samples/03-Model/Android/java/com/gaztin/orbit/samples/model/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.gaztin.orbit.samples.model; 2 | 3 | import android.app.NativeActivity; 4 | 5 | public class MainActivity extends NativeActivity 6 | { 7 | static 8 | { 9 | System.loadLibrary( "03-Model" ); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Samples/03-Model/Android/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/03-Model/Android/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/03-Model/Android/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/03-Model/Android/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/03-Model/Android/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/03-Model/Android/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/03-Model/Android/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/03-Model/Android/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/03-Model/Android/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/03-Model/Android/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/03-Model/Android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Orbit Model 3 | 4 | -------------------------------------------------------------------------------- /src/Samples/03-Model/ModelShader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "ModelShader.h" 19 | 20 | #include 21 | #include 22 | 23 | ModelShader::Vec4 ModelShader::VSMain( void ) 24 | { 25 | v_position = u_view_projection * u_model * a_position; 26 | v_color = a_color; 27 | v_texcoord = a_texcoord; 28 | v_normal = ( Transpose( u_model_inverse ) * Vec4( a_normal, 1.0 ) )->xyz; 29 | 30 | return v_position; 31 | } 32 | 33 | ModelShader::Vec4 ModelShader::PSMain( void ) 34 | { 35 | Vec4 tex_color = Sample( diffuse_texture, v_texcoord ); 36 | Vec4 out_color = tex_color + v_color; 37 | 38 | Float diffuse = ( -Dot( v_normal, u_light_dir ) * 0.5 ); 39 | out_color->rgb *= diffuse; 40 | 41 | return out_color; 42 | } 43 | -------------------------------------------------------------------------------- /src/Samples/03-Model/ModelShader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | class ModelShader final : public Orbit::ShaderGen::IShader 26 | { 27 | public: 28 | 29 | ModelShader( void ) = default; 30 | 31 | private: 32 | 33 | Vec4 VSMain( void ) override; 34 | Vec4 PSMain( void ) override; 35 | 36 | private: 37 | 38 | Sampler diffuse_texture; 39 | 40 | Attribute::Position a_position; 41 | Attribute::Color a_color; 42 | Attribute::TexCoord a_texcoord; 43 | Attribute::Normal a_normal; 44 | 45 | Varying::Position v_position; 46 | Varying::Color v_color; 47 | Varying::TexCoord v_texcoord; 48 | Varying::Normal v_normal; 49 | 50 | public: 51 | 52 | Uniform< Mat4 > u_view_projection; 53 | Uniform< Mat4 > u_model; 54 | Uniform< Mat4 > u_model_inverse; 55 | 56 | Uniform< Vec3 > u_light_dir; 57 | 58 | }; 59 | -------------------------------------------------------------------------------- /src/Samples/04-Animation/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Samples/04-Animation/Android/java/com/gaztin/orbit/samples/animation/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.gaztin.orbit.samples.animation; 2 | 3 | import android.app.NativeActivity; 4 | 5 | public class MainActivity extends NativeActivity 6 | { 7 | static 8 | { 9 | System.loadLibrary( "04-Animation" ); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Samples/04-Animation/Android/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/04-Animation/Android/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/04-Animation/Android/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/04-Animation/Android/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/04-Animation/Android/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/04-Animation/Android/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/04-Animation/Android/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/04-Animation/Android/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/04-Animation/Android/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/04-Animation/Android/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/04-Animation/Android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Orbit Animation 3 | 4 | -------------------------------------------------------------------------------- /src/Samples/04-Animation/AnimationShader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | class AnimationShader final : public Orbit::ShaderGen::IShader 26 | { 27 | public: 28 | 29 | static constexpr size_t joint_transform_count = 64; 30 | 31 | public: 32 | 33 | AnimationShader( void ) = default; 34 | 35 | private: 36 | 37 | Vec4 VSMain( void ) override; 38 | Vec4 PSMain( void ) override; 39 | 40 | private: 41 | 42 | Sampler diffuse_texture; 43 | 44 | Attribute::Position a_position; 45 | Attribute::Color a_color; 46 | Attribute::TexCoord a_texcoord; 47 | Attribute::Normal a_normal; 48 | Attribute::JointIDs a_joint_ids; 49 | Attribute::Weights a_weights; 50 | 51 | Varying::Position v_position; 52 | Varying::Color v_color; 53 | Varying::TexCoord v_texcoord; 54 | Varying::Normal v_normal; 55 | 56 | public: 57 | 58 | Uniform< Mat4 > u_view_projection; 59 | 60 | UniformArray< Mat4, joint_transform_count > u_joint_transforms; 61 | 62 | }; 63 | -------------------------------------------------------------------------------- /src/Samples/05-PostFX/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Samples/05-PostFX/Android/java/com/gaztin/orbit/samples/postfx/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.gaztin.orbit.samples.postfx; 2 | 3 | import android.app.NativeActivity; 4 | 5 | public class MainActivity extends NativeActivity 6 | { 7 | static 8 | { 9 | System.loadLibrary( "05-PostFX" ); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Samples/05-PostFX/Android/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/05-PostFX/Android/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/05-PostFX/Android/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/05-PostFX/Android/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/05-PostFX/Android/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/05-PostFX/Android/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/05-PostFX/Android/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/05-PostFX/Android/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/05-PostFX/Android/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaztin/Orbit/4589f3f0165d287482ab4b367f02633ea4e7c9a5/src/Samples/05-PostFX/Android/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/Samples/05-PostFX/Android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Orbit PostFX 3 | 4 | -------------------------------------------------------------------------------- /src/Samples/05-PostFX/PostFXShader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "PostFXShader.h" 19 | 20 | #include 21 | #include 22 | 23 | PostFXShader::Vec4 PostFXShader::VSMain( void ) 24 | { 25 | v_texcoord = CanonicalScreenPos( a_position->xy ) * 0.5 + 0.5; 26 | v_position = a_position; 27 | 28 | return v_position; 29 | } 30 | 31 | PostFXShader::Vec4 PostFXShader::PSMain( void ) 32 | { 33 | Vec4 tex_render = Sample( render_texture, v_texcoord ); 34 | Vec4 left = Sample( render_texture, v_texcoord + Vec2( Cos( u_time ), Sin( u_time ) ) * 0.1 ); 35 | Vec4 right = Sample( render_texture, v_texcoord - Vec2( Cos( u_time ), Sin( u_time ) ) * 0.1 ); 36 | 37 | return tex_render->rgba * 0.5 + left * 0.25 + right * 0.25; 38 | } 39 | -------------------------------------------------------------------------------- /src/Samples/05-PostFX/PostFXShader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | 22 | class PostFXShader final : public Orbit::ShaderGen::IShader 23 | { 24 | private: 25 | 26 | Vec4 VSMain( void ) override; 27 | Vec4 PSMain( void ) override; 28 | 29 | private: 30 | 31 | Sampler render_texture; 32 | 33 | Attribute::Position a_position; 34 | 35 | Varying::Position v_position; 36 | Varying::TexCoord v_texcoord; 37 | 38 | public: 39 | 40 | Uniform< Float > u_time; 41 | 42 | }; 43 | -------------------------------------------------------------------------------- /src/Samples/05-PostFX/SceneShader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #include "SceneShader.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | SceneShader::Vec4 SceneShader::VSMain( void ) 25 | { 26 | v_position = u_view_projection * u_model * a_position; 27 | v_color = a_color; 28 | v_texcoord = a_texcoord; 29 | v_normal = a_normal; 30 | 31 | return v_position; 32 | } 33 | 34 | SceneShader::Vec4 SceneShader::PSMain( void ) 35 | { 36 | Vec4 tex_color = Sample( diffuse_texture, v_texcoord ); 37 | Vec4 out_color = tex_color + v_color; 38 | 39 | Vec3 light_dir = Normalize( Vec3( -1.0, 1.0, 1.0 ) ); 40 | Float directional_influence = ( Dot( v_normal, light_dir ) * 0.75 ); 41 | Float ambient_influence = 0.5; 42 | 43 | out_color->rgb *= ( directional_influence + ambient_influence ); 44 | 45 | return out_color; 46 | } 47 | -------------------------------------------------------------------------------- /src/Samples/05-PostFX/SceneShader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Sebastian Kylander https://gaztin.com/ 3 | * 4 | * This software is provided 'as-is', without any express or implied warranty. In no event will 5 | * the authors be held liable for any damages arising from the use of this software. 6 | * 7 | * Permission is granted to anyone to use this software for any purpose, including commercial 8 | * applications, and to alter it and redistribute it freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the 11 | * original software. If you use this software in a product, an acknowledgment in the product 12 | * documentation would be appreciated but is not required. 13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as 14 | * being the original software. 15 | * 3. This notice may not be removed or altered from any source distribution. 16 | */ 17 | 18 | #pragma once 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | class SceneShader final : public Orbit::ShaderGen::IShader 26 | { 27 | public: 28 | 29 | SceneShader( void ) = default; 30 | 31 | private: 32 | 33 | Vec4 VSMain( void ) override; 34 | Vec4 PSMain( void ) override; 35 | 36 | private: 37 | 38 | Sampler diffuse_texture; 39 | 40 | Attribute::Position a_position; 41 | Attribute::Color a_color; 42 | Attribute::TexCoord a_texcoord; 43 | Attribute::Normal a_normal; 44 | 45 | Varying::Position v_position; 46 | Varying::Color v_color; 47 | Varying::TexCoord v_texcoord; 48 | Varying::Normal v_normal; 49 | 50 | public: 51 | 52 | Uniform< Mat4 > u_view_projection; 53 | Uniform< Mat4 > u_model; 54 | 55 | }; 56 | --------------------------------------------------------------------------------