From c1a87ed9469e64200f56d1304a1807fdb3714ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sun, 30 Jul 2023 20:30:06 +0200 Subject: [PATCH] Separated Assets to Resources (Engine assets) and Assets (Project specific) + AssetHierarchy: Exposed RootNode + ContentBrowserWindow: Fixed Empty Folder not being Leaf-Node + TreeNode: Added IsParentOf, IsChildOf and IsInSubtree. + Fixed InternalDeleteTreeAndChildren for null trees --- GlitchyEditor/BeefProj.toml | 2 +- .../Assets}/Models/plane.glb | Bin .../Assets}/Models/plane.glb.ass | 0 .../Assets}/Models/sphere.glb | Bin .../Assets}/Models/sphere.glb.ass | 0 .../Assets}/Scenes/Simple3D.scene | 0 .../Assets}/Scenes/childTest.scene | 0 .../Assets}/Scenes/physics2D.scene | 6 +- .../Assets}/Textures/DefaultNormal.png | Bin .../Assets}/Textures/DefaultNormal.png.ass | 0 .../Assets/Textures/RocketMaterial.mat | 31 ++ .../Assets}/Textures/RocketMaterial.mat.ass | 0 .../Assets}/Textures/TestMat/nrm.png | Bin .../Assets}/Textures/TestMat/nrm.png.ass | 0 .../Textures/TestMat/rustediron2_albedo.png | Bin .../TestMat/rustediron2_albedo.png.ass | 0 .../Textures/TestMat/rustediron2_metallic.png | Bin .../TestMat/rustediron2_metallic.png.ass | 0 .../Textures/TestMat/rustediron2_normal.png | Bin .../TestMat/rustediron2_normal.png.ass | 0 .../TestMat/rustediron2_roughness.png | Bin .../TestMat/rustediron2_roughness.png.ass | 0 .../Assets}/Textures/TestMaterial.mat | 12 +- .../Assets}/Textures/TestMaterial.mat.ass | 0 .../Assets}/Textures/White.png | Bin .../Assets}/Textures/White.png.ass | 0 .../Assets}/Textures/rocket.dds | Bin .../Assets}/Textures/rocket.dds.ass | 0 .../Assets}/Textures/rocket.png | Bin .../Assets}/Textures/rocket.png.ass | 0 .../Assets}/Textures/test_skybox.dds | Bin .../Assets}/Textures/test_skybox.dds.ass | 0 .../content/Textures/RocketMaterial.mat | 31 -- .../Fonts/CascadiaCode.ttf | Bin .../{content => resources}/Shaders/ACES.hlsl | 0 .../Shaders/ACES.hlsl.ass | 0 .../Shaders/ClearUInt.hlsl | 0 .../Shaders/ClearUInt.hlsl.ass | 0 .../Shaders/GammaCorrect.hlsl | 0 .../Shaders/GammaCorrect.hlsl.ass | 0 .../Shaders/GlitchyEngine.hlsl | 0 .../Shaders/GlitchyEngine.hlsl.ass | 0 .../Shaders/LightingFunctions.hlsl | 0 .../Shaders/LightingFunctions.hlsl.ass | 0 .../{content => resources}/Shaders/PBR.hlsl | 0 .../Shaders/PBR.hlsl.ass | 0 .../Shaders/RenderTargetGroupViewer.hlsl | 0 .../Shaders/RenderTargetGroupViewer.hlsl.ass | 0 .../Shaders/ShaderHelpers.hlsl | 0 .../Shaders/ShaderHelpers.hlsl.ass | 0 .../Shaders/SimpleTonemapping.hlsl | 0 .../Shaders/SimpleTonemapping.hlsl.ass | 0 .../Shaders/circlebatch.hlsl | 0 .../Shaders/circlebatch.hlsl.ass | 0 .../Shaders/lineShader.hlsl | 0 .../Shaders/lineShader.hlsl.ass | 0 .../Shaders/linebatch.hlsl | 0 .../Shaders/linebatch.hlsl.ass | 0 .../Shaders/msdfShader.hlsl | 0 .../Shaders/msdfShader.hlsl.ass | 0 .../Shaders/myEffect.hlsl | 0 .../Shaders/myEffect.hlsl.ass | 0 .../Shaders/simpleLight.hlsl | 0 .../Shaders/simpleLight.hlsl.ass | 0 .../Shaders/spritebatch.hlsl | 0 .../Shaders/spritebatch.hlsl.ass | 0 .../Shaders/textureViewerShader.hlsl | 0 .../Shaders/textureViewerShader.hlsl.ass | 0 .../Textures/EditorIcons.dds | Bin .../Textures/EditorIcons.dds.ass | 0 .../Textures/EditorIcons.psd | Bin GlitchyEditor/src/Assets/AssetHierarchy.bf | 280 ++++++++++++++---- GlitchyEditor/src/EditWindows/AssetViewer.bf | 4 +- .../src/EditWindows/ContentBrowserWindow.bf | 24 +- GlitchyEditor/src/EditorApp.bf | 2 +- GlitchyEditor/src/EditorContentManager.bf | 82 +++-- GlitchyEditor/src/EditorLayer.bf | 4 +- GlitchyEngine/src/Collections/TreeNode.bf | 31 ++ .../Platform/DX11/Renderer/Dx11RendererAPI.bf | 5 +- .../src/Platform/DX11/Renderer/Dx11Shader.bf | 4 +- GlitchyEngine/src/Renderer/Renderer.bf | 4 +- GlitchyEngine/src/Renderer/Renderer2D.bf | 109 +++---- .../src/Renderer/Text/FontRenderer.bf | 13 +- GlitchyEngine/src/World/SceneRenderer.bf | 4 +- Sandbox/src/TextureViewer.bf | 5 +- 85 files changed, 413 insertions(+), 240 deletions(-) rename GlitchyEditor/{content => SandboxProject/Assets}/Models/plane.glb (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Models/plane.glb.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Models/sphere.glb (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Models/sphere.glb.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Scenes/Simple3D.scene (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Scenes/childTest.scene (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Scenes/physics2D.scene (98%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/DefaultNormal.png (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/DefaultNormal.png.ass (100%) create mode 100644 GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/RocketMaterial.mat.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/nrm.png (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/nrm.png.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/rustediron2_albedo.png (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/rustediron2_albedo.png.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/rustediron2_metallic.png (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/rustediron2_metallic.png.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/rustediron2_normal.png (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/rustediron2_normal.png.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/rustediron2_roughness.png (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMat/rustediron2_roughness.png.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMaterial.mat (50%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/TestMaterial.mat.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/White.png (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/White.png.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/rocket.dds (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/rocket.dds.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/rocket.png (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/rocket.png.ass (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/test_skybox.dds (100%) rename GlitchyEditor/{content => SandboxProject/Assets}/Textures/test_skybox.dds.ass (100%) delete mode 100644 GlitchyEditor/content/Textures/RocketMaterial.mat rename GlitchyEditor/{content => resources}/Fonts/CascadiaCode.ttf (100%) rename GlitchyEditor/{content => resources}/Shaders/ACES.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/ACES.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/ClearUInt.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/ClearUInt.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/GammaCorrect.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/GammaCorrect.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/GlitchyEngine.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/GlitchyEngine.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/LightingFunctions.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/LightingFunctions.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/PBR.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/PBR.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/RenderTargetGroupViewer.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/RenderTargetGroupViewer.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/ShaderHelpers.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/ShaderHelpers.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/SimpleTonemapping.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/SimpleTonemapping.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/circlebatch.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/circlebatch.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/lineShader.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/lineShader.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/linebatch.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/linebatch.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/msdfShader.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/msdfShader.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/myEffect.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/myEffect.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/simpleLight.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/simpleLight.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/spritebatch.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/spritebatch.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Shaders/textureViewerShader.hlsl (100%) rename GlitchyEditor/{content => resources}/Shaders/textureViewerShader.hlsl.ass (100%) rename GlitchyEditor/{content => resources}/Textures/EditorIcons.dds (100%) rename GlitchyEditor/{content => resources}/Textures/EditorIcons.dds.ass (100%) rename GlitchyEditor/{content => resources}/Textures/EditorIcons.psd (100%) diff --git a/GlitchyEditor/BeefProj.toml b/GlitchyEditor/BeefProj.toml index 824a5be..8b6c0f8 100644 --- a/GlitchyEditor/BeefProj.toml +++ b/GlitchyEditor/BeefProj.toml @@ -7,4 +7,4 @@ TargetType = "BeefGUIApplication" StartupObject = "GlitchyEngine.Program" [Configs.Debug.Win64] -DebugCommandArguments = "\"content\\Scenes\\physics2D.scene\"" +DebugCommandArguments = "\"D:\\Development\\Projects\\Beef\\GlitchyEngine\\GlitchyEditor\\SandboxProject\"" diff --git a/GlitchyEditor/content/Models/plane.glb b/GlitchyEditor/SandboxProject/Assets/Models/plane.glb similarity index 100% rename from GlitchyEditor/content/Models/plane.glb rename to GlitchyEditor/SandboxProject/Assets/Models/plane.glb diff --git a/GlitchyEditor/content/Models/plane.glb.ass b/GlitchyEditor/SandboxProject/Assets/Models/plane.glb.ass similarity index 100% rename from GlitchyEditor/content/Models/plane.glb.ass rename to GlitchyEditor/SandboxProject/Assets/Models/plane.glb.ass diff --git a/GlitchyEditor/content/Models/sphere.glb b/GlitchyEditor/SandboxProject/Assets/Models/sphere.glb similarity index 100% rename from GlitchyEditor/content/Models/sphere.glb rename to GlitchyEditor/SandboxProject/Assets/Models/sphere.glb diff --git a/GlitchyEditor/content/Models/sphere.glb.ass b/GlitchyEditor/SandboxProject/Assets/Models/sphere.glb.ass similarity index 100% rename from GlitchyEditor/content/Models/sphere.glb.ass rename to GlitchyEditor/SandboxProject/Assets/Models/sphere.glb.ass diff --git a/GlitchyEditor/content/Scenes/Simple3D.scene b/GlitchyEditor/SandboxProject/Assets/Scenes/Simple3D.scene similarity index 100% rename from GlitchyEditor/content/Scenes/Simple3D.scene rename to GlitchyEditor/SandboxProject/Assets/Scenes/Simple3D.scene diff --git a/GlitchyEditor/content/Scenes/childTest.scene b/GlitchyEditor/SandboxProject/Assets/Scenes/childTest.scene similarity index 100% rename from GlitchyEditor/content/Scenes/childTest.scene rename to GlitchyEditor/SandboxProject/Assets/Scenes/childTest.scene diff --git a/GlitchyEditor/content/Scenes/physics2D.scene b/GlitchyEditor/SandboxProject/Assets/Scenes/physics2D.scene similarity index 98% rename from GlitchyEditor/content/Scenes/physics2D.scene rename to GlitchyEditor/SandboxProject/Assets/Scenes/physics2D.scene index e37e7d7..9492123 100644 --- a/GlitchyEditor/content/Scenes/physics2D.scene +++ b/GlitchyEditor/SandboxProject/Assets/Scenes/physics2D.scene @@ -13,7 +13,7 @@ B = 0.32878688, A = 1 }, - Sprite = "Textures/TestMat/rustediron2_albedo.png", + Sprite = "Assets/Textures/TestMat/rustediron2_albedo.png", UvTransform = { X = 0, Y = 0, @@ -309,10 +309,10 @@ } }, MeshComponent = { - Mesh = "Models/sphere.glb" + Mesh = "Assets/Models/sphere.glb" }, MeshRendererComponent = { - Material = "Textures/TestMaterial.mat" + Material = "Assets/Textures/TestMaterial.mat" } }, { diff --git a/GlitchyEditor/content/Textures/DefaultNormal.png b/GlitchyEditor/SandboxProject/Assets/Textures/DefaultNormal.png similarity index 100% rename from GlitchyEditor/content/Textures/DefaultNormal.png rename to GlitchyEditor/SandboxProject/Assets/Textures/DefaultNormal.png diff --git a/GlitchyEditor/content/Textures/DefaultNormal.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/DefaultNormal.png.ass similarity index 100% rename from GlitchyEditor/content/Textures/DefaultNormal.png.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/DefaultNormal.png.ass diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat b/GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat new file mode 100644 index 0000000..006d3ec --- /dev/null +++ b/GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat @@ -0,0 +1,31 @@ +{ + Effect = "Resources/Shaders/myEffect.hlsl", + Textures = [ + "AlbedoTexture": "Assets/Textures/rocket.png", + "NormalTexture": "Assets/Textures/TestMat/rustediron2_normal.png", + "MetallicTexture": "Assets/Textures/TestMat/rustediron2_metallic.png", + "RoughnessTexture": "Assets/Textures/TestMat/rustediron2_roughness.png" + ], + Variables = [ + "AlbedoColor": .ColorRGBA{ + Value = { + R = 1, + G = 1, + B = 1, + A = 1 + } + }, + "NormalScaling": .Float2{ + Value = { + X = 1, + Y = 1 + } + }, + "MetallicFactor": .Float{ + Value = 0 + }, + "RoughnessFactor": .Float{ + Value = 1 + } + ] +} \ No newline at end of file diff --git a/GlitchyEditor/content/Textures/RocketMaterial.mat.ass b/GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat.ass similarity index 100% rename from GlitchyEditor/content/Textures/RocketMaterial.mat.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat.ass diff --git a/GlitchyEditor/content/Textures/TestMat/nrm.png b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/nrm.png similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/nrm.png rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/nrm.png diff --git a/GlitchyEditor/content/Textures/TestMat/nrm.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/nrm.png.ass similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/nrm.png.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/nrm.png.ass diff --git a/GlitchyEditor/content/Textures/TestMat/rustediron2_albedo.png b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_albedo.png similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/rustediron2_albedo.png rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_albedo.png diff --git a/GlitchyEditor/content/Textures/TestMat/rustediron2_albedo.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_albedo.png.ass similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/rustediron2_albedo.png.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_albedo.png.ass diff --git a/GlitchyEditor/content/Textures/TestMat/rustediron2_metallic.png b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_metallic.png similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/rustediron2_metallic.png rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_metallic.png diff --git a/GlitchyEditor/content/Textures/TestMat/rustediron2_metallic.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_metallic.png.ass similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/rustediron2_metallic.png.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_metallic.png.ass diff --git a/GlitchyEditor/content/Textures/TestMat/rustediron2_normal.png b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_normal.png similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/rustediron2_normal.png rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_normal.png diff --git a/GlitchyEditor/content/Textures/TestMat/rustediron2_normal.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_normal.png.ass similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/rustediron2_normal.png.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_normal.png.ass diff --git a/GlitchyEditor/content/Textures/TestMat/rustediron2_roughness.png b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_roughness.png similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/rustediron2_roughness.png rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_roughness.png diff --git a/GlitchyEditor/content/Textures/TestMat/rustediron2_roughness.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_roughness.png.ass similarity index 100% rename from GlitchyEditor/content/Textures/TestMat/rustediron2_roughness.png.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_roughness.png.ass diff --git a/GlitchyEditor/content/Textures/TestMaterial.mat b/GlitchyEditor/SandboxProject/Assets/Textures/TestMaterial.mat similarity index 50% rename from GlitchyEditor/content/Textures/TestMaterial.mat rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMaterial.mat index 90ebaf9..a0c5ec1 100644 --- a/GlitchyEditor/content/Textures/TestMaterial.mat +++ b/GlitchyEditor/SandboxProject/Assets/Textures/TestMaterial.mat @@ -1,11 +1,11 @@ { - Effect = "Shaders/myEffect.hlsl", + Effect = "Resources/Shaders/myEffect.hlsl", Textures = [ - "AlbedoTexture": "Textures/TestMat/rustediron2_albedo.png", - "NormalTexture": "Textures/TestMat/rustediron2_normal.png", - "MetallicTexture": "Textures/TestMat/rustediron2_metallic.png", - "RoughnessTexture": "Textures/TestMat/rustediron2_roughness.png", - "EmissiveTexture": "Textures/rocket.png" + "AlbedoTexture": "Assets/Textures/TestMat/rustediron2_albedo.png", + "NormalTexture": "Assets/Textures/TestMat/rustediron2_normal.png", + "MetallicTexture": "Assets/Textures/TestMat/rustediron2_metallic.png", + "RoughnessTexture": "Assets/Textures/TestMat/rustediron2_roughness.png", + "EmissiveTexture": "Assets/Textures/rocket.png" ], Variables = [ "AlbedoColor": .ColorRGBA{ diff --git a/GlitchyEditor/content/Textures/TestMaterial.mat.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMaterial.mat.ass similarity index 100% rename from GlitchyEditor/content/Textures/TestMaterial.mat.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/TestMaterial.mat.ass diff --git a/GlitchyEditor/content/Textures/White.png b/GlitchyEditor/SandboxProject/Assets/Textures/White.png similarity index 100% rename from GlitchyEditor/content/Textures/White.png rename to GlitchyEditor/SandboxProject/Assets/Textures/White.png diff --git a/GlitchyEditor/content/Textures/White.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/White.png.ass similarity index 100% rename from GlitchyEditor/content/Textures/White.png.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/White.png.ass diff --git a/GlitchyEditor/content/Textures/rocket.dds b/GlitchyEditor/SandboxProject/Assets/Textures/rocket.dds similarity index 100% rename from GlitchyEditor/content/Textures/rocket.dds rename to GlitchyEditor/SandboxProject/Assets/Textures/rocket.dds diff --git a/GlitchyEditor/content/Textures/rocket.dds.ass b/GlitchyEditor/SandboxProject/Assets/Textures/rocket.dds.ass similarity index 100% rename from GlitchyEditor/content/Textures/rocket.dds.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/rocket.dds.ass diff --git a/GlitchyEditor/content/Textures/rocket.png b/GlitchyEditor/SandboxProject/Assets/Textures/rocket.png similarity index 100% rename from GlitchyEditor/content/Textures/rocket.png rename to GlitchyEditor/SandboxProject/Assets/Textures/rocket.png diff --git a/GlitchyEditor/content/Textures/rocket.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/rocket.png.ass similarity index 100% rename from GlitchyEditor/content/Textures/rocket.png.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/rocket.png.ass diff --git a/GlitchyEditor/content/Textures/test_skybox.dds b/GlitchyEditor/SandboxProject/Assets/Textures/test_skybox.dds similarity index 100% rename from GlitchyEditor/content/Textures/test_skybox.dds rename to GlitchyEditor/SandboxProject/Assets/Textures/test_skybox.dds diff --git a/GlitchyEditor/content/Textures/test_skybox.dds.ass b/GlitchyEditor/SandboxProject/Assets/Textures/test_skybox.dds.ass similarity index 100% rename from GlitchyEditor/content/Textures/test_skybox.dds.ass rename to GlitchyEditor/SandboxProject/Assets/Textures/test_skybox.dds.ass diff --git a/GlitchyEditor/content/Textures/RocketMaterial.mat b/GlitchyEditor/content/Textures/RocketMaterial.mat deleted file mode 100644 index 52eb50f..0000000 --- a/GlitchyEditor/content/Textures/RocketMaterial.mat +++ /dev/null @@ -1,31 +0,0 @@ -{ - Effect = "Shaders/myEffect.hlsl", - Textures = [ - "AlbedoTexture": "Textures/rocket.png", - "NormalTexture": "Textures/TestMat/rustediron2_normal.png", - "MetallicTexture": "Textures/TestMat/rustediron2_metallic.png", - "RoughnessTexture": "Textures/TestMat/rustediron2_roughness.png" - ], - Variables = [ - "AlbedoColor": .ColorRGBA{ - Value = { - R = 1, - G = 1, - B = 1, - A = 1 - } - }, - "NormalScaling": .Float2{ - Value = { - X = 1, - Y = 1 - } - }, - "MetallicFactor": .Float{ - Value = 0 - }, - "RoughnessFactor": .Float{ - Value = 1 - } - ] -} \ No newline at end of file diff --git a/GlitchyEditor/content/Fonts/CascadiaCode.ttf b/GlitchyEditor/resources/Fonts/CascadiaCode.ttf similarity index 100% rename from GlitchyEditor/content/Fonts/CascadiaCode.ttf rename to GlitchyEditor/resources/Fonts/CascadiaCode.ttf diff --git a/GlitchyEditor/content/Shaders/ACES.hlsl b/GlitchyEditor/resources/Shaders/ACES.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/ACES.hlsl rename to GlitchyEditor/resources/Shaders/ACES.hlsl diff --git a/GlitchyEditor/content/Shaders/ACES.hlsl.ass b/GlitchyEditor/resources/Shaders/ACES.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/ACES.hlsl.ass rename to GlitchyEditor/resources/Shaders/ACES.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/ClearUInt.hlsl b/GlitchyEditor/resources/Shaders/ClearUInt.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/ClearUInt.hlsl rename to GlitchyEditor/resources/Shaders/ClearUInt.hlsl diff --git a/GlitchyEditor/content/Shaders/ClearUInt.hlsl.ass b/GlitchyEditor/resources/Shaders/ClearUInt.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/ClearUInt.hlsl.ass rename to GlitchyEditor/resources/Shaders/ClearUInt.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/GammaCorrect.hlsl b/GlitchyEditor/resources/Shaders/GammaCorrect.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/GammaCorrect.hlsl rename to GlitchyEditor/resources/Shaders/GammaCorrect.hlsl diff --git a/GlitchyEditor/content/Shaders/GammaCorrect.hlsl.ass b/GlitchyEditor/resources/Shaders/GammaCorrect.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/GammaCorrect.hlsl.ass rename to GlitchyEditor/resources/Shaders/GammaCorrect.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/GlitchyEngine.hlsl b/GlitchyEditor/resources/Shaders/GlitchyEngine.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/GlitchyEngine.hlsl rename to GlitchyEditor/resources/Shaders/GlitchyEngine.hlsl diff --git a/GlitchyEditor/content/Shaders/GlitchyEngine.hlsl.ass b/GlitchyEditor/resources/Shaders/GlitchyEngine.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/GlitchyEngine.hlsl.ass rename to GlitchyEditor/resources/Shaders/GlitchyEngine.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/LightingFunctions.hlsl b/GlitchyEditor/resources/Shaders/LightingFunctions.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/LightingFunctions.hlsl rename to GlitchyEditor/resources/Shaders/LightingFunctions.hlsl diff --git a/GlitchyEditor/content/Shaders/LightingFunctions.hlsl.ass b/GlitchyEditor/resources/Shaders/LightingFunctions.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/LightingFunctions.hlsl.ass rename to GlitchyEditor/resources/Shaders/LightingFunctions.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/PBR.hlsl b/GlitchyEditor/resources/Shaders/PBR.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/PBR.hlsl rename to GlitchyEditor/resources/Shaders/PBR.hlsl diff --git a/GlitchyEditor/content/Shaders/PBR.hlsl.ass b/GlitchyEditor/resources/Shaders/PBR.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/PBR.hlsl.ass rename to GlitchyEditor/resources/Shaders/PBR.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/RenderTargetGroupViewer.hlsl b/GlitchyEditor/resources/Shaders/RenderTargetGroupViewer.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/RenderTargetGroupViewer.hlsl rename to GlitchyEditor/resources/Shaders/RenderTargetGroupViewer.hlsl diff --git a/GlitchyEditor/content/Shaders/RenderTargetGroupViewer.hlsl.ass b/GlitchyEditor/resources/Shaders/RenderTargetGroupViewer.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/RenderTargetGroupViewer.hlsl.ass rename to GlitchyEditor/resources/Shaders/RenderTargetGroupViewer.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/ShaderHelpers.hlsl b/GlitchyEditor/resources/Shaders/ShaderHelpers.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/ShaderHelpers.hlsl rename to GlitchyEditor/resources/Shaders/ShaderHelpers.hlsl diff --git a/GlitchyEditor/content/Shaders/ShaderHelpers.hlsl.ass b/GlitchyEditor/resources/Shaders/ShaderHelpers.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/ShaderHelpers.hlsl.ass rename to GlitchyEditor/resources/Shaders/ShaderHelpers.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/SimpleTonemapping.hlsl b/GlitchyEditor/resources/Shaders/SimpleTonemapping.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/SimpleTonemapping.hlsl rename to GlitchyEditor/resources/Shaders/SimpleTonemapping.hlsl diff --git a/GlitchyEditor/content/Shaders/SimpleTonemapping.hlsl.ass b/GlitchyEditor/resources/Shaders/SimpleTonemapping.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/SimpleTonemapping.hlsl.ass rename to GlitchyEditor/resources/Shaders/SimpleTonemapping.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/circlebatch.hlsl b/GlitchyEditor/resources/Shaders/circlebatch.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/circlebatch.hlsl rename to GlitchyEditor/resources/Shaders/circlebatch.hlsl diff --git a/GlitchyEditor/content/Shaders/circlebatch.hlsl.ass b/GlitchyEditor/resources/Shaders/circlebatch.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/circlebatch.hlsl.ass rename to GlitchyEditor/resources/Shaders/circlebatch.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/lineShader.hlsl b/GlitchyEditor/resources/Shaders/lineShader.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/lineShader.hlsl rename to GlitchyEditor/resources/Shaders/lineShader.hlsl diff --git a/GlitchyEditor/content/Shaders/lineShader.hlsl.ass b/GlitchyEditor/resources/Shaders/lineShader.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/lineShader.hlsl.ass rename to GlitchyEditor/resources/Shaders/lineShader.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/linebatch.hlsl b/GlitchyEditor/resources/Shaders/linebatch.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/linebatch.hlsl rename to GlitchyEditor/resources/Shaders/linebatch.hlsl diff --git a/GlitchyEditor/content/Shaders/linebatch.hlsl.ass b/GlitchyEditor/resources/Shaders/linebatch.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/linebatch.hlsl.ass rename to GlitchyEditor/resources/Shaders/linebatch.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/msdfShader.hlsl b/GlitchyEditor/resources/Shaders/msdfShader.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/msdfShader.hlsl rename to GlitchyEditor/resources/Shaders/msdfShader.hlsl diff --git a/GlitchyEditor/content/Shaders/msdfShader.hlsl.ass b/GlitchyEditor/resources/Shaders/msdfShader.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/msdfShader.hlsl.ass rename to GlitchyEditor/resources/Shaders/msdfShader.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/myEffect.hlsl b/GlitchyEditor/resources/Shaders/myEffect.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/myEffect.hlsl rename to GlitchyEditor/resources/Shaders/myEffect.hlsl diff --git a/GlitchyEditor/content/Shaders/myEffect.hlsl.ass b/GlitchyEditor/resources/Shaders/myEffect.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/myEffect.hlsl.ass rename to GlitchyEditor/resources/Shaders/myEffect.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/simpleLight.hlsl b/GlitchyEditor/resources/Shaders/simpleLight.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/simpleLight.hlsl rename to GlitchyEditor/resources/Shaders/simpleLight.hlsl diff --git a/GlitchyEditor/content/Shaders/simpleLight.hlsl.ass b/GlitchyEditor/resources/Shaders/simpleLight.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/simpleLight.hlsl.ass rename to GlitchyEditor/resources/Shaders/simpleLight.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/spritebatch.hlsl b/GlitchyEditor/resources/Shaders/spritebatch.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/spritebatch.hlsl rename to GlitchyEditor/resources/Shaders/spritebatch.hlsl diff --git a/GlitchyEditor/content/Shaders/spritebatch.hlsl.ass b/GlitchyEditor/resources/Shaders/spritebatch.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/spritebatch.hlsl.ass rename to GlitchyEditor/resources/Shaders/spritebatch.hlsl.ass diff --git a/GlitchyEditor/content/Shaders/textureViewerShader.hlsl b/GlitchyEditor/resources/Shaders/textureViewerShader.hlsl similarity index 100% rename from GlitchyEditor/content/Shaders/textureViewerShader.hlsl rename to GlitchyEditor/resources/Shaders/textureViewerShader.hlsl diff --git a/GlitchyEditor/content/Shaders/textureViewerShader.hlsl.ass b/GlitchyEditor/resources/Shaders/textureViewerShader.hlsl.ass similarity index 100% rename from GlitchyEditor/content/Shaders/textureViewerShader.hlsl.ass rename to GlitchyEditor/resources/Shaders/textureViewerShader.hlsl.ass diff --git a/GlitchyEditor/content/Textures/EditorIcons.dds b/GlitchyEditor/resources/Textures/EditorIcons.dds similarity index 100% rename from GlitchyEditor/content/Textures/EditorIcons.dds rename to GlitchyEditor/resources/Textures/EditorIcons.dds diff --git a/GlitchyEditor/content/Textures/EditorIcons.dds.ass b/GlitchyEditor/resources/Textures/EditorIcons.dds.ass similarity index 100% rename from GlitchyEditor/content/Textures/EditorIcons.dds.ass rename to GlitchyEditor/resources/Textures/EditorIcons.dds.ass diff --git a/GlitchyEditor/content/Textures/EditorIcons.psd b/GlitchyEditor/resources/Textures/EditorIcons.psd similarity index 100% rename from GlitchyEditor/content/Textures/EditorIcons.psd rename to GlitchyEditor/resources/Textures/EditorIcons.psd diff --git a/GlitchyEditor/src/Assets/AssetHierarchy.bf b/GlitchyEditor/src/Assets/AssetHierarchy.bf index da8b003..a2020f9 100644 --- a/GlitchyEditor/src/Assets/AssetHierarchy.bf +++ b/GlitchyEditor/src/Assets/AssetHierarchy.bf @@ -12,6 +12,7 @@ public class AssetNode { public String Name ~ delete _; public String Path ~ delete _; + public String Identifier ~ delete _; public bool IsDirectory; @@ -38,14 +39,43 @@ public static class AssetIdentifier { public const char8 DirectorySeparatorChar = '/'; + // TODO: Asset identifiers and paths have little to do with each other and already caused a bit of pain, we should consider not using String for both. + /// Removes or unifies potential platform specific or file-path related stuff in the given asset identifier public static void Fixup(String assetIdentifier) { - const String DotSeperator = $".{DirectorySeparatorChar}"; - const String SeperatorDot = $"{DirectorySeparatorChar}."; + int dotIndex = 0; assetIdentifier.Replace('\\', DirectorySeparatorChar); - assetIdentifier.Replace(DotSeperator, ""); - assetIdentifier.Replace(SeperatorDot, ""); + + // Replace /./ stuff + while ((dotIndex = assetIdentifier.IndexOf('.', dotIndex)) != -1) + { + char8 lastChar = '\0'; + char8 nextChar = '\0'; + + int nextIndex = dotIndex + 1; + if (nextIndex < assetIdentifier.Length) + nextChar = assetIdentifier[nextIndex]; + + int lastIndex = dotIndex - 1; + if (lastIndex < assetIdentifier.Length) + lastChar = assetIdentifier[nextIndex]; + + // We either need to have a slash on both sides, or we have to be at the start or end of the string + if ((lastChar == '\0' || lastChar == DirectorySeparatorChar) && + (lastChar == '\0' || lastChar == DirectorySeparatorChar)) + { + if (lastChar != '\0') + assetIdentifier.Remove(lastIndex, 2); + else + assetIdentifier.Remove(dotIndex, 2); + } + else + { + // Skip the dot + dotIndex++; + } + } if (assetIdentifier.StartsWith(DirectorySeparatorChar)) assetIdentifier.Remove(0, 1); @@ -61,32 +91,119 @@ class AssetHierarchy bool _fileSystemDirty = false; - internal TreeNode _assetHierarchy = null ~ DeleteTreeAndChildren!(_); + internal TreeNode _assetRootNode = null ~ DeleteTreeAndChildren!(_); + internal TreeNode _resourcesDirectoryNode = null; + internal TreeNode _assetsDirectoryNode = null; private append Dictionary> _pathToAssetNode = .(); + private append Dictionary> _identifierToAssetNode = .(); - private append String _contentDirectory = .(); + private append String _resourcesDirectory = .(); + private append String _assetsDirectory = .(); private EditorContentManager _contentManager; - public StringView ContentDirectory + public TreeNode RootNode => _assetRootNode; + + public StringView ResourcesDirectory { - get => _contentDirectory; + get => _resourcesDirectory; private set { - _contentDirectory.Clear(); - _contentDirectory.Append(value); - Path.Fixup(_contentDirectory); + _resourcesDirectory.Set(value); + Path.Fixup(_resourcesDirectory); + } + } + + public StringView AssetsDirectory + { + get => _assetsDirectory; + private set + { + _assetsDirectory.Set(value); + Path.Fixup(_assetsDirectory); } } public this(EditorContentManager contentManager) { _contentManager = contentManager; + + // Create a root node that will contain all Asset directory nodes. + _assetRootNode = new TreeNode(new AssetNode()); + _assetRootNode->Path = new String(); + _assetRootNode->Name = new String(); + _assetRootNode->IsDirectory = true; + + Log.EngineLogger.Trace($"Created root node"); } - public void SetContentDirectory(StringView contentDirectory) + public void SetResourcesDirectory(StringView fileName) { - ContentDirectory = contentDirectory; + ResourcesDirectory = fileName; + + _resourcesDirectoryNode?.ForEach(scope (node) => { + _pathToAssetNode.Remove(node->Path); + _identifierToAssetNode.Remove(node->Identifier); + }); + DeleteTreeAndChildren!(_resourcesDirectoryNode); + + if (!Directory.Exists(ResourcesDirectory)) + { + Log.EngineLogger.Error($"Resources directory \"{ResourcesDirectory}\" doesn't exist."); + return; + } + + AssetNode assetNode = new AssetNode(); + assetNode.Path = new String(ResourcesDirectory); + assetNode.Name = new String(); + assetNode.Identifier = new String("###resources"); + assetNode.IsDirectory = true; + Path.GetFileName(assetNode.Path, assetNode.Name); + + _resourcesDirectoryNode = _assetRootNode.AddChild(assetNode); + _pathToAssetNode.Add(assetNode.Path, _resourcesDirectoryNode); + _identifierToAssetNode.Add(assetNode.Identifier, _resourcesDirectoryNode); + + Log.EngineLogger.Trace($"Created directory node for: \"{ResourcesDirectory}\""); + + _fileSystemDirty = true; + + // TODO: Watch resources folder? + //SetupResourcesFileSystemWatcher(); + + Update(); + } + + public void SetAssetsDirectory(StringView fileName) + { + AssetsDirectory = fileName; + + _assetsDirectoryNode?.ForEach(scope (node) => { + _pathToAssetNode.Remove(node->Path); + _identifierToAssetNode.Remove(node->Identifier); + }); + DeleteTreeAndChildren!(_assetsDirectoryNode); + + if (!Directory.Exists(AssetsDirectory)) + { + // TODO: This is not an error, if no project is loaded + Log.EngineLogger.Warning($"Assets directory \"{AssetsDirectory}\" doesn't exist."); + return; + } + + AssetNode assetNode = new AssetNode(); + assetNode.Path = new String(AssetsDirectory); + assetNode.Name = new String(); + assetNode.Identifier = new String("###assets"); + assetNode.IsDirectory = true; + Path.GetFileName(assetNode.Path, assetNode.Name); + + _assetsDirectoryNode = _assetRootNode.AddChild(assetNode); + _pathToAssetNode.Add(assetNode.Path, _assetsDirectoryNode); + _identifierToAssetNode.Add(assetNode.Identifier, _assetsDirectoryNode); + + Log.EngineLogger.Trace($"Created directory node for: \"{AssetsDirectory}\""); + _fileSystemDirty = true; @@ -99,7 +216,7 @@ class AssetHierarchy private void SetupFileSystemWatcher() { delete fsw; - fsw = new FileSystemWatcher(_contentDirectory); + fsw = new FileSystemWatcher(_assetsDirectory); fsw.IncludeSubdirectories = true; fsw.OnChanged.Add(new (filename) => { @@ -153,6 +270,19 @@ class AssetHierarchy return .Err; } + /// Gets the tree node for the given filePath or .Err, if the file/directory doesn't exist. + /// @param filePath the path for which to return the tree node. + /// @remarks Do not hold a reference to the TreeNode because it can become invalid when the file hierarchy changes. + public Result> GetNodeFromIdentifier(StringView identifier) + { + if (_identifierToAssetNode.TryGetValue(identifier, let treeNode)) + { + return treeNode; + } + + return .Err; + } + public bool FileExists(StringView filePath) { return _pathToAssetNode.ContainsKey(filePath); @@ -173,27 +303,9 @@ class AssetHierarchy { Log.EngineLogger.Trace($"Updating asset hierarchy"); - if (_assetHierarchy == null) - { - // TODO: move to init? - - _assetHierarchy = new TreeNode(new AssetNode()); - _assetHierarchy->Path = new String(ContentDirectory); - _assetHierarchy->Name = new String("Content"); - _assetHierarchy->IsDirectory = true; - - Log.EngineLogger.Trace($"Created directory node for: \"{_assetHierarchy->Path}\""); - - _pathToAssetNode.Add(ContentDirectory, _assetHierarchy); - } - void HandleFile(AssetNode node) { - String identifier = scope .(node.Path.Length); - Path.GetRelativePath(node.Path, _contentDirectory, identifier); - AssetIdentifier.Fixup(identifier); - - node.AssetFile = new AssetFile(_contentManager, identifier, node.Path, node.IsDirectory); + node.AssetFile = new AssetFile(_contentManager, node.Identifier, node.Path, node.IsDirectory); } /// Determines the files that belong to the given directory and adds them to the tree. @@ -229,9 +341,12 @@ class AssetHierarchy assetNode.Path = new String(filepathBuffer); assetNode.IsDirectory = false; + + DetermineIdentifier(assetNode, directory); treeNode = directory.AddChild(assetNode); _pathToAssetNode.Add(assetNode.Path, treeNode); + _identifierToAssetNode.Add(assetNode.Identifier, treeNode); //GrabSubAssets(node); HandleFile(treeNode.Value); @@ -243,17 +358,6 @@ class AssetHierarchy void RemoveOrphanedEntries(TreeNode node) { - /// Removes the node and its children from _pathToAssetNode - void RemoveSubtree(TreeNode tree) - { - _pathToAssetNode.Remove(tree->Path); - - for (var child in tree.Children) - { - RemoveSubtree(child); - } - } - for (TreeNode child in node.Children) { if (!Directory.Exists(child->Path) && !File.Exists(child->Path)) @@ -262,13 +366,37 @@ class AssetHierarchy @child.Remove(); - RemoveSubtree(child); + child.ForEach(scope (node) => { + _pathToAssetNode.Remove(node->Path); + _identifierToAssetNode.Remove(node->Identifier); + }); DeleteTreeAndChildren!(child); } } } - + + void DetermineIdentifier(AssetNode assetNode, TreeNode parentNode) + { + if (assetNode.Identifier == null) + assetNode.Identifier = new String(); + + assetNode.Identifier.Clear(); + + // Get the Identifier which is simply the path relative to the asste root (either Resources- or Assets-Folder) + if (parentNode.IsInSubtree(_resourcesDirectoryNode)) + { + Path.GetRelativePath(assetNode.Path, _resourcesDirectoryNode->Path, assetNode.Identifier); + assetNode.Identifier.Insert(0, "Resources/"); + } + else if (parentNode.IsInSubtree(_assetsDirectoryNode)) + { + Path.GetRelativePath(assetNode.Path, _assetsDirectoryNode->Path, assetNode.Identifier); + assetNode.Identifier.Insert(0, "Assets/"); + } + AssetIdentifier.Fixup(assetNode.Identifier); + } + /// Adds the given directory to the specified tree. /// Recursively adds all Files and Subdirectories. void AddDirectoryToTree(String path, TreeNode parentNode) @@ -284,11 +412,29 @@ class AssetHierarchy AssetNode assetNode = new AssetNode(); assetNode.Path = new String(path); assetNode.Name = new String(); + //assetNode.Identifier = new String(); assetNode.IsDirectory = true; Path.GetFileName(assetNode.Path, assetNode.Name); + DetermineIdentifier(assetNode, parentNode); + + /*// Get the Identifier which is simply the path relative to the asste root (either Resources- or Assets-Folder) + if (parentNode == _resourcesDirectoryNode || parentNode.IsChildOf(_resourcesDirectoryNode)) + { + Path.GetRelativePath(assetNode.Path, _resourcesDirectoryNode->Path, assetNode.Identifier); + assetNode.Identifier.Insert(0, "Resources/"); + } + else + { + Path.GetRelativePath(assetNode.Path, _assetsDirectoryNode->Path, assetNode.Identifier); + assetNode.Identifier.Insert(0, "Assets/"); + } + AssetIdentifier.Fixup(assetNode.Identifier);*/ + treeNode = parentNode.AddChild(assetNode); _pathToAssetNode.Add(assetNode.Path, treeNode); + // No Identifiers for Directories, because we can't use directories as Assets anyways... + //_identifierToAssetNode.Add(assetNode.Identifier, treeNode); Log.EngineLogger.Trace($"Created directory node for: \"{assetNode.Path}\""); } @@ -309,9 +455,39 @@ class AssetHierarchy RemoveOrphanedEntries(treeNode); } + + if (!AssetsDirectory.IsWhiteSpace) + { + String filter = scope $"{AssetsDirectory}/*"; + + String directoryNameBuffer = scope String(256); + + for (var directory in Directory.Enumerate(filter, .Directories)) + { + directory.GetFilePath(directoryNameBuffer..Clear()); + + AddDirectoryToTree(directoryNameBuffer, _assetsDirectoryNode); + } + } - String filter = scope $"{ContentDirectory}/*"; - + if (!ResourcesDirectory.IsWhiteSpace) + { + String filter = scope $"{ResourcesDirectory}/*"; + + String directoryNameBuffer = scope String(256); + + for (var directory in Directory.Enumerate(filter, .Directories)) + { + directory.GetFilePath(directoryNameBuffer..Clear()); + + AddDirectoryToTree(directoryNameBuffer, _resourcesDirectoryNode); + } + + RemoveOrphanedEntries(_assetRootNode); + } + + //*String filter = scope $"{AssetsDirectory}/*"; + /* String directoryNameBuffer = scope String(256); for (var directory in Directory.Enumerate(filter, .Directories)) @@ -321,7 +497,7 @@ class AssetHierarchy AddDirectoryToTree(directoryNameBuffer, _assetHierarchy); } - RemoveOrphanedEntries(_assetHierarchy); + RemoveOrphanedEntries(_assetHierarchy);*/ _fileSystemDirty = false; } @@ -336,7 +512,7 @@ class AssetHierarchy fileName.RemoveFromEnd(AssetFile.ConfigFileExtension.Length); String fileNameWithContentRoot = scope .(); - Path.InternalCombine(fileNameWithContentRoot, _contentDirectory, fileName); + Path.InternalCombine(fileNameWithContentRoot, _assetsDirectory, fileName); var nodeResult = GetNodeFromPath(fileNameWithContentRoot); @@ -366,10 +542,10 @@ class AssetHierarchy String oldFileNameWithContentRoot = scope .(); - Path.InternalCombine(oldFileNameWithContentRoot, _contentDirectory, oldFilePath); + Path.InternalCombine(oldFileNameWithContentRoot, _assetsDirectory, oldFilePath); String newFileNameWithContentRoot = scope .(); - Path.InternalCombine(newFileNameWithContentRoot, _contentDirectory, newFilePath); + Path.InternalCombine(newFileNameWithContentRoot, _assetsDirectory, newFilePath); // Rename config file { diff --git a/GlitchyEditor/src/EditWindows/AssetViewer.bf b/GlitchyEditor/src/EditWindows/AssetViewer.bf index 77da6f8..3997786 100644 --- a/GlitchyEditor/src/EditWindows/AssetViewer.bf +++ b/GlitchyEditor/src/EditWindows/AssetViewer.bf @@ -175,8 +175,8 @@ class TexturererViewerer public this() { - _effect = Content.LoadAsset("Shaders\\textureViewerShader.hlsl"); - _renderTargetEffect = Content.LoadAsset("Shaders\\RenderTargetGroupViewer.hlsl"); + _effect = Content.LoadAsset("Resources/Shaders/textureViewerShader.hlsl"); + _renderTargetEffect = Content.LoadAsset("Resources/Shaders/RenderTargetGroupViewer.hlsl"); } float2 _position; diff --git a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf index 739570e..b17d376 100644 --- a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf +++ b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf @@ -1,6 +1,7 @@ using ImGui; using System; using System.IO; +using System.Linq; using GlitchyEngine.Collections; using System.Collections; using GlitchyEngine.Renderer; @@ -39,7 +40,7 @@ namespace GlitchyEditor.EditWindows // Make sure we are in an existing directory. if (!_manager.AssetHierarchy.FileExists(_currentDirectory)) { - _currentDirectory.Set(_manager.ContentDirectory); + _currentDirectory.Set(_manager.AssetDirectory); } if(!ImGui.Begin(s_WindowTitle, &_open, .None)) @@ -125,7 +126,7 @@ namespace GlitchyEditor.EditWindows /// Renders a sidebar that shows a tree of all directories in the asset folder. private void DrawDirectorySideBar() { - for(var child in _manager.AssetHierarchy.[Friend]_assetHierarchy.Children) + for(var child in _manager.AssetHierarchy.RootNode.Children) { ImGuiPrintEntityTree(child); } @@ -142,17 +143,22 @@ namespace GlitchyEditor.EditWindows ImGui.TreeNodeFlags flags = .OpenOnArrow | .SpanAvailWidth; - if(tree.Children.Count == 0) + if(tree.Children.Where(scope (node) => node->IsDirectory).Count() == 0) flags |= .Leaf; if (tree->Path == _currentDirectory) - { flags |= .Selected; - } + + // TODO: this kinda works, but the user should be able to close the directory + /*if (_manager.AssetHierarchy.GetNodeFromPath(_currentDirectory) case .Ok(let currentTreeNode)) + { + if (currentTreeNode.IsInSubtree(tree)) + ImGui.SetNextItemOpen(true); + }*/ bool isOpen = ImGui.TreeNodeEx(name, flags, $"{name}"); - if (ImGui.IsItemClicked(.Left)) + if (!ImGui.IsItemToggledOpen() && ImGui.IsItemClicked(.Left)) { _currentDirectory.Set(tree->Path); } @@ -186,7 +192,7 @@ namespace GlitchyEditor.EditWindows if (_searchEverywhere && searchFilter.Length > 0) { files = scope:: List>(); - _manager.AssetHierarchy.[Friend]_assetHierarchy.ForEach(scope (node) => + _manager.AssetHierarchy.[Friend]_assetRootNode.ForEach(scope (node) => { if (node->Name.Contains(searchFilter, true)) { @@ -343,8 +349,8 @@ namespace GlitchyEditor.EditWindows String fullpath = scope String(entry->Path); // TODO: this is dirty - if (fullpath.StartsWith(_manager.ContentDirectory, .OrdinalIgnoreCase)) - fullpath.Remove(0, _manager.ContentDirectory.Length); + if (fullpath.StartsWith(_manager.AssetDirectory, .OrdinalIgnoreCase)) + fullpath.Remove(0, _manager.AssetDirectory.Length); Path.Fixup(fullpath); diff --git a/GlitchyEditor/src/EditorApp.bf b/GlitchyEditor/src/EditorApp.bf index f9436b8..dba63b0 100644 --- a/GlitchyEditor/src/EditorApp.bf +++ b/GlitchyEditor/src/EditorApp.bf @@ -36,7 +36,7 @@ namespace GlitchyEditor _contentManager.SetAsDefaultAssetLoader(".hlsl"); _contentManager.SetAssetPropertiesEditor(=> EffectAssetPropertiesEditor.Factory); - _contentManager.SetContentDirectory("./content"); + _contentManager.SetResourcesDirectory("./Resources"); return _contentManager; } diff --git a/GlitchyEditor/src/EditorContentManager.bf b/GlitchyEditor/src/EditorContentManager.bf index b48d517..dd2fc76 100644 --- a/GlitchyEditor/src/EditorContentManager.bf +++ b/GlitchyEditor/src/EditorContentManager.bf @@ -15,12 +15,12 @@ namespace GlitchyEditor; class EditorContentManager : IContentManager { - private append String _contentDirectory = .(); + private append String _resourcesDirectory = .(); + private append String _assetsDirectory = .(); - public StringView ContentDirectory => _contentDirectory; + public StringView ResourcesDirectory => _resourcesDirectory; + public StringView AssetDirectory => _assetsDirectory; - //private append List _identifiers = .() ~ _.ClearAndDeleteItems(); - private append Dictionary _identiferToHandle = .(); // TODO: Check if all resources are unloaded private append Dictionary _handleToAsset = .(); @@ -64,13 +64,20 @@ class EditorContentManager : IContentManager _identiferToHandle.Add(asset.Identifier, asset.Handle); } - public void SetContentDirectory(StringView contentDirectory) + public void SetResourcesDirectory(StringView fileName) { - _contentDirectory.Clear(); - _contentDirectory.Append(contentDirectory); - Path.Fixup(_contentDirectory); + _resourcesDirectory.Set(fileName); + Path.Fixup(_resourcesDirectory); - _assetHierarchy.SetContentDirectory(contentDirectory); + _assetHierarchy.SetResourcesDirectory(_resourcesDirectory); + } + + public void SetAssetDirectory(StringView fileName) + { + _assetsDirectory.Set(fileName); + Path.Fixup(_assetsDirectory); + + _assetHierarchy.SetAssetsDirectory(_assetsDirectory); } public void Update() @@ -302,7 +309,7 @@ class EditorContentManager : IContentManager private void GetResourceFilePath(StringView resourceName, String filePath) { - Path.Combine(filePath, _contentDirectory, resourceName); + Path.Combine(filePath, _assetsDirectory, resourceName); Path.Fixup(filePath); } @@ -336,8 +343,11 @@ class EditorContentManager : IContentManager public AssetHandle LoadAsset(StringView identifier, bool blocking = false) { Debug.Profiler.ProfileResourceFunction!(); + + // It's valid to request no entity, but no entity is obviously invalid. + if (identifier.IsWhiteSpace) + return .Invalid; - // Todo: How strict should we be on paths? String fixedIdentifier = scope String(identifier); AssetIdentifier.Fixup(fixedIdentifier); @@ -346,16 +356,15 @@ class EditorContentManager : IContentManager GetResourceAndSubassetName(fixedIdentifier, let resourceName, let subassetName); - String filePath = scope .(); - GetResourceFilePath(resourceName, filePath); - - Result> resultNode = AssetHierarchy.GetNodeFromPath(filePath); + Result> resultNode = AssetHierarchy.GetNodeFromIdentifier(fixedIdentifier); if (resultNode case .Err) { - Log.EngineLogger.Error($"Could not find asset \"{filePath}\"."); + Log.EngineLogger.Error($"Could not find asset \"{fixedIdentifier}\"."); return .Invalid; } + + String filePath = scope String(resultNode->Value.Path); AssetFile file = resultNode->Value.AssetFile; @@ -374,7 +383,7 @@ class EditorContentManager : IContentManager // TODO: Support lazy loading for all asset types if (!(assetLoader is EditorTextureAssetLoader) || blocking) { - Stream stream = GetStream(filePath); + Stream stream = OpenStream(filePath, true); loadedAsset = assetLoader.LoadAsset(stream, file.AssetConfig.Config, resourceName, subassetName, this); @@ -418,7 +427,7 @@ class EditorContentManager : IContentManager { Debug.Profiler.ProfileResourceFunction!(); - Stream stream = GetStream(filePath); + Stream stream = OpenStream(filePath, true); Asset loadedAsset = assetLoader.LoadAsset(stream, file.AssetConfig.Config, resourceName, subassetName, this); @@ -511,23 +520,13 @@ class EditorContentManager : IContentManager return .Ok; } - private Stream OpenStream(StringView assetIdentifier, bool openOnly) + private Stream OpenStream(StringView fileName, bool openOnly) { - var assetIdentifier; - - if (!assetIdentifier.StartsWith(_contentDirectory)) - { - String filePath = scope:: String(assetIdentifier.Length + _contentDirectory.Length + 2); - Path.Combine(filePath, _contentDirectory, assetIdentifier); - - assetIdentifier = filePath; - } - FileStream fs = new FileStream(); FileMode fileMode = openOnly ? FileMode.Open : FileMode.OpenOrCreate; - var result = fs.Open(assetIdentifier, fileMode, openOnly ? .Read : .ReadWrite, .ReadWrite); + var result = fs.Open(fileName, fileMode, openOnly ? .Read : .ReadWrite, .ReadWrite); if (result case .Err) return null; @@ -535,28 +534,21 @@ class EditorContentManager : IContentManager return fs; } - // TODO: probably not needed + /// Returns a file stream for the given assetIdentifier public Stream GetStream(StringView assetIdentifier) { - return OpenStream(assetIdentifier, true); + String fixuppedIdentifier = scope .(assetIdentifier); + AssetIdentifier.Fixup(fixuppedIdentifier); - /*var assetIdentifier; + var node = _assetHierarchy.GetNodeFromIdentifier(fixuppedIdentifier); - if (!assetIdentifier.StartsWith(_contentDirectory)) + if (node case .Err) { - String filePath = scope:: String(assetIdentifier.Length + _contentDirectory.Length + 2); - Path.Combine(filePath, _contentDirectory, assetIdentifier); - - assetIdentifier = filePath; + Log.EngineLogger.Error($"Could not find asset node \"{assetIdentifier}\"."); + return null; } - FileStream fs = new FileStream(); - var result = fs.Open(assetIdentifier, .Open, .Read, .ReadWrite); - - if (result case .Err) - return null; - - return fs;*/ + return OpenStream(node->Value.Path, true); } public AssetHandle ManageAsset(Asset asset) diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index 3da1d32..aed2d2e 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -181,7 +181,7 @@ namespace GlitchyEditor .(.R8G8B8A8_UNorm)) }); - _editorIcons = new EditorIcons("Textures/EditorIcons.dds", .(64, 64)); + _editorIcons = new EditorIcons("Resources/Textures/EditorIcons.dds", .(64, 64)); _editorIcons.SamplerState = SamplerStateManager.AnisotropicClamp; ContentBrowserWindow.s_FolderTexture = _editorIcons.Folder; @@ -783,6 +783,8 @@ namespace GlitchyEditor _currentProject = Project.Load(workspacePath); String appAssemblyPath = scope String(); + _contentManager.SetAssetDirectory(_currentProject.AssetsFolder); + // TODO: obviously change dll name, configurable? Path.Combine(appAssemblyPath, _currentProject.AssetsFolder, "Scripts/bin/Sandbox.dll"); diff --git a/GlitchyEngine/src/Collections/TreeNode.bf b/GlitchyEngine/src/Collections/TreeNode.bf index 45bad62..a9a30ad 100644 --- a/GlitchyEngine/src/Collections/TreeNode.bf +++ b/GlitchyEngine/src/Collections/TreeNode.bf @@ -65,6 +65,34 @@ namespace GlitchyEngine.Collections DepthFirst } + public bool IsParentOf(TreeNode wantedChild) + { + return wantedChild.IsChildOf(this); + } + + public bool IsChildOf(TreeNode wantedParent) + { + TreeNode currentParent = Parent; + + while (currentParent != null) + { + if (currentParent == wantedParent) + return true; + + currentParent = currentParent.Parent; + } + + return false; + } + + public bool IsInSubtree(TreeNode subtree) + { + if (this == subtree) + return true; + + return IsChildOf(subtree); + } + public void ForEach(ElementFunc func, IterationMode iterationMode = .DepthFirst) { if (iterationMode == .BreadthFirst) @@ -123,6 +151,9 @@ namespace GlitchyEngine.Collections private static void InternalDeleteTreeAndChildren(TreeNode tree) where T : class, delete { + if (tree == null) + return; + for (var child in tree.Children) { InternalDeleteTreeAndChildren(child); diff --git a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11RendererAPI.bf b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11RendererAPI.bf index 283a9ad..98b1893 100644 --- a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11RendererAPI.bf +++ b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11RendererAPI.bf @@ -3,6 +3,7 @@ using GlitchyEngine.Math; using GlitchyEngine.Platform.DX11; using System; +using GlitchyEngine.Content; using internal GlitchyEngine.Renderer; using internal GlitchyEngine.Platform.DX11; @@ -15,7 +16,7 @@ namespace GlitchyEngine.Renderer { private GraphicsContext _context ~ _?.ReleaseRef(); - private Effect _clearUintFx ~ _?.ReleaseRef(); + private AssetHandle _clearUintFx; private BlendState _nonblendingState ~ _?.ReleaseRef(); public GraphicsContext Context @@ -30,7 +31,7 @@ namespace GlitchyEngine.Renderer { Debug.Profiler.ProfileFunction!(); - _clearUintFx = new Effect("content/Shaders/ClearUInt.hlsl"); + _clearUintFx = Content.LoadAsset("Resources/Shaders/ClearUInt.hlsl", null, true); BlendStateDescription desc =.Default; desc.RenderTarget[0].BlendEnable = false; _nonblendingState = new BlendState(desc); diff --git a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Shader.bf b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Shader.bf index d123b9a..1acf6d8 100644 --- a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Shader.bf +++ b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Shader.bf @@ -57,11 +57,11 @@ namespace GlitchyEngine.Renderer Path.Combine(pathNextToParent, includer._parentFileDirectory, StringView(fileName)); - Stream fileStream = Application.Get().ContentManager.GetStream(pathNextToParent); + Stream fileStream = Application.Instance.ContentManager.GetStream(pathNextToParent); if (fileStream == null) { - fileStream = Application.Get().ContentManager.GetStream(StringView(fileName)); + fileStream = Application.Instance.ContentManager.GetStream(StringView(fileName)); } if (fileStream == null) diff --git a/GlitchyEngine/src/Renderer/Renderer.bf b/GlitchyEngine/src/Renderer/Renderer.bf index a03bbbb..506444c 100644 --- a/GlitchyEngine/src/Renderer/Renderer.bf +++ b/GlitchyEngine/src/Renderer/Renderer.bf @@ -176,8 +176,8 @@ namespace GlitchyEngine.Renderer static void InitDeferredRenderer() { - TestFullscreenEffect = Content.LoadAsset("Shaders\\simpleLight.hlsl"); - s_tonemappingEffect = Content.LoadAsset("Shaders\\SimpleTonemapping.hlsl"); + TestFullscreenEffect = Content.LoadAsset("Resources/Shaders/simpleLight.hlsl"); + s_tonemappingEffect = Content.LoadAsset("Resources/Shaders/SimpleTonemapping.hlsl"); _gBuffer = new GBuffer(); BlendStateDescription gBufferBlendDesc = .Default; diff --git a/GlitchyEngine/src/Renderer/Renderer2D.bf b/GlitchyEngine/src/Renderer/Renderer2D.bf index 15a36b4..478eab6 100644 --- a/GlitchyEngine/src/Renderer/Renderer2D.bf +++ b/GlitchyEngine/src/Renderer/Renderer2D.bf @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using GlitchyEngine.Renderer.Text; using GlitchyEngine.World; +using GlitchyEngine.Content; namespace GlitchyEngine.Renderer { @@ -130,9 +131,9 @@ namespace GlitchyEngine.Renderer private static bool s_sceneRunning; #endif - private static Effect s_quadBatchEffect; - private static Effect s_circleBatchEffect; - private static Effect s_lineBatchEffect; + private static AssetHandle s_quadBatchEffect; + private static AssetHandle s_circleBatchEffect; + private static AssetHandle s_lineBatchEffect; private static GeometryBinding s_quadGeometry; @@ -161,9 +162,9 @@ namespace GlitchyEngine.Renderer private static DrawOrder s_drawOrder; /// The effect that is currently used to draw the sprites. - private static Effect s_currentQuadEffect; - private static Effect s_currentCircleEffect; - private static Effect s_currentLineEffect; + private static AssetHandle s_currentQuadEffect; + private static AssetHandle s_currentCircleEffect; + private static AssetHandle s_currentLineEffect; public static uint32 MaxInstancesPerBatch { @@ -183,9 +184,9 @@ namespace GlitchyEngine.Renderer { Debug.Profiler.ProfileFunction!(); - s_quadBatchEffect = new Effect("content\\Shaders\\spritebatch.hlsl"); - s_circleBatchEffect = new Effect("content\\Shaders\\circlebatch.hlsl"); - s_lineBatchEffect = new Effect("content\\Shaders\\linebatch.hlsl"); + s_quadBatchEffect = Content.LoadAsset("Resources/Shaders/spritebatch.hlsl", null, true); + s_circleBatchEffect = Content.LoadAsset("Resources/Shaders/circlebatch.hlsl", null, true); + s_lineBatchEffect = Content.LoadAsset("Resources/Shaders/linebatch.hlsl", null, true); } private static void InitGeometry() @@ -427,10 +428,6 @@ namespace GlitchyEngine.Renderer FontRenderer.Deinit(); - s_quadBatchEffect.ReleaseRef(); - s_circleBatchEffect.ReleaseRef(); - s_lineBatchEffect.ReleaseRef(); - s_quadGeometry.ReleaseRef(); s_whiteTexture.ReleaseRef(); @@ -449,10 +446,6 @@ namespace GlitchyEngine.Renderer delete s_circleInstanceQueue; delete s_lineInstanceQueue; - s_currentQuadEffect?.ReleaseRef(); - s_currentCircleEffect?.ReleaseRef(); - s_currentLineEffect?.ReleaseRef(); - s_opaqueBlendState.ReleaseRef(); s_transparentBlendState.ReleaseRef(); @@ -462,7 +455,7 @@ namespace GlitchyEngine.Renderer } // TODO: remove? - public static void BeginScene(OldCamera camera, DrawOrder drawOrder = .SortByTexture, Effect effect = null, Effect circleEffect = null) + public static void BeginScene(OldCamera camera, DrawOrder drawOrder = .SortByTexture, AssetHandle effect = .Invalid, AssetHandle circleEffect = .Invalid) { Debug.Profiler.ProfileRendererFunction!(); #if DEBUG @@ -470,28 +463,26 @@ namespace GlitchyEngine.Renderer Log.EngineLogger.AssertDebug(!s_sceneRunning, "You have to call EndScene before you can make another call to BeginScene."); #endif - //s_textureColorEffect.Bind(Renderer._context); - - s_currentQuadEffect?.ReleaseRef(); - if(effect != null) + if(effect != .Invalid) { - s_currentQuadEffect = effect..AddRef(); + s_currentQuadEffect = effect; } else { - s_currentQuadEffect = s_quadBatchEffect..AddRef(); + s_currentQuadEffect = s_quadBatchEffect; } - s_currentCircleEffect?.ReleaseRef(); - if(circleEffect != null) + if(circleEffect != .Invalid) { - s_currentCircleEffect = effect..AddRef(); + s_currentCircleEffect = circleEffect; } else { - s_currentCircleEffect = s_circleBatchEffect..AddRef(); + s_currentCircleEffect = s_circleBatchEffect; } - + + s_currentLineEffect = s_lineBatchEffect; + s_currentQuadEffect.Variables["ViewProjection"].SetData(camera.ViewProjection); s_currentCircleEffect.Variables["ViewProjection"].SetData(camera.ViewProjection); @@ -502,45 +493,33 @@ namespace GlitchyEngine.Renderer #endif } - public static void BeginScene(Camera camera, Matrix transform, DrawOrder drawOrder = .SortByTexture, Effect effect = null, Effect circleEffect = null) + public static void BeginScene(Camera camera, Matrix transform, DrawOrder drawOrder = .SortByTexture, AssetHandle effect = .Invalid, AssetHandle circleEffect = .Invalid) { Debug.Profiler.ProfileRendererFunction!(); #if DEBUG Log.EngineLogger.AssertDebug(s_initialized, "Renderer2D was not initialized."); Log.EngineLogger.AssertDebug(!s_sceneRunning, "You have to call EndScene before you can make another call to BeginScene."); #endif - - //s_textureColorEffect.Bind(Renderer._context); - s_currentQuadEffect?.ReleaseRef(); - if(effect != null) + if(effect != .Invalid) { - s_currentQuadEffect = effect..AddRef(); + s_currentQuadEffect = effect; } else { - s_currentQuadEffect = s_quadBatchEffect..AddRef(); + s_currentQuadEffect = s_quadBatchEffect; } - s_currentCircleEffect?.ReleaseRef(); - if(circleEffect != null) + if(circleEffect != .Invalid) { - s_currentCircleEffect = effect..AddRef(); + s_currentCircleEffect = circleEffect; } else { - s_currentCircleEffect = s_circleBatchEffect..AddRef(); + s_currentCircleEffect = s_circleBatchEffect; } - - s_currentLineEffect?.ReleaseRef(); - /*if(circleEffect != null) - { - s_currentLineEffect = effect..AddRef(); - } - else - {*/ - s_currentLineEffect = s_lineBatchEffect..AddRef(); - //} + + s_currentLineEffect = s_lineBatchEffect; Matrix viewProjection = camera.Projection * Matrix.Invert(transform); @@ -555,7 +534,7 @@ namespace GlitchyEngine.Renderer #endif } - public static void BeginScene(EditorCamera camera, DrawOrder drawOrder = .SortByTexture, Effect effect = null, Effect circleEffect = null) + public static void BeginScene(EditorCamera camera, DrawOrder drawOrder = .SortByTexture, AssetHandle effect = .Invalid, AssetHandle circleEffect = .Invalid) { Debug.Profiler.ProfileRendererFunction!(); #if DEBUG @@ -563,37 +542,25 @@ namespace GlitchyEngine.Renderer Log.EngineLogger.AssertDebug(!s_sceneRunning, "You have to call EndScene before you can make another call to BeginScene."); #endif - //s_textureColorEffect.Bind(Renderer._context); - - s_currentQuadEffect?.ReleaseRef(); - if(effect != null) + if(effect != .Invalid) { - s_currentQuadEffect = effect..AddRef(); + s_currentQuadEffect = effect; } else { - s_currentQuadEffect = s_quadBatchEffect..AddRef(); + s_currentQuadEffect = s_quadBatchEffect; } - s_currentCircleEffect?.ReleaseRef(); - if(circleEffect != null) + if(circleEffect != .Invalid) { - s_currentCircleEffect = effect..AddRef(); + s_currentCircleEffect = circleEffect; } else { - s_currentCircleEffect = s_circleBatchEffect..AddRef(); + s_currentCircleEffect = s_circleBatchEffect; } - - s_currentLineEffect?.ReleaseRef(); - /*if(circleEffect != null) - { - s_currentLineEffect = effect..AddRef(); - } - else - {*/ - s_currentLineEffect = s_lineBatchEffect..AddRef(); - //} + + s_currentLineEffect = s_lineBatchEffect; Matrix viewProjection = camera.Projection * camera.View; diff --git a/GlitchyEngine/src/Renderer/Text/FontRenderer.bf b/GlitchyEngine/src/Renderer/Text/FontRenderer.bf index ef8eebe..d4d2858 100644 --- a/GlitchyEngine/src/Renderer/Text/FontRenderer.bf +++ b/GlitchyEngine/src/Renderer/Text/FontRenderer.bf @@ -4,6 +4,7 @@ using System.Diagnostics; using GlitchyEngine.Math; using System.Collections; using GlitchyEngine.Core; +using GlitchyEngine.Content; using static FreeType.HarfBuzz; using internal GlitchyEngine.Renderer.Text; @@ -15,7 +16,7 @@ namespace GlitchyEngine.Renderer.Text { internal static FT_Library s_Library; - public static Effect _msdfEffect; + public static AssetHandle _msdfEffect; internal static bool s_isInitialized; @@ -28,7 +29,7 @@ namespace GlitchyEngine.Renderer.Text InitFreetype(); - _msdfEffect = new Effect("content\\Shaders\\msdfShader.hlsl"); + _msdfEffect = Content.LoadAsset("Resources/Shaders/msdfShader.hlsl"); s_isInitialized = true; } @@ -37,8 +38,6 @@ namespace GlitchyEngine.Renderer.Text { Debug.Profiler.ProfileFunction!(); - _msdfEffect.ReleaseRef(); - DeinitFreetype(); s_isInitialized = false; @@ -334,7 +333,7 @@ namespace GlitchyEngine.Renderer.Text // TODO: this is very not good! var lastEffect = Renderer2D.[Friend]s_currentQuadEffect; - Renderer2D.[Friend]s_currentQuadEffect = _msdfEffect..AddRef(); + Renderer2D.[Friend]s_currentQuadEffect = _msdfEffect; // TODO: oh no.... // Copy viewProjection from current effect Matrix viewProjection = lastEffect.Variables["ViewProjection"].[Friend]GetData(); @@ -409,7 +408,6 @@ namespace GlitchyEngine.Renderer.Text // TODO: not good! // Change back effect - _msdfEffect.ReleaseRef(); Renderer2D.[Friend]s_currentQuadEffect = lastEffect; // release all atlas textures @@ -440,7 +438,7 @@ namespace GlitchyEngine.Renderer.Text // TODO: this is very not good! var lastEffect = Renderer2D.[Friend]s_currentQuadEffect; - Renderer2D.[Friend]s_currentQuadEffect = _msdfEffect..AddRef(); + Renderer2D.[Friend]s_currentQuadEffect = _msdfEffect; // TODO: oh no.... // Copy viewProjection from current effect Matrix viewProjection = lastEffect.Variables["ViewProjection"].[Friend]GetData(); @@ -663,7 +661,6 @@ namespace GlitchyEngine.Renderer.Text // TODO: not good! // Change back effect - _msdfEffect.ReleaseRef(); Renderer2D.[Friend]s_currentQuadEffect = lastEffect; // release all atlas textures diff --git a/GlitchyEngine/src/World/SceneRenderer.bf b/GlitchyEngine/src/World/SceneRenderer.bf index aa666ab..9ac079f 100644 --- a/GlitchyEngine/src/World/SceneRenderer.bf +++ b/GlitchyEngine/src/World/SceneRenderer.bf @@ -18,7 +18,7 @@ class SceneRenderer private uint32 _viewportWidth; private uint32 _viewportHeight; - private AssetHandle _gammaCorrectEffect; + private AssetHandle _gammaCorrectEffect; public RenderTargetGroup CompositeTarget => _compositeTarget; @@ -41,7 +41,7 @@ class SceneRenderer DepthTargetDescription = .(.D24_UNorm_S8_UInt) }); - _gammaCorrectEffect = Content.LoadAsset("Shaders/GammaCorrect.hlsl");//Application.Get().EffectLibrary.Load("content/Shaders/GammaCorrect.hlsl"); + _gammaCorrectEffect = Content.LoadAsset("Resources/Shaders/GammaCorrect.hlsl"); } /// Sets the size of the viewport into which the scene will be rendered. diff --git a/Sandbox/src/TextureViewer.bf b/Sandbox/src/TextureViewer.bf index c97b351..af38d52 100644 --- a/Sandbox/src/TextureViewer.bf +++ b/Sandbox/src/TextureViewer.bf @@ -3,6 +3,7 @@ using GlitchyEngine; using ImGui; using GlitchyEngine.Math; using System; +using GlitchyEngine.Content; namespace Sandbox { class TextureViewer @@ -22,7 +23,7 @@ namespace Sandbox GraphicsContext _context ~ _.ReleaseRef(); - Effect _effect ~ _.ReleaseRef(); + AssetHandle _effect; float _zoom = 1.0f; @@ -48,7 +49,7 @@ namespace Sandbox private void InitEffect() { - _effect = new Effect("content\\Shaders\\textureViewerShader.hlsl"); + _effect = Content.LoadAsset("Shaders\\textureViewerShader.hlsl"); } private void InitState()