From 2a875c8bdc0fedd5eb503004271f3af6fbc42304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Thu, 27 Aug 2020 19:43:31 +0200 Subject: [PATCH] Remove Graphics module and fix compilation --- build/scripts/modules/graphics.lua | 8 - .../{build.lua => build_disabled.lua} | 0 examples/HardwareInfo/main.cpp | 32 - .../{build.lua => build_disabled.lua} | 0 .../Tut00/{build.lua => build_disabled.lua} | 0 .../Tut01/{build.lua => build_disabled.lua} | 0 .../Tut02/{build.lua => build_disabled.lua} | 0 include/Nazara/Graphics.hpp | 87 - .../Nazara/Graphics/AbstractBackground.hpp | 45 - .../Nazara/Graphics/AbstractRenderQueue.hpp | 105 -- .../Graphics/AbstractRenderTechnique.hpp | 47 - include/Nazara/Graphics/AbstractViewer.hpp | 53 - include/Nazara/Graphics/BasicRenderQueue.hpp | 142 -- include/Nazara/Graphics/BasicRenderQueue.inl | 38 - include/Nazara/Graphics/Billboard.hpp | 70 - include/Nazara/Graphics/Billboard.inl | 272 --- include/Nazara/Graphics/ColorBackground.hpp | 51 - include/Nazara/Graphics/ColorBackground.inl | 27 - include/Nazara/Graphics/Config.hpp | 64 - include/Nazara/Graphics/ConfigCheck.hpp | 26 - include/Nazara/Graphics/CullingList.hpp | 215 --- include/Nazara/Graphics/CullingList.inl | 498 ------ include/Nazara/Graphics/Debug.hpp | 8 - include/Nazara/Graphics/DebugOff.hpp | 9 - include/Nazara/Graphics/DeferredBloomPass.hpp | 57 - include/Nazara/Graphics/DeferredDOFPass.hpp | 41 - include/Nazara/Graphics/DeferredFXAAPass.hpp | 33 - include/Nazara/Graphics/DeferredFinalPass.hpp | 36 - include/Nazara/Graphics/DeferredFogPass.hpp | 34 - .../Nazara/Graphics/DeferredForwardPass.hpp | 31 - .../Nazara/Graphics/DeferredGeometryPass.hpp | 78 - .../Graphics/DeferredPhongLightingPass.hpp | 52 - .../Graphics/DeferredProxyRenderQueue.hpp | 58 - .../Graphics/DeferredProxyRenderQueue.inl | 30 - .../Nazara/Graphics/DeferredRenderPass.hpp | 57 - .../Nazara/Graphics/DeferredRenderQueue.inl | 0 .../Graphics/DeferredRenderTechnique.hpp | 80 - include/Nazara/Graphics/DepthRenderQueue.hpp | 46 - include/Nazara/Graphics/DepthRenderQueue.inl | 25 - .../Nazara/Graphics/DepthRenderTechnique.hpp | 92 - .../Nazara/Graphics/DepthRenderTechnique.inl | 3 - include/Nazara/Graphics/Drawable.hpp | 25 - include/Nazara/Graphics/Enums.hpp | 183 -- .../Graphics/ForwardRenderTechnique.hpp | 116 -- .../Graphics/ForwardRenderTechnique.inl | 98 -- include/Nazara/Graphics/Graphics.hpp | 32 - .../Graphics/GuillotineTextureAtlas.hpp | 29 - .../Nazara/Graphics/InstancedRenderable.hpp | 132 -- .../Nazara/Graphics/InstancedRenderable.inl | 280 --- include/Nazara/Graphics/Light.hpp | 121 -- include/Nazara/Graphics/Light.inl | 404 ----- include/Nazara/Graphics/Material.hpp | 230 --- include/Nazara/Graphics/Material.inl | 1504 ----------------- include/Nazara/Graphics/MaterialPipeline.hpp | 95 -- include/Nazara/Graphics/MaterialPipeline.inl | 147 -- include/Nazara/Graphics/Model.hpp | 100 -- include/Nazara/Graphics/Model.inl | 72 - .../Nazara/Graphics/ParticleController.hpp | 50 - .../Nazara/Graphics/ParticleDeclaration.hpp | 83 - .../Nazara/Graphics/ParticleDeclaration.inl | 20 - include/Nazara/Graphics/ParticleEmitter.hpp | 56 - .../Graphics/ParticleFunctionController.hpp | 45 - .../Graphics/ParticleFunctionController.inl | 45 - .../Graphics/ParticleFunctionGenerator.hpp | 45 - .../Graphics/ParticleFunctionGenerator.inl | 45 - .../Graphics/ParticleFunctionRenderer.hpp | 45 - .../Graphics/ParticleFunctionRenderer.inl | 45 - include/Nazara/Graphics/ParticleGenerator.hpp | 50 - include/Nazara/Graphics/ParticleGroup.hpp | 99 -- include/Nazara/Graphics/ParticleGroup.inl | 38 - include/Nazara/Graphics/ParticleMapper.hpp | 35 - include/Nazara/Graphics/ParticleMapper.inl | 86 - include/Nazara/Graphics/ParticleRenderer.hpp | 51 - include/Nazara/Graphics/ParticleStruct.hpp | 46 - include/Nazara/Graphics/RenderQueue.hpp | 101 -- include/Nazara/Graphics/RenderQueue.inl | 136 -- include/Nazara/Graphics/RenderTechniques.hpp | 42 - include/Nazara/Graphics/Renderable.hpp | 53 - include/Nazara/Graphics/Renderable.inl | 35 - include/Nazara/Graphics/SceneData.hpp | 27 - include/Nazara/Graphics/SkeletalModel.hpp | 84 - include/Nazara/Graphics/SkeletalModel.inl | 27 - include/Nazara/Graphics/SkinningManager.hpp | 43 - include/Nazara/Graphics/SkyboxBackground.hpp | 60 - include/Nazara/Graphics/SkyboxBackground.inl | 128 -- include/Nazara/Graphics/Sprite.hpp | 88 - include/Nazara/Graphics/Sprite.inl | 374 ---- include/Nazara/Graphics/TextSprite.hpp | 114 -- include/Nazara/Graphics/TextSprite.inl | 209 --- include/Nazara/Graphics/TextureBackground.hpp | 48 - include/Nazara/Graphics/TextureBackground.inl | 50 - include/Nazara/Graphics/TileMap.hpp | 99 -- include/Nazara/Graphics/TileMap.inl | 435 ----- include/NazaraSDK/Application.hpp | 56 - include/NazaraSDK/Application.inl | 186 +- include/NazaraSDK/BaseWidget.hpp | 179 -- include/NazaraSDK/BaseWidget.inl | 275 --- include/NazaraSDK/Canvas.hpp | 89 - include/NazaraSDK/Canvas.inl | 91 - .../NazaraSDK/Components/CameraComponent.hpp | 120 -- .../NazaraSDK/Components/CameraComponent.inl | 353 ---- .../NazaraSDK/Components/DebugComponent.hpp | 91 - .../NazaraSDK/Components/DebugComponent.inl | 74 - .../Components/GraphicsComponent.hpp | 170 -- .../Components/GraphicsComponent.inl | 291 ---- .../NazaraSDK/Components/LightComponent.hpp | 36 - .../NazaraSDK/Components/LightComponent.inl | 15 - .../Components/ParticleEmitterComponent.hpp | 49 - .../Components/ParticleEmitterComponent.inl | 47 - .../Components/ParticleGroupComponent.hpp | 41 - .../Components/ParticleGroupComponent.inl | 76 - include/NazaraSDK/Console.hpp | 88 - include/NazaraSDK/Console.inl | 46 - include/NazaraSDK/Systems/DebugSystem.hpp | 58 - include/NazaraSDK/Systems/DebugSystem.inl | 13 - include/NazaraSDK/Systems/ParticleSystem.hpp | 31 - include/NazaraSDK/Systems/ParticleSystem.inl | 3 - include/NazaraSDK/Systems/RenderSystem.hpp | 85 - include/NazaraSDK/Systems/RenderSystem.inl | 186 -- include/NazaraSDK/Widgets.hpp | 20 - .../Widgets/AbstractTextAreaWidget.hpp | 135 -- .../Widgets/AbstractTextAreaWidget.inl | 252 --- include/NazaraSDK/Widgets/BoxLayout.hpp | 48 - include/NazaraSDK/Widgets/BoxLayout.inl | 15 - include/NazaraSDK/Widgets/ButtonWidget.hpp | 99 -- include/NazaraSDK/Widgets/ButtonWidget.inl | 102 -- include/NazaraSDK/Widgets/CheckboxWidget.hpp | 105 -- include/NazaraSDK/Widgets/CheckboxWidget.inl | 94 -- include/NazaraSDK/Widgets/Enums.hpp | 37 - include/NazaraSDK/Widgets/ImageWidget.hpp | 51 - include/NazaraSDK/Widgets/ImageWidget.inl | 47 - include/NazaraSDK/Widgets/LabelWidget.hpp | 42 - include/NazaraSDK/Widgets/LabelWidget.inl | 17 - .../NazaraSDK/Widgets/ProgressBarWidget.hpp | 101 -- .../NazaraSDK/Widgets/ProgressBarWidget.inl | 155 -- .../NazaraSDK/Widgets/RichTextAreaWidget.hpp | 68 - .../NazaraSDK/Widgets/RichTextAreaWidget.inl | 88 - .../NazaraSDK/Widgets/ScrollAreaWidget.hpp | 74 - .../NazaraSDK/Widgets/ScrollAreaWidget.inl | 39 - include/NazaraSDK/Widgets/TextAreaWidget.hpp | 77 - include/NazaraSDK/Widgets/TextAreaWidget.inl | 124 -- plugins/Assimp/Plugin.cpp | 30 +- src/Nazara/Graphics/AbstractBackground.cpp | 21 - src/Nazara/Graphics/AbstractRenderQueue.cpp | 67 - .../Graphics/AbstractRenderTechnique.cpp | 62 - src/Nazara/Graphics/AbstractViewer.cpp | 66 - src/Nazara/Graphics/BasicRenderQueue.cpp | 957 ----------- src/Nazara/Graphics/Billboard.cpp | 53 - src/Nazara/Graphics/ColorBackground.cpp | 114 -- src/Nazara/Graphics/Debug/NewOverload.cpp | 31 - src/Nazara/Graphics/DeferredBloomPass.cpp | 248 --- src/Nazara/Graphics/DeferredDOFPass.cpp | 213 --- src/Nazara/Graphics/DeferredFXAAPass.cpp | 61 - src/Nazara/Graphics/DeferredFinalPass.cpp | 81 - src/Nazara/Graphics/DeferredFogPass.cpp | 178 -- src/Nazara/Graphics/DeferredForwardPass.cpp | 67 - src/Nazara/Graphics/DeferredGeometryPass.cpp | 716 -------- .../Graphics/DeferredPhongLightingPass.cpp | 327 ---- .../Graphics/DeferredProxyRenderQueue.cpp | 261 --- src/Nazara/Graphics/DeferredRenderPass.cpp | 86 - .../Graphics/DeferredRenderTechnique.cpp | 742 -------- src/Nazara/Graphics/DepthRenderQueue.cpp | 372 ---- src/Nazara/Graphics/DepthRenderTechnique.cpp | 674 -------- src/Nazara/Graphics/Drawable.cpp | 19 - src/Nazara/Graphics/Formats/MeshLoader.cpp | 100 -- src/Nazara/Graphics/Formats/MeshLoader.hpp | 21 - src/Nazara/Graphics/Formats/TextureLoader.cpp | 56 - src/Nazara/Graphics/Formats/TextureLoader.hpp | 21 - .../Graphics/ForwardRenderTechnique.cpp | 924 ---------- src/Nazara/Graphics/Graphics.cpp | 269 --- .../Graphics/GuillotineTextureAtlas.cpp | 70 - src/Nazara/Graphics/InstancedRenderable.cpp | 101 -- src/Nazara/Graphics/Light.cpp | 267 --- src/Nazara/Graphics/Material.cpp | 503 ------ src/Nazara/Graphics/MaterialPipeline.cpp | 235 --- src/Nazara/Graphics/Model.cpp | 289 ---- src/Nazara/Graphics/ParticleController.cpp | 69 - src/Nazara/Graphics/ParticleDeclaration.cpp | 337 ---- src/Nazara/Graphics/ParticleEmitter.cpp | 169 -- .../Graphics/ParticleFunctionController.cpp | 29 - .../Graphics/ParticleFunctionGenerator.cpp | 28 - .../Graphics/ParticleFunctionRenderer.cpp | 29 - src/Nazara/Graphics/ParticleGenerator.cpp | 69 - src/Nazara/Graphics/ParticleGroup.cpp | 492 ------ src/Nazara/Graphics/ParticleMapper.cpp | 31 - src/Nazara/Graphics/ParticleRenderer.cpp | 67 - src/Nazara/Graphics/RenderQueue.cpp | 18 - src/Nazara/Graphics/RenderTechniques.cpp | 247 --- src/Nazara/Graphics/Renderable.cpp | 57 - .../DeferredShading/Shaders/BloomBright.frag | 23 - .../Shaders/BloomBright.frag.h | 1 - .../DeferredShading/Shaders/BloomFinal.frag | 17 - .../DeferredShading/Shaders/BloomFinal.frag.h | 1 - .../Shaders/DirectionalLight.frag | 77 - .../Shaders/DirectionalLight.frag.h | 1 - .../DeferredShading/Shaders/FXAA.frag | 47 - .../DeferredShading/Shaders/FXAA.frag.h | 1 - .../DeferredShading/Shaders/GBufferClear.frag | 13 - .../Shaders/GBufferClear.frag.h | 1 - .../DeferredShading/Shaders/GaussianBlur.frag | 25 - .../Shaders/GaussianBlur.frag.h | 1 - .../Shaders/PointSpotLight.frag | 108 -- .../Shaders/PointSpotLight.frag.h | 1 - .../DeferredShading/Textures/ssaoNoise.jpg.h | 1 - .../Resources/Shaders/Basic/core.frag | 49 - .../Resources/Shaders/Basic/core.frag.h | 1 - .../Resources/Shaders/Basic/core.vert | 103 -- .../Resources/Shaders/Basic/core.vert.h | 1 - .../Resources/Shaders/PhongLighting/core.frag | 475 ------ .../Shaders/PhongLighting/core.frag.h | 1 - .../Resources/Shaders/PhongLighting/core.vert | 148 -- .../Shaders/PhongLighting/core.vert.h | 1 - src/Nazara/Graphics/SkeletalModel.cpp | 395 ----- src/Nazara/Graphics/SkinningManager.cpp | 262 --- src/Nazara/Graphics/SkyboxBackground.cpp | 220 --- src/Nazara/Graphics/Sprite.cpp | 225 --- src/Nazara/Graphics/TextSprite.cpp | 343 ---- src/Nazara/Graphics/TextureBackground.cpp | 98 -- src/Nazara/Graphics/TileMap.cpp | 135 -- src/NazaraSDK/Application.cpp | 123 -- src/NazaraSDK/BaseWidget.cpp | 381 ----- src/NazaraSDK/Canvas.cpp | 230 --- src/NazaraSDK/Components/CameraComponent.cpp | 363 ---- src/NazaraSDK/Components/DebugComponent.cpp | 35 - .../Components/GraphicsComponent.cpp | 348 ---- src/NazaraSDK/Components/LightComponent.cpp | 10 - .../Components/ParticleEmitterComponent.cpp | 30 - .../Components/ParticleGroupComponent.cpp | 10 - src/NazaraSDK/Console.cpp | 232 --- src/NazaraSDK/Sdk.cpp | 31 - src/NazaraSDK/Systems/DebugSystem.cpp | 526 ------ src/NazaraSDK/Systems/ParticleSystem.cpp | 44 - src/NazaraSDK/Systems/RenderSystem.cpp | 428 ----- .../Widgets/AbstractTextAreaWidget.cpp | 489 ------ src/NazaraSDK/Widgets/BoxLayout.cpp | 122 -- src/NazaraSDK/Widgets/ButtonWidget.cpp | 126 -- src/NazaraSDK/Widgets/CheckboxWidget.cpp | 178 -- src/NazaraSDK/Widgets/ImageWidget.cpp | 28 - src/NazaraSDK/Widgets/LabelWidget.cpp | 22 - src/NazaraSDK/Widgets/ProgressBarWidget.cpp | 100 -- src/NazaraSDK/Widgets/RichTextAreaWidget.cpp | 196 --- src/NazaraSDK/Widgets/ScrollAreaWidget.cpp | 198 --- src/NazaraSDK/Widgets/TextAreaWidget.cpp | 253 --- src/NazaraSDK/World.cpp | 6 - tests/Engine/Graphics/Billboard.cpp | 33 - tests/Engine/Graphics/ColorBackground.cpp | 20 - .../Graphics/DeferredRenderTechnique.cpp | 29 - tests/Engine/Graphics/Light.cpp | 31 - tests/Engine/Graphics/Model.cpp | 27 - tests/Engine/Graphics/ParticleDeclaration.cpp | 29 - tests/Engine/Graphics/ParticleGroup.cpp | 103 -- tests/Engine/Graphics/RenderTechniques.cpp | 47 - tests/Engine/Graphics/SkeletalModel.cpp | 25 - tests/Engine/Graphics/SkyboxBackground.cpp | 24 - tests/Engine/Graphics/TextureBackground.cpp | 19 - tests/Engine/Platform/EventHandler.cpp | 81 - .../Platform/EventHandler/BaseState.cpp | 39 - .../Platform/EventHandler/BaseState.hpp | 31 - .../Platform/EventHandler/EventState.cpp | 93 - .../Platform/EventHandler/EventState.hpp | 30 - .../Platform/EventHandler/FocusState.cpp | 41 - .../Platform/EventHandler/FocusState.hpp | 23 - .../Engine/Platform/EventHandler/KeyState.cpp | 77 - .../Engine/Platform/EventHandler/KeyState.hpp | 31 - .../Platform/EventHandler/MenuState.cpp | 47 - .../Platform/EventHandler/MenuState.hpp | 26 - .../Platform/EventHandler/MouseClickState.cpp | 81 - .../Platform/EventHandler/MouseClickState.hpp | 33 - .../Platform/EventHandler/MouseEnterState.cpp | 41 - .../Platform/EventHandler/MouseEnterState.hpp | 23 - .../Platform/EventHandler/MouseMoveState.cpp | 41 - .../Platform/EventHandler/MouseMoveState.hpp | 23 - .../Platform/EventHandler/StateContext.cpp | 7 - .../Platform/EventHandler/StateContext.hpp | 23 - .../Platform/EventHandler/StateFactory.cpp | 46 - .../Platform/EventHandler/StateFactory.hpp | 42 - tests/Engine/Platform/EventHandler/Text.cpp | 35 - tests/Engine/Platform/EventHandler/Text.hpp | 23 - .../Platform/EventHandler/TextEnterState.cpp | 39 - .../Platform/EventHandler/TextEnterState.hpp | 22 - .../EventHandler/WindowModificationState.cpp | 41 - .../EventHandler/WindowModificationState.hpp | 23 - tests/SDK/NDK/Systems/RenderSystem.cpp | 119 -- 283 files changed, 16 insertions(+), 32474 deletions(-) delete mode 100644 build/scripts/modules/graphics.lua rename examples/FirstScene/{build.lua => build_disabled.lua} (100%) rename examples/Particles/{build.lua => build_disabled.lua} (100%) rename examples/Tut00/{build.lua => build_disabled.lua} (100%) rename examples/Tut01/{build.lua => build_disabled.lua} (100%) rename examples/Tut02/{build.lua => build_disabled.lua} (100%) delete mode 100644 include/Nazara/Graphics.hpp delete mode 100644 include/Nazara/Graphics/AbstractBackground.hpp delete mode 100644 include/Nazara/Graphics/AbstractRenderQueue.hpp delete mode 100644 include/Nazara/Graphics/AbstractRenderTechnique.hpp delete mode 100644 include/Nazara/Graphics/AbstractViewer.hpp delete mode 100644 include/Nazara/Graphics/BasicRenderQueue.hpp delete mode 100644 include/Nazara/Graphics/BasicRenderQueue.inl delete mode 100644 include/Nazara/Graphics/Billboard.hpp delete mode 100644 include/Nazara/Graphics/Billboard.inl delete mode 100644 include/Nazara/Graphics/ColorBackground.hpp delete mode 100644 include/Nazara/Graphics/ColorBackground.inl delete mode 100644 include/Nazara/Graphics/Config.hpp delete mode 100644 include/Nazara/Graphics/ConfigCheck.hpp delete mode 100644 include/Nazara/Graphics/CullingList.hpp delete mode 100644 include/Nazara/Graphics/CullingList.inl delete mode 100644 include/Nazara/Graphics/Debug.hpp delete mode 100644 include/Nazara/Graphics/DebugOff.hpp delete mode 100644 include/Nazara/Graphics/DeferredBloomPass.hpp delete mode 100644 include/Nazara/Graphics/DeferredDOFPass.hpp delete mode 100644 include/Nazara/Graphics/DeferredFXAAPass.hpp delete mode 100644 include/Nazara/Graphics/DeferredFinalPass.hpp delete mode 100644 include/Nazara/Graphics/DeferredFogPass.hpp delete mode 100644 include/Nazara/Graphics/DeferredForwardPass.hpp delete mode 100644 include/Nazara/Graphics/DeferredGeometryPass.hpp delete mode 100644 include/Nazara/Graphics/DeferredPhongLightingPass.hpp delete mode 100644 include/Nazara/Graphics/DeferredProxyRenderQueue.hpp delete mode 100644 include/Nazara/Graphics/DeferredProxyRenderQueue.inl delete mode 100644 include/Nazara/Graphics/DeferredRenderPass.hpp delete mode 100644 include/Nazara/Graphics/DeferredRenderQueue.inl delete mode 100644 include/Nazara/Graphics/DeferredRenderTechnique.hpp delete mode 100644 include/Nazara/Graphics/DepthRenderQueue.hpp delete mode 100644 include/Nazara/Graphics/DepthRenderQueue.inl delete mode 100644 include/Nazara/Graphics/DepthRenderTechnique.hpp delete mode 100644 include/Nazara/Graphics/DepthRenderTechnique.inl delete mode 100644 include/Nazara/Graphics/Drawable.hpp delete mode 100644 include/Nazara/Graphics/Enums.hpp delete mode 100644 include/Nazara/Graphics/ForwardRenderTechnique.hpp delete mode 100644 include/Nazara/Graphics/ForwardRenderTechnique.inl delete mode 100644 include/Nazara/Graphics/Graphics.hpp delete mode 100644 include/Nazara/Graphics/GuillotineTextureAtlas.hpp delete mode 100644 include/Nazara/Graphics/InstancedRenderable.hpp delete mode 100644 include/Nazara/Graphics/InstancedRenderable.inl delete mode 100644 include/Nazara/Graphics/Light.hpp delete mode 100644 include/Nazara/Graphics/Light.inl delete mode 100644 include/Nazara/Graphics/Material.hpp delete mode 100644 include/Nazara/Graphics/Material.inl delete mode 100644 include/Nazara/Graphics/MaterialPipeline.hpp delete mode 100644 include/Nazara/Graphics/MaterialPipeline.inl delete mode 100644 include/Nazara/Graphics/Model.hpp delete mode 100644 include/Nazara/Graphics/Model.inl delete mode 100644 include/Nazara/Graphics/ParticleController.hpp delete mode 100644 include/Nazara/Graphics/ParticleDeclaration.hpp delete mode 100644 include/Nazara/Graphics/ParticleDeclaration.inl delete mode 100644 include/Nazara/Graphics/ParticleEmitter.hpp delete mode 100644 include/Nazara/Graphics/ParticleFunctionController.hpp delete mode 100644 include/Nazara/Graphics/ParticleFunctionController.inl delete mode 100644 include/Nazara/Graphics/ParticleFunctionGenerator.hpp delete mode 100644 include/Nazara/Graphics/ParticleFunctionGenerator.inl delete mode 100644 include/Nazara/Graphics/ParticleFunctionRenderer.hpp delete mode 100644 include/Nazara/Graphics/ParticleFunctionRenderer.inl delete mode 100644 include/Nazara/Graphics/ParticleGenerator.hpp delete mode 100644 include/Nazara/Graphics/ParticleGroup.hpp delete mode 100644 include/Nazara/Graphics/ParticleGroup.inl delete mode 100644 include/Nazara/Graphics/ParticleMapper.hpp delete mode 100644 include/Nazara/Graphics/ParticleMapper.inl delete mode 100644 include/Nazara/Graphics/ParticleRenderer.hpp delete mode 100644 include/Nazara/Graphics/ParticleStruct.hpp delete mode 100644 include/Nazara/Graphics/RenderQueue.hpp delete mode 100644 include/Nazara/Graphics/RenderQueue.inl delete mode 100644 include/Nazara/Graphics/RenderTechniques.hpp delete mode 100644 include/Nazara/Graphics/Renderable.hpp delete mode 100644 include/Nazara/Graphics/Renderable.inl delete mode 100644 include/Nazara/Graphics/SceneData.hpp delete mode 100644 include/Nazara/Graphics/SkeletalModel.hpp delete mode 100644 include/Nazara/Graphics/SkeletalModel.inl delete mode 100644 include/Nazara/Graphics/SkinningManager.hpp delete mode 100644 include/Nazara/Graphics/SkyboxBackground.hpp delete mode 100644 include/Nazara/Graphics/SkyboxBackground.inl delete mode 100644 include/Nazara/Graphics/Sprite.hpp delete mode 100644 include/Nazara/Graphics/Sprite.inl delete mode 100644 include/Nazara/Graphics/TextSprite.hpp delete mode 100644 include/Nazara/Graphics/TextSprite.inl delete mode 100644 include/Nazara/Graphics/TextureBackground.hpp delete mode 100644 include/Nazara/Graphics/TextureBackground.inl delete mode 100644 include/Nazara/Graphics/TileMap.hpp delete mode 100644 include/Nazara/Graphics/TileMap.inl delete mode 100644 include/NazaraSDK/BaseWidget.hpp delete mode 100644 include/NazaraSDK/BaseWidget.inl delete mode 100644 include/NazaraSDK/Canvas.hpp delete mode 100644 include/NazaraSDK/Canvas.inl delete mode 100644 include/NazaraSDK/Components/CameraComponent.hpp delete mode 100644 include/NazaraSDK/Components/CameraComponent.inl delete mode 100644 include/NazaraSDK/Components/DebugComponent.hpp delete mode 100644 include/NazaraSDK/Components/DebugComponent.inl delete mode 100644 include/NazaraSDK/Components/GraphicsComponent.hpp delete mode 100644 include/NazaraSDK/Components/GraphicsComponent.inl delete mode 100644 include/NazaraSDK/Components/LightComponent.hpp delete mode 100644 include/NazaraSDK/Components/LightComponent.inl delete mode 100644 include/NazaraSDK/Components/ParticleEmitterComponent.hpp delete mode 100644 include/NazaraSDK/Components/ParticleEmitterComponent.inl delete mode 100644 include/NazaraSDK/Components/ParticleGroupComponent.hpp delete mode 100644 include/NazaraSDK/Components/ParticleGroupComponent.inl delete mode 100644 include/NazaraSDK/Console.hpp delete mode 100644 include/NazaraSDK/Console.inl delete mode 100644 include/NazaraSDK/Systems/DebugSystem.hpp delete mode 100644 include/NazaraSDK/Systems/DebugSystem.inl delete mode 100644 include/NazaraSDK/Systems/ParticleSystem.hpp delete mode 100644 include/NazaraSDK/Systems/ParticleSystem.inl delete mode 100644 include/NazaraSDK/Systems/RenderSystem.hpp delete mode 100644 include/NazaraSDK/Systems/RenderSystem.inl delete mode 100644 include/NazaraSDK/Widgets.hpp delete mode 100644 include/NazaraSDK/Widgets/AbstractTextAreaWidget.hpp delete mode 100644 include/NazaraSDK/Widgets/AbstractTextAreaWidget.inl delete mode 100644 include/NazaraSDK/Widgets/BoxLayout.hpp delete mode 100644 include/NazaraSDK/Widgets/BoxLayout.inl delete mode 100644 include/NazaraSDK/Widgets/ButtonWidget.hpp delete mode 100644 include/NazaraSDK/Widgets/ButtonWidget.inl delete mode 100644 include/NazaraSDK/Widgets/CheckboxWidget.hpp delete mode 100644 include/NazaraSDK/Widgets/CheckboxWidget.inl delete mode 100644 include/NazaraSDK/Widgets/Enums.hpp delete mode 100644 include/NazaraSDK/Widgets/ImageWidget.hpp delete mode 100644 include/NazaraSDK/Widgets/ImageWidget.inl delete mode 100644 include/NazaraSDK/Widgets/LabelWidget.hpp delete mode 100644 include/NazaraSDK/Widgets/LabelWidget.inl delete mode 100644 include/NazaraSDK/Widgets/ProgressBarWidget.hpp delete mode 100644 include/NazaraSDK/Widgets/ProgressBarWidget.inl delete mode 100644 include/NazaraSDK/Widgets/RichTextAreaWidget.hpp delete mode 100644 include/NazaraSDK/Widgets/RichTextAreaWidget.inl delete mode 100644 include/NazaraSDK/Widgets/ScrollAreaWidget.hpp delete mode 100644 include/NazaraSDK/Widgets/ScrollAreaWidget.inl delete mode 100644 include/NazaraSDK/Widgets/TextAreaWidget.hpp delete mode 100644 include/NazaraSDK/Widgets/TextAreaWidget.inl delete mode 100644 src/Nazara/Graphics/AbstractBackground.cpp delete mode 100644 src/Nazara/Graphics/AbstractRenderQueue.cpp delete mode 100644 src/Nazara/Graphics/AbstractRenderTechnique.cpp delete mode 100644 src/Nazara/Graphics/AbstractViewer.cpp delete mode 100644 src/Nazara/Graphics/BasicRenderQueue.cpp delete mode 100644 src/Nazara/Graphics/Billboard.cpp delete mode 100644 src/Nazara/Graphics/ColorBackground.cpp delete mode 100644 src/Nazara/Graphics/Debug/NewOverload.cpp delete mode 100644 src/Nazara/Graphics/DeferredBloomPass.cpp delete mode 100644 src/Nazara/Graphics/DeferredDOFPass.cpp delete mode 100644 src/Nazara/Graphics/DeferredFXAAPass.cpp delete mode 100644 src/Nazara/Graphics/DeferredFinalPass.cpp delete mode 100644 src/Nazara/Graphics/DeferredFogPass.cpp delete mode 100644 src/Nazara/Graphics/DeferredForwardPass.cpp delete mode 100644 src/Nazara/Graphics/DeferredGeometryPass.cpp delete mode 100644 src/Nazara/Graphics/DeferredPhongLightingPass.cpp delete mode 100644 src/Nazara/Graphics/DeferredProxyRenderQueue.cpp delete mode 100644 src/Nazara/Graphics/DeferredRenderPass.cpp delete mode 100644 src/Nazara/Graphics/DeferredRenderTechnique.cpp delete mode 100644 src/Nazara/Graphics/DepthRenderQueue.cpp delete mode 100644 src/Nazara/Graphics/DepthRenderTechnique.cpp delete mode 100644 src/Nazara/Graphics/Drawable.cpp delete mode 100644 src/Nazara/Graphics/Formats/MeshLoader.cpp delete mode 100644 src/Nazara/Graphics/Formats/MeshLoader.hpp delete mode 100644 src/Nazara/Graphics/Formats/TextureLoader.cpp delete mode 100644 src/Nazara/Graphics/Formats/TextureLoader.hpp delete mode 100644 src/Nazara/Graphics/ForwardRenderTechnique.cpp delete mode 100644 src/Nazara/Graphics/Graphics.cpp delete mode 100644 src/Nazara/Graphics/GuillotineTextureAtlas.cpp delete mode 100644 src/Nazara/Graphics/InstancedRenderable.cpp delete mode 100644 src/Nazara/Graphics/Light.cpp delete mode 100644 src/Nazara/Graphics/Material.cpp delete mode 100644 src/Nazara/Graphics/MaterialPipeline.cpp delete mode 100644 src/Nazara/Graphics/Model.cpp delete mode 100644 src/Nazara/Graphics/ParticleController.cpp delete mode 100644 src/Nazara/Graphics/ParticleDeclaration.cpp delete mode 100644 src/Nazara/Graphics/ParticleEmitter.cpp delete mode 100644 src/Nazara/Graphics/ParticleFunctionController.cpp delete mode 100644 src/Nazara/Graphics/ParticleFunctionGenerator.cpp delete mode 100644 src/Nazara/Graphics/ParticleFunctionRenderer.cpp delete mode 100644 src/Nazara/Graphics/ParticleGenerator.cpp delete mode 100644 src/Nazara/Graphics/ParticleGroup.cpp delete mode 100644 src/Nazara/Graphics/ParticleMapper.cpp delete mode 100644 src/Nazara/Graphics/ParticleRenderer.cpp delete mode 100644 src/Nazara/Graphics/RenderQueue.cpp delete mode 100644 src/Nazara/Graphics/RenderTechniques.cpp delete mode 100644 src/Nazara/Graphics/Renderable.cpp delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag.h delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag.h delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag.h delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/GBufferClear.frag delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/GBufferClear.frag.h delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag.h delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag.h delete mode 100644 src/Nazara/Graphics/Resources/DeferredShading/Textures/ssaoNoise.jpg.h delete mode 100644 src/Nazara/Graphics/Resources/Shaders/Basic/core.frag delete mode 100644 src/Nazara/Graphics/Resources/Shaders/Basic/core.frag.h delete mode 100644 src/Nazara/Graphics/Resources/Shaders/Basic/core.vert delete mode 100644 src/Nazara/Graphics/Resources/Shaders/Basic/core.vert.h delete mode 100644 src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag delete mode 100644 src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h delete mode 100644 src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert delete mode 100644 src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h delete mode 100644 src/Nazara/Graphics/SkeletalModel.cpp delete mode 100644 src/Nazara/Graphics/SkinningManager.cpp delete mode 100644 src/Nazara/Graphics/SkyboxBackground.cpp delete mode 100644 src/Nazara/Graphics/Sprite.cpp delete mode 100644 src/Nazara/Graphics/TextSprite.cpp delete mode 100644 src/Nazara/Graphics/TextureBackground.cpp delete mode 100644 src/Nazara/Graphics/TileMap.cpp delete mode 100644 src/NazaraSDK/BaseWidget.cpp delete mode 100644 src/NazaraSDK/Canvas.cpp delete mode 100644 src/NazaraSDK/Components/CameraComponent.cpp delete mode 100644 src/NazaraSDK/Components/DebugComponent.cpp delete mode 100644 src/NazaraSDK/Components/GraphicsComponent.cpp delete mode 100644 src/NazaraSDK/Components/LightComponent.cpp delete mode 100644 src/NazaraSDK/Components/ParticleEmitterComponent.cpp delete mode 100644 src/NazaraSDK/Components/ParticleGroupComponent.cpp delete mode 100644 src/NazaraSDK/Console.cpp delete mode 100644 src/NazaraSDK/Systems/DebugSystem.cpp delete mode 100644 src/NazaraSDK/Systems/ParticleSystem.cpp delete mode 100644 src/NazaraSDK/Systems/RenderSystem.cpp delete mode 100644 src/NazaraSDK/Widgets/AbstractTextAreaWidget.cpp delete mode 100644 src/NazaraSDK/Widgets/BoxLayout.cpp delete mode 100644 src/NazaraSDK/Widgets/ButtonWidget.cpp delete mode 100644 src/NazaraSDK/Widgets/CheckboxWidget.cpp delete mode 100644 src/NazaraSDK/Widgets/ImageWidget.cpp delete mode 100644 src/NazaraSDK/Widgets/LabelWidget.cpp delete mode 100644 src/NazaraSDK/Widgets/ProgressBarWidget.cpp delete mode 100644 src/NazaraSDK/Widgets/RichTextAreaWidget.cpp delete mode 100644 src/NazaraSDK/Widgets/ScrollAreaWidget.cpp delete mode 100644 src/NazaraSDK/Widgets/TextAreaWidget.cpp delete mode 100644 tests/Engine/Graphics/Billboard.cpp delete mode 100644 tests/Engine/Graphics/ColorBackground.cpp delete mode 100644 tests/Engine/Graphics/DeferredRenderTechnique.cpp delete mode 100644 tests/Engine/Graphics/Light.cpp delete mode 100644 tests/Engine/Graphics/Model.cpp delete mode 100644 tests/Engine/Graphics/ParticleDeclaration.cpp delete mode 100644 tests/Engine/Graphics/ParticleGroup.cpp delete mode 100644 tests/Engine/Graphics/RenderTechniques.cpp delete mode 100644 tests/Engine/Graphics/SkeletalModel.cpp delete mode 100644 tests/Engine/Graphics/SkyboxBackground.cpp delete mode 100644 tests/Engine/Graphics/TextureBackground.cpp delete mode 100644 tests/Engine/Platform/EventHandler.cpp delete mode 100644 tests/Engine/Platform/EventHandler/BaseState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/BaseState.hpp delete mode 100644 tests/Engine/Platform/EventHandler/EventState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/EventState.hpp delete mode 100644 tests/Engine/Platform/EventHandler/FocusState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/FocusState.hpp delete mode 100644 tests/Engine/Platform/EventHandler/KeyState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/KeyState.hpp delete mode 100644 tests/Engine/Platform/EventHandler/MenuState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/MenuState.hpp delete mode 100644 tests/Engine/Platform/EventHandler/MouseClickState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/MouseClickState.hpp delete mode 100644 tests/Engine/Platform/EventHandler/MouseEnterState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/MouseEnterState.hpp delete mode 100644 tests/Engine/Platform/EventHandler/MouseMoveState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/MouseMoveState.hpp delete mode 100644 tests/Engine/Platform/EventHandler/StateContext.cpp delete mode 100644 tests/Engine/Platform/EventHandler/StateContext.hpp delete mode 100644 tests/Engine/Platform/EventHandler/StateFactory.cpp delete mode 100644 tests/Engine/Platform/EventHandler/StateFactory.hpp delete mode 100644 tests/Engine/Platform/EventHandler/Text.cpp delete mode 100644 tests/Engine/Platform/EventHandler/Text.hpp delete mode 100644 tests/Engine/Platform/EventHandler/TextEnterState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/TextEnterState.hpp delete mode 100644 tests/Engine/Platform/EventHandler/WindowModificationState.cpp delete mode 100644 tests/Engine/Platform/EventHandler/WindowModificationState.hpp delete mode 100644 tests/SDK/NDK/Systems/RenderSystem.cpp diff --git a/build/scripts/modules/graphics.lua b/build/scripts/modules/graphics.lua deleted file mode 100644 index 5c0bf4224..000000000 --- a/build/scripts/modules/graphics.lua +++ /dev/null @@ -1,8 +0,0 @@ -MODULE.Name = "Graphics" - -MODULE.Libraries = { - "NazaraCore", - "NazaraUtility", - "NazaraPlatform", - "NazaraRenderer" -} diff --git a/examples/FirstScene/build.lua b/examples/FirstScene/build_disabled.lua similarity index 100% rename from examples/FirstScene/build.lua rename to examples/FirstScene/build_disabled.lua diff --git a/examples/HardwareInfo/main.cpp b/examples/HardwareInfo/main.cpp index 820f42a62..ffeb4bb86 100644 --- a/examples/HardwareInfo/main.cpp +++ b/examples/HardwareInfo/main.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -58,37 +57,6 @@ int main() else oss << "Impossible de retrouver les informations du processeur" << std::endl; - oss << std::endl << "--Carte graphique--" << std::endl; - // La classe OpenGL nous donne accès à des informations sur la carte graphique - // Cependant celle-ci n'est accessible que si le projet est compilé avec NAZARA_RENDERER_OPENGL - // et que les répertoires d'inclusions donnent accès aux includes d'OpenGL (Cette démo utilisent ceux de Nazara) - Nz::Initializer openGL; - if (openGL) - { - // Nous récupérons ensuite la version d'OpenGL sous forme d'entier (ex: OpenGL 3.3 donnera 330) - unsigned int openglVersion = Nz::OpenGL::GetVersion(); - - // OpenGL nous donne accès à trois informations principales: - // 1) La chaîne d'identification du driver ("Renderer name") - // 2) La chaîne d'identification du concepteur ("Vendor name") - // 3) La version d'OpenGL - oss << "Identification: " << Nz::OpenGL::GetRendererName() << std::endl; - oss << "Concepteur: " << Nz::OpenGL::GetVendorName() << std::endl; - oss << "Version d'OpenGL: " << openglVersion/100 << '.' << openglVersion%100 << std::endl; - oss << std::endl; - - // Ainsi qu'un report des capacités de la carte graphique (avec le driver actuel) - oss << "Rapport des capacites: " << std::endl; // Pas d'accent car écriture dans un fichier (et on ne va pas s'embêter avec ça) - printCap(oss, "-Calculs 64bits", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_FP64)); - printCap(oss, "-Compression de textures (s3tc)", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_TextureCompression_s3tc)); - printCap(oss, "-Filtrage anisotrope", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_AnisotropicFilter)); - printCap(oss, "-Mode debug", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_DebugOutput)); - printCap(oss, "-Separate shader objects", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_SeparateShaderObjects)); - printCap(oss, "-Texture storage", Nz::OpenGL::IsSupported(Nz::OpenGLExtension_TextureStorage)); - } - else - oss << "Impossible de retrouver les informations de la carte graphique" << std::endl; - std::cout << "\r "; // On efface le message d'initialisation std::cout << '\r'; // Et on place déjà le caractère pour revenir sur la même ligne (Pour ne pas avoir un saut inutile) diff --git a/examples/Particles/build.lua b/examples/Particles/build_disabled.lua similarity index 100% rename from examples/Particles/build.lua rename to examples/Particles/build_disabled.lua diff --git a/examples/Tut00/build.lua b/examples/Tut00/build_disabled.lua similarity index 100% rename from examples/Tut00/build.lua rename to examples/Tut00/build_disabled.lua diff --git a/examples/Tut01/build.lua b/examples/Tut01/build_disabled.lua similarity index 100% rename from examples/Tut01/build.lua rename to examples/Tut01/build_disabled.lua diff --git a/examples/Tut02/build.lua b/examples/Tut02/build_disabled.lua similarity index 100% rename from examples/Tut02/build.lua rename to examples/Tut02/build_disabled.lua diff --git a/include/Nazara/Graphics.hpp b/include/Nazara/Graphics.hpp deleted file mode 100644 index 0d14c14a1..000000000 --- a/include/Nazara/Graphics.hpp +++ /dev/null @@ -1,87 +0,0 @@ -// This file was automatically generated - -/* - Nazara Engine - Graphics module - - Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_GLOBAL_GRAPHICS_HPP -#define NAZARA_GLOBAL_GRAPHICS_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif // NAZARA_GLOBAL_GRAPHICS_HPP diff --git a/include/Nazara/Graphics/AbstractBackground.hpp b/include/Nazara/Graphics/AbstractBackground.hpp deleted file mode 100644 index db969dd7e..000000000 --- a/include/Nazara/Graphics/AbstractBackground.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ABSTRACTBACKGROUND_HPP -#define NAZARA_ABSTRACTBACKGROUND_HPP - -#include -#include -#include -#include -#include - -namespace Nz -{ - class AbstractBackground; - class AbstractViewer; - - using BackgroundConstRef = ObjectRef; - using BackgroundLibrary = ObjectLibrary; - using BackgroundRef = ObjectRef; - - class NAZARA_GRAPHICS_API AbstractBackground : public RefCounted - { - public: - AbstractBackground() = default; - AbstractBackground(const AbstractBackground&) = default; - AbstractBackground(AbstractBackground&&) = delete; - virtual ~AbstractBackground(); - - virtual void Draw(const AbstractViewer* viewer) const = 0; - - virtual BackgroundType GetBackgroundType() const = 0; - - AbstractBackground& operator=(const AbstractBackground&) = default; - AbstractBackground& operator=(AbstractBackground&&) = delete; - - private: - static BackgroundLibrary::LibraryMap s_library; - }; -} - -#endif // NAZARA_ABSTRACTBACKGROUND_HPP diff --git a/include/Nazara/Graphics/AbstractRenderQueue.hpp b/include/Nazara/Graphics/AbstractRenderQueue.hpp deleted file mode 100644 index a9cc391c2..000000000 --- a/include/Nazara/Graphics/AbstractRenderQueue.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ABSTRACTRENDERQUEUE_HPP -#define NAZARA_ABSTRACTRENDERQUEUE_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class Drawable; - class Material; - class Texture; - struct MeshData; - struct VertexStruct_XYZ_Color_UV; - - class NAZARA_GRAPHICS_API AbstractRenderQueue - { - public: - struct DirectionalLight; - struct PointLight; - struct SpotLight; - - AbstractRenderQueue() = default; - AbstractRenderQueue(const AbstractRenderQueue&) = delete; - AbstractRenderQueue(AbstractRenderQueue&&) noexcept = default; - virtual ~AbstractRenderQueue(); - - // Je ne suis vraiment pas fan du nombre de surcharges pour AddBillboards, - // mais je n'ai pas d'autre solution tout aussi performante pour le moment... - virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr = nullptr, SparsePtr colorPtr = nullptr) = 0; - virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) = 0; - virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr = nullptr) = 0; - virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) = 0; - virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr = nullptr, SparsePtr colorPtr = nullptr) = 0; - virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) = 0; - virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr = nullptr) = 0; - virtual void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) = 0; - virtual void AddDrawable(int renderOrder, const Drawable* drawable) = 0; - virtual void AddDirectionalLight(const DirectionalLight& light); - virtual void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) = 0; - virtual void AddPointLight(const PointLight& light); - virtual void AddSpotLight(const SpotLight& light); - virtual void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay = nullptr) = 0; - - virtual void Clear(bool fully = false); - - AbstractRenderQueue& operator=(const AbstractRenderQueue&) = delete; - AbstractRenderQueue& operator=(AbstractRenderQueue&&) noexcept = default; - - struct DirectionalLight - { - Color color; - Matrix4f transformMatrix; - Vector3f direction; - Texture* shadowMap; - float ambientFactor; - float diffuseFactor; - }; - - struct PointLight - { - Color color; - Vector3f position; - Texture* shadowMap; - float ambientFactor; - float attenuation; - float diffuseFactor; - float invRadius; - float radius; - }; - - struct SpotLight - { - Color color; - Matrix4f transformMatrix; - Vector3f direction; - Vector3f position; - Texture* shadowMap; - float ambientFactor; - float attenuation; - float diffuseFactor; - float innerAngleCosine; - float invRadius; - float outerAngleCosine; - float outerAngleTangent; - float radius; - }; - - std::vector directionalLights; - std::vector pointLights; - std::vector spotLights; - }; -} - -#endif // NAZARA_ABSTRACTRENDERQUEUE_HPP diff --git a/include/Nazara/Graphics/AbstractRenderTechnique.hpp b/include/Nazara/Graphics/AbstractRenderTechnique.hpp deleted file mode 100644 index 3460b16e6..000000000 --- a/include/Nazara/Graphics/AbstractRenderTechnique.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ABSTRACTRENDERTECHNIQUE_HPP -#define NAZARA_ABSTRACTRENDERTECHNIQUE_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class AbstractRenderQueue; - struct SceneData; - - class NAZARA_GRAPHICS_API AbstractRenderTechnique - { - public: - AbstractRenderTechnique(); - AbstractRenderTechnique(const AbstractRenderTechnique&) = delete; - AbstractRenderTechnique(AbstractRenderTechnique&&) noexcept = default; - virtual ~AbstractRenderTechnique(); - - virtual void Clear(const SceneData& sceneData) const = 0; - virtual bool Draw(const SceneData& sceneData) const = 0; - - virtual void EnableInstancing(bool instancing); - - virtual String GetName() const; - virtual AbstractRenderQueue* GetRenderQueue() = 0; - virtual RenderTechniqueType GetType() const = 0; - - virtual bool IsInstancingEnabled() const; - - AbstractRenderTechnique& operator=(const AbstractRenderTechnique&) = delete; - AbstractRenderTechnique& operator=(AbstractRenderTechnique&&) noexcept = default; - - protected: - bool m_instancingEnabled; - }; -} - -#endif // NAZARA_ABSTRACTRENDERTECHNIQUE_HPP diff --git a/include/Nazara/Graphics/AbstractViewer.hpp b/include/Nazara/Graphics/AbstractViewer.hpp deleted file mode 100644 index 06284ddf4..000000000 --- a/include/Nazara/Graphics/AbstractViewer.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ABSTRACTVIEWER_HPP -#define NAZARA_ABSTRACTVIEWER_HPP - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class RenderTarget; - - class NAZARA_GRAPHICS_API AbstractViewer - { - public: - AbstractViewer() = default; - AbstractViewer(const AbstractViewer&) = default; - AbstractViewer(AbstractViewer&&) noexcept = default; - virtual ~AbstractViewer(); - - virtual void ApplyView() const = 0; - - virtual float GetAspectRatio() const = 0; - virtual Vector3f GetEyePosition() const = 0; - virtual Vector3f GetForward() const = 0; - virtual const Frustumf& GetFrustum() const = 0; - virtual const Matrix4f& GetProjectionMatrix() const = 0; - virtual Nz::ProjectionType GetProjectionType() const = 0; - virtual const RenderTarget* GetTarget() const = 0; - virtual const Matrix4f& GetViewMatrix() const = 0; - virtual const Recti& GetViewport() const = 0; - virtual float GetZFar() const = 0; - virtual float GetZNear() const = 0; - - Nz::Vector3f Project(const Nz::Vector3f& worldPosition) const; - float ProjectDepth(float depth); - - Nz::Vector3f Unproject(const Nz::Vector3f& screenPos) const; - - AbstractViewer& operator=(const AbstractViewer&) = default; - AbstractViewer& operator=(AbstractViewer&&) noexcept = default; - }; -} - -#endif // NAZARA_ABSTRACTVIEWER_HPP diff --git a/include/Nazara/Graphics/BasicRenderQueue.hpp b/include/Nazara/Graphics/BasicRenderQueue.hpp deleted file mode 100644 index e6f0c4240..000000000 --- a/include/Nazara/Graphics/BasicRenderQueue.hpp +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_BASICRENDERQUEUE_HPP -#define NAZARA_BASICRENDERQUEUE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class AbstractViewer; - - class NAZARA_GRAPHICS_API BasicRenderQueue : public AbstractRenderQueue - { - friend class ForwardRenderTechnique; - - public: - struct BillboardData; - - BasicRenderQueue() = default; - ~BasicRenderQueue() = default; - - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr = nullptr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr = nullptr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) override; - void AddDrawable(int renderOrder, const Drawable* drawable) override; - void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) override; - void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay = nullptr) override; - - void Clear(bool fully = false) override; - - inline const BillboardData* GetBillboardData(std::size_t billboardIndex) const; - - void Sort(const AbstractViewer* viewer); - - struct BillboardData - { - Color color; - Vector3f center; - Vector2f size; - Vector2f sinCos; - }; - - struct Billboard - { - int layerIndex; - MovablePtr material; - Nz::Recti scissorRect; - BillboardData data; - }; - - struct BillboardChain - { - int layerIndex; - MovablePtr material; - Nz::Recti scissorRect; - std::size_t billboardCount; - std::size_t billboardIndex; - }; - - RenderQueue billboards; - RenderQueue depthSortedBillboards; - - struct CustomDrawable - { - int layerIndex; - MovablePtr drawable; - }; - - RenderQueue customDrawables; - - struct Model - { - int layerIndex; - MeshData meshData; - MovablePtr material; - Nz::Matrix4f matrix; - Nz::Recti scissorRect; - Nz::Spheref obbSphere; - }; - - RenderQueue models; - RenderQueue depthSortedModels; - - struct SpriteChain - { - int layerIndex; - std::size_t spriteCount; - MovablePtr material; - MovablePtr overlay; - MovablePtr vertices; - Nz::Recti scissorRect; - }; - - RenderQueue basicSprites; - RenderQueue depthSortedSprites; - - private: - inline Color ComputeColor(float alpha); - inline Vector2f ComputeSinCos(float angle); - inline Vector2f ComputeSize(float size); - - inline void RegisterLayer(int layerIndex); - - std::unordered_map m_pipelineCache; - std::unordered_map m_materialCache; - std::unordered_map m_overlayCache; - std::unordered_map m_shaderCache; - std::unordered_map m_textureCache; - std::unordered_map m_vertexBufferCache; - std::unordered_map m_layerCache; - - std::vector m_billboards; - std::vector m_renderLayers; - }; -} - -#include - -#endif // NAZARA_BASICRENDERQUEUE_HPP diff --git a/include/Nazara/Graphics/BasicRenderQueue.inl b/include/Nazara/Graphics/BasicRenderQueue.inl deleted file mode 100644 index 29eb9509d..000000000 --- a/include/Nazara/Graphics/BasicRenderQueue.inl +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - inline const BasicRenderQueue::BillboardData* BasicRenderQueue::GetBillboardData(std::size_t billboardIndex) const - { - assert(billboardIndex < m_billboards.size()); - return &m_billboards[billboardIndex]; - } - - inline Color BasicRenderQueue::ComputeColor(float alpha) - { - return Color(255, 255, 255, static_cast(255.f * alpha)); - } - - inline Vector2f BasicRenderQueue::ComputeSinCos(float angle) - { - float radians = ToRadians(angle); - return { std::sin(radians), std::cos(radians) }; - } - - inline Vector2f BasicRenderQueue::ComputeSize(float size) - { - return Vector2f(size, size); - } - - inline void BasicRenderQueue::RegisterLayer(int layerIndex) - { - auto it = std::lower_bound(m_renderLayers.begin(), m_renderLayers.end(), layerIndex); - if (it == m_renderLayers.end() || *it != layerIndex) - m_renderLayers.insert(it, layerIndex); - } -} diff --git a/include/Nazara/Graphics/Billboard.hpp b/include/Nazara/Graphics/Billboard.hpp deleted file mode 100644 index 9b75c0aa2..000000000 --- a/include/Nazara/Graphics/Billboard.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_BILLBOARD_HPP -#define NAZARA_BILLBOARD_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class Billboard; - - using BillboardConstRef = ObjectRef; - using BillboardLibrary = ObjectLibrary; - using BillboardRef = ObjectRef; - - class NAZARA_GRAPHICS_API Billboard : public InstancedRenderable - { - public: - inline Billboard(); - inline Billboard(MaterialRef material); - inline Billboard(Texture* texture); - inline Billboard(const Billboard& billboard); - Billboard(Billboard&&) = delete; - ~Billboard() = default; - - void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override; - - std::unique_ptr Clone() const override; - - inline const Color& GetColor() const; - inline const RadianAnglef& GetRotation() const; - inline const Vector2f& GetSize() const; - - inline void SetColor(const Color& color); - inline void SetDefaultMaterial(); - inline void SetMaterial(MaterialRef material, bool resizeBillboard = true); - inline void SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeBillboard = true); - inline void SetRotation(const RadianAnglef& rotation); - inline void SetSize(const Vector2f& size); - inline void SetSize(float sizeX, float sizeY); - inline void SetTexture(TextureRef texture, bool resizeBillboard = true); - inline void SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeBillboard = true); - - inline Billboard& operator=(const Billboard& billboard); - Billboard& operator=(Billboard&&) = delete; - - template static BillboardRef New(Args&&... args); - - private: - void MakeBoundingVolume() const override; - - Color m_color; - Vector2f m_sinCos; - Vector2f m_size; - RadianAnglef m_rotation; - - static BillboardLibrary::LibraryMap s_library; - }; -} - -#include - -#endif // NAZARA_BILLBOARD_HPP diff --git a/include/Nazara/Graphics/Billboard.inl b/include/Nazara/Graphics/Billboard.inl deleted file mode 100644 index 13c232b88..000000000 --- a/include/Nazara/Graphics/Billboard.inl +++ /dev/null @@ -1,272 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \brief Constructs a Billboard object by default - */ - - inline Billboard::Billboard() - { - ResetMaterials(1); - - SetColor(Color::White); - SetDefaultMaterial(); - SetRotation(0.f); - SetSize(64.f, 64.f); - } - - /*! - * \brief Constructs a Billboard object with a reference to a material - * - * \param material Reference to a material - */ - - inline Billboard::Billboard(MaterialRef material) - { - ResetMaterials(1); - - SetColor(Color::White); - SetMaterial(std::move(material), true); - SetRotation(0.f); - SetSize(64.f, 64.f); - } - - /*! - * \brief Constructs a Billboard object with a pointer to a texture - * - * \param texture Pointer to a texture - */ - - inline Billboard::Billboard(Texture* texture) - { - ResetMaterials(1); - - SetColor(Color::White); - SetRotation(0.f); - SetSize(64.f, 64.f); - SetTexture(texture, true); - } - - /*! - * \brief Constructs a Billboard object by assignation - * - * \param billboard Billboard to copy into this - */ - - inline Billboard::Billboard(const Billboard& billboard) : - InstancedRenderable(billboard), - m_color(billboard.m_color), - m_sinCos(billboard.m_sinCos), - m_size(billboard.m_size), - m_rotation(billboard.m_rotation) - { - } - - /*! - * \brief Gets the color of the billboard - * \return Current color - */ - - inline const Color& Billboard::GetColor() const - { - return m_color; - } - - /*! - * \brief Gets the rotation of the billboard - * \return Current rotation - */ - - inline const RadianAnglef& Billboard::GetRotation() const - { - return m_rotation; - } - - /*! - * \brief Gets the size of the billboard - * \return Current size - */ - - inline const Vector2f& Billboard::GetSize() const - { - return m_size; - } - - /*! - * \brief Sets the color of the billboard - * - * \param color Color for the billboard - */ - - inline void Billboard::SetColor(const Color& color) - { - m_color = color; - } - - /*! - * \brief Sets the default material of the billboard (just default material) - */ - - inline void Billboard::SetDefaultMaterial() - { - MaterialRef material = Material::New(); - material->EnableFaceCulling(true); - - SetMaterial(std::move(material)); - } - - /*! - * \brief Sets the material of the billboard - * - * \param material Material for the billboard - * \param resizeBillboard Should billboard be resized to the material size (diffuse map) - */ - inline void Billboard::SetMaterial(MaterialRef material, bool resizeBillboard) - { - SetMaterial(GetSkin(), std::move(material), resizeBillboard); - } - - /*! - * \brief Sets the material of the billboard - * - * \param skinIndex Skin index to change - * \param material Material for the billboard - * \param resizeBillboard Should billboard be resized to the material size (diffuse map) - */ - inline void Billboard::SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeBillboard) - { - InstancedRenderable::SetMaterial(skinIndex, 0, std::move(material)); - - if (resizeBillboard) - { - if (const MaterialRef& newMat = GetMaterial()) - { - const TextureRef& diffuseMap = newMat->GetDiffuseMap(); - if (diffuseMap && diffuseMap->IsValid()) - SetSize(Vector2f(Vector2ui(diffuseMap->GetSize()))); - } - } - } - - /*! - * \brief Sets the rotation of the billboard - * - * \param rotation Rotation for the billboard - */ - - inline void Billboard::SetRotation(const RadianAnglef& rotation) - { - m_rotation = rotation; - - auto sincos = rotation.GetSinCos(); - m_sinCos.Set(sincos.first, sincos.second); - } - - /*! - * \brief Sets the size of the billboard - * - * \param size Size for the billboard - */ - - inline void Billboard::SetSize(const Vector2f& size) - { - m_size = size; - - // We invalidate the bounding volume - InvalidateBoundingVolume(); - } - - /*! - * \brief Sets the size of the billboard - * - * \param sizeX Size in X for the billboard - * \param sizeY Size in Y for the billboard - */ - - inline void Billboard::SetSize(float sizeX, float sizeY) - { - SetSize(Vector2f(sizeX, sizeY)); - } - - /*! - * \brief Sets the texture of the billboard - * - * \param texture Texture for the billboard - * \param resizeBillboard Should billboard be resized to the texture size - */ - inline void Billboard::SetTexture(TextureRef texture, bool resizeBillboard) - { - SetTexture(GetSkin(), std::move(texture), resizeBillboard); - } - - /*! - * \brief Sets the texture of the billboard for a specific index - * - * This function changes the diffuse map of the material associated with the specified skin index - * - * \param skinIndex Skin index to change - * \param texture Texture for the billboard - * \param resizeBillboard Should billboard be resized to the texture size - */ - inline void Billboard::SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeBillboard) - { - if (resizeBillboard && texture && texture->IsValid()) - SetSize(Vector2f(Vector2ui(texture->GetSize()))); - - const MaterialRef& material = GetMaterial(skinIndex); - - if (material->GetReferenceCount() > 1) - { - MaterialRef newMat = Material::New(*material); // Copy - newMat->SetDiffuseMap(std::move(texture)); - - SetMaterial(skinIndex, std::move(newMat)); - } - else - material->SetDiffuseMap(std::move(texture)); - } - - /*! - * \brief Sets the current billboard with the content of the other one - * \return A reference to this - * - * \param billboard The other Billboard - */ - - inline Billboard& Billboard::operator=(const Billboard& billboard) - { - InstancedRenderable::operator=(billboard); - - m_color = billboard.m_color; - m_size = billboard.m_size; - - InvalidateBoundingVolume(); - - return *this; - } - - /*! - * \brief Creates a new billboard from the arguments - * \return A reference to the newly created billboard - * - * \param args Arguments for the billboard - */ - - template - BillboardRef Billboard::New(Args&&... args) - { - std::unique_ptr object(new Billboard(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/ColorBackground.hpp b/include/Nazara/Graphics/ColorBackground.hpp deleted file mode 100644 index 759af3a39..000000000 --- a/include/Nazara/Graphics/ColorBackground.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_COLORBACKGROUND_HPP -#define NAZARA_COLORBACKGROUND_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class ColorBackground; - - using ColorBackgroundConstRef = ObjectRef; - using ColorBackgroundRef = ObjectRef; - - class NAZARA_GRAPHICS_API ColorBackground : public AbstractBackground - { - public: - ColorBackground(const Color& color = Color::Black); - ColorBackground(const ColorBackground&) = default; - ColorBackground(ColorBackground&&) = delete; - - void Draw(const AbstractViewer* viewer) const override; - - BackgroundType GetBackgroundType() const override; - Color GetColor() const; - - void SetColor(const Color& color); - - ColorBackground& operator=(ColorBackground&&) = delete; - - template static ColorBackgroundRef New(Args&&... args); - - private: - Color m_color; - UberShaderConstRef m_uberShader; - const UberShaderInstance* m_uberShaderInstance; - int m_materialDiffuseUniform; - int m_vertexDepthUniform; - }; -} - -#include - -#endif // NAZARA_COLORBACKGROUND_HPP diff --git a/include/Nazara/Graphics/ColorBackground.inl b/include/Nazara/Graphics/ColorBackground.inl deleted file mode 100644 index bd32a1877..000000000 --- a/include/Nazara/Graphics/ColorBackground.inl +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \brief Creates a new color background from the arguments - * \return A reference to the newly created color background - * - * \param args Arguments for the color background - */ - - template - ColorBackgroundRef ColorBackground::New(Args&&... args) - { - std::unique_ptr object(new ColorBackground(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/Config.hpp b/include/Nazara/Graphics/Config.hpp deleted file mode 100644 index e47c8d3a5..000000000 --- a/include/Nazara/Graphics/Config.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - Nazara Engine - Graphics module - - Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_GRAPHICS_HPP -#define NAZARA_CONFIG_GRAPHICS_HPP - -/*! -* \defgroup graphics (NazaraGraphics) Graphics module -* Graphics/System module including classes to handle graphical elements... -*/ - -/// Each modification of a paramater of the module needs a recompilation of the unit - -// How much instances are need of a same mesh/material to enable instancing ? -#define NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT 10 - -// Use the MemoryManager to manage dynamic allocations (can detect memory leak but allocations/frees are slower) -#define NAZARA_GRAPHICS_MANAGE_MEMORY 0 - -// Activate the security tests based on the code (Advised for development) -#define NAZARA_GRAPHICS_SAFE 1 - -/// Each modification of a parameter following implies a modification (often minor) of the code - -// The maximum number of lights in a standard shader -#define NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS 3 - -/// Checking the values and types of certain constants -#include - -#if defined(NAZARA_STATIC) - #define NAZARA_GRAPHICS_API -#else - #ifdef NAZARA_GRAPHICS_BUILD - #define NAZARA_GRAPHICS_API NAZARA_EXPORT - #else - #define NAZARA_GRAPHICS_API NAZARA_IMPORT - #endif -#endif - -#endif // NAZARA_CONFIG_GRAPHICS_HPP diff --git a/include/Nazara/Graphics/ConfigCheck.hpp b/include/Nazara/Graphics/ConfigCheck.hpp deleted file mode 100644 index f72b91725..000000000 --- a/include/Nazara/Graphics/ConfigCheck.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_CONFIG_CHECK_GRAPHICS_HPP -#define NAZARA_CONFIG_CHECK_GRAPHICS_HPP - -/// This file is used to check the constant values defined in Config.hpp - -#include -#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type ::value && name op val, #type err) - -// We force the value of MANAGE_MEMORY in debug -#if defined(NAZARA_DEBUG) && !NAZARA_GRAPHICS_MANAGE_MEMORY - #undef NAZARA_GRAPHICS_MANAGE_MEMORY - #define NAZARA_GRAPHICS_MANAGE_MEMORY 0 -#endif - -NazaraCheckTypeAndVal(NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT, integral, >, 0, " shall be a strictly positive integer"); -NazaraCheckTypeAndVal(NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS, integral, >, 0, " shall be a strictly positive integer"); - -#undef NazaraCheckTypeAndVal - -#endif // NAZARA_CONFIG_CHECK_GRAPHICS_HPP diff --git a/include/Nazara/Graphics/CullingList.hpp b/include/Nazara/Graphics/CullingList.hpp deleted file mode 100644 index 52b23f532..000000000 --- a/include/Nazara/Graphics/CullingList.hpp +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_CULLINGLIST_HPP -#define NAZARA_CULLINGLIST_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - template - class CullingList - { - public: - template class Entry; - class BoxEntry; - class NoTestEntry; - class SphereEntry; - class VolumeEntry; - - template friend class Entry; - friend BoxEntry; - friend NoTestEntry; - friend SphereEntry; - friend VolumeEntry; - - using ResultContainer = std::vector; - - CullingList() = default; - CullingList(const CullingList& renderable) = delete; - CullingList(CullingList&& renderable) = delete; - ~CullingList(); - - std::size_t Cull(const Frustumf& frustum, bool* forceInvalidation = nullptr); - - std::size_t FillWithAllEntries(bool* forceInvalidation = nullptr); - - const ResultContainer& GetFullyVisibleResults() const; - const ResultContainer& GetPartiallyVisibleResults() const; - - BoxEntry RegisterBoxTest(const T* renderable); - NoTestEntry RegisterNoTest(const T* renderable); - SphereEntry RegisterSphereTest(const T* renderable); - VolumeEntry RegisterVolumeTest(const T* renderable); - - CullingList& operator=(const CullingList& renderable) = delete; - CullingList& operator=(CullingList&& renderable) = delete; - - NazaraSignal(OnCullingListRelease, CullingList* /*cullingList*/); - - private: - inline void NotifyBoxUpdate(std::size_t index, const Boxf& boundingVolume); - inline void NotifyForceInvalidation(CullTest type, std::size_t index); - inline void NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr); - inline void NotifyRelease(CullTest type, std::size_t index); - inline void NotifySphereUpdate(std::size_t index, const Spheref& sphere); - inline void NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume); - - struct BoxVisibilityEntry - { - Boxf box; - BoxEntry* entry; - const T* renderable; - bool forceInvalidation; - }; - - struct NoTestVisibilityEntry - { - NoTestEntry* entry; - const T* renderable; - bool forceInvalidation; - }; - - struct SphereVisibilityEntry - { - Spheref sphere; - SphereEntry* entry; - const T* renderable; - bool forceInvalidation; - }; - - struct VolumeVisibilityEntry - { - BoundingVolumef volume; - VolumeEntry* entry; - const T* renderable; - bool forceInvalidation; - }; - - std::vector m_boxTestList; - std::vector m_noTestList; - std::vector m_sphereTestList; - std::vector m_volumeTestList; - ResultContainer m_fullyVisibleResults; - ResultContainer m_partiallyVisibleResults; - }; - - template - template - class CullingList::Entry - { - public: - Entry(); - Entry(const Entry&) = delete; - Entry(Entry&& entry); - ~Entry(); - - void ForceInvalidation(); - - CullingList* GetParent() const; - - void UpdateIndex(std::size_t index); - - Entry& operator=(const Entry&) = delete; - Entry& operator=(Entry&& entry); - - protected: - Entry(CullingList* parent, std::size_t index); - - std::size_t m_index; - CullingList* m_parent; - }; - - template - class CullingList::BoxEntry : public CullingList::template Entry - { - friend CullingList; - - using ParentType = Entry; - - public: - BoxEntry(); - BoxEntry(BoxEntry&&) = default; - ~BoxEntry() = default; - - void UpdateBox(const Boxf& box); - - BoxEntry& operator=(BoxEntry&&) = default; - - private: - BoxEntry(CullingList* parent, std::size_t index); - }; - - template - class CullingList::NoTestEntry : public CullingList::template Entry - { - friend CullingList; - - using ParentType = Entry; - - public: - NoTestEntry(); - NoTestEntry(NoTestEntry&&) = default; - ~NoTestEntry() = default; - - NoTestEntry& operator=(NoTestEntry&&) = default; - - private: - NoTestEntry(CullingList* parent, std::size_t index); - }; - - template - class CullingList::SphereEntry : public CullingList::template Entry - { - friend CullingList; - - using ParentType = Entry; - - public: - SphereEntry(); - SphereEntry(SphereEntry&&) = default; - ~SphereEntry() = default; - - void UpdateSphere(const Spheref& sphere); - - SphereEntry& operator=(SphereEntry&&) = default; - - private: - SphereEntry(CullingList* parent, std::size_t index); - }; - - template - class CullingList::VolumeEntry : public CullingList::template Entry - { - friend CullingList; - - using ParentType = Entry; - - public: - VolumeEntry(); - VolumeEntry(VolumeEntry&&) = default; - ~VolumeEntry() = default; - - void UpdateVolume(const BoundingVolumef& sphere); - - VolumeEntry& operator=(VolumeEntry&&) = default; - - private: - VolumeEntry(CullingList* parent, std::size_t index); - }; -} - -#include - -#endif // NAZARA_CULLINGLIST_HPP diff --git a/include/Nazara/Graphics/CullingList.inl b/include/Nazara/Graphics/CullingList.inl deleted file mode 100644 index bb36fb57d..000000000 --- a/include/Nazara/Graphics/CullingList.inl +++ /dev/null @@ -1,498 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - template - CullingList::~CullingList() - { - OnCullingListRelease(this); - } - - template - std::size_t CullingList::Cull(const Frustumf& frustum, bool* forceInvalidation) - { - m_fullyVisibleResults.clear(); - m_partiallyVisibleResults.clear(); - - bool forcedInvalidation = false; - - std::size_t fullyVisibleHash = 5U; - std::size_t partiallyVisibleHash = 5U; - - auto CombineHash = [](std::size_t currentHash, std::size_t newHash) - { - return currentHash * 23 + newHash; - }; - - for (BoxVisibilityEntry& entry : m_boxTestList) - { - switch (frustum.Intersect(entry.box)) - { - case IntersectionSide_Inside: - m_fullyVisibleResults.push_back(entry.renderable); - fullyVisibleHash = CombineHash(fullyVisibleHash, std::hash()(entry.renderable)); - - forcedInvalidation = forcedInvalidation | entry.forceInvalidation; - entry.forceInvalidation = false; - break; - - case IntersectionSide_Intersecting: - m_partiallyVisibleResults.push_back(entry.renderable); - partiallyVisibleHash = CombineHash(partiallyVisibleHash, std::hash()(entry.renderable)); - - forcedInvalidation = forcedInvalidation | entry.forceInvalidation; - entry.forceInvalidation = false; - break; - - case IntersectionSide_Outside: - break; - } - } - - for (NoTestVisibilityEntry& entry : m_noTestList) - { - m_fullyVisibleResults.push_back(entry.renderable); - CombineHash(fullyVisibleHash, std::hash()(entry.renderable)); - - if (entry.forceInvalidation) - { - forcedInvalidation = true; - entry.forceInvalidation = false; - } - } - - for (SphereVisibilityEntry& entry : m_sphereTestList) - { - switch (frustum.Intersect(entry.sphere)) - { - case IntersectionSide_Inside: - m_fullyVisibleResults.push_back(entry.renderable); - fullyVisibleHash = CombineHash(fullyVisibleHash, std::hash()(entry.renderable)); - - forcedInvalidation = forcedInvalidation | entry.forceInvalidation; - entry.forceInvalidation = false; - break; - - case IntersectionSide_Intersecting: - m_partiallyVisibleResults.push_back(entry.renderable); - partiallyVisibleHash = CombineHash(partiallyVisibleHash, std::hash()(entry.renderable)); - - forcedInvalidation = forcedInvalidation | entry.forceInvalidation; - entry.forceInvalidation = false; - break; - - case IntersectionSide_Outside: - break; - } - } - - for (VolumeVisibilityEntry& entry : m_volumeTestList) - { - switch (frustum.Intersect(entry.volume)) - { - case IntersectionSide_Inside: - m_fullyVisibleResults.push_back(entry.renderable); - fullyVisibleHash = CombineHash(fullyVisibleHash, std::hash()(entry.renderable)); - - forcedInvalidation = forcedInvalidation | entry.forceInvalidation; - entry.forceInvalidation = false; - break; - - case IntersectionSide_Intersecting: - m_partiallyVisibleResults.push_back(entry.renderable); - partiallyVisibleHash = CombineHash(partiallyVisibleHash, std::hash()(entry.renderable)); - - forcedInvalidation = forcedInvalidation | entry.forceInvalidation; - entry.forceInvalidation = false; - break; - - case IntersectionSide_Outside: - break; - } - } - - if (forceInvalidation) - *forceInvalidation = forcedInvalidation; - - return 5 + partiallyVisibleHash * 17 + fullyVisibleHash; - } - - template - std::size_t CullingList::FillWithAllEntries(bool* forceInvalidation) - { - m_fullyVisibleResults.clear(); - m_partiallyVisibleResults.clear(); - - bool forcedInvalidation = false; - - std::size_t visibleHash = 5U; - - auto FillWithList = [&](auto& testList) - { - for (auto& entry : testList) - { - m_fullyVisibleResults.push_back(entry.renderable); - visibleHash = visibleHash * 23 + std::hash()(entry.renderable); - - forcedInvalidation = forcedInvalidation | entry.forceInvalidation; - entry.forceInvalidation = false; - } - }; - - FillWithList(m_boxTestList); - FillWithList(m_noTestList); - FillWithList(m_sphereTestList); - FillWithList(m_volumeTestList); - - if (forceInvalidation) - *forceInvalidation = forcedInvalidation; - - return visibleHash; - } - - template - auto CullingList::GetFullyVisibleResults() const -> const ResultContainer& - { - return m_fullyVisibleResults; - } - - template - auto CullingList::GetPartiallyVisibleResults() const -> const ResultContainer& - { - return m_partiallyVisibleResults; - } - - template - auto CullingList::RegisterBoxTest(const T* renderable) -> BoxEntry - { - BoxEntry newEntry(this, m_boxTestList.size()); - m_boxTestList.emplace_back(BoxVisibilityEntry{ Nz::Boxf(), &newEntry, renderable, false }); //< Address of entry will be updated when moving - - return newEntry; - } - - template - auto CullingList::RegisterNoTest(const T* renderable) -> NoTestEntry - { - NoTestEntry newEntry(this, m_volumeTestList.size()); - m_noTestList.emplace_back(NoTestVisibilityEntry{&newEntry, renderable, false}); //< Address of entry will be updated when moving - - return newEntry; - } - - template - auto CullingList::RegisterSphereTest(const T* renderable) -> SphereEntry - { - SphereEntry newEntry(this, m_sphereTestList.size()); - m_sphereTestList.emplace_back(SphereVisibilityEntry{Nz::Spheref(), &newEntry, renderable, false}); //< Address of entry will be updated when moving - - return newEntry; - } - - template - auto CullingList::RegisterVolumeTest(const T* renderable) -> VolumeEntry - { - VolumeEntry newEntry(this, m_volumeTestList.size()); - m_volumeTestList.emplace_back(VolumeVisibilityEntry{Nz::BoundingVolumef(), &newEntry, renderable, false}); //< Address of entry will be updated when moving - - return newEntry; - } - - template - inline void CullingList::NotifyBoxUpdate(std::size_t index, const Boxf& box) - { - m_boxTestList[index].box = box; - } - - template - void CullingList::NotifyForceInvalidation(CullTest type, std::size_t index) - { - switch (type) - { - case CullTest::Box: - { - m_boxTestList[index].forceInvalidation = true; - break; - } - - case CullTest::NoTest: - { - m_noTestList[index].forceInvalidation = true; - break; - } - - case CullTest::Sphere: - { - m_sphereTestList[index].forceInvalidation = true; - break; - } - - case CullTest::Volume: - { - m_volumeTestList[index].forceInvalidation = true; - break; - } - - default: - NazaraInternalError("Unhandled culltype"); - break; - } - } - - template - void CullingList::NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr) - { - NazaraUnused(oldPtr); - - switch (type) - { - case CullTest::Box: - { - BoxVisibilityEntry& entry = m_boxTestList[index]; - NazaraAssert(entry.entry == oldPtr, "Invalid box entry"); - - entry.entry = static_cast(newPtr); - break; - } - - case CullTest::NoTest: - { - NoTestVisibilityEntry& entry = m_noTestList[index]; - NazaraAssert(entry.entry == oldPtr, "Invalid entry"); - - entry.entry = static_cast(newPtr); - break; - } - - case CullTest::Sphere: - { - SphereVisibilityEntry& entry = m_sphereTestList[index]; - NazaraAssert(entry.entry == oldPtr, "Invalid sphere entry"); - - entry.entry = static_cast(newPtr); - break; - } - - case CullTest::Volume: - { - VolumeVisibilityEntry& entry = m_volumeTestList[index]; - NazaraAssert(entry.entry == oldPtr, "Invalid volume entry"); - - entry.entry = static_cast(newPtr); - break; - } - - default: - NazaraInternalError("Unhandled culltype"); - break; - } - } - - template - void CullingList::NotifyRelease(CullTest type, std::size_t index) - { - switch (type) - { - case CullTest::Box: - { - m_boxTestList[index] = std::move(m_boxTestList.back()); - m_boxTestList[index].entry->UpdateIndex(index); - m_boxTestList.pop_back(); - break; - } - - case CullTest::NoTest: - { - m_noTestList[index] = std::move(m_noTestList.back()); - m_noTestList[index].entry->UpdateIndex(index); - m_noTestList.pop_back(); - break; - } - - case CullTest::Sphere: - { - m_sphereTestList[index] = std::move(m_sphereTestList.back()); - m_sphereTestList[index].entry->UpdateIndex(index); - m_sphereTestList.pop_back(); - break; - } - - case CullTest::Volume: - { - m_volumeTestList[index] = std::move(m_volumeTestList.back()); - m_volumeTestList[index].entry->UpdateIndex(index); - m_volumeTestList.pop_back(); - break; - } - - default: - NazaraInternalError("Unhandled culltype"); - break; - } - } - - template - void CullingList::NotifySphereUpdate(std::size_t index, const Spheref& sphere) - { - m_sphereTestList[index].sphere = sphere; - } - - template - void CullingList::NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume) - { - m_volumeTestList[index].volume = boundingVolume; - } - - ////////////////////////////////////////////////////////////////////////// - - template - template - CullingList::Entry::Entry() : - m_parent(nullptr) - { - } - - template - template - CullingList::Entry::Entry(CullingList* parent, std::size_t index) : - m_index(index), - m_parent(parent) - { - } - - template - template - CullingList::Entry::Entry(Entry&& entry) : - m_index(entry.m_index), - m_parent(entry.m_parent) - { - if (m_parent) - m_parent->NotifyMovement(Type, m_index, &entry, this); - - entry.m_parent = nullptr; - } - - template - template - CullingList::Entry::~Entry() - { - if (m_parent) - m_parent->NotifyRelease(Type, m_index); - } - - template - template - void CullingList::Entry::ForceInvalidation() - { - m_parent->NotifyForceInvalidation(Type, m_index); - } - - template - template - CullingList* CullingList::Entry::GetParent() const - { - return m_parent; - } - - template - template - void CullingList::Entry::UpdateIndex(std::size_t index) - { - m_index = index; - } - - template - template - typename CullingList::template Entry& CullingList::Entry::operator=(Entry&& entry) - { - m_index = entry.m_index; - m_parent = entry.m_parent; - if (m_parent) - m_parent->NotifyMovement(Type, m_index, &entry, this); - - entry.m_parent = nullptr; - - return *this; - } - - ////////////////////////////////////////////////////////////////////////// - - template - CullingList::BoxEntry::BoxEntry() : - ParentType() - { - } - - template - CullingList::BoxEntry::BoxEntry(CullingList* parent, std::size_t index) : - ParentType(parent, index) - { - } - - template - void CullingList::BoxEntry::UpdateBox(const Boxf& box) - { - this->m_parent->NotifyBoxUpdate(this->m_index, box); - } - - ////////////////////////////////////////////////////////////////////////// - - template - CullingList::NoTestEntry::NoTestEntry() : - ParentType() - { - } - - template - CullingList::NoTestEntry::NoTestEntry(CullingList* parent, std::size_t index) : - ParentType(parent, index) - { - } - - ////////////////////////////////////////////////////////////////////////// - - template - CullingList::SphereEntry::SphereEntry() : - ParentType() - { - } - - template - CullingList::SphereEntry::SphereEntry(CullingList* parent, std::size_t index) : - ParentType(parent, index) - { - } - - template - void CullingList::SphereEntry::UpdateSphere(const Spheref& sphere) - { - this->m_parent->NotifySphereUpdate(this->m_index, sphere); - } - - ////////////////////////////////////////////////////////////////////////// - - template - CullingList::VolumeEntry::VolumeEntry() : - ParentType() - { - } - - template - CullingList::VolumeEntry::VolumeEntry(CullingList* parent, std::size_t index) : - ParentType(parent, index) - { - } - - template - void CullingList::VolumeEntry::UpdateVolume(const BoundingVolumef& volume) - { - this->m_parent->NotifyVolumeUpdate(this->m_index, volume); - } -} - -#include diff --git a/include/Nazara/Graphics/Debug.hpp b/include/Nazara/Graphics/Debug.hpp deleted file mode 100644 index c7cd0cad5..000000000 --- a/include/Nazara/Graphics/Debug.hpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_GRAPHICS_MANAGE_MEMORY - #include -#endif diff --git a/include/Nazara/Graphics/DebugOff.hpp b/include/Nazara/Graphics/DebugOff.hpp deleted file mode 100644 index 42bef4737..000000000 --- a/include/Nazara/Graphics/DebugOff.hpp +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -// We suppose that Debug.hpp is already included, same goes for Config.hpp -#if NAZARA_GRAPHICS_MANAGE_MEMORY - #undef delete - #undef new -#endif diff --git a/include/Nazara/Graphics/DeferredBloomPass.hpp b/include/Nazara/Graphics/DeferredBloomPass.hpp deleted file mode 100644 index b93083b61..000000000 --- a/include/Nazara/Graphics/DeferredBloomPass.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDBLOOMPASS_HPP -#define NAZARA_DEFERREDBLOOMPASS_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API DeferredBloomPass : public DeferredRenderPass - { - public: - DeferredBloomPass(); - virtual ~DeferredBloomPass(); - - unsigned int GetBlurPassCount() const; - float GetBrightLuminance() const; - float GetBrightMiddleGrey() const; - float GetBrightThreshold() const; - Texture* GetTexture(unsigned int i) const; - - bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override; - bool Resize(const Vector2ui& dimensions) override; - - void SetBlurPassCount(unsigned int passCount); - void SetBrightLuminance(float luminance); - void SetBrightMiddleGrey(float middleGrey); - void SetBrightThreshold(float threshold); - - protected: - RenderStates m_bloomStates; - RenderTexture m_bloomRTT; - ShaderRef m_bloomBrightShader; - ShaderRef m_bloomFinalShader; - ShaderRef m_gaussianBlurShader; - TextureRef m_bloomTextures[2]; - TextureSampler m_bilinearSampler; - mutable bool m_uniformUpdated; - float m_brightLuminance; - float m_brightMiddleGrey; - float m_brightThreshold; - int m_gaussianBlurShaderFilterLocation; - unsigned int m_blurPassCount; - }; -} - -#endif // NAZARA_DEFERREDBLOOMPASS_HPP diff --git a/include/Nazara/Graphics/DeferredDOFPass.hpp b/include/Nazara/Graphics/DeferredDOFPass.hpp deleted file mode 100644 index fc06fade9..000000000 --- a/include/Nazara/Graphics/DeferredDOFPass.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDDOFPASS_HPP -#define NAZARA_DEFERREDDOFPASS_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API DeferredDOFPass : public DeferredRenderPass - { - public: - DeferredDOFPass(); - virtual ~DeferredDOFPass(); - - bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override; - bool Resize(const Vector2ui& dimensions) override; - - protected: - RenderTexture m_dofRTT; - RenderStates m_states; - ShaderConstRef m_dofShader; - ShaderConstRef m_gaussianBlurShader; - TextureRef m_dofTextures[2]; - TextureSampler m_bilinearSampler; - TextureSampler m_pointSampler; - int m_gaussianBlurShaderFilterLocation; - }; -} - -#endif // NAZARA_DEFERREDDOFPASS_HPP diff --git a/include/Nazara/Graphics/DeferredFXAAPass.hpp b/include/Nazara/Graphics/DeferredFXAAPass.hpp deleted file mode 100644 index 0a5b389df..000000000 --- a/include/Nazara/Graphics/DeferredFXAAPass.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDFXAAPASS_HPP -#define NAZARA_DEFERREDFXAAPASS_HPP - -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API DeferredFXAAPass : public DeferredRenderPass - { - public: - DeferredFXAAPass(); - virtual ~DeferredFXAAPass(); - - bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override; - - protected: - RenderStates m_states; - ShaderRef m_fxaaShader; - TextureSampler m_pointSampler; - }; -} - -#endif // NAZARA_DEFERREDFXAAPASS_HPP diff --git a/include/Nazara/Graphics/DeferredFinalPass.hpp b/include/Nazara/Graphics/DeferredFinalPass.hpp deleted file mode 100644 index 06b547a2d..000000000 --- a/include/Nazara/Graphics/DeferredFinalPass.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDFINALPASS_HPP -#define NAZARA_DEFERREDFINALPASS_HPP - -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API DeferredFinalPass : public DeferredRenderPass - { - public: - DeferredFinalPass(); - virtual ~DeferredFinalPass(); - - bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override; - - protected: - RenderStates m_states; - TextureSampler m_pointSampler; - UberShaderConstRef m_uberShader; - const UberShaderInstance* m_uberShaderInstance; - int m_materialDiffuseUniform; - int m_materialDiffuseMapUniform; - }; -} - -#endif // NAZARA_DEFERREDFINALPASS_HPP diff --git a/include/Nazara/Graphics/DeferredFogPass.hpp b/include/Nazara/Graphics/DeferredFogPass.hpp deleted file mode 100644 index c5faecf7e..000000000 --- a/include/Nazara/Graphics/DeferredFogPass.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDFOGPASS_HPP -#define NAZARA_DEFERREDFOGPASS_HPP - -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API DeferredFogPass : public DeferredRenderPass - { - public: - DeferredFogPass(); - virtual ~DeferredFogPass(); - - bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override; - - protected: - RenderStates m_states; - ShaderRef m_shader; - TextureSampler m_pointSampler; - int m_shaderEyePositionLocation; - }; -} - -#endif // NAZARA_DEFERREDFOGPASS_HPP diff --git a/include/Nazara/Graphics/DeferredForwardPass.hpp b/include/Nazara/Graphics/DeferredForwardPass.hpp deleted file mode 100644 index f711a74b5..000000000 --- a/include/Nazara/Graphics/DeferredForwardPass.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDFORWARDPASS_HPP -#define NAZARA_DEFERREDFORWARDPASS_HPP - -#include -#include - -namespace Nz -{ - class ForwardRenderTechnique; - - class NAZARA_GRAPHICS_API DeferredForwardPass : public DeferredRenderPass - { - public: - DeferredForwardPass(); - virtual ~DeferredForwardPass(); - - void Initialize(DeferredRenderTechnique* technique) override; - bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned int sceneTexture) const override; - - protected: - const ForwardRenderTechnique* m_forwardTechnique; - }; -} - -#endif // NAZARA_DEFERREDFORWARDPASS_HPP diff --git a/include/Nazara/Graphics/DeferredGeometryPass.hpp b/include/Nazara/Graphics/DeferredGeometryPass.hpp deleted file mode 100644 index 4c50241c8..000000000 --- a/include/Nazara/Graphics/DeferredGeometryPass.hpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDGEOMETRYPASS_HPP -#define NAZARA_DEFERREDGEOMETRYPASS_HPP - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API DeferredGeometryPass : public DeferredRenderPass - { - friend class DeferredRenderTechnique; - - public: - DeferredGeometryPass(); - virtual ~DeferredGeometryPass(); - - bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override; - bool Resize(const Vector2ui& dimensions) override; - - protected: - struct ShaderUniforms; - - void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const; - void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const; - void DrawModels(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& models) const; - void DrawSprites(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& sprites) const; - - const ShaderUniforms* GetShaderUniforms(const Shader* shader) const; - void OnShaderInvalidated(const Shader* shader) const; - - static bool Initialize(); - static void Uninitialize(); - - struct ShaderUniforms - { - NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot); - NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot); - - int eyePosition; - int sceneAmbient; - int textureOverlay; - }; - - struct SpriteBatch - { - std::size_t spriteCount; - const Material* material; - const Texture* overlayTexture; - Recti scissorRect; - }; - - mutable std::unordered_map m_shaderUniforms; - mutable std::vector m_spriteBatches; - Buffer m_vertexBuffer; - RenderStates m_clearStates; - ShaderRef m_clearShader; - TextureRef m_whiteTexture; - VertexBuffer m_billboardPointBuffer; - VertexBuffer m_spriteBuffer; - - static IndexBuffer s_quadIndexBuffer; - static VertexBuffer s_quadVertexBuffer; - static VertexDeclaration s_billboardInstanceDeclaration; - static VertexDeclaration s_billboardVertexDeclaration; - }; -} - -#endif // NAZARA_DEFERREDGEOMETRYPASS_HPP diff --git a/include/Nazara/Graphics/DeferredPhongLightingPass.hpp b/include/Nazara/Graphics/DeferredPhongLightingPass.hpp deleted file mode 100644 index 3dcdbe9fe..000000000 --- a/include/Nazara/Graphics/DeferredPhongLightingPass.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP -#define NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class StaticMesh; - - class NAZARA_GRAPHICS_API DeferredPhongLightingPass : public DeferredRenderPass - { - public: - DeferredPhongLightingPass(); - virtual ~DeferredPhongLightingPass(); - - void EnableLightMeshesDrawing(bool enable); - - bool IsLightMeshesDrawingEnabled() const; - - bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override; - - protected: - LightUniforms m_directionalLightUniforms; - LightUniforms m_pointSpotLightUniforms; - MeshRef m_cone; - MeshRef m_sphere; - ShaderRef m_directionalLightShader; - ShaderRef m_pointSpotLightShader; - TextureSampler m_pointSampler; - StaticMesh* m_coneMesh; - StaticMesh* m_sphereMesh; - bool m_lightMeshesDrawing; - int m_directionalLightShaderEyePositionLocation; - int m_directionalLightShaderSceneAmbientLocation; - int m_pointSpotLightShaderDiscardLocation; - int m_pointSpotLightShaderEyePositionLocation; - int m_pointSpotLightShaderSceneAmbientLocation; - }; -} - -#endif // NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP diff --git a/include/Nazara/Graphics/DeferredProxyRenderQueue.hpp b/include/Nazara/Graphics/DeferredProxyRenderQueue.hpp deleted file mode 100644 index a0ce9c6a5..000000000 --- a/include/Nazara/Graphics/DeferredProxyRenderQueue.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDRENDERQUEUE_HPP -#define NAZARA_DEFERREDRENDERQUEUE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class BasicRenderQueue; - - class NAZARA_GRAPHICS_API DeferredProxyRenderQueue final : public AbstractRenderQueue - { - public: - struct BillboardData; - - inline DeferredProxyRenderQueue(BasicRenderQueue* deferredQueue, BasicRenderQueue* forwardQueue); - ~DeferredProxyRenderQueue() = default; - - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr = nullptr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr = nullptr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) override; - void AddDrawable(int renderOrder, const Drawable* drawable) override; - void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) override; - void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay = nullptr) override; - - void Clear(bool fully = false) override; - - inline BasicRenderQueue* GetDeferredRenderQueue(); - inline BasicRenderQueue* GetForwardRenderQueue(); - - private: - BasicRenderQueue * m_deferredRenderQueue; - BasicRenderQueue* m_forwardRenderQueue; - }; -} - -#include - -#endif // NAZARA_DEFERREDRENDERQUEUE_HPP diff --git a/include/Nazara/Graphics/DeferredProxyRenderQueue.inl b/include/Nazara/Graphics/DeferredProxyRenderQueue.inl deleted file mode 100644 index 2f6e3da04..000000000 --- a/include/Nazara/Graphics/DeferredProxyRenderQueue.inl +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include - -namespace Nz -{ - /*! - * \brief Constructs a DeferredProxyRenderQueue using a deferred and a forward queues - * - * \param deferredQueue Deferred queue which will be used for non-blended objects - * \param forwardQueue Forward queue which will be used for blended objects - */ - inline DeferredProxyRenderQueue::DeferredProxyRenderQueue(BasicRenderQueue* deferredQueue, BasicRenderQueue* forwardQueue) : - m_deferredRenderQueue(deferredQueue), - m_forwardRenderQueue(forwardQueue) - { - } - - inline BasicRenderQueue* DeferredProxyRenderQueue::GetDeferredRenderQueue() - { - return m_deferredRenderQueue; - } - - inline BasicRenderQueue* DeferredProxyRenderQueue::GetForwardRenderQueue() - { - return m_forwardRenderQueue; - } -} diff --git a/include/Nazara/Graphics/DeferredRenderPass.hpp b/include/Nazara/Graphics/DeferredRenderPass.hpp deleted file mode 100644 index 217517d4c..000000000 --- a/include/Nazara/Graphics/DeferredRenderPass.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDRENDERPASS_HPP -#define NAZARA_DEFERREDRENDERPASS_HPP - -#include -#include -#include - -namespace Nz -{ - class DeferredRenderTechnique; - class DeferredProxyRenderQueue; - class RenderTexture; - class Texture; - struct SceneData; - - class NAZARA_GRAPHICS_API DeferredRenderPass - { - friend DeferredRenderTechnique; - - public: - DeferredRenderPass(); - DeferredRenderPass(const DeferredRenderPass&) = delete; - virtual ~DeferredRenderPass(); - - void Enable(bool enable); - - virtual void Initialize(DeferredRenderTechnique* technique); - - bool IsEnabled() const; - - virtual bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned int sceneTexture) const = 0; - virtual bool Resize(const Vector2ui& GBufferSize); - - DeferredRenderPass& operator=(const DeferredRenderPass&) = delete; - - protected: - Vector2ui m_dimensions; - DeferredRenderTechnique* m_deferredTechnique; - DeferredProxyRenderQueue* m_renderQueue; - RenderTexture* m_GBufferRTT; - RenderTexture* m_workRTT; - Texture* m_depthStencilTexture; - Texture* m_GBuffer[4]; - Texture* m_workTextures[2]; - - private: - bool m_enabled; - }; -} - -#endif // NAZARA_DEFERREDRENDERPASS_HPP diff --git a/include/Nazara/Graphics/DeferredRenderQueue.inl b/include/Nazara/Graphics/DeferredRenderQueue.inl deleted file mode 100644 index e69de29bb..000000000 diff --git a/include/Nazara/Graphics/DeferredRenderTechnique.hpp b/include/Nazara/Graphics/DeferredRenderTechnique.hpp deleted file mode 100644 index cca4cf166..000000000 --- a/include/Nazara/Graphics/DeferredRenderTechnique.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEFERREDRENDERTECHNIQUE_HPP -#define NAZARA_DEFERREDRENDERTECHNIQUE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class DeferredRenderPass; - - class NAZARA_GRAPHICS_API DeferredRenderTechnique : public AbstractRenderTechnique - { - friend class Graphics; - - public: - DeferredRenderTechnique(); - ~DeferredRenderTechnique(); - - void Clear(const SceneData& sceneData) const override; - bool Draw(const SceneData& sceneData) const override; - - void EnablePass(RenderPassType renderPass, int position, bool enable); - - Texture* GetDepthStencilTexture() const; - Texture* GetGBuffer(unsigned int i) const; - RenderTexture* GetGBufferRTT() const; - const ForwardRenderTechnique* GetForwardTechnique() const; - DeferredRenderPass* GetPass(RenderPassType renderPass, int position = 0); - AbstractRenderQueue* GetRenderQueue() override; - RenderTechniqueType GetType() const override; - RenderTexture* GetWorkRTT() const; - Texture* GetWorkTexture(unsigned int i) const; - - bool IsPassEnabled(RenderPassType renderPass, int position); - - DeferredRenderPass* ResetPass(RenderPassType renderPass, int position); - - void SetPass(RenderPassType relativeTo, int position, DeferredRenderPass* pass); - - static bool IsSupported(); - - private: - bool Resize(const Vector2ui& dimensions) const; - - static bool Initialize(); - static void Uninitialize(); - - struct RenderPassComparator - { - bool operator()(RenderPassType pass1, RenderPassType pass2) const; - }; - - std::map>, RenderPassComparator> m_passes; - BasicRenderQueue m_deferredRenderQueue; // Must be initialized before the ProxyRenderQueue - ForwardRenderTechnique m_forwardTechnique; // Must be initialized before the ProxyRenderQueue - DeferredProxyRenderQueue m_renderQueue; - mutable TextureRef m_depthStencilTexture; - mutable RenderTexture m_GBufferRTT; - mutable RenderTexture m_workRTT; - mutable TextureRef m_GBuffer[4]; - mutable TextureRef m_workTextures[2]; - mutable Vector2ui m_GBufferSize; - const RenderTarget* m_viewerTarget; - }; -} - -#endif // NAZARA_FORWARDRENDERTECHNIQUE_HPP diff --git a/include/Nazara/Graphics/DepthRenderQueue.hpp b/include/Nazara/Graphics/DepthRenderQueue.hpp deleted file mode 100644 index c0f6b57e0..000000000 --- a/include/Nazara/Graphics/DepthRenderQueue.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEPTHRENDERQUEUE_HPP -#define NAZARA_DEPTHRENDERQUEUE_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API DepthRenderQueue : public BasicRenderQueue - { - public: - DepthRenderQueue(); - ~DepthRenderQueue() = default; - - void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr = nullptr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr = nullptr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr = nullptr) override; - void AddBillboards(int renderOrder, const Material* material, std::size_t count, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) override; - void AddDirectionalLight(const DirectionalLight& light) override; - void AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) override; - void AddPointLight(const PointLight& light) override; - void AddSpotLight(const SpotLight& light) override; - void AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay = nullptr) override; - - private: - inline bool IsMaterialSuitable(const Material* material) const; - - MaterialRef m_baseMaterial; - }; -} - -#include - -#endif // NAZARA_DEPTHRENDERQUEUE_HPP diff --git a/include/Nazara/Graphics/DepthRenderQueue.inl b/include/Nazara/Graphics/DepthRenderQueue.inl deleted file mode 100644 index 2922736a1..000000000 --- a/include/Nazara/Graphics/DepthRenderQueue.inl +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include - -namespace Nz -{ - - /*! - * \brief Checks whether the material is suitable to fit in the render queue - * \return true If it is the case - * - * \param material Material to verify - */ - - bool DepthRenderQueue::IsMaterialSuitable(const Material* material) const - { - NazaraAssert(material, "Invalid material"); - - return material->HasDepthMaterial() || (material->IsDepthBufferEnabled() && material->IsDepthWriteEnabled() && material->IsShadowCastingEnabled()); - } -} - -#include diff --git a/include/Nazara/Graphics/DepthRenderTechnique.hpp b/include/Nazara/Graphics/DepthRenderTechnique.hpp deleted file mode 100644 index 945f546b8..000000000 --- a/include/Nazara/Graphics/DepthRenderTechnique.hpp +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DEPTHRENDERTECHNIQUE_HPP -#define NAZARA_DEPTHRENDERTECHNIQUE_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API DepthRenderTechnique : public AbstractRenderTechnique - { - public: - DepthRenderTechnique(); - ~DepthRenderTechnique() = default; - - void Clear(const SceneData& sceneData) const override; - bool Draw(const SceneData& sceneData) const override; - - AbstractRenderQueue* GetRenderQueue() override; - RenderTechniqueType GetType() const override; - - static bool Initialize(); - static void Uninitialize(); - - private: - struct ShaderUniforms; - - void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const; - void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const; - void DrawCustomDrawables(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& customDrawables) const; - void DrawModels(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& models) const; - void DrawSprites(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& sprites) const; - - const ShaderUniforms* GetShaderUniforms(const Shader* shader) const; - void OnShaderInvalidated(const Shader* shader) const; - - struct LightIndex - { - LightType type; - float score; - unsigned int index; - }; - - struct ShaderUniforms - { - NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot); - NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot); - - // Autre uniformes - int sceneAmbient; - int textureOverlay; - }; - - struct SpriteBatch - { - std::size_t spriteCount; - const Material* material; - const Texture* overlayTexture; - Recti scissorRect; - }; - - mutable std::unordered_map m_shaderUniforms; - mutable std::vector m_spriteBatches; - Buffer m_vertexBuffer; - RenderStates m_clearStates; - ShaderRef m_clearShader; - TextureRef m_whiteTexture; - VertexBuffer m_billboardPointBuffer; - VertexBuffer m_spriteBuffer; - mutable DepthRenderQueue m_renderQueue; - - static IndexBuffer s_quadIndexBuffer; - static VertexBuffer s_quadVertexBuffer; - static VertexDeclaration s_billboardInstanceDeclaration; - static VertexDeclaration s_billboardVertexDeclaration; - }; -} - - -#include - -#endif // NAZARA_DEPTHRENDERTECHNIQUE_HPP diff --git a/include/Nazara/Graphics/DepthRenderTechnique.inl b/include/Nazara/Graphics/DepthRenderTechnique.inl deleted file mode 100644 index 811fb7c6b..000000000 --- a/include/Nazara/Graphics/DepthRenderTechnique.inl +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Graphics/Drawable.hpp b/include/Nazara/Graphics/Drawable.hpp deleted file mode 100644 index 4970367a0..000000000 --- a/include/Nazara/Graphics/Drawable.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_DRAWABLE_HPP -#define NAZARA_DRAWABLE_HPP - -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API Drawable - { - public: - Drawable() = default; - virtual ~Drawable(); - - virtual void Draw() const = 0; - }; -} - -#endif // NAZARA_DRAWABLE_HPP diff --git a/include/Nazara/Graphics/Enums.hpp b/include/Nazara/Graphics/Enums.hpp deleted file mode 100644 index 6a351494e..000000000 --- a/include/Nazara/Graphics/Enums.hpp +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ENUMS_GRAPHICS_HPP -#define NAZARA_ENUMS_GRAPHICS_HPP - -namespace Nz -{ - enum BackgroundType - { - BackgroundType_Color, // ColorBackground - BackgroundType_Skybox, // SkyboxBackground - BackgroundType_Texture, // TextureBackground - BackgroundType_User, - - BackgroundType_Max = BackgroundType_User - }; - - enum class CullTest - { - Box, - NoTest, - Sphere, - Volume - }; - - enum ProjectionType - { - ProjectionType_Orthogonal, - ProjectionType_Perspective, - - ProjectionType_Max = ProjectionType_Perspective - }; - - enum LightType - { - LightType_Directional, - LightType_Point, - LightType_Spot, - - LightType_Max = LightType_Spot - }; - - enum MaterialUniform - { - MaterialUniform_AlphaMap, - MaterialUniform_AlphaThreshold, - MaterialUniform_Ambient, - MaterialUniform_Diffuse, - MaterialUniform_DiffuseMap, - MaterialUniform_EmissiveMap, - MaterialUniform_HeightMap, - MaterialUniform_NormalMap, - MaterialUniform_Shininess, - MaterialUniform_Specular, - MaterialUniform_SpecularMap, - - MaterialUniform_Max = MaterialUniform_SpecularMap - }; - - enum ParticleComponent - { - ParticleComponent_Unused = -1, - - ParticleComponent_Color, - ParticleComponent_Life, - ParticleComponent_Mass, - ParticleComponent_Normal, - ParticleComponent_Position, - ParticleComponent_Radius, - ParticleComponent_Rotation, - ParticleComponent_Size, - ParticleComponent_Velocity, - ParticleComponent_Userdata0, - ParticleComponent_Userdata1, - ParticleComponent_Userdata2, - ParticleComponent_Userdata3, - ParticleComponent_Userdata4, - ParticleComponent_Userdata5, - ParticleComponent_Userdata6, - ParticleComponent_Userdata7, - ParticleComponent_Userdata8, - - ParticleComponent_Max = ParticleComponent_Userdata8 - }; - - enum ParticleLayout - { - ParticleLayout_Billboard, - ParticleLayout_Model, - ParticleLayout_Sprite, - - ParticleLayout_Max = ParticleLayout_Sprite - }; - - enum RenderPassType - { - RenderPassType_AA, - RenderPassType_Bloom, - RenderPassType_DOF, - RenderPassType_Final, - RenderPassType_Fog, - RenderPassType_Forward, - RenderPassType_Lighting, - RenderPassType_Geometry, - RenderPassType_SSAO, - - RenderPassType_Max = RenderPassType_SSAO - }; - - enum RenderTechniqueType - { - RenderTechniqueType_AdvancedForward, // AdvancedForwardRenderTechnique - RenderTechniqueType_BasicForward, // BasicForwardRenderTechnique - RenderTechniqueType_DeferredShading, // DeferredRenderTechnique - RenderTechniqueType_Depth, // DepthRenderTechnique - RenderTechniqueType_LightPrePass, // LightPrePassRenderTechnique - RenderTechniqueType_User, - - RenderTechniqueType_Max = RenderTechniqueType_User - }; - - enum ReflectionMode - { - ReflectionMode_RealTime, - ReflectionMode_Probe, - ReflectionMode_Skybox, - - ReflectionMode_Max = ReflectionMode_Skybox - }; - - enum SceneNodeType - { - SceneNodeType_Light, // Light - SceneNodeType_Model, // Model - SceneNodeType_ParticleEmitter, // ParticleEmitter - SceneNodeType_Root, // SceneRoot - SceneNodeType_Sprite, // Sprite - SceneNodeType_TextSprite, // TextSprite - SceneNodeType_User, - - SceneNodeType_Max = SceneNodeType_User - }; - - // These parameters are independant of the material: they can not be asked for the moment - enum ShaderFlags - { - ShaderFlags_None = 0, - - ShaderFlags_Billboard = 0x01, - ShaderFlags_Deferred = 0x02, - ShaderFlags_Instancing = 0x04, - ShaderFlags_TextureOverlay = 0x08, - ShaderFlags_VertexColor = 0x10, - - ShaderFlags_Max = ShaderFlags_VertexColor * 2 - 1 - }; - - enum TextureMap - { - TextureMap_Alpha, - TextureMap_Diffuse, - TextureMap_Emissive, - TextureMap_Height, - TextureMap_ReflectionCube, - TextureMap_Normal, - TextureMap_Overlay, - TextureMap_Shadow2D_1, - TextureMap_Shadow2D_2, - TextureMap_Shadow2D_3, - TextureMap_ShadowCube_1, - TextureMap_ShadowCube_2, - TextureMap_ShadowCube_3, - TextureMap_Specular, - - TextureMap_Max = TextureMap_Specular - }; -} - -#endif // NAZARA_ENUMS_GRAPHICS_HPP diff --git a/include/Nazara/Graphics/ForwardRenderTechnique.hpp b/include/Nazara/Graphics/ForwardRenderTechnique.hpp deleted file mode 100644 index caa340981..000000000 --- a/include/Nazara/Graphics/ForwardRenderTechnique.hpp +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_FORWARDRENDERTECHNIQUE_HPP -#define NAZARA_FORWARDRENDERTECHNIQUE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API ForwardRenderTechnique : public AbstractRenderTechnique - { - public: - ForwardRenderTechnique(); - ~ForwardRenderTechnique() = default; - - void Clear(const SceneData& sceneData) const override; - bool Draw(const SceneData& sceneData) const override; - - unsigned int GetMaxLightPassPerObject() const; - AbstractRenderQueue* GetRenderQueue() override; - RenderTechniqueType GetType() const override; - - void SetMaxLightPassPerObject(unsigned int maxLightPassPerObject); - - static bool Initialize(); - static void Uninitialize(); - - protected: - struct ShaderUniforms; - - void ChooseLights(const Spheref& object, bool includeDirectionalLights = true) const; - void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const; - void DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const; - void DrawCustomDrawables(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& customDrawables) const; - void DrawModels(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& models) const; - void DrawSprites(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& sprites) const; - - const ShaderUniforms* GetShaderUniforms(const Shader* shader) const; - void OnShaderInvalidated(const Shader* shader) const; - void SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int lightIndex, unsigned int uniformOffset) const; - - static float ComputeDirectionalLightScore(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light); - static float ComputePointLightScore(const Spheref& object, const AbstractRenderQueue::PointLight& light); - static float ComputeSpotLightScore(const Spheref& object, const AbstractRenderQueue::SpotLight& light); - static bool IsDirectionalLightSuitable(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light); - static bool IsPointLightSuitable(const Spheref& object, const AbstractRenderQueue::PointLight& light); - static bool IsSpotLightSuitable(const Spheref& object, const AbstractRenderQueue::SpotLight& light); - - struct LightIndex - { - LightType type; - float score; - unsigned int index; - }; - - struct ShaderUniforms - { - NazaraSlot(Shader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot); - NazaraSlot(Shader, OnShaderRelease, shaderReleaseSlot); - - LightUniforms lightUniforms; - bool hasLightUniforms; - - /// Less costly in memory than storing a LightUniforms by index of light, - /// this may not work everywhere - int lightOffset; // "Distance" between Lights[0].type and Lights[1].type - - // Other uniforms - int eyePosition; - int reflectionMap; - int sceneAmbient; - int textureOverlay; - }; - - struct SpriteBatch - { - std::size_t spriteCount; - const Material* material; - const Texture* overlayTexture; - Recti scissorRect; - }; - - mutable std::unordered_map m_shaderUniforms; - mutable std::vector m_lights; - mutable std::vector m_spriteBatches; - Buffer m_vertexBuffer; - mutable BasicRenderQueue m_renderQueue; - TextureRef m_whiteCubemap; - TextureRef m_whiteTexture; - VertexBuffer m_billboardPointBuffer; - VertexBuffer m_spriteBuffer; - unsigned int m_maxLightPassPerObject; - - static IndexBuffer s_quadIndexBuffer; - static TextureSampler s_reflectionSampler; - static TextureSampler s_shadowSampler; - static VertexBuffer s_quadVertexBuffer; - static VertexDeclaration s_billboardInstanceDeclaration; - static VertexDeclaration s_billboardVertexDeclaration; - }; -} - -#include - -#endif // NAZARA_FORWARDRENDERTECHNIQUE_HPP diff --git a/include/Nazara/Graphics/ForwardRenderTechnique.inl b/include/Nazara/Graphics/ForwardRenderTechnique.inl deleted file mode 100644 index d76ae79dc..000000000 --- a/include/Nazara/Graphics/ForwardRenderTechnique.inl +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include - -namespace Nz -{ - /*! - * \brief Computes the score for directional light - * \return 0.f - * - * \param object Sphere symbolising the object - * \param light Light to compute - */ - - inline float ForwardRenderTechnique::ComputeDirectionalLightScore(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light) - { - NazaraUnused(object); - NazaraUnused(light); - - ///TODO: Compute a score depending on the light luminosity - return 0.f; - } - - /*! - * \brief Computes the score for point light - * \return Distance to the light - * - * \param object Sphere symbolising the object - * \param light Light to compute - */ - - inline float ForwardRenderTechnique::ComputePointLightScore(const Spheref& object, const AbstractRenderQueue::PointLight& light) - { - ///TODO: Compute a score depending on the light luminosity - return object.GetPosition().SquaredDistance(light.position); - } - - /*! - * \brief Computes the score for spot light - * \return Distance to the light - * - * \param object Sphere symbolising the object - * \param light Light to compute - */ - - inline float ForwardRenderTechnique::ComputeSpotLightScore(const Spheref& object, const AbstractRenderQueue::SpotLight& light) - { - ///TODO: Compute a score depending on the light luminosity and spot direction - return object.GetPosition().SquaredDistance(light.position); - } - - /*! - * \brief Checks whether the directional light is suitable for the computations - * \return true if light is enoughly close - * - * \param object Sphere symbolising the object - * \param light Light to compute - */ - - inline bool ForwardRenderTechnique::IsDirectionalLightSuitable(const Spheref& object, const AbstractRenderQueue::DirectionalLight& light) - { - NazaraUnused(object); - NazaraUnused(light); - - // Directional light are always suitable - return true; - } - - /*! - * \brief Checks whether the point light is suitable for the computations - * \return true if light is close enough - * - * \param object Sphere symbolizing the object - * \param light Light to compute - */ - - inline bool ForwardRenderTechnique::IsPointLightSuitable(const Spheref& object, const AbstractRenderQueue::PointLight& light) - { - // If the object is too far away from this point light, there is not way it could light it - return object.Intersect(Spheref(light.position, light.radius)); - } - - /*! - * \brief Checks whether the spot light is suitable for the computations - * \return true if light is close enough - * - * \param object Sphere symbolizing the object - * \param light Light to compute - */ - - inline bool ForwardRenderTechnique::IsSpotLightSuitable(const Spheref& object, const AbstractRenderQueue::SpotLight& light) - { - ///TODO: Exclude spot lights based on their direction and outer angle? - return object.Intersect(Spheref(light.position, light.radius)); - } -} diff --git a/include/Nazara/Graphics/Graphics.hpp b/include/Nazara/Graphics/Graphics.hpp deleted file mode 100644 index 3e1bfdf2a..000000000 --- a/include/Nazara/Graphics/Graphics.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_GRAPHICS_HPP -#define NAZARA_GRAPHICS_HPP - -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API Graphics - { - public: - Graphics() = delete; - ~Graphics() = delete; - - static bool Initialize(); - - static bool IsInitialized(); - - static void Uninitialize(); - - private: - static unsigned int s_moduleReferenceCounter; - }; -} - -#endif // NAZARA_GRAPHICS_HPP diff --git a/include/Nazara/Graphics/GuillotineTextureAtlas.hpp b/include/Nazara/Graphics/GuillotineTextureAtlas.hpp deleted file mode 100644 index fa38f205a..000000000 --- a/include/Nazara/Graphics/GuillotineTextureAtlas.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_GUILLOTINETEXTUREATLAS_HPP -#define NAZARA_GUILLOTINETEXTUREATLAS_HPP - -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API GuillotineTextureAtlas : public GuillotineImageAtlas - { - public: - GuillotineTextureAtlas() = default; - ~GuillotineTextureAtlas() = default; - - UInt32 GetStorage() const override; - - private: - AbstractImage* ResizeImage(AbstractImage* oldImage, const Vector2ui& size) const override; - }; -} - -#endif // NAZARA_GUILLOTINETEXTUREATLAS_HPP diff --git a/include/Nazara/Graphics/InstancedRenderable.hpp b/include/Nazara/Graphics/InstancedRenderable.hpp deleted file mode 100644 index fec1df25c..000000000 --- a/include/Nazara/Graphics/InstancedRenderable.hpp +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_INSTANCEDRENDERABLE_HPP -#define NAZARA_INSTANCEDRENDERABLE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class AbstractRenderQueue; - class InstancedRenderable; - - using InstancedRenderableConstRef = ObjectRef; - using InstancedRenderableLibrary = ObjectLibrary; - using InstancedRenderableRef = ObjectRef; - - class NAZARA_GRAPHICS_API InstancedRenderable : public RefCounted - { - public: - struct InstanceData; - - inline InstancedRenderable(); - inline InstancedRenderable(const InstancedRenderable& renderable); - InstancedRenderable(InstancedRenderable&& renderable) = delete; - virtual ~InstancedRenderable(); - - virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const = 0; - - virtual std::unique_ptr Clone() const = 0; - - virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const; - - inline void EnsureBoundingVolumeUpdated() const; - - virtual const BoundingVolumef& GetBoundingVolume() const; - - inline const MaterialRef& GetMaterial(std::size_t matIndex = 0) const; - inline const MaterialRef& GetMaterial(std::size_t skinIndex, std::size_t matIndex) const; - inline std::size_t GetMaterialCount() const; - inline std::size_t GetSkin() const; - inline std::size_t GetSkinCount() const; - - virtual void InvalidateData(InstanceData* instanceData, UInt32 flags) const; - - inline void SetMaterial(std::size_t matIndex, MaterialRef material); - inline void SetMaterial(std::size_t skinIndex, std::size_t matIndex, MaterialRef material); - inline void SetSkin(std::size_t skinIndex); - inline void SetSkinCount(std::size_t skinCount); - - virtual void UpdateBoundingVolume(InstanceData* instanceData) const; - virtual void UpdateData(InstanceData* instanceData) const; - - inline InstancedRenderable& operator=(const InstancedRenderable& renderable); - InstancedRenderable& operator=(InstancedRenderable&& renderable) = delete; - - // Signals: - NazaraSignal(OnInstancedRenderableInvalidateBoundingVolume, const InstancedRenderable* /*instancedRenderable*/); - NazaraSignal(OnInstancedRenderableInvalidateData, const InstancedRenderable* /*instancedRenderable*/, UInt32 /*flags*/); - NazaraSignal(OnInstancedRenderableInvalidateMaterial, const InstancedRenderable* /*instancedRenderable*/, std::size_t /*skinIndex*/, std::size_t /*matIndex*/, const MaterialRef& /*newMat*/); - NazaraSignal(OnInstancedRenderableRelease, const InstancedRenderable* /*instancedRenderable*/); - NazaraSignal(OnInstancedRenderableResetMaterials, const InstancedRenderable* /*instancedRenderable*/, std::size_t /*newMaterialCount*/); - NazaraSignal(OnInstancedRenderableSkinChange, const InstancedRenderable* /*instancedRenderable*/, std::size_t /*newSkinIndex*/); - - struct InstanceData - { - InstanceData(const Matrix4f& transformationMatrix) : - localMatrix(transformationMatrix), - flags(0) - { - } - - InstanceData(InstanceData&& instanceData) noexcept = default; - - InstanceData& operator=(InstanceData&& instanceData) noexcept - { - data = std::move(instanceData.data); - flags = instanceData.flags; - renderOrder = instanceData.renderOrder; - localMatrix = instanceData.localMatrix; - transformMatrix = instanceData.transformMatrix; - volume = instanceData.volume; - - return *this; - } - - std::vector data; - BoundingVolumef volume; - Matrix4f localMatrix; - mutable Matrix4f transformMatrix; - UInt32 flags; - int renderOrder; - }; - - protected: - inline void InvalidateBoundingVolume(); - inline void InvalidateInstanceData(UInt32 flags); - - virtual void MakeBoundingVolume() const = 0; - - inline void ResetMaterials(std::size_t matCount, std::size_t skinCount = 1); - - mutable BoundingVolumef m_boundingVolume; - - private: - inline void UpdateBoundingVolume() const; - - std::size_t m_matCount; - std::size_t m_skin; - std::size_t m_skinCount; - std::vector m_materials; - mutable bool m_boundingVolumeUpdated; - - static InstancedRenderableLibrary::LibraryMap s_library; - }; -} - -#include - -#endif // NAZARA_INSTANCEDRENDERABLE_HPP diff --git a/include/Nazara/Graphics/InstancedRenderable.inl b/include/Nazara/Graphics/InstancedRenderable.inl deleted file mode 100644 index 0aa0a03a5..000000000 --- a/include/Nazara/Graphics/InstancedRenderable.inl +++ /dev/null @@ -1,280 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \brief Constructs a InstancedRenderable object by default - */ - inline InstancedRenderable::InstancedRenderable() : - m_boundingVolumeUpdated(false) - { - } - - /*! - * \brief Constructs a InstancedRenderable object by assignation - * - * \param renderable InstancedRenderable to copy into this - */ - inline InstancedRenderable::InstancedRenderable(const InstancedRenderable& renderable) : - RefCounted(), - m_boundingVolume(renderable.m_boundingVolume), - m_matCount(renderable.m_matCount), - m_skin(renderable.m_skin), - m_skinCount(renderable.m_skinCount), - m_materials(renderable.m_materials), - m_boundingVolumeUpdated(renderable.m_boundingVolumeUpdated) - { - } - - /*! - * \brief Ensures that the bounding volume is up to date - */ - - inline void InstancedRenderable::EnsureBoundingVolumeUpdated() const - { - if (!m_boundingVolumeUpdated) - UpdateBoundingVolume(); - } - - /*! - * \brief Gets one of the material used by the object. - * \return A reference to the material. - * - * This function returns the active material at the specified index, depending on the current active skin. - * - * \param matIndex Material index to query - * - * \see GetSkin, GetMaterialCount, SetSkin - */ - inline const MaterialRef& InstancedRenderable::GetMaterial(std::size_t matIndex) const - { - return GetMaterial(m_skin, matIndex); - } - - /*! - * \brief Gets one of the material used by the object, independently from the active skin. - * \return A reference to the material. - * - * This function returns the active material at the specified index and the specified skin index. - * This function is the only way to query a material independently from the active skin. - * - * \param skinIndex Skin index to query - * \param matIndex Material index to query - * - * \see GetSkinCount, GetMaterialCount, SetSkin - */ - inline const MaterialRef& InstancedRenderable::GetMaterial(std::size_t skinIndex, std::size_t matIndex) const - { - NazaraAssert(skinIndex < m_skinCount, "Skin index out of bounds"); - NazaraAssert(matIndex < m_materials.size(), "Material index out of bounds"); - - return m_materials[m_matCount * skinIndex + matIndex]; - } - - /*! - * \brief Gets the number of material per skin. - * \return The current material count per skin - * - * This function returns how many different materials entries exists per skin - * and is independent from the number of skin. - */ - inline std::size_t InstancedRenderable::GetMaterialCount() const - { - return m_matCount; - } - - /*! - * \brief Gets the current active skin index - * \return Current skin index - * - * \see SetSkin - */ - inline std::size_t InstancedRenderable::GetSkin() const - { - return m_skin; - } - - /*! - * \brief Gets the number of skins this object has - * \return Skin count - * - * \see GetSkin, SetSkinCount - */ - inline std::size_t InstancedRenderable::GetSkinCount() const - { - return m_skinCount; - } - - /*! - * \brief Changes the material used at the specified index by another one - * - * This function changes the active material at the specified index, depending on the current active skin, to the one passed as parameter. - * - * \param matIndex Material index - * \param material New material, cannot be null - * - * \remark If you wish to reset the material to the default one, use the default material (see Material::GetDefault) - * - * \see SetMaterial - */ - inline void InstancedRenderable::SetMaterial(std::size_t matIndex, MaterialRef material) - { - SetMaterial(m_skin, matIndex, std::move(material)); - } - - /*! - * \brief Changes the material used at the specified index by another one, independently from the active skin. - * - * This function changes the active material at the specified index and for the specified skin index, to the one passed as parameter. - * - * \param skinIndex Skin index - * \param matIndex Material index - * \param material New material, cannot be null - * - * \remark If you wish to reset the material to the default one, use the default material (see Material::GetDefault) - * - * \see SetMaterial - */ - inline void InstancedRenderable::SetMaterial(std::size_t skinIndex, std::size_t matIndex, MaterialRef material) - { - NazaraAssert(skinIndex < m_skinCount, "Skin index out of bounds"); - NazaraAssert(matIndex < m_materials.size(), "Material index out of bounds"); - NazaraAssert(material.IsValid(), "Material must be valid"); - - MaterialRef& matEntry = m_materials[m_matCount * skinIndex + matIndex]; - if (matEntry != material) - { - OnInstancedRenderableInvalidateMaterial(this, skinIndex, matIndex, material); - - matEntry = std::move(material); - } - } - - /*! - * \brief Changes the active skin - * - * Each InstancedRenderable has the possibility to have multiples skins, which are sets of materials. - * Using this function allows you to have an object reference multiple materials, while using only some of thems (depending on the type of the object, see GetMaterialCount). - * - * \param skinIndex Skin index to change to - * - * \see SetSkinCount - */ - inline void InstancedRenderable::SetSkin(std::size_t skinIndex) - { - NazaraAssert(skinIndex < m_skinCount, "Skin index out of bounds"); - - if (m_skin != skinIndex) - { - OnInstancedRenderableSkinChange(this, skinIndex); - - m_skin = skinIndex; - - // Force render queue invalidation - InvalidateInstanceData(0); - } - } - - /*! - * \brief Changes the maximum skin count of the object - * - * This functions allows the object to store up to skinCount skins, which can then be switched to using SetSkin. - * Please note that the possibly new skins will be set to the default material, which should not be changed. - * - * \param skinCount Skin index to change to - * - * \see SetSkin - */ - inline void InstancedRenderable::SetSkinCount(std::size_t skinCount) - { - m_materials.resize(m_matCount * skinCount, Material::GetDefault()); - m_skinCount = skinCount; - } - - /*! - * \brief Invalidates the bounding volume - */ - - inline void InstancedRenderable::InvalidateBoundingVolume() - { - m_boundingVolumeUpdated = false; - - OnInstancedRenderableInvalidateBoundingVolume(this); - } - - /*! - * \brief Invalidates the instance data based on flags - * - * \param flags Flags to invalidate - */ - - inline void InstancedRenderable::InvalidateInstanceData(UInt32 flags) - { - OnInstancedRenderableInvalidateData(this, flags); - } - - /*! - * \brief Resets the materials, material count and skin count - * - * This function clears the materials in use by the InstancedRenderable and resets its material count per skin along with its skin count. - * This is the only way of setting the material count per skin and should be called at least by the constructor of the derived class. - * Please note that all materials will be set to the default material, which should not be changed. - * - * This function also resets the current skin to the first one. - * - * \param matCount The new material count per skin value, must be at least 1 - * \param skinCount The new skin count value - * - * \see GetMaterial, GetMaterialCount, GetSkinCount, SetSkinCount - */ - inline void InstancedRenderable::ResetMaterials(std::size_t matCount, std::size_t skinCount) - { - NazaraAssert(skinCount != 0, "Invalid skin count (cannot be zero)"); - - OnInstancedRenderableResetMaterials(this, matCount); - - m_materials.clear(); - m_materials.resize(matCount * skinCount, Material::GetDefault()); - - m_matCount = matCount; - m_skinCount = skinCount; - m_skin = 0; - } - - /*! - * \brief Sets the current instanced renderable with the content of the other one - * \return A reference to this - * - * \param renderable The other InstancedRenderable - */ - - inline InstancedRenderable& InstancedRenderable::operator=(const InstancedRenderable& renderable) - { - m_boundingVolume = renderable.m_boundingVolume; - m_boundingVolumeUpdated = renderable.m_boundingVolumeUpdated; - m_matCount = renderable.m_matCount; - m_materials = renderable.m_materials; - m_skin = renderable.m_skin; - m_skinCount = renderable.m_skinCount; - - return *this; - } - - /*! - * \brief Updates the bounding volume - */ - - inline void InstancedRenderable::UpdateBoundingVolume() const - { - MakeBoundingVolume(); - - m_boundingVolumeUpdated = true; - } -} - -#include diff --git a/include/Nazara/Graphics/Light.hpp b/include/Nazara/Graphics/Light.hpp deleted file mode 100644 index a7b26ab17..000000000 --- a/include/Nazara/Graphics/Light.hpp +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_LIGHT_HPP -#define NAZARA_LIGHT_HPP - -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API Light : public Renderable - { - public: - Light(LightType type = LightType_Point); - inline Light(const Light& light); - Light(Light&& light) = default; - ~Light() = default; - - void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const override; - - Light* Clone() const; - Light* Create() const; - - bool Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const override; - - inline void EnableShadowCasting(bool castShadows); - - inline void EnsureShadowMapUpdate() const; - - inline float GetAmbientFactor() const; - inline float GetAttenuation() const; - inline Color GetColor() const; - inline float GetDiffuseFactor() const; - inline float GetInnerAngle() const; - inline float GetInnerAngleCosine() const; - inline float GetInvRadius() const; - inline LightType GetLightType() const; - inline float GetOuterAngle() const; - inline float GetOuterAngleCosine() const; - inline float GetOuterAngleTangent() const; - inline float GetRadius() const; - inline TextureRef GetShadowMap() const; - inline PixelFormat GetShadowMapFormat() const; - inline const Vector2ui& GetShadowMapSize() const; - - inline bool IsShadowCastingEnabled() const; - - inline void SetAmbientFactor(float factor); - inline void SetAttenuation(float attenuation); - inline void SetColor(const Color& color); - inline void SetDiffuseFactor(float factor); - inline void SetInnerAngle(float innerAngle); - inline void SetLightType(LightType type); - inline void SetOuterAngle(float outerAngle); - inline void SetRadius(float radius); - inline void SetShadowMapFormat(PixelFormat shadowFormat); - inline void SetShadowMapSize(const Vector2ui& size); - - void UpdateBoundingVolume(const Matrix4f& transformMatrix) override; - - Light& operator=(const Light& light); - Light& operator=(Light&& light) = default; - - private: - void MakeBoundingVolume() const override; - inline void InvalidateShadowMap(); - void UpdateShadowMap() const; - - Color m_color; - LightType m_type; - PixelFormat m_shadowMapFormat; - Vector2ui m_shadowMapSize; - mutable TextureRef m_shadowMap; - bool m_shadowCastingEnabled; - mutable bool m_shadowMapUpdated; - float m_ambientFactor; - float m_attenuation; - float m_diffuseFactor; - float m_innerAngle; - float m_innerAngleCosine; - float m_invRadius; - float m_outerAngle; - float m_outerAngleCosine; - float m_outerAngleTangent; - float m_radius; - }; - - struct LightUniforms - { - struct UniformLocations - { - int type; - int color; - int factors; - int lightViewProjMatrix; - int parameters1; - int parameters2; - int parameters3; - int shadowMapping; - }; - - bool ubo; - - union - { - UniformLocations locations; - int blockLocation; - }; - }; -} - -#include - -#endif // NAZARA_LIGHT_HPP diff --git a/include/Nazara/Graphics/Light.inl b/include/Nazara/Graphics/Light.inl deleted file mode 100644 index 103445958..000000000 --- a/include/Nazara/Graphics/Light.inl +++ /dev/null @@ -1,404 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \brief Constructs a Light object by default - */ - - inline Light::Light(const Light& light) : - Renderable(light), - m_color(light.m_color), - m_type(light.m_type), - m_shadowMapFormat(light.m_shadowMapFormat), - m_shadowMapSize(light.m_shadowMapSize), - m_shadowCastingEnabled(light.m_shadowCastingEnabled), - m_shadowMapUpdated(false), - m_ambientFactor(light.m_ambientFactor), - m_attenuation(light.m_attenuation), - m_diffuseFactor(light.m_diffuseFactor), - m_innerAngle(light.m_innerAngle), - m_innerAngleCosine(light.m_innerAngleCosine), - m_invRadius(light.m_invRadius), - m_outerAngle(light.m_outerAngle), - m_outerAngleCosine(light.m_outerAngleCosine), - m_outerAngleTangent(light.m_outerAngleTangent), - m_radius(light.m_radius) - { - } - - /*! - * \brief Enables shadow casting - * - * \param castShadows Should shadows be cast - */ - - inline void Light::EnableShadowCasting(bool castShadows) - { - if (m_shadowCastingEnabled != castShadows) - { - m_shadowCastingEnabled = castShadows; - m_shadowMapUpdated = false; - } - } - - /*! - * \brief Ensures that the shadow map is up to date - */ - - inline void Light::EnsureShadowMapUpdate() const - { - if (!m_shadowMapUpdated) - UpdateShadowMap(); - } - - /*! - * \brief Gets the ambient factor - * \return Current ambient factor - */ - - inline float Light::GetAmbientFactor() const - { - return m_ambientFactor; - } - - /*! - * \brief Gets the light attenuation (in 1 / R^2) - * \return Attenuation - */ - - inline float Light::GetAttenuation() const - { - return m_attenuation; - } - - /*! - * \brief Gets the color of the light - * \return Light color - */ - - inline Color Light::GetColor() const - { - return m_color; - } - - /*! - * \brief Gets the diffuse factor - * \return Current diffuse factor - */ - - inline float Light::GetDiffuseFactor() const - { - return m_diffuseFactor; - } - - /*! - * \brief Gets the inner angle in spot light - * \return Inner angle - */ - - inline float Light::GetInnerAngle() const - { - return m_innerAngle; - } - - /*! - * \brief Gets the cosine inner angle in spot light - * \return Cosine inner angle - */ - - inline float Light::GetInnerAngleCosine() const - { - return m_innerAngleCosine; - } - - /*! - * \brief Gets the inverse of the radius - * \return Inverse of the radius - */ - - inline float Light::GetInvRadius() const - { - return m_invRadius; - } - - /*! - * \brief Gets the type of the light - * \return Light type - */ - - inline LightType Light::GetLightType() const - { - return m_type; - } - - /*! - * \brief Gets the outer angle in spot light - * \return Outer angle - */ - - inline float Light::GetOuterAngle() const - { - return m_outerAngle; - } - - /*! - * \brief Gets the cosine outer angle in spot light - * \return Cosine outer angle - */ - - inline float Light::GetOuterAngleCosine() const - { - return m_outerAngleCosine; - } - - /*! - * \brief Gets the tangent outer angle in spot light - * \return Tangent outer angle - */ - - inline float Light::GetOuterAngleTangent() const - { - return m_outerAngleTangent; - } - - /*! - * \brief Gets the radius of the light - * \return Light radius - */ - - inline float Light::GetRadius() const - { - return m_radius; - } - - /*! - * \brief Gets the shadow map - * \return Reference to the shadow map texture - */ - - inline TextureRef Light::GetShadowMap() const - { - EnsureShadowMapUpdate(); - - return m_shadowMap; - } - - /*! - * \brief Gets the format of the shadow map - * \return Shadow map format - */ - - inline PixelFormat Light::GetShadowMapFormat() const - { - return m_shadowMapFormat; - } - - /*! - * \brief Gets the size of the shadow map - * \return Shadow map size - */ - - inline const Vector2ui& Light::GetShadowMapSize() const - { - return m_shadowMapSize; - } - - /*! - * \brief Checks whether the shadow casting is enabled - * \return true If it is the case - */ - - inline bool Light::IsShadowCastingEnabled() const - { - return m_shadowCastingEnabled; - } - - /*! - * \brief Sets the ambient factor - * - * \param factor Ambient factor - */ - - inline void Light::SetAmbientFactor(float factor) - { - m_ambientFactor = factor; - } - - /*! - * \brief Sets the light attenuation (in 1 / R^2) - * - * \param attenuation Light attenuation - */ - - inline void Light::SetAttenuation(float attenuation) - { - m_attenuation = attenuation; - } - - /*! - * \brief Sets the color of the light - * - * \param color Light color - */ - - inline void Light::SetColor(const Color& color) - { - m_color = color; - } - - /*! - * \brief Sets the diffuse factor - * - * \param factor Diffuse factor - */ - - inline void Light::SetDiffuseFactor(float factor) - { - m_diffuseFactor = factor; - } - - /*! - * \brief Sets the inner angle in spot light - * - * \param innerAngle Inner angle - */ - - inline void Light::SetInnerAngle(float innerAngle) - { - m_innerAngle = innerAngle; - m_innerAngleCosine = std::cos(DegreeToRadian(m_innerAngle)); - } - - /*! - * \brief Sets the type of light - * - * \param type Light type - */ - - inline void Light::SetLightType(LightType type) - { - m_type = type; - - InvalidateShadowMap(); - } - - /*! - * \brief Sets the outer angle in spot light - * - * \param outerAngle Outer angle - * - * \remark Invalidates the bounding volume - */ - - inline void Light::SetOuterAngle(float outerAngle) - { - m_outerAngle = outerAngle; - m_outerAngleCosine = std::cos(DegreeToRadian(m_outerAngle)); - m_outerAngleTangent = std::tan(DegreeToRadian(m_outerAngle)); - - InvalidateBoundingVolume(); - } - - /*! - * \brief Sets the radius of the light - * - * \param radius Light radius - * - * \remark Invalidates the bounding volume - */ - - inline void Light::SetRadius(float radius) - { - m_radius = radius; - - m_invRadius = 1.f / m_radius; - - InvalidateBoundingVolume(); - } - - /*! - * \brief Sets the shadow map format - * - * \param shadowFormat Shadow map format - * - * \remark Invalidates the shadow map - * \remark Produces a NazaraAssert if format is not a depth type - */ - - inline void Light::SetShadowMapFormat(PixelFormat shadowFormat) - { - NazaraAssert(PixelFormatInfo::GetContent(shadowFormat) == PixelFormatContent_DepthStencil, "Shadow format type is not a depth format"); - - m_shadowMapFormat = shadowFormat; - - InvalidateShadowMap(); - } - - /*! - * \brief Sets the size of the shadow map - * - * \param size Shadow map size - * - * \remark Invalidates the shadow map - * \remark Produces a NazaraAssert if size is zero - */ - - inline void Light::SetShadowMapSize(const Vector2ui& size) - { - NazaraAssert(size.x > 0 && size.y > 0, "Shadow map size must have a positive size"); - - m_shadowMapSize = size; - - InvalidateShadowMap(); - } - - /*! - * \brief Sets the current light with the content of the other one - * \return A reference to this - * - * \param light The other Light - * - * \remark Invalidates the shadow map - */ - - inline Light& Light::operator=(const Light& light) - { - Renderable::operator=(light); - - m_ambientFactor = light.m_ambientFactor; - m_attenuation = light.m_attenuation; - m_color = light.m_color; - m_diffuseFactor = light.m_diffuseFactor; - m_innerAngle = light.m_innerAngle; - m_innerAngleCosine = light.m_innerAngleCosine; - m_invRadius = light.m_invRadius; - m_outerAngle = light.m_outerAngle; - m_outerAngleCosine = light.m_outerAngleCosine; - m_outerAngleTangent = light.m_outerAngleTangent; - m_radius = light.m_radius; - m_shadowCastingEnabled = light.m_shadowCastingEnabled; - m_shadowMapFormat = light.m_shadowMapFormat; - m_shadowMapSize = light.m_shadowMapSize; - m_type = light.m_type; - - InvalidateShadowMap(); - return *this; - } - - /*! - * \brief Invalidates the shadow map - */ - - inline void Light::InvalidateShadowMap() - { - m_shadowMapUpdated = false; - } -} - -#include diff --git a/include/Nazara/Graphics/Material.hpp b/include/Nazara/Graphics/Material.hpp deleted file mode 100644 index 03fa145b7..000000000 --- a/include/Nazara/Graphics/Material.hpp +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_MATERIAL_HPP -#define NAZARA_MATERIAL_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - struct NAZARA_GRAPHICS_API MaterialParams : ResourceParameters - { - bool loadAlphaMap = true; - bool loadDiffuseMap = true; - bool loadEmissiveMap = true; - bool loadHeightMap = true; - bool loadNormalMap = true; - bool loadSpecularMap = true; - std::string shaderName = "Basic"; - - bool IsValid() const; - }; - - class Material; - - using MaterialConstRef = ObjectRef; - using MaterialLibrary = ObjectLibrary; - using MaterialLoader = ResourceLoader; - using MaterialManager = ResourceManager; - using MaterialRef = ObjectRef; - - class NAZARA_GRAPHICS_API Material : public RefCounted, public Resource - { - friend MaterialLibrary; - friend MaterialLoader; - friend MaterialManager; - friend class Graphics; - - public: - inline Material(); - inline Material(const MaterialPipeline* pipeline); - inline Material(const MaterialPipelineInfo& pipelineInfo); - inline Material(const std::string& pipelineName); - inline Material(const Material& material); - inline ~Material(); - - void Apply(const MaterialPipeline::Instance& instance) const; - - void BuildFromParameters(const ParameterList& matData, const MaterialParams& matParams = MaterialParams()); - - inline void Configure(const MaterialPipeline* pipeline); - inline void Configure(const MaterialPipelineInfo& pipelineInfo); - inline bool Configure(const std::string& pipelineName); - - inline void EnableAlphaTest(bool alphaTest); - inline void EnableBlending(bool blending); - inline void EnableColorWrite(bool colorWrite); - inline void EnableDepthBuffer(bool depthBuffer); - inline void EnableDepthSorting(bool depthSorting); - inline void EnableDepthWrite(bool depthWrite); - inline void EnableFaceCulling(bool faceCulling); - inline void EnableReflectionMapping(bool reflection); - inline void EnableScissorTest(bool scissorTest); - inline void EnableShadowCasting(bool castShadows); - inline void EnableShadowReceive(bool receiveShadows); - inline void EnableStencilTest(bool stencilTest); - inline void EnableVertexColor(bool vertexColor); - - inline void EnsurePipelineUpdate() const; - - inline const TextureRef& GetAlphaMap() const; - inline float GetAlphaThreshold() const; - inline Color GetAmbientColor() const; - inline RendererComparison GetDepthFunc() const; - inline const MaterialRef& GetDepthMaterial() const; - inline Color GetDiffuseColor() const; - inline const TextureRef& GetDiffuseMap() const; - inline TextureSampler& GetDiffuseSampler(); - inline const TextureSampler& GetDiffuseSampler() const; - inline BlendFunc GetDstBlend() const; - inline const TextureRef& GetEmissiveMap() const; - inline FaceSide GetFaceCulling() const; - inline FaceFilling GetFaceFilling() const; - inline const TextureRef& GetHeightMap() const; - inline float GetLineWidth() const; - inline const TextureRef& GetNormalMap() const; - inline const MaterialPipeline* GetPipeline() const; - inline const MaterialPipelineInfo& GetPipelineInfo() const; - inline float GetPointSize() const; - inline ReflectionMode GetReflectionMode() const; - inline const UberShader* GetShader() const; - inline float GetShininess() const; - inline Color GetSpecularColor() const; - inline const TextureRef& GetSpecularMap() const; - inline TextureSampler& GetSpecularSampler(); - inline const TextureSampler& GetSpecularSampler() const; - inline BlendFunc GetSrcBlend() const; - - inline bool HasAlphaMap() const; - inline bool HasDepthMaterial() const; - inline bool HasDiffuseMap() const; - inline bool HasEmissiveMap() const; - inline bool HasHeightMap() const; - inline bool HasNormalMap() const; - inline bool HasSpecularMap() const; - inline bool HasVertexColor() const; - - inline bool IsAlphaTestEnabled() const; - inline bool IsBlendingEnabled() const; - inline bool IsColorWriteEnabled() const; - inline bool IsDepthBufferEnabled() const; - inline bool IsDepthSortingEnabled() const; - inline bool IsDepthWriteEnabled() const; - inline bool IsFaceCullingEnabled() const; - inline bool IsReflectionMappingEnabled() const; - inline bool IsScissorTestEnabled() const; - inline bool IsStencilTestEnabled() const; - inline bool IsShadowCastingEnabled() const; - inline bool IsShadowReceiveEnabled() const; - - void Reset(); - - void SaveToParameters(ParameterList* matData); - - inline bool SetAlphaMap(const std::string& textureName); - inline void SetAlphaMap(TextureRef alphaMap); - inline void SetAlphaThreshold(float alphaThreshold); - inline void SetAmbientColor(const Color& ambient); - inline void SetDepthFunc(RendererComparison depthFunc); - inline void SetDepthMaterial(MaterialRef depthMaterial); - inline void SetDiffuseColor(const Color& diffuse); - inline bool SetDiffuseMap(const std::string& textureName); - inline void SetDiffuseMap(TextureRef diffuseMap); - inline void SetDiffuseSampler(const TextureSampler& sampler); - inline void SetDstBlend(BlendFunc func); - inline bool SetEmissiveMap(const std::string& textureName); - inline void SetEmissiveMap(TextureRef textureName); - inline void SetFaceCulling(FaceSide faceSide); - inline void SetFaceFilling(FaceFilling filling); - inline bool SetHeightMap(const std::string& textureName); - inline void SetHeightMap(TextureRef textureName); - inline void SetLineWidth(float lineWidth); - inline bool SetNormalMap(const std::string& textureName); - inline void SetNormalMap(TextureRef textureName); - inline void SetPointSize(float pointSize); - inline void SetReflectionMode(ReflectionMode reflectionMode); - inline void SetShader(UberShaderConstRef uberShader); - inline bool SetShader(const std::string& uberShaderName); - inline void SetShininess(float shininess); - inline void SetSpecularColor(const Color& specular); - inline bool SetSpecularMap(const std::string& textureName); - inline void SetSpecularMap(TextureRef specularMap); - inline void SetSpecularSampler(const TextureSampler& sampler); - inline void SetSrcBlend(BlendFunc func); - - inline Material& operator=(const Material& material); - - inline static MaterialRef GetDefault(); - inline static int GetTextureUnit(TextureMap textureMap); - - static inline MaterialRef LoadFromFile(const std::filesystem::path& filePath, const MaterialParams& params = MaterialParams()); - static inline MaterialRef LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams()); - static inline MaterialRef LoadFromStream(Stream& stream, const MaterialParams& params = MaterialParams()); - - template static MaterialRef New(Args&&... args); - - // Signals: - NazaraSignal(OnMaterialReflectionModeChange, const Material* /*material*/, ReflectionMode /*newReflectionMode*/); - NazaraSignal(OnMaterialRelease, const Material* /*material*/); - NazaraSignal(OnMaterialReset, const Material* /*material*/); - - private: - void Copy(const Material& material); - inline void InvalidatePipeline(); - inline void UpdatePipeline() const; - - static bool Initialize(); - static void Uninitialize(); - - Color m_ambientColor; - Color m_diffuseColor; - Color m_specularColor; - MaterialRef m_depthMaterial; //< Materialception - mutable const MaterialPipeline* m_pipeline; - MaterialPipelineInfo m_pipelineInfo; - ReflectionMode m_reflectionMode; - TextureSampler m_diffuseSampler; - TextureSampler m_specularSampler; - TextureRef m_alphaMap; - TextureRef m_diffuseMap; - TextureRef m_emissiveMap; - TextureRef m_heightMap; - TextureRef m_normalMap; - TextureRef m_specularMap; - mutable bool m_pipelineUpdated; - bool m_shadowCastingEnabled; - float m_alphaThreshold; - float m_shininess; - unsigned int m_reflectionSize; - - static std::array s_textureUnits; - static MaterialLibrary::LibraryMap s_library; - static MaterialLoader::LoaderList s_loaders; - static MaterialManager::ManagerMap s_managerMap; - static MaterialManager::ManagerParams s_managerParameters; - static MaterialRef s_defaultMaterial; - }; -} - -#include - -#endif // NAZARA_MATERIAL_HPP diff --git a/include/Nazara/Graphics/Material.inl b/include/Nazara/Graphics/Material.inl deleted file mode 100644 index e56d1675c..000000000 --- a/include/Nazara/Graphics/Material.inl +++ /dev/null @@ -1,1504 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \brief Constructs a Material object with default states - * - * \see Reset - */ - inline Material::Material() - { - Reset(); - } - - /*! - * \brief Constructs a Material object using a MaterialPipeline - * - * Calls Configure with the pipeline parameter - * - * \see Configure - */ - inline Material::Material(const MaterialPipeline* pipeline) - { - ErrorFlags errFlags(ErrorFlag_ThrowException, true); - - Reset(); - Configure(pipeline); - } - - /*! - * \brief Constructs a Material object using a MaterialPipelineInfo - * - * Calls Configure with the pipelineInfo parameter - * - * \see Configure - */ - inline Material::Material(const MaterialPipelineInfo& pipelineInfo) - { - ErrorFlags errFlags(ErrorFlag_ThrowException, true); - - Reset(); - Configure(pipelineInfo); - } - - /*! - * \brief Constructs a Material object using a MaterialPipeline name - * - * Calls Configure with the pipelineName parameter - * - * \remark In case of error (ie. named pipeline is not registered), throw an exception - * - * \see Configure - */ - inline Material::Material(const std::string& pipelineName) - { - ErrorFlags errFlags(ErrorFlag_ThrowException, true); - - Reset(); - Configure(pipelineName); - } - - /*! - * \brief Constructs a Material object by assignation - * - * \param material Material to copy into this - */ - inline Material::Material(const Material& material) : - RefCounted(), - Resource(material), - m_reflectionMode(ReflectionMode_Skybox) - { - Copy(material); - } - - /*! - * \brief Destructs the object and calls OnMaterialRelease - * - * \see OnMaterialRelease - */ - inline Material::~Material() - { - OnMaterialRelease(this); - } - - /*! - * \brief Reset material pipeline state - * - * Sets the material pipeline - * - * \remark pipeline must be valid - * - * \see Configure - */ - inline void Material::Configure(const MaterialPipeline* pipeline) - { - NazaraAssert(pipeline, "Invalid material pipeline"); - - m_pipeline = pipeline; - m_pipelineInfo = m_pipeline->GetInfo(); - m_pipelineUpdated = true; - } - - /*! - * \brief Reset material pipeline state - * - * Sets the material pipeline using pipeline info - * - * \remark pipeline must be valid - * - * \see Configure - */ - inline void Material::Configure(const MaterialPipelineInfo& pipelineInfo) - { - m_pipelineInfo = pipelineInfo; - - // Temp and dirty fix for pipeline overriding has*Map - m_pipelineInfo.hasAlphaMap = m_alphaMap.IsValid(); - m_pipelineInfo.hasDiffuseMap = m_diffuseMap.IsValid(); - m_pipelineInfo.hasEmissiveMap = m_emissiveMap.IsValid(); - m_pipelineInfo.hasHeightMap = m_heightMap.IsValid(); - m_pipelineInfo.hasNormalMap = m_normalMap.IsValid(); - m_pipelineInfo.hasSpecularMap = m_specularMap.IsValid(); - - InvalidatePipeline(); - } - - /*! - * \brief Reset material pipeline state - * - * Sets the material pipeline using a name to lookup in the MaterialPipelineLibrary - * - * \return True if the material pipeline was found in the library - * - * \see Configure - */ - inline bool Material::Configure(const std::string& pipelineName) - { - MaterialPipelineRef pipeline = MaterialPipelineLibrary::Query(pipelineName); - if (!pipeline) - { - NazaraError("Failed to get pipeline \"" + pipelineName + "\""); - return false; - } - - Configure(std::move(pipeline)); - return true; - } - - /*! - * \brief Enable/Disable alpha test for this material - * - * When enabled, all objects using this material will be rendered using alpha testing, - * rejecting pixels if their alpha component is under a defined threshold. - * This allows some kind of transparency with a much cheaper cost as it doesn't prevent any optimization (as deferred rendering or batching). - * - * \param alphaTest Defines if this material will use alpha testing - * - * \remark Invalidates the pipeline - * - * \see IsAlphaTestEnabled - * \see SetAlphaThreshold - */ - inline void Material::EnableAlphaTest(bool alphaTest) - { - m_pipelineInfo.alphaTest = alphaTest; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable blending for this material - * - * When enabled, all objects using this material will be rendered using blending, obeying the dstBlend and srcBlend parameters - * This is useful with translucent objects, but will reduces performance as it prevents some optimizations (as deferred rendering) - * - * \param blending Defines if this material will use blending - * - * \remark Invalidates the pipeline - * - * \see IsBlendingEnabled - * \see SetDstBlend - * \see SetSrcBlend - */ - inline void Material::EnableBlending(bool blending) - { - m_pipelineInfo.blending = blending; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable color writing for this material - * - * \param colorWrite Defines if this material will use color writing - * - * \remark Invalidates the pipeline - * - * \see IsColorWritingEnabled - */ - inline void Material::EnableColorWrite(bool colorWrite) - { - m_pipelineInfo.colorWrite = colorWrite; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable depth buffer for this material - * - * When enabled, all objects using this material will be rendered using a depth buffer, if the RenderTarget has one. - * This will enable Depth Test, preventing further fragments to render on top of closer ones. - * - * This parameter is required for depth writing. - * - * In order to enable depth writing without enabling depth test, set the depth comparison function to RendererComparison_Never - * - * \param depthBuffer Defines if this material will use depth buffer - * - * \remark Invalidates the pipeline - * - * \see EnableDepthWrite - * \see IsDepthBufferEnabled - * \see SetDepthFunc - */ - inline void Material::EnableDepthBuffer(bool depthBuffer) - { - m_pipelineInfo.depthBuffer = depthBuffer; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable depth sorting for this material - * - * When enabled, all objects using this material will be rendered far from near - * This is useful with translucent objects, but will reduces performance as it breaks batching - * - * \param depthSorting Defines if this material will use depth sorting - * - * \remark Depth sorting may not be perfect (may be object-sorting instead of triangle-sorting) - * \remark Invalidates the pipeline - * - * \see IsDepthSortingEnabled - */ - inline void Material::EnableDepthSorting(bool depthSorting) - { - m_pipelineInfo.depthSorting = depthSorting; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable depth writing for this material - * - * When enabled, and if depth buffer is enabled and present, all fragments generated with this material will write - * to the depth buffer if they pass depth test. - * - * This is usually disabled with translucent objects, as depth test is wanted to prevent them from rendering on top of opaque objects but - * not depth writing (which could make other translucent fragments to fail depth test) - * - * \param depthBuffer Defines if this material will use depth write - * - * \remark Invalidates the pipeline - * - * \see EnableDepthBuffer - * \see IsDepthWriteEnabled - */ - inline void Material::EnableDepthWrite(bool depthWrite) - { - m_pipelineInfo.depthWrite = depthWrite; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable face culling for this material - * - * When enabled, the material prevents front and/or back faces from rendering. - * This is commonly used as an optimization to prevent processing of hidden faces by the rendering device. - * - * Use SetFaceCulling to control which side will be eliminated. - * - * \param faceCulling Defines if this material will use face culling - * - * \remark Invalidates the pipeline - * - * \see IsFaceCullingEnabled - * \see SetFaceCulling - */ - inline void Material::EnableFaceCulling(bool faceCulling) - { - m_pipelineInfo.faceCulling = faceCulling; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable reflection mapping for this material - * - * When enabled, the material will render reflections from the object environment according to the reflection mode. - * Whether or not this is expensive depends of the reflection mode and size. - * - * Please note this is only a hint for the render technique, and reflections can be forcefully enabled or disabled depending on the material shader. - * - * Use SetReflectionMode and SetReflectionSize to control reflection quality. - * - * \param reflection Defines if this material should use reflection mapping - * - * \remark May invalidates the pipeline - * - * \see IsReflectionMappingEnabled - * \see SetReflectionMode - * \see SetReflectionSize - */ - inline void Material::EnableReflectionMapping(bool reflection) - { - m_pipelineInfo.reflectionMapping = reflection; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable scissor test for this material - * - * When enabled, the material prevents fragments out of the scissor box to be rendered. - * This can be useful with GUI, where widgets must not be rendered outside of their parent rendering area. - * - * \param scissorTest Defines if this material will use scissor test - * - * \remark Invalidates the pipeline - * - * \see IsScissorTestEnabled - */ - inline void Material::EnableScissorTest(bool scissorTest) - { - m_pipelineInfo.scissorTest = scissorTest; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable shadow casting for this material - * - * When enabled, all objects using this material will be allowed to cast shadows upon any objects using a material with shadow receiving enabled. - * The depth material replaces this one when rendering shadows. - * - * \param castShadows Defines if this material will be allowed to cast shadows - * - * \remark Does not invalidate the pipeline - * - * \see EnableShadowReceive - * \see IsShadowCastingEnabled - * \see SetDepthMaterial - */ - inline void Material::EnableShadowCasting(bool castShadows) - { - // Has no influence on pipeline - m_shadowCastingEnabled = castShadows; - } - - /*! - * \brief Enable/Disable shadow receiving for this material - * - * When enabled, all objects using this material will be allowed to be casted shadows upon themselves - * Disabling this can be helpful to prevent some rendering artifacts (especially with translucent objects) - * - * \param receiveShadows Defines if this material will be able to receive shadows - * - * \remark Invalidates the pipeline - * - * \see IsShadowReceiveEnabled - */ - inline void Material::EnableShadowReceive(bool receiveShadows) - { - m_pipelineInfo.shadowReceive = receiveShadows; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable stencil test for this material - * - * When enabled, all fragments must pass the stencil test to be rendered. - * - * \param scissorTest Defines if this material will use stencil test - * - * \remark Invalidates the pipeline - * - * \see IsStencilTestEnabled - */ - inline void Material::EnableStencilTest(bool stencilTest) - { - m_pipelineInfo.stencilTest = stencilTest; - - InvalidatePipeline(); - } - - /*! - * \brief Enable/Disable vertex coloring on this material - * - * This is a temporary option, until the new material pipeline system is ready, allowing to enable vertex coloring. - * This option only works with meshes using vertex colors. - * - * \param vertexColor Defines if this material will use vertex color or not - * - * \remark Invalidates the pipeline - * - * \see HasVertexColor - */ - inline void Material::EnableVertexColor(bool vertexColor) - { - m_pipelineInfo.hasVertexColor = vertexColor; - - InvalidatePipeline(); - } - - /*! - * \brief Ensures the pipeline gets updated - * - * When the pipeline gets invalidated, it's not updated until required (per example by calling GetPipeline). - * Using this function forces the pipeline update, making GetPipeline thread-safe as long as the pipeline does not get invalidated. - * - * \see GetPipeline - */ - inline void Material::EnsurePipelineUpdate() const - { - if (!m_pipelineUpdated) - UpdatePipeline(); - } - - /*! - * \brief Gets the alpha map - * - * \return Constant reference to the current texture - * - * \see SetAlphaMap - */ - inline const TextureRef& Material::GetAlphaMap() const - { - return m_alphaMap; - } - - /*! - * \brief Gets the alpha test threshold - * - * \return The threshold value for the alpha test - * - * \see EnableAlphaTest - * \see SetAlphaThreshold - */ - inline float Material::GetAlphaThreshold() const - { - return m_alphaThreshold; - } - - /*! - * \brief Gets the ambient color - * - * \return Ambient color - * - * \see SetAmbientColor - */ - inline Color Material::GetAmbientColor() const - { - return m_ambientColor; - } - - /*! - * \brief Gets the function to compare depth - * - * \return Function comparing the depth of two materials - * - * \see EnableDepthTest - * \see SetAmbientColor - */ - inline RendererComparison Material::GetDepthFunc() const - { - return m_pipelineInfo.depthFunc; - } - - /*! - * \brief Gets the depth material - * - * \return Constant reference to the depth material - * - * \see EnableShadowCasting - */ - inline const MaterialRef& Material::GetDepthMaterial() const - { - return m_depthMaterial; - } - - /*! - * \brief Gets the diffuse color - * - * \return Diffuse color - * - * \see SetDiffuseColor - */ - inline Color Material::GetDiffuseColor() const - { - return m_diffuseColor; - } - - /*! - * \brief Gets the diffuse sampler - * - * \return Reference to the current texture sampler for the diffuse - * - * \see SetDiffuseSampler - */ - inline TextureSampler& Material::GetDiffuseSampler() - { - return m_diffuseSampler; - } - - /*! - * \brief Gets the diffuse sampler - * - * \return Constant reference to the current texture sampler for the diffuse - * - * \see SetDiffuseSampler - */ - inline const TextureSampler& Material::GetDiffuseSampler() const - { - return m_diffuseSampler; - } - - /*! - * \brief Gets the diffuse map - * - * \return Constant reference to the texture - * - * \see SetDiffuseMap - */ - const TextureRef& Material::GetDiffuseMap() const - { - return m_diffuseMap; - } - - /*! - * \brief Gets the dst in blend - * - * \return Function for dst blending - * - * \see SetDstBlend - */ - inline BlendFunc Material::GetDstBlend() const - { - return m_pipelineInfo.dstBlend; - } - - /*! - * \brief Gets the emissive map - * - * \return Constant reference to the texture - * - * \see SetEmissiveMap - */ - inline const TextureRef& Material::GetEmissiveMap() const - { - return m_emissiveMap; - } - - /*! - * \brief Gets the face culling - * - * \return Current face culling side - * - * \see SetFaceCulling - */ - inline FaceSide Material::GetFaceCulling() const - { - return m_pipelineInfo.cullingSide; - } - - /*! - * \brief Gets the face filling - * \return Current face filling - */ - inline FaceFilling Material::GetFaceFilling() const - { - return m_pipelineInfo.faceFilling; - } - - /*! - * \brief Gets the height map - * \return Constant reference to the texture - */ - inline const TextureRef& Material::GetHeightMap() const - { - return m_heightMap; - } - - /*! - * \brief Gets the line width of this material - * \return Line width - */ - inline float Material::GetLineWidth() const - { - return m_pipelineInfo.lineWidth; - } - - /*! - * \brief Gets the normal map - * \return Constant reference to the texture - */ - - inline const TextureRef& Material::GetNormalMap() const - { - return m_normalMap; - } - - /*! - * \brief Gets the render states - * \return Constant reference to the render states - */ - inline const MaterialPipeline* Material::GetPipeline() const - { - EnsurePipelineUpdate(); - - return m_pipeline; - } - - /*! - * \brief Gets the pipeline informations - * \return Constant reference to the pipeline info - */ - inline const MaterialPipelineInfo& Material::GetPipelineInfo() const - { - return m_pipelineInfo; - } - - /*! - * \brief Gets the point size of this material - * \return Point size - */ - inline float Material::GetPointSize() const - { - return m_pipelineInfo.pointSize; - } - - /*! - * \brief Gets the reflection mode of the material - * - * \return Current reflection mode - * - * \see SetReflectionMode - */ - inline ReflectionMode Material::GetReflectionMode() const - { - return m_reflectionMode; - } - - /*! - * \brief Gets the über-shader used by this material - * \return Constant pointer to the über-shader used - */ - inline const UberShader* Material::GetShader() const - { - return m_pipelineInfo.uberShader; - } - - /*! - * \brief Gets the shininess - * \return Current shininess - */ - inline float Material::GetShininess() const - { - return m_shininess; - } - - /*! - * \brief Gets the specular color - * \return Specular color - */ - inline Color Material::GetSpecularColor() const - { - return m_specularColor; - } - - /*! - * \brief Gets the specular map - * \return Constant reference to the texture - */ - inline const TextureRef& Material::GetSpecularMap() const - { - return m_specularMap; - } - - /*! - * \brief Gets the specular sampler - * \return Reference to the current texture sampler for the specular - */ - inline TextureSampler& Material::GetSpecularSampler() - { - return m_specularSampler; - } - - /*! - * \brief Gets the specular sampler - * \return Constant reference to the current texture sampler for the specular - */ - inline const TextureSampler& Material::GetSpecularSampler() const - { - return m_specularSampler; - } - - /*! - * \brief Gets the src in blend - * \return Function for src blending - */ - inline BlendFunc Material::GetSrcBlend() const - { - return m_pipelineInfo.srcBlend; - } - - /*! - * \brief Checks whether this material has an alpha map - * \return true If it is the case - */ - inline bool Material::HasAlphaMap() const - { - return m_alphaMap.IsValid(); - } - - /*! - * \brief Checks whether this material has a depth material - * \return true If it is the case - */ - inline bool Material::HasDepthMaterial() const - { - return m_depthMaterial.IsValid(); - } - - /*! - * \brief Checks whether this material has a diffuse map - * \return true If it is the case - */ - inline bool Material::HasDiffuseMap() const - { - return m_diffuseMap.IsValid(); - } - - /*! - * \brief Checks whether this material has a emissive map - * \return true If it is the case - */ - inline bool Material::HasEmissiveMap() const - { - return m_emissiveMap.IsValid(); - } - - /*! - * \brief Checks whether this material has a height map - * \return true If it is the case - */ - inline bool Material::HasHeightMap() const - { - return m_heightMap.IsValid(); - } - - /*! - * \brief Checks whether this material has a normal map - * \return true If it is the case - */ - inline bool Material::HasNormalMap() const - { - return m_normalMap.IsValid(); - } - - /*! - * \brief Checks whether this material has a specular map - * \return true If it is the case - */ - inline bool Material::HasSpecularMap() const - { - return m_specularMap.IsValid(); - } - - /*! - * \brief Checks whether this material uses vertex coloring - * \return true If it is the case - */ - inline bool Material::HasVertexColor() const - { - return m_pipelineInfo.hasVertexColor; - } - - /*! - * \brief Checks whether this material has alpha test enabled - * \return true If it is the case - */ - inline bool Material::IsAlphaTestEnabled() const - { - return m_pipelineInfo.alphaTest; - } - - /*! - * \brief Checks whether this material has blending enabled - * \return true If it is the case - */ - inline bool Material::IsBlendingEnabled() const - { - return m_pipelineInfo.blending; - } - - /*! - * \brief Checks whether this material has color write enabled - * \return true If it is the case - */ - inline bool Material::IsColorWriteEnabled() const - { - return m_pipelineInfo.colorWrite; - } - - /*! - * \brief Checks whether this material has depth buffer enabled - * \return true If it is the case - */ - inline bool Material::IsDepthBufferEnabled() const - { - return m_pipelineInfo.depthBuffer; - } - - /*! - * \brief Checks whether this material has depth sorting enabled - * \return true If it is the case - */ - inline bool Material::IsDepthSortingEnabled() const - { - return m_pipelineInfo.depthSorting; - } - - /*! - * \brief Checks whether this material has depth writing enabled - * \return true If it is the case - */ - inline bool Material::IsDepthWriteEnabled() const - { - return m_pipelineInfo.depthWrite; - } - - /*! - * \brief Checks whether this material has face culling enabled - * \return true If it is the case - */ - inline bool Material::IsFaceCullingEnabled() const - { - return m_pipelineInfo.faceCulling; - } - - /*! - * \brief Checks whether this material has reflection mapping enabled - * \return true If it is the case - * - * \see EnableReflectionMapping - */ - inline bool Material::IsReflectionMappingEnabled() const - { - return m_pipelineInfo.reflectionMapping; - } - - /*! - * \brief Checks whether this material has scissor test enabled - * \return true If it is the case - */ - inline bool Material::IsScissorTestEnabled() const - { - return m_pipelineInfo.scissorTest; - } - - /*! - * \brief Checks whether this material has stencil test enabled - * \return true If it is the case - */ - inline bool Material::IsStencilTestEnabled() const - { - return m_pipelineInfo.stencilTest; - } - - /*! - * \brief Checks whether this material cast shadow - * \return true If it is the case - */ - inline bool Material::IsShadowCastingEnabled() const - { - return m_shadowCastingEnabled; - } - - /*! - * \brief Checks whether this material receive shadow - * \return true If it is the case - */ - inline bool Material::IsShadowReceiveEnabled() const - { - return m_pipelineInfo.shadowReceive; - } - - /*! - * \brief Sets the alpha map by name - * \return true If successful - * - * \param textureName Named texture - */ - inline bool Material::SetAlphaMap(const std::string& textureName) - { - TextureRef texture = TextureLibrary::Query(textureName); - if (!texture) - { - texture = TextureManager::Get(textureName); - if (!texture) - { - NazaraError("Failed to get alpha map \"" + textureName + "\""); - return false; - } - } - - SetAlphaMap(std::move(texture)); - return true; - } - - /*! - * \brief Sets the alpha map with a reference to a texture - * \return true If successful - * - * \param alphaMap Texture - * - * \remark Invalidates the pipeline - */ - inline void Material::SetAlphaMap(TextureRef alphaMap) - { - m_alphaMap = std::move(alphaMap); - m_pipelineInfo.hasAlphaMap = m_alphaMap.IsValid(); - - InvalidatePipeline(); - } - - /*! - * \brief Sets the alpha threshold - * - * \param alphaThreshold Threshold for the alpha - */ - inline void Material::SetAlphaThreshold(float alphaThreshold) - { - m_alphaThreshold = alphaThreshold; - } - - /*! - * \brief Sets the color for ambient - * - * \param ambient Color for ambient - */ - inline void Material::SetAmbientColor(const Color& ambient) - { - m_ambientColor = ambient; - } - - /*! - * \brief Sets the depth functor - * - * \param depthFunc - * - * \remark Invalidates the pipeline - */ - inline void Material::SetDepthFunc(RendererComparison depthFunc) - { - m_pipelineInfo.depthFunc = depthFunc; - - InvalidatePipeline(); - } - - /*! - * \brief Sets the depth material - * \return true If successful - * - * \param depthMaterial Material for depth - */ - inline void Material::SetDepthMaterial(MaterialRef depthMaterial) - { - m_depthMaterial = std::move(depthMaterial); - } - - /*! - * \brief Sets the color for diffuse - * - * \param diffuse Color for diffuse - */ - inline void Material::SetDiffuseColor(const Color& diffuse) - { - m_diffuseColor = diffuse; - } - - /*! - * \brief Sets the diffuse map by name - * \return true If successful - * - * \param textureName Named texture - * - * \remark Invalidates the pipeline - */ - inline bool Material::SetDiffuseMap(const std::string& textureName) - { - TextureRef texture = TextureLibrary::Query(textureName); - if (!texture) - { - texture = TextureManager::Get(textureName); - if (!texture) - { - NazaraError("Failed to get diffuse map \"" + textureName + "\""); - return false; - } - } - - SetDiffuseMap(std::move(texture)); - return true; - } - - /*! - * \brief Sets the diffuse map with a reference to a texture - * \return true If successful - * - * \param diffuseMap Texture - * - * \remark Invalidates the pipeline - */ - inline void Material::SetDiffuseMap(TextureRef diffuseMap) - { - m_diffuseMap = std::move(diffuseMap); - m_pipelineInfo.hasDiffuseMap = m_diffuseMap.IsValid(); - - InvalidatePipeline(); - } - - /*! - * \brief Sets the diffuse sampler - * - * \param sampler Diffuse sample - */ - - inline void Material::SetDiffuseSampler(const TextureSampler& sampler) - { - m_diffuseSampler = sampler; - } - - /*! - * \brief Sets the dst in blend - * - * \param func Function for dst blending - * - * \remark Invalidates the pipeline - */ - inline void Material::SetDstBlend(BlendFunc func) - { - m_pipelineInfo.dstBlend = func; - - InvalidatePipeline(); - } - - /*! - * \brief Sets the emissive map by name - * \return true If successful - * - * \param textureName Named texture - * - * \see GetEmissiveMap - */ - inline bool Material::SetEmissiveMap(const std::string& textureName) - { - TextureRef texture = TextureLibrary::Query(textureName); - if (!texture) - { - texture = TextureManager::Get(textureName); - if (!texture) - { - NazaraError("Failed to get emissive map \"" + textureName + "\""); - return false; - } - } - - SetEmissiveMap(std::move(texture)); - return true; - } - - /*! - * \brief Sets the emissive map with a reference to a texture - * \return true If successful - * - * \param emissiveMap Texture - * - * \remark Invalidates the pipeline - */ - inline void Material::SetEmissiveMap(TextureRef emissiveMap) - { - m_emissiveMap = std::move(emissiveMap); - m_pipelineInfo.hasEmissiveMap = m_emissiveMap.IsValid(); - - InvalidatePipeline(); - } - - /*! - * \brief Sets the face culling - * - * \param faceSide Face to cull - * - * \remark Invalidates the pipeline - */ - inline void Material::SetFaceCulling(FaceSide faceSide) - { - m_pipelineInfo.cullingSide = faceSide; - - InvalidatePipeline(); - } - - /*! - * \brief Sets the face filling - * - * \param filling Face to fill - * - * \remark Invalidates the pipeline - */ - inline void Material::SetFaceFilling(FaceFilling filling) - { - m_pipelineInfo.faceFilling = filling; - - InvalidatePipeline(); - } - - /*! - * \brief Sets the height map by path or name - * \return true If successful - * - * \param textureName Named texture - * - * \see GetHeightMap - */ - inline bool Material::SetHeightMap(const std::string& textureName) - { - TextureRef texture = TextureLibrary::Query(textureName); - if (!texture) - { - texture = TextureManager::Get(textureName); - if (!texture) - { - NazaraError("Failed to get height map \"" + textureName + "\""); - return false; - } - } - - SetHeightMap(std::move(texture)); - return true; - } - - /*! - * \brief Sets the height map with a reference to a texture - * - * \param heightMap Texture - * - * \remark Invalidates the pipeline - * - * \see GetHeightMap - */ - inline void Material::SetHeightMap(TextureRef heightMap) - { - m_heightMap = std::move(heightMap); - m_pipelineInfo.hasHeightMap = m_heightMap.IsValid(); - - InvalidatePipeline(); - } - - /*! - * \brief Sets the line width for this material - * - * This parameter is used when rendering lines, to define the width (in pixels) the line will take on the framebuffer - * - * \param lineWidth Width of the line - * - * \remark Invalidates the pipeline - * - * \see GetLineWidth - */ - inline void Material::SetLineWidth(float lineWidth) - { - m_pipelineInfo.lineWidth = lineWidth; - - InvalidatePipeline(); - } - - /*! - * \brief Sets the normal map by path or name - * \return true If successful - * - * \param textureName Named texture - * - * \remark Invalidates the pipeline - * - * \see GetNormalMap - */ - inline bool Material::SetNormalMap(const std::string& textureName) - { - TextureRef texture = TextureLibrary::Query(textureName); - if (!texture) - { - texture = TextureManager::Get(textureName); - if (!texture) - { - NazaraError("Failed to get normal map \"" + textureName + "\""); - return false; - } - } - - SetNormalMap(std::move(texture)); - return true; - } - - /*! - * \brief Sets the normal map with a reference to a texture - * \return true If successful - * - * \param normalMap Texture - * - * \remark Invalidates the pipeline - * - * \see GetNormalMap - */ - inline void Material::SetNormalMap(TextureRef normalMap) - { - m_normalMap = std::move(normalMap); - m_pipelineInfo.hasNormalMap = m_normalMap.IsValid(); - - InvalidatePipeline(); - } - - /*! - * \brief Sets the point size for this material - * - * This parameter is used when rendering points, to define the size (in pixels) the point will take on the framebuffer - * - * \param pointSize Size of the point - * - * \remark Invalidates the pipeline - * - * \see GetPointSize - */ - inline void Material::SetPointSize(float pointSize) - { - m_pipelineInfo.pointSize = pointSize; - - InvalidatePipeline(); - } - - /*! - * \brief Changes reflection mode of the material - * - * When reflections are enabled, the material will render reflections from the object environment according to the reflection mode. - * This function does change the reflection mode used by the material. - * - * Skyboxes reflections are the cheapest but are static and thus can't reflect other objects. - * Probes reflections are cheap, depending on probes reflection mode, but require regular probe finding from objects using it. - * Real-time reflections are expensive but provide the most accurate reflection map (and can reflect other objects around). - * - * \param reflectionMode The new reflection mode this material should use - * - * \remark May invalidates the pipeline - * - * \see EnableReflectionMapping - * \see IsReflectionMappingEnabled - * \see SetReflectionSize - */ - inline void Material::SetReflectionMode(ReflectionMode reflectionMode) - { - if (m_reflectionMode != reflectionMode) - { - OnMaterialReflectionModeChange(this, reflectionMode); - - m_reflectionMode = reflectionMode; - } - } - - /*! - * \brief Sets the shader with a constant reference to a ubershader - * - * \param uberShader Uber shader to apply - * - * \remark Invalidates the pipeline - * - * \see GetShader - */ - inline void Material::SetShader(UberShaderConstRef uberShader) - { - m_pipelineInfo.uberShader = std::move(uberShader); - - InvalidatePipeline(); - } - - /*! - * \brief Sets the shader by name - * \return true If successful - * - * \param uberShaderName Named shader - */ - inline bool Material::SetShader(const std::string& uberShaderName) - { - UberShaderConstRef uberShader = UberShaderLibrary::Get(uberShaderName); - if (!uberShader) - return false; - - SetShader(std::move(uberShader)); - return true; - } - - /*! - * \brief Sets the shininess of the material - * - * \param shininess Value of the shininess - */ - inline void Material::SetShininess(float shininess) - { - m_shininess = shininess; - } - - /*! - * \brief Sets the color for specular - * - * \param specular Color - */ - inline void Material::SetSpecularColor(const Color& specular) - { - m_specularColor = specular; - } - - /*! - * \brief Sets the specular map by name - * \return true If successful - * - * \param textureName Named texture - * - * \remark Invalidates the pipeline - */ - inline bool Material::SetSpecularMap(const std::string& textureName) - { - TextureRef texture = TextureLibrary::Query(textureName); - if (!texture) - { - texture = TextureManager::Get(textureName); - if (!texture) - { - NazaraError("Failed to get specular map \"" + textureName + "\""); - return false; - } - } - - SetSpecularMap(std::move(texture)); - return true; - } - - /*! - * \brief Sets the specular map with a reference to a texture - * \return true If successful - * - * \param specularMap Texture - * - * \remark Invalidates the pipeline - * - * \see GetSpecularMap - */ - inline void Material::SetSpecularMap(TextureRef specularMap) - { - m_specularMap = std::move(specularMap); - m_pipelineInfo.hasSpecularMap = m_specularMap.IsValid(); - - InvalidatePipeline(); - } - - /*! - * \brief Sets the specular sampler - * - * \param sampler Specular sample - * - * \see GetSpecularSampler - */ - inline void Material::SetSpecularSampler(const TextureSampler& sampler) - { - m_specularSampler = sampler; - } - - /*! - * \brief Sets the src in blend - * - * \param func Function for src blending - * - * \remark Invalidates the pipeline - * - * \see GetSrcBlend - */ - inline void Material::SetSrcBlend(BlendFunc func) - { - m_pipelineInfo.srcBlend = func; - - InvalidatePipeline(); - } - - /*! - * \brief Sets the current material with the content of the other one - * \return A reference to this - * - * \param material The other Material - */ - inline Material& Material::operator=(const Material& material) - { - Resource::operator=(material); - - Copy(material); - return *this; - } - - /*! - * \brief Gets the default material - * - * \return Reference to the default material - * - * \remark This material should NOT be modified as it would affect all objects using it - */ - inline MaterialRef Material::GetDefault() - { - return s_defaultMaterial; - } - - inline int Material::GetTextureUnit(TextureMap textureMap) - { - return s_textureUnits[textureMap]; - } - - /*! - * \brief Loads the material from file - * \return true if loading is successful - * - * \param filePath Path to the file - * \param params Parameters for the material - */ - inline MaterialRef Material::LoadFromFile(const std::filesystem::path& filePath, const MaterialParams& params) - { - return MaterialLoader::LoadFromFile(filePath, params); - } - - /*! - * \brief Loads the material from memory - * \return true if loading is successful - * - * \param data Raw memory - * \param size Size of the memory - * \param params Parameters for the material - */ - inline MaterialRef Material::LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params) - { - return MaterialLoader::LoadFromMemory(data, size, params); - } - - /*! - * \brief Loads the material from stream - * \return true if loading is successful - * - * \param stream Stream to the material - * \param params Parameters for the material - */ - inline MaterialRef Material::LoadFromStream(Stream& stream, const MaterialParams& params) - { - return MaterialLoader::LoadFromStream(stream, params); - } - - inline void Material::InvalidatePipeline() - { - m_pipelineUpdated = false; - } - - inline void Material::UpdatePipeline() const - { - m_pipeline = MaterialPipeline::GetPipeline(m_pipelineInfo); - m_pipelineUpdated = true; - } - - /*! - * \brief Creates a new material from the arguments - * \return A reference to the newly created material - * - * \param args Arguments for the material - */ - template - MaterialRef Material::New(Args&&... args) - { - std::unique_ptr object(new Material(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/MaterialPipeline.hpp b/include/Nazara/Graphics/MaterialPipeline.hpp deleted file mode 100644 index 1f6575719..000000000 --- a/include/Nazara/Graphics/MaterialPipeline.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_MATERIALPIPELINE_HPP -#define NAZARA_MATERIALPIPELINE_HPP - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - struct MaterialPipelineInfo : RenderStates - { - bool alphaTest = false; - bool depthSorting = false; - bool hasAlphaMap = false; - bool hasDiffuseMap = false; - bool hasEmissiveMap = false; - bool hasHeightMap = false; - bool hasNormalMap = false; - bool hasSpecularMap = false; - bool hasVertexColor = false; - bool reflectionMapping = false; - bool shadowReceive = true; - - UberShaderConstRef uberShader; - }; - - inline bool operator==(const MaterialPipelineInfo& lhs, const MaterialPipelineInfo& rhs); - inline bool operator!=(const MaterialPipelineInfo& lhs, const MaterialPipelineInfo& rhs); - - class MaterialPipeline; - - using MaterialPipelineConstRef = ObjectRef; - using MaterialPipelineLibrary = ObjectLibrary; - using MaterialPipelineRef = ObjectRef; - - class NAZARA_GRAPHICS_API MaterialPipeline : public RefCounted - { - friend class Graphics; - friend MaterialPipelineLibrary; - - public: - struct Instance; - - MaterialPipeline(const MaterialPipeline&) = delete; - MaterialPipeline(MaterialPipeline&&) = delete; - ~MaterialPipeline() = default; - - inline const Instance& Apply(UInt32 flags = ShaderFlags_None) const; - - MaterialPipeline& operator=(const MaterialPipeline&) = delete; - MaterialPipeline& operator=(MaterialPipeline&&) = delete; - - inline const MaterialPipelineInfo& GetInfo() const; - inline const Instance& GetInstance(UInt32 flags = ShaderFlags_None) const; - - static MaterialPipelineRef GetPipeline(const MaterialPipelineInfo& pipelineInfo); - - struct Instance - { - RenderPipeline renderPipeline; - UberShaderInstance* uberInstance = nullptr; - std::array uniforms; - }; - - private: - inline MaterialPipeline(const MaterialPipelineInfo& pipelineInfo); - - void GenerateRenderPipeline(UInt32 flags) const; - - static bool Initialize(); - template static MaterialPipelineRef New(Args&&... args); - static void Uninitialize(); - - MaterialPipelineInfo m_pipelineInfo; - mutable std::array m_instances; - - using PipelineCache = std::unordered_map; - static PipelineCache s_pipelineCache; - - static MaterialPipelineLibrary::LibraryMap s_library; - }; -} - -#include - -#endif // NAZARA_MATERIALPIPELINE_HPP diff --git a/include/Nazara/Graphics/MaterialPipeline.inl b/include/Nazara/Graphics/MaterialPipeline.inl deleted file mode 100644 index 7fe6f1bbb..000000000 --- a/include/Nazara/Graphics/MaterialPipeline.inl +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -namespace Nz -{ - inline MaterialPipeline::MaterialPipeline(const MaterialPipelineInfo& pipelineInfo) : - m_pipelineInfo(pipelineInfo) - { - } - - /*! - * \brief Enable pipeline states for rendering - * - * \param flags Shader flags - */ - inline const MaterialPipeline::Instance& MaterialPipeline::Apply(UInt32 flags) const - { - const Instance& instance = GetInstance(flags); - instance.uberInstance->Activate(); - - Renderer::SetRenderStates(m_pipelineInfo); - - return instance; - } - - /*! - * \brief Retrieve a MaterialPipelineInfo object describing this pipeline - * - * \return Pipeline informations - */ - const MaterialPipelineInfo& MaterialPipeline::GetInfo() const - { - return m_pipelineInfo; - } - - /*! - * \brief Retrieve (and generate if required) a pipeline instance using shader flags without applying it - * - * \param flags Shader flags - * - * \return Pipeline instance - */ - inline const MaterialPipeline::Instance& MaterialPipeline::GetInstance(UInt32 flags) const - { - const Instance& instance = m_instances[flags]; - if (!instance.uberInstance) - GenerateRenderPipeline(flags); - - return instance; - } - - bool operator==(const MaterialPipelineInfo& lhs, const MaterialPipelineInfo& rhs) - { - if (!operator==(static_cast(lhs), static_cast(rhs))) - return false; - - #define NazaraPipelineMember(field) if (lhs.field != rhs.field) return false - #define NazaraPipelineBoolMember NazaraPipelineMember - - NazaraPipelineBoolMember(alphaTest); - NazaraPipelineBoolMember(depthSorting); - NazaraPipelineBoolMember(hasAlphaMap); - NazaraPipelineBoolMember(hasDiffuseMap); - NazaraPipelineBoolMember(hasEmissiveMap); - NazaraPipelineBoolMember(hasHeightMap); - NazaraPipelineBoolMember(hasNormalMap); - NazaraPipelineBoolMember(hasSpecularMap); - NazaraPipelineBoolMember(hasVertexColor); - NazaraPipelineBoolMember(reflectionMapping); - NazaraPipelineBoolMember(shadowReceive); - - NazaraPipelineMember(uberShader); - - #undef NazaraPipelineMember - #undef NazaraPipelineBoolMember - - return true; - } - - bool operator!=(const MaterialPipelineInfo& lhs, const MaterialPipelineInfo& rhs) - { - return !operator==(lhs, rhs); - } - - /*! - * \brief Creates a new MaterialPipeline from the arguments - * \return A reference to the newly created material pipeline - * - * \param args Arguments for the material pipeline - */ - template - MaterialPipelineRef MaterialPipeline::New(Args&&... args) - { - std::unique_ptr object(new MaterialPipeline(std::forward(args)...)); - object->SetPersistent(false); - return object.release(); - } -} - -namespace std -{ - template<> - struct hash - { - size_t operator()(const Nz::MaterialPipelineInfo& pipelineInfo) const - { - hash parentHash; - - std::size_t seed = parentHash(pipelineInfo); - - Nz::UInt16 parameterHash = 0; - Nz::UInt16 parameterIndex = 0; - - #define NazaraPipelineMember(member) Nz::HashCombine(seed, pipelineInfo.member) - #define NazaraPipelineBoolMember(member) parameterHash |= ((pipelineInfo.member) ? 1U : 0U) << (parameterIndex++) - - NazaraPipelineBoolMember(alphaTest); - NazaraPipelineBoolMember(depthSorting); - NazaraPipelineBoolMember(hasAlphaMap); - NazaraPipelineBoolMember(hasDiffuseMap); - NazaraPipelineBoolMember(hasEmissiveMap); - NazaraPipelineBoolMember(hasHeightMap); - NazaraPipelineBoolMember(hasNormalMap); - NazaraPipelineBoolMember(hasSpecularMap); - NazaraPipelineBoolMember(hasVertexColor); - NazaraPipelineBoolMember(reflectionMapping); - NazaraPipelineBoolMember(shadowReceive); - - NazaraPipelineMember(uberShader); - - #undef NazaraPipelineMember - #undef NazaraPipelineBoolMember - - Nz::HashCombine(seed, parameterHash); - - return seed; - } - }; -} - -#include diff --git a/include/Nazara/Graphics/Model.hpp b/include/Nazara/Graphics/Model.hpp deleted file mode 100644 index 3780bc1be..000000000 --- a/include/Nazara/Graphics/Model.hpp +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_MODEL_HPP -#define NAZARA_MODEL_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - struct NAZARA_GRAPHICS_API ModelParameters : ResourceParameters - { - ModelParameters(); - - bool loadMaterials = true; - MaterialParams material; - MeshParams mesh; - - bool IsValid() const; - }; - - class Model; - - using ModelConstRef = ObjectRef; - using ModelLibrary = ObjectLibrary; - using ModelLoader = ResourceLoader; - using ModelManager = ResourceManager; - using ModelRef = ObjectRef; - using ModelSaver = ResourceSaver; - - class NAZARA_GRAPHICS_API Model : public InstancedRenderable, public Resource - { - friend ModelLibrary; - friend ModelLoader; - friend ModelManager; - friend ModelSaver; - - public: - inline Model(); - Model(const Model& model); - Model(Model&& model) = delete; - virtual ~Model(); - - void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override; - inline void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder = 0, const Recti& scissorRect = Recti(-1, -1, -1, -1)) const; - - std::unique_ptr Clone() const override; - - using InstancedRenderable::GetMaterial; - const MaterialRef& GetMaterial(const std::string& subMeshName) const; - const MaterialRef& GetMaterial(std::size_t skinIndex, const std::string& subMeshName) const; - Mesh* GetMesh() const; - - virtual bool IsAnimated() const; - - using InstancedRenderable::SetMaterial; - bool SetMaterial(const std::string& subMeshName, MaterialRef material); - bool SetMaterial(std::size_t skinIndex, const std::string& subMeshName, MaterialRef material); - - virtual void SetMesh(Mesh* mesh); - - Model& operator=(const Model& node) = default; - Model& operator=(Model&& node) = delete; - - static ModelRef LoadFromFile(const std::filesystem::path& filePath, const ModelParameters& params = ModelParameters()); - static ModelRef LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters()); - static ModelRef LoadFromStream(Stream& stream, const ModelParameters& params = ModelParameters()); - - template static ModelRef New(Args&&... args); - - protected: - void MakeBoundingVolume() const override; - - MeshRef m_mesh; - - NazaraSlot(Mesh, OnMeshInvalidateAABB, m_meshAABBInvalidationSlot); - - static ModelLibrary::LibraryMap s_library; - static ModelLoader::LoaderList s_loaders; - static ModelManager::ManagerMap s_managerMap; - static ModelManager::ManagerParams s_managerParameters; - static ModelSaver::SaverList s_savers; - }; -} - -#include - -#endif // NAZARA_MODEL_HPP diff --git a/include/Nazara/Graphics/Model.inl b/include/Nazara/Graphics/Model.inl deleted file mode 100644 index e7a909dba..000000000 --- a/include/Nazara/Graphics/Model.inl +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \brief Constructs a Model object by default - */ - inline Model::Model() - { - ResetMaterials(0); - } - - /*! - * \brief Constructs a Model object by copying another - * - * \param model Model to copy - */ - inline Model::Model(const Model& model) : - InstancedRenderable(model) - { - SetMesh(model.m_mesh); - - // Since SetMesh does reset materials, we need reapply them - SetSkinCount(model.GetSkinCount()); - for (std::size_t skin = 0; skin < model.GetSkinCount(); ++skin) - { - for (std::size_t matIndex = 0; matIndex < model.GetMaterialCount(); ++matIndex) - SetMaterial(skin, matIndex, model.GetMaterial(skin, matIndex)); - } - } - - /*! - * \brief Adds this model to a render queue, using user-specified transform matrix and render order - * - * This can be useful when drawing particles - * - * \param renderQueue Queue to be added - * \param transformMatrix Transform matrix to be used for rendering the model - * \param renderOrder Specify the render queue layer to be used - * \param scissorRect The Scissor rect to uses for rendering - */ - inline void Model::AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder, const Recti& scissorRect) const - { - InstanceData instanceData(Nz::Matrix4f::Identity()); - instanceData.renderOrder = renderOrder; - instanceData.transformMatrix = transformMatrix; - return AddToRenderQueue(renderQueue, instanceData, scissorRect); - } - - /*! - * \brief Creates a new Model from the arguments - * \return A reference to the newly created model - * - * \param args Arguments for the model - */ - template - ModelRef Model::New(Args&&... args) - { - std::unique_ptr object(new Model(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/ParticleController.hpp b/include/Nazara/Graphics/ParticleController.hpp deleted file mode 100644 index 566381b05..000000000 --- a/include/Nazara/Graphics/ParticleController.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLECONTROLLER_HPP -#define NAZARA_PARTICLECONTROLLER_HPP - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class ParticleController; - class ParticleMapper; - class ParticleGroup; - - using ParticleControllerConstRef = ObjectRef; - using ParticleControllerLibrary = ObjectLibrary; - using ParticleControllerRef = ObjectRef; - - class NAZARA_GRAPHICS_API ParticleController : public RefCounted - { - friend ParticleControllerLibrary; - friend class Graphics; - - public: - ParticleController() = default; - ParticleController(const ParticleController& controller); - virtual ~ParticleController(); - - virtual void Apply(ParticleGroup& system, ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) = 0; - - // Signals: - NazaraSignal(OnParticleControllerRelease, const ParticleController* /*particleController*/); - - private: - static bool Initialize(); - static void Uninitialize(); - - static ParticleControllerLibrary::LibraryMap s_library; - }; -} - -#endif // NAZARA_PARTICLECONTROLLER_HPP diff --git a/include/Nazara/Graphics/ParticleDeclaration.hpp b/include/Nazara/Graphics/ParticleDeclaration.hpp deleted file mode 100644 index 2b370c3be..000000000 --- a/include/Nazara/Graphics/ParticleDeclaration.hpp +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLEDECLARATION_HPP -#define NAZARA_PARTICLEDECLARATION_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class ParticleDeclaration; - - using ParticleDeclarationConstRef = ObjectRef; - using ParticleDeclarationLibrary = ObjectLibrary; - using ParticleDeclarationRef = ObjectRef; - - class NAZARA_GRAPHICS_API ParticleDeclaration : public RefCounted - { - friend ParticleDeclarationLibrary; - friend class Graphics; - - public: - ParticleDeclaration(); - ParticleDeclaration(const ParticleDeclaration& declaration); - ~ParticleDeclaration(); - - void DisableComponent(ParticleComponent component); - void EnableComponent(ParticleComponent component, ComponentType type, std::size_t offset); - - void GetComponent(ParticleComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const; - std::size_t GetStride() const; - - void SetStride(unsigned int stride); - - ParticleDeclaration& operator=(const ParticleDeclaration& declaration); - - static ParticleDeclaration* Get(ParticleLayout layout); - static bool IsTypeSupported(ComponentType type); - template static ParticleDeclarationRef New(Args&&... args); - - // Signals: - NazaraSignal(OnParticleDeclarationRelease, const ParticleDeclaration* /*particleDeclaration*/); - - private: - static bool Initialize(); - static void Uninitialize(); - - struct Component - { - ComponentType type; - bool enabled = false; - std::size_t offset; - - /* - ** -Lynix: - ** It would be also possible to precise the stride by an independant way, what I don't allow - ** to decomplexify the interface of something I consider useless. - ** If you think that could be useful, don't hesitate to make me aware ! - */ - }; - - std::array m_components; - std::size_t m_stride; - - static std::array s_declarations; - static ParticleDeclarationLibrary::LibraryMap s_library; - }; -} - -#include - -#endif // NAZARA_PARTICLEDECLARATION_HPP diff --git a/include/Nazara/Graphics/ParticleDeclaration.inl b/include/Nazara/Graphics/ParticleDeclaration.inl deleted file mode 100644 index 719bd38ca..000000000 --- a/include/Nazara/Graphics/ParticleDeclaration.inl +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - template - ParticleDeclarationRef ParticleDeclaration::New(Args&&... args) - { - std::unique_ptr object(new ParticleDeclaration(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/ParticleEmitter.hpp b/include/Nazara/Graphics/ParticleEmitter.hpp deleted file mode 100644 index eafd5255b..000000000 --- a/include/Nazara/Graphics/ParticleEmitter.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLEEMITTER_HPP -#define NAZARA_PARTICLEEMITTER_HPP - -#include -#include -#include - -namespace Nz -{ - class ParticleMapper; - class ParticleGroup; - - class NAZARA_GRAPHICS_API ParticleEmitter - { - public: - ParticleEmitter(); - ParticleEmitter(const ParticleEmitter& emitter); - ParticleEmitter(ParticleEmitter&& emitter); - virtual ~ParticleEmitter(); - - virtual void Emit(ParticleGroup& system, float elapsedTime) const; - - void EnableLagCompensation(bool enable); - - std::size_t GetEmissionCount() const; - float GetEmissionRate() const; - - bool IsLagCompensationEnabled() const; - - void SetEmissionCount(std::size_t count); - void SetEmissionRate(float rate); - - ParticleEmitter& operator=(const ParticleEmitter& emitter) = default; - ParticleEmitter& operator=(ParticleEmitter&& emitter); - - // Signals: - NazaraSignal(OnParticleEmitterMove, ParticleEmitter* /*oldParticleEmitter*/, ParticleEmitter* /*newParticleEmitter*/); - NazaraSignal(OnParticleEmitterRelease, const ParticleEmitter* /*particleEmitter*/); - - private: - virtual void SetupParticles(ParticleMapper& mapper, unsigned int count) const = 0; - - bool m_lagCompensationEnabled; - mutable float m_emissionAccumulator; - float m_emissionRate; - std::size_t m_emissionCount; - }; -} - -#endif // NAZARA_PARTICLEEMITTER_HPP diff --git a/include/Nazara/Graphics/ParticleFunctionController.hpp b/include/Nazara/Graphics/ParticleFunctionController.hpp deleted file mode 100644 index f46e09500..000000000 --- a/include/Nazara/Graphics/ParticleFunctionController.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP -#define NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP - -#include -#include -#include - -namespace Nz -{ - class ParticleFunctionController; - - using ParticleFunctionControllerConstRef = ObjectRef; - using ParticleFunctionControllerRef = ObjectRef; - - class NAZARA_GRAPHICS_API ParticleFunctionController : public ParticleController - { - public: - using Controller = std::function; - - inline ParticleFunctionController(Controller controller); - ParticleFunctionController(const ParticleFunctionController&) = default; - ~ParticleFunctionController() = default; - - void Apply(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) override final; - - inline const Controller& GetController() const; - - inline void SetController(Controller controller); - - template static ParticleFunctionControllerRef New(Args&&... args); - - private: - Controller m_controller; - }; -} - -#include - -#endif // NAZARA_PARTICLEFUNCTIONCONTROLLER_HPP diff --git a/include/Nazara/Graphics/ParticleFunctionController.inl b/include/Nazara/Graphics/ParticleFunctionController.inl deleted file mode 100644 index ee03ddf8e..000000000 --- a/include/Nazara/Graphics/ParticleFunctionController.inl +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - inline ParticleFunctionController::ParticleFunctionController(Controller controller) : - m_controller(std::move(controller)) - { - } - - /*! - * \brief Gets the controller function - * - * \return Controller function responsible for particle update - */ - inline const ParticleFunctionController::Controller& ParticleFunctionController::GetController() const - { - return m_controller; - } - - /*! - * \brief Sets the controller function - * - * \remark The controller function must be valid - */ - inline void ParticleFunctionController::SetController(Controller controller) - { - m_controller = std::move(controller); - } - - template - ParticleFunctionControllerRef ParticleFunctionController::New(Args&&... args) - { - std::unique_ptr object(new ParticleFunctionController(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/ParticleFunctionGenerator.hpp b/include/Nazara/Graphics/ParticleFunctionGenerator.hpp deleted file mode 100644 index 7075ccbdb..000000000 --- a/include/Nazara/Graphics/ParticleFunctionGenerator.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLEFUNCTIONGENERATOR_HPP -#define NAZARA_PARTICLEFUNCTIONGENERATOR_HPP - -#include -#include -#include - -namespace Nz -{ - class ParticleFunctionGenerator; - - using ParticleFunctionGeneratorConstRef = ObjectRef; - using ParticleFunctionGeneratorRef = ObjectRef; - - class NAZARA_GRAPHICS_API ParticleFunctionGenerator : public ParticleGenerator - { - public: - using Generator = std::function; - - inline ParticleFunctionGenerator(Generator controller); - ParticleFunctionGenerator(const ParticleFunctionGenerator&) = default; - ~ParticleFunctionGenerator() = default; - - void Generate(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId) override final; - - inline const Generator& GetGenerator() const; - - inline void SetGenerator(Generator generator); - - template static ParticleFunctionGeneratorRef New(Args&&... args); - - private: - Generator m_generator; - }; -} - -#include - -#endif // NAZARA_PARTICLEFUNCTIONGENERATOR_HPP diff --git a/include/Nazara/Graphics/ParticleFunctionGenerator.inl b/include/Nazara/Graphics/ParticleFunctionGenerator.inl deleted file mode 100644 index 813f3a786..000000000 --- a/include/Nazara/Graphics/ParticleFunctionGenerator.inl +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - inline ParticleFunctionGenerator::ParticleFunctionGenerator(Generator generator) : - m_generator(std::move(generator)) - { - } - - /*! - * \brief Gets the generator function - * - * \return Generator function responsible for particle creation - */ - inline const ParticleFunctionGenerator::Generator& ParticleFunctionGenerator::GetGenerator() const - { - return m_generator; - } - - /*! - * \brief Sets the generator function - * - * \remark The generator function must be valid - */ - inline void ParticleFunctionGenerator::SetGenerator(Generator generator) - { - m_generator = std::move(generator); - } - - template - ParticleFunctionGeneratorRef ParticleFunctionGenerator::New(Args&&... args) - { - std::unique_ptr object(new ParticleFunctionGenerator(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/ParticleFunctionRenderer.hpp b/include/Nazara/Graphics/ParticleFunctionRenderer.hpp deleted file mode 100644 index bb6fd841e..000000000 --- a/include/Nazara/Graphics/ParticleFunctionRenderer.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLEFUNCTIONRENDERER_HPP -#define NAZARA_PARTICLEFUNCTIONRENDERER_HPP - -#include -#include -#include - -namespace Nz -{ - class ParticleFunctionRenderer; - - using ParticleFunctionRendererConstRef = ObjectRef; - using ParticleFunctionRendererRef = ObjectRef; - - class NAZARA_GRAPHICS_API ParticleFunctionRenderer : public ParticleRenderer - { - public: - using Renderer = std::function; - - inline ParticleFunctionRenderer(Renderer renderer); - ParticleFunctionRenderer(const ParticleFunctionRenderer&) = default; - ~ParticleFunctionRenderer() = default; - - void Render(const ParticleGroup& group, const ParticleMapper& mapper, unsigned int startId, unsigned int endId, AbstractRenderQueue* renderQueue) override final; - - inline const Renderer& GetRenderer() const; - - inline void SetRenderer(Renderer renderer); - - template static ParticleFunctionRendererRef New(Args&&... args); - - private: - Renderer m_renderer; - }; -} - -#include - -#endif // NAZARA_PARTICLEFUNCTIONRENDERER_HPP diff --git a/include/Nazara/Graphics/ParticleFunctionRenderer.inl b/include/Nazara/Graphics/ParticleFunctionRenderer.inl deleted file mode 100644 index 414805aa2..000000000 --- a/include/Nazara/Graphics/ParticleFunctionRenderer.inl +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - inline ParticleFunctionRenderer::ParticleFunctionRenderer(Renderer renderer) : - m_renderer(std::move(renderer)) - { - } - - /*! - * \brief Gets the renderer function - * - * \return Renderer function responsible for particle rendering - */ - inline const ParticleFunctionRenderer::Renderer& ParticleFunctionRenderer::GetRenderer() const - { - return m_renderer; - } - - /*! - * \brief Sets the renderer function - * - * \remark The renderer function must be valid - */ - inline void ParticleFunctionRenderer::SetRenderer(Renderer renderer) - { - m_renderer = std::move(renderer); - } - - template - ParticleFunctionRendererRef ParticleFunctionRenderer::New(Args&&... args) - { - std::unique_ptr object(new ParticleFunctionRenderer(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/ParticleGenerator.hpp b/include/Nazara/Graphics/ParticleGenerator.hpp deleted file mode 100644 index 85c61405a..000000000 --- a/include/Nazara/Graphics/ParticleGenerator.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLEGENERATOR_HPP -#define NAZARA_PARTICLEGENERATOR_HPP - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class ParticleGenerator; - class ParticleMapper; - class ParticleGroup; - - using ParticleGeneratorConstRef = ObjectRef; - using ParticleGeneratorLibrary = ObjectLibrary; - using ParticleGeneratorRef = ObjectRef; - - class NAZARA_GRAPHICS_API ParticleGenerator : public RefCounted - { - friend ParticleGeneratorLibrary; - friend class Graphics; - - public: - ParticleGenerator() = default; - ParticleGenerator(const ParticleGenerator& generator); - virtual ~ParticleGenerator(); - - virtual void Generate(ParticleGroup& system, ParticleMapper& mapper, unsigned int startId, unsigned int endId) = 0; - - // Signals: - NazaraSignal(OnParticleGeneratorRelease, const ParticleGenerator* /*particleGenerator*/); - - private: - static bool Initialize(); - static void Uninitialize(); - - static ParticleGeneratorLibrary::LibraryMap s_library; - }; -} - -#endif // NAZARA_PARTICLEGENERATOR_HPP diff --git a/include/Nazara/Graphics/ParticleGroup.hpp b/include/Nazara/Graphics/ParticleGroup.hpp deleted file mode 100644 index ae91cc099..000000000 --- a/include/Nazara/Graphics/ParticleGroup.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLEGROUP_HPP -#define NAZARA_PARTICLEGROUP_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API ParticleGroup : public Renderable - { - public: - ParticleGroup(unsigned int maxParticleCount, ParticleLayout layout); - ParticleGroup(unsigned int maxParticleCount, ParticleDeclarationConstRef declaration); - ParticleGroup(const ParticleGroup& emitter); - ~ParticleGroup(); - - void AddController(ParticleControllerRef controller); - void AddEmitter(ParticleEmitter* emitter); - void AddGenerator(ParticleGeneratorRef generator); - void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const override; - - void ApplyControllers(ParticleMapper& mapper, unsigned int particleCount, float elapsedTime); - - void* CreateParticle(); - void* CreateParticles(unsigned int count); - - void* GenerateParticle(); - void* GenerateParticles(unsigned int count); - - inline void* GetBuffer(); - inline const void* GetBuffer() const; - const ParticleDeclarationConstRef& GetDeclaration() const; - std::size_t GetMaxParticleCount() const; - std::size_t GetParticleCount() const; - std::size_t GetParticleSize() const; - - void KillParticle(std::size_t index); - void KillParticles(); - - void RemoveController(ParticleController* controller); - void RemoveEmitter(ParticleEmitter* emitter); - void RemoveGenerator(ParticleGenerator* generator); - - void SetRenderer(ParticleRenderer* renderer); - - void Update(float elapsedTime); - void UpdateBoundingVolume(const Matrix4f& transformMatrix) override; - - ParticleGroup& operator=(const ParticleGroup& emitter); - - // Signals: - NazaraSignal(OnParticleGroupRelease, const ParticleGroup* /*particleGroup*/); - - private: - void MakeBoundingVolume() const override; - void OnEmitterMove(ParticleEmitter* oldEmitter, ParticleEmitter* newEmitter); - void OnEmitterRelease(const ParticleEmitter* emitter); - void ResizeBuffer(); - - struct EmitterEntry - { - NazaraSlot(ParticleEmitter, OnParticleEmitterMove, moveSlot); - NazaraSlot(ParticleEmitter, OnParticleEmitterRelease, releaseSlot); - - ParticleEmitter* emitter; - }; - - std::set> m_dyingParticles; - std::size_t m_maxParticleCount; - std::size_t m_particleCount; - std::size_t m_particleSize; - mutable std::vector m_buffer; - std::vector m_controllers; - std::vector m_emitters; - std::vector m_generators; - ParticleDeclarationConstRef m_declaration; - ParticleRendererRef m_renderer; - bool m_processing; - }; -} - -#include - -#endif // NAZARA_PARTICLEGROUP_HPP diff --git a/include/Nazara/Graphics/ParticleGroup.inl b/include/Nazara/Graphics/ParticleGroup.inl deleted file mode 100644 index 645d31815..000000000 --- a/include/Nazara/Graphics/ParticleGroup.inl +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include - -namespace Nz -{ - /*! - * \brief Gets a raw pointer to the particle buffer - * - * This can be useful when working directly with a struct, or needing to iterate over all particles. - * - * \return Pointer to the buffer - * - * \see GetParticleCount - */ - inline void* ParticleGroup::GetBuffer() - { - return m_buffer.data(); - } - - /*! - * \brief Gets a raw pointer to the particle buffer - * - * This can be useful when working directly with a struct, or needing to iterate over all particles. - * - * \return Pointer to the buffer - * - * \see GetParticleCount - */ - inline const void* ParticleGroup::GetBuffer() const - { - return m_buffer.data(); - } -} - -#include diff --git a/include/Nazara/Graphics/ParticleMapper.hpp b/include/Nazara/Graphics/ParticleMapper.hpp deleted file mode 100644 index 642327b1d..000000000 --- a/include/Nazara/Graphics/ParticleMapper.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLEMAPPER_HPP -#define NAZARA_PARTICLEMAPPER_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_GRAPHICS_API ParticleMapper - { - public: - ParticleMapper(void* buffer, const ParticleDeclaration* declaration); - ~ParticleMapper(); - - template SparsePtr GetComponentPtr(ParticleComponent component); - template SparsePtr GetComponentPtr(ParticleComponent component) const; - inline void* GetPointer(); - - private: - const ParticleDeclaration* m_declaration; - UInt8* m_ptr; - }; -} - -#include - -#endif // NAZARA_PARTICLEMAPPER_HPP diff --git a/include/Nazara/Graphics/ParticleMapper.inl b/include/Nazara/Graphics/ParticleMapper.inl deleted file mode 100644 index 69caaabad..000000000 --- a/include/Nazara/Graphics/ParticleMapper.inl +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \brief Gets a pointer to iterate through same components - * \return SparsePtr pointing to same components - * - * \param component Component to get in the declaration - * - * \remark The same components are not continguous but separated by sizeof(ParticleSize) - * \remark Produces a NazaraError if component is disabled - */ - - template - SparsePtr ParticleMapper::GetComponentPtr(ParticleComponent component) - { - // Then the component that are interesting - bool enabled; - ComponentType type; - std::size_t offset; - m_declaration->GetComponent(component, &enabled, &type, &offset); - - if (enabled && GetComponentTypeOf() == type) - { - ///TODO: Check the ratio between the type of the attribute and the template type ? - return SparsePtr(m_ptr + offset, m_declaration->GetStride()); - } - else - { - NazaraError("Attribute 0x" + String::Number(component, 16) + " is not enabled"); - return SparsePtr(); - } - } - - /*! - * \brief Gets a pointer to iterate through same components - * \return SparsePtr pointing to same components - * - * \param component Component to get in the declaration - * - * \remark The same components are not continguous but separated by sizeof(ParticleSize) - * \remark Produces a NazaraError if component is disabled - */ - - template - SparsePtr ParticleMapper::GetComponentPtr(ParticleComponent component) const - { - // Then the component that are interesting - bool enabled; - ComponentType type; - std::size_t offset; - m_declaration->GetComponent(component, &enabled, &type, &offset); - - if (enabled && GetComponentTypeOf() == type) - { - ///TODO: Check the ratio between the type of the attribute and the template type ? - return SparsePtr(m_ptr + offset, m_declaration->GetStride()); - } - else - { - NazaraError("Attribute 0x" + String::Number(component, 16) + " is not enabled"); - return SparsePtr(); - } - } - - /*! - * \brief Gets a raw pointer to the particle buffer - * - * This can be useful when working directly with a struct - * - * \return Pointer to the buffer - */ - inline void* ParticleMapper::GetPointer() - { - return m_ptr; - } -} - -#include diff --git a/include/Nazara/Graphics/ParticleRenderer.hpp b/include/Nazara/Graphics/ParticleRenderer.hpp deleted file mode 100644 index 0b1927e27..000000000 --- a/include/Nazara/Graphics/ParticleRenderer.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLERENDERER_HPP -#define NAZARA_PARTICLERENDERER_HPP - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class AbstractRenderQueue; - class ParticleMapper; - class ParticleRenderer; - class ParticleGroup; - - using ParticleRendererConstRef = ObjectRef; - using ParticleRendererLibrary = ObjectLibrary; - using ParticleRendererRef = ObjectRef; - - class NAZARA_GRAPHICS_API ParticleRenderer : public RefCounted - { - friend ParticleRendererLibrary; - friend class Graphics; - - public: - ParticleRenderer() = default; - ParticleRenderer(const ParticleRenderer& renderer); - virtual ~ParticleRenderer(); - - virtual void Render(const ParticleGroup& system, const ParticleMapper& mapper, unsigned int startId, unsigned int endId, AbstractRenderQueue* renderQueue) = 0; - - // Signals: - NazaraSignal(OnParticleRendererRelease, const ParticleRenderer* /*particleRenderer*/); - - private: - static bool Initialize(); - static void Uninitialize(); - - static ParticleRendererLibrary::LibraryMap s_library; - }; -} - -#endif // NAZARA_PARTICLERENDERER_HPP diff --git a/include/Nazara/Graphics/ParticleStruct.hpp b/include/Nazara/Graphics/ParticleStruct.hpp deleted file mode 100644 index a10fd1631..000000000 --- a/include/Nazara/Graphics/ParticleStruct.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_PARTICLESTRUCT_HPP -#define NAZARA_PARTICLESTRUCT_HPP - -#include -#include -#include -#include - -namespace Nz -{ - struct ParticleStruct_Billboard - { - Color color; - Vector2f size; - Vector3f normal; - Vector3f position; - Vector3f velocity; - float life; - float rotation; - }; - - struct ParticleStruct_Model - { - Quaternionf rotation; - Vector3f position; - Vector3f velocity; - float life; - }; - - struct ParticleStruct_Sprite - { - Color color; - Vector3f position; - Vector3f velocity; - float life; - float rotation; - }; -} - -#endif // NAZARA_PARTICLESTRUCT_HPP diff --git a/include/Nazara/Graphics/RenderQueue.hpp b/include/Nazara/Graphics/RenderQueue.hpp deleted file mode 100644 index e6efd9ba3..000000000 --- a/include/Nazara/Graphics/RenderQueue.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RENDERQUEUE_HPP -#define NAZARA_RENDERQUEUE_HPP - -#include -#include -#include - -namespace Nz -{ - class RenderQueueInternal - { - public: - using Index = Nz::UInt64; - - RenderQueueInternal() = default; - RenderQueueInternal(const RenderQueueInternal&) = default; - RenderQueueInternal(RenderQueueInternal&&) = default; - ~RenderQueueInternal() = default; - - RenderQueueInternal& operator=(const RenderQueueInternal&) = default; - RenderQueueInternal& operator=(RenderQueueInternal&&) = default; - - protected: - using RenderDataPair = std::pair; - - void Sort(); - - std::vector m_orderedRenderQueue; - }; - - template - class RenderQueue : public RenderQueueInternal - { - public: - class const_iterator; - friend const_iterator; - using size_type = std::size_t; - - RenderQueue() = default; - RenderQueue(const RenderQueue&) = default; - RenderQueue(RenderQueue&&) noexcept = default; - ~RenderQueue() = default; - - void Clear(); - - void Insert(RenderData&& data); - - template void Sort(IndexFunc&& func); - - // STL API - inline const_iterator begin() const; - inline bool empty() const; - inline const_iterator end() const; - inline size_type size() const; - - RenderQueue& operator=(const RenderQueue&) = default; - RenderQueue& operator=(RenderQueue&&) noexcept = default; - - private: - const RenderData& GetData(std::size_t i) const; - - std::vector m_data; - }; - - template - class RenderQueue::const_iterator : public std::iterator - { - friend RenderQueue; - - public: - const_iterator(const const_iterator& it); - - const RenderData& operator*() const; - - const_iterator& operator=(const const_iterator& it); - const_iterator& operator++(); - const_iterator operator++(int); - - bool operator==(const const_iterator& rhs) const; - bool operator!=(const const_iterator& rhs) const; - - void swap(const_iterator& rhs); - - private: - const_iterator(const RenderQueue* queue, std::size_t nextId); - - std::size_t m_nextDataId; - const RenderQueue* m_queue; - }; - -} - -#include - -#endif // NAZARA_RENDERQUEUE_HPP diff --git a/include/Nazara/Graphics/RenderQueue.inl b/include/Nazara/Graphics/RenderQueue.inl deleted file mode 100644 index cfa368a8a..000000000 --- a/include/Nazara/Graphics/RenderQueue.inl +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - template - void RenderQueue::Clear() - { - m_orderedRenderQueue.clear(); - m_data.clear(); - } - - template - void RenderQueue::Insert(RenderData&& data) - { - m_data.emplace_back(std::move(data)); - } - - template - template - void RenderQueue::Sort(IndexFunc&& func) - { - m_orderedRenderQueue.clear(); - m_orderedRenderQueue.reserve(m_data.size()); - - std::size_t dataIndex = 0; - for (const RenderData& renderData : m_data) - m_orderedRenderQueue.emplace_back(func(renderData), dataIndex++); - - RenderQueueInternal::Sort(); - } - - template - typename RenderQueue::const_iterator RenderQueue::begin() const - { - return const_iterator(this, 0); - } - - template - bool RenderQueue::empty() const - { - return m_orderedRenderQueue.empty(); - } - - template - typename RenderQueue::const_iterator RenderQueue::end() const - { - return const_iterator(this, m_orderedRenderQueue.size()); - } - - template - typename RenderQueue::size_type RenderQueue::size() const - { - return m_orderedRenderQueue.size(); - } - - template - const RenderData& RenderQueue::GetData(std::size_t i) const - { - NazaraAssert(i < m_orderedRenderQueue.size(), "Cannot dereference post-end iterator"); - - return m_data[m_orderedRenderQueue[i].second]; - } - - - template - RenderQueue::const_iterator::const_iterator(const RenderQueue* queue, std::size_t nextId) : - m_nextDataId(nextId), - m_queue(queue) - { - } - - template - RenderQueue::const_iterator::const_iterator(const const_iterator& it) : - m_nextDataId(it.m_nextDataId), - m_queue(it.m_queue) - { - } - - template - const RenderData& RenderQueue::const_iterator::operator*() const - { - return m_queue->GetData(m_nextDataId); - } - - template - typename RenderQueue::const_iterator& RenderQueue::const_iterator::operator=(const const_iterator& it) - { - m_nextDataId = it.m_nextDataId; - m_queue = it.m_queue; - - return *this; - } - - template - typename RenderQueue::const_iterator& RenderQueue::const_iterator::operator++() - { - ++m_nextDataId; - - return *this; - } - - template - typename RenderQueue::const_iterator RenderQueue::const_iterator::operator++(int) - { - return iterator(m_queue, m_nextDataId++); - } - - template - bool RenderQueue::const_iterator::operator==(const typename RenderQueue::const_iterator& rhs) const - { - NazaraAssert(m_queue == rhs.m_queue, "Cannot compare iterator coming from different queues"); - - return m_nextDataId == rhs.m_nextDataId; - } - - template - bool RenderQueue::const_iterator::operator!=(const typename RenderQueue::const_iterator& rhs) const - { - return !operator==(rhs); - } - - template - void RenderQueue::const_iterator::swap(typename RenderQueue::const_iterator& rhs) - { - NazaraAssert(m_queue == rhs.m_queue, "Cannot swap iterator coming from different queues"); - - using std::swap; - - swap(m_nextDataId, rhs.m_nextDataId); - } -} diff --git a/include/Nazara/Graphics/RenderTechniques.hpp b/include/Nazara/Graphics/RenderTechniques.hpp deleted file mode 100644 index 99f277467..000000000 --- a/include/Nazara/Graphics/RenderTechniques.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RENDERTECHNIQUES_HPP -#define NAZARA_RENDERTECHNIQUES_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class AbstractRenderTechnique; - - class NAZARA_GRAPHICS_API RenderTechniques - { - public: - using RenderTechniqueFactory = AbstractRenderTechnique* (*)(); - - RenderTechniques() = delete; - ~RenderTechniques() = delete; - - static AbstractRenderTechnique* GetByEnum(RenderTechniqueType renderTechnique, int* techniqueRanking = nullptr); - static AbstractRenderTechnique* GetByIndex(unsigned int index, int* techniqueRanking = nullptr); - static AbstractRenderTechnique* GetByName(const String& name, int* techniqueRanking = nullptr); - static AbstractRenderTechnique* GetByRanking(int maxRanking, int* techniqueRanking = nullptr); - - static std::size_t GetCount(); - - static void Register(const String& name, int ranking, RenderTechniqueFactory factory); - - static String ToString(RenderTechniqueType renderTechnique); - - static void Unregister(const String& name); - }; -} - -#endif // NAZARA_RENDERTECHNIQUES_HPP diff --git a/include/Nazara/Graphics/Renderable.hpp b/include/Nazara/Graphics/Renderable.hpp deleted file mode 100644 index f28df8dcc..000000000 --- a/include/Nazara/Graphics/Renderable.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_RENDERABLE_HPP -#define NAZARA_RENDERABLE_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class AbstractRenderQueue; - - class NAZARA_GRAPHICS_API Renderable - { - public: - Renderable() = default; - Renderable(const Renderable& renderable) = default; - Renderable(Renderable&&) noexcept = default; - virtual ~Renderable(); - - virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const = 0; - - virtual bool Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const; - - inline void EnsureBoundingVolumeUpdated() const; - virtual const BoundingVolumef& GetBoundingVolume() const; - virtual void UpdateBoundingVolume(const Matrix4f& transformMatrix); - - Renderable& operator=(const Renderable& renderable) = default; - Renderable& operator=(Renderable&& renderable) noexcept = default; - - protected: - virtual void MakeBoundingVolume() const = 0; - inline void InvalidateBoundingVolume(); - - mutable BoundingVolumef m_boundingVolume; - - private: - inline void UpdateBoundingVolume() const; - - mutable bool m_boundingVolumeUpdated; - }; -} - -#include - -#endif // NAZARA_RENDERABLE_HPP diff --git a/include/Nazara/Graphics/Renderable.inl b/include/Nazara/Graphics/Renderable.inl deleted file mode 100644 index c7f9d43a2..000000000 --- a/include/Nazara/Graphics/Renderable.inl +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -namespace Nz -{ - /*! - * \brief Ensures that the bounding volume is up to date - */ - - inline void Renderable::EnsureBoundingVolumeUpdated() const - { - if (!m_boundingVolumeUpdated) - UpdateBoundingVolume(); - } - - /*! - * \brief Invalidates the bounding volume - */ - - inline void Renderable::InvalidateBoundingVolume() - { - m_boundingVolumeUpdated = false; - } - - /*! - * \brief Updates the bounding volume - */ - - inline void Renderable::UpdateBoundingVolume() const - { - MakeBoundingVolume(); - m_boundingVolumeUpdated = true; - } -} diff --git a/include/Nazara/Graphics/SceneData.hpp b/include/Nazara/Graphics/SceneData.hpp deleted file mode 100644 index 953d38ced..000000000 --- a/include/Nazara/Graphics/SceneData.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_SCENEDATA_HPP -#define NAZARA_SCENEDATA_HPP - -#include - -namespace Nz -{ - class AbstractBackground; - class AbstractViewer; - class Texture; - - struct SceneData - { - Color ambientColor; - const AbstractBackground* background; - const AbstractViewer* viewer; - Texture* globalReflectionTexture; - }; -} - -#endif // NAZARA_SCENEDATA_HPP diff --git a/include/Nazara/Graphics/SkeletalModel.hpp b/include/Nazara/Graphics/SkeletalModel.hpp deleted file mode 100644 index adaec3be1..000000000 --- a/include/Nazara/Graphics/SkeletalModel.hpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_SKELETALMODEL_HPP -#define NAZARA_SKELETALMODEL_HPP - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - struct NAZARA_GRAPHICS_API SkeletalModelParameters : ModelParameters - { - bool loadAnimation = true; - AnimationParams animation; - - bool IsValid() const; - }; - - class SkeletalModel; - - using SkeletalModelRef = ObjectRef; - - class NAZARA_GRAPHICS_API SkeletalModel : public Model, Updatable - { - public: - SkeletalModel(); - SkeletalModel(const SkeletalModel& model) = default; - SkeletalModel(SkeletalModel&& model) = default; - ~SkeletalModel() = default; - - void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override; - void AdvanceAnimation(float elapsedTime); - - std::unique_ptr Clone() const override; - SkeletalModel* Create() const; - - void EnableAnimation(bool animation); - - Animation* GetAnimation() const; - Skeleton* GetSkeleton(); - const Skeleton* GetSkeleton() const; - - bool HasAnimation() const; - - bool IsAnimated() const override; - bool IsAnimationEnabled() const; - - bool SetAnimation(Animation* animation); - void SetMesh(Mesh* mesh) override; - bool SetSequence(const String& sequenceName); - void SetSequence(unsigned int sequenceIndex); - - SkeletalModel& operator=(const SkeletalModel& node) = default; - SkeletalModel& operator=(SkeletalModel&& node) = default; - - template static SkeletalModelRef New(Args&&... args); - - private: - void MakeBoundingVolume() const override; - /*void Register() override; - void Unregister() override;*/ - void Update() override; - - AnimationRef m_animation; - Skeleton m_skeleton; - const Sequence* m_currentSequence; - bool m_animationEnabled; - float m_interpolation; - unsigned int m_currentFrame; - unsigned int m_nextFrame; - }; -} - -#include - -#endif // NAZARA_SKELETALMODEL_HPP diff --git a/include/Nazara/Graphics/SkeletalModel.inl b/include/Nazara/Graphics/SkeletalModel.inl deleted file mode 100644 index 70d550e67..000000000 --- a/include/Nazara/Graphics/SkeletalModel.inl +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \brief Creates a new SkeletalModel from the arguments - * \return A reference to the newly created SkeletalModel - * - * \param args Arguments for the skeletal model - */ - template - SkeletalModelRef SkeletalModel::New(Args&&... args) - { - std::unique_ptr object(new SkeletalModel(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/SkinningManager.hpp b/include/Nazara/Graphics/SkinningManager.hpp deleted file mode 100644 index 4cf24d0ad..000000000 --- a/include/Nazara/Graphics/SkinningManager.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_SKINNINGMANAGER_HPP -#define NAZARA_SKINNINGMANAGER_HPP - -#include -#include - -namespace Nz -{ - class Skeleton; - class SkeletalMesh; - class VertexBuffer; - - class NAZARA_GRAPHICS_API SkinningManager - { - friend class Graphics; - - public: - using SkinFunction = void (*)(const SkeletalMesh* mesh, const Skeleton* skeleton, VertexBuffer* buffer); - - SkinningManager() = delete; - ~SkinningManager() = delete; - - static VertexBuffer* GetBuffer(const SkeletalMesh* mesh, const Skeleton* skeleton); - static void Skin(); - - private: - static bool Initialize(); - static void OnSkeletalMeshDestroy(const SkeletalMesh* mesh); - static void OnSkeletonInvalidated(const Skeleton* skeleton); - static void OnSkeletonRelease(const Skeleton* skeleton); - static void Uninitialize(); - - static SkinFunction s_skinFunc; - }; -} - -#endif // NAZARA_SKINNINGMANAGER_HPP diff --git a/include/Nazara/Graphics/SkyboxBackground.hpp b/include/Nazara/Graphics/SkyboxBackground.hpp deleted file mode 100644 index 3488742fb..000000000 --- a/include/Nazara/Graphics/SkyboxBackground.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_SKYBOXBACKGROUND_HPP -#define NAZARA_SKYBOXBACKGROUND_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class AbstractViewer; - class SkyboxBackground; - - using SkyboxBackgroundConstRef = ObjectRef; - using SkyboxBackgroundRef = ObjectRef; - - class NAZARA_GRAPHICS_API SkyboxBackground : public AbstractBackground - { - friend class Graphics; - - public: - SkyboxBackground(TextureRef cubemapTexture = TextureRef()); - ~SkyboxBackground() = default; - - void Draw(const AbstractViewer* viewer) const override; - - BackgroundType GetBackgroundType() const override; - inline const Vector3f& GetMovementOffset() const; - inline float GetMovementScale() const; - inline const TextureRef& GetTexture() const; - inline TextureSampler& GetTextureSampler(); - inline const TextureSampler& GetTextureSampler() const; - - inline void SetMovementOffset(const Vector3f& offset); - inline void SetMovementScale(float scale); - inline void SetTexture(TextureRef cubemapTexture); - inline void SetTextureSampler(const TextureSampler& sampler); - - template static SkyboxBackgroundRef New(Args&&... args); - - private: - static bool Initialize(); - static void Uninitialize(); - - TextureRef m_texture; - TextureSampler m_sampler; - Vector3f m_movementOffset; - float m_movementScale; - }; -} - -#include - -#endif // NAZARA_SKYBOXBACKGROUND_HPP diff --git a/include/Nazara/Graphics/SkyboxBackground.inl b/include/Nazara/Graphics/SkyboxBackground.inl deleted file mode 100644 index 93a08ab90..000000000 --- a/include/Nazara/Graphics/SkyboxBackground.inl +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \brief Gets the movement offset - * \return Offset of the movement - */ - - inline const Vector3f& Nz::SkyboxBackground::GetMovementOffset() const - { - return m_movementOffset; - } - - /*! - * \brief Gets the movement scale - * \return Scale of the movement - */ - - inline float SkyboxBackground::GetMovementScale() const - { - return m_movementScale; - } - - /*! - * \brief Gets the texture of the background - * \return Texture of the background - */ - - inline const TextureRef& SkyboxBackground::GetTexture() const - { - return m_texture; - } - - /*! - * \brief Gets the texture sampler of the background - * \return A reference to the texture sampler of the background - */ - - inline TextureSampler& SkyboxBackground::GetTextureSampler() - { - return m_sampler; - } - - /*! - * \brief Gets the texture sampler of the background - * \return A constant reference to the texture sampler of the background - */ - - inline const TextureSampler& SkyboxBackground::GetTextureSampler() const - { - return m_sampler; - } - - /*! - * \brief Sets the movement offset - * - * \param offset Offset of the movement - */ - - inline void SkyboxBackground::SetMovementOffset(const Vector3f& offset) - { - NazaraAssert(std::isfinite(offset.x) && std::isfinite(offset.y) && std::isfinite(offset.z), "Offset must be a finite vector"); - - m_movementOffset = offset; - } - - /*! - * \brief Sets the movement scale - * - * \param scale Scale of the movement - */ - - inline void SkyboxBackground::SetMovementScale(float scale) - { - NazaraAssert(std::isfinite(scale), "Scale must be a finite value"); - - m_movementScale = scale; - } - - /*! - * \brief Sets the texture of the background - * - * \param cubemapTexture Texture of the background - */ - - inline void SkyboxBackground::SetTexture(TextureRef cubemapTexture) - { - NazaraAssert(!cubemapTexture || cubemapTexture->IsValid(), "Invalid texture"); - NazaraAssert(!cubemapTexture || cubemapTexture->IsCubemap(), "Texture must be a cubemap"); - - m_texture = std::move(cubemapTexture); - } - - /*! - * \brief Sets the texture sampler of the background - * - * \param sampler Texture sampler of the background - */ - - void SkyboxBackground::SetTextureSampler(const TextureSampler& sampler) - { - m_sampler = sampler; - } - - /*! - * \brief Creates a new skybox background from the arguments - * \return A reference to the newly created skybox background - * - * \param args Arguments for the skybox background - */ - - template - SkyboxBackgroundRef SkyboxBackground::New(Args&&... args) - { - std::unique_ptr object(new SkyboxBackground(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/Sprite.hpp b/include/Nazara/Graphics/Sprite.hpp deleted file mode 100644 index 7d94cb345..000000000 --- a/include/Nazara/Graphics/Sprite.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_SPRITE_HPP -#define NAZARA_SPRITE_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class Sprite; - - using SpriteConstRef = ObjectRef; - using SpriteLibrary = ObjectLibrary; - using SpriteRef = ObjectRef; - - class NAZARA_GRAPHICS_API Sprite : public InstancedRenderable - { - friend SpriteLibrary; - friend class Graphics; - - public: - inline Sprite(); - inline Sprite(MaterialRef material); - inline Sprite(Texture* texture); - Sprite(const Sprite&) = default; - Sprite(Sprite&&) = delete; - ~Sprite() = default; - - void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override; - - std::unique_ptr Clone() const override; - - inline const Color& GetColor() const; - inline const Color& GetCornerColor(RectCorner corner) const; - inline const Vector3f& GetOrigin() const; - inline const Vector2f& GetSize() const; - inline const Rectf& GetTextureCoords() const; - - inline void SetColor(const Color& color); - inline void SetCornerColor(RectCorner corner, const Color& color); - inline void SetDefaultMaterial(); - inline void SetMaterial(MaterialRef material, bool resizeSprite = true); - bool SetMaterial(std::string materialName, bool resizeSprite = true); - inline void SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeSprite = true); - bool SetMaterial(std::size_t skinIndex, std::string materialName, bool resizeSprite = true); - inline void SetOrigin(const Vector3f& origin); - inline void SetSize(const Vector2f& size); - inline void SetSize(float sizeX, float sizeY); - bool SetTexture(std::string textureName, bool resizeSprite = true); - inline void SetTexture(TextureRef texture, bool resizeSprite = true); - bool SetTexture(std::size_t skinIndex, std::string textureName, bool resizeSprite = true); - inline void SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeSprite = true); - inline void SetTextureCoords(const Rectf& coords); - inline void SetTextureRect(const Rectui& rect); - - inline Sprite& operator=(const Sprite& sprite); - Sprite& operator=(Sprite&& sprite) = delete; - - template static SpriteRef New(Args&&... args); - - private: - inline void InvalidateVertices(); - void MakeBoundingVolume() const override; - void UpdateData(InstanceData* instanceData) const override; - - static bool Initialize(); - static void Uninitialize(); - - std::array m_cornerColor; - Color m_color; - Rectf m_textureCoords; - Vector2f m_size; - Vector3f m_origin; - - static SpriteLibrary::LibraryMap s_library; - }; -} - -#include - -#endif // NAZARA_SPRITE_HPP diff --git a/include/Nazara/Graphics/Sprite.inl b/include/Nazara/Graphics/Sprite.inl deleted file mode 100644 index 4fd39cced..000000000 --- a/include/Nazara/Graphics/Sprite.inl +++ /dev/null @@ -1,374 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \brief Constructs a Sprite object by default - */ - - inline Sprite::Sprite() : - m_color(Color::White), - m_textureCoords(0.f, 0.f, 1.f, 1.f), - m_size(64.f, 64.f), - m_origin(Nz::Vector3f::Zero()) - { - ResetMaterials(1); - - for (Color& color : m_cornerColor) - color = Color::White; - - SetDefaultMaterial(); - } - - /*! - * \brief Constructs a Sprite object with a reference to a material - * - * \param material Reference to a material - */ - inline Sprite::Sprite(MaterialRef material) : - Sprite() - { - SetMaterial(std::move(material), true); - } - - /*! - * \brief Constructs a Sprite object with a pointer to a texture - * - * \param texture Pointer to a texture - */ - - inline Sprite::Sprite(Texture* texture) : - Sprite() - { - SetTexture(texture, true); - } - - /*! - * \brief Gets the color of the sprite - * - * This is the global color of the sprite, independent from corner colors - * - * \return Current color - * - * \see GetCornerColor - * \see SetColor - */ - inline const Color& Sprite::GetColor() const - { - return m_color; - } - - /*! - * \brief Gets the color setup on a corner of the sprite - * - * \return Current color - * - * \param corner Corner of the sprite to query - * - * \see SetCornerColor - */ - inline const Color& Sprite::GetCornerColor(RectCorner corner) const - { - NazaraAssert(static_cast(corner) < m_cornerColor.size(), "Invalid corner"); - - return m_cornerColor[corner]; - } - - /*! - * \brief Gets the origin of the sprite - * - * \return Current material - * - * \see SetOrigin - */ - inline const Vector3f& Sprite::GetOrigin() const - { - return m_origin; - } - - /*! - * \brief Gets the size of the sprite - * \return Current size - */ - - inline const Vector2f& Sprite::GetSize() const - { - return m_size; - } - - /*! - * \brief Gets the texture coordinates of the sprite - * \return Current texture coordinates - */ - inline const Rectf& Sprite::GetTextureCoords() const - { - return m_textureCoords; - } - - /*! - * \brief Sets the global color of the sprite - * - * This is independent from the corner color of the sprite - * - * \param color Color for the sprite - * - * \see GetColor - * \see SetCornerColor - */ - inline void Sprite::SetColor(const Color& color) - { - m_color = color; - - InvalidateVertices(); - } - - /*! - * \brief Sets a color for a corner of the sprite - * - * This is independent from the sprite global color, which gets multiplied by the corner color when rendering the sprite. - * - * \param corner Corner of the sprite to set - * \param color Color for the sprite - * - * \see GetCornerColor - * \see SetColor - */ - inline void Sprite::SetCornerColor(RectCorner corner, const Color& color) - { - NazaraAssert(static_cast(corner) < m_cornerColor.size(), "Invalid corner"); - - m_cornerColor[corner] = color; - - InvalidateVertices(); - } - - /*! - * \brief Sets the default material of the sprite (just default material) - */ - - inline void Sprite::SetDefaultMaterial() - { - MaterialRef material = Material::New(); - material->EnableFaceCulling(false); - material->EnableScissorTest(true); - - SetMaterial(std::move(material)); - } - - /*! - * \brief Changes the material of the sprite - * - * \param material Material for the sprite - * \param resizeSprite Should billboard be resized to the material size (diffuse map) - */ - inline void Sprite::SetMaterial(MaterialRef material, bool resizeSprite) - { - SetMaterial(GetSkin(), std::move(material), resizeSprite); - } - - /*! - * \brief Sets the material of the sprite - * - * \param skinIndex Skin index to change - * \param material Material for the sprite - * \param resizeBillboard Should billboard be resized to the material size (diffuse map) - */ - inline void Sprite::SetMaterial(std::size_t skinIndex, MaterialRef material, bool resizeSprite) - { - InstancedRenderable::SetMaterial(skinIndex, 0, std::move(material)); - - if (resizeSprite) - { - if (const MaterialRef& newMat = GetMaterial()) - { - const TextureRef& diffuseMap = newMat->GetDiffuseMap(); - if (diffuseMap && diffuseMap->IsValid()) - SetSize(Vector2f(Vector2ui(diffuseMap->GetSize()))); - } - } - } - - /*! - * \brief Sets the origin of the sprite - * - * The origin is the center of translation/rotation/scaling of the sprite. - * - * \param origin New origin for the sprite - * - * \see GetOrigin - */ - inline void Sprite::SetOrigin(const Vector3f& origin) - { - m_origin = origin; - - // On invalide la bounding box - InvalidateBoundingVolume(); - InvalidateVertices(); - } - - /*! - * \brief Sets the size of the sprite - * - * \param size Size for the sprite - */ - - inline void Sprite::SetSize(const Vector2f& size) - { - m_size = size; - - // On invalide la bounding box - InvalidateBoundingVolume(); - InvalidateVertices(); - } - - /*! - * \brief Sets the size of the sprite - * - * \param sizeX Size in X for the sprite - * \param sizeY Size in Y for the sprite - */ - - inline void Sprite::SetSize(float sizeX, float sizeY) - { - SetSize(Vector2f(sizeX, sizeY)); - } - - /*! - * \brief Sets the texture of the sprite for the current skin - * - * This function changes the diffuse map of the material associated with the current skin - * - * \param texture Texture for the sprite - * \param resizeSprite Should the sprite be resized to the texture size? - * - * \remark The sprite material gets copied to prevent accidentally changing other drawable materials - */ - inline void Sprite::SetTexture(TextureRef texture, bool resizeSprite) - { - SetTexture(GetSkin(), std::move(texture), resizeSprite); - } - - /*! - * \brief Sets the texture of the sprite for a specific skin - * - * This function changes the diffuse map of the material associated with the specified skin - * - * \param skinIndex Skin index to change - * \param texture Texture for the sprite - * \param resizeSprite Should the sprite be resized to the texture size? - * - * \remark The sprite material gets copied to prevent accidentally changing other drawable materials - */ - inline void Sprite::SetTexture(std::size_t skinIndex, TextureRef texture, bool resizeSprite) - { - const MaterialRef& material = GetMaterial(skinIndex); - - if (material->GetReferenceCount() > 1) - { - MaterialRef newMat = Material::New(*material); // Copy - newMat->SetDiffuseMap(std::move(texture)); - - SetMaterial(skinIndex, std::move(newMat), resizeSprite); - } - else - { - material->SetDiffuseMap(std::move(texture)); - const TextureRef& newTexture = material->GetDiffuseMap(); - - if (resizeSprite && newTexture && newTexture->IsValid()) - SetSize(Vector2f(Vector2ui(newTexture->GetSize()))); - } - } - - /*! - * \brief Sets the texture coordinates of the sprite - * - * \param coords Texture coordinates - */ - - inline void Sprite::SetTextureCoords(const Rectf& coords) - { - m_textureCoords = coords; - - InvalidateVertices(); - } - - /*! - * \brief Sets the texture rectangle of the sprite - * - * \param rect Rectangles symbolizing the size of the texture - * - * \remark Produces a NazaraAssert if material is invalid - * \remark Produces a NazaraAssert if material has no diffuse map - */ - - inline void Sprite::SetTextureRect(const Rectui& rect) - { - const MaterialRef& material = GetMaterial(); - NazaraAssert(material->HasDiffuseMap(), "Sprite material has no diffuse map"); - - Texture* diffuseMap = material->GetDiffuseMap(); - - float invWidth = 1.f / diffuseMap->GetWidth(); - float invHeight = 1.f / diffuseMap->GetHeight(); - - SetTextureCoords(Rectf(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height)); - } - - /*! - * \brief Sets the current sprite with the content of the other one - * \return A reference to this - * - * \param sprite The other Sprite - */ - - inline Sprite& Sprite::operator=(const Sprite& sprite) - { - InstancedRenderable::operator=(sprite); - - m_color = sprite.m_color; - m_origin = sprite.m_origin; - m_textureCoords = sprite.m_textureCoords; - m_size = sprite.m_size; - - // We do not copy final vertices because it's highly probable that our parameters are modified and they must be regenerated - InvalidateBoundingVolume(); - InvalidateVertices(); - - return *this; - } - - /*! - * \brief Invalidates the vertices - */ - - inline void Sprite::InvalidateVertices() - { - InvalidateInstanceData(0); - } - - /*! - * \brief Creates a new sprite from the arguments - * \return A reference to the newly created sprite - * - * \param args Arguments for the sprite - */ - - template - SpriteRef Sprite::New(Args&&... args) - { - std::unique_ptr object(new Sprite(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/TextSprite.hpp b/include/Nazara/Graphics/TextSprite.hpp deleted file mode 100644 index e6dabeab0..000000000 --- a/include/Nazara/Graphics/TextSprite.hpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_TEXTSPRITE_HPP -#define NAZARA_TEXTSPRITE_HPP - -#include -#include -#include -#include -#include - -namespace Nz -{ - class AbstractTextDrawer; - class TextSprite; - - using TextSpriteConstRef = ObjectRef; - using TextSpriteLibrary = ObjectLibrary; - using TextSpriteRef = ObjectRef; - - class NAZARA_GRAPHICS_API TextSprite : public InstancedRenderable - { - public: - inline TextSprite(); - inline TextSprite(const AbstractTextDrawer& drawer); - inline TextSprite(const TextSprite& sprite); - ~TextSprite() = default; - - void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override; - - inline void Clear(); - - std::unique_ptr Clone() const override; - - inline const Color& GetColor() const; - inline float GetScale() const; - - inline void SetColor(const Color& color); - inline void SetDefaultMaterial(); - using InstancedRenderable::SetMaterial; - inline void SetMaterial(MaterialRef material); - inline void SetMaterial(std::size_t skinIndex, MaterialRef material); - inline void SetScale(float scale); - - void Update(const AbstractTextDrawer& drawer); - - inline TextSprite& operator=(const TextSprite& text); - - template static TextSpriteRef New(Args&&... args); - - private: - inline void InvalidateVertices(); - void MakeBoundingVolume() const override; - void OnAtlasInvalidated(const AbstractAtlas* atlas); - void OnAtlasLayerChange(const AbstractAtlas* atlas, AbstractImage* oldLayer, AbstractImage* newLayer); - void UpdateData(InstanceData* instanceData) const override; - - struct RenderKey - { - Texture* texture; - int renderOrder; - - bool operator==(const RenderKey& rhs) const - { - return texture == rhs.texture && renderOrder == rhs.renderOrder; - } - - bool operator!=(const RenderKey& rhs) const - { - return !operator==(rhs); - } - }; - - struct HashRenderKey - { - std::size_t operator()(const RenderKey& key) const - { - // Since renderOrder will be very small, this will be enough - return std::hash()(key.texture) + key.renderOrder; - } - }; - - struct RenderIndices - { - unsigned int first; - unsigned int count; - }; - - struct AtlasSlots - { - bool used; - NazaraSlot(AbstractAtlas, OnAtlasCleared, clearSlot); - NazaraSlot(AbstractAtlas, OnAtlasLayerChange, layerChangeSlot); - NazaraSlot(AbstractAtlas, OnAtlasRelease, releaseSlot); - }; - - std::unordered_map m_atlases; - mutable std::unordered_map m_renderInfos; - mutable std::vector m_localVertices; - Color m_color; - Rectf m_localBounds; - float m_scale; - - static TextSpriteLibrary::LibraryMap s_library; - }; -} - -#include - -#endif // NAZARA_TEXTSPRITE_HPP diff --git a/include/Nazara/Graphics/TextSprite.inl b/include/Nazara/Graphics/TextSprite.inl deleted file mode 100644 index 06b3f14a4..000000000 --- a/include/Nazara/Graphics/TextSprite.inl +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \brief Constructs a TextSprite object by default - */ - - inline TextSprite::TextSprite() : - m_color(Color::White), - m_localBounds(Nz::Rectf::Zero()), - m_scale(1.f) - { - ResetMaterials(1U); - - SetDefaultMaterial(); - } - - /*! - * \brief Constructs a TextSprite object with a drawer - * - * \param drawer Drawer used to compose text on the sprite - */ - - inline TextSprite::TextSprite(const AbstractTextDrawer& drawer) : - TextSprite() - { - Update(drawer); - } - - /*! - * \brief Constructs a TextSprite object by assignation - * - * \param sprite TextSprite to copy into this - */ - - inline TextSprite::TextSprite(const TextSprite& sprite) : - InstancedRenderable(sprite), - m_renderInfos(sprite.m_renderInfos), - m_localVertices(sprite.m_localVertices), - m_color(sprite.m_color), - m_localBounds(sprite.m_localBounds), - m_scale(sprite.m_scale) - { - for (auto it = sprite.m_atlases.begin(); it != sprite.m_atlases.end(); ++it) - { - const AbstractAtlas* atlas = it->first; - AtlasSlots& atlasSlots = m_atlases[atlas]; - - atlasSlots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated); - atlasSlots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange); - atlasSlots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated); - } - } - - /*! - * \brief Clears the data - */ - - inline void TextSprite::Clear() - { - m_atlases.clear(); - m_boundingVolume.MakeNull(); - m_localVertices.clear(); - m_renderInfos.clear(); - } - - /*! - * \brief Gets the color of the text sprite - * \return Current color - */ - - inline const Color& TextSprite::GetColor() const - { - return m_color; - } - - /*! - * \brief Gets the current scale of the text sprite - * \return Current scale - */ - - inline float TextSprite::GetScale() const - { - return m_scale; - } - - /*! - * \brief Sets the color of the text sprite - * - * \param color Color for the text sprite - */ - - inline void TextSprite::SetColor(const Color& color) - { - m_color = color; - - InvalidateVertices(); - } - - /*! - * \brief Sets the default material of the text sprite (just default material) - */ - - - inline void TextSprite::SetDefaultMaterial() - { - SetMaterial(Material::New("Translucent2D")); - } - - /*! - * \brief Sets the material of the text sprite - * - * \param material Material for the text sprite - */ - - inline void TextSprite::SetMaterial(MaterialRef material) - { - InstancedRenderable::SetMaterial(0, std::move(material)); - } - - inline void TextSprite::SetMaterial(std::size_t skinIndex, MaterialRef material) - { - InstancedRenderable::SetMaterial(skinIndex, 0, std::move(material)); - } - - /*! - * \brief Sets the current scale of the text sprite - * - * \param scale Scale of the text sprite - */ - - inline void TextSprite::SetScale(float scale) - { - m_scale = scale; - - InvalidateBoundingVolume(); - InvalidateVertices(); - } - - /*! - * \brief Sets the current text sprite with the content of the other one - * \return A reference to this - * - * \param text sprite The other TextSprite - */ - - inline TextSprite& TextSprite::operator=(const TextSprite& text) - { - InstancedRenderable::operator=(text); - - m_atlases.clear(); - - m_color = text.m_color; - m_renderInfos = text.m_renderInfos; - m_localBounds = text.m_localBounds; - m_localVertices = text.m_localVertices; - m_scale = text.m_scale; - - // Connect to the slots of the new atlases - for (auto it = text.m_atlases.begin(); it != text.m_atlases.end(); ++it) - { - const AbstractAtlas* atlas = it->first; - AtlasSlots& atlasSlots = m_atlases[atlas]; - - atlasSlots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated); - atlasSlots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange); - atlasSlots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated); - } - - InvalidateBoundingVolume(); - InvalidateVertices(); - - return *this; - } - - /*! - * \brief Invalidates the vertices - */ - - inline void TextSprite::InvalidateVertices() - { - InvalidateInstanceData(0); - } - - /*! - * \brief Creates a new text sprite from the arguments - * \return A reference to the newly created text sprite - * - * \param args Arguments for the text sprite - */ - - template - TextSpriteRef TextSprite::New(Args&&... args) - { - std::unique_ptr object(new TextSprite(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/TextureBackground.hpp b/include/Nazara/Graphics/TextureBackground.hpp deleted file mode 100644 index 788968c47..000000000 --- a/include/Nazara/Graphics/TextureBackground.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_TEXTUREBACKGROUND_HPP -#define NAZARA_TEXTUREBACKGROUND_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class TextureBackground; - - using TextureBackgroundConstRef = ObjectRef; - using TextureBackgroundRef = ObjectRef; - - class NAZARA_GRAPHICS_API TextureBackground : public AbstractBackground - { - public: - TextureBackground(TextureRef texture = TextureRef()); - - void Draw(const AbstractViewer* viewer) const override; - - BackgroundType GetBackgroundType() const override; - inline const TextureRef& GetTexture() const; - - inline void SetTexture(TextureRef texture); - - template static TextureBackgroundRef New(Args&&... args); - - private: - TextureRef m_texture; - UberShaderConstRef m_uberShader; - const UberShaderInstance* m_uberShaderInstance; - int m_materialDiffuseUniform; - int m_materialDiffuseMapUniform; - int m_vertexDepthUniform; - }; -} - -#include - -#endif // NAZARA_TEXTUREBACKGROUND_HPP diff --git a/include/Nazara/Graphics/TextureBackground.inl b/include/Nazara/Graphics/TextureBackground.inl deleted file mode 100644 index 24ec19af8..000000000 --- a/include/Nazara/Graphics/TextureBackground.inl +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \brief Gets the texture of the background - * \return Texture of the background - */ - - inline const TextureRef& TextureBackground::GetTexture() const - { - return m_texture; - } - - /*! - * \brief Sets the texture of the background - * - * \param texture Texture of the background - */ - - inline void TextureBackground::SetTexture(TextureRef texture) - { - NazaraAssert(!texture || texture->IsValid(), "Invalid texture"); - - m_texture = std::move(texture); - } - - /*! - * \brief Creates a new texture background from the arguments - * \return A reference to the newly created texture background - * - * \param args Arguments for the texture background - */ - - template - TextureBackgroundRef TextureBackground::New(Args&&... args) - { - std::unique_ptr object(new TextureBackground(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/Nazara/Graphics/TileMap.hpp b/include/Nazara/Graphics/TileMap.hpp deleted file mode 100644 index e1e105206..000000000 --- a/include/Nazara/Graphics/TileMap.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_TILEMAP_HPP -#define NAZARA_TILEMAP_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class TileMap; - - using TileMapConstRef = ObjectRef; - using TileMapLibrary = ObjectLibrary; - using TileMapRef = ObjectRef; - - class NAZARA_GRAPHICS_API TileMap : public InstancedRenderable - { - friend TileMapLibrary; - friend class Graphics; - - public: - struct Tile; - - inline TileMap(const Nz::Vector2ui& mapSize, const Nz::Vector2f& tileSize, std::size_t materialCount = 1); - TileMap(const TileMap&) = default; - TileMap(TileMap&&) = delete; - ~TileMap() = default; - - void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override; - - std::unique_ptr Clone() const override; - - inline void DisableTile(const Vector2ui& tilePos); - inline void DisableTiles(); - inline void DisableTiles(const Vector2ui* tilesPos, std::size_t tileCount); - - inline void EnableIsometricMode(bool isometric); - - inline void EnableTile(const Vector2ui& tilePos, const Rectf& coords, const Color& color = Color::White, std::size_t materialIndex = 0U); - inline void EnableTile(const Vector2ui& tilePos, const Rectui& rect, const Color& color = Color::White, std::size_t materialIndex = 0U); - inline void EnableTiles(const Rectf& coords, const Color& color = Color::White, std::size_t materialIndex = 0U); - inline void EnableTiles(const Rectui& rect, const Color& color = Color::White, std::size_t materialIndex = 0U); - inline void EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectf& coords, const Color& color = Color::White, std::size_t materialIndex = 0U); - inline void EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectui& rect, const Color& color = Color::White, std::size_t materialIndex = 0U); - - inline const Vector2ui& GetMapSize() const; - inline Vector2f GetSize() const; - inline const Tile& GetTile(const Vector2ui& tilePos) const; - inline const Vector2f& GetTileSize() const; - - inline bool IsIsometricModeEnabled() const; - - using InstancedRenderable::SetMaterial; - - inline TileMap& operator=(const TileMap& TileMap); - TileMap& operator=(TileMap&& TileMap) = delete; - - template static TileMapRef New(Args&&... args); - - struct Tile - { - std::size_t layerIndex = 0U; - Color color = Color::White; - Rectf textureCoords = Rectf::Zero(); - bool enabled = false; - }; - - private: - void MakeBoundingVolume() const override; - void UpdateData(InstanceData* instanceData) const override; - - static bool Initialize(); - static void Uninitialize(); - - struct Layer - { - std::set tiles; - }; - - std::vector m_tiles; - std::vector m_layers; - Vector2ui m_mapSize; - Vector2f m_tileSize; - bool m_isometricModeEnabled; - - static TileMapLibrary::LibraryMap s_library; - }; -} - -#include - -#endif // NAZARA_TILEMAP_HPP diff --git a/include/Nazara/Graphics/TileMap.inl b/include/Nazara/Graphics/TileMap.inl deleted file mode 100644 index d363844eb..000000000 --- a/include/Nazara/Graphics/TileMap.inl +++ /dev/null @@ -1,435 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \brief Constructs a TileMap object, containing mapSize tileSize-sized tiles - * - * \param mapSize Number of tiles in each dimension, must be - * \param tileSize Size of each tile of the TileMap - * \param materialCount The maximum number of differents Material this TileMap will use - * - * \remark When constructed, a TileMap has no tile active and will not be rendered - * To use it, you have to enable some tiles. - * - * \remark The default material is used for every material requested - */ - inline TileMap::TileMap(const Nz::Vector2ui& mapSize, const Nz::Vector2f& tileSize, std::size_t materialCount) : - m_tiles(mapSize.x * mapSize.y), - m_layers(materialCount), - m_mapSize(mapSize), - m_tileSize(tileSize), - m_isometricModeEnabled(false) - { - NazaraAssert(m_tiles.size() != 0U, "Invalid map size"); - NazaraAssert(m_tileSize.x > 0 && m_tileSize.y > 0, "Invalid tile size"); - NazaraAssert(m_layers.size() != 0U, "Invalid material count"); - - ResetMaterials(materialCount); - - InvalidateBoundingVolume(); - } - - /*! - * \brief Disable the tile at position tilePos, disabling rendering at this location - * - * \param tilePos Position of the tile to disable - * - * \see DisableTiles - */ - inline void TileMap::DisableTile(const Vector2ui& tilePos) - { - NazaraAssert(tilePos.x < m_mapSize.x && tilePos.y < m_mapSize.y, "Tile position is out of bounds"); - - std::size_t tileIndex = tilePos.y * m_mapSize.x + tilePos.x; - Tile& tile = m_tiles[tileIndex]; - tile.enabled = false; - - m_layers[tile.layerIndex].tiles.erase(tileIndex); - - InvalidateInstanceData(1U << tile.layerIndex); - } - - /*! - * \brief Disable all tiles - */ - inline void TileMap::DisableTiles() - { - for (Tile& tile : m_tiles) - tile.enabled = false; - - for (Layer& layer : m_layers) - layer.tiles.clear(); - - InvalidateInstanceData(0xFFFFFFFF); - } - - /*! - * \brief Disable tileCount tiles at positions contained at tilesPos location, disabling rendering at those locations - * - * This is equivalent to calling tileCount times DisableTile with the positions contained at tilesPos - * - * \param tilesPos Pointer to a valid array of at least tileCount positions - * \param tileCount Number of tiles to disable - * - * \remark if tileCount is zero, this is a no-op and the value of tilesPos is not used - * - * \see DisableTile - */ - inline void TileMap::DisableTiles(const Vector2ui* tilesPos, std::size_t tileCount) - { - NazaraAssert(tilesPos || tileCount == 0, "Invalid tile position array with a non-zero tileCount"); - - UInt32 invalidatedLayers = 0; - - for (std::size_t i = 0; i < tileCount; ++i) - { - NazaraAssert(tilesPos->x < m_mapSize.x && tilesPos->y < m_mapSize.y, "Tile position is out of bounds"); - - std::size_t tileIndex = tilesPos->y * m_mapSize.x + tilesPos->x; - Tile& tile = m_tiles[tileIndex]; - tile.enabled = false; - - m_layers[tile.layerIndex].tiles.erase(tileIndex); - - invalidatedLayers |= 1U << tile.layerIndex; - - tilesPos++; - } - - if (tileCount > 0) - InvalidateInstanceData(invalidatedLayers); - } - - /*! - * \brief Enable/Disable isometric mode - * - * If enabled, every odd line will overlap by half the tile size with the upper line - * - * \param isometric Should the isometric mode be enabled for this TileMap - * - * \see IsIsometricModeEnabled - */ - inline void TileMap::EnableIsometricMode(bool isometric) - { - m_isometricModeEnabled = isometric; - - InvalidateInstanceData(0xFFFFFFFF); - } - - /*! - * \brief Enable and sets the tile at position tilePos - * - * Setup the tile at position tilePos using color, normalized coordinates coords and materialIndex - * - * \param tilePos Position of the tile to enable - * \param coords Normalized coordinates ([0..1]) used to specify which region of the material textures will be used - * \param color The multiplicative color applied to the tile - * \param materialIndex The material which will be used for rendering this tile - * - * \see EnableTiles - */ - inline void TileMap::EnableTile(const Vector2ui& tilePos, const Rectf& coords, const Color& color, std::size_t materialIndex) - { - NazaraAssert(tilePos.x < m_mapSize.x && tilePos.y < m_mapSize.y, "Tile position is out of bounds"); - NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds"); - - UInt32 invalidatedLayers = 1U << materialIndex; - - std::size_t tileIndex = tilePos.y * m_mapSize.x + tilePos.x; - Tile& tile = m_tiles[tilePos.y * m_mapSize.x + tilePos.x]; - - if (!tile.enabled) - m_layers[materialIndex].tiles.insert(tileIndex); - else if (materialIndex != tile.layerIndex) - { - m_layers[tile.layerIndex].tiles.erase(tileIndex); - m_layers[materialIndex].tiles.insert(tileIndex); - - invalidatedLayers |= 1U << tile.layerIndex; - } - - tile.enabled = true; - tile.color = color; - tile.textureCoords = coords; - tile.layerIndex = materialIndex; - - InvalidateInstanceData(invalidatedLayers); - } - - /*! - * \brief Enable and sets the tile at position tilePos - * - * Setup the tile at position tilePos using color, unnormalized coordinates rect and materialIndex - * - * \param tilePos Position of the tile to enable - * \param coords Unnormalized coordinates ([0..size]) used to specify which region of the material textures will be used - * \param color The multiplicative color applied to the tile - * \param materialIndex The material which will be used for rendering this tile - * - * \remark The material at [materialIndex] must have a valid diffuse map before using this function, - * as the size of the material diffuse map is used to compute normalized texture coordinates before returning. - * - * \see EnableTiles - */ - inline void TileMap::EnableTile(const Vector2ui& tilePos, const Rectui& rect, const Color& color, std::size_t materialIndex) - { - NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds"); - - const MaterialRef& material = GetMaterial(materialIndex); - NazaraAssert(material->HasDiffuseMap(), "Material has no diffuse map"); - - Texture* diffuseMap = material->GetDiffuseMap(); - float invWidth = 1.f / diffuseMap->GetWidth(); - float invHeight = 1.f / diffuseMap->GetHeight(); - - Rectf unnormalizedCoords(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height); - EnableTile(tilePos, unnormalizedCoords, color, materialIndex); - } - - /*! - * \brief Enable and sets all the tiles - * - * Setup all tiles using color, normalized coordinates coords and materialIndex - * - * \param coords Normalized coordinates ([0..1]) used to specify which region of the material textures will be used - * \param color The multiplicative color applied to the tile - * \param materialIndex The material which will be used for rendering this tile - * - * \remark The material at [materialIndex] must have a valid diffuse map before using this function, - * as the size of the material diffuse map is used to compute normalized texture coordinates before returning. - * - * \see EnableTile - */ - inline void TileMap::EnableTiles(const Rectf& coords, const Color& color, std::size_t materialIndex) - { - NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds"); - - for (Layer& layer : m_layers) - layer.tiles.clear(); - - std::size_t tileIndex = 0; - for (Tile& tile : m_tiles) - { - tile.enabled = true; - tile.color = color; - tile.textureCoords = coords; - tile.layerIndex = materialIndex; - - m_layers[materialIndex].tiles.insert(tileIndex++); - } - - InvalidateInstanceData(0xFFFFFFFF); - } - - /*! - * \brief Enable and sets all the tiles - * - * Setup all tiles using color, unnormalized coordinates coords and materialIndex - * - * \param coords Unnormalized coordinates ([0..size]) used to specify which region of the material textures will be used - * \param color The multiplicative color applied to the tile - * \param materialIndex The material which will be used for rendering this tile - * - * \remark The material at [materialIndex] must have a valid diffuse map before using this function, - * as the size of the material diffuse map is used to compute normalized texture coordinates before returning. - * - * \see EnableTile - */ - inline void TileMap::EnableTiles(const Rectui& rect, const Color& color, std::size_t materialIndex) - { - NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds"); - - Texture* diffuseMap = GetMaterial(materialIndex)->GetDiffuseMap(); - float invWidth = 1.f / diffuseMap->GetWidth(); - float invHeight = 1.f / diffuseMap->GetHeight(); - - Rectf unnormalizedCoords(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height); - EnableTiles(unnormalizedCoords, color, materialIndex); - } - - /*! - * \brief Enable and sets tileCount tiles at positions contained at tilesPos location, enabling rendering at those locations - * - * Setup all tiles using color, normalized coordinates coords and materialIndex - * - * \param tilesPos Pointer to a valid array of at least tileCount positions - * \param tileCount Number of tiles to enable - * \param coords Normalized coordinates ([0..1]) used to specify which region of the material textures will be used - * \param color The multiplicative color applied to the tile - * \param materialIndex The material which will be used for rendering this tile - * - * \see EnableTile - */ - inline void TileMap::EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectf& coords, const Color& color, std::size_t materialIndex) - { - NazaraAssert(tilesPos || tileCount == 0, "Invalid tile position array with a non-zero tileCount"); - NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds"); - - UInt32 invalidatedLayers = 1U << materialIndex; - - for (std::size_t i = 0; i < tileCount; ++i) - { - NazaraAssert(tilesPos->x < m_mapSize.x && tilesPos->y < m_mapSize.y, "Tile position is out of bounds"); - - std::size_t tileIndex = tilesPos->y * m_mapSize.x + tilesPos->x; - Tile& tile = m_tiles[tileIndex]; - - if (!tile.enabled) - m_layers[materialIndex].tiles.insert(tileIndex); - else if (materialIndex != tile.layerIndex) - { - m_layers[tile.layerIndex].tiles.erase(tileIndex); - m_layers[materialIndex].tiles.insert(tileIndex); - - invalidatedLayers |= 1U << tile.layerIndex; - } - - tile.enabled = true; - tile.color = color; - tile.textureCoords = coords; - tile.layerIndex = materialIndex; - tilesPos++; - } - - if (tileCount > 0) - InvalidateInstanceData(invalidatedLayers); - } - - /*! - * \brief Enable and sets tileCount tiles at positions contained at tilesPos location, enabling rendering at those locations - * - * Setup all tiles using color, unnormalized coordinates coords and materialIndex - * - * \param tilesPos Pointer to a valid array of at least tileCount positions - * \param tileCount Number of tiles to enable - * \param coords Unnormalized coordinates ([0..size]) used to specify which region of the material textures will be used - * \param color The multiplicative color applied to the tile - * \param materialIndex The material which will be used for rendering this tile - * - * \remark The material at [materialIndex] must have a valid diffuse map before using this function, - * as the size of the material diffuse map is used to compute normalized texture coordinates before returning. - * - * \see EnableTile - */ - inline void TileMap::EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectui& rect, const Color& color, std::size_t materialIndex) - { - NazaraAssert(materialIndex < m_layers.size(), "Material out of bounds"); - - const MaterialRef& material = GetMaterial(materialIndex); - NazaraAssert(material->HasDiffuseMap(), "Material has no diffuse map"); - - Texture* diffuseMap = material->GetDiffuseMap(); - float invWidth = 1.f / diffuseMap->GetWidth(); - float invHeight = 1.f / diffuseMap->GetHeight(); - - Rectf unnormalizedCoords(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height); - EnableTiles(tilesPos, tileCount, unnormalizedCoords, color, materialIndex); - } - - /*! - * \brief Gets the tilemap size (i.e. number of tiles in each dimension) - * \return Number of tiles in each dimension - * - * \see GetSize - * \see GetTileSize - */ - inline const Vector2ui& TileMap::GetMapSize() const - { - return m_mapSize; - } - - /*! - * \brief Returns the size of the tilemap in units (which is equivalent to GetMapSize() * GetTileSize()) - * \return Maximum size in units occupied by this tilemap - * - * \see GetMapSize - * \see GetTileSize - */ - inline Vector2f TileMap::GetSize() const - { - return Vector2f(m_mapSize) * m_tileSize; - } - - /*! - * \brief Returns informations about a particular tile - * - * \param tilePos Position of the tile to get (enabled or not) - * - * \return Maximum size in units occupied by this tilemap - */ - inline const TileMap::Tile& TileMap::GetTile(const Vector2ui& tilePos) const - { - NazaraAssert(tilePos.x < m_mapSize.x && tilePos.y < m_mapSize.y, "Tile position is out of bounds"); - - return m_tiles[tilePos.y * m_mapSize.x + tilePos.x]; - } - - /*! - * \brief Gets the tile size (i.e. number of units occupied by a tile in each dimension) - * \return Tile size in each dimension - * - * \see GetMapSize - * \see GetSize - */ - inline const Vector2f& TileMap::GetTileSize() const - { - return m_tileSize; - } - - /*! - * \brief Gets the actual state of the isometric mode - * \return True if the isometric mode is enabled - * - * \see EnableIsometricMode - */ - inline bool TileMap::IsIsometricModeEnabled() const - { - return m_isometricModeEnabled; - } - - /*! - * \brief Sets the current TileMap with the content of the other one - * \return A reference to this - * - * \param TileMap The other TileMap - */ - inline TileMap& TileMap::operator=(const TileMap& tileMap) - { - InstancedRenderable::operator=(tileMap); - - m_layers = tileMap.m_layers; - m_mapSize = tileMap.m_mapSize; - m_tiles = tileMap.m_tiles; - m_tileSize = tileMap.m_tileSize; - - // We do not copy final vertices because it's highly probable that our parameters are modified and they must be regenerated - InvalidateBoundingVolume(); - InvalidateInstanceData(0xFFFFFFFF); - - return *this; - } - - /*! - * \brief Creates a new TileMap from the arguments - * \return A reference to the newly created TileMap - * - * \param args Arguments for the TileMap - */ - template - TileMapRef TileMap::New(Args&&... args) - { - std::unique_ptr object(new TileMap(std::forward(args)...)); - object->SetPersistent(false); - - return object.release(); - } -} - -#include diff --git a/include/NazaraSDK/Application.hpp b/include/NazaraSDK/Application.hpp index 707677552..1ae04a520 100644 --- a/include/NazaraSDK/Application.hpp +++ b/include/NazaraSDK/Application.hpp @@ -15,11 +15,7 @@ #include #ifndef NDK_SERVER -#include -#include #include -#include -#include #include #endif @@ -28,11 +24,6 @@ namespace Ndk class NDK_API Application { public: - #ifndef NDK_SERVER - struct ConsoleOverlay; - struct FPSCounterOverlay; - #endif - inline Application(); Application(int argc, char* argv[]); Application(const Application&) = delete; @@ -44,14 +35,6 @@ namespace Ndk #endif template World& AddWorld(Args&&... args); - #ifndef NDK_SERVER - inline void EnableConsole(bool enable); - inline void EnableFPSCounter(bool enable); - - inline ConsoleOverlay& GetConsoleOverlay(std::size_t windowIndex = 0U); - inline FPSCounterOverlay& GetFPSCounterOverlay(std::size_t windowIndex = 0U); - #endif - inline const std::set& GetOptions() const; inline const std::map& GetParameters() const; @@ -78,53 +61,15 @@ namespace Ndk inline static Application* Instance(); - #ifndef NDK_SERVER - struct ConsoleOverlay - { - Console* console; - - NazaraSlot(Nz::EventHandler, OnEvent, eventSlot); - NazaraSlot(Nz::EventHandler, OnKeyPressed, keyPressedSlot); - NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, resizedSlot); - NazaraSlot(Nz::Log, OnLogWrite, logSlot); - }; - - struct FPSCounterOverlay - { - Nz::TextSpriteRef sprite; - EntityOwner entity; - float elapsedTime = 0.f; - unsigned int frameCount = 0; - }; - #endif - private: #ifndef NDK_SERVER - enum OverlayFlags - { - OverlayFlags_Console = 0x1, - OverlayFlags_FPSCounter = 0x2 - }; - struct WindowInfo { inline WindowInfo(std::unique_ptr&& window); - Nz::RenderTarget* renderTarget; std::unique_ptr window; - std::unique_ptr console; - std::unique_ptr canvas; - std::unique_ptr fpsCounter; - std::unique_ptr overlayWorld; }; - void SetupConsole(WindowInfo& info); - void SetupFPSCounter(WindowInfo& info); - void SetupOverlay(WindowInfo& info); - - template void SetupWindow(WindowInfo& info, T* renderTarget, std::true_type /*isRenderTarget*/); - template void SetupWindow(WindowInfo& /*info*/, T* /*renderTarget*/, std::false_type /*isNotRenderTarget*/); - std::vector m_windows; #endif @@ -134,7 +79,6 @@ namespace Ndk Nz::Clock m_updateClock; #ifndef NDK_SERVER - Nz::UInt32 m_overlayFlags; bool m_exitOnClosedWindows; #endif bool m_shouldQuit; diff --git a/include/NazaraSDK/Application.inl b/include/NazaraSDK/Application.inl index 7adf9ea0f..d74378cfd 100644 --- a/include/NazaraSDK/Application.inl +++ b/include/NazaraSDK/Application.inl @@ -16,7 +16,6 @@ namespace Ndk */ inline Application::Application() : #ifndef NDK_SERVER - m_overlayFlags(0U), m_exitOnClosedWindows(true), #endif m_shouldQuit(false), @@ -65,11 +64,7 @@ namespace Ndk m_windows.emplace_back(std::make_unique(std::forward(args)...)); WindowInfo& info = m_windows.back(); - T& window = static_cast(*info.window.get()); //< Warning: ugly - - SetupWindow(info, &window, std::is_base_of()); - - return window; + return static_cast(*info.window.get()); //< Warning: ugly } #endif @@ -87,133 +82,6 @@ namespace Ndk return m_worlds.back(); } - /*! - * \brief Enable/disable debug console - * - * \param enable Should the console overlay be enabled - */ - #ifndef NDK_SERVER - inline void Application::EnableConsole(bool enable) - { - if (enable != ((m_overlayFlags & OverlayFlags_Console) != 0)) - { - if (enable) - { - if (m_overlayFlags == 0) - { - for (WindowInfo& info : m_windows) - SetupOverlay(info); - } - - for (WindowInfo& info : m_windows) - { - if (info.renderTarget) - SetupConsole(info); - } - - m_overlayFlags |= OverlayFlags_Console; - } - else - { - for (WindowInfo& info : m_windows) - info.console.reset(); - - m_overlayFlags &= ~OverlayFlags_Console; - if (m_overlayFlags == 0) - { - for (WindowInfo& info : m_windows) - info.overlayWorld.reset(); - } - } - } - } - #endif - - /*! - * \brief Enable/disable debug FPS counter - * - * \param enable Should the FPS counter be displayed - */ - #ifndef NDK_SERVER - inline void Application::EnableFPSCounter(bool enable) - { - if (enable != ((m_overlayFlags & OverlayFlags_FPSCounter) != 0)) - { - if (enable) - { - if (m_overlayFlags == 0) - { - for (WindowInfo& info : m_windows) - SetupOverlay(info); - } - - for (WindowInfo& info : m_windows) - { - if (info.renderTarget) - SetupFPSCounter(info); - } - - m_overlayFlags |= OverlayFlags_FPSCounter; - - } - else - { - for (WindowInfo& info : m_windows) - info.fpsCounter.reset(); - - m_overlayFlags &= ~OverlayFlags_FPSCounter; - if (m_overlayFlags == 0) - { - for (WindowInfo& info : m_windows) - info.overlayWorld.reset(); - } - } - } - } - #endif - - /*! - * \brief Gets the console overlay for a specific window - * - * \param windowIndex Index of the window to get - * - * \remark The console overlay must be enabled - * - * \return A reference to the console overlay of the window - * - * \see IsConsoleOverlayEnabled - */ - #ifndef NDK_SERVER - inline Application::ConsoleOverlay& Application::GetConsoleOverlay(std::size_t windowIndex) - { - NazaraAssert(m_overlayFlags & OverlayFlags_Console, "Console overlay is not enabled"); - NazaraAssert(windowIndex <= m_windows.size(), "Window index is out of range"); - - return *m_windows[windowIndex].console; - } - #endif - - /*! - * \brief Gets the console overlay for a specific window - * - * \param windowIndex Index of the window to get - * - * \remark The console overlay must be enabled - * - * \return A reference to the console overlay of the window - * - * \see IsFPSCounterEnabled - */ - #ifndef NDK_SERVER - inline Application::FPSCounterOverlay& Application::GetFPSCounterOverlay(std::size_t windowIndex) - { - NazaraAssert(m_overlayFlags & OverlayFlags_FPSCounter, "FPS counter overlay is not enabled"); - NazaraAssert(windowIndex <= m_windows.size(), "Window index is out of range"); - - return *m_windows[windowIndex].fpsCounter; - } - #endif - /*! * \brief Gets the options used to start the application * @@ -287,35 +155,6 @@ namespace Ndk return true; } - /*! - * \brief Checks if the console overlay is enabled - * - * \remark This has nothing to do with the visibility state of the console - * - * \return True if the console overlay is enabled - * - * \see GetConsoleOverlay - */ - #ifndef NDK_SERVER - inline bool Application::IsConsoleEnabled() const - { - return (m_overlayFlags & OverlayFlags_Console) != 0; - } - #endif - - /*! - * \brief Checks if the FPS counter overlay is enabled - * \return True if the FPS counter overlay is enabled - * - * \see GetFPSCounterOverlay - */ - #ifndef NDK_SERVER - inline bool Application::IsFPSCounterEnabled() const - { - return (m_overlayFlags & OverlayFlags_FPSCounter) != 0; - } - #endif - /*! * \brief Makes the application exit when there's no more open window * @@ -348,30 +187,7 @@ namespace Ndk } #ifndef NDK_SERVER - template - inline void Application::SetupWindow(WindowInfo& info, T* renderTarget, std::true_type) - { - info.renderTarget = renderTarget; - - if (m_overlayFlags) - { - SetupOverlay(info); - - if (m_overlayFlags & OverlayFlags_Console) - SetupConsole(info); - - if (m_overlayFlags & OverlayFlags_FPSCounter) - SetupFPSCounter(info); - } - } - - template - inline void Application::SetupWindow(WindowInfo&, T*, std::false_type) - { - } - inline Application::WindowInfo::WindowInfo(std::unique_ptr&& windowPtr) : - renderTarget(nullptr), window(std::move(windowPtr)) { } diff --git a/include/NazaraSDK/BaseWidget.hpp b/include/NazaraSDK/BaseWidget.hpp deleted file mode 100644 index b9f0ec98c..000000000 --- a/include/NazaraSDK/BaseWidget.hpp +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_BASEWIDGET_HPP -#define NDK_BASEWIDGET_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - class Canvas; - - class NDK_API BaseWidget : public Nz::Node - { - friend Canvas; - - public: - BaseWidget(BaseWidget* parent); - BaseWidget(const BaseWidget&) = delete; - BaseWidget(BaseWidget&&) = delete; - virtual ~BaseWidget(); - - template T* Add(Args&&... args); - inline void AddChild(std::unique_ptr&& widget); - - inline void Center(); - inline void CenterHorizontal(); - inline void CenterVertical(); - - void ClearFocus(); - inline void ClearRenderingRect(); - - void Destroy(); - - void EnableBackground(bool enable); - - template void ForEachWidgetChild(F iterator); - template void ForEachWidgetChild(F iterator) const; - - //virtual BaseWidget* Clone() const = 0; - - inline const Nz::Color& GetBackgroundColor() const; - inline Canvas* GetCanvas(); - inline Nz::SystemCursor GetCursor() const; - inline float GetHeight() const; - - inline float GetMaximumHeight() const; - inline Nz::Vector2f GetMaximumSize() const; - inline float GetMaximumWidth() const; - - inline float GetMinimumHeight() const; - inline Nz::Vector2f GetMinimumSize() const; - inline float GetMinimumWidth() const; - - inline float GetPreferredHeight() const; - inline Nz::Vector2f GetPreferredSize() const; - inline float GetPreferredWidth() const; - - inline const Nz::Rectf& GetRenderingRect() const; - - inline Nz::Vector2f GetSize() const; - inline float GetWidth() const; - inline std::size_t GetWidgetChildCount() const; - - bool HasFocus() const; - - inline void Hide(); - inline bool IsVisible() const; - - void Resize(const Nz::Vector2f& size); - - void SetBackgroundColor(const Nz::Color& color); - void SetCursor(Nz::SystemCursor systemCursor); - void SetFocus(); - void SetParent(BaseWidget* widget); - - inline void SetFixedHeight(float fixedHeight); - inline void SetFixedSize(const Nz::Vector2f& fixedSize); - inline void SetFixedWidth(float fixedWidth); - - inline void SetMaximumHeight(float maximumHeight); - inline void SetMaximumSize(const Nz::Vector2f& maximumSize); - inline void SetMaximumWidth(float maximumWidth); - - inline void SetMinimumHeight(float minimumHeight); - inline void SetMinimumSize(const Nz::Vector2f& minimumSize); - inline void SetMinimumWidth(float minimumWidth); - - virtual void SetRenderingRect(const Nz::Rectf& renderingRect); - - void Show(bool show = true); - - BaseWidget& operator=(const BaseWidget&) = delete; - BaseWidget& operator=(BaseWidget&&) = delete; - - protected: - const EntityHandle& CreateEntity(); - void DestroyEntity(Entity* entity); - virtual void Layout(); - - void InvalidateNode() override; - - Nz::Rectf GetScissorRect() const; - - virtual bool IsFocusable() const; - virtual void OnFocusLost(); - virtual void OnFocusReceived(); - virtual bool OnKeyPressed(const Nz::WindowEvent::KeyEvent& key); - virtual void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key); - virtual void OnMouseEnter(); - virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY); - virtual void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button); - virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button); - virtual void OnMouseWheelMoved(int x, int y, float delta); - virtual void OnMouseExit(); - virtual void OnParentResized(const Nz::Vector2f& newSize); - virtual void OnTextEntered(char32_t character, bool repeated); - virtual void OnTextEdited(const std::array& characters, int length); - - inline void SetPreferredSize(const Nz::Vector2f& preferredSize); - - virtual void ShowChildren(bool show); - - private: - inline BaseWidget(); - - void DestroyChild(BaseWidget* widget); - void DestroyChildren(); - inline bool IsRegisteredToCanvas() const; - inline void NotifyParentResized(const Nz::Vector2f& newSize); - void RegisterToCanvas(); - inline void UpdateCanvasIndex(std::size_t index); - void UnregisterFromCanvas(); - void UpdatePositionAndSize(); - - struct WidgetEntity - { - EntityOwner handle; - bool isEnabled = true; - - NazaraSlot(Ndk::Entity, OnEntityDisabled, onDisabledSlot); - NazaraSlot(Ndk::Entity, OnEntityEnabled, onEnabledSlot); - }; - - static constexpr std::size_t InvalidCanvasIndex = std::numeric_limits::max(); - - std::size_t m_canvasIndex; - std::vector m_entities; - std::vector> m_children; - Canvas* m_canvas; - EntityOwner m_backgroundEntity; - WorldHandle m_world; - Nz::Color m_backgroundColor; - Nz::Rectf m_renderingRect; - Nz::SpriteRef m_backgroundSprite; - Nz::SystemCursor m_cursor; - Nz::Vector2f m_maximumSize; - Nz::Vector2f m_minimumSize; - Nz::Vector2f m_preferredSize; - Nz::Vector2f m_size; - BaseWidget* m_widgetParent; - bool m_visible; - }; -} - -#include - -#endif // NDK_BASEWIDGET_HPP diff --git a/include/NazaraSDK/BaseWidget.inl b/include/NazaraSDK/BaseWidget.inl deleted file mode 100644 index 7dbfd2c78..000000000 --- a/include/NazaraSDK/BaseWidget.inl +++ /dev/null @@ -1,275 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include - -namespace Ndk -{ - inline BaseWidget::BaseWidget() : - m_canvasIndex(InvalidCanvasIndex), - m_canvas(nullptr), - m_backgroundColor(Nz::Color(230, 230, 230, 255)), - m_renderingRect(-std::numeric_limits::infinity(), -std::numeric_limits::infinity(), std::numeric_limits::infinity(), std::numeric_limits::infinity()), - m_cursor(Nz::SystemCursor_Default), - m_maximumSize(std::numeric_limits::infinity()), - m_minimumSize(0.f), - m_preferredSize(-1), - m_size(50.f, 50.f), - m_widgetParent(nullptr), - m_visible(true) - { - } - - template - inline T* BaseWidget::Add(Args&&... args) - { - std::unique_ptr widget = std::make_unique(this, std::forward(args)...); - T* widgetPtr = widget.get(); - AddChild(std::move(widget)); - - return widgetPtr; - } - - inline void BaseWidget::AddChild(std::unique_ptr&& widget) - { - widget->Show(m_visible); - widget->SetParent(this); - m_children.emplace_back(std::move(widget)); - } - - inline void BaseWidget::Center() - { - NazaraAssert(m_widgetParent, "Widget has no parent"); - - Nz::Vector2f parentSize = m_widgetParent->GetSize(); - Nz::Vector2f mySize = GetSize(); - SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f); - } - - inline void BaseWidget::CenterHorizontal() - { - NazaraAssert(m_widgetParent, "Widget has no parent"); - - Nz::Vector2f parentSize = m_widgetParent->GetSize(); - Nz::Vector2f mySize = GetSize(); - SetPosition((parentSize.x - mySize.x) / 2.f, GetPosition(Nz::CoordSys_Local).y); - } - - inline void BaseWidget::CenterVertical() - { - NazaraAssert(m_widgetParent, "Widget has no parent"); - - Nz::Vector2f parentSize = m_widgetParent->GetSize(); - Nz::Vector2f mySize = GetSize(); - SetPosition(GetPosition(Nz::CoordSys_Local).x, (parentSize.y - mySize.y) / 2.f); - } - - inline void BaseWidget::ClearRenderingRect() - { - SetRenderingRect(Nz::Rectf(-std::numeric_limits::infinity(), -std::numeric_limits::infinity(), std::numeric_limits::infinity(), std::numeric_limits::infinity())); - } - - template - inline void BaseWidget::ForEachWidgetChild(F iterator) - { - for (const auto& child : m_children) - iterator(child.get()); - } - - template - inline void BaseWidget::ForEachWidgetChild(F iterator) const - { - for (const auto& child : m_children) - iterator(static_cast(child.get())); - } - - inline const Nz::Color& BaseWidget::GetBackgroundColor() const - { - return m_backgroundColor; - } - - inline Canvas* BaseWidget::GetCanvas() - { - return m_canvas; - } - - inline Nz::SystemCursor BaseWidget::GetCursor() const - { - return m_cursor; - } - - inline float BaseWidget::GetHeight() const - { - return m_size.y; - } - - inline float BaseWidget::GetMaximumHeight() const - { - return m_maximumSize.y; - } - - inline Nz::Vector2f BaseWidget::GetMaximumSize() const - { - return m_maximumSize; - } - - inline float BaseWidget::GetMaximumWidth() const - { - return m_maximumSize.x; - } - - inline float BaseWidget::GetMinimumHeight() const - { - return m_minimumSize.y; - } - - inline Nz::Vector2f BaseWidget::GetMinimumSize() const - { - return m_minimumSize; - } - - inline float BaseWidget::GetMinimumWidth() const - { - return m_minimumSize.x; - } - - inline float BaseWidget::GetPreferredHeight() const - { - return m_preferredSize.y; - } - - inline Nz::Vector2f BaseWidget::GetPreferredSize() const - { - return m_preferredSize; - } - - inline float BaseWidget::GetPreferredWidth() const - { - return m_preferredSize.x; - } - - inline const Nz::Rectf& BaseWidget::GetRenderingRect() const - { - return m_renderingRect; - } - - inline Nz::Vector2f BaseWidget::GetSize() const - { - return Nz::Vector2f(GetWidth(), GetHeight()); - } - - inline float BaseWidget::GetWidth() const - { - return m_size.x; - } - - inline std::size_t BaseWidget::GetWidgetChildCount() const - { - return m_children.size(); - } - - inline void BaseWidget::Hide() - { - return Show(false); - } - - inline bool BaseWidget::IsVisible() const - { - return m_visible; - } - - inline void BaseWidget::SetFixedHeight(float fixedHeight) - { - SetMaximumHeight(fixedHeight); - SetMinimumHeight(fixedHeight); - } - - inline void BaseWidget::SetFixedSize(const Nz::Vector2f& fixedSize) - { - SetMaximumSize(fixedSize); - SetMinimumSize(fixedSize); - } - - inline void BaseWidget::SetFixedWidth(float fixedWidth) - { - SetMaximumWidth(fixedWidth); - SetMinimumWidth(fixedWidth); - } - - inline void BaseWidget::SetMaximumHeight(float maximumHeight) - { - Nz::Vector2f maximumSize = GetMaximumSize(); - maximumSize.y = maximumHeight; - - SetMaximumSize(maximumSize); - } - - inline void BaseWidget::SetMaximumSize(const Nz::Vector2f& maximumSize) - { - m_maximumSize = maximumSize; - - Nz::Vector2f size = GetSize(); - if (size.x > m_maximumSize.x || size.y > m_maximumSize.y) - Resize(size); //< Will clamp automatically - } - - inline void BaseWidget::SetMaximumWidth(float maximumWidth) - { - Nz::Vector2f maximumSize = GetMaximumSize(); - maximumSize.x = maximumWidth; - - SetMaximumSize(maximumSize); - } - - inline void BaseWidget::SetMinimumHeight(float minimumHeight) - { - Nz::Vector2f minimumSize = GetMinimumSize(); - minimumSize.y = minimumHeight; - - SetMinimumSize(minimumSize); - } - - inline void BaseWidget::SetMinimumSize(const Nz::Vector2f& minimumSize) - { - m_minimumSize = minimumSize; - - Nz::Vector2f size = GetSize(); - if (size.x < m_minimumSize.x || size.y < m_minimumSize.y) - Resize(size); //< Will clamp automatically - } - - inline void BaseWidget::SetMinimumWidth(float minimumWidth) - { - Nz::Vector2f minimumSize = GetMinimumSize(); - minimumSize.x = minimumWidth; - - SetMinimumSize(minimumSize); - } - - inline void BaseWidget::SetPreferredSize(const Nz::Vector2f& preferredSize) - { - m_preferredSize = preferredSize; - - //Resize(m_preferredSize); - } - - inline bool BaseWidget::IsRegisteredToCanvas() const - { - return m_canvas && m_canvasIndex != InvalidCanvasIndex; - } - - inline void BaseWidget::NotifyParentResized(const Nz::Vector2f& newSize) - { - for (const auto& widgetPtr : m_children) - widgetPtr->OnParentResized(newSize); - } - - inline void BaseWidget::UpdateCanvasIndex(std::size_t index) - { - m_canvasIndex = index; - } -} diff --git a/include/NazaraSDK/Canvas.hpp b/include/NazaraSDK/Canvas.hpp deleted file mode 100644 index 0ff380468..000000000 --- a/include/NazaraSDK/Canvas.hpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_CANVAS_HPP -#define NDK_CANVAS_HPP - -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API Canvas : public BaseWidget - { - friend BaseWidget; - - public: - struct Padding; - - inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController); - Canvas(const Canvas&) = delete; - Canvas(Canvas&&) = delete; - inline ~Canvas(); - - inline const WorldHandle& GetWorld() const; - - Canvas& operator=(const Canvas&) = delete; - Canvas& operator=(Canvas&&) = delete; - - NazaraSignal(OnUnhandledKeyPressed, const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& /*event*/); - NazaraSignal(OnUnhandledKeyReleased, const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& /*event*/); - - protected: - inline void ClearKeyboardOwner(std::size_t canvasIndex); - - inline bool IsKeyboardOwner(std::size_t canvasIndex) const; - - inline void NotifyWidgetBoxUpdate(std::size_t index); - inline void NotifyWidgetCursorUpdate(std::size_t index); - - std::size_t RegisterWidget(BaseWidget* widget); - - inline void SetKeyboardOwner(std::size_t canvasIndex); - - void UnregisterWidget(std::size_t index); - - private: - void OnEventMouseButtonPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event); - void OnEventMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event); - void OnEventMouseLeft(const Nz::EventHandler* eventHandler); - void OnEventMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event); - void OnEventMouseWheelMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseWheelEvent& event); - void OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event); - void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event); - void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event); - void OnEventTextEdited(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::EditEvent& event); - - struct WidgetEntry - { - BaseWidget* widget; - Nz::Boxf box; - Nz::SystemCursor cursor; - }; - - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); - NazaraSlot(Nz::EventHandler, OnKeyReleased, m_keyReleasedSlot); - NazaraSlot(Nz::EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot); - NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot); - NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot); - NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot); - NazaraSlot(Nz::EventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot); - NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot); - NazaraSlot(Nz::EventHandler, OnTextEdited, m_textEditedSlot); - - std::size_t m_keyboardOwner; - std::size_t m_hoveredWidget; - std::vector m_widgetEntries; - Nz::CursorControllerHandle m_cursorController; - WorldHandle m_world; - }; -} - -#include - -#endif // NDK_CANVAS_HPP diff --git a/include/NazaraSDK/Canvas.inl b/include/NazaraSDK/Canvas.inl deleted file mode 100644 index 8f83a8533..000000000 --- a/include/NazaraSDK/Canvas.inl +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController) : - m_keyboardOwner(InvalidCanvasIndex), - m_hoveredWidget(InvalidCanvasIndex), - m_cursorController(cursorController), - m_world(std::move(world)) - { - m_canvas = this; - m_widgetParent = nullptr; - - // Register ourselves as a widget to handle cursor change - RegisterToCanvas(); - - // Connect to every meaningful event - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, this, &Canvas::OnEventKeyPressed); - m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, this, &Canvas::OnEventKeyReleased); - m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, this, &Canvas::OnEventMouseButtonPressed); - m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnEventMouseButtonRelease); - m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnEventMouseLeft); - m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved); - m_mouseWheelMovedSlot.Connect(eventHandler.OnMouseWheelMoved, this, &Canvas::OnEventMouseWheelMoved); - m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered); - m_textEditedSlot.Connect(eventHandler.OnTextEdited, this, &Canvas::OnEventTextEdited); - } - - inline Canvas::~Canvas() - { - // Destroy children explicitly because they signal us when getting destroyed, and that can't happen after our own destruction - DestroyChildren(); - - // Prevent our parent from trying to call us - m_canvasIndex = InvalidCanvasIndex; - } - - inline const WorldHandle& Canvas::GetWorld() const - { - return m_world; - } - - inline void Canvas::ClearKeyboardOwner(std::size_t canvasIndex) - { - if (m_keyboardOwner == canvasIndex) - SetKeyboardOwner(InvalidCanvasIndex); - } - - inline bool Canvas::IsKeyboardOwner(std::size_t canvasIndex) const - { - return m_keyboardOwner == canvasIndex; - } - - inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index) - { - WidgetEntry& entry = m_widgetEntries[index]; - - Nz::Vector3f pos = entry.widget->GetPosition(Nz::CoordSys_Global); - Nz::Vector2f size = entry.widget->GetSize(); - - entry.box.Set(pos.x, pos.y, pos.z, size.x, size.y, 1.f); - } - - inline void Canvas::NotifyWidgetCursorUpdate(std::size_t index) - { - WidgetEntry& entry = m_widgetEntries[index]; - - entry.cursor = entry.widget->GetCursor(); - if (m_cursorController && m_hoveredWidget == index) - m_cursorController->UpdateCursor(Nz::Cursor::Get(entry.cursor)); - } - - inline void Canvas::SetKeyboardOwner(std::size_t canvasIndex) - { - if (m_keyboardOwner != canvasIndex) - { - if (m_keyboardOwner != InvalidCanvasIndex) - m_widgetEntries[m_keyboardOwner].widget->OnFocusLost(); - - m_keyboardOwner = canvasIndex; - - if (m_keyboardOwner != InvalidCanvasIndex) - m_widgetEntries[m_keyboardOwner].widget->OnFocusReceived(); - } - } -} diff --git a/include/NazaraSDK/Components/CameraComponent.hpp b/include/NazaraSDK/Components/CameraComponent.hpp deleted file mode 100644 index c8be2ec83..000000000 --- a/include/NazaraSDK/Components/CameraComponent.hpp +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_COMPONENTS_CAMERACOMPONENT_HPP -#define NDK_COMPONENTS_CAMERACOMPONENT_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - class CameraComponent; - - using CameraComponentHandle = Nz::ObjectHandle; - - class NDK_API CameraComponent : public Component, public Nz::AbstractViewer - { - public: - inline CameraComponent(); - inline CameraComponent(const CameraComponent& camera); - ~CameraComponent() = default; - - void ApplyView() const override; - - inline void EnsureFrustumUpdate() const; - inline void EnsureProjectionMatrixUpdate() const; - inline void EnsureViewMatrixUpdate() const; - inline void EnsureViewportUpdate() const; - - float GetAspectRatio() const override; - Nz::Vector3f GetEyePosition() const override; - Nz::Vector3f GetForward() const override; - inline float GetFOV() const; - const Nz::Frustumf& GetFrustum() const override; - inline unsigned int GetLayer() const; - const Nz::Matrix4f& GetProjectionMatrix() const override; - inline const Nz::Vector3f& GetProjectionScale() const; - Nz::ProjectionType GetProjectionType() const override; - inline const Nz::Vector2f& GetSize() const; - const Nz::RenderTarget* GetTarget() const override; - inline const Nz::Rectf& GetTargetRegion() const; - const Nz::Matrix4f& GetViewMatrix() const override; - const Nz::Recti& GetViewport() const override; - float GetZFar() const override; - float GetZNear() const override; - - inline void SetFOV(float fov); - void SetLayer(unsigned int layer); - inline void SetProjectionScale(const Nz::Vector3f& scale); - inline void SetProjectionType(Nz::ProjectionType projection); - inline void SetSize(const Nz::Vector2f& size); - inline void SetSize(float width, float height); - inline void SetTarget(const Nz::RenderTarget* renderTarget); - inline void SetTargetRegion(const Nz::Rectf& region); - inline void SetViewport(const Nz::Recti& viewport); - inline void SetZFar(float zFar); - inline void SetZNear(float zNear); - - inline bool UpdateVisibility(std::size_t visibilityHash); - - static ComponentIndex componentIndex; - - private: - inline void InvalidateFrustum() const; - inline void InvalidateProjectionMatrix() const; - inline void InvalidateViewMatrix() const; - inline void InvalidateViewport() const; - - void OnAttached() override; - void OnComponentAttached(BaseComponent& component) override; - void OnComponentDetached(BaseComponent& component) override; - void OnDetached() override; - void OnNodeInvalidated(const Nz::Node* node); - void OnRenderTargetRelease(const Nz::RenderTarget* renderTarget); - void OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget); - - void UpdateFrustum() const; - void UpdateProjectionMatrix() const; - void UpdateViewMatrix() const; - void UpdateViewport() const; - - NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot); - NazaraSlot(Nz::RenderTarget, OnRenderTargetRelease, m_targetReleaseSlot); - NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot); - - std::size_t m_visibilityHash; - Nz::ProjectionType m_projectionType; - mutable Nz::Frustumf m_frustum; - mutable Nz::Matrix4f m_projectionMatrix; - mutable Nz::Matrix4f m_viewMatrix; - Nz::Rectf m_targetRegion; - mutable Nz::Recti m_viewport; - const Nz::RenderTarget* m_target; - Nz::Vector2f m_size; - Nz::Vector3f m_projectionScale; - mutable bool m_frustumUpdated; - mutable bool m_projectionMatrixUpdated; - mutable bool m_viewMatrixUpdated; - mutable bool m_viewportUpdated; - mutable float m_aspectRatio; - float m_fov; - float m_zFar; - float m_zNear; - unsigned int m_layer; - }; -} - -#include - -#endif // NDK_COMPONENTS_CAMERACOMPONENT_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/Components/CameraComponent.inl b/include/NazaraSDK/Components/CameraComponent.inl deleted file mode 100644 index 23ab08896..000000000 --- a/include/NazaraSDK/Components/CameraComponent.inl +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - /*! - * \brief Constructs an CameraComponent object by default - */ - - inline CameraComponent::CameraComponent() : - m_visibilityHash(0U), - m_projectionType(Nz::ProjectionType_Perspective), - m_targetRegion(0.f, 0.f, 1.f, 1.f), - m_target(nullptr), - m_size(0.f), - m_projectionScale(1.f, 1.f, 1.f), - m_frustumUpdated(false), - m_projectionMatrixUpdated(false), - m_viewMatrixUpdated(false), - m_viewportUpdated(false), - m_aspectRatio(0.f), - m_fov(70.f), - m_zFar(100.f), - m_zNear(1.f), - m_layer(0) - { - } - - /*! - * \brief Constructs a CameraComponent object by copy semantic - * - * \param camera CameraComponent to copy - */ - - inline CameraComponent::CameraComponent(const CameraComponent& camera) : - Component(camera), - AbstractViewer(camera), - m_visibilityHash(camera.m_visibilityHash), - m_projectionType(camera.m_projectionType), - m_targetRegion(camera.m_targetRegion), - m_target(nullptr), - m_size(camera.m_size), - m_projectionScale(camera.m_projectionScale), - m_frustumUpdated(false), - m_projectionMatrixUpdated(false), - m_viewMatrixUpdated(false), - m_viewportUpdated(false), - m_aspectRatio(camera.m_aspectRatio), - m_fov(camera.m_fov), - m_zFar(camera.m_zFar), - m_zNear(camera.m_zNear), - m_layer(camera.m_layer) - { - SetTarget(camera.m_target); - } - - /*! - * \brief Ensures the frustum is up to date - */ - - inline void CameraComponent::EnsureFrustumUpdate() const - { - if (!m_frustumUpdated) - UpdateFrustum(); - } - - /*! - * \brief Ensures the projection matrix is up to date - */ - - inline void CameraComponent::EnsureProjectionMatrixUpdate() const - { - if (!m_projectionMatrixUpdated) - UpdateProjectionMatrix(); - } - - /*! - * \brief Ensures the view matrix is up to date - */ - - inline void CameraComponent::EnsureViewMatrixUpdate() const - { - if (!m_viewMatrixUpdated) - UpdateViewMatrix(); - } - - /*! - * \brief Ensures the view port is up to date - */ - - inline void CameraComponent::EnsureViewportUpdate() const - { - if (!m_viewportUpdated) - UpdateViewport(); - } - - /*! - * \brief Gets the field of view of the camera - * \return Field of view of the camera - */ - inline float CameraComponent::GetFOV() const - { - return m_fov; - } - - /*! - * \brief Gets the layer of the camera - * \return Layer of the camera - */ - - inline unsigned int CameraComponent::GetLayer() const - { - return m_layer; - } - - /*! - * \brief Gets the projection scale of the camera - * \return Projection scale - */ - const Nz::Vector3f& CameraComponent::GetProjectionScale() const - { - return m_projectionScale; - } - - /*! - * \brief Gets the size of the camera - * \return Size of the camera - */ - inline const Nz::Vector2f & CameraComponent::GetSize() const - { - return m_size; - } - - /*! - * \brief Gets the target region of the camera - * \return A constant reference to the target region of the camera - */ - - inline const Nz::Rectf& CameraComponent::GetTargetRegion() const - { - return m_targetRegion; - } - - /*! - * \brief Sets the field of view of the camera - * - * \param fov Field of view of the camera - * - * \remark Produces a NazaraAssert if angle is zero - */ - - inline void CameraComponent::SetFOV(float fov) - { - NazaraAssert(!Nz::NumberEquals(fov, 0.f), "FOV must be different from zero"); - m_fov = fov; - - InvalidateProjectionMatrix(); - } - - /*! - * \brief Sets the camera projection scale - * - * \param scale New projection scale - */ - inline void CameraComponent::SetProjectionScale(const Nz::Vector3f& scale) - { - m_projectionScale = scale; - - InvalidateProjectionMatrix(); - } - - /*! - * \brief Sets the projection type of the camera - * - * \param projectionType Projection type of the camera - */ - inline void CameraComponent::SetProjectionType(Nz::ProjectionType projectionType) - { - m_projectionType = projectionType; - - InvalidateProjectionMatrix(); - } - - /*! - * \brief Sets the size of the camera - * - * \param size Size of the camera - */ - - inline void CameraComponent::SetSize(const Nz::Vector2f& size) - { - m_size = size; - - InvalidateProjectionMatrix(); - } - - /*! - * \brief Sets the size of the camera - * - * \param width Size in X of the camera - * \param height Size in Y of the camera - */ - - inline void CameraComponent::SetSize(float width, float height) - { - SetSize({width, height}); - } - - /*! - * \brief Sets the target of the camera - * - * \param renderTarget A constant reference to the render target of the camera - */ - - inline void CameraComponent::SetTarget(const Nz::RenderTarget* renderTarget) - { - m_target = renderTarget; - if (m_target) - { - m_targetResizeSlot.Connect(m_target->OnRenderTargetSizeChange, this, &CameraComponent::OnRenderTargetSizeChange); - m_targetReleaseSlot.Connect(m_target->OnRenderTargetRelease, this, &CameraComponent::OnRenderTargetRelease); - } - else - { - m_targetResizeSlot.Disconnect(); - m_targetReleaseSlot.Disconnect(); - } - } - - /*! - * \brief Sets the target region of the camera - * - * \param region A constant reference to the target region of the camera - */ - - inline void CameraComponent::SetTargetRegion(const Nz::Rectf& region) - { - m_targetRegion = region; - - InvalidateViewport(); - } - - /*! - * \brief Sets the view port of the camera - * - * \param viewport A constant reference to the view port of the camera - * - * \remark Produces a NazaraAssert if the camera has no target - */ - - inline void CameraComponent::SetViewport(const Nz::Recti& viewport) - { - NazaraAssert(m_target, "Component has no render target"); - - // We compute the region necessary to make this view port with the actual size of the target - Nz::Vector2f invSize = 1.f / Nz::Vector2f(m_target->GetSize()); - - SetTargetRegion(Nz::Rectf(invSize.x * viewport.x, invSize.y * viewport.y, invSize.x * viewport.width, invSize.y * viewport.height)); - } - - /*! - * \brief Sets the Z far distance of the camera - * - * \param zFar Z far distance of the camera - */ - - inline void CameraComponent::SetZFar(float zFar) - { - m_zFar = zFar; - - InvalidateProjectionMatrix(); - } - - /*! - * \brief Sets the Z near distance of the camera - * - * \param zNear Z near distance of the camera - * - * \remark Produces a NazaraAssert if zNear is zero - */ - - inline void CameraComponent::SetZNear(float zNear) - { - NazaraAssert(!Nz::NumberEquals(zNear, 0.f), "zNear cannot be zero"); - m_zNear = zNear; - - InvalidateProjectionMatrix(); - } - - /*! - * \brief Update the camera component visibility hash - * - * This is used with CullingList (which produce a visibility hash) - * - * \param visibilityHash New visibility hash - * - * \return True if the visibility hash is not the same as before - */ - inline bool CameraComponent::UpdateVisibility(std::size_t visibilityHash) - { - if (m_visibilityHash != visibilityHash) - { - m_visibilityHash = visibilityHash; - return true; - } - - return false; - } - - /*! - * \brief Invalidates the frustum - */ - - inline void CameraComponent::InvalidateFrustum() const - { - m_frustumUpdated = false; - } - - /*! - * \brief Invalidates the projection matrix - */ - - inline void CameraComponent::InvalidateProjectionMatrix() const - { - m_frustumUpdated = false; - m_projectionMatrixUpdated = false; - } - - /*! - * \brief Invalidates the view matrix - */ - - inline void CameraComponent::InvalidateViewMatrix() const - { - m_frustumUpdated = false; - m_viewMatrixUpdated = false; - } - - /*! - * \brief Invalidates the view port - */ - - inline void CameraComponent::InvalidateViewport() const - { - m_frustumUpdated = false; - m_projectionMatrixUpdated = false; - m_viewportUpdated = false; - } -} diff --git a/include/NazaraSDK/Components/DebugComponent.hpp b/include/NazaraSDK/Components/DebugComponent.hpp deleted file mode 100644 index 3718dc6d8..000000000 --- a/include/NazaraSDK/Components/DebugComponent.hpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_COMPONENTS_DEBUGCOMPONENT_HPP -#define NDK_COMPONENTS_DEBUGCOMPONENT_HPP - -#include -#include -#include - -namespace Ndk -{ - enum class DebugDraw - { - Collider2D, - Collider3D, - GraphicsAABB, - GraphicsOBB, - - Max = GraphicsOBB - }; -} - -namespace Nz -{ - template<> - struct EnumAsFlags - { - static constexpr Ndk::DebugDraw max = Ndk::DebugDraw::GraphicsOBB; - }; -} - -namespace Ndk -{ - using DebugDrawFlags = Nz::Flags; - - constexpr DebugDrawFlags DebugDraw_None = 0; - - class DebugComponent; - class GraphicsComponent; - - using DebugComponentHandle = Nz::ObjectHandle; - - class NDK_API DebugComponent : public Component - { - friend class DebugSystem; - - public: - inline DebugComponent(DebugDrawFlags flags = DebugDraw_None); - inline DebugComponent(const DebugComponent& debug); - ~DebugComponent() = default; - - inline void Disable(DebugDrawFlags flags); - inline void Enable(DebugDrawFlags flags); - - inline DebugDrawFlags GetFlags() const; - - inline bool IsEnabled(DebugDrawFlags flags) const; - - inline DebugComponent& operator=(const DebugComponent& debug); - - static ComponentIndex componentIndex; - - private: - void DetachDebugRenderables(GraphicsComponent& gfxComponent); - - inline const Nz::InstancedRenderableRef& GetDebugRenderable(DebugDraw option) const; - inline DebugDrawFlags GetEnabledFlags() const; - - void OnComponentDetached(BaseComponent& component) override; - void OnDetached() override; - - inline void UpdateDebugRenderable(DebugDraw option, Nz::InstancedRenderableRef renderable); - inline void UpdateEnabledFlags(DebugDrawFlags flags); - - static constexpr std::size_t DebugModeCount = static_cast(DebugDraw::Max) + 1; - - std::array m_debugRenderables; - DebugDrawFlags m_enabledFlags; - DebugDrawFlags m_flags; - }; -} - -#include - -#endif // NDK_COMPONENTS_DEBUGCOMPONENT_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/Components/DebugComponent.inl b/include/NazaraSDK/Components/DebugComponent.inl deleted file mode 100644 index ebac94095..000000000 --- a/include/NazaraSDK/Components/DebugComponent.inl +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - inline DebugComponent::DebugComponent(DebugDrawFlags flags) : - m_flags(flags) - { - } - - inline DebugComponent::DebugComponent(const DebugComponent& debug) : - m_flags(debug.m_flags) - { - } - - inline void DebugComponent::Disable(DebugDrawFlags flags) - { - m_flags &= ~flags; - - if (m_entity) - m_entity->Invalidate(); - } - - inline void DebugComponent::Enable(DebugDrawFlags flags) - { - m_flags |= flags; - - if (m_entity) - m_entity->Invalidate(); - } - - inline DebugDrawFlags DebugComponent::GetFlags() const - { - return m_flags; - } - - inline bool DebugComponent::IsEnabled(DebugDrawFlags flags) const - { - return (m_flags & flags) == flags; - } - - inline DebugComponent& DebugComponent::operator=(const DebugComponent& debug) - { - m_flags = debug.m_flags; - - if (m_entity) - m_entity->Invalidate(); - - return *this; - } - - inline const Nz::InstancedRenderableRef& DebugComponent::GetDebugRenderable(DebugDraw option) const - { - return m_debugRenderables[static_cast(option)]; - } - - inline DebugDrawFlags DebugComponent::GetEnabledFlags() const - { - return m_enabledFlags; - } - - inline void DebugComponent::UpdateDebugRenderable(DebugDraw option, Nz::InstancedRenderableRef renderable) - { - m_debugRenderables[static_cast(option)] = std::move(renderable); - } - - inline void DebugComponent::UpdateEnabledFlags(DebugDrawFlags flags) - { - m_enabledFlags = flags; - } -} diff --git a/include/NazaraSDK/Components/GraphicsComponent.hpp b/include/NazaraSDK/Components/GraphicsComponent.hpp deleted file mode 100644 index 38910b878..000000000 --- a/include/NazaraSDK/Components/GraphicsComponent.hpp +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP -#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP - -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - class GraphicsComponent; - - using GraphicsComponentCullingList = Nz::CullingList; - using GraphicsComponentHandle = Nz::ObjectHandle; - - class NDK_API GraphicsComponent : public Component - { - friend class RenderSystem; - - public: - using RenderableList = std::vector; - - inline GraphicsComponent(); - inline GraphicsComponent(const GraphicsComponent& graphicsComponent); - ~GraphicsComponent() = default; - - inline void AddToCullingList(GraphicsComponentCullingList* cullingList) const; - void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const; - void AddToRenderQueueByCulling(const Nz::Frustumf& frustum, Nz::AbstractRenderQueue* renderQueue) const; - - inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0); - void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0); - - inline void Clear(); - - inline void Detach(const Nz::InstancedRenderable* renderable); - - inline bool DoesRequireRealTimeReflections() const; - - inline void EnsureBoundingVolumesUpdate() const; - inline void EnsureTransformMatrixUpdate() const; - - template void ForEachRenderable(const Func& func) const; - - inline const Nz::Boxf& GetAABB() const; - - inline void GetAttachedRenderables(RenderableList* renderables) const; - inline std::size_t GetAttachedRenderableCount() const; - - inline const Nz::BoundingVolumef& GetBoundingVolume(std::size_t renderableIndex) const; - inline const Nz::Matrix4f& GetLocalMatrix(std::size_t renderableIndex) const; - inline const Nz::Matrix4f& GetTransformMatrix(std::size_t renderableIndex) const; - - inline void RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const; - - inline void SetScissorRect(const Nz::Recti& scissorRect); - - inline void UpdateLocalMatrix(const Nz::InstancedRenderable* instancedRenderable, const Nz::Matrix4f& localMatrix); - inline void UpdateRenderOrder(const Nz::InstancedRenderable* instancedRenderable, int renderOrder); - - static ComponentIndex componentIndex; - - private: - struct Renderable; - - void ConnectInstancedRenderableSignals(Renderable& renderable); - - inline void ForceCullingInvalidation(); - inline void InvalidateAABB() const; - void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index); - void InvalidateRenderableMaterial(const Nz::InstancedRenderable* renderable, std::size_t skinIndex, std::size_t matIndex, const Nz::MaterialRef& newMat); - inline void InvalidateRenderables(); - void InvalidateReflectionMap(); - inline void InvalidateTransformMatrix(); - - void RegisterMaterial(Nz::Material* material, std::size_t count = 1); - - void OnAttached() override; - void OnComponentAttached(BaseComponent& component) override; - void OnComponentDetached(BaseComponent& component) override; - void OnDetached() override; - - void OnInstancedRenderableResetMaterials(const Nz::InstancedRenderable* renderable, std::size_t newMaterialCount); - void OnInstancedRenderableSkinChange(const Nz::InstancedRenderable* renderable, std::size_t newSkinIndex); - void OnMaterialReflectionChange(const Nz::Material* material, Nz::ReflectionMode reflectionMode); - void OnNodeInvalidated(const Nz::Node* node); - - void UnregisterMaterial(Nz::Material* material); - - void UpdateBoundingVolumes() const; - void UpdateTransformMatrix() const; - - NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot); - - using CullingListBoxEntry = GraphicsComponentCullingList::BoxEntry; - - struct CullingBoxEntry - { - CullingListBoxEntry listEntry; - - NazaraSlot(GraphicsComponentCullingList, OnCullingListRelease, cullingListReleaseSlot); - }; - - struct MaterialEntry - { - NazaraSlot(Nz::Material, OnMaterialReflectionModeChange, reflectionModelChangeSlot); - - std::size_t renderableCounter; - }; - - struct Renderable - { - Renderable(const Nz::Matrix4f& transformMatrix) : - data(transformMatrix), - dataUpdated(false) - { - } - - Renderable(const Renderable&) = delete; - Renderable(Renderable&& rhs) noexcept = default; - - ~Renderable() - { - // Disconnect release slot before releasing instanced renderable reference - renderableReleaseSlot.Disconnect(); - } - - Renderable& operator=(const Renderable&) = delete; - Renderable& operator=(Renderable&& r) noexcept = default; - - NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateBoundingVolume, renderableBoundingVolumeInvalidationSlot); - NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateData, renderableDataInvalidationSlot); - NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateMaterial, renderableMaterialInvalidationSlot); - NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableRelease, renderableReleaseSlot); - NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableResetMaterials, renderableResetMaterialsSlot); - NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableSkinChange, renderableSkinChangeSlot); - - mutable Nz::BoundingVolumef boundingVolume; - mutable Nz::InstancedRenderable::InstanceData data; - Nz::InstancedRenderableRef renderable; - mutable bool dataUpdated; - }; - - std::size_t m_reflectiveMaterialCount; - mutable std::vector m_cullingBoxEntries; - std::vector m_renderables; - std::unordered_map m_materialEntries; - mutable Nz::Boxf m_aabb; - mutable Nz::Matrix4f m_transformMatrix; - Nz::Recti m_scissorRect; - Nz::TextureRef m_reflectionMap; - mutable bool m_boundingVolumesUpdated; - mutable bool m_transformMatrixUpdated; - unsigned int m_reflectionMapSize; - }; -} - -#include - -#endif // NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/Components/GraphicsComponent.inl b/include/NazaraSDK/Components/GraphicsComponent.inl deleted file mode 100644 index 2b26360db..000000000 --- a/include/NazaraSDK/Components/GraphicsComponent.inl +++ /dev/null @@ -1,291 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include - -namespace Ndk -{ - inline GraphicsComponent::GraphicsComponent() : - m_reflectiveMaterialCount(0), - m_scissorRect(-1, -1) - { - } - - /*! - * \brief Constructs a GraphicsComponent object by copy semantic - * - * \param graphicsComponent GraphicsComponent to copy - */ - inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) : - Component(graphicsComponent), - m_reflectiveMaterialCount(0), - m_aabb(graphicsComponent.m_aabb), - m_transformMatrix(graphicsComponent.m_transformMatrix), - m_scissorRect(graphicsComponent.m_scissorRect), - m_boundingVolumesUpdated(graphicsComponent.m_boundingVolumesUpdated), - m_transformMatrixUpdated(graphicsComponent.m_transformMatrixUpdated) - { - m_renderables.reserve(graphicsComponent.m_renderables.size()); - for (const Renderable& r : graphicsComponent.m_renderables) - Attach(r.renderable, r.data.localMatrix, r.data.renderOrder); - } - - inline void GraphicsComponent::AddToCullingList(GraphicsComponentCullingList* cullingList) const - { - m_cullingBoxEntries.emplace_back(); - CullingBoxEntry& entry = m_cullingBoxEntries.back(); - entry.cullingListReleaseSlot.Connect(cullingList->OnCullingListRelease, this, &GraphicsComponent::RemoveFromCullingList); - entry.listEntry = cullingList->RegisterBoxTest(this); - - InvalidateAABB(); - } - - /*! - * \brief Attaches a renderable to the entity - * - * \param renderable Reference to a renderable element - * \param renderOrder Render order of the element - */ - inline void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, int renderOrder) - { - return Attach(std::move(renderable), Nz::Matrix4f::Identity(), renderOrder); - } - - /*! - * \brief Clears every renderable elements - */ - - inline void GraphicsComponent::Clear() - { - m_materialEntries.clear(); - m_renderables.clear(); - - if (m_reflectiveMaterialCount > 0) - { - m_reflectiveMaterialCount = 0; - InvalidateReflectionMap(); - } - - InvalidateAABB(); - } - - /*! - * \brief Detaches a renderable to the entity - * - * \param renderable Reference to a renderable element - */ - - inline void GraphicsComponent::Detach(const Nz::InstancedRenderable* renderable) - { - for (auto it = m_renderables.begin(); it != m_renderables.end(); ++it) - { - if (it->renderable == renderable) - { - InvalidateAABB(); - - std::size_t materialCount = renderable->GetMaterialCount(); - for (std::size_t i = 0; i < materialCount; ++i) - UnregisterMaterial(renderable->GetMaterial(i)); - - m_renderables.erase(it); - - ForceCullingInvalidation(); - break; - } - } - } - - /*! - * \brief Checks if this graphics component requires real-time reflections to be generated - * - * If any of the materials attached to a GraphicsComponent (via the attached instanced renderable) needs real-time reflections, this function will return true. - * - * \return True if real-time reflections needs to be generated or false - */ - inline bool GraphicsComponent::DoesRequireRealTimeReflections() const - { - return m_reflectiveMaterialCount != 0 && m_reflectionMap; - } - - /*! - * \brief Ensures the bounding volume is up to date - */ - - inline void GraphicsComponent::EnsureBoundingVolumesUpdate() const - { - if (!m_boundingVolumesUpdated) - UpdateBoundingVolumes(); - } - - /*! - * \brief Ensures the transformation matrix is up to date - */ - - inline void GraphicsComponent::EnsureTransformMatrixUpdate() const - { - if (!m_transformMatrixUpdated) - UpdateTransformMatrix(); - } - - /*! - * \brief Gets the axis-aligned bounding box of the entity - * \return A constant reference to the AABB - */ - inline const Nz::Boxf& GraphicsComponent::GetAABB() const - { - EnsureBoundingVolumesUpdate(); - - return m_aabb; - } - - /*! - * \brief Gets the set of renderable elements - * - * \param renderables Pointer to the list of renderables - * - * \remark Produces a NazaraAssert if renderables is invalid - */ - - inline void GraphicsComponent::GetAttachedRenderables(RenderableList* renderables) const - { - NazaraAssert(renderables, "Invalid renderable list"); - - renderables->reserve(renderables->size() + m_renderables.size()); - for (const Renderable& r : m_renderables) - renderables->push_back(r.renderable); - } - - /*! - * \brief Gets the number of renderable elements attached to the entity - * \return Number of renderable elements - */ - - inline std::size_t GraphicsComponent::GetAttachedRenderableCount() const - { - return m_renderables.size(); - } - - inline const Nz::BoundingVolumef& GraphicsComponent::GetBoundingVolume(std::size_t renderableIndex) const - { - EnsureBoundingVolumesUpdate(); - - assert(renderableIndex < m_renderables.size()); - return m_renderables[renderableIndex].boundingVolume; - } - - inline const Nz::Matrix4f& GraphicsComponent::GetLocalMatrix(std::size_t renderableIndex) const - { - assert(renderableIndex < m_renderables.size()); - return m_renderables[renderableIndex].data.localMatrix; - } - - inline const Nz::Matrix4f& GraphicsComponent::GetTransformMatrix(std::size_t renderableIndex) const - { - EnsureBoundingVolumesUpdate(); - - assert(renderableIndex < m_renderables.size()); - return m_renderables[renderableIndex].data.transformMatrix; - } - - /*! - * \brief Calls a function for every renderable attached to this component - * - * \param func Callback function which will be called with renderable data - */ - template - void GraphicsComponent::ForEachRenderable(const Func& func) const - { - for (const auto& renderableData : m_renderables) - func(renderableData.renderable, renderableData.data.localMatrix, renderableData.data.renderOrder); - } - - inline void GraphicsComponent::RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const - { - for (auto it = m_cullingBoxEntries.begin(); it != m_cullingBoxEntries.end(); ++it) - { - if (it->listEntry.GetParent() == cullingList) - { - if (m_cullingBoxEntries.size() > 1) - *it = std::move(m_cullingBoxEntries.back()); - - m_cullingBoxEntries.pop_back(); - break; - } - } - } - - inline void GraphicsComponent::SetScissorRect(const Nz::Recti& scissorRect) - { - m_scissorRect = scissorRect; - - for (CullingBoxEntry& entry : m_cullingBoxEntries) - entry.listEntry.ForceInvalidation(); //< Invalidate render queues - } - - inline void GraphicsComponent::UpdateLocalMatrix(const Nz::InstancedRenderable* instancedRenderable, const Nz::Matrix4f& localMatrix) - { - for (auto& renderable : m_renderables) - { - if (renderable.renderable == instancedRenderable) - { - renderable.data.localMatrix = localMatrix; - - InvalidateAABB(); - break; - } - } - } - - inline void GraphicsComponent::UpdateRenderOrder(const Nz::InstancedRenderable* instancedRenderable, int renderOrder) - { - for (auto& renderable : m_renderables) - { - if (renderable.renderable == instancedRenderable) - { - renderable.data.renderOrder = renderOrder; - break; - } - } - } - - /*! - * \brief Invalidates the bounding volume - */ - - inline void GraphicsComponent::ForceCullingInvalidation() - { - for (CullingBoxEntry& entry : m_cullingBoxEntries) - entry.listEntry.ForceInvalidation(); //< Invalidate render queues - } - - inline void GraphicsComponent::InvalidateAABB() const - { - m_boundingVolumesUpdated = false; - } - - /*! - * \brief Invalidates every renderable elements - */ - - inline void GraphicsComponent::InvalidateRenderables() - { - for (Renderable& r : m_renderables) - r.dataUpdated = false; - } - - /*! - * \brief Invalidates the transformation matrix - */ - - inline void GraphicsComponent::InvalidateTransformMatrix() - { - m_transformMatrixUpdated = false; - - InvalidateAABB(); - InvalidateRenderables(); - } -} diff --git a/include/NazaraSDK/Components/LightComponent.hpp b/include/NazaraSDK/Components/LightComponent.hpp deleted file mode 100644 index f34e7a2c1..000000000 --- a/include/NazaraSDK/Components/LightComponent.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_COMPONENTS_LIGHTCOMPONENT_HPP -#define NDK_COMPONENTS_LIGHTCOMPONENT_HPP - -#include -#include - -namespace Ndk -{ - class LightComponent; - - using LightComponentHandle = Nz::ObjectHandle; - - class NDK_API LightComponent : public Component, public Nz::Light - { - public: - inline LightComponent(Nz::LightType lightType = Nz::LightType_Point); - LightComponent(const LightComponent& light) = default; - ~LightComponent() = default; - - LightComponent& operator=(const LightComponent& light) = default; - - static ComponentIndex componentIndex; - }; -} - -#include - -#endif // NDK_COMPONENTS_LIGHTCOMPONENT_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/Components/LightComponent.inl b/include/NazaraSDK/Components/LightComponent.inl deleted file mode 100644 index 43b278757..000000000 --- a/include/NazaraSDK/Components/LightComponent.inl +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -namespace Ndk -{ - /*! - * \brief Constructs an LightComponent object with a light type - */ - - inline LightComponent::LightComponent(Nz::LightType lightType) : - Nz::Light(lightType) - { - } -} diff --git a/include/NazaraSDK/Components/ParticleEmitterComponent.hpp b/include/NazaraSDK/Components/ParticleEmitterComponent.hpp deleted file mode 100644 index 99d7bd30e..000000000 --- a/include/NazaraSDK/Components/ParticleEmitterComponent.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP -#define NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP - -#include -#include - -namespace Ndk -{ - class ParticleEmitterComponent; - - using ParticleEmitterComponentHandle = Nz::ObjectHandle; - - class NDK_API ParticleEmitterComponent : public Component, public Nz::ParticleEmitter - { - public: - using SetupFunc = std::function; - - inline ParticleEmitterComponent(); - ParticleEmitterComponent(const ParticleEmitterComponent& emitter) = default; - ParticleEmitterComponent(ParticleEmitterComponent&& emitter) = default; - ~ParticleEmitterComponent() = default; - - inline void Enable(bool active = true); - - inline bool IsActive() const; - - inline void SetSetupFunc(SetupFunc func); - - static ComponentIndex componentIndex; - - private: - void SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const override; - - SetupFunc m_setupFunc; - bool m_isActive; - }; -} - -#include - -#endif // NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP -#endif // NDK_SERVER \ No newline at end of file diff --git a/include/NazaraSDK/Components/ParticleEmitterComponent.inl b/include/NazaraSDK/Components/ParticleEmitterComponent.inl deleted file mode 100644 index d37c82065..000000000 --- a/include/NazaraSDK/Components/ParticleEmitterComponent.inl +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -namespace Ndk -{ - /*! - * \brief Constructs an ParticleEmitterComponent object by default - */ - - inline ParticleEmitterComponent::ParticleEmitterComponent() : - m_isActive(true) - { - } - - /*! - * \brief Enables the emission of particles - * - * \param active Should the emitter be active - */ - - inline void Ndk::ParticleEmitterComponent::Enable(bool active) - { - m_isActive = active; - } - - /*! - * \brief Checks whether the emission of particles is activated - * \param true If it is the case - */ - - inline bool ParticleEmitterComponent::IsActive() const - { - return m_isActive; - } - - /*! - * \brief Sets the function use for setting up particles - * - * \param func Function to set up particles - */ - - inline void Ndk::ParticleEmitterComponent::SetSetupFunc(SetupFunc func) - { - m_setupFunc = std::move(func); - } -} diff --git a/include/NazaraSDK/Components/ParticleGroupComponent.hpp b/include/NazaraSDK/Components/ParticleGroupComponent.hpp deleted file mode 100644 index 1f760fe59..000000000 --- a/include/NazaraSDK/Components/ParticleGroupComponent.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP -#define NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP - -#include -#include - -namespace Ndk -{ - class ParticleGroupComponent; - - using ParticleGroupComponentHandle = Nz::ObjectHandle; - - class NDK_API ParticleGroupComponent : public Component, public Nz::ParticleGroup - { - public: - inline ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleLayout layout); - inline ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleDeclarationConstRef declaration); - ParticleGroupComponent(const ParticleGroupComponent&) = default; - ~ParticleGroupComponent() = default; - - void AddEmitter(Entity* emitter); - using ParticleGroup::AddEmitter; - - void RemoveEmitter(Entity* emitter); - using ParticleGroup::RemoveEmitter; - - static ComponentIndex componentIndex; - }; -} - -#include - -#endif // NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/Components/ParticleGroupComponent.inl b/include/NazaraSDK/Components/ParticleGroupComponent.inl deleted file mode 100644 index 672d4b308..000000000 --- a/include/NazaraSDK/Components/ParticleGroupComponent.inl +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::ParticleGroupComponent - * \brief NDK class that represents the component for a group of particles - */ - - /*! - * \brief Constructs a ParticleGroupComponent object with a maximal number of particles and a layout - * - * \param maxParticleCount Maximum number of particles to generate - * \param layout Enumeration for the layout of data information for the particles - */ - - inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleLayout layout) : - ParticleGroup(maxParticleCount, layout) - { - } - - /*! - * \brief Constructs a ParticleGroupComponent object with a maximal number of particles and a particle declaration - * - * \param maxParticleCount Maximum number of particles to generate - * \param declaration Data information for the particles - */ - - inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleDeclarationConstRef declaration) : - ParticleGroup(maxParticleCount, std::move(declaration)) - { - } - - /*! - * \brief Adds an emitter to the particles - * - * \param emitter Emitter for the particles - * - * \remark Produces a NazaraAssert if emitter is invalid - * \remark Produces a NazaraAssert if entity has no component of type ParticleEmitterComponent - */ - - inline void ParticleGroupComponent::AddEmitter(Entity* emitter) - { - NazaraAssert(emitter && emitter->IsValid(), "Invalid entity"); - NazaraAssert(emitter->HasComponent(), "Entity must have a ParticleEmitterComponent"); - - auto& emitterComponent = emitter->GetComponent(); - ParticleGroup::AddEmitter(&emitterComponent); - } - - - /*! - * \brief Removes an emitter to the particles - * - * \param emitter Emitter for the particles to remove - * - * \remark Produces a NazaraAssert if emitter is invalid - * \remark Produces a NazaraAssert if entity has no component of type ParticleEmitterComponent - */ - - inline void ParticleGroupComponent::RemoveEmitter(Entity* emitter) - { - NazaraAssert(emitter && emitter->IsValid(), "Invalid entity"); - NazaraAssert(emitter->HasComponent(), "Entity must have a ParticleEmitterComponent"); - - auto& emitterComponent = emitter->GetComponent(); - ParticleGroup::RemoveEmitter(&emitterComponent); - } -} diff --git a/include/NazaraSDK/Console.hpp b/include/NazaraSDK/Console.hpp deleted file mode 100644 index 8d8f73574..000000000 --- a/include/NazaraSDK/Console.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_CONSOLE_HPP -#define NDK_CONSOLE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - struct WindowEvent; -} - -namespace Ndk -{ - class AbstractTextAreaWidget; - class Console; - class Entity; - class RichTextAreaWidget; - class ScrollAreaWidget; - class TextAreaWidget; - - using ConsoleHandle = Nz::ObjectHandle; - - class NDK_API Console : public BaseWidget, public Nz::HandledObject - { - public: - Console(BaseWidget* parent); - Console(const Console& console) = delete; - Console(Console&& console) = default; - ~Console() = default; - - void AddLine(const Nz::String& text, const Nz::Color& color = Nz::Color::White); - - void Clear(); - void ClearFocus(); - - inline unsigned int GetCharacterSize() const; - inline const RichTextAreaWidget* GetHistory() const; - inline const TextAreaWidget* GetInput() const; - inline const Nz::FontRef& GetTextFont() const; - - void SetCharacterSize(unsigned int size); - void SetFocus(); - void SetTextFont(Nz::FontRef font); - - Console& operator=(const Console& console) = delete; - Console& operator=(Console&& console) = default; - - NazaraSignal(OnCommand, Console* /*console*/, const Nz::String& /*command*/); - - private: - void ExecuteInput(const AbstractTextAreaWidget* textArea, bool* ignoreDefaultAction); - void Layout() override; - - struct Line - { - Nz::Color color; - Nz::String text; - }; - - std::size_t m_historyPosition; - std::vector m_commandHistory; - std::vector m_historyLines; - ScrollAreaWidget* m_historyArea; - RichTextAreaWidget* m_history; - TextAreaWidget* m_input; - Nz::FontRef m_defaultFont; - unsigned int m_characterSize; - unsigned int m_maxHistoryLines; - }; -} - -#include - -#endif // NDK_CONSOLE_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/Console.inl b/include/NazaraSDK/Console.inl deleted file mode 100644 index fa902f2c3..000000000 --- a/include/NazaraSDK/Console.inl +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -namespace Ndk -{ - /*! - * \brief Gets the character size - * \return Height of the character - */ - - inline unsigned int Console::GetCharacterSize() const - { - return m_characterSize; - } - - /*! - * \brief Gets the entity representing the history of the console - * \return History of the console - */ - - inline const RichTextAreaWidget* Console::GetHistory() const - { - return m_history; - } - - /*! - * \brief Gets the entity representing the input of the console - * \return Input of the console - */ - - inline const TextAreaWidget* Console::GetInput() const - { - return m_input; - } - - /*! - * \brief Gets the font used by the console - * \return A reference to the font currenty used - */ - - inline const Nz::FontRef& Console::GetTextFont() const - { - return m_defaultFont; - } -} diff --git a/include/NazaraSDK/Systems/DebugSystem.hpp b/include/NazaraSDK/Systems/DebugSystem.hpp deleted file mode 100644 index 38fcd2680..000000000 --- a/include/NazaraSDK/Systems/DebugSystem.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_SYSTEMS_DEBUGSYSTEM_HPP -#define NDK_SYSTEMS_DEBUGSYSTEM_HPP - -#include -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API DebugSystem : public System - { - public: - DebugSystem(); - ~DebugSystem() = default; - - void EnableDepthBuffer(bool enable); - - inline bool IsDepthBufferEnabled() const; - - static SystemIndex systemIndex; - - private: - Nz::InstancedRenderableRef GenerateBox(Nz::Boxf box); - Nz::InstancedRenderableRef GenerateCollision2DMesh(Entity* entity, Nz::Vector3f* offset); - Nz::InstancedRenderableRef GenerateCollision3DMesh(Entity* entity); - - std::pair GetBoxMesh(); - Nz::MaterialRef GetCollisionMaterial(); - Nz::MaterialRef GetGlobalAABBMaterial(); - Nz::MaterialRef GetLocalAABBMaterial(); - Nz::MaterialRef GetOBBMaterial(); - - void OnEntityValidation(Entity* entity, bool justAdded) override; - void OnUpdate(float elapsedTime) override; - - Nz::MaterialRef m_globalAabbMaterial; - Nz::MaterialRef m_localAabbMaterial; - Nz::MaterialRef m_collisionMaterial; - Nz::MaterialRef m_obbMaterial; - Nz::IndexBufferRef m_boxMeshIndexBuffer; - Nz::VertexBufferRef m_boxMeshVertexBuffer; - bool m_isDepthBufferEnabled; - }; -} - -#include - -#endif // NDK_SYSTEMS_DEBUGSYSTEM_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/Systems/DebugSystem.inl b/include/NazaraSDK/Systems/DebugSystem.inl deleted file mode 100644 index 41f5e598d..000000000 --- a/include/NazaraSDK/Systems/DebugSystem.inl +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - inline bool DebugSystem::IsDepthBufferEnabled() const - { - return m_isDepthBufferEnabled; - } -} diff --git a/include/NazaraSDK/Systems/ParticleSystem.hpp b/include/NazaraSDK/Systems/ParticleSystem.hpp deleted file mode 100644 index 51d00782f..000000000 --- a/include/NazaraSDK/Systems/ParticleSystem.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_SYSTEMS_PARTICLESYSTEM_HPP -#define NDK_SYSTEMS_PARTICLESYSTEM_HPP - -#include - -namespace Ndk -{ - class NDK_API ParticleSystem : public System - { - public: - ParticleSystem(); - ~ParticleSystem() = default; - - static SystemIndex systemIndex; - - private: - void OnUpdate(float elapsedTime) override; - }; -} - -#include - -#endif // NDK_SYSTEMS_PARTICLESYSTEM_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/Systems/ParticleSystem.inl b/include/NazaraSDK/Systems/ParticleSystem.inl deleted file mode 100644 index b9de8cfdb..000000000 --- a/include/NazaraSDK/Systems/ParticleSystem.inl +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp diff --git a/include/NazaraSDK/Systems/RenderSystem.hpp b/include/NazaraSDK/Systems/RenderSystem.hpp deleted file mode 100644 index 82978e712..000000000 --- a/include/NazaraSDK/Systems/RenderSystem.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_SERVER -#ifndef NDK_SYSTEMS_RENDERSYSTEM_HPP -#define NDK_SYSTEMS_RENDERSYSTEM_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - class AbstractViewer; - - class NDK_API RenderSystem : public System - { - public: - RenderSystem(); - ~RenderSystem() = default; - - template T& ChangeRenderTechnique(); - inline Nz::AbstractRenderTechnique& ChangeRenderTechnique(std::unique_ptr&& renderTechnique); - - inline void EnableCulling(bool enable); - - inline const Nz::BackgroundRef& GetDefaultBackground() const; - inline const Nz::Matrix4f& GetCoordinateSystemMatrix() const; - inline Nz::Vector3f GetGlobalForward() const; - inline Nz::Vector3f GetGlobalRight() const; - inline Nz::Vector3f GetGlobalUp() const; - inline Nz::AbstractRenderTechnique& GetRenderTechnique() const; - - inline bool IsCullingEnabled() const; - - inline void SetDefaultBackground(Nz::BackgroundRef background); - inline void SetGlobalForward(const Nz::Vector3f& direction); - inline void SetGlobalRight(const Nz::Vector3f& direction); - inline void SetGlobalUp(const Nz::Vector3f& direction); - - static SystemIndex systemIndex; - - private: - inline void InvalidateCoordinateSystem(); - - void OnEntityRemoved(Entity* entity) override; - void OnEntityValidation(Entity* entity, bool justAdded) override; - void OnUpdate(float elapsedTime) override; - - void UpdateDynamicReflections(); - void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer); - void UpdatePointSpotShadowMaps(); - - std::unique_ptr m_renderTechnique; - std::vector m_volumeEntries; - std::vector m_cameras; - EntityList m_drawables; - EntityList m_directionalLights; - EntityList m_lights; - EntityList m_pointSpotLights; - EntityList m_particleGroups; - EntityList m_realtimeReflected; - GraphicsComponentCullingList m_drawableCulling; - Nz::BackgroundRef m_background; - Nz::DepthRenderTechnique m_shadowTechnique; - Nz::Matrix4f m_coordinateSystemMatrix; - Nz::RenderTexture m_shadowRT; - bool m_coordinateSystemInvalidated; - bool m_forceRenderQueueInvalidation; - bool m_isCullingEnabled; - }; -} - -#include - -#endif // NDK_SYSTEMS_RENDERSYSTEM_HPP -#endif // NDK_SERVER diff --git a/include/NazaraSDK/Systems/RenderSystem.inl b/include/NazaraSDK/Systems/RenderSystem.inl deleted file mode 100644 index 34b7588c2..000000000 --- a/include/NazaraSDK/Systems/RenderSystem.inl +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - /*! - * \brief Changes the render technique used for the system - * \return A reference to the render technique type - */ - - template - inline T& RenderSystem::ChangeRenderTechnique() - { - static_assert(std::is_base_of::value, "RenderTechnique is not a subtype of AbstractRenderTechnique"); - return static_cast(ChangeRenderTechnique(std::make_unique())); - } - - /*! - * \brief Changes the render technique used for the system - * \return A reference to the abstract render technique - * - * \param renderTechnique Render technique to use - */ - - inline Nz::AbstractRenderTechnique& RenderSystem::ChangeRenderTechnique(std::unique_ptr&& renderTechnique) - { - m_renderTechnique = std::move(renderTechnique); - return *m_renderTechnique; - } - - /*! - * \brief Enables/disables object culling - * - * Object culling is an algorithm used by the render system to detect invisible objects (which will not appear on screen) before they are rendered. - * This includes Frustum Culling and potentially Occlusion Culling. - * - * Disabling this is not recommended, as the system will draw every object in the world which could induce a performance loss. - * - * \param enable Whether to enable or disable culling - * - * \see IsCullingEnabled - */ - inline void RenderSystem::EnableCulling(bool enable) - { - m_isCullingEnabled = enable; - } - - /*! - * \brief Gets the background used for rendering - * \return A reference to the background - */ - - inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const - { - return m_background; - } - - /*! - * \brief Gets the coordinates matrix used for rendering - * \return A constant reference to the matrix of coordinates - */ - - inline const Nz::Matrix4f& RenderSystem::GetCoordinateSystemMatrix() const - { - return m_coordinateSystemMatrix; - } - - /*! - * \brief Gets the "forward" global direction - * \return The forward direction, by default, it's -UnitZ() (Right hand coordinates) - */ - - inline Nz::Vector3f RenderSystem::GetGlobalForward() const - { - return Nz::Vector3f(-m_coordinateSystemMatrix.m13, -m_coordinateSystemMatrix.m23, -m_coordinateSystemMatrix.m33); - } - - /*! - * \brief Gets the "right" global direction - * \return The right direction, by default, it's UnitX() (Right hand coordinates) - */ - - inline Nz::Vector3f RenderSystem::GetGlobalRight() const - { - return Nz::Vector3f(m_coordinateSystemMatrix.m11, m_coordinateSystemMatrix.m21, m_coordinateSystemMatrix.m31); - } - - /*! - * \brief Gets the "up" global direction - * \return The up direction, by default, it's UnitY() (Right hand coordinates) - */ - - inline Nz::Vector3f RenderSystem::GetGlobalUp() const - { - return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32); - } - - /*! - * \brief Gets the render technique used for rendering - * \return A reference to the abstract render technique being used - */ - - inline Nz::AbstractRenderTechnique& RenderSystem::GetRenderTechnique() const - { - return *m_renderTechnique.get(); - } - - /*! - * \brief Query if culling is enabled (enabled by default) - * \return True if culling is enabled, false otherwise - * - * \see EnableCulling - */ - inline bool RenderSystem::IsCullingEnabled() const - { - return m_isCullingEnabled; - } - - /*! - * \brief Sets the background used for rendering - * - * \param background A reference to the background - */ - - inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background) - { - m_background = std::move(background); - } - - /*! - * \brief Sets the "forward" global direction - * - * \param direction The new forward direction - */ - - inline void RenderSystem::SetGlobalForward(const Nz::Vector3f& direction) - { - m_coordinateSystemMatrix.m13 = -direction.x; - m_coordinateSystemMatrix.m23 = -direction.y; - m_coordinateSystemMatrix.m33 = -direction.z; - - InvalidateCoordinateSystem(); - } - - /*! - * \brief Sets the "right" global direction - * - * \param direction The new right direction - */ - - inline void RenderSystem::SetGlobalRight(const Nz::Vector3f& direction) - { - m_coordinateSystemMatrix.m11 = direction.x; - m_coordinateSystemMatrix.m21 = direction.y; - m_coordinateSystemMatrix.m31 = direction.z; - - InvalidateCoordinateSystem(); - } - - /*! - * \brief Sets the "up" global direction - * - * \param direction The new up direction - */ - - inline void RenderSystem::SetGlobalUp(const Nz::Vector3f& direction) - { - m_coordinateSystemMatrix.m12 = direction.x; - m_coordinateSystemMatrix.m22 = direction.y; - m_coordinateSystemMatrix.m32 = direction.z; - - InvalidateCoordinateSystem(); - } - - /*! - * \brief Invalidates the matrix of coordinates for the system - */ - - inline void RenderSystem::InvalidateCoordinateSystem() - { - m_coordinateSystemInvalidated = true; - } -} diff --git a/include/NazaraSDK/Widgets.hpp b/include/NazaraSDK/Widgets.hpp deleted file mode 100644 index e2225bf68..000000000 --- a/include/NazaraSDK/Widgets.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// This file was automatically generated - -#pragma once - -#ifndef NDK_WIDGETS_GLOBAL_HPP -#define NDK_WIDGETS_GLOBAL_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif // NDK_WIDGETS_GLOBAL_HPP diff --git a/include/NazaraSDK/Widgets/AbstractTextAreaWidget.hpp b/include/NazaraSDK/Widgets/AbstractTextAreaWidget.hpp deleted file mode 100644 index 6762f8d63..000000000 --- a/include/NazaraSDK/Widgets/AbstractTextAreaWidget.hpp +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_ABSTRACTTEXTAREAWIDGET_HPP -#define NDK_WIDGETS_ABSTRACTTEXTAREAWIDGET_HPP - -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API AbstractTextAreaWidget : public BaseWidget - { - public: - using CharacterFilter = std::function; - - AbstractTextAreaWidget(BaseWidget* parent); - AbstractTextAreaWidget(const AbstractTextAreaWidget&) = delete; - AbstractTextAreaWidget(AbstractTextAreaWidget&&) = default; - ~AbstractTextAreaWidget() = default; - - virtual void Clear(); - - //virtual TextAreaWidget* Clone() const = 0; - - void EnableLineWrap(bool enable = true); - inline void EnableMultiline(bool enable = true); - inline void EnableTabWriting(bool enable = true); - - inline void Erase(std::size_t glyphPosition); - virtual void Erase(std::size_t firstGlyph, std::size_t lastGlyph) = 0; - inline void EraseSelection(); - - inline const CharacterFilter& GetCharacterFilter() const; - inline const Nz::Vector2ui& GetCursorPosition() const; - inline Nz::Vector2ui GetCursorPosition(std::size_t glyphIndex) const; - inline EchoMode GetEchoMode() const; - inline std::size_t GetGlyphIndex() const; - inline std::size_t GetGlyphIndex(const Nz::Vector2ui& cursorPosition) const; - inline const Nz::String& GetText() const; - - Nz::Vector2ui GetHoveredGlyph(float x, float y) const; - - inline bool HasSelection() const; - - inline bool IsLineWrapEnabled() const; - inline bool IsMultilineEnabled() const; - inline bool IsReadOnly() const; - inline bool IsTabWritingEnabled() const; - - inline void MoveCursor(int offset); - inline void MoveCursor(const Nz::Vector2i& offset); - - inline Nz::Vector2ui NormalizeCursorPosition(Nz::Vector2ui cursorPosition) const; - - inline void SetCharacterFilter(CharacterFilter filter); - inline void SetCursorPosition(std::size_t glyphIndex); - inline void SetCursorPosition(Nz::Vector2ui cursorPosition); - inline void SetEchoMode(EchoMode echoMode); - inline void SetReadOnly(bool readOnly = true); - inline void SetSelection(Nz::Vector2ui fromPosition, Nz::Vector2ui toPosition); - - inline void Write(const Nz::String& text); - inline void Write(const Nz::String& text, const Nz::Vector2ui& glyphPosition); - virtual void Write(const Nz::String& text, std::size_t glyphPosition) = 0; - - AbstractTextAreaWidget& operator=(const AbstractTextAreaWidget&) = delete; - AbstractTextAreaWidget& operator=(AbstractTextAreaWidget&&) = default; - - NazaraSignal(OnTextAreaCursorMove, const AbstractTextAreaWidget* /*textArea*/, Nz::Vector2ui* /*newCursorPosition*/); - NazaraSignal(OnTextAreaKeyBackspace, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/); - NazaraSignal(OnTextAreaKeyDown, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/); - NazaraSignal(OnTextAreaKeyEnd, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/); - NazaraSignal(OnTextAreaKeyHome, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/); - NazaraSignal(OnTextAreaKeyLeft, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/); - NazaraSignal(OnTextAreaKeyReturn, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/); - NazaraSignal(OnTextAreaKeyRight, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/); - NazaraSignal(OnTextAreaKeyUp, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/); - NazaraSignal(OnTextAreaSelection, const AbstractTextAreaWidget* /*textArea*/, Nz::Vector2ui* /*start*/, Nz::Vector2ui* /*end*/); - - protected: - virtual Nz::AbstractTextDrawer& GetTextDrawer() = 0; - virtual const Nz::AbstractTextDrawer& GetTextDrawer() const = 0; - - void Layout() override; - - virtual void HandleIndentation(bool add) = 0; - virtual void HandleSelectionIndentation(bool add) = 0; - virtual void HandleWordCursorMove(bool left) = 0; - - bool IsFocusable() const override; - void OnFocusLost() override; - void OnFocusReceived() override; - bool OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override; - void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key) override; - void OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button) override; - void OnMouseButtonRelease(int /*x*/, int /*y*/, Nz::Mouse::Button button) override; - void OnMouseEnter() override; - void OnMouseMoved(int x, int y, int deltaX, int deltaY) override; - void OnTextEntered(char32_t character, bool repeated) override; - - inline void SetCursorPositionInternal(std::size_t glyphIndex); - inline void SetCursorPositionInternal(Nz::Vector2ui cursorPosition); - - void RefreshCursor(); - virtual void UpdateDisplayText() = 0; - void UpdateTextSprite(); - - CharacterFilter m_characterFilter; - EchoMode m_echoMode; - EntityHandle m_cursorEntity; - EntityHandle m_textEntity; - Nz::TextSpriteRef m_textSprite; - Nz::Vector2ui m_cursorPositionBegin; - Nz::Vector2ui m_cursorPositionEnd; - Nz::Vector2ui m_selectionCursor; - std::vector m_cursorSprites; - bool m_isLineWrapEnabled; - bool m_isMouseButtonDown; - bool m_multiLineEnabled; - bool m_readOnly; - bool m_tabEnabled; // writes (Shift+)Tab character if set to true - }; -} - -#include - -#endif // NDK_WIDGETS_ABSTRACTTEXTAREAWIDGET_HPP diff --git a/include/NazaraSDK/Widgets/AbstractTextAreaWidget.inl b/include/NazaraSDK/Widgets/AbstractTextAreaWidget.inl deleted file mode 100644 index 377321c35..000000000 --- a/include/NazaraSDK/Widgets/AbstractTextAreaWidget.inl +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - inline void AbstractTextAreaWidget::EnableMultiline(bool enable) - { - m_multiLineEnabled = enable; - } - - inline void AbstractTextAreaWidget::EnableTabWriting(bool enable) - { - m_tabEnabled = enable; - } - - inline void AbstractTextAreaWidget::Erase(std::size_t glyphPosition) - { - Erase(glyphPosition, glyphPosition + 1U); - } - - inline void AbstractTextAreaWidget::EraseSelection() - { - if (!HasSelection()) - return; - - Erase(GetGlyphIndex(m_cursorPositionBegin), GetGlyphIndex(m_cursorPositionEnd)); - } - - inline const AbstractTextAreaWidget::CharacterFilter& AbstractTextAreaWidget::GetCharacterFilter() const - { - return m_characterFilter; - } - - inline const Nz::Vector2ui& AbstractTextAreaWidget::GetCursorPosition() const - { - return m_cursorPositionBegin; - } - - Nz::Vector2ui AbstractTextAreaWidget::GetCursorPosition(std::size_t glyphIndex) const - { - const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer(); - - glyphIndex = std::min(glyphIndex, GetTextDrawer().GetGlyphCount()); - - std::size_t lineCount = textDrawer.GetLineCount(); - std::size_t line = 0U; - for (std::size_t i = line + 1; i < lineCount; ++i) - { - if (textDrawer.GetLine(i).glyphIndex > glyphIndex) - break; - - line = i; - } - - const auto& lineInfo = textDrawer.GetLine(line); - - Nz::Vector2ui cursorPos; - cursorPos.y = static_cast(line); - cursorPos.x = static_cast(glyphIndex - lineInfo.glyphIndex); - - return cursorPos; - } - - inline EchoMode AbstractTextAreaWidget::GetEchoMode() const - { - return m_echoMode; - } - - inline std::size_t AbstractTextAreaWidget::GetGlyphIndex() const - { - return GetGlyphIndex(m_cursorPositionBegin); - } - - inline std::size_t AbstractTextAreaWidget::GetGlyphIndex(const Nz::Vector2ui& cursorPosition) const - { - const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer(); - - std::size_t glyphIndex = textDrawer.GetLine(cursorPosition.y).glyphIndex + cursorPosition.x; - if (textDrawer.GetLineCount() > cursorPosition.y + 1) - glyphIndex = std::min(glyphIndex, textDrawer.GetLine(cursorPosition.y + 1).glyphIndex - 1); - else - glyphIndex = std::min(glyphIndex, textDrawer.GetGlyphCount()); - - return glyphIndex; - } - - inline bool AbstractTextAreaWidget::HasSelection() const - { - return m_cursorPositionBegin != m_cursorPositionEnd; - } - - inline bool AbstractTextAreaWidget::IsLineWrapEnabled() const - { - return m_isLineWrapEnabled; - } - - inline bool AbstractTextAreaWidget::IsMultilineEnabled() const - { - return m_multiLineEnabled; - } - - inline bool AbstractTextAreaWidget::IsTabWritingEnabled() const - { - return m_tabEnabled; - } - - inline bool AbstractTextAreaWidget::IsReadOnly() const - { - return m_readOnly; - } - - inline void AbstractTextAreaWidget::MoveCursor(int offset) - { - std::size_t cursorGlyph = GetGlyphIndex(m_cursorPositionBegin); - if (offset >= 0) - SetCursorPosition(cursorGlyph + static_cast(offset)); - else - { - std::size_t nOffset = static_cast(-offset); - if (nOffset >= cursorGlyph) - SetCursorPosition(0); - else - SetCursorPosition(cursorGlyph - nOffset); - } - } - - inline void AbstractTextAreaWidget::MoveCursor(const Nz::Vector2i& offset) - { - auto ClampOffset = [] (unsigned int cursorPosition, int cursorOffset) -> unsigned int - { - if (cursorOffset >= 0) - return cursorPosition + cursorOffset; - else - { - unsigned int nOffset = static_cast(-cursorOffset); - if (nOffset >= cursorPosition) - return 0; - else - return cursorPosition - nOffset; - } - }; - - Nz::Vector2ui cursorPosition = m_cursorPositionBegin; - cursorPosition.x = ClampOffset(static_cast(cursorPosition.x), offset.x); - cursorPosition.y = ClampOffset(static_cast(cursorPosition.y), offset.y); - - SetCursorPosition(cursorPosition); - } - - inline Nz::Vector2ui AbstractTextAreaWidget::NormalizeCursorPosition(Nz::Vector2ui cursorPosition) const - { - const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer(); - - std::size_t lineCount = textDrawer.GetLineCount(); - if (cursorPosition.y >= lineCount) - cursorPosition.y = static_cast(lineCount - 1); - - const auto& lineInfo = textDrawer.GetLine(cursorPosition.y); - if (cursorPosition.y + 1 < lineCount) - { - const auto& nextLineInfo = textDrawer.GetLine(cursorPosition.y + 1); - cursorPosition.x = std::min(cursorPosition.x, static_cast(nextLineInfo.glyphIndex - lineInfo.glyphIndex - 1)); - } - - return cursorPosition; - } - - inline void AbstractTextAreaWidget::SetCharacterFilter(CharacterFilter filter) - { - m_characterFilter = std::move(filter); - } - - inline void AbstractTextAreaWidget::SetCursorPosition(std::size_t glyphIndex) - { - Nz::Vector2ui position = GetCursorPosition(glyphIndex); - Nz::Vector2ui newPosition = position; - - OnTextAreaCursorMove(this, &newPosition); - - if (position == newPosition) - SetCursorPositionInternal(position); - else - SetCursorPositionInternal(GetGlyphIndex(newPosition)); - } - - inline void AbstractTextAreaWidget::SetCursorPosition(Nz::Vector2ui cursorPosition) - { - OnTextAreaCursorMove(this, &cursorPosition); - - return SetCursorPositionInternal(NormalizeCursorPosition(cursorPosition)); - } - - inline void AbstractTextAreaWidget::SetEchoMode(EchoMode echoMode) - { - m_echoMode = echoMode; - - UpdateDisplayText(); - } - - inline void AbstractTextAreaWidget::SetReadOnly(bool readOnly) - { - m_readOnly = readOnly; - m_cursorEntity->Enable(!m_readOnly && HasFocus()); - } - - inline void AbstractTextAreaWidget::SetSelection(Nz::Vector2ui fromPosition, Nz::Vector2ui toPosition) - { - // Ensure begin is before end - if (toPosition.y < fromPosition.y || (toPosition.y == fromPosition.y && toPosition.x < fromPosition.x)) - std::swap(fromPosition, toPosition); - - if (m_cursorPositionBegin != fromPosition || m_cursorPositionEnd != toPosition) - { - OnTextAreaSelection(this, &fromPosition, &toPosition); - - // Ensure begin is before end a second time (in case signal changed it) - if (toPosition.y < fromPosition.y || (toPosition.y == fromPosition.y && toPosition.x < fromPosition.x)) - std::swap(fromPosition, toPosition); - - m_cursorPositionBegin = NormalizeCursorPosition(fromPosition); - m_cursorPositionEnd = NormalizeCursorPosition(toPosition); - - RefreshCursor(); - } - } - - inline void AbstractTextAreaWidget::Write(const Nz::String& text) - { - Write(text, GetGlyphIndex(m_cursorPositionBegin)); - } - - inline void AbstractTextAreaWidget::Write(const Nz::String& text, const Nz::Vector2ui& glyphPosition) - { - Write(text, GetGlyphIndex(glyphPosition)); - } - - void AbstractTextAreaWidget::SetCursorPositionInternal(std::size_t glyphIndex) - { - return SetCursorPositionInternal(GetCursorPosition(glyphIndex)); - } - - inline void AbstractTextAreaWidget::SetCursorPositionInternal(Nz::Vector2ui cursorPosition) - { - m_cursorPositionBegin = cursorPosition; - m_cursorPositionEnd = m_cursorPositionBegin; - - RefreshCursor(); - } -} diff --git a/include/NazaraSDK/Widgets/BoxLayout.hpp b/include/NazaraSDK/Widgets/BoxLayout.hpp deleted file mode 100644 index 408f1a996..000000000 --- a/include/NazaraSDK/Widgets/BoxLayout.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_BOXLAYOUT_HPP -#define NDK_WIDGETS_BOXLAYOUT_HPP - -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API BoxLayout : public BaseWidget - { - public: - inline BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation); - BoxLayout(const BoxLayout&) = delete; - BoxLayout(BoxLayout&&) = default; - ~BoxLayout() = default; - - void Layout() override; - - BoxLayout& operator=(const BoxLayout&) = delete; - BoxLayout& operator=(BoxLayout&&) = default; - - private: - struct ChildInfo - { - BaseWidget* widget; - bool isConstrained; - float maximumSize; - float minimumSize; - float size; - }; - - std::vector m_childInfos; - BoxLayoutOrientation m_orientation; - float m_spacing; - }; -} - -#include - -#endif // NDK_WIDGETS_BOXLAYOUT_HPP diff --git a/include/NazaraSDK/Widgets/BoxLayout.inl b/include/NazaraSDK/Widgets/BoxLayout.inl deleted file mode 100644 index c28b31232..000000000 --- a/include/NazaraSDK/Widgets/BoxLayout.inl +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - BoxLayout::BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation) : - BaseWidget(parent), - m_orientation(orientation), - m_spacing(5.f) - { - } -} diff --git a/include/NazaraSDK/Widgets/ButtonWidget.hpp b/include/NazaraSDK/Widgets/ButtonWidget.hpp deleted file mode 100644 index 6a75b4e23..000000000 --- a/include/NazaraSDK/Widgets/ButtonWidget.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_BUTTONWIDGET_HPP -#define NDK_WIDGETS_BUTTONWIDGET_HPP - -#include -#include -#include -#include -#include - -namespace Nz -{ - class AbstractTextDrawer; -} - -namespace Ndk -{ - class NDK_API ButtonWidget : public BaseWidget - { - public: - ButtonWidget(BaseWidget* parent); - ButtonWidget(const ButtonWidget&) = delete; - ButtonWidget(ButtonWidget&&) = default; - ~ButtonWidget() = default; - - inline const Nz::Color& GetColor() const; - inline const Nz::Color& GetCornerColor() const; - inline const Nz::Color& GetHoverColor() const; - inline const Nz::Color& GetHoverCornerColor() const; - inline const Nz::Color& GetPressColor() const; - inline const Nz::Color& GetPressCornerColor() const; - - inline const Nz::TextureRef& GetTexture() const; - inline const Nz::TextureRef& GetHoverTexture() const; - inline const Nz::TextureRef& GetPressTexture() const; - - inline void SetColor(const Nz::Color& color, const Nz::Color& cornerColor); - inline void SetHoverColor(const Nz::Color& color, const Nz::Color& cornerColor); - inline void SetPressColor(const Nz::Color& color, const Nz::Color& cornerColor); - - inline void SetTexture(const Nz::TextureRef& texture); - inline void SetHoverTexture(const Nz::TextureRef& texture); - inline void SetPressTexture(const Nz::TextureRef& texture); - - inline void UpdateText(const Nz::AbstractTextDrawer& drawer); - - ButtonWidget& operator=(const ButtonWidget&) = delete; - ButtonWidget& operator=(ButtonWidget&&) = default; - - static const Nz::Color& GetDefaultColor(); - static const Nz::Color& GetDefaultCornerColor(); - static const Nz::Color& GetDefaultHoverColor(); - static const Nz::Color& GetDefaultHoverCornerColor(); - static const Nz::Color& GetDefaultPressColor(); - static const Nz::Color& GetDefaultPressCornerColor(); - - NazaraSignal(OnButtonTrigger, const ButtonWidget* /*button*/); - - private: - void Layout() override; - - void OnMouseEnter() override; - void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) override; - void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override; - void OnMouseExit() override; - - EntityHandle m_textEntity; - EntityHandle m_gradientEntity; - Nz::SpriteRef m_gradientSprite; - Nz::TextSpriteRef m_textSprite; - - Nz::Color m_color; - Nz::Color m_cornerColor; - Nz::Color m_hoverColor; - Nz::Color m_hoverCornerColor; - Nz::Color m_pressColor; - Nz::Color m_pressCornerColor; - - Nz::TextureRef m_texture; - Nz::TextureRef m_hoverTexture; - Nz::TextureRef m_pressTexture; - - static Nz::Color s_color; - static Nz::Color s_cornerColor; - static Nz::Color s_hoverColor; - static Nz::Color s_hoverCornerColor; - static Nz::Color s_pressColor; - static Nz::Color s_pressCornerColor; - }; -} - -#include - -#endif // NDK_WIDGETS_BUTTONWIDGET_HPP diff --git a/include/NazaraSDK/Widgets/ButtonWidget.inl b/include/NazaraSDK/Widgets/ButtonWidget.inl deleted file mode 100644 index 5d320e767..000000000 --- a/include/NazaraSDK/Widgets/ButtonWidget.inl +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - inline const Nz::Color& ButtonWidget::GetColor() const - { - return m_color; - } - - inline const Nz::Color& ButtonWidget::GetCornerColor() const - { - return m_cornerColor; - } - - inline const Nz::Color& ButtonWidget::GetHoverColor() const - { - return m_hoverColor; - } - - inline const Nz::Color& ButtonWidget::GetHoverCornerColor() const - { - return m_hoverCornerColor; - } - - inline const Nz::Color& ButtonWidget::GetPressColor() const - { - return m_pressColor; - } - - inline const Nz::Color& ButtonWidget::GetPressCornerColor() const - { - return m_pressCornerColor; - } - - inline const Nz::TextureRef& ButtonWidget::GetTexture() const - { - return m_texture; - } - - inline const Nz::TextureRef& ButtonWidget::GetHoverTexture() const - { - return m_hoverTexture; - } - - inline const Nz::TextureRef& ButtonWidget::GetPressTexture() const - { - return m_pressTexture; - } - - inline void ButtonWidget::SetColor(const Nz::Color& color, const Nz::Color& cornerColor) - { - m_color = color; - m_cornerColor = cornerColor; - - m_gradientSprite->SetColor(m_color); - m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_cornerColor); - m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_cornerColor); - } - - inline void ButtonWidget::SetHoverColor(const Nz::Color& color, const Nz::Color& cornerColor) - { - m_hoverColor = color; - m_hoverCornerColor = cornerColor; - } - - inline void ButtonWidget::SetPressColor(const Nz::Color& color, const Nz::Color& cornerColor) - { - m_pressColor = color; - m_pressCornerColor = cornerColor; - } - - inline void ButtonWidget::SetTexture(const Nz::TextureRef& texture) - { - m_texture = texture; - m_gradientSprite->SetTexture(m_texture); - } - - inline void ButtonWidget::SetHoverTexture(const Nz::TextureRef& texture) - { - m_hoverTexture = texture; - } - - inline void ButtonWidget::SetPressTexture(const Nz::TextureRef& texture) - { - m_pressTexture = texture; - } - - inline void ButtonWidget::UpdateText(const Nz::AbstractTextDrawer& drawer) - { - m_textSprite->Update(drawer); - - Nz::Vector2f textSize = Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths()); - SetMinimumSize(textSize); - SetPreferredSize(textSize + Nz::Vector2f(20.f, 10.f)); - - Layout(); - } -} diff --git a/include/NazaraSDK/Widgets/CheckboxWidget.hpp b/include/NazaraSDK/Widgets/CheckboxWidget.hpp deleted file mode 100644 index d9057a248..000000000 --- a/include/NazaraSDK/Widgets/CheckboxWidget.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_CHECKBOXWIDGET_HPP -#define NDK_WIDGETS_CHECKBOXWIDGET_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class AbstractTextDrawer; -} - -namespace Ndk -{ - class NDK_API CheckboxWidget : public BaseWidget - { - friend class Sdk; - - public: - CheckboxWidget(BaseWidget* parent); - CheckboxWidget(const CheckboxWidget&) = delete; - CheckboxWidget(CheckboxWidget&&) = default; - ~CheckboxWidget() = default; - - //virtual CheckboxWidget* Clone() const = 0; - - inline void EnableAdaptativeMargin(bool enable = true); - inline void EnableCheckbox(bool enable = true); - inline void EnableTristate(bool enable = true); - - inline bool IsCheckboxEnabled() const; - inline bool IsMarginAdaptative() const; - inline bool IsTristateEnabled() const; - - inline const Nz::Vector2f& GetCheckboxSize() const; - inline Nz::Vector2f GetCheckboxBorderSize() const; - inline CheckboxState GetState() const; - inline float GetTextMargin() const; - - inline void SetCheckboxSize(const Nz::Vector2f& size); - CheckboxState SwitchToNextState(); - void SetState(CheckboxState state); - inline void SetTextMargin(float margin); - - inline void UpdateText(const Nz::AbstractTextDrawer& drawer); - - - CheckboxWidget& operator=(const CheckboxWidget&) = delete; - CheckboxWidget& operator=(CheckboxWidget&&) = default; - - NazaraSignal(OnStateChanged, const CheckboxWidget* /*checkbox*/); - - private: - static bool Initialize(); - static void Uninitialize(); - - void Layout() override; - void UpdateCheckbox(); - void UpdateSize(); - - void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override; - inline bool ContainsCheckbox(int x, int y) const; - - - EntityHandle m_checkboxBorderEntity; - EntityHandle m_checkboxBackgroundEntity; - EntityHandle m_checkboxContentEntity; - EntityHandle m_textEntity; - - Nz::TextureRef m_checkMark; - - Nz::SpriteRef m_checkboxContentSprite; - Nz::SpriteRef m_checkboxBorderSprite; - Nz::SpriteRef m_checkboxBackgroundSprite; - Nz::TextSpriteRef m_textSprite; - - static Nz::Color s_backgroundColor; - static Nz::Color s_disabledBackgroundColor; - static Nz::Color s_disabledBorderColor; - static Nz::Color s_borderColor; - - bool m_adaptativeMargin; - bool m_checkboxEnabled; - bool m_tristateEnabled; - - static float s_borderScale; - float m_textMargin; - CheckboxState m_state; - }; -} - -#include - -#endif // NDK_WIDGETS_CHECKBOXWIDGET_HPP diff --git a/include/NazaraSDK/Widgets/CheckboxWidget.inl b/include/NazaraSDK/Widgets/CheckboxWidget.inl deleted file mode 100644 index 5fa9e30ed..000000000 --- a/include/NazaraSDK/Widgets/CheckboxWidget.inl +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -namespace Ndk -{ - inline void CheckboxWidget::EnableAdaptativeMargin(bool enable) - { - m_adaptativeMargin = enable; - Layout(); - } - - inline void CheckboxWidget::EnableCheckbox(bool enable) - { - m_checkboxEnabled = enable; - UpdateCheckbox(); - } - - inline void CheckboxWidget::EnableTristate(bool enable) - { - m_tristateEnabled = enable; - - if (m_tristateEnabled && GetState() == CheckboxState_Tristate) - SetState(CheckboxState_Unchecked); - } - - inline bool CheckboxWidget::IsCheckboxEnabled() const - { - return m_checkboxEnabled; - } - - inline bool CheckboxWidget::IsMarginAdaptative() const - { - return m_adaptativeMargin; - } - - inline bool CheckboxWidget::IsTristateEnabled() const - { - return m_tristateEnabled; - } - - inline const Nz::Vector2f& CheckboxWidget::GetCheckboxSize() const - { - return m_checkboxBorderSprite->GetSize(); - } - - inline Nz::Vector2f CheckboxWidget::GetCheckboxBorderSize() const - { - return GetCheckboxSize() / s_borderScale; - } - - inline CheckboxState CheckboxWidget::GetState() const - { - return m_state; - } - - inline float CheckboxWidget::GetTextMargin() const - { - return m_textMargin; - } - - inline void CheckboxWidget::SetCheckboxSize(const Nz::Vector2f& size) - { - m_checkboxBorderSprite->SetSize(size); - m_checkboxBackgroundSprite->SetSize(size - GetCheckboxBorderSize() * 2.f); - m_checkboxContentSprite->SetSize(GetCheckboxSize() - GetCheckboxBorderSize() * 2.f - Nz::Vector2f { 4.f, 4.f }); - - UpdateSize(); - Layout(); - } - - inline void CheckboxWidget::SetTextMargin(float margin) - { - m_textMargin = margin; - Layout(); - } - - inline void CheckboxWidget::UpdateText(const Nz::AbstractTextDrawer& drawer) - { - m_textSprite->Update(drawer); - - UpdateSize(); - Layout(); - } - - inline bool CheckboxWidget::ContainsCheckbox(int x, int y) const - { - Nz::Vector2f checkboxSize = GetCheckboxSize(); - Nz::Vector3f pos = m_checkboxBorderEntity->GetComponent().GetPosition(Nz::CoordSys_Local); - - return x > pos.x && x < pos.x + checkboxSize.x && - y > pos.y && y < pos.y + checkboxSize.y; - } -} diff --git a/include/NazaraSDK/Widgets/Enums.hpp b/include/NazaraSDK/Widgets/Enums.hpp deleted file mode 100644 index a11511694..000000000 --- a/include/NazaraSDK/Widgets/Enums.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NAZARA_ENUMS_SDK_HPP -#define NAZARA_ENUMS_SDK_HPP - -namespace Ndk -{ - enum BoxLayoutOrientation - { - BoxLayoutOrientation_Horizontal, - BoxLayoutOrientation_Vertical - }; - - enum CheckboxState - { - CheckboxState_Checked, - CheckboxState_Tristate, - CheckboxState_Unchecked, - - CheckboxState_Max = CheckboxState_Unchecked - }; - - enum EchoMode - { - EchoMode_Normal, - EchoMode_Password, - EchoMode_PasswordExceptLast, - - EchoMode_Max = EchoMode_PasswordExceptLast - }; -} - -#endif // NAZARA_ENUMS_SDK_HPP diff --git a/include/NazaraSDK/Widgets/ImageWidget.hpp b/include/NazaraSDK/Widgets/ImageWidget.hpp deleted file mode 100644 index 4435a7058..000000000 --- a/include/NazaraSDK/Widgets/ImageWidget.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_IMAGEWIDGET_HPP -#define NDK_WIDGETS_IMAGEWIDGET_HPP - -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API ImageWidget : public BaseWidget - { - public: - ImageWidget(BaseWidget* parent); - ImageWidget(const ImageWidget&) = delete; - ImageWidget(ImageWidget&&) = default; - ~ImageWidget() = default; - - //virtual ImageWidget* Clone() const = 0; - - inline const Nz::Color& GetColor() const; - inline const Nz::TextureRef& GetTexture() const; - inline const Nz::Rectf& GetTextureCoords() const; - - inline void SetColor(const Nz::Color& color); - inline void SetTexture(const Nz::TextureRef& texture); - inline void SetTextureCoords(const Nz::Rectf& coords); - inline void SetTextureRect(const Nz::Rectui& rect); - - ImageWidget& operator=(const ImageWidget&) = delete; - ImageWidget& operator=(ImageWidget&&) = default; - - private: - void Layout() override; - - Ndk::EntityHandle m_entity; - Nz::SpriteRef m_sprite; - }; -} - -#include - -#endif // NDK_WIDGETS_IMAGEWIDGET_HPP diff --git a/include/NazaraSDK/Widgets/ImageWidget.inl b/include/NazaraSDK/Widgets/ImageWidget.inl deleted file mode 100644 index 666adf12e..000000000 --- a/include/NazaraSDK/Widgets/ImageWidget.inl +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - inline const Nz::Color& ImageWidget::GetColor() const - { - return m_sprite->GetColor(); - } - - inline const Nz::TextureRef& ImageWidget::GetTexture() const - { - return m_sprite->GetMaterial()->GetDiffuseMap(); - } - - inline const Nz::Rectf& ImageWidget::GetTextureCoords() const - { - return m_sprite->GetTextureCoords(); - } - - inline void ImageWidget::SetColor(const Nz::Color& color) - { - m_sprite->SetColor(color); - } - - inline void ImageWidget::SetTexture(const Nz::TextureRef& texture) - { - m_sprite->SetTexture(texture, false); - - Nz::Vector2f textureSize = Nz::Vector2f(Nz::Vector2ui(m_sprite->GetMaterial()->GetDiffuseMap()->GetSize())); - SetMinimumSize(textureSize); - SetPreferredSize(textureSize); - } - - inline void ImageWidget::SetTextureCoords(const Nz::Rectf& coords) - { - m_sprite->SetTextureCoords(coords); - } - - inline void ImageWidget::SetTextureRect(const Nz::Rectui& rect) - { - m_sprite->SetTextureRect(rect); - } -} diff --git a/include/NazaraSDK/Widgets/LabelWidget.hpp b/include/NazaraSDK/Widgets/LabelWidget.hpp deleted file mode 100644 index 9b01a44e8..000000000 --- a/include/NazaraSDK/Widgets/LabelWidget.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_LABELWIDGET_HPP -#define NDK_WIDGETS_LABELWIDGET_HPP - -#include -#include -#include - -namespace Nz -{ - class AbstractTextDrawer; -} - -namespace Ndk -{ - class NDK_API LabelWidget : public BaseWidget - { - public: - LabelWidget(BaseWidget* parent); - LabelWidget(const LabelWidget&) = delete; - LabelWidget(LabelWidget&&) = default; - ~LabelWidget() = default; - - inline void UpdateText(const Nz::AbstractTextDrawer& drawer); - - LabelWidget& operator=(const LabelWidget&) = delete; - LabelWidget& operator=(LabelWidget&&) = default; - - private: - EntityHandle m_textEntity; - Nz::TextSpriteRef m_textSprite; - }; -} - -#include - -#endif // NDK_WIDGETS_LABELWIDGET_HPP diff --git a/include/NazaraSDK/Widgets/LabelWidget.inl b/include/NazaraSDK/Widgets/LabelWidget.inl deleted file mode 100644 index ee168ead0..000000000 --- a/include/NazaraSDK/Widgets/LabelWidget.inl +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - inline void LabelWidget::UpdateText(const Nz::AbstractTextDrawer& drawer) - { - m_textSprite->Update(drawer); - - Nz::Vector2f size = Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths()); - SetMinimumSize(size); - SetPreferredSize(size); - } -} diff --git a/include/NazaraSDK/Widgets/ProgressBarWidget.hpp b/include/NazaraSDK/Widgets/ProgressBarWidget.hpp deleted file mode 100644 index 7d2d5d7d4..000000000 --- a/include/NazaraSDK/Widgets/ProgressBarWidget.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_PROGRESSBARWIDGET_HPP -#define NDK_WIDGETS_PROGRESSBARWIDGET_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API ProgressBarWidget : public BaseWidget - { - friend class Sdk; - - public: - ProgressBarWidget(BaseWidget* parent); - ProgressBarWidget(const ProgressBarWidget&) = delete; - ProgressBarWidget(ProgressBarWidget&&) = default; - ~ProgressBarWidget() = default; - - //virtual ProgressBarWidget* Clone() const = 0; - - inline void EnableText(bool enable = true); - inline void EnableBorder(bool enable = true); - - inline bool IsTextEnabled() const; - inline bool IsBorderEnabled() const; - - - inline unsigned GetPercentageValue() const; - inline Nz::Vector2f GetProgressBarSize() const; - inline Nz::Vector2f GetProgressBarBorderSize() const; - inline float GetTextMargin() const; - - - inline const Nz::Color& GetBarBackgroundColor() const; - inline const Nz::Color& GetBarBackgroundCornerColor() const; - inline const Nz::Color& GetBarColor() const; - inline const Nz::Color& GetBarCornerColor() const; - - inline const Nz::TextureRef& GetBarBackgroundTexture() const; - inline const Nz::TextureRef& GetBarTexture() const; - - static const Nz::Color& GetDefaultBarColor(); - static const Nz::Color& GetDefaultBarCornerColor(); - static const Nz::Color& GetDefaultBarBackgroundColor(); - static const Nz::Color& GetDefaultBarBackgroundCornerColor(); - - - inline void SetBarBackgroundColor(const Nz::Color& globalColor, const Nz::Color& cornerColor); - inline void SetBarBackgroundTexture(Nz::TextureRef texture, bool resetColors = true); - inline void SetBarColor(const Nz::Color& globalColor, const Nz::Color& cornerColor); - inline void SetBarTexture(Nz::TextureRef texture, bool resetColors = true); - - - inline void SetPercentageValue(unsigned percentage); - inline void SetTextMargin(float margin); - inline void SetTextColor(const Nz::Color& color); - - NazaraSignal(OnValueChanged, const ProgressBarWidget* /*progressBar*/); - - private: - void Layout() override; - inline void UpdateText(); - - - EntityHandle m_borderEntity; - EntityHandle m_barEntity; - EntityHandle m_textEntity; - - static Nz::Color s_borderColor; - static Nz::Color s_barBackgroundColor; - static Nz::Color s_barBackgroundCornerColor; - static Nz::Color s_barColor; - static Nz::Color s_barCornerColor; - Nz::Color m_textColor; - - Nz::SpriteRef m_borderSprite; - Nz::SpriteRef m_barBackgroundSprite; - Nz::SpriteRef m_barSprite; - Nz::TextSpriteRef m_textSprite; - - static float s_borderScale; - float m_textMargin; - unsigned m_value; - }; -} - -#include - -#endif // NDK_WIDGETS_PROGRESSBARWIDGET_HPP diff --git a/include/NazaraSDK/Widgets/ProgressBarWidget.inl b/include/NazaraSDK/Widgets/ProgressBarWidget.inl deleted file mode 100644 index 9fe2c8382..000000000 --- a/include/NazaraSDK/Widgets/ProgressBarWidget.inl +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -namespace Ndk -{ - inline void ProgressBarWidget::EnableText(bool enable) - { - m_textEntity->Enable(enable); - Layout(); - } - - inline void ProgressBarWidget::EnableBorder(bool enable) - { - m_borderEntity->Enable(enable); - } - - inline bool ProgressBarWidget::IsTextEnabled() const - { - return m_textEntity->IsEnabled(); - } - - inline bool ProgressBarWidget::IsBorderEnabled() const - { - return m_borderEntity->IsEnabled(); - } - - - inline unsigned ProgressBarWidget::GetPercentageValue() const - { - return m_value; - } - - inline Nz::Vector2f ProgressBarWidget::GetProgressBarSize() const - { - Nz::Vector3f progressBarSize = m_borderSprite->GetBoundingVolume().obb.localBox.GetLengths(); - - if (IsTextEnabled()) - { - Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths(); - progressBarSize -= { textSize.x + m_textMargin, 0.f, 0.f }; - } - - return { progressBarSize.x, progressBarSize.y }; - } - - inline Nz::Vector2f ProgressBarWidget::GetProgressBarBorderSize() const - { - Nz::Vector2f barSize = GetProgressBarSize(); - return { barSize.y / s_borderScale, barSize.y / s_borderScale }; - } - - inline float ProgressBarWidget::GetTextMargin() const - { - return m_textMargin; - } - - - inline const Nz::Color& ProgressBarWidget::GetBarBackgroundColor() const - { - return m_barBackgroundSprite->GetColor(); - } - - inline const Nz::Color& ProgressBarWidget::GetBarBackgroundCornerColor() const - { - return m_barBackgroundSprite->GetCornerColor(Nz::RectCorner_LeftTop); - } - - inline const Nz::Color& ProgressBarWidget::GetBarColor() const - { - return m_barSprite->GetColor(); - } - - inline const Nz::Color& ProgressBarWidget::GetBarCornerColor() const - { - return m_barSprite->GetCornerColor(Nz::RectCorner_LeftTop); - } - - - inline const Nz::TextureRef& ProgressBarWidget::GetBarBackgroundTexture() const - { - return m_barBackgroundSprite->GetMaterial()->GetDiffuseMap(); - } - - inline const Nz::TextureRef& ProgressBarWidget::GetBarTexture() const - { - return m_barSprite->GetMaterial()->GetDiffuseMap(); - } - - - inline void ProgressBarWidget::SetBarBackgroundColor(const Nz::Color& globalColor, const Nz::Color& cornerColor) - { - m_barBackgroundSprite->SetColor(globalColor); - m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_LeftTop, cornerColor); - m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_RightTop, cornerColor); - m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_LeftBottom, globalColor); - m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_RightBottom, globalColor); - } - - inline void ProgressBarWidget::SetBarBackgroundTexture(Nz::TextureRef texture, bool resetColors) - { - m_barBackgroundSprite->SetTexture(texture, false); - - if (resetColors) - SetBarBackgroundColor(Nz::Color::White, Nz::Color::White); - } - - inline void ProgressBarWidget::SetBarColor(const Nz::Color& globalColor, const Nz::Color& cornerColor) - { - m_barSprite->SetColor(globalColor); - m_barSprite->SetCornerColor(Nz::RectCorner_LeftTop, cornerColor); - m_barSprite->SetCornerColor(Nz::RectCorner_RightTop, cornerColor); - m_barSprite->SetCornerColor(Nz::RectCorner_LeftBottom, globalColor); - m_barSprite->SetCornerColor(Nz::RectCorner_RightBottom, globalColor); - } - - inline void ProgressBarWidget::SetBarTexture(Nz::TextureRef texture, bool resetColors) - { - m_barSprite->SetTexture(texture, false); - - if (resetColors) - SetBarColor(Nz::Color::White, Nz::Color::White); - } - - - inline void ProgressBarWidget::SetPercentageValue(unsigned percentage) - { - m_value = percentage; - OnValueChanged(this); - Layout(); - } - - inline void ProgressBarWidget::SetTextMargin(float margin) - { - m_textMargin = margin; - - if (IsTextEnabled()) - Layout(); - } - - inline void ProgressBarWidget::SetTextColor(const Nz::Color& color) - { - m_textColor = color; - UpdateText(); - } - - inline void ProgressBarWidget::UpdateText() - { - if (IsTextEnabled()) - { - Nz::Vector2f size = GetSize(); - m_textSprite->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_value).Append('%'), static_cast(std::min(size.x, size.y) / 2.f), 0u, m_textColor)); - } - } -} diff --git a/include/NazaraSDK/Widgets/RichTextAreaWidget.hpp b/include/NazaraSDK/Widgets/RichTextAreaWidget.hpp deleted file mode 100644 index a75fd34dc..000000000 --- a/include/NazaraSDK/Widgets/RichTextAreaWidget.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_RICHTEXTAREAWIDGET_HPP -#define NDK_WIDGETS_RICHTEXTAREAWIDGET_HPP - -#include -#include - -namespace Ndk -{ - class NDK_API RichTextAreaWidget : public AbstractTextAreaWidget - { - public: - RichTextAreaWidget(BaseWidget* parent); - RichTextAreaWidget(const RichTextAreaWidget&) = delete; - RichTextAreaWidget(RichTextAreaWidget&&) = default; - ~RichTextAreaWidget() = default; - - void AppendText(const Nz::String& text); - - void Clear() override; - - void Erase(std::size_t firstGlyph, std::size_t lastGlyph) override; - - inline unsigned int GetCharacterSize() const; - inline float GetCharacterSpacingOffset() const; - inline float GetLineSpacingOffset() const; - inline const Nz::Color& GetTextColor() const; - inline Nz::Font* GetTextFont() const; - inline const Nz::Color& GetTextOutlineColor() const; - inline float GetTextOutlineThickness() const; - inline Nz::TextStyleFlags GetTextStyle() const; - - inline void SetCharacterSize(unsigned int characterSize); - inline void SetCharacterSpacingOffset(float offset); - inline void SetLineSpacingOffset(float offset); - inline void SetTextColor(const Nz::Color& color); - inline void SetTextFont(Nz::FontRef font); - inline void SetTextOutlineColor(const Nz::Color& color); - inline void SetTextOutlineThickness(float thickness); - inline void SetTextStyle(Nz::TextStyleFlags style); - - void Write(const Nz::String& text, std::size_t glyphPosition) override; - - RichTextAreaWidget& operator=(const RichTextAreaWidget&) = delete; - RichTextAreaWidget& operator=(RichTextAreaWidget&&) = default; - - private: - Nz::AbstractTextDrawer& GetTextDrawer() override; - const Nz::AbstractTextDrawer& GetTextDrawer() const override; - - void HandleIndentation(bool add) override; - void HandleSelectionIndentation(bool add) override; - void HandleWordCursorMove(bool left) override; - - void UpdateDisplayText() override; - - Nz::RichTextDrawer m_drawer; - }; -} - -#include - -#endif // NDK_WIDGETS_TEXTAREAWIDGET_HPP diff --git a/include/NazaraSDK/Widgets/RichTextAreaWidget.inl b/include/NazaraSDK/Widgets/RichTextAreaWidget.inl deleted file mode 100644 index cc9b933cf..000000000 --- a/include/NazaraSDK/Widgets/RichTextAreaWidget.inl +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - inline unsigned int RichTextAreaWidget::GetCharacterSize() const - { - return m_drawer.GetDefaultCharacterSize(); - } - - inline float RichTextAreaWidget::GetCharacterSpacingOffset() const - { - return m_drawer.GetDefaultCharacterSpacingOffset(); - } - - inline float RichTextAreaWidget::GetLineSpacingOffset() const - { - return m_drawer.GetDefaultLineSpacingOffset(); - } - - inline const Nz::Color& RichTextAreaWidget::GetTextColor() const - { - return m_drawer.GetDefaultColor(); - } - - inline Nz::Font* RichTextAreaWidget::GetTextFont() const - { - return m_drawer.GetDefaultFont(); - } - - inline const Nz::Color& RichTextAreaWidget::GetTextOutlineColor() const - { - return m_drawer.GetDefaultOutlineColor(); - } - - inline float RichTextAreaWidget::GetTextOutlineThickness() const - { - return m_drawer.GetDefaultOutlineThickness(); - } - - inline Nz::TextStyleFlags RichTextAreaWidget::GetTextStyle() const - { - return m_drawer.GetDefaultStyle(); - } - - inline void RichTextAreaWidget::SetCharacterSize(unsigned int characterSize) - { - m_drawer.SetDefaultCharacterSize(characterSize); - } - - inline void RichTextAreaWidget::SetCharacterSpacingOffset(float offset) - { - m_drawer.SetDefaultCharacterSpacingOffset(offset); - } - - inline void RichTextAreaWidget::SetLineSpacingOffset(float offset) - { - m_drawer.SetDefaultLineSpacingOffset(offset); - } - - inline void RichTextAreaWidget::SetTextColor(const Nz::Color& color) - { - m_drawer.SetDefaultColor(color); - } - - inline void RichTextAreaWidget::SetTextFont(Nz::FontRef font) - { - m_drawer.SetDefaultFont(std::move(font)); - } - - inline void RichTextAreaWidget::SetTextOutlineColor(const Nz::Color& color) - { - m_drawer.SetDefaultOutlineColor(color); - } - - inline void RichTextAreaWidget::SetTextOutlineThickness(float thickness) - { - m_drawer.SetDefaultOutlineThickness(thickness); - } - - inline void RichTextAreaWidget::SetTextStyle(Nz::TextStyleFlags style) - { - m_drawer.SetDefaultStyle(style); - } -} diff --git a/include/NazaraSDK/Widgets/ScrollAreaWidget.hpp b/include/NazaraSDK/Widgets/ScrollAreaWidget.hpp deleted file mode 100644 index e7652c3e7..000000000 --- a/include/NazaraSDK/Widgets/ScrollAreaWidget.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_SCROLLAREAWIDGET_HPP -#define NDK_WIDGETS_SCROLLAREAWIDGET_HPP - -#include -#include -#include - -namespace Ndk -{ - class NDK_API ScrollAreaWidget : public BaseWidget - { - public: - ScrollAreaWidget(BaseWidget* parent, BaseWidget* content); - ScrollAreaWidget(const ScrollAreaWidget&) = delete; - ScrollAreaWidget(ScrollAreaWidget&&) = default; - ~ScrollAreaWidget() = default; - - void EnableScrollbar(bool enable); - - inline float GetScrollHeight() const; - inline float GetScrollRatio() const; - - inline bool HasScrollbar() const; - inline bool IsScrollbarEnabled() const; - inline bool IsScrollbarVisible() const; - - inline void ScrollToHeight(float height); - void ScrollToRatio(float ratio); - - ScrollAreaWidget& operator=(const ScrollAreaWidget&) = delete; - ScrollAreaWidget& operator=(ScrollAreaWidget&&) = default; - - private: - enum class ScrollBarStatus - { - Grabbed, - Hovered, - None - }; - - Nz::Rectf GetScrollbarRect() const; - - void Layout() override; - - void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) override; - void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override; - void OnMouseExit() override; - void OnMouseMoved(int x, int y, int deltaX, int deltaY) override; - void OnMouseWheelMoved(int x, int y, float delta) override; - - void UpdateScrollbarStatus(ScrollBarStatus status); - - BaseWidget* m_content; - EntityHandle m_scrollbarBackgroundEntity; - EntityHandle m_scrollbarEntity; - Nz::SpriteRef m_scrollbarBackgroundSprite; - Nz::SpriteRef m_scrollbarSprite; - Nz::Vector2i m_grabbedDelta; - ScrollBarStatus m_scrollbarStatus; - bool m_isScrollbarEnabled; - bool m_hasScrollbar; - float m_scrollRatio; - }; -} - -#include - -#endif // NDK_WIDGETS_SCROLLAREAWIDGET_HPP diff --git a/include/NazaraSDK/Widgets/ScrollAreaWidget.inl b/include/NazaraSDK/Widgets/ScrollAreaWidget.inl deleted file mode 100644 index 71ccd579c..000000000 --- a/include/NazaraSDK/Widgets/ScrollAreaWidget.inl +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - inline float ScrollAreaWidget::GetScrollHeight() const - { - return m_scrollRatio * m_content->GetHeight(); - } - - inline float ScrollAreaWidget::GetScrollRatio() const - { - return m_scrollRatio; - } - - inline bool ScrollAreaWidget::HasScrollbar() const - { - return m_hasScrollbar; - } - - inline bool ScrollAreaWidget::IsScrollbarEnabled() const - { - return m_isScrollbarEnabled; - } - - inline bool ScrollAreaWidget::IsScrollbarVisible() const - { - return HasScrollbar() && IsScrollbarEnabled(); - } - - inline void ScrollAreaWidget::ScrollToHeight(float height) - { - float contentHeight = m_content->GetHeight(); - ScrollToRatio(height / contentHeight); - } -} diff --git a/include/NazaraSDK/Widgets/TextAreaWidget.hpp b/include/NazaraSDK/Widgets/TextAreaWidget.hpp deleted file mode 100644 index e438ead2b..000000000 --- a/include/NazaraSDK/Widgets/TextAreaWidget.hpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_WIDGETS_TEXTAREAWIDGET_HPP -#define NDK_WIDGETS_TEXTAREAWIDGET_HPP - -#include -#include - -namespace Ndk -{ - class NDK_API TextAreaWidget : public AbstractTextAreaWidget - { - public: - TextAreaWidget(BaseWidget* parent); - TextAreaWidget(const TextAreaWidget&) = delete; - TextAreaWidget(TextAreaWidget&&) = default; - ~TextAreaWidget() = default; - - void AppendText(const Nz::String& text); - - void Clear() override; - - using AbstractTextAreaWidget::Erase; - void Erase(std::size_t firstGlyph, std::size_t lastGlyph) override; - - inline unsigned int GetCharacterSize() const; - inline const Nz::String& GetDisplayText() const; - inline float GetCharacterSpacingOffset() const; - inline float GetLineSpacingOffset() const; - inline const Nz::String& GetText() const; - inline const Nz::Color& GetTextColor() const; - inline Nz::Font* GetTextFont() const; - inline const Nz::Color& GetTextOulineColor() const; - inline float GetTextOulineThickness() const; - inline Nz::TextStyleFlags GetTextStyle() const; - - inline void SetCharacterSize(unsigned int characterSize); - inline void SetCharacterSpacingOffset(float offset); - inline void SetLineSpacingOffset(float offset); - inline void SetText(const Nz::String& text); - inline void SetTextColor(const Nz::Color& text); - inline void SetTextFont(Nz::FontRef font); - inline void SetTextOutlineColor(const Nz::Color& color); - inline void SetTextOutlineThickness(float thickness); - inline void SetTextStyle(Nz::TextStyleFlags style); - - using AbstractTextAreaWidget::Write; - void Write(const Nz::String& text, std::size_t glyphPosition) override; - - TextAreaWidget& operator=(const TextAreaWidget&) = delete; - TextAreaWidget& operator=(TextAreaWidget&&) = default; - - NazaraSignal(OnTextChanged, const AbstractTextAreaWidget* /*textArea*/, const Nz::String& /*text*/); - - private: - Nz::AbstractTextDrawer& GetTextDrawer() override; - const Nz::AbstractTextDrawer& GetTextDrawer() const override; - - void HandleIndentation(bool add) override; - void HandleSelectionIndentation(bool add) override; - void HandleWordCursorMove(bool left) override; - - void UpdateDisplayText() override; - void UpdateMinimumSize(); - - Nz::SimpleTextDrawer m_drawer; - Nz::String m_text; - }; -} - -#include - -#endif // NDK_WIDGETS_TEXTAREAWIDGET_HPP diff --git a/include/NazaraSDK/Widgets/TextAreaWidget.inl b/include/NazaraSDK/Widgets/TextAreaWidget.inl deleted file mode 100644 index 9cfc1cd57..000000000 --- a/include/NazaraSDK/Widgets/TextAreaWidget.inl +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - inline unsigned int TextAreaWidget::GetCharacterSize() const - { - return m_drawer.GetCharacterSize(); - } - - inline const Nz::String& TextAreaWidget::GetDisplayText() const - { - return m_drawer.GetText(); - } - - inline float TextAreaWidget::GetCharacterSpacingOffset() const - { - return m_drawer.GetCharacterSpacingOffset(); - } - - inline float TextAreaWidget::GetLineSpacingOffset() const - { - return m_drawer.GetLineSpacingOffset(); - } - - inline const Nz::String& TextAreaWidget::GetText() const - { - return m_text; - } - - inline const Nz::Color& TextAreaWidget::GetTextColor() const - { - return m_drawer.GetColor(); - } - - inline Nz::Font* TextAreaWidget::GetTextFont() const - { - return m_drawer.GetFont(); - } - - inline const Nz::Color& TextAreaWidget::GetTextOulineColor() const - { - return m_drawer.GetOutlineColor(); - } - - inline float TextAreaWidget::GetTextOulineThickness() const - { - return m_drawer.GetOutlineThickness(); - } - - inline Nz::TextStyleFlags TextAreaWidget::GetTextStyle() const - { - return m_drawer.GetStyle(); - } - - inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize) - { - m_drawer.SetCharacterSize(characterSize); - - UpdateMinimumSize(); - UpdateDisplayText(); - } - - inline void TextAreaWidget::SetCharacterSpacingOffset(float offset) - { - m_drawer.SetCharacterSpacingOffset(offset); - - UpdateMinimumSize(); - UpdateDisplayText(); - } - - inline void TextAreaWidget::SetLineSpacingOffset(float offset) - { - m_drawer.SetLineSpacingOffset(offset); - - UpdateDisplayText(); - } - - inline void TextAreaWidget::SetText(const Nz::String& text) - { - m_text = text; - OnTextChanged(this, m_text); - - UpdateDisplayText(); - } - - inline void TextAreaWidget::SetTextColor(const Nz::Color& text) - { - m_drawer.SetColor(text); - - UpdateDisplayText(); - } - - inline void TextAreaWidget::SetTextFont(Nz::FontRef font) - { - m_drawer.SetFont(font); - - UpdateDisplayText(); - } - - inline void TextAreaWidget::SetTextOutlineColor(const Nz::Color& color) - { - m_drawer.SetOutlineColor(color); - - UpdateDisplayText(); - } - - inline void TextAreaWidget::SetTextOutlineThickness(float thickness) - { - m_drawer.SetOutlineThickness(thickness); - - UpdateDisplayText(); - } - - inline void TextAreaWidget::SetTextStyle(Nz::TextStyleFlags style) - { - m_drawer.SetStyle(style); - - UpdateDisplayText(); - } -} diff --git a/plugins/Assimp/Plugin.cpp b/plugins/Assimp/Plugin.cpp index e84b9f4f5..cc9978b9b 100644 --- a/plugins/Assimp/Plugin.cpp +++ b/plugins/Assimp/Plugin.cpp @@ -381,25 +381,25 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters) if (wrapKey) { - SamplerWrap wrap = SamplerWrap_Default; + SamplerWrap wrap = SamplerWrap_Clamp; switch (mapMode[0]) { - case aiTextureMapMode_Clamp: - case aiTextureMapMode_Decal: - wrap = SamplerWrap_Clamp; - break; + case aiTextureMapMode_Clamp: + case aiTextureMapMode_Decal: + wrap = SamplerWrap_Clamp; + break; - case aiTextureMapMode_Mirror: - wrap = SamplerWrap_MirroredRepeat; - break; + case aiTextureMapMode_Mirror: + wrap = SamplerWrap_MirroredRepeat; + break; - case aiTextureMapMode_Wrap: - wrap = SamplerWrap_Repeat; - break; + case aiTextureMapMode_Wrap: + wrap = SamplerWrap_Repeat; + break; - default: - NazaraWarning("Assimp texture map mode 0x" + String::Number(mapMode[0], 16) + " not handled"); - break; + default: + NazaraWarning("Assimp texture map mode 0x" + String::Number(mapMode[0], 16) + " not handled"); + break; } matData.SetParameter(wrapKey, static_cast(wrap)); @@ -567,7 +567,7 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters) if (wrapKey) { - SamplerWrap wrap = SamplerWrap_Default; + SamplerWrap wrap = SamplerWrap_Clamp; switch (mapMode[0]) { case aiTextureMapMode_Clamp: diff --git a/src/Nazara/Graphics/AbstractBackground.cpp b/src/Nazara/Graphics/AbstractBackground.cpp deleted file mode 100644 index 3a0600c85..000000000 --- a/src/Nazara/Graphics/AbstractBackground.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::AbstractBackground - * \brief Graphics class that represents the background for our scene - * - * \remark This class is abstract - */ - - AbstractBackground::~AbstractBackground() = default; - - BackgroundLibrary::LibraryMap AbstractBackground::s_library; -} diff --git a/src/Nazara/Graphics/AbstractRenderQueue.cpp b/src/Nazara/Graphics/AbstractRenderQueue.cpp deleted file mode 100644 index b5878cc78..000000000 --- a/src/Nazara/Graphics/AbstractRenderQueue.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::AbstractRenderQueue - * \brief Graphics class that represents the rendering queue for our scene - * - * \remark This class is abstract - */ - - AbstractRenderQueue::~AbstractRenderQueue() = default; - - /*! - * \brief Adds a directional light to the rendering queue - * - * \param light Directional light - */ - - void AbstractRenderQueue::AddDirectionalLight(const DirectionalLight& light) - { - directionalLights.push_back(light); - } - - /*! - * \brief Adds a point light to the rendering queue - * - * \param light Point light - */ - - void AbstractRenderQueue::AddPointLight(const PointLight& light) - { - pointLights.push_back(light); - } - - /*! - * \brief Adds a spot light to the rendering queue - * - * \param light Spot light - */ - - void AbstractRenderQueue::AddSpotLight(const SpotLight& light) - { - spotLights.push_back(light); - } - - /*! - * \brief Clears the rendering queue - * - * \param fully Should everything be cleared ? - */ - - void AbstractRenderQueue::Clear(bool fully) - { - NazaraUnused(fully); - - directionalLights.clear(); - pointLights.clear(); - spotLights.clear(); - } -} diff --git a/src/Nazara/Graphics/AbstractRenderTechnique.cpp b/src/Nazara/Graphics/AbstractRenderTechnique.cpp deleted file mode 100644 index 9dad6e24e..000000000 --- a/src/Nazara/Graphics/AbstractRenderTechnique.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::AbstractRenderTechnique - * \brief Graphics class that represents the rendering technique for our scene - * - * \remark This class is abstract - */ - - /*! - * \brief Constructs a AbstractRenderTechnique object - */ - - AbstractRenderTechnique::AbstractRenderTechnique() : - m_instancingEnabled(true) - { - } - - AbstractRenderTechnique::~AbstractRenderTechnique() = default; - - /*! - * \brief Enables the instancing - * - * \param instancing Should instancing be enabled - * - * \remark This may improve performances - */ - - void AbstractRenderTechnique::EnableInstancing(bool instancing) - { - m_instancingEnabled = instancing; - } - - /*! - * \brief Gets the name of the actual technique - * \return Name of the technique being used - */ - - String AbstractRenderTechnique::GetName() const - { - return RenderTechniques::ToString(GetType()); - } - - /*! - * \brief Checks whether the instancing is enabled - * \return true If it is the case - */ - - bool AbstractRenderTechnique::IsInstancingEnabled() const - { - return m_instancingEnabled; - } -} diff --git a/src/Nazara/Graphics/AbstractViewer.cpp b/src/Nazara/Graphics/AbstractViewer.cpp deleted file mode 100644 index e2c4a8f8e..000000000 --- a/src/Nazara/Graphics/AbstractViewer.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::AbstractViewer - * \brief Graphics class that represents the viewer for our scene - * - * \remark This class is abstract - */ - - AbstractViewer::~AbstractViewer() = default; - - Vector3f AbstractViewer::Project(const Nz::Vector3f& worldPosition) const - { - Vector4f pos4D(worldPosition, 1.f); - pos4D = GetViewMatrix() * pos4D; - pos4D = GetProjectionMatrix() * pos4D; - pos4D /= pos4D.w; - - Rectf viewport = Rectf(GetViewport()); - - Nz::Vector3f screenPosition(pos4D.x * 0.5f + 0.5f, -pos4D.y * 0.5f + 0.5f, pos4D.z * 0.5f + 0.5f); - screenPosition.x = screenPosition.x * viewport.width + viewport.x; - screenPosition.y = screenPosition.y * viewport.height + viewport.y; - - return screenPosition; - } - - float AbstractViewer::ProjectDepth(float depth) - { - const Matrix4f& projectionMatrix = GetProjectionMatrix(); - float a = projectionMatrix(2, 2); - float b = projectionMatrix(2, 3); - - return (0.5f * (-a * depth + b) / depth + 0.5f); - } - - Vector3f AbstractViewer::Unproject(const Nz::Vector3f& screenPos) const - { - Rectf viewport = Rectf(GetViewport()); - - Nz::Vector4f normalizedPosition; - normalizedPosition.x = (screenPos.x - viewport.x) / viewport.width * 2.f - 1.f; - normalizedPosition.y = (screenPos.y - viewport.y) / viewport.height * 2.f - 1.f; - normalizedPosition.z = screenPos.z * 2.f - 1.f; - normalizedPosition.w = 1.f; - - normalizedPosition.y = -normalizedPosition.y; - - Nz::Matrix4f invMatrix = GetViewMatrix() * GetProjectionMatrix(); - invMatrix.Inverse(); - - Nz::Vector4f worldPos = invMatrix * normalizedPosition; - worldPos /= worldPos.w; - - return Nz::Vector3f(worldPos.x, worldPos.y, worldPos.z); - } -} diff --git a/src/Nazara/Graphics/BasicRenderQueue.cpp b/src/Nazara/Graphics/BasicRenderQueue.cpp deleted file mode 100644 index 2b8dd58a3..000000000 --- a/src/Nazara/Graphics/BasicRenderQueue.cpp +++ /dev/null @@ -1,957 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -///TODO: Replace sinus/cosinus by a lookup table (which will lead to a speed up about 10x) - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::BasicRenderQueue - * \brief Graphics class that represents a simple rendering queue - */ - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param colorPtr Color of the billboards if null, Color::White is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void BasicRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - Vector2f defaultSinCos(0.f, 1.f); // sin(0) = 0, cos(0) = 1 - - if (!sinCosPtr) - sinCosPtr.Reset(&defaultSinCos, 0); // The trick here is to put the stride to zero, which leads the pointer to be immobile - - if (!colorPtr) - colorPtr.Reset(&Color::White, 0); // Same - - if (material->IsDepthSortingEnabled()) - { - for (std::size_t i = 0; i < billboardCount; ++i) - { - depthSortedBillboards.Insert({ - renderOrder, - material, - scissorRect, - { - *colorPtr++, - *positionPtr++, - *sizePtr++, - *sinCosPtr++ - } - }); - } - } - else - { - std::size_t billboardIndex = m_billboards.size(); - m_billboards.resize(billboardIndex + billboardCount); - BillboardData* data = &m_billboards[billboardIndex]; - - for (std::size_t i = 0; i < billboardCount; ++i) - { - data->center = *positionPtr++; - data->color = *colorPtr++; - data->sinCos = *sinCosPtr++; - data->size = *sizePtr++; - data++; - } - - billboards.Insert({ - renderOrder, - material, - scissorRect, - billboardCount, - billboardIndex - }); - } - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void BasicRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - Vector2f defaultSinCos(0.f, 1.f); // sin(0) = 0, cos(0) = 1 - - if (!sinCosPtr) - sinCosPtr.Reset(&defaultSinCos, 0); // The trick here is to put the stride to zero, which leads the pointer to be immobile - - float defaultAlpha = 1.f; - - if (!alphaPtr) - alphaPtr.Reset(&defaultAlpha, 0); // Same - - if (material->IsDepthSortingEnabled()) - { - for (std::size_t i = 0; i < billboardCount; ++i) - { - depthSortedBillboards.Insert({ - renderOrder, - material, - scissorRect, - { - ComputeColor(*alphaPtr++), - *positionPtr++, - *sizePtr++, - *sinCosPtr++ - } - }); - } - } - else - { - std::size_t billboardIndex = m_billboards.size(); - m_billboards.resize(billboardIndex + billboardCount); - BillboardData* data = &m_billboards[billboardIndex]; - - for (std::size_t i = 0; i < billboardCount; ++i) - { - data->center = *positionPtr++; - data->color = ComputeColor(*alphaPtr++); - data->sinCos = *sinCosPtr++; - data->size = *sizePtr++; - data++; - } - - billboards.Insert({ - renderOrder, - material, - scissorRect, - billboardCount, - billboardIndex - }); - } - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param colorPtr Color of the billboards if null, Color::White is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void BasicRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - float defaultRotation = 0.f; - - if (!anglePtr) - anglePtr.Reset(&defaultRotation, 0); // The trick here is to put the stride to zero, which leads the pointer to be immobile - - if (!colorPtr) - colorPtr.Reset(&Color::White, 0); // Same - - if (material->IsDepthSortingEnabled()) - { - for (std::size_t i = 0; i < billboardCount; ++i) - { - depthSortedBillboards.Insert({ - renderOrder, - material, - scissorRect, - { - *colorPtr++, - *positionPtr++, - *sizePtr++, - ComputeSinCos(*anglePtr++) - } - }); - } - } - else - { - std::size_t billboardIndex = m_billboards.size(); - m_billboards.resize(billboardIndex + billboardCount); - BillboardData* data = &m_billboards[billboardIndex]; - - for (std::size_t i = 0; i < billboardCount; ++i) - { - data->center = *positionPtr++; - data->color = *colorPtr++; - data->sinCos = ComputeSinCos(*anglePtr++); - data->size = *sizePtr++; - data++; - } - - billboards.Insert({ - renderOrder, - material, - scissorRect, - billboardCount, - billboardIndex - }); - } - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void BasicRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - float defaultRotation = 0.f; - - if (!anglePtr) - anglePtr.Reset(&defaultRotation, 0); // The trick here is to put the stride to zero, which leads the pointer to be immobile - - float defaultAlpha = 1.f; - - if (!alphaPtr) - alphaPtr.Reset(&defaultAlpha, 0); // Same - - if (material->IsDepthSortingEnabled()) - { - for (std::size_t i = 0; i < billboardCount; ++i) - { - depthSortedBillboards.Insert({ - renderOrder, - material, - scissorRect, - { - ComputeColor(*alphaPtr++), - *positionPtr++, - *sizePtr++, - ComputeSinCos(*anglePtr++) - } - }); - } - } - else - { - std::size_t billboardIndex = m_billboards.size(); - m_billboards.resize(billboardIndex + billboardCount); - BillboardData* data = &m_billboards[billboardIndex]; - - for (std::size_t i = 0; i < billboardCount; ++i) - { - data->center = *positionPtr++; - data->color = ComputeColor(*alphaPtr++); - data->sinCos = ComputeSinCos(*anglePtr++); - data->size = *sizePtr++; - data++; - } - - billboards.Insert({ - renderOrder, - material, - scissorRect, - billboardCount, - billboardIndex - }); - } - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param colorPtr Color of the billboards if null, Color::White is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void BasicRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - Vector2f defaultSinCos(0.f, 1.f); // sin(0) = 0, cos(0) = 1 - - if (!sinCosPtr) - sinCosPtr.Reset(&defaultSinCos, 0); // The trick here is to put the stride to zero, which leads the pointer to be immobile - - if (!colorPtr) - colorPtr.Reset(&Color::White, 0); // Same - - if (material->IsDepthSortingEnabled()) - { - for (std::size_t i = 0; i < billboardCount; ++i) - { - depthSortedBillboards.Insert({ - renderOrder, - material, - scissorRect, - { - *colorPtr++, - *positionPtr++, - ComputeSize(*sizePtr++), - *sinCosPtr++ - } - }); - } - } - else - { - std::size_t billboardIndex = m_billboards.size(); - m_billboards.resize(billboardIndex + billboardCount); - BillboardData* data = &m_billboards[billboardIndex]; - - for (std::size_t i = 0; i < billboardCount; ++i) - { - data->center = *positionPtr++; - data->color = *colorPtr++; - data->sinCos = *sinCosPtr++; - data->size = ComputeSize(*sizePtr++); - data++; - } - - billboards.Insert({ - renderOrder, - material, - scissorRect, - billboardCount, - billboardIndex - }); - } - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void BasicRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - Vector2f defaultSinCos(0.f, 1.f); // sin(0) = 0, cos(0) = 1 - - if (!sinCosPtr) - sinCosPtr.Reset(&defaultSinCos, 0); // The trick here is to put the stride to zero, which leads the pointer to be immobile - - float defaultAlpha = 1.f; - - if (!alphaPtr) - alphaPtr.Reset(&defaultAlpha, 0); // Same - - if (material->IsDepthSortingEnabled()) - { - for (std::size_t i = 0; i < billboardCount; ++i) - { - depthSortedBillboards.Insert({ - renderOrder, - material, - scissorRect, - { - ComputeColor(*alphaPtr++), - *positionPtr++, - ComputeSize(*sizePtr++), - *sinCosPtr++ - } - }); - } - } - else - { - std::size_t billboardIndex = m_billboards.size(); - m_billboards.resize(billboardIndex + billboardCount); - BillboardData* data = &m_billboards[billboardIndex]; - - for (std::size_t i = 0; i < billboardCount; ++i) - { - data->center = *positionPtr++; - data->color = ComputeColor(*alphaPtr++); - data->sinCos = *sinCosPtr++; - data->size = ComputeSize(*sizePtr++); - data++; - } - - billboards.Insert({ - renderOrder, - material, - scissorRect, - billboardCount, - billboardIndex - }); - } - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param colorPtr Color of the billboards if null, Color::White is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void BasicRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - float defaultRotation = 0.f; - - if (!anglePtr) - anglePtr.Reset(&defaultRotation, 0); // The trick here is to put the stride to zero, which leads the pointer to be immobile - - if (!colorPtr) - colorPtr.Reset(&Color::White, 0); // Same - - if (material->IsDepthSortingEnabled()) - { - for (std::size_t i = 0; i < billboardCount; ++i) - { - depthSortedBillboards.Insert({ - renderOrder, - material, - scissorRect, - { - *colorPtr++, - *positionPtr++, - ComputeSize(*sizePtr++), - ComputeSinCos(*anglePtr++) - } - }); - } - } - else - { - std::size_t billboardIndex = m_billboards.size(); - m_billboards.resize(billboardIndex + billboardCount); - BillboardData* data = &m_billboards[billboardIndex]; - - for (std::size_t i = 0; i < billboardCount; ++i) - { - data->center = *positionPtr++; - data->color = *colorPtr++; - data->sinCos = ComputeSinCos(*anglePtr++); - data->size = ComputeSize(*sizePtr++); - data++; - } - - billboards.Insert({ - renderOrder, - material, - scissorRect, - billboardCount, - billboardIndex - }); - } - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void BasicRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - float defaultRotation = 0.f; - - if (!anglePtr) - anglePtr.Reset(&defaultRotation, 0); // The trick here is to put the stride to zero, which leads the pointer to be immobile - - float defaultAlpha = 1.f; - - if (!alphaPtr) - alphaPtr.Reset(&defaultAlpha, 0); // Same - - if (material->IsDepthSortingEnabled()) - { - for (std::size_t i = 0; i < billboardCount; ++i) - { - depthSortedBillboards.Insert({ - renderOrder, - material, - scissorRect, - { - ComputeColor(*alphaPtr++), - *positionPtr++, - ComputeSize(*sizePtr++), - ComputeSinCos(*anglePtr++) - } - }); - } - } - else - { - std::size_t billboardIndex = m_billboards.size(); - m_billboards.resize(billboardIndex + billboardCount); - BillboardData* data = &m_billboards[billboardIndex]; - - for (std::size_t i = 0; i < billboardCount; ++i) - { - data->center = *positionPtr++; - data->color = ComputeColor(*alphaPtr++); - data->sinCos = ComputeSinCos(*anglePtr++); - data->size = ComputeSize(*sizePtr++); - data++; - } - - billboards.Insert({ - renderOrder, - material, - scissorRect, - billboardCount, - billboardIndex - }); - } - } - - /*! - * \brief Adds drawable to the queue - * - * \param renderOrder Order of rendering - * \param drawable Drawable user defined - * - * \remark Produces a NazaraError if drawable is invalid - */ - void BasicRenderQueue::AddDrawable(int renderOrder, const Drawable* drawable) - { - NazaraAssert(drawable, "Invalid material"); - - RegisterLayer(renderOrder); - - customDrawables.Insert({ - renderOrder, - drawable - }); - } - - /*! - * \brief Adds mesh to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the mesh - * \param meshData Data of the mesh - * \param meshAABB Box of the mesh - * \param transformMatrix Matrix of the mesh - * - * \remark Produces a NazaraAssert if material is invalid - */ - void BasicRenderQueue::AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - Spheref obbSphere(transformMatrix.GetTranslation() + meshAABB.GetCenter(), meshAABB.GetSquaredRadius()); - - if (material->IsDepthSortingEnabled()) - { - depthSortedModels.Insert({ - renderOrder, - meshData, - material, - transformMatrix, - scissorRect, - obbSphere - }); - } - else - { - models.Insert({ - renderOrder, - meshData, - material, - transformMatrix, - scissorRect, - obbSphere - }); - } - } - - /*! - * \brief Adds sprites to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the sprites - * \param vertices Buffer of data for the sprites - * \param spriteCount Number of sprites - * \param overlay Texture of the sprites - * - * \remark Produces a NazaraAssert if material is invalid - */ - void BasicRenderQueue::AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay /*= nullptr*/) - { - NazaraAssert(material, "Invalid material"); - - RegisterLayer(renderOrder); - - if (material->IsDepthSortingEnabled()) - { - depthSortedSprites.Insert({ - renderOrder, - spriteCount, - material, - overlay, - vertices, - scissorRect - }); - } - else - { - basicSprites.Insert({ - renderOrder, - spriteCount, - material, - overlay, - vertices, - scissorRect - }); - } - } - - /*! - * \brief Clears the queue - * - * \param fully Should everything be cleared or we can keep layers - */ - - void BasicRenderQueue::Clear(bool fully) - { - AbstractRenderQueue::Clear(fully); - - basicSprites.Clear(); - billboards.Clear(); - depthSortedBillboards.Clear(); - depthSortedModels.Clear(); - depthSortedSprites.Clear(); - models.Clear(); - - m_pipelineCache.clear(); - m_materialCache.clear(); - m_overlayCache.clear(); - m_shaderCache.clear(); - m_textureCache.clear(); - m_vertexBufferCache.clear(); - - m_billboards.clear(); - m_renderLayers.clear(); - } - - /*! - * \brief Sorts the object according to the viewer position, furthest to nearest - * - * \param viewer Viewer of the scene - */ - - void BasicRenderQueue::Sort(const AbstractViewer* viewer) - { - m_layerCache.clear(); - for (int layer : m_renderLayers) - m_layerCache.emplace(layer, m_layerCache.size()); - - auto GetOrInsert = [](auto& container, auto&& value) - { - auto it = container.find(value); - if (it == container.end()) - it = container.emplace(value, container.size()).first; - - return it->second; - }; - - basicSprites.Sort([&](const SpriteChain& vertices) - { - // RQ index: - // - Layer (16bits) - // - Pipeline (8bits) - // - Material (8bits) - // - Shader? (8bits) - // - Textures (8bits) - // - Overlay (8bits) - // - Scissor (4bits) - // - ??? (4bits) - - UInt64 layerIndex = m_layerCache[vertices.layerIndex]; - UInt64 pipelineIndex = GetOrInsert(m_pipelineCache, vertices.material->GetPipeline()); - UInt64 materialIndex = GetOrInsert(m_materialCache, vertices.material); - UInt64 shaderIndex = GetOrInsert(m_shaderCache, vertices.material->GetShader()); - UInt64 textureIndex = GetOrInsert(m_textureCache, vertices.material->GetDiffuseMap()); - UInt64 overlayIndex = GetOrInsert(m_overlayCache, vertices.overlay); - UInt64 scissorIndex = 0; //< TODO - - UInt64 index = (layerIndex & 0xFFFF) << 48 | - (pipelineIndex & 0xFF) << 40 | - (materialIndex & 0xFF) << 32 | - (shaderIndex & 0xFF) << 24 | - (textureIndex & 0xFF) << 16 | - (overlayIndex & 0xFF) << 8 | - (scissorIndex & 0x0F) << 4; - - return index; - }); - - billboards.Sort([&](const BillboardChain& billboard) - { - // RQ index: - // - Layer (16bits) - // - Pipeline (8bits) - // - Material (8bits) - // - Shader? (8bits) - // - Textures (8bits) - // - Scissor (4bits) - // - ??? (12bits) - - UInt64 layerIndex = m_layerCache[billboard.layerIndex]; - UInt64 pipelineIndex = GetOrInsert(m_pipelineCache, billboard.material->GetPipeline()); - UInt64 materialIndex = GetOrInsert(m_materialCache, billboard.material); - UInt64 shaderIndex = GetOrInsert(m_shaderCache, billboard.material->GetShader()); - UInt64 textureIndex = GetOrInsert(m_textureCache, billboard.material->GetDiffuseMap()); - UInt64 unknownIndex = 0; //< ??? - UInt64 scissorIndex = 0; //< TODO - - UInt64 index = (layerIndex & 0xFFFF) << 48 | - (pipelineIndex & 0xFF) << 40 | - (materialIndex & 0xFF) << 32 | - (shaderIndex & 0xFF) << 24 | - (textureIndex & 0xFF) << 16 | - (scissorIndex & 0x0F) << 12 | - (unknownIndex & 0xFF) << 0; - - return index; - }); - - customDrawables.Sort([&](const CustomDrawable& drawable) - { - // RQ index: - // - Layer (16bits) - - UInt64 layerIndex = m_layerCache[drawable.layerIndex]; - - UInt64 index = (layerIndex & 0xFFFF) << 48; - - return index; - - }); - - models.Sort([&](const Model& renderData) - { - // RQ index: - // - Layer (16bits) - // - Pipeline (8bits) - // - Material (8bits) - // - Shader? (8bits) - // - Textures (8bits) - // - Buffers (8bits) - // - Scissor (4bits) - // - ??? (4bits) - - UInt64 layerIndex = m_layerCache[renderData.layerIndex]; - UInt64 pipelineIndex = GetOrInsert(m_pipelineCache, renderData.material->GetPipeline()); - UInt64 materialIndex = GetOrInsert(m_materialCache, renderData.material); - UInt64 shaderIndex = GetOrInsert(m_shaderCache, renderData.material->GetShader()); - UInt64 textureIndex = GetOrInsert(m_textureCache, renderData.material->GetDiffuseMap()); - UInt64 bufferIndex = GetOrInsert(m_vertexBufferCache, renderData.meshData.vertexBuffer); - UInt64 scissorIndex = 0; //< TODO - UInt64 depthIndex = 0; //< TODO - - UInt64 index = (layerIndex & 0xFFFF) << 48 | - (pipelineIndex & 0xFF) << 40 | - (materialIndex & 0xFF) << 32 | - (shaderIndex & 0xFF) << 24 | - (textureIndex & 0xFF) << 16 | - (bufferIndex & 0xFF) << 8 | - (scissorIndex & 0x0F) << 4; - - return index; - }); - - static_assert(std::numeric_limits::is_iec559, "The following sorting functions relies on IEEE 754 floatings-points"); - -#if defined(arm) && \ - ((defined(__MAVERICK__) && defined(NAZARA_BIG_ENDIAN)) || \ - (!defined(__SOFTFP__) && !defined(__VFP_FP__) && !defined(__MAVERICK__))) - #error The following code relies on native-endian IEEE-754 representation, which your platform does not guarantee -#endif - - Planef nearPlane = viewer->GetFrustum().GetPlane(FrustumPlane_Near); - - depthSortedBillboards.Sort([&](const Billboard& billboard) - { - // RQ index: - // - Layer (16bits) - // - Depth (32bits) - // - ?? (16bits) - - // Reinterpret depth as UInt32 (this will work as long as they're all either positive or negative, - // a negative distance may happen with billboard behind the camera which we don't care about since they'll not be rendered) - float depth = nearPlane.Distance(billboard.data.center); - - UInt64 layerIndex = m_layerCache[billboard.layerIndex]; - UInt64 depthIndex = ~reinterpret_cast(depth); - - UInt64 index = (layerIndex & 0xFFFF) << 48 | - (depthIndex & 0xFFFFFFFF) << 16; - - return index; - }); - - if (viewer->GetProjectionType() == ProjectionType_Orthogonal) - { - depthSortedModels.Sort([&](const Model& model) - { - // RQ index: - // - Layer (16bits) - // - Depth (32bits) - // - ?? (16bits) - - float depth = nearPlane.Distance(model.obbSphere.GetPosition()); - - UInt64 layerIndex = m_layerCache[model.layerIndex]; - UInt64 depthIndex = ~reinterpret_cast(depth); - - UInt64 index = (layerIndex & 0xFFFF) << 48 | - (depthIndex & 0xFFFFFFFF) << 16; - - return index; - }); - - depthSortedSprites.Sort([&](const SpriteChain& spriteChain) - { - // RQ index: - // - Layer (16bits) - // - Depth (32bits) - // - ?? (16bits) - - float depth = nearPlane.Distance(spriteChain.vertices[0].position); - - UInt64 layerIndex = m_layerCache[spriteChain.layerIndex]; - UInt64 depthIndex = ~reinterpret_cast(depth); - - UInt64 index = (layerIndex & 0xFFFF) << 48 | - (depthIndex & 0xFFFFFFFF) << 16; - - return index; - }); - } - else - { - Vector3f viewerPos = viewer->GetEyePosition(); - - depthSortedModels.Sort([&](const Model& model) - { - // RQ index: - // - Layer (16bits) - // - Depth (32bits) - // - ?? (16bits) - - float depth = viewerPos.SquaredDistance(model.obbSphere.GetPosition()); - - UInt64 layerIndex = m_layerCache[model.layerIndex]; - UInt64 depthIndex = ~reinterpret_cast(depth); - - UInt64 index = (layerIndex & 0x0F) << 48 | - (depthIndex & 0xFFFFFFFF) << 16; - - return index; - }); - - depthSortedSprites.Sort([&](const SpriteChain& sprites) - { - // RQ index: - // - Layer (16bits) - // - Depth (32bits) - // - ?? (16bits) - - float depth = viewerPos.SquaredDistance(sprites.vertices[0].position); - - UInt64 layerIndex = m_layerCache[sprites.layerIndex]; - UInt64 depthIndex = ~reinterpret_cast(depth); - - UInt64 index = (layerIndex & 0xFFFF) << 48 | - (depthIndex & 0xFFFFFFFF) << 16; - - return index; - }); - } - } -} diff --git a/src/Nazara/Graphics/Billboard.cpp b/src/Nazara/Graphics/Billboard.cpp deleted file mode 100644 index 4ad49d097..000000000 --- a/src/Nazara/Graphics/Billboard.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::Billboard - * \brief Graphics class that represents a billboard, a 2D surface which simulates a 3D object - */ - - /*! - * \brief Adds this billboard to the render queue - * - * \param renderQueue Queue to be added - * \param instanceData Data used for instance - */ - - void Billboard::AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const - { - Nz::Vector3f position = instanceData.transformMatrix.GetTranslation(); - renderQueue->AddBillboards(instanceData.renderOrder, GetMaterial(), 1, scissorRect, &position, &m_size, &m_sinCos, &m_color); - } - - /*! - * \brief Clones this billboard - */ - std::unique_ptr Billboard::Clone() const - { - return std::make_unique(*this); - } - - /* - * \brief Makes the bounding volume of this billboard - */ - - void Billboard::MakeBoundingVolume() const - { - // As billboard always face the screen, we must take its maximum size in account on every axis - float maxSize = float(M_SQRT2) * std::max(m_size.x, m_size.y); - - Nz::Vector3f halfSize = (maxSize * Vector3f::Right() + maxSize * Vector3f::Down() + maxSize * Vector3f::Forward()) / 2.f; - - m_boundingVolume.Set(-halfSize, halfSize); - } - - BillboardLibrary::LibraryMap Billboard::s_library; -} diff --git a/src/Nazara/Graphics/ColorBackground.cpp b/src/Nazara/Graphics/ColorBackground.cpp deleted file mode 100644 index 465b29964..000000000 --- a/src/Nazara/Graphics/ColorBackground.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - /*! - * \brief Defines render states - * \return RenderStates for the color background - */ - - RenderStates BuildRenderStates() - { - RenderStates states; - states.cullingSide = FaceSide_Back; - states.depthFunc = RendererComparison_Equal; - states.depthBuffer = true; - states.depthWrite = false; - states.faceCulling = true; - - return states; - } - } - - /*! - * \ingroup graphics - * \class Nz::ColorBackground - * \brief Graphics class that represents a background with uniform color - */ - - /*! - * \brief Constructs a ColorBackground object with a color - * - * \param color Uniform color (by default Black) - */ - - ColorBackground::ColorBackground(const Color& color) : - m_color(color) - { - m_uberShader = UberShaderLibrary::Get("Basic"); - - ParameterList list; - list.SetParameter("UNIFORM_VERTEX_DEPTH", true); - - m_uberShaderInstance = m_uberShader->Get(list); - - const Shader* shader = m_uberShaderInstance->GetShader(); - m_materialDiffuseUniform = shader->GetUniformLocation("MaterialDiffuse"); - m_vertexDepthUniform = shader->GetUniformLocation("VertexDepth"); - } - - /*! - * \brief Draws this relatively to the viewer - * - * \param viewer Viewer for the background - */ - - void ColorBackground::Draw(const AbstractViewer* viewer) const - { - NazaraUnused(viewer); - - static RenderStates states(BuildRenderStates()); - - Renderer::SetRenderStates(states); - - m_uberShaderInstance->Activate(); - - const Shader* shader = m_uberShaderInstance->GetShader(); - shader->SendColor(m_materialDiffuseUniform, m_color); - shader->SendFloat(m_vertexDepthUniform, 1.f); - - Renderer::DrawFullscreenQuad(); - } - - /*! - * \brief Gets the background type - * \return Type of background - */ - - BackgroundType ColorBackground::GetBackgroundType() const - { - return BackgroundType_Color; - } - - /*! - * \brief Gets the color of the background - * \return Background color - */ - - Color ColorBackground::GetColor() const - { - return m_color; - } - - /*! - * \brief Sets the color of the background - * - * \param color Background color - */ - - void ColorBackground::SetColor(const Color& color) - { - m_color = color; - } -} diff --git a/src/Nazara/Graphics/Debug/NewOverload.cpp b/src/Nazara/Graphics/Debug/NewOverload.cpp deleted file mode 100644 index 74d124395..000000000 --- a/src/Nazara/Graphics/Debug/NewOverload.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_GRAPHICS_MANAGE_MEMORY - -#include -#include // Nécessaire ? - -void* operator new(std::size_t size) -{ - return Nz::MemoryManager::Allocate(size, false); -} - -void* operator new[](std::size_t size) -{ - return Nz::MemoryManager::Allocate(size, true); -} - -void operator delete(void* pointer) noexcept -{ - Nz::MemoryManager::Free(pointer, false); -} - -void operator delete[](void* pointer) noexcept -{ - Nz::MemoryManager::Free(pointer, true); -} - -#endif // NAZARA_GRAPHICS_MANAGE_MEMORY diff --git a/src/Nazara/Graphics/DeferredBloomPass.cpp b/src/Nazara/Graphics/DeferredBloomPass.cpp deleted file mode 100644 index 5dc34d3d2..000000000 --- a/src/Nazara/Graphics/DeferredBloomPass.cpp +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::DeferredBloomPass - * \brief Graphics class that represents the pass for bloom in deferred rendering - */ - - /*! - * \brief Constructs a DeferredBloomPass object by default - */ - - DeferredBloomPass::DeferredBloomPass() : - m_uniformUpdated(false), - m_brightLuminance(0.8f), - m_brightMiddleGrey(0.5f), - m_brightThreshold(0.4f), - m_blurPassCount(5) - { - m_bilinearSampler.SetAnisotropyLevel(1); - m_bilinearSampler.SetFilterMode(SamplerFilter_Bilinear); - m_bilinearSampler.SetWrapMode(SamplerWrap_Clamp); - - m_bloomBrightShader = ShaderLibrary::Get("DeferredBloomBright"); - m_bloomFinalShader = ShaderLibrary::Get("DeferredBloomFinal"); - m_bloomStates.depthBuffer = false; - m_gaussianBlurShader = ShaderLibrary::Get("DeferredGaussianBlur"); - m_gaussianBlurShaderFilterLocation = m_gaussianBlurShader->GetUniformLocation("Filter"); - - for (unsigned int i = 0; i < 2; ++i) - m_bloomTextures[i] = Texture::New(); - } - - DeferredBloomPass::~DeferredBloomPass() = default; - - /*! - * \brief Gets the number of pass for blur - * \return Number of pass for blur - */ - - unsigned int DeferredBloomPass::GetBlurPassCount() const - { - return m_blurPassCount; - } - - /*! - * \brief Gets the coefficiant for luminosity - * \return Luminosity of bright elements - */ - - float DeferredBloomPass::GetBrightLuminance() const - { - return m_brightLuminance; - } - - /*! - * \brief Gets the coefficiant for the middle grey - * \return Luminosity of grey elements - */ - - float DeferredBloomPass::GetBrightMiddleGrey() const - { - return m_brightMiddleGrey; - } - - /*! - * \brief Gets the coefficiant for things to be bright - * \return Threshold for bright elements - */ - - float DeferredBloomPass::GetBrightThreshold() const - { - return m_brightThreshold; - } - - /*! - * \brief Gets the ith texture - * \return Texture computed - * - * \param i Index of the texture - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if index is invalid - */ - - Texture* DeferredBloomPass::GetTexture(unsigned int i) const - { - #if NAZARA_GRAPHICS_SAFE - if (i >= 2) - { - NazaraError("Texture index out of range (" + String::Number(i) + " >= 2)"); - return nullptr; - } - #endif - - return m_bloomTextures[i]; - } - - /*! - * \brief Processes the work on the data while working with textures - * \return true - * - * \param sceneData Data for the scene - * \param firstWorkTexture Index of the first texture to work with - * \param firstWorkTexture Index of the second texture to work with - */ - - bool DeferredBloomPass::Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const - { - NazaraUnused(sceneData); - - Renderer::SetRenderStates(m_bloomStates); - Renderer::SetTextureSampler(0, m_bilinearSampler); - Renderer::SetTextureSampler(1, m_bilinearSampler); - - m_workRTT->SetColorTarget(firstWorkTexture); - Renderer::SetTarget(m_workRTT); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x, m_dimensions.y)); - - Renderer::SetShader(m_bloomBrightShader); - if (!m_uniformUpdated) - { - m_bloomBrightShader->SendFloat(m_bloomBrightShader->GetUniformLocation("BrightLuminance"), m_brightLuminance); - m_bloomBrightShader->SendFloat(m_bloomBrightShader->GetUniformLocation("BrightMiddleGrey"), m_brightMiddleGrey); - m_bloomBrightShader->SendFloat(m_bloomBrightShader->GetUniformLocation("BrightThreshold"), m_brightThreshold); - - m_uniformUpdated = true; - } - - Renderer::SetTexture(0, m_workTextures[secondWorkTexture]); - Renderer::DrawFullscreenQuad(); - - Renderer::SetTarget(&m_bloomRTT); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x / 8, m_dimensions.y / 8)); - - Renderer::SetShader(m_gaussianBlurShader); - - for (unsigned int i = 0; i < m_blurPassCount; ++i) - { - m_bloomRTT.SetColorTarget(0); // bloomTextureA - - m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, Vector2f(1.f, 0.f)); - - Renderer::SetTexture(0, (i == 0) ? m_workTextures[firstWorkTexture] : static_cast(m_bloomTextures[1])); - Renderer::DrawFullscreenQuad(); - - m_bloomRTT.SetColorTarget(1); // bloomTextureB - - m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, Vector2f(0.f, 1.f)); - - Renderer::SetTexture(0, m_bloomTextures[0]); - Renderer::DrawFullscreenQuad(); - } - - m_workRTT->SetColorTarget(firstWorkTexture); - Renderer::SetTarget(m_workRTT); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x, m_dimensions.y)); - - Renderer::SetShader(m_bloomFinalShader); - Renderer::SetTexture(0, m_bloomTextures[1]); - Renderer::SetTexture(1, m_workTextures[secondWorkTexture]); - Renderer::DrawFullscreenQuad(); - - return true; - } - - /*! - * \brief Resizes the texture sizes - * \return true If successful - * - * \param dimensions Dimensions for the compute texture - */ - - bool DeferredBloomPass::Resize(const Vector2ui& dimensions) - { - DeferredRenderPass::Resize(dimensions); - - m_bloomRTT.Create(true); - for (unsigned int i = 0; i < 2; ++i) - { - m_bloomTextures[i]->Create(ImageType_2D, PixelFormat_RGBA8, dimensions.x / 8, dimensions.y / 8); - m_bloomRTT.AttachTexture(AttachmentPoint_Color, i, m_bloomTextures[i]); - } - m_bloomRTT.Unlock(); - - if (!m_bloomRTT.IsComplete()) - { - NazaraError("Incomplete RTT"); - return false; - } - - return true; - } - - /*! - * \brief Sets the number of pass for blur - * - * \param passCount Number of pass for blur - */ - - void DeferredBloomPass::SetBlurPassCount(unsigned int passCount) - { - m_blurPassCount = passCount; // N'est pas une uniforme - } - - /*! - * \brief Sets the coefficiant for luminosity - * - * \param luminance Luminosity of bright elements - */ - - void DeferredBloomPass::SetBrightLuminance(float luminance) - { - m_brightLuminance = luminance; - m_uniformUpdated = false; - } - - /*! - * \brief Sets the coefficiant for the middle grey - * - * \param middleGrey Luminosity of grey elements - */ - - void DeferredBloomPass::SetBrightMiddleGrey(float middleGrey) - { - m_brightMiddleGrey = middleGrey; - m_uniformUpdated = false; - } - - /*! - * \brief Sets the coefficiant for things to be bright - * - * \param threshold Threshold for bright elements - */ - - void DeferredBloomPass::SetBrightThreshold(float threshold) - { - m_brightThreshold = threshold; - m_uniformUpdated = false; - } -} diff --git a/src/Nazara/Graphics/DeferredDOFPass.cpp b/src/Nazara/Graphics/DeferredDOFPass.cpp deleted file mode 100644 index 9cf138d2b..000000000 --- a/src/Nazara/Graphics/DeferredDOFPass.cpp +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - /*! - * \brief Builds the shader for the depth of field - * \return Reference to the shader newly created - */ - // http://digitalerr0r.wordpress.com/2009/05/16/xna-shader-programming-tutorial-20-depth-of-field/ - ShaderRef BuildDepthOfFieldShader() - { - const char* fragmentSource = - "#version 140\n" - - "out vec4 RenderTarget0;\n" - - "uniform sampler2D BlurTexture;\n" - "uniform sampler2D ColorTexture;\n" - "uniform sampler2D GBuffer1;\n" - "uniform vec2 InvTargetSize;" "\n" - - "float Distance = 30.0;\n" - "float Range = 10.0;\n" - "float Near = 0.1;\n" - "float Far = (1000.0) / (1000.0 - 0.1);\n" - //"float Far = 50.0;\n" - - "void main()\n" - "{\n" - "vec2 texCoord = gl_FragCoord.xy * InvTargetSize;\n" - - "// Get our original pixel from ColorMap\n" - "vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb;\n" - - "// Get our bloom pixel from bloom texture\n" - "vec3 blur = textureLod(BlurTexture, texCoord, 0.0).rgb;\n" - - "float depth = textureLod(GBuffer1, texCoord, 0.0).w;\n" - "depth = (2.0 * 0.1) / (1000.0 + 0.1 - depth * (1000.0 - 0.1));" - "depth = 1.0 - depth;\n" - - "float fSceneZ = ( -Near * Far ) / ( depth - Far);\n" - "float blurFactor = clamp(abs(fSceneZ - Distance)/Range, 0.0, 1.0);\n" - - "RenderTarget0 = vec4(mix(color, blur, blurFactor), 1.0);\n" - "}\n"; - - const char* vertexSource = - "#version 140\n" - - "in vec3 VertexPosition;\n" - - "void main()\n" - "{\n" - "\t" "gl_Position = vec4(VertexPosition, 1.0);" "\n" - "}\n"; - - ///TODO: Remplacer ça par des ShaderNode - ShaderRef shader = Shader::New(); - if (!shader->Create()) - { - NazaraError("Failed to load create shader"); - return nullptr; - } - - if (!shader->AttachStageFromSource(ShaderStageType_Fragment, fragmentSource)) - { - NazaraError("Failed to load fragment shader"); - return nullptr; - } - - if (!shader->AttachStageFromSource(ShaderStageType_Vertex, vertexSource)) - { - NazaraError("Failed to load vertex shader"); - return nullptr; - } - - if (!shader->Link()) - { - NazaraError("Failed to link shader"); - return nullptr; - } - - return shader; - } - } - - /*! - * \ingroup graphics - * \class Nz::DeferredDOFPass - * \brief Graphics class that represents the pass for depth of field in deferred rendering - */ - - /*! - * \brief Constructs a DeferredDOFPass object by default - */ - - DeferredDOFPass::DeferredDOFPass() - { - m_dofShader = BuildDepthOfFieldShader(); - m_dofShader->SendInteger(m_dofShader->GetUniformLocation("ColorTexture"), 0); - m_dofShader->SendInteger(m_dofShader->GetUniformLocation("BlurTexture"), 1); - m_dofShader->SendInteger(m_dofShader->GetUniformLocation("GBuffer1"), 2); - - m_gaussianBlurShader = ShaderLibrary::Get("DeferredGaussianBlur"); - m_gaussianBlurShaderFilterLocation = m_gaussianBlurShader->GetUniformLocation("Filter"); - - for (unsigned int i = 0; i < 2; ++i) - m_dofTextures[i] = Texture::New(); - - m_bilinearSampler.SetAnisotropyLevel(1); - m_bilinearSampler.SetFilterMode(SamplerFilter_Bilinear); - m_bilinearSampler.SetWrapMode(SamplerWrap_Clamp); - - m_pointSampler.SetAnisotropyLevel(1); - m_pointSampler.SetFilterMode(SamplerFilter_Nearest); - m_pointSampler.SetWrapMode(SamplerWrap_Clamp); - - m_states.depthBuffer = false; - } - - DeferredDOFPass::~DeferredDOFPass() = default; - - /*! - * \brief Processes the work on the data while working with textures - * \return true - * - * \param sceneData Data for the scene - * \param firstWorkTexture Index of the first texture to work with - * \param firstWorkTexture Index of the second texture to work with - */ - - bool DeferredDOFPass::Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const - { - NazaraUnused(sceneData); - - Renderer::SetTextureSampler(0, m_pointSampler); - Renderer::SetTextureSampler(1, m_bilinearSampler); - Renderer::SetTextureSampler(2, m_pointSampler); - - Renderer::SetTarget(&m_dofRTT); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x/4, m_dimensions.y/4)); - - Renderer::SetShader(m_gaussianBlurShader); - - const unsigned int dofBlurPass = 2; - for (unsigned int i = 0; i < dofBlurPass; ++i) - { - m_dofRTT.SetColorTarget(0); // dofTextureA - - m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, Vector2f(1.f, 0.f)); - - Renderer::SetTexture(0, (i == 0) ? m_workTextures[secondWorkTexture] : static_cast(m_dofTextures[1])); - Renderer::DrawFullscreenQuad(); - - m_dofRTT.SetColorTarget(1); // dofTextureB - - m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, Vector2f(0.f, 1.f)); - - Renderer::SetTexture(0, m_dofTextures[0]); - Renderer::DrawFullscreenQuad(); - } - - m_workRTT->SetColorTarget(firstWorkTexture); - Renderer::SetTarget(m_workRTT); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x, m_dimensions.y)); - - Renderer::SetShader(m_dofShader); - Renderer::SetTexture(0, m_workTextures[secondWorkTexture]); - Renderer::SetTexture(1, m_dofTextures[1]); - Renderer::SetTexture(2, m_GBuffer[1]); - Renderer::DrawFullscreenQuad(); - - return true; - } - - /*! - * \brief Resizes the texture sizes - * \return true If successful - * - * \param dimensions Dimensions for the compute texture - */ - - bool DeferredDOFPass::Resize(const Vector2ui& dimensions) - { - DeferredRenderPass::Resize(dimensions); - - m_dofRTT.Create(true); - for (unsigned int i = 0; i < 2; ++i) - { - m_dofTextures[i]->Create(ImageType_2D, PixelFormat_RGBA8, dimensions.x/4, dimensions.y/4); - m_dofRTT.AttachTexture(AttachmentPoint_Color, i, m_dofTextures[i]); - } - m_dofRTT.Unlock(); - - if (!m_dofRTT.IsComplete()) - { - NazaraError("Incomplete RTT"); - return false; - } - - return true; - } -} diff --git a/src/Nazara/Graphics/DeferredFXAAPass.cpp b/src/Nazara/Graphics/DeferredFXAAPass.cpp deleted file mode 100644 index eb8052b8a..000000000 --- a/src/Nazara/Graphics/DeferredFXAAPass.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::DeferredFXAAPass - * \brief Graphics class that represents the pass for FXAA in deferred rendering - */ - - /*! - * \brief Constructs a DeferredFXAAPass object by default - */ - - DeferredFXAAPass::DeferredFXAAPass() - { - m_fxaaShader = ShaderLibrary::Get("DeferredFXAA"); - - m_pointSampler.SetAnisotropyLevel(1); - m_pointSampler.SetFilterMode(SamplerFilter_Nearest); - m_pointSampler.SetWrapMode(SamplerWrap_Clamp); - - m_states.depthBuffer = false; - } - - DeferredFXAAPass::~DeferredFXAAPass() = default; - - /*! - * \brief Processes the work on the data while working with textures - * \return true - * - * \param sceneData Data for the scene - * \param firstWorkTexture Index of the first texture to work with - * \param firstWorkTexture Index of the second texture to work with - */ - - bool DeferredFXAAPass::Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const - { - NazaraUnused(sceneData); - - m_workRTT->SetColorTarget(firstWorkTexture); - Renderer::SetTarget(m_workRTT); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x, m_dimensions.y)); - - Renderer::SetRenderStates(m_states); - Renderer::SetShader(m_fxaaShader); - Renderer::SetTexture(0, m_workTextures[secondWorkTexture]); - Renderer::SetTextureSampler(0, m_pointSampler); - Renderer::DrawFullscreenQuad(); - - return true; - } -} diff --git a/src/Nazara/Graphics/DeferredFinalPass.cpp b/src/Nazara/Graphics/DeferredFinalPass.cpp deleted file mode 100644 index 996104a26..000000000 --- a/src/Nazara/Graphics/DeferredFinalPass.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::DeferredFinalPass - * \brief Graphics class that represents the final pass in deferred rendering - */ - - /*! - * \brief Constructs a DeferredFinalPass object by default - */ - - DeferredFinalPass::DeferredFinalPass() - { - m_pointSampler.SetAnisotropyLevel(1); - m_pointSampler.SetFilterMode(SamplerFilter_Nearest); - m_pointSampler.SetWrapMode(SamplerWrap_Clamp); - - m_states.depthBuffer = false; - - m_uberShader = UberShaderLibrary::Get("Basic"); - - ParameterList list; - list.SetParameter("AUTO_TEXCOORDS", true); - list.SetParameter("DIFFUSE_MAPPING", true); - list.SetParameter("TEXTURE_MAPPING", false); - - m_uberShaderInstance = m_uberShader->Get(list); - - const Shader* shader = m_uberShaderInstance->GetShader(); - m_materialDiffuseUniform = shader->GetUniformLocation("MaterialDiffuse"); - m_materialDiffuseMapUniform = shader->GetUniformLocation("MaterialDiffuseMap"); - } - - DeferredFinalPass::~DeferredFinalPass() = default; - - /*! - * \brief Processes the work on the data while working with textures - * \return true - * - * \param sceneData Data for the scene - * \param firstWorkTexture Index of the first texture to work with - * \param firstWorkTexture Index of the second texture to work with - */ - - bool DeferredFinalPass::Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const - { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - - NazaraUnused(firstWorkTexture); - - sceneData.viewer->ApplyView(); - - Renderer::SetRenderStates(m_states); - Renderer::SetTexture(0, m_workTextures[secondWorkTexture]); - Renderer::SetTextureSampler(0, m_pointSampler); - - m_uberShaderInstance->Activate(); - - const Shader* shader = m_uberShaderInstance->GetShader(); - shader->SendColor(m_materialDiffuseUniform, Color::White); - shader->SendInteger(m_materialDiffuseMapUniform, 0); - - Renderer::DrawFullscreenQuad(); - - return false; - } -} diff --git a/src/Nazara/Graphics/DeferredFogPass.cpp b/src/Nazara/Graphics/DeferredFogPass.cpp deleted file mode 100644 index 826e26d1d..000000000 --- a/src/Nazara/Graphics/DeferredFogPass.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - /*! - * \brief Builds the shader for the fog - * \return Reference to the shader newly created - */ - - ShaderRef BuildFogShader() - { - /*const UInt8 fragmentSource[] = { - #include - };*/ - - const char* fragmentSource = - "#version 140\n" - - "out vec4 RenderTarget0;\n" - - "uniform sampler2D ColorTexture;\n" - "uniform sampler2D GBuffer2;\n" - "uniform mat4 InvViewProjMatrix;\n" - "uniform vec2 InvTargetSize;\n" - "uniform vec3 EyePosition;\n" - - "float n = 0.1;" - "float f = 1000.0;" - - "float color_to_float(vec3 color)\n" - "{\n" - "const vec3 byte_to_float = vec3(1.0, 1.0/256, 1.0/(256*256));\n" - "return dot(color, byte_to_float);\n" - "}\n" - - "void main()\n" - "{" - "vec2 texCoord = gl_FragCoord.xy * InvTargetSize;\n" - "\t" "vec3 color = texture(ColorTexture, texCoord).xyz;\n" - "vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);\n" - "float depth = color_to_float(gVec2.xyz)*2.0 - 1.0;\n" - "float linearDepth = (2 * n) / (f + n - depth * (f - n));" - - "vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);\n" - - "vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);\n" - "worldPos.xyz /= worldPos.w;\n" - - /*"float lumThreshold = 0.1;" - "float lumMultipler = 2.0;" - //"float lumFactor = max(dot(color, vec3(0.299, 0.587, 0.114)) - lumThreshold, 0.0) / (1.0-lumThreshold);" - "float fogFactor = (1.0 - clamp(worldPos.y-2.0, 0.0, 1.0)) - lumFactor*lumMultipler;" - "fogFactor += (1.0 - clamp(EyePosition.y-2.5, 0.0, 1.0));" - "fogFactor = clamp(fogFactor, 0.0, 1.0);"*/ - - "float lumThreshold = 0.8;" - "float lumMultipler = 2.0;" - "float luminosity = dot(color, vec3(0.299, 0.587, 0.114));" - "float lumFactor = max(luminosity - lumThreshold, 0.0) / (1.0-lumThreshold);" - - "vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0);\n" - "vec2 fogrange = vec2(0, 50);\n" - "float fogeffect = clamp( 1.0 - (fogrange.y - linearDepth*0.5*f) / (fogrange.y - fogrange.x) , 0.0, 1.0 ) * fogColor.w;\n" - "fogeffect = max(fogeffect-lumFactor, 0.0);" - - //fogeffect*=(1.0 - int(depth)); - "\t" "vec3 fragmentColor = color*(1.0-fogeffect) + fogColor.rgb * fogeffect;\n" - "\t" "RenderTarget0 = vec4(fragmentColor, 1.0);\n" - "}"; - - const char* vertexSource = - "#version 140\n" - - "in vec3 VertexPosition;\n" - - "void main()\n" - "{\n" - "\t" "gl_Position = vec4(VertexPosition, 1.0);" "\n" - "}\n"; - - ///TODO: Remplacer ça par des ShaderNode - ShaderRef shader = Shader::New(); - if (!shader->Create()) - { - NazaraError("Failed to load create shader"); - return nullptr; - } - - if (!shader->AttachStageFromSource(ShaderStageType_Fragment, fragmentSource/*String(reinterpret_cast(fragmentSource), sizeof(fragmentSource))*/)) - { - NazaraError("Failed to load fragment shader"); - return nullptr; - } - - if (!shader->AttachStageFromSource(ShaderStageType_Vertex, vertexSource)) - { - NazaraError("Failed to load vertex shader"); - return nullptr; - } - - if (!shader->Link()) - { - NazaraError("Failed to link shader"); - return nullptr; - } - - shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0); - shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 1); - - return shader; - } - } - - /*! - * \ingroup graphics - * \class Nz::DeferredFogPass - * \brief Graphics class that represents the pass for fog in deferred rendering - */ - - /*! - * \brief Constructs a DeferredFogPass object by default - */ - - DeferredFogPass::DeferredFogPass() - { - m_pointSampler.SetAnisotropyLevel(1); - m_pointSampler.SetFilterMode(SamplerFilter_Nearest); - m_pointSampler.SetWrapMode(SamplerWrap_Clamp); - - m_shader = BuildFogShader(); - m_shaderEyePositionLocation = m_shader->GetUniformLocation("EyePosition"); - - m_states.depthBuffer = false; - } - - DeferredFogPass::~DeferredFogPass() = default; - - /*! - * \brief Processes the work on the data while working with textures - * \return true - * - * \param sceneData Data for the scene - * \param firstWorkTexture Index of the first texture to work with - * \param firstWorkTexture Index of the second texture to work with - */ - - bool DeferredFogPass::Process( const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const - { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - - m_workRTT->SetColorTarget(firstWorkTexture); - Renderer::SetTarget(m_workRTT); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x, m_dimensions.y)); - - Renderer::SetShader(m_shader); - m_shader->SendVector(m_shaderEyePositionLocation, sceneData.viewer->GetEyePosition()); - - Renderer::SetRenderStates(m_states); - Renderer::SetTexture(0, m_workTextures[secondWorkTexture]); - Renderer::SetTexture(1, m_GBuffer[2]); - Renderer::SetTextureSampler(0, m_pointSampler); - Renderer::SetTextureSampler(1, m_pointSampler); - Renderer::DrawFullscreenQuad(); - - return true; -} -} diff --git a/src/Nazara/Graphics/DeferredForwardPass.cpp b/src/Nazara/Graphics/DeferredForwardPass.cpp deleted file mode 100644 index e4be9e955..000000000 --- a/src/Nazara/Graphics/DeferredForwardPass.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::DeferredForwardPass - * \brief Graphics class that represents the forward pass in deferred rendering - */ - - DeferredForwardPass::DeferredForwardPass() = default; - DeferredForwardPass::~DeferredForwardPass() = default; - - /*! - * \brief Initializes the deferred forward pass which needs the forward technique - * - * \param technique Rendering technique - */ - - void DeferredForwardPass::Initialize(DeferredRenderTechnique* technique) - { - DeferredRenderPass::Initialize(technique); - - m_forwardTechnique = technique->GetForwardTechnique(); - } - - /*! - * \brief Processes the work on the data while working with textures - * \return true - * - * \param sceneData Data for the scene - * \param firstWorkTexture Index of the first texture to work with - * \param firstWorkTexture Index of the second texture to work with - */ - - bool DeferredForwardPass::Process(const SceneData& sceneData, unsigned int workTexture, unsigned int sceneTexture) const - { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - NazaraUnused(workTexture); - - m_workRTT->SetColorTarget(sceneTexture); - Renderer::SetTarget(m_workRTT); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x, m_dimensions.y)); - - if (sceneData.background) - sceneData.background->Draw(sceneData.viewer); - - Renderer::SetMatrix(MatrixType_Projection, sceneData.viewer->GetProjectionMatrix()); - Renderer::SetMatrix(MatrixType_View, sceneData.viewer->GetViewMatrix()); - - m_forwardTechnique->Draw(sceneData); - - return false; - } -} diff --git a/src/Nazara/Graphics/DeferredGeometryPass.cpp b/src/Nazara/Graphics/DeferredGeometryPass.cpp deleted file mode 100644 index 3801963b4..000000000 --- a/src/Nazara/Graphics/DeferredGeometryPass.cpp +++ /dev/null @@ -1,716 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - struct BillboardPoint - { - Color color; - Vector3f position; - Vector2f size; - Vector2f sinCos; // must follow `size` (both will be sent as a Vector4f) - Vector2f uv; - }; - - constexpr UInt32 s_vertexBufferSize = 4 * 1024 * 1024; // 4 MiB - constexpr UInt32 s_maxQuadPerDraw = s_vertexBufferSize / sizeof(VertexLayout_XYZ_Color_UV); - } - - /*! - * \ingroup graphics - * \class Nz::DeferredGeometryPass - * \brief Graphics class that represents the pass for geometries in deferred rendering - */ - - /*! - * \brief Constructs a DeferredGeometryPass object by default - */ - - DeferredGeometryPass::DeferredGeometryPass() : - m_vertexBuffer(BufferType_Vertex) - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - - m_whiteTexture = Nz::TextureLibrary::Get("White2D"); - - m_vertexBuffer.Create(s_vertexBufferSize, DataStorage_Hardware, BufferUsage_Dynamic); - - m_billboardPointBuffer.Reset(&s_billboardVertexDeclaration, &m_vertexBuffer); - m_spriteBuffer.Reset(VertexDeclaration::Get(VertexLayout_XYZ_Color_UV), &m_vertexBuffer); - - m_clearShader = ShaderLibrary::Get("DeferredGBufferClear"); - m_clearStates.depthBuffer = true; - m_clearStates.faceCulling = true; - m_clearStates.stencilTest = true; - m_clearStates.depthFunc = RendererComparison_Always; - m_clearStates.stencilCompare.front = RendererComparison_Always; - m_clearStates.stencilPass.front = StencilOperation_Zero; - } - - DeferredGeometryPass::~DeferredGeometryPass() = default; - - /*! - * \brief Processes the work on the data while working with textures - * \return false - * - * \param sceneData Data for the scene - * \param firstWorkTexture Index of the first texture to work with - * \param firstWorkTexture Index of the second texture to work with - */ - - bool DeferredGeometryPass::Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const - { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - NazaraUnused(firstWorkTexture); - NazaraUnused(secondWorkTexture); - - bool instancingEnabled = m_deferredTechnique->IsInstancingEnabled(); - - m_GBufferRTT->SetColorTargets({0, 1, 2}); // G-Buffer - Renderer::SetTarget(m_GBufferRTT); - Renderer::SetScissorRect(Recti(0, 0, m_dimensions.x, m_dimensions.y)); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x, m_dimensions.y)); - - Renderer::SetRenderStates(m_clearStates); - Renderer::SetShader(m_clearShader); - Renderer::DrawFullscreenQuad(); - - - Renderer::SetMatrix(MatrixType_Projection, sceneData.viewer->GetProjectionMatrix()); - Renderer::SetMatrix(MatrixType_View, sceneData.viewer->GetViewMatrix()); - - BasicRenderQueue& renderQueue = *m_renderQueue->GetDeferredRenderQueue(); - - renderQueue.Sort(sceneData.viewer); - - if (!renderQueue.models.empty()) - DrawModels(sceneData, renderQueue, renderQueue.models); - - if (!renderQueue.basicSprites.empty()) - DrawSprites(sceneData, renderQueue, renderQueue.basicSprites); - - if (!renderQueue.billboards.empty()) - DrawBillboards(sceneData, renderQueue, renderQueue.billboards); - - if (!renderQueue.depthSortedModels.empty()) - DrawModels(sceneData, renderQueue, renderQueue.depthSortedModels); - - if (!renderQueue.depthSortedSprites.empty()) - DrawSprites(sceneData, renderQueue, renderQueue.depthSortedSprites); - - if (!renderQueue.depthSortedBillboards.empty()) - DrawBillboards(sceneData, renderQueue, renderQueue.depthSortedBillboards); - - return false; // We only fill the G-Buffer, the work texture are unchanged - } - - /*! - * \brief Resizes the texture sizes - * \return true If successful - * - * \param dimensions Dimensions for the compute texture - */ - - bool DeferredGeometryPass::Resize(const Vector2ui& dimensions) - { - DeferredRenderPass::Resize(dimensions); - - /* - G-Buffer: - Texture0: Diffuse Color + Flags - Texture1: Encoded normal - Texture2: Specular value + Shininess - Texture3: N/A - */ - - try - { - ErrorFlags errFlags(ErrorFlag_ThrowException); - - unsigned int width = dimensions.x; - unsigned int height = dimensions.y; - - m_depthStencilTexture->Create(ImageType_2D, PixelFormat_Depth24Stencil8, width, height); - - m_GBuffer[0]->Create(ImageType_2D, PixelFormat_RGBA8, width, height); // Texture 0 : Diffuse Color + Specular - m_GBuffer[1]->Create(ImageType_2D, PixelFormat_RG16F, width, height); // Texture 1 : Encoded normal - m_GBuffer[2]->Create(ImageType_2D, PixelFormat_RGBA8, width, height); // Texture 2 : Depth (24bits) + Shininess - - m_GBufferRTT->Create(true); - - m_GBufferRTT->AttachTexture(AttachmentPoint_Color, 0, m_GBuffer[0]); - m_GBufferRTT->AttachTexture(AttachmentPoint_Color, 1, m_GBuffer[1]); - m_GBufferRTT->AttachTexture(AttachmentPoint_Color, 2, m_GBuffer[2]); - - // Texture 3 : Emission map ? - - m_GBufferRTT->AttachTexture(AttachmentPoint_DepthStencil, 0, m_depthStencilTexture); - - m_GBufferRTT->Unlock(); - - m_workRTT->Create(true); - - for (unsigned int i = 0; i < 2; ++i) - { - m_workTextures[i]->Create(ImageType_2D, PixelFormat_RGBA8, width, height); - m_workRTT->AttachTexture(AttachmentPoint_Color, i, m_workTextures[i]); - } - - m_workRTT->AttachTexture(AttachmentPoint_DepthStencil, 0, m_depthStencilTexture); - - m_workRTT->Unlock(); - - if (!m_workRTT->IsComplete() || !m_GBufferRTT->IsComplete()) - { - NazaraError("Incomplete RTT"); - return false; - } - - return true; - } - catch (const std::exception& e) - { - NazaraError("Failed to create G-Buffer RTT: " + String(e.what())); - return false; - } - } - - void DeferredGeometryPass::DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const - { - VertexBuffer* instanceBuffer = Renderer::GetInstanceBuffer(); - instanceBuffer->SetVertexDeclaration(&s_billboardInstanceDeclaration); - - Renderer::SetVertexBuffer(&s_quadVertexBuffer); - - Nz::BufferMapper instanceBufferMapper; - std::size_t billboardCount = 0; - std::size_t maxBillboardPerDraw = instanceBuffer->GetVertexCount(); - - auto Commit = [&]() - { - if (billboardCount > 0) - { - instanceBufferMapper.Unmap(); - - Renderer::DrawPrimitivesInstanced(billboardCount, PrimitiveMode_TriangleStrip, 0, 4); - - billboardCount = 0; - } - }; - - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - for (const BasicRenderQueue::Billboard& billboard : billboards) - { - const Nz::Recti& scissorRect = (billboard.scissorRect.width > 0) ? billboard.scissorRect : fullscreenScissorRect; - - if (billboard.material != lastMaterial || (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect)) - { - Commit(); - - const MaterialPipeline* pipeline = billboard.material->GetPipeline(); - if (lastPipeline != pipeline) - { - pipelineInstance = &billboard.material->GetPipeline()->Apply(ShaderFlags_Billboard | ShaderFlags_Deferred | ShaderFlags_Instancing | ShaderFlags_VertexColor); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - // Position of the camera - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (lastMaterial != billboard.material) - { - billboard.material->Apply(*pipelineInstance); - lastMaterial = billboard.material; - } - - if (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(scissorRect); - lastScissorRect = scissorRect; - } - } - - if (!instanceBufferMapper.GetBuffer()) - instanceBufferMapper.Map(instanceBuffer, BufferAccess_DiscardAndWrite); - - std::memcpy(static_cast(instanceBufferMapper.GetPointer()) + sizeof(BasicRenderQueue::BillboardData) * billboardCount, &billboard.data, sizeof(BasicRenderQueue::BillboardData)); - if (++billboardCount >= maxBillboardPerDraw) - Commit(); - } - - Commit(); - } - - void DeferredGeometryPass::DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const - { - VertexBuffer* instanceBuffer = Renderer::GetInstanceBuffer(); - instanceBuffer->SetVertexDeclaration(&s_billboardInstanceDeclaration); - - Renderer::SetVertexBuffer(&s_quadVertexBuffer); - - Nz::BufferMapper instanceBufferMapper; - std::size_t billboardCount = 0; - std::size_t maxBillboardPerDraw = instanceBuffer->GetVertexCount(); - - auto Commit = [&]() - { - if (billboardCount > 0) - { - instanceBufferMapper.Unmap(); - - Renderer::DrawPrimitivesInstanced(billboardCount, PrimitiveMode_TriangleStrip, 0, 4); - - billboardCount = 0; - } - }; - - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - for (const BasicRenderQueue::BillboardChain& billboard : billboards) - { - const Nz::Recti& scissorRect = (billboard.scissorRect.width > 0) ? billboard.scissorRect : fullscreenScissorRect; - - if (billboard.material != lastMaterial || (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect)) - { - Commit(); - - const MaterialPipeline* pipeline = billboard.material->GetPipeline(); - if (lastPipeline != pipeline) - { - pipelineInstance = &billboard.material->GetPipeline()->Apply(ShaderFlags_Billboard | ShaderFlags_Deferred | ShaderFlags_Instancing | ShaderFlags_VertexColor); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - // Position of the camera - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (lastMaterial != billboard.material) - { - billboard.material->Apply(*pipelineInstance); - lastMaterial = billboard.material; - } - - if (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(scissorRect); - lastScissorRect = scissorRect; - } - } - - std::size_t billboardRemaining = billboard.billboardCount; - const BasicRenderQueue::BillboardData* billboardData = renderQueue.GetBillboardData(billboard.billboardIndex); - do - { - std::size_t renderedBillboardCount = std::min(billboardRemaining, maxBillboardPerDraw - billboardCount); - billboardRemaining -= renderedBillboardCount; - - if (!instanceBufferMapper.GetBuffer()) - instanceBufferMapper.Map(instanceBuffer, BufferAccess_DiscardAndWrite); - - std::memcpy(static_cast(instanceBufferMapper.GetPointer()) + sizeof(BasicRenderQueue::BillboardData) * billboardCount, billboardData, renderedBillboardCount * sizeof(BasicRenderQueue::BillboardData)); - billboardCount += renderedBillboardCount; - billboardData += renderedBillboardCount; - - if (billboardCount >= maxBillboardPerDraw) - Commit(); - } - while (billboardRemaining > 0); - } - - Commit(); - } - - void DeferredGeometryPass::DrawModels(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const Nz::RenderQueue& models) const - { - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - ///TODO: Reimplement instancing - - for (const BasicRenderQueue::Model& model : models) - { - const MaterialPipeline* pipeline = model.material->GetPipeline(); - if (lastPipeline != pipeline) - { - pipelineInstance = &model.material->GetPipeline()->Apply(ShaderFlags_Deferred); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - // Position of the camera - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (lastMaterial != model.material) - { - model.material->Apply(*pipelineInstance); - lastMaterial = model.material; - } - - if (model.material->IsScissorTestEnabled()) - { - const Nz::Recti& scissorRect = (model.scissorRect.width > 0) ? model.scissorRect : fullscreenScissorRect; - if (scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(scissorRect); - lastScissorRect = scissorRect; - } - } - - // Handle draw call before rendering loop - Renderer::DrawCall drawFunc; - Renderer::DrawCallInstanced instancedDrawFunc; - unsigned int indexCount; - - if (model.meshData.indexBuffer) - { - drawFunc = Renderer::DrawIndexedPrimitives; - instancedDrawFunc = Renderer::DrawIndexedPrimitivesInstanced; - indexCount = model.meshData.indexBuffer->GetIndexCount(); - } - else - { - drawFunc = Renderer::DrawPrimitives; - instancedDrawFunc = Renderer::DrawPrimitivesInstanced; - indexCount = model.meshData.vertexBuffer->GetVertexCount(); - } - - Renderer::SetIndexBuffer(model.meshData.indexBuffer); - Renderer::SetVertexBuffer(model.meshData.vertexBuffer); - - Renderer::SetMatrix(MatrixType_World, model.matrix); - drawFunc(model.meshData.primitiveMode, 0, indexCount); - } - } - - void DeferredGeometryPass::DrawSprites(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& spriteList) const - { - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const std::size_t maxSpriteCount = std::min(s_maxQuadPerDraw, m_spriteBuffer.GetVertexCount() / 4); - - const unsigned int overlayTextureUnit = Material::GetTextureUnit(TextureMap_Overlay); - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - Renderer::SetIndexBuffer(&s_quadIndexBuffer); - Renderer::SetMatrix(MatrixType_World, Matrix4f::Identity()); - Renderer::SetVertexBuffer(&m_spriteBuffer); - - auto Draw = [&]() - { - unsigned int firstIndex = 0; - for (const auto& batch : m_spriteBatches) - { - const MaterialPipeline* pipeline = batch.material->GetPipeline(); - if (pipeline != lastPipeline) - { - pipelineInstance = &batch.material->GetPipeline()->Apply(ShaderFlags_TextureOverlay | ShaderFlags_VertexColor); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - // Position of the camera - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); - - // Overlay texture unit - shader->SendInteger(shaderUniforms->textureOverlay, overlayTextureUnit); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (batch.material != lastMaterial) - { - batch.material->Apply(*pipelineInstance); - - Renderer::SetTextureSampler(overlayTextureUnit, batch.material->GetDiffuseSampler()); - - lastMaterial = batch.material; - } - - if (batch.overlayTexture != lastOverlay) - { - Renderer::SetTexture(overlayTextureUnit, batch.overlayTexture); - lastOverlay = batch.overlayTexture; - } - - if (batch.material->IsScissorTestEnabled() && batch.scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(batch.scissorRect); - lastScissorRect = batch.scissorRect; - } - - unsigned int indexCount = batch.spriteCount * 6; - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, firstIndex, indexCount); - firstIndex += indexCount; - } - }; - - m_spriteBatches.clear(); - { - BufferMapper vertexMapper; - VertexStruct_XYZ_Color_UV* vertices = nullptr; - - std::size_t remainingSprite = maxSpriteCount; - - const Material* lastMaterial = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - for (const BasicRenderQueue::SpriteChain& basicSprites : spriteList) - { - const Nz::Texture* overlayTexture = (basicSprites.overlay) ? basicSprites.overlay.Get() : m_whiteTexture.Get(); - const Nz::Recti& scissorRect = (basicSprites.scissorRect.width > 0) ? basicSprites.scissorRect : fullscreenScissorRect; - - const VertexStruct_XYZ_Color_UV* spriteVertices = basicSprites.vertices; - std::size_t spriteCount = basicSprites.spriteCount; - - for (;;) - { - if (m_spriteBatches.empty() || basicSprites.material != lastMaterial || overlayTexture != lastOverlay || (basicSprites.material->IsScissorTestEnabled() && scissorRect != lastScissorRect)) - { - m_spriteBatches.emplace_back(); - SpriteBatch& newBatch = m_spriteBatches.back(); - newBatch.material = basicSprites.material; - newBatch.overlayTexture = overlayTexture; - newBatch.scissorRect = scissorRect; - newBatch.spriteCount = 0; - - lastMaterial = basicSprites.material; - lastOverlay = overlayTexture; - lastScissorRect = scissorRect; - } - - SpriteBatch& currentBatch = m_spriteBatches.back(); - - if (!vertices) - { - vertexMapper.Map(m_spriteBuffer, BufferAccess_DiscardAndWrite); - vertices = static_cast(vertexMapper.GetPointer()); - } - - std::size_t processedSpriteCount = std::min(remainingSprite, spriteCount); - std::size_t processedVertices = processedSpriteCount * 4; - - std::memcpy(vertices, spriteVertices, processedVertices * sizeof(VertexStruct_XYZ_Color_UV)); - vertices += processedVertices; - spriteVertices += processedVertices; - - currentBatch.spriteCount += processedSpriteCount; - spriteCount -= processedSpriteCount; - - remainingSprite -= processedSpriteCount; - if (remainingSprite == 0) - { - vertexMapper.Unmap(); - vertices = nullptr; - - Draw(); - - remainingSprite = maxSpriteCount; - m_spriteBatches.clear(); - } - - if (spriteCount == 0) - break; - } - } - } - - Draw(); - } - - const DeferredGeometryPass::ShaderUniforms* DeferredGeometryPass::GetShaderUniforms(const Shader* shader) const - { - auto it = m_shaderUniforms.find(shader); - if (it == m_shaderUniforms.end()) - { - ShaderUniforms uniforms; - uniforms.shaderReleaseSlot.Connect(shader->OnShaderRelease, this, &DeferredGeometryPass::OnShaderInvalidated); - uniforms.shaderUniformInvalidatedSlot.Connect(shader->OnShaderUniformInvalidated, this, &DeferredGeometryPass::OnShaderInvalidated); - - uniforms.eyePosition = shader->GetUniformLocation("EyePosition"); - uniforms.sceneAmbient = shader->GetUniformLocation("SceneAmbient"); - uniforms.textureOverlay = shader->GetUniformLocation("TextureOverlay"); - - it = m_shaderUniforms.emplace(shader, std::move(uniforms)).first; - } - - return &it->second; - } - - /*! - * \brief Handle the invalidation of a shader - * - * \param shader Shader being invalidated - */ - - void DeferredGeometryPass::OnShaderInvalidated(const Shader* shader) const - { - m_shaderUniforms.erase(shader); - } - - bool DeferredGeometryPass::Initialize() - { - try - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - - s_quadIndexBuffer.Reset(true, s_maxQuadPerDraw * 6, DataStorage_Hardware, 0); - - BufferMapper mapper(s_quadIndexBuffer, BufferAccess_WriteOnly); - UInt32* indices = static_cast(mapper.GetPointer()); - - for (UInt32 i = 0; i < s_maxQuadPerDraw; ++i) - { - *indices++ = i * 4 + 0; - *indices++ = i * 4 + 2; - *indices++ = i * 4 + 1; - - *indices++ = i * 4 + 2; - *indices++ = i * 4 + 3; - *indices++ = i * 4 + 1; - } - - mapper.Unmap(); // No point to keep the buffer open any longer - - // Quad buffer (used for instancing of billboards and sprites) - //Note: UV are computed in the shader - s_quadVertexBuffer.Reset(VertexDeclaration::Get(VertexLayout_XY), 4, DataStorage_Hardware, 0); - - float vertices[2 * 4] = { - -0.5f, -0.5f, - 0.5f, -0.5f, - -0.5f, 0.5f, - 0.5f, 0.5f, - }; - - s_quadVertexBuffer.FillRaw(vertices, 0, sizeof(vertices)); - - // Declaration used when rendering the vertex billboards - s_billboardVertexDeclaration.EnableComponent(VertexComponent_Color, ComponentType_Color, NazaraOffsetOf(BillboardPoint, color)); - s_billboardVertexDeclaration.EnableComponent(VertexComponent_Position, ComponentType_Float3, NazaraOffsetOf(BillboardPoint, position)); - s_billboardVertexDeclaration.EnableComponent(VertexComponent_TexCoord, ComponentType_Float2, NazaraOffsetOf(BillboardPoint, uv)); - s_billboardVertexDeclaration.EnableComponent(VertexComponent_Userdata0, ComponentType_Float4, NazaraOffsetOf(BillboardPoint, size)); // Includes sincos - - // Declaration used when rendering the billboards with intancing - // The main advantage is the direct copy (std::memcpy) of data in the RenderQueue to the GPU buffer - s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData0, ComponentType_Float3, NazaraOffsetOf(BasicRenderQueue::BillboardData, center)); - s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData1, ComponentType_Float4, NazaraOffsetOf(BasicRenderQueue::BillboardData, size)); // Englobe sincos - s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData2, ComponentType_Color, NazaraOffsetOf(BasicRenderQueue::BillboardData, color)); - } - catch (const std::exception& e) - { - NazaraError("Failed to initialise: " + String(e.what())); - return false; - } - - return true; - } - - void DeferredGeometryPass::Uninitialize() - { - s_quadIndexBuffer.Reset(); - s_quadVertexBuffer.Reset(); - } - - IndexBuffer DeferredGeometryPass::s_quadIndexBuffer; - VertexBuffer DeferredGeometryPass::s_quadVertexBuffer; - VertexDeclaration DeferredGeometryPass::s_billboardInstanceDeclaration; - VertexDeclaration DeferredGeometryPass::s_billboardVertexDeclaration; -} diff --git a/src/Nazara/Graphics/DeferredPhongLightingPass.cpp b/src/Nazara/Graphics/DeferredPhongLightingPass.cpp deleted file mode 100644 index f9c7a77b9..000000000 --- a/src/Nazara/Graphics/DeferredPhongLightingPass.cpp +++ /dev/null @@ -1,327 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::DeferredPhongLightingPass - * \brief Graphics class that represents the pass for phong lighting in deferred rendering - */ - - /*! - * \brief Constructs a DeferredPhongLightingPass object by default - */ - - DeferredPhongLightingPass::DeferredPhongLightingPass() : - m_lightMeshesDrawing(false) - { - m_directionalLightShader = ShaderLibrary::Get("DeferredDirectionnalLight"); - m_directionalLightShaderEyePositionLocation = m_directionalLightShader->GetUniformLocation("EyePosition"); - m_directionalLightShaderSceneAmbientLocation = m_directionalLightShader->GetUniformLocation("SceneAmbient"); - - m_directionalLightUniforms.ubo = false; - m_directionalLightUniforms.locations.type = -1; // Type already known - m_directionalLightUniforms.locations.color = m_directionalLightShader->GetUniformLocation("LightColor"); - m_directionalLightUniforms.locations.factors = m_directionalLightShader->GetUniformLocation("LightFactors"); - m_directionalLightUniforms.locations.parameters1 = m_directionalLightShader->GetUniformLocation("LightDirection"); - m_directionalLightUniforms.locations.parameters2 = -1; - m_directionalLightUniforms.locations.parameters3 = -1; - - m_pointSpotLightShader = ShaderLibrary::Get("DeferredPointSpotLight"); - m_pointSpotLightShaderDiscardLocation = m_pointSpotLightShader->GetUniformLocation("Discard"); - m_pointSpotLightShaderEyePositionLocation = m_pointSpotLightShader->GetUniformLocation("EyePosition"); - m_pointSpotLightShaderSceneAmbientLocation = m_pointSpotLightShader->GetUniformLocation("SceneAmbient"); - - m_pointSpotLightUniforms.ubo = false; - m_pointSpotLightUniforms.locations.type = m_pointSpotLightShader->GetUniformLocation("LightType"); - m_pointSpotLightUniforms.locations.color = m_pointSpotLightShader->GetUniformLocation("LightColor"); - m_pointSpotLightUniforms.locations.factors = m_pointSpotLightShader->GetUniformLocation("LightFactors"); - m_pointSpotLightUniforms.locations.parameters1 = m_pointSpotLightShader->GetUniformLocation("LightParameters1"); - m_pointSpotLightUniforms.locations.parameters2 = m_pointSpotLightShader->GetUniformLocation("LightParameters2"); - m_pointSpotLightUniforms.locations.parameters3 = m_pointSpotLightShader->GetUniformLocation("LightParameters3"); - - m_pointSampler.SetAnisotropyLevel(1); - m_pointSampler.SetFilterMode(SamplerFilter_Nearest); - m_pointSampler.SetWrapMode(SamplerWrap_Clamp); - - m_cone = Mesh::New(); - m_cone->CreateStatic(); - m_coneMesh = static_cast(m_cone->BuildSubMesh(Primitive::Cone(1.f, 1.f, 16, Matrix4f::Rotate(EulerAnglesf(90.f, 0.f, 0.f))))); - - m_sphere = Mesh::New(); - m_sphere->CreateStatic(); - m_sphereMesh = static_cast(m_sphere->BuildSubMesh(Primitive::IcoSphere(1.f, 1))); - } - - DeferredPhongLightingPass::~DeferredPhongLightingPass() = default; - - /*! - * \brief Enables the drawing of meshes with light - * - * \param enable Should meshes with light parameter be drawed - */ - - void DeferredPhongLightingPass::EnableLightMeshesDrawing(bool enable) - { - m_lightMeshesDrawing = enable; - } - - /*! - * \brief Checks whether the drawing of meshes with light is enabled - * \return true If it is the case - */ - - bool DeferredPhongLightingPass::IsLightMeshesDrawingEnabled() const - { - return m_lightMeshesDrawing; - } - - /*! - * \brief Processes the work on the data while working with textures - * \return true - * - * \param sceneData Data for the scene - * \param firstWorkTexture Index of the first texture to work with - * \param firstWorkTexture Index of the second texture to work with - */ - - bool DeferredPhongLightingPass::Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const - { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - NazaraUnused(secondWorkTexture); - - m_workRTT->SetColorTarget(firstWorkTexture); - Renderer::SetTarget(m_workRTT); - Renderer::SetViewport(Recti(0, 0, m_dimensions.x, m_dimensions.y)); - - Renderer::SetTexture(0, m_GBuffer[0]); - Renderer::SetTextureSampler(0, m_pointSampler); - - Renderer::SetTexture(1, m_GBuffer[1]); - Renderer::SetTextureSampler(1, m_pointSampler); - - Renderer::SetTexture(2, m_GBuffer[2]); - Renderer::SetTextureSampler(2, m_pointSampler); - - Renderer::SetTexture(3, m_depthStencilTexture); - Renderer::SetTextureSampler(3, m_pointSampler); - - Renderer::SetClearColor(Color::Black); - Renderer::Clear(RendererBuffer_Color); - - RenderStates lightStates; - lightStates.dstBlend = BlendFunc_One; - lightStates.srcBlend = BlendFunc_One; - lightStates.blending = true; - lightStates.depthBuffer = false; - lightStates.depthWrite = false; - - // Directional lights - if (!m_renderQueue->directionalLights.empty()) - { - Renderer::SetRenderStates(lightStates); - Renderer::SetShader(m_directionalLightShader); - m_directionalLightShader->SendColor(m_directionalLightShaderSceneAmbientLocation, sceneData.ambientColor); - m_directionalLightShader->SendVector(m_directionalLightShaderEyePositionLocation, sceneData.viewer->GetEyePosition()); - - for (auto& light : m_renderQueue->directionalLights) - { - m_directionalLightShader->SendColor(m_directionalLightUniforms.locations.color, light.color); - m_directionalLightShader->SendVector(m_directionalLightUniforms.locations.factors, Vector2f(light.ambientFactor, light.diffuseFactor)); - m_directionalLightShader->SendVector(m_directionalLightUniforms.locations.parameters1, Vector4f(light.direction)); - - Renderer::DrawFullscreenQuad(); - } - } - - // Point lights/Spot lights - if (!m_renderQueue->pointLights.empty() || !m_renderQueue->spotLights.empty()) - { - // http://www.altdevblogaday.com/2011/08/08/stencil-buffer-optimisation-for-deferred-lights/ - lightStates.cullingSide = FaceSide_Front; - lightStates.stencilTest = true; - lightStates.stencilDepthFail.back = StencilOperation_Invert; - lightStates.stencilDepthFail.front = StencilOperation_Invert; - lightStates.stencilFail.back = StencilOperation_Keep; - lightStates.stencilFail.front = StencilOperation_Keep; - lightStates.stencilPass.back = StencilOperation_Keep; - lightStates.stencilPass.front = StencilOperation_Keep; - lightStates.stencilReference.back = 0; - lightStates.stencilReference.front = 0; - lightStates.stencilWriteMask.back = 0xFF; - lightStates.stencilWriteMask.front = 0xFF; - - Renderer::SetRenderStates(lightStates); - - Renderer::SetShader(m_pointSpotLightShader); - m_pointSpotLightShader->SendColor(m_pointSpotLightShaderSceneAmbientLocation, sceneData.ambientColor); - m_pointSpotLightShader->SendVector(m_pointSpotLightShaderEyePositionLocation, sceneData.viewer->GetEyePosition()); - - Matrix4f lightMatrix; - lightMatrix.MakeIdentity(); - if (!m_renderQueue->pointLights.empty()) - { - const IndexBuffer* indexBuffer = m_sphereMesh->GetIndexBuffer(); - Renderer::SetIndexBuffer(indexBuffer); - Renderer::SetVertexBuffer(m_sphereMesh->GetVertexBuffer()); - - m_pointSpotLightShader->SendInteger(m_pointSpotLightUniforms.locations.type, LightType_Point); - for (const auto& light : m_renderQueue->pointLights) - { - m_pointSpotLightShader->SendColor(m_pointSpotLightUniforms.locations.color, light.color); - m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.factors, Vector2f(light.ambientFactor, light.diffuseFactor)); - m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters1, Vector4f(light.position, light.attenuation)); - m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters2, Vector4f(0.f, 0.f, 0.f, light.invRadius)); - - lightMatrix.SetScale(Vector3f(light.radius * 1.1f)); // To correct imperfections due to the sphere - lightMatrix.SetTranslation(light.position); - - Renderer::SetMatrix(MatrixType_World, lightMatrix); - - // Sphere rendering in the stencil buffer - Renderer::Enable(RendererParameter_ColorWrite, false); - Renderer::Enable(RendererParameter_DepthBuffer, true); - Renderer::Enable(RendererParameter_FaceCulling, false); - Renderer::SetStencilCompareFunction(RendererComparison_Always); - - m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, true); - - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); - - // Sphere rendering as effect zone - Renderer::Enable(RendererParameter_ColorWrite, true); - Renderer::Enable(RendererParameter_DepthBuffer, false); - Renderer::Enable(RendererParameter_FaceCulling, true); - Renderer::SetStencilCompareFunction(RendererComparison_NotEqual, FaceSide_Back); - Renderer::SetStencilPassOperation(StencilOperation_Zero, FaceSide_Back); - - m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, false); - - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); - } - - if (m_lightMeshesDrawing) - { - Renderer::Enable(RendererParameter_DepthBuffer, true); - Renderer::Enable(RendererParameter_DepthWrite, true); - Renderer::Enable(RendererParameter_FaceCulling, false); - Renderer::Enable(RendererParameter_StencilTest, false); - Renderer::SetFaceFilling(FaceFilling_Line); - - const Shader* shader = ShaderLibrary::Get("DebugSimple"); - static int colorLocation = shader->GetUniformLocation("Color"); - - Renderer::SetShader(shader); - for (const auto& light : m_renderQueue->pointLights) - { - lightMatrix.SetScale(Vector3f(light.radius * 1.1f)); // To correct imperfections due to the sphere - lightMatrix.SetTranslation(light.position); - - Renderer::SetMatrix(MatrixType_World, lightMatrix); - - shader->SendColor(colorLocation, light.color); - - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); - } - - Renderer::Enable(RendererParameter_DepthBuffer, false); - Renderer::Enable(RendererParameter_DepthWrite, false); - Renderer::Enable(RendererParameter_FaceCulling, true); - Renderer::Enable(RendererParameter_StencilTest, true); - Renderer::SetFaceFilling(FaceFilling_Fill); - } - } - - if (!m_renderQueue->spotLights.empty()) - { - const IndexBuffer* indexBuffer = m_coneMesh->GetIndexBuffer(); - Renderer::SetIndexBuffer(indexBuffer); - Renderer::SetVertexBuffer(m_coneMesh->GetVertexBuffer()); - - m_pointSpotLightShader->SendInteger(m_pointSpotLightUniforms.locations.type, LightType_Spot); - for (const auto& light : m_renderQueue->spotLights) - { - m_pointSpotLightShader->SendColor(m_pointSpotLightUniforms.locations.color, light.color); - m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.factors, Vector2f(light.ambientFactor, light.diffuseFactor)); - m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters1, Vector4f(light.position, light.attenuation)); - m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters2, Vector4f(light.direction, light.invRadius)); - m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters3, Vector2f(light.innerAngleCosine, light.outerAngleCosine)); - - float baseRadius = light.radius * light.outerAngleTangent * 1.1f; - lightMatrix.MakeTransform(light.position, Quaternionf::RotationBetween(Vector3f::Forward(), light.direction), Vector3f(baseRadius, baseRadius, light.radius)); - - Renderer::SetMatrix(MatrixType_World, lightMatrix); - - // Sphere rendering in the stencil buffer - Renderer::Enable(RendererParameter_ColorWrite, false); - Renderer::Enable(RendererParameter_DepthBuffer, true); - Renderer::Enable(RendererParameter_FaceCulling, false); - Renderer::SetStencilCompareFunction(RendererComparison_Always); - - m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, true); - - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); - - // Sphere rendering as effect zone - Renderer::Enable(RendererParameter_ColorWrite, true); - Renderer::Enable(RendererParameter_DepthBuffer, false); - Renderer::Enable(RendererParameter_FaceCulling, true); - Renderer::SetFaceCulling(FaceSide_Front); - Renderer::SetStencilCompareFunction(RendererComparison_NotEqual, FaceSide_Back); - Renderer::SetStencilPassOperation(StencilOperation_Zero, FaceSide_Back); - - m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, false); - - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); - } - - if (m_lightMeshesDrawing) - { - Renderer::Enable(RendererParameter_DepthBuffer, true); - Renderer::Enable(RendererParameter_DepthWrite, true); - Renderer::Enable(RendererParameter_FaceCulling, false); - Renderer::Enable(RendererParameter_StencilTest, false); - Renderer::SetFaceFilling(FaceFilling_Line); - - const Shader* shader = ShaderLibrary::Get("DebugSimple"); - static int colorLocation = shader->GetUniformLocation("Color"); - - Renderer::SetShader(shader); - for (const auto& light : m_renderQueue->spotLights) - { - float baseRadius = light.radius * light.outerAngleTangent * 1.1f; - lightMatrix.MakeTransform(light.position, Quaternionf::RotationBetween(Vector3f::Forward(), light.direction), Vector3f(baseRadius, baseRadius, light.radius)); - - Renderer::SetMatrix(MatrixType_World, lightMatrix); - - shader->SendColor(colorLocation, light.color); - - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); - } - - Renderer::Enable(RendererParameter_DepthBuffer, false); - Renderer::Enable(RendererParameter_DepthWrite, false); - Renderer::Enable(RendererParameter_FaceCulling, true); - Renderer::Enable(RendererParameter_StencilTest, true); - Renderer::SetFaceFilling(FaceFilling_Fill); - } - } - - Renderer::Enable(RendererParameter_StencilTest, false); - } - - return true; - } -} diff --git a/src/Nazara/Graphics/DeferredProxyRenderQueue.cpp b/src/Nazara/Graphics/DeferredProxyRenderQueue.cpp deleted file mode 100644 index c016b4496..000000000 --- a/src/Nazara/Graphics/DeferredProxyRenderQueue.cpp +++ /dev/null @@ -1,261 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::DeferredProxyRenderQueue - * \brief Graphics class sorting the objects into a deferred and forward render queue (depending on blending) - */ - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param colorPtr Color of the billboards if null, Color::White is used - */ - - void DeferredProxyRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, colorPtr); - else - m_forwardRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, colorPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - */ - - void DeferredProxyRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, alphaPtr); - else - m_forwardRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, alphaPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param colorPtr Color of the billboards if null, Color::White is used - */ - - void DeferredProxyRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, colorPtr); - else - m_forwardRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, colorPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - */ - - void DeferredProxyRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, alphaPtr); - else - m_forwardRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, alphaPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param colorPtr Color of the billboards if null, Color::White is used - */ - - void DeferredProxyRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, colorPtr); - else - m_forwardRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, colorPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - */ - - void DeferredProxyRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, alphaPtr); - else - m_forwardRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, alphaPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param colorPtr Color of the billboards if null, Color::White is used - */ - - void DeferredProxyRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, colorPtr); - else - m_forwardRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, colorPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - */ - - void DeferredProxyRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, alphaPtr); - else - m_forwardRenderQueue->AddBillboards(renderOrder, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, alphaPtr); - } - - /*! - * \brief Adds drawable to the queue - * - * \param renderOrder Order of rendering - * \param drawable Drawable user defined - * - * \remark Produces a NazaraError if drawable is invalid - */ - - void DeferredProxyRenderQueue::AddDrawable(int renderOrder, const Drawable* drawable) - { - m_forwardRenderQueue->AddDrawable(renderOrder, drawable); - } - - /*! - * \brief Adds mesh to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the mesh - * \param meshData Data of the mesh - * \param meshAABB Box of the mesh - * \param transformMatrix Matrix of the mesh - */ - - void DeferredProxyRenderQueue::AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddMesh(renderOrder, material, meshData, meshAABB, transformMatrix, scissorRect); - else - m_forwardRenderQueue->AddMesh(renderOrder, material, meshData, meshAABB, transformMatrix, scissorRect); - } - - /*! - * \brief Adds sprites to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the sprites - * \param vertices Buffer of data for the sprites - * \param spriteCount Number of sprites - * \param overlay Texture of the sprites - */ - - void DeferredProxyRenderQueue::AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay) - { - NazaraAssert(material, "Invalid material"); - - if (!material->IsBlendingEnabled()) - m_deferredRenderQueue->AddSprites(renderOrder, material, vertices, spriteCount, scissorRect, overlay); - else - m_forwardRenderQueue->AddSprites(renderOrder, material, vertices, spriteCount, scissorRect, overlay); - } - - /*! - * \brief Clears the queue - * - * \param fully Should everything be cleared or we can keep layers - */ - - void DeferredProxyRenderQueue::Clear(bool fully) - { - AbstractRenderQueue::Clear(fully); - - m_deferredRenderQueue->Clear(fully); - m_forwardRenderQueue->Clear(fully); - } -} diff --git a/src/Nazara/Graphics/DeferredRenderPass.cpp b/src/Nazara/Graphics/DeferredRenderPass.cpp deleted file mode 100644 index e8e1ff289..000000000 --- a/src/Nazara/Graphics/DeferredRenderPass.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::DeferredRenderPass - * \brief Graphics class that represents the pass for rendering in deferred rendering - */ - - /*! - * \brief Constructs a DeferredRenderPass object by default - */ - - DeferredRenderPass::DeferredRenderPass() : - m_enabled(true) - { - } - - DeferredRenderPass::~DeferredRenderPass() = default; - - /*! - * \brief Enables the deferred rendering - * - * \param enable Should deferred rendering be activated - */ - - void DeferredRenderPass::Enable(bool enable) - { - m_enabled = enable; - } - - /*! - * \brief Initializes the deferred forward pass which needs the deferred technique - * - * \param technique Rendering technique - */ - - void DeferredRenderPass::Initialize(DeferredRenderTechnique* technique) - { - m_deferredTechnique = technique; - m_renderQueue = static_cast(technique->GetRenderQueue()); - - m_depthStencilTexture = technique->GetDepthStencilTexture(); - - m_GBufferRTT = technique->GetGBufferRTT(); - for (unsigned int i = 0; i < 3; ++i) - m_GBuffer[i] = technique->GetGBuffer(i); - - m_workRTT = technique->GetWorkRTT(); - for (unsigned int i = 0; i < 2; ++i) - m_workTextures[i] = technique->GetWorkTexture(i); - } - - /*! - * \brief Checks whether the deferred rendering is enabled - * \return true If it the case - */ - - bool DeferredRenderPass::IsEnabled() const - { - return m_enabled; - } - - /*! - * \brief Resizes the texture sizes - * \return true If successful - * - * \param dimensions Dimensions for the compute texture - */ - - bool DeferredRenderPass::Resize(const Vector2ui& dimensions) - { - m_dimensions = dimensions; - - return true; - } -} diff --git a/src/Nazara/Graphics/DeferredRenderTechnique.cpp b/src/Nazara/Graphics/DeferredRenderTechnique.cpp deleted file mode 100644 index e4d435df0..000000000 --- a/src/Nazara/Graphics/DeferredRenderTechnique.cpp +++ /dev/null @@ -1,742 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_RENDERER_OPENGL -#define NAZARA_RENDERER_OPENGL // Nécessaire pour inclure les headers OpenGL -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - const UInt8 r_fragmentSource_BloomBright[] = { - #include - }; - - const UInt8 r_fragmentSource_BloomFinal[] = { - #include - }; - - const UInt8 r_fragmentSource_DirectionalLight[] = { - #include - }; - - const UInt8 r_fragmentSource_FXAA[] = { - #include - }; - - const UInt8 r_fragmentSource_GBufferClear[] = { - #include - }; - - const UInt8 r_fragmentSource_GaussianBlur[] = { - #include - }; - - const UInt8 r_fragmentSource_PointSpotLight[] = { - #include - }; - - unsigned int RenderPassPriority[] = - { - 6, // RenderPassType_AA - 4, // RenderPassType_Bloom - 7, // RenderPassType_DOF - 0xFF, // RenderPassType_Final - 5, // RenderPassType_Fog - 2, // RenderPassType_Forward - 1, // RenderPassType_Lighting - 0, // RenderPassType_Geometry - 3, // RenderPassType_SSAO - }; - - static_assert(sizeof(RenderPassPriority) / sizeof(unsigned int) == RenderPassType_Max + 1, "Render pass priority array is incomplete"); - - /*! - * \brief Registers the deferred shader - * \return Reference to the newly created shader - * - * \param name Name of the shader - * \param fragmentSource Raw data to fragment shader - * \param fragmentSourceLength Size of the fragment source - * \param vertexStage Stage of the shader - * \param err Pointer to string to contain error message - */ - - inline ShaderRef RegisterDeferredShader(const String& name, const UInt8* fragmentSource, unsigned int fragmentSourceLength, const ShaderStage& vertexStage, String* err) - { - ErrorFlags errFlags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled); - - ShaderRef shader = Shader::New(); - if (!shader->Create()) - { - err->Set("Failed to create shader: " + Error::GetLastError()); - return nullptr; - } - - if (!shader->AttachStageFromSource(ShaderStageType_Fragment, reinterpret_cast(fragmentSource), fragmentSourceLength)) - { - err->Set("Failed to attach fragment stage: " + Error::GetLastError()); - return nullptr; - } - - shader->AttachStage(ShaderStageType_Vertex, vertexStage); - - if (!shader->Link()) - { - err->Set("Failed to link shader: " + Error::GetLastError()); - return nullptr; - } - - ShaderLibrary::Register(name, shader); - return shader; - } - } - - /*! - * \ingroup graphics - * \class Nz::DeferredRenderTechnique - * \brief Graphics class that represents the technique used in deferred rendering - */ - - /*! - * \brief Constructs a DeferredRenderTechnique object by default - * - * \remark Produces a NazaraError if one pass could not be created - */ - - DeferredRenderTechnique::DeferredRenderTechnique() : - m_renderQueue(&m_deferredRenderQueue, static_cast(m_forwardTechnique.GetRenderQueue())), - m_GBufferSize(0U) - { - m_depthStencilTexture = Texture::New(); - - for (unsigned int i = 0; i < 2; ++i) - m_workTextures[i] = Texture::New(); - - for (unsigned int i = 0; i < 3; ++i) - m_GBuffer[i] = Texture::New(); - - try - { - ErrorFlags errFlags(ErrorFlag_ThrowException); - - ResetPass(RenderPassType_Final, 0); - ResetPass(RenderPassType_Geometry, 0); - ResetPass(RenderPassType_Lighting, 0); - } - catch (const std::exception& e) - { - ErrorFlags errFlags(ErrorFlag_ThrowExceptionDisabled); - - NazaraError("Failed to add geometry and/or phong lighting pass: " + String(e.what())); - throw; - } - - try - { - ErrorFlags errFlags(ErrorFlag_ThrowException); - ResetPass(RenderPassType_AA, 0); - } - catch (const std::exception& e) - { - NazaraWarning("Failed to add FXAA pass: " + String(e.what())); - } - - try - { - ErrorFlags errFlags(ErrorFlag_ThrowException); - ResetPass(RenderPassType_Bloom, 0); - } - catch (const std::exception& e) - { - NazaraWarning("Failed to add bloom pass: " + String(e.what())); - } - - try - { - ErrorFlags errFlags(ErrorFlag_ThrowException); - - DeferredRenderPass* dofPass = ResetPass(RenderPassType_DOF, 0); - dofPass->Enable(false); - } - catch (const std::exception& e) - { - NazaraWarning("Failed to add DOF pass: " + String(e.what())); - } - - try - { - ErrorFlags errFlags(ErrorFlag_ThrowException); - - DeferredRenderPass* fogPass = ResetPass(RenderPassType_Fog, 0); - fogPass->Enable(false); - } - catch (const std::exception& e) - { - NazaraWarning("Failed to add fog pass: " + String(e.what())); - } - - try - { - ErrorFlags errFlags(ErrorFlag_ThrowException); - ResetPass(RenderPassType_Forward, 0); - } - catch (const std::exception& e) - { - NazaraWarning("Failed to add forward pass: " + String(e.what())); - } - - try - { - ErrorFlags errFlags(ErrorFlag_ThrowException); - ResetPass(RenderPassType_SSAO, 0); - } - catch (const std::exception& e) - { - NazaraWarning("Failed to add SSAO pass: " + String(e.what())); - } - } - - DeferredRenderTechnique::~DeferredRenderTechnique() = default; - - /*! - * \brief Clears the data - * - * \param sceneData Data of the scene - */ - - void DeferredRenderTechnique::Clear(const SceneData& sceneData) const - { - NazaraUnused(sceneData); - } - - /*! - * \brief Draws the data of the scene - * \return true If successful - * - * \param sceneData Data of the scene - * - * \remark Produces a NazaraAssert if viewer of the scene is invalid - * \remark Produces a NazaraError if updating viewport dimensions failed - */ - - bool DeferredRenderTechnique::Draw(const SceneData& sceneData) const - { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - Recti viewerViewport = sceneData.viewer->GetViewport(); - - Vector2ui viewportDimensions(viewerViewport.width, viewerViewport.height); - if (viewportDimensions != m_GBufferSize) - { - if (!Resize(viewportDimensions)) - { - NazaraError("Failed to update RTT"); - return false; - } - } - - unsigned int sceneTexture = 0; - unsigned int workTexture = 1; - for (auto& passIt : m_passes) - { - for (auto& passIt2 : passIt.second) - { - const DeferredRenderPass* pass = passIt2.second.get(); - if (pass->IsEnabled()) - { - if (pass->Process(sceneData, workTexture, sceneTexture)) - std::swap(workTexture, sceneTexture); - } - } - } - - return true; - } - - /*! - * \brief Enables a pass - * - * \param renderPass Enumeration for the pass - * \param position Position of the pass - * \param enable Should the pass be enabled - */ - - void DeferredRenderTechnique::EnablePass(RenderPassType renderPass, int position, bool enable) - { - auto it = m_passes.find(renderPass); - if (it != m_passes.end()) - { - auto it2 = it->second.find(position); - if (it2 != it->second.end()) - it2->second->Enable(enable); - } - } - - /*! - * \brief Gets the stencil buffer - * \return Pointer to the rendering buffer - */ - - Texture* DeferredRenderTechnique::GetDepthStencilTexture() const - { - return m_depthStencilTexture; - } - - /*! - * \brief Gets the G-buffer - * \return Pointer to the ith texture - * - * \param i Index of the G-buffer - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if index is invalid - */ - - Texture* DeferredRenderTechnique::GetGBuffer(unsigned int i) const - { - #if NAZARA_GRAPHICS_SAFE - if (i >= 3) - { - NazaraError("GBuffer texture index out of range (" + String::Number(i) + " >= 3)"); - return nullptr; - } - #endif - - return m_GBuffer[i]; - } - - /*! - * \brief Gets the rendering texture of the G-buffer - * \return Pointer to the rendering buffer - */ - - RenderTexture* DeferredRenderTechnique::GetGBufferRTT() const - { - return &m_GBufferRTT; - } - - /*! - * \brief Gets the forward technique - * \return Constant pointer to the forward technique - */ - - const ForwardRenderTechnique* DeferredRenderTechnique::GetForwardTechnique() const - { - return &m_forwardTechnique; - } - - /*! - * \brief Gets the pass - * \return Pointer to the deferred render pass - * - * \param renderPass Enumeration for the pass - * \param position Position of the pass - */ - - DeferredRenderPass* DeferredRenderTechnique::GetPass(RenderPassType renderPass, int position) - { - auto it = m_passes.find(renderPass); - if (it != m_passes.end()) - { - auto it2 = it->second.find(position); - if (it2 != it->second.end()) - return it2->second.get(); - } - - return nullptr; - } - - /*! - * \brief Gets the render queue - * \return Pointer to the render queue - */ - - AbstractRenderQueue* DeferredRenderTechnique::GetRenderQueue() - { - return &m_renderQueue; - } - - /*! - * \brief Gets the type of the current technique - * \return Type of the render technique - */ - - RenderTechniqueType DeferredRenderTechnique::GetType() const - { - return RenderTechniqueType_DeferredShading; - } - - /*! - * \brief Gets the render texture used to work - * \return Pointer to the rendering texture - */ - - RenderTexture* DeferredRenderTechnique::GetWorkRTT() const - { - return &m_workRTT; - } - - /*! - * \brief Gets the ith texture to work - * \return Pointer to the texture - * - * \param i Index of the texture used to work - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if index is invalid - */ - - Texture* DeferredRenderTechnique::GetWorkTexture(unsigned int i) const - { - #if NAZARA_GRAPHICS_SAFE - if (i >= 2) - { - NazaraError("Work texture index out of range (" + String::Number(i) + " >= 2)"); - return nullptr; - } - #endif - - return m_workTextures[i]; - } - - /*! - * \brief Checks whether the pass is enable - * \return true If it is the case - * - * \param renderPass Enumeration for the pass - * \param position Position of the pass - */ - - bool DeferredRenderTechnique::IsPassEnabled(RenderPassType renderPass, int position) - { - auto it = m_passes.find(renderPass); - if (it != m_passes.end()) - { - auto it2 = it->second.find(position); - if (it2 != it->second.end()) - return it2->second->IsEnabled(); - } - - return false; - } - - /*! - * \brief Resets the pass - * \return Pointer to the new deferred render pass - * - * \param renderPass Enumeration for the pass - * \param position Position of the pass - */ - - DeferredRenderPass* DeferredRenderTechnique::ResetPass(RenderPassType renderPass, int position) - { - std::unique_ptr smartPtr; // We avoid to leak in case of exception - - switch (renderPass) - { - case RenderPassType_AA: - smartPtr = std::make_unique(); - break; - - case RenderPassType_Bloom: - smartPtr = std::make_unique(); - break; - - case RenderPassType_DOF: - smartPtr = std::make_unique(); - break; - - case RenderPassType_Final: - smartPtr = std::make_unique(); - break; - - case RenderPassType_Fog: - smartPtr = std::make_unique(); - break; - - case RenderPassType_Forward: - smartPtr = std::make_unique(); - break; - - case RenderPassType_Geometry: - smartPtr = std::make_unique(); - break; - - case RenderPassType_Lighting: - smartPtr = std::make_unique(); - break; - - case RenderPassType_SSAO: - //smartPtr.reset(new DeferredSSAOPass); - break; - } - - DeferredRenderPass* oldPass = GetPass(renderPass, position); - if (oldPass && !oldPass->IsEnabled()) - smartPtr->Enable(false); - - SetPass(renderPass, position, smartPtr.get()); - return smartPtr.release(); - } - - /*! - * \brief Sets the pass - * - * \param relativeTo Enumeration for the pass - * \param position Position of the pass - * \param pass Render pass to set - */ - - void DeferredRenderTechnique::SetPass(RenderPassType relativeTo, int position, DeferredRenderPass* pass) - { - if (pass) - { - pass->Initialize(this); - if (m_GBufferSize != Vector2ui(0U)) - pass->Resize(m_GBufferSize); - - m_passes[relativeTo][position].reset(pass); - } - else - m_passes[relativeTo].erase(position); - } - - /*! - * \brief Checks whether the technique is supported - * \return true if it is the case - */ - - bool DeferredRenderTechnique::IsSupported() - { - // Since OpenGL 3.3 is the minimal version, the Renderer supports what it needs, but we are never sure... - return Renderer::GetMaxColorAttachments() >= 4 && Renderer::GetMaxRenderTargets() >= 4; - } - - /*! - * \brief Resizes the texture sizes used for the render technique - * \return true If successful - * - * \param dimensions Dimensions for the render technique - * - * \param Produces a NazaraError if one pass could not be resized - */ - - bool DeferredRenderTechnique::Resize(const Vector2ui& dimensions) const - { - try - { - ErrorFlags errFlags(ErrorFlag_ThrowException); - - for (auto& passIt : m_passes) - for (auto& passIt2 : passIt.second) - passIt2.second->Resize(dimensions); - - m_GBufferSize = dimensions; - - return true; - } - catch (const std::exception& e) - { - NazaraError("Failed to create work RTT/G-Buffer: " + String(e.what())); - return false; - } - } - - /*! - * \brief Initializes the deferred render technique - * \return true If successful - * - * \remark Produces a NazaraError if one shader creation failed - */ - - bool DeferredRenderTechnique::Initialize() - { - const char vertexSource_Basic[] = - "#version 140\n" - - "in vec3 VertexPosition;\n" - "uniform mat4 WorldViewProjMatrix;\n" - - "void main()\n" - "{\n" - "gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);\n" - "}\n"; - - const char vertexSource_PostProcess[] = - "#version 140\n" - - "in vec3 VertexPosition;\n" - - "void main()\n" - "{\n" - "gl_Position = vec4(VertexPosition, 1.0);" - "}\n"; - - ShaderStage basicVertexStage(ShaderStageType_Vertex); - if (!basicVertexStage.IsValid()) - { - NazaraError("Failed to create basic vertex shader"); - return false; - } - - basicVertexStage.SetSource(vertexSource_Basic, sizeof(vertexSource_Basic)); - - if (!basicVertexStage.Compile()) - { - NazaraError("Failed to compile basic vertex shader"); - return false; - } - - - ShaderStage ppVertexStage(ShaderStageType_Vertex); - if (!ppVertexStage.IsValid()) - { - NazaraError("Failed to create vertex shader"); - return false; - } - - ppVertexStage.SetSource(vertexSource_PostProcess, sizeof(vertexSource_PostProcess)); - - if (!ppVertexStage.Compile()) - { - NazaraError("Failed to compile vertex shader"); - return false; - } - - - String error; - Shader* shader; - - // Shaders critiques (Nécessaires pour le Deferred Shading minimal) - shader = RegisterDeferredShader("DeferredGBufferClear", r_fragmentSource_GBufferClear, sizeof(r_fragmentSource_GBufferClear), ppVertexStage, &error); - if (!shader) - { - NazaraError("Failed to register critical shader: " + error); - return false; - } - - - shader = RegisterDeferredShader("DeferredDirectionnalLight", r_fragmentSource_DirectionalLight, sizeof(r_fragmentSource_DirectionalLight), ppVertexStage, &error); - if (!shader) - { - NazaraError("Failed to register critical shader: " + error); - return false; - } - - shader->SendInteger(shader->GetUniformLocation("GBuffer0"), 0); - shader->SendInteger(shader->GetUniformLocation("GBuffer1"), 1); - shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 2); - shader->SendInteger(shader->GetUniformLocation("DepthBuffer"), 3); - - - shader = RegisterDeferredShader("DeferredPointSpotLight", r_fragmentSource_PointSpotLight, sizeof(r_fragmentSource_PointSpotLight), basicVertexStage, &error); - if (!shader) - { - NazaraError("Failed to register critical shader: " + error); - return false; - } - - shader->SendInteger(shader->GetUniformLocation("GBuffer0"), 0); - shader->SendInteger(shader->GetUniformLocation("GBuffer1"), 1); - shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 2); - shader->SendInteger(shader->GetUniformLocation("DepthBuffer"), 3); - - - // Shaders optionnels (S'ils ne sont pas présents, le rendu minimal sera quand même assuré) - shader = RegisterDeferredShader("DeferredBloomBright", r_fragmentSource_BloomBright, sizeof(r_fragmentSource_BloomBright), ppVertexStage, &error); - if (shader) - shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0); - else - { - NazaraWarning("Failed to register bloom (bright pass) shader, certain features will not work: " + error); - } - - - shader = RegisterDeferredShader("DeferredBloomFinal", r_fragmentSource_BloomFinal, sizeof(r_fragmentSource_BloomFinal), ppVertexStage, &error); - if (shader) - { - shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0); - shader->SendInteger(shader->GetUniformLocation("BloomTexture"), 1); - } - else - { - NazaraWarning("Failed to register bloom (final pass) shader, certain features will not work: " + error); - } - - - shader = RegisterDeferredShader("DeferredFXAA", r_fragmentSource_FXAA, sizeof(r_fragmentSource_FXAA), ppVertexStage, &error); - if (shader) - shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0); - else - { - NazaraWarning("Failed to register FXAA shader, certain features will not work: " + error); - } - - - shader = RegisterDeferredShader("DeferredGaussianBlur", r_fragmentSource_GaussianBlur, sizeof(r_fragmentSource_GaussianBlur), ppVertexStage, &error); - if (shader) - shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0); - else - { - NazaraWarning("Failed to register gaussian blur shader, certain features will not work: " + error); - } - - if (!DeferredGeometryPass::Initialize()) - { - NazaraError("Failed to initialize geometry pass"); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the deferred render technique - */ - - void DeferredRenderTechnique::Uninitialize() - { - DeferredGeometryPass::Uninitialize(); - - ShaderLibrary::Unregister("DeferredGBufferClear"); - ShaderLibrary::Unregister("DeferredDirectionnalLight"); - ShaderLibrary::Unregister("DeferredPointSpotLight"); - ShaderLibrary::Unregister("DeferredBloomBright"); - ShaderLibrary::Unregister("DeferredBloomFinal"); - ShaderLibrary::Unregister("DeferredFXAA"); - ShaderLibrary::Unregister("DeferredGaussianBlur"); - } - - /*! - * \brief Functor to compare two render pass - * \return true If first render pass is "smaller" than the second one - * - * \param pass1 First render pass to compare - * \param pass2 Second render pass to compare - */ - - bool DeferredRenderTechnique::RenderPassComparator::operator()(RenderPassType pass1, RenderPassType pass2) const - { - return RenderPassPriority[pass1] < RenderPassPriority[pass2]; - } -} diff --git a/src/Nazara/Graphics/DepthRenderQueue.cpp b/src/Nazara/Graphics/DepthRenderQueue.cpp deleted file mode 100644 index 9c684b28a..000000000 --- a/src/Nazara/Graphics/DepthRenderQueue.cpp +++ /dev/null @@ -1,372 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::DepthRenderQueue - * \brief Graphics class that represents the rendering queue for depth rendering - */ - - /*! - * \brief Constructs a DepthRenderTechnique object by default - */ - - DepthRenderQueue::DepthRenderQueue() - { - // Material - m_baseMaterial = Material::New(); - m_baseMaterial->EnableColorWrite(false); - m_baseMaterial->EnableFaceCulling(false); - //m_baseMaterial->SetFaceCulling(FaceSide_Front); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param colorPtr Color of the billboards if null, Color::White is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddBillboards(0, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, colorPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddBillboards(0, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, alphaPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param colorPtr Color of the billboards if null, Color::White is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddBillboards(0, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, colorPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Sizes of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddBillboards(0, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, alphaPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param colorPtr Color of the billboards if null, Color::White is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddBillboards(0, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, colorPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param sinCosPtr Rotation of the billboards if null, Vector2f(0.f, 1.f) is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr sinCosPtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddBillboards(0, material, billboardCount, scissorRect, positionPtr, sizePtr, sinCosPtr, alphaPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param colorPtr Color of the billboards if null, Color::White is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr colorPtr) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddBillboards(0, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, colorPtr); - } - - /*! - * \brief Adds multiple billboards to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the billboards - * \param count Number of billboards - * \param positionPtr Position of the billboards - * \param sizePtr Size of the billboards - * \param anglePtr Rotation of the billboards if null, 0.f is used - * \param alphaPtr Alpha parameters of the billboards if null, 1.f is used - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddBillboards(int renderOrder, const Material* material, std::size_t billboardCount, const Recti& scissorRect, SparsePtr positionPtr, SparsePtr sizePtr, SparsePtr anglePtr, SparsePtr alphaPtr) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddBillboards(0, material, billboardCount, scissorRect, positionPtr, sizePtr, anglePtr, alphaPtr); - } - - /*! - * \brief Adds a directional light to the queue - * - * \param light Light to add - * - * \remark Produces a NazaraAssert - */ - - void DepthRenderQueue::AddDirectionalLight(const DirectionalLight& light) - { - NazaraAssert(false, "Depth render queue doesn't handle lights"); - NazaraUnused(light); - } - - /*! - * \brief Adds mesh to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the mesh - * \param meshData Data of the mesh - * \param meshAABB Box of the mesh - * \param transformMatrix Matrix of the mesh - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddMesh(int renderOrder, const Material* material, const MeshData& meshData, const Boxf& meshAABB, const Matrix4f& transformMatrix, const Recti& scissorRect) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - NazaraUnused(meshAABB); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddMesh(0, material, meshData, meshAABB, transformMatrix, scissorRect); - } - - /*! - * \brief Adds a point light to the queue - * - * \param light Light to add - * - * \remark Produces a NazaraAssert - */ - - void DepthRenderQueue::AddPointLight(const PointLight& light) - { - NazaraAssert(false, "Depth render queue doesn't handle lights"); - NazaraUnused(light); - } - - /*! - * \brief Adds a spot light to the queue - * - * \param light Light to add - * - * \remark Produces a NazaraAssert - */ - - void DepthRenderQueue::AddSpotLight(const SpotLight& light) - { - NazaraAssert(false, "Depth render queue doesn't handle lights"); - NazaraUnused(light); - } - - /*! - * \brief Adds sprites to the queue - * - * \param renderOrder Order of rendering - * \param material Material of the sprites - * \param vertices Buffer of data for the sprites - * \param spriteCount Number of sprites - * \param overlay Texture of the sprites - * - * \remark Produces a NazaraAssert if material is invalid - */ - - void DepthRenderQueue::AddSprites(int renderOrder, const Material* material, const VertexStruct_XYZ_Color_UV* vertices, std::size_t spriteCount, const Recti& scissorRect, const Texture* overlay /*= nullptr*/) - { - NazaraAssert(material, "Invalid material"); - NazaraUnused(renderOrder); - NazaraUnused(overlay); - - if (!IsMaterialSuitable(material)) - return; - - if (material->HasDepthMaterial()) - material = material->GetDepthMaterial(); - else - material = m_baseMaterial; - - BasicRenderQueue::AddSprites(0, material, vertices, spriteCount, scissorRect, overlay); - } -} - diff --git a/src/Nazara/Graphics/DepthRenderTechnique.cpp b/src/Nazara/Graphics/DepthRenderTechnique.cpp deleted file mode 100644 index 44eb1e9f7..000000000 --- a/src/Nazara/Graphics/DepthRenderTechnique.cpp +++ /dev/null @@ -1,674 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - struct BillboardPoint - { - Color color; - Vector3f position; - Vector2f size; - Vector2f sinCos; // must follow `size` (both will be sent as a Vector4f) - Vector2f uv; - }; - - constexpr UInt32 s_vertexBufferSize = 4 * 1024 * 1024; // 4 MiB - constexpr UInt32 s_maxQuadPerDraw = s_vertexBufferSize / sizeof(VertexLayout_XYZ_Color_UV); - } - - /*! - * \ingroup graphics - * \class Nz::DepthRenderTechnique - * \brief Graphics class that represents the technique used in depth rendering - */ - - /*! - * \brief Constructs a DepthRenderTechnique object by default - */ - - DepthRenderTechnique::DepthRenderTechnique() : - m_vertexBuffer(BufferType_Vertex) - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - - m_whiteTexture = Nz::TextureLibrary::Get("White2D"); - - m_vertexBuffer.Create(s_vertexBufferSize, DataStorage_Hardware, BufferUsage_Dynamic); - - m_billboardPointBuffer.Reset(&s_billboardVertexDeclaration, &m_vertexBuffer); - m_spriteBuffer.Reset(VertexDeclaration::Get(VertexLayout_XYZ_Color_UV), &m_vertexBuffer); - } - - /*! - * \brief Clears the data - * - * \param sceneData Data of the scene - */ - - void DepthRenderTechnique::Clear(const SceneData& sceneData) const - { - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - Renderer::SetScissorRect(fullscreenScissorRect); - - Renderer::Enable(RendererParameter_DepthBuffer, true); - Renderer::Enable(RendererParameter_DepthWrite, true); - Renderer::Clear(RendererBuffer_Depth); - - // Just in case the background does render depth - if (sceneData.background) - sceneData.background->Draw(sceneData.viewer); - } - - /*! - * \brief Draws the data of the scene - * \return true If successful - * - * \param sceneData Data of the scene - */ - - bool DepthRenderTechnique::Draw(const SceneData& sceneData) const - { - m_renderQueue.Sort(sceneData.viewer); - - if (!m_renderQueue.models.empty()) - DrawModels(sceneData, m_renderQueue, m_renderQueue.models); - - if (!m_renderQueue.basicSprites.empty()) - DrawSprites(sceneData, m_renderQueue, m_renderQueue.basicSprites); - - if (!m_renderQueue.billboards.empty()) - DrawBillboards(sceneData, m_renderQueue, m_renderQueue.billboards); - - if (!m_renderQueue.depthSortedModels.empty()) - DrawModels(sceneData, m_renderQueue, m_renderQueue.depthSortedModels); - - if (!m_renderQueue.depthSortedSprites.empty()) - DrawSprites(sceneData, m_renderQueue, m_renderQueue.depthSortedSprites); - - if (!m_renderQueue.depthSortedBillboards.empty()) - DrawBillboards(sceneData, m_renderQueue, m_renderQueue.depthSortedBillboards); - - if (!m_renderQueue.customDrawables.empty()) - DrawCustomDrawables(sceneData, m_renderQueue, m_renderQueue.customDrawables); - - return true; - } - - /*! - * \brief Gets the render queue - * \return Pointer to the render queue - */ - - AbstractRenderQueue* DepthRenderTechnique::GetRenderQueue() - { - return &m_renderQueue; - } - - /*! - * \brief Gets the type of the current technique - * \return Type of the render technique - */ - - RenderTechniqueType DepthRenderTechnique::GetType() const - { - return RenderTechniqueType_Depth; - } - - /*! - * \brief Initializes the depth render technique - * \return true If successful - * - * \remark Produces a NazaraError if one shader creation failed - */ - - bool DepthRenderTechnique::Initialize() - { - try - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - - s_quadIndexBuffer.Reset(true, s_maxQuadPerDraw * 6, DataStorage_Hardware, 0); - - BufferMapper mapper(s_quadIndexBuffer, BufferAccess_WriteOnly); - UInt32* indices = static_cast(mapper.GetPointer()); - - for (UInt32 i = 0; i < s_maxQuadPerDraw; ++i) - { - *indices++ = i * 4 + 0; - *indices++ = i * 4 + 2; - *indices++ = i * 4 + 1; - - *indices++ = i * 4 + 2; - *indices++ = i * 4 + 3; - *indices++ = i * 4 + 1; - } - - mapper.Unmap(); // Inutile de garder le buffer ouvert plus longtemps - - // Quad buffer (utilisé pour l'instancing de billboard et de sprites) - //Note: Les UV sont calculés dans le shader - s_quadVertexBuffer.Reset(VertexDeclaration::Get(VertexLayout_XY), 4, DataStorage_Hardware, 0); - - float vertices[2 * 4] = { - -0.5f, -0.5f, - 0.5f, -0.5f, - -0.5f, 0.5f, - 0.5f, 0.5f, - }; - - s_quadVertexBuffer.FillRaw(vertices, 0, sizeof(vertices)); - - // Déclaration lors du rendu des billboards par sommet - s_billboardVertexDeclaration.EnableComponent(VertexComponent_Color, ComponentType_Color, NazaraOffsetOf(BillboardPoint, color)); - s_billboardVertexDeclaration.EnableComponent(VertexComponent_Position, ComponentType_Float3, NazaraOffsetOf(BillboardPoint, position)); - s_billboardVertexDeclaration.EnableComponent(VertexComponent_TexCoord, ComponentType_Float2, NazaraOffsetOf(BillboardPoint, uv)); - s_billboardVertexDeclaration.EnableComponent(VertexComponent_Userdata0, ComponentType_Float4, NazaraOffsetOf(BillboardPoint, size)); // Englobe sincos - - // Declaration utilisée lors du rendu des billboards par instancing - // L'avantage ici est la copie directe (std::memcpy) des données de la RenderQueue vers le buffer GPU - s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData0, ComponentType_Float3, NazaraOffsetOf(BasicRenderQueue::BillboardData, center)); - s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData1, ComponentType_Float4, NazaraOffsetOf(BasicRenderQueue::BillboardData, size)); // Englobe sincos - s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData2, ComponentType_Color, NazaraOffsetOf(BasicRenderQueue::BillboardData, color)); - } - catch (const std::exception& e) - { - NazaraError("Failed to initialise: " + String(e.what())); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the depth render technique - */ - - void DepthRenderTechnique::Uninitialize() - { - s_quadIndexBuffer.Reset(); - s_quadVertexBuffer.Reset(); - } - - void DepthRenderTechnique::DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const - { - VertexBuffer* instanceBuffer = Renderer::GetInstanceBuffer(); - instanceBuffer->SetVertexDeclaration(&s_billboardInstanceDeclaration); - - Renderer::SetVertexBuffer(&s_quadVertexBuffer); - - Nz::BufferMapper instanceBufferMapper; - std::size_t billboardCount = 0; - std::size_t maxBillboardPerDraw = instanceBuffer->GetVertexCount(); - - auto Commit = [&]() - { - if (billboardCount > 0) - { - instanceBufferMapper.Unmap(); - - Renderer::DrawPrimitivesInstanced(billboardCount, PrimitiveMode_TriangleStrip, 0, 4); - - billboardCount = 0; - } - }; - - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - for (const BasicRenderQueue::Billboard& billboard : billboards) - { - const Nz::Recti& scissorRect = (billboard.scissorRect.width > 0) ? billboard.scissorRect : fullscreenScissorRect; - - if (billboard.material != lastMaterial || (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect)) - { - Commit(); - - const MaterialPipeline* pipeline = billboard.material->GetPipeline(); - if (lastPipeline != pipeline) - { - pipelineInstance = &billboard.material->GetPipeline()->Apply(ShaderFlags_Billboard | ShaderFlags_Deferred | ShaderFlags_Instancing | ShaderFlags_VertexColor); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (lastMaterial != billboard.material) - { - billboard.material->Apply(*pipelineInstance); - lastMaterial = billboard.material; - } - - if (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(scissorRect); - lastScissorRect = scissorRect; - } - } - - if (!instanceBufferMapper.GetBuffer()) - instanceBufferMapper.Map(instanceBuffer, BufferAccess_DiscardAndWrite); - - std::memcpy(static_cast(instanceBufferMapper.GetPointer()) + sizeof(BasicRenderQueue::BillboardData) * billboardCount, &billboard.data, sizeof(BasicRenderQueue::BillboardData)); - if (++billboardCount >= maxBillboardPerDraw) - Commit(); - } - - Commit(); - } - - void DepthRenderTechnique::DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const - { - VertexBuffer* instanceBuffer = Renderer::GetInstanceBuffer(); - instanceBuffer->SetVertexDeclaration(&s_billboardInstanceDeclaration); - - Renderer::SetVertexBuffer(&s_quadVertexBuffer); - - Nz::BufferMapper instanceBufferMapper; - std::size_t billboardCount = 0; - std::size_t maxBillboardPerDraw = instanceBuffer->GetVertexCount(); - - auto Commit = [&]() - { - if (billboardCount > 0) - { - instanceBufferMapper.Unmap(); - - Renderer::DrawPrimitivesInstanced(billboardCount, PrimitiveMode_TriangleStrip, 0, 4); - - billboardCount = 0; - } - }; - - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - for (const BasicRenderQueue::BillboardChain& billboard : billboards) - { - const Nz::Recti& scissorRect = (billboard.scissorRect.width > 0) ? billboard.scissorRect : fullscreenScissorRect; - - if (billboard.material != lastMaterial || (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect)) - { - Commit(); - - const MaterialPipeline* pipeline = billboard.material->GetPipeline(); - if (lastPipeline != pipeline) - { - pipelineInstance = &billboard.material->GetPipeline()->Apply(ShaderFlags_Billboard | ShaderFlags_Deferred | ShaderFlags_Instancing | ShaderFlags_VertexColor); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (lastMaterial != billboard.material) - { - billboard.material->Apply(*pipelineInstance); - lastMaterial = billboard.material; - } - - if (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(scissorRect); - lastScissorRect = scissorRect; - } - } - - std::size_t billboardRemaining = billboard.billboardCount; - const BasicRenderQueue::BillboardData* billboardData = renderQueue.GetBillboardData(billboard.billboardIndex); - do - { - std::size_t renderedBillboardCount = std::min(billboardRemaining, maxBillboardPerDraw - billboardCount); - billboardRemaining -= renderedBillboardCount; - - if (!instanceBufferMapper.GetBuffer()) - instanceBufferMapper.Map(instanceBuffer, BufferAccess_DiscardAndWrite); - - std::memcpy(static_cast(instanceBufferMapper.GetPointer()) + sizeof(BasicRenderQueue::BillboardData) * billboardCount, billboardData, renderedBillboardCount * sizeof(BasicRenderQueue::BillboardData)); - billboardCount += renderedBillboardCount; - billboardData += renderedBillboardCount; - - if (billboardCount >= maxBillboardPerDraw) - Commit(); - } - while (billboardRemaining > 0); - } - - Commit(); - } - - void DepthRenderTechnique::DrawCustomDrawables(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& customDrawables) const - { - for (const BasicRenderQueue::CustomDrawable& customDrawable : customDrawables) - customDrawable.drawable->Draw(); - } - - void DepthRenderTechnique::DrawModels(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const Nz::RenderQueue& models) const - { - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - ///TODO: Reimplement instancing - - for (const BasicRenderQueue::Model& model : models) - { - const MaterialPipeline* pipeline = model.material->GetPipeline(); - if (lastPipeline != pipeline) - { - pipelineInstance = &model.material->GetPipeline()->Apply(ShaderFlags_Deferred); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (lastMaterial != model.material) - { - model.material->Apply(*pipelineInstance); - lastMaterial = model.material; - } - - if (model.material->IsScissorTestEnabled()) - { - const Nz::Recti& scissorRect = (model.scissorRect.width > 0) ? model.scissorRect : fullscreenScissorRect; - if (scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(scissorRect); - lastScissorRect = scissorRect; - } - } - - // Handle draw call before rendering loop - Renderer::DrawCall drawFunc; - Renderer::DrawCallInstanced instancedDrawFunc; - unsigned int indexCount; - - if (model.meshData.indexBuffer) - { - drawFunc = Renderer::DrawIndexedPrimitives; - instancedDrawFunc = Renderer::DrawIndexedPrimitivesInstanced; - indexCount = model.meshData.indexBuffer->GetIndexCount(); - } - else - { - drawFunc = Renderer::DrawPrimitives; - instancedDrawFunc = Renderer::DrawPrimitivesInstanced; - indexCount = model.meshData.vertexBuffer->GetVertexCount(); - } - - Renderer::SetIndexBuffer(model.meshData.indexBuffer); - Renderer::SetVertexBuffer(model.meshData.vertexBuffer); - - Renderer::SetMatrix(MatrixType_World, model.matrix); - drawFunc(model.meshData.primitiveMode, 0, indexCount); - } - } - - void DepthRenderTechnique::DrawSprites(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& spriteList) const - { - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const std::size_t maxSpriteCount = std::min(s_maxQuadPerDraw, m_spriteBuffer.GetVertexCount() / 4); - - const unsigned int overlayTextureUnit = Material::GetTextureUnit(TextureMap_Overlay); - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - Renderer::SetIndexBuffer(&s_quadIndexBuffer); - Renderer::SetMatrix(MatrixType_World, Matrix4f::Identity()); - Renderer::SetVertexBuffer(&m_spriteBuffer); - - auto Draw = [&]() - { - unsigned int firstIndex = 0; - for (const auto& batch : m_spriteBatches) - { - const MaterialPipeline* pipeline = batch.material->GetPipeline(); - if (pipeline != lastPipeline) - { - pipelineInstance = &batch.material->GetPipeline()->Apply(ShaderFlags_TextureOverlay | ShaderFlags_VertexColor); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - - // Overlay texture unit - shader->SendInteger(shaderUniforms->textureOverlay, overlayTextureUnit); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (batch.material != lastMaterial) - { - batch.material->Apply(*pipelineInstance); - - Renderer::SetTextureSampler(overlayTextureUnit, batch.material->GetDiffuseSampler()); - - lastMaterial = batch.material; - } - - if (batch.overlayTexture != lastOverlay) - { - Renderer::SetTexture(overlayTextureUnit, batch.overlayTexture); - lastOverlay = batch.overlayTexture; - } - - if (batch.material->IsScissorTestEnabled() && batch.scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(batch.scissorRect); - lastScissorRect = batch.scissorRect; - } - - unsigned int indexCount = batch.spriteCount * 6; - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, firstIndex, indexCount); - firstIndex += indexCount; - } - }; - - m_spriteBatches.clear(); - { - BufferMapper vertexMapper; - VertexStruct_XYZ_Color_UV* vertices = nullptr; - - std::size_t remainingSprite = maxSpriteCount; - - const Material* lastMaterial = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - for (const BasicRenderQueue::SpriteChain& basicSprites : spriteList) - { - const Nz::Texture* overlayTexture = (basicSprites.overlay) ? basicSprites.overlay.Get() : m_whiteTexture.Get(); - const Nz::Recti& scissorRect = (basicSprites.scissorRect.width > 0) ? basicSprites.scissorRect : fullscreenScissorRect; - - const VertexStruct_XYZ_Color_UV* spriteVertices = basicSprites.vertices; - std::size_t spriteCount = basicSprites.spriteCount; - - for (;;) - { - if (m_spriteBatches.empty() || basicSprites.material != lastMaterial || overlayTexture != lastOverlay || (basicSprites.material->IsScissorTestEnabled() && scissorRect != lastScissorRect)) - { - m_spriteBatches.emplace_back(); - SpriteBatch& newBatch = m_spriteBatches.back(); - newBatch.material = basicSprites.material; - newBatch.overlayTexture = overlayTexture; - newBatch.scissorRect = scissorRect; - newBatch.spriteCount = 0; - - lastMaterial = basicSprites.material; - lastOverlay = overlayTexture; - lastScissorRect = scissorRect; - } - - SpriteBatch& currentBatch = m_spriteBatches.back(); - - if (!vertices) - { - vertexMapper.Map(m_spriteBuffer, BufferAccess_DiscardAndWrite); - vertices = static_cast(vertexMapper.GetPointer()); - } - - std::size_t processedSpriteCount = std::min(remainingSprite, spriteCount); - std::size_t processedVertices = processedSpriteCount * 4; - - std::memcpy(vertices, spriteVertices, processedVertices * sizeof(VertexStruct_XYZ_Color_UV)); - vertices += processedVertices; - spriteVertices += processedVertices; - - currentBatch.spriteCount += processedSpriteCount; - spriteCount -= processedSpriteCount; - - remainingSprite -= processedSpriteCount; - if (remainingSprite == 0) - { - vertexMapper.Unmap(); - vertices = nullptr; - - Draw(); - - remainingSprite = maxSpriteCount; - m_spriteBatches.clear(); - } - - if (spriteCount == 0) - break; - } - } - } - - Draw(); - } - - /*! - * \brief Gets the shader uniforms - * \return Uniforms of the shader - * - * \param shader Shader to get uniforms from - */ - - const DepthRenderTechnique::ShaderUniforms* DepthRenderTechnique::GetShaderUniforms(const Shader* shader) const - { - auto it = m_shaderUniforms.find(shader); - if (it == m_shaderUniforms.end()) - { - ShaderUniforms uniforms; - uniforms.shaderReleaseSlot.Connect(shader->OnShaderRelease, this, &DepthRenderTechnique::OnShaderInvalidated); - uniforms.shaderUniformInvalidatedSlot.Connect(shader->OnShaderUniformInvalidated, this, &DepthRenderTechnique::OnShaderInvalidated); - - uniforms.sceneAmbient = shader->GetUniformLocation("SceneAmbient"); - uniforms.textureOverlay = shader->GetUniformLocation("TextureOverlay"); - - it = m_shaderUniforms.emplace(shader, std::move(uniforms)).first; - } - - return &it->second; - } - - /*! - * \brief Handle the invalidation of a shader - * - * \param shader Shader being invalidated - */ - - void DepthRenderTechnique::OnShaderInvalidated(const Shader* shader) const - { - m_shaderUniforms.erase(shader); - } - - IndexBuffer DepthRenderTechnique::s_quadIndexBuffer; - VertexBuffer DepthRenderTechnique::s_quadVertexBuffer; - VertexDeclaration DepthRenderTechnique::s_billboardInstanceDeclaration; - VertexDeclaration DepthRenderTechnique::s_billboardVertexDeclaration; -} diff --git a/src/Nazara/Graphics/Drawable.cpp b/src/Nazara/Graphics/Drawable.cpp deleted file mode 100644 index 3695fa1cd..000000000 --- a/src/Nazara/Graphics/Drawable.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::Drawable - * \brief Graphics class that represents something drawable for our scene - * - * \remark This class is abstract - */ - - Drawable::~Drawable() = default; -} diff --git a/src/Nazara/Graphics/Formats/MeshLoader.cpp b/src/Nazara/Graphics/Formats/MeshLoader.cpp deleted file mode 100644 index f804cf4cb..000000000 --- a/src/Nazara/Graphics/Formats/MeshLoader.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - void LoadMaterials(Model* model, const ModelParameters& parameters) - { - unsigned int matCount = model->GetMaterialCount(); - - for (unsigned int i = 0; i < matCount; ++i) - { - const ParameterList& matData = model->GetMesh()->GetMaterialData(i); - - String path; - if (matData.GetStringParameter(MaterialData::FilePath, &path)) - { - std::filesystem::path filePath = path.ToStdString(); - if (!std::filesystem::exists(filePath)) - { - NazaraWarning("Shader name does not refer to an existing file, \".tga\" is used by default"); - filePath.replace_extension(".tga"); - } - - if (MaterialRef material = Material::LoadFromFile(filePath, parameters.material)) - model->SetMaterial(i, std::move(material)); - else - NazaraWarning("Failed to load material from file " + String::Number(i)); - } - else - { - MaterialRef material = Material::New(); - material->BuildFromParameters(matData, parameters.material); - - model->SetMaterial(i, std::move(material)); - } - } - } - - Ternary Check(Stream& stream, const ModelParameters& parameters) - { - NazaraUnused(stream); - - bool skip; - if (parameters.custom.GetBooleanParameter("SkipNativeMeshLoader", &skip) && skip) - return Ternary_False; - - return Ternary_Unknown; - } - - ModelRef Load(Stream& stream, const ModelParameters& parameters) - { - NazaraUnused(parameters); - - MeshRef mesh = Mesh::LoadFromStream(stream, parameters.mesh); - if (!mesh) - { - NazaraError("Failed to load model mesh"); - return nullptr; - } - - ModelRef model; - if (mesh->IsAnimable()) - model = SkeletalModel::New(); - else - model = Model::New(); - - model->SetMesh(mesh); - - if (parameters.loadMaterials) - LoadMaterials(model, parameters); - - return model; - } - } - - namespace Loaders - { - void RegisterMesh() - { - ModelLoader::RegisterLoader(MeshLoader::IsExtensionSupported, Check, Load); - } - - void UnregisterMesh() - { - ModelLoader::UnregisterLoader(MeshLoader::IsExtensionSupported, Check, Load); - } - } -} - diff --git a/src/Nazara/Graphics/Formats/MeshLoader.hpp b/src/Nazara/Graphics/Formats/MeshLoader.hpp deleted file mode 100644 index 68e08f079..000000000 --- a/src/Nazara/Graphics/Formats/MeshLoader.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_LOADERS_MESH_HPP -#define NAZARA_LOADERS_MESH_HPP - -#include - -namespace Nz -{ - namespace Loaders - { - void RegisterMesh(); - void UnregisterMesh(); - } -} - -#endif // NAZARA_LOADERS_MESH_HPP diff --git a/src/Nazara/Graphics/Formats/TextureLoader.cpp b/src/Nazara/Graphics/Formats/TextureLoader.cpp deleted file mode 100644 index e8555b6db..000000000 --- a/src/Nazara/Graphics/Formats/TextureLoader.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - Ternary Check(Stream& stream, const MaterialParams& parameters) - { - NazaraUnused(stream); - - bool skip; - if (parameters.custom.GetBooleanParameter("SkipNativeTextureLoader", &skip) && skip) - return Ternary_False; - - return Ternary_Unknown; - } - - MaterialRef Load(Stream& stream, const MaterialParams& parameters) - { - NazaraUnused(parameters); - - TextureRef texture = Texture::LoadFromStream(stream); - if (!texture) - { - NazaraError("Failed to load diffuse map"); - return nullptr; - } - - MaterialRef material = Material::New(); - material->SetDiffuseMap(texture); - material->SetShader(parameters.shaderName); - - return material; - } - } - - namespace Loaders - { - void RegisterTexture() - { - MaterialLoader::RegisterLoader(ImageLoader::IsExtensionSupported, Check, Load); - } - - void UnregisterTexture() - { - MaterialLoader::UnregisterLoader(ImageLoader::IsExtensionSupported, Check, Load); - } - } -} diff --git a/src/Nazara/Graphics/Formats/TextureLoader.hpp b/src/Nazara/Graphics/Formats/TextureLoader.hpp deleted file mode 100644 index f6dba4711..000000000 --- a/src/Nazara/Graphics/Formats/TextureLoader.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_LOADERS_TEXTURE_HPP -#define NAZARA_LOADERS_TEXTURE_HPP - -#include - -namespace Nz -{ - namespace Loaders - { - void RegisterTexture(); - void UnregisterTexture(); - } -} - -#endif // NAZARA_LOADERS_TEXTURE_HPP diff --git a/src/Nazara/Graphics/ForwardRenderTechnique.cpp b/src/Nazara/Graphics/ForwardRenderTechnique.cpp deleted file mode 100644 index d620a3076..000000000 --- a/src/Nazara/Graphics/ForwardRenderTechnique.cpp +++ /dev/null @@ -1,924 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - struct BillboardPoint - { - Color color; - Vector3f position; - Vector2f size; - Vector2f sinCos; // must follow `size` (both will be sent as a Vector4f) - Vector2f uv; - }; - - constexpr UInt32 s_vertexBufferSize = 4 * 1024 * 1024; // 4 MiB - constexpr UInt32 s_maxQuadPerDraw = s_vertexBufferSize / sizeof(VertexLayout_XYZ_Color_UV); - } - - /*! - * \ingroup graphics - * \class Nz::ForwardRenderTechnique - * \brief Graphics class that represents the technique used in forward rendering - */ - - /*! - * \brief Constructs a ForwardRenderTechnique object by default - */ - - ForwardRenderTechnique::ForwardRenderTechnique() : - m_vertexBuffer(BufferType_Vertex), - m_maxLightPassPerObject(3) - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - - m_whiteCubemap = Nz::TextureLibrary::Get("WhiteCubemap"); - m_whiteTexture = Nz::TextureLibrary::Get("White2D"); - - m_vertexBuffer.Create(s_vertexBufferSize, DataStorage_Hardware, BufferUsage_Dynamic); - - m_billboardPointBuffer.Reset(&s_billboardVertexDeclaration, &m_vertexBuffer); - m_spriteBuffer.Reset(VertexDeclaration::Get(VertexLayout_XYZ_Color_UV), &m_vertexBuffer); - } - - /*! - * \brief Clears the data - * - * \param sceneData Data of the scene - */ - - void ForwardRenderTechnique::Clear(const SceneData& sceneData) const - { - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - Renderer::SetScissorRect(fullscreenScissorRect); - - Renderer::Enable(RendererParameter_DepthBuffer, true); - Renderer::Enable(RendererParameter_DepthWrite, true); - Renderer::Clear(RendererBuffer_Depth); - - if (sceneData.background) - sceneData.background->Draw(sceneData.viewer); - } - - /*! - * \brief Draws the data of the scene - * \return true If successful - * - * \param sceneData Data of the scene - * - * \remark Produces a NazaraAssert if viewer of the scene is invalid - */ - - bool ForwardRenderTechnique::Draw(const SceneData& sceneData) const - { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - - m_renderQueue.Sort(sceneData.viewer); - - if (!m_renderQueue.models.empty()) - DrawModels(sceneData, m_renderQueue, m_renderQueue.models); - - if (!m_renderQueue.basicSprites.empty()) - DrawSprites(sceneData, m_renderQueue, m_renderQueue.basicSprites); - - if (!m_renderQueue.billboards.empty()) - DrawBillboards(sceneData, m_renderQueue, m_renderQueue.billboards); - - if (!m_renderQueue.depthSortedModels.empty()) - DrawModels(sceneData, m_renderQueue, m_renderQueue.depthSortedModels); - - if (!m_renderQueue.depthSortedSprites.empty()) - DrawSprites(sceneData, m_renderQueue, m_renderQueue.depthSortedSprites); - - if (!m_renderQueue.depthSortedBillboards.empty()) - DrawBillboards(sceneData, m_renderQueue, m_renderQueue.depthSortedBillboards); - - if (!m_renderQueue.customDrawables.empty()) - DrawCustomDrawables(sceneData, m_renderQueue, m_renderQueue.customDrawables); - - return true; - } - - /*! - * \brief Gets the maximum number of lights available per pass per object - * \return Maximum number of light simultaneously per object - */ - - unsigned int ForwardRenderTechnique::GetMaxLightPassPerObject() const - { - return m_maxLightPassPerObject; - } - - /*! - * \brief Gets the render queue - * \return Pointer to the render queue - */ - - AbstractRenderQueue* ForwardRenderTechnique::GetRenderQueue() - { - return &m_renderQueue; - } - - /*! - * \brief Gets the type of the current technique - * \return Type of the render technique - */ - - RenderTechniqueType ForwardRenderTechnique::GetType() const - { - return RenderTechniqueType_BasicForward; - } - - /*! - * \brief Sets the maximum number of lights available per pass per object - * - * \param passCount Maximum number of light simulatenously per object - */ - - void ForwardRenderTechnique::SetMaxLightPassPerObject(unsigned int maxLightPassPerObject) - { - m_maxLightPassPerObject = maxLightPassPerObject; - } - - /*! - * \brief Initializes the forward render technique - * \return true If successful - * - * \remark Produces a NazaraError if one shader creation failed - */ - - bool ForwardRenderTechnique::Initialize() - { - try - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - - s_quadIndexBuffer.Reset(true, s_maxQuadPerDraw * 6, DataStorage_Hardware, 0); - - BufferMapper mapper(s_quadIndexBuffer, BufferAccess_WriteOnly); - UInt32* indices = static_cast(mapper.GetPointer()); - - for (UInt32 i = 0; i < s_maxQuadPerDraw; ++i) - { - *indices++ = i * 4 + 0; - *indices++ = i * 4 + 2; - *indices++ = i * 4 + 1; - - *indices++ = i * 4 + 2; - *indices++ = i * 4 + 3; - *indices++ = i * 4 + 1; - } - - mapper.Unmap(); // No point to keep the buffer open any longer - - // Quad buffer (used for instancing of billboards and sprites) - //Note: UV are computed in the shader - s_quadVertexBuffer.Reset(VertexDeclaration::Get(VertexLayout_XY), 4, DataStorage_Hardware, 0); - - float vertices[2 * 4] = { - -0.5f, -0.5f, - 0.5f, -0.5f, - -0.5f, 0.5f, - 0.5f, 0.5f, - }; - - s_quadVertexBuffer.FillRaw(vertices, 0, sizeof(vertices)); - - // Declaration used when rendering the vertex billboards - s_billboardVertexDeclaration.EnableComponent(VertexComponent_Color, ComponentType_Color, NazaraOffsetOf(BillboardPoint, color)); - s_billboardVertexDeclaration.EnableComponent(VertexComponent_Position, ComponentType_Float3, NazaraOffsetOf(BillboardPoint, position)); - s_billboardVertexDeclaration.EnableComponent(VertexComponent_TexCoord, ComponentType_Float2, NazaraOffsetOf(BillboardPoint, uv)); - s_billboardVertexDeclaration.EnableComponent(VertexComponent_Userdata0, ComponentType_Float4, NazaraOffsetOf(BillboardPoint, size)); // Includes sincos - - // Declaration used when rendering the billboards with intancing - // The main advantage is the direct copy (std::memcpy) of data in the RenderQueue to the GPU buffer - s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData0, ComponentType_Float3, NazaraOffsetOf(BasicRenderQueue::BillboardData, center)); - s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData1, ComponentType_Float4, NazaraOffsetOf(BasicRenderQueue::BillboardData, size)); // Englobe sincos - s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData2, ComponentType_Color, NazaraOffsetOf(BasicRenderQueue::BillboardData, color)); - - s_reflectionSampler.SetFilterMode(SamplerFilter_Bilinear); - s_reflectionSampler.SetWrapMode(SamplerWrap_Clamp); - - s_shadowSampler.SetFilterMode(SamplerFilter_Bilinear); - s_shadowSampler.SetWrapMode(SamplerWrap_Clamp); - } - catch (const std::exception& e) - { - NazaraError("Failed to initialise: " + String(e.what())); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the forward render technique - */ - - void ForwardRenderTechnique::Uninitialize() - { - s_quadIndexBuffer.Reset(); - s_quadVertexBuffer.Reset(); - } - - /*! - * \brief Chooses the nearest lights for one object - * - * \param object Sphere symbolizing the object - * \param includeDirectionalLights Should directional lights be included in the computation - */ - - void ForwardRenderTechnique::ChooseLights(const Spheref& object, bool includeDirectionalLights) const - { - m_lights.clear(); - - // First step: add all the lights into a common list and compute their score, exlucing those who have no chance of lighting the object - // (Those who are too far away). - - if (includeDirectionalLights) - { - for (unsigned int i = 0; i < m_renderQueue.directionalLights.size(); ++i) - { - const auto& light = m_renderQueue.directionalLights[i]; - if (IsDirectionalLightSuitable(object, light)) - m_lights.push_back({LightType_Directional, ComputeDirectionalLightScore(object, light), i}); - } - } - - for (unsigned int i = 0; i < m_renderQueue.pointLights.size(); ++i) - { - const auto& light = m_renderQueue.pointLights[i]; - if (IsPointLightSuitable(object, light)) - m_lights.push_back({LightType_Point, ComputePointLightScore(object, light), i}); - } - - for (unsigned int i = 0; i < m_renderQueue.spotLights.size(); ++i) - { - const auto& light = m_renderQueue.spotLights[i]; - if (IsSpotLightSuitable(object, light)) - m_lights.push_back({LightType_Spot, ComputeSpotLightScore(object, light), i}); - } - - // Then, sort the lights according to their score - std::sort(m_lights.begin(), m_lights.end(), [](const LightIndex& light1, const LightIndex& light2) - { - return light1.score < light2.score; - }); - } - - void ForwardRenderTechnique::DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const - { - VertexBuffer* instanceBuffer = Renderer::GetInstanceBuffer(); - instanceBuffer->SetVertexDeclaration(&s_billboardInstanceDeclaration); - - Renderer::SetVertexBuffer(&s_quadVertexBuffer); - - Nz::BufferMapper instanceBufferMapper; - std::size_t billboardCount = 0; - std::size_t maxBillboardPerDraw = instanceBuffer->GetVertexCount(); - - auto Commit = [&]() - { - if (billboardCount > 0) - { - instanceBufferMapper.Unmap(); - - Renderer::DrawPrimitivesInstanced(billboardCount, PrimitiveMode_TriangleStrip, 0, 4); - - billboardCount = 0; - } - }; - - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - for (const BasicRenderQueue::Billboard& billboard : billboards) - { - const Nz::Recti& scissorRect = (billboard.scissorRect.width > 0) ? billboard.scissorRect : fullscreenScissorRect; - - if (billboard.material != lastMaterial || (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect)) - { - Commit(); - - const MaterialPipeline* pipeline = billboard.material->GetPipeline(); - if (lastPipeline != pipeline) - { - pipelineInstance = &billboard.material->GetPipeline()->Apply(ShaderFlags_Billboard | ShaderFlags_Instancing | ShaderFlags_VertexColor); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - // Position of the camera - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (lastMaterial != billboard.material) - { - billboard.material->Apply(*pipelineInstance); - lastMaterial = billboard.material; - } - - if (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(scissorRect); - lastScissorRect = scissorRect; - } - } - - if (!instanceBufferMapper.GetBuffer()) - instanceBufferMapper.Map(instanceBuffer, BufferAccess_DiscardAndWrite); - - std::memcpy(static_cast(instanceBufferMapper.GetPointer()) + sizeof(BasicRenderQueue::BillboardData) * billboardCount, &billboard.data, sizeof(BasicRenderQueue::BillboardData)); - if (++billboardCount >= maxBillboardPerDraw) - Commit(); - } - - Commit(); - } - - void ForwardRenderTechnique::DrawBillboards(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& billboards) const - { - VertexBuffer* instanceBuffer = Renderer::GetInstanceBuffer(); - instanceBuffer->SetVertexDeclaration(&s_billboardInstanceDeclaration); - - Renderer::SetVertexBuffer(&s_quadVertexBuffer); - - Nz::BufferMapper instanceBufferMapper; - std::size_t billboardCount = 0; - std::size_t maxBillboardPerDraw = instanceBuffer->GetVertexCount(); - - auto Commit = [&]() - { - if (billboardCount > 0) - { - instanceBufferMapper.Unmap(); - - Renderer::DrawPrimitivesInstanced(billboardCount, PrimitiveMode_TriangleStrip, 0, 4); - - billboardCount = 0; - } - }; - - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - for (const BasicRenderQueue::BillboardChain& billboard : billboards) - { - const Nz::Recti& scissorRect = (billboard.scissorRect.width > 0) ? billboard.scissorRect : fullscreenScissorRect; - - if (billboard.material != lastMaterial || (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect)) - { - Commit(); - - const MaterialPipeline* pipeline = billboard.material->GetPipeline(); - if (lastPipeline != pipeline) - { - pipelineInstance = &billboard.material->GetPipeline()->Apply(ShaderFlags_Billboard | ShaderFlags_Instancing | ShaderFlags_VertexColor); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - // Position of the camera - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (lastMaterial != billboard.material) - { - billboard.material->Apply(*pipelineInstance); - lastMaterial = billboard.material; - } - - if (billboard.material->IsScissorTestEnabled() && scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(scissorRect); - lastScissorRect = scissorRect; - } - } - - std::size_t billboardRemaining = billboard.billboardCount; - const BasicRenderQueue::BillboardData* billboardData = renderQueue.GetBillboardData(billboard.billboardIndex); - do - { - std::size_t renderedBillboardCount = std::min(billboardRemaining, maxBillboardPerDraw - billboardCount); - billboardRemaining -= renderedBillboardCount; - - if (!instanceBufferMapper.GetBuffer()) - instanceBufferMapper.Map(instanceBuffer, BufferAccess_DiscardAndWrite); - - std::memcpy(static_cast(instanceBufferMapper.GetPointer()) + sizeof(BasicRenderQueue::BillboardData) * billboardCount, billboardData, renderedBillboardCount * sizeof(BasicRenderQueue::BillboardData)); - billboardCount += renderedBillboardCount; - billboardData += renderedBillboardCount; - - if (billboardCount >= maxBillboardPerDraw) - Commit(); - } - while (billboardRemaining > 0); - } - - Commit(); - } - - void ForwardRenderTechnique::DrawCustomDrawables(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& customDrawables) const - { - for (const BasicRenderQueue::CustomDrawable& customDrawable : customDrawables) - customDrawable.drawable->Draw(); - } - - void ForwardRenderTechnique::DrawModels(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const Nz::RenderQueue& models) const - { - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - ///TODO: Reimplement instancing - - for (const BasicRenderQueue::Model& model : models) - { - const MaterialPipeline* pipeline = model.material->GetPipeline(); - if (lastPipeline != pipeline) - { - pipelineInstance = &model.material->GetPipeline()->Apply(); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - // Position of the camera - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (lastMaterial != model.material) - { - model.material->Apply(*pipelineInstance); - lastMaterial = model.material; - } - - if (model.material->IsScissorTestEnabled()) - { - const Nz::Recti& scissorRect = (model.scissorRect.width > 0) ? model.scissorRect : fullscreenScissorRect; - if (scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(scissorRect); - lastScissorRect = scissorRect; - } - } - - if (shaderUniforms->reflectionMap != -1) - { - unsigned int textureUnit = Material::GetTextureUnit(TextureMap_ReflectionCube); - - Renderer::SetTexture(textureUnit, sceneData.globalReflectionTexture); - Renderer::SetTextureSampler(textureUnit, s_reflectionSampler); - } - - // Handle draw call before rendering loop - Renderer::DrawCall drawFunc; - Renderer::DrawCallInstanced instancedDrawFunc; - unsigned int indexCount; - - if (model.meshData.indexBuffer) - { - drawFunc = Renderer::DrawIndexedPrimitives; - instancedDrawFunc = Renderer::DrawIndexedPrimitivesInstanced; - indexCount = model.meshData.indexBuffer->GetIndexCount(); - } - else - { - drawFunc = Renderer::DrawPrimitives; - instancedDrawFunc = Renderer::DrawPrimitivesInstanced; - indexCount = model.meshData.vertexBuffer->GetVertexCount(); - } - - Renderer::SetIndexBuffer(model.meshData.indexBuffer); - Renderer::SetVertexBuffer(model.meshData.vertexBuffer); - - if (shaderUniforms->hasLightUniforms) - { - ChooseLights(model.obbSphere); - - std::size_t lightCount = m_lights.size(); - - Nz::Renderer::SetMatrix(Nz::MatrixType_World, model.matrix); - std::size_t lightIndex = 0; - RendererComparison oldDepthFunc = Renderer::GetDepthFunc(); // In the case where we have to change it - - std::size_t passCount = (lightCount == 0) ? 1 : (lightCount - 1) / NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS + 1; - for (std::size_t pass = 0; pass < passCount; ++pass) - { - lightCount -= std::min(lightCount, NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS); - - if (pass == 1) - { - // To add the result of light computations - // We won't interfere with materials parameters because we only render opaques objects - // (A.K.A., without blending) - // About the depth function, it must be applied only the first time - Renderer::Enable(RendererParameter_Blend, true); - Renderer::SetBlendFunc(BlendFunc_One, BlendFunc_One); - Renderer::SetDepthFunc(RendererComparison_Equal); - } - - // Sends the light uniforms to the shader - for (unsigned int i = 0; i < NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS; ++i) - SendLightUniforms(lastShader, shaderUniforms->lightUniforms, i, lightIndex++, shaderUniforms->lightOffset*i); - - // And we draw - drawFunc(model.meshData.primitiveMode, 0, indexCount); - } - - Renderer::Enable(RendererParameter_Blend, false); - Renderer::SetDepthFunc(oldDepthFunc); - } - else - { - Renderer::SetMatrix(MatrixType_World, model.matrix); - drawFunc(model.meshData.primitiveMode, 0, indexCount); - } - } - } - - void ForwardRenderTechnique::DrawSprites(const SceneData& sceneData, const BasicRenderQueue& renderQueue, const RenderQueue& spriteList) const - { - const RenderTarget* renderTarget = sceneData.viewer->GetTarget(); - Recti fullscreenScissorRect = Recti(Vector2i(renderTarget->GetSize())); - - const std::size_t maxSpriteCount = std::min(s_maxQuadPerDraw, m_spriteBuffer.GetVertexCount() / 4); - - const unsigned int overlayTextureUnit = Material::GetTextureUnit(TextureMap_Overlay); - const Material* lastMaterial = nullptr; - const MaterialPipeline* lastPipeline = nullptr; - const Shader* lastShader = nullptr; - const ShaderUniforms* shaderUniforms = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - const MaterialPipeline::Instance* pipelineInstance = nullptr; - - Renderer::SetIndexBuffer(&s_quadIndexBuffer); - Renderer::SetMatrix(MatrixType_World, Matrix4f::Identity()); - Renderer::SetVertexBuffer(&m_spriteBuffer); - - auto Draw = [&]() - { - unsigned int firstIndex = 0; - for (const auto& batch : m_spriteBatches) - { - const MaterialPipeline* pipeline = batch.material->GetPipeline(); - if (pipeline != lastPipeline) - { - pipelineInstance = &batch.material->GetPipeline()->Apply(ShaderFlags_TextureOverlay | ShaderFlags_VertexColor); - - const Shader* shader = pipelineInstance->uberInstance->GetShader(); - if (shader != lastShader) - { - // Index of uniforms in the shader - shaderUniforms = GetShaderUniforms(shader); - - // Ambient color of the scene - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); - // Position of the camera - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); - - // Overlay texture unit - shader->SendInteger(shaderUniforms->textureOverlay, overlayTextureUnit); - - lastShader = shader; - } - - lastPipeline = pipeline; - } - - if (batch.material != lastMaterial) - { - batch.material->Apply(*pipelineInstance); - - Renderer::SetTextureSampler(overlayTextureUnit, batch.material->GetDiffuseSampler()); - - lastMaterial = batch.material; - } - - if (batch.overlayTexture != lastOverlay) - { - Renderer::SetTexture(overlayTextureUnit, batch.overlayTexture); - lastOverlay = batch.overlayTexture; - } - - if (batch.material->IsScissorTestEnabled() && batch.scissorRect != lastScissorRect) - { - Renderer::SetScissorRect(batch.scissorRect); - lastScissorRect = batch.scissorRect; - } - - unsigned int indexCount = batch.spriteCount * 6; - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, firstIndex, indexCount); - firstIndex += indexCount; - } - }; - - m_spriteBatches.clear(); - { - BufferMapper vertexMapper; - VertexStruct_XYZ_Color_UV* vertices = nullptr; - - std::size_t remainingSprite = maxSpriteCount; - - const Material* lastMaterial = nullptr; - const Texture* lastOverlay = nullptr; - Recti lastScissorRect = Recti(-1, -1); - - for (const BasicRenderQueue::SpriteChain& basicSprites : spriteList) - { - const Nz::Texture* overlayTexture = (basicSprites.overlay) ? basicSprites.overlay.Get() : m_whiteTexture.Get(); - const Nz::Recti& scissorRect = (basicSprites.scissorRect.width > 0) ? basicSprites.scissorRect : fullscreenScissorRect; - - const VertexStruct_XYZ_Color_UV* spriteVertices = basicSprites.vertices; - std::size_t spriteCount = basicSprites.spriteCount; - - for (;;) - { - if (m_spriteBatches.empty() || basicSprites.material != lastMaterial || overlayTexture != lastOverlay || (basicSprites.material->IsScissorTestEnabled() && scissorRect != lastScissorRect)) - { - m_spriteBatches.emplace_back(); - SpriteBatch& newBatch = m_spriteBatches.back(); - newBatch.material = basicSprites.material; - newBatch.overlayTexture = overlayTexture; - newBatch.scissorRect = scissorRect; - newBatch.spriteCount = 0; - - lastMaterial = basicSprites.material; - lastOverlay = overlayTexture; - lastScissorRect = scissorRect; - } - - SpriteBatch& currentBatch = m_spriteBatches.back(); - - if (!vertices) - { - vertexMapper.Map(m_spriteBuffer, BufferAccess_DiscardAndWrite); - vertices = static_cast(vertexMapper.GetPointer()); - } - - std::size_t processedSpriteCount = std::min(remainingSprite, spriteCount); - std::size_t processedVertices = processedSpriteCount * 4; - - std::memcpy(vertices, spriteVertices, processedVertices * sizeof(VertexStruct_XYZ_Color_UV)); - vertices += processedVertices; - spriteVertices += processedVertices; - - currentBatch.spriteCount += processedSpriteCount; - spriteCount -= processedSpriteCount; - - remainingSprite -= processedSpriteCount; - if (remainingSprite == 0) - { - vertexMapper.Unmap(); - vertices = nullptr; - - Draw(); - - remainingSprite = maxSpriteCount; - m_spriteBatches.clear(); - } - - if (spriteCount == 0) - break; - } - } - } - - Draw(); - } - - const ForwardRenderTechnique::ShaderUniforms* ForwardRenderTechnique::GetShaderUniforms(const Shader* shader) const - { - auto it = m_shaderUniforms.find(shader); - if (it == m_shaderUniforms.end()) - { - ShaderUniforms uniforms; - uniforms.shaderReleaseSlot.Connect(shader->OnShaderRelease, this, &ForwardRenderTechnique::OnShaderInvalidated); - uniforms.shaderUniformInvalidatedSlot.Connect(shader->OnShaderUniformInvalidated, this, &ForwardRenderTechnique::OnShaderInvalidated); - - uniforms.eyePosition = shader->GetUniformLocation("EyePosition"); - uniforms.reflectionMap = shader->GetUniformLocation("ReflectionMap"); - uniforms.sceneAmbient = shader->GetUniformLocation("SceneAmbient"); - uniforms.textureOverlay = shader->GetUniformLocation("TextureOverlay"); - - int type0Location = shader->GetUniformLocation("Lights[0].type"); - int type1Location = shader->GetUniformLocation("Lights[1].type"); - - if (type0Location > 0 && type1Location > 0) - { - uniforms.hasLightUniforms = true; - uniforms.lightOffset = type1Location - type0Location; - uniforms.lightUniforms.ubo = false; - uniforms.lightUniforms.locations.type = type0Location; - uniforms.lightUniforms.locations.color = shader->GetUniformLocation("Lights[0].color"); - uniforms.lightUniforms.locations.factors = shader->GetUniformLocation("Lights[0].factors"); - uniforms.lightUniforms.locations.lightViewProjMatrix = shader->GetUniformLocation("LightViewProjMatrix[0]"); - uniforms.lightUniforms.locations.parameters1 = shader->GetUniformLocation("Lights[0].parameters1"); - uniforms.lightUniforms.locations.parameters2 = shader->GetUniformLocation("Lights[0].parameters2"); - uniforms.lightUniforms.locations.parameters3 = shader->GetUniformLocation("Lights[0].parameters3"); - uniforms.lightUniforms.locations.shadowMapping = shader->GetUniformLocation("Lights[0].shadowMapping"); - } - else - uniforms.hasLightUniforms = false; - - it = m_shaderUniforms.emplace(shader, std::move(uniforms)).first; - } - - return &it->second; - } - - /*! - * \brief Handle the invalidation of a shader - * - * \param shader Shader being invalidated - */ - - void ForwardRenderTechnique::OnShaderInvalidated(const Shader* shader) const - { - m_shaderUniforms.erase(shader); - } - - /*! - * \brief Sends the uniforms for light - * - * \param shader Shader to send uniforms to - * \param uniforms Uniforms to send - * \param index Index of the light - * \param uniformOffset Offset for the uniform - * \param availableTextureUnit Unit texture available - */ - void ForwardRenderTechnique::SendLightUniforms(const Shader* shader, const LightUniforms& uniforms, unsigned int index, unsigned int lightIndex, unsigned int uniformOffset) const - { - if (lightIndex < m_lights.size()) - { - const LightIndex& lightInfo = m_lights[lightIndex]; - - shader->SendInteger(uniforms.locations.type + uniformOffset, lightInfo.type); //< Sends the light type - - switch (lightInfo.type) - { - case LightType_Directional: - { - const auto& light = m_renderQueue.directionalLights[lightInfo.index]; - - shader->SendColor(uniforms.locations.color + uniformOffset, light.color); - shader->SendVector(uniforms.locations.factors + uniformOffset, Vector2f(light.ambientFactor, light.diffuseFactor)); - shader->SendVector(uniforms.locations.parameters1 + uniformOffset, Vector4f(light.direction)); - - if (uniforms.locations.shadowMapping != -1) - shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr); - - if (light.shadowMap) - { - unsigned int textureUnit2D = Material::GetTextureUnit(static_cast(TextureMap_Shadow2D_1 + index)); - - Renderer::SetTexture(textureUnit2D, light.shadowMap); - Renderer::SetTextureSampler(textureUnit2D, s_shadowSampler); - - if (uniforms.locations.lightViewProjMatrix != -1) - shader->SendMatrix(uniforms.locations.lightViewProjMatrix + index, light.transformMatrix); - } - break; - } - - case LightType_Point: - { - const auto& light = m_renderQueue.pointLights[lightInfo.index]; - - shader->SendColor(uniforms.locations.color + uniformOffset, light.color); - shader->SendVector(uniforms.locations.factors + uniformOffset, Vector2f(light.ambientFactor, light.diffuseFactor)); - shader->SendVector(uniforms.locations.parameters1 + uniformOffset, Vector4f(light.position, light.attenuation)); - shader->SendVector(uniforms.locations.parameters2 + uniformOffset, Vector4f(0.f, 0.f, 0.f, light.invRadius)); - - if (uniforms.locations.shadowMapping != -1) - shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr); - - if (light.shadowMap) - { - unsigned int textureUnitCube = Material::GetTextureUnit(static_cast(TextureMap_ShadowCube_1 + index)); - - Renderer::SetTexture(textureUnitCube, light.shadowMap); - Renderer::SetTextureSampler(textureUnitCube, s_shadowSampler); - } - break; - } - - case LightType_Spot: - { - const auto& light = m_renderQueue.spotLights[lightInfo.index]; - - shader->SendColor(uniforms.locations.color + uniformOffset, light.color); - shader->SendVector(uniforms.locations.factors + uniformOffset, Vector2f(light.ambientFactor, light.diffuseFactor)); - shader->SendVector(uniforms.locations.parameters1 + uniformOffset, Vector4f(light.position, light.attenuation)); - shader->SendVector(uniforms.locations.parameters2 + uniformOffset, Vector4f(light.direction, light.invRadius)); - shader->SendVector(uniforms.locations.parameters3 + uniformOffset, Vector2f(light.innerAngleCosine, light.outerAngleCosine)); - - if (uniforms.locations.shadowMapping != -1) - shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr); - - if (light.shadowMap) - { - unsigned int textureUnit2D = Material::GetTextureUnit(static_cast(TextureMap_Shadow2D_1 + index)); - - Renderer::SetTexture(textureUnit2D, light.shadowMap); - Renderer::SetTextureSampler(textureUnit2D, s_shadowSampler); - - if (uniforms.locations.lightViewProjMatrix != -1) - shader->SendMatrix(uniforms.locations.lightViewProjMatrix + index, light.transformMatrix); - } - break; - } - } - } - else - { - if (uniforms.locations.type != -1) - shader->SendInteger(uniforms.locations.type + uniformOffset, -1); //< Disable the light in the shader - } - } - - IndexBuffer ForwardRenderTechnique::s_quadIndexBuffer; - TextureSampler ForwardRenderTechnique::s_reflectionSampler; - TextureSampler ForwardRenderTechnique::s_shadowSampler; - VertexBuffer ForwardRenderTechnique::s_quadVertexBuffer; - VertexDeclaration ForwardRenderTechnique::s_billboardInstanceDeclaration; - VertexDeclaration ForwardRenderTechnique::s_billboardVertexDeclaration; -} diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp deleted file mode 100644 index 7120d33cd..000000000 --- a/src/Nazara/Graphics/Graphics.cpp +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::Graphics - * \brief Graphics class that represents the module initializer of Graphics - */ - - /*! - * \brief Initializes the Graphics module - * \return true if initialization is successful - * - * \remark Produces a NazaraNotice - * \remark Produces a NazaraError if one submodule failed - */ - - bool Graphics::Initialize() - { - if (IsInitialized()) - { - s_moduleReferenceCounter++; - return true; // Already initialized - } - - // Initialisation of dependances - if (!Renderer::Initialize()) - { - NazaraError("Failed to initialize Renderer module"); - return false; - } - - s_moduleReferenceCounter++; - - // Initialisation of the module - CallOnExit onExit(Graphics::Uninitialize); - - // Materials - if (!MaterialPipeline::Initialize()) - { - NazaraError("Failed to initialize material pipelines"); - return false; - } - - if (!Material::Initialize()) - { - NazaraError("Failed to initialize materials"); - return false; - } - - // Renderables - if (!ParticleController::Initialize()) - { - NazaraError("Failed to initialize particle controllers"); - return false; - } - - if (!ParticleDeclaration::Initialize()) - { - NazaraError("Failed to initialize particle declarations"); - return false; - } - - if (!ParticleGenerator::Initialize()) - { - NazaraError("Failed to initialize particle generators"); - return false; - } - - if (!ParticleRenderer::Initialize()) - { - NazaraError("Failed to initialize particle renderers"); - return false; - } - - if (!SkinningManager::Initialize()) - { - NazaraError("Failed to initialize skinning manager"); - return false; - } - - if (!SkyboxBackground::Initialize()) - { - NazaraError("Failed to initialize skybox backgrounds"); - return false; - } - - if (!Sprite::Initialize()) - { - NazaraError("Failed to initialize sprites"); - return false; - } - - if (!TileMap::Initialize()) - { - NazaraError("Failed to initialize tilemaps"); - return false; - } - - // Generic loaders - Loaders::RegisterMesh(); - Loaders::RegisterTexture(); - - // Render techniques - if (!DepthRenderTechnique::Initialize()) - { - NazaraError("Failed to initialize Depth Rendering"); - return false; - } - - if (!ForwardRenderTechnique::Initialize()) - { - NazaraError("Failed to initialize Forward Rendering"); - return false; - } - - RenderTechniques::Register(RenderTechniques::ToString(RenderTechniqueType_BasicForward), 0, []() -> AbstractRenderTechnique* { return new ForwardRenderTechnique; }); - - if (DeferredRenderTechnique::IsSupported()) - { - if (DeferredRenderTechnique::Initialize()) - RenderTechniques::Register(RenderTechniques::ToString(RenderTechniqueType_DeferredShading), 20, []() -> AbstractRenderTechnique* { return new DeferredRenderTechnique; }); - else - { - NazaraWarning("Failed to initialize Deferred Rendering"); - } - } - - Font::SetDefaultAtlas(std::make_shared()); - - // Textures - std::array whitePixels = { { 255, 255, 255, 255, 255, 255 } }; - - Nz::TextureRef whiteTexture = Nz::Texture::New(); - whiteTexture->Create(ImageType_2D, PixelFormat_L8, 1, 1); - whiteTexture->Update(whitePixels.data()); - - TextureLibrary::Register("White2D", std::move(whiteTexture)); - - Nz::TextureRef whiteCubemap = Nz::Texture::New(); - whiteCubemap->Create(ImageType_Cubemap, PixelFormat_L8, 1, 1); - whiteCubemap->Update(whitePixels.data()); - - TextureLibrary::Register("WhiteCubemap", std::move(whiteCubemap)); - - onExit.Reset(); - - NazaraNotice("Initialized: Graphics module"); - return true; - } - - /*! - * \brief Checks whether the module is initialized - * \return true if module is initialized - */ - - bool Graphics::IsInitialized() - { - return s_moduleReferenceCounter != 0; - } - - /*! - * \brief Uninitializes the Graphics module - * - * \remark Produces a NazaraNotice - */ - - void Graphics::Uninitialize() - { - if (s_moduleReferenceCounter != 1) - { - // The module is still in use, or can not be uninitialized - if (s_moduleReferenceCounter > 1) - s_moduleReferenceCounter--; - - return; - } - - // Free of module - s_moduleReferenceCounter = 0; - - // Free of atlas if it is ours - std::shared_ptr defaultAtlas = Font::GetDefaultAtlas(); - if (defaultAtlas && defaultAtlas->GetStorage() == DataStorage_Hardware) - { - Font::SetDefaultAtlas(nullptr); - - // The default police can make live one hardware atlas after the free of a module (which could be problematic) - // So, if the default police use a hardware atlas, we stole it. - // I don't like this solution, but I don't have any better - if (!defaultAtlas.unique()) - { - // Still at least one police use the atlas - Font* defaultFont = Font::GetDefault(); - defaultFont->SetAtlas(nullptr); - - if (!defaultAtlas.unique()) - { - // Still not the only one to own it ? Then crap. - NazaraWarning("Default font atlas uses hardware storage and is still used"); - } - } - } - - defaultAtlas.reset(); - - // Textures - TextureLibrary::Unregister("White2D"); - TextureLibrary::Unregister("WhiteCubemap"); - - // Loaders - Loaders::UnregisterMesh(); - Loaders::UnregisterTexture(); - - // Renderables - ParticleRenderer::Uninitialize(); - ParticleGenerator::Uninitialize(); - ParticleDeclaration::Uninitialize(); - ParticleController::Uninitialize(); - SkyboxBackground::Uninitialize(); - Sprite::Uninitialize(); - TileMap::Uninitialize(); - - // Render techniques - DeferredRenderTechnique::Uninitialize(); - DepthRenderTechnique::Uninitialize(); - ForwardRenderTechnique::Uninitialize(); - SkinningManager::Uninitialize(); - - // Materials - Material::Uninitialize(); - MaterialPipeline::Uninitialize(); - - NazaraNotice("Uninitialized: Graphics module"); - - // Free of dependances - Renderer::Uninitialize(); - } - - unsigned int Graphics::s_moduleReferenceCounter = 0; -} diff --git a/src/Nazara/Graphics/GuillotineTextureAtlas.cpp b/src/Nazara/Graphics/GuillotineTextureAtlas.cpp deleted file mode 100644 index 83ac85be2..000000000 --- a/src/Nazara/Graphics/GuillotineTextureAtlas.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::GuillotineTextureAtlas - * \brief Graphics class that represents an atlas texture for guillotine - */ - - /*! - * \brief Gets the underlying data storage - * \return Value of the enumeration of the underlying data storage - */ - - UInt32 GuillotineTextureAtlas::GetStorage() const - { - return DataStorage_Hardware; - } - - /*! - * \brief Resizes the image - * \return Updated texture - * - * \param oldImage Old image to resize - * \param size New image size - * - * \remark Produces a NazaraError if resize failed - */ - - AbstractImage* GuillotineTextureAtlas::ResizeImage(AbstractImage* oldImage, const Vector2ui& size) const - { - std::unique_ptr newTexture(new Texture); - if (newTexture->Create(ImageType_2D, PixelFormat_A8, size.x, size.y, 1)) - { - if (oldImage) - { - Texture* oldTexture = static_cast(oldImage); - - // Copy of old data - ///TODO: Copy from texture to texture - Image image; - if (!oldTexture->Download(&image)) - { - NazaraError("Failed to download old texture"); - return nullptr; - } - - if (!newTexture->Update(&image, Rectui(0, 0, image.GetWidth(), image.GetHeight()))) - { - NazaraError("Failed to update texture"); - return nullptr; - } - } - - return newTexture.release(); - } - else - { - // If we are here, it is that the size is too big for the graphic card or we don't have enough - return nullptr; - } - } -} diff --git a/src/Nazara/Graphics/InstancedRenderable.cpp b/src/Nazara/Graphics/InstancedRenderable.cpp deleted file mode 100644 index 412c4809e..000000000 --- a/src/Nazara/Graphics/InstancedRenderable.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::InstancedRenderable - * \brief Graphics class that represents an instancer renderable - * - * \remark This class is abstract - */ - - /*! - * \brief Destructs the object and calls OnInstancedRenderableRelease - * - * \see OnInstancedRenderableRelease - */ - - InstancedRenderable::~InstancedRenderable() - { - OnInstancedRenderableRelease(this); - } - - /*! - * \brief Culls the instanced if not in the frustum - * \return true If instanced is in the frustum - * - * \param frustum Symbolizing the field of view - * \param transformMatrix Matrix transformation for our object - */ - - bool InstancedRenderable::Cull(const Frustumf& frustum, const InstanceData& instanceData) const - { - return frustum.Contains(instanceData.volume); - } - - /*! - * \brief Gets the bounding volume - * \return Bounding volume of the instanced - */ - - const BoundingVolumef& InstancedRenderable::GetBoundingVolume() const - { - EnsureBoundingVolumeUpdated(); - - return m_boundingVolume; - } - - /*! - * \brief Invalidates data for instanced - * - * \param instanceData Pointer to data of instances - * \param flags Flags for the instances - * - * \remark Produces a NazaraAssert if instanceData is invalid - */ - - void InstancedRenderable::InvalidateData(InstanceData* instanceData, UInt32 flags) const - { - NazaraAssert(instanceData, "Invalid instance data"); - - instanceData->flags |= flags; - } - - /*! - * \brief Updates the bounding volume - * - * \param instanceData Pointer to data of instances - * - * \remark Produces a NazaraAssert if instanceData is invalid - */ - - void InstancedRenderable::UpdateBoundingVolume(InstanceData* instanceData) const - { - NazaraAssert(instanceData, "Invalid instance data"); - NazaraUnused(instanceData); - - instanceData->volume.Update(instanceData->transformMatrix); - } - - /*! - * \brief Updates the instance data - * - * \param instanceData Pointer to data of instances - * - * \remark Produces a NazaraAssert if instanceData is invalid - */ - - void InstancedRenderable::UpdateData(InstanceData* instanceData) const - { - NazaraAssert(instanceData, "Invalid instance data"); - NazaraUnused(instanceData); - } - - InstancedRenderableLibrary::LibraryMap InstancedRenderable::s_library; -} diff --git a/src/Nazara/Graphics/Light.cpp b/src/Nazara/Graphics/Light.cpp deleted file mode 100644 index be356fa85..000000000 --- a/src/Nazara/Graphics/Light.cpp +++ /dev/null @@ -1,267 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -///TODO: Use of UBOs -///TODO: Scale ? - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::Light - * \brief Graphics class that represents a light - */ - - /*! - * \brief Constructs a Light object with a type - * - * \param type Type of the light - */ - - Light::Light(LightType type) : - m_type(type), - m_shadowMapFormat(PixelFormat_Depth16), - m_shadowMapSize(512, 512), - m_shadowCastingEnabled(false), - m_shadowMapUpdated(false) - { - SetAmbientFactor((type == LightType_Directional) ? 0.2f : 0.f); - SetAttenuation(0.9f); - SetColor(Color::White); - SetDiffuseFactor(1.f); - SetInnerAngle(15.f); - SetOuterAngle(45.f); - SetRadius(5.f); - } - - /*! - * \brief Adds this light to the render queue - * - * \param renderQueue Queue to be added - * \param transformMatrix Matrix transformation for this light - * - * \remark Produces a NazaraError if type is invalid - */ - - void Light::AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const - { - static Matrix4f biasMatrix(0.5f, 0.f, 0.f, 0.f, - 0.f, 0.5f, 0.f, 0.f, - 0.f, 0.f, 0.5f, 0.f, - 0.5f, 0.5f, 0.5f, 1.f); - - switch (m_type) - { - case LightType_Directional: - { - AbstractRenderQueue::DirectionalLight light; - light.ambientFactor = m_ambientFactor; - light.color = m_color; - light.diffuseFactor = m_diffuseFactor; - light.direction = transformMatrix.Transform(Vector3f::Forward(), 0.f); - light.shadowMap = m_shadowMap.Get(); - light.transformMatrix = Matrix4f::ViewMatrix(transformMatrix.GetRotation() * Vector3f::Forward() * 100.f, transformMatrix.GetRotation()) * Matrix4f::Ortho(0.f, 100.f, 100.f, 0.f, 1.f, 100.f) * biasMatrix; - - renderQueue->AddDirectionalLight(light); - break; - } - - case LightType_Point: - { - AbstractRenderQueue::PointLight light; - light.ambientFactor = m_ambientFactor; - light.attenuation = m_attenuation; - light.color = m_color; - light.diffuseFactor = m_diffuseFactor; - light.invRadius = m_invRadius; - light.position = transformMatrix.GetTranslation(); - light.radius = m_radius; - light.shadowMap = m_shadowMap.Get(); - - renderQueue->AddPointLight(light); - break; - } - - case LightType_Spot: - { - AbstractRenderQueue::SpotLight light; - light.ambientFactor = m_ambientFactor; - light.attenuation = m_attenuation; - light.color = m_color; - light.diffuseFactor = m_diffuseFactor; - light.direction = transformMatrix.Transform(Vector3f::Forward(), 0.f); - light.innerAngleCosine = m_innerAngleCosine; - light.invRadius = m_invRadius; - light.outerAngleCosine = m_outerAngleCosine; - light.outerAngleTangent = m_outerAngleTangent; - light.position = transformMatrix.GetTranslation(); - light.radius = m_radius; - light.shadowMap = m_shadowMap.Get(); - light.transformMatrix = Matrix4f::ViewMatrix(transformMatrix.GetTranslation(), transformMatrix.GetRotation()) * Matrix4f::Perspective(m_outerAngle*2.f, 1.f, 0.1f, m_radius) * biasMatrix; - - renderQueue->AddSpotLight(light); - break; - } - - default: - NazaraError("Invalid light type (0x" + String::Number(m_type, 16) + ')'); - break; - } - } - - /*! - * \brief Clones this light - * \return Pointer to newly allocated Light - */ - - Light* Light::Clone() const - { - return new Light(*this); - } - - /*! - * \brief Creates a default light - * \return Pointer to newly allocated light - */ - - Light* Light::Create() const - { - return new Light; - } - - /*! - * \brief Culls the light if not in the frustum - * \return true If light is in the frustum - * - * \param frustum Symbolizing the field of view - * \param transformMatrix Matrix transformation for our object - * - * \remark Produces a NazaraError if type is invalid - */ - - bool Light::Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const - { - switch (m_type) - { - case LightType_Directional: - return true; // Always visible - - case LightType_Point: - return frustum.Contains(Spheref(transformMatrix.GetTranslation(), m_radius)); // A sphere test is much faster (and precise) - - case LightType_Spot: - return frustum.Contains(m_boundingVolume); - } - - NazaraError("Invalid light type (0x" + String::Number(m_type, 16) + ')'); - return false; - } - - /*! - * \brief Updates the bounding volume by a matrix - * - * \param transformMatrix Matrix transformation for our bounding volume - * - * \remark Produces a NazaraError if type is invalid - */ - - void Light::UpdateBoundingVolume(const Matrix4f& transformMatrix) - { - switch (m_type) - { - case LightType_Directional: - break; // Nothing to do (bounding volume should be infinite) - - case LightType_Point: - m_boundingVolume.Update(transformMatrix.GetTranslation()); // The bounding volume only needs to be shifted - break; - - case LightType_Spot: - m_boundingVolume.Update(transformMatrix); - break; - - default: - NazaraError("Invalid light type (0x" + String::Number(m_type, 16) + ')'); - break; - } - } - - /* - * \brief Makes the bounding volume of this light - * - * \remark Produces a NazaraError if type is invalid - */ - - void Light::MakeBoundingVolume() const - { - switch (m_type) - { - case LightType_Directional: - m_boundingVolume.MakeInfinite(); - break; - - case LightType_Point: - { - Vector3f radius(m_radius * float(M_SQRT3)); - m_boundingVolume.Set(-radius, radius); - break; - } - - case LightType_Spot: - { - // We make a box center in the origin - Boxf box(Vector3f::Zero()); - - // We compute the other points - Vector3f base(Vector3f::Forward() * m_radius); - - // Now we need the radius of the projected circle depending on the distance - // Tangent = Opposite/Adjacent <=> Opposite = Adjacent * Tangent - float radius = m_radius * m_outerAngleTangent; - Vector3f lExtend = Vector3f::Left() * radius; - Vector3f uExtend = Vector3f::Up() * radius; - - // And we add the four extremities of our pyramid - box.ExtendTo(base + lExtend + uExtend); - box.ExtendTo(base + lExtend - uExtend); - box.ExtendTo(base - lExtend + uExtend); - box.ExtendTo(base - lExtend - uExtend); - - m_boundingVolume.Set(box); - break; - } - - default: - NazaraError("Invalid light type (0x" + String::Number(m_type, 16) + ')'); - break; - } - } - - /*! - * \brief Updates the shadow map - */ - - void Light::UpdateShadowMap() const - { - if (m_shadowCastingEnabled) - { - if (!m_shadowMap) - m_shadowMap = Texture::New(); - - m_shadowMap->Create((m_type == LightType_Point) ? ImageType_Cubemap : ImageType_2D, m_shadowMapFormat, m_shadowMapSize.x, m_shadowMapSize.y); - } - else - m_shadowMap.Reset(); - - m_shadowMapUpdated = true; - } -} diff --git a/src/Nazara/Graphics/Material.cpp b/src/Nazara/Graphics/Material.cpp deleted file mode 100644 index cdfd619fe..000000000 --- a/src/Nazara/Graphics/Material.cpp +++ /dev/null @@ -1,503 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::Material - * \brief Graphics class that represents a material - */ - - /*! - * \brief Checks whether the parameters for the material are correct - * \return true If parameters are valid - */ - bool MaterialParams::IsValid() const - { - if (!UberShaderLibrary::Has(shaderName)) - return false; - - return true; - } - - /*! - * \brief Applies shader to the material - * - * \param instance Pipeline instance to update - * \param textureUnit Unit for the texture GL_TEXTURE"i" - * \param lastUsedUnit Optional argument to get the last texture unit - */ - void Material::Apply(const MaterialPipeline::Instance& instance) const - { - const Shader* shader = instance.renderPipeline.GetInfo().shader; - - if (instance.uniforms[MaterialUniform_AlphaThreshold] != -1) - shader->SendFloat(instance.uniforms[MaterialUniform_AlphaThreshold], m_alphaThreshold); - - if (instance.uniforms[MaterialUniform_Ambient] != -1) - shader->SendColor(instance.uniforms[MaterialUniform_Ambient], m_ambientColor); - - if (instance.uniforms[MaterialUniform_Diffuse] != -1) - shader->SendColor(instance.uniforms[MaterialUniform_Diffuse], m_diffuseColor); - - if (instance.uniforms[MaterialUniform_Shininess] != -1) - shader->SendFloat(instance.uniforms[MaterialUniform_Shininess], m_shininess); - - if (instance.uniforms[MaterialUniform_Specular] != -1) - shader->SendColor(instance.uniforms[MaterialUniform_Specular], m_specularColor); - - if (m_alphaMap && instance.uniforms[MaterialUniform_AlphaMap] != -1) - { - unsigned int textureUnit = s_textureUnits[TextureMap_Alpha]; - - Renderer::SetTexture(textureUnit, m_alphaMap); - Renderer::SetTextureSampler(textureUnit, m_diffuseSampler); - } - - if (m_diffuseMap && instance.uniforms[MaterialUniform_DiffuseMap] != -1) - { - unsigned int textureUnit = s_textureUnits[TextureMap_Diffuse]; - - Renderer::SetTexture(textureUnit, m_diffuseMap); - Renderer::SetTextureSampler(textureUnit, m_diffuseSampler); - } - - if (m_emissiveMap && instance.uniforms[MaterialUniform_EmissiveMap] != -1) - { - unsigned int textureUnit = s_textureUnits[TextureMap_Emissive]; - - Renderer::SetTexture(textureUnit, m_emissiveMap); - Renderer::SetTextureSampler(textureUnit, m_diffuseSampler); - } - - if (m_heightMap && instance.uniforms[MaterialUniform_HeightMap] != -1) - { - unsigned int textureUnit = s_textureUnits[TextureMap_Height]; - - Renderer::SetTexture(textureUnit, m_heightMap); - Renderer::SetTextureSampler(textureUnit, m_diffuseSampler); - } - - if (m_normalMap && instance.uniforms[MaterialUniform_NormalMap] != -1) - { - unsigned int textureUnit = s_textureUnits[TextureMap_Normal]; - - Renderer::SetTexture(textureUnit, m_normalMap); - Renderer::SetTextureSampler(textureUnit, m_diffuseSampler); - } - - if (m_specularMap && instance.uniforms[MaterialUniform_SpecularMap] != -1) - { - unsigned int textureUnit = s_textureUnits[TextureMap_Specular]; - - Renderer::SetTexture(textureUnit, m_specularMap); - Renderer::SetTextureSampler(textureUnit, m_specularSampler); - } - } - - /*! - * \brief Builds the material from a parameter list - * - * \param matData Data information for the material - * \param matParams Additional parameters for the material - */ - void Material::BuildFromParameters(const ParameterList& matData, const MaterialParams& matParams) - { - Color color; - bool isEnabled; - double dValue; - long long iValue; - Nz::String path; - - ErrorFlags errFlags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled, true); - - if (matData.GetDoubleParameter(MaterialData::AlphaThreshold, &dValue)) - SetAlphaThreshold(float(dValue)); - - if (matData.GetBooleanParameter(MaterialData::AlphaTest, &isEnabled)) - EnableAlphaTest(isEnabled); - - if (matData.GetColorParameter(MaterialData::AmbientColor, &color)) - SetAmbientColor(color); - - if (matData.GetIntegerParameter(MaterialData::CullingSide, &iValue)) - SetFaceCulling(static_cast(iValue)); - - if (matData.GetIntegerParameter(MaterialData::DepthFunc, &iValue)) - SetDepthFunc(static_cast(iValue)); - - if (matData.GetBooleanParameter(MaterialData::DepthSorting, &isEnabled)) - EnableDepthSorting(isEnabled); - - if (matData.GetColorParameter(MaterialData::DiffuseColor, &color)) - SetDiffuseColor(color); - - if (matData.GetIntegerParameter(MaterialData::DstBlend, &iValue)) - SetDstBlend(static_cast(iValue)); - - if (matData.GetIntegerParameter(MaterialData::FaceFilling, &iValue)) - SetFaceFilling(static_cast(iValue)); - - if (matData.GetDoubleParameter(MaterialData::LineWidth, &dValue)) - SetLineWidth(float(dValue)); - - if (matData.GetDoubleParameter(MaterialData::PointSize, &dValue)) - SetPointSize(float(dValue)); - - if (matData.GetColorParameter(MaterialData::SpecularColor, &color)) - SetSpecularColor(color); - - if (matData.GetDoubleParameter(MaterialData::Shininess, &dValue)) - SetShininess(float(dValue)); - - if (matData.GetIntegerParameter(MaterialData::SrcBlend, &iValue)) - SetSrcBlend(static_cast(iValue)); - - // RendererParameter - if (matData.GetBooleanParameter(MaterialData::Blending, &isEnabled)) - EnableBlending(isEnabled); - - if (matData.GetBooleanParameter(MaterialData::ColorWrite, &isEnabled)) - EnableColorWrite(isEnabled); - - if (matData.GetBooleanParameter(MaterialData::DepthBuffer, &isEnabled)) - EnableDepthBuffer(isEnabled); - - if (matData.GetBooleanParameter(MaterialData::DepthWrite, &isEnabled)) - EnableDepthWrite(isEnabled); - - if (matData.GetBooleanParameter(MaterialData::FaceCulling, &isEnabled)) - EnableFaceCulling(isEnabled); - - if (matData.GetBooleanParameter(MaterialData::ScissorTest, &isEnabled)) - EnableScissorTest(isEnabled); - - if (matData.GetBooleanParameter(MaterialData::StencilTest, &isEnabled)) - EnableStencilTest(isEnabled); - - if (matData.GetBooleanParameter(MaterialData::VertexColor, &isEnabled)) - EnableVertexColor(isEnabled); - - // Samplers - if (matData.GetIntegerParameter(MaterialData::DiffuseAnisotropyLevel, &iValue)) - m_diffuseSampler.SetAnisotropyLevel(static_cast(iValue)); - - if (matData.GetIntegerParameter(MaterialData::DiffuseFilter, &iValue)) - m_diffuseSampler.SetFilterMode(static_cast(iValue)); - - if (matData.GetIntegerParameter(MaterialData::DiffuseWrap, &iValue)) - m_diffuseSampler.SetWrapMode(static_cast(iValue)); - - if (matData.GetIntegerParameter(MaterialData::SpecularAnisotropyLevel, &iValue)) - m_specularSampler.SetAnisotropyLevel(static_cast(iValue)); - - if (matData.GetIntegerParameter(MaterialData::SpecularFilter, &iValue)) - m_specularSampler.SetFilterMode(static_cast(iValue)); - - if (matData.GetIntegerParameter(MaterialData::SpecularWrap, &iValue)) - m_specularSampler.SetWrapMode(static_cast(iValue)); - - // Stencil - if (matData.GetIntegerParameter(MaterialData::StencilCompare, &iValue)) - m_pipelineInfo.stencilCompare.front = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::StencilFail, &iValue)) - m_pipelineInfo.stencilFail.front = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::StencilPass, &iValue)) - m_pipelineInfo.stencilPass.front = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::StencilZFail, &iValue)) - m_pipelineInfo.stencilDepthFail.front = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::StencilMask, &iValue)) - m_pipelineInfo.stencilWriteMask.front = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::StencilReference, &iValue)) - m_pipelineInfo.stencilReference.front = static_cast(iValue); - - // Stencil (back) - if (matData.GetIntegerParameter(MaterialData::BackFaceStencilCompare, &iValue)) - m_pipelineInfo.stencilCompare.back = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::BackFaceStencilFail, &iValue)) - m_pipelineInfo.stencilFail.back = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::BackFaceStencilPass, &iValue)) - m_pipelineInfo.stencilPass.back = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::BackFaceStencilZFail, &iValue)) - m_pipelineInfo.stencilDepthFail.back = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::BackFaceStencilMask, &iValue)) - m_pipelineInfo.stencilWriteMask.back = static_cast(iValue); - - if (matData.GetIntegerParameter(MaterialData::BackFaceStencilReference, &iValue)) - m_pipelineInfo.stencilReference.back = static_cast(iValue); - - InvalidatePipeline(); - - // Textures - if (matParams.loadAlphaMap && matData.GetStringParameter(MaterialData::AlphaTexturePath, &path)) - SetAlphaMap(path.ToStdString()); - - if (matParams.loadDiffuseMap && matData.GetStringParameter(MaterialData::DiffuseTexturePath, &path)) - SetDiffuseMap(path.ToStdString()); - - if (matParams.loadEmissiveMap && matData.GetStringParameter(MaterialData::EmissiveTexturePath, &path)) - SetEmissiveMap(path.ToStdString()); - - if (matParams.loadHeightMap && matData.GetStringParameter(MaterialData::HeightTexturePath, &path)) - SetHeightMap(path.ToStdString()); - - if (matParams.loadNormalMap && matData.GetStringParameter(MaterialData::NormalTexturePath, &path)) - SetNormalMap(path.ToStdString()); - - if (matParams.loadSpecularMap && matData.GetStringParameter(MaterialData::SpecularTexturePath, &path)) - SetSpecularMap(path.ToStdString()); - - SetShader(matParams.shaderName); - } - - /*! - * \brief Builds a ParameterList with material data - * - * \param matData Destination parameter list which will receive material data - */ - void Material::SaveToParameters(ParameterList* matData) - { - NazaraAssert(matData, "Invalid ParameterList"); - - matData->SetParameter(MaterialData::AlphaTest, IsAlphaTestEnabled()); - matData->SetParameter(MaterialData::AlphaThreshold, GetAlphaThreshold()); - matData->SetParameter(MaterialData::AmbientColor, GetAmbientColor()); - matData->SetParameter(MaterialData::CullingSide, static_cast(GetFaceCulling())); - matData->SetParameter(MaterialData::DepthFunc, static_cast(GetDepthFunc())); - matData->SetParameter(MaterialData::DepthSorting, IsDepthSortingEnabled()); - matData->SetParameter(MaterialData::DiffuseColor, GetDiffuseColor()); - matData->SetParameter(MaterialData::DstBlend, static_cast(GetDstBlend())); - matData->SetParameter(MaterialData::FaceFilling, static_cast(GetFaceFilling())); - matData->SetParameter(MaterialData::LineWidth, GetLineWidth()); - matData->SetParameter(MaterialData::PointSize, GetPointSize()); - matData->SetParameter(MaterialData::Shininess, GetShininess()); - matData->SetParameter(MaterialData::SpecularColor, GetSpecularColor()); - matData->SetParameter(MaterialData::SrcBlend, static_cast(GetSrcBlend())); - - // RendererParameter - matData->SetParameter(MaterialData::Blending, IsBlendingEnabled()); - matData->SetParameter(MaterialData::ColorWrite, IsColorWriteEnabled()); - matData->SetParameter(MaterialData::DepthBuffer, IsDepthBufferEnabled()); - matData->SetParameter(MaterialData::DepthWrite, IsDepthWriteEnabled()); - matData->SetParameter(MaterialData::FaceCulling, IsFaceCullingEnabled()); - matData->SetParameter(MaterialData::ScissorTest, IsScissorTestEnabled()); - matData->SetParameter(MaterialData::StencilTest, IsStencilTestEnabled()); - matData->SetParameter(MaterialData::VertexColor, HasVertexColor()); - - // Samplers - matData->SetParameter(MaterialData::DiffuseAnisotropyLevel, static_cast(GetDiffuseSampler().GetAnisotropicLevel())); - matData->SetParameter(MaterialData::DiffuseFilter, static_cast(GetDiffuseSampler().GetFilterMode())); - matData->SetParameter(MaterialData::DiffuseWrap, static_cast(GetDiffuseSampler().GetWrapMode())); - - matData->SetParameter(MaterialData::SpecularAnisotropyLevel, static_cast(GetSpecularSampler().GetAnisotropicLevel())); - matData->SetParameter(MaterialData::SpecularFilter, static_cast(GetSpecularSampler().GetFilterMode())); - matData->SetParameter(MaterialData::SpecularWrap, static_cast(GetSpecularSampler().GetWrapMode())); - - // Stencil - matData->SetParameter(MaterialData::StencilCompare, static_cast(GetPipelineInfo().stencilCompare.front)); - matData->SetParameter(MaterialData::StencilFail, static_cast(GetPipelineInfo().stencilFail.front)); - matData->SetParameter(MaterialData::StencilPass, static_cast(GetPipelineInfo().stencilPass.front)); - matData->SetParameter(MaterialData::StencilZFail, static_cast(GetPipelineInfo().stencilDepthFail.front)); - matData->SetParameter(MaterialData::StencilMask, static_cast(GetPipelineInfo().stencilWriteMask.front)); - matData->SetParameter(MaterialData::StencilReference, static_cast(GetPipelineInfo().stencilReference.front)); - - // Stencil (back) - matData->SetParameter(MaterialData::BackFaceStencilCompare, static_cast(GetPipelineInfo().stencilCompare.back)); - matData->SetParameter(MaterialData::BackFaceStencilFail, static_cast(GetPipelineInfo().stencilFail.back)); - matData->SetParameter(MaterialData::BackFaceStencilPass, static_cast(GetPipelineInfo().stencilPass.back)); - matData->SetParameter(MaterialData::BackFaceStencilZFail, static_cast(GetPipelineInfo().stencilDepthFail.back)); - matData->SetParameter(MaterialData::BackFaceStencilMask, static_cast(GetPipelineInfo().stencilWriteMask.back)); - matData->SetParameter(MaterialData::BackFaceStencilReference, static_cast(GetPipelineInfo().stencilReference.back)); - - // Textures - if (HasAlphaMap()) - { - const std::filesystem::path& path = GetAlphaMap()->GetFilePath(); - if (!path.empty()) - matData->SetParameter(MaterialData::AlphaTexturePath, path.generic_u8string()); - } - - if (HasDiffuseMap()) - { - const std::filesystem::path& path = GetDiffuseMap()->GetFilePath(); - if (!path.empty()) - matData->SetParameter(MaterialData::DiffuseTexturePath, path.generic_u8string()); - } - - if (HasEmissiveMap()) - { - const std::filesystem::path& path = GetEmissiveMap()->GetFilePath(); - if (!path.empty()) - matData->SetParameter(MaterialData::EmissiveTexturePath, path.generic_u8string()); - } - - if (HasHeightMap()) - { - const std::filesystem::path& path = GetHeightMap()->GetFilePath(); - if (!path.empty()) - matData->SetParameter(MaterialData::HeightTexturePath, path.generic_u8string()); - } - - if (HasNormalMap()) - { - const std::filesystem::path& path = GetNormalMap()->GetFilePath(); - if (!path.empty()) - matData->SetParameter(MaterialData::NormalTexturePath, path.generic_u8string()); - } - - if (HasSpecularMap()) - { - const std::filesystem::path& path = GetSpecularMap()->GetFilePath(); - if (!path.empty()) - matData->SetParameter(MaterialData::SpecularTexturePath, path.generic_u8string()); - } - } - - /*! - * \brief Resets the material, cleans everything - * - * \remark Invalidates the pipeline - */ - void Material::Reset() - { - OnMaterialReset(this); - - m_alphaMap.Reset(); - m_depthMaterial.Reset(); - m_diffuseMap.Reset(); - m_emissiveMap.Reset(); - m_heightMap.Reset(); - m_normalMap.Reset(); - m_specularMap.Reset(); - - m_alphaThreshold = 0.2f; - m_ambientColor = Color(128, 128, 128); - m_diffuseColor = Color::White; - m_diffuseSampler = TextureSampler(); - m_reflectionMode = ReflectionMode_Skybox; - m_shadowCastingEnabled = true; - m_shininess = 50.f; - m_specularColor = Color::White; - m_specularSampler = TextureSampler(); - m_pipelineInfo = MaterialPipelineInfo(); - m_pipelineInfo.depthBuffer = true; - m_pipelineInfo.faceCulling = true; - m_reflectionSize = 256; - - SetShader("Basic"); - - InvalidatePipeline(); - } - - /*! - * \brief Copies the other material - * - * \param material Material to copy into this - */ - void Material::Copy(const Material& material) - { - // Copy of base states - m_alphaThreshold = material.m_alphaThreshold; - m_ambientColor = material.m_ambientColor; - m_diffuseColor = material.m_diffuseColor; - m_diffuseSampler = material.m_diffuseSampler; - m_pipelineInfo = material.m_pipelineInfo; - m_shininess = material.m_shininess; - m_shadowCastingEnabled = material.m_shadowCastingEnabled; - m_specularColor = material.m_specularColor; - m_specularSampler = material.m_specularSampler; - - // Copy of reference to the textures - m_alphaMap = material.m_alphaMap; - m_depthMaterial = material.m_depthMaterial; - m_diffuseMap = material.m_diffuseMap; - m_emissiveMap = material.m_emissiveMap; - m_heightMap = material.m_heightMap; - m_normalMap = material.m_normalMap; - m_specularMap = material.m_specularMap; - - SetReflectionMode(material.GetReflectionMode()); - - InvalidatePipeline(); - } - - /*! - * \brief Initializes the material librairies - * \return true If successful - * - * \remark Produces a NazaraError if the material library failed to be initialized - */ - bool Material::Initialize() - { - if (!MaterialLibrary::Initialize()) - { - NazaraError("Failed to initialise library"); - return false; - } - - if (!MaterialManager::Initialize()) - { - NazaraError("Failed to initialise manager"); - return false; - } - - s_defaultMaterial = New(); - s_defaultMaterial->EnableFaceCulling(false); - s_defaultMaterial->SetFaceFilling(FaceFilling_Line); - MaterialLibrary::Register("Default", s_defaultMaterial); - - unsigned int textureUnit = 0; - - s_textureUnits[TextureMap_Diffuse] = textureUnit++; - s_textureUnits[TextureMap_Alpha] = textureUnit++; - s_textureUnits[TextureMap_Specular] = textureUnit++; - s_textureUnits[TextureMap_Normal] = textureUnit++; - s_textureUnits[TextureMap_Emissive] = textureUnit++; - s_textureUnits[TextureMap_Overlay] = textureUnit++; - s_textureUnits[TextureMap_ReflectionCube] = textureUnit++; - s_textureUnits[TextureMap_Height] = textureUnit++; - s_textureUnits[TextureMap_Shadow2D_1] = textureUnit++; - s_textureUnits[TextureMap_ShadowCube_1] = textureUnit++; - s_textureUnits[TextureMap_Shadow2D_2] = textureUnit++; - s_textureUnits[TextureMap_ShadowCube_2] = textureUnit++; - s_textureUnits[TextureMap_Shadow2D_3] = textureUnit++; - s_textureUnits[TextureMap_ShadowCube_3] = textureUnit++; - - return true; - } - - /*! - * \brief Uninitializes the material librairies - */ - void Material::Uninitialize() - { - s_defaultMaterial.Reset(); - - MaterialManager::Uninitialize(); - MaterialLibrary::Uninitialize(); - } - - std::array Material::s_textureUnits; - MaterialLibrary::LibraryMap Material::s_library; - MaterialLoader::LoaderList Material::s_loaders; - MaterialManager::ManagerMap Material::s_managerMap; - MaterialManager::ManagerParams Material::s_managerParameters; - MaterialRef Material::s_defaultMaterial = nullptr; -} diff --git a/src/Nazara/Graphics/MaterialPipeline.cpp b/src/Nazara/Graphics/MaterialPipeline.cpp deleted file mode 100644 index a3f84ecdf..000000000 --- a/src/Nazara/Graphics/MaterialPipeline.cpp +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - const UInt8 r_basicFragmentShader[] = { - #include - }; - - const UInt8 r_basicVertexShader[] = { - #include - }; - - const UInt8 r_phongLightingFragmentShader[] = { - #include - }; - - const UInt8 r_phongLightingVertexShader[] = { - #include - }; - - void OverrideShader(const std::filesystem::path& path, String* source) - { - ErrorFlags errFlags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled); - - File shaderFile(path, Nz::OpenMode_ReadOnly | Nz::OpenMode_Text); - if (shaderFile.IsOpen()) - { - StringStream shaderSource; - - while (!shaderFile.EndOfFile()) - { - shaderSource << shaderFile.ReadLine(); - shaderSource << '\n'; - } - - *source = shaderSource; - - NazaraNotice(path.generic_u8string() + " will be used to override built-in shader"); - } - } - } - - /*! - * \ingroup graphics - * \class Nz::MaterialPipeline - * - * \brief Graphics class used to contains all rendering states that are not allowed to change individually on rendering devices - */ - - /*! - * \brief Returns a reference to a MaterialPipeline built with MaterialPipelineInfo - * - * This function is using a cache, calling it multiples times with the same MaterialPipelineInfo will returns references to a single MaterialPipeline - * - * \param pipelineInfo Pipeline informations used to build/retrieve a MaterialPipeline object - */ - MaterialPipelineRef MaterialPipeline::GetPipeline(const MaterialPipelineInfo& pipelineInfo) - { - auto it = s_pipelineCache.find(pipelineInfo); - if (it == s_pipelineCache.end()) - it = s_pipelineCache.insert(it, PipelineCache::value_type(pipelineInfo, New(pipelineInfo))); - - return it->second; - } - - void MaterialPipeline::GenerateRenderPipeline(UInt32 flags) const - { - NazaraAssert(m_pipelineInfo.uberShader, "Material pipeline has no uber shader"); - - ParameterList list; - list.SetParameter("ALPHA_MAPPING", m_pipelineInfo.hasAlphaMap); - list.SetParameter("ALPHA_TEST", m_pipelineInfo.alphaTest); - list.SetParameter("COMPUTE_TBNMATRIX", m_pipelineInfo.hasNormalMap || m_pipelineInfo.hasHeightMap); - list.SetParameter("DIFFUSE_MAPPING", m_pipelineInfo.hasDiffuseMap); - list.SetParameter("EMISSIVE_MAPPING", m_pipelineInfo.hasEmissiveMap); - list.SetParameter("NORMAL_MAPPING", m_pipelineInfo.hasNormalMap); - list.SetParameter("PARALLAX_MAPPING", m_pipelineInfo.hasHeightMap); - list.SetParameter("REFLECTION_MAPPING", m_pipelineInfo.reflectionMapping); - list.SetParameter("SHADOW_MAPPING", m_pipelineInfo.shadowReceive); - list.SetParameter("SPECULAR_MAPPING", m_pipelineInfo.hasSpecularMap); - list.SetParameter("TEXTURE_MAPPING", m_pipelineInfo.hasAlphaMap || m_pipelineInfo.hasDiffuseMap || m_pipelineInfo.hasEmissiveMap || - m_pipelineInfo.hasNormalMap || m_pipelineInfo.hasHeightMap || m_pipelineInfo.hasSpecularMap || - m_pipelineInfo.reflectionMapping || flags & ShaderFlags_TextureOverlay); - list.SetParameter("TRANSFORM", true); - - list.SetParameter("FLAG_BILLBOARD", static_cast((flags & ShaderFlags_Billboard) != 0)); - list.SetParameter("FLAG_DEFERRED", static_cast((flags & ShaderFlags_Deferred) != 0)); - list.SetParameter("FLAG_INSTANCING", static_cast((flags & ShaderFlags_Instancing) != 0)); - list.SetParameter("FLAG_TEXTUREOVERLAY", static_cast((flags & ShaderFlags_TextureOverlay) != 0)); - list.SetParameter("FLAG_VERTEXCOLOR", m_pipelineInfo.hasVertexColor || static_cast((flags & ShaderFlags_VertexColor) != 0)); - - Instance& instance = m_instances[flags]; - instance.uberInstance = m_pipelineInfo.uberShader->Get(list); - - RenderPipelineInfo renderPipelineInfo; - static_cast(renderPipelineInfo).operator=(m_pipelineInfo); // Not my proudest line - - renderPipelineInfo.shader = instance.uberInstance->GetShader(); - - instance.renderPipeline.Create(renderPipelineInfo); - - #define CacheUniform(name) instance.uniforms[MaterialUniform_##name] = renderPipelineInfo.shader->GetUniformLocation("Material" #name) - - CacheUniform(AlphaMap); - CacheUniform(AlphaThreshold); - CacheUniform(Ambient); - CacheUniform(Diffuse); - CacheUniform(DiffuseMap); - CacheUniform(EmissiveMap); - CacheUniform(HeightMap); - CacheUniform(NormalMap); - CacheUniform(Shininess); - CacheUniform(Specular); - CacheUniform(SpecularMap); - - #undef CacheUniform - - // Send texture units (those never changes) - renderPipelineInfo.shader->SendInteger(instance.uniforms[MaterialUniform_AlphaMap], Material::GetTextureUnit(TextureMap_Alpha)); - renderPipelineInfo.shader->SendInteger(instance.uniforms[MaterialUniform_DiffuseMap], Material::GetTextureUnit(TextureMap_Diffuse)); - renderPipelineInfo.shader->SendInteger(instance.uniforms[MaterialUniform_EmissiveMap], Material::GetTextureUnit(TextureMap_Emissive)); - renderPipelineInfo.shader->SendInteger(instance.uniforms[MaterialUniform_HeightMap], Material::GetTextureUnit(TextureMap_Height)); - renderPipelineInfo.shader->SendInteger(instance.uniforms[MaterialUniform_NormalMap], Material::GetTextureUnit(TextureMap_Normal)); - renderPipelineInfo.shader->SendInteger(instance.uniforms[MaterialUniform_SpecularMap], Material::GetTextureUnit(TextureMap_Specular)); - - renderPipelineInfo.shader->SendInteger(renderPipelineInfo.shader->GetUniformLocation("ReflectionMap"), Material::GetTextureUnit(TextureMap_ReflectionCube)); - renderPipelineInfo.shader->SendInteger(renderPipelineInfo.shader->GetUniformLocation("TextureOverlay"), Material::GetTextureUnit(TextureMap_Overlay)); - - renderPipelineInfo.shader->SendInteger(renderPipelineInfo.shader->GetUniformLocation("DirectionalSpotLightShadowMap[0]"), Material::GetTextureUnit(TextureMap_Shadow2D_1)); - renderPipelineInfo.shader->SendInteger(renderPipelineInfo.shader->GetUniformLocation("DirectionalSpotLightShadowMap[1]"), Material::GetTextureUnit(TextureMap_Shadow2D_2)); - renderPipelineInfo.shader->SendInteger(renderPipelineInfo.shader->GetUniformLocation("DirectionalSpotLightShadowMap[2]"), Material::GetTextureUnit(TextureMap_Shadow2D_3)); - - renderPipelineInfo.shader->SendInteger(renderPipelineInfo.shader->GetUniformLocation("PointLightShadowMap[0]"), Material::GetTextureUnit(TextureMap_ShadowCube_1)); - renderPipelineInfo.shader->SendInteger(renderPipelineInfo.shader->GetUniformLocation("PointLightShadowMap[1]"), Material::GetTextureUnit(TextureMap_ShadowCube_2)); - renderPipelineInfo.shader->SendInteger(renderPipelineInfo.shader->GetUniformLocation("PointLightShadowMap[2]"), Material::GetTextureUnit(TextureMap_ShadowCube_3)); - } - - bool MaterialPipeline::Initialize() - { - // Basic shader - { - UberShaderPreprocessorRef uberShader = UberShaderPreprocessor::New(); - - String fragmentShader(reinterpret_cast(r_basicFragmentShader), sizeof(r_basicFragmentShader)); - String vertexShader(reinterpret_cast(r_basicVertexShader), sizeof(r_basicVertexShader)); - - #ifdef NAZARA_DEBUG - OverrideShader("Shaders/Basic/core.frag", &fragmentShader); - OverrideShader("Shaders/Basic/core.vert", &vertexShader); - #endif - - uberShader->SetShader(ShaderStageType_Fragment, fragmentShader, "FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING TEXTURE_MAPPING"); - uberShader->SetShader(ShaderStageType_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_INSTANCING FLAG_VERTEXCOLOR TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH"); - - UberShaderLibrary::Register("Basic", uberShader); - } - - // PhongLighting shader - { - UberShaderPreprocessorRef uberShader = UberShaderPreprocessor::New(); - - String fragmentShader(reinterpret_cast(r_phongLightingFragmentShader), sizeof(r_phongLightingFragmentShader)); - String vertexShader(reinterpret_cast(r_phongLightingVertexShader), sizeof(r_phongLightingVertexShader)); - - #ifdef NAZARA_DEBUG - OverrideShader("Shaders/PhongLighting/core.frag", &fragmentShader); - OverrideShader("Shaders/PhongLighting/core.vert", &vertexShader); - #endif - - uberShader->SetShader(ShaderStageType_Fragment, fragmentShader, "FLAG_DEFERRED FLAG_TEXTUREOVERLAY ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING EMISSIVE_MAPPING NORMAL_MAPPING PARALLAX_MAPPING REFLECTION_MAPPING SHADOW_MAPPING SPECULAR_MAPPING"); - uberShader->SetShader(ShaderStageType_Vertex, vertexShader, "FLAG_BILLBOARD FLAG_DEFERRED FLAG_INSTANCING FLAG_VERTEXCOLOR COMPUTE_TBNMATRIX PARALLAX_MAPPING SHADOW_MAPPING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH"); - - UberShaderLibrary::Register("PhongLighting", uberShader); - } - - // Once the base shaders are registered, we can now set some default materials - MaterialPipelineInfo pipelineInfo; - pipelineInfo.uberShader = UberShaderLibrary::Get("Basic"); - - // Basic 2D - No depth write/face culling with scissoring - pipelineInfo.depthWrite = false; - pipelineInfo.faceCulling = false; - pipelineInfo.scissorTest = true; - - MaterialPipelineLibrary::Register("Basic2D", GetPipeline(pipelineInfo)); - - // Translucent 2D - Alpha blending with no depth write/face culling and scissoring - pipelineInfo.blending = true; - pipelineInfo.depthWrite = false; - pipelineInfo.faceCulling = false; - pipelineInfo.depthSorting = false; - pipelineInfo.scissorTest = true; - pipelineInfo.dstBlend = BlendFunc_InvSrcAlpha; - pipelineInfo.srcBlend = BlendFunc_SrcAlpha; - - MaterialPipelineLibrary::Register("Translucent2D", GetPipeline(pipelineInfo)); - - // Translucent 3D - Alpha blending with depth buffer and no depth write/face culling - pipelineInfo.blending = true; - pipelineInfo.depthBuffer = true; - pipelineInfo.depthWrite = false; - pipelineInfo.faceCulling = false; - pipelineInfo.depthSorting = true; - pipelineInfo.scissorTest = false; - pipelineInfo.dstBlend = BlendFunc_InvSrcAlpha; - pipelineInfo.srcBlend = BlendFunc_SrcAlpha; - - MaterialPipelineLibrary::Register("Translucent3D", GetPipeline(pipelineInfo)); - - return true; - } - - void MaterialPipeline::Uninitialize() - { - s_pipelineCache.clear(); - UberShaderLibrary::Unregister("PhongLighting"); - UberShaderLibrary::Unregister("Basic"); - MaterialPipelineLibrary::Uninitialize(); - } - - MaterialPipelineLibrary::LibraryMap MaterialPipeline::s_library; - MaterialPipeline::PipelineCache MaterialPipeline::s_pipelineCache; -} diff --git a/src/Nazara/Graphics/Model.cpp b/src/Nazara/Graphics/Model.cpp deleted file mode 100644 index 1a2bc0814..000000000 --- a/src/Nazara/Graphics/Model.cpp +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::Model - * \brief Graphics class that represents a model - */ - - /*! - * \brief Constructs a ModelParameters object by default - */ - - ModelParameters::ModelParameters() - { - material.shaderName = "PhongLighting"; - } - - /*! - * \brief Checks whether the parameters for the model are correct - * \return true If parameters are valid - */ - - bool ModelParameters::IsValid() const - { - if (loadMaterials && !material.IsValid()) - return false; - - return mesh.IsValid(); - } - - /*! - * \brief Destructs the object and cleans resources - */ - Model::~Model() = default; - - /*! - * \brief Adds this model to the render queue - * - * \param renderQueue Queue to be added - * \param instanceData Data used for this instance - */ - void Model::AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const - { - unsigned int submeshCount = m_mesh->GetSubMeshCount(); - for (unsigned int i = 0; i < submeshCount; ++i) - { - const StaticMesh* mesh = static_cast(m_mesh->GetSubMesh(i)); - const MaterialRef& material = GetMaterial(mesh->GetMaterialIndex()); - - MeshData meshData; - meshData.indexBuffer = mesh->GetIndexBuffer(); - meshData.primitiveMode = mesh->GetPrimitiveMode(); - meshData.vertexBuffer = mesh->GetVertexBuffer(); - - renderQueue->AddMesh(instanceData.renderOrder, material, meshData, mesh->GetAABB(), instanceData.transformMatrix, scissorRect); - } - } - - /*! - * \brief Clones this model - */ - std::unique_ptr Model::Clone() const - { - return std::make_unique(*this); - } - - /*! - * \brief Gets the material of the named submesh - * \return Pointer to the current material - * - * \param subMeshName Name of the subMesh - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE if there is no mesh - * \remark Produces a NazaraError if there is no subMesh with that name - * \remark Produces a NazaraError if material is invalid - */ - const MaterialRef& Model::GetMaterial(const std::string& subMeshName) const - { - NazaraAssert(m_mesh, "Model has no mesh"); - - SubMesh* subMesh = m_mesh->GetSubMesh(subMeshName); - if (!subMesh) - { - NazaraError("Mesh has no submesh \"" + subMeshName + '"'); - - static MaterialRef Invalid; - return Invalid; - } - - return GetMaterial(subMesh->GetMaterialIndex()); - } - - /*! - * \brief Gets the material by index of the named submesh - * \return Pointer to the current material - * - * \param skinIndex Index of the skin - * \param subMeshName Name of the subMesh - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if skinIndex is invalid - * \remark Produces a NazaraError if there is no subMesh with that name - * \remark Produces a NazaraError if material index is invalid - */ - const MaterialRef& Model::GetMaterial(std::size_t skinIndex, const std::string& subMeshName) const - { - NazaraAssert(m_mesh, "Model has no mesh"); - - SubMesh* subMesh = m_mesh->GetSubMesh(subMeshName); - if (!subMesh) - { - NazaraError("Mesh has no submesh \"" + subMeshName + '"'); - - static MaterialRef Invalid; - return Invalid; - } - - return GetMaterial(subMesh->GetMaterialIndex()); - } - - /*! - * \brief Gets the mesh - * \return Current mesh - */ - - Mesh* Model::GetMesh() const - { - return m_mesh; - } - - /*! - * \brief Checks whether the model is animated - * \return false - */ - - bool Model::IsAnimated() const - { - return false; - } - - /*! - * \brief Sets the material of the named submesh - * \return true If successful - * - * \param subMeshName Name of the subMesh - * \param material Pointer to the material - * - * \remark Produces a NazaraError if there is no subMesh with that name - * \remark Produces a NazaraError if material index is invalid - */ - - bool Model::SetMaterial(const std::string& subMeshName, MaterialRef material) - { - SubMesh* subMesh = m_mesh->GetSubMesh(subMeshName); - if (!subMesh) - { - NazaraError("Mesh has no submesh \"" + subMeshName + '"'); - return false; - } - - SetMaterial(subMesh->GetMaterialIndex(), std::move(material)); - return true; - } - - /*! - * \brief Sets the material by index of the named submesh - * \return true If successful - * - * \param skinIndex Index of the skin - * \param subMeshName Name of the subMesh - * \param material Pointer to the material - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if skinIndex is invalid - * \remark Produces a NazaraError if there is no subMesh with that name - * \remark Produces a NazaraError if material index is invalid - */ - bool Model::SetMaterial(std::size_t skinIndex, const std::string& subMeshName, MaterialRef material) - { - SubMesh* subMesh = m_mesh->GetSubMesh(subMeshName); - if (!subMesh) - { - NazaraError("Mesh has no submesh \"" + subMeshName + '"'); - return false; - } - - SetMaterial(skinIndex, subMesh->GetMaterialIndex(), std::move(material)); - return true; - } - - /*! - * \brief Sets the mesh - * - * \param pointer to the mesh - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if mesh is invalid - */ - - void Model::SetMesh(Mesh* mesh) - { - #if NAZARA_GRAPHICS_SAFE - if (mesh && !mesh->IsValid()) - { - NazaraError("Invalid mesh"); - return; - } - #endif - - m_mesh = mesh; - - if (m_mesh) - { - ResetMaterials(mesh->GetMaterialCount()); - m_meshAABBInvalidationSlot.Connect(m_mesh->OnMeshInvalidateAABB, [this](const Nz::Mesh*) { InvalidateBoundingVolume(); }); - } - else - { - ResetMaterials(0); - m_meshAABBInvalidationSlot.Disconnect(); - } - - InvalidateBoundingVolume(); - } - - /*! - * \brief Loads the model from file - * \return true if loading is successful - * - * \param filePath Path to the file - * \param params Parameters for the model - */ - ModelRef Model::LoadFromFile(const std::filesystem::path& filePath, const ModelParameters& params) - { - return ModelLoader::LoadFromFile(filePath, params); - } - - /*! - * \brief Loads the model from memory - * \return true if loading is successful - * - * \param data Raw memory - * \param size Size of the memory - * \param params Parameters for the model - */ - ModelRef Model::LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params) - { - return ModelLoader::LoadFromMemory(data, size, params); - } - - /*! - * \brief Loads the model from stream - * \return true if loading is successful - * - * \param stream Stream to the model - * \param params Parameters for the model - */ - ModelRef Model::LoadFromStream(Stream& stream, const ModelParameters& params) - { - return ModelLoader::LoadFromStream(stream, params); - } - - /* - * \brief Makes the bounding volume of this billboard - */ - - void Model::MakeBoundingVolume() const - { - if (m_mesh) - m_boundingVolume.Set(m_mesh->GetAABB()); - else - m_boundingVolume.MakeNull(); - } - - ModelLibrary::LibraryMap Model::s_library; - ModelLoader::LoaderList Model::s_loaders; - ModelManager::ManagerMap Model::s_managerMap; - ModelManager::ManagerParams Model::s_managerParameters; - ModelSaver::SaverList Model::s_savers; -} diff --git a/src/Nazara/Graphics/ParticleController.cpp b/src/Nazara/Graphics/ParticleController.cpp deleted file mode 100644 index a760314cf..000000000 --- a/src/Nazara/Graphics/ParticleController.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleController - * \brief Graphics class which controls a flow of particles - * - * \remark This class is abstract - */ - - /*! - * \brief Constructs a ParticleController object by assignation - * - * \param controller ParticleController to copy into this - */ - - ParticleController::ParticleController(const ParticleController& controller) : - RefCounted() - { - NazaraUnused(controller); - } - - /*! - * \brief Destructs the object and calls OnParticleControllerRelease - * - * \see OnParticleControllerRelease - */ - - ParticleController::~ParticleController() - { - OnParticleControllerRelease(this); - } - - /*! - * \brief Initializes the particle controller librairies - * \return true If successful - * - * \remark Produces a NazaraError if the particle controller library failed to be initialized - */ - - bool ParticleController::Initialize() - { - if (!ParticleControllerLibrary::Initialize()) - { - NazaraError("Failed to initialise library"); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the particle controller librairies - */ - - void ParticleController::Uninitialize() - { - ParticleControllerLibrary::Uninitialize(); - } - - ParticleControllerLibrary::LibraryMap ParticleController::s_library; -} diff --git a/src/Nazara/Graphics/ParticleDeclaration.cpp b/src/Nazara/Graphics/ParticleDeclaration.cpp deleted file mode 100644 index 99fdf8dd7..000000000 --- a/src/Nazara/Graphics/ParticleDeclaration.cpp +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleDeclaration - * \brief Graphics class that represents the declaration of the particle, works like an ECS - */ - - /*! - * \brief Constructs a ParticleDeclaration object by default - */ - - ParticleDeclaration::ParticleDeclaration() : - m_stride(0) - { - } - - /*! - * \brief Constructs a ParticleDeclaration object by assignation - * - * \param declaration ParticleDeclaration to copy into this - */ - - ParticleDeclaration::ParticleDeclaration(const ParticleDeclaration& declaration) : - RefCounted(), - m_components(declaration.m_components), - m_stride(declaration.m_stride) - { - } - - /*! - * \brief Destructs the object and calls OnParticleDeclarationRelease - * - * \see OnParticleDeclarationRelease - */ - - ParticleDeclaration::~ParticleDeclaration() - { - OnParticleDeclarationRelease(this); - } - - /*! - * \brief Disables a component - * - * \param component Component to disable in the declaration - * - * \remark Produces a NazaraError with NAZARA_DEBUG defined if enumeration is invalid - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if enumeration is equal to ParticleComponent_Unused - */ - - void ParticleDeclaration::DisableComponent(ParticleComponent component) - { - #ifdef NAZARA_DEBUG - if (component > ParticleComponent_Max) - { - NazaraError("Vertex component out of enum"); - return; - } - #endif - - #if NAZARA_GRAPHICS_SAFE - if (component == ParticleComponent_Unused) - { - NazaraError("Cannot disable \"unused\" component"); - return; - } - #endif - - Component& vertexComponent = m_components[component]; - if (vertexComponent.enabled) - { - vertexComponent.enabled = false; - m_stride -= Utility::ComponentStride[vertexComponent.type]; - } - } - - /*! - * \brief Enables a component - * - * \param component Component to enable in the declaration - * \param type Type of this component - * \param offset Offset in the declaration - * - * \remark Produces a NazaraError with NAZARA_DEBUG defined if enumeration is invalid - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if type is not supported - */ - - void ParticleDeclaration::EnableComponent(ParticleComponent component, ComponentType type, std::size_t offset) - { - #ifdef NAZARA_DEBUG - if (component > ParticleComponent_Max) - { - NazaraError("Vertex component out of enum"); - return; - } - #endif - - #if NAZARA_GRAPHICS_SAFE - if (!IsTypeSupported(type)) - { - NazaraError("Component type 0x" + String::Number(type, 16) + " is not supported by particle declarations"); - return; - } - #endif - - if (component != ParticleComponent_Unused) - { - Component& particleComponent = m_components[component]; - if (particleComponent.enabled) - m_stride -= Utility::ComponentStride[particleComponent.type]; - else - particleComponent.enabled = true; - - particleComponent.offset = offset; - particleComponent.type = type; - } - - m_stride += Utility::ComponentStride[type]; - } - - /*! - * \brief Gets a component - * - * \param component Component in the declaration - * \param enabled Optional argument to get if this component is enabled - * \param type Optional argument to get if the type of the component - * \param offset Optional argument to get if the offset in the declaration - * - * \remark Produces a NazaraError with NAZARA_DEBUG defined if enumeration is invalid - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if enumeration is equal to ParticleComponent_Unused - */ - - void ParticleDeclaration::GetComponent(ParticleComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const - { - #ifdef NAZARA_DEBUG - if (component > ParticleComponent_Max) - { - NazaraError("Particle component out of enum"); - return; - } - #endif - - #if NAZARA_GRAPHICS_SAFE - if (component == ParticleComponent_Unused) - { - NazaraError("Cannot get \"unused\" component"); - return; - } - #endif - - const Component& particleComponent = m_components[component]; - - if (enabled) - *enabled = particleComponent.enabled; - - if (type) - *type = particleComponent.type; - - if (offset) - *offset = particleComponent.offset; - } - - /*! - * \brief Gets the stride of the declaration - * \return Stride of the declaration - */ - - std::size_t ParticleDeclaration::GetStride() const - { - return m_stride; - } - - /*! - * \brief Sets the stride of the declaration - * - * \param stride Stride of the declaration - */ - - void ParticleDeclaration::SetStride(unsigned int stride) - { - m_stride = stride; - } - - /*! - * \brief Sets the current particle declaration with the content of the other one - * \return A reference to this - * - * \param declaration The other ParticleDeclaration - */ - - ParticleDeclaration& ParticleDeclaration::operator=(const ParticleDeclaration& declaration) - { - m_components = declaration.m_components; - m_stride = declaration.m_stride; - - return *this; - } - - /*! - * \brief Gets the particle declaration based on the layout - * \return Pointer to the declaration - * - * \param layout Layout of the particle declaration - * - * \remark Produces a NazaraError with NAZARA_DEBUG if enumeration is invalid - */ - - ParticleDeclaration* ParticleDeclaration::Get(ParticleLayout layout) - { - NazaraAssert(layout <= ParticleLayout_Max, "Particle layout out of enum"); - - return &s_declarations[layout]; - } - - /*! - * \brief Checks whether the type is supported - * \return true If it is the case - * - * \param type Type of the component - * - * \remark Produces a NazaraError if enumeration is invalid - */ - - bool ParticleDeclaration::IsTypeSupported(ComponentType type) - { - switch (type) - { - case ComponentType_Color: - case ComponentType_Double1: - case ComponentType_Double2: - case ComponentType_Double3: - case ComponentType_Double4: - case ComponentType_Float1: - case ComponentType_Float2: - case ComponentType_Float3: - case ComponentType_Float4: - case ComponentType_Int1: - case ComponentType_Int2: - case ComponentType_Int3: - case ComponentType_Int4: - case ComponentType_Quaternion: - return true; - } - - NazaraError("Component type not handled (0x" + String::Number(type, 16) + ')'); - return false; - } - - /*! - * \brief Initializes the particle declaration librairies - * \return true If successful - * - * \remark Produces a NazaraError if the particle declaration library failed to be initialized - * \remark Produces a NazaraAssert if memory layout of declaration does not match the corresponding structure - */ - - bool ParticleDeclaration::Initialize() - { - if (!ParticleDeclarationLibrary::Initialize()) - { - NazaraError("Failed to initialise library"); - return false; - } - - try - { - ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowException); - - // Layout : Type - ParticleDeclaration* declaration; - - // ParticleLayout_Billboard : ParticleStruct_Billboard - declaration = &s_declarations[ParticleLayout_Billboard]; - declaration->EnableComponent(ParticleComponent_Color, ComponentType_Color, NazaraOffsetOf(ParticleStruct_Billboard, color)); - declaration->EnableComponent(ParticleComponent_Life, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Billboard, life)); - declaration->EnableComponent(ParticleComponent_Normal, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Billboard, normal)); - declaration->EnableComponent(ParticleComponent_Position, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Billboard, position)); - declaration->EnableComponent(ParticleComponent_Rotation, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Billboard, rotation)); - declaration->EnableComponent(ParticleComponent_Size, ComponentType_Float2, NazaraOffsetOf(ParticleStruct_Billboard, size)); - declaration->EnableComponent(ParticleComponent_Velocity, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Billboard, velocity)); - - NazaraAssert(declaration->GetStride() == sizeof(ParticleStruct_Billboard), "Invalid stride for declaration ParticleLayout_Billboard"); - - // ParticleLayout_Model : ParticleStruct_Model - declaration = &s_declarations[ParticleLayout_Model]; - declaration->EnableComponent(ParticleComponent_Life, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Model, life)); - declaration->EnableComponent(ParticleComponent_Position, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Model, position)); - declaration->EnableComponent(ParticleComponent_Rotation, ComponentType_Quaternion, NazaraOffsetOf(ParticleStruct_Model, rotation)); - declaration->EnableComponent(ParticleComponent_Velocity, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Model, velocity)); - - NazaraAssert(declaration->GetStride() == sizeof(ParticleStruct_Model), "Invalid stride for declaration ParticleLayout_Model"); - - // ParticleLayout_Sprite : ParticleStruct_Sprite - declaration = &s_declarations[ParticleLayout_Sprite]; - declaration->EnableComponent(ParticleComponent_Color, ComponentType_Color, NazaraOffsetOf(ParticleStruct_Sprite, color)); - declaration->EnableComponent(ParticleComponent_Life, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Sprite, life)); - declaration->EnableComponent(ParticleComponent_Position, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Sprite, position)); - declaration->EnableComponent(ParticleComponent_Rotation, ComponentType_Float1, NazaraOffsetOf(ParticleStruct_Sprite, rotation)); - declaration->EnableComponent(ParticleComponent_Velocity, ComponentType_Float3, NazaraOffsetOf(ParticleStruct_Sprite, velocity)); - - NazaraAssert(declaration->GetStride() == sizeof(ParticleStruct_Sprite), "Invalid stride for declaration ParticleLayout_Sprite"); - } - catch (const std::exception& e) - { - NazaraError("Failed to initialize particle declarations: " + String(e.what())); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the particle declaration librairies - */ - - void ParticleDeclaration::Uninitialize() - { - ParticleDeclarationLibrary::Uninitialize(); - } - - std::array ParticleDeclaration::s_declarations; - ParticleDeclarationLibrary::LibraryMap ParticleDeclaration::s_library; -} diff --git a/src/Nazara/Graphics/ParticleEmitter.cpp b/src/Nazara/Graphics/ParticleEmitter.cpp deleted file mode 100644 index dd9b5fc28..000000000 --- a/src/Nazara/Graphics/ParticleEmitter.cpp +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleEmitter - * \brief Graphics class that represents an emitter of particles - */ - - /*! - * \brief Constructs a ParticleEmitter object by default - */ - - ParticleEmitter::ParticleEmitter() : - m_lagCompensationEnabled(false), - m_emissionAccumulator(0.f), - m_emissionRate(0.f), - m_emissionCount(1) - { - } - - ParticleEmitter::ParticleEmitter(const ParticleEmitter& emitter) : - m_lagCompensationEnabled(emitter.m_lagCompensationEnabled), - m_emissionAccumulator(0.f), - m_emissionRate(emitter.m_emissionRate), - m_emissionCount(emitter.m_emissionCount) - { - } - - ParticleEmitter::ParticleEmitter(ParticleEmitter&& emitter) : - m_lagCompensationEnabled(emitter.m_lagCompensationEnabled), - m_emissionAccumulator(0.f), - m_emissionRate(emitter.m_emissionRate), - m_emissionCount(emitter.m_emissionCount) - { - OnParticleEmitterMove(&emitter, this); - } - - ParticleEmitter::~ParticleEmitter() - { - OnParticleEmitterRelease(this); - } - - /*! - * \brief Emits particles according to the delta time between the previous frame - * - * \param system Particle system to work on - * \param elapsedTime Delta time between the previous frame - */ - - void ParticleEmitter::Emit(ParticleGroup& system, float elapsedTime) const - { - if (m_emissionRate > 0.f) - { - // We accumulate the real part (to avoid that a high emission rate prevents particles to form) - m_emissionAccumulator += elapsedTime * m_emissionRate; - - float emissionCount = std::floor(m_emissionAccumulator); // The number of emissions in this update - m_emissionAccumulator -= emissionCount; // We get rid off the integer part - - if (emissionCount >= 1.f) - { - // We compute the maximum number of particles which can be emitted - std::size_t emissionCountInt = static_cast(emissionCount); - std::size_t maxParticleCount = emissionCountInt * m_emissionCount; - - // We get the number of particles that we are able to create (depending on the free space) - std::size_t particleCount = std::min(maxParticleCount, system.GetMaxParticleCount() - system.GetParticleCount()); - if (particleCount == 0) - return; - - // And we emit our particles - void* particles = system.GenerateParticles(particleCount); - ParticleMapper mapper(particles, system.GetDeclaration()); - - SetupParticles(mapper, particleCount); - - if (m_lagCompensationEnabled) - { - // We will now apply our controllers - float invEmissionRate = 1.f / m_emissionRate; - for (unsigned int i = 1; i <= emissionCountInt; ++i) - system.ApplyControllers(mapper, std::min(m_emissionCount * i, particleCount), invEmissionRate); - } - } - } - } - - /*! - * \brief Enables the lag compensation - * - * \param enable Should lag compensation be enabled - */ - - void ParticleEmitter::EnableLagCompensation(bool enable) - { - m_lagCompensationEnabled = enable; - } - - /*! - * \brief Gets the emission count - * \return Current emission count - */ - - std::size_t ParticleEmitter::GetEmissionCount() const - { - return m_emissionCount; - } - - /*! - * \brief Gets the emission rate - * \return Current emission rate - */ - - float ParticleEmitter::GetEmissionRate() const - { - return m_emissionRate; - } - - /*! - * \brief Checks whether the lag compensation is enabled - * \return true If it is the case - */ - - bool ParticleEmitter::IsLagCompensationEnabled() const - { - return m_lagCompensationEnabled; - } - - /*! - * \brief Sets the emission count - * - * \param count Emission count - */ - - void ParticleEmitter::SetEmissionCount(std::size_t count) - { - m_emissionCount = count; - } - - /*! - * \brief Sets the emission rate - * - * \param rate Emission rate - */ - - void ParticleEmitter::SetEmissionRate(float rate) - { - m_emissionRate = rate; - } - - ParticleEmitter& ParticleEmitter::operator=(ParticleEmitter && emitter) - { - m_emissionCount = emitter.m_emissionCount; - m_emissionRate = emitter.m_emissionRate; - m_lagCompensationEnabled = emitter.m_lagCompensationEnabled; - - OnParticleEmitterMove(&emitter, this); - return *this; - } -} diff --git a/src/Nazara/Graphics/ParticleFunctionController.cpp b/src/Nazara/Graphics/ParticleFunctionController.cpp deleted file mode 100644 index 270f329e0..000000000 --- a/src/Nazara/Graphics/ParticleFunctionController.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleFunctionController - * \brief Helper class used to provide a function as a particle controller without going in the process of making a new class - */ - - /*! - * \brief Calls the controller function - * - * \param group Particle group responsible of the particles - * \param mapper Particle mapper, allowing access to the particle data - * \param startId The first ID of the particle to update (inclusive) - * \param endId The last ID of the particle to update (inclusive) - * \param elapsedTime Elapsed time in seconds since the last update - */ - void ParticleFunctionController::Apply(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) - { - m_controller(group, mapper, startId, endId, elapsedTime); - } -} diff --git a/src/Nazara/Graphics/ParticleFunctionGenerator.cpp b/src/Nazara/Graphics/ParticleFunctionGenerator.cpp deleted file mode 100644 index 65c46d60a..000000000 --- a/src/Nazara/Graphics/ParticleFunctionGenerator.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleFunctionGenerator - * \brief Helper class used to provide a function as a particle generator without going in the process of making a new class - */ - - /*! - * \brief Calls the generator function - * - * \param group Particle group responsible of the particles - * \param mapper Particle mapper, allowing access to the particle data - * \param startId The first ID of the particle to update (inclusive) - * \param endId The last ID of the particle to update (inclusive) - */ - void ParticleFunctionGenerator::Generate(ParticleGroup& group, ParticleMapper& mapper, unsigned int startId, unsigned int endId) - { - m_generator(group, mapper, startId, endId); - } -} diff --git a/src/Nazara/Graphics/ParticleFunctionRenderer.cpp b/src/Nazara/Graphics/ParticleFunctionRenderer.cpp deleted file mode 100644 index b395df916..000000000 --- a/src/Nazara/Graphics/ParticleFunctionRenderer.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleFunctionRenderer - * \brief Helper class used to provide a function as a particle renderer without going in the process of making a new class - */ - - /*! - * \brief Calls the renderer function - * - * \param group Particle group responsible of the particles - * \param mapper Particle mapper, allowing constant access to the particle data - * \param startId The first ID of the particle to update (inclusive) - * \param endId The last ID of the particle to update (inclusive) - * \param renderQueue The concerned render queue that will receive drawable informations - */ - void ParticleFunctionRenderer::Render(const ParticleGroup& group, const ParticleMapper& mapper, unsigned int startId, unsigned int endId, AbstractRenderQueue* renderQueue) - { - m_renderer(group, mapper, startId, endId, renderQueue); - } -} diff --git a/src/Nazara/Graphics/ParticleGenerator.cpp b/src/Nazara/Graphics/ParticleGenerator.cpp deleted file mode 100644 index 295f56105..000000000 --- a/src/Nazara/Graphics/ParticleGenerator.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleGenerator - * \brief Graphics class which generates particles - * - * \remark This class is abstract - */ - - /*! - * \brief Constructs a ParticleGenerator object by assignation - * - * \param generator ParticleGenerator to copy into this - */ - - ParticleGenerator::ParticleGenerator(const ParticleGenerator& generator) : - RefCounted() - { - NazaraUnused(generator); - } - - /*! - * \brief Destructs the object and calls OnParticleGeneratorRelease - * - * \see OnParticleGeneratorRelease - */ - - ParticleGenerator::~ParticleGenerator() - { - OnParticleGeneratorRelease(this); - } - - /*! - * \brief Initializes the particle generator librairies - * \return true If successful - * - * \remark Produces a NazaraError if the particle generator library failed to be initialized - */ - - bool ParticleGenerator::Initialize() - { - if (!ParticleGeneratorLibrary::Initialize()) - { - NazaraError("Failed to initialise library"); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the particle generator librairies - */ - - void ParticleGenerator::Uninitialize() - { - ParticleGeneratorLibrary::Uninitialize(); - } - - ParticleGeneratorLibrary::LibraryMap ParticleGenerator::s_library; -} diff --git a/src/Nazara/Graphics/ParticleGroup.cpp b/src/Nazara/Graphics/ParticleGroup.cpp deleted file mode 100644 index d2df6f201..000000000 --- a/src/Nazara/Graphics/ParticleGroup.cpp +++ /dev/null @@ -1,492 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleSystem - * \brief Graphics class that represents the system to handle particles - */ - - /*! - * \brief Constructs a ParticleSystem object with a maximal number of particles and a layout - * - * \param maxParticleCount Maximum number of particles to generate - * \param layout Enumeration for the layout of data information for the particles - */ - - ParticleGroup::ParticleGroup(unsigned int maxParticleCount, ParticleLayout layout) : - ParticleGroup(maxParticleCount, ParticleDeclaration::Get(layout)) - { - } - - /*! - * \brief Constructs a ParticleSystem object with a maximal number of particles and a particle declaration - * - * \param maxParticleCount Maximum number of particles to generate - * \param declaration Data information for the particles - */ - - ParticleGroup::ParticleGroup(unsigned int maxParticleCount, ParticleDeclarationConstRef declaration) : - m_maxParticleCount(maxParticleCount), - m_particleCount(0), - m_declaration(std::move(declaration)), - m_processing(false) - { - // In case of error, the constructor can only throw an exception - ErrorFlags flags(ErrorFlag_ThrowException, true); - - m_particleSize = m_declaration->GetStride(); // The size of each particle - - ResizeBuffer(); - } - - /*! - * \brief Constructs a ParticleSystem object by assignation - * - * \param system ParticleSystem to copy into this - */ - - ParticleGroup::ParticleGroup(const ParticleGroup& system) : - Renderable(system), - m_maxParticleCount(system.m_maxParticleCount), - m_particleCount(system.m_particleCount), - m_particleSize(system.m_particleSize), - m_controllers(system.m_controllers), - m_generators(system.m_generators), - m_declaration(system.m_declaration), - m_renderer(system.m_renderer), - m_processing(false) - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - - ResizeBuffer(); - - // We only copy alive particles - std::memcpy(m_buffer.data(), system.m_buffer.data(), system.m_particleCount*m_particleSize); - } - - ParticleGroup::~ParticleGroup() - { - OnParticleGroupRelease(this); - } - - /*! - * \brief Adds a controller to the particles - * - * \param controller Controller for the particles - * - * \remark Produces a NazaraAssert if controller is invalid - */ - - void ParticleGroup::AddController(ParticleControllerRef controller) - { - NazaraAssert(controller, "Invalid particle controller"); - - m_controllers.emplace_back(std::move(controller)); - } - - /*! - * \brief Adds an emitter to the particles - * - * \param emitter Emitter for the particles - * - * \remark Produces a NazaraAssert if emitter is invalid - */ - - void ParticleGroup::AddEmitter(ParticleEmitter* emitter) - { - NazaraAssert(emitter, "Invalid particle emitter"); - - EmitterEntry entry; - entry.emitter = emitter; - entry.moveSlot.Connect(emitter->OnParticleEmitterMove, this, &ParticleGroup::OnEmitterMove); - entry.releaseSlot.Connect(emitter->OnParticleEmitterRelease, this, &ParticleGroup::OnEmitterRelease); - - m_emitters.emplace_back(std::move(entry)); - } - - /*! - * \brief Adds a generator to the particles - * - * \param generator Generator for the particles - * - * \remark Produces a NazaraAssert if generator is invalid - */ - - void ParticleGroup::AddGenerator(ParticleGeneratorRef generator) - { - NazaraAssert(generator, "Invalid particle generator"); - - m_generators.emplace_back(std::move(generator)); - } - - /*! - * \brief Adds the particle system to the rendering queue - * - * \param renderQueue Queue to be added - * \param transformMatrix Transformation matrix for the system - * - * \remark Produces a NazaraAssert if inner renderer is invalid - * \remark Produces a NazaraAssert if renderQueue is invalid - */ - - void ParticleGroup::AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& /*transformMatrix*/) const - { - NazaraAssert(m_renderer, "Invalid particle renderer"); - NazaraAssert(renderQueue, "Invalid renderqueue"); - - if (m_particleCount > 0) - { - ParticleMapper mapper(m_buffer.data(), m_declaration); - m_renderer->Render(*this, mapper, 0, m_particleCount - 1, renderQueue); - } - } - - /*! - * \brief Applies the controllers - * - * \param mapper Mapper containing layout information of each particle - * \param particleCount Number of particles - * \param elapsedTime Delta time between the previous frame - */ - void ParticleGroup::ApplyControllers(ParticleMapper& mapper, unsigned int particleCount, float elapsedTime) - { - m_processing = true; - - // To avoid a lock in case of exception - CallOnExit onExit([this]() - { - m_processing = false; - }); - - for (ParticleController* controller : m_controllers) - controller->Apply(*this, mapper, 0, particleCount - 1, elapsedTime); - - onExit.CallAndReset(); - - // We only kill now the dead particles during the update - if (m_dyingParticles.size() < m_particleCount) - { - // We kill them in reverse order, std::set sorting them via std::greater - // The reason is simple, as the death of a particle means moving the last particle in the buffer, - // without this solution, certain particles could avoid death - for (unsigned int index : m_dyingParticles) - KillParticle(index); - } - else - KillParticles(); // Every particles are dead, this is way faster - - m_dyingParticles.clear(); - } - - /*! - * \brief Creates one particle - * \return Pointer to the particle memory buffer - */ - - void* ParticleGroup::CreateParticle() - { - return CreateParticles(1); - } - - /*! - * \brief Creates multiple particles - * \return Pointer to the first particle memory buffer - */ - - void* ParticleGroup::CreateParticles(unsigned int count) - { - if (count == 0) - return nullptr; - - if (m_particleCount + count > m_maxParticleCount) - return nullptr; - - std::size_t particlesIndex = m_particleCount; - m_particleCount += count; - - return &m_buffer[particlesIndex * m_particleSize]; - } - - /*! - * \brief Generates one particle - * \return Pointer to the particle memory buffer - */ - - void* ParticleGroup::GenerateParticle() - { - return GenerateParticles(1); - } - - /*! - * \brief Generates multiple particles - * \return Pointer to the first particle memory buffer - */ - - void* ParticleGroup::GenerateParticles(unsigned int count) - { - void* ptr = CreateParticles(count); - if (!ptr) - return nullptr; - - ParticleMapper mapper(ptr, m_declaration); - for (ParticleGenerator* generator : m_generators) - generator->Generate(*this, mapper, 0, count - 1); - - return ptr; - } - - /*! - * \brief Gets the particle declaration - * \return Particle declaration - */ - - const ParticleDeclarationConstRef& ParticleGroup::GetDeclaration() const - { - return m_declaration; - } - - /*! - * \brief Gets the maximum number of particles - * \return Current maximum number - */ - - std::size_t ParticleGroup::GetMaxParticleCount() const - { - return m_maxParticleCount; - } - - /*! - * \brief Gets the number of particles - * \return Current number - */ - - std::size_t ParticleGroup::GetParticleCount() const - { - return m_particleCount; - } - - /*! - * \brief Gets the size of particles - * \return Current size - */ - - std::size_t ParticleGroup::GetParticleSize() const - { - return m_particleSize; - } - - /*! - * \brief Kills one particle - * - * \param index Index of the particle - */ - - void ParticleGroup::KillParticle(std::size_t index) - { - ///FIXME: Verify the index - - if (m_processing) - { - // The buffer is being modified, we can not reduce its size, we put the particle in the waiting list - m_dyingParticles.insert(index); - return; - } - - // We move the last alive particle to the place of this one - if (--m_particleCount > 0) - std::memcpy(&m_buffer[index * m_particleSize], &m_buffer[m_particleCount * m_particleSize], m_particleSize); - } - - /*! - * \brief Kills every particles - */ - - void ParticleGroup::KillParticles() - { - m_particleCount = 0; - } - - /*! - * \brief Removes a controller to the particles - * - * \param controller Controller for the particles to remove - */ - - void ParticleGroup::RemoveController(ParticleController* controller) - { - auto it = std::find(m_controllers.begin(), m_controllers.end(), controller); - if (it != m_controllers.end()) - m_controllers.erase(it); - } - - /*! - * \brief Removes an emitter to the particles - * - * \param emitter Emitter for the particles to remove - */ - - void ParticleGroup::RemoveEmitter(ParticleEmitter* emitter) - { - for (auto it = m_emitters.begin(); it != m_emitters.end(); ++it) - { - if (it->emitter == emitter) - { - m_emitters.erase(it); - break; - } - } - } - - /*! - * \brief Removes a generator to the particles - * - * \param generator Generator for the particles to remove - */ - - void ParticleGroup::RemoveGenerator(ParticleGenerator* generator) - { - auto it = std::find(m_generators.begin(), m_generators.end(), generator); - if (it != m_generators.end()) - m_generators.erase(it); - } - - /*! - * \brief Sets the renderer of the particles - * - * \param renderer Renderer for the particles - */ - - void ParticleGroup::SetRenderer(ParticleRenderer* renderer) - { - m_renderer = renderer; - } - - /*! - * \brief Updates the system - * - * \param elapsedTime Delta time between the previous frame - */ - - void ParticleGroup::Update(float elapsedTime) - { - // Emission - for (const EmitterEntry& entry : m_emitters) - entry.emitter->Emit(*this, elapsedTime); - - // Update - if (m_particleCount > 0) - { - ///TODO: Update using threads - ParticleMapper mapper(m_buffer.data(), m_declaration); - ApplyControllers(mapper, m_particleCount, elapsedTime); - } - } - - /*! - * \brief Updates the bounding volume by a matrix - * - * \param transformMatrix Matrix transformation for our bounding volume - */ - - void ParticleGroup::UpdateBoundingVolume(const Matrix4f& /*transformMatrix*/) - { - // Nothing to do here (our bounding volume is global) - } - - /*! - * \brief Sets the current particle system with the content of the other one - * \return A reference to this - * - * \param system The other ParticleSystem - */ - - ParticleGroup& ParticleGroup::operator=(const ParticleGroup& system) - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - - Renderable::operator=(system); - - m_controllers = system.m_controllers; - m_declaration = system.m_declaration; - m_generators = system.m_generators; - m_maxParticleCount = system.m_maxParticleCount; - m_particleCount = system.m_particleCount; - m_particleSize = system.m_particleSize; - m_renderer = system.m_renderer; - - // The copy can not (or should not) happen during the update, there is no use to copy - m_dyingParticles.clear(); - m_processing = false; - - m_buffer.clear(); // To avoid a copy due to resize() which will be pointless - ResizeBuffer(); - - // We only copy alive particles - std::memcpy(m_buffer.data(), system.m_buffer.data(), system.m_particleCount * m_particleSize); - - return *this; - } - - /*! - * \brief Makes the bounding volume of this text - */ - - void ParticleGroup::MakeBoundingVolume() const - { - ///TODO: Compute the AABB (taking into account the size of particles) - m_boundingVolume.MakeInfinite(); - } - - void ParticleGroup::OnEmitterMove(ParticleEmitter* oldEmitter, ParticleEmitter* newEmitter) - { - for (EmitterEntry& entry : m_emitters) - { - if (entry.emitter == oldEmitter) - entry.emitter = newEmitter; - } - } - - void ParticleGroup::OnEmitterRelease(const ParticleEmitter* emitter) - { - for (auto it = m_emitters.begin(); it != m_emitters.end();) - { - if (it->emitter == emitter) - it = m_emitters.erase(it); - else - ++it; - } - } - - /*! - * \brief Resizes the internal buffer - * - * \remark Produces a NazaraError if resize did not work - */ - - void ParticleGroup::ResizeBuffer() - { - // Just to have a better description of our problem in case of error - try - { - m_buffer.resize(m_maxParticleCount*m_particleSize); - } - catch (const std::exception& e) - { - StringStream stream; - stream << "Failed to allocate particle buffer (" << e.what() << ") for " << m_maxParticleCount << " particles of size " << m_particleSize; - - NazaraError(stream.ToString()); - } - } -} diff --git a/src/Nazara/Graphics/ParticleMapper.cpp b/src/Nazara/Graphics/ParticleMapper.cpp deleted file mode 100644 index a70043c39..000000000 --- a/src/Nazara/Graphics/ParticleMapper.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleMapper - * \brief Graphics class that represents the mapping between the internal buffer and the particle declaration - */ - - /*! - * \brief Constructs a ParticleMapper object with a raw buffer and a particle declaration - * - * \param buffer Raw buffer to store particles data - * \param declaration Declaration of the particle - */ - - ParticleMapper::ParticleMapper(void* buffer, const ParticleDeclaration* declaration) : - m_declaration(declaration), - m_ptr(static_cast(buffer)) - { - } - - ParticleMapper::~ParticleMapper() = default; - -} diff --git a/src/Nazara/Graphics/ParticleRenderer.cpp b/src/Nazara/Graphics/ParticleRenderer.cpp deleted file mode 100644 index cc06c87ce..000000000 --- a/src/Nazara/Graphics/ParticleRenderer.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::ParticleRenderer - * \brief Graphics class that represents the rendering of the particle - */ - - /*! - * \brief Constructs a ParticleRenderer object by assignation - * - * \param renderer ParticleRenderer to copy into this - */ - - ParticleRenderer::ParticleRenderer(const ParticleRenderer& renderer) : - RefCounted() - { - NazaraUnused(renderer); - } - - /*! - * \brief Destructs the object and calls OnParticleRendererRelease - * - * \see OnParticleRendererRelease - */ - - ParticleRenderer::~ParticleRenderer() - { - OnParticleRendererRelease(this); - } - - /*! - * \brief Initializes the particle renderer librairies - * \return true If successful - * - * \remark Produces a NazaraError if the particle renderer library failed to be initialized - */ - - bool ParticleRenderer::Initialize() - { - if (!ParticleRendererLibrary::Initialize()) - { - NazaraError("Failed to initialise library"); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the particle renderer librairies - */ - - void ParticleRenderer::Uninitialize() - { - ParticleRendererLibrary::Uninitialize(); - } - - ParticleRendererLibrary::LibraryMap ParticleRenderer::s_library; -} diff --git a/src/Nazara/Graphics/RenderQueue.cpp b/src/Nazara/Graphics/RenderQueue.cpp deleted file mode 100644 index c94f999da..000000000 --- a/src/Nazara/Graphics/RenderQueue.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - void RenderQueueInternal::Sort() - { - std::sort(m_orderedRenderQueue.begin(), m_orderedRenderQueue.end(), [](const RenderDataPair& lhs, const RenderDataPair& rhs) - { - return lhs.first < rhs.first; - }); - } -} diff --git a/src/Nazara/Graphics/RenderTechniques.cpp b/src/Nazara/Graphics/RenderTechniques.cpp deleted file mode 100644 index 06a3db15d..000000000 --- a/src/Nazara/Graphics/RenderTechniques.cpp +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - const char* techniquesName[] = - { - "Advanced Forward", - "Basic Forward", - "Deferred Shading", - "Depth Pass", - "Light Pre-Pass", - "User" - }; - - static_assert(sizeof(techniquesName) / sizeof(const char*) == RenderTechniqueType_Max + 1, "Render technique type name array is incomplete"); - - struct RenderTechnique - { - RenderTechniques::RenderTechniqueFactory factory; - int ranking; - }; - - std::unordered_map s_renderTechniques; - } - - /*! - * \ingroup graphics - * \class Nz::RenderTechniques - * \brief Graphics class that represents the techniques used in rendering - */ - - /*! - * \brief Gets the technique by enumeration - * \return A reference to the newly created technique - * - * \param renderTechnique Enumeration of the technique - * \param techniqueRanking Ranking for the technique - * - * \remark Produces a NazaraError if renderTechnique does not exist - */ - - AbstractRenderTechnique* RenderTechniques::GetByEnum(RenderTechniqueType renderTechnique, int* techniqueRanking) - { - #ifdef NAZARA_DEBUG - if (renderTechnique > RenderTechniqueType_Max) - { - NazaraError("Render technique type out of enum"); - return nullptr; - } - #endif - - return GetByName(techniquesName[renderTechnique], techniqueRanking); - } - - /*! - * \brief Gets the technique by index - * \return A reference to the newly created technique - * - * \param index Index of the technique - * \param techniqueRanking Ranking for the technique - * - * \remark Produces a NazaraError if index is out or range - */ - - AbstractRenderTechnique* RenderTechniques::GetByIndex(unsigned int index, int* techniqueRanking) - { - #if NAZARA_GRAPHICS_SAFE - if (index >= s_renderTechniques.size()) - { - NazaraError("Technique index out of range (" + String::Number(index) + " >= " + String::Number(s_renderTechniques.size()) + ')'); - return nullptr; - } - #endif - - auto it = s_renderTechniques.begin(); - std::advance(it, index); - - if (techniqueRanking) - *techniqueRanking = it->second.ranking; - - return it->second.factory(); - } - - /*! - * \brief Gets the technique by name - * \return A reference to the newly created technique - * - * \param name Name of the technique - * \param techniqueRanking Ranking for the technique - * - * \remark Produces a NazaraError if name does not exist or is invalid - */ - - AbstractRenderTechnique* RenderTechniques::GetByName(const String& name, int* techniqueRanking) - { - #if NAZARA_GRAPHICS_SAFE - if (name.IsEmpty()) - { - NazaraError("Technique name cannot be empty"); - return nullptr; - } - #endif - - auto it = s_renderTechniques.find(name); - if (it == s_renderTechniques.end()) - { - NazaraError("Technique not found"); - return nullptr; - } - - if (techniqueRanking) - *techniqueRanking = it->second.ranking; - - return it->second.factory(); - } - - /*! - * \brief Gets the technique by ranking - * \return A reference to the newly created technique - * - * \param maxRanking Ranking maximum of the technique - * \param techniqueRanking Ranking for the technique - * - * \remark Produces a NazaraError if name does not exist or is invalid - */ - - AbstractRenderTechnique* RenderTechniques::GetByRanking(int maxRanking, int* techniqueRanking) - { - if (maxRanking < 0) - maxRanking = std::numeric_limits::max(); - - int currentRanking = -1; - RenderTechnique* technique = nullptr; - - for (auto it = s_renderTechniques.begin(); it != s_renderTechniques.end(); ++it) - { - int ranking = it->second.ranking; - if (ranking > currentRanking && ranking <= maxRanking) - { - currentRanking = ranking; - technique = &(it->second); - } - } - - if (!technique) - { - NazaraError("No technique found"); - return nullptr; - } - - if (techniqueRanking) - *techniqueRanking = currentRanking; - - return technique->factory(); - } - - /*! - * \brief Gets the number of techniques available - * \return Number of techniques - */ - - std::size_t RenderTechniques::GetCount() - { - return s_renderTechniques.size(); - } - - /*! - * \brief Registers a technique - * - * \param name Name of the technique - * \param ranking Ranking of the technique - * \param factory Factory to create the technique - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if name is empty - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if ranking is negative - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if factory is invalid is invalid - */ - - void RenderTechniques::Register(const String& name, int ranking, RenderTechniqueFactory factory) - { - #if NAZARA_GRAPHICS_SAFE - if (name.IsEmpty()) - { - NazaraError("Technique name cannot be empty"); - return; - } - - if (ranking < 0) - { - NazaraError("Technique ranking cannot be negative"); - return; - } - - if (!factory) - { - NazaraError("Technique function must be valid"); - return; - } - #endif - - s_renderTechniques[name] = {factory, ranking}; - } - - /*! - * \brief Converts the enumeration to string - * \return String symbolizing the technique - * - * \param renderTechnique Enumeration of the technique - * - * \remark Produces a NazaraError if renderTechnique does not exist and returns "Error" - */ - - String RenderTechniques::ToString(RenderTechniqueType renderTechnique) - { - #ifdef NAZARA_DEBUG - if (renderTechnique > RenderTechniqueType_Max) - { - NazaraError("Render technique type out of enum"); - return String("Error"); - } - #endif - - return techniquesName[renderTechnique]; - } - - /*! - * \brief Unregisters a technique - * - * \param name Name of the technique - */ - - void RenderTechniques::Unregister(const String& name) - { - s_renderTechniques.erase(name); - } -} diff --git a/src/Nazara/Graphics/Renderable.cpp b/src/Nazara/Graphics/Renderable.cpp deleted file mode 100644 index 6633bd173..000000000 --- a/src/Nazara/Graphics/Renderable.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::Renderable - * \brief Graphics class that represents a renderable element for our scene - * - * \remark This class is abstract - */ - - Renderable::~Renderable() = default; - - /*! - * \brief Culls the model if not in the frustum - * \return true If renderable is in the frustum - * - * \param frustum Symbolizing the field of view - * \param transformMatrix Matrix transformation for our object - */ - - bool Renderable::Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const - { - NazaraUnused(transformMatrix); - - return frustum.Contains(m_boundingVolume); - } - - /*! - * \brief Gets the bounding volume - * \return Bounding volume of the renderable element - */ - - const BoundingVolumef& Renderable::GetBoundingVolume() const - { - EnsureBoundingVolumeUpdated(); - - return m_boundingVolume; - } - - /*! - * \brief Updates the bounding volume by a matrix - * - * \param transformMatrix Matrix transformation for our bounding volume - */ - - void Renderable::UpdateBoundingVolume(const Matrix4f& transformMatrix) - { - m_boundingVolume.Update(transformMatrix); - } -} diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag deleted file mode 100644 index 6d73c9d06..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag +++ /dev/null @@ -1,23 +0,0 @@ -#version 140 - -out vec4 RenderTarget0; - -uniform float BrightLuminance = 0.8; -uniform float BrightMiddleGrey = 0.5; -uniform float BrightThreshold = 0.8; -uniform sampler2D ColorTexture; -uniform vec2 InvTargetSize; - -void main() -{ - vec2 texCoord = gl_FragCoord.xy * InvTargetSize; - - vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb; - - color *= BrightMiddleGrey/BrightLuminance; - color *= 1.0 + (color / (BrightThreshold*BrightThreshold)); - color -= 0.5; - color /= (1.0 + color); - - RenderTarget0 = vec4(color, 1.0); -} diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag.h b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag.h deleted file mode 100644 index 7b1439d81..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag.h +++ /dev/null @@ -1 +0,0 @@ -35,118,101,114,115,105,111,110,32,49,52,48,10,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,10,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,66,114,105,103,104,116,76,117,109,105,110,97,110,99,101,32,61,32,48,46,56,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,66,114,105,103,104,116,77,105,100,100,108,101,71,114,101,121,32,61,32,48,46,53,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,66,114,105,103,104,116,84,104,114,101,115,104,111,108,100,32,61,32,48,46,56,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,10,9,118,101,99,51,32,99,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,10,10,9,99,111,108,111,114,32,42,61,32,66,114,105,103,104,116,77,105,100,100,108,101,71,114,101,121,47,66,114,105,103,104,116,76,117,109,105,110,97,110,99,101,59,10,9,99,111,108,111,114,32,42,61,32,49,46,48,32,43,32,40,99,111,108,111,114,32,47,32,40,66,114,105,103,104,116,84,104,114,101,115,104,111,108,100,42,66,114,105,103,104,116,84,104,114,101,115,104,111,108,100,41,41,59,10,9,99,111,108,111,114,32,45,61,32,48,46,53,59,10,9,99,111,108,111,114,32,47,61,32,40,49,46,48,32,43,32,99,111,108,111,114,41,59,10,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,99,111,108,111,114,44,32,49,46,48,41,59,10,125,10, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag deleted file mode 100644 index 89b5c1945..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag +++ /dev/null @@ -1,17 +0,0 @@ -#version 140 - -out vec4 RenderTarget0; - -uniform sampler2D BloomTexture; -uniform sampler2D ColorTexture; -uniform vec2 InvTargetSize; - -void main() -{ - vec2 texCoord = gl_FragCoord.xy * InvTargetSize; - - vec3 bloomColor = textureLod(BloomTexture, texCoord, 0.0).rgb; - vec3 originalColor = textureLod(ColorTexture, texCoord, 0.0).rgb; - - RenderTarget0 = vec4(originalColor + bloomColor, 1.0); -} diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag.h b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag.h deleted file mode 100644 index 63f3c0e13..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag.h +++ /dev/null @@ -1 +0,0 @@ -35,118,101,114,115,105,111,110,32,49,52,48,10,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,10,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,66,108,111,111,109,84,101,120,116,117,114,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,10,9,118,101,99,51,32,98,108,111,111,109,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,66,108,111,111,109,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,10,9,118,101,99,51,32,111,114,105,103,105,110,97,108,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,10,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,111,114,105,103,105,110,97,108,67,111,108,111,114,32,43,32,98,108,111,111,109,67,111,108,111,114,44,32,49,46,48,41,59,10,125,10, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag deleted file mode 100644 index fabb0e6f5..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag +++ /dev/null @@ -1,77 +0,0 @@ -#version 140 - -out vec4 RenderTarget0; - -uniform vec3 EyePosition; - -uniform vec4 LightColor; -uniform vec2 LightFactors; -uniform vec4 LightDirection; - -uniform sampler2D GBuffer0; -uniform sampler2D GBuffer1; -uniform sampler2D GBuffer2; -uniform sampler2D DepthBuffer; - -uniform mat4 InvViewProjMatrix; -uniform vec2 InvTargetSize; -uniform vec4 SceneAmbient; - -#define kPI 3.1415926536 - -vec3 DecodeNormal(in vec4 encodedNormal) -{ - //return encodedNormal.xyz*2.0 - 1.0; - float a = encodedNormal.x * kPI; - vec2 scth = vec2(sin(a), cos(a)); - - vec2 scphi = vec2(sqrt(1.0 - encodedNormal.y*encodedNormal.y), encodedNormal.y); - return vec3(scth.y*scphi.x, scth.x*scphi.x, scphi.y); -} - -void main() -{ - vec2 texCoord = gl_FragCoord.xy * InvTargetSize; - vec4 gVec0 = textureLod(GBuffer0, texCoord, 0.0); - vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0); - vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0); - - vec3 diffuseColor = gVec0.xyz; - vec3 normal = DecodeNormal(gVec1); - float specularMultiplier = gVec0.w; - float depth = textureLod(DepthBuffer, texCoord, 0.0).r; - float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5); - - vec3 lightDir = -LightDirection.xyz; - - // Ambient - vec3 lightAmbient = LightColor.rgb * LightFactors.x * (vec3(1.0) + SceneAmbient.rgb); - - // Diffuse - float lambert = max(dot(normal, lightDir), 0.0); - - vec3 lightDiffuse = lambert * LightColor.rgb * LightFactors.y; - - // Specular - vec3 lightSpecular; - if (shininess > 0.0) - { - vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth*2.0 - 1.0); - - vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0); - worldPos.xyz /= worldPos.w; - - vec3 eyeVec = normalize(EyePosition - worldPos.xyz); - - vec3 reflection = reflect(-lightDir, normal); - float specularFactor = max(dot(reflection, eyeVec), 0.0); - specularFactor = pow(specularFactor, shininess); - - lightSpecular = specularFactor * LightColor.rgb * specularMultiplier; - } - else - lightSpecular = vec3(0.0); - - vec3 fragmentColor = diffuseColor * (lightAmbient + lightDiffuse + lightSpecular); - RenderTarget0 = vec4(fragmentColor, 1.0); -} \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag.h b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag.h deleted file mode 100644 index b8ba80ab6..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag.h +++ /dev/null @@ -1 +0,0 @@ -35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,117,110,105,102,111,114,109,32,118,101,99,51,32,69,121,101,80,111,115,105,116,105,111,110,59,13,10,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,76,105,103,104,116,67,111,108,111,114,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,76,105,103,104,116,70,97,99,116,111,114,115,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,76,105,103,104,116,68,105,114,101,99,116,105,111,110,59,13,10,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,71,66,117,102,102,101,114,48,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,71,66,117,102,102,101,114,49,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,71,66,117,102,102,101,114,50,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,68,101,112,116,104,66,117,102,102,101,114,59,13,10,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,73,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,83,99,101,110,101,65,109,98,105,101,110,116,59,13,10,13,10,35,100,101,102,105,110,101,32,107,80,73,32,51,46,49,52,49,53,57,50,54,53,51,54,13,10,13,10,118,101,99,51,32,68,101,99,111,100,101,78,111,114,109,97,108,40,105,110,32,118,101,99,52,32,101,110,99,111,100,101,100,78,111,114,109,97,108,41,13,10,123,13,10,9,47,47,114,101,116,117,114,110,32,101,110,99,111,100,101,100,78,111,114,109,97,108,46,120,121,122,42,50,46,48,32,45,32,49,46,48,59,9,13,10,9,102,108,111,97,116,32,97,32,61,32,101,110,99,111,100,101,100,78,111,114,109,97,108,46,120,32,42,32,107,80,73,59,13,10,32,32,32,32,118,101,99,50,32,115,99,116,104,32,61,32,118,101,99,50,40,115,105,110,40,97,41,44,32,99,111,115,40,97,41,41,59,13,10,13,10,32,32,32,32,118,101,99,50,32,115,99,112,104,105,32,61,32,118,101,99,50,40,115,113,114,116,40,49,46,48,32,45,32,101,110,99,111,100,101,100,78,111,114,109,97,108,46,121,42,101,110,99,111,100,101,100,78,111,114,109,97,108,46,121,41,44,32,101,110,99,111,100,101,100,78,111,114,109,97,108,46,121,41,59,13,10,32,32,32,32,114,101,116,117,114,110,32,118,101,99,51,40,115,99,116,104,46,121,42,115,99,112,104,105,46,120,44,32,115,99,116,104,46,120,42,115,99,112,104,105,46,120,44,32,115,99,112,104,105,46,121,41,59,13,10,125,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,9,118,101,99,52,32,103,86,101,99,48,32,61,32,116,101,120,116,117,114,101,76,111,100,40,71,66,117,102,102,101,114,48,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,59,13,10,9,118,101,99,52,32,103,86,101,99,49,32,61,32,116,101,120,116,117,114,101,76,111,100,40,71,66,117,102,102,101,114,49,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,59,13,10,9,118,101,99,52,32,103,86,101,99,50,32,61,32,116,101,120,116,117,114,101,76,111,100,40,71,66,117,102,102,101,114,50,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,59,13,10,13,10,9,118,101,99,51,32,100,105,102,102,117,115,101,67,111,108,111,114,32,61,32,103,86,101,99,48,46,120,121,122,59,13,10,9,118,101,99,51,32,110,111,114,109,97,108,32,61,32,68,101,99,111,100,101,78,111,114,109,97,108,40,103,86,101,99,49,41,59,13,10,9,102,108,111,97,116,32,115,112,101,99,117,108,97,114,77,117,108,116,105,112,108,105,101,114,32,61,32,103,86,101,99,48,46,119,59,13,10,9,102,108,111,97,116,32,100,101,112,116,104,32,61,32,116,101,120,116,117,114,101,76,111,100,40,68,101,112,116,104,66,117,102,102,101,114,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,59,13,10,9,102,108,111,97,116,32,115,104,105,110,105,110,101,115,115,32,61,32,40,103,86,101,99,50,46,119,32,61,61,32,48,46,48,41,32,63,32,48,46,48,32,58,32,101,120,112,50,40,103,86,101,99,50,46,119,42,49,48,46,53,41,59,13,10,13,10,9,118,101,99,51,32,108,105,103,104,116,68,105,114,32,61,32,45,76,105,103,104,116,68,105,114,101,99,116,105,111,110,46,120,121,122,59,13,10,13,10,9,47,47,32,65,109,98,105,101,110,116,13,10,9,118,101,99,51,32,108,105,103,104,116,65,109,98,105,101,110,116,32,61,32,76,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,76,105,103,104,116,70,97,99,116,111,114,115,46,120,32,42,32,40,118,101,99,51,40,49,46,48,41,32,43,32,83,99,101,110,101,65,109,98,105,101,110,116,46,114,103,98,41,59,13,10,13,10,9,47,47,32,68,105,102,102,117,115,101,13,10,9,102,108,111,97,116,32,108,97,109,98,101,114,116,32,61,32,109,97,120,40,100,111,116,40,110,111,114,109,97,108,44,32,108,105,103,104,116,68,105,114,41,44,32,48,46,48,41,59,13,10,13,10,9,118,101,99,51,32,108,105,103,104,116,68,105,102,102,117,115,101,32,61,32,108,97,109,98,101,114,116,32,42,32,76,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,76,105,103,104,116,70,97,99,116,111,114,115,46,121,59,13,10,13,10,9,47,47,32,83,112,101,99,117,108,97,114,13,10,9,118,101,99,51,32,108,105,103,104,116,83,112,101,99,117,108,97,114,59,13,10,9,105,102,32,40,115,104,105,110,105,110,101,115,115,32,62,32,48,46,48,41,13,10,9,123,13,10,9,9,118,101,99,51,32,118,105,101,119,83,112,97,99,101,32,61,32,118,101,99,51,40,116,101,120,67,111,111,114,100,42,50,46,48,32,45,32,49,46,48,44,32,100,101,112,116,104,42,50,46,48,32,45,32,49,46,48,41,59,13,10,13,10,9,9,118,101,99,52,32,119,111,114,108,100,80,111,115,32,61,32,73,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,118,105,101,119,83,112,97,99,101,44,32,49,46,48,41,59,13,10,9,9,119,111,114,108,100,80,111,115,46,120,121,122,32,47,61,32,119,111,114,108,100,80,111,115,46,119,59,13,10,13,10,9,9,118,101,99,51,32,101,121,101,86,101,99,32,61,32,110,111,114,109,97,108,105,122,101,40,69,121,101,80,111,115,105,116,105,111,110,32,45,32,119,111,114,108,100,80,111,115,46,120,121,122,41,59,13,10,13,10,9,9,118,101,99,51,32,114,101,102,108,101,99,116,105,111,110,32,61,32,114,101,102,108,101,99,116,40,45,108,105,103,104,116,68,105,114,44,32,110,111,114,109,97,108,41,59,13,10,9,9,102,108,111,97,116,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,109,97,120,40,100,111,116,40,114,101,102,108,101,99,116,105,111,110,44,32,101,121,101,86,101,99,41,44,32,48,46,48,41,59,13,10,9,9,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,112,111,119,40,115,112,101,99,117,108,97,114,70,97,99,116,111,114,44,32,115,104,105,110,105,110,101,115,115,41,59,13,10,13,10,9,9,108,105,103,104,116,83,112,101,99,117,108,97,114,32,61,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,42,32,76,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,115,112,101,99,117,108,97,114,77,117,108,116,105,112,108,105,101,114,59,13,10,9,125,13,10,9,101,108,115,101,13,10,9,9,108,105,103,104,116,83,112,101,99,117,108,97,114,32,61,32,118,101,99,51,40,48,46,48,41,59,13,10,13,10,9,118,101,99,51,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,100,105,102,102,117,115,101,67,111,108,111,114,32,42,32,40,108,105,103,104,116,65,109,98,105,101,110,116,32,43,32,108,105,103,104,116,68,105,102,102,117,115,101,32,43,32,108,105,103,104,116,83,112,101,99,117,108,97,114,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,102,114,97,103,109,101,110,116,67,111,108,111,114,44,32,49,46,48,41,59,13,10,125, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag deleted file mode 100644 index 704842fbb..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag +++ /dev/null @@ -1,47 +0,0 @@ -#version 140 - -out vec4 RenderTarget0; - -uniform float FXAAReduceMul = 0.0; // 1.0/8.0 -uniform float FXAASpanMax = 8.0; -uniform sampler2D ColorTexture; -uniform vec2 InvTargetSize; - -void main() -{ - #define FXAA_REDUCE_MIN (1.0/128.0) - - vec2 texCoord = gl_FragCoord.xy * InvTargetSize; - - vec3 rgbNW = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(-1,-1)).rgb; - vec3 rgbNE = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(1,-1)).rgb; - vec3 rgbSW = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(-1,1)).rgb; - vec3 rgbSE = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(1,1)).rgb; - vec3 rgbM = textureLod(ColorTexture, texCoord, 0.0).rgb; - - vec3 luma = vec3(0.299, 0.587, 0.114); - float lumaNW = dot(rgbNW, luma); - float lumaNE = dot(rgbNE, luma); - float lumaSW = dot(rgbSW, luma); - float lumaSE = dot(rgbSE, luma); - float lumaM = dot(rgbM, luma); - - float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); - float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); - - vec2 dir; - dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); - dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); - - float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAAReduceMul), FXAA_REDUCE_MIN); - float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce); - dir = min(vec2(FXAASpanMax, FXAASpanMax), max(vec2(-FXAASpanMax, -FXAASpanMax), dir * rcpDirMin)) * InvTargetSize; - - vec3 rgbA = (1.0/2.0) * (textureLod(ColorTexture, texCoord + dir * (1.0/3.0 - 0.5), 0.0).rgb + textureLod(ColorTexture, texCoord + dir * (2.0/3.0 - 0.5), 0.0).rgb); - vec3 rgbB = rgbA * 1.0/2.0 + 1.0/4.0 * (textureLod(ColorTexture, texCoord + dir * (0.0/3.0 - 0.5), 0.0).rgb + textureLod(ColorTexture, texCoord + dir * (3.0/3.0 - 0.5), 0.0).rgb); - float lumaB = dot(rgbB, luma); - - vec3 fragmentColor = (lumaB < lumaMin || lumaB > lumaMax) ? rgbA : rgbB; - - RenderTarget0 = vec4(fragmentColor, 1.0); -} \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h deleted file mode 100644 index 4722dd840..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h +++ /dev/null @@ -1 +0,0 @@ -35,118,101,114,115,105,111,110,32,49,52,48,10,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,10,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,70,88,65,65,82,101,100,117,99,101,77,117,108,32,61,32,48,46,48,59,32,47,47,32,49,46,48,47,56,46,48,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,70,88,65,65,83,112,97,110,77,97,120,32,61,32,56,46,48,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,32,32,32,32,35,100,101,102,105,110,101,32,70,88,65,65,95,82,69,68,85,67,69,95,77,73,78,32,32,32,40,49,46,48,47,49,50,56,46,48,41,10,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,10,32,32,32,32,118,101,99,51,32,114,103,98,78,87,32,61,32,116,101,120,116,117,114,101,76,111,100,79,102,102,115,101,116,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,44,32,105,118,101,99,50,40,45,49,44,45,49,41,41,46,114,103,98,59,10,32,32,32,32,118,101,99,51,32,114,103,98,78,69,32,61,32,116,101,120,116,117,114,101,76,111,100,79,102,102,115,101,116,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,44,32,105,118,101,99,50,40,49,44,45,49,41,41,46,114,103,98,59,10,32,32,32,32,118,101,99,51,32,114,103,98,83,87,32,61,32,116,101,120,116,117,114,101,76,111,100,79,102,102,115,101,116,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,44,32,105,118,101,99,50,40,45,49,44,49,41,41,46,114,103,98,59,10,32,32,32,32,118,101,99,51,32,114,103,98,83,69,32,61,32,116,101,120,116,117,114,101,76,111,100,79,102,102,115,101,116,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,44,32,105,118,101,99,50,40,49,44,49,41,41,46,114,103,98,59,10,32,32,32,32,118,101,99,51,32,114,103,98,77,32,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,10,10,32,32,32,32,118,101,99,51,32,108,117,109,97,32,61,32,118,101,99,51,40,48,46,50,57,57,44,32,48,46,53,56,55,44,32,48,46,49,49,52,41,59,10,32,32,32,32,102,108,111,97,116,32,108,117,109,97,78,87,32,61,32,100,111,116,40,114,103,98,78,87,44,32,108,117,109,97,41,59,10,32,32,32,32,102,108,111,97,116,32,108,117,109,97,78,69,32,61,32,100,111,116,40,114,103,98,78,69,44,32,108,117,109,97,41,59,10,32,32,32,32,102,108,111,97,116,32,108,117,109,97,83,87,32,61,32,100,111,116,40,114,103,98,83,87,44,32,108,117,109,97,41,59,10,32,32,32,32,102,108,111,97,116,32,108,117,109,97,83,69,32,61,32,100,111,116,40,114,103,98,83,69,44,32,108,117,109,97,41,59,10,32,32,32,32,102,108,111,97,116,32,108,117,109,97,77,32,32,61,32,100,111,116,40,114,103,98,77,44,32,32,108,117,109,97,41,59,10,10,32,32,32,32,102,108,111,97,116,32,108,117,109,97,77,105,110,32,61,32,109,105,110,40,108,117,109,97,77,44,32,109,105,110,40,109,105,110,40,108,117,109,97,78,87,44,32,108,117,109,97,78,69,41,44,32,109,105,110,40,108,117,109,97,83,87,44,32,108,117,109,97,83,69,41,41,41,59,10,32,32,32,32,102,108,111,97,116,32,108,117,109,97,77,97,120,32,61,32,109,97,120,40,108,117,109,97,77,44,32,109,97,120,40,109,97,120,40,108,117,109,97,78,87,44,32,108,117,109,97,78,69,41,44,32,109,97,120,40,108,117,109,97,83,87,44,32,108,117,109,97,83,69,41,41,41,59,10,10,32,32,32,32,118,101,99,50,32,100,105,114,59,32,10,32,32,32,32,100,105,114,46,120,32,61,32,45,40,40,108,117,109,97,78,87,32,43,32,108,117,109,97,78,69,41,32,45,32,40,108,117,109,97,83,87,32,43,32,108,117,109,97,83,69,41,41,59,10,32,32,32,32,100,105,114,46,121,32,61,32,32,40,40,108,117,109,97,78,87,32,43,32,108,117,109,97,83,87,41,32,45,32,40,108,117,109,97,78,69,32,43,32,108,117,109,97,83,69,41,41,59,10,10,32,32,32,32,102,108,111,97,116,32,100,105,114,82,101,100,117,99,101,32,61,32,109,97,120,40,40,108,117,109,97,78,87,32,43,32,108,117,109,97,78,69,32,43,32,108,117,109,97,83,87,32,43,32,108,117,109,97,83,69,41,32,42,32,40,48,46,50,53,32,42,32,70,88,65,65,82,101,100,117,99,101,77,117,108,41,44,32,70,88,65,65,95,82,69,68,85,67,69,95,77,73,78,41,59,10,32,32,32,32,102,108,111,97,116,32,114,99,112,68,105,114,77,105,110,32,61,32,49,46,48,47,40,109,105,110,40,97,98,115,40,100,105,114,46,120,41,44,32,97,98,115,40,100,105,114,46,121,41,41,32,43,32,100,105,114,82,101,100,117,99,101,41,59,10,32,32,32,32,100,105,114,32,61,32,109,105,110,40,118,101,99,50,40,70,88,65,65,83,112,97,110,77,97,120,44,32,70,88,65,65,83,112,97,110,77,97,120,41,44,32,109,97,120,40,118,101,99,50,40,45,70,88,65,65,83,112,97,110,77,97,120,44,32,45,70,88,65,65,83,112,97,110,77,97,120,41,44,32,100,105,114,32,42,32,114,99,112,68,105,114,77,105,110,41,41,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,10,32,32,32,32,118,101,99,51,32,114,103,98,65,32,61,32,40,49,46,48,47,50,46,48,41,32,42,32,40,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,43,32,100,105,114,32,42,32,40,49,46,48,47,51,46,48,32,45,32,48,46,53,41,44,32,48,46,48,41,46,114,103,98,32,43,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,43,32,100,105,114,32,42,32,40,50,46,48,47,51,46,48,32,45,32,48,46,53,41,44,32,48,46,48,41,46,114,103,98,41,59,10,32,32,32,32,118,101,99,51,32,114,103,98,66,32,61,32,114,103,98,65,32,42,32,49,46,48,47,50,46,48,32,43,32,49,46,48,47,52,46,48,32,42,32,40,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,43,32,100,105,114,32,42,32,40,48,46,48,47,51,46,48,32,45,32,48,46,53,41,44,32,48,46,48,41,46,114,103,98,32,43,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,43,32,100,105,114,32,42,32,40,51,46,48,47,51,46,48,32,45,32,48,46,53,41,44,32,48,46,48,41,46,114,103,98,41,59,10,32,32,32,32,102,108,111,97,116,32,108,117,109,97,66,32,61,32,100,111,116,40,114,103,98,66,44,32,108,117,109,97,41,59,10,10,9,118,101,99,51,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,40,108,117,109,97,66,32,60,32,108,117,109,97,77,105,110,32,124,124,32,108,117,109,97,66,32,62,32,108,117,109,97,77,97,120,41,32,63,32,114,103,98,65,32,58,32,114,103,98,66,59,10,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,102,114,97,103,109,101,110,116,67,111,108,111,114,44,32,49,46,48,41,59,10,125, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GBufferClear.frag b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GBufferClear.frag deleted file mode 100644 index 9ee5891f4..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GBufferClear.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 140 - -out vec4 RenderTarget0; -out vec4 RenderTarget1; -out vec4 RenderTarget2; - -void main() -{ - RenderTarget0 = vec4(0.0, 0.0, 0.0, 0.0); - RenderTarget1 = vec4(0.0, 0.0, 0.0, 0.0); - RenderTarget2 = vec4(1.0, 0.0, 0.0, 0.0); - gl_FragDepth = 1.0; -} diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GBufferClear.frag.h b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GBufferClear.frag.h deleted file mode 100644 index b81786f2d..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GBufferClear.frag.h +++ /dev/null @@ -1 +0,0 @@ -35,118,101,114,115,105,111,110,32,49,52,48,10,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,49,59,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,50,59,10,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,10,9,82,101,110,100,101,114,84,97,114,103,101,116,49,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,10,9,82,101,110,100,101,114,84,97,114,103,101,116,50,32,61,32,118,101,99,52,40,49,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,10,9,103,108,95,70,114,97,103,68,101,112,116,104,32,61,32,49,46,48,59,10,125,10, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag deleted file mode 100644 index 16c3a0996..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag +++ /dev/null @@ -1,25 +0,0 @@ -// http://www.geeks3d.com/20100909/shader-library-gaussian-blur-post-processing-filter-in-glsl/ -#version 140 - -out vec4 RenderTarget0; - -uniform sampler2D ColorTexture; -uniform vec2 Filter; -uniform vec2 InvTargetSize; - -float offset[3] = float[](0.0, 1.3846153846, 3.2307692308); -float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); - -void main() -{ - vec2 texCoord = gl_FragCoord.xy * InvTargetSize; - vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb * weight[0]; - - for (int i = 1; i < 3; i++) - { - color += textureLod(ColorTexture, texCoord + Filter*vec2(offset[i])*InvTargetSize, 0.0).rgb * weight[i]; - color += textureLod(ColorTexture, texCoord - Filter*vec2(offset[i])*InvTargetSize, 0.0).rgb * weight[i]; - } - - RenderTarget0 = vec4(color, 1.0); -} diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag.h b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag.h deleted file mode 100644 index 6b805bbb5..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag.h +++ /dev/null @@ -1 +0,0 @@ -47,47,32,104,116,116,112,58,47,47,119,119,119,46,103,101,101,107,115,51,100,46,99,111,109,47,50,48,49,48,48,57,48,57,47,115,104,97,100,101,114,45,108,105,98,114,97,114,121,45,103,97,117,115,115,105,97,110,45,98,108,117,114,45,112,111,115,116,45,112,114,111,99,101,115,115,105,110,103,45,102,105,108,116,101,114,45,105,110,45,103,108,115,108,47,10,35,118,101,114,115,105,111,110,32,49,52,48,10,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,10,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,10,117,110,105,102,111,114,109,32,118,101,99,50,32,70,105,108,116,101,114,59,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,10,102,108,111,97,116,32,111,102,102,115,101,116,91,51,93,32,61,32,102,108,111,97,116,91,93,40,48,46,48,44,32,49,46,51,56,52,54,49,53,51,56,52,54,44,32,51,46,50,51,48,55,54,57,50,51,48,56,41,59,10,102,108,111,97,116,32,119,101,105,103,104,116,91,51,93,32,61,32,102,108,111,97,116,91,93,40,48,46,50,50,55,48,50,55,48,50,55,48,44,32,48,46,51,49,54,50,49,54,50,49,54,50,44,32,48,46,48,55,48,50,55,48,50,55,48,51,41,59,10,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,9,118,101,99,51,32,99,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,32,42,32,119,101,105,103,104,116,91,48,93,59,10,10,9,102,111,114,32,40,105,110,116,32,105,32,61,32,49,59,32,105,32,60,32,51,59,32,105,43,43,41,10,9,123,10,9,9,99,111,108,111,114,32,43,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,43,32,70,105,108,116,101,114,42,118,101,99,50,40,111,102,102,115,101,116,91,105,93,41,42,73,110,118,84,97,114,103,101,116,83,105,122,101,44,32,48,46,48,41,46,114,103,98,32,42,32,119,101,105,103,104,116,91,105,93,59,10,9,9,99,111,108,111,114,32,43,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,45,32,70,105,108,116,101,114,42,118,101,99,50,40,111,102,102,115,101,116,91,105,93,41,42,73,110,118,84,97,114,103,101,116,83,105,122,101,44,32,48,46,48,41,46,114,103,98,32,42,32,119,101,105,103,104,116,91,105,93,59,10,9,125,10,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,99,111,108,111,114,44,32,49,46,48,41,59,10,125,10, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag deleted file mode 100644 index 37b3f5e1a..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag +++ /dev/null @@ -1,108 +0,0 @@ -#version 140 - -#define LIGHT_DIRECTIONAL 0 -#define LIGHT_POINT 1 -#define LIGHT_SPOT 2 - -out vec4 RenderTarget0; - -uniform vec3 EyePosition; - -uniform int LightType; -uniform vec4 LightColor; -uniform vec2 LightFactors; -uniform vec4 LightDirection; -uniform vec4 LightParameters1; -uniform vec4 LightParameters2; -uniform vec2 LightParameters3; - -uniform sampler2D GBuffer0; -uniform sampler2D GBuffer1; -uniform sampler2D GBuffer2; -uniform sampler2D DepthBuffer; - -uniform mat4 InvViewProjMatrix; -uniform vec2 InvTargetSize; -uniform vec4 SceneAmbient; - -uniform bool Discard = false; - -float ColorToFloat(vec3 color) -{ - const vec3 byte_to_float = vec3(1.0, 1.0/256, 1.0/(256*256)); - return dot(color, byte_to_float); -} - -#define kPI 3.1415926536 - -vec3 DecodeNormal(in vec4 encodedNormal) -{ - //return encodedNormal.xyz*2.0 - 1.0; - float a = encodedNormal.x * kPI; - vec2 scth = vec2(sin(a), cos(a)); - - vec2 scphi = vec2(sqrt(1.0 - encodedNormal.y*encodedNormal.y), encodedNormal.y); - return vec3(scth.y*scphi.x, scth.x*scphi.x, scphi.y); -} - -void main() -{ - if (Discard) - return; - - vec2 texCoord = gl_FragCoord.xy * InvTargetSize; - vec4 gVec0 = textureLod(GBuffer0, texCoord, 0.0); - vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0); - vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0); - - vec3 diffuseColor = gVec0.xyz; - vec3 normal = DecodeNormal(gVec1); - float specularMultiplier = gVec0.w; - float depth = textureLod(DepthBuffer, texCoord, 0.0).r; - float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5); - - vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth*2.0 - 1.0); - - vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0); - worldPos.xyz /= worldPos.w; - - vec3 lightDir = LightParameters1.xyz - worldPos.xyz; - float lightDirLength = length(lightDir); - lightDir /= lightDirLength; - - float att = max(LightParameters1.w - LightParameters2.w*lightDirLength, 0.0); - - // Ambient - vec3 lightAmbient = att * LightColor.rgb * LightFactors.x * (vec3(1.0) + SceneAmbient.rgb); - - if (LightType == LIGHT_SPOT) - { - // Modification de l'atténuation pour gérer le spot - float curAngle = dot(LightParameters2.xyz, -lightDir); - float outerAngle = LightParameters3.y; - float innerMinusOuterAngle = LightParameters3.x - outerAngle; - att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0); - } - - // Diffuse - float lambert = max(dot(normal, lightDir), 0.0); - - vec3 lightDiffuse = att * lambert * LightColor.rgb * LightFactors.y; - - // Specular - vec3 lightSpecular; - if (shininess > 0.0) - { - vec3 eyeVec = normalize(EyePosition - worldPos.xyz); - vec3 reflection = reflect(-lightDir, normal); - float specularFactor = max(dot(reflection, eyeVec), 0.0); - specularFactor = pow(specularFactor, shininess); - - lightSpecular = att * specularFactor * LightColor.rgb * specularMultiplier; - } - else - lightSpecular = vec3(0.0); - - vec3 fragmentColor = diffuseColor * (lightAmbient + lightDiffuse + lightSpecular); - RenderTarget0 = vec4(fragmentColor, 1.0); -} \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag.h b/src/Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag.h deleted file mode 100644 index 7f0de77ea..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag.h +++ /dev/null @@ -1 +0,0 @@ -35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,35,100,101,102,105,110,101,32,76,73,71,72,84,95,68,73,82,69,67,84,73,79,78,65,76,32,48,13,10,35,100,101,102,105,110,101,32,76,73,71,72,84,95,80,79,73,78,84,32,49,13,10,35,100,101,102,105,110,101,32,76,73,71,72,84,95,83,80,79,84,32,50,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,117,110,105,102,111,114,109,32,118,101,99,51,32,69,121,101,80,111,115,105,116,105,111,110,59,13,10,13,10,117,110,105,102,111,114,109,32,105,110,116,32,76,105,103,104,116,84,121,112,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,76,105,103,104,116,67,111,108,111,114,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,76,105,103,104,116,70,97,99,116,111,114,115,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,76,105,103,104,116,68,105,114,101,99,116,105,111,110,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,76,105,103,104,116,80,97,114,97,109,101,116,101,114,115,49,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,76,105,103,104,116,80,97,114,97,109,101,116,101,114,115,50,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,76,105,103,104,116,80,97,114,97,109,101,116,101,114,115,51,59,13,10,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,71,66,117,102,102,101,114,48,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,71,66,117,102,102,101,114,49,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,71,66,117,102,102,101,114,50,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,68,101,112,116,104,66,117,102,102,101,114,59,13,10,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,73,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,83,99,101,110,101,65,109,98,105,101,110,116,59,13,10,13,10,117,110,105,102,111,114,109,32,98,111,111,108,32,68,105,115,99,97,114,100,32,61,32,102,97,108,115,101,59,13,10,13,10,102,108,111,97,116,32,67,111,108,111,114,84,111,70,108,111,97,116,40,118,101,99,51,32,99,111,108,111,114,41,13,10,123,32,9,13,10,9,99,111,110,115,116,32,118,101,99,51,32,98,121,116,101,95,116,111,95,102,108,111,97,116,32,61,32,118,101,99,51,40,49,46,48,44,32,49,46,48,47,50,53,54,44,32,49,46,48,47,40,50,53,54,42,50,53,54,41,41,59,13,10,9,114,101,116,117,114,110,32,100,111,116,40,99,111,108,111,114,44,32,98,121,116,101,95,116,111,95,102,108,111,97,116,41,59,13,10,125,13,10,13,10,35,100,101,102,105,110,101,32,107,80,73,32,51,46,49,52,49,53,57,50,54,53,51,54,13,10,13,10,118,101,99,51,32,68,101,99,111,100,101,78,111,114,109,97,108,40,105,110,32,118,101,99,52,32,101,110,99,111,100,101,100,78,111,114,109,97,108,41,13,10,123,13,10,9,47,47,114,101,116,117,114,110,32,101,110,99,111,100,101,100,78,111,114,109,97,108,46,120,121,122,42,50,46,48,32,45,32,49,46,48,59,13,10,9,102,108,111,97,116,32,97,32,61,32,101,110,99,111,100,101,100,78,111,114,109,97,108,46,120,32,42,32,107,80,73,59,13,10,9,118,101,99,50,32,115,99,116,104,32,61,32,118,101,99,50,40,115,105,110,40,97,41,44,32,99,111,115,40,97,41,41,59,13,10,13,10,9,118,101,99,50,32,115,99,112,104,105,32,61,32,118,101,99,50,40,115,113,114,116,40,49,46,48,32,45,32,101,110,99,111,100,101,100,78,111,114,109,97,108,46,121,42,101,110,99,111,100,101,100,78,111,114,109,97,108,46,121,41,44,32,101,110,99,111,100,101,100,78,111,114,109,97,108,46,121,41,59,13,10,9,114,101,116,117,114,110,32,118,101,99,51,40,115,99,116,104,46,121,42,115,99,112,104,105,46,120,44,32,115,99,116,104,46,120,42,115,99,112,104,105,46,120,44,32,115,99,112,104,105,46,121,41,59,13,10,125,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,105,102,32,40,68,105,115,99,97,114,100,41,13,10,9,9,114,101,116,117,114,110,59,13,10,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,9,118,101,99,52,32,103,86,101,99,48,32,61,32,116,101,120,116,117,114,101,76,111,100,40,71,66,117,102,102,101,114,48,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,59,13,10,9,118,101,99,52,32,103,86,101,99,49,32,61,32,116,101,120,116,117,114,101,76,111,100,40,71,66,117,102,102,101,114,49,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,59,13,10,9,118,101,99,52,32,103,86,101,99,50,32,61,32,116,101,120,116,117,114,101,76,111,100,40,71,66,117,102,102,101,114,50,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,59,13,10,13,10,9,118,101,99,51,32,100,105,102,102,117,115,101,67,111,108,111,114,32,61,32,103,86,101,99,48,46,120,121,122,59,13,10,9,118,101,99,51,32,110,111,114,109,97,108,32,61,32,68,101,99,111,100,101,78,111,114,109,97,108,40,103,86,101,99,49,41,59,13,10,9,102,108,111,97,116,32,115,112,101,99,117,108,97,114,77,117,108,116,105,112,108,105,101,114,32,61,32,103,86,101,99,48,46,119,59,13,10,9,102,108,111,97,116,32,100,101,112,116,104,32,61,32,116,101,120,116,117,114,101,76,111,100,40,68,101,112,116,104,66,117,102,102,101,114,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,59,13,10,9,102,108,111,97,116,32,115,104,105,110,105,110,101,115,115,32,61,32,40,103,86,101,99,50,46,119,32,61,61,32,48,46,48,41,32,63,32,48,46,48,32,58,32,101,120,112,50,40,103,86,101,99,50,46,119,42,49,48,46,53,41,59,13,10,13,10,9,118,101,99,51,32,118,105,101,119,83,112,97,99,101,32,61,32,118,101,99,51,40,116,101,120,67,111,111,114,100,42,50,46,48,32,45,32,49,46,48,44,32,100,101,112,116,104,42,50,46,48,32,45,32,49,46,48,41,59,13,10,13,10,9,118,101,99,52,32,119,111,114,108,100,80,111,115,32,61,32,73,110,118,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,118,105,101,119,83,112,97,99,101,44,32,49,46,48,41,59,13,10,9,119,111,114,108,100,80,111,115,46,120,121,122,32,47,61,32,119,111,114,108,100,80,111,115,46,119,59,13,10,13,10,9,118,101,99,51,32,108,105,103,104,116,68,105,114,32,61,32,76,105,103,104,116,80,97,114,97,109,101,116,101,114,115,49,46,120,121,122,32,45,32,119,111,114,108,100,80,111,115,46,120,121,122,59,13,10,9,102,108,111,97,116,32,108,105,103,104,116,68,105,114,76,101,110,103,116,104,32,61,32,108,101,110,103,116,104,40,108,105,103,104,116,68,105,114,41,59,13,10,9,108,105,103,104,116,68,105,114,32,47,61,32,108,105,103,104,116,68,105,114,76,101,110,103,116,104,59,13,10,13,10,9,102,108,111,97,116,32,97,116,116,32,61,32,109,97,120,40,76,105,103,104,116,80,97,114,97,109,101,116,101,114,115,49,46,119,32,45,32,76,105,103,104,116,80,97,114,97,109,101,116,101,114,115,50,46,119,42,108,105,103,104,116,68,105,114,76,101,110,103,116,104,44,32,48,46,48,41,59,13,10,13,10,9,47,47,32,65,109,98,105,101,110,116,13,10,9,118,101,99,51,32,108,105,103,104,116,65,109,98,105,101,110,116,32,61,32,97,116,116,32,42,32,76,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,76,105,103,104,116,70,97,99,116,111,114,115,46,120,32,42,32,40,118,101,99,51,40,49,46,48,41,32,43,32,83,99,101,110,101,65,109,98,105,101,110,116,46,114,103,98,41,59,13,10,13,10,9,105,102,32,40,76,105,103,104,116,84,121,112,101,32,61,61,32,76,73,71,72,84,95,83,80,79,84,41,13,10,9,123,13,10,9,9,47,47,32,77,111,100,105,102,105,99,97,116,105,111,110,32,100,101,32,108,39,97,116,116,195,169,110,117,97,116,105,111,110,32,112,111,117,114,32,103,195,169,114,101,114,32,108,101,32,115,112,111,116,13,10,9,9,102,108,111,97,116,32,99,117,114,65,110,103,108,101,32,61,32,100,111,116,40,76,105,103,104,116,80,97,114,97,109,101,116,101,114,115,50,46,120,121,122,44,32,45,108,105,103,104,116,68,105,114,41,59,13,10,9,9,102,108,111,97,116,32,111,117,116,101,114,65,110,103,108,101,32,61,32,76,105,103,104,116,80,97,114,97,109,101,116,101,114,115,51,46,121,59,13,10,9,9,102,108,111,97,116,32,105,110,110,101,114,77,105,110,117,115,79,117,116,101,114,65,110,103,108,101,32,61,32,76,105,103,104,116,80,97,114,97,109,101,116,101,114,115,51,46,120,32,45,32,111,117,116,101,114,65,110,103,108,101,59,13,10,9,9,97,116,116,32,42,61,32,109,97,120,40,40,99,117,114,65,110,103,108,101,32,45,32,111,117,116,101,114,65,110,103,108,101,41,32,47,32,105,110,110,101,114,77,105,110,117,115,79,117,116,101,114,65,110,103,108,101,44,32,48,46,48,41,59,13,10,9,125,13,10,9,13,10,9,47,47,32,68,105,102,102,117,115,101,13,10,9,102,108,111,97,116,32,108,97,109,98,101,114,116,32,61,32,109,97,120,40,100,111,116,40,110,111,114,109,97,108,44,32,108,105,103,104,116,68,105,114,41,44,32,48,46,48,41,59,13,10,13,10,9,118,101,99,51,32,108,105,103,104,116,68,105,102,102,117,115,101,32,61,32,97,116,116,32,42,32,108,97,109,98,101,114,116,32,42,32,76,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,76,105,103,104,116,70,97,99,116,111,114,115,46,121,59,13,10,13,10,9,47,47,32,83,112,101,99,117,108,97,114,13,10,9,118,101,99,51,32,108,105,103,104,116,83,112,101,99,117,108,97,114,59,13,10,9,105,102,32,40,115,104,105,110,105,110,101,115,115,32,62,32,48,46,48,41,13,10,9,123,13,10,9,9,118,101,99,51,32,101,121,101,86,101,99,32,61,32,110,111,114,109,97,108,105,122,101,40,69,121,101,80,111,115,105,116,105,111,110,32,45,32,119,111,114,108,100,80,111,115,46,120,121,122,41,59,13,10,9,9,118,101,99,51,32,114,101,102,108,101,99,116,105,111,110,32,61,32,114,101,102,108,101,99,116,40,45,108,105,103,104,116,68,105,114,44,32,110,111,114,109,97,108,41,59,13,10,9,9,102,108,111,97,116,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,109,97,120,40,100,111,116,40,114,101,102,108,101,99,116,105,111,110,44,32,101,121,101,86,101,99,41,44,32,48,46,48,41,59,13,10,9,9,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,112,111,119,40,115,112,101,99,117,108,97,114,70,97,99,116,111,114,44,32,115,104,105,110,105,110,101,115,115,41,59,13,10,13,10,9,9,108,105,103,104,116,83,112,101,99,117,108,97,114,32,61,32,97,116,116,32,42,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,42,32,76,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,115,112,101,99,117,108,97,114,77,117,108,116,105,112,108,105,101,114,59,13,10,9,125,13,10,9,101,108,115,101,13,10,9,9,108,105,103,104,116,83,112,101,99,117,108,97,114,32,61,32,118,101,99,51,40,48,46,48,41,59,13,10,13,10,9,118,101,99,51,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,100,105,102,102,117,115,101,67,111,108,111,114,32,42,32,40,108,105,103,104,116,65,109,98,105,101,110,116,32,43,32,108,105,103,104,116,68,105,102,102,117,115,101,32,43,32,108,105,103,104,116,83,112,101,99,117,108,97,114,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,102,114,97,103,109,101,110,116,67,111,108,111,114,44,32,49,46,48,41,59,13,10,125, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/DeferredShading/Textures/ssaoNoise.jpg.h b/src/Nazara/Graphics/Resources/DeferredShading/Textures/ssaoNoise.jpg.h deleted file mode 100644 index 406f43d2d..000000000 --- a/src/Nazara/Graphics/Resources/DeferredShading/Textures/ssaoNoise.jpg.h +++ /dev/null @@ -1 +0,0 @@ -255,216,255,224,0,16,74,70,73,70,0,1,1,2,0,28,0,28,0,0,255,226,12,88,73,67,67,95,80,82,79,70,73,76,69,0,1,1,0,0,12,72,76,105,110,111,2,16,0,0,109,110,116,114,82,71,66,32,88,89,90,32,7,206,0,2,0,9,0,6,0,49,0,0,97,99,115,112,77,83,70,84,0,0,0,0,73,69,67,32,115,82,71,66,0,0,0,0,0,0,0,0,0,0,0,1,0,0,246,214,0,1,0,0,0,0,211,45,72,80,32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,99,112,114,116,0,0,1,80,0,0,0,51,100,101,115,99,0,0,1,132,0,0,0,108,119,116,112,116,0,0,1,240,0,0,0,20,98,107,112,116,0,0,2,4,0,0,0,20,114,88,89,90,0,0,2,24,0,0,0,20,103,88,89,90,0,0,2,44,0,0,0,20,98,88,89,90,0,0,2,64,0,0,0,20,100,109,110,100,0,0,2,84,0,0,0,112,100,109,100,100,0,0,2,196,0,0,0,136,118,117,101,100,0,0,3,76,0,0,0,134,118,105,101,119,0,0,3,212,0,0,0,36,108,117,109,105,0,0,3,248,0,0,0,20,109,101,97,115,0,0,4,12,0,0,0,36,116,101,99,104,0,0,4,48,0,0,0,12,114,84,82,67,0,0,4,60,0,0,8,12,103,84,82,67,0,0,4,60,0,0,8,12,98,84,82,67,0,0,4,60,0,0,8,12,116,101,120,116,0,0,0,0,67,111,112,121,114,105,103,104,116,32,40,99,41,32,49,57,57,56,32,72,101,119,108,101,116,116,45,80,97,99,107,97,114,100,32,67,111,109,112,97,110,121,0,0,100,101,115,99,0,0,0,0,0,0,0,18,115,82,71,66,32,73,69,67,54,49,57,54,54,45,50,46,49,0,0,0,0,0,0,0,0,0,0,0,18,115,82,71,66,32,73,69,67,54,49,57,54,54,45,50,46,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,88,89,90,32,0,0,0,0,0,0,243,81,0,1,0,0,0,1,22,204,88,89,90,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,88,89,90,32,0,0,0,0,0,0,111,162,0,0,56,245,0,0,3,144,88,89,90,32,0,0,0,0,0,0,98,153,0,0,183,133,0,0,24,218,88,89,90,32,0,0,0,0,0,0,36,160,0,0,15,132,0,0,182,207,100,101,115,99,0,0,0,0,0,0,0,22,73,69,67,32,104,116,116,112,58,47,47,119,119,119,46,105,101,99,46,99,104,0,0,0,0,0,0,0,0,0,0,0,22,73,69,67,32,104,116,116,112,58,47,47,119,119,119,46,105,101,99,46,99,104,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,101,115,99,0,0,0,0,0,0,0,46,73,69,67,32,54,49,57,54,54,45,50,46,49,32,68,101,102,97,117,108,116,32,82,71,66,32,99,111,108,111,117,114,32,115,112,97,99,101,32,45,32,115,82,71,66,0,0,0,0,0,0,0,0,0,0,0,46,73,69,67,32,54,49,57,54,54,45,50,46,49,32,68,101,102,97,117,108,116,32,82,71,66,32,99,111,108,111,117,114,32,115,112,97,99,101,32,45,32,115,82,71,66,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,101,115,99,0,0,0,0,0,0,0,44,82,101,102,101,114,101,110,99,101,32,86,105,101,119,105,110,103,32,67,111,110,100,105,116,105,111,110,32,105,110,32,73,69,67,54,49,57,54,54,45,50,46,49,0,0,0,0,0,0,0,0,0,0,0,44,82,101,102,101,114,101,110,99,101,32,86,105,101,119,105,110,103,32,67,111,110,100,105,116,105,111,110,32,105,110,32,73,69,67,54,49,57,54,54,45,50,46,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118,105,101,119,0,0,0,0,0,19,164,254,0,20,95,46,0,16,207,20,0,3,237,204,0,4,19,11,0,3,92,158,0,0,0,1,88,89,90,32,0,0,0,0,0,76,9,86,0,80,0,0,0,87,31,231,109,101,97,115,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,143,0,0,0,2,115,105,103,32,0,0,0,0,67,82,84,32,99,117,114,118,0,0,0,0,0,0,4,0,0,0,0,5,0,10,0,15,0,20,0,25,0,30,0,35,0,40,0,45,0,50,0,55,0,59,0,64,0,69,0,74,0,79,0,84,0,89,0,94,0,99,0,104,0,109,0,114,0,119,0,124,0,129,0,134,0,139,0,144,0,149,0,154,0,159,0,164,0,169,0,174,0,178,0,183,0,188,0,193,0,198,0,203,0,208,0,213,0,219,0,224,0,229,0,235,0,240,0,246,0,251,1,1,1,7,1,13,1,19,1,25,1,31,1,37,1,43,1,50,1,56,1,62,1,69,1,76,1,82,1,89,1,96,1,103,1,110,1,117,1,124,1,131,1,139,1,146,1,154,1,161,1,169,1,177,1,185,1,193,1,201,1,209,1,217,1,225,1,233,1,242,1,250,2,3,2,12,2,20,2,29,2,38,2,47,2,56,2,65,2,75,2,84,2,93,2,103,2,113,2,122,2,132,2,142,2,152,2,162,2,172,2,182,2,193,2,203,2,213,2,224,2,235,2,245,3,0,3,11,3,22,3,33,3,45,3,56,3,67,3,79,3,90,3,102,3,114,3,126,3,138,3,150,3,162,3,174,3,186,3,199,3,211,3,224,3,236,3,249,4,6,4,19,4,32,4,45,4,59,4,72,4,85,4,99,4,113,4,126,4,140,4,154,4,168,4,182,4,196,4,211,4,225,4,240,4,254,5,13,5,28,5,43,5,58,5,73,5,88,5,103,5,119,5,134,5,150,5,166,5,181,5,197,5,213,5,229,5,246,6,6,6,22,6,39,6,55,6,72,6,89,6,106,6,123,6,140,6,157,6,175,6,192,6,209,6,227,6,245,7,7,7,25,7,43,7,61,7,79,7,97,7,116,7,134,7,153,7,172,7,191,7,210,7,229,7,248,8,11,8,31,8,50,8,70,8,90,8,110,8,130,8,150,8,170,8,190,8,210,8,231,8,251,9,16,9,37,9,58,9,79,9,100,9,121,9,143,9,164,9,186,9,207,9,229,9,251,10,17,10,39,10,61,10,84,10,106,10,129,10,152,10,174,10,197,10,220,10,243,11,11,11,34,11,57,11,81,11,105,11,128,11,152,11,176,11,200,11,225,11,249,12,18,12,42,12,67,12,92,12,117,12,142,12,167,12,192,12,217,12,243,13,13,13,38,13,64,13,90,13,116,13,142,13,169,13,195,13,222,13,248,14,19,14,46,14,73,14,100,14,127,14,155,14,182,14,210,14,238,15,9,15,37,15,65,15,94,15,122,15,150,15,179,15,207,15,236,16,9,16,38,16,67,16,97,16,126,16,155,16,185,16,215,16,245,17,19,17,49,17,79,17,109,17,140,17,170,17,201,17,232,18,7,18,38,18,69,18,100,18,132,18,163,18,195,18,227,19,3,19,35,19,67,19,99,19,131,19,164,19,197,19,229,20,6,20,39,20,73,20,106,20,139,20,173,20,206,20,240,21,18,21,52,21,86,21,120,21,155,21,189,21,224,22,3,22,38,22,73,22,108,22,143,22,178,22,214,22,250,23,29,23,65,23,101,23,137,23,174,23,210,23,247,24,27,24,64,24,101,24,138,24,175,24,213,24,250,25,32,25,69,25,107,25,145,25,183,25,221,26,4,26,42,26,81,26,119,26,158,26,197,26,236,27,20,27,59,27,99,27,138,27,178,27,218,28,2,28,42,28,82,28,123,28,163,28,204,28,245,29,30,29,71,29,112,29,153,29,195,29,236,30,22,30,64,30,106,30,148,30,190,30,233,31,19,31,62,31,105,31,148,31,191,31,234,32,21,32,65,32,108,32,152,32,196,32,240,33,28,33,72,33,117,33,161,33,206,33,251,34,39,34,85,34,130,34,175,34,221,35,10,35,56,35,102,35,148,35,194,35,240,36,31,36,77,36,124,36,171,36,218,37,9,37,56,37,104,37,151,37,199,37,247,38,39,38,87,38,135,38,183,38,232,39,24,39,73,39,122,39,171,39,220,40,13,40,63,40,113,40,162,40,212,41,6,41,56,41,107,41,157,41,208,42,2,42,53,42,104,42,155,42,207,43,2,43,54,43,105,43,157,43,209,44,5,44,57,44,110,44,162,44,215,45,12,45,65,45,118,45,171,45,225,46,22,46,76,46,130,46,183,46,238,47,36,47,90,47,145,47,199,47,254,48,53,48,108,48,164,48,219,49,18,49,74,49,130,49,186,49,242,50,42,50,99,50,155,50,212,51,13,51,70,51,127,51,184,51,241,52,43,52,101,52,158,52,216,53,19,53,77,53,135,53,194,53,253,54,55,54,114,54,174,54,233,55,36,55,96,55,156,55,215,56,20,56,80,56,140,56,200,57,5,57,66,57,127,57,188,57,249,58,54,58,116,58,178,58,239,59,45,59,107,59,170,59,232,60,39,60,101,60,164,60,227,61,34,61,97,61,161,61,224,62,32,62,96,62,160,62,224,63,33,63,97,63,162,63,226,64,35,64,100,64,166,64,231,65,41,65,106,65,172,65,238,66,48,66,114,66,181,66,247,67,58,67,125,67,192,68,3,68,71,68,138,68,206,69,18,69,85,69,154,69,222,70,34,70,103,70,171,70,240,71,53,71,123,71,192,72,5,72,75,72,145,72,215,73,29,73,99,73,169,73,240,74,55,74,125,74,196,75,12,75,83,75,154,75,226,76,42,76,114,76,186,77,2,77,74,77,147,77,220,78,37,78,110,78,183,79,0,79,73,79,147,79,221,80,39,80,113,80,187,81,6,81,80,81,155,81,230,82,49,82,124,82,199,83,19,83,95,83,170,83,246,84,66,84,143,84,219,85,40,85,117,85,194,86,15,86,92,86,169,86,247,87,68,87,146,87,224,88,47,88,125,88,203,89,26,89,105,89,184,90,7,90,86,90,166,90,245,91,69,91,149,91,229,92,53,92,134,92,214,93,39,93,120,93,201,94,26,94,108,94,189,95,15,95,97,95,179,96,5,96,87,96,170,96,252,97,79,97,162,97,245,98,73,98,156,98,240,99,67,99,151,99,235,100,64,100,148,100,233,101,61,101,146,101,231,102,61,102,146,102,232,103,61,103,147,103,233,104,63,104,150,104,236,105,67,105,154,105,241,106,72,106,159,106,247,107,79,107,167,107,255,108,87,108,175,109,8,109,96,109,185,110,18,110,107,110,196,111,30,111,120,111,209,112,43,112,134,112,224,113,58,113,149,113,240,114,75,114,166,115,1,115,93,115,184,116,20,116,112,116,204,117,40,117,133,117,225,118,62,118,155,118,248,119,86,119,179,120,17,120,110,120,204,121,42,121,137,121,231,122,70,122,165,123,4,123,99,123,194,124,33,124,129,124,225,125,65,125,161,126,1,126,98,126,194,127,35,127,132,127,229,128,71,128,168,129,10,129,107,129,205,130,48,130,146,130,244,131,87,131,186,132,29,132,128,132,227,133,71,133,171,134,14,134,114,134,215,135,59,135,159,136,4,136,105,136,206,137,51,137,153,137,254,138,100,138,202,139,48,139,150,139,252,140,99,140,202,141,49,141,152,141,255,142,102,142,206,143,54,143,158,144,6,144,110,144,214,145,63,145,168,146,17,146,122,146,227,147,77,147,182,148,32,148,138,148,244,149,95,149,201,150,52,150,159,151,10,151,117,151,224,152,76,152,184,153,36,153,144,153,252,154,104,154,213,155,66,155,175,156,28,156,137,156,247,157,100,157,210,158,64,158,174,159,29,159,139,159,250,160,105,160,216,161,71,161,182,162,38,162,150,163,6,163,118,163,230,164,86,164,199,165,56,165,169,166,26,166,139,166,253,167,110,167,224,168,82,168,196,169,55,169,169,170,28,170,143,171,2,171,117,171,233,172,92,172,208,173,68,173,184,174,45,174,161,175,22,175,139,176,0,176,117,176,234,177,96,177,214,178,75,178,194,179,56,179,174,180,37,180,156,181,19,181,138,182,1,182,121,182,240,183,104,183,224,184,89,184,209,185,74,185,194,186,59,186,181,187,46,187,167,188,33,188,155,189,21,189,143,190,10,190,132,190,255,191,122,191,245,192,112,192,236,193,103,193,227,194,95,194,219,195,88,195,212,196,81,196,206,197,75,197,200,198,70,198,195,199,65,199,191,200,61,200,188,201,58,201,185,202,56,202,183,203,54,203,182,204,53,204,181,205,53,205,181,206,54,206,182,207,55,207,184,208,57,208,186,209,60,209,190,210,63,210,193,211,68,211,198,212,73,212,203,213,78,213,209,214,85,214,216,215,92,215,224,216,100,216,232,217,108,217,241,218,118,218,251,219,128,220,5,220,138,221,16,221,150,222,28,222,162,223,41,223,175,224,54,224,189,225,68,225,204,226,83,226,219,227,99,227,235,228,115,228,252,229,132,230,13,230,150,231,31,231,169,232,50,232,188,233,70,233,208,234,91,234,229,235,112,235,251,236,134,237,17,237,156,238,40,238,180,239,64,239,204,240,88,240,229,241,114,241,255,242,140,243,25,243,167,244,52,244,194,245,80,245,222,246,109,246,251,247,138,248,25,248,168,249,56,249,199,250,87,250,231,251,119,252,7,252,152,253,41,253,186,254,75,254,220,255,109,255,255,255,219,0,67,0,3,2,2,3,2,2,3,3,3,3,4,3,3,4,5,8,5,5,4,4,5,10,7,7,6,8,12,10,12,12,11,10,11,11,13,14,18,16,13,14,17,14,11,11,16,22,16,17,19,20,21,21,21,12,15,23,24,22,20,24,18,20,21,20,255,219,0,67,1,3,4,4,5,4,5,9,5,5,9,20,13,11,13,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,255,192,0,17,8,0,64,0,64,3,1,17,0,2,17,1,3,17,1,255,196,0,24,0,0,3,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,6,255,196,0,39,16,0,2,1,4,1,3,4,3,1,1,0,0,0,0,0,0,1,2,17,0,3,18,33,49,19,34,65,81,97,113,145,50,66,129,82,161,255,196,0,25,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,2,0,3,5,8,255,196,0,39,17,1,0,2,2,3,0,2,0,5,5,0,0,0,0,0,0,1,0,17,2,33,18,49,65,34,81,3,19,50,97,161,113,129,177,193,225,255,218,0,12,3,1,0,2,17,3,17,0,63,0,233,186,118,144,100,206,92,206,33,154,190,170,188,157,19,195,87,207,233,17,47,113,206,54,215,166,53,196,154,218,13,187,153,165,239,100,180,178,206,87,146,0,225,142,133,75,144,66,233,197,250,136,173,156,149,109,140,154,76,147,177,77,229,219,42,242,208,178,19,181,14,36,130,76,146,218,170,123,220,195,203,30,79,189,193,109,179,156,138,174,181,218,102,133,13,66,206,188,154,178,185,82,12,49,115,194,234,7,205,77,151,11,11,241,255,0,83,55,118,48,150,242,65,198,74,124,85,1,219,22,154,77,201,202,211,228,67,99,26,2,121,167,228,76,153,241,125,169,99,170,35,16,182,148,207,119,154,159,143,187,148,56,228,158,201,104,96,193,153,174,1,162,194,68,213,26,134,58,50,196,212,8,4,49,128,139,192,21,166,216,164,59,156,149,134,129,160,14,192,21,180,67,91,73,164,56,32,28,79,175,129,83,169,95,23,83,62,144,196,240,236,76,24,106,110,65,147,84,202,68,101,10,8,107,74,1,16,15,53,150,255,0,120,226,153,7,189,144,82,221,41,22,131,23,227,33,0,80,213,247,48,107,141,247,212,58,66,218,175,104,203,230,69,55,112,199,45,3,228,32,169,115,192,3,126,132,252,81,220,90,50,71,170,146,183,11,144,122,152,123,20,144,106,146,188,148,227,96,213,198,75,34,48,202,7,152,16,13,26,89,2,56,172,107,104,207,123,170,70,206,255,0,230,235,47,209,58,94,238,174,72,10,177,34,79,130,12,255,0,105,219,39,27,116,119,5,184,216,194,226,87,201,138,200,94,230,1,41,212,29,206,86,213,216,136,229,99,85,131,186,143,19,227,93,68,164,44,220,237,30,130,43,59,248,205,177,182,95,69,140,23,18,102,101,76,197,79,35,201,47,208,205,12,185,197,152,173,177,185,0,73,169,235,103,112,42,239,31,38,65,212,98,168,142,109,141,153,82,102,174,158,215,115,31,42,183,113,146,24,106,210,31,39,63,31,117,186,246,86,206,222,228,130,21,114,65,150,137,102,93,199,181,61,180,195,45,87,41,99,170,0,56,18,231,137,58,3,224,84,252,95,117,51,199,29,253,196,165,118,199,169,153,34,10,236,86,111,175,36,3,141,213,35,2,217,48,148,46,7,44,7,52,213,123,45,7,166,160,182,13,211,144,148,19,38,107,114,13,74,252,206,185,72,22,193,114,28,224,36,228,224,159,170,87,90,155,22,242,229,143,247,37,165,216,102,91,96,192,17,63,149,14,58,188,160,98,42,127,201,55,9,113,176,24,147,5,128,138,77,72,235,227,122,154,92,182,2,141,170,5,51,174,106,71,114,191,17,172,105,242,46,147,230,165,161,217,183,36,196,10,214,86,165,99,144,229,95,114,16,220,134,97,122,124,5,198,5,83,93,84,14,57,15,44,101,5,103,79,11,227,216,123,212,216,50,31,129,247,228,78,200,128,130,11,21,255,0,58,20,130,206,182,213,158,65,89,141,176,172,228,169,50,64,17,89,11,176,145,150,26,176,166,53,44,234,229,1,233,131,250,86,209,87,220,57,2,228,194,213,142,225,12,109,137,156,88,243,67,151,237,114,141,188,82,254,164,48,92,137,86,152,231,186,9,53,69,251,54,57,242,43,62,163,182,172,228,220,184,172,60,119,31,20,52,104,136,85,35,46,2,160,13,12,79,2,216,143,186,59,117,4,215,199,249,137,202,140,138,184,0,122,152,36,252,86,47,210,97,239,12,205,49,33,99,44,247,1,243,140,82,215,65,39,18,172,72,22,5,96,184,18,63,105,136,173,85,46,154,168,4,103,73,68,33,71,236,218,173,96,237,147,200,227,76,172,21,100,221,49,224,8,153,162,215,88,203,197,240,145,108,33,200,91,44,96,255,0,5,83,126,206,63,34,212,233,149,125,148,66,23,11,191,59,6,140,71,186,157,27,63,73,100,46,28,218,50,96,119,51,197,96,162,13,136,155,168,130,90,180,87,125,220,243,170,215,147,43,110,188,238,29,91,154,96,129,73,227,29,79,189,110,39,87,39,19,27,219,166,81,188,70,69,152,134,58,146,186,163,143,212,223,150,226,184,155,146,240,206,3,247,145,198,2,105,58,212,45,191,143,243,7,115,105,37,159,33,199,227,17,88,45,209,43,48,67,32,166,34,110,50,16,85,48,35,133,59,250,167,67,10,55,227,29,188,150,74,7,51,234,146,62,232,107,216,209,151,234,255,0,51,255,217, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/Shaders/Basic/core.frag b/src/Nazara/Graphics/Resources/Shaders/Basic/core.frag deleted file mode 100644 index 9002e9ded..000000000 --- a/src/Nazara/Graphics/Resources/Shaders/Basic/core.frag +++ /dev/null @@ -1,49 +0,0 @@ -#if EARLY_FRAGMENT_TESTS && !ALPHA_TEST -layout(early_fragment_tests) in; -#endif - -/********************Entrant********************/ -in vec4 vColor; -in vec2 vTexCoord; - -/********************Sortant********************/ -out vec4 RenderTarget0; - -/********************Uniformes********************/ -uniform vec2 InvTargetSize; -uniform sampler2D MaterialAlphaMap; -uniform float MaterialAlphaThreshold; -uniform vec4 MaterialDiffuse; -uniform sampler2D MaterialDiffuseMap; -uniform sampler2D TextureOverlay; - -/********************Fonctions********************/ -void main() -{ - vec4 fragmentColor = MaterialDiffuse * vColor; - -#if AUTO_TEXCOORDS - vec2 texCoord = gl_FragCoord.xy * InvTargetSize; -#elif TEXTURE_MAPPING - vec2 texCoord = vTexCoord; -#endif - -#if DIFFUSE_MAPPING - fragmentColor *= texture(MaterialDiffuseMap, texCoord); -#endif - -#if ALPHA_MAPPING - fragmentColor.a *= texture(MaterialAlphaMap, texCoord).r; -#endif - -#if FLAG_TEXTUREOVERLAY - fragmentColor *= texture(TextureOverlay, texCoord); -#endif - -#if ALPHA_TEST - if (fragmentColor.a < MaterialAlphaThreshold) - discard; -#endif - - RenderTarget0 = fragmentColor; -} \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/Shaders/Basic/core.frag.h b/src/Nazara/Graphics/Resources/Shaders/Basic/core.frag.h deleted file mode 100644 index e4f7a19c5..000000000 --- a/src/Nazara/Graphics/Resources/Shaders/Basic/core.frag.h +++ /dev/null @@ -1 +0,0 @@ -35,105,102,32,69,65,82,76,89,95,70,82,65,71,77,69,78,84,95,84,69,83,84,83,32,38,38,32,33,65,76,80,72,65,95,84,69,83,84,10,108,97,121,111,117,116,40,101,97,114,108,121,95,102,114,97,103,109,101,110,116,95,116,101,115,116,115,41,32,105,110,59,10,35,101,110,100,105,102,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,105,110,32,118,101,99,52,32,118,67,111,108,111,114,59,10,105,110,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,84,101,120,116,117,114,101,79,118,101,114,108,97,121,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,32,42,32,118,67,111,108,111,114,59,10,10,35,105,102,32,65,85,84,79,95,84,69,88,67,79,79,82,68,83,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,10,35,101,108,105,102,32,84,69,88,84,85,82,69,95,77,65,80,80,73,78,71,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,118,84,101,120,67,111,111,114,100,59,10,35,101,110,100,105,102,10,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,116,101,120,67,111,111,114,100,41,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,59,10,35,101,110,100,105,102,10,10,35,105,102,32,70,76,65,71,95,84,69,88,84,85,82,69,79,86,69,82,76,65,89,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,84,101,120,116,117,114,101,79,118,101,114,108,97,121,44,32,116,101,120,67,111,111,114,100,41,59,10,35,101,110,100,105,102,10,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,10,9,9,100,105,115,99,97,114,100,59,10,35,101,110,100,105,102,10,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,10,125, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/Shaders/Basic/core.vert b/src/Nazara/Graphics/Resources/Shaders/Basic/core.vert deleted file mode 100644 index 2f1db5868..000000000 --- a/src/Nazara/Graphics/Resources/Shaders/Basic/core.vert +++ /dev/null @@ -1,103 +0,0 @@ -/********************Entrant********************/ -#if FLAG_BILLBOARD -in vec3 InstanceData0; // center -in vec4 InstanceData1; // size | sin cos -in vec4 InstanceData2; // color -#else -in mat4 InstanceData0; -#endif - -in vec4 VertexColor; -in vec3 VertexPosition; -in vec2 VertexTexCoord; -in vec4 VertexUserdata0; - -/********************Sortant********************/ -out vec4 vColor; -out vec2 vTexCoord; - -/********************Uniformes********************/ -uniform float VertexDepth; -uniform mat4 ViewMatrix; -uniform mat4 ViewProjMatrix; -uniform mat4 WorldViewProjMatrix; - -/********************Fonctions********************/ -void main() -{ -#if FLAG_VERTEXCOLOR - vec4 color = VertexColor; -#else - vec4 color = vec4(1.0); -#endif - - vec2 texCoords; - -#if FLAG_BILLBOARD - #if FLAG_INSTANCING - vec3 billboardCenter = InstanceData0; - vec2 billboardSize = InstanceData1.xy; - vec2 billboardSinCos = InstanceData1.zw; - vec4 billboardColor = InstanceData2; - - vec2 rotatedPosition; - rotatedPosition.x = VertexPosition.x*billboardSinCos.y - VertexPosition.y*billboardSinCos.x; - rotatedPosition.y = VertexPosition.y*billboardSinCos.y + VertexPosition.x*billboardSinCos.x; - rotatedPosition *= billboardSize; - - vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]); - vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]); - vec3 vertexPos = billboardCenter + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y; - - gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0); - color = billboardColor; - texCoords = VertexPosition.xy + 0.5; - #else - vec2 billboardCorner = VertexTexCoord - 0.5; - vec2 billboardSize = VertexUserdata0.xy; - vec2 billboardSinCos = VertexUserdata0.zw; - - vec2 rotatedPosition; - rotatedPosition.x = billboardCorner.x*billboardSinCos.y - billboardCorner.y*billboardSinCos.x; - rotatedPosition.y = billboardCorner.y*billboardSinCos.y + billboardCorner.x*billboardSinCos.x; - rotatedPosition *= billboardSize; - - vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]); - vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]); - vec3 vertexPos = VertexPosition + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y; - - gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0); - texCoords = VertexTexCoord; - #endif - texCoords.y = 1.0 - texCoords.y; -#else - #if FLAG_INSTANCING - #if TRANSFORM - gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0); - #else - #if UNIFORM_VERTEX_DEPTH - gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0); - #else - gl_Position = InstanceData0 * vec4(VertexPosition, 1.0); - #endif - #endif - #else - #if TRANSFORM - gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0); - #else - #if UNIFORM_VERTEX_DEPTH - gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0); - #else - gl_Position = vec4(VertexPosition, 1.0); - #endif - #endif - #endif - - texCoords = VertexTexCoord; -#endif - - vColor = color; -#if TEXTURE_MAPPING - vTexCoord = vec2(texCoords); -#endif -} diff --git a/src/Nazara/Graphics/Resources/Shaders/Basic/core.vert.h b/src/Nazara/Graphics/Resources/Shaders/Basic/core.vert.h deleted file mode 100644 index 993c7291b..000000000 --- a/src/Nazara/Graphics/Resources/Shaders/Basic/core.vert.h +++ /dev/null @@ -1 +0,0 @@ -47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,35,105,102,32,70,76,65,71,95,66,73,76,76,66,79,65,82,68,10,105,110,32,118,101,99,51,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,32,47,47,32,99,101,110,116,101,114,10,105,110,32,118,101,99,52,32,73,110,115,116,97,110,99,101,68,97,116,97,49,59,32,47,47,32,115,105,122,101,32,124,32,115,105,110,32,99,111,115,10,105,110,32,118,101,99,52,32,73,110,115,116,97,110,99,101,68,97,116,97,50,59,32,47,47,32,99,111,108,111,114,10,35,101,108,115,101,10,105,110,32,109,97,116,52,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,10,35,101,110,100,105,102,10,10,105,110,32,118,101,99,52,32,86,101,114,116,101,120,67,111,108,111,114,59,10,105,110,32,118,101,99,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,10,105,110,32,118,101,99,50,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,10,105,110,32,118,101,99,52,32,86,101,114,116,101,120,85,115,101,114,100,97,116,97,48,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,111,117,116,32,118,101,99,52,32,118,67,111,108,111,114,59,10,111,117,116,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,86,101,114,116,101,120,68,101,112,116,104,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,77,97,116,114,105,120,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,35,105,102,32,70,76,65,71,95,86,69,82,84,69,88,67,79,76,79,82,10,9,118,101,99,52,32,99,111,108,111,114,32,61,32,86,101,114,116,101,120,67,111,108,111,114,59,10,35,101,108,115,101,10,9,118,101,99,52,32,99,111,108,111,114,32,61,32,118,101,99,52,40,49,46,48,41,59,10,35,101,110,100,105,102,10,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,115,59,10,10,35,105,102,32,70,76,65,71,95,66,73,76,76,66,79,65,82,68,10,9,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,10,9,118,101,99,51,32,98,105,108,108,98,111,97,114,100,67,101,110,116,101,114,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,83,105,122,101,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,49,46,120,121,59,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,49,46,122,119,59,10,9,118,101,99,52,32,98,105,108,108,98,111,97,114,100,67,111,108,111,114,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,50,59,10,10,9,118,101,99,50,32,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,120,32,61,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,121,32,45,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,120,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,121,32,61,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,121,32,43,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,120,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,32,42,61,32,98,105,108,108,98,111,97,114,100,83,105,122,101,59,10,10,9,118,101,99,51,32,99,97,109,101,114,97,82,105,103,104,116,32,61,32,118,101,99,51,40,86,105,101,119,77,97,116,114,105,120,91,48,93,91,48,93,44,32,86,105,101,119,77,97,116,114,105,120,91,49,93,91,48,93,44,32,86,105,101,119,77,97,116,114,105,120,91,50,93,91,48,93,41,59,10,9,118,101,99,51,32,99,97,109,101,114,97,85,112,32,61,32,118,101,99,51,40,86,105,101,119,77,97,116,114,105,120,91,48,93,91,49,93,44,32,86,105,101,119,77,97,116,114,105,120,91,49,93,91,49,93,44,32,86,105,101,119,77,97,116,114,105,120,91,50,93,91,49,93,41,59,10,9,118,101,99,51,32,118,101,114,116,101,120,80,111,115,32,61,32,98,105,108,108,98,111,97,114,100,67,101,110,116,101,114,32,43,32,99,97,109,101,114,97,82,105,103,104,116,42,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,120,32,43,32,99,97,109,101,114,97,85,112,42,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,121,59,10,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,118,101,114,116,101,120,80,111,115,44,32,49,46,48,41,59,10,9,99,111,108,111,114,32,61,32,98,105,108,108,98,111,97,114,100,67,111,108,111,114,59,10,9,116,101,120,67,111,111,114,100,115,32,61,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,32,43,32,48,46,53,59,10,9,35,101,108,115,101,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,32,61,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,32,45,32,48,46,53,59,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,83,105,122,101,32,61,32,86,101,114,116,101,120,85,115,101,114,100,97,116,97,48,46,120,121,59,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,32,61,32,86,101,114,116,101,120,85,115,101,114,100,97,116,97,48,46,122,119,59,10,9,10,9,118,101,99,50,32,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,120,32,61,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,46,120,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,121,32,45,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,46,121,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,120,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,121,32,61,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,46,121,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,121,32,43,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,46,120,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,120,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,32,42,61,32,98,105,108,108,98,111,97,114,100,83,105,122,101,59,10,10,9,118,101,99,51,32,99,97,109,101,114,97,82,105,103,104,116,32,61,32,118,101,99,51,40,86,105,101,119,77,97,116,114,105,120,91,48,93,91,48,93,44,32,86,105,101,119,77,97,116,114,105,120,91,49,93,91,48,93,44,32,86,105,101,119,77,97,116,114,105,120,91,50,93,91,48,93,41,59,10,9,118,101,99,51,32,99,97,109,101,114,97,85,112,32,61,32,118,101,99,51,40,86,105,101,119,77,97,116,114,105,120,91,48,93,91,49,93,44,32,86,105,101,119,77,97,116,114,105,120,91,49,93,91,49,93,44,32,86,105,101,119,77,97,116,114,105,120,91,50,93,91,49,93,41,59,10,9,118,101,99,51,32,118,101,114,116,101,120,80,111,115,32,61,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,32,43,32,99,97,109,101,114,97,82,105,103,104,116,42,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,120,32,43,32,99,97,109,101,114,97,85,112,42,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,121,59,10,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,118,101,114,116,101,120,80,111,115,44,32,49,46,48,41,59,10,9,116,101,120,67,111,111,114,100,115,32,61,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,10,9,35,101,110,100,105,102,10,9,116,101,120,67,111,111,114,100,115,46,121,32,61,32,49,46,48,32,45,32,116,101,120,67,111,111,114,100,115,46,121,59,10,35,101,108,115,101,10,9,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,10,9,9,35,105,102,32,84,82,65,78,83,70,79,82,77,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,9,9,35,101,108,115,101,10,9,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,10,9,9,9,35,101,108,115,101,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,9,9,9,35,101,110,100,105,102,10,9,9,35,101,110,100,105,102,10,9,35,101,108,115,101,10,9,9,35,105,102,32,84,82,65,78,83,70,79,82,77,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,9,9,35,101,108,115,101,10,9,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,10,9,9,9,35,101,108,115,101,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,9,9,9,35,101,110,100,105,102,10,9,9,35,101,110,100,105,102,10,9,35,101,110,100,105,102,10,10,9,116,101,120,67,111,111,114,100,115,32,61,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,10,35,101,110,100,105,102,10,10,9,118,67,111,108,111,114,32,61,32,99,111,108,111,114,59,10,35,105,102,32,84,69,88,84,85,82,69,95,77,65,80,80,73,78,71,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,116,101,120,67,111,111,114,100,115,41,59,10,35,101,110,100,105,102,10,125,10, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag b/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag deleted file mode 100644 index 560ca4c29..000000000 --- a/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag +++ /dev/null @@ -1,475 +0,0 @@ -#if EARLY_FRAGMENT_TESTS && !ALPHA_TEST -layout(early_fragment_tests) in; -#endif - -// HACK UNTIL PROPER FIX -#if GLSL_VERSION < 400 - #undef SHADOW_MAPPING - #define SHADOW_MAPPING 0 -#endif -// HACK - -#define LIGHT_DIRECTIONAL 0 -#define LIGHT_POINT 1 -#define LIGHT_SPOT 2 - -/********************Entrant********************/ -in vec4 vColor; -in vec4 vLightSpacePos[3]; -in mat3 vLightToWorld; -in vec3 vNormal; -in vec2 vTexCoord; -in vec3 vViewDir; -in vec3 vWorldPos; - -/********************Sortant********************/ -out vec4 RenderTarget0; -out vec4 RenderTarget1; -out vec4 RenderTarget2; - -/********************Uniformes********************/ -struct Light -{ - int type; - vec4 color; - vec2 factors; - - vec4 parameters1; - vec4 parameters2; - vec2 parameters3; - bool shadowMapping; -}; - -// Lumières -uniform Light Lights[3]; -uniform samplerCube PointLightShadowMap[3]; -uniform sampler2D DirectionalSpotLightShadowMap[3]; - -// Matériau -uniform sampler2D MaterialAlphaMap; -uniform float MaterialAlphaThreshold; -uniform vec4 MaterialAmbient; -uniform vec4 MaterialDiffuse; -uniform sampler2D MaterialDiffuseMap; -uniform sampler2D MaterialEmissiveMap; -uniform sampler2D MaterialHeightMap; -uniform sampler2D MaterialNormalMap; -uniform float MaterialShininess; -uniform vec4 MaterialSpecular; -uniform sampler2D MaterialSpecularMap; - -// Autres -uniform float ParallaxBias = -0.03; -uniform float ParallaxScale = 0.02; -uniform vec2 InvTargetSize; -uniform vec3 EyePosition; -uniform samplerCube ReflectionMap; -uniform vec4 SceneAmbient; - -uniform sampler2D TextureOverlay; - -/********************Fonctions********************/ - -#define kPI 3.1415926536 - -vec4 EncodeNormal(in vec3 normal) -{ - //return vec4(normal*0.5 + 0.5, 0.0); - return vec4(vec2(atan(normal.y, normal.x)/kPI, normal.z), 0.0, 0.0); -} - -float VectorToDepthValue(vec3 vec, float zNear, float zFar) -{ - vec3 absVec = abs(vec); - float localZ = max(absVec.x, max(absVec.y, absVec.z)); - - float normZ = ((zFar + zNear) * localZ - (2.0*zFar*zNear)) / ((zFar - zNear)*localZ); - return (normZ + 1.0) * 0.5; -} - -#if SHADOW_MAPPING -float CalculateDirectionalShadowFactor(int lightIndex) -{ - vec4 lightSpacePos = vLightSpacePos[lightIndex]; - return (texture(DirectionalSpotLightShadowMap[lightIndex], lightSpacePos.xy).x >= (lightSpacePos.z - 0.0005)) ? 1.0 : 0.0; -} - -float CalculatePointShadowFactor(int lightIndex, vec3 lightToWorld, float zNear, float zFar) -{ - return (texture(PointLightShadowMap[lightIndex], vec3(lightToWorld.x, -lightToWorld.y, -lightToWorld.z)).x >= VectorToDepthValue(lightToWorld, zNear, zFar)) ? 1.0 : 0.0; -} - -float CalculateSpotShadowFactor(int lightIndex) -{ - vec4 lightSpacePos = vLightSpacePos[lightIndex]; - - float visibility = 1.0; - float x,y; - for (y = -3.5; y <= 3.5; y+= 1.0) - for (x = -3.5; x <= 3.5; x+= 1.0) - visibility += (textureProj(DirectionalSpotLightShadowMap[lightIndex], lightSpacePos.xyw + vec3(x/1024.0 * lightSpacePos.w, y/1024.0 * lightSpacePos.w, 0.0)).x >= (lightSpacePos.z - 0.0005)/lightSpacePos.w) ? 1.0 : 0.0; - - visibility /= 64.0; - - return visibility; -} -#endif - -void main() -{ - vec4 diffuseColor = MaterialDiffuse * vColor; - -#if AUTO_TEXCOORDS - vec2 texCoord = gl_FragCoord.xy * InvTargetSize; -#else - vec2 texCoord = vTexCoord; -#endif - -#if PARALLAX_MAPPING - float height = texture(MaterialHeightMap, texCoord).r; - float v = height*ParallaxScale + ParallaxBias; - - vec3 viewDir = normalize(vViewDir); - texCoord += v * viewDir.xy; -#endif - -#if DIFFUSE_MAPPING - diffuseColor *= texture(MaterialDiffuseMap, texCoord); -#endif - -#if FLAG_TEXTUREOVERLAY - diffuseColor *= texture(TextureOverlay, texCoord); -#endif - -#if FLAG_DEFERRED - #if ALPHA_TEST - // Inutile de faire de l'alpha-mapping sans alpha-test en Deferred (l'alpha n'est pas sauvegardé dans le G-Buffer) - #if ALPHA_MAPPING - diffuseColor.a *= texture(MaterialAlphaMap, texCoord).r; - #endif - - if (diffuseColor.a < MaterialAlphaThreshold) - discard; - #endif // ALPHA_TEST - - #if NORMAL_MAPPING - vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 1.0)); - #else - vec3 normal = normalize(vNormal); - #endif // NORMAL_MAPPING - - vec3 specularColor = MaterialSpecular.rgb; - #if SPECULAR_MAPPING - specularColor *= texture(MaterialSpecularMap, texCoord).rgb; - #endif - - /* - Texture0: Diffuse Color + Specular - Texture1: Normal + Specular - Texture2: Encoded depth + Shininess - */ - RenderTarget0 = vec4(diffuseColor.rgb, dot(specularColor, vec3(0.3, 0.59, 0.11))); - RenderTarget1 = vec4(EncodeNormal(normal)); - RenderTarget2 = vec4(0.0, 0.0, 0.0, (MaterialShininess == 0.0) ? 0.0 : max(log2(MaterialShininess), 0.1)/10.5); // http://www.guerrilla-games.com/publications/dr_kz2_rsx_dev07.pdf -#else // FLAG_DEFERRED - #if ALPHA_MAPPING - diffuseColor.a *= texture(MaterialAlphaMap, texCoord).r; - #endif - - #if ALPHA_TEST - if (diffuseColor.a < MaterialAlphaThreshold) - discard; - #endif - - vec3 lightAmbient = vec3(0.0); - vec3 lightDiffuse = vec3(0.0); - vec3 lightSpecular = vec3(0.0); - - #if NORMAL_MAPPING - vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 1.0)); - #else - vec3 normal = normalize(vNormal); - #endif - - if (MaterialShininess > 0.0) - { - vec3 eyeVec = normalize(EyePosition - vWorldPos); - - for (int i = 0; i < 3; ++i) - { - vec4 lightColor = Lights[i].color; - float lightAmbientFactor = Lights[i].factors.x; - float lightDiffuseFactor = Lights[i].factors.y; - - switch (Lights[i].type) - { - case LIGHT_DIRECTIONAL: - { - vec3 lightDir = -Lights[i].parameters1.xyz; - - // Ambient - lightAmbient += lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb); - - float att = 1.0; - - #if SHADOW_MAPPING - if (Lights[i].shadowMapping) - { - float shadowFactor = CalculateDirectionalShadowFactor(i); - if (shadowFactor == 0.0) - break; - - att *= shadowFactor; - } - #endif - - // Diffuse - float lambert = max(dot(normal, lightDir), 0.0); - - lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor; - - // Specular - vec3 reflection = reflect(-lightDir, normal); - float specularFactor = max(dot(reflection, eyeVec), 0.0); - specularFactor = pow(specularFactor, MaterialShininess); - - lightSpecular += att * specularFactor * lightColor.rgb; - break; - } - - case LIGHT_POINT: - { - vec3 lightPos = Lights[i].parameters1.xyz; - float lightAttenuation = Lights[i].parameters1.w; - float lightInvRadius = Lights[i].parameters2.w; - - vec3 worldToLight = lightPos - vWorldPos; - float lightDirLength = length(worldToLight); - vec3 lightDir = worldToLight / lightDirLength; // Normalisation - - float att = max(lightAttenuation - lightInvRadius * lightDirLength, 0.0); - - // Ambient - lightAmbient += att * lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb); - - #if SHADOW_MAPPING - if (Lights[i].shadowMapping) - { - float shadowFactor = CalculatePointShadowFactor(i, vWorldPos - lightPos, 0.1, 50.0); - if (shadowFactor == 0.0) - break; - - att *= shadowFactor; - } - #endif - - // Diffuse - float lambert = max(dot(normal, lightDir), 0.0); - - lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor; - - // Specular - vec3 reflection = reflect(-lightDir, normal); - float specularFactor = max(dot(reflection, eyeVec), 0.0); - specularFactor = pow(specularFactor, MaterialShininess); - - lightSpecular += att * specularFactor * lightColor.rgb; - break; - } - - case LIGHT_SPOT: - { - vec3 lightPos = Lights[i].parameters1.xyz; - vec3 lightDir = Lights[i].parameters2.xyz; - float lightAttenuation = Lights[i].parameters1.w; - float lightInvRadius = Lights[i].parameters2.w; - float lightInnerAngle = Lights[i].parameters3.x; - float lightOuterAngle = Lights[i].parameters3.y; - - vec3 worldToLight = lightPos - vWorldPos; - float lightDistance = length(worldToLight); - worldToLight /= lightDistance; // Normalisation - - float att = max(lightAttenuation - lightInvRadius * lightDistance, 0.0); - - // Ambient - lightAmbient += att * lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb); - - #if SHADOW_MAPPING - if (Lights[i].shadowMapping) - { - float shadowFactor = CalculateSpotShadowFactor(i); - if (shadowFactor == 0.0) - break; - - att *= shadowFactor; - } - #endif - - // Modification de l'atténuation pour gérer le spot - float curAngle = dot(lightDir, -worldToLight); - float innerMinusOuterAngle = lightInnerAngle - lightOuterAngle; - att *= max((curAngle - lightOuterAngle) / innerMinusOuterAngle, 0.0); - - // Diffuse - float lambert = max(dot(normal, worldToLight), 0.0); - - lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor; - - // Specular - vec3 reflection = reflect(-worldToLight, normal); - float specularFactor = max(dot(reflection, eyeVec), 0.0); - specularFactor = pow(specularFactor, MaterialShininess); - - lightSpecular += att * specularFactor * lightColor.rgb; - break; - } - - default: - break; - } - } - } - else - { - for (int i = 0; i < 3; ++i) - { - vec4 lightColor = Lights[i].color; - float lightAmbientFactor = Lights[i].factors.x; - float lightDiffuseFactor = Lights[i].factors.y; - - switch (Lights[i].type) - { - case LIGHT_DIRECTIONAL: - { - vec3 lightDir = -Lights[i].parameters1.xyz; - - // Ambient - lightAmbient += lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb); - - float att = 1.0; - - #if SHADOW_MAPPING - if (Lights[i].shadowMapping) - { - float shadowFactor = CalculateDirectionalShadowFactor(i); - if (shadowFactor == 0.0) - break; - - att *= shadowFactor; - } - #endif - - // Diffuse - float lambert = max(dot(normal, lightDir), 0.0); - - lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor; - break; - } - - case LIGHT_POINT: - { - vec3 lightPos = Lights[i].parameters1.xyz; - float lightAttenuation = Lights[i].parameters1.w; - float lightInvRadius = Lights[i].parameters2.w; - - vec3 worldToLight = lightPos - vWorldPos; - float lightDirLength = length(worldToLight); - vec3 lightDir = worldToLight / lightDirLength; // Normalisation - - float att = max(lightAttenuation - lightInvRadius * lightDirLength, 0.0); - - // Ambient - lightAmbient += att * lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb); - - #if SHADOW_MAPPING - if (Lights[i].shadowMapping) - { - float shadowFactor = CalculatePointShadowFactor(i, vWorldPos - lightPos, 0.1, 50.0); - if (shadowFactor == 0.0) - break; - - att *= shadowFactor; - } - #endif - - // Diffuse - float lambert = max(dot(normal, lightDir), 0.0); - - lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor; - break; - } - - case LIGHT_SPOT: - { - vec3 lightPos = Lights[i].parameters1.xyz; - vec3 lightDir = Lights[i].parameters2.xyz; - float lightAttenuation = Lights[i].parameters1.w; - float lightInvRadius = Lights[i].parameters2.w; - float lightInnerAngle = Lights[i].parameters3.x; - float lightOuterAngle = Lights[i].parameters3.y; - - vec3 worldToLight = lightPos - vWorldPos; - float lightDistance = length(worldToLight); - worldToLight /= lightDistance; // Normalisation - - float att = max(lightAttenuation - lightInvRadius * lightDistance, 0.0); - - // Ambient - lightAmbient += att * lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb); - - #if SHADOW_MAPPING - if (Lights[i].shadowMapping) - { - float shadowFactor = CalculateSpotShadowFactor(i); - if (shadowFactor == 0.0) - break; - - att *= shadowFactor; - } - #endif - - // Modification de l'atténuation pour gérer le spot - float curAngle = dot(lightDir, -worldToLight); - float innerMinusOuterAngle = lightInnerAngle - lightOuterAngle; - att *= max((curAngle - lightOuterAngle) / innerMinusOuterAngle, 0.0); - - // Diffuse - float lambert = max(dot(normal, worldToLight), 0.0); - - lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor; - } - - default: - break; - } - } - } - - lightSpecular *= MaterialSpecular.rgb; - #if SPECULAR_MAPPING - lightSpecular *= texture(MaterialSpecularMap, texCoord).rgb; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens - #endif - - vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular); - - #if REFLECTION_MAPPING - vec3 eyeVec = normalize(vWorldPos - EyePosition); - - vec3 reflected = normalize(reflect(eyeVec, normal)); - lightColor *= texture(ReflectionMap, reflected).rgb; - #endif - - vec4 fragmentColor = vec4(lightColor, 1.0) * diffuseColor; - - #if EMISSIVE_MAPPING - float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11)); - - vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, texCoord).rgb; - RenderTarget0 = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a); - #else - RenderTarget0 = fragmentColor; - #endif // EMISSIVE_MAPPING -#endif // FLAG_DEFERRED -} - diff --git a/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h b/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h deleted file mode 100644 index 555144993..000000000 --- a/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h +++ /dev/null @@ -1 +0,0 @@ -35,105,102,32,69,65,82,76,89,95,70,82,65,71,77,69,78,84,95,84,69,83,84,83,32,38,38,32,33,65,76,80,72,65,95,84,69,83,84,13,10,108,97,121,111,117,116,40,101,97,114,108,121,95,102,114,97,103,109,101,110,116,95,116,101,115,116,115,41,32,105,110,59,13,10,35,101,110,100,105,102,13,10,13,10,47,47,32,72,65,67,75,32,85,78,84,73,76,32,80,82,79,80,69,82,32,70,73,88,13,10,35,105,102,32,71,76,83,76,95,86,69,82,83,73,79,78,32,60,32,52,48,48,13,10,9,35,117,110,100,101,102,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,13,10,9,35,100,101,102,105,110,101,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,32,48,13,10,35,101,110,100,105,102,13,10,47,47,32,72,65,67,75,13,10,13,10,35,100,101,102,105,110,101,32,76,73,71,72,84,95,68,73,82,69,67,84,73,79,78,65,76,32,48,13,10,35,100,101,102,105,110,101,32,76,73,71,72,84,95,80,79,73,78,84,32,49,13,10,35,100,101,102,105,110,101,32,76,73,71,72,84,95,83,80,79,84,32,50,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,105,110,32,118,101,99,52,32,118,67,111,108,111,114,59,13,10,105,110,32,118,101,99,52,32,118,76,105,103,104,116,83,112,97,99,101,80,111,115,91,51,93,59,13,10,105,110,32,109,97,116,51,32,118,76,105,103,104,116,84,111,87,111,114,108,100,59,13,10,105,110,32,118,101,99,51,32,118,78,111,114,109,97,108,59,13,10,105,110,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,105,110,32,118,101,99,51,32,118,86,105,101,119,68,105,114,59,13,10,105,110,32,118,101,99,51,32,118,87,111,114,108,100,80,111,115,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,49,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,50,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,115,116,114,117,99,116,32,76,105,103,104,116,13,10,123,13,10,9,105,110,116,32,116,121,112,101,59,13,10,9,118,101,99,52,32,99,111,108,111,114,59,13,10,9,118,101,99,50,32,102,97,99,116,111,114,115,59,13,10,13,10,9,118,101,99,52,32,112,97,114,97,109,101,116,101,114,115,49,59,13,10,9,118,101,99,52,32,112,97,114,97,109,101,116,101,114,115,50,59,13,10,9,118,101,99,50,32,112,97,114,97,109,101,116,101,114,115,51,59,13,10,9,98,111,111,108,32,115,104,97,100,111,119,77,97,112,112,105,110,103,59,13,10,125,59,13,10,13,10,47,47,32,76,117,109,105,195,168,114,101,115,13,10,117,110,105,102,111,114,109,32,76,105,103,104,116,32,76,105,103,104,116,115,91,51,93,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,67,117,98,101,32,80,111,105,110,116,76,105,103,104,116,83,104,97,100,111,119,77,97,112,91,51,93,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,68,105,114,101,99,116,105,111,110,97,108,83,112,111,116,76,105,103,104,116,83,104,97,100,111,119,77,97,112,91,51,93,59,13,10,13,10,47,47,32,77,97,116,195,169,114,105,97,117,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,65,109,98,105,101,110,116,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,69,109,105,115,115,105,118,101,77,97,112,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,72,101,105,103,104,116,77,97,112,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,78,111,114,109,97,108,77,97,112,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,83,104,105,110,105,110,101,115,115,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,83,112,101,99,117,108,97,114,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,83,112,101,99,117,108,97,114,77,97,112,59,13,10,13,10,47,47,32,65,117,116,114,101,115,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,80,97,114,97,108,108,97,120,66,105,97,115,32,61,32,45,48,46,48,51,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,80,97,114,97,108,108,97,120,83,99,97,108,101,32,61,32,48,46,48,50,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,51,32,69,121,101,80,111,115,105,116,105,111,110,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,67,117,98,101,32,82,101,102,108,101,99,116,105,111,110,77,97,112,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,83,99,101,110,101,65,109,98,105,101,110,116,59,13,10,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,84,101,120,116,117,114,101,79,118,101,114,108,97,121,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,13,10,35,100,101,102,105,110,101,32,107,80,73,32,51,46,49,52,49,53,57,50,54,53,51,54,13,10,13,10,118,101,99,52,32,69,110,99,111,100,101,78,111,114,109,97,108,40,105,110,32,118,101,99,51,32,110,111,114,109,97,108,41,13,10,123,13,10,9,47,47,114,101,116,117,114,110,32,118,101,99,52,40,110,111,114,109,97,108,42,48,46,53,32,43,32,48,46,53,44,32,48,46,48,41,59,13,10,9,114,101,116,117,114,110,32,118,101,99,52,40,118,101,99,50,40,97,116,97,110,40,110,111,114,109,97,108,46,121,44,32,110,111,114,109,97,108,46,120,41,47,107,80,73,44,32,110,111,114,109,97,108,46,122,41,44,32,48,46,48,44,32,48,46,48,41,59,13,10,125,13,10,13,10,102,108,111,97,116,32,86,101,99,116,111,114,84,111,68,101,112,116,104,86,97,108,117,101,40,118,101,99,51,32,118,101,99,44,32,102,108,111,97,116,32,122,78,101,97,114,44,32,102,108,111,97,116,32,122,70,97,114,41,13,10,123,13,10,9,118,101,99,51,32,97,98,115,86,101,99,32,61,32,97,98,115,40,118,101,99,41,59,13,10,9,102,108,111,97,116,32,108,111,99,97,108,90,32,61,32,109,97,120,40,97,98,115,86,101,99,46,120,44,32,109,97,120,40,97,98,115,86,101,99,46,121,44,32,97,98,115,86,101,99,46,122,41,41,59,13,10,13,10,9,102,108,111,97,116,32,110,111,114,109,90,32,61,32,40,40,122,70,97,114,32,43,32,122,78,101,97,114,41,32,42,32,108,111,99,97,108,90,32,45,32,40,50,46,48,42,122,70,97,114,42,122,78,101,97,114,41,41,32,47,32,40,40,122,70,97,114,32,45,32,122,78,101,97,114,41,42,108,111,99,97,108,90,41,59,13,10,9,114,101,116,117,114,110,32,40,110,111,114,109,90,32,43,32,49,46,48,41,32,42,32,48,46,53,59,13,10,125,13,10,13,10,35,105,102,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,13,10,102,108,111,97,116,32,67,97,108,99,117,108,97,116,101,68,105,114,101,99,116,105,111,110,97,108,83,104,97,100,111,119,70,97,99,116,111,114,40,105,110,116,32,108,105,103,104,116,73,110,100,101,120,41,13,10,123,13,10,9,118,101,99,52,32,108,105,103,104,116,83,112,97,99,101,80,111,115,32,61,32,118,76,105,103,104,116,83,112,97,99,101,80,111,115,91,108,105,103,104,116,73,110,100,101,120,93,59,13,10,9,114,101,116,117,114,110,32,40,116,101,120,116,117,114,101,40,68,105,114,101,99,116,105,111,110,97,108,83,112,111,116,76,105,103,104,116,83,104,97,100,111,119,77,97,112,91,108,105,103,104,116,73,110,100,101,120,93,44,32,108,105,103,104,116,83,112,97,99,101,80,111,115,46,120,121,41,46,120,32,62,61,32,40,108,105,103,104,116,83,112,97,99,101,80,111,115,46,122,32,45,32,48,46,48,48,48,53,41,41,32,63,32,49,46,48,32,58,32,48,46,48,59,13,10,125,13,10,13,10,102,108,111,97,116,32,67,97,108,99,117,108,97,116,101,80,111,105,110,116,83,104,97,100,111,119,70,97,99,116,111,114,40,105,110,116,32,108,105,103,104,116,73,110,100,101,120,44,32,118,101,99,51,32,108,105,103,104,116,84,111,87,111,114,108,100,44,32,102,108,111,97,116,32,122,78,101,97,114,44,32,102,108,111,97,116,32,122,70,97,114,41,13,10,123,13,10,9,114,101,116,117,114,110,32,40,116,101,120,116,117,114,101,40,80,111,105,110,116,76,105,103,104,116,83,104,97,100,111,119,77,97,112,91,108,105,103,104,116,73,110,100,101,120,93,44,32,118,101,99,51,40,108,105,103,104,116,84,111,87,111,114,108,100,46,120,44,32,45,108,105,103,104,116,84,111,87,111,114,108,100,46,121,44,32,45,108,105,103,104,116,84,111,87,111,114,108,100,46,122,41,41,46,120,32,62,61,32,86,101,99,116,111,114,84,111,68,101,112,116,104,86,97,108,117,101,40,108,105,103,104,116,84,111,87,111,114,108,100,44,32,122,78,101,97,114,44,32,122,70,97,114,41,41,32,63,32,49,46,48,32,58,32,48,46,48,59,13,10,125,13,10,13,10,102,108,111,97,116,32,67,97,108,99,117,108,97,116,101,83,112,111,116,83,104,97,100,111,119,70,97,99,116,111,114,40,105,110,116,32,108,105,103,104,116,73,110,100,101,120,41,13,10,123,13,10,9,118,101,99,52,32,108,105,103,104,116,83,112,97,99,101,80,111,115,32,61,32,118,76,105,103,104,116,83,112,97,99,101,80,111,115,91,108,105,103,104,116,73,110,100,101,120,93,59,13,10,13,10,9,102,108,111,97,116,32,118,105,115,105,98,105,108,105,116,121,32,61,32,49,46,48,59,13,10,9,102,108,111,97,116,32,120,44,121,59,13,10,9,102,111,114,32,40,121,32,61,32,45,51,46,53,59,32,121,32,60,61,32,51,46,53,59,32,121,43,61,32,49,46,48,41,13,10,9,9,102,111,114,32,40,120,32,61,32,45,51,46,53,59,32,120,32,60,61,32,51,46,53,59,32,120,43,61,32,49,46,48,41,13,10,9,9,9,118,105,115,105,98,105,108,105,116,121,32,43,61,32,40,116,101,120,116,117,114,101,80,114,111,106,40,68,105,114,101,99,116,105,111,110,97,108,83,112,111,116,76,105,103,104,116,83,104,97,100,111,119,77,97,112,91,108,105,103,104,116,73,110,100,101,120,93,44,32,108,105,103,104,116,83,112,97,99,101,80,111,115,46,120,121,119,32,43,32,118,101,99,51,40,120,47,49,48,50,52,46,48,32,42,32,108,105,103,104,116,83,112,97,99,101,80,111,115,46,119,44,32,121,47,49,48,50,52,46,48,32,42,32,108,105,103,104,116,83,112,97,99,101,80,111,115,46,119,44,32,48,46,48,41,41,46,120,32,62,61,32,40,108,105,103,104,116,83,112,97,99,101,80,111,115,46,122,32,45,32,48,46,48,48,48,53,41,47,108,105,103,104,116,83,112,97,99,101,80,111,115,46,119,41,32,63,32,49,46,48,32,58,32,48,46,48,59,13,10,13,10,9,118,105,115,105,98,105,108,105,116,121,32,47,61,32,54,52,46,48,59,13,10,9,13,10,9,114,101,116,117,114,110,32,118,105,115,105,98,105,108,105,116,121,59,13,10,125,13,10,35,101,110,100,105,102,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,52,32,100,105,102,102,117,115,101,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,32,42,32,118,67,111,108,111,114,59,13,10,13,10,35,105,102,32,65,85,84,79,95,84,69,88,67,79,79,82,68,83,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,35,101,108,115,101,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,118,84,101,120,67,111,111,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,80,65,82,65,76,76,65,88,95,77,65,80,80,73,78,71,13,10,9,102,108,111,97,116,32,104,101,105,103,104,116,32,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,72,101,105,103,104,116,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,59,13,10,9,102,108,111,97,116,32,118,32,61,32,104,101,105,103,104,116,42,80,97,114,97,108,108,97,120,83,99,97,108,101,32,43,32,80,97,114,97,108,108,97,120,66,105,97,115,59,13,10,13,10,9,118,101,99,51,32,118,105,101,119,68,105,114,32,61,32,110,111,114,109,97,108,105,122,101,40,118,86,105,101,119,68,105,114,41,59,13,10,9,116,101,120,67,111,111,114,100,32,43,61,32,118,32,42,32,118,105,101,119,68,105,114,46,120,121,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,100,105,102,102,117,115,101,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,116,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,70,76,65,71,95,84,69,88,84,85,82,69,79,86,69,82,76,65,89,13,10,9,100,105,102,102,117,115,101,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,84,101,120,116,117,114,101,79,118,101,114,108,97,121,44,32,116,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,9,35,105,102,32,65,76,80,72,65,95,84,69,83,84,13,10,9,9,47,47,32,73,110,117,116,105,108,101,32,100,101,32,102,97,105,114,101,32,100,101,32,108,39,97,108,112,104,97,45,109,97,112,112,105,110,103,32,115,97,110,115,32,97,108,112,104,97,45,116,101,115,116,32,101,110,32,68,101,102,101,114,114,101,100,32,40,108,39,97,108,112,104,97,32,110,39,101,115,116,32,112,97,115,32,115,97,117,118,101,103,97,114,100,195,169,32,100,97,110,115,32,108,101,32,71,45,66,117,102,102,101,114,41,13,10,9,9,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,13,10,9,100,105,102,102,117,115,101,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,59,13,10,9,9,35,101,110,100,105,102,13,10,9,9,13,10,9,105,102,32,40,100,105,102,102,117,115,101,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,13,10,9,9,100,105,115,99,97,114,100,59,13,10,9,35,101,110,100,105,102,32,47,47,32,65,76,80,72,65,95,84,69,83,84,13,10,13,10,9,35,105,102,32,78,79,82,77,65,76,95,77,65,80,80,73,78,71,13,10,9,118,101,99,51,32,110,111,114,109,97,108,32,61,32,110,111,114,109,97,108,105,122,101,40,118,76,105,103,104,116,84,111,87,111,114,108,100,32,42,32,40,50,46,48,32,42,32,118,101,99,51,40,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,78,111,114,109,97,108,77,97,112,44,32,116,101,120,67,111,111,114,100,41,41,32,45,32,49,46,48,41,41,59,13,10,9,35,101,108,115,101,13,10,9,118,101,99,51,32,110,111,114,109,97,108,32,61,32,110,111,114,109,97,108,105,122,101,40,118,78,111,114,109,97,108,41,59,13,10,9,35,101,110,100,105,102,32,47,47,32,78,79,82,77,65,76,95,77,65,80,80,73,78,71,13,10,13,10,9,118,101,99,51,32,115,112,101,99,117,108,97,114,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,83,112,101,99,117,108,97,114,46,114,103,98,59,13,10,9,35,105,102,32,83,80,69,67,85,76,65,82,95,77,65,80,80,73,78,71,13,10,9,115,112,101,99,117,108,97,114,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,83,112,101,99,117,108,97,114,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,103,98,59,13,10,9,35,101,110,100,105,102,13,10,13,10,9,47,42,13,10,9,84,101,120,116,117,114,101,48,58,32,68,105,102,102,117,115,101,32,67,111,108,111,114,32,43,32,83,112,101,99,117,108,97,114,13,10,9,84,101,120,116,117,114,101,49,58,32,78,111,114,109,97,108,32,43,32,83,112,101,99,117,108,97,114,13,10,9,84,101,120,116,117,114,101,50,58,32,69,110,99,111,100,101,100,32,100,101,112,116,104,32,43,32,83,104,105,110,105,110,101,115,115,13,10,9,42,47,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,100,105,102,102,117,115,101,67,111,108,111,114,46,114,103,98,44,32,100,111,116,40,115,112,101,99,117,108,97,114,67,111,108,111,114,44,32,118,101,99,51,40,48,46,51,44,32,48,46,53,57,44,32,48,46,49,49,41,41,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,49,32,61,32,118,101,99,52,40,69,110,99,111,100,101,78,111,114,109,97,108,40,110,111,114,109,97,108,41,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,50,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,40,77,97,116,101,114,105,97,108,83,104,105,110,105,110,101,115,115,32,61,61,32,48,46,48,41,32,63,32,48,46,48,32,58,32,109,97,120,40,108,111,103,50,40,77,97,116,101,114,105,97,108,83,104,105,110,105,110,101,115,115,41,44,32,48,46,49,41,47,49,48,46,53,41,59,32,47,47,32,104,116,116,112,58,47,47,119,119,119,46,103,117,101,114,114,105,108,108,97,45,103,97,109,101,115,46,99,111,109,47,112,117,98,108,105,99,97,116,105,111,110,115,47,100,114,95,107,122,50,95,114,115,120,95,100,101,118,48,55,46,112,100,102,13,10,35,101,108,115,101,32,47,47,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,9,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,13,10,9,100,105,102,102,117,115,101,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,59,13,10,9,35,101,110,100,105,102,13,10,13,10,9,35,105,102,32,65,76,80,72,65,95,84,69,83,84,13,10,9,105,102,32,40,100,105,102,102,117,115,101,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,13,10,9,9,100,105,115,99,97,114,100,59,13,10,9,35,101,110,100,105,102,13,10,13,10,9,118,101,99,51,32,108,105,103,104,116,65,109,98,105,101,110,116,32,61,32,118,101,99,51,40,48,46,48,41,59,13,10,9,118,101,99,51,32,108,105,103,104,116,68,105,102,102,117,115,101,32,61,32,118,101,99,51,40,48,46,48,41,59,13,10,9,118,101,99,51,32,108,105,103,104,116,83,112,101,99,117,108,97,114,32,61,32,118,101,99,51,40,48,46,48,41,59,13,10,13,10,9,35,105,102,32,78,79,82,77,65,76,95,77,65,80,80,73,78,71,13,10,9,118,101,99,51,32,110,111,114,109,97,108,32,61,32,110,111,114,109,97,108,105,122,101,40,118,76,105,103,104,116,84,111,87,111,114,108,100,32,42,32,40,50,46,48,32,42,32,118,101,99,51,40,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,78,111,114,109,97,108,77,97,112,44,32,116,101,120,67,111,111,114,100,41,41,32,45,32,49,46,48,41,41,59,13,10,9,35,101,108,115,101,13,10,9,118,101,99,51,32,110,111,114,109,97,108,32,61,32,110,111,114,109,97,108,105,122,101,40,118,78,111,114,109,97,108,41,59,13,10,9,35,101,110,100,105,102,13,10,13,10,9,105,102,32,40,77,97,116,101,114,105,97,108,83,104,105,110,105,110,101,115,115,32,62,32,48,46,48,41,13,10,9,123,13,10,9,9,118,101,99,51,32,101,121,101,86,101,99,32,61,32,110,111,114,109,97,108,105,122,101,40,69,121,101,80,111,115,105,116,105,111,110,32,45,32,118,87,111,114,108,100,80,111,115,41,59,13,10,13,10,9,9,102,111,114,32,40,105,110,116,32,105,32,61,32,48,59,32,105,32,60,32,51,59,32,43,43,105,41,13,10,9,9,123,13,10,9,9,9,118,101,99,52,32,108,105,103,104,116,67,111,108,111,114,32,61,32,76,105,103,104,116,115,91,105,93,46,99,111,108,111,114,59,13,10,9,9,9,102,108,111,97,116,32,108,105,103,104,116,65,109,98,105,101,110,116,70,97,99,116,111,114,32,61,32,76,105,103,104,116,115,91,105,93,46,102,97,99,116,111,114,115,46,120,59,13,10,9,9,9,102,108,111,97,116,32,108,105,103,104,116,68,105,102,102,117,115,101,70,97,99,116,111,114,32,61,32,76,105,103,104,116,115,91,105,93,46,102,97,99,116,111,114,115,46,121,59,13,10,13,10,9,9,9,115,119,105,116,99,104,32,40,76,105,103,104,116,115,91,105,93,46,116,121,112,101,41,13,10,9,9,9,123,13,10,9,9,9,9,99,97,115,101,32,76,73,71,72,84,95,68,73,82,69,67,84,73,79,78,65,76,58,13,10,9,9,9,9,123,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,68,105,114,32,61,32,45,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,120,121,122,59,13,10,13,10,9,9,9,9,9,47,47,32,65,109,98,105,101,110,116,13,10,9,9,9,9,9,108,105,103,104,116,65,109,98,105,101,110,116,32,43,61,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,65,109,98,105,101,110,116,70,97,99,116,111,114,32,42,32,40,77,97,116,101,114,105,97,108,65,109,98,105,101,110,116,46,114,103,98,32,43,32,83,99,101,110,101,65,109,98,105,101,110,116,46,114,103,98,41,59,13,10,13,10,9,9,9,9,9,102,108,111,97,116,32,97,116,116,32,61,32,49,46,48,59,13,10,13,10,9,9,9,9,9,35,105,102,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,13,10,9,9,9,9,9,105,102,32,40,76,105,103,104,116,115,91,105,93,46,115,104,97,100,111,119,77,97,112,112,105,110,103,41,13,10,9,9,9,9,9,123,13,10,9,9,9,9,9,9,102,108,111,97,116,32,115,104,97,100,111,119,70,97,99,116,111,114,32,61,32,67,97,108,99,117,108,97,116,101,68,105,114,101,99,116,105,111,110,97,108,83,104,97,100,111,119,70,97,99,116,111,114,40,105,41,59,13,10,9,9,9,9,9,9,105,102,32,40,115,104,97,100,111,119,70,97,99,116,111,114,32,61,61,32,48,46,48,41,13,10,9,9,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,9,9,9,13,10,9,9,9,9,9,9,97,116,116,32,42,61,32,115,104,97,100,111,119,70,97,99,116,111,114,59,13,10,9,9,9,9,9,125,13,10,9,9,9,9,9,35,101,110,100,105,102,13,10,13,10,9,9,9,9,9,47,47,32,68,105,102,102,117,115,101,13,10,9,9,9,9,9,102,108,111,97,116,32,108,97,109,98,101,114,116,32,61,32,109,97,120,40,100,111,116,40,110,111,114,109,97,108,44,32,108,105,103,104,116,68,105,114,41,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,108,105,103,104,116,68,105,102,102,117,115,101,32,43,61,32,97,116,116,32,42,32,108,97,109,98,101,114,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,68,105,102,102,117,115,101,70,97,99,116,111,114,59,13,10,13,10,9,9,9,9,9,47,47,32,83,112,101,99,117,108,97,114,13,10,9,9,9,9,9,118,101,99,51,32,114,101,102,108,101,99,116,105,111,110,32,61,32,114,101,102,108,101,99,116,40,45,108,105,103,104,116,68,105,114,44,32,110,111,114,109,97,108,41,59,13,10,9,9,9,9,9,102,108,111,97,116,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,109,97,120,40,100,111,116,40,114,101,102,108,101,99,116,105,111,110,44,32,101,121,101,86,101,99,41,44,32,48,46,48,41,59,13,10,9,9,9,9,9,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,112,111,119,40,115,112,101,99,117,108,97,114,70,97,99,116,111,114,44,32,77,97,116,101,114,105,97,108,83,104,105,110,105,110,101,115,115,41,59,13,10,13,10,9,9,9,9,9,108,105,103,104,116,83,112,101,99,117,108,97,114,32,43,61,32,97,116,116,32,42,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,59,13,10,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,125,13,10,13,10,9,9,9,9,99,97,115,101,32,76,73,71,72,84,95,80,79,73,78,84,58,13,10,9,9,9,9,123,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,80,111,115,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,120,121,122,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,65,116,116,101,110,117,97,116,105,111,110,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,119,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,73,110,118,82,97,100,105,117,115,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,50,46,119,59,13,10,9,9,9,9,9,13,10,9,9,9,9,9,118,101,99,51,32,119,111,114,108,100,84,111,76,105,103,104,116,32,61,32,108,105,103,104,116,80,111,115,32,45,32,118,87,111,114,108,100,80,111,115,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,68,105,114,76,101,110,103,116,104,32,61,32,108,101,110,103,116,104,40,119,111,114,108,100,84,111,76,105,103,104,116,41,59,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,68,105,114,32,61,32,119,111,114,108,100,84,111,76,105,103,104,116,32,47,32,108,105,103,104,116,68,105,114,76,101,110,103,116,104,59,32,47,47,32,78,111,114,109,97,108,105,115,97,116,105,111,110,13,10,9,9,9,9,9,13,10,9,9,9,9,9,102,108,111,97,116,32,97,116,116,32,61,32,109,97,120,40,108,105,103,104,116,65,116,116,101,110,117,97,116,105,111,110,32,45,32,108,105,103,104,116,73,110,118,82,97,100,105,117,115,32,42,32,108,105,103,104,116,68,105,114,76,101,110,103,116,104,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,47,47,32,65,109,98,105,101,110,116,13,10,9,9,9,9,9,108,105,103,104,116,65,109,98,105,101,110,116,32,43,61,32,97,116,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,65,109,98,105,101,110,116,70,97,99,116,111,114,32,42,32,40,77,97,116,101,114,105,97,108,65,109,98,105,101,110,116,46,114,103,98,32,43,32,83,99,101,110,101,65,109,98,105,101,110,116,46,114,103,98,41,59,13,10,13,10,9,9,9,9,9,35,105,102,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,13,10,9,9,9,9,9,105,102,32,40,76,105,103,104,116,115,91,105,93,46,115,104,97,100,111,119,77,97,112,112,105,110,103,41,13,10,9,9,9,9,9,123,13,10,9,9,9,9,9,9,102,108,111,97,116,32,115,104,97,100,111,119,70,97,99,116,111,114,32,61,32,67,97,108,99,117,108,97,116,101,80,111,105,110,116,83,104,97,100,111,119,70,97,99,116,111,114,40,105,44,32,118,87,111,114,108,100,80,111,115,32,45,32,108,105,103,104,116,80,111,115,44,32,48,46,49,44,32,53,48,46,48,41,59,13,10,9,9,9,9,9,9,105,102,32,40,115,104,97,100,111,119,70,97,99,116,111,114,32,61,61,32,48,46,48,41,13,10,9,9,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,9,9,9,13,10,9,9,9,9,9,9,97,116,116,32,42,61,32,115,104,97,100,111,119,70,97,99,116,111,114,59,13,10,9,9,9,9,9,125,13,10,9,9,9,9,9,35,101,110,100,105,102,13,10,13,10,9,9,9,9,9,47,47,32,68,105,102,102,117,115,101,13,10,9,9,9,9,9,102,108,111,97,116,32,108,97,109,98,101,114,116,32,61,32,109,97,120,40,100,111,116,40,110,111,114,109,97,108,44,32,108,105,103,104,116,68,105,114,41,44,32,48,46,48,41,59,13,10,9,9,9,9,9,13,10,9,9,9,9,9,108,105,103,104,116,68,105,102,102,117,115,101,32,43,61,32,97,116,116,32,42,32,108,97,109,98,101,114,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,68,105,102,102,117,115,101,70,97,99,116,111,114,59,13,10,13,10,9,9,9,9,9,47,47,32,83,112,101,99,117,108,97,114,13,10,9,9,9,9,9,118,101,99,51,32,114,101,102,108,101,99,116,105,111,110,32,61,32,114,101,102,108,101,99,116,40,45,108,105,103,104,116,68,105,114,44,32,110,111,114,109,97,108,41,59,13,10,9,9,9,9,9,102,108,111,97,116,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,109,97,120,40,100,111,116,40,114,101,102,108,101,99,116,105,111,110,44,32,101,121,101,86,101,99,41,44,32,48,46,48,41,59,13,10,9,9,9,9,9,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,112,111,119,40,115,112,101,99,117,108,97,114,70,97,99,116,111,114,44,32,77,97,116,101,114,105,97,108,83,104,105,110,105,110,101,115,115,41,59,13,10,13,10,9,9,9,9,9,108,105,103,104,116,83,112,101,99,117,108,97,114,32,43,61,32,97,116,116,32,42,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,59,13,10,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,125,13,10,13,10,9,9,9,9,99,97,115,101,32,76,73,71,72,84,95,83,80,79,84,58,13,10,9,9,9,9,123,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,80,111,115,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,120,121,122,59,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,68,105,114,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,50,46,120,121,122,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,65,116,116,101,110,117,97,116,105,111,110,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,119,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,73,110,118,82,97,100,105,117,115,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,50,46,119,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,73,110,110,101,114,65,110,103,108,101,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,51,46,120,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,79,117,116,101,114,65,110,103,108,101,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,51,46,121,59,13,10,13,10,9,9,9,9,9,118,101,99,51,32,119,111,114,108,100,84,111,76,105,103,104,116,32,61,32,108,105,103,104,116,80,111,115,32,45,32,118,87,111,114,108,100,80,111,115,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,68,105,115,116,97,110,99,101,32,61,32,108,101,110,103,116,104,40,119,111,114,108,100,84,111,76,105,103,104,116,41,59,13,10,9,9,9,9,9,119,111,114,108,100,84,111,76,105,103,104,116,32,47,61,32,108,105,103,104,116,68,105,115,116,97,110,99,101,59,32,47,47,32,78,111,114,109,97,108,105,115,97,116,105,111,110,13,10,9,9,9,9,9,13,10,9,9,9,9,9,102,108,111,97,116,32,97,116,116,32,61,32,109,97,120,40,108,105,103,104,116,65,116,116,101,110,117,97,116,105,111,110,32,45,32,108,105,103,104,116,73,110,118,82,97,100,105,117,115,32,42,32,108,105,103,104,116,68,105,115,116,97,110,99,101,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,47,47,32,65,109,98,105,101,110,116,13,10,9,9,9,9,9,108,105,103,104,116,65,109,98,105,101,110,116,32,43,61,32,97,116,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,65,109,98,105,101,110,116,70,97,99,116,111,114,32,42,32,40,77,97,116,101,114,105,97,108,65,109,98,105,101,110,116,46,114,103,98,32,43,32,83,99,101,110,101,65,109,98,105,101,110,116,46,114,103,98,41,59,13,10,13,10,9,9,9,9,9,35,105,102,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,13,10,9,9,9,9,9,105,102,32,40,76,105,103,104,116,115,91,105,93,46,115,104,97,100,111,119,77,97,112,112,105,110,103,41,13,10,9,9,9,9,9,123,13,10,9,9,9,9,9,9,102,108,111,97,116,32,115,104,97,100,111,119,70,97,99,116,111,114,32,61,32,67,97,108,99,117,108,97,116,101,83,112,111,116,83,104,97,100,111,119,70,97,99,116,111,114,40,105,41,59,13,10,9,9,9,9,9,9,105,102,32,40,115,104,97,100,111,119,70,97,99,116,111,114,32,61,61,32,48,46,48,41,13,10,9,9,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,9,9,9,13,10,9,9,9,9,9,9,97,116,116,32,42,61,32,115,104,97,100,111,119,70,97,99,116,111,114,59,13,10,9,9,9,9,9,125,13,10,9,9,9,9,9,35,101,110,100,105,102,13,10,13,10,9,9,9,9,9,47,47,32,77,111,100,105,102,105,99,97,116,105,111,110,32,100,101,32,108,39,97,116,116,195,169,110,117,97,116,105,111,110,32,112,111,117,114,32,103,195,169,114,101,114,32,108,101,32,115,112,111,116,13,10,9,9,9,9,9,102,108,111,97,116,32,99,117,114,65,110,103,108,101,32,61,32,100,111,116,40,108,105,103,104,116,68,105,114,44,32,45,119,111,114,108,100,84,111,76,105,103,104,116,41,59,13,10,9,9,9,9,9,102,108,111,97,116,32,105,110,110,101,114,77,105,110,117,115,79,117,116,101,114,65,110,103,108,101,32,61,32,108,105,103,104,116,73,110,110,101,114,65,110,103,108,101,32,45,32,108,105,103,104,116,79,117,116,101,114,65,110,103,108,101,59,13,10,9,9,9,9,9,97,116,116,32,42,61,32,109,97,120,40,40,99,117,114,65,110,103,108,101,32,45,32,108,105,103,104,116,79,117,116,101,114,65,110,103,108,101,41,32,47,32,105,110,110,101,114,77,105,110,117,115,79,117,116,101,114,65,110,103,108,101,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,47,47,32,68,105,102,102,117,115,101,13,10,9,9,9,9,9,102,108,111,97,116,32,108,97,109,98,101,114,116,32,61,32,109,97,120,40,100,111,116,40,110,111,114,109,97,108,44,32,119,111,114,108,100,84,111,76,105,103,104,116,41,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,108,105,103,104,116,68,105,102,102,117,115,101,32,43,61,32,97,116,116,32,42,32,108,97,109,98,101,114,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,68,105,102,102,117,115,101,70,97,99,116,111,114,59,13,10,13,10,9,9,9,9,9,47,47,32,83,112,101,99,117,108,97,114,13,10,9,9,9,9,9,118,101,99,51,32,114,101,102,108,101,99,116,105,111,110,32,61,32,114,101,102,108,101,99,116,40,45,119,111,114,108,100,84,111,76,105,103,104,116,44,32,110,111,114,109,97,108,41,59,13,10,9,9,9,9,9,102,108,111,97,116,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,109,97,120,40,100,111,116,40,114,101,102,108,101,99,116,105,111,110,44,32,101,121,101,86,101,99,41,44,32,48,46,48,41,59,13,10,9,9,9,9,9,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,61,32,112,111,119,40,115,112,101,99,117,108,97,114,70,97,99,116,111,114,44,32,77,97,116,101,114,105,97,108,83,104,105,110,105,110,101,115,115,41,59,13,10,13,10,9,9,9,9,9,108,105,103,104,116,83,112,101,99,117,108,97,114,32,43,61,32,97,116,116,32,42,32,115,112,101,99,117,108,97,114,70,97,99,116,111,114,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,59,13,10,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,125,13,10,9,9,9,9,13,10,9,9,9,9,100,101,102,97,117,108,116,58,13,10,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,125,13,10,9,9,125,13,10,9,125,13,10,9,101,108,115,101,13,10,9,123,13,10,9,9,102,111,114,32,40,105,110,116,32,105,32,61,32,48,59,32,105,32,60,32,51,59,32,43,43,105,41,13,10,9,9,123,13,10,9,9,9,118,101,99,52,32,108,105,103,104,116,67,111,108,111,114,32,61,32,76,105,103,104,116,115,91,105,93,46,99,111,108,111,114,59,13,10,9,9,9,102,108,111,97,116,32,108,105,103,104,116,65,109,98,105,101,110,116,70,97,99,116,111,114,32,61,32,76,105,103,104,116,115,91,105,93,46,102,97,99,116,111,114,115,46,120,59,13,10,9,9,9,102,108,111,97,116,32,108,105,103,104,116,68,105,102,102,117,115,101,70,97,99,116,111,114,32,61,32,76,105,103,104,116,115,91,105,93,46,102,97,99,116,111,114,115,46,121,59,13,10,13,10,9,9,9,115,119,105,116,99,104,32,40,76,105,103,104,116,115,91,105,93,46,116,121,112,101,41,13,10,9,9,9,123,13,10,9,9,9,9,99,97,115,101,32,76,73,71,72,84,95,68,73,82,69,67,84,73,79,78,65,76,58,13,10,9,9,9,9,123,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,68,105,114,32,61,32,45,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,120,121,122,59,13,10,13,10,9,9,9,9,9,47,47,32,65,109,98,105,101,110,116,13,10,9,9,9,9,9,108,105,103,104,116,65,109,98,105,101,110,116,32,43,61,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,65,109,98,105,101,110,116,70,97,99,116,111,114,32,42,32,40,77,97,116,101,114,105,97,108,65,109,98,105,101,110,116,46,114,103,98,32,43,32,83,99,101,110,101,65,109,98,105,101,110,116,46,114,103,98,41,59,13,10,13,10,9,9,9,9,9,102,108,111,97,116,32,97,116,116,32,61,32,49,46,48,59,13,10,13,10,9,9,9,9,9,35,105,102,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,13,10,9,9,9,9,9,105,102,32,40,76,105,103,104,116,115,91,105,93,46,115,104,97,100,111,119,77,97,112,112,105,110,103,41,13,10,9,9,9,9,9,123,13,10,9,9,9,9,9,9,102,108,111,97,116,32,115,104,97,100,111,119,70,97,99,116,111,114,32,61,32,67,97,108,99,117,108,97,116,101,68,105,114,101,99,116,105,111,110,97,108,83,104,97,100,111,119,70,97,99,116,111,114,40,105,41,59,13,10,9,9,9,9,9,9,105,102,32,40,115,104,97,100,111,119,70,97,99,116,111,114,32,61,61,32,48,46,48,41,13,10,9,9,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,9,9,9,13,10,9,9,9,9,9,9,97,116,116,32,42,61,32,115,104,97,100,111,119,70,97,99,116,111,114,59,13,10,9,9,9,9,9,125,13,10,9,9,9,9,9,35,101,110,100,105,102,13,10,13,10,9,9,9,9,9,47,47,32,68,105,102,102,117,115,101,13,10,9,9,9,9,9,102,108,111,97,116,32,108,97,109,98,101,114,116,32,61,32,109,97,120,40,100,111,116,40,110,111,114,109,97,108,44,32,108,105,103,104,116,68,105,114,41,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,108,105,103,104,116,68,105,102,102,117,115,101,32,43,61,32,97,116,116,32,42,32,108,97,109,98,101,114,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,68,105,102,102,117,115,101,70,97,99,116,111,114,59,13,10,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,125,13,10,13,10,9,9,9,9,99,97,115,101,32,76,73,71,72,84,95,80,79,73,78,84,58,13,10,9,9,9,9,123,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,80,111,115,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,120,121,122,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,65,116,116,101,110,117,97,116,105,111,110,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,119,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,73,110,118,82,97,100,105,117,115,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,50,46,119,59,13,10,9,9,9,9,9,13,10,9,9,9,9,9,118,101,99,51,32,119,111,114,108,100,84,111,76,105,103,104,116,32,61,32,108,105,103,104,116,80,111,115,32,45,32,118,87,111,114,108,100,80,111,115,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,68,105,114,76,101,110,103,116,104,32,61,32,108,101,110,103,116,104,40,119,111,114,108,100,84,111,76,105,103,104,116,41,59,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,68,105,114,32,61,32,119,111,114,108,100,84,111,76,105,103,104,116,32,47,32,108,105,103,104,116,68,105,114,76,101,110,103,116,104,59,32,47,47,32,78,111,114,109,97,108,105,115,97,116,105,111,110,13,10,9,9,9,9,9,13,10,9,9,9,9,9,102,108,111,97,116,32,97,116,116,32,61,32,109,97,120,40,108,105,103,104,116,65,116,116,101,110,117,97,116,105,111,110,32,45,32,108,105,103,104,116,73,110,118,82,97,100,105,117,115,32,42,32,108,105,103,104,116,68,105,114,76,101,110,103,116,104,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,47,47,32,65,109,98,105,101,110,116,13,10,9,9,9,9,9,108,105,103,104,116,65,109,98,105,101,110,116,32,43,61,32,97,116,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,65,109,98,105,101,110,116,70,97,99,116,111,114,32,42,32,40,77,97,116,101,114,105,97,108,65,109,98,105,101,110,116,46,114,103,98,32,43,32,83,99,101,110,101,65,109,98,105,101,110,116,46,114,103,98,41,59,13,10,13,10,9,9,9,9,9,35,105,102,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,13,10,9,9,9,9,9,105,102,32,40,76,105,103,104,116,115,91,105,93,46,115,104,97,100,111,119,77,97,112,112,105,110,103,41,13,10,9,9,9,9,9,123,13,10,9,9,9,9,9,9,102,108,111,97,116,32,115,104,97,100,111,119,70,97,99,116,111,114,32,61,32,67,97,108,99,117,108,97,116,101,80,111,105,110,116,83,104,97,100,111,119,70,97,99,116,111,114,40,105,44,32,118,87,111,114,108,100,80,111,115,32,45,32,108,105,103,104,116,80,111,115,44,32,48,46,49,44,32,53,48,46,48,41,59,13,10,9,9,9,9,9,9,105,102,32,40,115,104,97,100,111,119,70,97,99,116,111,114,32,61,61,32,48,46,48,41,13,10,9,9,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,9,9,9,13,10,9,9,9,9,9,9,97,116,116,32,42,61,32,115,104,97,100,111,119,70,97,99,116,111,114,59,13,10,9,9,9,9,9,125,13,10,9,9,9,9,9,35,101,110,100,105,102,13,10,13,10,9,9,9,9,9,47,47,32,68,105,102,102,117,115,101,13,10,9,9,9,9,9,102,108,111,97,116,32,108,97,109,98,101,114,116,32,61,32,109,97,120,40,100,111,116,40,110,111,114,109,97,108,44,32,108,105,103,104,116,68,105,114,41,44,32,48,46,48,41,59,13,10,9,9,9,9,9,13,10,9,9,9,9,9,108,105,103,104,116,68,105,102,102,117,115,101,32,43,61,32,97,116,116,32,42,32,108,97,109,98,101,114,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,68,105,102,102,117,115,101,70,97,99,116,111,114,59,13,10,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,125,13,10,13,10,9,9,9,9,99,97,115,101,32,76,73,71,72,84,95,83,80,79,84,58,13,10,9,9,9,9,123,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,80,111,115,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,120,121,122,59,13,10,9,9,9,9,9,118,101,99,51,32,108,105,103,104,116,68,105,114,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,50,46,120,121,122,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,65,116,116,101,110,117,97,116,105,111,110,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,49,46,119,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,73,110,118,82,97,100,105,117,115,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,50,46,119,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,73,110,110,101,114,65,110,103,108,101,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,51,46,120,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,79,117,116,101,114,65,110,103,108,101,32,61,32,76,105,103,104,116,115,91,105,93,46,112,97,114,97,109,101,116,101,114,115,51,46,121,59,13,10,13,10,9,9,9,9,9,118,101,99,51,32,119,111,114,108,100,84,111,76,105,103,104,116,32,61,32,108,105,103,104,116,80,111,115,32,45,32,118,87,111,114,108,100,80,111,115,59,13,10,9,9,9,9,9,102,108,111,97,116,32,108,105,103,104,116,68,105,115,116,97,110,99,101,32,61,32,108,101,110,103,116,104,40,119,111,114,108,100,84,111,76,105,103,104,116,41,59,13,10,9,9,9,9,9,119,111,114,108,100,84,111,76,105,103,104,116,32,47,61,32,108,105,103,104,116,68,105,115,116,97,110,99,101,59,32,47,47,32,78,111,114,109,97,108,105,115,97,116,105,111,110,13,10,9,9,9,9,9,13,10,9,9,9,9,9,102,108,111,97,116,32,97,116,116,32,61,32,109,97,120,40,108,105,103,104,116,65,116,116,101,110,117,97,116,105,111,110,32,45,32,108,105,103,104,116,73,110,118,82,97,100,105,117,115,32,42,32,108,105,103,104,116,68,105,115,116,97,110,99,101,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,47,47,32,65,109,98,105,101,110,116,13,10,9,9,9,9,9,108,105,103,104,116,65,109,98,105,101,110,116,32,43,61,32,97,116,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,65,109,98,105,101,110,116,70,97,99,116,111,114,32,42,32,40,77,97,116,101,114,105,97,108,65,109,98,105,101,110,116,46,114,103,98,32,43,32,83,99,101,110,101,65,109,98,105,101,110,116,46,114,103,98,41,59,13,10,13,10,9,9,9,9,9,35,105,102,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,13,10,9,9,9,9,9,105,102,32,40,76,105,103,104,116,115,91,105,93,46,115,104,97,100,111,119,77,97,112,112,105,110,103,41,13,10,9,9,9,9,9,123,13,10,9,9,9,9,9,9,102,108,111,97,116,32,115,104,97,100,111,119,70,97,99,116,111,114,32,61,32,67,97,108,99,117,108,97,116,101,83,112,111,116,83,104,97,100,111,119,70,97,99,116,111,114,40,105,41,59,13,10,9,9,9,9,9,9,105,102,32,40,115,104,97,100,111,119,70,97,99,116,111,114,32,61,61,32,48,46,48,41,13,10,9,9,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,9,9,9,9,13,10,9,9,9,9,9,9,97,116,116,32,42,61,32,115,104,97,100,111,119,70,97,99,116,111,114,59,13,10,9,9,9,9,9,125,13,10,9,9,9,9,9,35,101,110,100,105,102,13,10,13,10,9,9,9,9,9,47,47,32,77,111,100,105,102,105,99,97,116,105,111,110,32,100,101,32,108,39,97,116,116,195,169,110,117,97,116,105,111,110,32,112,111,117,114,32,103,195,169,114,101,114,32,108,101,32,115,112,111,116,13,10,9,9,9,9,9,102,108,111,97,116,32,99,117,114,65,110,103,108,101,32,61,32,100,111,116,40,108,105,103,104,116,68,105,114,44,32,45,119,111,114,108,100,84,111,76,105,103,104,116,41,59,13,10,9,9,9,9,9,102,108,111,97,116,32,105,110,110,101,114,77,105,110,117,115,79,117,116,101,114,65,110,103,108,101,32,61,32,108,105,103,104,116,73,110,110,101,114,65,110,103,108,101,32,45,32,108,105,103,104,116,79,117,116,101,114,65,110,103,108,101,59,13,10,9,9,9,9,9,97,116,116,32,42,61,32,109,97,120,40,40,99,117,114,65,110,103,108,101,32,45,32,108,105,103,104,116,79,117,116,101,114,65,110,103,108,101,41,32,47,32,105,110,110,101,114,77,105,110,117,115,79,117,116,101,114,65,110,103,108,101,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,47,47,32,68,105,102,102,117,115,101,13,10,9,9,9,9,9,102,108,111,97,116,32,108,97,109,98,101,114,116,32,61,32,109,97,120,40,100,111,116,40,110,111,114,109,97,108,44,32,119,111,114,108,100,84,111,76,105,103,104,116,41,44,32,48,46,48,41,59,13,10,13,10,9,9,9,9,9,108,105,103,104,116,68,105,102,102,117,115,101,32,43,61,32,97,116,116,32,42,32,108,97,109,98,101,114,116,32,42,32,108,105,103,104,116,67,111,108,111,114,46,114,103,98,32,42,32,108,105,103,104,116,68,105,102,102,117,115,101,70,97,99,116,111,114,59,13,10,9,9,9,9,125,13,10,9,9,9,9,13,10,9,9,9,9,100,101,102,97,117,108,116,58,13,10,9,9,9,9,9,98,114,101,97,107,59,13,10,9,9,9,125,13,10,9,9,125,13,10,9,125,13,10,9,13,10,9,108,105,103,104,116,83,112,101,99,117,108,97,114,32,42,61,32,77,97,116,101,114,105,97,108,83,112,101,99,117,108,97,114,46,114,103,98,59,13,10,9,35,105,102,32,83,80,69,67,85,76,65,82,95,77,65,80,80,73,78,71,13,10,9,108,105,103,104,116,83,112,101,99,117,108,97,114,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,83,112,101,99,117,108,97,114,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,103,98,59,32,47,47,32,85,116,105,108,105,115,101,114,32,108,39,97,108,112,104,97,32,100,101,32,77,97,116,101,114,105,97,108,83,112,101,99,117,108,97,114,32,110,39,97,117,114,97,105,116,32,97,117,99,117,110,32,115,101,110,115,13,10,9,35,101,110,100,105,102,13,10,9,9,13,10,9,118,101,99,51,32,108,105,103,104,116,67,111,108,111,114,32,61,32,40,108,105,103,104,116,65,109,98,105,101,110,116,32,43,32,108,105,103,104,116,68,105,102,102,117,115,101,32,43,32,108,105,103,104,116,83,112,101,99,117,108,97,114,41,59,13,10,9,13,10,9,35,105,102,32,82,69,70,76,69,67,84,73,79,78,95,77,65,80,80,73,78,71,13,10,9,118,101,99,51,32,101,121,101,86,101,99,32,61,32,110,111,114,109,97,108,105,122,101,40,118,87,111,114,108,100,80,111,115,32,45,32,69,121,101,80,111,115,105,116,105,111,110,41,59,13,10,13,10,9,118,101,99,51,32,114,101,102,108,101,99,116,101,100,32,61,32,110,111,114,109,97,108,105,122,101,40,114,101,102,108,101,99,116,40,101,121,101,86,101,99,44,32,110,111,114,109,97,108,41,41,59,13,10,9,108,105,103,104,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,82,101,102,108,101,99,116,105,111,110,77,97,112,44,32,114,101,102,108,101,99,116,101,100,41,46,114,103,98,59,13,10,9,35,101,110,100,105,102,13,10,9,13,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,118,101,99,52,40,108,105,103,104,116,67,111,108,111,114,44,32,49,46,48,41,32,42,32,100,105,102,102,117,115,101,67,111,108,111,114,59,13,10,13,10,9,35,105,102,32,69,77,73,83,83,73,86,69,95,77,65,80,80,73,78,71,13,10,9,102,108,111,97,116,32,108,105,103,104,116,73,110,116,101,110,115,105,116,121,32,61,32,100,111,116,40,108,105,103,104,116,67,111,108,111,114,44,32,118,101,99,51,40,48,46,51,44,32,48,46,53,57,44,32,48,46,49,49,41,41,59,13,10,13,10,9,118,101,99,51,32,101,109,105,115,115,105,111,110,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,46,114,103,98,32,42,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,69,109,105,115,115,105,118,101,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,103,98,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,109,105,120,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,114,103,98,44,32,101,109,105,115,115,105,111,110,67,111,108,111,114,44,32,99,108,97,109,112,40,49,46,48,32,45,32,51,46,48,42,108,105,103,104,116,73,110,116,101,110,115,105,116,121,44,32,48,46,48,44,32,49,46,48,41,41,44,32,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,41,59,13,10,9,35,101,108,115,101,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,13,10,9,35,101,110,100,105,102,32,47,47,32,69,77,73,83,83,73,86,69,95,77,65,80,80,73,78,71,13,10,35,101,110,100,105,102,32,47,47,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,125,13,10,13,10, \ No newline at end of file diff --git a/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert b/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert deleted file mode 100644 index 8943c5935..000000000 --- a/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert +++ /dev/null @@ -1,148 +0,0 @@ -/********************Entrant********************/ -#if FLAG_BILLBOARD -in vec3 InstanceData0; // center -in vec4 InstanceData1; // size | sin cos -in vec4 InstanceData2; // color -#else -in mat4 InstanceData0; -#endif - -in vec4 VertexColor; -in vec3 VertexPosition; -in vec3 VertexNormal; -in vec3 VertexTangent; -in vec2 VertexTexCoord; -in vec4 VertexUserdata0; - -/********************Sortant********************/ -out vec4 vColor; -out vec4 vLightSpacePos[3]; -out mat3 vLightToWorld; -out vec3 vNormal; -out vec2 vTexCoord; -out vec3 vViewDir; -out vec3 vWorldPos; - -/********************Uniformes********************/ -uniform vec3 EyePosition; -uniform mat4 InvViewMatrix; -uniform mat4 LightViewProjMatrix[3]; -uniform float VertexDepth; -uniform mat4 ViewMatrix; -uniform mat4 ViewProjMatrix; -uniform mat4 WorldMatrix; -uniform mat4 WorldViewProjMatrix; - -/********************Fonctions********************/ -void main() -{ -#if FLAG_VERTEXCOLOR - vec4 color = VertexColor; -#else - vec4 color = vec4(1.0); -#endif - - vec2 texCoords; - -#if FLAG_BILLBOARD - #if FLAG_INSTANCING - vec3 billboardCenter = InstanceData0; - vec2 billboardSize = InstanceData1.xy; - vec2 billboardSinCos = InstanceData1.zw; - vec4 billboardColor = InstanceData2; - - vec2 rotatedPosition; - rotatedPosition.x = VertexPosition.x*billboardSinCos.y - VertexPosition.y*billboardSinCos.x; - rotatedPosition.y = VertexPosition.y*billboardSinCos.y + VertexPosition.x*billboardSinCos.x; - rotatedPosition *= billboardSize; - - vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]); - vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]); - vec3 vertexPos = billboardCenter + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y; - - gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0); - color = billboardColor; - texCoords = VertexPosition.xy + 0.5; - #else - vec2 billboardCorner = VertexTexCoord - 0.5; - vec2 billboardSize = VertexUserdata0.xy; - vec2 billboardSinCos = VertexUserdata0.zw; - - vec2 rotatedPosition; - rotatedPosition.x = billboardCorner.x*billboardSinCos.y - billboardCorner.y*billboardSinCos.x; - rotatedPosition.y = billboardCorner.y*billboardSinCos.y + billboardCorner.x*billboardSinCos.x; - rotatedPosition *= billboardSize; - - vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]); - vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]); - vec3 vertexPos = VertexPosition + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y; - - gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0); - texCoords = VertexTexCoord; - #endif - texCoords.y = 1.0 - texCoords.y; -#else - #if FLAG_INSTANCING - #if TRANSFORM - gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0); - #else - #if UNIFORM_VERTEX_DEPTH - gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0); - #else - gl_Position = InstanceData0 * vec4(VertexPosition, 1.0); - #endif - #endif - #else - #if TRANSFORM - gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0); - #else - #if UNIFORM_VERTEX_DEPTH - gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0); - #else - gl_Position = vec4(VertexPosition, 1.0); - #endif - #endif - #endif - - texCoords = VertexTexCoord; -#endif - - vColor = color; - -#if FLAG_INSTANCING - mat3 rotationMatrix = mat3(InstanceData0); -#else - mat3 rotationMatrix = mat3(WorldMatrix); -#endif - -#if COMPUTE_TBNMATRIX - vec3 binormal = cross(VertexNormal, VertexTangent); - vLightToWorld[0] = normalize(rotationMatrix * VertexTangent); - vLightToWorld[1] = normalize(rotationMatrix * binormal); - vLightToWorld[2] = normalize(rotationMatrix * VertexNormal); -#else - vNormal = normalize(rotationMatrix * VertexNormal); -#endif - -#if SHADOW_MAPPING - for (int i = 0; i < 3; ++i) - vLightSpacePos[i] = LightViewProjMatrix[i] * WorldMatrix * vec4(VertexPosition, 1.0); -#endif - -#if TEXTURE_MAPPING - vTexCoord = VertexTexCoord; -#endif - -#if PARALLAX_MAPPING - vViewDir = EyePosition - VertexPosition; - vViewDir *= vLightToWorld; -#endif - -#if !FLAG_DEFERRED - #if FLAG_INSTANCING - vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0)); - #else - vWorldPos = vec3(WorldMatrix * vec4(VertexPosition, 1.0)); - #endif -#endif -} diff --git a/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h b/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h deleted file mode 100644 index 7e63feb08..000000000 --- a/src/Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h +++ /dev/null @@ -1 +0,0 @@ -47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,35,105,102,32,70,76,65,71,95,66,73,76,76,66,79,65,82,68,10,105,110,32,118,101,99,51,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,32,47,47,32,99,101,110,116,101,114,10,105,110,32,118,101,99,52,32,73,110,115,116,97,110,99,101,68,97,116,97,49,59,32,47,47,32,115,105,122,101,32,124,32,115,105,110,32,99,111,115,10,105,110,32,118,101,99,52,32,73,110,115,116,97,110,99,101,68,97,116,97,50,59,32,47,47,32,99,111,108,111,114,10,35,101,108,115,101,10,105,110,32,109,97,116,52,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,10,35,101,110,100,105,102,10,10,105,110,32,118,101,99,52,32,86,101,114,116,101,120,67,111,108,111,114,59,10,105,110,32,118,101,99,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,10,105,110,32,118,101,99,51,32,86,101,114,116,101,120,78,111,114,109,97,108,59,10,105,110,32,118,101,99,51,32,86,101,114,116,101,120,84,97,110,103,101,110,116,59,10,105,110,32,118,101,99,50,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,10,105,110,32,118,101,99,52,32,86,101,114,116,101,120,85,115,101,114,100,97,116,97,48,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,111,117,116,32,118,101,99,52,32,118,67,111,108,111,114,59,10,111,117,116,32,118,101,99,52,32,118,76,105,103,104,116,83,112,97,99,101,80,111,115,91,51,93,59,10,111,117,116,32,109,97,116,51,32,118,76,105,103,104,116,84,111,87,111,114,108,100,59,10,111,117,116,32,118,101,99,51,32,118,78,111,114,109,97,108,59,10,111,117,116,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,10,111,117,116,32,118,101,99,51,32,118,86,105,101,119,68,105,114,59,10,111,117,116,32,118,101,99,51,32,118,87,111,114,108,100,80,111,115,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,117,110,105,102,111,114,109,32,118,101,99,51,32,69,121,101,80,111,115,105,116,105,111,110,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,73,110,118,86,105,101,119,77,97,116,114,105,120,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,76,105,103,104,116,86,105,101,119,80,114,111,106,77,97,116,114,105,120,91,51,93,59,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,86,101,114,116,101,120,68,101,112,116,104,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,77,97,116,114,105,120,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,77,97,116,114,105,120,59,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,10,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,10,118,111,105,100,32,109,97,105,110,40,41,10,123,10,35,105,102,32,70,76,65,71,95,86,69,82,84,69,88,67,79,76,79,82,10,9,118,101,99,52,32,99,111,108,111,114,32,61,32,86,101,114,116,101,120,67,111,108,111,114,59,10,35,101,108,115,101,10,9,118,101,99,52,32,99,111,108,111,114,32,61,32,118,101,99,52,40,49,46,48,41,59,10,35,101,110,100,105,102,10,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,115,59,10,10,35,105,102,32,70,76,65,71,95,66,73,76,76,66,79,65,82,68,10,9,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,10,9,118,101,99,51,32,98,105,108,108,98,111,97,114,100,67,101,110,116,101,114,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,83,105,122,101,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,49,46,120,121,59,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,49,46,122,119,59,10,9,118,101,99,52,32,98,105,108,108,98,111,97,114,100,67,111,108,111,114,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,50,59,10,10,9,118,101,99,50,32,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,120,32,61,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,121,32,45,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,120,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,121,32,61,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,121,32,43,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,120,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,32,42,61,32,98,105,108,108,98,111,97,114,100,83,105,122,101,59,10,10,9,118,101,99,51,32,99,97,109,101,114,97,82,105,103,104,116,32,61,32,118,101,99,51,40,86,105,101,119,77,97,116,114,105,120,91,48,93,91,48,93,44,32,86,105,101,119,77,97,116,114,105,120,91,49,93,91,48,93,44,32,86,105,101,119,77,97,116,114,105,120,91,50,93,91,48,93,41,59,10,9,118,101,99,51,32,99,97,109,101,114,97,85,112,32,61,32,118,101,99,51,40,86,105,101,119,77,97,116,114,105,120,91,48,93,91,49,93,44,32,86,105,101,119,77,97,116,114,105,120,91,49,93,91,49,93,44,32,86,105,101,119,77,97,116,114,105,120,91,50,93,91,49,93,41,59,10,9,118,101,99,51,32,118,101,114,116,101,120,80,111,115,32,61,32,98,105,108,108,98,111,97,114,100,67,101,110,116,101,114,32,43,32,99,97,109,101,114,97,82,105,103,104,116,42,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,120,32,43,32,99,97,109,101,114,97,85,112,42,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,121,59,10,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,118,101,114,116,101,120,80,111,115,44,32,49,46,48,41,59,10,9,99,111,108,111,114,32,61,32,98,105,108,108,98,111,97,114,100,67,111,108,111,114,59,10,9,116,101,120,67,111,111,114,100,115,32,61,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,32,43,32,48,46,53,59,10,9,35,101,108,115,101,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,32,61,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,32,45,32,48,46,53,59,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,83,105,122,101,32,61,32,86,101,114,116,101,120,85,115,101,114,100,97,116,97,48,46,120,121,59,10,9,118,101,99,50,32,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,32,61,32,86,101,114,116,101,120,85,115,101,114,100,97,116,97,48,46,122,119,59,10,9,10,9,118,101,99,50,32,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,120,32,61,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,46,120,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,121,32,45,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,46,121,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,120,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,121,32,61,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,46,121,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,121,32,43,32,98,105,108,108,98,111,97,114,100,67,111,114,110,101,114,46,120,42,98,105,108,108,98,111,97,114,100,83,105,110,67,111,115,46,120,59,10,9,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,32,42,61,32,98,105,108,108,98,111,97,114,100,83,105,122,101,59,10,10,9,118,101,99,51,32,99,97,109,101,114,97,82,105,103,104,116,32,61,32,118,101,99,51,40,86,105,101,119,77,97,116,114,105,120,91,48,93,91,48,93,44,32,86,105,101,119,77,97,116,114,105,120,91,49,93,91,48,93,44,32,86,105,101,119,77,97,116,114,105,120,91,50,93,91,48,93,41,59,10,9,118,101,99,51,32,99,97,109,101,114,97,85,112,32,61,32,118,101,99,51,40,86,105,101,119,77,97,116,114,105,120,91,48,93,91,49,93,44,32,86,105,101,119,77,97,116,114,105,120,91,49,93,91,49,93,44,32,86,105,101,119,77,97,116,114,105,120,91,50,93,91,49,93,41,59,10,9,118,101,99,51,32,118,101,114,116,101,120,80,111,115,32,61,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,32,43,32,99,97,109,101,114,97,82,105,103,104,116,42,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,120,32,43,32,99,97,109,101,114,97,85,112,42,114,111,116,97,116,101,100,80,111,115,105,116,105,111,110,46,121,59,10,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,118,101,114,116,101,120,80,111,115,44,32,49,46,48,41,59,10,9,116,101,120,67,111,111,114,100,115,32,61,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,10,9,35,101,110,100,105,102,10,9,116,101,120,67,111,111,114,100,115,46,121,32,61,32,49,46,48,32,45,32,116,101,120,67,111,111,114,100,115,46,121,59,10,35,101,108,115,101,10,9,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,10,9,9,35,105,102,32,84,82,65,78,83,70,79,82,77,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,9,9,35,101,108,115,101,10,9,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,10,9,9,9,35,101,108,115,101,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,9,9,9,35,101,110,100,105,102,10,9,9,35,101,110,100,105,102,10,9,35,101,108,115,101,10,9,9,35,105,102,32,84,82,65,78,83,70,79,82,77,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,9,9,35,101,108,115,101,10,9,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,10,9,9,9,35,101,108,115,101,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,9,9,9,35,101,110,100,105,102,10,9,9,35,101,110,100,105,102,10,9,35,101,110,100,105,102,10,10,9,116,101,120,67,111,111,114,100,115,32,61,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,10,35,101,110,100,105,102,10,10,9,118,67,111,108,111,114,32,61,32,99,111,108,111,114,59,10,10,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,10,9,109,97,116,51,32,114,111,116,97,116,105,111,110,77,97,116,114,105,120,32,61,32,109,97,116,51,40,73,110,115,116,97,110,99,101,68,97,116,97,48,41,59,10,35,101,108,115,101,10,9,109,97,116,51,32,114,111,116,97,116,105,111,110,77,97,116,114,105,120,32,61,32,109,97,116,51,40,87,111,114,108,100,77,97,116,114,105,120,41,59,10,35,101,110,100,105,102,10,9,10,35,105,102,32,67,79,77,80,85,84,69,95,84,66,78,77,65,84,82,73,88,10,9,118,101,99,51,32,98,105,110,111,114,109,97,108,32,61,32,99,114,111,115,115,40,86,101,114,116,101,120,78,111,114,109,97,108,44,32,86,101,114,116,101,120,84,97,110,103,101,110,116,41,59,10,9,118,76,105,103,104,116,84,111,87,111,114,108,100,91,48,93,32,61,32,110,111,114,109,97,108,105,122,101,40,114,111,116,97,116,105,111,110,77,97,116,114,105,120,32,42,32,86,101,114,116,101,120,84,97,110,103,101,110,116,41,59,10,9,118,76,105,103,104,116,84,111,87,111,114,108,100,91,49,93,32,61,32,110,111,114,109,97,108,105,122,101,40,114,111,116,97,116,105,111,110,77,97,116,114,105,120,32,42,32,98,105,110,111,114,109,97,108,41,59,10,9,118,76,105,103,104,116,84,111,87,111,114,108,100,91,50,93,32,61,32,110,111,114,109,97,108,105,122,101,40,114,111,116,97,116,105,111,110,77,97,116,114,105,120,32,42,32,86,101,114,116,101,120,78,111,114,109,97,108,41,59,10,35,101,108,115,101,10,9,118,78,111,114,109,97,108,32,61,32,110,111,114,109,97,108,105,122,101,40,114,111,116,97,116,105,111,110,77,97,116,114,105,120,32,42,32,86,101,114,116,101,120,78,111,114,109,97,108,41,59,10,35,101,110,100,105,102,10,10,35,105,102,32,83,72,65,68,79,87,95,77,65,80,80,73,78,71,10,9,102,111,114,32,40,105,110,116,32,105,32,61,32,48,59,32,105,32,60,32,51,59,32,43,43,105,41,10,9,9,118,76,105,103,104,116,83,112,97,99,101,80,111,115,91,105,93,32,61,32,76,105,103,104,116,86,105,101,119,80,114,111,106,77,97,116,114,105,120,91,105,93,32,42,32,87,111,114,108,100,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,10,35,101,110,100,105,102,10,10,35,105,102,32,84,69,88,84,85,82,69,95,77,65,80,80,73,78,71,10,9,118,84,101,120,67,111,111,114,100,32,61,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,10,35,101,110,100,105,102,10,10,35,105,102,32,80,65,82,65,76,76,65,88,95,77,65,80,80,73,78,71,10,9,118,86,105,101,119,68,105,114,32,61,32,69,121,101,80,111,115,105,116,105,111,110,32,45,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,32,10,9,118,86,105,101,119,68,105,114,32,42,61,32,118,76,105,103,104,116,84,111,87,111,114,108,100,59,10,35,101,110,100,105,102,10,10,35,105,102,32,33,70,76,65,71,95,68,69,70,69,82,82,69,68,10,9,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,10,9,118,87,111,114,108,100,80,111,115,32,61,32,118,101,99,51,40,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,41,59,10,9,35,101,108,115,101,10,9,118,87,111,114,108,100,80,111,115,32,61,32,118,101,99,51,40,87,111,114,108,100,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,41,59,10,9,35,101,110,100,105,102,10,35,101,110,100,105,102,10,125,10, \ No newline at end of file diff --git a/src/Nazara/Graphics/SkeletalModel.cpp b/src/Nazara/Graphics/SkeletalModel.cpp deleted file mode 100644 index 4423bb167..000000000 --- a/src/Nazara/Graphics/SkeletalModel.cpp +++ /dev/null @@ -1,395 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::SkeletalModel - * \brief Graphics class that represents a model with a skeleton - */ - - /*! - * \brief Checks whether the parameters for the skeletal mesh are correct - * \return true If parameters are valid - */ - - bool SkeletalModelParameters::IsValid() const - { - if (!ModelParameters::IsValid()) - return false; - - if (loadAnimation && !animation.IsValid()) - return false; - - return true; - } - - /*! - * \brief Constructs a SkeletalModel object by default - */ - - SkeletalModel::SkeletalModel() : - m_currentSequence(nullptr), - m_animationEnabled(true) - { - } - - /*! - * \brief Adds the skeletal mesh to the rendering queue - * - * \param renderQueue Queue to be added - * \param instanceData Data for the instance - */ - - void SkeletalModel::AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const - { - if (!m_mesh) - return; - - unsigned int submeshCount = m_mesh->GetSubMeshCount(); - for (unsigned int i = 0; i < submeshCount; ++i) - { - const SkeletalMesh* mesh = static_cast(m_mesh->GetSubMesh(i)); - const Material* material = GetMaterial(mesh->GetMaterialIndex()); - - MeshData meshData; - meshData.indexBuffer = mesh->GetIndexBuffer(); - meshData.primitiveMode = mesh->GetPrimitiveMode(); - meshData.vertexBuffer = SkinningManager::GetBuffer(mesh, &m_skeleton); - - renderQueue->AddMesh(instanceData.renderOrder, material, meshData, m_skeleton.GetAABB(), instanceData.transformMatrix, scissorRect); - } - } - - /*! - * \brief Updates the animation of the mesh - * - * \param elapsedTime Delta time between two frames - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if there is no animation - */ - - void SkeletalModel::AdvanceAnimation(float elapsedTime) - { - #if NAZARA_GRAPHICS_SAFE - if (!m_animation) - { - NazaraError("Model has no animation"); - return; - } - #endif - - m_interpolation += m_currentSequence->frameRate * elapsedTime; - while (m_interpolation > 1.f) - { - m_interpolation -= 1.f; - - unsigned lastFrame = m_currentSequence->firstFrame + m_currentSequence->frameCount - 1; - if (m_nextFrame + 1 > lastFrame) - { - if (m_animation->IsLoopPointInterpolationEnabled()) - { - m_currentFrame = m_nextFrame; - m_nextFrame = m_currentSequence->firstFrame; - } - else - { - m_currentFrame = m_currentSequence->firstFrame; - m_nextFrame = m_currentFrame + 1; - } - } - else - { - m_currentFrame = m_nextFrame; - m_nextFrame++; - } - } - - m_animation->AnimateSkeleton(&m_skeleton, m_currentFrame, m_nextFrame, m_interpolation); - - InvalidateBoundingVolume(); - } - - /*! - * \brief Clones this skeletal model - * \return Pointer to newly allocated SkeletalModel - */ - std::unique_ptr SkeletalModel::Clone() const - { - return std::make_unique(*this); - } - - /*! - * \brief Creates a default skeletal model - * \return Pointer to newly allocated SkeletalModel - */ - - SkeletalModel* SkeletalModel::Create() const - { - return new SkeletalModel; - } - - /*! - * \brief Enables the animation of the model - * - * \param animation Should the model be animated - */ - - void SkeletalModel::EnableAnimation(bool animation) - { - m_animationEnabled = animation; - } - - /*! - * \brief Gets the animation of the model - * \return Pointer to the animation - */ - - Animation* SkeletalModel::GetAnimation() const - { - return m_animation; - } - - /*! - * \brief Gets the skeleton of the model - * \return Pointer to the skeleton - */ - - Skeleton* SkeletalModel::GetSkeleton() - { - InvalidateBoundingVolume(); - - return &m_skeleton; - } - - /*! - * \brief Gets the skeleton of the model - * \return Constant pointer to the skeleton - */ - - const Skeleton* SkeletalModel::GetSkeleton() const - { - return &m_skeleton; - } - - /*! - * \brief Checks whether the skeleton has an animation - * \return true If it is the case - * - * \see IsAnimated, IsAnimationEnabled - */ - - bool SkeletalModel::HasAnimation() const - { - return m_animation != nullptr; - } - - /*! - * \brief Checks whether the skeleton is animated - * \return true - * - * \see HasAnimation, IsAnimationEnabled - */ - - bool SkeletalModel::IsAnimated() const - { - return true; - } - - /*! - * \brief Checks whether the skeleton is currently animated - * \return true If it is the case - * - * \see HasAnimation, IsAnimated - */ - - bool SkeletalModel::IsAnimationEnabled() const - { - return m_animationEnabled; - } - - /*! - * \brief Sets the animation for the model - * \return true If successful - * - * \param animation Animation for the model - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE if there is no mesh - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE if animation is invalid - */ - - bool SkeletalModel::SetAnimation(Animation* animation) - { - #if NAZARA_GRAPHICS_SAFE - if (!m_mesh) - { - NazaraError("Model has no mesh"); - return false; - } - - if (animation) - { - if (!animation->IsValid()) - { - NazaraError("Invalid animation"); - return false; - } - - if (animation->GetType() != m_mesh->GetAnimationType()) - { - NazaraError("Animation type must match mesh animation type"); - return false; - } - - if (animation->GetJointCount() != m_mesh->GetJointCount()) - { - NazaraError("Animation joint count must match mesh joint count"); - return false; - } - } - #endif - - m_animation = animation; - if (m_animation) - { - m_currentFrame = 0; - m_interpolation = 0.f; - - SetSequence(0); - } - - return true; - } - - /*! - * \brief Sets the mesh for the model - * - * \param mesh Mesh for the model - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE if there is no mesh or if invalid - */ - - void SkeletalModel::SetMesh(Mesh* mesh) - { - #if NAZARA_GRAPHICS_SAFE - if (mesh && mesh->GetAnimationType() != AnimationType_Skeletal) - { - NazaraError("Mesh animation type must be skeletal"); - return; - } - #endif - - Model::SetMesh(mesh); - - if (m_mesh) - { - if (m_animation && m_animation->GetJointCount() != m_mesh->GetJointCount()) - { - NazaraWarning("Animation joint count is not matching new mesh joint count, disabling animation..."); - SetAnimation(nullptr); - } - - m_skeleton = *m_mesh->GetSkeleton(); // Copy of skeleton template - } - } - - /*! - * \brief Sets the sequence for the model - * \return true If successful - * - * \param sequenceName Name for the sequence animation - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE if there is no animation - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE if sequence name does not exist for the current animation - */ - - bool SkeletalModel::SetSequence(const String& sequenceName) - { - ///TODO: Make this error "safe" with the new system of error handling (No-log) - #if NAZARA_GRAPHICS_SAFE - if (!m_animation) - { - NazaraError("Model has no animation"); - return false; - } - #endif - - const Sequence* currentSequence = m_animation->GetSequence(sequenceName); - #if NAZARA_GRAPHICS_SAFE - if (!currentSequence) - { - NazaraError("Sequence not found"); - return false; - } - #endif - - m_currentSequence = currentSequence; - m_nextFrame = m_currentSequence->firstFrame; - - return true; - } - - /*! - * \brief Sets the sequence for the model - * - * \param sequenceIndex Index for the sequence animation - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE if there is no animation - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE if sequence name does not exist for the current animation - */ - - void SkeletalModel::SetSequence(unsigned int sequenceIndex) - { - #if NAZARA_GRAPHICS_SAFE - if (!m_animation) - { - NazaraError("Model has no animation"); - return; - } - #endif - - const Sequence* currentSequence = m_animation->GetSequence(sequenceIndex); - #if NAZARA_GRAPHICS_SAFE - if (!currentSequence) - { - NazaraError("Sequence not found"); - return; - } - #endif - - m_currentSequence = currentSequence; - m_nextFrame = m_currentSequence->firstFrame; - } - - /* - * \brief Makes the bounding volume of this text - */ - - void SkeletalModel::MakeBoundingVolume() const - { - m_boundingVolume.Set(m_skeleton.GetAABB()); - } - - /*! - * \brief Updates the model - */ - - void SkeletalModel::Update() - { - ///TODO - /*if (m_animationEnabled && m_animation) - AdvanceAnimation(m_scene->GetUpdateTime());*/ - } -} diff --git a/src/Nazara/Graphics/SkinningManager.cpp b/src/Nazara/Graphics/SkinningManager.cpp deleted file mode 100644 index 5c148838c..000000000 --- a/src/Nazara/Graphics/SkinningManager.cpp +++ /dev/null @@ -1,262 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - struct BufferData - { - NazaraSlot(SkeletalMesh, OnSkeletalMeshDestroy, skeletalMeshDestroySlot); - - VertexBufferRef buffer; - bool updated; - }; - - using MeshMap = std::unordered_map; - - struct MeshData - { - NazaraSlot(Skeleton, OnSkeletonDestroy, skeletonDestroySlot); - NazaraSlot(Skeleton, OnSkeletonJointsInvalidated, skeletonJointsInvalidatedSlot); - - MeshMap meshMap; - }; - - struct QueueData - { - const SkeletalMesh* mesh; - const Skeleton* skeleton; - VertexBuffer* buffer; - }; - - using SkeletonMap = std::unordered_map; - SkeletonMap s_cache; - std::vector s_skinningQueue; - - /*! - * \brief Skins the mesh for a single thread context - * - * \param mesh Skeletal mesh to get vertex buffer from - * \param skeleton Skeleton to consider for getting data - * \param buffer Vertex buffer symbolizing the transition - */ - - void Skin_MonoCPU(const SkeletalMesh* mesh, const Skeleton* skeleton, VertexBuffer* buffer) - { - BufferMapper inputMapper(mesh->GetVertexBuffer(), BufferAccess_ReadOnly); - BufferMapper outputMapper(buffer, BufferAccess_DiscardAndWrite); - - SkinningData skinningData; - skinningData.inputVertex = static_cast(inputMapper.GetPointer()); - skinningData.outputVertex = static_cast(outputMapper.GetPointer()); - skinningData.joints = skeleton->GetJoints(); - - SkinPositionNormalTangent(skinningData, 0, mesh->GetVertexCount()); - } - - /*! - * \brief Skins the mesh for a multi-threaded context - * - * \param mesh Skeletal mesh to get vertex buffer from - * \param skeleton Skeleton to consider for getting data - * \param buffer Vertex buffer symbolizing the transition - */ - - void Skin_MultiCPU(const SkeletalMesh* mesh, const Skeleton* skeleton, VertexBuffer* buffer) - { - BufferMapper inputMapper(mesh->GetVertexBuffer(), BufferAccess_ReadOnly); - BufferMapper outputMapper(buffer, BufferAccess_DiscardAndWrite); - - SkinningData skinningData; - skinningData.inputVertex = static_cast(inputMapper.GetPointer()); - skinningData.outputVertex = static_cast(outputMapper.GetPointer()); - skinningData.joints = skeleton->GetJoints(); - - // To avoid different threads to update the same matrix at the same time - // We try to update them before launching the tasks - unsigned int jointCount = skeleton->GetJointCount(); - for (unsigned int i = 0; i < jointCount; ++i) - skinningData.joints[i].EnsureSkinningMatrixUpdate(); - - unsigned int workerCount = TaskScheduler::GetWorkerCount(); - - std::ldiv_t div = std::ldiv(mesh->GetVertexCount(), workerCount); - for (unsigned int i = 0; i < workerCount; ++i) - TaskScheduler::AddTask(SkinPositionNormalTangent, skinningData, i*div.quot, (i == workerCount-1) ? div.quot + div.rem : div.quot); - - TaskScheduler::Run(); - TaskScheduler::WaitForTasks(); - } - } - - /*! - * \ingroup graphics - * \class Nz::SkinningManager - * \brief Graphics class that represents the management of skinning - */ - - /*! - * \brief Gets the vertex buffer from a skeletal mesh with its skeleton - * \return A pointer to the vertex buffer newly created - * - * \param mesh Skeletal mesh to get vertex buffer from - * \param skeleton Skeleton to consider for getting data - * - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if mesh is invalid - * \remark Produces a NazaraError with NAZARA_GRAPHICS_SAFE defined if skeleton is invalid - */ - - VertexBuffer* SkinningManager::GetBuffer(const SkeletalMesh* mesh, const Skeleton* skeleton) - { - #if NAZARA_GRAPHICS_SAFE - if (!mesh) - { - NazaraError("Invalid mesh"); - return nullptr; - } - - if (!skeleton) - { - NazaraError("Invalid skeleton"); - return nullptr; - } - #endif - - ErrorFlags flags(ErrorFlag_ThrowException); - - SkeletonMap::iterator it = s_cache.find(skeleton); - if (it == s_cache.end()) - { - MeshData meshData; - meshData.skeletonDestroySlot.Connect(skeleton->OnSkeletonDestroy, OnSkeletonRelease); - meshData.skeletonJointsInvalidatedSlot.Connect(skeleton->OnSkeletonJointsInvalidated, OnSkeletonInvalidated); - - it = s_cache.insert(std::make_pair(skeleton, std::move(meshData))).first; - } - - VertexBuffer* buffer; - - MeshMap& meshMap = it->second.meshMap; - MeshMap::iterator it2 = meshMap.find(mesh); - if (it2 == meshMap.end()) - { - VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), mesh->GetVertexCount(), DataStorage_Hardware, BufferUsage_Dynamic); - - BufferData data; - data.skeletalMeshDestroySlot.Connect(mesh->OnSkeletalMeshDestroy, OnSkeletalMeshDestroy); - data.buffer = vertexBuffer; - data.updated = true; - - meshMap.insert(std::make_pair(mesh, std::move(data))); - - s_skinningQueue.push_back(QueueData{mesh, skeleton, vertexBuffer}); - - buffer = vertexBuffer; - } - else - { - BufferData& data = it2->second; - if (!data.updated) - { - s_skinningQueue.push_back(QueueData{mesh, skeleton, data.buffer}); - data.updated = true; - } - - buffer = data.buffer; - } - - return buffer; - } - - /*! - * \brief Skins the skeletal mesh - */ - - void SkinningManager::Skin() - { - for (QueueData& data : s_skinningQueue) - s_skinFunc(data.mesh, data.skeleton, data.buffer); - - s_skinningQueue.clear(); - } - - /*! - * \brief Initializes the skinning librairies - * \return true - */ - - bool SkinningManager::Initialize() - { - ///TODO: GPU Skinning - if (TaskScheduler::Initialize()) - s_skinFunc = Skin_MultiCPU; - else - s_skinFunc = Skin_MonoCPU; - - return true; // Nothing particular to do - } - - /*! - * \brief Handle the destruction of a skeletal mesh - * - * \param mesh SkeletalMesh being destroyed - */ - - void SkinningManager::OnSkeletalMeshDestroy(const SkeletalMesh* mesh) - { - for (auto& pair : s_cache) - { - MeshMap& meshMap = pair.second.meshMap; - meshMap.erase(mesh); - } - } - - /*! - * \brief Handle the invalidation of a skeletal mesh - * - * \param mesh SkeletalMesh being invalidated - */ - - void SkinningManager::OnSkeletonInvalidated(const Skeleton* skeleton) - { - for (auto& pair : s_cache.at(skeleton).meshMap) - pair.second.updated = false; - } - - /*! - * \brief Handle the release of a skeletal mesh - * - * \param skeleton SkeletalMesh being released - */ - - void SkinningManager::OnSkeletonRelease(const Skeleton* skeleton) - { - s_cache.erase(skeleton); - } - - /*! - * \brief Uninitializes the skinning librairies - */ - - void SkinningManager::Uninitialize() - { - s_cache.clear(); - s_skinningQueue.clear(); - } - - SkinningManager::SkinFunction SkinningManager::s_skinFunc = nullptr; -} diff --git a/src/Nazara/Graphics/SkyboxBackground.cpp b/src/Nazara/Graphics/SkyboxBackground.cpp deleted file mode 100644 index 5415c95f6..000000000 --- a/src/Nazara/Graphics/SkyboxBackground.cpp +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - static IndexBufferRef s_indexBuffer; - static RenderStates s_renderStates; - static ShaderRef s_shader; - static VertexBufferRef s_vertexBuffer; - } - - /*! - * \ingroup graphics - * \class Nz::SkyboxBackground - * \brief Graphics class that represents a background with a cubemap texture - */ - - /*! - * \brief Constructs a SkyboxBackground object with a cubemap texture - * - * \param cubemapTexture Cubemap texture - */ - - SkyboxBackground::SkyboxBackground(TextureRef cubemapTexture) : - m_movementOffset(Vector3f::Zero()), - m_movementScale(0.f) - { - m_sampler.SetWrapMode(SamplerWrap_Clamp); // We don't want to see any beam - - SetTexture(std::move(cubemapTexture)); - } - - /*! - * \brief Draws this relatively to the viewer - * - * \param viewer Viewer for the background - */ - - void SkyboxBackground::Draw(const AbstractViewer* viewer) const - { - const Nz::RenderTarget* target = viewer->GetTarget(); - Nz::Vector2ui targetSize = target->GetSize(); - - Matrix4f skyboxMatrix(viewer->GetViewMatrix()); - skyboxMatrix.SetTranslation(Vector3f::Zero()); - - float zNear = viewer->GetZNear(); - - constexpr float movementLimit = 0.05f; - - Vector3f offset = (viewer->GetEyePosition() - m_movementOffset) * -m_movementScale; - offset.x = Clamp(offset.x, -movementLimit, movementLimit); - offset.y = Clamp(offset.y, -movementLimit, movementLimit); - offset.z = Clamp(offset.z, -movementLimit, movementLimit); - offset *= zNear; - - Matrix4f world; - world.MakeIdentity(); - world.SetScale(Vector3f(zNear)); - world.SetTranslation(offset); - - Renderer::SetIndexBuffer(s_indexBuffer); - Renderer::SetMatrix(MatrixType_Projection, viewer->GetProjectionMatrix()); - Renderer::SetMatrix(MatrixType_View, skyboxMatrix); - Renderer::SetMatrix(MatrixType_World, world); - Renderer::SetRenderStates(s_renderStates); - Renderer::SetShader(s_shader); - Renderer::SetTexture(0, m_texture); - Renderer::SetTextureSampler(0, m_sampler); - Renderer::SetVertexBuffer(s_vertexBuffer); - - Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, 36); - - Renderer::SetMatrix(MatrixType_Projection, viewer->GetProjectionMatrix()); - Renderer::SetMatrix(MatrixType_View, viewer->GetViewMatrix()); - } - - /*! - * \brief Gets the background type - * \return Type of background - */ - - BackgroundType SkyboxBackground::GetBackgroundType() const - { - return BackgroundType_Skybox; - } - - /*! - * \brief Initializes the skybox - * \return true If successful - * - * \remark Produces a NazaraError if initialization failed - */ - - bool SkyboxBackground::Initialize() - { - const UInt16 indices[6 * 6] = - { - 0, 1, 2, 0, 2, 3, - 3, 2, 6, 3, 6, 7, - 7, 6, 5, 7, 5, 4, - 4, 5, 1, 4, 1, 0, - 0, 3, 7, 0, 7, 4, - 1, 6, 2, 1, 5, 6 - }; - - const float vertices[8 * 3 * sizeof(float)] = - { - -1.0, 1.0, 1.0, - -1.0, -1.0, 1.0, - 1.0, -1.0, 1.0, - 1.0, 1.0, 1.0, - -1.0, 1.0, -1.0, - -1.0, -1.0, -1.0, - 1.0, -1.0, -1.0, - 1.0, 1.0, -1.0, - }; - - ///TODO: Replace by ShaderNode (probably after Vulkan) - const char* fragmentShaderSource = - "#version 140\n" - - "in vec3 vTexCoord;\n" - - "out vec4 RenderTarget0;\n" - - "uniform samplerCube Skybox;\n" - "uniform float VertexDepth;\n" - - "void main()\n" - "{\n" - " RenderTarget0 = texture(Skybox, vTexCoord);\n" - " gl_FragDepth = VertexDepth;\n" - "}\n"; - - const char* vertexShaderSource = - "#version 140\n" - - "in vec3 VertexPosition;\n" - - "out vec3 vTexCoord;\n" - - "uniform mat4 WorldViewProjMatrix;\n" - - "void main()\n" - "{\n" - " vec4 WVPVertex = WorldViewProjMatrix * vec4(VertexPosition, 1.0);\n" - " gl_Position = WVPVertex.xyww;\n" - " vTexCoord = VertexPosition;\n" - "}\n"; - - try - { - ErrorFlags flags(ErrorFlag_ThrowException, true); - - // Index buffer - IndexBufferRef indexBuffer = IndexBuffer::New(false, 36, DataStorage_Hardware, 0); - indexBuffer->Fill(indices, 0, 36); - - // Vertex buffer - VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ), 8, DataStorage_Hardware, 0); - vertexBuffer->Fill(vertices, 0, 8); - - // Shader - ShaderRef shader = Shader::New(); - shader->Create(); - shader->AttachStageFromSource(ShaderStageType_Fragment, fragmentShaderSource); - shader->AttachStageFromSource(ShaderStageType_Vertex, vertexShaderSource); - shader->Link(); - - shader->SendInteger(shader->GetUniformLocation("Skybox"), 0); - shader->SendFloat(shader->GetUniformLocation("VertexDepth"), 1.f); - - // Renderstates - s_renderStates.depthFunc = RendererComparison_Equal; - s_renderStates.cullingSide = FaceSide_Front; - s_renderStates.depthBuffer = true; - s_renderStates.depthWrite = false; - s_renderStates.faceCulling = true; - - // Exception-free zone - s_indexBuffer = std::move(indexBuffer); - s_shader = std::move(shader); - s_vertexBuffer = std::move(vertexBuffer); - } - catch (const std::exception& e) - { - NazaraError("Failed to initialise: " + String(e.what())); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the skybox - */ - - void SkyboxBackground::Uninitialize() - { - s_indexBuffer.Reset(); - s_shader.Reset(); - s_vertexBuffer.Reset(); - } -} diff --git a/src/Nazara/Graphics/Sprite.cpp b/src/Nazara/Graphics/Sprite.cpp deleted file mode 100644 index 07499c3af..000000000 --- a/src/Nazara/Graphics/Sprite.cpp +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::Sprite - * \brief Graphics class that represents the rendering of a sprite - */ - - /*! - * \brief Adds the sprite to the rendering queue - * - * \param renderQueue Queue to be added - * \param instanceData Data for the instance - */ - void Sprite::AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const - { - const VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast(instanceData.data.data()); - renderQueue->AddSprites(instanceData.renderOrder, GetMaterial(), vertices, 1, scissorRect); - } - - /*! - * \brief Clones this sprite - */ - std::unique_ptr Sprite::Clone() const - { - return std::make_unique(*this); - } - - /*! - * \brief Makes the bounding volume of this text - */ - void Sprite::MakeBoundingVolume() const - { - Vector3f origin(m_origin.x, -m_origin.y, m_origin.z); - - m_boundingVolume.Set(-origin, m_size.x*Vector3f::Right() + m_size.y*Vector3f::Down() - origin); - } - - /*! - * \brief Sets the material of the sprite from a name - * - * Tries to get a material from the MaterialLibrary and then the MaterialManager (which will treat the name as a path) - * Fails if the texture name is not a part of the MaterialLibrary nor the MaterialManager (which fails if it couldn't load the texture from its filepath) - * - * \param materialName Named texture for the material - * \param resizeSprite Should the sprite be resized to the material diffuse map size? - * - * \return True if the material was found or loaded from its name/path, false if it couldn't - */ - bool Sprite::SetMaterial(std::string materialName, bool resizeSprite) - { - MaterialRef material = MaterialLibrary::Query(materialName); - if (!material) - { - material = MaterialManager::Get(materialName); - if (!material) - { - NazaraError("Failed to get material \"" + materialName + "\""); - return false; - } - } - - SetMaterial(std::move(material), resizeSprite); - return true; - } - - /*! - * \brief Sets the material of the sprite from a name for a specific skin - * - * Tries to get a material from the MaterialLibrary and then the MaterialManager (which will treat the name as a path) - * Fails if the texture name is not a part of the MaterialLibrary nor the MaterialManager (which fails if it couldn't load the texture from its filepath) - * - * \param skinIndex Skin index to change - * \param materialName Named texture for the material - * \param resizeSprite Should the sprite be resized to the material diffuse map size? - * - * \return True if the material was found or loaded from its name/path, false if it couldn't - */ - bool Sprite::SetMaterial(std::size_t skinIndex, std::string materialName, bool resizeSprite) - { - MaterialRef material = MaterialLibrary::Query(materialName); - if (!material) - { - material = MaterialManager::Get(materialName); - if (!material) - { - NazaraError("Failed to get material \"" + materialName + "\""); - return false; - } - } - - SetMaterial(skinIndex, std::move(material), resizeSprite); - return true; - } - - /*! - * \brief Sets the texture of the sprite from a name for the current skin - * \return True if the texture was found or loaded from its name/path, false if it couldn't - * - * Tries to get a texture from the TextureLibrary and then the TextureManager (which will treat the name as a path) - * Fails if the texture name is not a part of the TextureLibrary nor the TextureManager (which fails if it couldn't load the texture from its filepath) - * - * \param textureName Named texture for the sprite - * \param resizeSprite Should the sprite be resized to the texture size? - * - * \remark The sprite material gets copied to prevent accidentally changing other drawable materials - */ - bool Sprite::SetTexture(std::string textureName, bool resizeSprite) - { - TextureRef texture = TextureLibrary::Query(textureName); - if (!texture) - { - texture = TextureManager::Get(textureName); - if (!texture) - { - NazaraError("Failed to get texture \"" + textureName + "\""); - return false; - } - } - - SetTexture(std::move(texture), resizeSprite); - return true; - } - - /*! - * \brief Sets the texture of the sprite from a name for a specific skin - * \return True if the texture was found or loaded from its name/path, false if it couldn't - * - * Tries to get a texture from the TextureLibrary and then the TextureManager (which will treat the name as a path) - * Fails if the texture name is not a part of the TextureLibrary nor the TextureManager (which fails if it couldn't load the texture from its filepath) - * - * \param skinIndex Named texture for the sprite - * \param textureName Named texture for the sprite - * \param resizeSprite Should the sprite be resized to the texture size? - * - * \remark The sprite material gets copied to prevent accidentally changing other drawable materials - */ - bool Sprite::SetTexture(std::size_t skinIndex, std::string textureName, bool resizeSprite) - { - TextureRef texture = TextureLibrary::Query(textureName); - if (!texture) - { - texture = TextureManager::Get(textureName); - if (!texture) - { - NazaraError("Failed to get texture \"" + textureName + "\""); - return false; - } - } - - SetTexture(skinIndex, std::move(texture), resizeSprite); - return true; - } - - /*! - * \brief Updates the data of the sprite - * - * \param instanceData Data of the instance - */ - void Sprite::UpdateData(InstanceData* instanceData) const - { - instanceData->data.resize(4 * sizeof(VertexStruct_XYZ_Color_UV)); - VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast(instanceData->data.data()); - - SparsePtr colorPtr(&vertices[0].color, sizeof(VertexStruct_XYZ_Color_UV)); - SparsePtr posPtr(&vertices[0].position, sizeof(VertexStruct_XYZ_Color_UV)); - SparsePtr texCoordPtr(&vertices[0].uv, sizeof(VertexStruct_XYZ_Color_UV)); - - Vector3f origin(m_origin.x, -m_origin.y, m_origin.z); - - *colorPtr++ = m_color * m_cornerColor[RectCorner_LeftTop]; - *posPtr++ = instanceData->transformMatrix.Transform(Vector3f(-origin)); - *texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_LeftTop); - - *colorPtr++ = m_color * m_cornerColor[RectCorner_RightTop]; - *posPtr++ = instanceData->transformMatrix.Transform(m_size.x*Vector3f::Right() - origin); - *texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_RightTop); - - *colorPtr++ = m_color * m_cornerColor[RectCorner_LeftBottom]; - *posPtr++ = instanceData->transformMatrix.Transform(m_size.y*Vector3f::Down() - origin); - *texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_LeftBottom); - - *colorPtr++ = m_color * m_cornerColor[RectCorner_RightBottom]; - *posPtr++ = instanceData->transformMatrix.Transform(m_size.x*Vector3f::Right() + m_size.y*Vector3f::Down() - origin); - *texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_RightBottom); - } - - /*! - * \brief Initializes the sprite library - * \return true If successful - * - * \remark Produces a NazaraError if the sprite library failed to be initialized - */ - - bool Sprite::Initialize() - { - if (!SpriteLibrary::Initialize()) - { - NazaraError("Failed to initialise library"); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the sprite library - */ - - void Sprite::Uninitialize() - { - SpriteLibrary::Uninitialize(); - } - - SpriteLibrary::LibraryMap Sprite::s_library; -} diff --git a/src/Nazara/Graphics/TextSprite.cpp b/src/Nazara/Graphics/TextSprite.cpp deleted file mode 100644 index 8f00aba93..000000000 --- a/src/Nazara/Graphics/TextSprite.cpp +++ /dev/null @@ -1,343 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::TextSprite - * \brief Graphics class that represents the rendering of a sprite containing text - */ - - /*! - * \brief Adds the text to the rendering queue - * - * \param renderQueue Queue to be added - * \param instanceData Data for the instance - */ - - void TextSprite::AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const - { - for (auto& pair : m_renderInfos) - { - const RenderKey& key = pair.first; - RenderIndices& indices = pair.second; - - if (indices.count > 0) - { - const VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast(instanceData.data.data()); - renderQueue->AddSprites(instanceData.renderOrder + key.renderOrder, GetMaterial(), &vertices[indices.first * 4], indices.count, scissorRect, key.texture); - } - } - } - - /*! - * \brief Clones this text sprite - */ - std::unique_ptr TextSprite::Clone() const - { - return std::make_unique(*this); - } - - /*! - * \brief Updates the text - * - * \param drawer Drawer used to compose the text - * - * \remark Produces a NazaraAssert if atlas does not use a hardware storage - */ - - void TextSprite::Update(const AbstractTextDrawer& drawer) - { - CallOnExit clearOnFail([this]() - { - Clear(); - }); - - // Mark every atlas as unused... - for (auto& pair : m_atlases) - pair.second.used = false; - - // ... until they are marked as used by the drawer - std::size_t fontCount = drawer.GetFontCount(); - for (std::size_t i = 0; i < fontCount; ++i) - { - Font* font = drawer.GetFont(i); - const AbstractAtlas* atlas = font->GetAtlas().get(); - NazaraAssert(atlas->GetStorage() == DataStorage_Hardware, "Font uses a non-hardware atlas which cannot be used by text sprites"); - - auto it = m_atlases.find(atlas); - if (it == m_atlases.end()) - { - it = m_atlases.insert(std::make_pair(atlas, AtlasSlots())).first; - AtlasSlots& atlasSlots = it->second; - - atlasSlots.clearSlot.Connect(atlas->OnAtlasCleared, this, &TextSprite::OnAtlasInvalidated); - atlasSlots.layerChangeSlot.Connect(atlas->OnAtlasLayerChange, this, &TextSprite::OnAtlasLayerChange); - atlasSlots.releaseSlot.Connect(atlas->OnAtlasRelease, this, &TextSprite::OnAtlasInvalidated); - } - - it->second.used = true; - } - - // Remove unused atlas slots - auto atlasIt = m_atlases.begin(); - while (atlasIt != m_atlases.end()) - { - if (!atlasIt->second.used) - m_atlases.erase(atlasIt++); - else - ++atlasIt; - } - - std::size_t glyphCount = drawer.GetGlyphCount(); - - // Reset glyph count for every texture to zero - for (auto& pair : m_renderInfos) - pair.second.count = 0; - - // Count glyph count for each texture - RenderKey lastRenderKey { nullptr, 0 }; - unsigned int* count = nullptr; - - std::size_t visibleGlyphCount = 0; - for (std::size_t i = 0; i < glyphCount; ++i) - { - const AbstractTextDrawer::Glyph& glyph = drawer.GetGlyph(i); - if (!glyph.atlas) - continue; - - Texture* texture = static_cast(glyph.atlas); - RenderKey renderKey{ texture, glyph.renderOrder }; - if (lastRenderKey != renderKey) - { - auto it = m_renderInfos.find(renderKey); - if (it == m_renderInfos.end()) - it = m_renderInfos.insert(std::make_pair(renderKey, RenderIndices{0U, 0U})).first; - - count = &it->second.count; - lastRenderKey = renderKey; - } - - (*count)++; - visibleGlyphCount++; - } - - m_localVertices.resize(visibleGlyphCount * 4); - - // Attributes indices and reinitialize glyph count to zero to use it as a counter in the next loop - // This is because the 1st glyph can use texture A, the 2nd glyph can use texture B and the 3th glyph C can use texture A again - // so we need a counter to know where to write informations - // also remove unused render infos - unsigned int index = 0; - auto infoIt = m_renderInfos.begin(); - while (infoIt != m_renderInfos.end()) - { - RenderIndices& indices = infoIt->second; - if (indices.count == 0) - infoIt = m_renderInfos.erase(infoIt); //< No glyph uses this texture, remove from indices - else - { - indices.first = index; - - index += indices.count; - indices.count = 0; - ++infoIt; - } - } - - lastRenderKey = { nullptr, 0 }; - RenderIndices* indices = nullptr; - for (unsigned int i = 0; i < glyphCount; ++i) - { - const AbstractTextDrawer::Glyph& glyph = drawer.GetGlyph(i); - if (!glyph.atlas) - continue; - - Texture* texture = static_cast(glyph.atlas); - RenderKey renderKey{ texture, glyph.renderOrder }; - if (lastRenderKey != renderKey) - { - indices = &m_renderInfos[renderKey]; //< We changed texture, adjust the pointer - lastRenderKey = renderKey; - } - - // First, compute the uv coordinates from our atlas rect - Vector2ui size(texture->GetSize()); - float invWidth = 1.f / size.x; - float invHeight = 1.f / size.y; - - Rectf uvRect(glyph.atlasRect); - uvRect.x *= invWidth; - uvRect.y *= invHeight; - uvRect.width *= invWidth; - uvRect.height *= invHeight; - - // Our glyph may be flipped in the atlas, to render it correctly we need to change the uv coordinates accordingly - const RectCorner normalCorners[4] = {RectCorner_LeftTop, RectCorner_RightTop, RectCorner_LeftBottom, RectCorner_RightBottom}; - const RectCorner flippedCorners[4] = {RectCorner_LeftBottom, RectCorner_LeftTop, RectCorner_RightBottom, RectCorner_RightTop}; - - // Set the position, color and UV of our vertices - for (unsigned int j = 0; j < 4; ++j) - { - // Remember that indices->count is a counter here, not a count value - std::size_t offset = (indices->first + indices->count) * 4 + j; - m_localVertices[offset].color = glyph.color; - m_localVertices[offset].position.Set(glyph.corners[j]); - m_localVertices[offset].uv.Set(uvRect.GetCorner((glyph.flipped) ? flippedCorners[j] : normalCorners[j])); - } - - // Increment the counter, go to next glyph - indices->count++; - } - - m_localBounds = drawer.GetBounds(); - - InvalidateBoundingVolume(); - InvalidateInstanceData(0); - - clearOnFail.Reset(); - } - - /* - * \brief Makes the bounding volume of this text - */ - - void TextSprite::MakeBoundingVolume() const - { - Vector2f max = m_scale * m_localBounds.GetMaximum(); - Vector2f min = m_scale * m_localBounds.GetMinimum(); - - m_boundingVolume.Set(min.x * Vector3f::Right() + min.y * Vector3f::Down(), max.x * Vector3f::Right() + max.y * Vector3f::Down()); - } - - /*! - * \brief Handle the invalidation of an atlas - * - * \param atlas Atlas being invalidated - */ - - void TextSprite::OnAtlasInvalidated(const AbstractAtlas* atlas) - { - #ifdef NAZARA_DEBUG - if (m_atlases.find(atlas) == m_atlases.end()) - { - NazaraInternalError("Not listening to " + String::Pointer(atlas)); - return; - } - #endif - - NazaraWarning("TextSprite " + String::Pointer(this) + " has been cleared because atlas " + String::Pointer(atlas) + " has been invalidated (cleared or released)"); - Clear(); - } - - /*! - * \brief Handle the size change of an atlas layer - * - * \param atlas Atlas being invalidated - * \param oldLayer Pointer to the previous layer - * \param newLayer Pointer to the new layer - */ - void TextSprite::OnAtlasLayerChange(const AbstractAtlas* atlas, AbstractImage* oldLayer, AbstractImage* newLayer) - { - NazaraUnused(atlas); - - #ifdef NAZARA_DEBUG - if (m_atlases.find(atlas) == m_atlases.end()) - { - NazaraInternalError("Not listening to " + String::Pointer(atlas)); - return; - } - #endif - - if (!oldLayer) - return; - - assert(newLayer); - - // The texture of an atlas have just been recreated (size change) - // we have to adjust the coordinates of the texture and the rendering texture - Texture* oldTexture = static_cast(oldLayer); - Texture* newTexture = static_cast(newLayer); - - Vector2ui oldSize(oldTexture->GetSize()); - Vector2ui newSize(newTexture->GetSize()); - Vector2f scale = Vector2f(oldSize) / Vector2f(newSize); // ratio of the old one to the new one - - // It is possible we actually use that texture multiple times, check them all - for (auto it = m_renderInfos.begin(); it != m_renderInfos.end(); ++it) - { - const RenderKey& renderKey = it->first; - const RenderIndices& indices = it->second; - - // Adjust texture coordinates by size ratio - SparsePtr texCoordPtr(&m_localVertices[indices.first].uv, sizeof(VertexStruct_XY_Color_UV)); - for (unsigned int i = 0; i < indices.count; ++i) - { - for (unsigned int j = 0; j < 4; ++j) - m_localVertices[i * 4 + j].uv *= scale; - } - - // Erase and re-insert with the new texture handle - m_renderInfos.erase(it); - m_renderInfos.insert(std::make_pair(RenderKey{ newTexture, renderKey.renderOrder }, indices)); - it = m_renderInfos.begin(); //< std::unordered_map::insert may invalidate all iterators, start from the beginning... - } - } - - /*! - * \brief Updates the data of the sprite - * - * \param instanceData Data of the instance - */ - - void TextSprite::UpdateData(InstanceData* instanceData) const - { - instanceData->data.resize(m_localVertices.size() * sizeof(VertexStruct_XYZ_Color_UV)); - VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast(instanceData->data.data()); - - SparsePtr colorPtr(&vertices[0].color, sizeof(VertexStruct_XYZ_Color_UV)); - SparsePtr posPtr(&vertices[0].position, sizeof(VertexStruct_XYZ_Color_UV)); - SparsePtr texCoordPtr(&vertices[0].uv, sizeof(VertexStruct_XYZ_Color_UV)); - - // We will not initialize the final vertices (those send to the RenderQueue) - // With the help of the coordinates axis, the matrix and our color attribute - for (auto& pair : m_renderInfos) - { - RenderIndices& indices = pair.second; - if (indices.count == 0) - continue; //< Ignore empty render indices - - SparsePtr color = colorPtr + indices.first * 4; - SparsePtr pos = posPtr + indices.first * 4; - SparsePtr uv = texCoordPtr + indices.first * 4; - VertexStruct_XY_Color_UV* localVertex = &m_localVertices[indices.first * 4]; - for (unsigned int i = 0; i < indices.count; ++i) - { - for (unsigned int j = 0; j < 4; ++j) - { - Vector3f localPos = localVertex->position.x*Vector3f::Right() + localVertex->position.y*Vector3f::Down(); - localPos *= m_scale; - - *pos++ = instanceData->transformMatrix.Transform(localPos); - *color++ = m_color * localVertex->color; - *uv++ = localVertex->uv; - - localVertex++; - } - } - } - } - - TextSpriteLibrary::LibraryMap TextSprite::s_library; -} diff --git a/src/Nazara/Graphics/TextureBackground.cpp b/src/Nazara/Graphics/TextureBackground.cpp deleted file mode 100644 index 9b115ecef..000000000 --- a/src/Nazara/Graphics/TextureBackground.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - /*! - * \brief Defines render states - * \return RenderStates for the color background - */ - - RenderStates BuildRenderStates() - { - RenderStates states; - states.depthFunc = RendererComparison_Equal; - states.cullingSide = FaceSide_Back; - states.depthBuffer = true; - states.depthWrite = false; - states.faceCulling = true; - - return states; - } - } - - /*! - * \ingroup graphics - * \class Nz::TextureBackground - * \brief Graphics class that represents a background with a texture - */ - - /*! - * \brief Constructs a TextureBackground object with a texture - * - * \param texture Texture - */ - - TextureBackground::TextureBackground(TextureRef texture) - { - m_uberShader = UberShaderLibrary::Get("Basic"); - - ParameterList list; - list.SetParameter("DIFFUSE_MAPPING", true); - list.SetParameter("TEXTURE_MAPPING", true); - list.SetParameter("UNIFORM_VERTEX_DEPTH", true); - - m_uberShaderInstance = m_uberShader->Get(list); - - const Shader* shader = m_uberShaderInstance->GetShader(); - m_materialDiffuseUniform = shader->GetUniformLocation("MaterialDiffuse"); - m_materialDiffuseMapUniform = shader->GetUniformLocation("MaterialDiffuseMap"); - m_vertexDepthUniform = shader->GetUniformLocation("VertexDepth"); - - SetTexture(std::move(texture)); - } - - /*! - * \brief Draws this relatively to the viewer - * - * \param viewer Viewer for the background - */ - - void TextureBackground::Draw(const AbstractViewer* viewer) const - { - NazaraUnused(viewer); - - static RenderStates states(BuildRenderStates()); - - Renderer::SetRenderStates(states); - Renderer::SetTexture(0, m_texture); - - m_uberShaderInstance->Activate(); - - const Shader* shader = m_uberShaderInstance->GetShader(); - shader->SendColor(m_materialDiffuseUniform, Color::White); - shader->SendFloat(m_vertexDepthUniform, 1.f); - shader->SendInteger(m_materialDiffuseMapUniform, 0); - - Renderer::DrawFullscreenQuad(); - } - - /*! - * \brief Gets the background type - * \return Type of background - */ - - BackgroundType TextureBackground::GetBackgroundType() const - { - return BackgroundType_Texture; - } -} diff --git a/src/Nazara/Graphics/TileMap.cpp b/src/Nazara/Graphics/TileMap.cpp deleted file mode 100644 index 71bdc6af1..000000000 --- a/src/Nazara/Graphics/TileMap.cpp +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Graphics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup graphics - * \class Nz::TileMap - * \brief Graphics class that represent several tiles of the same size assembled into a grid - * This class is far more efficient than using a sprite for every tile - */ - - /*! - * \brief Adds the TileMap to the rendering queue - * - * \param renderQueue Queue to be added - * \param instanceData Data for the instance - */ - void TileMap::AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const - { - const VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast(instanceData.data.data()); - - std::size_t spriteCount = 0; - for (std::size_t layerIndex = 0; layerIndex < m_layers.size(); ++layerIndex) - { - const auto& layer = m_layers[layerIndex]; - if (layer.tiles.empty()) - continue; - - renderQueue->AddSprites(instanceData.renderOrder, GetMaterial(layerIndex), &vertices[4 * spriteCount], layer.tiles.size(), scissorRect); - - spriteCount += layer.tiles.size(); - } - } - - /*! - * \brief Clones this tilemap - */ - std::unique_ptr TileMap::Clone() const - { - return std::make_unique(*this); - } - - void TileMap::MakeBoundingVolume() const - { - Nz::Vector2f size = GetSize(); - m_boundingVolume.Set(Vector3f(0.f), size.x*Vector3f::Right() + size.y*Vector3f::Down()); - } - - void TileMap::UpdateData(InstanceData* instanceData) const - { - std::size_t spriteCount = 0; - for (const Layer& layer : m_layers) - spriteCount += layer.tiles.size(); - - instanceData->data.resize(4 * spriteCount * sizeof(VertexStruct_XYZ_Color_UV)); - VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast(instanceData->data.data()); - - spriteCount = 0; - for (const Layer& layer : m_layers) - { - SparsePtr colorPtr(&vertices[4 * spriteCount].color, sizeof(VertexStruct_XYZ_Color_UV)); - SparsePtr posPtr(&vertices[4 * spriteCount].position, sizeof(VertexStruct_XYZ_Color_UV)); - SparsePtr texCoordPtr(&vertices[4 * spriteCount].uv, sizeof(VertexStruct_XYZ_Color_UV)); - - for (std::size_t tileIndex : layer.tiles) - { - const Tile& tile = m_tiles[tileIndex]; - NazaraAssert(tile.enabled, "Tile specified for rendering is not enabled"); - - std::size_t x = tileIndex % m_mapSize.x; - std::size_t y = tileIndex / m_mapSize.x; - - Vector3f tileLeftCorner; - if (m_isometricModeEnabled) - tileLeftCorner.Set(x * m_tileSize.x + m_tileSize.x/2.f * (y % 2), y/2.f * -m_tileSize.y, 0.f); - else - tileLeftCorner.Set(x * m_tileSize.x, y * -m_tileSize.y, 0.f); - - *colorPtr++ = tile.color; - *posPtr++ = instanceData->transformMatrix.Transform(tileLeftCorner); - *texCoordPtr++ = tile.textureCoords.GetCorner(RectCorner_LeftTop); - - *colorPtr++ = tile.color; - *posPtr++ = instanceData->transformMatrix.Transform(tileLeftCorner + m_tileSize.x * Vector3f::Right()); - *texCoordPtr++ = tile.textureCoords.GetCorner(RectCorner_RightTop); - - *colorPtr++ = tile.color; - *posPtr++ = instanceData->transformMatrix.Transform(tileLeftCorner + m_tileSize.y * Vector3f::Down()); - *texCoordPtr++ = tile.textureCoords.GetCorner(RectCorner_LeftBottom); - - *colorPtr++ = tile.color; - *posPtr++ = instanceData->transformMatrix.Transform(tileLeftCorner + m_tileSize.x * Vector3f::Right() + m_tileSize.y * Vector3f::Down()); - *texCoordPtr++ = tile.textureCoords.GetCorner(RectCorner_RightBottom); - } - spriteCount += layer.tiles.size(); - } - } - - /*! - * \brief Initializes the tilemap library - * \return true If successful - * - * \remark Produces a NazaraError if the tilemap library failed to be initialized - */ - - bool TileMap::Initialize() - { - if (!TileMapLibrary::Initialize()) - { - NazaraError("Failed to initialise library"); - return false; - } - - return true; - } - - /*! - * \brief Uninitializes the tilemap library - */ - - void TileMap::Uninitialize() - { - TileMapLibrary::Uninitialize(); - } - - TileMapLibrary::LibraryMap TileMap::s_library; -} diff --git a/src/NazaraSDK/Application.cpp b/src/NazaraSDK/Application.cpp index 4bfb97a0c..4c01e3683 100644 --- a/src/NazaraSDK/Application.cpp +++ b/src/NazaraSDK/Application.cpp @@ -7,12 +7,8 @@ #include #ifndef NDK_SERVER -#include #include -#include -#include #include -#include #endif namespace Ndk @@ -63,14 +59,6 @@ namespace Ndk else NazaraWarning("Ignored command-line argument #" + Nz::String::Number(i) + " \"" + argument + '"'); } - - #ifndef NDK_SERVER - if (HasOption("console")) - EnableConsole(true); - - if (HasOption("fpscounter")) - EnableFPSCounter(true); - #endif } /*! @@ -111,119 +99,8 @@ namespace Ndk for (World& world : m_worlds) world.Update(m_updateTime); - #ifndef NDK_SERVER - for (WindowInfo& info : m_windows) - { - if (!info.overlayWorld) - continue; - - if (info.fpsCounter) - { - FPSCounterOverlay& fpsCounter = *info.fpsCounter; - - fpsCounter.frameCount++; - - fpsCounter.elapsedTime += m_updateTime; - if (fpsCounter.elapsedTime >= 1.f) - { - fpsCounter.sprite->Update(Nz::SimpleTextDrawer::Draw("FPS: " + Nz::String::Number(fpsCounter.frameCount), 36)); - fpsCounter.frameCount = 0; - fpsCounter.elapsedTime = 0.f; - } - } - - info.overlayWorld->Update(m_updateTime); - } - #endif - return true; } - #ifndef NDK_SERVER - void Application::SetupConsole(WindowInfo& info) - { - std::unique_ptr overlay = std::make_unique(); - - Nz::Vector2ui windowDimensions; - if (info.window->IsValid()) - windowDimensions = info.window->GetSize(); - else - windowDimensions.MakeZero(); - - overlay->console = info.canvas->Add(); - - Console& consoleRef = *overlay->console; - consoleRef.Resize({float(windowDimensions.x), windowDimensions.y / 4.f}); - consoleRef.Show(false); - - // Redirect logs toward the console - overlay->logSlot.Connect(Nz::Log::OnLogWrite, [&consoleRef] (const Nz::String& str) - { - consoleRef.AddLine(str); - }); - - // Setup a few event callback to handle the console - Nz::EventHandler& eventHandler = info.window->GetEventHandler(); - - overlay->keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&consoleRef] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event) - { - if (event.virtualKey == Nz::Keyboard::VKey::F9) - { - // Toggle console visibility and focus - if (consoleRef.IsVisible()) - { - consoleRef.ClearFocus(); - consoleRef.Show(false); - } - else - { - consoleRef.Show(true); - consoleRef.SetFocus(); - } - } - }); - - overlay->resizedSlot.Connect(info.renderTarget->OnRenderTargetSizeChange, [&consoleRef] (const Nz::RenderTarget* renderTarget) - { - Nz::Vector2ui size = renderTarget->GetSize(); - consoleRef.Resize({float(size.x), size.y / 4.f}); - }); - - info.console = std::move(overlay); - } - - void Application::SetupFPSCounter(WindowInfo& info) - { - std::unique_ptr fpsCounter = std::make_unique(); - fpsCounter->sprite = Nz::TextSprite::New(); - - fpsCounter->entity = info.overlayWorld->CreateEntity(); - fpsCounter->entity->AddComponent(); - fpsCounter->entity->AddComponent().Attach(fpsCounter->sprite); - - info.fpsCounter = std::move(fpsCounter); - } - - void Application::SetupOverlay(WindowInfo& info) - { - info.overlayWorld = std::make_unique(false); //< No default system - - if (info.window->IsValid()) - info.canvas = std::make_unique(info.overlayWorld->CreateHandle(), info.window->GetEventHandler(), info.window->GetCursorController().CreateHandle()); - - RenderSystem& renderSystem = info.overlayWorld->AddSystem(); - renderSystem.ChangeRenderTechnique(); - renderSystem.SetDefaultBackground(nullptr); - renderSystem.SetGlobalUp(Nz::Vector3f::Down()); - - EntityHandle viewer = info.overlayWorld->CreateEntity(); - CameraComponent& camComponent = viewer->AddComponent(); - viewer->AddComponent(); - - camComponent.SetProjectionType(Nz::ProjectionType_Orthogonal); - camComponent.SetTarget(info.renderTarget); - } - #endif - Application* Application::s_application = nullptr; } diff --git a/src/NazaraSDK/BaseWidget.cpp b/src/NazaraSDK/BaseWidget.cpp deleted file mode 100644 index 3897a23c7..000000000 --- a/src/NazaraSDK/BaseWidget.cpp +++ /dev/null @@ -1,381 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::BaseWidget - * \brief Abstract class serving as a base class for all widgets - */ - - /*! - * \brief Constructs a BaseWidget object using another widget as its parent - * - * \param parent Parent widget, must be valid and attached to a canvas - * - * Constructs a BaseWidget object using another widget as a base. - * This will also register the widget to the canvas owning the top-most widget. - */ - BaseWidget::BaseWidget(BaseWidget* parent) : - BaseWidget() - { - NazaraAssert(parent, "Invalid parent"); - NazaraAssert(parent->GetCanvas(), "Parent has no canvas"); - - m_canvas = parent->GetCanvas(); - m_widgetParent = parent; - m_world = m_canvas->GetWorld(); - - RegisterToCanvas(); - } - - /*! - * \brief Frees the widget, unregistering it from its canvas - */ - BaseWidget::~BaseWidget() - { - UnregisterFromCanvas(); - } - - /*! - * \brief Clears keyboard focus if and only if this widget owns it. - */ - void BaseWidget::ClearFocus() - { - if (IsRegisteredToCanvas()) - m_canvas->ClearKeyboardOwner(m_canvasIndex); - } - - /*! - * \brief Destroy the widget, deleting it in the process. - * - * Calling this function immediately destroys the widget, freeing its memory. - */ - void BaseWidget::Destroy() - { - NazaraAssert(this != m_canvas, "Canvas cannot be destroyed by calling Destroy()"); - - m_widgetParent->DestroyChild(this); //< This does delete us - } - - /*! - * \brief Enable or disables the widget background. - */ - void BaseWidget::EnableBackground(bool enable) - { - if (m_backgroundEntity.IsValid() == enable) - return; - - if (enable) - { - m_backgroundSprite = Nz::Sprite::New(); - m_backgroundSprite->SetColor(m_backgroundColor); - m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D")); //< TODO: Use a shared material instead of creating one everytime - - m_backgroundEntity = CreateEntity(); - m_backgroundEntity->AddComponent().Attach(m_backgroundSprite, -1); - m_backgroundEntity->AddComponent().SetParent(this); - - BaseWidget::Layout(); // Only layout background - } - else - { - DestroyEntity(m_backgroundEntity); - m_backgroundEntity.Reset(); - m_backgroundSprite.Reset(); - } - } - - /*! - * \brief Checks if this widget has keyboard focus - * \return true if widget has keyboard focus, false otherwise - */ - bool BaseWidget::HasFocus() const - { - if (!IsRegisteredToCanvas()) - return false; - - return m_canvas->IsKeyboardOwner(m_canvasIndex); - } - - void BaseWidget::Resize(const Nz::Vector2f& size) - { - // Adjust new size - Nz::Vector2f newSize = size; - newSize.Maximize(m_minimumSize); - newSize.Minimize(m_maximumSize); - - NotifyParentResized(newSize); - m_size = newSize; - - Layout(); - } - - void BaseWidget::SetBackgroundColor(const Nz::Color& color) - { - m_backgroundColor = color; - - if (m_backgroundSprite) - { - m_backgroundSprite->SetColor(color); - m_backgroundSprite->GetMaterial()->Configure((color.IsOpaque()) ? "Basic2D" : "Translucent2D"); //< Our sprite has its own material (see EnableBackground) - } - } - - void BaseWidget::SetCursor(Nz::SystemCursor systemCursor) - { - m_cursor = systemCursor; - - if (IsRegisteredToCanvas()) - m_canvas->NotifyWidgetCursorUpdate(m_canvasIndex); - } - - void BaseWidget::SetFocus() - { - if (IsRegisteredToCanvas()) - m_canvas->SetKeyboardOwner(m_canvasIndex); - } - - void BaseWidget::SetParent(BaseWidget* widget) - { - Canvas* oldCanvas = m_canvas; - Canvas* newCanvas = widget->GetCanvas(); - - // Changing a widget canvas is a problem because of the canvas entities - NazaraAssert(oldCanvas == newCanvas, "Transferring a widget between canvas is not yet supported"); - - Node::SetParent(widget); - m_widgetParent = widget; - - Layout(); - } - - void BaseWidget::SetRenderingRect(const Nz::Rectf& renderingRect) - { - m_renderingRect = renderingRect; - - UpdatePositionAndSize(); - for (const auto& widgetPtr : m_children) - widgetPtr->UpdatePositionAndSize(); - } - - void BaseWidget::Show(bool show) - { - if (m_visible != show) - { - m_visible = show; - - if (m_visible) - RegisterToCanvas(); - else - UnregisterFromCanvas(); - - for (WidgetEntity& entity : m_entities) - { - if (entity.isEnabled) - { - entity.handle->Enable(show); //< This will override isEnabled - entity.isEnabled = true; - } - } - - ShowChildren(show); - } - } - - const EntityHandle& BaseWidget::CreateEntity() - { - const EntityHandle& newEntity = m_world->CreateEntity(); - newEntity->Enable(m_visible); - - m_entities.emplace_back(); - WidgetEntity& newWidgetEntity = m_entities.back(); - newWidgetEntity.handle = newEntity; - newWidgetEntity.onDisabledSlot.Connect(newEntity->OnEntityDisabled, [this](Entity* entity) - { - auto it = std::find_if(m_entities.begin(), m_entities.end(), [&](const WidgetEntity& widgetEntity) { return widgetEntity.handle == entity; }); - NazaraAssert(it != m_entities.end(), "Entity does not belong to this widget"); - - it->isEnabled = false; - }); - - newWidgetEntity.onEnabledSlot.Connect(newEntity->OnEntityEnabled, [this](Entity* entity) - { - auto it = std::find_if(m_entities.begin(), m_entities.end(), [&](const WidgetEntity& widgetEntity) { return widgetEntity.handle == entity; }); - NazaraAssert(it != m_entities.end(), "Entity does not belong to this widget"); - - if (!IsVisible()) - entity->Disable(); // Next line will override isEnabled status - - it->isEnabled = true; - }); - - return newEntity; - } - - void BaseWidget::DestroyEntity(Entity* entity) - { - auto it = std::find_if(m_entities.begin(), m_entities.end(), [&](const WidgetEntity& widgetEntity) { return widgetEntity.handle == entity; }); - NazaraAssert(it != m_entities.end(), "Entity does not belong to this widget"); - - m_entities.erase(it); - } - - void BaseWidget::Layout() - { - if (m_backgroundSprite) - m_backgroundSprite->SetSize(m_size.x, m_size.y); - - UpdatePositionAndSize(); - } - - void BaseWidget::InvalidateNode() - { - Node::InvalidateNode(); - - UpdatePositionAndSize(); - } - - Nz::Rectf BaseWidget::GetScissorRect() const - { - Nz::Vector2f widgetPos = Nz::Vector2f(GetPosition(Nz::CoordSys_Global)); - Nz::Vector2f widgetSize = GetSize(); - - Nz::Rectf widgetRect(widgetPos.x, widgetPos.y, widgetSize.x, widgetSize.y); - Nz::Rectf widgetRenderingRect(widgetPos.x + m_renderingRect.x, widgetPos.y + m_renderingRect.y, m_renderingRect.width, m_renderingRect.height); - - widgetRect.Intersect(widgetRenderingRect, &widgetRect); - - return widgetRect; - } - - bool BaseWidget::IsFocusable() const - { - return false; - } - - void BaseWidget::OnFocusLost() - { - } - - void BaseWidget::OnFocusReceived() - { - } - - bool BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) - { - return false; - } - - void BaseWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& /*key*/) - { - } - - void BaseWidget::OnMouseEnter() - { - } - - void BaseWidget::OnMouseMoved(int /*x*/, int /*y*/, int /*deltaX*/, int /*deltaY*/) - { - } - - void BaseWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button /*button*/) - { - } - - void BaseWidget::OnMouseButtonRelease(int /*x*/, int /*y*/, Nz::Mouse::Button /*button*/) - { - } - - void BaseWidget::OnMouseWheelMoved(int /*x*/, int /*y*/, float /*delta*/) - { - } - - void BaseWidget::OnMouseExit() - { - } - - void BaseWidget::OnParentResized(const Nz::Vector2f& /*newSize*/) - { - } - - void BaseWidget::OnTextEntered(char32_t /*character*/, bool /*repeated*/) - { - } - - void BaseWidget::OnTextEdited(const std::array& /*characters*/, int /*length*/) - { - } - - void BaseWidget::ShowChildren(bool show) - { - for (const auto& widgetPtr : m_children) - widgetPtr->Show(show); - } - - void BaseWidget::DestroyChild(BaseWidget* widget) - { - auto it = std::find_if(m_children.begin(), m_children.end(), [widget] (const std::unique_ptr& widgetPtr) -> bool - { - return widgetPtr.get() == widget; - }); - - NazaraAssert(it != m_children.end(), "Child widget not found in parent"); - - m_children.erase(it); - } - - void BaseWidget::DestroyChildren() - { - m_children.clear(); - } - - void BaseWidget::RegisterToCanvas() - { - NazaraAssert(!IsRegisteredToCanvas(), "Widget is already registered to canvas"); - - m_canvasIndex = m_canvas->RegisterWidget(this); - } - - void BaseWidget::UnregisterFromCanvas() - { - if (IsRegisteredToCanvas()) - { - m_canvas->UnregisterWidget(m_canvasIndex); - m_canvasIndex = InvalidCanvasIndex; - } - } - - void BaseWidget::UpdatePositionAndSize() - { - if (IsRegisteredToCanvas()) - m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex); - - Nz::Rectf scissorRect = GetScissorRect(); - - if (m_widgetParent) - { - Nz::Rectf parentScissorRect = m_widgetParent->GetScissorRect(); - - if (!scissorRect.Intersect(parentScissorRect, &scissorRect)) - scissorRect = parentScissorRect; - } - - Nz::Recti fullBounds(scissorRect); - for (WidgetEntity& widgetEntity : m_entities) - { - const Ndk::EntityHandle& entity = widgetEntity.handle; - if (entity->HasComponent()) - entity->GetComponent().SetScissorRect(fullBounds); - } - } -} diff --git a/src/NazaraSDK/Canvas.cpp b/src/NazaraSDK/Canvas.cpp deleted file mode 100644 index f785609e4..000000000 --- a/src/NazaraSDK/Canvas.cpp +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - std::size_t Canvas::RegisterWidget(BaseWidget* widget) - { - WidgetEntry box; - box.cursor = widget->GetCursor(); - box.widget = widget; - - std::size_t index = m_widgetEntries.size(); - m_widgetEntries.emplace_back(box); - - NotifyWidgetBoxUpdate(index); - return index; - } - - void Canvas::UnregisterWidget(std::size_t index) - { - WidgetEntry& entry = m_widgetEntries[index]; - - if (m_hoveredWidget == index) - m_hoveredWidget = InvalidCanvasIndex; - - if (m_keyboardOwner == index) - m_keyboardOwner = InvalidCanvasIndex; - - if (m_widgetEntries.size() > 1U) - { - WidgetEntry& lastEntry = m_widgetEntries.back(); - std::size_t lastEntryIndex = m_widgetEntries.size() - 1; - - entry = std::move(lastEntry); - entry.widget->UpdateCanvasIndex(index); - - if (m_hoveredWidget == lastEntryIndex) - m_hoveredWidget = index; - - if (m_keyboardOwner == lastEntryIndex) - m_keyboardOwner = index; - } - - m_widgetEntries.pop_back(); - } - - void Canvas::OnEventMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event) - { - if (m_hoveredWidget != InvalidCanvasIndex) - { - WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget]; - - int x = static_cast(std::round(event.x - hoveredWidget.box.x)); - int y = static_cast(std::round(event.y - hoveredWidget.box.y)); - - hoveredWidget.widget->OnMouseButtonPress(x, y, event.button); - } - } - - void Canvas::OnEventMouseButtonRelease(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event) - { - if (m_hoveredWidget != InvalidCanvasIndex) - { - WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget]; - - int x = static_cast(std::round(event.x - hoveredWidget.box.x)); - int y = static_cast(std::round(event.y - hoveredWidget.box.y)); - - hoveredWidget.widget->OnMouseButtonRelease(x, y, event.button); - } - } - - void Canvas::OnEventMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event) - { - std::size_t bestEntry = InvalidCanvasIndex; - float bestEntryArea = std::numeric_limits::infinity(); - - Nz::Vector3f mousePos(float(event.x), float(event.y), 0.f); - for (std::size_t i = 0; i < m_widgetEntries.size(); ++i) - { - const Nz::Boxf& box = m_widgetEntries[i].box; - - if (box.Contains(mousePos)) - { - float area = box.width * box.height; - if (area < bestEntryArea) - { - bestEntry = i; - bestEntryArea = area; - } - } - } - - if (bestEntry != InvalidCanvasIndex) - { - if (m_hoveredWidget != bestEntry) - { - if (m_hoveredWidget != InvalidCanvasIndex) - { - WidgetEntry& previouslyHovered = m_widgetEntries[m_hoveredWidget]; - previouslyHovered.widget->OnMouseExit(); - } - - m_hoveredWidget = bestEntry; - m_widgetEntries[m_hoveredWidget].widget->OnMouseEnter(); - - if (m_cursorController) - m_cursorController->UpdateCursor(Nz::Cursor::Get(m_widgetEntries[m_hoveredWidget].cursor)); - } - - WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget]; - - int x = static_cast(std::round(event.x - hoveredWidget.box.x)); - int y = static_cast(std::round(event.y - hoveredWidget.box.y)); - hoveredWidget.widget->OnMouseMoved(x, y, event.deltaX, event.deltaY); - } - else if (m_hoveredWidget != InvalidCanvasIndex) - { - m_widgetEntries[m_hoveredWidget].widget->OnMouseExit(); - m_hoveredWidget = InvalidCanvasIndex; - - if (m_cursorController) - m_cursorController->UpdateCursor(Nz::Cursor::Get(Nz::SystemCursor_Default)); - } - } - - void Canvas::OnEventMouseWheelMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseWheelEvent& event) - { - if (m_hoveredWidget != InvalidCanvasIndex) - { - WidgetEntry& hoveredWidget = m_widgetEntries[m_hoveredWidget]; - - int x = static_cast(std::round(event.x - hoveredWidget.box.x)); - int y = static_cast(std::round(event.y - hoveredWidget.box.y)); - - hoveredWidget.widget->OnMouseWheelMoved(x, y, event.delta); - } - } - - void Canvas::OnEventMouseLeft(const Nz::EventHandler* /*eventHandler*/) - { - if (m_hoveredWidget != InvalidCanvasIndex) - { - m_widgetEntries[m_hoveredWidget].widget->OnMouseExit(); - m_hoveredWidget = InvalidCanvasIndex; - } - } - - void Canvas::OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event) - { - if (m_keyboardOwner != InvalidCanvasIndex) - { - if (m_widgetEntries[m_keyboardOwner].widget->OnKeyPressed(event)) - return; - - if (event.virtualKey == Nz::Keyboard::VKey::Tab) - { - if (!event.shift) - { - // Forward - for (std::size_t i = m_keyboardOwner + 1; i < m_widgetEntries.size(); ++i) - { - if (m_widgetEntries[i].widget->IsFocusable()) - { - SetKeyboardOwner(i); - return; - } - } - - for (std::size_t i = 0; i < m_keyboardOwner; ++i) - { - if (m_widgetEntries[i].widget->IsFocusable()) - { - SetKeyboardOwner(i); - return; - } - } - } - else - { - // Backward - for (decltype(m_widgetEntries)::reverse_iterator rit{ m_widgetEntries.begin() + m_keyboardOwner }; rit != m_widgetEntries.rend(); ++rit) - { - if (rit->widget->IsFocusable()) - { - SetKeyboardOwner(std::distance(m_widgetEntries.begin(), rit.base()) - 1); - return; - } - } - - decltype(m_widgetEntries)::reverse_iterator rend { m_widgetEntries.begin() + m_keyboardOwner }; - for (auto rit = m_widgetEntries.rbegin(); rit != rend; ++rit) - { - if (rit->widget->IsFocusable()) - { - SetKeyboardOwner(std::distance(m_widgetEntries.begin(), rit.base()) - 1); - return; - } - } - } - } - } - - OnUnhandledKeyPressed(eventHandler, event); - } - - void Canvas::OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event) - { - if (m_keyboardOwner != InvalidCanvasIndex) - m_widgetEntries[m_keyboardOwner].widget->OnKeyReleased(event); - - OnUnhandledKeyReleased(eventHandler, event); - } - - void Canvas::OnEventTextEntered(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::TextEvent& event) - { - if (m_keyboardOwner != InvalidCanvasIndex) - m_widgetEntries[m_keyboardOwner].widget->OnTextEntered(event.character, event.repeated); - } - - void Canvas::OnEventTextEdited(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::EditEvent& event) - { - if (m_keyboardOwner != InvalidCanvasIndex) - m_widgetEntries[m_keyboardOwner].widget->OnTextEdited(event.text, event.length); - } -} diff --git a/src/NazaraSDK/Components/CameraComponent.cpp b/src/NazaraSDK/Components/CameraComponent.cpp deleted file mode 100644 index 9e63590e4..000000000 --- a/src/NazaraSDK/Components/CameraComponent.cpp +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::CameraComponent - * \brief NDK class that represents the component for camera - */ - - /*! - * \brief Applys the view of the camera - * - * \remark Produces a NazaraAssert if the camera has no target - */ - - void CameraComponent::ApplyView() const - { - NazaraAssert(m_target, "CameraComponent has no target"); - - EnsureProjectionMatrixUpdate(); - EnsureViewMatrixUpdate(); - EnsureViewportUpdate(); - - Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, m_projectionMatrix); - Nz::Renderer::SetMatrix(Nz::MatrixType_View, m_viewMatrix); - Nz::Renderer::SetTarget(m_target); - Nz::Renderer::SetViewport(m_viewport); - } - - /*! - * \brief Gets the aspect ratio of the camera - * \return Aspect ratio of the camera - */ - float CameraComponent::GetAspectRatio() const - { - EnsureViewportUpdate(); - - return m_aspectRatio; - } - - /*! - * \brief Gets the eye position of the camera - * - * \remark Produces a NazaraAssert if entity is invalid or has no NodeComponent - */ - - Nz::Vector3f CameraComponent::GetEyePosition() const - { - NazaraAssert(m_entity && m_entity->HasComponent(), "CameraComponent requires NodeComponent"); - - return m_entity->GetComponent().GetPosition(); - } - - /*! - * \brief Gets the forward direction of the camera - * - * \remark Produces a NazaraAssert if entity is invalid or has no NodeComponent - */ - Nz::Vector3f CameraComponent::GetForward() const - { - NazaraAssert(m_entity && m_entity->HasComponent(), "CameraComponent requires NodeComponent"); - - return m_entity->GetComponent().GetForward(); - } - - /*! - * \brief Gets the frutum of the camera - * \return A constant reference to the frustum of the camera - */ - const Nz::Frustumf& CameraComponent::GetFrustum() const - { - EnsureFrustumUpdate(); - - return m_frustum; - } - - /*! - * \brief Gets the projection matrix of the camera - * \return A constant reference to the projection matrix of the camera - */ - const Nz::Matrix4f& CameraComponent::GetProjectionMatrix() const - { - EnsureProjectionMatrixUpdate(); - - return m_projectionMatrix; - } - - - /*! - * \brief Gets the projection type of the camera - * \return Projection type of the camera - */ - Nz::ProjectionType CameraComponent::GetProjectionType() const - { - return m_projectionType; - } - - - /*! - * \brief Gets the target of the camera - * \return A constant reference to the render target of the camera - */ - const Nz::RenderTarget* CameraComponent::GetTarget() const - { - return m_target; - } - - /*! - * \brief Gets the view matrix of the camera - * \return A constant reference to the view matrix of the camera - */ - const Nz::Matrix4f& CameraComponent::GetViewMatrix() const - { - EnsureViewMatrixUpdate(); - - return m_viewMatrix; - } - - /*! - * \brief Gets the view port of the camera - * \return A constant reference to the view port of the camera - */ - const Nz::Recti& CameraComponent::GetViewport() const - { - EnsureViewportUpdate(); - - return m_viewport; - } - - /*! - * \brief Gets the Z far distance of the camera - * \return Z far distance of the camera - */ - float CameraComponent::GetZFar() const - { - return m_zFar; - } - - /*! - * \brief Gets the Z near distance of the camera - * \return Z near distance of the camera - */ - float CameraComponent::GetZNear() const - { - return m_zNear; - } - - /*! - * \brief Sets the layer of the camera in case of multiples layers - * - * \param layer Layer of the camera - */ - void CameraComponent::SetLayer(unsigned int layer) - { - m_layer = layer; - - m_entity->Invalidate(); // Invalidate the entity to make it passes through RenderSystem validation - } - - /*! - * \brief Operation to perform when component is attached to an entity - */ - void CameraComponent::OnAttached() - { - if (m_entity->HasComponent()) - m_nodeInvalidationSlot.Connect(m_entity->GetComponent().OnNodeInvalidation, this, &CameraComponent::OnNodeInvalidated); - - InvalidateViewMatrix(); - } - - /*! - * \brief Operation to perform when component is attached to this component - * - * \param component Component being attached - */ - - void CameraComponent::OnComponentAttached(BaseComponent& component) - { - if (IsComponent(component)) - { - NodeComponent& nodeComponent = static_cast(component); - m_nodeInvalidationSlot.Connect(nodeComponent.OnNodeInvalidation, this, &CameraComponent::OnNodeInvalidated); - - InvalidateViewMatrix(); - } - } - - /*! - * \brief Operation to perform when component is detached from this component - * - * \param component Component being detached - */ - - void CameraComponent::OnComponentDetached(BaseComponent& component) - { - if (IsComponent(component)) - { - m_nodeInvalidationSlot.Disconnect(); - - InvalidateViewMatrix(); - } - } - - /*! - * \brief Operation to perform when component is detached from an entity - */ - - void CameraComponent::OnDetached() - { - m_nodeInvalidationSlot.Disconnect(); - - InvalidateViewMatrix(); - } - - /*! - * \brief Operation to perform when the node is invalidated - * - * \param node Pointer to the node - */ - - void CameraComponent::OnNodeInvalidated(const Nz::Node* node) - { - NazaraUnused(node); - - // Our view matrix depends on NodeComponent position/rotation - InvalidateViewMatrix(); - } - - /*! - * \brief Operation to perform when the render target is released - * - * \param renderTarget Pointer to the RenderTarget - */ - - void CameraComponent::OnRenderTargetRelease(const Nz::RenderTarget* renderTarget) - { - if (renderTarget == m_target) - m_target = nullptr; - else - NazaraInternalError("Not listening to " + Nz::String::Pointer(renderTarget)); - } - - /*! - * \brief Operation to perform when the render target has its size changed - * - * \param renderTarget Pointer to the RenderTarget - */ - - void CameraComponent::OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget) - { - if (renderTarget == m_target) - InvalidateViewport(); - else - NazaraInternalError("Not listening to " + Nz::String::Pointer(renderTarget)); - } - - /*! - * \brief Updates the frustum of the camera - */ - - void CameraComponent::UpdateFrustum() const - { - EnsureProjectionMatrixUpdate(); - EnsureViewMatrixUpdate(); - - // Extract the frustum from the view and projection matrices - m_frustum.Extract(m_viewMatrix, m_projectionMatrix); - m_frustumUpdated = true; - } - - /*! - * \brief Updates the project matrix of the camera - */ - - void CameraComponent::UpdateProjectionMatrix() const - { - switch (m_projectionType) - { - case Nz::ProjectionType_Orthogonal: - if (m_size.x <= 0.f || m_size.y <= 0.f) - { - EnsureViewportUpdate(); - - m_projectionMatrix.MakeOrtho(0.f, static_cast(m_viewport.width), 0.f, static_cast(m_viewport.height), m_zNear, m_zFar); - } - else - m_projectionMatrix.MakeOrtho(0.f, m_size.x, 0.f, m_size.y, m_zNear, m_zFar); - break; - - case Nz::ProjectionType_Perspective: - EnsureViewportUpdate(); // Can affect aspect ratio - - m_projectionMatrix.MakePerspective(m_fov, m_aspectRatio, m_zNear, m_zFar); - break; - } - - m_projectionMatrix *= Nz::Matrix4f::Scale(m_projectionScale); - - m_projectionMatrixUpdated = true; - } - - /*! - * \brief Updates the view matrix of the camera - * - * \remark Produces a NazaraAssert if entity is invalid or has no NodeComponent - */ - - void CameraComponent::UpdateViewMatrix() const - { - NazaraAssert(m_entity && m_entity->HasComponent(), "CameraComponent requires NodeComponent"); - - NodeComponent& nodeComponent = m_entity->GetComponent(); - - // Build the view matrix using the NodeComponent position/rotation - m_viewMatrix.MakeViewMatrix(nodeComponent.GetPosition(Nz::CoordSys_Global), nodeComponent.GetRotation(Nz::CoordSys_Global)); - m_viewMatrixUpdated = true; - } - - /*! - * \brief Updates the view port of the camera - * - * \remark Produces a NazaraAssert if entity has no target - */ - - void CameraComponent::UpdateViewport() const - { - NazaraAssert(m_target, "CameraComponent has no target"); - - Nz::Vector2ui targetSize = m_target->GetSize(); - targetSize.y = std::max(targetSize.y, 1U); // Let's make sure we won't divide by zero - - // Our target region is expressed as % of the viewport dimensions, let's compute it in pixels - Nz::Rectf fViewport(m_targetRegion); - fViewport.x *= targetSize.x; - fViewport.y *= targetSize.y; - fViewport.width *= targetSize.x; - fViewport.height *= targetSize.y; - - // Compute the new aspect ratio, if it's different we need to invalidate the projection matrix - float aspectRatio = fViewport.width/fViewport.height; - if (!Nz::NumberEquals(m_aspectRatio, aspectRatio, 0.001f)) - { - m_aspectRatio = aspectRatio; - - if (m_projectionType == Nz::ProjectionType_Perspective) - InvalidateProjectionMatrix(); - } - - // Convert it back to int - m_viewport.Set(fViewport); - m_viewportUpdated = true; - } - - ComponentIndex CameraComponent::componentIndex; -} diff --git a/src/NazaraSDK/Components/DebugComponent.cpp b/src/NazaraSDK/Components/DebugComponent.cpp deleted file mode 100644 index 22c742f6f..000000000 --- a/src/NazaraSDK/Components/DebugComponent.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - void DebugComponent::DetachDebugRenderables(GraphicsComponent& gfxComponent) - { - for (auto& renderable : m_debugRenderables) - { - if (renderable) - { - gfxComponent.Detach(renderable); - renderable.Reset(); - } - } - } - - void DebugComponent::OnComponentDetached(BaseComponent& component) - { - if (IsComponent(component)) - DetachDebugRenderables(static_cast(component)); - } - - void DebugComponent::OnDetached() - { - if (m_entity->HasComponent()) - DetachDebugRenderables(m_entity->GetComponent()); - } - - ComponentIndex DebugComponent::componentIndex; -} diff --git a/src/NazaraSDK/Components/GraphicsComponent.cpp b/src/NazaraSDK/Components/GraphicsComponent.cpp deleted file mode 100644 index 80ab3805b..000000000 --- a/src/NazaraSDK/Components/GraphicsComponent.cpp +++ /dev/null @@ -1,348 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::GraphicsComponent - * \brief NDK class that represents the component for graphics - */ - - /*! - * \brief Adds the renderable elements to the render queue - * - * \param renderQueue Queue to be added - */ - void GraphicsComponent::AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const - { - EnsureBoundingVolumesUpdate(); - EnsureTransformMatrixUpdate(); - - RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem(); - - for (const Renderable& object : m_renderables) - { - if (!object.dataUpdated) - { - object.renderable->UpdateData(&object.data); - object.dataUpdated = true; - } - - object.renderable->AddToRenderQueue(renderQueue, object.data, m_scissorRect); - } - } - - /*! - * \brief Adds the renderable elements to the render queue if their bounding volume intersects with the frustum - * - * \param frustum Queue to be added - * \param renderQueue Queue to be added - */ - void GraphicsComponent::AddToRenderQueueByCulling(const Nz::Frustumf& frustum, Nz::AbstractRenderQueue* renderQueue) const - { - EnsureBoundingVolumesUpdate(); - EnsureTransformMatrixUpdate(); - - RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem(); - - for (const Renderable& object : m_renderables) - { - if (frustum.Contains(object.boundingVolume)) - { - if (!object.dataUpdated) - { - object.renderable->UpdateData(&object.data); - object.dataUpdated = true; - } - - object.renderable->AddToRenderQueue(renderQueue, object.data, m_scissorRect); - } - } - } - - /*! - * \brief Attaches a renderable to the entity with a specific matrix - * - * \param renderable Reference to a renderable element - * \param localMatrix Local matrix that will be applied to the instanced renderable - * \param renderOrder Render order of the element - */ - void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder) - { - m_renderables.emplace_back(m_transformMatrix); - Renderable& entry = m_renderables.back(); - entry.data.localMatrix = localMatrix; - entry.data.renderOrder = renderOrder; - entry.renderable = std::move(renderable); - - ConnectInstancedRenderableSignals(entry); - - std::size_t materialCount = entry.renderable->GetMaterialCount(); - for (std::size_t i = 0; i < materialCount; ++i) - RegisterMaterial(entry.renderable->GetMaterial(i)); - - InvalidateAABB(); - ForceCullingInvalidation(); - } - - void GraphicsComponent::ConnectInstancedRenderableSignals(Renderable& entry) - { - entry.renderableBoundingVolumeInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateBoundingVolume, [this](const Nz::InstancedRenderable*) { InvalidateAABB(); }); - entry.renderableDataInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size() - 1)); - entry.renderableMaterialInvalidationSlot.Connect(entry.renderable->OnInstancedRenderableInvalidateMaterial, this, &GraphicsComponent::InvalidateRenderableMaterial); - entry.renderableReleaseSlot.Connect(entry.renderable->OnInstancedRenderableRelease, this, &GraphicsComponent::Detach); - entry.renderableResetMaterialsSlot.Connect(entry.renderable->OnInstancedRenderableResetMaterials, this, &GraphicsComponent::OnInstancedRenderableResetMaterials); - entry.renderableSkinChangeSlot.Connect(entry.renderable->OnInstancedRenderableSkinChange, this, &GraphicsComponent::OnInstancedRenderableSkinChange); - } - - void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable , Nz::UInt32 flags, std::size_t index) - { - NazaraAssert(index < m_renderables.size(), "Invalid renderable index"); - NazaraUnused(renderable); - - Renderable& r = m_renderables[index]; - r.dataUpdated = false; - r.renderable->InvalidateData(&r.data, flags); - - ForceCullingInvalidation(); - } - - void GraphicsComponent::InvalidateRenderableMaterial(const Nz::InstancedRenderable* renderable, std::size_t skinIndex, std::size_t matIndex, const Nz::MaterialRef& newMat) - { - // Don't listen to dormant materials - if (renderable->GetSkin() != skinIndex) - return; - - RegisterMaterial(newMat); - - const Nz::MaterialRef& oldMat = renderable->GetMaterial(skinIndex, matIndex); - UnregisterMaterial(oldMat); - - ForceCullingInvalidation(); - } - - void GraphicsComponent::InvalidateReflectionMap() - { - m_entity->Invalidate(); - - if (m_reflectiveMaterialCount > 0) - { - if (!m_reflectionMap) - { - m_reflectionMap = Nz::Texture::New(); - if (!m_reflectionMap->Create(Nz::ImageType_Cubemap, Nz::PixelFormat_RGB8, m_reflectionMapSize, m_reflectionMapSize)) - { - NazaraWarning("Failed to create reflection map, reflections will be disabled for this entity"); - return; - } - } - } - else - m_reflectionMap.Reset(); - } - - void GraphicsComponent::RegisterMaterial(Nz::Material* material, std::size_t count) - { - auto it = m_materialEntries.find(material); - if (it == m_materialEntries.end()) - { - MaterialEntry matEntry; - matEntry.reflectionModelChangeSlot.Connect(material->OnMaterialReflectionModeChange, this, &GraphicsComponent::OnMaterialReflectionChange); - matEntry.renderableCounter = count; - - if (material->GetReflectionMode() == Nz::ReflectionMode_RealTime) - { - if (m_reflectiveMaterialCount++ == 0) - InvalidateReflectionMap(); - } - - m_materialEntries.emplace(material, std::move(matEntry)); - } - else - it->second.renderableCounter += count; - } - - /*! - * \brief Operation to perform when component is attached to an entity - */ - - void GraphicsComponent::OnAttached() - { - if (m_entity->HasComponent()) - m_nodeInvalidationSlot.Connect(m_entity->GetComponent().OnNodeInvalidation, this, &GraphicsComponent::OnNodeInvalidated); - - InvalidateTransformMatrix(); - } - - /*! - * \brief Operation to perform when component is attached to this component - * - * \param component Component being attached - */ - - void GraphicsComponent::OnComponentAttached(BaseComponent& component) - { - if (IsComponent(component)) - { - NodeComponent& nodeComponent = static_cast(component); - m_nodeInvalidationSlot.Connect(nodeComponent.OnNodeInvalidation, this, &GraphicsComponent::OnNodeInvalidated); - - InvalidateTransformMatrix(); - } - } - - /*! - * \brief Operation to perform when component is detached from this component - * - * \param component Component being detached - */ - - void GraphicsComponent::OnComponentDetached(BaseComponent& component) - { - if (IsComponent(component)) - { - m_nodeInvalidationSlot.Disconnect(); - - InvalidateTransformMatrix(); - } - } - - /*! - * \brief Operation to perform when component is detached from an entity - */ - - void GraphicsComponent::OnDetached() - { - m_nodeInvalidationSlot.Disconnect(); - - InvalidateTransformMatrix(); - } - - void GraphicsComponent::OnInstancedRenderableResetMaterials(const Nz::InstancedRenderable* renderable, std::size_t newMaterialCount) - { - RegisterMaterial(Nz::Material::GetDefault(), newMaterialCount); - - std::size_t materialCount = renderable->GetMaterialCount(); - for (std::size_t i = 0; i < materialCount; ++i) - UnregisterMaterial(renderable->GetMaterial(i)); - - ForceCullingInvalidation(); - } - - void GraphicsComponent::OnInstancedRenderableSkinChange(const Nz::InstancedRenderable* renderable, std::size_t newSkinIndex) - { - std::size_t materialCount = renderable->GetMaterialCount(); - for (std::size_t i = 0; i < materialCount; ++i) - RegisterMaterial(renderable->GetMaterial(newSkinIndex, i)); - - for (std::size_t i = 0; i < materialCount; ++i) - UnregisterMaterial(renderable->GetMaterial(i)); - - ForceCullingInvalidation(); - } - - void GraphicsComponent::OnMaterialReflectionChange(const Nz::Material* material, Nz::ReflectionMode reflectionMode) - { - // Since this signal is only called when the new reflection mode is different from the current one, no need to compare both - if (material->GetReflectionMode() == Nz::ReflectionMode_RealTime) - { - if (--m_reflectiveMaterialCount == 0) - InvalidateReflectionMap(); - } - else if (reflectionMode == Nz::ReflectionMode_RealTime) - { - if (m_reflectiveMaterialCount++ == 0) - InvalidateReflectionMap(); - } - } - - void GraphicsComponent::OnNodeInvalidated(const Nz::Node* node) - { - NazaraUnused(node); - - // Our view matrix depends on NodeComponent position/rotation - InvalidateAABB(); - InvalidateTransformMatrix(); - - ForceCullingInvalidation(); //< Force invalidation on movement for now (FIXME) - } - - void GraphicsComponent::UnregisterMaterial(Nz::Material* material) - { - auto it = m_materialEntries.find(material); - NazaraAssert(it != m_materialEntries.end(), "Material not registered"); - - MaterialEntry& matEntry = it->second; - if (--matEntry.renderableCounter == 0) - { - if (material->GetReflectionMode() == Nz::ReflectionMode_RealTime) - { - if (--m_reflectiveMaterialCount == 0) - InvalidateReflectionMap(); - } - - m_materialEntries.erase(it); - } - } - - /*! - * \brief Updates the bounding volume - */ - - void GraphicsComponent::UpdateBoundingVolumes() const - { - EnsureTransformMatrixUpdate(); - - RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem(); - - m_aabb.Set(-1.f, -1.f, -1.f); - - bool isAabbSet = false; - - for (const Renderable& r : m_renderables) - { - r.boundingVolume = r.renderable->GetBoundingVolume(); - r.data.transformMatrix = Nz::Matrix4f::ConcatenateAffine(renderSystem.GetCoordinateSystemMatrix(), Nz::Matrix4f::ConcatenateAffine(r.data.localMatrix, m_transformMatrix)); - if (r.boundingVolume.IsFinite()) - { - r.boundingVolume.Update(r.data.transformMatrix); - - if (isAabbSet) - m_aabb.ExtendTo(r.boundingVolume.aabb); - else - { - m_aabb.Set(r.boundingVolume.aabb); - isAabbSet = true; - } - } - } - - m_boundingVolumesUpdated = true; - - for (CullingBoxEntry& entry : m_cullingBoxEntries) - entry.listEntry.UpdateBox(m_aabb); - } - - /*! - * \brief Updates the transform matrix of the renderable - * - * \remark Produces a NazaraAssert if entity is invalid or has no NodeComponent - */ - - void GraphicsComponent::UpdateTransformMatrix() const - { - NazaraAssert(m_entity && m_entity->HasComponent(), "GraphicsComponent requires NodeComponent"); - - m_transformMatrix = m_entity->GetComponent().GetTransformMatrix(); - m_transformMatrixUpdated = true; - } - - ComponentIndex GraphicsComponent::componentIndex; -} diff --git a/src/NazaraSDK/Components/LightComponent.cpp b/src/NazaraSDK/Components/LightComponent.cpp deleted file mode 100644 index a3cf50368..000000000 --- a/src/NazaraSDK/Components/LightComponent.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - ComponentIndex LightComponent::componentIndex; -} diff --git a/src/NazaraSDK/Components/ParticleEmitterComponent.cpp b/src/NazaraSDK/Components/ParticleEmitterComponent.cpp deleted file mode 100644 index 365f4d6f4..000000000 --- a/src/NazaraSDK/Components/ParticleEmitterComponent.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::ParticleEmitterComponent - * \brief NDK class that represents the component emitter of particles - */ - - /*! - * \brief Sets up the particles - * - * \param mapper Mapper containing layout information of each particle - * \param count Number of particles - */ - - void ParticleEmitterComponent::SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const - { - if (m_isActive && m_setupFunc) - m_setupFunc(m_entity, mapper, count); - } - - ComponentIndex ParticleEmitterComponent::componentIndex; -} diff --git a/src/NazaraSDK/Components/ParticleGroupComponent.cpp b/src/NazaraSDK/Components/ParticleGroupComponent.cpp deleted file mode 100644 index 244f28b34..000000000 --- a/src/NazaraSDK/Components/ParticleGroupComponent.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - ComponentIndex ParticleGroupComponent::componentIndex; -} diff --git a/src/NazaraSDK/Console.cpp b/src/NazaraSDK/Console.cpp deleted file mode 100644 index b26e1b37f..000000000 --- a/src/NazaraSDK/Console.cpp +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - namespace - { - const char s_inputPrefix[] = "> "; - constexpr std::size_t s_inputPrefixSize = Nz::CountOf(s_inputPrefix) - 1; - } - - /*! - * \ingroup NDK - * \class Ndk::Console - * \brief NDK class that represents a console to help development with Lua scripting - */ - - /*! - * \brief Constructs a Console object with a world to interact with - * - * \param world World to interact with - * \param size (Width, Height) of the console - * \param instance Lua instance that will interact with the world - */ - - Console::Console(BaseWidget* parent) : - BaseWidget(parent), - m_historyPosition(0), - m_defaultFont(Nz::Font::GetDefault()), - m_characterSize(24), - m_maxHistoryLines(200) - { - // History - m_history = Add(); - m_history->EnableBackground(true); - m_history->EnableLineWrap(true); - m_history->SetReadOnly(true); - m_history->SetBackgroundColor(Nz::Color(80, 80, 160, 128)); - - m_historyArea = Add(m_history); - - // Input - m_input = Add(); - m_input->EnableBackground(true); - m_input->SetText(s_inputPrefix); - m_input->SetTextColor(Nz::Color::Black); - - m_input->OnTextAreaKeyReturn.Connect(this, &Console::ExecuteInput); - - // Protect input prefix from erasure/selection - m_input->SetCursorPosition(s_inputPrefixSize); - - m_input->OnTextAreaCursorMove.Connect([](const AbstractTextAreaWidget* textArea, Nz::Vector2ui* newCursorPos) - { - newCursorPos->x = std::max(newCursorPos->x, static_cast(s_inputPrefixSize)); - }); - - m_input->OnTextAreaSelection.Connect([](const AbstractTextAreaWidget* textArea, Nz::Vector2ui* start, Nz::Vector2ui* end) - { - start->x = std::max(start->x, static_cast(s_inputPrefixSize)); - end->x = std::max(end->x, static_cast(s_inputPrefixSize)); - }); - - m_input->OnTextAreaKeyBackspace.Connect([](const AbstractTextAreaWidget* textArea, bool* ignoreDefaultAction) - { - if (textArea->GetGlyphIndex() < s_inputPrefixSize) - *ignoreDefaultAction = true; - }); - - // Handle history - m_input->OnTextAreaKeyUp.Connect([&] (const AbstractTextAreaWidget* textArea, bool* ignoreDefaultAction) - { - *ignoreDefaultAction = true; - - if (m_commandHistory.empty()) - return; - - if (m_historyPosition > 0) - m_historyPosition--; - - m_input->SetText(s_inputPrefix + m_commandHistory[m_historyPosition]); - }); - - m_input->OnTextAreaKeyDown.Connect([&] (const AbstractTextAreaWidget* textArea, bool* ignoreDefaultAction) - { - *ignoreDefaultAction = true; - - if (m_commandHistory.empty()) - return; - - if (++m_historyPosition >= m_commandHistory.size()) - m_historyPosition = 0; - - m_input->SetText(s_inputPrefix + m_commandHistory[m_historyPosition]); - }); - } - - /*! - * \brief Adds a line to the console - * - * \param text New line of text - * \param color Color for the text - */ - void Console::AddLine(const Nz::String& text, const Nz::Color& color) - { - if (m_historyLines.size() >= m_maxHistoryLines) - m_historyLines.erase(m_historyLines.begin()); - - m_historyLines.emplace_back(Line{ color, text }); - m_history->SetTextColor(color); - m_history->AppendText(text + '\n'); - m_history->Resize(m_history->GetPreferredSize()); - m_historyArea->Resize(m_historyArea->GetSize()); - m_historyArea->ScrollToRatio(1.f); - } - - /*! - * \brief Clears the console - * - * Clears the console history and input - */ - void Console::Clear() - { - m_historyLines.clear(); - m_history->Clear(); - m_history->Resize(m_history->GetPreferredSize()); - m_historyArea->Resize(m_historyArea->GetSize()); - m_input->SetText(s_inputPrefix); - } - - /*! - * \brief Clears the console focus - * - * Clear console input widget focus (if owned) - */ - void Console::ClearFocus() - { - m_input->ClearFocus(); - } - - /*! - * \brief Sets the character size - * - * \param size Size of the font - */ - void Console::SetCharacterSize(unsigned int size) - { - m_characterSize = size; - - m_history->SetCharacterSize(size); - m_input->SetCharacterSize(size); - - Layout(); - } - - /*! - * \brief Give the console input focus - * - */ - void Console::SetFocus() - { - m_input->SetFocus(); - } - - /*! - * \brief Sets the text font - * - * \param font Reference to a valid font - * - * \remark Produces a NazaraAssert if font is invalid or null - */ - void Console::SetTextFont(Nz::FontRef font) - { - NazaraAssert(font && font->IsValid(), "Invalid font"); - - m_defaultFont = std::move(font); - m_history->SetTextFont(m_defaultFont); - m_input->SetTextFont(m_defaultFont); - - Layout(); - } - - /*! - * \brief Performs this action when an input is added to the console - */ - void Console::ExecuteInput(const AbstractTextAreaWidget* textArea, bool* ignoreDefaultAction) - { - NazaraAssert(textArea == m_input, "Unexpected signal from an other text area"); - - *ignoreDefaultAction = true; - - Nz::String input = m_input->GetText(); - Nz::String inputCmd = input.SubString(s_inputPrefixSize); - m_input->SetText(s_inputPrefix); - - if (m_commandHistory.empty() || m_commandHistory.back() != inputCmd) - m_commandHistory.push_back(inputCmd); - - m_historyPosition = m_commandHistory.size(); - - AddLine(input); //< With the input prefix - - OnCommand(this, inputCmd); - } - - /*! - * \brief Places the console according to its layout - */ - void Console::Layout() - { - Nz::Vector2f origin = Nz::Vector2f(GetPosition()); - const Nz::Vector2f& size = GetSize(); - - unsigned int lineHeight = m_defaultFont->GetSizeInfo(m_characterSize).lineHeight; - float historyHeight = size.y - lineHeight; - - m_historyArea->SetPosition(origin.x, origin.y); - m_historyArea->Resize({ size.x, historyHeight - 4.f }); - - m_input->Resize({size.x, size.y - historyHeight}); - m_input->SetPosition(origin.x, origin.y + historyHeight); - } -} diff --git a/src/NazaraSDK/Sdk.cpp b/src/NazaraSDK/Sdk.cpp index 6fd036924..8a14e30a9 100644 --- a/src/NazaraSDK/Sdk.cpp +++ b/src/NazaraSDK/Sdk.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -27,18 +26,8 @@ #include #ifndef NDK_SERVER -#include -#include -#include #include -#include -#include -#include -#include -#include #include -#include -#include #endif namespace Ndk @@ -75,7 +64,6 @@ namespace Ndk #ifndef NDK_SERVER // Client modules Nz::Audio::Initialize(); - Nz::Graphics::Initialize(); #endif // SDK Initialization @@ -95,13 +83,7 @@ namespace Ndk #ifndef NDK_SERVER // Client components - InitializeComponent("NdkCam"); - InitializeComponent("NdkDebug"); - InitializeComponent("NdkLight"); InitializeComponent("NdkList"); - InitializeComponent("NdkGfx"); - InitializeComponent("NdkPaEmi"); - InitializeComponent("NdkPaGrp"); #endif // Systems @@ -116,17 +98,7 @@ namespace Ndk #ifndef NDK_SERVER // Client systems - InitializeSystem(); InitializeSystem(); - InitializeSystem(); - InitializeSystem(); - - // Widgets - if (!CheckboxWidget::Initialize()) - { - NazaraError("Failed to initialize Checkbox Widget"); - return false; - } #endif NazaraNotice("Initialized: SDK"); @@ -170,7 +142,6 @@ namespace Ndk #ifndef NDK_SERVER // Client modules Nz::Audio::Uninitialize(); - Nz::Graphics::Uninitialize(); #endif // Shared modules @@ -179,8 +150,6 @@ namespace Ndk Nz::Utility::Uninitialize(); #ifndef NDK_SERVER - // Widgets - CheckboxWidget::Uninitialize(); #endif NazaraNotice("Uninitialized: SDK"); diff --git a/src/NazaraSDK/Systems/DebugSystem.cpp b/src/NazaraSDK/Systems/DebugSystem.cpp deleted file mode 100644 index da02053ac..000000000 --- a/src/NazaraSDK/Systems/DebugSystem.cpp +++ /dev/null @@ -1,526 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - namespace - { - class DebugRenderable : public Nz::InstancedRenderable - { - public: - DebugRenderable(Ndk::Entity* owner, Nz::IndexBufferRef indexBuffer, Nz::VertexBufferRef vertexBuffer) : - m_entityOwner(owner), - m_indexBuffer(std::move(indexBuffer)), - m_vertexBuffer(std::move(vertexBuffer)) - { - ResetMaterials(1); - - m_meshData.indexBuffer = m_indexBuffer; - m_meshData.primitiveMode = Nz::PrimitiveMode_LineList; - m_meshData.vertexBuffer = m_vertexBuffer; - } - - void UpdateBoundingVolume(InstanceData* /*instanceData*/) const override - { - } - - void MakeBoundingVolume() const override - { - // We generate an infinite bounding volume so that we're always considered for rendering when culling does occurs - // (bounding volume culling happens only if GraphicsComponent AABB partially fail) - m_boundingVolume.MakeInfinite(); - } - - protected: - Ndk::EntityHandle m_entityOwner; - Nz::IndexBufferRef m_indexBuffer; - Nz::MeshData m_meshData; - Nz::VertexBufferRef m_vertexBuffer; - }; - - class AABBDebugRenderable : public DebugRenderable - { - public: - AABBDebugRenderable(Ndk::Entity* owner, Nz::MaterialRef globalMaterial, Nz::MaterialRef localMaterial, Nz::IndexBufferRef indexBuffer, Nz::VertexBufferRef vertexBuffer) : - DebugRenderable(owner, std::move(indexBuffer), std::move(vertexBuffer)), - m_globalMaterial(std::move(globalMaterial)), - m_localMaterial(std::move(localMaterial)) - { - } - - void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Nz::Recti& scissorRect) const override - { - NazaraAssert(m_entityOwner, "DebugRenderable has no owner"); - - const DebugComponent& entityDebug = m_entityOwner->GetComponent(); - const GraphicsComponent& entityGfx = m_entityOwner->GetComponent(); - - auto DrawBox = [&](const Nz::Boxf& box, const Nz::MaterialRef& mat) - { - Nz::Matrix4f transformMatrix = Nz::Matrix4f::Identity(); - transformMatrix.SetScale(box.GetLengths()); - transformMatrix.SetTranslation(box.GetCenter()); - - renderQueue->AddMesh(0, mat, m_meshData, Nz::Boxf::Zero(), transformMatrix, scissorRect); - }; - - DrawBox(entityGfx.GetAABB(), m_globalMaterial); - - for (std::size_t i = 0; i < entityGfx.GetAttachedRenderableCount(); ++i) - { - const Nz::BoundingVolumef& boundingVolume = entityGfx.GetBoundingVolume(i); - if (boundingVolume.IsFinite()) - DrawBox(boundingVolume.aabb, m_localMaterial); - } - } - - std::unique_ptr Clone() const override - { - return nullptr; - } - - private: - Nz::MaterialRef m_globalMaterial; - Nz::MaterialRef m_localMaterial; - }; - - class OBBDebugRenderable : public DebugRenderable - { - public: - OBBDebugRenderable(Ndk::Entity* owner, Nz::MaterialRef material, Nz::IndexBufferRef indexBuffer, Nz::VertexBufferRef vertexBuffer) : - DebugRenderable(owner, std::move(indexBuffer), std::move(vertexBuffer)), - m_material(std::move(material)) - { - } - - void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Nz::Recti& scissorRect) const override - { - NazaraAssert(m_entityOwner, "DebugRenderable has no owner"); - - const DebugComponent& entityDebug = m_entityOwner->GetComponent(); - const GraphicsComponent& entityGfx = m_entityOwner->GetComponent(); - - auto DrawBox = [&](const Nz::Boxf& box, const Nz::Matrix4f& transformMatrix) - { - Nz::Matrix4f boxMatrix = Nz::Matrix4f::Identity(); - boxMatrix.SetScale(box.GetLengths()); - boxMatrix.SetTranslation(box.GetCenter()); - boxMatrix.ConcatenateAffine(transformMatrix); - - renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), boxMatrix, scissorRect); - }; - - for (std::size_t i = 0; i < entityGfx.GetAttachedRenderableCount(); ++i) - { - const Nz::BoundingVolumef& boundingVolume = entityGfx.GetBoundingVolume(i); - if (boundingVolume.IsFinite()) - DrawBox(boundingVolume.obb.localBox, entityGfx.GetTransformMatrix(i)); - } - } - - std::unique_ptr Clone() const override - { - return nullptr; - } - - private: - Nz::MaterialRef m_material; - }; - } - - /*! - * \ingroup NDK - * \class Ndk::DebugSystem - * \brief NDK class that represents the debug system - * - * \remark This system is enabled if the entity owns the trait: DebugComponent and GraphicsComponent - */ - - /*! - * \brief Constructs an DebugSystem object by default - */ - DebugSystem::DebugSystem() : - m_isDepthBufferEnabled(true) - { - Requires(); - SetUpdateOrder(1000); //< Update last - } - - void DebugSystem::EnableDepthBuffer(bool enable) - { - m_isDepthBufferEnabled = enable; - - if (m_collisionMaterial) - m_collisionMaterial->EnableDepthBuffer(enable); - - if (m_globalAabbMaterial) - m_globalAabbMaterial->EnableDepthBuffer(enable); - - if (m_localAabbMaterial) - m_localAabbMaterial->EnableDepthBuffer(enable); - - if (m_obbMaterial) - m_obbMaterial->EnableDepthBuffer(enable); - } - - Nz::InstancedRenderableRef DebugSystem::GenerateBox(Nz::Boxf box) - { - Nz::MeshRef mesh = Nz::Mesh::New(); - mesh->CreateStatic(); - - mesh->BuildSubMesh(Nz::Primitive::Box(box.GetLengths())); - mesh->SetMaterialCount(1); - - Nz::ModelRef model = Nz::Model::New(); - model->SetMesh(mesh); - model->SetMaterial(0, GetOBBMaterial()); - - return model; - } - - Nz::InstancedRenderableRef DebugSystem::GenerateCollision2DMesh(Entity* entity, Nz::Vector3f* offset) - { - if (entity->HasComponent()) - { - CollisionComponent2D& entityCollision = entity->GetComponent(); - const Nz::Collider2DRef& geom = entityCollision.GetGeom(); - - std::vector vertices; - std::vector indices; - - geom->ForEachPolygon([&](const Nz::Vector2f* polygonVertices, std::size_t vertexCount) - { - std::size_t firstIndex = vertices.size(); - - // Don't reserve and let the vector handle its own capacity - for (std::size_t i = 0; i < vertexCount; ++i) - vertices.emplace_back(*polygonVertices++); - - for (std::size_t i = 0; i < vertexCount - 1; ++i) - { - indices.push_back(firstIndex + i); - indices.push_back(firstIndex + i + 1); - } - - indices.push_back(firstIndex + vertexCount - 1); - indices.push_back(firstIndex); - }); - - Nz::IndexBufferRef indexBuffer = Nz::IndexBuffer::New(vertices.size() > 0xFFFF, Nz::UInt32(indices.size()), Nz::DataStorage_Hardware, 0); - Nz::IndexMapper indexMapper(indexBuffer, Nz::BufferAccess_WriteOnly); - - Nz::IndexIterator indexPtr = indexMapper.begin(); - for (std::size_t index : indices) - *indexPtr++ = static_cast(index); - - indexMapper.Unmap(); - - Nz::VertexBufferRef vertexBuffer = Nz::VertexBuffer::New(Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ), Nz::UInt32(vertices.size()), Nz::DataStorage_Hardware, 0); - vertexBuffer->Fill(vertices.data(), 0, Nz::UInt32(vertices.size())); - - Nz::MeshRef mesh = Nz::Mesh::New(); - mesh->CreateStatic(); - - Nz::StaticMeshRef subMesh = Nz::StaticMesh::New(vertexBuffer, indexBuffer); - subMesh->SetPrimitiveMode(Nz::PrimitiveMode_LineList); - subMesh->SetMaterialIndex(0); - subMesh->GenerateAABB(); - - mesh->SetMaterialCount(1); - mesh->AddSubMesh(subMesh); - - Nz::ModelRef model = Nz::Model::New(); - model->SetMesh(mesh); - model->SetMaterial(0, GetCollisionMaterial()); - - // Find center of mass - if (entity->HasComponent()) - { - const PhysicsComponent2D& entityPhys = entity->GetComponent(); - *offset = entityPhys.GetMassCenter(Nz::CoordSys_Local) + entityCollision.GetGeomOffset(); - } - else - *offset = entityCollision.GetGeomOffset(); - - return model; - } - else - return nullptr; - } - - Nz::InstancedRenderableRef DebugSystem::GenerateCollision3DMesh(Entity* entity) - { - if (entity->HasComponent()) - { - CollisionComponent3D& entityCollision = entity->GetComponent(); - const Nz::Collider3DRef& geom = entityCollision.GetGeom(); - - std::vector vertices; - std::vector indices; - - geom->ForEachPolygon([&](const Nz::Vector3f* polygonVertices, std::size_t vertexCount) - { - std::size_t firstIndex = vertices.size(); - vertices.resize(firstIndex + vertexCount); - std::copy(polygonVertices, polygonVertices + vertexCount, &vertices[firstIndex]); - - for (std::size_t i = 0; i < vertexCount - 1; ++i) - { - indices.push_back(firstIndex + i); - indices.push_back(firstIndex + i + 1); - } - - indices.push_back(firstIndex + vertexCount - 1); - indices.push_back(firstIndex); - }); - - Nz::IndexBufferRef indexBuffer = Nz::IndexBuffer::New(vertices.size() > 0xFFFF, Nz::UInt32(indices.size()), Nz::DataStorage_Hardware, 0); - Nz::IndexMapper indexMapper(indexBuffer, Nz::BufferAccess_WriteOnly); - - Nz::IndexIterator indexPtr = indexMapper.begin(); - for (std::size_t index : indices) - *indexPtr++ = static_cast(index); - - indexMapper.Unmap(); - - Nz::VertexBufferRef vertexBuffer = Nz::VertexBuffer::New(Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ), Nz::UInt32(vertices.size()), Nz::DataStorage_Hardware, 0); - vertexBuffer->Fill(vertices.data(), 0, Nz::UInt32(vertices.size())); - - Nz::MeshRef mesh = Nz::Mesh::New(); - mesh->CreateStatic(); - - Nz::StaticMeshRef subMesh = Nz::StaticMesh::New(vertexBuffer, indexBuffer); - subMesh->SetPrimitiveMode(Nz::PrimitiveMode_LineList); - subMesh->SetMaterialIndex(0); - subMesh->GenerateAABB(); - - mesh->SetMaterialCount(1); - mesh->AddSubMesh(subMesh); - - Nz::ModelRef model = Nz::Model::New(); - model->SetMesh(mesh); - model->SetMaterial(0, GetCollisionMaterial()); - - return model; - } - else - return nullptr; - } - - std::pair DebugSystem::GetBoxMesh() - { - if (!m_boxMeshIndexBuffer) - { - std::array indices = { - { - 0, 1, - 1, 2, - 2, 3, - 3, 0, - - 4, 5, - 5, 6, - 6, 7, - 7, 4, - - 0, 4, - 1, 5, - 2, 6, - 3, 7 - } - }; - - m_boxMeshIndexBuffer = Nz::IndexBuffer::New(false, Nz::UInt32(indices.size()), Nz::DataStorage_Hardware, 0); - m_boxMeshIndexBuffer->Fill(indices.data(), 0, Nz::UInt32(indices.size())); - } - - if (!m_boxMeshVertexBuffer) - { - Nz::Boxf box(-0.5f, -0.5f, -0.5f, 1.f, 1.f, 1.f); - - std::array positions = { - { - box.GetCorner(Nz::BoxCorner_FarLeftBottom), - box.GetCorner(Nz::BoxCorner_NearLeftBottom), - box.GetCorner(Nz::BoxCorner_NearRightBottom), - box.GetCorner(Nz::BoxCorner_FarRightBottom), - box.GetCorner(Nz::BoxCorner_FarLeftTop), - box.GetCorner(Nz::BoxCorner_NearLeftTop), - box.GetCorner(Nz::BoxCorner_NearRightTop), - box.GetCorner(Nz::BoxCorner_FarRightTop) - } - }; - - m_boxMeshVertexBuffer = Nz::VertexBuffer::New(Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ), Nz::UInt32(positions.size()), Nz::DataStorage_Hardware, 0); - m_boxMeshVertexBuffer->Fill(positions.data(), 0, Nz::UInt32(positions.size())); - } - - return { m_boxMeshIndexBuffer, m_boxMeshVertexBuffer }; - } - - Nz::MaterialRef DebugSystem::GetGlobalAABBMaterial() - { - if (!m_globalAabbMaterial) - { - m_globalAabbMaterial = Nz::Material::New(); - m_globalAabbMaterial->EnableFaceCulling(false); - m_globalAabbMaterial->EnableDepthBuffer(true); - m_globalAabbMaterial->SetDiffuseColor(Nz::Color::Orange); - m_globalAabbMaterial->SetFaceFilling(Nz::FaceFilling_Line); - //m_globalAabbMaterial->SetLineWidth(2.f); - } - - return m_globalAabbMaterial; - } - - Nz::MaterialRef DebugSystem::GetLocalAABBMaterial() - { - if (!m_localAabbMaterial) - { - m_localAabbMaterial = Nz::Material::New(); - m_localAabbMaterial->EnableFaceCulling(false); - m_localAabbMaterial->EnableDepthBuffer(true); - m_localAabbMaterial->SetDiffuseColor(Nz::Color::Red); - m_localAabbMaterial->SetFaceFilling(Nz::FaceFilling_Line); - //m_localAabbMaterial->SetLineWidth(2.f); - } - - return m_localAabbMaterial; - } - - Nz::MaterialRef DebugSystem::GetCollisionMaterial() - { - if (!m_collisionMaterial) - { - m_collisionMaterial = Nz::Material::New(); - m_collisionMaterial->EnableFaceCulling(false); - m_collisionMaterial->EnableDepthBuffer(true); - m_collisionMaterial->SetDiffuseColor(Nz::Color::Blue); - m_collisionMaterial->SetFaceFilling(Nz::FaceFilling_Line); - //m_collisionMaterial->SetLineWidth(2.f); - } - - return m_collisionMaterial; - } - - Nz::MaterialRef DebugSystem::GetOBBMaterial() - { - if (!m_obbMaterial) - { - m_obbMaterial = Nz::Material::New(); - m_obbMaterial->EnableFaceCulling(false); - m_obbMaterial->EnableDepthBuffer(true); - m_obbMaterial->SetDiffuseColor(Nz::Color::Green); - m_obbMaterial->SetFaceFilling(Nz::FaceFilling_Line); - //m_obbMaterial->SetLineWidth(2.f); - } - - return m_obbMaterial; - } - - void DebugSystem::OnEntityValidation(Entity* entity, bool /*justAdded*/) - { - static constexpr int DebugDrawOrder = 1'000; - - DebugComponent& entityDebug = entity->GetComponent(); - GraphicsComponent& entityGfx = entity->GetComponent(); - NodeComponent& entityNode = entity->GetComponent(); - - DebugDrawFlags enabledFlags = entityDebug.GetEnabledFlags(); - DebugDrawFlags flags = entityDebug.GetFlags(); - - DebugDrawFlags flagsToEnable = flags & ~enabledFlags; - for (std::size_t i = 0; i <= static_cast(DebugDraw::Max); ++i) - { - DebugDraw option = static_cast(i); - if (flagsToEnable & option) - { - switch (option) - { - case DebugDraw::Collider2D: - { - Nz::Vector3f offset; - Nz::InstancedRenderableRef renderable = GenerateCollision2DMesh(entity, &offset); - if (renderable) - entityGfx.Attach(renderable, Nz::Matrix4f::Translate(offset), DebugDrawOrder); - - entityDebug.UpdateDebugRenderable(option, std::move(renderable)); - break; - } - - case DebugDraw::Collider3D: - { - const Nz::Boxf& obb = entityGfx.GetAABB(); - - Nz::InstancedRenderableRef renderable = GenerateCollision3DMesh(entity); - if (renderable) - entityGfx.Attach(renderable, Nz::Matrix4f::Translate(obb.GetCenter() - entityNode.GetPosition()), DebugDrawOrder); - - entityDebug.UpdateDebugRenderable(option, std::move(renderable)); - break; - } - - case DebugDraw::GraphicsAABB: - { - auto indexVertexBuffers = GetBoxMesh(); - - Nz::InstancedRenderableRef renderable = new AABBDebugRenderable(entity, GetGlobalAABBMaterial(), GetLocalAABBMaterial(), indexVertexBuffers.first, indexVertexBuffers.second); - renderable->SetPersistent(false); - - entityGfx.Attach(renderable, Nz::Matrix4f::Identity(), DebugDrawOrder); - - entityDebug.UpdateDebugRenderable(option, std::move(renderable)); - break; - } - - case DebugDraw::GraphicsOBB: - { - auto indexVertexBuffers = GetBoxMesh(); - - Nz::InstancedRenderableRef renderable = new OBBDebugRenderable(entity, GetOBBMaterial(), indexVertexBuffers.first, indexVertexBuffers.second); - renderable->SetPersistent(false); - - entityGfx.Attach(renderable, Nz::Matrix4f::Identity(), DebugDrawOrder); - - entityDebug.UpdateDebugRenderable(option, std::move(renderable)); - break; - } - - default: - break; - } - } - } - - DebugDrawFlags flagsToDisable = enabledFlags & ~flags; - for (std::size_t i = 0; i <= static_cast(DebugDraw::Max); ++i) - { - DebugDraw option = static_cast(i); - if (flagsToDisable & option) - entityGfx.Detach(entityDebug.GetDebugRenderable(option)); - } - - entityDebug.UpdateEnabledFlags(flags); - } - - void DebugSystem::OnUpdate(float elapsedTime) - { - // Nothing to do - } - - SystemIndex DebugSystem::systemIndex; -} diff --git a/src/NazaraSDK/Systems/ParticleSystem.cpp b/src/NazaraSDK/Systems/ParticleSystem.cpp deleted file mode 100644 index ab54b572e..000000000 --- a/src/NazaraSDK/Systems/ParticleSystem.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::ParticleSystem - * \brief NDK class that represents the particle system - * - * \remark This system is enabled if the entity has the trait: NodeComponent and any of these two: ParticleGroupComponent - */ - - /*! - * \brief Constructs an ParticleSystem object by default - */ - - ParticleSystem::ParticleSystem() - { - Requires(); - } - - /*! - * \brief Operation to perform when system is updated - * - * \param elapsedTime Delta time used for the update - */ - - void ParticleSystem::OnUpdate(float elapsedTime) - { - for (const Ndk::EntityHandle& entity : GetEntities()) - { - ParticleGroupComponent& group = entity->GetComponent(); - - group.Update(elapsedTime); - } - } - - SystemIndex ParticleSystem::systemIndex; -} diff --git a/src/NazaraSDK/Systems/RenderSystem.cpp b/src/NazaraSDK/Systems/RenderSystem.cpp deleted file mode 100644 index 5c5e8abd7..000000000 --- a/src/NazaraSDK/Systems/RenderSystem.cpp +++ /dev/null @@ -1,428 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::RenderSystem - * \brief NDK class that represents the rendering system - * - * \remark This system is enabled if the entity is a 'camera' with the trait: CameraComponent and NodeComponent - * or a drawable element with trait: GraphicsComponent and NodeComponent - * or a light element with trait: LightComponent and NodeComponent - * or a set of particles with trait: ParticleGroupComponent - */ - - /*! - * \brief Constructs an RenderSystem object by default - */ - RenderSystem::RenderSystem() : - m_coordinateSystemMatrix(Nz::Matrix4f::Identity()), - m_coordinateSystemInvalidated(true), - m_forceRenderQueueInvalidation(false), - m_isCullingEnabled(true) - { - ChangeRenderTechnique(); - SetDefaultBackground(Nz::ColorBackground::New()); - SetUpdateOrder(100); //< Render last, after every movement is done - SetMaximumUpdateRate(0.f); //< We don't want any rate limit - } - - /*! - * \brief Operation to perform when an entity is removed - * - * \param entity Pointer to the entity - */ - void RenderSystem::OnEntityRemoved(Entity* entity) - { - m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list - - for (auto it = m_cameras.begin(); it != m_cameras.end(); ++it) - { - if (it->GetObject() == entity) - { - m_cameras.erase(it); - break; - } - } - - if (entity->HasComponent()) - { - GraphicsComponent& gfxComponent = entity->GetComponent(); - gfxComponent.RemoveFromCullingList(&m_drawableCulling); - } - } - - /*! - * \brief Operation to perform when entity is validated for the system - * - * \param entity Pointer to the entity - * \param justAdded Is the entity newly added - */ - void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded) - { - NazaraUnused(justAdded); - - if (entity->HasComponent() && entity->HasComponent()) - { - m_cameras.emplace_back(entity); - std::sort(m_cameras.begin(), m_cameras.end(), [](const EntityHandle& handle1, const EntityHandle& handle2) - { - return handle1->GetComponent().GetLayer() < handle2->GetComponent().GetLayer(); - }); - } - else - { - for (auto it = m_cameras.begin(); it != m_cameras.end(); ++it) - { - if (it->GetObject() == entity) - { - m_cameras.erase(it); - break; - } - } - } - - if (entity->HasComponent() && entity->HasComponent()) - { - m_drawables.Insert(entity); - - GraphicsComponent& gfxComponent = entity->GetComponent(); - if (justAdded) - gfxComponent.AddToCullingList(&m_drawableCulling); - - if (gfxComponent.DoesRequireRealTimeReflections()) - m_realtimeReflected.Insert(entity); - else - m_realtimeReflected.Remove(entity); - } - else - { - m_drawables.Remove(entity); - m_realtimeReflected.Remove(entity); - - if (entity->HasComponent()) - { - GraphicsComponent& gfxComponent = entity->GetComponent(); - gfxComponent.RemoveFromCullingList(&m_drawableCulling); - } - } - - if (entity->HasComponent() && entity->HasComponent()) - { - m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list - - LightComponent& lightComponent = entity->GetComponent(); - if (lightComponent.GetLightType() == Nz::LightType_Directional) - { - m_directionalLights.Insert(entity); - m_pointSpotLights.Remove(entity); - } - else - { - m_directionalLights.Remove(entity); - m_pointSpotLights.Insert(entity); - } - - m_lights.Insert(entity); - } - else - { - m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list - - m_directionalLights.Remove(entity); - m_lights.Remove(entity); - m_pointSpotLights.Remove(entity); - } - - if (entity->HasComponent()) - { - m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list - - m_particleGroups.Insert(entity); - } - else - { - m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list - - m_particleGroups.Remove(entity); - } - } - - /*! - * \brief Operation to perform when system is updated - * - * \param elapsedTime Delta time used for the update - */ - - void RenderSystem::OnUpdate(float /*elapsedTime*/) - { - // Invalidate every renderable if the coordinate system changed - if (m_coordinateSystemInvalidated) - { - for (const Ndk::EntityHandle& drawable : m_drawables) - { - GraphicsComponent& graphicsComponent = drawable->GetComponent(); - graphicsComponent.InvalidateTransformMatrix(); - } - - m_coordinateSystemInvalidated = false; - } - - Nz::SkinningManager::Skin(); - - UpdateDynamicReflections(); - UpdatePointSpotShadowMaps(); - - for (const Ndk::EntityHandle& camera : m_cameras) - { - CameraComponent& camComponent = camera->GetComponent(); - - //UpdateDirectionalShadowMaps(camComponent); - - Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue(); - - // To make sure the bounding volumes used by the culling list is updated - for (const Ndk::EntityHandle& drawable : m_drawables) - { - GraphicsComponent& graphicsComponent = drawable->GetComponent(); - graphicsComponent.EnsureBoundingVolumesUpdate(); - } - - bool forceInvalidation = false; - - const Nz::Frustumf& frustum = camComponent.GetFrustum(); - - std::size_t visibilityHash; - if (m_isCullingEnabled) - visibilityHash = m_drawableCulling.Cull(frustum, &forceInvalidation); - else - visibilityHash = m_drawableCulling.FillWithAllEntries(&forceInvalidation); - - // Always regenerate renderqueue if particle groups are present for now (FIXME) - if (!m_lights.empty() || !m_particleGroups.empty()) - forceInvalidation = true; - - if (camComponent.UpdateVisibility(visibilityHash) || m_forceRenderQueueInvalidation || forceInvalidation) - { - renderQueue->Clear(); - for (const GraphicsComponent* gfxComponent : m_drawableCulling.GetFullyVisibleResults()) - gfxComponent->AddToRenderQueue(renderQueue); - - for (const GraphicsComponent* gfxComponent : m_drawableCulling.GetPartiallyVisibleResults()) - gfxComponent->AddToRenderQueueByCulling(frustum, renderQueue); - - for (const Ndk::EntityHandle& light : m_lights) - { - LightComponent& lightComponent = light->GetComponent(); - NodeComponent& lightNode = light->GetComponent(); - - ///TODO: Cache somehow? - lightComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::ConcatenateAffine(m_coordinateSystemMatrix, lightNode.GetTransformMatrix())); - } - - for (const Ndk::EntityHandle& particleGroup : m_particleGroups) - { - ParticleGroupComponent& groupComponent = particleGroup->GetComponent(); - - groupComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::Identity()); //< ParticleGroup doesn't use any transform matrix (yet) - } - - m_forceRenderQueueInvalidation = false; - } - - camComponent.ApplyView(); - - Nz::SceneData sceneData; - sceneData.ambientColor = Nz::Color(25, 25, 25); - sceneData.background = m_background; - sceneData.globalReflectionTexture = nullptr; - sceneData.viewer = &camComponent; - - if (m_background && m_background->GetBackgroundType() == Nz::BackgroundType_Skybox) - sceneData.globalReflectionTexture = static_cast(m_background.Get())->GetTexture(); - - m_renderTechnique->Clear(sceneData); - m_renderTechnique->Draw(sceneData); - } - } - - /*! - * \brief Updates the directional shadow maps according to the position of the viewer - * - * \param viewer Viewer of the scene - */ - - void RenderSystem::UpdateDynamicReflections() - { - Nz::SceneData dummySceneData; - dummySceneData.ambientColor = Nz::Color(0, 0, 0); - dummySceneData.background = nullptr; - dummySceneData.viewer = nullptr; //< Depth technique doesn't require any viewer - - for (const Ndk::EntityHandle& handle : m_realtimeReflected) - { - //NazaraWarning("Realtime reflected: #" + handle->ToString()); - } - } - - void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& /*viewer*/) - { - if (!m_shadowRT.IsValid()) - m_shadowRT.Create(); - - Nz::SceneData dummySceneData; - dummySceneData.ambientColor = Nz::Color(0, 0, 0); - dummySceneData.background = nullptr; - dummySceneData.viewer = nullptr; //< Depth technique doesn't require any viewer - - for (const Ndk::EntityHandle& light : m_directionalLights) - { - LightComponent& lightComponent = light->GetComponent(); - NodeComponent& lightNode = light->GetComponent(); - - if (!lightComponent.IsShadowCastingEnabled()) - continue; - - Nz::Vector2ui shadowMapSize(lightComponent.GetShadowMap()->GetSize()); - - m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap()); - Nz::Renderer::SetTarget(&m_shadowRT); - Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y)); - - Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue(); - renderQueue->Clear(); - - ///TODO: Culling - for (const Ndk::EntityHandle& drawable : m_drawables) - { - GraphicsComponent& graphicsComponent = drawable->GetComponent(); - - graphicsComponent.AddToRenderQueue(renderQueue); - } - - ///TODO: Cache the matrices in the light? - Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Ortho(0.f, 100.f, 100.f, 0.f, 1.f, 100.f)); - Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetRotation() * Nz::Vector3f::Forward() * 100.f, lightNode.GetRotation())); - - m_shadowTechnique.Clear(dummySceneData); - m_shadowTechnique.Draw(dummySceneData); - } - } - - /*! - * \brief Updates the point spot shadow maps - */ - - void RenderSystem::UpdatePointSpotShadowMaps() - { - if (!m_shadowRT.IsValid()) - m_shadowRT.Create(); - - Nz::SceneData dummySceneData; - dummySceneData.ambientColor = Nz::Color(0, 0, 0); - dummySceneData.background = nullptr; - dummySceneData.viewer = nullptr; //< Depth technique doesn't require any viewer - - for (const Ndk::EntityHandle& light : m_pointSpotLights) - { - LightComponent& lightComponent = light->GetComponent(); - NodeComponent& lightNode = light->GetComponent(); - - if (!lightComponent.IsShadowCastingEnabled()) - continue; - - Nz::Vector2ui shadowMapSize(lightComponent.GetShadowMap()->GetSize()); - - switch (lightComponent.GetLightType()) - { - case Nz::LightType_Directional: - NazaraInternalError("Directional lights included in point/spot light list"); - break; - - case Nz::LightType_Point: - { - static Nz::Quaternionf rotations[6] = - { - Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitX()), // CubemapFace_PositiveX - Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitX()), // CubemapFace_NegativeX - Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitY()), // CubemapFace_PositiveY - Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitY()), // CubemapFace_NegativeY - Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitZ()), // CubemapFace_PositiveZ - Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitZ()) // CubemapFace_NegativeZ - }; - - for (unsigned int face = 0; face < 6; ++face) - { - m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap(), face); - Nz::Renderer::SetTarget(&m_shadowRT); - Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y)); - - ///TODO: Cache the matrices in the light? - Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Perspective(Nz::FromDegrees(90.f), 1.f, 0.1f, lightComponent.GetRadius())); - Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetPosition(), rotations[face])); - - Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue(); - renderQueue->Clear(); - - ///TODO: Culling - for (const Ndk::EntityHandle& drawable : m_drawables) - { - GraphicsComponent& graphicsComponent = drawable->GetComponent(); - - graphicsComponent.AddToRenderQueue(renderQueue); - } - - m_shadowTechnique.Clear(dummySceneData); - m_shadowTechnique.Draw(dummySceneData); - } - break; - } - - case Nz::LightType_Spot: - { - m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap()); - Nz::Renderer::SetTarget(&m_shadowRT); - Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y)); - - ///TODO: Cache the matrices in the light? - Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Perspective(lightComponent.GetOuterAngle()*2.f, 1.f, 0.1f, lightComponent.GetRadius())); - Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetPosition(), lightNode.GetRotation())); - - Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue(); - renderQueue->Clear(); - - ///TODO: Culling - for (const Ndk::EntityHandle& drawable : m_drawables) - { - GraphicsComponent& graphicsComponent = drawable->GetComponent(); - - graphicsComponent.AddToRenderQueue(renderQueue); - } - - m_shadowTechnique.Clear(dummySceneData); - m_shadowTechnique.Draw(dummySceneData); - break; - } - } - } - } - - SystemIndex RenderSystem::systemIndex; -} diff --git a/src/NazaraSDK/Widgets/AbstractTextAreaWidget.cpp b/src/NazaraSDK/Widgets/AbstractTextAreaWidget.cpp deleted file mode 100644 index 7bce2c026..000000000 --- a/src/NazaraSDK/Widgets/AbstractTextAreaWidget.cpp +++ /dev/null @@ -1,489 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include -#include - -namespace Ndk -{ - namespace - { - constexpr float paddingWidth = 5.f; - constexpr float paddingHeight = 3.f; - } - - AbstractTextAreaWidget::AbstractTextAreaWidget(BaseWidget* parent) : - BaseWidget(parent), - m_characterFilter(), - m_echoMode(EchoMode_Normal), - m_cursorPositionBegin(0U, 0U), - m_cursorPositionEnd(0U, 0U), - m_isLineWrapEnabled(false), - m_isMouseButtonDown(false), - m_multiLineEnabled(false), - m_readOnly(false), - m_tabEnabled(false) - { - m_textSprite = Nz::TextSprite::New(); - - m_textEntity = CreateEntity(); - m_textEntity->AddComponent().Attach(m_textSprite); - - auto& textNode = m_textEntity->AddComponent(); - textNode.SetParent(this); - textNode.SetPosition(paddingWidth, paddingHeight); - - m_cursorEntity = CreateEntity(); - m_cursorEntity->AddComponent(); - m_cursorEntity->AddComponent().SetParent(m_textEntity); - m_cursorEntity->GetComponent(); - m_cursorEntity->Enable(false); - - SetCursor(Nz::SystemCursor_Text); - - EnableBackground(true); - } - - void AbstractTextAreaWidget::Clear() - { - Nz::AbstractTextDrawer& textDrawer = GetTextDrawer(); - - m_cursorPositionBegin.MakeZero(); - m_cursorPositionEnd.MakeZero(); - textDrawer.Clear(); - m_textSprite->Update(textDrawer); - SetPreferredSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths())); - - RefreshCursor(); - } - - void AbstractTextAreaWidget::EnableLineWrap(bool enable) - { - if (m_isLineWrapEnabled != enable) - { - m_isLineWrapEnabled = enable; - - Nz::AbstractTextDrawer& textDrawer = GetTextDrawer(); - - if (enable) - textDrawer.SetMaxLineWidth(GetWidth()); - else - textDrawer.SetMaxLineWidth(std::numeric_limits::infinity()); - - UpdateTextSprite(); - } - } - - Nz::Vector2ui AbstractTextAreaWidget::GetHoveredGlyph(float x, float y) const - { - const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer(); - - auto& textNode = m_textEntity->GetComponent(); - Nz::Vector2f textPosition = Nz::Vector2f(textNode.GetPosition(Nz::CoordSys_Local)); - x -= textPosition.x; - y -= textPosition.y; - - std::size_t glyphCount = textDrawer.GetGlyphCount(); - if (glyphCount > 0) - { - std::size_t lineCount = textDrawer.GetLineCount(); - std::size_t line = 0U; - for (; line < lineCount - 1; ++line) - { - Nz::Rectf lineBounds = textDrawer.GetLine(line).bounds; - if (lineBounds.GetMaximum().y > y) - break; - } - - std::size_t upperLimit = (line != lineCount - 1) ? textDrawer.GetLine(line + 1).glyphIndex : glyphCount + 1; - - std::size_t firstLineGlyph = textDrawer.GetLine(line).glyphIndex; - std::size_t i = firstLineGlyph; - for (; i < upperLimit - 1; ++i) - { - Nz::Rectf bounds = textDrawer.GetGlyph(i).bounds; - if (x < bounds.x + bounds.width * 0.75f) - break; - } - - return Nz::Vector2ui(Nz::Vector2(i - firstLineGlyph, line)); - } - - return Nz::Vector2ui::Zero(); - } - - void AbstractTextAreaWidget::Layout() - { - BaseWidget::Layout(); - - if (m_isLineWrapEnabled) - { - Nz::AbstractTextDrawer& textDrawer = GetTextDrawer(); - - textDrawer.SetMaxLineWidth(GetWidth()); - UpdateTextSprite(); - } - - RefreshCursor(); - } - - bool AbstractTextAreaWidget::IsFocusable() const - { - return !m_readOnly; - } - - void AbstractTextAreaWidget::OnFocusLost() - { - m_cursorEntity->Disable(); - } - - void AbstractTextAreaWidget::OnFocusReceived() - { - if (!m_readOnly) - m_cursorEntity->Enable(true); - } - - bool AbstractTextAreaWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) - { - const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer(); - - switch (key.virtualKey) - { - case Nz::Keyboard::VKey::Backspace: - { - bool ignoreDefaultAction = false; - OnTextAreaKeyBackspace(this, &ignoreDefaultAction); - - std::size_t cursorGlyphEnd = GetGlyphIndex(m_cursorPositionEnd); - - if (ignoreDefaultAction || cursorGlyphEnd == 0) - return true; - - // When a text is selected, delete key does the same as delete and leave the character behind it - if (HasSelection()) - EraseSelection(); - else - { - MoveCursor(-1); - Erase(GetGlyphIndex(m_cursorPositionBegin)); - } - - return true; - } - - case Nz::Keyboard::VKey::Delete: - { - if (HasSelection()) - EraseSelection(); - else - Erase(GetGlyphIndex(m_cursorPositionBegin)); - - return true; - } - - case Nz::Keyboard::VKey::Down: - { - bool ignoreDefaultAction = false; - OnTextAreaKeyDown(this, &ignoreDefaultAction); - - if (ignoreDefaultAction) - return true; - - if (HasSelection()) - SetCursorPosition(m_cursorPositionEnd); - - MoveCursor({0, 1}); - return true; - } - - case Nz::Keyboard::VKey::End: - { - bool ignoreDefaultAction = false; - OnTextAreaKeyEnd(this, &ignoreDefaultAction); - - if (ignoreDefaultAction) - return true; - - std::size_t lineCount = textDrawer.GetLineCount(); - if (key.control && lineCount > 0) - SetCursorPosition({ static_cast(textDrawer.GetLineGlyphCount(lineCount - 1)), static_cast(lineCount - 1) }); - else - SetCursorPosition({ static_cast(textDrawer.GetLineGlyphCount(m_cursorPositionEnd.y)), m_cursorPositionEnd.y }); - - return true; - } - - case Nz::Keyboard::VKey::Home: - { - bool ignoreDefaultAction = false; - OnTextAreaKeyHome(this, &ignoreDefaultAction); - - if (ignoreDefaultAction) - return true; - - SetCursorPosition({ 0U, key.control ? 0U : m_cursorPositionEnd.y }); - return true; - } - - case Nz::Keyboard::VKey::Left: - { - bool ignoreDefaultAction = false; - OnTextAreaKeyLeft(this, &ignoreDefaultAction); - - if (ignoreDefaultAction) - return true; - - if (HasSelection()) - SetCursorPosition(m_cursorPositionBegin); - else if (key.control) - HandleWordCursorMove(true); - else - MoveCursor(-1); - - return true; - } - - case Nz::Keyboard::VKey::Return: - { - bool ignoreDefaultAction = false; - OnTextAreaKeyReturn(this, &ignoreDefaultAction); - - if (ignoreDefaultAction) - return true; - - if (!m_multiLineEnabled) - break; - - if (HasSelection()) - EraseSelection(); - - Write(Nz::String('\n')); - return true;; - } - - case Nz::Keyboard::VKey::Right: - { - bool ignoreDefaultAction = false; - OnTextAreaKeyRight(this, &ignoreDefaultAction); - - if (ignoreDefaultAction) - return true; - - if (HasSelection()) - SetCursorPosition(m_cursorPositionEnd); - else if (key.control) - HandleWordCursorMove(false); - else - MoveCursor(1); - - return true; - } - - case Nz::Keyboard::VKey::Up: - { - bool ignoreDefaultAction = false; - OnTextAreaKeyUp(this, &ignoreDefaultAction); - - if (ignoreDefaultAction) - return true; - - if (HasSelection()) - SetCursorPosition(m_cursorPositionBegin); - - MoveCursor({0, -1}); - return true; - } - - case Nz::Keyboard::VKey::Tab: - { - if (!m_tabEnabled) - return false; - - if (HasSelection()) - HandleSelectionIndentation(!key.shift); - else - HandleIndentation(!key.shift); - - return true; - } - - default: - break; - } - - return false; - } - - void AbstractTextAreaWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& /*key*/) - { - } - - void AbstractTextAreaWidget::OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) - { - if (button == Nz::Mouse::Left) - { - SetFocus(); - - Nz::Vector2ui hoveredGlyph = GetHoveredGlyph(float(x), float(y)); - - // Shift extends selection - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RShift)) - SetSelection(hoveredGlyph, m_selectionCursor); - else - { - SetCursorPosition(hoveredGlyph); - m_selectionCursor = m_cursorPositionBegin; - } - - m_isMouseButtonDown = true; - } - } - - void AbstractTextAreaWidget::OnMouseButtonRelease(int, int, Nz::Mouse::Button button) - { - if (button == Nz::Mouse::Left) - m_isMouseButtonDown = false; - } - - void AbstractTextAreaWidget::OnMouseEnter() - { - if (!Nz::Mouse::IsButtonPressed(Nz::Mouse::Left)) - m_isMouseButtonDown = false; - } - - void AbstractTextAreaWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY) - { - if (m_isMouseButtonDown) - SetSelection(m_selectionCursor, GetHoveredGlyph(float(x), float(y))); - } - - void AbstractTextAreaWidget::OnTextEntered(char32_t character, bool /*repeated*/) - { - if (m_readOnly) - return; - - if (Nz::Unicode::GetCategory(character) == Nz::Unicode::Category_Other_Control || (m_characterFilter && !m_characterFilter(character))) - return; - - if (HasSelection()) - EraseSelection(); - - Write(Nz::String::Unicode(character)); - } - - void AbstractTextAreaWidget::RefreshCursor() - { - if (m_readOnly) - return; - - const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer(); - - auto GetGlyph = [&](const Nz::Vector2ui& glyphPosition, std::size_t* glyphIndex) -> const Nz::AbstractTextDrawer::Glyph* - { - if (glyphPosition.y >= textDrawer.GetLineCount()) - return nullptr; - - const auto& lineInfo = textDrawer.GetLine(glyphPosition.y); - - std::size_t cursorGlyph = GetGlyphIndex({ glyphPosition.x, glyphPosition.y }); - if (glyphIndex) - *glyphIndex = cursorGlyph; - - std::size_t glyphCount = textDrawer.GetGlyphCount(); - if (glyphCount > 0 && lineInfo.glyphIndex < cursorGlyph) - { - const auto& glyph = textDrawer.GetGlyph(std::min(cursorGlyph, glyphCount - 1)); - return &glyph; - } - else - return nullptr; - }; - - // Move text so that cursor is always visible - const auto* lastGlyph = GetGlyph(m_cursorPositionEnd, nullptr); - float glyphPos = (lastGlyph) ? lastGlyph->bounds.x : 0.f; - float glyphWidth = (lastGlyph) ? lastGlyph->bounds.width : 0.f; - - auto& node = m_textEntity->GetComponent(); - float textPosition = node.GetPosition(Nz::CoordSys_Local).x - paddingWidth; - float cursorPosition = glyphPos + textPosition; - float width = GetWidth(); - - if (width <= textDrawer.GetBounds().width) - { - if (cursorPosition + glyphWidth > width) - node.Move(width - cursorPosition - glyphWidth, 0.f); - else if (cursorPosition - glyphWidth < 0.f) - node.Move(-cursorPosition + glyphWidth, 0.f); - } - else - node.Move(-textPosition, 0.f); // Reset text position if we have enough room to show everything - - // Show cursor/selection - std::size_t selectionLineCount = m_cursorPositionEnd.y - m_cursorPositionBegin.y + 1; - std::size_t oldSpriteCount = m_cursorSprites.size(); - if (m_cursorSprites.size() != selectionLineCount) - { - m_cursorSprites.resize(m_cursorPositionEnd.y - m_cursorPositionBegin.y + 1); - for (std::size_t i = oldSpriteCount; i < m_cursorSprites.size(); ++i) - { - m_cursorSprites[i] = Nz::Sprite::New(); - m_cursorSprites[i]->SetMaterial(Nz::Material::New("Translucent2D")); - } - } - - GraphicsComponent& gfxComponent = m_cursorEntity->GetComponent(); - gfxComponent.Clear(); - - for (unsigned int i = m_cursorPositionBegin.y; i <= m_cursorPositionEnd.y; ++i) - { - const auto& lineInfo = textDrawer.GetLine(i); - - Nz::SpriteRef& cursorSprite = m_cursorSprites[i - m_cursorPositionBegin.y]; - if (i == m_cursorPositionBegin.y || i == m_cursorPositionEnd.y) - { - auto GetGlyphPos = [&](const Nz::Vector2ui& glyphPosition) - { - std::size_t glyphIndex; - const auto* glyph = GetGlyph(glyphPosition, &glyphIndex); - if (glyph) - { - float position = glyph->bounds.x; - if (glyphIndex >= textDrawer.GetGlyphCount()) - position += glyph->bounds.width; - - return position; - } - else - return 0.f; - }; - - float beginX = (i == m_cursorPositionBegin.y) ? GetGlyphPos({ m_cursorPositionBegin.x, i }) : 0.f; - float endX = (i == m_cursorPositionEnd.y) ? GetGlyphPos({ m_cursorPositionEnd.x, i }) : lineInfo.bounds.width; - float spriteSize = std::max(endX - beginX, 1.f); - - cursorSprite->SetColor((m_cursorPositionBegin == m_cursorPositionEnd) ? Nz::Color::Black : Nz::Color(0, 0, 0, 50)); - cursorSprite->SetSize(spriteSize, lineInfo.bounds.height); - - gfxComponent.Attach(cursorSprite, Nz::Matrix4f::Translate({ beginX, lineInfo.bounds.y, 0.f })); - } - else - { - cursorSprite->SetColor(Nz::Color(0, 0, 0, 50)); - cursorSprite->SetSize(lineInfo.bounds.width, lineInfo.bounds.height); - - gfxComponent.Attach(cursorSprite, Nz::Matrix4f::Translate({ 0.f, lineInfo.bounds.y, 0.f })); - } - } - } - - void AbstractTextAreaWidget::UpdateTextSprite() - { - m_textSprite->Update(GetTextDrawer()); - SetPreferredSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths())); - } -} diff --git a/src/NazaraSDK/Widgets/BoxLayout.cpp b/src/NazaraSDK/Widgets/BoxLayout.cpp deleted file mode 100644 index dd9a94efa..000000000 --- a/src/NazaraSDK/Widgets/BoxLayout.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include - -namespace Ndk -{ - void BoxLayout::Layout() - { - std::size_t axis1, axis2; - - switch (m_orientation) - { - case BoxLayoutOrientation_Horizontal: - axis1 = 0; //< x - axis2 = 1; //< y - break; - - case BoxLayoutOrientation_Vertical: - axis1 = 1; //< y - axis2 = 0; //< x - break; - - default: - assert(false); - break; - } - - m_childInfos.clear(); - - // Handle size - ForEachWidgetChild([&](BaseWidget* child) - { - if (!child->IsVisible()) - return; - - m_childInfos.emplace_back(); - auto& info = m_childInfos.back(); - info.isConstrained = false; - info.maximumSize = child->GetMaximumSize()[axis1]; - info.minimumSize = child->GetMinimumSize()[axis1]; - info.size = info.minimumSize; - info.widget = child; - }); - - Nz::Vector2f layoutSize = GetSize(); - - float availableSpace = layoutSize[axis1] - m_spacing * (m_childInfos.size() - 1); - float remainingSize = availableSpace; - for (auto& info : m_childInfos) - remainingSize -= info.minimumSize; - - // Okay this algorithm is FAR from perfect but I couldn't figure a way other than this one - std::size_t unconstrainedChildCount = m_childInfos.size(); - - bool hasUnconstrainedChilds = false; - for (std::size_t i = 0; i < m_childInfos.size(); ++i) - { - if (remainingSize <= 0.0001f) - break; - - float evenSize = remainingSize / unconstrainedChildCount; - - for (auto& info : m_childInfos) - { - if (info.isConstrained) - continue; - - float previousSize = info.size; - - info.size += evenSize; - if (info.size > info.maximumSize) - { - unconstrainedChildCount--; - - evenSize += (info.size - info.maximumSize) / unconstrainedChildCount; - info.isConstrained = true; - info.size = info.maximumSize; - } - else - hasUnconstrainedChilds = true; - - remainingSize -= info.size - previousSize; - } - - if (!hasUnconstrainedChilds) - break; - } - - float spacing = m_spacing + remainingSize / (m_childInfos.size() - 1); - - for (auto& info : m_childInfos) - { - Nz::Vector2f newSize = info.widget->GetSize(); - newSize[axis1] = info.size; - - info.widget->Resize(newSize); - } - - // Handle position - float cursor = 0.f; - bool first = true; - for (auto& info : m_childInfos) - { - if (first) - first = false; - else - cursor += spacing; - - Nz::Vector2f position = Nz::Vector2f(0.f, 0.f); - position[axis1] = cursor; - - info.widget->SetPosition(position); - - cursor += info.size; - }; - } -} diff --git a/src/NazaraSDK/Widgets/ButtonWidget.cpp b/src/NazaraSDK/Widgets/ButtonWidget.cpp deleted file mode 100644 index 84a72b17f..000000000 --- a/src/NazaraSDK/Widgets/ButtonWidget.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include - -namespace Ndk -{ - Nz::Color ButtonWidget::s_color { 74, 74, 74 }; - Nz::Color ButtonWidget::s_cornerColor { 180, 180, 180 }; - Nz::Color ButtonWidget::s_hoverColor { 128, 128, 128 }; - Nz::Color ButtonWidget::s_hoverCornerColor { s_cornerColor }; - Nz::Color ButtonWidget::s_pressColor { s_cornerColor }; - Nz::Color ButtonWidget::s_pressCornerColor { s_color }; - - ButtonWidget::ButtonWidget(BaseWidget* parent) : - BaseWidget(parent), - m_color { s_color }, - m_cornerColor { s_cornerColor }, - m_hoverColor { s_hoverColor }, - m_hoverCornerColor { s_hoverCornerColor }, - m_pressColor { s_pressColor }, - m_pressCornerColor { s_pressCornerColor } - { - m_gradientSprite = Nz::Sprite::New(); - m_gradientSprite->SetColor(m_color); - m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_cornerColor); - m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_cornerColor); - m_gradientSprite->SetMaterial(Nz::Material::New("Basic2D")); - - m_gradientEntity = CreateEntity(); - m_gradientEntity->AddComponent().SetParent(this); - m_gradientEntity->AddComponent().Attach(m_gradientSprite); - - m_textSprite = Nz::TextSprite::New(); - - m_textEntity = CreateEntity(); - m_textEntity->AddComponent().SetParent(this); - m_textEntity->AddComponent().Attach(m_textSprite, 1); - - Layout(); - } - - const Nz::Color& ButtonWidget::GetDefaultColor() - { - return s_color; - } - - const Nz::Color& ButtonWidget::GetDefaultCornerColor() - { - return s_cornerColor; - } - - const Nz::Color& ButtonWidget::GetDefaultHoverColor() - { - return s_hoverColor; - } - - const Nz::Color& ButtonWidget::GetDefaultHoverCornerColor() - { - return s_hoverCornerColor; - } - - const Nz::Color& ButtonWidget::GetDefaultPressColor() - { - return s_pressColor; - } - - const Nz::Color& ButtonWidget::GetDefaultPressCornerColor() - { - return s_pressCornerColor; - } - - void ButtonWidget::Layout() - { - BaseWidget::Layout(); - - Nz::Vector2f size = GetSize(); - m_gradientSprite->SetSize(size); - - Nz::Boxf textBox = m_textEntity->GetComponent().GetAABB(); - m_textEntity->GetComponent().SetPosition(size.x / 2.f - textBox.width / 2.f, size.y / 2.f - textBox.height / 2.f); - } - - void ButtonWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button) - { - if (button == Nz::Mouse::Left) - { - m_gradientSprite->SetColor(m_pressColor); - m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_pressCornerColor); - m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_pressCornerColor); - m_gradientSprite->SetTexture(m_pressTexture, false); - } - } - - void ButtonWidget::OnMouseButtonRelease(int /*x*/, int /*y*/, Nz::Mouse::Button button) - { - if (button == Nz::Mouse::Left) - { - m_gradientSprite->SetColor(m_hoverColor); - m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_hoverCornerColor); - m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_hoverCornerColor); - m_gradientSprite->SetTexture(m_hoverTexture, false); - - OnButtonTrigger(this); - } - } - - void ButtonWidget::OnMouseEnter() - { - m_gradientSprite->SetColor(m_hoverColor); - m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_hoverCornerColor); - m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_hoverCornerColor); - m_gradientSprite->SetTexture(m_hoverTexture, false); - } - - void ButtonWidget::OnMouseExit() - { - m_gradientSprite->SetColor(m_color); - m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_cornerColor); - m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_cornerColor); - m_gradientSprite->SetTexture(m_texture, false); - } -} diff --git a/src/NazaraSDK/Widgets/CheckboxWidget.cpp b/src/NazaraSDK/Widgets/CheckboxWidget.cpp deleted file mode 100644 index 3c16b1219..000000000 --- a/src/NazaraSDK/Widgets/CheckboxWidget.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include - -namespace Ndk -{ - Nz::Color CheckboxWidget::s_backgroundColor { Nz::Color::White }; - Nz::Color CheckboxWidget::s_disabledBackgroundColor { 201, 201, 201 }; - Nz::Color CheckboxWidget::s_disabledBorderColor { 62, 62, 62 }; - Nz::Color CheckboxWidget::s_borderColor { Nz::Color::Black }; - float CheckboxWidget::s_borderScale { 16.f }; - - CheckboxWidget::CheckboxWidget(BaseWidget* parent) : - BaseWidget(parent), - m_adaptativeMargin { true }, - m_checkboxEnabled { true }, - m_tristateEnabled { false }, - m_textMargin { 16.f }, - m_state { CheckboxState_Unchecked } - { - m_checkboxBorderSprite = Nz::Sprite::New(Nz::Material::New("Basic2D")); - m_checkboxBackgroundSprite = Nz::Sprite::New(Nz::Material::New("Basic2D")); - m_checkboxContentSprite = Nz::Sprite::New(Nz::Material::New("Translucent2D")); - m_textSprite = Nz::TextSprite::New(); - - m_checkboxBorderEntity = CreateEntity(); - m_checkboxBorderEntity->AddComponent().SetParent(this); - m_checkboxBorderEntity->AddComponent().Attach(m_checkboxBorderSprite); - - m_checkboxBackgroundEntity = CreateEntity(); - m_checkboxBackgroundEntity->AddComponent().SetParent(this); - m_checkboxBackgroundEntity->AddComponent().Attach(m_checkboxBackgroundSprite, 1); - - m_checkboxContentEntity = CreateEntity(); - m_checkboxContentEntity->AddComponent().SetParent(this); - m_checkboxContentEntity->AddComponent().Attach(m_checkboxContentSprite, 2); - - m_textEntity = CreateEntity(); - m_textEntity->AddComponent().SetParent(this); - m_textEntity->AddComponent().Attach(m_textSprite); - - m_checkMark = Nz::TextureLibrary::Get("Ndk::CheckboxWidget::checkmark"); - - SetCheckboxSize({ 32.f, 32.f }); - UpdateCheckbox(); - } - - bool CheckboxWidget::Initialize() - { - const Nz::UInt8 r_checkmark[] = - { - #include - }; - - Nz::TextureRef checkmarkTexture = Nz::Texture::LoadFromMemory(r_checkmark, sizeof(r_checkmark) / sizeof(r_checkmark[0])); - if (!checkmarkTexture) - { - NazaraError("Failed to load embedded checkmark"); - return false; - } - - Nz::TextureLibrary::Register("Ndk::CheckboxWidget::checkmark", std::move(checkmarkTexture)); - return true; - } - - void CheckboxWidget::Uninitialize() - { - Nz::TextureLibrary::Unregister("Ndk::CheckboxWidget::checkmark"); - } - - void CheckboxWidget::SetState(CheckboxState state) - { - if (!m_checkboxEnabled) - return; - - if (state == CheckboxState_Tristate) - m_tristateEnabled = true; - - m_state = state; - UpdateCheckbox(); - } - - CheckboxState CheckboxWidget::SwitchToNextState() - { - if (!m_checkboxEnabled) - return m_state; - - switch (m_state) - { - case CheckboxState_Unchecked: - SetState(CheckboxState_Checked); - break; - - case CheckboxState_Checked: - SetState(m_tristateEnabled ? CheckboxState_Tristate : CheckboxState_Unchecked); - break; - - case CheckboxState_Tristate: - SetState(CheckboxState_Unchecked); - break; - } - - return m_state; - } - - void CheckboxWidget::Layout() - { - BaseWidget::Layout(); - - Nz::Vector2f checkboxSize = GetCheckboxSize(); - Nz::Vector2f borderSize = GetCheckboxBorderSize(); - - m_checkboxBackgroundEntity->GetComponent().SetPosition(borderSize); - - Nz::Vector3f checkboxBox = m_checkboxContentSprite->GetBoundingVolume().obb.localBox.GetLengths(); - m_checkboxContentEntity->GetComponent().SetPosition(checkboxSize.x / 2.f - checkboxBox.x / 2.f, checkboxSize.y / 2.f - checkboxBox.y / 2.f); - - Nz::Vector3f textBox = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths(); - m_textEntity->GetComponent().SetPosition(checkboxSize.x + (m_adaptativeMargin ? checkboxSize.x / 2.f : m_textMargin), checkboxSize.y / 2.f - textBox.y / 2.f); - } - - void CheckboxWidget::OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) - { - if (button == Nz::Mouse::Left && ContainsCheckbox(x, y) && IsCheckboxEnabled()) - { - SwitchToNextState(); - OnStateChanged(this); - } - } - - void CheckboxWidget::UpdateCheckbox() - { - if (m_checkboxEnabled) - { - m_checkboxBorderSprite->SetColor(s_borderColor); - m_checkboxBackgroundSprite->SetColor(s_backgroundColor); - } - else - { - m_checkboxBorderSprite->SetColor(s_disabledBorderColor); - m_checkboxBackgroundSprite->SetColor(s_disabledBackgroundColor); - } - - - if (m_state == CheckboxState_Unchecked) - { - m_checkboxContentEntity->Enable(false); - return; - } - else if (m_state == CheckboxState_Checked) - { - m_checkboxContentEntity->Enable(); - m_checkboxContentSprite->SetColor(Nz::Color::White); - m_checkboxContentSprite->SetTexture(m_checkMark, false); - } - else // Tristate - { - m_checkboxContentEntity->Enable(); - m_checkboxContentSprite->SetColor(Nz::Color::Black); - m_checkboxContentSprite->SetTexture(Nz::TextureRef {}); - } - } - - void CheckboxWidget::UpdateSize() - { - Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths(); - Nz::Vector2f checkboxSize = GetCheckboxSize(); - - Nz::Vector2f finalSize { checkboxSize.x + (m_adaptativeMargin ? checkboxSize.x / 2.f : m_textMargin) + textSize.x, std::max(textSize.y, checkboxSize.y) }; - SetMinimumSize(finalSize); - SetPreferredSize(finalSize); - } -} diff --git a/src/NazaraSDK/Widgets/ImageWidget.cpp b/src/NazaraSDK/Widgets/ImageWidget.cpp deleted file mode 100644 index bb8398806..000000000 --- a/src/NazaraSDK/Widgets/ImageWidget.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include - -namespace Ndk -{ - ImageWidget::ImageWidget(BaseWidget* parent) : - BaseWidget(parent) - { - m_entity = CreateEntity(); - m_entity->AddComponent().SetParent(this); - auto& gfx = m_entity->AddComponent(); - - m_sprite = Nz::Sprite::New(); - gfx.Attach(m_sprite); - } - - void ImageWidget::Layout() - { - BaseWidget::Layout(); - - m_sprite->SetSize(GetSize()); - } -} diff --git a/src/NazaraSDK/Widgets/LabelWidget.cpp b/src/NazaraSDK/Widgets/LabelWidget.cpp deleted file mode 100644 index bbff99e0d..000000000 --- a/src/NazaraSDK/Widgets/LabelWidget.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include - -namespace Ndk -{ - LabelWidget::LabelWidget(BaseWidget* parent) : - BaseWidget(parent) - { - m_textSprite = Nz::TextSprite::New(); - - m_textEntity = CreateEntity(); - m_textEntity->AddComponent().Attach(m_textSprite); - m_textEntity->AddComponent().SetParent(this); - - Layout(); - } -} diff --git a/src/NazaraSDK/Widgets/ProgressBarWidget.cpp b/src/NazaraSDK/Widgets/ProgressBarWidget.cpp deleted file mode 100644 index 0c566b423..000000000 --- a/src/NazaraSDK/Widgets/ProgressBarWidget.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (C) 2017 Samy Bensaid -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include - -namespace Ndk -{ - float ProgressBarWidget::s_borderScale { 16.f }; - Nz::Color ProgressBarWidget::s_borderColor { Nz::Color::Black }; - Nz::Color ProgressBarWidget::s_barBackgroundColor { Nz::Color { 225, 225, 225 } }; - Nz::Color ProgressBarWidget::s_barBackgroundCornerColor { Nz::Color { 255, 255, 255 } }; - Nz::Color ProgressBarWidget::s_barColor { Nz::Color { 0, 225, 0 } }; - Nz::Color ProgressBarWidget::s_barCornerColor { Nz::Color { 220, 255, 220 } }; - - ProgressBarWidget::ProgressBarWidget(BaseWidget* parent) : - BaseWidget(parent), - m_textColor { Nz::Color::Black }, - m_textMargin { 16.f }, - m_value { 0u } - { - m_borderSprite = Nz::Sprite::New(Nz::Material::New("Basic2D")); - m_barBackgroundSprite = Nz::Sprite::New(Nz::Material::New("Basic2D")); - m_barSprite = Nz::Sprite::New(Nz::Material::New("Basic2D")); - - m_borderSprite->SetColor(s_borderColor); - SetBarBackgroundColor(s_barBackgroundColor, s_barBackgroundCornerColor); - SetBarColor(s_barColor, s_barCornerColor); - - - m_borderEntity = CreateEntity(); - m_borderEntity->AddComponent().SetParent(this); - m_borderEntity->AddComponent().Attach(m_borderSprite); - - m_barEntity = CreateEntity(); - m_barEntity->AddComponent().SetParent(this); - GraphicsComponent& graphics = m_barEntity->AddComponent(); - - graphics.Attach(m_barBackgroundSprite, 1); - graphics.Attach(m_barSprite, 2); - - - m_textSprite = Nz::TextSprite::New(); - m_textEntity = CreateEntity(); - - m_textEntity->AddComponent().SetParent(this); - m_textEntity->AddComponent().Attach(m_textSprite); - - UpdateText(); - Layout(); - } - - - const Nz::Color& ProgressBarWidget::GetDefaultBarColor() - { - return s_barColor; - } - - const Nz::Color& ProgressBarWidget::GetDefaultBarCornerColor() - { - return s_barCornerColor; - } - - const Nz::Color& ProgressBarWidget::GetDefaultBarBackgroundColor() - { - return s_barBackgroundColor; - } - - const Nz::Color& ProgressBarWidget::GetDefaultBarBackgroundCornerColor() - { - return s_barBackgroundCornerColor; - } - - - void ProgressBarWidget::Layout() - { - Nz::Vector2f size = GetSize(); - Nz::Vector2f progressBarSize = size; - - if (IsTextEnabled()) - { - UpdateText(); - - Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths(); - m_textEntity->GetComponent().SetPosition(size.x - textSize.x, size.y / 2.f - textSize.y); - - progressBarSize -= { textSize.x + m_textMargin, 0.f }; - } - - m_borderSprite->SetSize(progressBarSize); - Nz::Vector2f borderSize = GetProgressBarBorderSize(); - - m_barBackgroundSprite->SetSize(progressBarSize - (borderSize * 2.f)); - m_barSprite->SetSize((progressBarSize.x - (borderSize.x * 2.f)) / 100.f * static_cast(m_value), progressBarSize.y - (borderSize.y * 2.f)); - - m_barEntity->GetComponent().SetPosition(borderSize.x, borderSize.y); - } -} diff --git a/src/NazaraSDK/Widgets/RichTextAreaWidget.cpp b/src/NazaraSDK/Widgets/RichTextAreaWidget.cpp deleted file mode 100644 index a9eec53b9..000000000 --- a/src/NazaraSDK/Widgets/RichTextAreaWidget.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include - -namespace Ndk -{ - RichTextAreaWidget::RichTextAreaWidget(BaseWidget* parent) : - AbstractTextAreaWidget(parent) - { - Layout(); - } - - void RichTextAreaWidget::AppendText(const Nz::String& text) - { - //m_text += text; - switch (m_echoMode) - { - case EchoMode_Normal: - m_drawer.AppendText(text); - break; - - case EchoMode_Password: - m_drawer.AppendText(Nz::String(text.GetLength(), '*')); - break; - - case EchoMode_PasswordExceptLast: - { - /*m_drawer.Clear(); - std::size_t textLength = m_text.GetLength(); - if (textLength >= 2) - { - std::size_t lastCharacterPosition = m_text.GetCharacterPosition(textLength - 2); - if (lastCharacterPosition != Nz::String::npos) - m_drawer.AppendText(Nz::String(textLength - 1, '*')); - } - - if (textLength >= 1) - m_drawer.AppendText(m_text.SubString(m_text.GetCharacterPosition(textLength - 1)));*/ - - break; - } - } - - UpdateTextSprite(); - - //OnTextChanged(this, m_text); - } - - void RichTextAreaWidget::Clear() - { - AbstractTextAreaWidget::Clear(); - } - - void RichTextAreaWidget::Erase(std::size_t firstGlyph, std::size_t lastGlyph) - { - if (firstGlyph > lastGlyph) - std::swap(firstGlyph, lastGlyph); - - std::size_t textLength = m_drawer.GetGlyphCount(); - if (firstGlyph > textLength) - return; - - std::size_t firstBlock = m_drawer.FindBlock(firstGlyph); - std::size_t lastBlock = m_drawer.FindBlock((lastGlyph > 0) ? lastGlyph - 1 : lastGlyph); - if (firstBlock == lastBlock) - { - const Nz::String& blockText = m_drawer.GetBlockText(firstBlock); - std::size_t blockFirstGlyph = m_drawer.GetBlockFirstGlyphIndex(firstBlock); - - Nz::String newText; - if (firstGlyph > blockFirstGlyph) - { - std::size_t characterPosition = blockText.GetCharacterPosition(firstGlyph - blockFirstGlyph); - NazaraAssert(characterPosition != Nz::String::npos, "Invalid character position"); - - newText.Append(blockText.SubString(0, characterPosition - 1)); - } - - if (lastGlyph < textLength) - newText.Append(blockText.SubString(blockText.GetCharacterPosition(lastGlyph - blockFirstGlyph))); - - if (!newText.IsEmpty()) - m_drawer.SetBlockText(firstBlock, std::move(newText)); - else - m_drawer.RemoveBlock(firstBlock); - } - else - { - const Nz::String& lastBlockText = m_drawer.GetBlockText(lastBlock); - std::size_t lastBlockGlyphIndex = m_drawer.GetBlockFirstGlyphIndex(lastBlock); - - // First, update/delete last block - std::size_t lastCharPos = lastBlockText.GetCharacterPosition(lastGlyph - lastBlockGlyphIndex); - if (lastCharPos != Nz::String::npos) - { - Nz::String newText = lastBlockText.SubString(lastCharPos); - if (!newText.IsEmpty()) - m_drawer.SetBlockText(lastBlock, std::move(newText)); - else - m_drawer.RemoveBlock(lastBlock); - } - - // And then remove all middle blocks, remove in reverse order because of index shifting - assert(lastBlock > 0); - for (std::size_t i = lastBlock - 1; i > firstBlock; --i) - m_drawer.RemoveBlock(i); - - const Nz::String& firstBlockText = m_drawer.GetBlockText(firstBlock); - std::size_t firstBlockGlyphIndex = m_drawer.GetBlockFirstGlyphIndex(firstBlock); - - // And finally update/delete first block - if (firstGlyph > firstBlockGlyphIndex) - { - std::size_t firstCharPos = firstBlockText.GetCharacterPosition(firstGlyph - firstBlockGlyphIndex - 1); - if (firstCharPos != Nz::String::npos) - { - Nz::String newText = firstBlockText.SubString(0, firstCharPos); - if (!newText.IsEmpty()) - m_drawer.SetBlockText(firstBlock, std::move(newText)); - else - m_drawer.RemoveBlock(firstBlock); - } - } - else - m_drawer.RemoveBlock(firstBlock); - } - - UpdateDisplayText(); - } - - void RichTextAreaWidget::Write(const Nz::String& text, std::size_t glyphPosition) - { - if (m_drawer.HasBlocks()) - { - auto block = m_drawer.GetBlock(m_drawer.FindBlock((glyphPosition > 0) ? glyphPosition - 1 : glyphPosition)); - std::size_t firstGlyph = block.GetFirstGlyphIndex(); - assert(glyphPosition >= firstGlyph); - - Nz::String blockText = block.GetText(); - std::size_t characterPosition = blockText.GetCharacterPosition(glyphPosition - firstGlyph); - blockText.Insert(characterPosition, text); - - block.SetText(blockText); - } - else - m_drawer.AppendText(text); - - SetCursorPosition(glyphPosition + text.GetLength()); - - UpdateDisplayText(); - } - - Nz::AbstractTextDrawer& RichTextAreaWidget::GetTextDrawer() - { - return m_drawer; - } - - const Nz::AbstractTextDrawer& RichTextAreaWidget::GetTextDrawer() const - { - return m_drawer; - } - - void RichTextAreaWidget::HandleIndentation(bool add) - { - } - - void RichTextAreaWidget::HandleSelectionIndentation(bool add) - { - } - - void RichTextAreaWidget::HandleWordCursorMove(bool left) - { - } - - void RichTextAreaWidget::UpdateDisplayText() - { - /*m_drawer.Clear(); - switch (m_echoMode) - { - case EchoMode_Normal: - m_drawer.AppendText(m_text); - break; - - case EchoMode_Password: - case EchoMode_PasswordExceptLast: - m_drawer.AppendText(Nz::String(m_text.GetLength(), '*')); - break; - }*/ - - UpdateTextSprite(); - - SetCursorPosition(m_cursorPositionBegin); //< Refresh cursor position (prevent it from being outside of the text) - } -} diff --git a/src/NazaraSDK/Widgets/ScrollAreaWidget.cpp b/src/NazaraSDK/Widgets/ScrollAreaWidget.cpp deleted file mode 100644 index 323642ac7..000000000 --- a/src/NazaraSDK/Widgets/ScrollAreaWidget.cpp +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include - -namespace Ndk -{ - namespace - { - constexpr float scrollbarPadding = 5.f; - } - - ScrollAreaWidget::ScrollAreaWidget(BaseWidget* parent, BaseWidget* content) : - BaseWidget(parent), - m_content(content), - m_scrollbarStatus(ScrollBarStatus::None), - m_isScrollbarEnabled(true), - m_scrollRatio(0.f) - { - m_content->SetParent(this); - m_content->SetPosition(Nz::Vector3f::Zero()); - - m_scrollbarBackgroundSprite = Nz::Sprite::New(); - m_scrollbarBackgroundSprite->SetColor(Nz::Color(62, 62, 62)); - - m_scrollbarBackgroundEntity = CreateEntity(); - m_scrollbarBackgroundEntity->AddComponent().SetParent(this); - m_scrollbarBackgroundEntity->AddComponent().Attach(m_scrollbarBackgroundSprite, 1); - - m_scrollbarSprite = Nz::Sprite::New(); - m_scrollbarSprite->SetColor(Nz::Color(104, 104, 104)); - - m_scrollbarEntity = CreateEntity(); - m_scrollbarEntity->AddComponent().SetParent(this); - m_scrollbarEntity->AddComponent().Attach(m_scrollbarSprite); - - Resize(m_content->GetSize()); - } - - void ScrollAreaWidget::EnableScrollbar(bool enable) - { - if (m_isScrollbarEnabled != enable) - { - m_isScrollbarEnabled = enable; - - bool isVisible = IsScrollbarVisible(); - m_scrollbarEntity->Enable(isVisible); - m_scrollbarBackgroundEntity->Enable(isVisible); - } - } - - void ScrollAreaWidget::ScrollToRatio(float ratio) - { - m_scrollRatio = Nz::Clamp(ratio, 0.f, 1.f); - - float widgetHeight = GetHeight(); - float maxHeight = widgetHeight - m_scrollbarSprite->GetSize().y - 2.f * scrollbarPadding; - - auto& scrollbarNode = m_scrollbarEntity->GetComponent(); - scrollbarNode.SetPosition(Nz::Vector2f(scrollbarNode.GetPosition(Nz::CoordSys_Local).x, scrollbarPadding + m_scrollRatio * maxHeight)); - - float contentPosition = m_scrollRatio * (widgetHeight - m_content->GetHeight()); - - m_content->SetPosition(0.f, contentPosition); - m_content->SetRenderingRect(Nz::Rectf(-std::numeric_limits::infinity(), -contentPosition, std::numeric_limits::infinity(), widgetHeight)); - } - - Nz::Rectf ScrollAreaWidget::GetScrollbarRect() const - { - Nz::Vector2f scrollBarPosition = Nz::Vector2f(m_scrollbarEntity->GetComponent().GetPosition(Nz::CoordSys_Local)); - Nz::Vector2f scrollBarSize = m_scrollbarSprite->GetSize(); - return Nz::Rectf(scrollBarPosition.x, scrollBarPosition.y, scrollBarSize.x, scrollBarSize.y); - } - - void ScrollAreaWidget::Layout() - { - constexpr float scrollBarBackgroundWidth = 20.f; - constexpr float scrollBarWidth = scrollBarBackgroundWidth - 2.f * scrollbarPadding; - - float areaHeight = GetHeight(); - float contentHeight = m_content->GetHeight(); - - if (contentHeight > areaHeight) - { - m_hasScrollbar = true; - - Nz::Vector2f contentSize(GetWidth() - scrollBarBackgroundWidth, contentHeight); - m_content->Resize(contentSize); - - if (m_isScrollbarEnabled) - { - m_scrollbarEntity->Enable(); - m_scrollbarBackgroundEntity->Enable(); - } - - float scrollBarHeight = std::max(std::floor(areaHeight * (areaHeight / contentHeight)), 20.f); - - m_scrollbarBackgroundSprite->SetSize(scrollBarBackgroundWidth, areaHeight); - m_scrollbarSprite->SetSize(scrollBarWidth, scrollBarHeight); - - m_scrollbarBackgroundEntity->GetComponent().SetPosition(contentSize.x, 0.f); - m_scrollbarEntity->GetComponent().SetPosition(contentSize.x + (scrollBarBackgroundWidth - scrollBarWidth) / 2.f, 0.f); - - ScrollToRatio(m_scrollRatio); - } - else - { - m_hasScrollbar = false; - - m_content->Resize(GetSize()); - - m_scrollbarEntity->Disable(); - m_scrollbarBackgroundEntity->Disable(); - - ScrollToRatio(0.f); - } - - BaseWidget::Layout(); - } - - void ScrollAreaWidget::OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) - { - if (button != Nz::Mouse::Left) - return; - - if (m_scrollbarStatus == ScrollBarStatus::Hovered) - { - UpdateScrollbarStatus(ScrollBarStatus::Grabbed); - - auto& scrollbarNode = m_scrollbarEntity->GetComponent(); - - m_grabbedDelta.Set(x, int(y - scrollbarNode.GetPosition(Nz::CoordSys_Local).y)); - } - } - - void ScrollAreaWidget::OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) - { - if (button != Nz::Mouse::Left) - return; - - if (m_scrollbarStatus == ScrollBarStatus::Grabbed) - { - Nz::Rectf scrollBarRect = GetScrollbarRect(); - UpdateScrollbarStatus((scrollBarRect.Contains(Nz::Vector2f(float(x), float(y)))) ? ScrollBarStatus::Hovered : ScrollBarStatus::None); - } - } - - void ScrollAreaWidget::OnMouseExit() - { - //if (m_scrollbarStatus == ScrollBarStatus::Hovered) - UpdateScrollbarStatus(ScrollBarStatus::None); - } - - void ScrollAreaWidget::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/) - { - if (m_scrollbarStatus == ScrollBarStatus::Grabbed) - { - float height = GetHeight(); - float maxHeight = height - m_scrollbarSprite->GetSize().y; - float newHeight = Nz::Clamp(float(y - m_grabbedDelta.y), 0.f, maxHeight); - - ScrollToHeight(newHeight / maxHeight * m_content->GetHeight()); - } - else - { - Nz::Rectf scrollBarRect = GetScrollbarRect(); - UpdateScrollbarStatus((scrollBarRect.Contains(Nz::Vector2f(float(x), float(y)))) ? ScrollBarStatus::Hovered : ScrollBarStatus::None); - } - } - - void ScrollAreaWidget::OnMouseWheelMoved(int /*x*/, int /*y*/, float delta) - { - constexpr float scrollStep = 100.f; - - ScrollToHeight(GetScrollHeight() - scrollStep * delta); - } - - void ScrollAreaWidget::UpdateScrollbarStatus(ScrollBarStatus status) - { - if (m_scrollbarStatus != status) - { - Nz::Color newColor; - switch (status) - { - case ScrollBarStatus::Grabbed: newColor = Nz::Color(235, 235, 235); break; - case ScrollBarStatus::Hovered: newColor = Nz::Color(152, 152, 152); break; - case ScrollBarStatus::None: newColor = Nz::Color(104, 104, 104); break; - } - - m_scrollbarSprite->SetColor(newColor); - m_scrollbarStatus = status; - } - } -} diff --git a/src/NazaraSDK/Widgets/TextAreaWidget.cpp b/src/NazaraSDK/Widgets/TextAreaWidget.cpp deleted file mode 100644 index 3615ad5f6..000000000 --- a/src/NazaraSDK/Widgets/TextAreaWidget.cpp +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include -#include - -namespace Ndk -{ - TextAreaWidget::TextAreaWidget(BaseWidget* parent) : - AbstractTextAreaWidget(parent) - { - SetCharacterSize(GetCharacterSize()); //< Actualize minimum / preferred size - - Layout(); - } - - void TextAreaWidget::AppendText(const Nz::String& text) - { - m_text += text; - switch (m_echoMode) - { - case EchoMode_Normal: - m_drawer.AppendText(text); - break; - - case EchoMode_Password: - m_drawer.AppendText(Nz::String(text.GetLength(), '*')); - break; - - case EchoMode_PasswordExceptLast: - { - m_drawer.Clear(); - std::size_t textLength = m_text.GetLength(); - if (textLength >= 2) - { - std::size_t lastCharacterPosition = m_text.GetCharacterPosition(textLength - 2); - if (lastCharacterPosition != Nz::String::npos) - m_drawer.AppendText(Nz::String(textLength - 1, '*')); - } - - if (textLength >= 1) - m_drawer.AppendText(m_text.SubString(m_text.GetCharacterPosition(textLength - 1))); - - break; - } - } - - UpdateTextSprite(); - - OnTextChanged(this, m_text); - } - - void TextAreaWidget::Clear() - { - AbstractTextAreaWidget::Clear(); - - m_text.Clear(); - OnTextChanged(this, m_text); - } - - void TextAreaWidget::Erase(std::size_t firstGlyph, std::size_t lastGlyph) - { - if (firstGlyph > lastGlyph) - std::swap(firstGlyph, lastGlyph); - - std::size_t textLength = m_text.GetLength(); - if (firstGlyph > textLength) - return; - - Nz::String newText; - if (firstGlyph > 0) - { - std::size_t characterPosition = m_text.GetCharacterPosition(firstGlyph); - NazaraAssert(characterPosition != Nz::String::npos, "Invalid character position"); - - newText.Append(m_text.SubString(0, characterPosition - 1)); - } - - if (lastGlyph < textLength) - { - std::size_t characterPosition = m_text.GetCharacterPosition(lastGlyph); - NazaraAssert(characterPosition != Nz::String::npos, "Invalid character position"); - - newText.Append(m_text.SubString(characterPosition)); - } - - SetText(newText); - } - - void TextAreaWidget::Write(const Nz::String& text, std::size_t glyphPosition) - { - if (glyphPosition >= m_drawer.GetGlyphCount()) - { - // It's faster to append than to insert in the middle - AppendText(text); - SetCursorPosition(m_drawer.GetGlyphCount()); - } - else - { - m_text.Insert(m_text.GetCharacterPosition(glyphPosition), text); - SetText(m_text); - - SetCursorPosition(glyphPosition + text.GetLength()); - } - } - - Nz::AbstractTextDrawer& TextAreaWidget::GetTextDrawer() - { - return m_drawer; - } - - const Nz::AbstractTextDrawer& TextAreaWidget::GetTextDrawer() const - { - return m_drawer; - } - - void TextAreaWidget::HandleIndentation(bool add) - { - if (add) - Write(Nz::String('\t')); - else - { - std::size_t currentGlyph = GetGlyphIndex(m_cursorPositionBegin); - - if (currentGlyph > 0 && m_text[m_text.GetCharacterPosition(currentGlyph - 1U)] == '\t') // Check if previous glyph is a tab - { - Erase(currentGlyph - 1U); - - if (m_cursorPositionBegin.x < static_cast(m_drawer.GetLineGlyphCount(m_cursorPositionBegin.y))) - MoveCursor(-1); - } - } - } - - void TextAreaWidget::HandleSelectionIndentation(bool add) - { - for (unsigned line = m_cursorPositionBegin.y; line <= m_cursorPositionEnd.y; ++line) - { - const Nz::Vector2ui cursorPositionBegin = m_cursorPositionBegin; - const Nz::Vector2ui cursorPositionEnd = m_cursorPositionEnd; - - if (add) - { - Write(Nz::String('\t'), { 0U, line }); - SetSelection(cursorPositionBegin + (cursorPositionBegin.y == line && cursorPositionBegin.x != 0U ? Nz::Vector2ui{ 1U, 0U } : Nz::Vector2ui{}), - cursorPositionEnd + (cursorPositionEnd.y == line ? Nz::Vector2ui{ 1U, 0U } : Nz::Vector2ui{})); - } - else - { - if (m_drawer.GetLineGlyphCount(line) == 0) - continue; - - std::size_t firstGlyph = GetGlyphIndex({ 0U, line }); - - if (m_text[m_text.GetCharacterPosition(firstGlyph)] == '\t') - { - Erase(firstGlyph); - SetSelection(cursorPositionBegin - (cursorPositionBegin.y == line && cursorPositionBegin.x != 0U ? Nz::Vector2ui{ 1U, 0U } : Nz::Vector2ui{}), - cursorPositionEnd - (cursorPositionEnd.y == line && cursorPositionEnd.x != 0U ? Nz::Vector2ui{ 1U, 0U } : Nz::Vector2ui{})); - } - } - } - } - - void TextAreaWidget::HandleWordCursorMove(bool left) - { - if (left) - { - std::size_t index = GetGlyphIndex(m_cursorPositionBegin); - if (index == 0) - return; - - std::size_t spaceIndex = m_text.FindLast(' ', index - 2); - std::size_t endlIndex = m_text.FindLast('\n', index - 1); - - if ((spaceIndex > endlIndex || endlIndex == Nz::String::npos) && spaceIndex != Nz::String::npos) - SetCursorPosition(spaceIndex + 1); - else if (endlIndex != Nz::String::npos) - { - if (index == endlIndex + 1) - SetCursorPosition(endlIndex); - else - SetCursorPosition(endlIndex + 1); - } - else - SetCursorPosition({ 0U, m_cursorPositionBegin.y }); - } - else - { - std::size_t index = GetGlyphIndex(m_cursorPositionEnd); - std::size_t spaceIndex = m_text.Find(' ', index); - std::size_t endlIndex = m_text.Find('\n', index); - - if (spaceIndex < endlIndex && spaceIndex != Nz::String::npos) - { - if (m_text.GetSize() > spaceIndex) - SetCursorPosition(spaceIndex + 1); - else - SetCursorPosition({ static_cast(m_drawer.GetLineGlyphCount(m_cursorPositionEnd.y)), m_cursorPositionEnd.y }); - } - else if (endlIndex != Nz::String::npos) - { - if (index == endlIndex) - SetCursorPosition(endlIndex + 1); - else - SetCursorPosition(endlIndex); - } - else - SetCursorPosition({ static_cast(m_drawer.GetLineGlyphCount(m_cursorPositionEnd.y)), m_cursorPositionEnd.y }); - } - } - - void TextAreaWidget::UpdateDisplayText() - { - switch (m_echoMode) - { - case EchoMode_Normal: - m_drawer.SetText(m_text); - break; - - case EchoMode_Password: - case EchoMode_PasswordExceptLast: - m_drawer.SetText(Nz::String(m_text.GetLength(), '*')); - break; - } - - UpdateTextSprite(); - - SetCursorPosition(m_cursorPositionBegin); //< Refresh cursor position (prevent it from being outside of the text) - } - - void TextAreaWidget::UpdateMinimumSize() - { - std::size_t fontCount = m_drawer.GetFontCount(); - float lineHeight = 0; - int spaceAdvance = 0; - for (std::size_t i = 0; i < fontCount; ++i) - { - Nz::Font* font = m_drawer.GetFont(i); - - const Nz::Font::SizeInfo& sizeInfo = font->GetSizeInfo(m_drawer.GetCharacterSize()); - lineHeight = std::max(lineHeight, m_drawer.GetLineHeight()); - spaceAdvance = std::max(spaceAdvance, sizeInfo.spaceAdvance); - } - - Nz::Vector2f size = { float(spaceAdvance), lineHeight + 5.f }; - SetMinimumSize(size); - } -} diff --git a/src/NazaraSDK/World.cpp b/src/NazaraSDK/World.cpp index af2ca3370..42650b169 100644 --- a/src/NazaraSDK/World.cpp +++ b/src/NazaraSDK/World.cpp @@ -12,10 +12,7 @@ #include #ifndef NDK_SERVER -#include #include -#include -#include #endif namespace Ndk @@ -50,10 +47,7 @@ namespace Ndk AddSystem(); #ifndef NDK_SERVER - AddSystem(); AddSystem(); - AddSystem(); - AddSystem(); #endif } diff --git a/tests/Engine/Graphics/Billboard.cpp b/tests/Engine/Graphics/Billboard.cpp deleted file mode 100644 index 376d990b1..000000000 --- a/tests/Engine/Graphics/Billboard.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include - -SCENARIO("Billboard", "[GRAPHICS][BILLBOARD]") -{ - GIVEN("A default billboard") - { - Nz::Billboard billboard; - - WHEN("We assign it to another") - { - Nz::MaterialRef materialRef = Nz::Material::LoadFromFile("resources/Engine/Graphics/Nazara.png"); - Nz::Color materialColor = materialRef->GetDiffuseColor(); - Nz::BillboardRef otherBillboard = Nz::Billboard::New(materialRef); - - billboard = *otherBillboard; - - THEN("The old one has the same properties than the new one") - { - REQUIRE(billboard.GetColor() == materialColor); - REQUIRE(billboard.GetMaterial().Get() == materialRef.Get()); - REQUIRE(billboard.GetRotation().value == Approx(0.f)); - REQUIRE(billboard.GetSize() == Nz::Vector2f(64.f, 64.f)); // Default sizes - } - - THEN("We set it with our new material and ask for its real size") - { - billboard.SetMaterial(materialRef, true); - REQUIRE(billboard.GetSize() == Nz::Vector2f(765.f, 212.f)); // Nazara.png sizes - } - } - } -} diff --git a/tests/Engine/Graphics/ColorBackground.cpp b/tests/Engine/Graphics/ColorBackground.cpp deleted file mode 100644 index f4a88eb30..000000000 --- a/tests/Engine/Graphics/ColorBackground.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -SCENARIO("ColorBackground", "[GRAPHICS][COLORBACKGROUND]") -{ - GIVEN("A default color background") - { - Nz::ColorBackground colorBackground; - - WHEN("We assign it a color") - { - colorBackground.SetColor(Nz::Color::Red); - - THEN("We can get it") - { - REQUIRE(colorBackground.GetColor() == Nz::Color::Red); - } - } - } -} diff --git a/tests/Engine/Graphics/DeferredRenderTechnique.cpp b/tests/Engine/Graphics/DeferredRenderTechnique.cpp deleted file mode 100644 index f61c9800c..000000000 --- a/tests/Engine/Graphics/DeferredRenderTechnique.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -SCENARIO("DeferredRenderTechnique", "[GRAPHICS][DEFERREDRENDERTECHNIQUE]") -{ - GIVEN("A default deferred render technique") - { - Nz::DeferredRenderTechnique deferredRenderTechnique; - - WHEN("We can disable a pass") - { - REQUIRE(deferredRenderTechnique.IsPassEnabled(Nz::RenderPassType::RenderPassType_AA, 0)); - deferredRenderTechnique.EnablePass(Nz::RenderPassType::RenderPassType_AA, 0, false); - - THEN("It is disabled") - { - REQUIRE(!deferredRenderTechnique.IsPassEnabled(Nz::RenderPassType::RenderPassType_AA, 0)); - } - - AND_THEN("We reset it, it is disabled and not the same as the old one") - { - Nz::DeferredRenderPass* oldPass = deferredRenderTechnique.GetPass(Nz::RenderPassType::RenderPassType_AA, 0); - deferredRenderTechnique.ResetPass(Nz::RenderPassType::RenderPassType_AA, 0); - REQUIRE(!deferredRenderTechnique.IsPassEnabled(Nz::RenderPassType::RenderPassType_AA, 0)); - REQUIRE(deferredRenderTechnique.GetPass(Nz::RenderPassType::RenderPassType_AA, 0) != oldPass); - } - } - } -} diff --git a/tests/Engine/Graphics/Light.cpp b/tests/Engine/Graphics/Light.cpp deleted file mode 100644 index bd5f1c7f9..000000000 --- a/tests/Engine/Graphics/Light.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -SCENARIO("Light", "[GRAPHICS][LIGHT]") -{ - GIVEN("Different light") - { - Nz::Light directionalLight(Nz::LightType_Directional); - Nz::Light pointLight(Nz::LightType_Point); - Nz::Light spotLight(Nz::LightType_Spot); - - WHEN("We try to cull") - { - Nz::Frustumf frustum; - frustum.Build(90.f, 16.f / 9.f, 1.f, 1000.f, Nz::Vector3f::Zero(), Nz::Vector3f::UnitX()); - Nz::Matrix4f Unit3InX = Nz::Matrix4f::Translate(Nz::Vector3f::UnitX() * 3.f); - Nz::Matrix4f rotationTowardsY = Unit3InX * Nz::Matrix4f::Rotate(Nz::EulerAnglesf(Nz::FromDegrees(90.f), 0.f, 0.f).ToQuaternion()); - - THEN("These results are expected") - { - REQUIRE(directionalLight.Cull(frustum, Unit3InX)); - REQUIRE(pointLight.Cull(frustum, Unit3InX)); - REQUIRE(!spotLight.Cull(frustum, Unit3InX)); - - REQUIRE(directionalLight.Cull(frustum, rotationTowardsY)); - REQUIRE(pointLight.Cull(frustum, rotationTowardsY)); - REQUIRE(!spotLight.Cull(frustum, rotationTowardsY)); - } - } - } -} diff --git a/tests/Engine/Graphics/Model.cpp b/tests/Engine/Graphics/Model.cpp deleted file mode 100644 index 89c1988f0..000000000 --- a/tests/Engine/Graphics/Model.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -SCENARIO("Model", "[GRAPHICS][MODEL]") -{ - GIVEN("The standford dragon model") - { - WHEN("We get general informations") - { - THEN("These results are expected") - { - Nz::ModelParameters params; - params.mesh.optimizeIndexBuffers = false; - - Nz::ModelRef model = Nz::Model::LoadFromFile("resources/Engine/Graphics/dragon_recon/dragon_vrip_res4.obj", params); - REQUIRE(model); - - REQUIRE(model->GetMaterialCount() == 1); - REQUIRE(model->GetSkin() == 0); - REQUIRE(model->GetSkinCount() == 1); - - Nz::Material* material = model->GetMaterial(0); - REQUIRE(material->GetAmbientColor() == Nz::Color::Black); - } - } - } -} diff --git a/tests/Engine/Graphics/ParticleDeclaration.cpp b/tests/Engine/Graphics/ParticleDeclaration.cpp deleted file mode 100644 index 4cde9c5d2..000000000 --- a/tests/Engine/Graphics/ParticleDeclaration.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -SCENARIO("ParticleDeclaration", "[GRAPHICS][PARTICLEDECLARATION]") -{ - GIVEN("A particle declaration of a model") - { - Nz::ParticleDeclaration* particleDeclaration = Nz::ParticleDeclaration::Get(Nz::ParticleLayout_Model); - - WHEN("We disable a component") - { - bool enabled; - Nz::ComponentType type; - std::size_t offset; - particleDeclaration->GetComponent(Nz::ParticleComponent_Position, &enabled, &type, &offset); - REQUIRE(enabled); - std::size_t oldStride = particleDeclaration->GetStride(); - - particleDeclaration->DisableComponent(Nz::ParticleComponent_Position); - REQUIRE(oldStride != particleDeclaration->GetStride()); - - THEN("We can enable it and the stride is back") - { - particleDeclaration->EnableComponent(Nz::ParticleComponent_Position, type, offset); - REQUIRE(oldStride == particleDeclaration->GetStride()); - } - } - } -} diff --git a/tests/Engine/Graphics/ParticleGroup.cpp b/tests/Engine/Graphics/ParticleGroup.cpp deleted file mode 100644 index 361a5fba3..000000000 --- a/tests/Engine/Graphics/ParticleGroup.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include - -#include -#include - -class TestParticleController : public Nz::ParticleController -{ - public: - // Be aware that the interval is [startId, endId] and NOT [startId, endId) - void Apply(Nz::ParticleGroup& system, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) override - { - Nz::SparsePtr positionPtr = mapper.GetComponentPtr(Nz::ParticleComponent_Position); - Nz::SparsePtr velocityPtr = mapper.GetComponentPtr(Nz::ParticleComponent_Velocity); - Nz::SparsePtr lifePtr = mapper.GetComponentPtr(Nz::ParticleComponent_Life); - - for (unsigned int i = startId; i <= endId; ++i) - { - Nz::Vector3f& particlePosition = positionPtr[i]; - Nz::Vector3f& particleVelocity = velocityPtr[i]; - float& particleLife = lifePtr[i]; - - particleLife -= elapsedTime; - if (particleLife <= 0.f) - system.KillParticle(i); - } - } -}; - -class TestParticleEmitter : public Nz::ParticleEmitter -{ - public: - ~TestParticleEmitter() override = default; - - void Emit(Nz::ParticleGroup& system, float /*elapsedTime*/) const override - { - system.GenerateParticles(GetEmissionCount()); - } - - private: - void SetupParticles(Nz::ParticleMapper& /*mapper*/, unsigned int /*count*/) const override - { - } -}; - -class TestParticleGenerator : public Nz::ParticleGenerator -{ - public: - ~TestParticleGenerator() override = default; - - // Be aware that the interval is [startId, endId] and NOT [startId, endId) - void Generate(Nz::ParticleGroup& /*system*/, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId) override - { - Nz::SparsePtr positionPtr = mapper.GetComponentPtr(Nz::ParticleComponent_Position); - Nz::SparsePtr velocityPtr = mapper.GetComponentPtr(Nz::ParticleComponent_Velocity); - Nz::SparsePtr lifePtr = mapper.GetComponentPtr(Nz::ParticleComponent_Life); - - for (unsigned int i = startId; i <= endId; ++i) - { - Nz::Vector3f& particlePosition = positionPtr[i]; - Nz::Vector3f& particleVelocity = velocityPtr[i]; - float& particleLife = lifePtr[i]; - - particlePosition = Nz::Vector3f::Zero(); - particleVelocity = Nz::Vector3f::UnitX(); - particleLife = 1.3f; - } - } -}; - -SCENARIO("ParticleGroup", "[GRAPHICS][PARTICLEGROUP]") -{ - GIVEN("A particle system of maximum 10 billboards with its generators") - { - // These need to be alive longer than the particle system - TestParticleController particleController; - TestParticleGenerator particleGenerator; - Nz::ParticleGroup particleGroup(10, Nz::ParticleLayout_Billboard); - - particleGroup.AddController(&particleController); - TestParticleEmitter particleEmitter; - particleEmitter.SetEmissionCount(10); - particleGroup.AddEmitter(&particleEmitter); - - particleGroup.AddGenerator(&particleGenerator); - - WHEN("We update to generate 10 particles") - { - particleGroup.Update(1.f); - - THEN("There must be 10 particles") - { - REQUIRE(particleGroup.GetParticleCount() == 10); - } - - AND_THEN("We update to make them die") - { - particleGroup.Update(2.f); - REQUIRE(particleGroup.GetParticleCount() == 0); - } - } - } -} diff --git a/tests/Engine/Graphics/RenderTechniques.cpp b/tests/Engine/Graphics/RenderTechniques.cpp deleted file mode 100644 index ac5849da9..000000000 --- a/tests/Engine/Graphics/RenderTechniques.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include - -#include -#include - -SCENARIO("RenderTechniques", "[GRAPHICS][RENDERTECHNIQUES]") -{ - GIVEN("Nothing") - { - WHEN("We try to get a technique") - { - THEN("We should get it") - { - std::unique_ptr forwardByEnum(Nz::RenderTechniques::GetByEnum(Nz::RenderTechniqueType_BasicForward)); - REQUIRE(forwardByEnum->GetType() == Nz::RenderTechniqueType_BasicForward); - - std::unique_ptr forwardByIndex(Nz::RenderTechniques::GetByIndex(1)); - REQUIRE(forwardByIndex->GetType() == Nz::RenderTechniqueType_BasicForward); - - std::unique_ptr forwardByName(Nz::RenderTechniques::GetByName(Nz::RenderTechniques::ToString(Nz::RenderTechniqueType_BasicForward))); - REQUIRE(forwardByName->GetType() == Nz::RenderTechniqueType_BasicForward); - } - - THEN("We can register a render technique") - { - unsigned int previousCount = Nz::RenderTechniques::GetCount(); - - Nz::RenderTechniques::Register("test", 23, []() -> Nz::AbstractRenderTechnique* { - return new Nz::ForwardRenderTechnique; - }); - - REQUIRE(previousCount < Nz::RenderTechniques::GetCount()); - - std::unique_ptr forwardByRanking(Nz::RenderTechniques::GetByRanking(23)); - REQUIRE(forwardByRanking->GetType() == Nz::RenderTechniqueType_BasicForward); - - std::unique_ptr forwardByName(Nz::RenderTechniques::GetByName("test")); - REQUIRE(forwardByName->GetType() == Nz::RenderTechniqueType_BasicForward); - - Nz::RenderTechniques::Unregister("test"); - - REQUIRE(previousCount == Nz::RenderTechniques::GetCount()); - } - } - } -} \ No newline at end of file diff --git a/tests/Engine/Graphics/SkeletalModel.cpp b/tests/Engine/Graphics/SkeletalModel.cpp deleted file mode 100644 index 95d819c9a..000000000 --- a/tests/Engine/Graphics/SkeletalModel.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -SCENARIO("SkeletalModel", "[GRAPHICS][SKELETALMODEL]") -{ - GIVEN("A default skeletal model") - { - WHEN("We can load the bob lamp") - { - Nz::AnimationRef animation = Nz::Animation::LoadFromFile("resources/Engine/Graphics/Bob lamp/bob_lamp_update.md5anim"); - Nz::SkeletalModelRef skeletalModel = Nz::StaticRefCast(Nz::SkeletalModel::LoadFromFile("resources/Engine/Graphics/Bob lamp/bob_lamp_update.md5mesh")); - REQUIRE(skeletalModel); - REQUIRE(animation); - skeletalModel->SetAnimation(animation); - - THEN("We can enable its animation") - { - REQUIRE(skeletalModel->HasAnimation()); - skeletalModel->EnableAnimation(true); - skeletalModel->AdvanceAnimation(0.10f); - REQUIRE(skeletalModel->IsAnimationEnabled()); - } - } - } -} diff --git a/tests/Engine/Graphics/SkyboxBackground.cpp b/tests/Engine/Graphics/SkyboxBackground.cpp deleted file mode 100644 index c2b1910ab..000000000 --- a/tests/Engine/Graphics/SkyboxBackground.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include - -SCENARIO("SkyboxBackground", "[GRAPHICS][SKYBOXBACKGROUND]") -{ - GIVEN("A skybox background with a loaded image") - { - Nz::TextureRef textureRef = Nz::Texture::LoadCubemapFromFile("resources/Engine/Graphics/skybox.png"); - Nz::SkyboxBackgroundRef skyboxBackgroundRef = Nz::SkyboxBackground::New(textureRef); - - WHEN("We assign it parameters") - { - skyboxBackgroundRef->SetMovementOffset(Nz::Vector3f::Unit()); - skyboxBackgroundRef->SetMovementScale(1.f); - - THEN("We can get it") - { - REQUIRE(skyboxBackgroundRef->GetMovementOffset() == Nz::Vector3f::Unit()); - REQUIRE(skyboxBackgroundRef->GetMovementScale() == Approx(1.f)); - REQUIRE(skyboxBackgroundRef->GetTexture().Get() == textureRef.Get()); - } - } - } -} diff --git a/tests/Engine/Graphics/TextureBackground.cpp b/tests/Engine/Graphics/TextureBackground.cpp deleted file mode 100644 index ff89cc46f..000000000 --- a/tests/Engine/Graphics/TextureBackground.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -SCENARIO("TextureBackground", "[GRAPHICS][TEXTUREBACKGROUND]") -{ - GIVEN("A default texture background") - { - Nz::TextureRef textureRef = Nz::Texture::LoadFromFile("resources/Engine/Graphics/skybox.png"); - Nz::TextureBackgroundRef textureBackgroundRef = Nz::TextureBackground::New(textureRef); - - WHEN("We assign it parameters") - { - THEN("We can get it") - { - REQUIRE(textureBackgroundRef->GetTexture().Get() == textureRef.Get()); - } - } - } -} diff --git a/tests/Engine/Platform/EventHandler.cpp b/tests/Engine/Platform/EventHandler.cpp deleted file mode 100644 index c131386af..000000000 --- a/tests/Engine/Platform/EventHandler.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "EventHandler/StateContext.hpp" -#include "EventHandler/StateFactory.hpp" - -#include - -Ndk::EntityHandle AddCamera(Ndk::World& world, Nz::RenderWindow& window); - -/*! - Known issues on Linux: - - - There is no real double click event in X11 - - Should always the key be repeated in key pressed mode ? - - No smooth wheel, only 1.f or -1.f - - Modify dimension of window updates position (which is not wrong) - - Text entered is never repeated -*/ - -SCENARIO("EventHandler", "[PLATFORM][EVENTHANDLER][INTERACTIVE][.]") -{ - GIVEN("An application") - { - Ndk::Application& app = *Ndk::Application::Instance(); - auto& window = app.AddWindow(); - if (!window.Create(Nz::VideoMode(1024, 768, 32), "EventHandler")) - { - NazaraError("Failed to create window. See NazaraLog.log for further informations"); - REQUIRE(false); - } - window.EnableVerticalSync(true); - - auto& world = app.AddWorld(); - - auto camera = AddCamera(world, window); - - StateContext context(window, world); - - StateFactory::Initialize(context); - Ndk::StateMachine fsm(StateFactory::Get(EventStatus::Menu)); - - Nz::Clock elapsedTimeClock; - while (app.Run()) - { - window.Display(); - - float elapsedTime = elapsedTimeClock.Restart() / 1'000'000; - if (!fsm.Update(elapsedTime)) - { - NazaraError("Failed to update state machine."); - REQUIRE(false); - } - } - - StateFactory::Uninitialize(); - REQUIRE(true); - } -} - -Ndk::EntityHandle AddCamera(Ndk::World& world, Nz::RenderWindow& window) -{ - Ndk::EntityHandle view = world.CreateEntity(); - auto& node = view->AddComponent(); - node.SetPosition(Nz::Vector3f::Zero()); - auto& cam = view->AddComponent(); - cam.SetProjectionType(Nz::ProjectionType_Orthogonal); // 2D - cam.SetTarget(&window); - - world.GetSystem().SetGlobalUp(Nz::Vector3f::Down()); - world.GetSystem().SetDefaultBackground(Nz::ColorBackground::New(Nz::Color::Black)); - - return view; -} diff --git a/tests/Engine/Platform/EventHandler/BaseState.cpp b/tests/Engine/Platform/EventHandler/BaseState.cpp deleted file mode 100644 index eacd7c221..000000000 --- a/tests/Engine/Platform/EventHandler/BaseState.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "BaseState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -BaseState::BaseState(StateContext& context) : -State(), -m_context(context), -m_text(context) -{ -} - -BaseState::~BaseState() -{ -} - -void BaseState::Enter(Ndk::StateMachine& /*fsm*/) -{ - m_text.SetVisible(true); - DrawMenu(); -} - -void BaseState::Leave(Ndk::StateMachine& /*fsm*/) -{ - m_text.SetVisible(false); -} - -bool BaseState::Update(Ndk::StateMachine& /*fsm*/, float /*elapsedTime*/) -{ - return true; -} - -void BaseState::DrawMenu() -{ - m_text.SetContent("This shouldn't be visible\nM for Menu"); -} \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/BaseState.hpp b/tests/Engine/Platform/EventHandler/BaseState.hpp deleted file mode 100644 index 2fc721b9c..000000000 --- a/tests/Engine/Platform/EventHandler/BaseState.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef BASESTATE_HPP -#define BASESTATE_HPP - -#include "Text.hpp" - -#include - -#include - -class StateContext; - -class BaseState : public Ndk::State -{ - public: - BaseState(StateContext& stateContext); - virtual ~BaseState(); - - virtual void Enter(Ndk::StateMachine& fsm) override; - - virtual void Leave(Ndk::StateMachine& fsm) override; - - virtual bool Update(Ndk::StateMachine& fsm, float elapsedTime) override; - - protected: - virtual void DrawMenu(); - - StateContext& m_context; - Text m_text; -}; - -#endif // BASESTATE_HPP \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/EventState.cpp b/tests/Engine/Platform/EventHandler/EventState.cpp deleted file mode 100644 index a09ecee21..000000000 --- a/tests/Engine/Platform/EventHandler/EventState.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "EventState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -EventState::EventState(StateContext& context) : -BaseState(context), -m_count(0) -{ -} - -void EventState::Enter(Ndk::StateMachine& fsm) -{ - BaseState::Enter(fsm); - - Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) - { - fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); - } - }); - - m_eventSlot.Connect(eventHandler.OnEvent, [&] (const Nz::EventHandler*, const Nz::WindowEvent& event) - { - AddEvent(event); - ++m_count; - }); -} - -void EventState::AddEvent(const Nz::WindowEvent& event) -{ - if (m_events.size() > 9) - m_events.pop_front(); - - m_events.push_back(Nz::String::Number(m_count) + " - " + ToString(event)); - - Nz::String content; - for (auto&& currentEvent : m_events) - { - content += currentEvent + "\n"; - } - content += "\nM for Menu"; - m_text.SetContent(content, 36); -} - -void EventState::DrawMenu() -{ - m_text.SetContent("Do whathever you want, this text should change !\nM for Menu"); -} - -Nz::String EventState::ToString(const Nz::WindowEvent& event) const -{ - switch (event.type) - { - case Nz::WindowEventType_GainedFocus: - return "WindowEventType_GainedFocus"; - case Nz::WindowEventType_LostFocus: - return "WindowEventType_LostFocus"; - case Nz::WindowEventType_KeyPressed: - return "WindowEventType_KeyPressed"; - case Nz::WindowEventType_KeyReleased: - return "WindowEventType_KeyReleased"; - case Nz::WindowEventType_MouseButtonDoubleClicked: - return "WindowEventType_MouseButtonDoubleClicked"; - case Nz::WindowEventType_MouseButtonPressed: - return "WindowEventType_MouseButtonPressed"; - case Nz::WindowEventType_MouseButtonReleased: - return "WindowEventType_MouseButtonReleased"; - case Nz::WindowEventType_MouseEntered: - return "WindowEventType_MouseEntered"; - case Nz::WindowEventType_MouseLeft: - return "WindowEventType_MouseLeft"; - case Nz::WindowEventType_MouseMoved: - return "WindowEventType_MouseMoved"; - case Nz::WindowEventType_MouseWheelMoved: - return "WindowEventType_MouseWheelMoved"; - case Nz::WindowEventType_Moved: - return "WindowEventType_Moved"; - case Nz::WindowEventType_Quit: - return "WindowEventType_Quit"; - case Nz::WindowEventType_Resized: - return "WindowEventType_Resized"; - case Nz::WindowEventType_TextEntered: - return "WindowEventType_TextEntered"; - default: - return "Not handled"; - } -} diff --git a/tests/Engine/Platform/EventHandler/EventState.hpp b/tests/Engine/Platform/EventHandler/EventState.hpp deleted file mode 100644 index d22ebd4c4..000000000 --- a/tests/Engine/Platform/EventHandler/EventState.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __EVENTSTATE_HPP__ -#define __EVENTSTATE_HPP__ - -#include "BaseState.hpp" - -#include - -class StateContext; - -class EventState : public BaseState -{ - public: - EventState(StateContext& stateContext); - - void Enter(Ndk::StateMachine& fsm) override; - - private: - void AddEvent(const Nz::WindowEvent& event); - - void DrawMenu() override; - - Nz::String ToString(const Nz::WindowEvent& event) const; - - std::deque m_events; - int m_count; - NazaraSlot(Nz::EventHandler, OnEvent, m_eventSlot); - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); -}; - -#endif // __EVENTSTATE_HPP__ \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/FocusState.cpp b/tests/Engine/Platform/EventHandler/FocusState.cpp deleted file mode 100644 index a04f6ba56..000000000 --- a/tests/Engine/Platform/EventHandler/FocusState.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "FocusState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -FocusState::FocusState(StateContext& context) : -BaseState(context) -{ -} - -void FocusState::Enter(Ndk::StateMachine& fsm) -{ - BaseState::Enter(fsm); - - Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) - { - fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); - } - }); - - m_gainedFocusSlot.Connect(eventHandler.OnGainedFocus, [&] (const Nz::EventHandler*) - { - m_text.SetContent("GAINED\nM for Menu"); - }); - - m_lostFocusSlot.Connect(eventHandler.OnLostFocus, [&] (const Nz::EventHandler*) - { - m_text.SetContent("LOST\nM for Menu"); - }); -} - -void FocusState::DrawMenu() -{ - m_text.SetContent("Click outside the windows, this text should change !\nM for Menu"); -} diff --git a/tests/Engine/Platform/EventHandler/FocusState.hpp b/tests/Engine/Platform/EventHandler/FocusState.hpp deleted file mode 100644 index 359dceaa1..000000000 --- a/tests/Engine/Platform/EventHandler/FocusState.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __FOCUSSTATE_HPP__ -#define __FOCUSSTATE_HPP__ - -#include "BaseState.hpp" - -class StateContext; - -class FocusState : public BaseState -{ - public: - FocusState(StateContext& stateContext); - - void Enter(Ndk::StateMachine& fsm) override; - - private: - void DrawMenu() override; - - NazaraSlot(Nz::EventHandler, OnGainedFocus, m_gainedFocusSlot); - NazaraSlot(Nz::EventHandler, OnLostFocus, m_lostFocusSlot); - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); -}; - -#endif // __FOCUSSTATE_HPP__ \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/KeyState.cpp b/tests/Engine/Platform/EventHandler/KeyState.cpp deleted file mode 100644 index 3a3c4d894..000000000 --- a/tests/Engine/Platform/EventHandler/KeyState.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "KeyState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -KeyState::KeyState(StateContext& context) : -BaseState(context), -m_keyStatus(KeyStatus::Pressed) -{ -} - -void KeyState::Enter(Ndk::StateMachine& fsm) -{ - BaseState::Enter(fsm); - - Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - ManageInput(KeyStatus::Pressed, key, fsm); - }); - - m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - ManageInput(KeyStatus::Released, key, fsm); - }); -} - -void KeyState::DrawMenu() -{ - m_text.SetContent("Clic on a key, this text should change !\nN for alternating event\nM for Menu"); -} - -void KeyState::ManageInput(KeyStatus /*isKeyPressed*/, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm) -{ - if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) - fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); - else if (key.virtualKey == Nz::Keyboard::VKey::N && key.shift) - { - if (m_keyStatus == KeyStatus::Pressed) - m_keyStatus = KeyStatus::Released; - else - m_keyStatus = KeyStatus::Pressed; - } - else - { - Nz::String content; - if (m_keyStatus == KeyStatus::Pressed) - content = "Pressed: "; - else - content = "Released: "; - - Nz::String keyName = Nz::Keyboard::GetKeyName(key.virtualKey) + " (" + Nz::Keyboard::GetKeyName(key.scancode) + ")"; - if (keyName.IsEmpty()) - { - m_text.SetContent("Unknown\nM for Menu"); - } - else - { - content += keyName; - if (key.alt) - content += " alt"; - if (key.control) - content += " control"; - if (key.repeated) - content += " repeated"; - if (key.shift) - content += " shift"; - if (key.system) - content += " system"; - - m_text.SetContent(content + "\nM for Menu"); - } - } -} diff --git a/tests/Engine/Platform/EventHandler/KeyState.hpp b/tests/Engine/Platform/EventHandler/KeyState.hpp deleted file mode 100644 index 8e16c85f2..000000000 --- a/tests/Engine/Platform/EventHandler/KeyState.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __KEYSTATE_HPP__ -#define __KEYSTATE_HPP__ - -#include "BaseState.hpp" - -class StateContext; - -enum class KeyStatus -{ - Pressed, - Released -}; - -class KeyState : public BaseState -{ - public: - KeyState(StateContext& stateContext); - - void Enter(Ndk::StateMachine& fsm) override; - - private: - void DrawMenu() override; - - void ManageInput(KeyStatus isKeyPressed, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm); - - KeyStatus m_keyStatus; - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); - NazaraSlot(Nz::EventHandler, OnKeyReleased, m_keyReleasedSlot); -}; - -#endif // __KEYSTATE_HPP__ \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/MenuState.cpp b/tests/Engine/Platform/EventHandler/MenuState.cpp deleted file mode 100644 index aa7708edc..000000000 --- a/tests/Engine/Platform/EventHandler/MenuState.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "MenuState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -MenuState::MenuState(StateContext& context) : -BaseState(context), -m_selectedNextState(-1) -{ -} - -void MenuState::Enter(Ndk::StateMachine& fsm) -{ - BaseState::Enter(fsm); - - Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [this] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - if (key.virtualKey >= Nz::Keyboard::VKey::A && key.virtualKey < static_cast(static_cast(Nz::Keyboard::VKey::A) + static_cast(EventStatus::Max) - 1)) - { - m_selectedNextState = static_cast(key.virtualKey) - static_cast(Nz::Keyboard::VKey::A); - } - }); -} - -void MenuState::Leave(Ndk::StateMachine& fsm) -{ - BaseState::Leave(fsm); - m_selectedNextState = -1; -} - -bool MenuState::Update(Ndk::StateMachine& fsm, float /*elapsedTime*/) -{ - if (m_selectedNextState != -1) { - fsm.ChangeState(StateFactory::Get(m_selectedNextState + 1)); - } - - return true; -} - -void MenuState::DrawMenu() -{ - m_text.SetContent("a. Event\nb. Focus\nc. Key\nd. Mouse click\ne. Mouse enter\nf. Mouse move\ng. Text enter\nh. Window modification"); -} diff --git a/tests/Engine/Platform/EventHandler/MenuState.hpp b/tests/Engine/Platform/EventHandler/MenuState.hpp deleted file mode 100644 index 56c7d594c..000000000 --- a/tests/Engine/Platform/EventHandler/MenuState.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __MENUSTATE_HPP__ -#define __MENUSTATE_HPP__ - -#include "BaseState.hpp" - -class StateContext; - -class MenuState : public BaseState -{ - public: - MenuState(StateContext& stateContext); - - void Enter(Ndk::StateMachine& fsm) override; - - void Leave(Ndk::StateMachine& fsm) override; - - bool Update(Ndk::StateMachine& fsm, float elapsedTime) override; - - private: - void DrawMenu() override; - - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); - int m_selectedNextState; -}; - -#endif // __MENUSTATE_HPP__ diff --git a/tests/Engine/Platform/EventHandler/MouseClickState.cpp b/tests/Engine/Platform/EventHandler/MouseClickState.cpp deleted file mode 100644 index 09e9a9668..000000000 --- a/tests/Engine/Platform/EventHandler/MouseClickState.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "MouseClickState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -MouseClickState::MouseClickState(StateContext& context) : -BaseState(context) -{ -} - -void MouseClickState::Enter(Ndk::StateMachine& fsm) -{ - BaseState::Enter(fsm); - - Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) - { - fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); - } - }); - - m_mouseButtonDoubleClickedSlot.Connect(eventHandler.OnMouseButtonDoubleClicked, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& mouse) - { - ManageInput(MouseStatus::DoubleClick, mouse, fsm); - }); - - m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& mouse) - { - ManageInput(MouseStatus::Pressed, mouse, fsm); - }); - - m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& mouse) - { - ManageInput(MouseStatus::Released, mouse, fsm); - }); -} - -void MouseClickState::DrawMenu() -{ - m_text.SetContent("Click in the windows, this text should change !\nM for Menu"); -} - -void MouseClickState::ManageInput(MouseStatus mouseStatus, const Nz::WindowEvent::MouseButtonEvent& mouse, Ndk::StateMachine& /*fsm*/) -{ - Nz::String content; - if (mouseStatus == MouseStatus::Pressed) - content = "Pressed: "; - else if (mouseStatus == MouseStatus::Released) - content = "Released: "; - else - content = "Double clicked: "; - - switch (mouse.button) - { - case Nz::Mouse::Left: - content += "Left"; - break; - case Nz::Mouse::Middle: - content += "Middle"; - break; - case Nz::Mouse::Right: - content += "Right"; - break; - case Nz::Mouse::XButton1: - content += "XButton1"; - break; - case Nz::Mouse::XButton2: - content += "XButton2"; - break; - default: - content += "Unknown"; - break; - } - - m_text.SetContent(content + "\nM for Menu"); -} diff --git a/tests/Engine/Platform/EventHandler/MouseClickState.hpp b/tests/Engine/Platform/EventHandler/MouseClickState.hpp deleted file mode 100644 index 9a0e38077..000000000 --- a/tests/Engine/Platform/EventHandler/MouseClickState.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __MOUSECLICKSTATE_HPP__ -#define __MOUSECLICKSTATE_HPP__ - -#include "BaseState.hpp" - -class StateContext; - -enum class MouseStatus -{ - DoubleClick, - Pressed, - Released -}; - -class MouseClickState : public BaseState -{ - public: - MouseClickState(StateContext& stateContext); - - void Enter(Ndk::StateMachine& fsm) override; - - private: - void DrawMenu() override; - - void ManageInput(MouseStatus mouseStatus, const Nz::WindowEvent::MouseButtonEvent& mouse, Ndk::StateMachine& fsm); - - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); - NazaraSlot(Nz::EventHandler, OnMouseButtonDoubleClicked, m_mouseButtonDoubleClickedSlot); - NazaraSlot(Nz::EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot); - NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot); -}; - -#endif // __MOUSECLICKSTATE_HPP__ \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/MouseEnterState.cpp b/tests/Engine/Platform/EventHandler/MouseEnterState.cpp deleted file mode 100644 index 404499f6d..000000000 --- a/tests/Engine/Platform/EventHandler/MouseEnterState.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "MouseEnterState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -MouseEnterState::MouseEnterState(StateContext& context) : -BaseState(context) -{ -} - -void MouseEnterState::Enter(Ndk::StateMachine& fsm) -{ - BaseState::Enter(fsm); - - Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) - { - fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); - } - }); - - m_mouseEnteredSlot.Connect(eventHandler.OnMouseEntered, [&] (const Nz::EventHandler*) - { - m_text.SetContent("Entered\nM for Menu"); - }); - - m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, [&] (const Nz::EventHandler*) - { - m_text.SetContent("Left\nM for Menu"); - }); -} - -void MouseEnterState::DrawMenu() -{ - m_text.SetContent("Move your mouse outside the windows, this text should change !\nM for Menu"); -} diff --git a/tests/Engine/Platform/EventHandler/MouseEnterState.hpp b/tests/Engine/Platform/EventHandler/MouseEnterState.hpp deleted file mode 100644 index 2328149ea..000000000 --- a/tests/Engine/Platform/EventHandler/MouseEnterState.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __MOUSEENTERSTATE_HPP__ -#define __MOUSEENTERSTATE_HPP__ - -#include "BaseState.hpp" - -class StateContext; - -class MouseEnterState : public BaseState -{ - public: - MouseEnterState(StateContext& stateContext); - - void Enter(Ndk::StateMachine& fsm) override; - - private: - void DrawMenu() override; - - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); - NazaraSlot(Nz::EventHandler, OnMouseEntered, m_mouseEnteredSlot); - NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot); -}; - -#endif // __MOUSEENTERSTATE_HPP__ \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/MouseMoveState.cpp b/tests/Engine/Platform/EventHandler/MouseMoveState.cpp deleted file mode 100644 index 53f014ed5..000000000 --- a/tests/Engine/Platform/EventHandler/MouseMoveState.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "MouseMoveState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -MouseMoveState::MouseMoveState(StateContext& context) : -BaseState(context) -{ -} - -void MouseMoveState::Enter(Ndk::StateMachine& fsm) -{ - BaseState::Enter(fsm); - - Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) - { - fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); - } - }); - - m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseMoveEvent& event) - { - m_text.SetContent("Position(" + Nz::String::Number(event.x) + ", " + Nz::String::Number(event.y) + ") delta: (" + Nz::String::Number(event.deltaX) + ", " + Nz::String::Number(event.deltaY) + ") \nM for Menu"); - }); - - m_mouseWheelMovedSlot.Connect(eventHandler.OnMouseWheelMoved, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseWheelEvent& event) - { - m_text.SetContent("Wheel delta: " + Nz::String::Number(event.delta) + "\nM for Menu"); - }); -} - -void MouseMoveState::DrawMenu() -{ - m_text.SetContent("Move your mouse or your wheel, this text should change !\nM for Menu"); -} diff --git a/tests/Engine/Platform/EventHandler/MouseMoveState.hpp b/tests/Engine/Platform/EventHandler/MouseMoveState.hpp deleted file mode 100644 index 9aade79f8..000000000 --- a/tests/Engine/Platform/EventHandler/MouseMoveState.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __MOUSEMOVESTATE_HPP__ -#define __MOUSEMOVESTATE_HPP__ - -#include "BaseState.hpp" - -class StateContext; - -class MouseMoveState : public BaseState -{ - public: - MouseMoveState(StateContext& stateContext); - - void Enter(Ndk::StateMachine& fsm) override; - - private: - void DrawMenu() override; - - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); - NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot); - NazaraSlot(Nz::EventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot); -}; - -#endif // __MOUSEMOVESTATE_HPP__ \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/StateContext.cpp b/tests/Engine/Platform/EventHandler/StateContext.cpp deleted file mode 100644 index 69739a616..000000000 --- a/tests/Engine/Platform/EventHandler/StateContext.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "StateContext.hpp" - -StateContext::StateContext(Nz::RenderWindow& windowContext, Ndk::World& worldContext) : -window(windowContext), -world(worldContext) -{ -} diff --git a/tests/Engine/Platform/EventHandler/StateContext.hpp b/tests/Engine/Platform/EventHandler/StateContext.hpp deleted file mode 100644 index 62614e073..000000000 --- a/tests/Engine/Platform/EventHandler/StateContext.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __STATECONTEXT_HPP__ -#define __STATECONTEXT_HPP__ - -namespace Ndk -{ - class World; -} - -namespace Nz -{ - class RenderWindow; -} - -class StateContext -{ - public: - StateContext(Nz::RenderWindow& window, Ndk::World& world); - - Nz::RenderWindow& window; - Ndk::World& world; -}; - -#endif // __STATECONTEXT_HPP__ diff --git a/tests/Engine/Platform/EventHandler/StateFactory.cpp b/tests/Engine/Platform/EventHandler/StateFactory.cpp deleted file mode 100644 index 8086dea6b..000000000 --- a/tests/Engine/Platform/EventHandler/StateFactory.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "StateFactory.hpp" - -#include "MenuState.hpp" -#include "EventState.hpp" -#include "FocusState.hpp" -#include "KeyState.hpp" -#include "MouseClickState.hpp" -#include "MouseEnterState.hpp" -#include "MouseMoveState.hpp" -#include "TextEnterState.hpp" -#include "WindowModificationState.hpp" - -std::shared_ptr StateFactory::Get(EventStatus state) -{ - return s_states[state]; -} - -std::shared_ptr StateFactory::Get(unsigned int state) -{ - NazaraAssert(state < s_states.size(), "State out of range"); - auto it = s_states.begin(); - std::advance(it, state); - return it->second; -} - -bool StateFactory::Initialize(StateContext& context) -{ - s_states.emplace(std::make_pair(EventStatus::Menu, std::make_shared(context))); - s_states.emplace(std::make_pair(EventStatus::Event, std::make_shared(context))); - s_states.emplace(std::make_pair(EventStatus::Focus, std::make_shared(context))); - s_states.emplace(std::make_pair(EventStatus::Key, std::make_shared(context))); - s_states.emplace(std::make_pair(EventStatus::MouseClick, std::make_shared(context))); - s_states.emplace(std::make_pair(EventStatus::MouseEnter, std::make_shared(context))); - s_states.emplace(std::make_pair(EventStatus::MouseMove, std::make_shared(context))); - s_states.emplace(std::make_pair(EventStatus::TextEnter, std::make_shared(context))); - s_states.emplace(std::make_pair(EventStatus::WindowModification, std::make_shared(context))); - - return true; -} - -void StateFactory::Uninitialize() -{ - s_states.clear(); -} - -std::map> StateFactory::s_states; \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/StateFactory.hpp b/tests/Engine/Platform/EventHandler/StateFactory.hpp deleted file mode 100644 index 596934fbb..000000000 --- a/tests/Engine/Platform/EventHandler/StateFactory.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __STATEFACTORY_HPP__ -#define __STATEFACTORY_HPP__ - -#include - -#include -#include - -class StateContext; - -enum class EventStatus -{ - Min = 0, - Menu, - Event, - Focus, - Key, - MouseClick, - MouseEnter, - MouseMove, - TextEnter, - WindowModification, - Max = WindowModification -}; - -class StateFactory -{ - public: - - static std::shared_ptr Get(EventStatus state); - static std::shared_ptr Get(unsigned int state); - - static bool Initialize(StateContext& stateContext); - - static void Uninitialize(); - - private: - - static std::map> s_states; -}; - -#endif // __STATEFACTORY_HPP__ diff --git a/tests/Engine/Platform/EventHandler/Text.cpp b/tests/Engine/Platform/EventHandler/Text.cpp deleted file mode 100644 index 5aef2ceac..000000000 --- a/tests/Engine/Platform/EventHandler/Text.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "Text.hpp" - -#include -#include -#include -#include -#include -#include - -Text::Text(StateContext& stateContext) : -m_context(stateContext) -{ - m_text = m_context.world.CreateEntity(); - m_text->AddComponent(); - Ndk::GraphicsComponent& graphicsComponent = m_text->AddComponent(); - - m_textSprite = Nz::TextSprite::New(); - graphicsComponent.Attach(m_textSprite); -} - -Text::~Text() -{ - m_textSprite->Clear(); - m_text->Kill(); -} - -void Text::SetContent(const Nz::String& string, unsigned int size) -{ - m_textSprite->Update(Nz::SimpleTextDrawer::Draw(string, size)); -} - -void Text::SetVisible(bool shouldBeVisible) -{ - m_text->Enable(shouldBeVisible); -} \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/Text.hpp b/tests/Engine/Platform/EventHandler/Text.hpp deleted file mode 100644 index 7997759aa..000000000 --- a/tests/Engine/Platform/EventHandler/Text.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __TEXT_HPP__ -#define __TEXT_HPP__ - -#include -#include -#include "StateContext.hpp" - -class Text -{ - public: - Text(StateContext& context); - ~Text(); - - void SetContent(const Nz::String& string, unsigned int size = 36); - void SetVisible(bool shouldBeVisible = true); - - private: - StateContext& m_context; - Ndk::EntityHandle m_text; - Nz::TextSpriteRef m_textSprite; -}; - -#endif // __TEXT_HPP__ \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/TextEnterState.cpp b/tests/Engine/Platform/EventHandler/TextEnterState.cpp deleted file mode 100644 index ab8e2850e..000000000 --- a/tests/Engine/Platform/EventHandler/TextEnterState.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "TextEnterState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -TextEnterState::TextEnterState(StateContext& context) : -BaseState(context) -{ -} - -void TextEnterState::Enter(Ndk::StateMachine& fsm) -{ - BaseState::Enter(fsm); - - Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) - { - fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); - } - }); - - m_textEnteredSlot.Connect(eventHandler.OnTextEntered, [&] (const Nz::EventHandler*, const Nz::WindowEvent::TextEvent& event) - { - Nz::String content = "Character: " + Nz::String::Unicode(event.character); - if (event.repeated) - content += " repeated"; - m_text.SetContent(content + "\nM for Menu"); - }); -} - -void TextEnterState::DrawMenu() -{ - m_text.SetContent("Enter some text, this text should change !\nM for Menu"); -} diff --git a/tests/Engine/Platform/EventHandler/TextEnterState.hpp b/tests/Engine/Platform/EventHandler/TextEnterState.hpp deleted file mode 100644 index ed193d204..000000000 --- a/tests/Engine/Platform/EventHandler/TextEnterState.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __TEXTENTERSTATE_HPP__ -#define __TEXTENTERSTATE_HPP__ - -#include "BaseState.hpp" - -class StateContext; - -class TextEnterState : public BaseState -{ - public: - TextEnterState(StateContext& stateContext); - - void Enter(Ndk::StateMachine& fsm) override; - - private: - void DrawMenu() override; - - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); - NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot); -}; - -#endif // __TEXTENTERSTATE_HPP__ \ No newline at end of file diff --git a/tests/Engine/Platform/EventHandler/WindowModificationState.cpp b/tests/Engine/Platform/EventHandler/WindowModificationState.cpp deleted file mode 100644 index 994d824fd..000000000 --- a/tests/Engine/Platform/EventHandler/WindowModificationState.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "WindowModificationState.hpp" - -#include "StateContext.hpp" -#include "StateFactory.hpp" - -#include -#include - -WindowModificationState::WindowModificationState(StateContext& context) : -BaseState(context) -{ -} - -void WindowModificationState::Enter(Ndk::StateMachine& fsm) -{ - BaseState::Enter(fsm); - - Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); - m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) - { - if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) - { - fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); - } - }); - - m_movedSlot.Connect(eventHandler.OnMoved, [&] (const Nz::EventHandler*, const Nz::WindowEvent::PositionEvent& event) - { - m_text.SetContent("Position(" + Nz::String::Number(event.x) + ", " + Nz::String::Number(event.y) + ")\nM for Menu"); - }); - - m_resizedSlot.Connect(eventHandler.OnResized, [&] (const Nz::EventHandler*, const Nz::WindowEvent::SizeEvent& event) - { - m_text.SetContent("Size(" + Nz::String::Number(event.width) + ", " + Nz::String::Number(event.height) + ")\nM for Menu"); - }); -} - -void WindowModificationState::DrawMenu() -{ - m_text.SetContent("Move the window or resize it, this text should change !\nM for Menu"); -} diff --git a/tests/Engine/Platform/EventHandler/WindowModificationState.hpp b/tests/Engine/Platform/EventHandler/WindowModificationState.hpp deleted file mode 100644 index fce207039..000000000 --- a/tests/Engine/Platform/EventHandler/WindowModificationState.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __WINDOWMODIFICATIONSTATE_HPP__ -#define __WINDOWMODIFICATIONSTATE_HPP__ - -#include "BaseState.hpp" - -class StateContext; - -class WindowModificationState : public BaseState -{ - public: - WindowModificationState(StateContext& stateContext); - - void Enter(Ndk::StateMachine& fsm) override; - - private: - void DrawMenu() override; - - NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot); - NazaraSlot(Nz::EventHandler, OnMoved, m_movedSlot); - NazaraSlot(Nz::EventHandler, OnResized, m_resizedSlot); -}; - -#endif // __WINDOWMODIFICATIONSTATE_HPP__ \ No newline at end of file diff --git a/tests/SDK/NDK/Systems/RenderSystem.cpp b/tests/SDK/NDK/Systems/RenderSystem.cpp deleted file mode 100644 index 110b98299..000000000 --- a/tests/SDK/NDK/Systems/RenderSystem.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -void CompareAABB(const Nz::Rectf& aabb, const Nz::Boxf& box); - -SCENARIO("RenderSystem", "[NDK][RenderSystem]") -{ - GIVEN("A world with a camera, a drawable, a light and some particles") - { - Ndk::World world; - const Ndk::EntityHandle& cameraEntity = world.CreateEntity(); - Ndk::CameraComponent& cameraComponentCamera = cameraEntity->AddComponent(); - Ndk::NodeComponent& nodeComponentCamera = cameraEntity->AddComponent(); - - const Ndk::EntityHandle& drawableEntity = world.CreateEntity(); - Ndk::GraphicsComponent& graphicsComponentDrawable = drawableEntity->AddComponent(); - Nz::SpriteRef sprite = Nz::Sprite::New(); - graphicsComponentDrawable.Attach(sprite); - Ndk::NodeComponent& nodeComponentDrawable = drawableEntity->AddComponent(); - - const Ndk::EntityHandle& lightEntity = world.CreateEntity(); - Ndk::LightComponent& lightComponentLight = lightEntity->AddComponent(); - Ndk::NodeComponent& nodeComponentLight = lightEntity->AddComponent(); - - const Ndk::EntityHandle& particlesEntity = world.CreateEntity(); - Ndk::ParticleGroupComponent& particleGroupComponentParticles = particlesEntity->AddComponent(1, Nz::ParticleLayout_Sprite); - - WHEN("We change the render technique to ForwardRenderTechnique") - { - Ndk::RenderSystem& renderSystem = world.GetSystem(); - renderSystem.ChangeRenderTechnique(); - - THEN("The render system should be ForwardRenderTechnique") - { - REQUIRE(renderSystem.GetRenderTechnique().GetType() == Nz::RenderTechniqueType_BasicForward); - } - } - } - - GIVEN("A world with 2D coordinates (upper-left) and an entity with graphics and physics") - { - Ndk::World world; - world.GetSystem().SetGlobalUp(Nz::Vector3f::Down()); - const Ndk::EntityHandle& entity = world.CreateEntity(); - - Nz::Vector2f position(3.f, 4.f); - Ndk::NodeComponent& nodeComponent = entity->AddComponent(); - nodeComponent.SetPosition(position); - - Nz::Vector2f dimensions(1.f, 2.f); - Ndk::GraphicsComponent& graphicsComponent = entity->AddComponent(); - Nz::SpriteRef sprite = Nz::Sprite::New(); - sprite->SetSize(dimensions); - graphicsComponent.Attach(sprite); - - Nz::Rectf aabb(Nz::Vector2f::Zero(), dimensions); - Nz::BoxCollider2DRef boxCollider2D = Nz::BoxCollider2D::New(aabb); - entity->AddComponent(boxCollider2D); - Ndk::PhysicsComponent2D& physicsComponent2D = entity->AddComponent(); - - world.GetSystem().SetFixedUpdateRate(30.f); - world.Update(1.f); - - WHEN("We move it") - { - Nz::Vector2f velocity = Nz::Vector2f::UnitY(); - physicsComponent2D.SetVelocity(velocity); - world.Update(1.f); - - THEN("Graphics and physics should be synchronised") - { - CHECK(nodeComponent.GetPosition() == position + velocity); - CHECK(physicsComponent2D.GetAABB() == aabb.Translate(position + velocity)); - CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); - } - } - - WHEN("We set an angular velocity") - { - Nz::RadianAnglef angularSpeed = Nz::RadianAnglef::FromDegrees(90.f); - physicsComponent2D.SetAngularVelocity(angularSpeed); - world.Update(1.f); - - THEN("We expect those to be true") - { - CHECK(physicsComponent2D.GetAngularVelocity() == angularSpeed); - CHECK(physicsComponent2D.GetRotation() == angularSpeed); - CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(2.5f, 4.5f, 2.f, 1.f)); - CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); - - world.Update(1.f); - CHECK(physicsComponent2D.GetRotation() == 2.f * angularSpeed); - CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(3.f, 4.0f, 1.f, 2.f)); - CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); - - world.Update(1.f); - CHECK(physicsComponent2D.GetRotation() == 3.f * angularSpeed); - CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(2.5f, 4.5f, 2.f, 1.f)); - CompareAABB(physicsComponent2D.GetAABB(), graphicsComponent.GetAABB()); - - world.Update(1.f); - CHECK(physicsComponent2D.GetRotation() == 4.f * angularSpeed); - } - } - } -} - -void CompareAABB(const Nz::Rectf& aabb, const Nz::Boxf& box) -{ - CHECK(aabb.x == Approx(box.x)); - CHECK(aabb.y == Approx(box.y)); - CHECK(aabb.width == Approx(box.width)); - CHECK(aabb.height == Approx(box.height)); -}