├── .editorconfig ├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ ├── install-chroot │ ├── install-dotnet-debian9 │ ├── main.yaml │ ├── setup-xvfb │ ├── upgrade-debian │ ├── xvfb-daemon-run │ └── xvfb_init ├── .gitignore ├── .gitmodules ├── .scripts └── git-hooks │ ├── dotnet-pre-push │ └── install-hooks ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── Assets ├── Shaders │ ├── .gitignore │ ├── common │ │ ├── header.glsl │ │ ├── lib.frag.glsl │ │ ├── lib.frag.small.glsl │ │ └── lighting.glsl │ ├── deferred-gbuffer.frag │ ├── deferred-gbuffer.vert │ ├── deferred-shading.frag │ ├── deferred-shading.vert │ ├── forward.frag │ ├── forward.vert │ ├── lines.frag │ ├── lines.vert │ ├── screen-lines.frag │ ├── screen-lines.vert │ ├── screen.frag │ ├── screen.vert │ ├── shadow-cube.frag │ ├── shadow-cube.geom │ ├── shadow-cube.vert │ ├── shadow-directional.frag │ ├── shadow-directional.geom │ ├── shadow-directional.vert │ ├── skybox.frag │ ├── skybox.vert │ └── white.frag └── Textures │ ├── desert-skybox │ ├── back.tga │ ├── bottom.tga │ ├── front.tga │ ├── left.tga │ ├── right.tga │ └── top.tga │ ├── water-skybox │ ├── back.jpg │ ├── bottom.jpg │ ├── front.jpg │ ├── left.jpg │ ├── right.jpg │ └── top.jpg │ ├── wood.png │ ├── woodenbox.png │ └── woodenbox_specular.png ├── CHANGELOG.md ├── Common ├── .editorconfig ├── AssemblyInfo.cs ├── AssetManager.cs ├── AxMath.cs ├── AxPixelFormat.cs ├── AxPrimitiveType.cs ├── Buffers │ ├── BufferData.cs │ ├── BufferData1D.cs │ ├── BufferData1D{T}.cs │ ├── BufferData2D.cs │ ├── BufferData2D{T}.cs │ ├── BufferData3D.cs │ ├── BufferData3D{T}.cs │ └── BufferDataExtentions.cs ├── Camera │ ├── Camera.cs │ ├── OrthographicCamera.cs │ └── PerspectiveFieldOfViewCamera.cs ├── Common.csproj ├── DataHelper.cs ├── DebugHelper.cs ├── EventCounter.cs ├── Extensions │ ├── BoxExtensions.cs │ ├── DictionaryExtensions.cs │ ├── ImageExtensions.cs │ ├── LogExtensions.cs │ ├── StreamExtensions.cs │ ├── StringExtensions.cs │ └── VectorExtensions.cs ├── Hashing.cs ├── Helper │ ├── BoxHelper.cs │ └── VectorHelper.cs ├── IVisitor.cs ├── ImageContext.cs ├── Interfaces.cs ├── Log.cs ├── Mesh │ ├── ArrayExtensions.cs │ ├── DynamicArrayExtensions.cs │ ├── FaceExtensions.cs │ ├── IArray.cs │ ├── IDynamicArray.cs │ ├── InternalMeshFace.cs │ ├── ListExtensions.cs │ ├── Mesh.cs │ ├── MeshComponent.cs │ ├── MeshComponentType.cs │ ├── MeshComponents │ │ ├── MeshColorComponent.cs │ │ ├── MeshNormalComponent.cs │ │ ├── MeshPosition2Component.cs │ │ ├── MeshPosition3Component.cs │ │ ├── MeshPositionComponent.cs │ │ └── MeshUVComponent.cs │ ├── MeshComponent{T}.cs │ ├── MeshFace.cs │ ├── MeshFaceList.cs │ ├── MeshFaceType.cs │ ├── MeshVertexEnumerator.cs │ ├── MeshVertexList.cs │ ├── MeshVisitors │ │ ├── VertexPos2UVVisitor.cs │ │ ├── VertexPosColorVisitor.cs │ │ ├── VertexPosNormalColorVisitor.cs │ │ ├── VertexPosNormalUVVisitor.cs │ │ ├── VertexPosition3Visitor.cs │ │ └── VertexVisitor.cs │ └── NormalSolver.cs ├── PathBuilder.cs ├── Plane.cs ├── Ray.cs ├── Rotor │ ├── AntiVector4d.cs │ ├── BiVector3d.cs │ ├── BiVector4d.cs │ └── Rotor3.cs ├── SharedLib.cs ├── SlotAllocator{T}.cs ├── TaskQueue.cs ├── TgaDecoder.cs ├── Transform.cs ├── UIAnchors.cs ├── Util │ ├── IcoSphere │ │ ├── IcoSphereCreator.cs │ │ ├── IcoSphereMesh.cs │ │ ├── MeshGeometry3D.cs │ │ ├── TriangleIndices.cs │ │ └── VertexSoup.cs │ └── RoundedCubeGenerator.cs └── VertexData │ ├── Primitives │ ├── IPrimitive.cs │ ├── IPrimitive{TVertex}.cs │ ├── Line{TVertex}.cs │ ├── Polygon{TVertex}.cs │ └── Quad{TVertex}.cs │ ├── VertexDataPos.cs │ ├── VertexDataPos2.cs │ ├── VertexDataPos2UV.cs │ ├── VertexDataPosColor.cs │ ├── VertexDataPosNormalColor.cs │ ├── VertexDataPosNormalUV.cs │ ├── VertexDataPosUV.cs │ └── VertexInterfaces │ ├── IVertex.cs │ ├── IVertexColor.cs │ ├── IVertexNormal.cs │ ├── IVertexPos2UV.cs │ ├── IVertexPosColor.cs │ ├── IVertexPosNormalColor.cs │ ├── IVertexPosNormalUV.cs │ ├── IVertexPosUV.cs │ ├── IVertexPosition.cs │ ├── IVertexPosition2.cs │ ├── IVertexPosition3.cs │ └── IVertexUV.cs ├── Demo ├── .editorconfig ├── Demo.csproj ├── DemoApplication.cs ├── Experiment │ ├── Test.cs │ ├── definitions │ │ ├── definition.json │ │ └── schema.json │ └── doc.txt └── Program.cs ├── Engine.sln ├── Engine ├── .editorconfig ├── Actors │ └── Actor.cs ├── Application.cs ├── ApplicationConfig.cs ├── AssemblyInfo.cs ├── Audio │ └── AudioManager.cs ├── CommandLineManager.cs ├── CommandLineOptions.cs ├── Components │ ├── ActorComponent.cs │ ├── BufferComponent.cs │ ├── Geometry │ │ ├── CrossLineComponent.cs │ │ ├── CubeComponent.cs │ │ ├── DebugCubeComponent.cs │ │ ├── Experiment │ │ │ ├── ISceneInterface.cs │ │ │ ├── PrimitiveDrawInterface.cs │ │ │ ├── PrimitiveSceneProxy.cs │ │ │ ├── StaticMeshSceneProxy.cs │ │ │ └── StaticPrimitiveDrawInterface.cs │ │ ├── GraphicsScreenTextureComponent.cs │ │ ├── GridPlaneComponent.cs │ │ ├── LineComponent.cs │ │ ├── MeshComponent.cs │ │ ├── PrimitiveComponent.cs │ │ ├── QuadComponent.cs │ │ ├── RoundedCubeComponent.cs │ │ ├── ScreenTextureComponent.cs │ │ ├── SkyBoxComponent.cs │ │ ├── SphereComponent.cs │ │ ├── StaticMeshComponent.cs │ │ └── StatsComponent.cs │ ├── Lights │ │ ├── DirectionalLightComponent.cs │ │ ├── LightComponent.cs │ │ └── PointLightComponent.cs │ ├── SceneComponent.cs │ └── UI │ │ ├── UIButton.cs │ │ ├── UIButtonComponent.cs │ │ ├── UIComponent.cs │ │ ├── UIContainerComponent.cs │ │ ├── UIFloatingContainer.cs │ │ ├── UIFlowContainer.cs │ │ ├── UIImage.cs │ │ ├── UILabelComponent.cs │ │ ├── UIPanelComponent.cs │ │ ├── UIRect.cs │ │ └── UISlider.cs ├── Engine.csproj ├── EngineAssets.cs ├── ExecuteConsoleCommandLineArgs.cs ├── Generators │ ├── AlchemyCircle │ │ ├── AlchemyCircleGenerator.cs │ │ ├── AlchemyCircleOptions.cs │ │ ├── CiaccoRandom.cs │ │ └── TextureDraw.cs │ ├── RandomNumbers │ │ ├── NativeFunctions.cs │ │ ├── RandomNumberGeneratorBase.cs │ │ ├── TrueRandomNumberGenerator.cs │ │ ├── Well512RandomNumberGenerator.cs │ │ └── XorShift128RandomNumberGenerator.cs │ └── Voronoi │ │ └── VoronoiGenerator.cs ├── Materials │ ├── Material.cs │ ├── MaterialManager.cs │ ├── PipelineType.cs │ ├── Shader.cs │ ├── Texture.cs │ └── TextureManager.cs ├── MeshBuilder.cs ├── SceneContext.cs ├── SceneObject.cs ├── Startup.cs ├── Startup{TApplication,TGtk}.cs ├── Startup{TApplication}.cs ├── TransformUtil.cs ├── Tween │ ├── ScaleFuncs.cs │ ├── Tween.cs │ ├── Tween1.cs │ ├── Tween2.cs │ ├── Tween3.cs │ ├── TweenBuilder.cs │ ├── TweenBuilderExtensions.cs │ ├── TweenBuilder{TTarget}.cs │ └── Tween{TValue}.cs └── Windows │ ├── GtkUI.cs │ ├── MouseButtonArgs.cs │ ├── MouseMoveArgs.cs │ ├── RenderWindow.cs │ ├── Win32Native.cs │ └── WindowContext.cs ├── LICENSE ├── README.md ├── Render ├── .editorconfig ├── AssemblyInfo.cs ├── GLSL │ ├── Attributes.cs │ ├── GlslBase.cs │ ├── GlslTest.cs │ └── Structs.cs ├── Lib.cs ├── MeshData.cs ├── MeshData{T}.cs ├── MeshDepthSorter.cs ├── MeshExtensions.cs ├── Objects │ ├── LightObject.cs │ ├── PrimitiveObject.cs │ ├── RenderObject.cs │ ├── RenderObjectBase.cs │ ├── ScreenSceneObject.cs │ ├── ScreenTextureObject.cs │ ├── ScreenshotObject.cs │ ├── SimpleVertexObject.cs │ └── SkyboxObject.cs ├── OpenGL │ ├── Buffers │ │ ├── BindingPoint.cs │ │ ├── BufferObject.cs │ │ ├── ElementsBufferObject.cs │ │ ├── UniformBufferObject.cs │ │ └── VertexBufferObject.cs │ ├── FlushRenderBackend.cs │ ├── FrameBuffer.cs │ ├── GraphicsDevice.cs │ ├── GraphicsTexture.cs │ ├── InternalLightManager.cs │ ├── InternalTextureManager.cs │ ├── Mesh │ │ ├── DynamicInternalMesh.cs │ │ ├── InternalMesh.cs │ │ └── StaticInternalMesh.cs │ ├── MeshDataBuilder.cs │ ├── ObjectManager.cs │ ├── RenderBuffer.cs │ ├── RendererShader.cs │ ├── RendererTexture.cs │ ├── ShaderCompilation.cs │ ├── ShaderSource.cs │ ├── StructHelper.cs │ ├── VertexArrayObject.cs │ ├── VertexLayoutBinded.cs │ ├── VertexLayoutBindedAttribute.cs │ ├── VertexLayoutDefinition.cs │ └── VertexLayoutDefinitionAttribute.cs ├── Pipelines │ ├── DeferredRenderPipeline.cs │ ├── DirectionalShadowRenderPipeline.cs │ ├── ForwardRenderPipeline.cs │ ├── PointShadowRenderPipeline.cs │ ├── RenderPipeline.cs │ └── ScreenPipeline.cs ├── PixelFormatExtensions.cs ├── Render.csproj ├── RenderContext.cs ├── Renderer.cs ├── RendererMaterial.cs └── ScreenResizeEventArgs.cs ├── Tests ├── .editorconfig ├── AssemblyInfo.cs ├── Assets │ ├── .gitignore │ └── TestOutputs │ │ ├── LightTests │ │ ├── BoxDeferredColorAmbient0.0.png │ │ ├── BoxDeferredColorAmbient0.2.png │ │ ├── BoxDeferredColorAmbient1.0.png │ │ ├── BoxDeferredTextureAmbient0.0.png │ │ ├── BoxDeferredTextureAmbient0.2.png │ │ ├── BoxDeferredTextureAmbient1.0.png │ │ ├── BoxForwardColorAmbient0.0.png │ │ ├── BoxForwardColorAmbient0.2.png │ │ ├── BoxForwardColorAmbient1.0.png │ │ ├── BoxForwardTextureAmbient0.0.png │ │ ├── BoxForwardTextureAmbient0.2.png │ │ └── BoxForwardTextureAmbient1.0.png │ │ ├── LightTypeTests │ │ ├── BoxDeferredColorAmbient0.2Directional.png │ │ ├── BoxDeferredColorAmbient0.2Point.png │ │ ├── BoxForwardColorAmbient0.2Directional.png │ │ └── BoxForwardColorAmbient0.2Point.png │ │ ├── MeshRenderTests │ │ ├── Bomb.png │ │ └── Sphere.png │ │ ├── RenderTests │ │ ├── BoxDeferredColorAmbient0.0.png │ │ ├── BoxDeferredColorAmbient0.5.png │ │ ├── BoxDeferredColorAmbient1.0.png │ │ ├── BoxDeferredTextureAmbient0.0.png │ │ ├── BoxDeferredTextureAmbient0.5.png │ │ ├── BoxDeferredTextureAmbient1.0.png │ │ ├── BoxForwardColorAmbient0.0.png │ │ ├── BoxForwardColorAmbient0.5.png │ │ ├── BoxForwardColorAmbient1.0.png │ │ ├── BoxForwardTextureAmbient0.0.png │ │ ├── BoxForwardTextureAmbient0.5.png │ │ └── BoxForwardTextureAmbient1.0.png │ │ └── ShadowTypeTests │ │ ├── BoxDeferredDirectional.png │ │ ├── BoxDeferredPoint.png │ │ ├── BoxForwardDirectional.png │ │ └── BoxForwardPoint.png ├── ImageHashing.cs ├── Operations │ └── MeshOperationTests.cs ├── Program.cs ├── RenderTests │ ├── LightTests.cs │ ├── LightTypeTests.cs │ ├── MeshRenderTests.cs │ ├── RenderTests.cs │ └── ShadowTypeTests.cs ├── TestBase.cs ├── TestConfig.cs ├── Tests.csproj ├── TestsApplication.cs └── run-tests └── props ├── AssemblyVersion.props ├── Aximo.Nuget.csproj ├── Nuspec.props ├── SharedProjectSettings.props ├── default.ruleset └── stylecop.json /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pdf filter=lfs diff=lfs merge=lfs -text 2 | *.png filter=lfs diff=lfs merge=lfs -text 3 | *.bmp filter=lfs diff=lfs merge=lfs -text 4 | *.jpg filter=lfs diff=lfs merge=lfs -text 5 | *.jpeg filter=lfs diff=lfs merge=lfs -text 6 | *.tga filter=lfs diff=lfs merge=lfs -text 7 | *.wav filter=lfs diff=lfs merge=lfs -text 8 | *.mp3 filter=lfs diff=lfs merge=lfs -text 9 | *.dll filter=lfs diff=lfs merge=lfs -text 10 | *.so filter=lfs diff=lfs merge=lfs -text 11 | *.mod filter=lfs diff=lfs merge=lfs -text 12 | *.ogg filter=lfs diff=lfs merge=lfs -text 13 | *.exe filter=lfs diff=lfs merge=lfs -text 14 | *.zip filter=lfs diff=lfs merge=lfs -text 15 | *.pdf filter=lfs diff=lfs merge=lfs -text 16 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: arakis -------------------------------------------------------------------------------- /.github/workflows/install-chroot: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd $(dirname $0) 4 | 5 | # Stage 0 Install chroot 6 | 7 | # debootstrap stretch aximo-chroot 8 | # sudo mount --bind /proc aximo-chroot/proc 9 | # sudo mount --bind /sys aximo-chroot/sys 10 | # sudo mount --bind /dev aximo-chroot/dev 11 | # sudo mount --bind /dev/pts aximo-chroot/dev/pts 12 | 13 | # Stage 1 Preparation (manual) 14 | 15 | # apt-get update && apt-get -y install git sudo 16 | # git clone --recursive https://github.com/AximoGames/AxEngine.git 17 | # Now Call .github/workfows/install-chroot 18 | 19 | # Stage 2 20 | echo deb http://deb.debian.org/debian stretch-backports main >> /etc/apt/sources.list 21 | apt-get wget zsh git-lfs 22 | 23 | # comfort 24 | apt-get -y install zsh 25 | git clone --recursive https://github.com/Arakis/prezto.git ~/.zprezto 26 | # Manual: launch zsh and run: ~/.zprezto/install 27 | 28 | ./install-dotnet-debian9 29 | 30 | #--- 31 | apt-get install -y build-essential cmake libosmesa6-dev gdb 32 | 33 | # build GLFW: 34 | 35 | # git clone --recursive https://github.com/glfw/glfw.git 36 | # cd glfw 37 | # git checkout 3.3.2 38 | # cmake -DGLFW_USE_OSMESA=ON -DBUILD_SHARED_LIBS=ON . 39 | # make 40 | # cp src/libglfw.so* ../AxEngine/Tests/bin/Debug/netcoreapp3.1 41 | 42 | # Test: 43 | 44 | # dotnet test Tests --no-build -v detailed -------------------------------------------------------------------------------- /.github/workflows/install-dotnet-debian9: -------------------------------------------------------------------------------- 1 | wget -O- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg 2 | sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/ 3 | wget https://packages.microsoft.com/config/debian/9/prod.list 4 | sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list 5 | sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg 6 | sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list 7 | 8 | sudo apt-get update 9 | sudo apt-get -y install apt-transport-https 10 | sudo apt-get update 11 | sudo apt-get -y install dotnet-sdk-3.1 12 | -------------------------------------------------------------------------------- /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | # This workflow is triggered on pushes to the repository. 3 | on: [push] 4 | 5 | jobs: 6 | build-unix: 7 | name: Linux Test 8 | runs-on: ubuntu-18.04 9 | steps: 10 | - uses: actions/checkout@master 11 | with: 12 | submodules: recursive 13 | lfs: true 14 | # - uses: actions/setup-dotnet@v1.4.0 15 | # with: 16 | # dotnet-version: "3.1.100" # SDK Version to use. 17 | - name: Build 18 | run: dotnet build 19 | # - name: Update Package respository 20 | # run: .github/workflows/upgrade-debian 21 | - name: Install xvfb 22 | run: .github/workflows/setup-xvfb 23 | - name: Run Render Tests 24 | run: .github/workflows/xvfb-daemon-run dotnet test Tests -v detailed --no-build -- RunConfiguration.TestSessionTimeout=120000 25 | # env: 26 | # LIBGL_ALWAYS_SOFTWARE: true 27 | # - name: Running tests 28 | # run: dotnet test -p Tests 29 | # env: 30 | # LIBGL_ALWAYS_SOFTWARE: true 31 | # GALLIUM_DRIVER: softpipe 32 | -------------------------------------------------------------------------------- /.github/workflows/setup-xvfb: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -e 4 | 5 | cd $(dirname $0) 6 | 7 | sudo apt-get install -y xvfb x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps \ 8 | libgl1-mesa-glx llvm 9 | 10 | sudo cp xvfb_init /etc/init.d/xvfb 11 | sudo chmod a+x /etc/init.d/xvfb 12 | 13 | sudo chmod a+x xvfb-daemon-run 14 | 15 | export DISPLAY=:99 16 | -------------------------------------------------------------------------------- /.github/workflows/upgrade-debian: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | cd $(dirname $0) 5 | 6 | export DEBIAN_FRONTEND=noninteractive 7 | 8 | sudo sed -i s/stretch/buster/g /etc/apt/sources.list 9 | sudo apt-get -y -o Acquire::Check-Valid-Until=false update 10 | sudo apt-get -y dist-upgrade -------------------------------------------------------------------------------- /.github/workflows/xvfb-daemon-run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export DISPLAY=:99 3 | /etc/init.d/xvfb start 4 | sleep 1 5 | $@ 6 | exit_value=$? 7 | /etc/init.d/xvfb stop 8 | exit $exit_value -------------------------------------------------------------------------------- /.github/workflows/xvfb_init: -------------------------------------------------------------------------------- 1 | XVFB=/usr/bin/Xvfb 2 | XVFBARGS="$DISPLAY -ac -screen 0 1024x768x16 +extension RANDR" 3 | PIDFILE=/var/xvfb_${DISPLAY:1}.pid 4 | case "$1" in 5 | start) 6 | echo -n "Starting virtual X frame buffer: Xvfb" 7 | /sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS 8 | echo "." 9 | ;; 10 | stop) 11 | echo -n "Stopping virtual X frame buffer: Xvfb" 12 | /sbin/start-stop-daemon --stop --quiet --pidfile $PIDFILE 13 | echo "." 14 | ;; 15 | restart) 16 | $0 stop 17 | $0 start 18 | ;; 19 | *) 20 | echo "Usage: /etc/init.d/xvfb {start|stop|restart}" 21 | exit 1 22 | esac 23 | exit 0 -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "External/Net3dBool"] 2 | path = External/Net3dBool 3 | url = https://github.com/arakis/Net3dBool.git 4 | pushurl = git@github.com:arakis/Net3dBool.git 5 | [submodule "Aximo.AudioRack"] 6 | path = Aximo.AudioRack 7 | url = https://github.com/AximoGames/Aximo.AudioRack.git 8 | pushurl = git@github.com:AximoGames/Aximo.AudioRack.git 9 | -------------------------------------------------------------------------------- /.scripts/git-hooks/dotnet-pre-push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | protected_branch='develop' 3 | current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') 4 | RED='\033[0;31m' 5 | GREEN='\033[1;32m' 6 | YELLOW='\033[1;33m' 7 | NC='\033[0m' # No Color 8 | 9 | # only run this if you are pushing to master 10 | if [[ $current_branch = $protected_branch ]] ; then 11 | echo -e "${YELLOW}Running pre push to master check...${NC}" 12 | 13 | echo -e "${YELLOW}Trying to build tests project...${NC}" 14 | 15 | #Let's speed things up a little bit 16 | DOTNET_CLI_TELEMETRY_OPTOUT=1 17 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 18 | 19 | # build the project 20 | dotnet build 21 | 22 | # $? is a shell variable which stores the return code from what we just ran 23 | rc=$? 24 | if [[ $rc != 0 ]] ; then 25 | echo -e "${RED}Failed to build the project, please fix this and push again${NC}" 26 | echo "" 27 | exit $rc 28 | fi 29 | 30 | # navigate to the test project to run the tests 31 | # TODO: change this to your test project directory 32 | cd test 33 | 34 | echo -e "${YELLOW}Running unit tests...${NC}" 35 | echo "" 36 | 37 | # run the unit tests 38 | dotnet test 39 | 40 | # $? is a shell variable which stores the return code from what we just ran 41 | rc=$? 42 | if [[ $rc != 0 ]] ; then 43 | # A non-zero return code means an error occurred, so tell the user and exit 44 | echo -e "${RED}Unit tests failed, please fix and push again${NC}" 45 | echo "" 46 | exit $rc 47 | fi 48 | 49 | # Everything went OK so we can exit with a zero 50 | echo -e "${GREEN}Pre push check passed!${NC}" 51 | echo "" 52 | fi 53 | 54 | exit 0 55 | -------------------------------------------------------------------------------- /.scripts/git-hooks/install-hooks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -e 4 | 5 | cd $(dirname $0) 6 | 7 | ln -s ../../.scripts/git-hooks/dotnet-pre-push ../../.git/hooks/pre-push 8 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Demo", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | "program": "${workspaceFolder}/Demo/bin/Debug/netcoreapp3.1/AxDemo.dll", 13 | "args": [], 14 | "cwd": "${workspaceFolder}", 15 | "stopAtEntry": false, 16 | "console": "integratedTerminal" 17 | }, 18 | ] 19 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "glsl-linter.validatorPath": "/usr/bin/glslangValidator" 3 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build", 8 | "type": "shell", 9 | "command": "dotnet", 10 | "args": [ 11 | "msbuild", 12 | // Ask msbuild to generate full paths for file names. 13 | "/p:Configuration=Debug", 14 | "/property:GenerateFullPaths=true", 15 | "/t:build", 16 | // Do not generate summary otherwise it leads to duplicate errors in Problems panel 17 | "/consoleloggerparameters:NoSummary" 18 | ], 19 | "group": "build", 20 | "presentation": { 21 | // Reveal the output only if unrecognized errors occur. 22 | "reveal": "silent" 23 | }, 24 | // Use the standard MS compiler pattern to detect errors, warnings and infos 25 | "problemMatcher": "$msCompile", 26 | "options": { 27 | "cwd": "${workspaceRoot}/Demo", 28 | "env": { 29 | "FrameworkPathOverride": "/usr/lib/mono/4.5" 30 | } 31 | } 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /Assets/Shaders/.gitignore: -------------------------------------------------------------------------------- 1 | *-compiled.* 2 | -------------------------------------------------------------------------------- /Assets/Shaders/common/header.glsl: -------------------------------------------------------------------------------- 1 | 2 | #define CUBE_MAP_SHADOW_ROTATED 3 | //#undef CUBE_MAP_SHADOW_ROTATED 4 | 5 | #define MAX_NUM_TOTAL_LIGHTS 100 6 | 7 | struct SLight { 8 | vec3 Position; //The position of the light. 9 | vec4 Color; //The color of the light. 10 | mat4 LightSpaceMatrix; 11 | vec3 Direction; 12 | int ShadowLayer; 13 | 14 | int DirectionalLight; 15 | float Linear; 16 | float Quadratic; 17 | float FarPlane; 18 | }; 19 | 20 | struct SMaterial { 21 | 22 | // Formular: Map * Color 23 | sampler2D DiffuseMap; // White default map, as fallbak 24 | vec4 DiffuseColor; // white, if map is used 25 | 26 | sampler2D SpecularMap; // Defaults to white or 1.0 27 | float SpecularStrength; // defaults to 1.0 28 | float Shininess; 29 | 30 | float Ambient; 31 | int ColorBlendMode; 32 | }; 33 | 34 | struct SLightResult { 35 | float Shadow; 36 | vec4 Diffuse; 37 | vec4 Specular; 38 | }; 39 | -------------------------------------------------------------------------------- /Assets/Shaders/common/lib.frag.small.glsl: -------------------------------------------------------------------------------- 1 | // Only Function with no references outisde this scope (no prior included methods, no global uniforms) 2 | // All data needs to passed as argument -------------------------------------------------------------------------------- /Assets/Shaders/common/lighting.glsl: -------------------------------------------------------------------------------- 1 | SLightResult lightResult; 2 | lightResult.Diffuse = vec4(0); 3 | lightResult.Specular = vec4(0); 4 | lightResult.Shadow = 0; 5 | 6 | float originalAlpha = matDiffuse.a; 7 | 8 | // then calculate lighting as usual 9 | vec4 lighting = matDiffuse * matAmbient; // hard-coded ambient component 10 | 11 | for(int i = 0; i < LightCount; ++i) 12 | { 13 | SLight light = lights[i]; 14 | 15 | // diffuse 16 | vec3 lightDir; 17 | if(light.DirectionalLight == 1) 18 | lightDir = -light.Direction; 19 | else 20 | lightDir = normalize(light.Position - FragPos); 21 | 22 | vec4 diffuse = max(dot(normal, lightDir), 0.0) * matDiffuse * light.Color; 23 | 24 | // specular 25 | vec4 specular; 26 | // if(light.DirectionalLight == 1) { 27 | // specular = vec4(0); 28 | // } 29 | //else { 30 | vec3 halfwayDir = normalize(lightDir + viewDir); 31 | float spec = pow(max(dot(normal, halfwayDir), 0.0), matShininess); 32 | specular = light.Color * spec * matSpecular; 33 | //} 34 | 35 | // attenuation 36 | float attenuation; 37 | if(light.DirectionalLight == 1) { 38 | attenuation = 1.0; 39 | } 40 | else { 41 | float distance = length(light.Position - FragPos); 42 | attenuation = 1.0 / (1.0 + light.Linear * distance + light.Quadratic * (distance * distance)); 43 | } 44 | 45 | //attenuation = 1.0; // debug 46 | 47 | #ifdef USE_SHADOW 48 | float shadow; 49 | if(light.DirectionalLight == 1) { 50 | shadow = ShadowCalculation(vec4(FragPos, 1.0) * light.LightSpaceMatrix, light); 51 | } 52 | else { 53 | shadow = ShadowCalculationCubeSoft(FragPos, light); 54 | } 55 | lightResult.Shadow += shadow * attenuation; 56 | #endif 57 | 58 | lightResult.Diffuse += diffuse * attenuation; 59 | lightResult.Specular += specular * attenuation; 60 | 61 | //shadow *= attenuation; // just a test 62 | } 63 | 64 | lighting += (lightResult.Diffuse + lightResult.Specular) * (1.0 - lightResult.Shadow); 65 | lighting.a = originalAlpha; 66 | 67 | FragColor = lighting; 68 | -------------------------------------------------------------------------------- /Assets/Shaders/deferred-gbuffer.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | #extension GL_ARB_shading_language_include : enable 3 | 4 | #include "common/header.glsl" 5 | 6 | #ifdef FRAG_HEADER_FILE 7 | #include FRAG_HEADER_FILE 8 | #endif 9 | 10 | layout (location = 0) out vec3 gPosition; 11 | layout (location = 1) out vec3 gNormal; 12 | layout (location = 2) out vec4 gAlbedoSpec; 13 | layout (location = 3) out vec3 gMaterial; 14 | 15 | #ifdef USE_VERTEX_UV 16 | in vec2 TexCoords; 17 | #endif 18 | #ifdef USE_VERTEX_COLOR 19 | in vec4 Color; 20 | #endif 21 | in vec3 FragPos; 22 | in vec3 Normal; 23 | in vec3 NormalTransposed; 24 | 25 | uniform SMaterial material; 26 | 27 | #include "common/lib.frag.small.glsl" 28 | 29 | void main() 30 | { 31 | // store the fragment position vector in the first gbuffer texture 32 | gPosition = FragPos; 33 | // also store the per-fragment normals into the gbuffer 34 | gNormal = normalize(Normal); 35 | // and the diffuse per-fragment color 36 | vec4 matDiffuse = material.DiffuseColor; 37 | #ifndef OVERRIDE_GET_MATERIAL_DIFFUSE_FILE 38 | 39 | #ifdef USE_VERTEX_UV 40 | matDiffuse = texture(material.DiffuseMap, TexCoords) * material.DiffuseColor; 41 | #endif 42 | #ifdef USE_VERTEX_COLOR 43 | matDiffuse = Color * material.DiffuseColor; 44 | #endif 45 | 46 | #else 47 | #include OVERRIDE_GET_MATERIAL_DIFFUSE_FILE 48 | #endif 49 | 50 | gAlbedoSpec.rgb = matDiffuse.rgb; 51 | #ifdef USE_VERTEX_UV 52 | // store specular intensity in gAlbedoSpec's alpha component 53 | gAlbedoSpec.a = texture(material.SpecularMap, TexCoords).r * material.SpecularStrength; 54 | #else 55 | gAlbedoSpec.a = material.SpecularStrength; 56 | #endif 57 | 58 | // Extra material parameters 59 | gMaterial.r = material.Ambient; 60 | //gMaterial.r = 0; 61 | gMaterial.g = material.Shininess; 62 | gMaterial.b = 0; // unused 63 | } -------------------------------------------------------------------------------- /Assets/Shaders/deferred-gbuffer.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | layout (location = 1) in vec3 aNormal; 4 | #ifdef USE_VERTEX_UV 5 | layout (location = 2) in vec2 aTexCoords; 6 | #ifdef USE_VERTEX_COLOR 7 | layout (location = 3) in vec4 aColor; 8 | #endif 9 | #else 10 | #ifdef USE_VERTEX_COLOR 11 | layout (location = 2) in vec4 aColor; 12 | #endif 13 | #endif 14 | 15 | out vec3 FragPos; 16 | #ifdef USE_VERTEX_UV 17 | out vec2 TexCoords; 18 | #endif 19 | #ifdef USE_VERTEX_COLOR 20 | out vec4 Color; 21 | #endif 22 | out vec3 Normal; 23 | out vec3 NormalTransposed; 24 | 25 | uniform mat4 Model; 26 | uniform mat4 View; 27 | uniform mat4 Projection; 28 | 29 | void main() 30 | { 31 | vec4 worldPos = vec4(aPos, 1.0) * Model; 32 | //FragPos = worldPos.xyz; 33 | FragPos = worldPos.xyz; 34 | #ifdef USE_VERTEX_UV 35 | TexCoords = aTexCoords; 36 | #endif 37 | #ifdef USE_VERTEX_COLOR 38 | Color = aColor; 39 | #endif 40 | 41 | mat3 normalMatrix = transpose(inverse(mat3(Model))); 42 | Normal = aNormal * normalMatrix; 43 | NormalTransposed = normalMatrix * aNormal; 44 | 45 | gl_Position = worldPos * View * Projection; 46 | } -------------------------------------------------------------------------------- /Assets/Shaders/deferred-shading.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | #extension GL_ARB_shading_language_include : enable 3 | #extension GL_ARB_texture_cube_map_array : enable 4 | 5 | #include "common/header.glsl" 6 | 7 | out vec4 FragColor; 8 | 9 | in vec2 TexCoords; 10 | 11 | uniform SMaterial material; 12 | 13 | uniform sampler2D gPosition; 14 | uniform sampler2D gNormal; 15 | uniform sampler2D gAlbedoSpec; 16 | uniform sampler2D gMaterial; 17 | 18 | // struct Light { 19 | // vec3 Position; 20 | // vec3 Color; 21 | 22 | // float Linear; 23 | // float Quadratic; 24 | // }; 25 | 26 | #ifdef USE_SHADOW 27 | uniform sampler2DArray DirectionalShadowMap; 28 | uniform samplerCubeArray PointShadowMap; 29 | #endif 30 | 31 | uniform vec3 ViewPos; 32 | uniform int LightCount; 33 | layout(std140) uniform LightsArray { SLight lights[MAX_NUM_TOTAL_LIGHTS]; }; 34 | 35 | vec3 Normal; 36 | vec3 FragPos; 37 | 38 | #include "common/lib.frag.glsl" 39 | 40 | void main() 41 | { 42 | // retrieve data from gbuffer 43 | FragPos = texture(gPosition, TexCoords).rgb; 44 | if(FragPos == vec3(0)) 45 | discard; 46 | 47 | vec3 viewDir = normalize(ViewPos - FragPos); 48 | 49 | vec3 normal = texture(gNormal, TexCoords).rgb; 50 | Normal = normal; 51 | 52 | vec4 matDiffuse = vec4(texture(gAlbedoSpec, TexCoords).rgb, 1.0); 53 | float matSpecular = texture(gAlbedoSpec, TexCoords).a; 54 | float matAmbient = texture(gMaterial, TexCoords).r; 55 | float matShininess = texture(gMaterial, TexCoords).g; 56 | 57 | #include "common/lighting.glsl" 58 | } 59 | -------------------------------------------------------------------------------- /Assets/Shaders/deferred-shading.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | layout (location = 1) in vec2 aTexCoords; 4 | 5 | out vec2 TexCoords; 6 | 7 | void main() 8 | { 9 | TexCoords = aTexCoords; 10 | gl_Position = vec4(aPos, 1.0); 11 | } -------------------------------------------------------------------------------- /Assets/Shaders/forward.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | #extension GL_ARB_shading_language_include : enable 3 | #extension GL_ARB_texture_cube_map_array : enable 4 | 5 | #include "common/header.glsl" 6 | 7 | #ifdef FRAG_HEADER_FILE 8 | #include FRAG_HEADER_FILE 9 | #endif 10 | 11 | out vec4 FragColor; 12 | 13 | //In order to calculate some basic lighting we need a few things per model basis, and a few things per fragment basis: 14 | uniform vec3 ViewPos; //The position of the view and/or of the player. 15 | uniform SMaterial material; 16 | 17 | in vec3 Normal; //The normal of the fragment is calculated in the vertex shader. 18 | in vec3 NormalTransposed; 19 | in vec3 FragPos; //The fragment position. 20 | #ifdef USE_VERTEX_UV 21 | in vec2 TexCoords; 22 | #endif 23 | #ifdef USE_VERTEX_COLOR 24 | in vec4 Color; 25 | #endif 26 | 27 | #ifdef USE_SHADOW 28 | uniform sampler2DArray DirectionalShadowMap; 29 | uniform samplerCubeArray PointShadowMap; 30 | #endif 31 | 32 | uniform int LightCount; 33 | layout(std140) uniform LightsArray { SLight lights[MAX_NUM_TOTAL_LIGHTS]; }; 34 | 35 | #include "common/lib.frag.glsl" 36 | 37 | void main() 38 | { 39 | vec3 viewDir = normalize(ViewPos - FragPos); 40 | vec4 matDiffuse = material.DiffuseColor; 41 | #ifndef OVERRIDE_GET_MATERIAL_DIFFUSE_FILE 42 | 43 | #ifdef USE_VERTEX_UV 44 | matDiffuse = texture(material.DiffuseMap, TexCoords) * material.DiffuseColor; 45 | #endif 46 | #ifdef USE_VERTEX_COLOR 47 | matDiffuse = Color * material.DiffuseColor; 48 | #endif 49 | 50 | #else 51 | #include OVERRIDE_GET_MATERIAL_DIFFUSE_FILE 52 | #endif 53 | 54 | float matSpecular = 0.0; 55 | #ifdef USE_VERTEX_UV 56 | matSpecular = texture(material.SpecularMap, TexCoords).r * material.SpecularStrength; 57 | #else 58 | matSpecular = material.SpecularStrength; 59 | #endif 60 | float matAmbient = material.Ambient; 61 | float matShininess = material.Shininess; 62 | 63 | //vec3 color = material.DiffuseColor; // solid color for debugging 64 | vec3 normal = normalize(Normal); 65 | 66 | #include "common/lighting.glsl" 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Assets/Shaders/forward.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec3 aPos; 4 | layout (location = 1) in vec3 aNormal; 5 | #ifdef USE_VERTEX_UV 6 | layout (location = 2) in vec2 aTexCoords; 7 | #ifdef USE_VERTEX_COLOR 8 | layout (location = 3) in vec4 aColor; 9 | #endif 10 | #else 11 | #ifdef USE_VERTEX_COLOR 12 | layout (location = 2) in vec4 aColor; 13 | #endif 14 | #endif 15 | 16 | uniform mat4 Model; 17 | uniform mat4 View; 18 | uniform mat4 Projection; 19 | uniform mat4 LightSpaceMatrix; 20 | 21 | out vec3 Normal; 22 | out vec3 NormalTransposed; 23 | out vec3 FragPos; 24 | #ifdef USE_VERTEX_UV 25 | out vec2 TexCoords; 26 | #endif 27 | #ifdef USE_VERTEX_COLOR 28 | out vec4 Color; 29 | #endif 30 | 31 | out vec4 FragPosLightSpace; 32 | 33 | void main() 34 | { 35 | gl_Position = vec4(aPos, 1.0) * Model * View * Projection; 36 | FragPos = vec3(vec4(aPos, 1.0) * Model); 37 | 38 | mat3 normalMatrix = transpose(inverse(mat3(Model))); 39 | Normal = aNormal * normalMatrix; 40 | NormalTransposed = normalMatrix * aNormal; 41 | 42 | #ifdef USE_VERTEX_UV 43 | TexCoords = aTexCoords; 44 | #endif 45 | #ifdef USE_VERTEX_COLOR 46 | Color = aColor; 47 | #endif 48 | 49 | // shadow 50 | FragPosLightSpace = vec4(FragPos, 1.0) * LightSpaceMatrix; // BUGFIX: aPos --> FragPos 51 | } -------------------------------------------------------------------------------- /Assets/Shaders/lines.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | in vec4 Color; 3 | out vec4 FragColor; 4 | 5 | void main() 6 | { 7 | FragColor = Color; // set all 4 vector values to 1.0 8 | } -------------------------------------------------------------------------------- /Assets/Shaders/lines.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0)in vec3 aPos; 4 | layout(location = 1)in vec4 aColor; 5 | 6 | uniform mat4 Model; 7 | uniform mat4 View; 8 | uniform mat4 Projection; 9 | 10 | out vec4 Color; 11 | 12 | void main() 13 | { 14 | gl_Position = vec4(aPos, 1.0) * Model * View * Projection; 15 | Color = aColor; 16 | } -------------------------------------------------------------------------------- /Assets/Shaders/screen-lines.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | in vec4 Color; 3 | out vec4 FragColor; 4 | 5 | void main() 6 | { 7 | FragColor = Color; // set all 4 vector values to 1.0 8 | } -------------------------------------------------------------------------------- /Assets/Shaders/screen-lines.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0)in vec3 aPos; 4 | layout(location = 1)in vec4 aColor; 5 | 6 | uniform mat4 Model; 7 | 8 | out vec4 Color; 9 | 10 | void main() 11 | { 12 | gl_Position = vec4(aPos, 1.0) * Model; 13 | Color = aColor; 14 | } -------------------------------------------------------------------------------- /Assets/Shaders/screen.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec2 TexCoords; 5 | 6 | uniform sampler2D screenTexture; 7 | 8 | void main() 9 | { 10 | vec4 color = texture(screenTexture, TexCoords); 11 | 12 | // Negative color (effect) 13 | //color = vec4(1-color.r, 1-color.g, 1-color.b, color.a); 14 | 15 | //color = vec4(0, (1-gl_FragCoord.z)*100000, 0, 1); 16 | 17 | // dispay shadow map: (override) 18 | //color = vec4(vec3(color.r), 1.0); 19 | 20 | FragColor = color; 21 | } -------------------------------------------------------------------------------- /Assets/Shaders/screen.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout(location = 0)in vec2 aPos; 3 | layout(location = 1)in vec2 aTexCoords; 4 | 5 | out vec2 TexCoords; 6 | uniform mat4 Model; 7 | 8 | void main() 9 | { 10 | gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0) * Model; 11 | TexCoords = aTexCoords; 12 | } -------------------------------------------------------------------------------- /Assets/Shaders/shadow-cube.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | #extension GL_ARB_shading_language_include : enable 3 | 4 | #include "common/header.glsl" 5 | 6 | in vec4 FragPos; 7 | 8 | uniform SLight Light; 9 | 10 | void main() 11 | { 12 | float lightDistance = length(FragPos.xyz - Light.Position); 13 | 14 | // map to [0;1] range by dividing by FarPlane 15 | lightDistance = lightDistance / Light.FarPlane; 16 | 17 | // write this as modified depth 18 | gl_FragDepth = lightDistance; 19 | } -------------------------------------------------------------------------------- /Assets/Shaders/shadow-cube.geom: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | #extension GL_ARB_shading_language_include : enable 3 | 4 | #include "common/header.glsl" 5 | 6 | layout(triangles)in; 7 | layout(triangle_strip, max_vertices = 18)out; 8 | 9 | uniform mat4 ShadowMatrices[6]; 10 | uniform SLight Light; 11 | 12 | out vec4 FragPos; // FragPos from GS (output per emitvertex) 13 | 14 | void main() 15 | { 16 | int offset = Light.ShadowLayer * 6; 17 | for(int face = 0; face < 6; ++ face) 18 | { 19 | gl_Layer = offset + face; // built-in variable that specifies to which face we render. 20 | for(int i = 0; i < 3; ++ i)// for each triangle's vertices 21 | { 22 | FragPos = gl_in[i].gl_Position; 23 | gl_Position = FragPos * ShadowMatrices[face]; 24 | EmitVertex(); 25 | } 26 | EndPrimitive(); 27 | } 28 | } -------------------------------------------------------------------------------- /Assets/Shaders/shadow-cube.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0)in vec3 aPos; 4 | 5 | uniform mat4 Model; 6 | 7 | void main() 8 | { 9 | gl_Position = vec4(aPos, 1.0) * Model; 10 | } 11 | -------------------------------------------------------------------------------- /Assets/Shaders/shadow-directional.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | //out vec4 FragColor; 4 | 5 | void main() 6 | { 7 | //gl_FragDepth = gl_FragCoord.z; 8 | //gl_FragDepth = 0.5; 9 | //FragColor = vec4(0,0,1,0.5); 10 | } -------------------------------------------------------------------------------- /Assets/Shaders/shadow-directional.geom: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout(triangles)in; 3 | layout (triangle_strip, max_vertices = 3) out; 4 | 5 | uniform int ShadowLayer; 6 | 7 | out vec4 FragPos; // FragPos from GS (output per emitvertex) 8 | 9 | void main() 10 | { 11 | gl_Layer = ShadowLayer; // built-in variable that specifies to which face we render. 12 | for(int i = 0; i < 3; ++ i)// for each triangle's vertices 13 | { 14 | gl_Position = gl_in[i].gl_Position; 15 | EmitVertex(); 16 | } 17 | EndPrimitive(); 18 | } -------------------------------------------------------------------------------- /Assets/Shaders/shadow-directional.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0)in vec3 aPos; 4 | layout(location = 1)in vec3 aNormal; 5 | layout(location = 2)in vec2 aTexCoords; 6 | 7 | uniform mat4 Model; 8 | uniform mat4 LightSpaceMatrix; 9 | 10 | void main() 11 | { 12 | gl_Position = vec4(aPos, 1.0) * Model * LightSpaceMatrix; 13 | } -------------------------------------------------------------------------------- /Assets/Shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | in vec3 TexCoords; 5 | 6 | uniform samplerCube Skybox; 7 | 8 | void main() 9 | { 10 | //gl_FragDepth = 1.0; // TODO, Pereformance: writing to gl_FragDepth disables all depth check optimizations 11 | FragColor = texture(Skybox, TexCoords.xzy); 12 | } -------------------------------------------------------------------------------- /Assets/Shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec3 aPos; 3 | 4 | out vec3 TexCoords; 5 | 6 | uniform mat4 Projection; 7 | uniform mat4 View; 8 | 9 | void main() 10 | { 11 | TexCoords = aPos; 12 | //TexCoords = aPos.xzy; 13 | gl_Position = vec4(aPos, 1.0) * View * Projection; 14 | gl_Position.z = gl_Position.w; // Force Depth Test at specific position 15 | } -------------------------------------------------------------------------------- /Assets/Shaders/white.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | void main() 5 | { 6 | FragColor = vec4(1.0); // set all 4 vector values to 1.0 7 | } -------------------------------------------------------------------------------- /Assets/Textures/desert-skybox/back.tga: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e92c756c9dc5c29a5303c9f0f0bf06372093916dc01c049f1d26fac63a146038 3 | size 786450 4 | -------------------------------------------------------------------------------- /Assets/Textures/desert-skybox/bottom.tga: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:d542a7950a97467e4335b774750a07f4afd4c516da67c8c9f8a1247c7eafaa17 3 | size 786450 4 | -------------------------------------------------------------------------------- /Assets/Textures/desert-skybox/front.tga: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:273d135ec41cdf16cd01421ae74b04dc2d4c77f14fdb51f6730d0c78bc13628e 3 | size 786450 4 | -------------------------------------------------------------------------------- /Assets/Textures/desert-skybox/left.tga: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:f16ad3adad0c1ea90ea78ec58f9e077587ad44d0f5bd0132a7d01b2ff16b2572 3 | size 786450 4 | -------------------------------------------------------------------------------- /Assets/Textures/desert-skybox/right.tga: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:1219c4259f63bf2407b56caa965a8290b105483b62dfd90c906dc9cab429e7ec 3 | size 786450 4 | -------------------------------------------------------------------------------- /Assets/Textures/desert-skybox/top.tga: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e3e80bad6d7422105de1a103172f35dc74e231a6066cd4c405278305b40d316d 3 | size 786450 4 | -------------------------------------------------------------------------------- /Assets/Textures/water-skybox/back.jpg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:da4938039f6a536c7db3fba35ffdd905861ce36608ceadf4412479c5fcacd138 3 | size 740068 4 | -------------------------------------------------------------------------------- /Assets/Textures/water-skybox/bottom.jpg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:088f074272f731abdc9da601cf925aeb80060d048ef33d2a60dd1b215d41feec 3 | size 280589 4 | -------------------------------------------------------------------------------- /Assets/Textures/water-skybox/front.jpg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:dd6f9d8bb04466c06387e8dc736eb453bcb92a09750be520b8d5e00e8bd484fe 3 | size 473329 4 | -------------------------------------------------------------------------------- /Assets/Textures/water-skybox/left.jpg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:087df0cdc2d28b7e9f5f6b2d82795aa6b10684ce51d3104e8dd3c128b485a960 3 | size 601885 4 | -------------------------------------------------------------------------------- /Assets/Textures/water-skybox/right.jpg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:d4a1b6fd9daffdfb6c42d0dc169cffba7129a8d7da3fab52531e4df4a203191d 3 | size 538038 4 | -------------------------------------------------------------------------------- /Assets/Textures/water-skybox/top.jpg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:ff0aa54d15b7c69fc6fae738f943854950a67afd7b1a4e297809668b2380e055 3 | size 346139 4 | -------------------------------------------------------------------------------- /Assets/Textures/wood.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:d75e076385ddec163df04d0d07d7620b05c141722b54a94c62b5a1e9391d027f 3 | size 1641845 4 | -------------------------------------------------------------------------------- /Assets/Textures/woodenbox.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:906c9243fc09fa17c848fcfb695bbfb35c39b4a7441308c17f54dc4ddc534566 3 | size 431879 4 | -------------------------------------------------------------------------------- /Assets/Textures/woodenbox_specular.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:b380731430ebe57ddb0e822f30ef09647addeeeffa6617e59704a5e6aa0b081a 3 | size 144081 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### 1.0.11 4 | 5 | * Added RoundedCube Component 6 | * Fixed Bugs in Light Component 7 | * Added Voronoi Generator 8 | 9 | ### 1.0.9 10 | 11 | * Check Cache version 12 | * Added UISlider 13 | * Added OpenAL 14 | * Added some Audio Modules 15 | * Implemented Scaled UI Pixels for resolution independent positions 16 | * Fixed Default Font Selection Bug 17 | 18 | ### 1.0.8 19 | 20 | * Fixed Shadows if they are out of shadow map 21 | * Corrected Directional light 22 | * Removed SetConfig() from public API. 23 | * Preparation for OpenAL 24 | 25 | ### 1.0.7 26 | 27 | * Renamed Animataion to Tween. Make Tween generic. 28 | * Skip unnecessary uniform set 29 | * Cache Shaders (deduplication) 30 | * Cache Vertex Data (deduplication) 31 | * new tweening system 32 | 33 | ### 1.0.6 34 | Fixed: 35 | 36 | * Detection of AppRootDir. Dtected wrong .cache directory. 37 | 38 | ### 1.0.5 39 | 40 | Refactor: 41 | 42 | * GameMaterial --> Material 43 | * RenderApplication --> Application 44 | * GameShader --> Shader 45 | * GameObject --> SceneObject 46 | * GameContext --> SceneContext 47 | 48 | * Moved Cameras to Aximo namespace. 49 | * Moved Mesh classes to Aximo namespace. 50 | -------------------------------------------------------------------------------- /Common/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | [assembly: InternalsVisibleTo("Aximo.Render")] 7 | [assembly: InternalsVisibleTo("AxEngine")] 8 | [assembly: InternalsVisibleTo("AxTests")] 9 | -------------------------------------------------------------------------------- /Common/AxPixelFormat.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public enum AxPixelFormat 7 | { 8 | None, 9 | Rgba32, 10 | Bgra32, 11 | Rgb24, 12 | Bgr24, 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Common/AxPrimitiveType.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public enum AxPrimitiveType 7 | { 8 | Triangles, 9 | Lines, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Common/Buffers/BufferData.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace Aximo 8 | { 9 | public abstract class BufferData 10 | { 11 | public abstract int Length { get; } 12 | public abstract int ElementSize { get; } 13 | 14 | public abstract GCHandle CreateHandle(); 15 | 16 | public static BufferData1D Create(T[] data) 17 | where T : struct 18 | { 19 | return new BufferData1D(data); 20 | } 21 | 22 | public static BufferData2D Create(T[,] data) 23 | where T : struct 24 | { 25 | return new BufferData2D(data); 26 | } 27 | 28 | public static BufferData3D Create(T[,,] data) 29 | where T : struct 30 | { 31 | return new BufferData3D(data); 32 | } 33 | 34 | public int Bytes => Length * ElementSize; 35 | 36 | public abstract BufferData Clone(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Common/Buffers/BufferData1D.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public abstract class BufferData1D : BufferData 7 | { 8 | public abstract int SizeX { get; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Common/Buffers/BufferData1D{T}.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace Aximo 8 | { 9 | public class BufferData1D : BufferData1D 10 | where T : struct 11 | { 12 | public BufferData1D(T[] data) 13 | { 14 | SetData(data); 15 | } 16 | 17 | public void SetData(T[] data) 18 | { 19 | _Data = data; 20 | _Length = data.Length; 21 | _ElementSize = Marshal.SizeOf(); 22 | _Memory = _Data.AsMemory(); 23 | } 24 | 25 | public override GCHandle CreateHandle() 26 | { 27 | return GCHandle.Alloc(_Data, GCHandleType.Pinned); 28 | } 29 | 30 | private Memory _Memory; 31 | public Memory Memory => _Memory; 32 | 33 | public Span Span => new Span(_Data); 34 | 35 | private T[] _Data; 36 | public T this[int index] 37 | { 38 | get { return _Data[index]; } 39 | set { _Data[index] = value; } 40 | } 41 | 42 | public override int GetHashCode() 43 | { 44 | return Hashing.FNV32(Span); 45 | } 46 | 47 | private int _Length; 48 | public override int Length => _Length; 49 | 50 | public override int SizeX => _Length; 51 | 52 | private int _ElementSize; 53 | public override int ElementSize => _ElementSize; 54 | 55 | public override BufferData Clone() 56 | { 57 | var copy = (T[])_Data.Clone(); 58 | return new BufferData1D(copy); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Common/Buffers/BufferData2D.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public abstract class BufferData2D : BufferData 7 | { 8 | public abstract int SizeX { get; } 9 | public abstract int SizeY { get; } 10 | 11 | public int Width => SizeX; 12 | public int Height => SizeY; 13 | 14 | public AxPixelFormat PixelFormat { get; set; } 15 | 16 | public abstract void FlipY(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Common/Buffers/BufferData3D.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public abstract class BufferData3D : BufferData 7 | { 8 | public abstract int SizeX { get; } 9 | public abstract int SizeY { get; } 10 | public abstract int SizeZ { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Common/Buffers/BufferData3D{T}.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace Aximo 8 | { 9 | public class BufferData3D : BufferData3D 10 | where T : struct 11 | { 12 | public BufferData3D(T[,,] data) 13 | { 14 | SetData(data); 15 | } 16 | 17 | public void SetData(T[,,] data) 18 | { 19 | _Data = data; 20 | _Length = data.Length; 21 | _SizeX = data.GetUpperBound(0) + 1; 22 | _SizeY = data.GetUpperBound(1) + 1; 23 | _SizeZ = data.GetUpperBound(2) + 1; 24 | _ElementSize = Marshal.SizeOf(); 25 | } 26 | 27 | private T[,,] _Data; 28 | 29 | public T this[int x, int y, int z] 30 | { 31 | get { return _Data[x, y, z]; } 32 | set { _Data[x, y, z] = value; } 33 | } 34 | 35 | private int _Length; 36 | public override int Length => _Length; 37 | 38 | private int _SizeX; 39 | public override int SizeX => _SizeX; 40 | 41 | private int _SizeY; 42 | public override int SizeY => _SizeY; 43 | 44 | private int _SizeZ; 45 | public override int SizeZ => _SizeZ; 46 | 47 | public override GCHandle CreateHandle() 48 | { 49 | return GCHandle.Alloc(_Data, GCHandleType.Pinned); 50 | } 51 | 52 | private int _ElementSize; 53 | public override int ElementSize => _ElementSize; 54 | 55 | public override BufferData Clone() 56 | { 57 | throw new NotImplementedException(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Common/Camera/OrthographicCamera.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo 7 | { 8 | public class OrthographicCamera : Camera 9 | { 10 | public override CameraType Type => CameraType.Orthographic; 11 | 12 | private Vector2 _Size = new Vector2(20, 20); 13 | public Vector2 Size 14 | { 15 | get { return _Size; } 16 | set { if (_Size == value) return; _Size = value; OnCameraChanged(); } 17 | } 18 | 19 | public OrthographicCamera(Vector3 position) : base(position) 20 | { 21 | } 22 | 23 | protected override Matrix4 GetProjectionMatrix() 24 | { 25 | // float near_plane = 0.01f; 26 | // float FarPlane = 7.5f; 27 | 28 | //return Matrix4.CreateOrthographicOffCenter(-Size.X / 2, Size.X / 2, -Size.Y / 2, Size.Y / 2, NearPlane, FarPlane); 29 | return Matrix4.CreateOrthographic(Size.X, Size.Y, NearPlane, FarPlane); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Common/Camera/PerspectiveFieldOfViewCamera.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo 7 | { 8 | public class PerspectiveFieldOfViewCamera : Camera 9 | { 10 | public override CameraType Type => CameraType.PerspectiveFieldOfView; 11 | 12 | public PerspectiveFieldOfViewCamera(Vector3 position, float aspectRatio) : base(position) 13 | { 14 | AspectRatio = aspectRatio; 15 | } 16 | 17 | public PerspectiveFieldOfViewCamera(Vector3 position) : base(position) 18 | { 19 | } 20 | 21 | protected override Matrix4 GetProjectionMatrix() 22 | { 23 | return Matrix4.CreatePerspectiveFieldOfView(FovInternal, AspectRatio, NearPlane, FarPlane); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Common/Common.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Aximo 4 | AxCommon 5 | netcoreapp3.1 6 | CS0162 7 | true 8 | ..\props\default.ruleset 9 | 10 | 11 | 12 | 13 | Aximo.Common 14 | $(DependencyDescription) 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Common/DebugHelper.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Threading; 5 | 6 | namespace Aximo 7 | { 8 | public static class DebugHelper 9 | { 10 | private static Serilog.ILogger Log = Aximo.Log.ForContext(nameof(DebugHelper)); 11 | 12 | public static void LogThreadInfo(string message) 13 | { 14 | LogThreadInfo(Thread.CurrentThread, message); 15 | } 16 | public static void LogThreadInfo(Thread th, string message) 17 | { 18 | if (message == th.Name) 19 | message = ""; 20 | Log.Info("Thread #{ThreadId} {ThreadName} {Message}", th.ManagedThreadId, th.Name, message); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Common/EventCounter.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Diagnostics; 6 | 7 | namespace Aximo 8 | { 9 | public class EventCounter 10 | { 11 | private Stopwatch Watch = new Stopwatch(); 12 | private double FrameCount = 0; 13 | private double DeltaTime = 0.0; 14 | private double UpdateRate = 4.0; // 4 updates per sec. 15 | 16 | private double _Fps = 0.0; 17 | public double EventsPerSecond => _Fps; 18 | 19 | public TimeSpan Elapsed { get; private set; } 20 | 21 | public void Reset() 22 | { 23 | Watch.Restart(); 24 | } 25 | 26 | public void Tick() 27 | { 28 | Watch.Stop(); 29 | Elapsed = Watch.Elapsed; 30 | FrameCount++; 31 | DeltaTime += Watch.ElapsedMilliseconds / 1000.0; 32 | if (DeltaTime > 1.0 / UpdateRate) 33 | { 34 | _Fps = FrameCount / DeltaTime; 35 | FrameCount = 0; 36 | DeltaTime -= 1.0 / UpdateRate; 37 | } 38 | Watch.Restart(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Common/Extensions/BoxExtensions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | using SixLabors.ImageSharp; 6 | 7 | namespace Aximo 8 | { 9 | public static class BoxExtensions 10 | { 11 | public static RectangleF ToRectangleF(this Box2 value) 12 | { 13 | return new RectangleF(value.Min.X, value.Min.Y, value.Size.X, value.Size.Y); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Common/Extensions/DictionaryExtensions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Aximo 8 | { 9 | public static class DictionaryExtensions 10 | { 11 | public static bool TryAdd(this IDictionary dict, TKey key, TValue value) 12 | { 13 | lock (dict) 14 | { 15 | if (dict.ContainsKey(key)) 16 | return false; 17 | 18 | dict.Add(key, value); 19 | return true; 20 | } 21 | } 22 | 23 | public static void Set(this IDictionary dict, TKey key, TValue value) 24 | { 25 | lock (dict) 26 | { 27 | if (dict.ContainsKey(key)) 28 | dict[key] = value; 29 | else 30 | dict.Add(key, value); 31 | } 32 | } 33 | 34 | public static void Set(this IDictionary dict, TKey key, Func getValue) 35 | { 36 | lock (dict) 37 | { 38 | if (dict.ContainsKey(key)) 39 | dict[key] = getValue(); 40 | else 41 | dict.Add(key, getValue()); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Common/Extensions/StreamExtensions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.IO; 5 | 6 | namespace Aximo 7 | { 8 | public static class StreamExtensions 9 | { 10 | public static byte[] ReadToEnd(this Stream input) 11 | { 12 | byte[] buffer = new byte[16 * 1024]; 13 | using (MemoryStream ms = new MemoryStream()) 14 | { 15 | int read; 16 | while ((read = input.Read(buffer, 0, buffer.Length)) > 0) 17 | { 18 | ms.Write(buffer, 0, read); 19 | } 20 | return ms.ToArray(); 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Common/Extensions/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public static class StringExtensions 7 | { 8 | public static bool IsUnset(this string value) 9 | { 10 | return string.IsNullOrEmpty(value); 11 | } 12 | 13 | public static bool IsSet(this string value) 14 | { 15 | return !string.IsNullOrEmpty(value); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Common/Helper/BoxHelper.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo 7 | { 8 | public static class BoxHelper 9 | { 10 | public static Box2 FromSize(Vector2 location, Vector2 size) 11 | { 12 | return new Box2(location, location + size); 13 | } 14 | 15 | public static Box2 FromCenteredSize(Vector2 center, Vector2 size) 16 | { 17 | return new Box2 18 | { 19 | Center = center, 20 | Size = size, 21 | }; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Common/Helper/VectorHelper.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo 7 | { 8 | public static class VectorHelper 9 | { 10 | /// 11 | /// The wedge product of two vectors. 12 | /// This creates a bivector that represents the plane formed by these vectors. 13 | /// 14 | /// The first vector. 15 | /// The second vector. 16 | /// The resulting bivector. 17 | public static BiVector3d Wedge(Vector3 v1, Vector3 v2) 18 | { 19 | Wedge(v1, v2, out BiVector3d bv); 20 | return bv; 21 | } 22 | 23 | /// 24 | /// The wedge product of two vectors. 25 | /// This creates a bivector that represents the plane formed by these vectors. 26 | /// 27 | public static void Wedge(in Vector3 v1, in Vector3 v2, out BiVector3d bv) 28 | { 29 | bv.b01 = (v1.X * v2.Y) - (v1.Y * v2.X); 30 | bv.b02 = (v1.X * v2.Z) - (v1.Z * v2.X); 31 | bv.b12 = (v1.Y * v2.Z) - (v1.Z * v2.Y); 32 | } 33 | 34 | public static void Wedge(in Vector4 p, in Vector4 q, out BiVector4d bv) 35 | { 36 | bv.WX = q.X - p.X; 37 | bv.WY = q.Y - p.Y; 38 | bv.WZ = q.Z - p.Z; 39 | bv.YZ = (p.Y * q.Z) - (p.Z * q.Y); 40 | bv.ZX = (p.Z * q.X) - (p.X * q.Z); 41 | bv.XY = (p.X * q.Y) - (p.Y * q.Y); 42 | } 43 | 44 | public static void AntiWedge(in Vector4 v, in AntiVector4d tv, out float s) 45 | { 46 | s = (v.X * tv.NotX) + (v.Y * tv.NotY) + (v.Z * tv.NotZ); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Common/IVisitor.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public interface IVisitor 7 | { 8 | void Visit(IVisitorNode node); 9 | } 10 | 11 | public interface IVisitorNode 12 | { 13 | void Accept(IVisitor visitor); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Common/Log.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Serilog; 5 | 6 | namespace Aximo 7 | { 8 | public static class Log 9 | { 10 | private static bool Initialized; 11 | public static void Init() 12 | { 13 | if (Initialized) 14 | return; 15 | 16 | Serilog.Log.Logger = new LoggerConfiguration() 17 | .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss.fff} {Level:u3}] <{SourceContext}> {Message:lj}{NewLine}{Exception}") 18 | .MinimumLevel.Verbose() 19 | .CreateLogger(); 20 | 21 | Initialized = true; 22 | } 23 | 24 | public static ILogger ForContext() 25 | { 26 | Init(); 27 | return Serilog.Log.ForContext("SourceContext", typeof(T).Name); 28 | } 29 | 30 | public static ILogger ForContext(string sourceContext) 31 | { 32 | Init(); 33 | return Serilog.Log.ForContext("SourceContext", sourceContext); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Common/Mesh/ArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Aximo.VertexData; 8 | 9 | namespace Aximo 10 | { 11 | public static class ArrayExtensions 12 | { 13 | public static T[] EnsureSize(this T[] input, int length) 14 | { 15 | if (input == null) 16 | input = Array.Empty(); 17 | if (input.Length >= length) 18 | return input; 19 | var ar = new T[length]; 20 | input.CopyTo(ar, 0); 21 | return ar; 22 | } 23 | 24 | public static T[] AppendElement(this T[] input, T element) 25 | { 26 | if (input == null) 27 | input = Array.Empty(); 28 | var ar = EnsureSize(input, input.Length + 1); 29 | ar[ar.Length - 1] = element; 30 | return ar; 31 | } 32 | 33 | public static T[] RemoveElement(this T[] input, T element) 34 | { 35 | // TODO: Don't use List<> 36 | var list = new List(input); 37 | list.Remove(element); 38 | return list.ToArray(); 39 | } 40 | 41 | public static bool HasIndex(this T[] input, int index) 42 | { 43 | return index >= 0 && input.Length > index; 44 | } 45 | 46 | public static T TryGet(this T[] input, int index) 47 | { 48 | if (!HasIndex(input, index)) 49 | return default; 50 | 51 | return input[index]; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Common/Mesh/DynamicArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace Aximo 8 | { 9 | public static class DynamicArrayExtensions 10 | { 11 | internal static void SetValueWithExpand(this IDynamicArray array, int index, T value) 12 | { 13 | array.SetLength(index + 1); 14 | array[index] = value; 15 | } 16 | 17 | internal static T GetValueWithExpand(this IDynamicArray array, int index) 18 | { 19 | array.SetLength(index + 1); 20 | return array[index]; 21 | } 22 | 23 | public static void Clear(this IDynamicArray array) 24 | { 25 | array.SetLength(0); 26 | } 27 | 28 | internal static bool Contains(this IDynamicArray array, T value) 29 | { 30 | var length = array.Count; 31 | for (var i = 0; i < length; i++) 32 | if (array[i].Equals(value)) 33 | return true; 34 | return false; 35 | } 36 | 37 | internal static bool Remove(this IDynamicArray array, T value) 38 | { 39 | throw new NotImplementedException(); 40 | } 41 | 42 | internal static void RemoveAt(this IDynamicArray array, int index) 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | 47 | public static T[] ToArray(this IDynamicArray array) 48 | { 49 | var ar = new T[array.Count]; 50 | var count = array.Count; 51 | for (var i = 0; i < count; i++) 52 | ar[i] = array[i]; 53 | return ar; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Common/Mesh/FaceExtensions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using Aximo.VertexData; 7 | 8 | namespace Aximo 9 | { 10 | public static class FaceExtensions 11 | { 12 | public static IEnumerable ToIndiciesList(this IList> faces) 13 | where T : IVertex 14 | { 15 | // TODO: Improve performance 16 | return faces.SelectMany(face => face.GetIndicies()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Common/Mesh/IArray.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | 7 | namespace Aximo 8 | { 9 | public interface IArray 10 | { 11 | T this[int index] { get; set; } 12 | int Count { get; } 13 | } 14 | 15 | internal class ArrayEnumerator : IEnumerator 16 | { 17 | private IArray Array; 18 | public ArrayEnumerator(IArray array) 19 | { 20 | Array = array; 21 | } 22 | 23 | private int Index = -1; 24 | 25 | public T Current => Array[Index]; 26 | 27 | object IEnumerator.Current => Current; 28 | 29 | public void Dispose() 30 | { 31 | } 32 | 33 | public bool MoveNext() 34 | { 35 | if (Index >= Array.Count - 1) 36 | return false; 37 | Index++; 38 | return true; 39 | } 40 | 41 | public void Reset() 42 | { 43 | Index = -1; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Common/Mesh/IDynamicArray.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public interface IDynamicArray : IArray 7 | { 8 | void SetLength(int length); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Common/Mesh/InternalMeshFace.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | 6 | namespace Aximo 7 | { 8 | // public unsafe struct Triangle 9 | // { 10 | // private fixed int blah[3]; 11 | // public Span Points => new Span(Unsafe.AsPointer(ref blah[0], 3)); 12 | // } 13 | 14 | internal struct InternalMeshFace 15 | { 16 | public int StartIndex; 17 | public int Count; 18 | public int MaterialId; 19 | 20 | public int this[int faceVertexIndex] 21 | { 22 | get 23 | { 24 | if (faceVertexIndex >= Count) 25 | throw new IndexOutOfRangeException(); 26 | 27 | return StartIndex + faceVertexIndex; 28 | } 29 | } 30 | 31 | public bool IsPoint => Count == 1; 32 | public bool IsLine => Count == 2; 33 | public bool IsTriangle => Count == 3; 34 | public bool IsQuad => Count == 4; 35 | public bool IsNgon => Count > 4; 36 | 37 | public MeshFaceType Type 38 | { 39 | get 40 | { 41 | var cnt = Count; 42 | if (cnt > 4) 43 | return MeshFaceType.Ngon; 44 | else 45 | return (MeshFaceType)cnt; 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Common/Mesh/MeshComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using OpenToolkit.Mathematics; 6 | 7 | namespace Aximo 8 | { 9 | public abstract class MeshComponent 10 | { 11 | public virtual MeshComponentType Type { get; protected set; } 12 | 13 | public static MeshComponent Create(MeshComponentType componentType) 14 | { 15 | switch (componentType) 16 | { 17 | case MeshComponentType.Position: 18 | return new MeshComponent(componentType); 19 | case MeshComponentType.Normal: 20 | return new MeshComponent(componentType); 21 | case MeshComponentType.Color: 22 | return new MeshComponent(componentType); 23 | case MeshComponentType.UV: 24 | return new MeshComponent(componentType); 25 | default: 26 | throw new ArgumentOutOfRangeException(nameof(componentType)); 27 | } 28 | } 29 | 30 | public abstract int Count { get; } 31 | 32 | public abstract void AddRange(MeshComponent src, int start, int count); 33 | 34 | public abstract MeshComponent CloneEmpty(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Common/Mesh/MeshComponentType.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public enum MeshComponentType 7 | { 8 | Position, 9 | Normal, 10 | UV, 11 | Color, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common/Mesh/MeshComponents/MeshColorComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using Aximo.VertexData; 6 | using OpenToolkit.Mathematics; 7 | 8 | namespace Aximo 9 | { 10 | public class MeshColorComponent : MeshComponent 11 | { 12 | public MeshColorComponent() 13 | : base(MeshComponentType.Color) 14 | { 15 | } 16 | 17 | public override MeshComponent CloneEmpty() => new MeshColorComponent(); 18 | public override void AddRange(IEnumerable values) 19 | { 20 | foreach (var v in values) 21 | if (v is IVertexColor p) 22 | Add(p.Color); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Common/Mesh/MeshComponents/MeshNormalComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using Aximo.VertexData; 6 | using OpenToolkit.Mathematics; 7 | 8 | namespace Aximo 9 | { 10 | public class MeshNormalComponent : MeshComponent 11 | { 12 | public MeshNormalComponent() 13 | : base(MeshComponentType.Normal) 14 | { 15 | } 16 | 17 | public override MeshComponent CloneEmpty() => new MeshNormalComponent(); 18 | 19 | public override void AddRange(IEnumerable values) 20 | { 21 | foreach (var v in values) 22 | if (v is IVertexNormal p) 23 | Add(p.Normal); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Common/Mesh/MeshComponents/MeshPosition2Component.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Aximo.VertexData; 8 | using OpenToolkit.Mathematics; 9 | 10 | namespace Aximo 11 | { 12 | public class MeshPosition2Component : MeshPositionComponent 13 | { 14 | public MeshPosition2Component() 15 | { 16 | } 17 | 18 | public override MeshComponent CloneEmpty() => new MeshPosition2Component(); 19 | 20 | public MeshPosition2Component(ICollection values) 21 | { 22 | AddRange(values.Select(v => v.Position)); 23 | } 24 | 25 | public override void AddRange(IEnumerable values) 26 | { 27 | foreach (var v in values) 28 | if (v is IVertexPosition2 p) 29 | Add(p.Position); 30 | } 31 | 32 | public Box2 Bounds { get; private set; } 33 | 34 | public override void CalculateBounds() 35 | { 36 | float minX = 0; 37 | float minY = 0; 38 | 39 | float maxX = 0; 40 | float maxY = 0; 41 | 42 | for (var i = 0; i < Values.Count; i++) 43 | { 44 | var pos = Values[i]; 45 | 46 | minX = MathF.Min(minX, pos.X); 47 | minY = MathF.Min(minY, pos.Y); 48 | 49 | maxX = MathF.Min(maxX, pos.X); 50 | maxY = MathF.Min(maxY, pos.Y); 51 | } 52 | 53 | Bounds = new Box2(minX, minY, maxX, maxY); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Common/Mesh/MeshComponents/MeshPosition3Component.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Aximo.VertexData; 8 | using OpenToolkit.Mathematics; 9 | 10 | namespace Aximo 11 | { 12 | public class MeshPosition3Component : MeshPositionComponent 13 | { 14 | public MeshPosition3Component() 15 | { 16 | } 17 | 18 | public MeshPosition3Component(ICollection values) 19 | { 20 | AddRange(values.Select(v => v.Position)); 21 | } 22 | 23 | public override MeshComponent CloneEmpty() => new MeshPosition3Component(); 24 | 25 | public void AddRange(IEnumerable values) 26 | { 27 | _Values.AddRange(values.Select(v => v.Position)); 28 | } 29 | 30 | public override void AddRange(IEnumerable values) 31 | { 32 | foreach (var v in values) 33 | if (v is IVertexPosition3 p) 34 | Add(p.Position); 35 | } 36 | 37 | public Box3 Bounds { get; private set; } 38 | 39 | public override void CalculateBounds() 40 | { 41 | float minX = 0; 42 | float minY = 0; 43 | float minZ = 0; 44 | 45 | float maxX = 0; 46 | float maxY = 0; 47 | float maxZ = 0; 48 | 49 | for (var i = 0; i < Values.Count; i++) 50 | { 51 | var pos = Values[i]; 52 | 53 | minX = MathF.Min(minX, pos.X); 54 | minY = MathF.Min(minY, pos.Y); 55 | minZ = MathF.Min(minZ, pos.Z); 56 | 57 | maxX = MathF.Min(maxX, pos.X); 58 | maxY = MathF.Min(maxY, pos.Y); 59 | maxZ = MathF.Min(maxZ, pos.Z); 60 | } 61 | 62 | Bounds = new Box3(minX, minY, minZ, maxX, maxY, maxZ); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Common/Mesh/MeshComponents/MeshPositionComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public abstract class MeshPositionComponent : MeshComponent 7 | where T : unmanaged 8 | { 9 | public MeshPositionComponent() 10 | : base(MeshComponentType.Position) 11 | { 12 | } 13 | 14 | public abstract void CalculateBounds(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Common/Mesh/MeshComponents/MeshUVComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using Aximo.VertexData; 6 | using OpenToolkit.Mathematics; 7 | 8 | namespace Aximo 9 | { 10 | public class MeshUVComponent : MeshComponent 11 | { 12 | public MeshUVComponent() 13 | : base(MeshComponentType.UV) 14 | { 15 | } 16 | 17 | public override MeshComponent CloneEmpty() => new MeshUVComponent(); 18 | 19 | public override void AddRange(IEnumerable values) 20 | { 21 | foreach (var v in values) 22 | if (v is IVertexUV p) 23 | Add(p.UV); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Common/Mesh/MeshFace.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using Aximo.VertexData; 6 | 7 | namespace Aximo 8 | { 9 | public struct MeshFace 10 | where T : IVertex 11 | { 12 | // Global List 13 | private IList VertexView; 14 | private IList Indicies; 15 | 16 | internal InternalMeshFace InternalFace; 17 | 18 | public int[] GetIndicies() 19 | { 20 | var array = new int[Count]; 21 | CopyIndiciesTo(array, 0); 22 | return array; 23 | } 24 | 25 | public void CopyIndiciesTo(int[] array, int arrayIndex) 26 | { 27 | for (var i = 0; i < Count; i++) 28 | array[arrayIndex + i] = GetIndex(i); 29 | } 30 | 31 | internal MeshFace(IList vertexView, IList indicies, InternalMeshFace internalFace) 32 | { 33 | VertexView = vertexView; 34 | Indicies = indicies; 35 | InternalFace = internalFace; 36 | } 37 | 38 | public int Count => InternalFace.Count; 39 | 40 | public bool IsPoint => InternalFace.IsPoint; 41 | public bool IsLine => InternalFace.IsLine; 42 | public bool IsTriangle => InternalFace.IsTriangle; 43 | public bool IsQuad => InternalFace.IsQuad; 44 | public bool IsNgon => InternalFace.IsNgon; 45 | public MeshFaceType Type => InternalFace.Type; 46 | 47 | public int GetIndex(int index) => Indicies[InternalFace[index]]; 48 | 49 | public T this[int index] => VertexView[GetIndex(index)]; 50 | 51 | public int MaterialId => InternalFace.MaterialId; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Common/Mesh/MeshFaceType.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo 5 | { 6 | public enum MeshFaceType 7 | { 8 | None = 0, 9 | Point = 1, 10 | Line = 2, 11 | Triangle = 3, 12 | Quad = 4, 13 | Ngon = 5, 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Common/Mesh/MeshVertexEnumerator.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using Aximo.VertexData; 7 | 8 | namespace Aximo 9 | { 10 | internal class MeshVertexEnumerator : IEnumerator 11 | where T : IVertex 12 | { 13 | public MeshVertexEnumerator(Mesh mesh) 14 | { 15 | Mesh = mesh; 16 | Visitor = VertexVisitor.CreateVisitor(mesh); 17 | } 18 | 19 | private Mesh Mesh; 20 | 21 | internal VertexVisitor Visitor; 22 | 23 | public T Current => (T)Visitor.Value; 24 | 25 | object IEnumerator.Current => Visitor.Value; 26 | 27 | public void Dispose() 28 | { 29 | Visitor?.Dispose(); 30 | Visitor = null; 31 | } 32 | 33 | public bool MoveNext() 34 | { 35 | if (Visitor.Index >= Mesh.VertexCount - 1) 36 | return false; 37 | 38 | Visitor.Index++; 39 | return true; 40 | } 41 | 42 | public void Reset() 43 | { 44 | Visitor.Index = -1; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Common/Mesh/MeshVisitors/VertexPosition3Visitor.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.VertexData; 5 | using OpenToolkit.Mathematics; 6 | 7 | namespace Aximo 8 | { 9 | internal class VertexPosition3Visitor : VertexVisitor, IVertexPosition3 10 | { 11 | private IDynamicArray PositionComponent; 12 | 13 | public VertexPosition3Visitor(Mesh mesh) : base(mesh) 14 | { 15 | PositionComponent = mesh.GetComponent(); 16 | } 17 | 18 | public override void SetLength(int length) 19 | { 20 | PositionComponent.SetLength(length); 21 | } 22 | 23 | private void EnsureSize() 24 | { 25 | SetLength(Index + 1); 26 | } 27 | 28 | public Vector3 Position 29 | { 30 | get => PositionComponent.GetValueWithExpand(Index); 31 | set => PositionComponent.SetValueWithExpand(Index, value); 32 | } 33 | protected override void Set(IVertex vertex) 34 | { 35 | if (vertex is IVertexPosition3 position) 36 | Position = position.Position; 37 | } 38 | 39 | public void SetPosition(IVertexPosition3 source) 40 | { 41 | Position = source.Position; 42 | } 43 | 44 | public void SetPosition(Vector3 source) 45 | { 46 | Position = source; 47 | } 48 | 49 | public override IVertex Clone() => new VertexDataPos(Position); 50 | 51 | IVertexPosition3 IVertexPosition3.Clone() => new VertexDataPos(Position); 52 | IVertexPosition IVertexPosition.Clone() => new VertexDataPos(Position); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Common/PathBuilder.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Linq; 6 | using OpenToolkit.Mathematics; 7 | 8 | namespace Aximo 9 | { 10 | public static class PathBuilder 11 | { 12 | public static Vector2[] Quad() 13 | { 14 | return new Vector2[] 15 | { 16 | new Vector2(-0.5f, -0.5f), 17 | new Vector2(0.5f, -0.5f), 18 | new Vector2(0.5f, 0.5f), 19 | new Vector2(-0.5f, 0.5f), 20 | }; 21 | } 22 | 23 | public static Vector2[] Circle(int slices = 8) 24 | { 25 | var points = new Vector2[slices]; 26 | for (var i = 0; i < slices; i++) 27 | { 28 | var angle = MathF.PI * 2 / slices * i; 29 | points[i].X = MathF.Cos(angle) * 0.5f; 30 | points[i].Y = MathF.Sin(angle) * 0.5f; 31 | } 32 | return points; 33 | } 34 | 35 | public static Vector2[] ClosePath(this Vector2[] points) 36 | { 37 | if (points[0].Approximately(points[points.Length - 1])) 38 | return points; 39 | 40 | return points.Append(points[0]).ToArray(); 41 | } 42 | 43 | public static Vector3[] ToVector3(this Vector2[] points) 44 | { 45 | return points.Select(p => new Vector3(p)).ToArray(); 46 | } 47 | 48 | public static bool Approximately(this in Vector2 value, in Vector2 other) 49 | { 50 | return AxMath.Approximately(value.X, other.X) && AxMath.Approximately(value.Y, other.Y); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Common/Ray.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo 7 | { 8 | public struct Ray 9 | { 10 | private Vector3 _Origin; 11 | private Vector3 _Direction; 12 | 13 | public Ray(Vector3 origin, Vector3 direction) 14 | { 15 | _Origin = origin; 16 | _Direction = direction.Normalized(); 17 | } 18 | 19 | public static Ray FromPoints(Vector3 origin, Vector3 destination) 20 | { 21 | return new Ray(origin, destination - origin); 22 | } 23 | 24 | public Vector3 Origin 25 | { 26 | get { return _Origin; } 27 | set { _Origin = value; } 28 | } 29 | 30 | public Vector3 Direction 31 | { 32 | get { return _Direction; } 33 | set { _Direction = value.Normalized(); } 34 | } 35 | 36 | /// 37 | /// Returns a point at 'distance' units along the ray. 38 | /// 39 | public Vector3 GetPoint(float distance) 40 | { 41 | return _Origin + (_Direction * distance); 42 | } 43 | 44 | public override string ToString() 45 | { 46 | return $"[{_Origin}, {_Direction}]"; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Common/SharedLib.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Globalization; 6 | using SixLabors.Fonts; 7 | 8 | namespace Aximo 9 | { 10 | public static class SharedLib 11 | { 12 | public static CultureInfo LocaleInvariant = CultureInfo.InvariantCulture; 13 | public static FontFamily DefaultFontFamily() 14 | { 15 | if (Environment.OSVersion.Platform == PlatformID.Win32NT) 16 | return SystemFonts.Find("Arial"); 17 | else 18 | return SystemFonts.Find("DejaVu Sans"); 19 | 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Common/SlotAllocator{T}.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Aximo.Render 8 | { 9 | public class SlotAllocator 10 | { 11 | private static Serilog.ILogger Log = Aximo.Log.ForContext>(); 12 | 13 | private HashSet UsedNumbers = new HashSet(); 14 | private List FreeNumbers; 15 | public string Name { get; set; } 16 | 17 | public SlotAllocator(IEnumerable freeNumbers) : this(freeNumbers, "SlotAllocator") 18 | { 19 | } 20 | 21 | public SlotAllocator(IEnumerable freeNumbers, string name) 22 | { 23 | Name = name; 24 | Init(freeNumbers); 25 | } 26 | 27 | public void Init(IEnumerable freeNumbers) 28 | { 29 | FreeNumbers = new List(freeNumbers); 30 | Log.ForContext(Name).Verbose("Initialized with {Count} elements", FreeNumbers.Count); 31 | } 32 | 33 | public T Alloc() 34 | { 35 | if (FreeNumbers.Count == 0) 36 | throw new Exception($"{Name}: No free slots available. In use: {UsedNumbers.Count}"); 37 | 38 | var num = FreeNumbers[FreeNumbers.Count - 1]; 39 | FreeNumbers.Remove(num); 40 | UsedNumbers.Add(num); 41 | Log.ForContext(Name).Verbose("Allocated Slot {Slot}. Remaining elements: {Remaining}", num, FreeNumbers.Count); 42 | return num; 43 | } 44 | 45 | public void Free(T num) 46 | { 47 | if (UsedNumbers.Remove(num)) 48 | { 49 | FreeNumbers.Add(num); 50 | Log.ForContext(Name).Verbose("Free Slot {Slot}. Available elements: {Remaining}", num, FreeNumbers.Count); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Common/TaskQueue.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Aximo.Engine 8 | { 9 | public class TaskQueue 10 | { 11 | private Queue Tasks = new Queue(); 12 | 13 | public void Dispatch(Action act) 14 | { 15 | lock (Tasks) 16 | Tasks.Enqueue(act); 17 | } 18 | 19 | public void ProcessTasks() 20 | { 21 | while (Tasks.Count > 0) 22 | { 23 | Action act; 24 | lock (Tasks) 25 | act = Tasks.Dequeue(); 26 | 27 | act?.Invoke(); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Common/Transform.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | using SixLabors.ImageSharp.Processing; 6 | 7 | namespace Aximo 8 | { 9 | public struct Transform 10 | { 11 | public Vector3 Scale; 12 | public Quaternion Rotation; 13 | public Vector3 Translation; 14 | 15 | public static readonly Transform Identity = new Transform(Vector3.One, Quaternion.Identity, Vector3.Zero); 16 | //public static readonly Transform One = new Transform(Vector3.One, Quaternion.Identity, Vector3.One); 17 | 18 | public Transform(Vector3 scale, Quaternion rotation, Vector3 translation) 19 | { 20 | Scale = scale; 21 | Rotation = rotation; 22 | Translation = translation; 23 | } 24 | 25 | public Matrix4 GetMatrix() 26 | { 27 | return Matrix4.CreateScale(Scale) * Matrix4.CreateFromQuaternion(Rotation) * Matrix4.CreateTranslation(Translation); 28 | } 29 | 30 | public static Transform CreateScale(Vector3 scale) 31 | { 32 | return new Transform(scale, Quaternion.Identity, Vector3.Zero); 33 | } 34 | 35 | public static Transform CreateScale(float x, float y, float z) 36 | { 37 | return new Transform(new Vector3(x, y, z), Quaternion.Identity, Vector3.Zero); 38 | } 39 | 40 | public static Transform CreateScale(float scale) 41 | { 42 | return new Transform(new Vector3(scale), Quaternion.Identity, Vector3.Zero); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Common/UIAnchors.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo 7 | { 8 | public struct UIAnchors 9 | { 10 | public UIAnchors(float left, float top, float right, float bottom) 11 | { 12 | Left = left; 13 | Top = top; 14 | Right = right; 15 | Bottom = bottom; 16 | } 17 | 18 | public UIAnchors(float all) 19 | { 20 | Left = all; 21 | Top = all; 22 | Right = all; 23 | Bottom = all; 24 | } 25 | 26 | public static UIAnchors Zero => new UIAnchors(); 27 | 28 | public Vector2 Min => new Vector2(Left, Top); 29 | public Vector2 Max => new Vector2(Right, Bottom); 30 | 31 | public float Top; 32 | public float Left; 33 | public float Right; 34 | public float Bottom; 35 | 36 | public float Width => Left + Right; 37 | public float Height => Top + Bottom; 38 | 39 | public Vector2 Size => new Vector2(Width, Height); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Common/Util/IcoSphere/MeshGeometry3D.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | // Adapted from this excellent IcoSphere tutorial by Andreas Kahler 5 | // http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html 6 | // Changes Copyright (C) 2014 by David Jeske, and donated to the public domain. 7 | 8 | using System.Collections.Generic; 9 | using OpenToolkit.Mathematics; 10 | 11 | namespace Aximo.Util.IcoSphere 12 | { 13 | public class MeshGeometry3D 14 | { 15 | public List Positions = new List(); 16 | public List MeshIndicies = new List(); 17 | public List Faces = new List(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Common/Util/IcoSphere/TriangleIndices.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | // Adapted from this excellent IcoSphere tutorial by Andreas Kahler 5 | // http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html 6 | // Changes Copyright (C) 2014 by David Jeske, and donated to the public domain. 7 | 8 | namespace Aximo.Util.IcoSphere 9 | { 10 | public struct TriangleIndices 11 | { 12 | public int V1; 13 | public int V2; 14 | public int V3; 15 | 16 | public TriangleIndices(int v1, int v2, int v3) 17 | { 18 | V1 = v1; 19 | V2 = v2; 20 | V3 = v3; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Common/Util/IcoSphere/VertexSoup.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | // Adapted from this excellent IcoSphere tutorial by Andreas Kahler 5 | // http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html 6 | // Changes Copyright (C) 2014 by David Jeske, and donated to the public domain. 7 | 8 | using System.Collections.Generic; 9 | 10 | namespace Aximo.Util.IcoSphere 11 | { 12 | public class VertexSoup 13 | { 14 | private Dictionary vertexToIndexMap = new Dictionary(); 15 | public List Verticies = new List(); 16 | private readonly bool deDup; 17 | 18 | public ushort DigestVertex(ref TVertexStruct vertex) 19 | { 20 | ushort retval; 21 | if (deDup && vertexToIndexMap.ContainsKey(vertex)) 22 | { 23 | retval = vertexToIndexMap[vertex]; 24 | } 25 | else 26 | { 27 | ushort nextIndex = (ushort)Verticies.Count; 28 | vertexToIndexMap[vertex] = nextIndex; 29 | Verticies.Add(vertex); 30 | retval = nextIndex; 31 | } 32 | 33 | return retval; 34 | } 35 | 36 | public ushort[] DigestVerticies(TVertexStruct[] vertex_list) 37 | { 38 | ushort[] retval = new ushort[vertex_list.Length]; 39 | 40 | for (int x = 0; x < vertex_list.Length; x++) 41 | { 42 | retval[x] = DigestVertex(ref vertex_list[x]); 43 | } 44 | return retval; 45 | } 46 | 47 | public VertexSoup(bool deDup = true) 48 | { 49 | this.deDup = deDup; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Common/VertexData/Primitives/IPrimitive.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Aximo.VertexData 7 | { 8 | public interface IPrimitive 9 | { 10 | int Count { get; } 11 | void CopyTo(ICollection destination); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common/VertexData/Primitives/IPrimitive{TVertex}.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Aximo.VertexData 7 | { 8 | public interface IPrimitive : IPrimitive 9 | { 10 | TVertex this[int index] { get; set; } 11 | void CopyTo(ICollection> destination); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common/VertexData/VertexDataPos2.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Runtime.InteropServices; 7 | using OpenToolkit.Mathematics; 8 | 9 | namespace Aximo.VertexData 10 | { 11 | [StructLayout(LayoutKind.Sequential, Pack = 4)] 12 | public struct VertexDataPos2 : IVertexPosition2 13 | { 14 | public Vector2 Position; 15 | 16 | // Vertex order: 17 | // 18 | // 3 2 19 | // 20 | // 0 1 21 | 22 | public static Quad DefaultQuad 23 | => new Quad(PathBuilder.Quad().Select(v => new VertexDataPos2(v)).ToArray()); 24 | 25 | public VertexDataPos2(Vector2 position) 26 | { 27 | Position = position; 28 | } 29 | 30 | Vector2 IVertexPosition.Position { get => Position; set => Position = value; } 31 | 32 | public VertexDataPos2 Clone() => new VertexDataPos2(Position); 33 | IVertexPosition2 IVertexPosition2.Clone() => Clone(); 34 | IVertexPosition IVertexPosition.Clone() => Clone(); 35 | IVertex IVertex.Clone() => Clone(); 36 | } 37 | 38 | public static partial class EngineExtensions 39 | { 40 | public static void Add(this IList list, Vector2 position) 41 | { 42 | list.Add(new VertexDataPos2(position)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Common/VertexData/VertexDataPosUV.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using System.Runtime.InteropServices; 6 | using OpenToolkit.Mathematics; 7 | 8 | namespace Aximo.VertexData 9 | { 10 | [StructLayout(LayoutKind.Sequential, Pack = 4)] 11 | public struct VertexDataPosUV : IVertexPosUV 12 | { 13 | public Vector3 Position; 14 | public Vector2 UV; 15 | 16 | public VertexDataPosUV(Vector3 position, Vector2 uv) 17 | { 18 | Position = position; 19 | UV = uv; 20 | } 21 | 22 | Vector3 IVertexPosition.Position { get => Position; set => Position = value; } 23 | Vector2 IVertexUV.UV { get => UV; set => UV = value; } 24 | 25 | public void Set(IVertexPosUV source) 26 | { 27 | Position = source.Position; 28 | UV = source.UV; 29 | } 30 | 31 | public void Set(VertexDataPosUV source) 32 | { 33 | Position = source.Position; 34 | UV = source.UV; 35 | } 36 | 37 | public void SetPosition(IVertexPosition3 source) 38 | { 39 | Position = source.Position; 40 | } 41 | public void SetPosition(Vector3 source) 42 | { 43 | Position = source; 44 | } 45 | 46 | public VertexDataPosUV Clone() => new VertexDataPosUV(Position, UV); 47 | IVertexPosition3 IVertexPosition3.Clone() => Clone(); 48 | IVertexPosition IVertexPosition.Clone() => Clone(); 49 | IVertex IVertex.Clone() => Clone(); 50 | } 51 | 52 | public static partial class EngineExtensions 53 | { 54 | public static void Add(this IList list, Vector3 position, Vector2 uv) 55 | { 56 | list.Add(new VertexDataPosUV(position, uv)); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertex.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.VertexData 5 | { 6 | public interface IVertex 7 | { 8 | IVertex Clone(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexColor.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.VertexData 7 | { 8 | public interface IVertexColor : IVertex 9 | { 10 | Vector4 Color { get; set; } 11 | 12 | new IVertexColor Clone(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexNormal.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.VertexData 7 | { 8 | public interface IVertexNormal : IVertex 9 | { 10 | Vector3 Normal { get; set; } 11 | new IVertexNormal Clone(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexPos2UV.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.VertexData 5 | { 6 | public interface IVertexPos2UV : IVertexPosition2, IVertexUV 7 | { 8 | void Set(IVertexPos2UV source); 9 | void Set(VertexDataPos2UV source); 10 | 11 | new VertexDataPos2UV Clone(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexPosColor.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.VertexData 5 | { 6 | public interface IVertexPosColor : IVertexPosition3, IVertexColor 7 | { 8 | void Set(IVertexPosColor source); 9 | void Set(VertexDataPosColor source); 10 | new VertexDataPosColor Clone(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexPosNormalColor.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.VertexData 5 | { 6 | public interface IVertexPosNormalColor : IVertexPosition3, IVertexNormal, IVertexColor 7 | { 8 | void Set(IVertexPosNormalColor source); 9 | void Set(VertexDataPosNormalColor source); 10 | 11 | new VertexDataPosNormalColor Clone(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexPosNormalUV.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.VertexData 5 | { 6 | public interface IVertexPosNormalUV : IVertexPosition3, IVertexNormal, IVertexUV 7 | { 8 | void Set(IVertexPosNormalUV source); 9 | void Set(VertexDataPosNormalUV source); 10 | 11 | new VertexDataPosNormalUV Clone(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexPosUV.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.VertexData 5 | { 6 | public interface IVertexPosUV : IVertexPosition3, IVertexUV 7 | { 8 | void Set(IVertexPosUV source); 9 | void Set(VertexDataPosUV source); 10 | 11 | new VertexDataPosUV Clone(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexPosition.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.VertexData 5 | { 6 | public interface IVertexPosition : IVertex 7 | where TVector : unmanaged 8 | { 9 | TVector Position { get; set; } 10 | new IVertexPosition Clone(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexPosition2.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.VertexData 7 | { 8 | public interface IVertexPosition2 : IVertexPosition 9 | { 10 | new IVertexPosition2 Clone(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexPosition3.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.VertexData 7 | { 8 | public interface IVertexPosition3 : IVertexPosition 9 | { 10 | void SetPosition(IVertexPosition3 source); 11 | void SetPosition(Vector3 source); 12 | new IVertexPosition3 Clone(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Common/VertexData/VertexInterfaces/IVertexUV.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.VertexData 7 | { 8 | public interface IVertexUV : IVertex 9 | { 10 | Vector2 UV { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Demo/Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Aximo.Demo 4 | AxDemo 5 | netcoreapp3.1 6 | 7 | Exe 8 | 9 | CS0162 10 | ..\props\default.ruleset 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Demo/Experiment/doc.txt: -------------------------------------------------------------------------------- 1 | https://www.researchgate.net/publication/330564334_Implementation_of_a_Procedural_Level_Generation_Engine_for_Developing_Rouge-like_Dungeons -------------------------------------------------------------------------------- /Demo/Program.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Engine; 5 | using OpenToolkit.Mathematics; 6 | using OpenToolkit.Windowing.Common; 7 | 8 | namespace Aximo.AxDemo 9 | { 10 | internal class Program 11 | { 12 | public static void Main(string[] args) 13 | { 14 | var config = new ApplicationConfig 15 | { 16 | WindowTitle = "AxEngineDemo", 17 | WindowSize = new Vector2i(800, 600), 18 | WindowBorder = WindowBorder.Resizable, 19 | IsMultiThreaded = true, 20 | RenderFrequency = 0, 21 | UpdateFrequency = 0, 22 | IdleRenderFrequency = 0, 23 | IdleUpdateFrequency = 0, 24 | VSync = VSyncMode.Off, 25 | // UseGtkUI = true, 26 | UseConsole = true, 27 | NormalizedUISize = new Vector2(800, 600), 28 | }; 29 | new DemoApplication().Start(config); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Engine/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | [assembly: InternalsVisibleTo("AxTests")] 7 | -------------------------------------------------------------------------------- /Engine/CommandLineManager.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Linq; 6 | using System.Security.Policy; 7 | using System.Threading; 8 | using Aximo.Engine.Components.Geometry; 9 | using Aximo.Engine.Windows; 10 | using Aximo.Render.OpenGL; 11 | 12 | namespace Aximo.Engine 13 | { 14 | public delegate void ExecuteConsoleCommandLineDelegate(ExecuteConsoleCommandLineArgs e); 15 | 16 | public class CommandLineManager 17 | { 18 | public event ExecuteConsoleCommandLineDelegate OnExecuteConsoleCommandLine; 19 | 20 | public static CommandLineManager Current { get; private set; } = new CommandLineManager(); 21 | 22 | internal void InvokeExecuteConsoleCommandLine(ExecuteConsoleCommandLineArgs e) 23 | { 24 | OnExecuteConsoleCommandLine?.Invoke(e); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Engine/CommandLineOptions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Aximo.Engine 8 | { 9 | public class CommandLineOptions 10 | { 11 | public bool Mute { get; set; } 12 | 13 | public CommandLineOptions(string[] commandLineArgs) 14 | { 15 | Mute = commandLineArgs.Contains("--mute"); 16 | } 17 | 18 | private static CommandLineOptions _Current; 19 | public static CommandLineOptions Current 20 | { 21 | get 22 | { 23 | if (_Current == null) 24 | _Current = new CommandLineOptions(Environment.GetCommandLineArgs()); 25 | 26 | return _Current; 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Engine/Components/BufferComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render; 5 | using Aximo.Render.Objects; 6 | 7 | namespace Aximo.Engine 8 | { 9 | public class BufferComponent : ActorComponent 10 | { 11 | public BufferComponent() 12 | { 13 | SetData(new BufferData2D()); 14 | } 15 | 16 | public BufferComponent(BufferData2D bufferData) 17 | { 18 | SetData(bufferData); 19 | } 20 | 21 | public void SetData(BufferData2D bufferData) 22 | { 23 | BufferData = bufferData; 24 | } 25 | 26 | public BufferData2D BufferData; 27 | 28 | private ScreenshotObject RenderObject; 29 | 30 | internal override void SyncChanges() 31 | { 32 | bool created = false; 33 | if (RenderObject == null) 34 | { 35 | created = true; 36 | RenderObject = new ScreenshotObject(BufferData); 37 | } 38 | 39 | if (created) 40 | RenderContext.Current.AddObject(RenderObject); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/CrossLineComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render.OpenGL; 5 | 6 | namespace Aximo.Engine.Components.Geometry 7 | { 8 | public class CrossLineComponent : StaticMeshComponent 9 | { 10 | public CrossLineComponent(int size, bool center) : base(MeshDataBuilder.CrossLine(), MaterialManager.DefaultLineMaterial) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/CubeComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render.OpenGL; 5 | 6 | namespace Aximo.Engine.Components.Geometry 7 | { 8 | public class CubeComponent : StaticMeshComponent 9 | { 10 | public CubeComponent() : base(MeshDataBuilder.Cube(), Material.Default) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/DebugCubeComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render.OpenGL; 5 | 6 | namespace Aximo.Engine.Components.Geometry 7 | { 8 | public class DebugCubeComponent : StaticMeshComponent 9 | { 10 | public DebugCubeComponent() : base(MeshDataBuilder.DebugCube(), Material.Default) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/Experiment/ISceneInterface.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Engine.Components.Geometry; 5 | using Aximo.Engine.Components.Lights; 6 | 7 | namespace Aximo.Engine 8 | { 9 | public interface ISceneInterface 10 | { 11 | void AddLight(LightComponent light); 12 | void RemoveLight(LightComponent light); 13 | 14 | void AddPrimitive(PrimitiveComponent primitive); 15 | void RemovePrimitive(PrimitiveComponent primitive); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/Experiment/PrimitiveDrawInterface.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine 5 | { 6 | public class PrimitiveDrawInterface 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/Experiment/PrimitiveSceneProxy.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using Aximo.Engine.Components.Geometry; 6 | using Aximo.Render; 7 | 8 | namespace Aximo.Engine 9 | { 10 | public class PrimitiveSceneProxy 11 | { 12 | public List Materials = new List(); 13 | 14 | public PrimitiveSceneProxy(PrimitiveComponent component) { } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/Experiment/StaticMeshSceneProxy.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Engine.Components.Geometry; 5 | 6 | namespace Aximo.Engine 7 | { 8 | public class StaticMeshSceneProxy : PrimitiveSceneProxy 9 | { 10 | public StaticMeshSceneProxy(StaticMeshComponent component) : base(component) { } 11 | 12 | public void DrawStaticElements(StaticPrimitiveDrawInterface pdi) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/Experiment/StaticPrimitiveDrawInterface.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine 5 | { 6 | public class StaticPrimitiveDrawInterface : PrimitiveDrawInterface 7 | { 8 | // public void DrawMesh(MeshBatch mesh) 9 | // { 10 | // } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/GraphicsScreenTextureComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | using SixLabors.ImageSharp; 6 | using SixLabors.ImageSharp.PixelFormats; 7 | 8 | namespace Aximo.Engine.Components.Geometry 9 | { 10 | public class GraphicsScreenTextureComponent : ScreenTextureComponent 11 | { 12 | public GraphicsScreenTextureComponent(Vector2 size) 13 | { 14 | var realSize = TransformSize(size); 15 | Image = new Image(realSize.X, realSize.Y); 16 | ImageContext = new ImageContext(Image, SceneContext.Current.ScaleToPixelFactor); 17 | ImageContext.OnFlush += () => UpdateTexture(); 18 | Texture = Texture.GetFromBitmap(Image, null); 19 | Material.DiffuseTexture = Texture; 20 | UpdateTexture(); 21 | } 22 | 23 | private Vector2i TransformSize(Vector2 size) => (size * SceneContext.Current.ScaleToPixelFactor).Round().ToVector2i(); 24 | 25 | protected void ResizeImage(Vector2 size) 26 | { 27 | var realSize = TransformSize(size); 28 | 29 | if (realSize.X == 0 || realSize.Y == 0) 30 | return; 31 | 32 | Image = new Image(realSize.X, realSize.Y); 33 | ImageContext.SetImage(Image); 34 | UpdateTexture(); 35 | } 36 | 37 | protected Image Image { get; private set; } 38 | public ImageContext ImageContext { get; private set; } 39 | 40 | public Texture Texture { get; private set; } 41 | 42 | public void UpdateTexture() 43 | { 44 | Texture.SetData(Image); 45 | PropertyChanged(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/GridPlaneComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render.OpenGL; 5 | 6 | namespace Aximo.Engine.Components.Geometry 7 | { 8 | public class GridPlaneComponent : StaticMeshComponent 9 | { 10 | public GridPlaneComponent(int size, bool center) : base(MeshDataBuilder.Grid(size, center), MaterialManager.DefaultLineMaterial) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/LineComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render.OpenGL; 5 | using OpenToolkit.Mathematics; 6 | 7 | namespace Aximo.Engine.Components.Geometry 8 | { 9 | public class LineComponent : StaticMeshComponent 10 | { 11 | public LineComponent(Vector3 start, Vector3 end) 12 | : this(start, end, new Vector4(0, 1, 0, 1)) 13 | { 14 | } 15 | 16 | public LineComponent(Vector3 start, Vector3 end, Vector4 color) 17 | : this(start, end, color, color) 18 | { 19 | } 20 | 21 | public LineComponent(Vector3 start, Vector3 end, Vector4 colorStart, Vector4 colorEnd) 22 | : base(MeshDataBuilder.Line(start, end, colorStart, colorEnd), MaterialManager.DefaultLineMaterial) 23 | { 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/MeshComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine.Components.Geometry 5 | { 6 | /// 7 | /// Represents a Mesh. 8 | /// 9 | public class MeshComponent : PrimitiveComponent 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/QuadComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine.Components.Geometry 5 | { 6 | public class QuadComponent : StaticMeshComponent 7 | { 8 | public QuadComponent() : base(Mesh.CreateQuad3(), Material.Default) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/RoundedCubeComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render.OpenGL; 5 | 6 | namespace Aximo.Engine.Components.Geometry 7 | { 8 | 9 | public class RoundedCubeComponent : StaticMeshComponent 10 | { 11 | public RoundedCubeComponent() : base(MeshDataBuilder.RoundedCube(), Material.Default) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/SkyBoxComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render; 5 | using Aximo.Render.Objects; 6 | 7 | namespace Aximo.Engine.Components.Geometry 8 | { 9 | public class SkyBoxComponent : MeshComponent 10 | { 11 | public SkyBoxComponent() 12 | { 13 | } 14 | 15 | public SkyBoxComponent(string skyBoxPath) 16 | { 17 | } 18 | 19 | internal override void SyncChanges() 20 | { 21 | if (!HasChanges) 22 | return; 23 | 24 | base.SyncChanges(); 25 | 26 | bool created = false; 27 | if (RenderableObject == null) 28 | { 29 | created = true; 30 | RenderableObject = new SkyboxObject(); 31 | } 32 | 33 | var obj = (SkyboxObject)RenderableObject; 34 | 35 | if (created) 36 | RenderContext.Current.AddObject(RenderableObject); 37 | } 38 | 39 | internal override void DoDeallocation() 40 | { 41 | if (!HasDeallocation) 42 | return; 43 | 44 | if (RenderableObject == null) 45 | return; 46 | 47 | RenderableObject.Orphaned = true; 48 | RenderableObject = null; 49 | 50 | base.DoDeallocation(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/SphereComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine.Components.Geometry 5 | { 6 | public class SphereComponent : StaticMeshComponent 7 | { 8 | public SphereComponent(int divisions = 2) : base(Mesh.CreateSphere(divisions), Material.Default) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Engine/Components/Geometry/StatsComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Linq; 6 | using Aximo.Engine.Components.UI; 7 | using OpenToolkit.Mathematics; 8 | using SixLabors.Fonts; 9 | using SixLabors.ImageSharp; 10 | using SixLabors.ImageSharp.Drawing.Processing; 11 | using SixLabors.ImageSharp.Processing; 12 | using Color = SixLabors.ImageSharp.Color; 13 | 14 | namespace Aximo.Engine.Components.Geometry 15 | { 16 | /// 17 | /// Displays metrics, for example the Frames per Second and Updates per Second. 18 | /// 19 | public class StatsComponent : UIComponent 20 | { 21 | private DateTime LastStatUpdate; 22 | 23 | public StatsComponent() : this(new Vector2(200, 100)) 24 | { 25 | } 26 | 27 | public StatsComponent(Vector2 size) : base(size) 28 | { 29 | ImageContext.Clear(Color.Transparent); 30 | UpdateTexture(); 31 | } 32 | 33 | public float FontSize = 24; 34 | 35 | public override void UpdateFrame() 36 | { 37 | if ((DateTime.UtcNow - LastStatUpdate).TotalSeconds > 1) 38 | { 39 | LastStatUpdate = DateTime.UtcNow; 40 | ImageContext.Clear(Color.Transparent); 41 | var txt = "FPS: " + Math.Round(Application.Current.RenderCounter.EventsPerSecond).ToString(); 42 | txt += "\nUPS: " + Math.Round(Application.Current.UpdateCounter.EventsPerSecond).ToString(); 43 | ImageContext.FontSize = FontSize; 44 | ImageContext.FillStyle(Color.White); 45 | ImageContext.DrawText(txt, new Vector2(5, 5)); 46 | UpdateTexture(); 47 | } 48 | base.UpdateFrame(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Engine/Components/Lights/DirectionalLightComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render; 5 | using OpenToolkit.Mathematics; 6 | 7 | namespace Aximo.Engine.Components.Lights 8 | { 9 | public class DirectionalLightComponent : LightComponent 10 | { 11 | protected override LightType LightType => LightType.Directional; 12 | 13 | private Vector3 _Direction = new Vector3(0, 0, -1).Normalized(); 14 | public Vector3 Direction 15 | { 16 | get => _Direction; 17 | set { if (_Direction == value) return; _Direction = value; LightAttributesChanged = true; } 18 | } 19 | 20 | private bool LightAttributesChanged = true; 21 | 22 | internal override void SyncChanges() 23 | { 24 | if (!HasChanges) 25 | return; 26 | 27 | base.SyncChanges(); 28 | 29 | if (LightAttributesChanged) 30 | LightObject.Direction = _Direction; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Engine/Components/Lights/PointLightComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render; 5 | using OpenToolkit.Mathematics; 6 | 7 | namespace Aximo.Engine.Components.Lights 8 | { 9 | public class PointLightComponent : LightComponent 10 | { 11 | protected override LightType LightType => LightType.Point; 12 | 13 | private float _Linear = 0.1f; 14 | public float Linear 15 | { 16 | get => _Linear; 17 | set { if (_Linear == value) return; _Linear = value; LightAttributesChanged(); } 18 | } 19 | 20 | private float _Quadric = 0.0f; 21 | public float Quadric 22 | { 23 | get => _Quadric; 24 | set { if (_Quadric == value) return; _Quadric = value; LightAttributesChanged(); } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Engine/Components/UI/UIButtonComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine.Components.UI 5 | { 6 | public class UIButtonComponent : UIContainerComponent 7 | { 8 | public UILabelComponent LabelComponent; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Engine/Components/UI/UIContainerComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.Engine.Components.UI 7 | { 8 | public abstract class UIContainerComponent : UIComponent 9 | { 10 | public UIAnchors Padding; 11 | 12 | internal override UIAnchors PaddingInternal => Padding; 13 | 14 | internal override void SetChildBounds() 15 | { 16 | foreach (var child in UIComponents) 17 | { 18 | if (child.Size == Vector2.Zero) 19 | { 20 | child.AbsoluteOuterRect = AbsolutePaddingRect; 21 | } 22 | else 23 | { 24 | var location = child.Location; 25 | var size = child.Size + child.PaddingInternal.Size + child.Border.Size + child.Margin.Size; 26 | 27 | //location.X += Border.Left; 28 | //location.Y += Border.Top; 29 | 30 | //size.X -= child.Border.Size.X; 31 | //size.Y -= child.Border.Size.Y; 32 | 33 | child.AbsoluteOuterRect = BoxHelper.FromSize(AbsolutePaddingRect.Min + location, size); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Engine/Components/UI/UIFloatingContainer.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine.Components.UI 5 | { 6 | public class UIFloatingContainer : UIContainerComponent 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Engine/Components/UI/UIFlowContainer.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.Engine.Components.UI 7 | { 8 | public class UIFlowContainer : UIContainerComponent 9 | { 10 | public Vector2 DefaultChildSizes; 11 | public UIAnchors ExtraChildMargin; 12 | 13 | internal override void SetChildBounds() 14 | { 15 | var location = Vector2.Zero; 16 | foreach (var child in UIComponents) 17 | { 18 | var extra = child.PaddingInternal.Size + child.Border.Size + child.Margin.Size; 19 | 20 | var defaultSize = DefaultChildSizes; 21 | if (defaultSize.X == 0) 22 | defaultSize.X = AbsolutePaddingRect.Size.X - extra.X - ExtraChildMargin.Size.X; 23 | if (defaultSize.Y == 0) 24 | defaultSize.Y = AbsolutePaddingRect.Size.Y - extra.Y - ExtraChildMargin.Size.Y; 25 | 26 | var size = child.Size; 27 | if (size.X == 0) 28 | size.X = defaultSize.X; 29 | if (size.Y == 0) 30 | size.Y = defaultSize.Y; 31 | 32 | size += extra; 33 | child.AbsoluteOuterRect = BoxHelper.FromSize(AbsolutePaddingRect.Min + location + ExtraChildMargin.Min, size); 34 | location.Y += size.Y + ExtraChildMargin.Size.Y; // TODO: Use X for other alignment 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Engine/Components/UI/UIImage.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.Engine.Components.UI 7 | { 8 | public class UIImage : UIComponent 9 | { 10 | public UIImage(Material material) : this(material, new Vector2(100, 100)) 11 | { 12 | } 13 | 14 | public UIImage(Material material, Vector2 size) : base(size) 15 | { 16 | Material = material; 17 | } 18 | 19 | public UIImage(string imagePath) : this(Texture.GetFromFile(imagePath), new Vector2(100, 100)) 20 | { 21 | } 22 | 23 | public UIImage(string imagePath, Vector2 size) : this(Texture.GetFromFile(imagePath), size) 24 | { 25 | } 26 | 27 | public UIImage(Texture image) : this(image, new Vector2(100, 100)) 28 | { 29 | } 30 | 31 | public UIImage(Texture image, Vector2 size) : base(size) 32 | { 33 | Material.DiffuseTexture = image; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Engine/Components/UI/UILabelComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Linq; 5 | using OpenToolkit.Mathematics; 6 | using SixLabors.Fonts; 7 | using SixLabors.ImageSharp; 8 | using SixLabors.ImageSharp.Drawing.Processing; 9 | using SixLabors.ImageSharp.Processing; 10 | 11 | namespace Aximo.Engine.Components.UI 12 | { 13 | public class UILabelComponent : UIComponent 14 | { 15 | private string _Text; 16 | public string Text 17 | { 18 | get => _Text; 19 | set 20 | { 21 | if (_Text == value) 22 | return; 23 | _Text = value; 24 | Redraw(); 25 | } 26 | } 27 | 28 | public float FontSize { get; set; } = 15; 29 | 30 | public UILabelComponent() 31 | { 32 | } 33 | 34 | public UILabelComponent(string text) 35 | { 36 | Text = text; 37 | Name = "Label"; 38 | } 39 | 40 | public Color Color { get; set; } = Color.Black; 41 | 42 | protected override void DrawControl() 43 | { 44 | ImageContext.Clear(Color.Transparent); 45 | ImageContext.VerticalTextAlignment = VerticalAlignment.Center; 46 | ImageContext.FontSize = FontSize; 47 | 48 | if (Text != null) 49 | ImageContext.DrawText(Text, Color, new Vector2(0, RelatativePaddingRect.Size.Y / 2)); 50 | } 51 | 52 | protected override void OnResized() 53 | { 54 | InvokeDrawControl(); 55 | } 56 | 57 | internal override void DumpInfo(bool list) 58 | { 59 | Log.ForContext("DumpInfo").Info(new string(' ', (Level + 1) * 2) + "{Type} #{Id} {Name} Text={Text}", GetType().Name, ObjectId, Name, Text); 60 | if (list) 61 | VisitChilds(a => a.DumpInfo(false)); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Engine/Components/UI/UIPanelComponent.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine.Components.UI 5 | { 6 | public class UIPanelComponent : UIContainerComponent 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Engine/Components/UI/UIRect.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | 6 | namespace Aximo.Engine.Components.UI 7 | { 8 | public class UIRect 9 | { 10 | public float Top; 11 | public float Left; 12 | public float? Width; 13 | public float? Height; 14 | } 15 | 16 | [Flags] 17 | public enum UIDock 18 | { 19 | None = 0, 20 | Top = 1, 21 | Left = 2, 22 | Right = 4, 23 | Bottom = 8, 24 | Fill = Top | Left | Right | Bottom, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Engine/Engine.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Aximo.Engine 4 | AxEngine 5 | netcoreapp3.1 6 | 7 | Library 8 | 9 | CS0162 10 | ..\props\default.ruleset 11 | true 12 | 13 | 14 | 15 | 16 | Aximo.Engine 17 | $(DependencyDescription) 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Engine/ExecuteConsoleCommandLineArgs.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Linq; 6 | using System.Security.Policy; 7 | using System.Threading; 8 | using Aximo.Engine.Components.Geometry; 9 | using Aximo.Engine.Windows; 10 | using Aximo.Render.OpenGL; 11 | 12 | namespace Aximo.Engine 13 | { 14 | public class ExecuteConsoleCommandLineArgs 15 | { 16 | public string CommandLine { get; private set; } 17 | public bool Handled { get; set; } 18 | 19 | public ExecuteConsoleCommandLineArgs(string commandLine) 20 | { 21 | CommandLine = commandLine; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Engine/Generators/AlchemyCircle/AlchemyCircleOptions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | // Reference: https://github.com/CiaccoDavide/Alchemy-Circles-Generator 5 | // Credits: CiaccoDavide 6 | 7 | using SixLabors.ImageSharp; 8 | 9 | namespace Aximo.Generators.AlchemyCircle 10 | { 11 | public class AlchemyCircleOptions 12 | { 13 | public int Seed; 14 | public Color BackgroundColor = Color.Transparent; 15 | public Color Color = Color.White; 16 | public int Size; 17 | public int Thickness = 4; 18 | 19 | public override string ToString() 20 | { 21 | return $"Seed{Seed}Size{Size}Thickness{Thickness}Color{Color}BackgroundColor{BackgroundColor}"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Engine/Generators/AlchemyCircle/CiaccoRandom.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | 6 | namespace Aximo.Generators.AlchemyCircle 7 | { 8 | public class CiaccoRandom 9 | { 10 | private static int superSeed = 0; 11 | 12 | public CiaccoRandom() 13 | { 14 | } 15 | 16 | public void SetSeed(int seed) 17 | { 18 | // seed can only be positive and seed range is [0 -> 9999998] seed=9999999 schould give the same as seed=0 19 | superSeed = (Math.Abs(seed) % 9999999) + 1; 20 | // init for randomness fairness 21 | superSeed = (superSeed * 125) % 2796203; 22 | superSeed = (superSeed * 125) % 2796203; 23 | superSeed = (superSeed * 125) % 2796203; 24 | superSeed = (superSeed * 125) % 2796203; 25 | superSeed = (superSeed * 125) % 2796203; 26 | superSeed = (superSeed * 125) % 2796203; 27 | superSeed = (superSeed * 125) % 2796203; 28 | superSeed = (superSeed * 125) % 2796203; 29 | superSeed = (superSeed * 125) % 2796203; 30 | } 31 | 32 | public int GetRand(int min, int max) // both included: getRand(0,1) will return 0s and 1s 33 | { 34 | superSeed = (superSeed * 125) % 2796203; 35 | return (superSeed % (max - min + 1)) + min; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Engine/Materials/PipelineType.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine 5 | { 6 | public enum PipelineType 7 | { 8 | Default, 9 | Forward, 10 | Deferred, 11 | Screen, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Engine/Materials/Shader.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine 5 | { 6 | public class Shader 7 | { 8 | public string VertexShaderPath; 9 | public string FragmentShaderPath; 10 | public string GeometryShaderPath; 11 | 12 | public Shader(string vertexShaderPath, string fragmentShaderPath, string geometryShaderPath = null) 13 | { 14 | VertexShaderPath = vertexShaderPath; 15 | FragmentShaderPath = fragmentShaderPath; 16 | GeometryShaderPath = geometryShaderPath; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Engine/Materials/TextureManager.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Aximo.Engine 7 | { 8 | public static class TextureManager 9 | { 10 | private static Dictionary FileTextures = new Dictionary(); 11 | 12 | public static Texture GetFromFile(string path) 13 | { 14 | lock (FileTextures) 15 | { 16 | Texture txt; 17 | if (FileTextures.TryGetValue(path, out txt)) 18 | return txt; 19 | else 20 | FileTextures.Add(path, txt = Texture.CreateFromFile(path)); 21 | return txt; 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Engine/MeshBuilder.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Engine.Components.Geometry; 5 | using Aximo.Render.OpenGL; 6 | 7 | namespace Aximo.Engine 8 | { 9 | public static class MeshBuilder 10 | { 11 | public static StaticMeshComponent Cube() 12 | { 13 | return new StaticMeshComponent(MeshDataBuilder.Cube(), Material.Default); 14 | } 15 | 16 | public static StaticMeshComponent DebugCube() 17 | { 18 | return new StaticMeshComponent(MeshDataBuilder.DebugCube(), Material.Default); 19 | } 20 | 21 | public static StaticMeshComponent Sphere(int divisions) 22 | { 23 | return new StaticMeshComponent(Mesh.CreateSphere(divisions), Material.Default); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Engine/Startup.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | 6 | namespace Aximo.Engine 7 | { 8 | /// 9 | /// Wrapper to start the . Takes care about thread ownership. 10 | /// 11 | public abstract class Startup : IDisposable 12 | { 13 | protected abstract void Dispose(bool disposing); 14 | 15 | public void Dispose() 16 | { 17 | Dispose(true); 18 | } 19 | 20 | public static void Start() 21 | where TApplication : Application, new() 22 | { 23 | new Startup().Start(); 24 | } 25 | 26 | public static void Start(ApplicationConfig config) 27 | where TApplication : Application, new() 28 | { 29 | new Startup(config).Start(); 30 | } 31 | 32 | internal static void Start(ApplicationConfig config, TApplication instance) 33 | where TApplication : Application, new() 34 | { 35 | new Startup(config).Start(instance); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Engine/Startup{TApplication,TGtk}.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using Aximo.Engine.Windows; 6 | 7 | namespace Aximo.Engine 8 | { 9 | /// 10 | /// 11 | public class Startup : Startup 12 | where TApplication : Application, new() 13 | where TGtk : GtkUI, new() 14 | { 15 | public Startup(ApplicationConfig config) : base(config) 16 | { 17 | } 18 | 19 | private protected override GtkUI CreateGtkUI() => (TGtk)Activator.CreateInstance(typeof(TGtk)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Engine/Tween/Tween1.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Engine 5 | { 6 | /// 7 | public class Tween1 : Tween 8 | { 9 | internal static float LerpFloat(float start, float end, float progress) { return start + ((end - start) * progress); } 10 | 11 | protected override LerpFunc GetDefaultLerpFunc() 12 | { 13 | return LerpFloat; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Engine/Tween/Tween2.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.Engine 7 | { 8 | /// 9 | public class Tween2 : Tween 10 | { 11 | protected override LerpFunc GetDefaultLerpFunc() 12 | { 13 | return Vector2.Lerp; 14 | } 15 | 16 | public static LerpFunc Circle() 17 | => (start, end, p) => new Vector2(AxMath.CosNorm(p), AxMath.SinNorm(p)); 18 | 19 | public static LerpFunc Circle(float scale) 20 | => (start, end, p) => new Vector2(AxMath.CosNorm(p) * scale, AxMath.SinNorm(p) * scale); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Engine/Tween/Tween3.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo.Engine 7 | { 8 | /// 9 | public class Tween3 : Tween 10 | { 11 | protected override LerpFunc GetDefaultLerpFunc() 12 | { 13 | return Vector3.Lerp; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Engine/Windows/GtkUI.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Threading; 6 | using Gdk; 7 | using Gtk; 8 | 9 | namespace Aximo.Engine.Windows 10 | { 11 | public class GtkUI : IDisposable 12 | { 13 | private Thread th; 14 | 15 | public void Start() 16 | { 17 | th = new Thread(Run); 18 | th.Start(); 19 | } 20 | 21 | private Gtk.Window win; 22 | private Gtk.Application app; 23 | 24 | private void Run() 25 | { 26 | Gtk.Application.Init(); 27 | app = new Gtk.Application("", GLib.ApplicationFlags.None); 28 | app.Register(GLib.Cancellable.Current); 29 | 30 | win = new Gtk.Window(""); 31 | app.AddWindow(win); 32 | 33 | Fill(); 34 | 35 | win.ShowAll(); 36 | Gtk.Application.Run(); 37 | } 38 | 39 | private void Fill() 40 | { 41 | var menu = new GLib.Menu(); 42 | menu.AppendItem(new GLib.MenuItem("Help", "app.help")); 43 | menu.AppendItem(new GLib.MenuItem("About", "app.about")); 44 | menu.AppendItem(new GLib.MenuItem("Quit", "app.quit")); 45 | app.AppMenu = menu; 46 | 47 | win.DefaultSize = new Size(300, 300); 48 | 49 | var s = new Scale(Orientation.Horizontal, 0, 100, 1); 50 | s.ShowAll(); 51 | win.Add(s); 52 | } 53 | 54 | public void Dispose() 55 | { 56 | win?.Dispose(); 57 | win = null; 58 | app?.Dispose(); 59 | app = null; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Engine/Windows/MouseButtonArgs.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | using OpenToolkit.Windowing.Common; 6 | using OpenToolkit.Windowing.Common.Input; 7 | 8 | namespace Aximo.Engine.Windows 9 | { 10 | public class MouseButtonArgs 11 | { 12 | public Vector2 OldPixelPosition { get; private set; } 13 | public Vector2 PixelPosition { get; private set; } 14 | 15 | public Vector2 OldPosition { get; private set; } 16 | public Vector2 Position { get; private set; } 17 | 18 | public Vector2 OldPositionNDC { get; private set; } 19 | public Vector2 PositionNDC { get; private set; } 20 | 21 | public MouseButton Button { get; private set; } 22 | public InputAction Action { get; private set; } 23 | public KeyModifiers Modifiers { get; private set; } 24 | public bool IsPressed { get; private set; } 25 | 26 | public bool Handled { get; set; } 27 | 28 | //public float WheelDelta { get; set; } 29 | 30 | internal MouseButtonArgs(Vector2 oldPosition, Vector2 position, MouseButtonEventArgs e) 31 | { 32 | OldPositionNDC = oldPosition; 33 | PositionNDC = position; 34 | 35 | OldPixelPosition = AxMath.MapFromNDC(OldPositionNDC, Application.Current.ScreenPixelSize); 36 | PixelPosition = AxMath.MapFromNDC(PositionNDC, Application.Current.ScreenPixelSize); 37 | 38 | Button = e.Button; 39 | Action = e.Action; 40 | Modifiers = e.Modifiers; 41 | IsPressed = e.IsPressed; 42 | 43 | Position = PixelPosition * SceneContext.Current.ScreenScale; 44 | OldPosition = OldPixelPosition * SceneContext.Current.ScreenScale; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Engine/Windows/MouseMoveArgs.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | using OpenToolkit.Windowing.Common; 6 | 7 | namespace Aximo.Engine.Windows 8 | { 9 | public class MouseMoveArgs 10 | { 11 | public Vector2 OldPixelPosition { get; private set; } 12 | public Vector2 PixelPosition { get; private set; } 13 | public Vector2 Delta { get; private set; } 14 | public float DeltaX { get; private set; } 15 | public float DeltaY { get; private set; } 16 | 17 | public Vector2 OldPosition { get; private set; } 18 | public Vector2 Position { get; private set; } 19 | 20 | public bool Handled { get; set; } 21 | 22 | internal MouseMoveArgs(MouseMoveEventArgs e) 23 | { 24 | PixelPosition = e.Position; 25 | Delta = e.Delta; 26 | DeltaX = e.DeltaX; 27 | DeltaY = e.DeltaY; 28 | OldPixelPosition = PixelPosition - Delta; 29 | 30 | Position = PixelPosition * SceneContext.Current.ScreenScale; 31 | OldPosition = OldPixelPosition * SceneContext.Current.ScreenScale; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Engine/Windows/Win32Native.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace Aximo.Engine.Windows 8 | { 9 | internal static class Win32Native 10 | { 11 | [DllImport("user32.dll")] 12 | private static extern IntPtr GetActiveWindow(); 13 | 14 | [DllImport("user32.dll", SetLastError = true)] 15 | private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 16 | private const int GWL_STYLE = -16; 17 | 18 | public static void HideTitleBar() 19 | { 20 | IntPtr ptr = GetActiveWindow(); 21 | SetWindowLong(ptr, GWL_STYLE, 0); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Aximo Games 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Render/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | [assembly: InternalsVisibleTo("AxEngine")] 7 | -------------------------------------------------------------------------------- /Render/GLSL/Attributes.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | //using System; 5 | 6 | //// WIP / Test! 7 | 8 | //namespace Aximo.Render.GLSL 9 | //{ 10 | // public class InParamAttribute : Attribute 11 | // { 12 | // } 13 | // public class GlslLayoutAttribute : Attribute 14 | // { 15 | // public GlslLayoutType Type; 16 | 17 | // public GlslLayoutAttribute(GlslLayoutType type) 18 | // { 19 | // Type = type; 20 | // } 21 | // } 22 | 23 | // public enum GlslLayoutType 24 | // { 25 | // Std140, 26 | // } 27 | 28 | // public class OutParamAttribute : Attribute 29 | // { 30 | // } 31 | // public class UniformAttribute : Attribute 32 | // { 33 | // } 34 | // public class ArraySizeAttribute : Attribute 35 | // { 36 | // public int Size; 37 | // public ArraySizeAttribute(int size) { 38 | // Size = size; 39 | // } 40 | // } 41 | //} 42 | -------------------------------------------------------------------------------- /Render/GLSL/GlslBase.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | //using System; 5 | 6 | //// WIP / Test! 7 | 8 | //namespace Aximo.Render.GLSL 9 | //{ 10 | // public abstract class GlslBase 11 | // { 12 | // public abstract void Main(); 13 | 14 | // public static Vec3 Normalize(Vec3 a) => throw new NotImplementedException(); 15 | 16 | // public static Vec4 Texture(Sampler2D sampler, Vec2 texCoords) => throw new NotImplementedException(); 17 | 18 | // } 19 | //} 20 | -------------------------------------------------------------------------------- /Render/GLSL/GlslTest.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | //using System.Runtime.InteropServices; 5 | 6 | //// WIP / Test! 7 | 8 | //#pragma warning disable SA1134 // Attributes should not share line 9 | //#pragma warning disable SA1400 // Access modifier should be declared 10 | 11 | //namespace Aximo.Render.GLSL 12 | //{ 13 | // public struct SMaterial 14 | // { 15 | // public Vec4 DiffuseColor; 16 | // public Sampler2D DiffuseMap; 17 | // } 18 | 19 | // [StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)] 20 | // public struct SLight 21 | // { 22 | // } 23 | 24 | // public struct LightsArray 25 | // { 26 | // public const int MAX_NUM_TOTAL_LIGHTS = 100; 27 | // [ArraySize(MAX_NUM_TOTAL_LIGHTS)] public SLight Lights; 28 | // } 29 | 30 | // public abstract class GlslTest : GlslBase 31 | // { 32 | // [OutParam] Vec4 FragColor; 33 | 34 | // [Uniform] SMaterial Material; 35 | // [Uniform] Vec3 ViewPos; 36 | // [Uniform] Sampler2DArray DirectionalShadowMap; 37 | // [Uniform] SamplerCubeArray PointShadowMap; 38 | // [InParam] Vec2 TexCoords; 39 | 40 | // [InParam] Vec3 Normal; 41 | // [InParam] Vec3 NormalTransposed; 42 | // [InParam] Vec3 FragPos; 43 | 44 | // [GlslLayout(GlslLayoutType.Std140)] [Uniform] LightsArray Lights; 45 | 46 | // public override void Main() 47 | // { 48 | // Vec3 viewDir = Normalize(ViewPos - FragPos); 49 | // Vec4 matDiffuse = Material.DiffuseColor; 50 | // matDiffuse = Texture(Material.DiffuseMap, TexCoords) * Material.DiffuseColor; 51 | // } 52 | // } 53 | //} 54 | -------------------------------------------------------------------------------- /Render/GLSL/Structs.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | //using System; 5 | 6 | //// WIP / Test! 7 | 8 | //namespace Aximo.Render.GLSL 9 | //{ 10 | // public struct Vec2 11 | // { 12 | // public static Vec2 operator +(Vec2 a, Vec2 b) => throw new NotImplementedException(); 13 | // public static Vec2 operator -(Vec2 a, Vec2 b) => throw new NotImplementedException(); 14 | // } 15 | // public struct Vec3 16 | // { 17 | // public static Vec3 operator +(Vec3 a, Vec3 b) => throw new NotImplementedException(); 18 | // public static Vec3 operator -(Vec3 a, Vec3 b) => throw new NotImplementedException(); 19 | // } 20 | 21 | // public struct Vec4 22 | // { 23 | // public static Vec4 operator +(Vec4 a, Vec4 b) => throw new NotImplementedException(); 24 | // public static Vec4 operator -(Vec4 a, Vec4 b) => throw new NotImplementedException(); 25 | // public static Vec4 operator *(Vec4 a, Vec4 b) => throw new NotImplementedException(); 26 | // public static Vec4 operator /(Vec4 a, Vec4 b) => throw new NotImplementedException(); 27 | // } 28 | 29 | // public struct Sampler2D { } 30 | // public struct Sampler2DArray { } 31 | // public struct SamplerCubeArray { } 32 | //} 33 | -------------------------------------------------------------------------------- /Render/MeshData.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Render.OpenGL 5 | { 6 | public abstract class MeshData 7 | { 8 | public VertexLayoutDefinition Layout { get; protected set; } 9 | public abstract BufferData1D Data { get; } 10 | public virtual int VertexCount { get; protected set; } 11 | public BufferData1D Indicies { get; protected set; } 12 | public virtual int IndiciesCount { get; protected set; } 13 | 14 | public VertexLayoutBinded BindLayoutToShader(RendererShader shader) => Layout.BindToShader(shader); 15 | public AxPrimitiveType PrimitiveType { get; protected set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Render/MeshDepthSorter.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using OpenToolkit.Mathematics; 6 | 7 | namespace Aximo.Render 8 | { 9 | public class MeshDepthSorter : IComparer 10 | { 11 | public Camera Camera; 12 | private Vector3 CameraPosition; 13 | private bool DistanceCheck; 14 | 15 | public MeshDepthSorter(Camera camera, bool distanceCheck = true) 16 | { 17 | DistanceCheck = distanceCheck; 18 | Camera = camera; 19 | CameraPosition = camera.Position; 20 | } 21 | 22 | // returns: Draw-Order. 23 | public int Compare(IRenderableObject x, IRenderableObject y) 24 | { 25 | // Draw Early: -1. 26 | // Draw Late: 1 27 | 28 | if (x.UseTransparency != y.UseTransparency) 29 | return x.UseTransparency.CompareTo(y.UseTransparency); 30 | 31 | if (x.DrawPriority != y.DrawPriority) 32 | return x.DrawPriority.CompareTo(y.DrawPriority); 33 | 34 | var reverse = 0; 35 | if (x.UseTransparency) // no check for Y needed 36 | reverse = 1; 37 | 38 | if (!DistanceCheck) 39 | return 0; // TODO: Use index in array 40 | 41 | var boundsX = x as IBounds; 42 | var boundsY = y as IBounds; 43 | var hasBoundsX = boundsX != null ? 1 : 0; 44 | var hasBoundsY = boundsY != null ? 1 : 0; 45 | if (hasBoundsX != hasBoundsY) 46 | return hasBoundsX.CompareTo(hasBoundsY); 47 | 48 | if (hasBoundsX == 0) // no check for Y needed 49 | return 0; 50 | 51 | var distanceX = Vector3.Distance(CameraPosition, boundsX.WorldBounds.Center); 52 | var distanceY = Vector3.Distance(CameraPosition, boundsY.WorldBounds.Center); 53 | return distanceX.CompareTo(distanceY) * reverse; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Render/Objects/RenderObject.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using Aximo.Render.Pipelines; 6 | 7 | namespace Aximo.Render.Objects 8 | { 9 | public abstract class RenderObject : RenderObjectBase 10 | { 11 | public virtual List RenderPipelines { get; } = new List(); 12 | 13 | public void UsePipeline() 14 | where T : class, IRenderPipeline 15 | { 16 | UsePipeline(Context.GetPipeline()); 17 | } 18 | 19 | public void UsePipeline(IRenderPipeline pipeline) 20 | { 21 | if (pipeline == null) 22 | return; 23 | 24 | if (!RenderPipelines.Contains(pipeline)) 25 | RenderPipelines.Add(pipeline); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Render/Objects/ScreenSceneObject.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render.Pipelines; 5 | 6 | namespace Aximo.Render.Objects 7 | { 8 | public class ScreenSceneObject : ScreenTextureObject 9 | { 10 | public override void Init() 11 | { 12 | SourceTexture = Context.GetPipeline().FrameBuffer.GetDestinationTexture(); 13 | base.Init(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Render/Objects/ScreenshotObject.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Aximo.Render.Pipelines; 5 | 6 | namespace Aximo.Render.Objects 7 | { 8 | public class ScreenshotObject : RenderObjectBase 9 | { 10 | public ScreenshotObject(BufferData2D data) 11 | { 12 | Data = data; 13 | } 14 | 15 | public override void Init() 16 | { 17 | } 18 | 19 | private BufferData2D Data; 20 | 21 | public override void OnWorldRendered() 22 | { 23 | if (Data == null) 24 | Data = new BufferData2D(Context.ScreenPixelSize.X, Context.ScreenPixelSize.Y); 25 | //FrameBuffer.Default.GetData(Data); 26 | 27 | var fb = Context.GetPipeline().FrameBuffer; 28 | var txt = fb.DestinationTextures[0]; 29 | Data.PixelFormat = txt.Format.ToGamePixelFormat(); 30 | txt.GetTexture(Data); 31 | 32 | // var bmpt = Data.CreateBitmap(); 33 | // bmpt.Save("/tmp/blubb.png"); 34 | } 35 | 36 | public override void Free() 37 | { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Render/OpenGL/Buffers/BindingPoint.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace Aximo.Render.OpenGL 8 | { 9 | public class BindingPoint 10 | { 11 | private int _Number; 12 | public int Number => _Number; 13 | 14 | private static SlotAllocator Allocator; 15 | static BindingPoint() 16 | { 17 | var freeNumbers = new List(); 18 | Allocator = new SlotAllocator(Enumerable.Range(1, 32), nameof(BindingPoint)); 19 | } 20 | 21 | public static BindingPoint Default { get; private set; } = new BindingPoint(false) { _Number = 0 }; 22 | 23 | public BindingPoint() : this(true) 24 | { 25 | } 26 | 27 | private BindingPoint(bool alloc) 28 | { 29 | if (alloc) 30 | { 31 | _Number = Allocator.Alloc(); 32 | } 33 | } 34 | 35 | public void Free() 36 | { 37 | Allocator.Free(_Number); 38 | _Number = -1; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Render/OpenGL/Buffers/BufferObject.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Runtime.InteropServices; 5 | using OpenToolkit.Graphics.OpenGL4; 6 | 7 | namespace Aximo.Render.OpenGL 8 | { 9 | public abstract class BufferObject 10 | { 11 | public BufferObject() 12 | { 13 | } 14 | 15 | protected BufferTarget Target = BufferTarget.ArrayBuffer; 16 | 17 | private int _Handle; 18 | public int Handle => _Handle; 19 | 20 | public void Create() 21 | { 22 | _Handle = GL.GenBuffer(); 23 | } 24 | 25 | public int Size { get; private set; } 26 | 27 | public unsafe void SetData(BufferData data) 28 | { 29 | var currentBuffer = CurrentBuffer; 30 | Bind(); 31 | Size = data.Length; 32 | GCHandle h = data.CreateHandle(); 33 | try 34 | { 35 | GL.BufferData(Target, data.Length * data.ElementSize, h.AddrOfPinnedObject(), BufferUsageHint.StaticDraw); 36 | } 37 | finally 38 | { 39 | h.Free(); 40 | } 41 | } 42 | 43 | private static int CurrentHandle; 44 | private static BufferObject CurrentBuffer; 45 | 46 | public void Bind() 47 | { 48 | Bind(Target, _Handle); 49 | CurrentBuffer = this; 50 | } 51 | 52 | private static void Bind(BufferTarget target, int handle) 53 | { 54 | // if (CurrentHandle == handle) 55 | // return; 56 | CurrentHandle = handle; 57 | GL.BindBuffer(target, handle); 58 | } 59 | 60 | public void BindDefault() 61 | { 62 | Bind(Target, 0); 63 | CurrentBuffer = null; 64 | } 65 | 66 | public void Free() 67 | { 68 | GL.DeleteBuffer(_Handle); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Render/OpenGL/Buffers/ElementsBufferObject.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Graphics.OpenGL4; 5 | 6 | namespace Aximo.Render.OpenGL 7 | { 8 | public class ElementsBufferObject : BufferObject 9 | { 10 | public ElementsBufferObject() 11 | { 12 | Target = BufferTarget.ElementArrayBuffer; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Render/OpenGL/Buffers/UniformBufferObject.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using OpenToolkit.Graphics.OpenGL4; 6 | 7 | namespace Aximo.Render.OpenGL 8 | { 9 | public class UniformBufferObject : BufferObject 10 | { 11 | public UniformBufferObject() 12 | { 13 | Target = BufferTarget.UniformBuffer; 14 | } 15 | 16 | public void SetBindingPoint(BindingPoint bindingPoint) 17 | { 18 | if (Target != BufferTarget.UniformBuffer) 19 | throw new InvalidOperationException(); 20 | 21 | GL.BindBufferBase(BufferRangeTarget.UniformBuffer, bindingPoint.Number, Handle); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Render/OpenGL/Buffers/VertexBufferObject.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Graphics.OpenGL4; 5 | 6 | namespace Aximo.Render.OpenGL 7 | { 8 | public class VertexBufferObject : BufferObject 9 | { 10 | public VertexBufferObject() 11 | { 12 | Target = BufferTarget.ArrayBuffer; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Render/OpenGL/FlushRenderBackend.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Render.OpenGL 5 | { 6 | public enum FlushRenderBackend 7 | { 8 | /// 9 | /// No flush. 10 | /// 11 | None, 12 | 13 | /// 14 | /// Flush after render pipeline 15 | /// 16 | End, 17 | 18 | /// 19 | /// Flush after every draw call 20 | /// 21 | Draw, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Render/OpenGL/GraphicsTexture.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using OpenToolkit.Mathematics; 6 | using SixLabors.ImageSharp; 7 | using SixLabors.ImageSharp.PixelFormats; 8 | 9 | namespace Aximo.Render.OpenGL 10 | { 11 | public class GraphicsTexture : IDisposable 12 | { 13 | public GraphicsTexture(Vector2i size) : this(size.X, size.Y) 14 | { 15 | } 16 | 17 | public GraphicsTexture(int width, int height) 18 | { 19 | Image = new Image(width, height); 20 | Texture = new RendererTexture(Image, "GraphicsTexture"); 21 | UpdateTexture(); 22 | } 23 | 24 | private Image Image; 25 | 26 | public RendererTexture Texture { get; private set; } 27 | 28 | public void UpdateTexture() 29 | { 30 | // Graphics.Save(); 31 | // Graphics.Dispose(); 32 | Texture.SetData(Image); 33 | } 34 | 35 | public void Dispose() 36 | { 37 | Image?.Dispose(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Render/OpenGL/InternalLightManager.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Aximo.Render.OpenGL 8 | { 9 | public static class InternalLightManager 10 | { 11 | private static SlotAllocator PointLayer = new SlotAllocator(Enumerable.Range(0, 2), nameof(PointLayer)); 12 | private static SlotAllocator DirectionalLayer = new SlotAllocator(Enumerable.Range(0, 2), nameof(DirectionalLayer)); 13 | 14 | private static SlotAllocator GetAllocator(ILightObject lightObject) 15 | { 16 | switch (lightObject.LightType) 17 | { 18 | case LightType.Point: 19 | return PointLayer; 20 | case LightType.Directional: 21 | return DirectionalLayer; 22 | default: 23 | throw new ArgumentOutOfRangeException(nameof(lightObject), nameof(lightObject.LightType)); 24 | } 25 | } 26 | 27 | public static void RequestShadowLayer(ILightObject lightObject) 28 | { 29 | lightObject.ShadowTextureIndex = GetAllocator(lightObject).Alloc(); 30 | } 31 | 32 | public static void FreeShadowLayer(ILightObject lightObject) 33 | { 34 | GetAllocator(lightObject).Free(lightObject.ShadowTextureIndex); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Render/OpenGL/Mesh/DynamicInternalMesh.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Render.OpenGL 5 | { 6 | public class DynamicInternalMesh : InternalMesh 7 | { 8 | public DynamicInternalMesh() : base() { } 9 | public DynamicInternalMesh(Mesh meshData) : base(meshData) { } 10 | public DynamicInternalMesh(Mesh meshData, RendererMaterial material) : base(meshData, material) { } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Render/OpenGL/Mesh/StaticInternalMesh.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Render.OpenGL 5 | { 6 | public class StaticInternalMesh : InternalMesh 7 | { 8 | public StaticInternalMesh() : base() { } 9 | public StaticInternalMesh(Mesh meshData) : base(meshData) { } 10 | public StaticInternalMesh(Mesh meshData, RendererMaterial material) : base(meshData, material) { } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Render/OpenGL/RenderBuffer.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Graphics.OpenGL4; 5 | 6 | namespace Aximo.Render.OpenGL 7 | { 8 | public class RenderBuffer : IObjectLabel 9 | { 10 | private int _Handle; 11 | public int Handle => _Handle; 12 | 13 | private string _ObjectLabel; 14 | public string ObjectLabel { get => _ObjectLabel; set { _ObjectLabel = value; ObjectManager.SetLabel(this); } } 15 | 16 | private RenderbufferTarget Target = RenderbufferTarget.Renderbuffer; 17 | public RenderbufferStorage RenderBufferStorage; 18 | private FramebufferAttachment FrameBufferAttachment; 19 | 20 | public ObjectLabelIdentifier ObjectLabelIdentifier => ObjectLabelIdentifier.Renderbuffer; 21 | 22 | public RenderBuffer(FrameBuffer fb, RenderbufferStorage renderbufferStorage, FramebufferAttachment framebufferAttachment) 23 | { 24 | Target = RenderbufferTarget.Renderbuffer; 25 | RenderBufferStorage = renderbufferStorage; 26 | FrameBufferAttachment = framebufferAttachment; 27 | 28 | fb.Bind(); 29 | 30 | GL.GenRenderbuffers(1, out _Handle); 31 | Bind(); 32 | GL.RenderbufferStorage(Target, renderbufferStorage, fb.Width, fb.Height); 33 | GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, framebufferAttachment, Target, _Handle); 34 | } 35 | 36 | public void Bind() 37 | { 38 | GL.BindRenderbuffer(Target, _Handle); 39 | } 40 | 41 | public void Resize(FrameBuffer fb) 42 | { 43 | fb.Bind(); 44 | GL.RenderbufferStorage(Target, RenderBufferStorage, fb.Width, fb.Height); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Render/OpenGL/ShaderCompilation.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using OpenToolkit.Graphics.OpenGL4; 8 | 9 | namespace Aximo.Render.OpenGL 10 | { 11 | public class ShaderCompilation : IObjectLabel 12 | { 13 | public List Sources = new List(); 14 | public ShaderType Type; 15 | public int Handle { get; internal set; } 16 | public string ObjectLabel { get { return Path.GetFileName(Sources.First().Path); } set { } } 17 | 18 | public ObjectLabelIdentifier ObjectLabelIdentifier => ObjectLabelIdentifier.Shader; 19 | 20 | public string AllSources() => string.Join("\n", Sources.Select(s => s.Source)); 21 | 22 | public void GenerateSource() 23 | { 24 | SetOrdinals(); 25 | foreach (var source in Sources) 26 | source.GenerateSource(); 27 | } 28 | 29 | public void SetOrdinals() 30 | { 31 | int ordinal = 0; 32 | foreach (var source in Sources) 33 | source.Ordinal = ordinal++; 34 | } 35 | 36 | public IDictionary Defines { get; } = new Dictionary(); 37 | 38 | public void SetDefine(string name) 39 | { 40 | SetDefine(name, null); 41 | } 42 | 43 | public void SetDefine(string name, object value) 44 | { 45 | if (Defines.ContainsKey(name)) 46 | Defines[name] = value; 47 | else 48 | Defines.Add(name, value); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Render/OpenGL/StructHelper.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using OpenToolkit.Graphics.OpenGL4; 6 | using OpenToolkit.Mathematics; 7 | 8 | namespace Aximo.Render.OpenGL 9 | { 10 | public static class StructHelper 11 | { 12 | public static VertexAttribPointerType GetVertexAttribPointerType(Type type) 13 | { 14 | if (type == typeof(float)) 15 | return VertexAttribPointerType.Float; 16 | return VertexAttribPointerType.Float; 17 | } 18 | 19 | public static int GetFieldSizeOf(Type type) 20 | { 21 | if (type == typeof(float)) 22 | return 4; 23 | 24 | return 4; 25 | } 26 | 27 | public static int GetFieldsOf(Type type) 28 | { 29 | if (type == typeof(float)) 30 | return 1; 31 | if (type == typeof(Vector4)) 32 | return 4; 33 | if (type == typeof(Vector3)) 34 | return 3; 35 | if (type == typeof(Vector2)) 36 | return 2; 37 | 38 | return type.GetFields().Length; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Render/OpenGL/VertexLayoutBindedAttribute.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.Render.OpenGL 5 | { 6 | public class VertexLayoutBindedAttribute : VertexLayoutDefinitionAttribute 7 | { 8 | public int Index; 9 | 10 | internal override string GetDumpString() 11 | { 12 | return $"{base.GetDumpString()}, Index: {Index}"; 13 | } 14 | 15 | public override int GetHashCode() 16 | { 17 | return Hashing.HashInteger(Index, base.GetHashCode()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Render/OpenGL/VertexLayoutDefinitionAttribute.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Graphics.OpenGL4; 5 | using SixLabors.ImageSharp.PixelFormats; 6 | 7 | namespace Aximo.Render.OpenGL 8 | { 9 | public class VertexLayoutDefinitionAttribute 10 | { 11 | public string Name; 12 | public int Size; 13 | public VertexAttribPointerType Type; 14 | public bool Normalized; 15 | public int Stride; 16 | public int Offset; 17 | 18 | public override int GetHashCode() 19 | { 20 | return Hashing.HashInteger(Name.GetHashCode(), Size, (int)Type, Normalized ? 1 : 0, Stride, Offset); 21 | } 22 | 23 | public void CopyTo(VertexLayoutDefinitionAttribute destination) 24 | { 25 | destination.Name = Name; 26 | destination.Size = Size; 27 | destination.Type = Type; 28 | destination.Normalized = Normalized; 29 | destination.Stride = Stride; 30 | destination.Offset = Offset; 31 | } 32 | 33 | internal virtual string GetDumpString() 34 | { 35 | return $"Name: {Name}, Size: {Size}, Type: {Type}, Normalized: {Normalized}, Stride: {Stride}, Offset: {Offset}"; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Render/Pipelines/DirectionalShadowRenderPipeline.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using Aximo.Render.OpenGL; 6 | using OpenToolkit.Graphics.OpenGL4; 7 | 8 | namespace Aximo.Render.Pipelines 9 | { 10 | public class DirectionalShadowRenderPipeline : RenderPipeline 11 | { 12 | public FrameBuffer FrameBuffer { get; private set; } 13 | 14 | public override void Init() 15 | { 16 | FrameBuffer = new FrameBuffer(1024, 1024); 17 | FrameBuffer.InitDepth(); 18 | } 19 | 20 | public override void Render(RenderContext context, Camera camera) 21 | { 22 | GL.Viewport(0, 0, FrameBuffer.Width, FrameBuffer.Height); 23 | FrameBuffer.Bind(); 24 | GL.Clear(ClearBufferMask.DepthBufferBit); 25 | 26 | foreach (var obj in GetRenderObjects(context, camera)) 27 | Render(context, camera, obj); 28 | } 29 | 30 | public override IEnumerable GetRenderObjects(RenderContext context, Camera camera) 31 | { 32 | return SortFromFrontToBack(context, camera, GetRenderObjectsInternal(context, camera)); 33 | } 34 | 35 | private IEnumerable GetRenderObjectsInternal(RenderContext context, Camera camera) 36 | { 37 | foreach (var obj in base.GetRenderObjects(context, camera)) 38 | if (obj is IShadowObject m) 39 | if (m.RenderShadow) 40 | yield return m; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Render/Pipelines/PointShadowRenderPipeline.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using Aximo.Render.OpenGL; 6 | using OpenToolkit.Graphics.OpenGL4; 7 | 8 | namespace Aximo.Render.Pipelines 9 | { 10 | public class PointShadowRenderPipeline : RenderPipeline 11 | { 12 | public FrameBuffer FrameBuffer { get; private set; } 13 | 14 | public override void Init() 15 | { 16 | FrameBuffer = new FrameBuffer(1024, 1024); 17 | FrameBuffer.InitCubeDepth(); 18 | } 19 | 20 | public override void Render(RenderContext context, Camera camera) 21 | { 22 | GL.Viewport(0, 0, FrameBuffer.Width, FrameBuffer.Height); 23 | FrameBuffer.Bind(); 24 | GL.Clear(ClearBufferMask.DepthBufferBit); 25 | 26 | foreach (var obj in GetRenderObjects(context, camera)) 27 | Render(context, camera, obj); 28 | } 29 | 30 | public override IEnumerable GetRenderObjects(RenderContext context, Camera camera) 31 | { 32 | return SortFromFrontToBack(context, camera, GetRenderObjectsInternal(context, camera)); 33 | } 34 | 35 | private IEnumerable GetRenderObjectsInternal(RenderContext context, Camera camera) 36 | { 37 | foreach (var obj in base.GetRenderObjects(context, camera)) 38 | if (obj is IShadowObject m) 39 | if (m.RenderShadow) 40 | yield return m; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Render/Pipelines/ScreenPipeline.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using OpenToolkit.Graphics.OpenGL4; 7 | 8 | namespace Aximo.Render.Pipelines 9 | { 10 | public class ScreenPipeline : RenderPipeline 11 | { 12 | public override void Init() 13 | { 14 | } 15 | 16 | public override void Render(RenderContext context, Camera camera) 17 | { 18 | GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); 19 | GL.Disable(EnableCap.DepthTest); 20 | GL.ClearColor(1.0f, 0.0f, 1.0f, 1.0f); 21 | GL.Clear(ClearBufferMask.ColorBufferBit); 22 | 23 | foreach (var obj in GetRenderObjects(context, camera).OrderBy(o => o.DrawPriority)) 24 | Render(context, camera, obj); 25 | } 26 | 27 | public override IEnumerable GetRenderObjects(RenderContext context, Camera camera) 28 | { 29 | return SortFromFrontToBack(context, camera, base.GetRenderObjects(context, camera)); 30 | } 31 | 32 | protected override IEnumerable SortFromFrontToBack(RenderContext context, Camera camera, IEnumerable objects) 33 | { 34 | var list = objects.ToList(); 35 | return list; 36 | list.Sort(new MeshDepthSorter(camera, false)); 37 | return list; 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Render/PixelFormatExtensions.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Graphics.OpenGL4; 5 | 6 | namespace Aximo.Render 7 | { 8 | public static class PixelFormatExtensions 9 | { 10 | public static AxPixelFormat ToGamePixelFormat(this PixelFormat format) 11 | { 12 | switch (format) 13 | { 14 | case PixelFormat.Rgba: 15 | return AxPixelFormat.Rgba32; 16 | case PixelFormat.Bgra: 17 | return AxPixelFormat.Bgra32; 18 | case PixelFormat.Rgb: 19 | return AxPixelFormat.Rgb24; 20 | case PixelFormat.Bgr: 21 | return AxPixelFormat.Bgr24; 22 | default: 23 | return AxPixelFormat.None; 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Render/Render.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Aximo.Render 4 | Aximo.Render 5 | netcoreapp3.1 6 | CS0162 7 | ..\props\default.ruleset 8 | true 9 | 10 | 11 | 12 | 13 | Aximo.Render 14 | $(DependencyDescription) 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | true 26 | content\Assets 27 | true 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Render/ScreenResizeEventArgs.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using OpenToolkit.Mathematics; 5 | 6 | namespace Aximo 7 | { 8 | public class ScreenResizeEventArgs 9 | { 10 | public Vector2i OldSize { get; private set; } 11 | public Vector2i Size { get; private set; } 12 | 13 | internal ScreenResizeEventArgs(Vector2i oldSize, Vector2i size) 14 | { 15 | OldSize = oldSize; 16 | Size = size; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Xunit; 5 | 6 | [assembly: CollectionBehavior(DisableTestParallelization = true)] 7 | -------------------------------------------------------------------------------- /Tests/Assets/.gitignore: -------------------------------------------------------------------------------- 1 | *.current 2 | *.current.* 3 | *.original1 4 | *.current1.* 5 | *.original2 6 | *.current2.* 7 | Diffs/ 8 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxDeferredColorAmbient0.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:3da90c1b363972449faef555c26b0b2f3e2a2fd05f85f69701dd23d6abf0c6a9 3 | size 1986 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxDeferredColorAmbient0.2.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:083a5ca8e8eb2b3d031990702aae3ae9d13d86d7d78365ab51625d96bd4eac95 3 | size 1873 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxDeferredColorAmbient1.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e7a31150d4905046c040f760c4d2a96cfa2904b4ce20cd183e07d2bc6a908386 3 | size 1635 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxDeferredTextureAmbient0.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:f94b3ff1944eaee16aaae24a5fdd0a471f30534fa9539ab87e75b58a6e122daa 3 | size 4109 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxDeferredTextureAmbient0.2.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e468fffe3677bf8a149b1b51afda9fe79f0dd64a38599885dac5c2483c13fe2a 3 | size 4541 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxDeferredTextureAmbient1.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:c3697098943a127b4bf7675fcf844f43462b835677ae3eccc5c1b8fa65b01ea2 3 | size 4708 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxForwardColorAmbient0.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:82bcab4828671b39a8098e6bcf31b64f12c6f38ec9cc22c3b68063654b338cb5 3 | size 1995 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxForwardColorAmbient0.2.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:ab4367bdd6c54af99412e0c548d9054a28dd3250028543804165eed9cfbfcda6 3 | size 1861 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxForwardColorAmbient1.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:fb497b0a969874ee575515db21af726a9d6a0d03cb1247ac28fa777e6a4e3548 3 | size 1644 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxForwardTextureAmbient0.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:c2bc78ce39b1ae570066e00c22f9b710392455a50401891ae29e17c60f819c88 3 | size 4121 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxForwardTextureAmbient0.2.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:2fd3148b118b99798886e4bcfc44b90b2452e9f5c5ce9448e0c3b8da15d17e77 3 | size 4535 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTests/BoxForwardTextureAmbient1.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:363c91a9b3f94a30b324ffc3c83ca16ea58cdba340f8f3274671a73c9e32b432 3 | size 4718 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTypeTests/BoxDeferredColorAmbient0.2Directional.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:083a5ca8e8eb2b3d031990702aae3ae9d13d86d7d78365ab51625d96bd4eac95 3 | size 1873 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTypeTests/BoxDeferredColorAmbient0.2Point.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:f4925ef6275a6444da096ff76936ae3f54dfbb761ffc5eb0f3affca44e4a4c76 3 | size 2066 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTypeTests/BoxForwardColorAmbient0.2Directional.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:ab4367bdd6c54af99412e0c548d9054a28dd3250028543804165eed9cfbfcda6 3 | size 1861 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/LightTypeTests/BoxForwardColorAmbient0.2Point.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:cd76567fe408a8363da4a8039198a963248945f291d8ac4ab5d05a9675d32942 3 | size 2056 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/MeshRenderTests/Bomb.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:70f90ae4bdda8896919a38a30e47870c7a433a4d3b4ad8ab8432bd2c65648b0b 3 | size 2348 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/MeshRenderTests/Sphere.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:1286fad28065d35dc3fdedefb4872ad85c5cd614d08c9bf0acf7fb2589d2ddb5 3 | size 2398 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxDeferredColorAmbient0.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:878c41507ad838afe022376d498820baa4a1f0f81e314bf53f3dddbbe75f103b 3 | size 544 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxDeferredColorAmbient0.5.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:90d3b7d6ad4eeba0a5c775683a95fbab2e1ec551e40fe8da304b848dd9a2ad43 3 | size 545 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxDeferredColorAmbient1.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:3bb14b0b975f336e63bda17610cd75d4dca2740cf3deffade53c6fa405779c42 3 | size 545 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxDeferredTextureAmbient0.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:878c41507ad838afe022376d498820baa4a1f0f81e314bf53f3dddbbe75f103b 3 | size 544 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxDeferredTextureAmbient0.5.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:def870fcbff590c26b08718416a908c65be36cb2b72c18634bd7a36f74284447 3 | size 4177 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxDeferredTextureAmbient1.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:008f498a3dd9669d69655dc09dc43fc330d376ea1ac55b4844757fc73f64c8eb 3 | size 4530 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxForwardColorAmbient0.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:878c41507ad838afe022376d498820baa4a1f0f81e314bf53f3dddbbe75f103b 3 | size 544 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxForwardColorAmbient0.5.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:90d3b7d6ad4eeba0a5c775683a95fbab2e1ec551e40fe8da304b848dd9a2ad43 3 | size 545 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxForwardColorAmbient1.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:3bb14b0b975f336e63bda17610cd75d4dca2740cf3deffade53c6fa405779c42 3 | size 545 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxForwardTextureAmbient0.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:878c41507ad838afe022376d498820baa4a1f0f81e314bf53f3dddbbe75f103b 3 | size 544 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxForwardTextureAmbient0.5.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:b26375d7abb0195cc2e5b90b8eb20b11f79bc3505ec57f778f0202a3355ad40d 3 | size 4164 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/RenderTests/BoxForwardTextureAmbient1.0.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:008f498a3dd9669d69655dc09dc43fc330d376ea1ac55b4844757fc73f64c8eb 3 | size 4530 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/ShadowTypeTests/BoxDeferredDirectional.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:5b4ccf87b94731aeae40dbe0b04e329f4642eb284fff5a22e6924063e80cb366 3 | size 1587 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/ShadowTypeTests/BoxDeferredPoint.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:6c10ddd6b273f84995f2b74385454974c73ef347f16ca7d497a67e4a30024f7f 3 | size 5772 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/ShadowTypeTests/BoxForwardDirectional.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:8717e26eb5dbb52bfac8a5809fd74b3b16957473404a69ed0a9fbf0c7a99e67c 3 | size 1572 4 | -------------------------------------------------------------------------------- /Tests/Assets/TestOutputs/ShadowTypeTests/BoxForwardPoint.png: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:481c971255de7f7cfd6e8b5da1880bce4aaf79d29d0d0e2340e8062880552126 3 | size 5740 4 | -------------------------------------------------------------------------------- /Tests/Program.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace Aximo.AxTests 8 | { 9 | internal class Program 10 | { 11 | public static void Main(string[] args) 12 | { 13 | // var tester = new ShadowTypeTests(); 14 | // tester.Box(new ShadowTypeTests.TestCase 15 | // { 16 | // Pipeline = PipelineType.Deferred, 17 | // LightType = LightType.Directional, 18 | // ComparisonName = "Deferred", 19 | // }); 20 | // tester.Dispose(); 21 | 22 | // var tester2 = new ShadowTypeTests(); 23 | // tester2.Box(new ShadowTypeTests.TestCase 24 | // { 25 | // Pipeline = PipelineType.Deferred, 26 | // LightType = LightType.Point, 27 | // ComparisonName = "Deferred", 28 | // }); 29 | // tester.Dispose(); 30 | 31 | foreach (var testCaseArgs in ShadowTypeTests.GetTestData().Reverse()) 32 | { 33 | var testCase = (ShadowTypeTests.TestCase)testCaseArgs[0]; 34 | if (testCase.CompareWith != null) 35 | continue; 36 | 37 | using (var tester = new ShadowTypeTests()) 38 | tester.Box(testCase); 39 | } 40 | 41 | //Console.ReadLine(); 42 | Environment.Exit(0); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tests/TestConfig.cs: -------------------------------------------------------------------------------- 1 | // This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Aximo.AxTests 5 | { 6 | public static class TestConfig 7 | { 8 | public static bool ComparePipelines { get; set; } = true; 9 | } 10 | } -------------------------------------------------------------------------------- /Tests/Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | AxTests 4 | AxTests 5 | netcoreapp3.1 6 | 7 | Exe 8 | 9 | CS0162 10 | ..\props\default.ruleset 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | all 26 | runtime; build; native; contentfiles; analyzers; buildtransitive 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Tests/run-tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # exit when any command fails 4 | set -e 5 | 6 | ORIGIN_DIR=$(pwd) 7 | THIS_DIR=$(dirname $0) 8 | 9 | cd $THIS_DIR 10 | #dotnet msbuild /p:Configuration=Debug /property:GenerateFullPaths=true 11 | #mono --debug ~/.nuget/packages/xunit.runner.console/2.4.1/tools/net472/xunit.console.exe bin/Debug/net472/AxTests.exe -parallel none -noshadow -verbose 12 | 13 | dotnet test 14 | -------------------------------------------------------------------------------- /props/AssemblyVersion.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 1.0.11 6 | 7 | 8 | 9 | 10 | 11 | $(AssemblyVersion) 12 | $(AssemblyVersion) 13 | $(AssemblyVersion)-$(VersionPostfix) 14 | 15 | 16 | -------------------------------------------------------------------------------- /props/Aximo.Nuget.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netcoreapp3.1 4 | 5 | 6 | 7 | 8 | Aximo 9 | $(CommonDescription) 10 | 11 | 12 | false 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /props/Nuspec.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sebastian Loncar (Arakis) 4 | 3D Game Engine OpenGL Render Rendering Mesh OpenTK OpenToolkit Graphics 5 | true 6 | true 7 | https://github.com/AximoGames/AxEngine 8 | MIT 9 | true 10 | $(MSBuildThisFileDirectory)\..\.cache\packages 11 | 12 | 13 | 14 | Aximo Game Engine is an Open Source Game Engine written purly in C#. 15 | Documentation: https://www.aximo.games 16 | Source: https://github.com/AximoGames/AxEngine 17 | 18 | 19 | Do not use reference this package directly. Use this meta package: https://www.nuget.org/packages/Aximo 20 | 21 | $(CommonDescription) 22 | 23 | 24 | -------------------------------------------------------------------------------- /props/stylecop.json: -------------------------------------------------------------------------------- 1 | { 2 | // ACTION REQUIRED: This file was automatically added to your project, but it 3 | // will not take effect until additional steps are taken to enable it. See the 4 | // following page for additional information: 5 | // 6 | // https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md 7 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", 8 | "settings": { 9 | "readabilityRules": { 10 | "allowBuiltInTypeAliases": true 11 | }, 12 | "documentationRules": { 13 | "companyName": "Aximo Games", 14 | "copyrightText": "This file is part of Aximo, a Game Engine written in C#. Web: https://github.com/AximoGames\nLicensed under the {licenseName} license. See {licenseFile} file in the project root for full license information.", 15 | "xmlHeader": false, 16 | "variables": { 17 | "licenseName": "MIT", 18 | "licenseFile": "LICENSE" 19 | } 20 | } 21 | } 22 | } --------------------------------------------------------------------------------