diff --git a/GlitchyEditor/content/Textures/EditorIcons.dds b/GlitchyEditor/content/Textures/EditorIcons.dds index 25dc22d..c2de425 100644 Binary files a/GlitchyEditor/content/Textures/EditorIcons.dds and b/GlitchyEditor/content/Textures/EditorIcons.dds differ diff --git a/GlitchyEditor/content/Textures/EditorIcons.psd b/GlitchyEditor/content/Textures/EditorIcons.psd index 7544cde..af27432 100644 Binary files a/GlitchyEditor/content/Textures/EditorIcons.psd and b/GlitchyEditor/content/Textures/EditorIcons.psd differ diff --git a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf new file mode 100644 index 0000000..7be59de --- /dev/null +++ b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf @@ -0,0 +1,272 @@ +using ImGui; +using System; +using System.IO; +using GlitchyEngine.Collections; +using System.Collections; +using GlitchyEngine.Renderer; +using GlitchyEngine.Math; + +namespace GlitchyEditor.EditWindows +{ + class ContentBrowserWindow : EditorWindow + { + // TODO: Get from project + const String ContentDirectory = "./content"; + + FileSystemWatcher fsw ~ { + _.StopRaisingEvents(); + delete _; + }; + + private String _currentDirectory ~ delete _; + + public static SubTexture2D s_FolderTexture; + public static SubTexture2D s_FileTexture; + + public this() + { + fsw = new FileSystemWatcher(ContentDirectory); + fsw.IncludeSubdirectories = true; + + fsw.OnChanged.Add(new (filename) => { + _fileSystemDirty = true; + _currentDirectoryDirty = true; + }); + + fsw.OnCreated.Add(new (filename) => { + _fileSystemDirty = true; + _currentDirectoryDirty = true; + }); + + fsw.OnDeleted.Add(new (filename) => { + _fileSystemDirty = true; + _currentDirectoryDirty = true; + }); + + fsw.OnRenamed.Add(new (newName, oldName) => { + _fileSystemDirty = true; + _currentDirectoryDirty = true; + }); + + fsw.StartRaisingEvents(); + + } + + protected override void InternalShow() + { + if(!ImGui.Begin("Content Browser", &_open, .None)) + { + ImGui.End(); + return; + } + + if (_fileSystemDirty) + { + BuildDirectoryTree(); + + _fileSystemDirty = false; + } + + if (_currentDirectoryDirty) + { + BuildCurrentDirectory(); + } + + ImGui.Columns(2); + + DrawDirectorySideBar(); + + ImGui.NextColumn(); + + DrawCurrentDirectory(); + + ImGui.Columns(1); + + ImGui.End(); + } + + private bool _fileSystemDirty = true; + private bool _currentDirectoryDirty = true; + + class DirectoryNode + { + public String Name ~ delete _; + public String Path ~ delete _; + } + + TreeNode directoryNames = new TreeNode() ~ DeleteTreeAndChildren!(_); + + class Entry + { + public String Name ~ delete _; + public bool IsDirectory; + } + + List _currentDirContent = new .() ~ DeleteContainerAndItems!(_); + + private void BuildDirectoryTree() + { + DeleteTreeAndChildren!(directoryNames); + directoryNames = new TreeNode(); + + String str = scope .(ContentDirectory); + + void AddDirectoryToTree(String path, TreeNode parentNode) + { + DirectoryNode node = new DirectoryNode(); + node.Path = new String(path); + node.Name = new String(); + + Path.GetFileName(node.Path, node.Name); + + var newNode = parentNode.AddChild(node); + + String filter = scope $"{path}/*"; + + for (var directory in Directory.Enumerate(filter, .Directories)) + { + directory.GetFilePath(str..Clear()); + + AddDirectoryToTree(str, newNode); + } + } + + String filter = scope $"{ContentDirectory}/*"; + + for (var directory in Directory.Enumerate(filter, .Directories)) + { + directory.GetFilePath(str..Clear()); + + AddDirectoryToTree(str, directoryNames); + } + } + + private void BuildCurrentDirectory() + { + ClearAndDeleteItems!(_currentDirContent); + + String filter = scope $"{_currentDirectory}/*"; + + String buffer = scope String(); + + for (var entry in Directory.Enumerate(filter, .Directories | .Files)) + { + entry.GetFilePath(buffer..Clear()); + + Entry e = new Entry(); + e.Name = new String(); + Path.GetFileName(buffer, e.Name); + e.IsDirectory = entry.IsDirectory; + + _currentDirContent.Add(e); + } + } + + private void DrawDirectorySideBar() + { + for(var child in directoryNames.Children) + { + ImGuiPrintEntityTree(child); + } + } + + private void ImGuiPrintEntityTree(TreeNode tree) + { + String name = tree.Value.Name; + + ImGui.TreeNodeFlags flags = .OpenOnArrow | .SpanAvailWidth; + + if(tree.Children.Count == 0) + flags |= .Leaf; + + if (tree.Value.Path == _currentDirectory) + { + flags |= .Selected; + } + + bool isOpen = ImGui.TreeNodeEx(name, flags, $"{name}"); + + if (ImGui.IsItemClicked(.Left)) + { + if (_currentDirectory != null) + delete _currentDirectory; + + _currentDirectory = new String(tree.Value.Path); + } + + if(isOpen) + { + for(var child in tree.Children) + { + ImGuiPrintEntityTree(child); + } + + ImGui.TreePop(); + } + } + + private static Vector2 DirectoryItemSize = .(100, 100); + + const Vector2 padding = .(24, 24); + + private void DrawCurrentDirectory() + { + ImGui.Style* style = ImGui.GetStyle(); + + float window_visible_x2 = ImGui.GetWindowPos().x + ImGui.GetWindowContentRegionMax().x; + for (var entry in _currentDirContent) + { + ImGui.PushID(entry.Name); + + DrawDirectoryItem(entry); + + float last_button_x2 = ImGui.GetItemRectMax().x; + float next_button_x2 = last_button_x2 + style.ItemSpacing.x + DirectoryItemSize.X; // Expected position if next button was on same line + if (entry != _currentDirContent.Back && next_button_x2 < window_visible_x2) + ImGui.SameLine(); + + ImGui.PopID(); + } + } + + private void DrawDirectoryItem(Entry entry) + { + ImGui.BeginChild("item", (.)DirectoryItemSize); + + SubTexture2D image = entry.IsDirectory ? s_FolderTexture : s_FileTexture; + + ImGui.PushStyleColor(.Button, ImGui.Vec4(0, 0, 0, 0)); + + ImGui.ImageButton(image, (.)(DirectoryItemSize - padding)); + + if (ImGui.BeginDragDropSource()) + { + String fullpath = scope $"{_currentDirectory}{Path.DirectorySeparatorChar}{entry.Name}"; + + ImGui.SetDragDropPayload("CONTENT_BROWSER_ITEM", fullpath.CStr(), (.)fullpath.Length, .Once); + + ImGui.EndDragDropSource(); + } + + if (ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(.Left)) + { + EntryDoubleClicked(entry); + } + + ImGui.PopStyleColor(); + + ImGui.TextUnformatted(entry.Name); + + ImGui.EndChild(); + } + + private void EntryDoubleClicked(Entry entry) + { + if (entry.IsDirectory) + { + _currentDirectory.Append(Path.DirectorySeparatorChar); + _currentDirectory.Append(entry.Name); + } + } + } +} \ No newline at end of file diff --git a/GlitchyEditor/src/EditWindows/SceneViewportWindow.bf b/GlitchyEditor/src/EditWindows/SceneViewportWindow.bf index 33c2a5b..e78a082 100644 --- a/GlitchyEditor/src/EditWindows/SceneViewportWindow.bf +++ b/GlitchyEditor/src/EditWindows/SceneViewportWindow.bf @@ -35,12 +35,14 @@ namespace GlitchyEditor.EditWindows _editor = editor; } - private ImGui.Vec2 oldViewportSize; + private ImGui.Vec2 oldViewportSize = .(100, 100); private bool viewPortChanged; public uint32 SelectedEntityId; public bool SelectionChanged; + public Vector2 ViewportSize => (Vector2)oldViewportSize; + protected override void InternalShow() { ImGui.PushStyleVar(.WindowPadding, ImGui.Vec2(1, 1)); @@ -88,6 +90,21 @@ namespace GlitchyEditor.EditWindows //ImGui.Image(_editor.CurrentCamera.RenderTarget.GetViewBinding(0), viewportSize); //ImGui.Image(_editor.CurrentScene.[Friend]_compositeTarget.GetViewBinding(0), viewportSize); } + + if (ImGui.BeginDragDropTarget()) + { + ImGui.Payload* payload = ImGui.AcceptDragDropPayload("CONTENT_BROWSER_ITEM"); + + if (payload != null) + { + Log.EngineLogger.Warning(""); + + StringView path = .((char8*)payload.Data, (int)payload.DataSize); + _editor.RequestOpenScene(this, path); + } + + ImGui.EndDragDropTarget(); + } bool gizmoUsed = DrawImGuizmo(viewportSize); diff --git a/GlitchyEditor/src/Editor.bf b/GlitchyEditor/src/Editor.bf index f246b4b..fca76d2 100644 --- a/GlitchyEditor/src/Editor.bf +++ b/GlitchyEditor/src/Editor.bf @@ -15,10 +15,12 @@ namespace GlitchyEditor private EntityHierarchyWindow _entityHierarchyWindow ~ delete _; private ComponentEditWindow _componentEditWindow ~ delete _; private SceneViewportWindow _sceneViewportWindow = new .(this) ~ delete _; + private ContentBrowserWindow _contentBrowserWindow = new .() ~ delete _; public EntityHierarchyWindow EntityHierarchyWindow => _entityHierarchyWindow; public ComponentEditWindow ComponentEditWindow => _componentEditWindow; public SceneViewportWindow SceneViewportWindow => _sceneViewportWindow; + public ContentBrowserWindow ContentBrowserWindow => _contentBrowserWindow; public Scene CurrentScene { @@ -32,6 +34,8 @@ namespace GlitchyEditor public EditorCamera* CurrentCamera { get; set; } + public Event> RequestOpenScene ~ _.Dispose(); + /// Creates a new editor for the given world public this(Scene scene) { @@ -46,6 +50,7 @@ namespace GlitchyEditor _entityHierarchyWindow.Show(); _componentEditWindow.Show(); _sceneViewportWindow.Show(); + _contentBrowserWindow.Show(); } } } diff --git a/GlitchyEditor/src/EditorIcons.bf b/GlitchyEditor/src/EditorIcons.bf new file mode 100644 index 0000000..9580983 --- /dev/null +++ b/GlitchyEditor/src/EditorIcons.bf @@ -0,0 +1,52 @@ +using System; +using GlitchyEngine.Renderer; +using GlitchyEngine.Math; +using GlitchyEngine; + +namespace GlitchyEditor +{ + class EditorIcons : RefCounted + { + Texture2D _texture ~ _.ReleaseRef(); + + public SubTexture2D DirectionalLight ~ _.ReleaseRef(); + public SubTexture2D Camera ~ _.ReleaseRef(); + public SubTexture2D Folder ~ _.ReleaseRef(); + public SubTexture2D File ~ _.ReleaseRef(); + + public SamplerState SamplerState + { + get => _texture.SamplerState; + set => _texture.SamplerState = value; + } + + public this(String texturePath, Vector2 iconSize) + { + _texture = new Texture2D(texturePath); + + Vector2 pen = .(); + + DirectionalLight = GetNextGridTexture(ref pen, iconSize); + Camera = GetNextGridTexture(ref pen, iconSize); + Folder = GetNextGridTexture(ref pen, iconSize); + File = GetNextGridTexture(ref pen, iconSize); + } + + private SubTexture2D GetNextGridTexture(ref Vector2 pen, Vector2 iconSize) + { + SubTexture2D subTexture = .CreateFromGrid(_texture, pen, iconSize); + + pen.X += 1.0f; + + if (pen.X >= (_texture.Width / iconSize.X)) + { + pen.X = 0; + pen.Y += 1.0f; + } + + Log.EngineLogger.AssertDebug(pen.Y <=(_texture.Height / iconSize.Y)); + + return subTexture; + } + } +} \ No newline at end of file diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index e3e19b0..e7aad13 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -50,9 +50,11 @@ namespace GlitchyEditor EditorCamera _camera ~ _.Dispose(); - Texture2D _editorIcons ~ _.ReleaseRef(); + /*Texture2D _editorIcons ~ _.ReleaseRef(); SubTexture2D _iconDirectionalLight ~ _.ReleaseRef(); - SubTexture2D _iconCamera ~ _.ReleaseRef(); + SubTexture2D _iconCamera ~ _.ReleaseRef();*/ + + EditorIcons _editorIcons ~ _.ReleaseRef(); public this() : base("Example") { @@ -62,10 +64,10 @@ namespace GlitchyEditor _camera = EditorCamera(Vector3(3.5f, 1.25f, 2.75f), Quaternion.FromEulerAngles(MathHelper.ToRadians(40), MathHelper.ToRadians(25), 0), MathHelper.ToRadians(75), 0.1f, 1); _camera.RenderTarget = _cameraTarget; + + InitEditor(); NewScene(); - - InitEditor(); } private void InitGraphics() @@ -104,10 +106,16 @@ namespace GlitchyEditor .(.R8G8B8A8_UNorm)) }); - _editorIcons = new Texture2D("Textures/EditorIcons.dds"); + _editorIcons = new EditorIcons("Textures/EditorIcons.dds", .(64, 64)); + _editorIcons.SamplerState = SamplerStateManager.AnisotropicClamp; + + ContentBrowserWindow.s_FolderTexture = _editorIcons.Folder; + ContentBrowserWindow.s_FileTexture = _editorIcons.File; + + /*_editorIcons = new Texture2D("Textures/EditorIcons.dds"); _editorIcons.SamplerState = SamplerStateManager.AnisotropicClamp; _iconDirectionalLight = .CreateFromGrid(_editorIcons, .(0, 0), .(64, 64)); - _iconCamera = .CreateFromGrid(_editorIcons, .(1, 0), .(64, 64)); + _iconCamera = .CreateFromGrid(_editorIcons, .(1, 0), .(64, 64));*/ } private void InitEditor() @@ -115,6 +123,10 @@ namespace GlitchyEditor _editor = new Editor(_scene); _editor.SceneViewportWindow.ViewportSizeChangedEvent.Add(new (s, e) => ViewportSizeChanged(s, e)); _editor.CurrentCamera = &_camera; + + _editor.RequestOpenScene.Add(new (s, fileName) => { + LoadSceneFile(fileName); + }); } public override void Update(GameTime gameTime) @@ -178,7 +190,7 @@ namespace GlitchyEditor Matrix world = Billboard(transform.WorldTransform); float alpha = CalculateAlpha(transform.WorldTransform.Translation); - Renderer2D.DrawQuad(world, _iconCamera, ColorRGBA(alpha, alpha, alpha, alpha), .(0, 0, 1, 1), entity.Index); + Renderer2D.DrawQuad(world, _editorIcons.Camera, ColorRGBA(alpha, alpha, alpha, alpha), .(0, 0, 1, 1), entity.Index); //Renderer2D.DrawQuad(world, _iconCamera, .White, .(0, 0, 1, 1), entity.Index); } @@ -199,7 +211,7 @@ namespace GlitchyEditor Matrix world = Billboard(transform.WorldTransform); float alpha = CalculateAlpha(transform.WorldTransform.Translation); - Renderer2D.DrawQuad(world, _iconDirectionalLight, ColorRGBA(light.SceneLight.Color.R * alpha, light.SceneLight.Color.G * alpha, light.SceneLight.Color.B * alpha, alpha), .(0, 0, 1, 1), entity.Index); + Renderer2D.DrawQuad(world, _editorIcons.DirectionalLight, ColorRGBA(light.SceneLight.Color.R * alpha, light.SceneLight.Color.G * alpha, light.SceneLight.Color.B * alpha, alpha), .(0, 0, 1, 1), entity.Index); //Renderer2D.DrawQuad(world, _iconDirectionalLight, ColorRGBA(light.SceneLight.Color, alpha), .(0, 0, 1, 1), entity.Index); } } @@ -366,6 +378,12 @@ namespace GlitchyEditor private void NewScene() { SceneFilePath = null; + + delete _scene; + _scene = new Scene(); + _editor.CurrentScene = _scene; + var vpSize = _editor.SceneViewportWindow.ViewportSize; + _scene.OnViewportResize((.)vpSize.X, (.)vpSize.Y); _camera.Position = .(-1.5f, 1.5f, -2.5f); _camera.RotationEuler = .(MathHelper.ToRadians(25), MathHelper.ToRadians(35), 0); @@ -421,19 +439,26 @@ namespace GlitchyEditor { if (val == .OK) { - SceneFilePath = ofd.FileNames[0]; - - delete _scene; - _scene = new Scene(); - - SceneSerializer serializer = scope .(_scene); - serializer.Deserialize(SceneFilePath); - - _editor.CurrentScene = _scene; + LoadSceneFile(ofd.FileNames[0]); } } } + /// Loads the given scene file. + private void LoadSceneFile(StringView filename) + { + SceneFilePath = scope String(filename); + + delete _scene; + _scene = new Scene(); + _editor.CurrentScene = _scene; + var vpSize = _editor.SceneViewportWindow.ViewportSize; + _scene.OnViewportResize((.)vpSize.X, (.)vpSize.Y); + + SceneSerializer serializer = scope .(_scene); + serializer.Deserialize(SceneFilePath); + } + private void DrawMainMenuBar() { ImGui.BeginMainMenuBar(); diff --git a/GlitchyEngine/src/Collections/TreeNode.bf b/GlitchyEngine/src/Collections/TreeNode.bf index ab91281..bfc6f87 100644 --- a/GlitchyEngine/src/Collections/TreeNode.bf +++ b/GlitchyEngine/src/Collections/TreeNode.bf @@ -45,4 +45,26 @@ namespace GlitchyEngine.Collections return null; } } + + static + { + public static mixin DeleteTreeAndChildren(TreeNode tree) where T : class, delete + { + InternalDeleteTreeAndChildren(tree); + } + + private static void InternalDeleteTreeAndChildren(TreeNode tree) where T : class, delete + { + for (var child in tree.Children) + { + InternalDeleteTreeAndChildren(child); + } + + delete tree.Value; + + tree.Children.Clear(); + + delete tree; + } + } } diff --git a/GlitchyEngine/src/ImGui/ImGuiExtension.bf b/GlitchyEngine/src/ImGui/ImGuiExtension.bf index b23abbb..efd8d91 100644 --- a/GlitchyEngine/src/ImGui/ImGuiExtension.bf +++ b/GlitchyEngine/src/ImGui/ImGuiExtension.bf @@ -1,6 +1,7 @@ using GlitchyEngine.Math; using GlitchyEngine.Renderer; using System; +using GlitchyEngine; namespace ImGui { @@ -34,6 +35,16 @@ namespace ImGui Image(texture.GetViewBinding(), size, uv0, uv1, tint_col, border_col); } + public static void Image(SubTexture2D subTexture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero) + { + if (uv0 != .Zero || uv1 != .Ones) + Runtime.NotImplemented(); + + Vector2 v = (.)subTexture.TexCoords.XY + subTexture.TexCoords.ZW; + + Image(subTexture.Texture.GetViewBinding(), size, (.)subTexture.TexCoords.XY, (.)v, tint_col, border_col); + } + public static void Image(RenderTarget2D texture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero) { Image(texture.GetViewBinding(), size, uv0, uv1, tint_col, border_col); @@ -41,6 +52,18 @@ namespace ImGui public static extern void Image(TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero); + public static bool ImageButton(SubTexture2D subTexture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, int32 frame_padding = -1, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones) + { + if (uv0 != .Zero || uv1 != .Ones) + Runtime.NotImplemented(); + + Vector2 v = (.)subTexture.TexCoords.XY + subTexture.TexCoords.ZW; + + return ImageButton(subTexture.Texture.GetViewBinding(), size, (.)subTexture.TexCoords.XY, (.)v, frame_padding, bg_col, tint_col); + } + + public static extern bool ImageButton(TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, int32 frame_padding = -1, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones); + public static void TextUnformatted(StringView text) => TextUnformattedImpl(text.Ptr, text.Ptr + text.Length); public static void PushID(StringView id) => PushID(id.Ptr, id.Ptr + id.Length); diff --git a/GlitchyEngine/src/Math/Vector2.bf b/GlitchyEngine/src/Math/Vector2.bf index 1dd8b30..21ed285 100644 --- a/GlitchyEngine/src/Math/Vector2.bf +++ b/GlitchyEngine/src/Math/Vector2.bf @@ -4,7 +4,7 @@ using System; namespace GlitchyEngine.Math { [BonTarget] - [SwizzleVector(2, "Vector")] + [SwizzleVector(2, "GlitchyEngine.Math.Vector")] public struct Vector2 { public const Vector2 Zero = .(0f, 0f); diff --git a/GlitchyEngine/src/Math/Vector3.bf b/GlitchyEngine/src/Math/Vector3.bf index 033e8de..2aaba43 100644 --- a/GlitchyEngine/src/Math/Vector3.bf +++ b/GlitchyEngine/src/Math/Vector3.bf @@ -4,7 +4,7 @@ using System; namespace GlitchyEngine.Math { [BonTarget] - [SwizzleVector(3, "Vector")] + [SwizzleVector(3, "GlitchyEngine.Math.Vector")] public struct Vector3 { public const Vector3 Zero = .(0f, 0f, 0f); diff --git a/GlitchyEngine/src/Math/Vector4.bf b/GlitchyEngine/src/Math/Vector4.bf index 965aa39..334098d 100644 --- a/GlitchyEngine/src/Math/Vector4.bf +++ b/GlitchyEngine/src/Math/Vector4.bf @@ -4,7 +4,7 @@ using System; namespace GlitchyEngine.Math { [BonTarget] - [SwizzleVector(4, "Vector")] + [SwizzleVector(4, "GlitchyEngine.Math.Vector")] public struct Vector4 { public const Vector4 Zero = .(0f, 0f, 0f, 0f); diff --git a/GlitchyEngine/src/Platform/DX11/ImGui/ImGui.bf b/GlitchyEngine/src/Platform/DX11/ImGui/ImGui.bf index c82728e..b886d84 100644 --- a/GlitchyEngine/src/Platform/DX11/ImGui/ImGui.bf +++ b/GlitchyEngine/src/Platform/DX11/ImGui/ImGui.bf @@ -19,7 +19,19 @@ namespace ImGui ImGui.Image(view, size, uv0, uv1, tint_col, border_col); - textureViewBinding.ReleaseRef(); + textureViewBinding.Release(); + } + + public static override bool ImageButton(TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, int32 frame_padding = -1, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones) + { + var view = textureViewBinding._nativeShaderResourceView..AddRef(); + _resourceViews.Add(view); + + bool pressed = ImGui.ImageButton(view, size, uv0, uv1, frame_padding, bg_col, tint_col); + + textureViewBinding.Release(); + + return pressed; } protected internal static override void CleanupFrame() diff --git a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf index 5a34efa..c8d7c94 100644 --- a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf +++ b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11Texture.bf @@ -146,7 +146,7 @@ namespace GlitchyEngine.Renderer } // TODO: Update Texture Arrays! - protected override System.Result PlatformSetData(void* data, uint32 elementSize, uint32 destX, + protected override Result PlatformSetData(void* data, uint32 elementSize, uint32 destX, uint32 destY, uint32 destWidth, uint32 destHeight, uint32 arraySlice, uint32 mipLevel, GlitchyEngine.Renderer.MapType mapType) { Debug.Profiler.ProfileResourceFunction!(); @@ -259,7 +259,7 @@ namespace GlitchyEngine.Renderer protected override TextureViewBinding PlatformGetViewBinding() { - return .(_nativeResourceView, _samplerState.nativeSamplerState); + return .(_nativeResourceView, _samplerState?.nativeSamplerState); } } diff --git a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11TextureViewBinding.bf b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11TextureViewBinding.bf index aac1924..409783e 100644 --- a/GlitchyEngine/src/Platform/DX11/Renderer/Dx11TextureViewBinding.bf +++ b/GlitchyEngine/src/Platform/DX11/Renderer/Dx11TextureViewBinding.bf @@ -24,7 +24,7 @@ namespace GlitchyEngine.Renderer _nativeSamplerState?.AddRef(); } - public override void ReleaseRef() + public override void Release() { _nativeShaderResourceView?.Release(); _nativeSamplerState?.Release(); diff --git a/GlitchyEngine/src/Renderer/Effect.bf b/GlitchyEngine/src/Renderer/Effect.bf index 0cd17c9..c72cb9e 100644 --- a/GlitchyEngine/src/Renderer/Effect.bf +++ b/GlitchyEngine/src/Renderer/Effect.bf @@ -63,13 +63,20 @@ namespace GlitchyEngine.Renderer name = scope:: String(); Path.GetFileNameWithoutExtension(filepath, name); } - - Log.EngineLogger.AssertDebug(!Exists(name), "Can't add two effects with the same name to library."); - Effect effect = new Effect(filepath, name); - Add(effect); + if (Exists(name)) + { + return Get(name); + } + else + { + Log.EngineLogger.AssertDebug(!Exists(name), "Can't add two effects with the same name to library."); - return effect; + Effect effect = new Effect(filepath, name); + Add(effect); + + return effect; + } } /** @@ -182,7 +189,7 @@ namespace GlitchyEngine.Renderer for(let entry in _textures) { - entry.value.BoundTexture.ReleaseRef(); + entry.value.BoundTexture.Release(); } } @@ -192,7 +199,7 @@ namespace GlitchyEngine.Renderer ref TextureEntry entry = ref _textures[name]; - entry.BoundTexture.ReleaseRef(); + entry.BoundTexture.Release(); entry.BoundTexture = texture.GetViewBinding(); } @@ -205,7 +212,7 @@ namespace GlitchyEngine.Renderer ref TextureEntry entry = ref _textures[name]; - entry.BoundTexture.ReleaseRef(); + entry.BoundTexture.Release(); //entry.BoundTexture = .RenderTargetGroup(renderTargetGroup..AddRef(), firstTarget, targetCount); entry.BoundTexture = renderTargetGroup.GetViewBinding(firstTarget); } @@ -216,7 +223,7 @@ namespace GlitchyEngine.Renderer ref TextureEntry entry = ref _textures[name]; - entry.BoundTexture.ReleaseRef(); + entry.BoundTexture.Release(); entry.BoundTexture = textureViewBinding..AddRef(); } @@ -226,11 +233,11 @@ namespace GlitchyEngine.Renderer for(let (name, entry) in _textures) { - entry.VsSlot?.BoundTexture.ReleaseRef(); + entry.VsSlot?.BoundTexture.Release(); entry.VsSlot?.BoundTexture = entry.BoundTexture; entry.VsSlot?.BoundTexture.AddRef(); - entry.PsSlot?.BoundTexture.ReleaseRef(); + entry.PsSlot?.BoundTexture.Release(); entry.PsSlot?.BoundTexture = entry.BoundTexture; entry.PsSlot?.BoundTexture.AddRef(); } diff --git a/GlitchyEngine/src/Renderer/Material.bf b/GlitchyEngine/src/Renderer/Material.bf index a3ccb16..28af7bb 100644 --- a/GlitchyEngine/src/Renderer/Material.bf +++ b/GlitchyEngine/src/Renderer/Material.bf @@ -40,7 +40,7 @@ namespace GlitchyEngine.Renderer { for(let (name, texture) in _textures) { - texture.ReleaseRef(); + texture.Release(); } delete _textures; @@ -90,7 +90,7 @@ namespace GlitchyEngine.Renderer { if(_textures.TryGetValue(name, var entry)) { - entry.ReleaseRef(); + entry.Release(); _textures[name] = texture.GetViewBinding(); //texture?.AddRef(); } diff --git a/GlitchyEngine/src/Renderer/RenderCommand.bf b/GlitchyEngine/src/Renderer/RenderCommand.bf index 6525799..d17d1cc 100644 --- a/GlitchyEngine/src/Renderer/RenderCommand.bf +++ b/GlitchyEngine/src/Renderer/RenderCommand.bf @@ -34,7 +34,9 @@ namespace GlitchyEngine.Renderer _rendererAPI.Init(); } - [Inline] + // REPORT!!!!!!!!! + // Inline doesn't compile + //[Inline] public static void Clear(RenderTarget2D renderTarget, ColorRGBA color) { _rendererAPI.Clear(renderTarget, color); diff --git a/GlitchyEngine/src/Renderer/ShaderTextureCollection.bf b/GlitchyEngine/src/Renderer/ShaderTextureCollection.bf index acbc1f6..08a5ab7 100644 --- a/GlitchyEngine/src/Renderer/ShaderTextureCollection.bf +++ b/GlitchyEngine/src/Renderer/ShaderTextureCollection.bf @@ -31,7 +31,7 @@ namespace GlitchyEngine.Renderer for(let entry in entries) { delete entry.Name; - entry.BoundTexture.ReleaseRef(); + entry.BoundTexture.Release(); } delete entries; diff --git a/GlitchyEngine/src/Renderer/TextureViewBinding.bf b/GlitchyEngine/src/Renderer/TextureViewBinding.bf index 3b82f99..9aa24fc 100644 --- a/GlitchyEngine/src/Renderer/TextureViewBinding.bf +++ b/GlitchyEngine/src/Renderer/TextureViewBinding.bf @@ -9,8 +9,8 @@ namespace GlitchyEngine.Renderer public extern bool IsEmpty { get; } public extern void AddRef(); - public extern void ReleaseRef(); + public extern void Release(); - public void Dispose() => ReleaseRef(); + public void Dispose() => Release(); } } diff --git a/GlitchyEngine/src/World/Scene.bf b/GlitchyEngine/src/World/Scene.bf index bb47fa9..b9336d0 100644 --- a/GlitchyEngine/src/World/Scene.bf +++ b/GlitchyEngine/src/World/Scene.bf @@ -33,13 +33,13 @@ namespace GlitchyEngine.World public this() { - Entity entity = CreateEntity("Green Quad"); + /*Entity entity = CreateEntity("Green Quad"); entity.AddComponent(.(ColorRGBA.SRgbToLinear(.(0.2f, 0.9f, 0.15f)))); Entity entity2 = CreateEntity("Red Square"); var v = entity2.AddComponent(.(ColorRGBA.SRgbToLinear(.(0.95f, 0.1f, 0.3f)))); v.Sprite = new Texture2D("Textures/rocket.dds"); - v.Sprite.SamplerState = SamplerStateManager.PointClamp; + v.Sprite.SamplerState = SamplerStateManager.PointClamp;*/ _onComponentAddedHandlers.Add(typeof(CameraComponent), (e, t, c) => { CameraComponent* cameraComponent = (.)c;